@adhdev/daemon-standalone 0.8.17 → 0.8.19

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,61 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-CKqklWLC.js","assets/vendor-CPghmr9Y.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
- var ya=Object.defineProperty;var va=(t,s,n)=>s in t?ya(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Ke=(t,s,n)=>va(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as Qn,a as er,b as wa,c as ja,u as St,R as Os,t as ka,d as Na,e as Sa,D as Ca,f as Ia,g as Ma,h as zs,i as _a,k as Ta,B as Aa,l as La,m as ct,N as As,n as Ra}from"./vendor-CPghmr9Y.js";import{_ as $a}from"./terminal-CKqklWLC.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const tr=a.createContext({ides:[],updateIdeChats:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),sr=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function mn(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.childSessions)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function vs(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},i=s.version??n.version??t.version,o=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(r.version=i),o&&(r.serverVersion=o),i&&o&&i===o?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(r.versionMismatch=!0),r)}function Pa(t,s,n){var l,f,u,x,h,p,v;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(m=>({...m,_lastUpdate:r}));const o=new Map;for(const m of s)o.set(m.id,m);for(const m of t){const C=o.get(m.id);if(!C){o.set(m.id,{...m,_lastUpdate:r});continue}const b=mn(m),w=mn(C);if(b>w){const N=(l=m.chats)!=null&&l.length?m.chats:C.chats,D=vs(C,m,{...C,...m,chats:N,_lastUpdate:r});o.set(m.id,D)}else if(b<w){const N={};if(m.status&&m.status!==C.status&&(N.status=m.status),m.cdpConnected!==void 0&&(N.cdpConnected=m.cdpConnected),(f=m.chats)!=null&&f.length&&!((u=C.chats)!=null&&u.length)&&(N.chats=m.chats),m.machineNickname!==void 0&&m.machineNickname!==C.machineNickname&&(N.machineNickname=m.machineNickname),m.version!==void 0&&(N.version=m.version),m.serverVersion!==void 0&&(N.serverVersion=m.serverVersion),m.versionMismatch===!0&&(N.versionMismatch=!0),Object.keys(N).length>0){const D=vs(C,m,{...C,...N,_lastUpdate:C._lastUpdate});o.set(m.id,D)}}else{const N=m.timestamp||r,D=C._lastUpdate||C.timestamp||0;if(N>=D){const g=(x=m.chats)!=null&&x.length?m.chats:C.chats,j=vs(C,m,{...C,...m,chats:g,_lastUpdate:r});o.set(m.id,j)}else(h=m.chats)!=null&&h.length&&!((p=C.chats)!=null&&p.length)&&o.set(m.id,{...C,chats:m.chats})}}const c=new Set(t.map(m=>m.id)),d=new Set;for(const m of t){const C=m.daemonId||((v=m.id)==null?void 0:v.split(":")[0]);C&&d.add(C)}for(const[m,C]of o){const b=C.daemonId||m.split(":")[0];if(!d.has(b))continue;if(i.has(b)&&!c.has(m)){o.delete(m);continue}const w=r-(C._lastUpdate||C.timestamp||0);(C.transport==="pty"&&!c.has(m)&&w>1e4||C.transport==="acp"&&!c.has(m)&&w>1e4||C.transport==="cdp-page"&&!c.has(m)&&w>3e4)&&o.delete(m)}for(const[m,C]of o)r-(C._lastUpdate||C.timestamp||0)>3e5&&C.status!=="online"&&o.delete(m);return Array.from(o.values())}function Ea(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 Da({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState(!1),[c,d]=a.useState([]),[l,f]=a.useState(void 0),u=a.useRef(n);a.useEffect(()=>{u.current=n},[n]);const x=a.useCallback((b,w)=>{r(N=>{let D=!1;const g=N.map(j=>j.id!==b||j.chats===w?j:(D=!0,{...j,chats:w}));return D?g:N})},[]),h=a.useCallback((b,w)=>{r(N=>{const D=N.length===0?b:Pa(b,N,w);return Ea(N,D)?N:D})},[]),p=a.useCallback(()=>o(!0),[]),v=a.useMemo(()=>({injectEntries:h,markLoaded:p,getIdes:()=>u.current}),[h,p]),m=s,C=a.useMemo(()=>({ides:n,updateIdeChats:x,initialLoaded:i,toasts:c,setToasts:d,wsStatus:(m==null?void 0:m.wsStatus)??"connected",isConnected:(m==null?void 0:m.isConnected)??!0,connectionStates:(m==null?void 0:m.connectionStates)??{},connectionTransports:(m==null?void 0:m.connectionTransports)??{},showReconnected:(m==null?void 0:m.showReconnected)??!1,retryConnection:m==null?void 0:m.retryConnection,isP2PActive:(m==null?void 0:m.isP2PActive)??!1,p2pStates:(m==null?void 0:m.p2pStates)??{},userRole:m==null?void 0:m.userRole,userName:l,setUserName:f}),[n,x,i,c,m==null?void 0:m.wsStatus,m==null?void 0:m.isConnected,m==null?void 0:m.connectionStates,m==null?void 0:m.connectionTransports,m==null?void 0:m.showReconnected,m==null?void 0:m.retryConnection,m==null?void 0:m.isP2PActive,m==null?void 0:m.p2pStates,m==null?void 0:m.userRole,l]);return e.jsx(sr.Provider,{value:v,children:e.jsx(tr.Provider,{value:C,children:t})})}function $t(){return a.useContext(tr)}function xn(){return a.useContext(sr)}function nr(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function i(d){return d.startsWith("http")?d:`${s}${d.startsWith("/")?"":"/"}${d}`}function o(d){const l=n==null?void 0:n(),f=i(d),u=d.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&u.searchParams.set("token",l),!d.startsWith("http")&&!s?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function c(d,l={}){const f={"Content-Type":"application/json",...l.headers||{}},u=n==null?void 0:n();u&&(f.Authorization=`Bearer ${u}`);const x=i(d),h=await fetch(x,{...l,headers:f});if(h.status===401)throw r==null||r(),new Error("Unauthorized");if(!h.ok){const p=await h.json().catch(()=>({error:h.statusText}));throw new Error(p.error||`API Error: ${h.status}`)}return h.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:d=>c(`/api/v1/daemons/${d}/status`),sendCommand:(d,l,f={})=>c(`/api/v1/daemons/${d}/command`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),execTerminal:(d,l,f)=>c(`/api/v1/daemons/${d}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:f})}),sendAgentMessage:(d,l,f)=>c(`/api/v1/shortcuts/${d}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:f})}),getAgentStatus:d=>c(`/api/v1/shortcuts/${d}/status`),approveAgent:(d,l,f)=>c(`/api/v1/shortcuts/${d}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:f?"approve":"reject"})}),getMuxState:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/state`),getMuxSocketInfo:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/socket-info`),controlMux:(d,l,f={})=>c(`/api/v1/mux/${encodeURIComponent(d)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),getMuxEventsUrl:d=>o(`/api/v1/mux/${encodeURIComponent(d)}/events`),getRuntimeEventsUrl:d=>o(`/api/v1/runtime/${encodeURIComponent(d)}/events`),request:c}}const Ba=nr({baseUrl:"http://localhost:3847"}),Ka=a.createContext(Ba);function Wa({client:t,children:s}){return e.jsx(Ka.Provider,{value:t,children:s})}const Oa={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},rr=a.createContext(Oa);function za({value:t,children:s}){return e.jsx(rr.Provider,{value:t,children:s})}function ut(){return a.useContext(rr)}const Ne={size:18};function ar({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function Us({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}function ss({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 Ua({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 Ha({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"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 Fa({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function ns({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),e.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"}),e.jsx("line",{x1:"9",y1:"7",x2:"16",y2:"7"}),e.jsx("line",{x1:"9",y1:"11",x2:"14",y2:"11"})]})}function Va({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 us({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 ir({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function or({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function it({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function Ve({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Hs({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 qa({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Pt({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function Fs({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 Vs({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function bt({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}function cr({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Ga({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C5 20 1 12 1 12a21.8 21.8 0 0 1 5.06-5.94"}),e.jsx("path",{d:"M9.9 4.24A10.93 10.93 0 0 1 12 4c7 0 11 8 11 8a21.77 21.77 0 0 1-2.16 3.19"}),e.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function lr({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]})}function Ya({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 qs({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function dr({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})}function kt({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function ur({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function Xa({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"8",width:"18",height:"12",rx:"2"}),e.jsx("path",{d:"M12 2v6"}),e.jsx("circle",{cx:"8.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"15.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"})]})}function Za({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function Ja({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("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 ps({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"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 Qa({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function ei({size:t=Ne.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function ti({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function si({size:t=Ne.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function ni(t){var l,f;const s=u=>u.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),r=t.split(`
3
- `).map(u=>{if(!u.includes("\r"))return u;const x=u.split("\r").map(v=>v.trim()).filter(Boolean);if(x.length===0)return"";const h=x.filter(v=>v.startsWith("⏺"));if(h.length>0)return h[h.length-1];const p=x.filter(v=>!(/^[❯›>]\s*$/.test(v)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(v)&&v.length<40||/^[╭╰│├╮╯─═]+$/.test(v)));return p.length>0?p[p.length-1]:x[x.length-1]}).join(`
4
- `).split(`
5
- `),i={},o=[];let c=!1;for(const u of r){const x=s(u);if(x===""){c=!1,o.push("");continue}if(/^❯\s*$/.test(x)||/^>\s*$/.test(x)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(x)||/^◐\s/.test(x)||/\/effort/.test(x)||/^⎿\s+(Tip|Note|Hint):/.test(x)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(x)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(x)||/Brewing[…\.]{0,3}\s*\d*$/i.test(x)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(x)||/^Auto-updating/i.test(x)||/^✳\s*Debug (?:Claude Code|Codex) CLI/i.test(x)||/^(?:─|═|╭|╰|│|├|╮|╯|┌|┐|└|┘|┬|┴|┼)+$/.test(x))continue;if(/^[⏺●·⏵]/.test(u)){const p=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(p)i[p[1]]=(i[p[1]]||0)+1;else{const v=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);v&&(i[v]=(i[v]||0)+1)}c=!0;continue}if(/^(?:Bash|Read|Write|Edit|MultiEdit|Task|Glob|Grep|LS|NotebookEdit|Exact output)(?:\(|:)/.test(x)){const p=((f=(l=x.match(/^([A-Za-z][A-Za-z0-9_ ]+)/))==null?void 0:l[1])==null?void 0:f.trim())||"Tool";i[p]=(i[p]||0)+1,c=!0;continue}if(/^Read\s+\d+\s+files?(?:\s+\(.*\))?$/i.test(x)){i.Read=(i.Read||0)+1,c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(x)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||c&&/^\s{2,}/.test(u))continue;c=!1;const h=x.replace(/^❯\s+/,"");o.push(h)}const d=o.join(`
6
- `).replace(/\n{3,}/g,`
7
-
8
- `).trim();return{toolCounts:i,textContent:d,hasTools:Object.keys(i).length>0}}function Ls(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function ri(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function wt(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(o=>(o==null?void 0:o.text)||"").join(`
9
- `):String(n.content||"");return[n.id?`id:${n.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",typeof n.index=="number"?`msgIndex:${n.index}`:"",n.timestamp?`ts:${n.timestamp}`:"",n.role?`role:${n.role}`:"",r?`content:${r.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const fn=700,ai=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Qn,{remarkPlugins:[er],children:s.text}),e.jsx("span",{className:"action-time",children:Ls(s.timestamp)})]})},(t,s)=>t.log===s.log),ii=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:d,onToggleExpanded:l,onToggleTextExpanded:f}){var D;const u=(s.role||"").toLowerCase(),x=u==="user"||u==="human",h=s.kind||(u==="tool"?"tool":"standard"),p=typeof s.content=="string"?s.content:(s.content||[]).map(g=>g.text||"").join(`
10
- `);if(h==="thought"){const g=((D=s.meta)==null?void 0:D.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Za,{size:13}),e.jsx("span",{children:g})]}),e.jsx("div",{className:"chat-msg-body",children:p})]})}if(h==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:p.split(`
11
- `)[0].slice(0,80)})]});if(h==="terminal"){const g=s.meta||{},j=g.isRunning?"⏳":"✅",y=g.label||"Ran command";return e.jsxs("div",{className:"self-start chat-msg-terminal",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx("span",{children:j}),e.jsx("span",{children:y})]}),e.jsx("pre",{className:"chat-msg-body",children:p})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:p.slice(0,100)});const v=!x&&o?ni(p):null,m=v?v.textContent:p,C=v?Object.entries(v.toolCounts):[],b=o&&!x&&!c&&m.length>fn,w=c?p:b&&!d?m.slice(0,fn):m,N=ri(w);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${x?"self-end":"self-start"}`,children:[C.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[C.map(([g,j])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",g,j>1?` ×${j}`:""]},g)),(v==null?void 0:v.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!m&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Ls(n)})]}),(m||x)&&e.jsxs("div",{className:`chat-bubble ${x?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${m?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:x?i||"You":s.senderName||r}),n!=null&&e.jsx("span",{className:"chat-time",children:Ls(n)})]}),m&&e.jsx("div",{className:"chat-markdown",children:N?e.jsx(Qn,{remarkPlugins:[er,wa,ja],children:w}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:w})}),b&&e.jsx("button",{onClick:f,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:d?"Collapse ↑":`Show more (${Math.round(m.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),oi=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:l={},emptyState:f,onLoadMore:u,isLoadingMore:x,hasMoreHistory:h,hiddenLiveCount:p=0,loadError:v},m){var H;const C=a.useRef(null),b=a.useRef(null),w=a.useRef(null),N=a.useRef(0),D=a.useRef(""),g=a.useRef(!1),j=a.useRef(null),y=a.useRef(!1),k=a.useRef(null),E=a.useRef(!1),[$,A]=a.useState(new Set),[U,L]=a.useState(new Set),T=a.useRef(!1),z=()=>{const J=C.current;return J?J.scrollHeight-J.scrollTop-J.clientHeight<200:!0},W=a.useCallback((J="auto")=>{const ee=C.current;ee&&ee.scrollTo({top:ee.scrollHeight,behavior:J})},[]),K=a.useCallback(()=>{var ue;const J=C.current,ee=(ue=window.getSelection)==null?void 0:ue.call(window);if(!J||!ee||ee.rangeCount===0||ee.isCollapsed){E.current=!1;return}const ge=ee.anchorNode,te=ee.focusNode;E.current=!!(ge&&te&&J.contains(ge)&&J.contains(te))},[]),M=a.useCallback((J="auto")=>{j.current!=null&&cancelAnimationFrame(j.current),j.current=requestAnimationFrame(()=>{j.current=null,W(J)})},[W]),P=s.length>0?`${s.length}:${(((H=s[s.length-1])==null?void 0:H.content)||"").length}`:"0:0";a.useEffect(()=>{const J=!g.current,ee=D.current!==d;if(D.current=d,J||ee){g.current=!0,T.current=!1,y.current=!0,E.current||M("auto"),N.current=s.length;return}s.length>N.current?!T.current&&!E.current&&M("auto"):z()&&!T.current&&!E.current&&M("auto"),N.current=s.length},[P,d,c,s.length,M]),a.useEffect(()=>()=>{j.current!=null&&cancelAnimationFrame(j.current),k.current!=null&&window.clearTimeout(k.current)},[]),a.useEffect(()=>{const J=b.current;if(!J)return;const ee=()=>{k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{y.current=!1,k.current=null},180)},ge=new ResizeObserver(()=>{y.current&&(E.current||(M("auto"),ee()))});return ge.observe(J),()=>{ge.disconnect(),k.current!=null&&(window.clearTimeout(k.current),k.current=null)}},[M,d]),a.useImperativeHandle(m,()=>({scrollToBottom:(J="smooth")=>{W(J)}}),[W]),a.useEffect(()=>{const J=C.current;if(!J)return;let ee;const ge=()=>{clearTimeout(ee),ee=setTimeout(()=>{T.current=!z()},50)};return J.addEventListener("scroll",ge,{passive:!0}),()=>{J.removeEventListener("scroll",ge),clearTimeout(ee)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",K),()=>document.removeEventListener("selectionchange",K)),[K]);const _=a.useRef(0),R=a.useRef(!1);a.useEffect(()=>{const J=C.current;if(!J||!R.current||_.current===0)return;const ee=J.scrollHeight-_.current;ee>0&&(J.scrollTop=ee),_.current=0,R.current=!1},[s.length]);const F=()=>{const J=C.current;J&&(_.current=J.scrollHeight),R.current=!0,u==null||u()},ce=a.useMemo(()=>{const J=s.map((ue,xe)=>({type:"message",data:ue,index:xe,ts:ue.receivedAt||l[wt(ue,xe)]||0}));if(!n||n.length===0)return J;const ee=[...n].sort((ue,xe)=>ue.timestamp-xe.timestamp).map((ue,xe)=>({type:"action",data:ue,index:xe,ts:ue.timestamp})),ge=[];let te=0;for(const ue of J){for(;te<ee.length&&ue.ts>0&&ee[te].ts<ue.ts;)ge.push(ee[te++]);ge.push(ue)}for(;te<ee.length;)ge.push(ee[te++]);return ge},[s,n,l]),de=p>0||!!h,he=p>0?`↑ Show ${Math.min(p,80)} earlier messages${p>80?` (${p} hidden)`:""}`:v?`↻ ${v}`:"↑ Load older messages";return e.jsx("div",{ref:C,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:b,className:"chat-container-content",children:[x&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),de&&!x&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:F,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${v&&p===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:he})}),ce.length===0&&!de&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),ce.map(J=>{if(J.type==="action"){const se=J.data;return e.jsx(ai,{log:se},`action-${J.index}`)}const ee=J.data,ge=J.index,te=wt(ee,ge),ue=ee.receivedAt||l[te],xe=`${d}-${te}`,X=$.has(xe),me=U.has(xe);return e.jsx(ii,{message:ee,receivedAt:ue,agentName:r,userName:i,isCliMode:o,isExpanded:X,isTextExpanded:me,onToggleExpanded:()=>A(se=>{const pe=new Set(se);return X?pe.delete(xe):pe.add(xe),pe}),onToggleTextExpanded:()=>L(se=>{const pe=new Set(se);return me?pe.delete(xe):pe.add(xe),pe})},`msg-${te}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:w})]})})}),ci=a.memo(oi,(t,s)=>t.messages===s.messages&&t.actionLogs===s.actionLogs&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isWorking===s.isWorking&&t.contextKey===s.contextKey&&t.receivedAtMap===s.receivedAtMap&&t.emptyState===s.emptyState&&t.onLoadMore===s.onLoadMore&&t.isLoadingMore===s.isLoadingMore&&t.hasMoreHistory===s.hasMoreHistory&&t.hiddenLiveCount===s.hiddenLiveCount&&t.loadError===s.loadError);let hn=!1;const pr=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,d]=a.useState(null),l=a.useRef([]),f=a.useRef(!1),u=a.useRef(!1),x=a.useRef(!1),h=()=>{const p=o.current;if(p){f.current&&(p.clear(),f.current=!1);for(const v of l.current)p.write(v);l.current=[],u.current&&(p.fit(),u.current=!1),x.current&&(p.bumpResize(),x.current=!1)}};return a.useImperativeHandle(i,()=>({write:p=>{o.current?o.current.write(p):l.current.push(p)},clear:()=>{o.current?o.current.clear():(l.current=[],f.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(l.current=[],f.current=!0)},resize:(p,v)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(p,v)},fit:()=>{o.current?o.current.fit():u.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():x.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const p=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(p)},[c]),a.useEffect(()=>{let p=!1;return $a(()=>import("./terminal-CKqklWLC.js").then(v=>v.i),__vite__mapDeps([0,1,2])).then(v=>{hn||(hn=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),p||d(()=>v.GhosttyTerminalView)}).catch(v=>{console.error("[CliTerminal] failed to load terminal renderer",v)}),()=>{p=!0}},[]),c?e.jsx(c,{ref:o,onInput:t,onResize:s,fontSize:n,readOnly:r,className:"w-full h-full rounded-lg overflow-hidden"}):e.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});pr.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 bn({value:t,max:s,label:n,color:r="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,d=c>85?"#ef4444":c>60?"var(--status-warning)":r;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:d}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function li({cursorPos:t,viewportRef:s,imgRef:n}){var w;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(w=s.current)==null?void 0:w.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,d=r.naturalHeight||i.height,l=c/d,f=i.width/i.height;let u,x,h,p;l>f?(u=i.width,x=i.width/l,h=0,p=(i.height-x)/2):(x=i.height,u=i.height*l,h=(i.width-u)/2,p=0);const v=i.left-o.left+h+u*t.nx,m=i.top-o.top+p+x*t.ny,C=Math.max(8,Math.min(o.width-8,v)),b=Math.max(8,Math.min(o.height-8,m));return e.jsxs("div",{style:{position:"absolute",left:C-8,top:b-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function di({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:d,handleImeSubmit:l,isConnActive:f,zoom:u,isMobile:x,mobileFillZoom:h,onZoomOut:p,onZoomReset:v,onZoomIn:m,transportType:C,screenshotUsage:b,lastActionStatus:w}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:N=>N.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(N=>!N),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),n&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:c,autoFocus:!0,onTouchStart:N=>N.stopPropagation(),onChange:N=>d(N.target.value),onKeyDown:N=>{l(N)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{o(N=>!N),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:f?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:f?"#22c55e":"#eab308",boxShadow:f?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:f?"#22c55e":"#eab308"},children:f?"Connected":"WS"})]}),u>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*100),"%"]}),C==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),C==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),b&&b.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:b.budgetExhausted?"#ef4444":"#c4b5fd",background:b.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:b.budgetExhausted?"TURN blocked":`TURN ${b.dailyUsedMinutes}/${b.dailyBudgetMinutes}m`}),w&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:w})]})]}),i&&e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",u<=(x?h:1)+.01?x?"FILL":"FIT":`${Math.round(u*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),p()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),v()},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:x?"FILL":"FIT"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function ui({waitingLabel:t,waitingHint:s,transportType:n}){return e.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:t}),e.jsx("div",{className:"text-[11px] text-white/40",children:s}),n==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function pi(){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 gn(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 Bt(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!pi())return;r.current+=1;const i=n.current;if(!i){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,d])=>[c,gn(d)]))}),n.current=s;return}const o=Object.keys({...i,...s}).filter(c=>!Object.is(i[c],s[c]));o.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,gn(s[c])]))}),n.current=s})}function mi({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:d,panYRef:l,setPanX:f,setPanY:u,setZoom:x,lastWheelTimeRef:h,onAction:p,setLastActionStatus:v,spawnRippleFromNormalized:m,clampPan:C,isMobile:b,mobileFillZoom:w}){const[N,D]=a.useState(null),g=a.useRef(null),j=a.useRef(null),y=a.useRef(null),k=a.useRef(!1),E=a.useRef(null),$=a.useRef(0),A=a.useRef(null),U=a.useRef(1),L=a.useRef({x:0,y:0}),T=a.useRef(!1),z=a.useRef(r),W=a.useRef(p),K=30,M=550,P=18,_=60,R=400,F=12,ce=()=>{if(g.current)return;const H={nx:.5,ny:.5};g.current=H,D(H)};return a.useEffect(()=>{z.current=r,r==="mouse"&&ce()},[r]),a.useEffect(()=>{W.current=p},[p]),a.useEffect(()=>{const H=t.current;if(!H)return;const J=X=>{if(!n.current)return null;const me=n.current.getBoundingClientRect();return!me.width||!me.height?null:{nx:Math.max(0,Math.min(1,(X.clientX-me.left)/me.width)),ny:Math.max(0,Math.min(1,(X.clientY-me.top)/me.height))}},ee=(X,me)=>{if(!n.current)return{dnx:0,dny:0};const se=n.current,pe=se.getBoundingClientRect(),Y=se.naturalWidth||pe.width,ie=se.naturalHeight||pe.height,S=Y/ie,Z=pe.width/pe.height;let Q,re;return S>Z?(Q=pe.width,re=pe.width/S):(re=pe.height,Q=pe.height*S),{dnx:X/Q,dny:me/re}},ge=(X,me,se)=>{if(se<=1.05)return;const pe=-(X-.5)*100,Y=-(me-.5)*100,ie=C(pe,Y,se);(Math.abs(ie.x-d.current)>.1||Math.abs(ie.y-l.current)>.1)&&(f(ie.x),u(ie.y),d.current=ie.x,l.current=ie.y)},te=X=>{const me=s.current;if(me&&X.target instanceof Node&&me.contains(X.target))X.preventDefault();else return;if(X.touches.length===1){const se=X.touches[0];j.current={x:se.clientX,y:se.clientY,time:Date.now()},y.current={x:se.clientX,y:se.clientY},T.current||(k.current=!1),E.current=setTimeout(()=>{if(!k.current&&!T.current)if(k.current=!0,z.current==="mouse"){const pe=g.current||{nx:.5,ny:.5};v("Right Click"),m(pe.nx,pe.ny,"right"),W.current("input_click",{...pe,button:"right"}).catch(()=>{})}else{const pe=J(se);pe&&(v("Right Click"),m(pe.nx,pe.ny,"right"),W.current("input_click",{...pe,button:"right"}).catch(()=>{}))}},500);return}if(X.touches.length===2){E.current&&clearTimeout(E.current),k.current=!0,T.current=!0;const se=X.touches[1].clientX-X.touches[0].clientX,pe=X.touches[1].clientY-X.touches[0].clientY;A.current=Math.sqrt(se*se+pe*pe),U.current=c.current,L.current={x:(X.touches[0].clientX+X.touches[1].clientX)/2,y:(X.touches[0].clientY+X.touches[1].clientY)/2}}},ue=X=>{const me=s.current;if(me&&X.target instanceof Node&&me.contains(X.target)&&X.preventDefault(),X.touches.length===1&&y.current){const se=X.touches[0],pe=se.clientX-y.current.x,Y=se.clientY-y.current.y;if(!k.current&&j.current){const ie=se.clientX-j.current.x,S=se.clientY-j.current.y;Math.sqrt(ie*ie+S*S)>8&&(k.current=!0,E.current&&clearTimeout(E.current))}if(k.current)if(z.current==="mouse"){const ie=ee(pe,Y),S=g.current||{nx:.5,ny:.5},Z=Math.max(0,Math.min(1,S.nx+ie.dnx)),Q=Math.max(0,Math.min(1,S.ny+ie.dny));g.current={nx:Z,ny:Q},D({nx:Z,ny:Q}),v(`Cursor: ${Math.round(Z*100)}%, ${Math.round(Q*100)}%`),ge(Z,Q,c.current);const re=Date.now();re-h.current>=30&&(h.current=re,W.current("input_mouseMoved",{nx:Z,ny:Q}).catch(()=>{}))}else if(c.current>1){const ie=s.current;if(ie){const S=ie.clientWidth,Z=ie.clientHeight,Q=d.current+pe/S*100,re=l.current+Y/Z*100,fe=C(Q,re,c.current);f(fe.x),u(fe.y),d.current=fe.x,l.current=fe.y}}else{const ie=J(se);if(ie){const S=Date.now();S-h.current>=40&&(h.current=S,v("Scroll"),W.current("input_wheel",{nx:ie.nx,ny:ie.ny,deltaX:Math.round(-pe*2.5),deltaY:Math.round(-Y*2.5)}).catch(()=>{}))}}y.current={x:se.clientX,y:se.clientY};return}if(X.touches.length===2&&A.current!==null){const se=X.touches[1].clientX-X.touches[0].clientX,pe=X.touches[1].clientY-X.touches[0].clientY,ie=Math.sqrt(se*se+pe*pe)/A.current,S=(X.touches[0].clientX+X.touches[1].clientX)/2,Z=(X.touches[0].clientY+X.touches[1].clientY)/2,Q=S-L.current.x,re=Z-L.current.y,fe=Math.abs(ie-1)>.03;if(z.current==="mouse"){if(fe){const ye=Math.max(o,Math.min(5,U.current*ie));x(ye),c.current=ye}else if(Math.abs(Q)>2||Math.abs(re)>2){const ye=g.current||{nx:.5,ny:.5},Ce=Date.now();Ce-h.current>=30&&(h.current=Ce,v("Scroll"),W.current("input_wheel",{nx:ye.nx,ny:ye.ny,deltaX:Math.round(-Q*3),deltaY:Math.round(-re*3)}).catch(()=>{}))}}else{const ye=Math.max(o,Math.min(5,U.current*ie));x(ye),c.current=ye;const Ce=s.current;if(Ce&&ye>1){const Me=Ce.clientWidth,Xe=Ce.clientHeight,We=d.current+Q/Me*100,Ge=l.current+re/Xe*100,Ee=C(We,Ge,ye);f(Ee.x),u(Ee.y),d.current=Ee.x,l.current=Ee.y}}L.current={x:S,y:Z}}},xe=X=>{var me;if(E.current&&clearTimeout(E.current),A.current=null,X.touches.length===1&&T.current){const se=X.touches[0];j.current={x:se.clientX,y:se.clientY,time:Date.now()},y.current={x:se.clientX,y:se.clientY},k.current=!0;return}if(X.touches.length===0){if(T.current){T.current=!1,k.current=!1;return}if(X.changedTouches.length===1){const se=X.changedTouches[0],pe=Date.now(),Y=pe-(((me=j.current)==null?void 0:me.time)||0),ie=j.current?se.clientX-j.current.x:0,S=j.current?se.clientY-j.current.y:0,Z=Math.sqrt(ie*ie+S*S);if(z.current==="mouse"){if(Y<K||Y>M||Z>P){k.current=!1;return}const Q=g.current||J(se);Q&&(v(`Click: ${Math.round(Q.nx*100)}%, ${Math.round(Q.ny*100)}%`),m(Q.nx,Q.ny,"left"),W.current("input_click",{...Q}).catch(()=>{}))}else{if(k.current){k.current=!1;return}if(Y<_||Y>R||Z>F){k.current=!1;return}const Q=J(se);if(!Q)return;pe-$.current<300?(v("Double tap"),m(Q.nx,Q.ny,"double"),W.current("input_click",{...Q,clickCount:2}).catch(()=>{}),$.current=0):(v(`Tap: ${Math.round(Q.nx*100)}%, ${Math.round(Q.ny*100)}%`),m(Q.nx,Q.ny,"left"),W.current("input_click",{...Q}).catch(()=>{}),$.current=pe)}}k.current=!1}};return H.addEventListener("touchstart",te,{passive:!1}),H.addEventListener("touchmove",ue,{passive:!1}),H.addEventListener("touchend",xe,{passive:!1}),()=>{H.removeEventListener("touchstart",te),H.removeEventListener("touchmove",ue),H.removeEventListener("touchend",xe),E.current&&clearTimeout(E.current)}},[t,s,n,o,c,d,l,f,u,x,h,v,m,C]),{cursorPos:N,cursorPosRef:g,handleToggleInputMode:()=>{i(H=>{const J=H==="touch"?"mouse":"touch";return J==="mouse"&&ce(),J})},handleZoomReset:()=>{const H=b?w:1;x(H),c.current=H,f(0),u(0),d.current=0,l.current=0}}}function mr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),d=a.useRef(null),l=a.useRef(null),[f,u]=a.useState(null),[x,h]=a.useState(""),[,p]=a.useState(!1),[v,m]=a.useState([]),C=a.useRef(0),[b,w]=a.useState(!1),[N,D]=a.useState(!1),g=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[j,y]=a.useState(g?"mouse":"touch"),[k,E]=a.useState(1),$=a.useRef(!1),[A,U]=a.useState(1),[L,T]=a.useState(0),[z,W]=a.useState(0);Bt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:j,zoom:A,panX:L,panY:z,isMenuOpen:b,isImeOpen:N});const K=a.useRef(0),M=a.useRef(A),P=a.useRef(L),_=a.useRef(z);a.useEffect(()=>{M.current=A},[A]),a.useEffect(()=>{P.current=L},[L]),a.useEffect(()=>{_.current=z},[z]),a.useEffect(()=>{var Y;(Y=c.current)==null||Y.focus()},[]);const R=n==="connected",F=r,ce=R?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",de=R?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!g||$.current||!F)return;const Y=l.current,ie=d.current;if(!Y||!ie)return;const S=()=>{const Z=ie.clientWidth,Q=ie.clientHeight,re=Y.naturalWidth,fe=Y.naturalHeight;if(!re||!fe||!Z||!Q)return;const ye=Math.min(Z/re,Q/fe),Me=Math.max(Z/re,Q/fe)/ye;Me>1.01&&(E(Me),U(Me),M.current=Me),$.current=!0};Y.complete&&Y.naturalWidth?S():Y.addEventListener("load",S,{once:!0})},[F,g]);const he=.5;a.useEffect(()=>{A<=he&&(T(0),W(0))},[A,he]);const H=(Y,ie,S)=>{if(S<=he)return{x:0,y:0};const Z=(S-1)/(2*S)*100,Q=(S-1)/(2*S)*100;return{x:Math.max(-Z,Math.min(Z,Y)),y:Math.max(-Q,Math.min(Q,ie))}},J=(Y,ie)=>{if(!l.current)return null;const S=l.current.getBoundingClientRect();return!S.width||!S.height?null:{nx:Math.max(0,Math.min(1,(Y-S.left)/S.width)),ny:Math.max(0,Math.min(1,(ie-S.top)/S.height))}},ee=(Y,ie,S)=>{const Z=d.current;if(!Z)return;const Q=Z.getBoundingClientRect(),re=++C.current;m(fe=>[...fe,{id:re,x:Y-Q.left,y:ie-Q.top,type:S}]),setTimeout(()=>m(fe=>fe.filter(ye=>ye.id!==re)),600)},ge=(Y,ie,S)=>{const Z=l.current,Q=d.current;if(!Z||!Q)return;const re=Z.getBoundingClientRect(),fe=Q.getBoundingClientRect(),ye=Z.naturalWidth||re.width,Ce=Z.naturalHeight||re.height,Me=ye/Ce,Xe=re.width/re.height;let We,Ge,Ee,De;Me>Xe?(We=re.width,Ge=re.width/Me,Ee=0,De=(re.height-Ge)/2):(Ge=re.height,We=re.height*Me,Ee=(re.width-We)/2,De=0);const Oe=re.left-fe.left+Ee+We*Y,Ze=re.top-fe.top+De+Ge*ie,oe=++C.current;m(je=>[...je,{id:oe,x:Oe,y:Ze,type:S}]),setTimeout(()=>m(je=>je.filter(ve=>ve.id!==oe)),600)},te=async Y=>{var S;const ie=J(Y.clientX,Y.clientY);if(ie){u(`Click: ${Math.round(ie.nx*100)}%, ${Math.round(ie.ny*100)}%`),ee(Y.clientX,Y.clientY,"left"),(S=c.current)==null||S.focus();try{const Z=await t("input_click",{nx:ie.nx,ny:ie.ny});Z!=null&&Z.success||s(`❌ Click failed: ${Z==null?void 0:Z.error}`)}catch(Z){s(`❌ Click error: ${Z.message||Z}`)}}},ue=async(Y,ie,S,Z=0)=>{try{await t("input_key",{type:S?"char":"keyDown",key:Y,code:ie,text:S?Y:void 0,unmodifiedText:S?Y:void 0,modifiers:Z})}catch(Q){s(`❌ Key error: ${Q.message||Q}`)}},xe=async Y=>{if(Y.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Y.key)&&Y.preventDefault();let S=0;Y.altKey&&(S|=1),Y.ctrlKey&&(S|=2),Y.metaKey&&(S|=4),Y.shiftKey&&(S|=8),u(`Key: ${Y.key}`),await ue(Y.key,Y.code,Y.key.length===1,S)},X=async Y=>{if(Y.key==="Enter"){if(Y.nativeEvent.isComposing)return;if(x){const ie=x;h(""),u(`IME Sent: ${ie}`);try{const S=await t("input_type",{text:ie});S!=null&&S.success||s(`❌ IME error: ${S==null?void 0:S.error}`)}catch(S){s(`❌ IME error: ${S.message}`)}}else u("Key: Enter"),await ue("Enter","Enter",!1)}};a.useEffect(()=>{const Y=c.current;if(!Y)return;const ie=S=>{var Z;if((Z=l.current)!=null&&Z.contains(S.target)){S.preventDefault();const Q=Date.now();if(Q-K.current<40)return;K.current=Q;const re=J(S.clientX,S.clientY);if(!re)return;u(`Scroll: ${Math.round(S.deltaY)}`),t("input_wheel",{nx:re.nx,ny:re.ny,deltaX:Math.round(S.deltaX),deltaY:Math.round(S.deltaY)}).catch(()=>{})}};return Y.addEventListener("wheel",ie,{passive:!1}),()=>Y.removeEventListener("wheel",ie)},[t]);const{cursorPos:me,handleToggleInputMode:se,handleZoomReset:pe}=mi({containerRef:c,viewportRef:d,imgRef:l,inputMode:j,setInputMode:y,minZoom:he,zoomRef:M,panXRef:P,panYRef:_,setPanX:T,setPanY:W,setZoom:U,lastWheelTimeRef:K,onAction:t,setLastActionStatus:u,spawnRippleFromNormalized:ge,clampPan:H,isMobile:g,mobileFillZoom:k});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:xe,onContextMenu:Y=>Y.preventDefault(),onFocus:()=>p(!0),onBlur:()=>p(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[F?e.jsx("img",{ref:l,src:F,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${A}) translate(${L}%, ${z}%)`,transformOrigin:"center center",cursor:j==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:te,onContextMenu:Y=>Y.preventDefault(),onDragStart:Y=>Y.preventDefault()}):e.jsx(ui,{waitingLabel:ce,waitingHint:de,transportType:o}),j==="mouse"&&F&&e.jsx(li,{cursorPos:me,viewportRef:d,imgRef:l}),v.map(Y=>{const S={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Y.type];return e.jsxs("div",{style:{position:"absolute",left:Y.x,top:Y.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${S}, 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(${S}, 0.9)`,boxShadow:`0 0 12px rgba(${S}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Y.id)})]}),e.jsx(di,{inputMode:j,onToggleInputMode:se,isImeOpen:N,setIsImeOpen:D,isMenuOpen:b,setIsMenuOpen:w,imeText:x,setImeText:h,handleImeSubmit:X,isConnActive:R,zoom:A,isMobile:g,mobileFillZoom:k,onZoomOut:()=>U(Y=>Math.max(.5,Y-.25)),onZoomReset:pe,onZoomIn:()=>U(Y=>Math.min(5,Y+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),e.jsx("style",{children:`
12
- @keyframes slideUp {
13
- from { opacity: 0; transform: translateY(6px); }
14
- to { opacity: 1; transform: translateY(0); }
15
- }
16
- @keyframes slideUpSidebar {
17
- from { opacity: 0; transform: translateY(6px); }
18
- to { opacity: 1; transform: translateY(0); }
19
- }
20
- @keyframes click-ripple-ring {
21
- 0% { transform: scale(0.3); opacity: 1; }
22
- 100% { transform: scale(2.2); opacity: 0; }
23
- }
24
- @keyframes click-ripple-dot {
25
- 0% { transform: scale(1); opacity: 0.9; }
26
- 50% { transform: scale(1.8); opacity: 0.6; }
27
- 100% { transform: scale(0.5); opacity: 0; }
28
- }
29
- @keyframes remote-float {
30
- 0% { transform: translateY(0px); }
31
- 50% { transform: translateY(-7px); }
32
- 100% { transform: translateY(0px); }
33
- }
34
- `})]})}function xi(t,s={}){if(!t)return"";const{suffix:n="",nowLabel:r="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return r;const d=Math.floor(c/60);if(d<60)return`${d}m${n}`;const l=Math.floor(d/60);if(l<24)return`${l}h${n}`;const f=Math.floor(l/24);return f<7?`${f}d${n}`:new Date(t).toLocaleDateString()}const xr=t=>xi(t);function fi(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ms(t){const s=t.connectionState==="failed"||t.connectionState==="closed",n=t.connectionState==="connecting"||t.connectionState==="new",r=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:n,isGenerating:r,isWaiting:i}}function Kt(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...fi(i)})};for(const r of t)if(!r.daemonMode){n(r.sessionId,r);for(const i of r.childSessions||[])n(i.id,i)}return s}function Et(t,s){if(t.sessionId){const n=s.get(t.sessionId);if(n)return n}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function Dt(t,s,n){const r=Et(t,s),i=ms(t),o=i.isReconnecting,c=i.isConnecting,d=i.isGenerating,l=i.isWaiting,f=r.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||l,u=r.inboxBucket==="working"||d,x=r.inboxBucket==="task_complete"&&r.unread&&!(n!=null&&n.hideOpenTaskCompleteUnread&&(n!=null&&n.isOpenConversation));return{unread:x,requiresAction:f,isWorking:u,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":u?"working":x?"task_complete":"idle"}}function hi(t,s,n){return Dt(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function bi(t,s,n){return Et(t,n||new Map).surfaceHidden}function fr({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ms(t).isWaiting||!t.modalButtons)return null;const o=d=>{n||(r(d),s(d))},c=d=>d.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"text-white py-2.5 px-4 shrink-0 z-[5]",style:{background:"linear-gradient(135deg, var(--status-warning), color-mix(in srgb, var(--status-warning) 85%, #000))"},children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Vs,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((d,l)=>{const f=c(d).toLowerCase(),u=/^(run|approve|accept|yes|allow|always)/.test(f),x=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,p=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${u?"bg-white font-extrabold":x?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!h?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:u?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const yn=new Map,gi={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function yi({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=ut(),u=`${t}:${s||r}`,x=gi[r]||"#94a3b8",[h,p]=a.useState({}),v=a.useRef(0),m={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<v.current?h:{}};a.useEffect(()=>{c&&Date.now()>v.current&&p({})},[c]);const[C,b]=a.useState(yn.get(u)||{}),[w,N]=a.useState(null),[D,g]=a.useState(null),j=a.useCallback(async(L,T={})=>{const z={...T,...s&&{targetSessionId:s}};return await f(t,L,z)},[t,s,f]);if(!o||o.length===0)return null;const y=o.filter(L=>L.placement==="bar").sort((L,T)=>(L.order??50)-(T.order??50));if(y.length===0)return null;const k=async L=>{var z,W,K;if(w===L.id){N(null);return}if((((z=L.options)==null?void 0:z.map(M=>M.value))||C[L.id]||[]).length>0){N(L.id);return}if(L.dynamic&&L.listScript){g(L.id);try{const M=await j(L.listScript==="listModels"?"list_extension_models":L.listScript==="listModes"?"list_extension_modes":L.listScript,{agentType:r,ideType:n}),_=((M==null?void 0:M.models)||(M==null?void 0:M.modes)||((W=M==null?void 0:M.result)==null?void 0:W.models)||((K=M==null?void 0:M.result)==null?void 0:K.modes)||(M==null?void 0:M.options)||[]).map(R=>typeof R=="string"?R:(R==null?void 0:R.name)||(R==null?void 0:R.id)||(R==null?void 0:R.value)||String(R));b(R=>{const F={...R,[L.id]:_};return yn.set(u,F),F}),N(L.id)}catch{}finally{g(null)}}},E=async(L,T)=>{N(null),p(z=>({...z,[L.id]:T})),v.current=Date.now()+5e3;try{if(!L.setScript)return;const z=ws(L.setScript,r);await j(z,{agentType:r,ideType:n,model:L.id==="model"?T:void 0,mode:L.id==="mode"?T:void 0,value:T})}catch{}},$=async L=>{var P;const T=((P=L.options)==null?void 0:P.map(_=>_.value))||C[L.id]||[];if(T.length===0)return;const z=String(m[L.id]||""),K=(T.indexOf(z)+1)%T.length,M=T[K];if(typeof M=="string"){p(_=>({..._,[L.id]:M})),v.current=Date.now()+5e3;try{if(!L.setScript)return;const _=ws(L.setScript,r);await j(_,{agentType:r,ideType:n,value:M})}catch{}}},A=async L=>{const z=!m[L.id];p(W=>({...W,[L.id]:z})),v.current=Date.now()+5e3;try{if(!L.setScript)return;const W=ws(L.setScript,r);await j(W,{agentType:r,ideType:n,value:z})}catch{}},U=async L=>{if(L.invokeScript)try{await j("invoke_extension_script",{agentType:r,ideType:n,scriptName:L.invokeScript})}catch{}};return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-surface-primary font-[var(--font)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:x},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),y.map(L=>{var M;const T=String(m[L.id]||""),z=w===L.id,W=D===L.id,K=((M=L.options)==null?void 0:M.map(P=>P.value))||C[L.id]||[];switch(L.type){case"select":return e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:z?`${x}55`:"transparent",border:"1px solid",color:T?"var(--text-primary)":"var(--text-muted)"},onClick:()=>k(L),children:[L.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:L.icon}),W?"...":T||L.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),z&&K.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>N(null)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:L.label.toUpperCase()}),K.map(P=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:P===T?`${x}18`:"transparent",color:P===T?x:"var(--text-secondary)",fontWeight:P===T?600:400,borderLeft:P===T?`2px solid ${x}`:"2px solid transparent"},onMouseEnter:_=>{_.currentTarget.style.background=`${x}12`},onMouseLeave:_=>{_.currentTarget.style.background=P===T?`${x}18`:"transparent"},onClick:()=>E(L,P),children:P},P))]})]})]},L.id);case"cycle":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap",style:{border:"1px solid transparent",color:T?"var(--text-primary)":"var(--text-muted)"},onClick:()=>$(L),title:`Click to cycle: ${K.join(" → ")}`,children:[L.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:L.icon}),T||L.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},L.id);case"toggle":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all whitespace-nowrap",style:{border:"1px solid",borderColor:T?`${x}44`:"transparent",background:T?`${x}14`:"var(--surface-tertiary)",color:T?x:"var(--text-muted)"},onClick:()=>A(L),children:[L.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:L.icon}),L.label]},L.id);case"action":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>U(L),children:[L.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:L.icon}),L.label]},L.id);default:return null}})]})}function ws(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const vi=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,d]=a.useState("");a.useEffect(()=>{d("")},[s]);const l=()=>{const f=c.trim();!f||r||(d(""),i(f))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:f=>d(f.target.value),onPaste:f=>{const u=f.clipboardData.getData("text");u&&d(x=>x+u),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),l()}},onBlur:f=>{if(window.innerWidth<768){const u=f.relatedTarget;if((u==null?void 0:u.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:l,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.trim()&&!r?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var wi=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ji(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function qe(t,s){if(ji(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":wi.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 hr(t){return qe(t)==="generating"}function Te(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ki(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function vn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gs(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const i=r.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function Ni(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 Si(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function Ci(t){return Ni(t.trim().replace(/\.local$/i,""))}function Ii(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function br(t,s={}){var i,o;const n=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0&&!Si(c));if(n&&n!=="Unknown")return Ci(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function nt(t,s={}){return Ii(t)||br(t,s)}function rs(t){return t.transport==="pty"}function _t(t){return t.transport==="acp"}function wn(t,s){return Te(t)}function jn(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=Te(n||"").trim().toLowerCase();return r===i||r===o||r===c}function Mi(t){return qe(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function _i(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=qe(r.status);if(!o){s.set(i,{...r,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function js(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function Ti(t){var n,r;const s=(r=(n=t==null?void 0:t.messages)==null?void 0:n.at)==null?void 0:r.call(n,-1);return s&&(js(s.timestamp)||js(s.receivedAt)||js(s.createdAt))||0}function Ai(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function Rs(t){return Math.max(Ai(t),Ti(t.activeChat))}function Li(t,s,n,r,i,o){const c=s-t;if(c!==0)return c;const d=n.localeCompare(r);return d!==0?d:i.localeCompare(o)}function Ri(t,s){return Li(Rs(t),Rs(s),nt(t,{fallbackId:t.id}),nt(s,{fallbackId:s.id}),t.id,s.id)}function gr({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r,interactive:i=!0}){var v;const o=St(),c=t.daemonId||((v=t.ideId)==null?void 0:v.split(":")[0])||t.ideId,d=t.transport==="cdp-page"||t.transport==="cdp-webview",l=t.streamSource==="agent-stream"&&!!t.agentName,f=!l&&(t.transport==="pty"||t.transport==="acp"),u=t.agentName||Te(t.agentType||t.ideType||""),x=(()=>{var m,C;if(t.streamSource==="agent-stream"){const b=(C=(m=t.displaySecondary)==null?void 0:m.split("·")[0])==null?void 0:C.trim();if(b)return b}return Te(t.ideType||"")})(),h=a.useCallback(()=>{if(r){r();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,r]),p=a.useCallback(()=>{if(n){n();return}const m=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;m&&o(`/dashboard?activeTab=${encodeURIComponent(m)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[d&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:x,children:[e.jsx(Ve,{size:12}),e.jsx("span",{children:x})]}):e.jsxs("span",{className:"conversation-meta-chip",title:x,children:[e.jsx(Ve,{size:12}),e.jsx("span",{children:x})]})),l&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(bt,{size:12}),e.jsx("span",{children:t.agentName})]}),f&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:u,children:[e.jsx(bt,{size:12}),e.jsx("span",{children:u})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:h,title:t.machineName,children:[e.jsx(ss,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(ss,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Pe=t=>t.transport==="pty",Nt=(t,s)=>Pe(t)?s||t.mode||"terminal":"chat",yr=(t,s)=>Pe(t)&&Nt(t,s)==="terminal",Ae=t=>t.transport==="acp";function as(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
35
- `).replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}function $s(t){const s=Number((t==null?void 0:t.timestamp)||(t==null?void 0:t.receivedAt)||(t==null?void 0:t.createdAt)||0);return Number.isFinite(s)?s:0}function $i(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const n=String((t==null?void 0:t.role)||"").toLowerCase(),r=String((s==null?void 0:s.role)||"").toLowerCase();if(n!==r)return!1;const i=as(t==null?void 0:t.content),o=as(s==null?void 0:s.content);if(!i||i!==o)return!1;const c=$s(t),d=$s(s);return c&&d?Math.abs(c-d)<=15e3:!!(t!=null&&t._localId)!=!!(s!=null&&s._localId)}function kn(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),$s(t)&&(s+=1),s}function Pi(t,s){const n=kn(t),r=kn(s);return r!==n?r>n?s:t:as(s==null?void 0:s.content).length>=as(t==null?void 0:t.content).length?s:t}function Nn(t){const s=[];for(const n of t){const r=s.findIndex(i=>$i(i,n));if(r>=0){s.splice(r,1,Pi(s[r],n));continue}s.push(n)}return s}const Ei=60,Di=60;function Ps({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:d,showMetaChips:l=!1}){const f=a.useRef(new Map),{sendCommand:u}=ut();Bt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const x=Os.useMemo(()=>ms(t),[t.status,t.connectionState]),h=a.useRef(new Map),p=a.useCallback(T=>(h.current.has(T)||h.current.set(T,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Ei}),h.current.get(T)),[]),v=a.useCallback((T,z)=>{const W=p(T);h.current.set(T,{...W,...z}),m(K=>K+1)},[p]),[,m]=a.useState(0),C=t.tabKey,b=p(C),w=b.messages,N=b.hasMore,D=b.error,g=Math.max(0,t.messages.length-b.visibleLiveCount),[j,y]=a.useState(!1),k=a.useCallback(async()=>{var W,K;if(j)return;const T=t.tabKey,z=p(T);if(t.messages.length>z.visibleLiveCount){v(T,{visibleLiveCount:Math.min(t.messages.length,z.visibleLiveCount+Di),error:null});return}y(!0),v(T,{error:null});try{const M=(s==null?void 0:s.daemonId)||((W=t.ideId)==null?void 0:W.split(":")[0])||"";if(!M){v(T,{hasMore:!1});return}const P=t.ideType||t.agentType||"",_=await u(M,"chat_history",{agentType:P,offset:z.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),R=(_==null?void 0:_.result)??_;if(((K=R.messages)==null?void 0:K.length)>0){const F=p(T);v(T,{messages:[...R.messages,...F.messages],offset:F.offset+R.messages.length,hasMore:!!R.hasMore})}else v(T,{hasMore:!!R.hasMore})}catch(M){const P=(M==null?void 0:M.message)||"";P.includes("P2P not available")||P.includes("channel not open")||P.includes("P2P not connected")||P.includes("timeout")?v(T,{error:"Connection not ready — tap to retry"}):v(T,{hasMore:!1,error:"Failed to load history"})}finally{y(!1)}},[j,s,t,u,p,v]),{allMessages:E,receivedAtMap:$}=a.useMemo(()=>{const T=g>0?t.messages.slice(-b.visibleLiveCount):t.messages;if(w.length===0){const P=Nn(T),_={};return P.forEach((R,F)=>{const ce=`${t.tabKey}:${wt(R,F)}`;let de=R.receivedAt||f.current.get(ce)||0;de||(de=Date.now(),f.current.set(ce,de)),_[wt(R,F)]=de}),{allMessages:P,receivedAtMap:_}}const z=new Set(T.map(P=>`${P.role}:${(P.content||"").slice(0,100)}`)),W=w.filter(P=>!z.has(`${P.role}:${(P.content||"").slice(0,100)}`)),K=Nn([...W,...T]),M={};return K.forEach((P,_)=>{const R=`${t.tabKey}:${wt(P,_)}`;let F=P.receivedAt||f.current.get(R)||0;F||(F=Date.now(),f.current.set(R,F)),M[wt(P,_)]=F}),{allMessages:K,receivedAtMap:M}},[t.messages,t.tabKey,g,w,b.visibleLiveCount]),A=a.useMemo(()=>c.filter(T=>T.ideId===t.tabKey).sort((T,z)=>T.timestamp-z.timestamp),[c,t.tabKey]),U=t.displayPrimary||t.agentName||"Agent",L=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((x.isGenerating||t.status==="streaming")&&y(!1),t.status==="not_monitored")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(bt,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",U," 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(cr,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",U," 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"&&!j)return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]})}},[t.messages.length,t.connectionState,t.status,i,o,j,U,x.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(gr,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(ci,{messages:E,actionLogs:A,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Pe(t)||Ae(t),isWorking:x.isGenerating,contextKey:t.tabKey,receivedAtMap:$,onLoadMore:k,isLoadingMore:j,hasMoreHistory:N,hiddenLiveCount:g,loadError:D??void 0,emptyState:L}),!yr(t)&&(()=>{const T=t.streamSource!=="agent-stream",z=T?t.ideType:t.agentType,W=T?s!=null&&s.type?Te(s.type):Te(t.ideType||""):t.agentName||Te(t.agentType||""),K=!T&&(s!=null&&s.childSessions)&&s.childSessions.find(_=>_.id===t.sessionId||_.providerType===t.agentType)||s,M=K==null?void 0:K.providerControls,P=K==null?void 0:K.controlValues;return e.jsx(yi,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:z,displayLabel:W,controls:M,controlValues:P,serverModel:(K==null?void 0:K.currentModel)||void 0,serverMode:(K==null?void 0:K.currentPlan)||void 0,acpConfigOptions:Ae(t)?K==null?void 0:K.acpConfigOptions:void 0,acpModes:Ae(t)?K==null?void 0:K.acpModes:void 0})})(),e.jsx(vi,{contextKey:t.tabKey,panelLabel:U,isSending:r,onSend:n})]})}let vr=$t;function Ys(){return vr()}class Bi{constructor(){Ke(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let wr=new Bi;class Ki{sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let $e=new Ki;function Wi(t){t.dashboardWS&&(wr=t.dashboardWS),t.connectionManager&&($e=t.connectionManager),t.useDaemonsHook&&(vr=t.useDaemonsHook)}function Oi({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var K;const c=a.useRef(null),{sendCommand:d,sendData:l}=ut(),[f,u]=a.useState(""),[x,h]=a.useState(!1),[p,v]=a.useState(1),m=a.useRef(!1),C=a.useRef(0),b=a.useRef(!1),w=a.useRef(""),N=a.useRef(null),D=a.useRef(!1),g=a.useRef(null),j=t.tabKey,y=t.sessionId||"",k=t.daemonId||((K=t.ideId)==null?void 0:K.split(":")[0])||t.ideId||"",E=.6,$=1.15,A=()=>{if(typeof window>"u")return 1;const M=window.innerWidth||0;return M<=360?.68:M<=390?.74:M<=430?.82:M<=480?.9:1},U=()=>{var M,P;C.current=0,b.current=!1,w.current="",N.current=null,D.current=!1,g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),h(!1),(P=(M=n.current)==null?void 0:M.reset)==null||P.call(M)},L=()=>{var M,P;C.current=0,b.current=!1,w.current="",N.current=null,D.current=!1,g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),h(!0),(P=(M=n.current)==null?void 0:M.reset)==null||P.call(M)},T=()=>{var P;if(g.current=null,!o)return;const M=w.current;M&&(w.current="",(P=n.current)==null||P.write(M))},z=M=>{M&&(w.current+=M,o&&g.current===null&&(g.current=requestAnimationFrame(T)))},W=(M,P=0,_,R)=>{var F,ce,de,he,H;P>0&&C.current>=P||P===0&&b.current||(C.current=P,h(!0),typeof _=="number"&&typeof R=="number"&&_>0&&R>0&&((ce=(F=n.current)==null?void 0:F.resize)==null||ce.call(F,_,R)),(he=(de=n.current)==null?void 0:de.reset)==null||he.call(de),M&&((H=n.current)==null||H.write(M)))};return a.useEffect(()=>{U()},[y]),a.useEffect(()=>{var P;if(!y)return;const M=((P=$e.onRuntimeEvent)==null?void 0:P.call($e,y,_=>{if(!(!_||_.sessionId!==y)){if(_.type==="runtime_snapshot"){if(!o){N.current={text:_.text||"",seq:_.seq||0,cols:_.cols,rows:_.rows};return}W(_.text||"",_.seq||0,_.cols,_.rows);return}if(_.type==="session_output"){b.current=!0,typeof _.seq=="number"&&(C.current=Math.max(C.current,_.seq)),x||h(!0),typeof _.data=="string"&&z(_.data);return}if(_.type==="session_cleared"){if(!o){D.current=!0,w.current="",N.current=null;return}L()}}}))||(()=>{});return()=>{M()}},[k,y,n,o,x]),a.useEffect(()=>{var P,_,R;if(!y)return;k&&((P=$e.getState)==null?void 0:P.call($e,k))==="connected"&&(h(!0),(_=$e.requestRuntimeSnapshot)==null||_.call($e,k,y).catch(()=>{}));const M=(R=$e.onStateChange)==null?void 0:R.call($e,(F,ce)=>{var de;F!==k||ce!=="connected"||(h(!0),(de=$e.requestRuntimeSnapshot)==null||de.call($e,k,y).catch(()=>{}))});return()=>{M==null||M()}},[k,y,n]),a.useEffect(()=>{s&&U()},[s,j,n]),a.useEffect(()=>{u("")},[t.tabKey]),a.useEffect(()=>{const M=()=>{m.current||v(A())};return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),a.useEffect(()=>{var P;if(!o){(P=c.current)==null||P.blur();return}D.current&&(D.current=!1,L());const M=N.current;M&&(N.current=null,W(M.text,M.seq,M.cols,M.rows)),w.current&&g.current===null&&(g.current=requestAnimationFrame(T))},[o]),a.useEffect(()=>()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)},[]),a.useEffect(()=>{const M=P=>{var R;const _=P.detail;_!=null&&_.sessionId&&_.sessionId!==y||x&&((R=n.current)==null||R.fit())};return window.addEventListener("adhdev:fit-cli-terminal",M),()=>{window.removeEventListener("adhdev:fit-cli-terminal",M)}},[x,y,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[e.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{m.current=!0,v(M=>Math.max(E,Number((M-.1).toFixed(2))))},title:"Shrink terminal viewport",children:"-"}),e.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{m.current=!0,v(M=>Math.min($,Number((M+.1).toFixed(2))))},title:"Increase terminal viewport",children:"+"})]}),e.jsx("div",{className:"w-full h-full overflow-auto rounded-lg",children:e.jsx("div",{style:{width:`${100/p}%`,height:`${100/p}%`,transform:`scale(${p})`,transformOrigin:"top left"},children:e.jsx(pr,{ref:n,readOnly:!x||!o,onInput:M=>{x&&(l!=null&&l(k,{type:"pty_input",targetSessionId:y,data:M})||d(k,"pty_input",{targetSessionId:y,data:M}).catch(console.error))},onResize:(M,P)=>{x&&(l!=null&&l(k,{type:"pty_resize",targetSessionId:y,cols:M,rows:P})||d(k,"pty_resize",{targetSessionId:y,cols:M,rows:P,force:!0}).catch(()=>{}))}})})}),!x&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:f,disabled:!x||!o||i,onChange:M=>u(M.target.value),onPaste:M=>{const P=M.clipboardData.getData("text");P&&u(_=>_+P),M.preventDefault()},onKeyDown:M=>{if(M.key!=="Enter")return;if(M.nativeEvent.isComposing){M.preventDefault();return}M.preventDefault();const P=f.trim();!x||!P||i||(u(""),r(P))},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 M=f.trim();!x||!M||i||(u(""),r(M))},disabled:!x||!o||!f.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${f.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:f.trim()&&!i?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:f.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function zi({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"accent",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},d={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function Ui({terminalBackend:t,isStandalone:s=!1,machineLabel:n,machineKey:r}){const i=a.useMemo(()=>!r||!t?null:`adhdev:terminal-backend-banner:dismissed:${r}:${t.backend}`,[r,t]),[o,c]=a.useState(!1);if(a.useEffect(()=>{if(!i){c(!1);return}try{c(localStorage.getItem(i)==="1")}catch{c(!1)}},[i]),!s||!t||t.backend!=="xterm"||o)return null;const d=(n==null?void 0:n.trim())||"This machine",l=()=>{if(i)try{localStorage.setItem(i,"1")}catch{}c(!0)};return e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5",style:{background:"linear-gradient(90deg, rgba(245,158,11,0.12), rgba(245,158,11,0.04))",borderBottom:"1px solid rgba(245,158,11,0.2)",color:"#d97706"},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5 justify-center flex-wrap",children:[e.jsxs("span",{children:[d," is using `xterm` fallback."]}),e.jsx("span",{style:{opacity:.8},children:"ghostty-vt is unavailable on this machine, so terminal rendering may be less accurate."})]}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 text-[12px] font-semibold px-2 py-1 rounded-md transition-colors",style:{color:"#b45309",background:"rgba(245,158,11,0.1)",border:"1px solid rgba(245,158,11,0.18)"},"aria-label":"Dismiss terminal backend warning",title:"Dismiss",children:"Dismiss"})]})}function Xs({mode:t,onChange:s,compact:n=!1}){const r=n?14:15;return e.jsx("button",{type:"button",onClick:()=>s(t==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:t==="chat"?"Switch to Terminal view":"Switch to Chat view",children:t==="chat"?e.jsx(qs,{size:r}):e.jsx(it,{size:r})})}function Sn({conversation:t,isAttention:s,onClick:n}){return e.jsxs("button",{type:"button",className:`dashboard-header-inbox-item ${s?"is-attention":""}`.trim(),onClick:n,children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:t.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:t.displaySecondary})]})}function Hi({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:u,onHideConversation:x,hiddenConversations:h=[],onShowConversation:p,onShowAllHidden:v}){const m=Ys(),C=m.p2pStates||{},b=m.ides||[],w=!!t&&Pe(t)&&!Ae(t),N=l||(t?yr(t)?"terminal":"chat":null),[D,g]=a.useState(!1),[j,y]=a.useState(!1),[k,E]=a.useState(!1),$=a.useRef(null),A=a.useRef(null),U=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",L=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",T=b.filter(H=>H.type==="adhdev-daemon"),z=a.useMemo(()=>Kt(b),[b]),W=Object.values(C),K=W.filter(H=>H==="connected").length,M=W.filter(H=>H==="connecting"||H==="new"||H==="checking").length,_=n!=="connected"||T.length===0?null:M>0&&K===0?"P2P connecting...":K>0&&s===0?"Waiting for IDE...":null,R=a.useMemo(()=>i.filter(H=>!bi(H,i,z)),[i,z]),F=a.useMemo(()=>R.filter(H=>Dt(H,z).requiresAction),[R,z]),ce=a.useMemo(()=>R.filter(H=>{const J=(t==null?void 0:t.tabKey)===H.tabKey;return Dt(H,z,{hideOpenTaskCompleteUnread:!0,isOpenConversation:J}).unread}),[t,R,z]),de=F.length+ce.length;a.useEffect(()=>{if(!D)return;const H=J=>{var ee;(ee=$.current)!=null&&ee.contains(J.target)||g(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[D]),a.useEffect(()=>{if(!j)return;const H=J=>{var ee;(ee=A.current)!=null&&ee.contains(J.target)||y(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[j]);const he=H=>{if(!H)return;const J=i.find(ee=>ee.tabKey===H);J&&(x==null||x(J))};return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"header-title-block",children:e.jsxs("div",{className:"header-title-row",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(it,{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:U,boxShadow:L}})})]}),e.jsxs("div",{className:"header-subtitle",children:[e.jsxs("span",{className:"header-subtitle-copy",children:[s," agent",s!==1?"s":""," active"]}),e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:U,boxShadow:L}}),_&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",_]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(w||!Ae(t))&&e.jsxs("div",{className:"dashboard-header-actions-group",children:[e.jsx("span",{className:"dashboard-header-action-target",title:t.displaySecondary||t.displayPrimary,children:t.displayPrimary}),w&&d&&e.jsxs(e.Fragment,{children:[f&&N&&e.jsx(Xs,{mode:N,onChange:f,compact:!0}),e.jsx("button",{onClick:()=>d(t),className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(kt,{size:14})})]}),!Ae(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Hs,{size:14})}),!w&&!Ae(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Ve,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:$,children:[e.jsxs("div",{className:`dashboard-header-hidden${k?" is-drop-target":""}`,ref:A,onDragEnter:H=>{H.dataTransfer.types.includes("text/tab-key")&&(H.preventDefault(),E(!0))},onDragOver:H=>{H.dataTransfer.types.includes("text/tab-key")&&(H.preventDefault(),H.dataTransfer.dropEffect="move",E(!0))},onDragLeave:H=>{H.currentTarget.contains(H.relatedTarget)||E(!1)},onDrop:H=>{const J=H.dataTransfer.getData("text/tab-key");H.preventDefault(),E(!1),he(J)},children:[e.jsxs("button",{type:"button",onClick:()=>y(H=>!H),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Ga,{size:16}),h.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:h.length})]}),j&&e.jsxs("div",{className:"dashboard-header-hidden-popover",children:[e.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),h.length>0&&v&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{v(),y(!1)},children:"Restore all"})]}),t&&x&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>x(t),children:[e.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),e.jsx("span",{className:"dashboard-header-hidden-current-title",children:t.displayPrimary})]}),h.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:h.map(H=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{p==null||p(H),y(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:H.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:H.displaySecondary})]},H.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>g(H=>!H),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(ps,{size:16}),de>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:de})]}),D&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[F.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),F.map(H=>e.jsx(Sn,{conversation:H,isAttention:!0,onClick:()=>{u==null||u(H),g(!1)}},H.tabKey))]}),ce.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),ce.map(H=>e.jsx(Sn,{conversation:H,onClick:()=>{u==null||u(H),g(!1)}},H.tabKey))]}),de===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Fi(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(t))}catch{return new Date(t).toLocaleString()}}function Vi({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:u,onResumeSavedSession:x}){var C;const h=s.find(b=>b.id===t.ideId),p=(h==null?void 0:h.chats)||[],v=(C=h==null?void 0:h.activeChat)==null?void 0:C.id,m=Pe(t)&&!Ae(t);return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:d,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:m?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Te(t.ideType)]})]}),e.jsx("button",{onClick:d,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[!m&&e.jsx("button",{onClick:l,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),m?e.jsx(e.Fragment,{children:i.map(b=>{const w=t.providerSessionId===b.providerSessionId,N=w||!b.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{N||!x||x(b)},disabled:N,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${w?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${N?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:`font-bold text-sm mb-1 truncate ${w?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:b.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:Fi(b.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:b.preview||"No saved preview yet"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[e.jsxs("div",{className:"truncate",children:[b.workspace||"Workspace unknown",b.currentModel?` · ${b.currentModel}`:"",b.messageCount>0?` · ${b.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:w?"ACTIVE":b.canResume?c===b.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},b.id)})}):p.map(b=>e.jsxs("div",{onClick:()=>{f(t.ideId,b.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${v===b.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${v===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[b.id.substring(0,12),"..."]}),v===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),(m&&!o&&i.length===0||!m&&p.length===0)&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(Ja,{size:32})}),e.jsx("div",{className:"text-[13px]",children:m?"No saved sessions found yet.":"No recent chat sessions found."})]}),m&&o&&e.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:e.jsx("div",{className:"text-[13px]",children:"Refreshing saved sessions…"})})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,disabled:r||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:r||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fs,{size:13})," ",m?"Refresh Sessions":"Refresh History"]})})})]})]})}const Cn={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Done"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Attention"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Update"}};function jr({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=>{const i=Cn[r.type]||Cn.info;return e.jsxs("div",{className:"fade-in pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[380px] relative group overflow-hidden rounded-[16px] border shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:"color-mix(in srgb, var(--surface-primary) 94%, var(--bg-secondary) 6%)",borderColor:"color-mix(in srgb, var(--border-default) 88%, transparent)",color:"var(--text-primary)"},onClick:()=>{var o;(o=r.actions)!=null&&o.length||(n&&n(r),s(r.id))},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${i.accent}, color-mix(in srgb, ${i.accent} 55%, transparent))`}}),e.jsx("button",{className:"absolute top-2 right-2 w-7 h-7 rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-glass transition-colors text-[13px] leading-none cursor-pointer",onClick:o=>{o.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsxs("div",{className:"px-4 py-3.5 pl-5",children:[e.jsx("div",{className:"flex items-center gap-2 pr-8",children:e.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-[0.08em]",style:{background:i.chipBg,color:i.chipText,border:`1px solid color-mix(in srgb, ${i.accent} 22%, transparent)`},children:i.label})}),e.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-3",children:r.actions.map((o,c)=>e.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${o.variant==="primary"||o.variant==="danger",""}`,style:o.variant==="primary"?{background:"color-mix(in srgb, var(--accent-primary) 12%, var(--surface-primary))",color:"var(--text-primary)",borderColor:"color-mix(in srgb, var(--accent-primary) 26%, transparent)"}:o.variant==="danger"?{background:"color-mix(in srgb, var(--status-error) 10%, var(--surface-primary))",color:"var(--status-error)",borderColor:"color-mix(in srgb, var(--status-error) 22%, transparent)"}:{background:"var(--surface-secondary)",color:"var(--text-secondary)",borderColor:"var(--border-subtle)"},onClick:d=>{d.stopPropagation(),o.onClick(),s(r.id)},children:o.label},c))})]})]},r.id)})})}function Zs(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(" ").replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}const qi=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Gi(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Yi(t){return t.sessionId||t.instanceId||t.agentType}function ks(t,s){return t||s}function In(t){return Zs(t)}function Mn(t){const s=Number((t==null?void 0:t.timestamp)||(t==null?void 0:t.receivedAt)||(t==null?void 0:t.createdAt)||0);return Number.isFinite(s)?s:0}function _n(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const n=String(t.role||"").toLowerCase(),r=String(s.role||"").toLowerCase();if(n!==r)return!1;const i=In(t.content),o=In(s.content);if(!i||i!==o)return!1;const c=Mn(t),d=Mn(s);return c&&d?Math.abs(c-d)<=15e3:!!t._localId!=!!s._localId}function Tn(t,s){const n=new Set,r=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;n.has(c)||(n.add(c),r.push(o))}return r.sort((i,o)=>i.timestamp-o.timestamp)}function kr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=nt(r,{fallbackId:r.id}))}return s}function Nr(t,s,n={}){var h,p,v,m,C,b;const r=[],i=n.machineName,o=n.connectionState,c=Gi(t),d=Te(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(w=>{var N,D;return{sessionId:w.id,instanceId:w.id,providerSessionId:w.providerSessionId,agentType:w.providerType,agentName:w.providerName,status:w.status,title:w.title,messages:((N=w.activeChat)==null?void 0:N.messages)||[],activeModal:((D=w.activeChat)==null?void 0:D.activeModal)||void 0,unread:w.unread,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,inboxBucket:w.inboxBucket,surfaceHidden:w.surfaceHidden}}):[],f=qi(t),u=t.activeChat||{title:""},x=u.title&&String(u.title).trim()?String(u.title).trim():"";if(f){const w=t.sessionId||t.instanceId,N=wn(t.type),D=(h=t.activeChat)==null?void 0:h.activeModal,g=D&&Array.isArray(D.buttons)&&D.buttons.length>0,j=qe((p=t.activeChat)==null?void 0:p.status,{activeModal:(v=t.activeChat)==null?void 0:v.activeModal})||qe((C=(m=t.agents)==null?void 0:m[0])==null?void 0:C.status)||"idle",y=t.activeChat||{title:"",messages:[]};let k=y.title&&String(y.title).trim()?String(y.title).trim():"";const E=(b=t.activeChat)==null?void 0:b.id,$=t.chats;if(E&&Array.isArray($)&&$.length>0){const K=$.find(M=>M.id===E||M.id&&String(M.id)===String(E));K!=null&&K.title&&String(K.title).trim()&&(k=String(K.title).trim())}const A=(Pe(t)||Ae(t))&&(t.cliType||t.acpType)||t.type,U=(Pe(t)||Ae(t))&&jn(k,N,A)?"":k,L=y.messages||[],T=Tn(s,[t.id,w]),z=L.filter(K=>String((K==null?void 0:K.role)||"").toLowerCase()==="user").slice(),W=T.filter(K=>{const M=z.findIndex(P=>_n(P,K));return M>=0?(z.splice(M,1),!1):!0});r.push({ideId:t.id,sessionId:w,providerSessionId:t.providerSessionId,nativeSessionId:w,transport:t.transport,daemonId:t.daemonId||void 0,mode:Pe(t)?t.mode||"terminal":"chat",agentName:N,agentType:A,status:j,title:U,messages:[...L,...W],resume:t.resume,ideType:A,workspaceName:c,displayPrimary:c||U||(Pe(t)?t.mode==="chat"?N:"Terminal":N),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:g?D.buttons:void 0,modalMessage:g?D.message:void 0,streamSource:"native",tabKey:ks(w,t.id),machineName:i,connectionState:o})}if(f&&(Pe(t)||Ae(t)))return r;for(const w of l){const N=w.activeModal&&Array.isArray(w.activeModal.buttons)&&w.activeModal.buttons.length>0,D=Mi(w),g=Yi(w),j=`${t.id}:${g}`,y=w.title&&String(w.title).trim()||"",k=jn(y,w.agentName,w.agentType)?"":y,E=w.messages||[],$=Tn(s,[j,w.sessionId,w.instanceId]),A=E.filter(T=>String((T==null?void 0:T.role)||"").toLowerCase()==="user").slice(),U=$.filter(T=>{const z=A.findIndex(W=>_n(W,T));return z>=0?(A.splice(z,1),!1):!0});(E.length>0||U.length>0||N||k||!["idle","panel_hidden","disconnected","not_monitored"].includes(D))&&r.push({ideId:t.id,sessionId:w.sessionId||w.instanceId,providerSessionId:w.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:w.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:w.agentName,agentType:w.agentType,status:D,title:k,messages:[...E,...U],ideType:w.agentType,workspaceName:c,displayPrimary:k||x||c||d,displaySecondary:`${d}·${w.agentName}`,cdpConnected:t.cdpConnected,modalButtons:N?w.activeModal.buttons:void 0,modalMessage:N?w.activeModal.message:void 0,streamSource:"agent-stream",tabKey:ks(w.sessionId||w.instanceId,j),machineName:i,connectionState:o})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,providerSessionId:t.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:wn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||d,displaySecondary:d,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:ks(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Xi(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const i=n.get(r.parentId)||[];i.push(r),n.set(r.parentId,i)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Zi(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Xi(d),u=l.filter(p=>p.kind==="workspace"&&p.transport==="cdp-page"),x=l.filter(p=>p.kind==="agent"&&p.transport==="pty"),h=l.filter(p=>p.kind==="agent"&&p.transport==="acp");n.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:u.some(p=>!!p.cdpConnected)});for(const p of u){const v=f.get(p.id)||[];n.push({id:`${r}:ide:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,status:p.cdpConnected?"online":"detected",daemonId:r,instanceId:p.id,workspace:p.workspace,terminals:0,childSessions:v,agents:v.map(m=>({id:m.id,name:m.providerName,type:m.providerType,status:m.status})),activeChat:p.activeChat,chats:[],cdpConnected:p.cdpConnected,currentModel:p.currentModel,currentPlan:p.currentPlan,currentAutoApprove:p.currentAutoApprove,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c})}for(const p of x)n.push({id:`${r}:cli:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:p.mode||"terminal",workspace:p.workspace||"",activeChat:p.activeChat,resume:p.resume,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isCli:!0});for(const p of h)n.push({id:`${r}:acp:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:"chat",workspace:p.workspace||"",activeChat:p.activeChat,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],currentModel:p.currentModel,currentPlan:p.currentPlan,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,acpConfigOptions:p.acpConfigOptions,acpModes:p.acpModes,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isAcp:!0});return n}function Ji(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 Qi(t,s){const n=Ji(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Sr=[{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:"💚"}],Cr=[{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:"🧩"}],Ir=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Mr="adhdev_notification_prefs",An={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function eo(){try{const t=localStorage.getItem(Mr);if(t){const s=JSON.parse(t);return{...An,...s}}}catch{}return{...An}}function to(t){try{localStorage.setItem(Mr,JSON.stringify(t))}catch{}}let st=eo(),Zt=[];function so(){Zt.forEach(t=>t())}function no(){return{...st}}function ro(t){st={...st,...t},to(st),so()}function ao(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Zt.push(n),()=>{Zt=Zt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{ro(n)},[]);return[{...st},s]}function Tt(t){if(!st.globalEnabled)return!1;switch(t){case"disconnect":return st.disconnectAlert;case"completion":return st.completionAlert;case"approval":return st.approvalAlert;case"browser":return st.browserNotifications;default:return!0}}const io={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function oo(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function _r(){return"Notification"in window&&Notification.permission==="granted"}let pt=null;async function co(){if(pt!==null)return pt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return pt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(pt=!!await t.pushManager.getSubscription(),pt):(pt=!1,!1)}catch{return pt=!1,!1}}function Es(t,s,n){if(_r())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 lo(t,s={}){const n={...io,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{co().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Es(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!_r())&&Tt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,qe(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),u=qe(l.status,{activeModal:l.activeModal}),x=l.name||l.id;if(n.onApproval&&Tt("approval")&&u==="waiting_approval"&&f!=="waiting_approval"){const h=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${x} — Approval needed`,h.slice(0,120),`approval-${l.id}`)}n.onComplete&&Tt("completion")&&hr(f)&&u==="idle"&&c(`✅ ${x} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&f!=="error"&&c(`⚠️ ${x} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class uo{constructor(){Ke(this,"dedupMap",new Map);Ke(this,"DEDUP_WINDOW_MS",5e3);Ke(this,"DEDUP_MAX_SIZE",50);Ke(this,"DEDUP_CLEANUP_AGE_MS",1e4);Ke(this,"toastCallbacks",[]);Ke(this,"systemMessageCallbacks",[]);Ke(this,"clearSystemMessageCallbacks",[]);Ke(this,"resolveActionFn",null);Ke(this,"viewRequestRespondFn",null);Ke(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,x;if(!s.ideId&&s.instanceId){for(const h of this.ides)if(h.id.endsWith(`:ide:${s.instanceId}`)||h.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=h.id;break}}const r=this.resolveConversationKey(s),o=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=Te(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=nt(d,{fallbackId:d.id});h&&(c=s.ideType==="adhdev-daemon"?h:`${h}/${c}`)}let l="",f="info";if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${h}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&no().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${h}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,f="warning",r){const h=s.modalMessage||"Approval requested",p=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(v=>`[${v}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
36
- ${p}`,_localId:`sys_approval_${Date.now()}`})}if((x=s.modalButtons)!=null&&x.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const p=s.agentType||s.ideType||"",v=s.ideType||"",m=s.modalButtons,C=g=>g.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),b=this.resolveActionFn,w=m.map((g,j)=>{const y=C(g).toLowerCase(),k=/^(run|approve|accept|yes|allow|always)/.test(y),E=/^(reject|deny|delete|remove|abort|cancel|no)/.test(y);return{label:C(g),variant:k?"primary":E?"danger":"default",onClick:()=>{const $=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y);b(h,"resolve_action",{action:$?"approve":"reject",button:g,buttonIndex:j,agentType:p,ideType:v,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),N=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,D=Date.now();this.emitToast({id:D,message:N,type:f,timestamp:D,targetKey:r||h,actions:w,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${h}`,f="warning",Tt("browser")&&!document.hasFocus()&&Es(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",p=s.requestId,v=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",p&&v&&this.viewRequestRespondFn){const m=this.viewRequestRespondFn,C=Date.now(),b=[{label:"Approve",variant:"primary",onClick:()=>{m(v,p,"approve").catch(w=>console.error("[EventManager] approve view request failed:",w))}},{label:"Decline",variant:"danger",onClick:()=>{m(v,p,"reject").catch(w=>console.error("[EventManager] reject view request failed:",w))}}];this.emitToast({id:C,message:l,type:f,timestamp:C,actions:b,duration:3e4}),l=""}Tt("browser")&&!document.hasFocus()&&Es("👁️ View Request",`${h} wants to view your session`,`view-request-${p}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:r||s.ideId,duration:5e3})}}}const lt=new uo;function gt(...t){return ka(Na(t))}function po({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:gt("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function is({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(po,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:gt("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function Fe({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:gt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Js({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:gt("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const mo={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"},xo={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function fo({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:gt("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",mo[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:xo[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 ho={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"},bo={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function go({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:gt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",ho[t],n),children:[e.jsx("span",{className:gt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",bo[t])}),r]})}function yo(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ds(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Jt(t){return t==="system"?yo():t}function vo(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Jt(Ds()))}function Tr(){const[t,s]=a.useState(Ds),[n,r]=a.useState(()=>Jt(Ds()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Jt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Jt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function dt({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("div",{className:`flex justify-between items-center ${r?"opacity-60":""}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,e.jsxs("button",{type:"button",role:"switch","aria-checked":n,"aria-disabled":r,disabled:r,onClick:()=>i(!n),className:`relative inline-flex items-center ${r?"cursor-not-allowed":"cursor-pointer"}`,children:[e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function wo({onPrefChange:t}){const[s,n]=ao(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ve,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qa,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ei,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(bt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function jo({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Js,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(No,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function Ln({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return Sa.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:r==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:n})]})]})}),document.body)}function ko(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Sr,...Cr,...Ir].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function No({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var T,z;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,u]=a.useState(null),[x,h]=a.useState("idle"),[p,v]=a.useState(""),m=t,C=m.version||m.daemonVersion||null,b=((T=m.machine)==null?void 0:T.platform)||((z=m.system)==null?void 0:z.platform)||"",w=nt(m,{fallbackId:t.id}),N=b==="win32"?"🪟":b==="darwin"?"🍎":"🐧",D=s.filter(W=>W.daemonId===t.id&&W.transport==="cdp-page"),g=s.filter(W=>W.daemonId===t.id&&W.transport==="pty"),j=s.filter(W=>W.daemonId===t.id&&W.transport==="acp"),y=m.p2p,k=async()=>{var W,K,M,P;if(n){c("upgrading"),l("Starting upgrade...");try{const _=await n(t.id,"daemon_upgrade",{});(W=_==null?void 0:_.result)!=null&&W.alreadyLatest?(c("done"),l(`Already on v${_.result.version||"latest"}.`)):(K=_==null?void 0:_.result)!=null&&K.upgraded||(M=_==null?void 0:_.result)!=null&&M.success?(c("done"),l(`Upgrade to v${_.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((P=_==null?void 0:_.result)==null?void 0:P.error)||"Upgrade failed"))}catch(_){c("error"),l((_==null?void 0:_.message)||"Connection lost during upgrade")}}},E=async()=>{if(u(null),!!r){h("loading");try{await r(t.id),h("done"),v("Machine disconnected.")}catch(W){h("error"),v((W==null?void 0:W.message)||"Failed to disconnect")}}},$=async()=>{if(u(null),!!i){h("loading");try{await i(t.id),h("done"),v('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(W){h("error"),v((W==null?void 0:W.message)||"Failed to revoke token")}}},A="0.8.17",U=!C||C!==A,L=D.length+g.length+j.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:N}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:w}),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),"…"]}),C&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${U?"":"bg-bg-secondary"}`,style:U?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",C,!U&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&U&&e.jsx("button",{onClick:k,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${A}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${A}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:x==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:x==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(go,{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:[y&&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 ${y.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${y.state==="connecting"||y.state==="new"?"animate-pulse":""}`,style:y.state==="connecting"||y.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",y.state==="connected"?"connected":y.state==="connecting"||y.state==="new"?"connecting...":y.state||"off"]}),y.peers!==void 0&&y.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",y.peers," peer",y.peers!==1?"s":"",")"]})]}),y&&L>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),L>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[D.map(W=>{const K=ko(W.type),M=W.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:K.icon}),e.jsx("span",{children:K.name}),M!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${M?"bg-green-400":"animate-pulse"}`,style:M?void 0:{background:"var(--status-warning)"},title:M?"CDP connected":"CDP connecting..."})]},W.id)}),g.map(W=>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:W.cliName||"CLI"})]},W.id)),j.map(W=>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:W.cliName||"ACP"})]},W.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||x==="error"?"text-red-400":o==="done"||x==="done"?"text-green-400":"text-text-muted"}`,children:p||d})]}),f==="disconnect"&&e.jsx(Ln,{title:"🔌 Disconnect Machine",message:`Disconnect "${w}" from ADHDev?
37
-
38
- This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
39
-
40
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:E,onCancel:()=>u(null)}),f==="revoke"&&e.jsx(Ln,{title:"⚠️ Remove Machine",message:`Remove "${w}" from your dashboard?
41
-
42
- This will:
43
- • Immediately disconnect the machine
44
- • Delete the machine registration
45
- • Require restarting "adhdev-standalone" on that machine
46
-
47
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:$,onCancel:()=>u(null)})]})}const So=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Co(){const{preference:t,setPreference:s}=Tr();return e.jsx("div",{className:"flex gap-2",children:So.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===n.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}function Io(t){const s=t.trim();return/^#[0-9a-fA-F]{6}$/.test(s)?s:/^#[0-9a-fA-F]{3}$/.test(s)?`#${s[1]}${s[1]}${s[2]}${s[2]}${s[3]}${s[3]}`:null}function Mo(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Ns(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function Rn(t){const{r:s,g:n,b:r}=Mo(t);return .2126*Ns(s)+.7152*Ns(n)+.0722*Ns(r)}function $n(t,s){const n=Rn(t),r=Rn(s),i=Math.max(n,r),o=Math.min(n,r);return(i+.05)/(o+.05)}function Qs(t){const s=Io(t);if(!s)return"#111827";const n="#111827",r="#ffffff";return $n(s,n)>=$n(s,r)?n:r}const Ar="adhdev-accent-color",Bs="#cf7a45";function _o(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,r),o=Math.min(s,n,r);let c=0,d=0;const l=(i+o)/2;if(i!==o){const f=i-o;switch(d=l>.5?f/(2-i-o):f/(i+o),i){case s:c=((n-r)/f+(n<r?6:0))/6;break;case n:c=((r-s)/f+2)/6;break;case r:c=((s-n)/f+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)}}function Pn(t,s){const{h:n,s:r,l:i}=_o(t),o=Math.min(100,i+s);return`hsl(${n}, ${r}%, ${o}%)`}function Ss(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function To(){return typeof window>"u"?Bs:localStorage.getItem(Ar)||Bs}function Ao(){if(typeof window>"u")return!1;try{return localStorage.getItem(Ar)!=null}catch{return!1}}function Lo(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",Pn(t,15)),s.style.setProperty("--accent-on-primary",Qs(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${Pn(t,20)})`),s.style.setProperty("--border-accent",Ss(t,.4)),s.style.setProperty("--nav-active-bg",Ss(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${Ss(t,.06)}`)}function Ro(){const t=To();t!==Bs&&Lo(t)}const Ks={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},Ws={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},$o=[{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"}}}],Lr="adhdev-chat-theme",Rr="adhdev-chat-theme-custom";function Qt(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Lr)||"ember"}catch{return"ember"}}function et(t){try{const s=localStorage.getItem(Rr);if(s){const n=JSON.parse(s);return{...t==="dark"?Ks:Ws,...n[t]}}}catch{}return t==="dark"?Ks:Ws}function Ht(t,s){try{localStorage.setItem(Rr,JSON.stringify({dark:t,light:s}))}catch{}}function Je(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function os(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Po={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function At(t,s){var i;if(Ao())return;const n=(i=Po[t])==null?void 0:i[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",os(n,24)),r.style.setProperty("--accent-on-primary",Qs(n)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${os(n,18)})`),r.style.setProperty("--border-accent",Je(n,.35)),r.style.setProperty("--nav-active-bg",Je(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Je(n,.06)}`)}function xt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Je(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Je(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Je(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",Je(t.borderSubtle,.5)),s.style.setProperty("--border-default",Je(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",os(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Qs(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${os(t.accentColor,40)})`),s.style.setProperty("--border-accent",Je(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Je(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Je(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 ${Je(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function en(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function Eo(t){try{localStorage.setItem(Lr,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else en(),At(t,ft()?"dark":"light")}function Do(){const t=Qt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else en(),At(t,ft()?"dark":"light")}function ft(){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)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function Ct({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 Bo({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>et(n));a.useEffect(()=>{i(et(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},x=et(n==="dark"?"light":"dark");return n==="dark"?Ht(f,x):Ht(x,f),xt(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(Ct,{title:"App Background",children:[e.jsx(He,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(He,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(He,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Ct,{title:"App Text",children:[e.jsx(He,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(He,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(He,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Ct,{title:"Borders & Accent",children:[e.jsx(He,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(He,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(He,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Ct,{title:"Chat Bubbles",children:[e.jsx(He,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(He,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(He,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(He,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Ct,{title:"Chat Layout",children:[e.jsx(He,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(He,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(He,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ks:Ws,l=et(t?"light":"dark");t?Ht(c,l):Ht(l,c),i(c),xt(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Ko(){const[t,s]=a.useState(Qt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>et("dark"));a.useEffect(()=>{r(ft());const l=new MutationObserver(()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")};return f.addEventListener("change",u),()=>{l.disconnect(),f.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?xt(et(n?"dark":"light")):(en(),At(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(et(n?"dark":"light"))},[n]);const c=l=>{s(l),Eo(l)},d=[...$o,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const f=t===l.id,u=n?l.preview.dark:l.preview.light,x=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:x},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Bo,{dark:n,onColorsChange:l=>o(l)})]})}const $r="adhdev_mobileDashboardMode_v1";function Pr(){try{return localStorage.getItem($r)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Wo(t){try{localStorage.setItem($r,t)}catch{}}function Oo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Pr()==="chat")},[]),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:n=>{s(n),Wo(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Er="adhdev_hiddenTabs";function zo(){try{const t=localStorage.getItem(Er);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function yt(t){try{localStorage.setItem(Er,JSON.stringify([...t]))}catch{}}function Uo(){const[t,s]=a.useState(zo),n=a.useCallback(f=>{s(u=>{const x=new Set(u);return x.has(f)?x.delete(f):x.add(f),yt(x),x})},[]),r=a.useCallback(f=>{s(u=>{if(u.has(f))return u;const x=new Set(u);return x.add(f),yt(x),x})},[]),i=a.useCallback(f=>{s(u=>{if(!u.has(f))return u;const x=new Set(u);return x.delete(f),yt(x),x})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const u=new Set;return yt(u),u})},[]),c=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.add(p);return yt(h),h})},[]),d=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.delete(p);return yt(h),h})},[]),l=a.useCallback(f=>t.has(f),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:d,isHidden:l}}function Ho({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{oo()},[]);const i=a.useMemo(()=>t.map(o=>({id:o.tabKey,name:o.title||o.agentName||o.ideId,status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[t]);return lo(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[u,x]of Object.entries(d))l-x<5e3&&(f[u]=x);return Object.keys(f).length===Object.keys(d).length?d:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(d=>{const l=d.filter(f=>f.timestamp>c).slice(-100);return l.length===d.length?d:l})},6e4);return()=>clearInterval(o)},[r]),null}function Cs(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function jt(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return Cs(s==null?void 0:s.timestamp)||Cs(s==null?void 0:s.receivedAt)||Cs(s==null?void 0:s.createdAt)||0}function Dr(t){return jt(t)}function Fo(t,s,n=Dr){const r=n(s)-n(t);if(r!==0)return r;const i=(t.machineName||"").localeCompare(s.machineName||"");if(i!==0)return i;const o=t.displayPrimary.localeCompare(s.displayPrimary);if(o!==0)return o;const c=t.displaySecondary.localeCompare(s.displaySecondary);return c!==0?c:t.tabKey.localeCompare(s.tabKey)}function Vo(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const i=n.get(r.id);if(!i){n.set(r.id,r);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>o||(r.timestamp||0)>(i.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function Ft(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 qo(t,s){const n=Date.now();return t.map(r=>{const i=s[r.tabKey];return i&&n-i<5e3?{...r,messages:[],title:""}:r})}function Go(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;n.push({key:c,ref:s[c]}),n.push({key:i.id,ref:s[i.id]})}return n}function Yo(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 Xo(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Zo(t){const s=Xo(t);if(!s)return`empty:${t.messages.length}`;if(s.id)return`id:${String(s.id)}`;if(s._localId)return`local:${String(s._localId)}`;const n=String(s.role||""),r=Zs(s.content).slice(0,240);return`${t.messages.length}:${n}:${r}`}function Jo({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),d=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const g=Vo(t);return Ft(o.current,g)?o.current:(o.current=g,g)},[t]),u=a.useMemo(()=>kr(t),[t]),x=a.useRef(new Map),h=a.useRef(new Map),p=a.useMemo(()=>{var $;const g=new Map,j=[];for(const A of f){const U=A.daemonId||(($=A.id)==null?void 0:$.split(":")[0])||A.id,L=s[U]||"new",T=A.daemonId&&u[A.daemonId]||void 0,z=Go(A,n),W=x.current.get(A.id);if(W&&W.ide===A&&W.connectionState===L&&W.machineName===T&&Yo(W.localRefs,z)){g.set(A.id,W),j.push(...W.conversations);continue}const K=Nr(A,n,{machineName:T,connectionState:L}),M={ide:A,connectionState:L,machineName:T,localRefs:z,conversations:K};g.set(A.id,M),j.push(...K)}x.current=g;const y=new Map,k=A=>{const U=Zo(A),L=h.current.get(A.tabKey);if(L&&L.signature===U)return y.set(A.tabKey,L),L.timestamp;const T={signature:U,timestamp:Dr(A)||(L==null?void 0:L.timestamp)||0};return y.set(A.tabKey,T),T.timestamp},E=[...j].sort((A,U)=>Fo(A,U,k));return h.current=y,E},[f,n,s,u]),v=a.useMemo(()=>{const g=qo(p,r);return Ft(c.current,g)?c.current:(c.current=g,g)},[p,r]),m=a.useMemo(()=>{const g=new Map;for(const j of v)j.sessionId&&g.set(j.sessionId,j);return g},[v]),C=a.useMemo(()=>{const g=new Map;for(const j of v)j.sessionId&&g.set(j.sessionId,j),g.set(j.ideId,j),g.set(j.tabKey,j);return g},[v]),b=a.useCallback(g=>{if(g)return m.get(g)},[m]),w=a.useCallback(g=>{if(g)return C.get(g)},[C]),N=a.useMemo(()=>{const g=v.filter(j=>!i.has(j.tabKey));return Ft(d.current,g)?d.current:(d.current=g,g)},[v,i]),D=a.useMemo(()=>{const g=N.map(j=>j.tabKey);return Ft(l.current,g)?l.current:(l.current=g,g)},[N]);return{chatIdes:f,conversations:v,visibleConversations:N,visibleTabKeys:D,resolveConversationBySessionId:b,resolveConversationByTarget:w}}function Qo({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var d;return t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var d;return!t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(d=>{const l=new URLSearchParams(d);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function ec({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{lt.setIdes(t)},[t]),a.useEffect(()=>{lt.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=lt.onToast(l=>{n(u=>u.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?u:[...u.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const f=l.duration||5e3;setTimeout(()=>n(u=>u.filter(x=>x.id!==l.id)),f)}),c=lt.onSystemMessage((l,f)=>{var p,v;const u=i(l),x=(p=f._localId)==null?void 0:p.startsWith("sys_approval_"),h=!!(u&&(u.status==="waiting_approval"||(v=u.modalButtons)!=null&&v.length||u.modalMessage));x&&h||r(m=>({...m,[l]:[...m[l]||[],f]}))}),d=lt.onClearSystemMessage((l,f)=>{r(u=>{var x;return(x=u[l])!=null&&x.length?{...u,[l]:u[l].filter(h=>{var p;return!(h.role==="system"&&((p=h._localId)!=null&&p.startsWith(f)))})}:u})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=wr.on("status_event",c=>lt.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=d=>{const l=d.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,u=i(f),x=(u==null?void 0:u.ideId)||l.ideId;x&&s(x,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(h=>console.error("[SW Action] approve failed:",h))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var d;return(d=navigator.serviceWorker)==null?void 0:d.removeEventListener("message",o)}},[i,s])}const tc="adhdev_dashboardLayout_v1",sc="adhdev_dashboardDockview_v1",It={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Br(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Kr(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Wr(t){return`${tc}:${t}`}function nc(t){const s=Wr(t);return Br(s,null)}function rc(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=Wr(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Or(t){return`${sc}:${t}`}function ac(t){const s=Or(t);return Br(s,null)}function ic(t,s){try{const n=Or(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function oc(){return{groupAssignments:[...It.groupAssignments],focusedGroup:It.focusedGroup,groupActiveTabIds:{...It.groupActiveTabIds},groupTabOrders:{...It.groupTabOrders},groupSizes:[...It.groupSizes]}}function cc(){const[t]=a.useState(()=>Kr(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[d,l]=a.useState({}),[f,u]=a.useState([]),[x,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,v]=a.useState(!1),m=a.useCallback(()=>{if(p)return;const C=nc(t)??oc();n(new Map(C.groupAssignments)),i(C.focusedGroup),c(C.groupActiveTabIds),l(C.groupTabOrders),u(C.groupSizes),v(!0)},[p,t]);return a.useEffect(()=>{p&&rc(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[p,t,s,r,o,d,f]),a.useEffect(()=>{const C=window.matchMedia("(max-width: 767px)"),b=w=>h(w.matches);return C.addEventListener("change",b),()=>C.removeEventListener("change",b)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:u,isMobile:x,hasHydratedStoredLayout:p,hydrateStoredLayout:m}}function lc({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:u,isRefreshingHistory:x,ides:h,handleRefreshHistory:p}){const v=a.useRef(!1),m=a.useRef(!1),C=a.useRef(null),b=a.useRef(!1);a.useEffect(()=>{if(!t||v.current||s.length===0)return;if(!i){o();return}const w=n(t);if(!w)return;const N=r.get(w.tabKey)??0;c(D=>({...D,[N]:w.tabKey})),d(N),v.current=!0,m.current=!0,C.current!=null&&(window.clearTimeout(C.current),C.current=null),l(D=>{const g=new URLSearchParams(D);return g.delete("activeTab"),g},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(m.current||i)&&s.length!==0){if(!t){o(),m.current=!0;return}if(v.current){m.current=!0;return}if(C.current==null)return C.current=window.setTimeout(()=>{C.current=null,!(m.current||i)&&(o(),m.current=!0)},1500),()=>{C.current!=null&&(window.clearTimeout(C.current),C.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){b.current=!1;return}if(!u||b.current||x)return;const w=h.find(N=>N.id===u.ideId);w&&(!w.chats||w.chats.length===0)&&(b.current=!0,p())},[f,u,x,h,p]),a.useEffect(()=>{if(!u)return;let w=null,N=0,D=-1,g=0;const j=()=>{w=null;const y=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(E=>E.offsetParent!==null);if(y.length===0){N<18&&(N+=1,w=requestAnimationFrame(j));return}let k=0;for(const E of y)E.scrollTop=E.scrollHeight,k+=E.scrollHeight;k===D?g+=1:(g=0,D=k),N+=1,!(g>=2||N>=18)&&(w=requestAnimationFrame(j))};return w=requestAnimationFrame(j),()=>{w!=null&&cancelAnimationFrame(w)}},[u==null?void 0:u.tabKey])}function dc({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[u,x]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const b=d(r);return b&&!Pe(b)&&!Ae(b)?b:null},[t,r,d]),p=a.useMemo(()=>{const b=l==null?void 0:l.ideId;if(!b)return null;const w=l!=null&&l.tabKey?o.find(N=>N.tabKey===l.tabKey):i?o.find(N=>N.tabKey===i):null;return(w==null?void 0:w.ideId)===b?w:o.find(N=>N.ideId===b&&N.streamSource==="native")||o.find(N=>N.ideId===b)||null},[o,l,i]),v=a.useMemo(()=>{if(p)return c.find(b=>b.id===p.ideId)},[c,p]);a.useEffect(()=>{h&&(f({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),x(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const m=a.useCallback(b=>{b&&(f({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),x(b))},[]),C=a.useCallback(()=>{f(null),x(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:v,remoteDialogActiveConv:u,setRemoteDialogActiveConv:x,openRemoteDialog:m,closeRemoteDialog:C}}function Lt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Pe(t)||Ae(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function cs(t){return t&&(t.ideId||t.daemonId)||""}function Vt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function En({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),u=a.useCallback(async v=>{try{await t("standalone","launch_ide",{ideType:v,enableCdp:!0})}catch(m){console.error("Launch failed",m)}},[t]),x=a.useCallback(async(v,m)=>{try{const C=v||(s==null?void 0:s.daemonId)||"",b=await t(C,"switch_chat",{id:m,sessionId:m,...Lt(s)}),w=b==null?void 0:b.result;if((b==null?void 0:b.success)===!0||w==="switched"||w==="switched-by-title")return;w===!1||w==="not_found"?Vt(r,"⚠️ Session tab not found — try refreshing history"):typeof w=="string"&&w.startsWith("error:")?Vt(r,`⚠️ Switch error: ${w}`):Vt(r,"⚠️ Session switch failed")}catch(C){console.error("Switch failed",C),Vt(r,`❌ Switch failed: ${C.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const v=cs(s);await t(v,"new_chat",{...Lt(s)}),o(m=>({...m,[s.tabKey]:Date.now()})),i(m=>({...m,[s.tabKey]:[]}))}catch(v){console.error("New chat failed",v)}finally{d(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var v;if(!(!s||l)){f(!0);try{const m=cs(s),C=await t(m,"list_chats",{forceExpand:!0,...Lt(s)}),b=(C==null?void 0:C.chats)||((v=C==null?void 0:C.result)==null?void 0:v.chats);C!=null&&C.success&&Array.isArray(b)&&n(s.ideId,b)}catch(m){console.error("Refresh history failed",m)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:x,handleNewChat:h,handleRefreshHistory:p}}function uc(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 pc(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Dn(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[Number(i)]===t[Number(i)])}function qt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Bn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function mc(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function xc(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Kn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=Number(r);n[o>=s?o+1:o]=i}return n}function Wn(t){return Array(t).fill(100/t)}function fc({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const u=a.useRef(null),x=a.useMemo(()=>qt(t,f),[t,f]),h=x.assignments,p=a.useMemo(()=>d?1:x.groupCount,[x.groupCount,d]),v=p>1,m=a.useCallback((g,j)=>{s(y=>{const k=new Map(qt(y,f).assignments);return j===0?k.delete(g):k.set(g,j),k}),r(y=>({...y,[j]:g})),n(j)},[s,f,r,n]),C=a.useCallback(g=>{s(j=>{const y=qt(j,f).assignments,k=new Map;for(const[E,$]of y)$!==g&&($>g?k.set(E,$-1):k.set(E,$));return k}),c(j=>{if(j.length<=1)return[];const y=[...j];y.splice(g,1);const k=y.reduce((E,$)=>E+$,0);return k>0?y.map(E=>E/k*100):[]}),n(0)},[s,f,c,n]),b=a.useCallback((g,j)=>{j.preventDefault();const y=u.current;if(!y)return;const k=j.clientX,E=y.offsetWidth,$=o.length===p?[...o]:Wn(p),A=L=>{const z=(L.clientX-k)/E*100,W=[...$];W[g]=Math.max(15,$[g]+z),W[g+1]=Math.max(15,$[g+1]-z),c(W)},U=()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",U),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",A),document.addEventListener("mouseup",U)},[o,p,c]),w=a.useCallback((g,j,y)=>{if(p>=4)return;const k=y==="left"?j:j+1;s(E=>{const $=qt(E,f).assignments,A=new Map;for(const U of l){const L=$.get(U.tabKey)??0,T=L>=k?L+1:L;T>0&&A.set(U.tabKey,T)}return k>0&&A.set(g,k),A}),c(E=>{const $=E.length===p?[...E]:Wn(p),A=$[j]??100/p,U=Math.max(15,A/2),L=Math.max(15,A/2),T=[...$];T[j]=U,T.splice(k,0,L);const z=T.reduce((W,K)=>W+K,0);return T.map(W=>W/z*100)}),r(E=>{const $=Kn(E,k);return $[k]=g,$}),i(E=>{const $=Kn(E,k);return $[k]=[g],$}),n(k)},[p,s,f,l,c,r,i,n]);a.useEffect(()=>{uc(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:g,usedGroups:j}=x;r(y=>{const k=Bn(y,g);return Dn(y,k)?y:k}),i(y=>{const k=Bn(y,g);return Dn(y,k)?y:k}),n(y=>{const k=d?0:mc(y,j,g);return y===k?y:k}),c(y=>{const k=d?[]:xc(y,j,x.groupCount);return pc(y,k)?y:k})},[x,d,r,i,n,c]);const N=a.useMemo(()=>{const g=Array.from({length:p},()=>[]);for(const j of l){const y=h.get(j.tabKey)??0,k=Math.min(y,p-1);g[k].push(j)}return g},[l,h,p]),D=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:h,numGroups:p,isSplitMode:v,groupedConvs:N,moveTabToGroup:m,closeGroup:C,handleResizeStart:b,splitTabRelative:w,clearAllSplits:D}}function hc({ides:t,sendDaemonCommand:s}){const n="0.8.17",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const u=f.version||f.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var u,x;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(u=h==null?void 0:h.result)!=null&&u.upgraded||(x=h==null?void 0:h.result)!=null&&x.success?d(p=>({...p,[f]:"done"})):d(p=>({...p,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function xs({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[d,l]=a.useState(!1),f=a.useRef(!1),u=a.useRef(null),x=a.useCallback(async m=>{if(!s)return;const C=m.trim();if(!C||f.current)return;const b=s.tabKey,w=Date.now(),N=u.current;if(N&&N.tabKey===b&&N.message===C&&w-N.timestamp<2e3)return;f.current=!0,l(!0),u.current={tabKey:b,message:C,timestamp:w};const D=`${w}-${Math.random().toString(36).slice(2,8)}`,g={role:"user",content:C,timestamp:w,_localId:D};n(j=>({...j,[b]:[...j[b]||[],g]}));try{const j=cs(s);if(!j)return;const y=await t(j,"send_chat",{message:C,text:C,...Lt(s)});if(y!=null&&y.deduplicated||(y==null?void 0:y.sent)===!1){n(k=>({...k,[b]:(k[b]||[]).filter(E=>E._localId!==D)}));return}setTimeout(()=>{const k=Date.now()-6e4;n(E=>{const $=E[b];if(!$)return E;const A=$.filter(U=>U.timestamp>k);return A.length===$.length?E:{...E,[b]:A}})},6e4)}catch(j){console.error("Send failed",j),n(y=>({...y,[b]:(y[b]||[]).filter(k=>k._localId!==D)}))}finally{f.current=!1,l(!1)}},[s,t,n]),h=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(m){console.error("Relaunch failed",m)}},[s,t]),p=a.useCallback(async m=>{if(s)try{const b=(s.modalButtons||[]).indexOf(m),w=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),N=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w),D=cs(s);if(!D)return;(await t(D,"resolve_action",{button:m,action:N?"approve":"reject",...b>=0&&{buttonIndex:b},...Lt(s)})).success||r(j=>[...j,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(C){console.error("[ModalButton] Error:",C),r(b=>[...b,{ideId:s.tabKey,text:`❌ **${m}** error`,timestamp:Date.now()}])}},[s,t,r]),v=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:x,handleRelaunch:h,handleModalButton:p,handleFocusAgent:v}}const tn=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p}){return e.jsxs(e.Fragment,{children:[e.jsx(fr,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(Vs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:d,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:r?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Oi,{activeConv:s,clearToken:n,terminalRef:o,handleSendChat:l,isSendingChat:f,isVisible:r})}),!r&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Ps,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})})]}):e.jsx(Ps,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function bc({selectedConversation:t,isAcp:s,isStandalone:n,selectedIdeEntry:r,actionLogs:i,userName:o,isSendingChat:c,isFocusingAgent:d,onBack:l,onOpenNativeConversation:f,onOpenMachine:u,onOpenHistory:x,onOpenRemote:h,onHideConversation:p,onStopCli:v,cliViewMode:m,onSetCliViewMode:C,handleSendChat:b,handleFocusAgent:w,handleModalButton:N,handleRelaunch:D}){const g=a.useRef(null),j=Pe(t)&&!s,y=j&&m==="terminal",k=n?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${k} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:l,type:"button","aria-label":"Back",children:e.jsx(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(gr,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>f(t),onOpenMachine:()=>u(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[j&&m&&e.jsx(Xs,{mode:m,onChange:C,compact:!0}),j&&v&&e.jsx("button",{onClick:()=>{v(t)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(kt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(t),type:"button",children:e.jsx(Hs,{size:14})}),!s&&!j&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",children:e.jsx(Ve,{size:14})}),p&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(t),type:"button",title:"Close chat",children:e.jsx(kt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(tn,{activeConv:t,clearToken:0,isCliTerminal:y,ideEntry:r,terminalRef:g,handleModalButton:N,handleRelaunch:D,handleSendChat:b,isSendingChat:c,handleFocusAgent:w,isFocusingAgent:d,actionLogs:i,userName:o})})]})}const Is={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 gc(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function zr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(gc())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(Is[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Is[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Is[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Ur({section:t,onSectionChange:s}){const n=[{key:"machines",label:"Machines",icon:Ve},{key:"chats",label:"Chats",icon:it}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:n.map(({key:r,label:i,icon:o})=>{const c=t===r;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(r),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(o,{size:15})}),e.jsx("span",{children:i})]},r)})})})}function Gt({title:t,className:s=""}){return e.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${s}`,children:e.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:t})})}function vt({children:t,className:s=""}){return e.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function Mt({icon:t,title:s,subtitle:n,children:r}){return e.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),r]})}function Yt({item:t,type:s,getAvatarText:n,onOpenConversation:r}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`group flex items-start gap-3.5 px-4 py-3.5 w-full text-left relative overflow-hidden transition-colors active:scale-[0.995] ${i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":"bg-transparent"} ${c?"opacity-70 saturate-50":""}`,onClick:()=>r(t.conversation),type:"button",children:[i||o?e.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,e.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary shadow-glow":o?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":"bg-bg-primary border border-border-subtle text-text-secondary"}`,style:i?{color:"var(--accent-on-primary)"}:void 0,children:n(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:xr(t.timestamp)})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[t.conversation.displaySecondary,t.conversation.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(Ve,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]},t.conversation.tabKey)}function On({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function yc({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:u,onOpenMachine:x,onOpenSettings:h,onSectionChange:p,wsStatus:v="connected",isStandalone:m=!1}){const C=v==="disconnected"||v==="reconnecting"||v==="offline"||v==="auth_failed",b=c.length>0,w=s.length>0||n.length>0||r.length>0||i.length>0,N=t==="machines"?"Machines":"Chats",D=m?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",g=m?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]";return e.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${D}`,children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:N}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(ps,{size:13}),e.jsx("span",{children:s.length+n.length})]}),e.jsx("button",{onClick:h,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:e.jsx(us,{size:18})})]})]})}),e.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${g}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:C?e.jsx(Mt,{icon:e.jsx(On,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:v==="offline"?"Your device appears to be offline. Waiting for network…":v==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:m?"Waiting for your IDE":"Connect your first machine",subtitle:m?"Launch any supported IDE or CLI agent — it will appear here automatically.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!m&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(zr,{})})}):e.jsx(vt,{children:c.map((j,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(j.id),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:d(j.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:j.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[j.unread," new"]}):j.total>0?`${j.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:j.subtitle}),j.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[j.total," chat",j.total!==1?"s":"",j.unread>0?` · ${j.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},j.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gt,{title:"Needs attention",className:"mb-0"}),e.jsx(vt,{children:s.map((j,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:j,type:"needs_attention",getAvatarText:d,onOpenConversation:l})},j.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gt,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(vt,{children:n.map((j,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:j,type:"task_complete",getAvatarText:d,onOpenConversation:l})},j.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gt,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(vt,{children:r.map((j,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:j,type:"working",getAvatarText:d,onOpenConversation:l})},j.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[i.length>0&&e.jsx(Gt,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(vt,{children:i.map((j,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:j,type:"earlier",getAvatarText:d,onOpenConversation:l})},j.conversation.tabKey))}):w?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):C?e.jsx(Mt,{icon:e.jsx(On,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):b?e.jsx(Mt,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(it,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open an IDE or launch a CLI agent to start your first conversation."}):e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:u,children:"Restore all"})]}),e.jsx(vt,{className:"bg-bg-secondary/25",children:o.map((j,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] opacity-50 saturate-0 ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(j),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-border-subtle text-text-secondary",children:d(j.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.displayPrimary}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[j.displaySecondary,j.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(Ve,{size:11})," ",j.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},j.tabKey))})]})]}),e.jsx(Ur,{section:t,onSectionChange:p})]})}function vc(t){const s=t.trim();if(!s)return null;if(s.startsWith("~"))return s;if(/^[A-Za-z]:$/.test(s))return`${s[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(s))return`${s[0].toUpperCase()}:${s.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(s))return`${s[0].toUpperCase()}:\\${s.slice(2).replace(/[\\/]+/g,"\\")}`;const n=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(n){const r=n[1].toUpperCase(),i=(n[2]||"").replace(/[\\/]+/g,"\\");return i?`${r}:\\${i}`:`${r}:\\`}return null}function sn(t,s=[]){if(t==="win32"){for(const n of s){if(typeof n!="string")continue;const r=vc(n);if(r)return r}return"C:\\"}for(const n of s){const r=typeof n=="string"?n.trim():"";if(r)return r}return"~"}function wc(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const n=s.includes("\\")?"\\":"/",r=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(r[0]||"")?r.length<=2?`${r[0]}\\`:r.slice(0,-1).join("\\"):r.length<=2?n:r.slice(0,-1).join(n)||n}async function Hr(t,s,n){const r=await t(s,"file_list_browse",{path:n});if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Could not browse folder");const i=typeof(r==null?void 0:r.path)=="string"?r.path:n,o=i.includes("\\")?"\\":"/",c=(l,f)=>/^[A-Za-z]:\\?$/.test(l)?`${l.replace(/\\?$/,"\\")}${f}`:l==="/"||l==="\\"?`${o}${f}`:`${l.replace(/[\\/]+$/,"")}${o}${f}`,d=Array.isArray(r==null?void 0:r.files)?r.files.filter(l=>(l==null?void 0:l.type)==="directory"&&typeof(l==null?void 0:l.name)=="string").map(l=>({name:l.name,path:c(i,l.name)})).sort((l,f)=>l.name.localeCompare(f.name)):[];return{path:i,directories:d}}function nn({title:t,description:s,currentPath:n,directories:r,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:d,onNavigate:l,onConfirm:f}){const[u,x]=a.useState(n);a.useEffect(()=>{x(n)},[n]);const h=wc(n),p=u.trim();return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:d,"aria-label":"Close folder browser",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!h||i||l(h)},disabled:!h||i,children:[e.jsx(Us,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:v=>x(v.target.value),onKeyDown:v=>{v.key!=="Enter"||!p||i||(v.preventDefault(),l(p))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!p||i||l(p)},disabled:!p||i,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):r.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:r.map(v=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>l(v.path),children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Pt,{size:17})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:v.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:v.path})]})]},v.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>f(p||n),disabled:!p&&!n||i,children:c})]})]})})}function rn({title:t,description:s,details:n,workspaceOptions:r,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:d=!1,onConfirm:l,onCancel:f}){const u=r==null?void 0:r.find(x=>x.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:f,"aria-label":"Close launch confirmation",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[r&&r.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:x=>o(x.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:r.map(x=>e.jsx("option",{value:x.key,children:x.label},x.key))}),(u==null?void 0:u.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:u.description})]}),n.map(x=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:x.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:x.value})]},`${x.label}:${x.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:f,disabled:d,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:l,disabled:d,children:[e.jsx(dr,{size:14}),d?"Launching…":c]})]})]})})}function zn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function ht(t){const{machine:s,currentWorkspacePath:n,currentWorkspaceId:r,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const l of s.workspaces||[])o.push({key:`saved:${l.id}`,label:`${l.id===s.defaultWorkspaceId?"⭐ ":""}${zn(l.path,l.label)}`,description:l.path,workspaceId:l.id,workspacePath:l.path});const c=(n==null?void 0:n.trim())||"",d=c?(s.workspaces||[]).find(l=>l.path===c):null;if(c&&!d&&o.push({key:`custom:${c}`,label:zn(c),description:c,workspaceId:null,workspacePath:c}),r){const l=`saved:${r}`;if(o.some(f=>f.key===l))return{options:o,selectedKey:l}}return d?{options:o,selectedKey:`saved:${d.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function jc({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,isStandalone:l,section:f,showBottomNav:u,onBack:x,onSectionChange:h,onOpenConversation:p,onOpenRecent:v,onOpenMachineDetails:m,onMachineUpgrade:C,onLaunchDetectedIde:b,onAddWorkspace:w,onBrowseDirectory:N,onLaunchWorkspaceProvider:D}){var Ee,De,Oe,Ze;const g=(oe,je,ve)=>oe?"ide":je>0?"cli":ve>0?"acp":null,[j,y]=a.useState(!1),k=oe=>oe==="ide"?"IDE":oe==="cli"?"CLI":"ACP",E=n.slice(0,4),$=s.slice(0,3),A=(((Ee=t.detectedIdes)==null?void 0:Ee.length)||0)>0,U=a.useMemo(()=>t.workspaces||[],[t]),L=t.defaultWorkspaceId||null,[T,z]=a.useState(L||((De=U[0])==null?void 0:De.id)||""),[W,K]=a.useState(""),[M,P]=a.useState(""),[_,R]=a.useState([]),[F,ce]=a.useState(!1),[de,he]=a.useState(""),[H,J]=a.useState(!1),[ee,ge]=a.useState(g(A,r.length,i.length)),te=a.useRef(null),[ue,xe]=a.useState(null),X=a.useRef("__home__"),[me,se]=a.useState("__home__"),[pe,Y]=a.useState(!1),ie=a.useRef(null),S=T==="__custom__"?W.trim():((Oe=U.find(oe=>oe.id===T))==null?void 0:Oe.path)||"",Z=T==="__custom__"&&!!S&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message),Q=T!=="__custom__"&&((Ze=U.find(oe=>oe.id===T))==null?void 0:Ze.path)||"",re=a.useCallback(async oe=>{ce(!0),he("");try{const je=await N(oe);P(je.path),K(je.path),R(je.directories)}catch(je){he(je instanceof Error?je.message:"Could not load folder")}finally{ce(!1)}},[N]),fe=a.useCallback(()=>{var je,ve;z("__custom__"),J(!0);const oe=sn(t.platform,[W.trim(),Q,(je=U.find(we=>we.id===L))==null?void 0:je.path,(ve=U[0])==null?void 0:ve.path]);re(oe)},[W,L,re,Q,t.platform,U]),ye=a.useCallback((oe,je)=>{te.current=je,X.current=oe.selectedWorkspaceKey||"__home__",se(oe.selectedWorkspaceKey||"__home__"),xe(oe)},[]),Ce=a.useCallback(()=>{te.current&&(Y(!0),te.current().finally(()=>{te.current=null,Y(!1),xe(null)}))},[]);a.useEffect(()=>{var oe;ie.current!==t.id&&(ie.current=t.id,z(L||((oe=U[0])==null?void 0:oe.id)||"__custom__"),K(""),P(""),R([]),he(""),J(!1),ge(g(A,r.length,i.length)))},[i.length,r.length,L,A,t.id,U]),a.useEffect(()=>{var oe;T!=="__custom__"&&(T&&U.some(je=>je.id===T)||z(L||((oe=U[0])==null?void 0:oe.id)||"__custom__"))},[L,T,U]),a.useEffect(()=>{ee==="ide"&&A||ee==="cli"&&r.length>0||ee==="acp"&&i.length>0||ge(g(A,r.length,i.length))},[ee,i.length,r.length,A]);const Me=a.useMemo(()=>{const oe=E.map(ve=>({key:`recent-launch:${ve.id}`,type:"session",primary:ve.label,secondary:`${k(ve.kind)}${ve.subtitle?` · ${ve.subtitle}`:""}`,unread:!1,onClick:()=>{const{options:we,selectedKey:O}=ht({machine:{workspaces:U,defaultWorkspaceId:L},currentWorkspacePath:ve.workspace});ye({title:`Launch ${ve.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:we,selectedWorkspaceKey:O,details:[{label:"Mode",value:k(ve.kind)},...ve.providerType?[{label:"Provider",value:ve.providerType}]:[]]},async()=>{const B=we.find(ne=>ne.key===X.current);B!=null&&B.workspaceId?(z(B.workspaceId),K("")):B!=null&&B.workspacePath?(z("__custom__"),K(B.workspacePath)):(z(""),K("")),await v({...ve,workspace:(B==null?void 0:B.workspacePath)??null})})}})),je=$.map(ve=>({key:`recent-chat:${ve.conversation.tabKey}`,type:"conversation",primary:ve.conversation.displayPrimary,secondary:`Chat${ve.conversation.displaySecondary?` · ${ve.conversation.displaySecondary}`:""}${ve.timestamp?` · ${xr(ve.timestamp)}`:""}`,unread:ve.unread,onClick:()=>p(ve.conversation)}));return[...oe,...je]},[L,p,v,ye,$,E,U]),Xe=j?Me:Me.slice(0,5),We=Me.length>0,Ge=l?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`flex items-center justify-between gap-3 ${Ge} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:x,type:"button","aria-label":"Back",children:e.jsx(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:nt(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[We&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Xe.map(oe=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${oe.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:oe.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:oe.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:oe.secondary})]},oe.key))}),Me.length>5&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>y(oe=>!oe),children:j?"Show fewer":`Show ${Me.length-5} more`})})]}),(A||r.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:T,onChange:oe=>{const je=oe.target.value;if(z(je),je==="__custom__"){fe();return}K("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:U.length>0?e.jsxs(e.Fragment,{children:[U.map(oe=>e.jsxs("option",{value:oe.id,children:[oe.id===L?"⭐ ":"",Gs(oe.path,oe.label)||oe.path]},oe.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),T==="__custom__"&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx("div",{className:"rounded-2xl border border-border-default/80 bg-bg-primary/80 px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Pt,{size:17})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.08em] text-text-muted mb-1",children:"Selected folder"}),e.jsx("div",{className:"text-[12px] leading-relaxed text-text-primary break-all",children:S||M||"No folder selected yet."})]})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-secondary text-[12px] font-bold",onClick:fe,children:"Select workspace…"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[12px] font-bold disabled:opacity-40",onClick:()=>{S&&w(S)},disabled:!S||F,children:"Save as workspace"})]})]}),S&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:S})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[A&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${ee==="ide"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>ge("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${ee==="cli"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>ge("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${ee==="acp"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>ge("acp"),children:"ACP"})]}),ee&&e.jsxs("div",{className:"flex flex-col gap-2.5 px-4 pt-3",children:[e.jsx("div",{className:"text-xs font-bold text-text-secondary",children:ee==="ide"?"Choose an IDE":ee==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:ee==="ide"?(t.detectedIdes||[]).slice(0,6).map(oe=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:ve}=ht({machine:{workspaces:U,defaultWorkspaceId:L},currentWorkspaceId:T!=="__custom__"?T:null,currentWorkspacePath:S});ye({title:`Launch ${oe.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:je,selectedWorkspaceKey:ve,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:oe.name}]},async()=>{const we=je.find(O=>O.key===X.current);we!=null&&we.workspaceId?(z(we.workspaceId),K("")):we!=null&&we.workspacePath?(z("__custom__"),K(we.workspacePath)):(z(""),K("")),b(oe.type,{workspacePath:(we==null?void 0:we.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:oe.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:S||"Use selected workspace"})]},oe.type)):(ee==="cli"?r:i).map(oe=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:ve}=ht({machine:{workspaces:U,defaultWorkspaceId:L},currentWorkspaceId:T!=="__custom__"?T:null,currentWorkspacePath:S});ye({title:`Launch ${oe.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${ee.toUpperCase()}`,workspaceOptions:je,selectedWorkspaceKey:ve,details:[{label:"Mode",value:ee.toUpperCase()},{label:"Provider",value:oe.displayName}]},async()=>{const we=je.find(O=>O.key===X.current);we!=null&&we.workspaceId?(z(we.workspaceId),K("")):we!=null&&we.workspacePath?(z("__custom__"),K(we.workspacePath)):(z(""),K("")),D(ee,oe.type,{workspaceId:(we==null?void 0:we.workspaceId)??null,workspacePath:(we==null?void 0:we.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[oe.icon?`${oe.icon} `:"",oe.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:S||"Use selected workspace"})]},oe.type))})]}),d.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${d.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[d.message,Z&&e.jsx("div",{className:"mt-2",children:e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[34px] px-4 rounded-lg bg-surface-primary text-text-primary font-bold text-xs",onClick:()=>w(S,{createIfMissing:!0}),children:"Create folder"})})]})]}),e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:C,children:[e.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",c]}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:m,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),H&&e.jsx(nn,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:M,directories:_,busy:F,error:de,confirmLabel:"Use this folder",onClose:()=>J(!1),onNavigate:oe=>{re(oe)},onConfirm:oe=>{K(oe),z("__custom__"),J(!1)}}),ue&&e.jsx(rn,{title:ue.title,description:ue.description,details:ue.details,workspaceOptions:ue.workspaceOptions,selectedWorkspaceKey:me,onWorkspaceChange:oe=>{X.current=oe,se(oe)},confirmLabel:ue.confirmLabel,busy:pe,onConfirm:Ce,onCancel:()=>{te.current=null,xe(null)}}),u&&e.jsx(Ur,{section:f,onSectionChange:h})]})}function kc(t){return Zs(t)}function Un(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=kc(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function Nc(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Xt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function Sc(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function Hn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Cc(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function Ic({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:u,requestedMachineId:x,onRequestedMachineConsumed:h,requestedMobileSection:p,onRequestedMobileSectionConsumed:v,onOpenHistory:m,onOpenRemote:C,onStopCli:b,wsStatus:w,isConnected:N,onShowHiddenConversation:D,onShowAllHiddenConversations:g,onHideConversation:j}){const[y,k]=a.useState(()=>{var O;return((O=t[0])==null?void 0:O.tabKey)||null}),[E,$]=a.useState(()=>t[0]?"chat":"inbox"),[A,U]=a.useState("chats"),[L,T]=a.useState(null),[z,W]=a.useState("inbox"),[K,M]=a.useState("idle"),[P,_]=a.useState(""),[R,F]=a.useState(null),ce=a.useRef(null),de=St(),he="0.8.17",H=a.useMemo(()=>t.find(O=>O.tabKey===y)||t[0]||null,[t,y]),J=a.useMemo(()=>H?n.find(O=>O.id===H.ideId):void 0,[n,H]),ee=a.useMemo(()=>!H||Ae(H)||!Pe(H)?null:Nt(H),[H]),ge=a.useMemo(()=>n.filter(O=>O.type==="adhdev-daemon"||O.daemonMode).sort(Ri),[n]),te=a.useMemo(()=>ge.find(O=>O.id===L)||null,[ge,L]),ue=a.useMemo(()=>Kt(n),[n]),xe=xs({sendDaemonCommand:i,activeConv:H||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),X=a.useCallback(O=>{if(!O||!O.sessionId)return;const B=Et(O,ue),ne=Math.max(Date.now(),jt(O),B.lastUpdated||0);Xt("mark_read:start",{tabKey:O.tabKey,sessionId:O.sessionId,displayPrimary:O.displayPrimary,inboxBucket:B.inboxBucket,unread:B.unread,lastSeenAt:B.lastSeenAt,lastUpdated:B.lastUpdated,activityAt:jt(O),readAt:ne}),i(O.daemonId||O.ideId,"mark_session_seen",{sessionId:O.sessionId,seenAt:ne}).then(le=>{Xt("mark_read:result",{tabKey:O.tabKey,sessionId:O.sessionId,result:le})}).catch(le=>{Xt("mark_read:error",{tabKey:O.tabKey,sessionId:O.sessionId,error:le instanceof Error?le.message:String(le)})})},[ue,i]);a.useEffect(()=>{var B;if(!H){$("inbox"),k(((B=t[0])==null?void 0:B.tabKey)||null),ce.current=null;return}if(E!=="chat"){ce.current=null;return}const O=`${H.tabKey}:${H.sessionId||""}`;ce.current!==O&&(ce.current=O,X(H))},[t,X,E,H]),a.useEffect(()=>{if(!f)return;const O=t.find(B=>B.tabKey===f);O&&(k(O.tabKey),$("chat"),u==null||u())},[t,u,f]),a.useEffect(()=>{if(!x)return;const O=ge.find(B=>B.id===x);O&&(T(O.id),M("idle"),_(""),U("machines"),W("inbox"),$("machine"),h==null||h())},[ge,h,x]),a.useEffect(()=>{p&&(U(p),$("inbox"),v==null||v())},[v,p]);const me=a.useMemo(()=>t.map(O=>{const B=E==="chat"&&(H==null?void 0:H.tabKey)===O.tabKey,ne=Dt(O,ue,{hideOpenTaskCompleteUnread:!0,isOpenConversation:B}),le=jt(O),I=Un(O);return{conversation:O,timestamp:le,preview:I,unread:ne.unread,requiresAction:ne.requiresAction,isWorking:ne.isWorking,inboxBucket:ne.inboxBucket}}),[t,ue,E,H]);a.useEffect(()=>{const O=me.filter(B=>B.inboxBucket==="task_complete"||B.unread);O.length!==0&&Xt("inbox_state",{screen:E,selectedTabKey:y,items:O.map(B=>{const ne=Et(B.conversation,ue);return{liveState:ne,tabKey:B.conversation.tabKey,sessionId:B.conversation.sessionId,displayPrimary:B.conversation.displayPrimary,serverBucket:ne.inboxBucket,computedBucket:B.inboxBucket,serverUnread:ne.unread,computedUnread:B.unread,lastSeenAt:ne.lastSeenAt,lastUpdated:ne.lastUpdated,activityAt:jt(B.conversation)}})})},[me,ue,E,y]);const se=a.useMemo(()=>me.filter(O=>O.requiresAction),[me]),pe=a.useMemo(()=>me.filter(O=>O.unread&&!O.requiresAction),[me]),Y=a.useMemo(()=>me.filter(O=>!O.unread&&!O.requiresAction&&O.isWorking),[me]),ie=a.useMemo(()=>me.filter(O=>!O.unread&&!O.requiresAction&&!O.isWorking),[me]),S=a.useMemo(()=>te?me.filter(O=>O.conversation.daemonId===te.id||O.conversation.ideId===te.id):[],[me,te]),Z=a.useMemo(()=>{if(!te)return[];const O=te.recentLaunches||[];return O.length>0?O.map(B=>({id:B.id,label:B.title||B.providerName||B.providerType,kind:B.kind,providerType:B.providerType,providerSessionId:B.providerSessionId,subtitle:B.currentModel||B.workspace||void 0,workspace:B.workspace,currentModel:B.currentModel})):n.filter(B=>!B.daemonMode&&B.daemonId===te.id).map(B=>{var le,I,q,ae,V;const ne=rs(B)?"cli":_t(B)?"acp":"ide";return{id:`${ne}:${B.type}:${B.workspace||""}`,label:((le=B.activeChat)==null?void 0:le.title)||(rs(B)?B.cliName||B.type:_t(B)&&B.cliName||B.type),kind:ne,providerType:B.type,providerSessionId:B.providerSessionId,subtitle:_t(B)?B.currentModel||B.workspace||void 0:B.workspace||void 0,workspace:B.workspace||void 0,currentModel:B.currentModel,timestamp:((V=(ae=(q=(I=B.activeChat)==null?void 0:I.messages)==null?void 0:q.at)==null?void 0:ae.call(q,-1))==null?void 0:V.timestamp)||0}}).sort((B,ne)=>ne.timestamp-B.timestamp).map(({timestamp:B,...ne})=>ne)},[n,te]),Q=(te==null?void 0:te.version)||(te==null?void 0:te.daemonVersion)||null,re=!!te&&!!Q&&!0&&Q!==he,fe=a.useMemo(()=>(te==null?void 0:te.availableProviders)||[],[te]),ye=a.useMemo(()=>fe.filter(O=>O.category==="cli").map(O=>({type:O.type,displayName:O.displayName||O.type,icon:O.icon})),[fe]),Ce=a.useMemo(()=>fe.filter(O=>O.category==="acp").map(O=>({type:O.type,displayName:O.displayName||O.type,icon:O.icon})),[fe]),Me=a.useMemo(()=>{const O=new Map;for(const B of me){const ne=B.conversation.daemonId||B.conversation.ideId,le=O.get(ne);le?le.push(B):O.set(ne,[B])}return ge.map(B=>{const ne=O.get(B.id)||[],le=[...ne].sort((G,Se)=>Se.timestamp-G.timestamp)[0]||null,I=(le==null?void 0:le.conversation)||null,q=Rs(B),ae=ne.filter(G=>G.unread||G.requiresAction).length,V=B.status==="online"?"Connected":B.status||"Unknown",ke=[B.platform||"machine",V].filter(Boolean);return{id:B.id,label:nt(B,{fallbackId:B.id}),subtitle:ke.join(" · "),unread:ae,total:ne.length,latestConversation:I,latestTimestamp:(le==null?void 0:le.timestamp)||0,fallbackActivityAt:q,preview:I?`${I.displayPrimary} · ${Un(I)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((B,ne)=>{const le=B.latestTimestamp||B.fallbackActivityAt||0,I=ne.latestTimestamp||ne.fallbackActivityAt||0;return I!==le?I-le:B.label.localeCompare(ne.label)})},[me,ge]),Xe=a.useCallback(O=>{k(O.tabKey),$("chat"),X(O)},[X]),We=a.useCallback(O=>{const B=t.find(ne=>ne.ideId===O.ideId&&ne.streamSource==="native");B&&(k(B.tabKey),$("chat"),X(B))},[t,X]),Ge=a.useCallback(()=>{X(H),$("inbox")},[X,H]),Ee=a.useCallback(O=>{T(O),M("idle"),_(""),F(null),U("machines"),W("inbox"),$("machine")},[]),De=a.useCallback(O=>{var ne;const B=O.daemonId||((ne=O.ideId)==null?void 0:ne.split(":")[0])||O.ideId;B&&(T(B),M("idle"),_(""),F(null),U("machines"),W("chat"),$("machine"))},[]),Oe=a.useCallback(()=>{F(null),$(z)},[z]),Ze=a.useCallback(async(O,B,ne)=>{var le;try{M("loading"),_(`Launching ${B}…`);const I={ideType:B,enableCdp:!0};(le=ne==null?void 0:ne.workspacePath)!=null&&le.trim()&&(I.workspace=ne.workspacePath.trim()),await i(O,"launch_ide",I),M("done"),_(`${B} launch requested`)}catch(I){M("error"),_(I instanceof Error?I.message:"Launch IDE failed"),console.error("Launch IDE failed",I)}},[i]),oe=a.useCallback(async(O,B,ne)=>{if(B.trim())try{M("loading"),_(ne!=null&&ne.createIfMissing?"Creating folder…":"Saving workspace…");const le=await i(O,"workspace_add",{path:B.trim(),createIfMissing:(ne==null?void 0:ne.createIfMissing)===!0});if(le!=null&&le.success){M("done"),_(ne!=null&&ne.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}M("error"),_((le==null?void 0:le.error)||"Could not save workspace")}catch(le){M("error"),_(le instanceof Error?le.message:"Could not save workspace")}},[i]),je=a.useCallback(async O=>{var B,ne,le,I,q,ae;try{M("loading"),_("Starting daemon upgrade…");const V=await i(O,"daemon_upgrade",{});if((B=V==null?void 0:V.result)!=null&&B.alreadyLatest){M("done"),_(`Already on v${((ne=V==null?void 0:V.result)==null?void 0:ne.version)||"latest"}.`);return}if((le=V==null?void 0:V.result)!=null&&le.upgraded||(I=V==null?void 0:V.result)!=null&&I.success){M("done"),_(`Upgrade to v${((q=V==null?void 0:V.result)==null?void 0:q.version)||"latest"} started. Daemon is restarting…`);return}M("error"),_(((ae=V==null?void 0:V.result)==null?void 0:ae.error)||"Upgrade failed")}catch(V){M("error"),_(V instanceof Error?V.message:"Upgrade failed")}},[i]),ve=a.useCallback(async(O,B,ne,le)=>{var ae;const I=Date.now(),q={machineId:O,kind:B,providerType:ne,workspaceId:(le==null?void 0:le.workspaceId)||null,workspacePath:(le==null?void 0:le.workspacePath)||null,resumeSessionId:(le==null?void 0:le.resumeSessionId)||null,startedAt:I};try{M("loading"),_(`Launching ${ne}…`),F(q);const V={cliType:ne};(ae=le==null?void 0:le.workspacePath)!=null&&ae.trim()?V.dir=le.workspacePath.trim():le!=null&&le.workspaceId&&(V.workspaceId=le.workspaceId),le!=null&&le.resumeSessionId&&(V.resumeSessionId=le.resumeSessionId);const ke=await i(O,"launch_cli",V),G=(ke==null?void 0:ke.result)||ke,Se=(G==null?void 0:G.sessionId)||(G==null?void 0:G.id);if(ke!=null&&ke.success&&Se){F(null),M("done"),_(`${ne} launched`),de(`/dashboard?activeTab=${encodeURIComponent(Se)}`);return}if(ke!=null&&ke.success){M("loading"),_(`${ne} launch requested — waiting for session…`);return}F(null),M("error"),_((ke==null?void 0:ke.error)||(G==null?void 0:G.error)||`Could not launch ${B.toUpperCase()} workspace`)}catch(V){if(Cc(V)){M("loading"),_(`${ne} launch requested — waiting for session…`);return}F(null),M("error"),_(V instanceof Error?V.message:`Could not launch ${B.toUpperCase()} workspace`)}},[de,i]);a.useEffect(()=>{var le;if(!R)return;const O=Hn(R.workspacePath),B=n.find(I=>{var Se,ze,Ue,Re;if(!I||I.type==="adhdev-daemon"||I.daemonMode||Sc(I.daemonId||I.id)!==R.machineId||(I.transport==="acp"?"acp":I.transport==="pty"?"cli":null)!==R.kind||String(I.agentType||I.ideType||I.type||"")!==R.providerType)return!1;const ke=String(I.providerSessionId||"");if(R.resumeSessionId&&ke)return ke===R.resumeSessionId;if(O){const ot=Hn(I.workspace||I.runtimeWorkspaceLabel);return ot?ot===O:!1}return Number(I.lastUpdated||I._lastUpdate||I.timestamp||((Re=(Ue=(ze=(Se=I.activeChat)==null?void 0:Se.messages)==null?void 0:ze.at)==null?void 0:Ue.call(ze,-1))==null?void 0:Re.timestamp)||0)>=R.startedAt-5e3});if(!B)return;const ne=typeof B.sessionId=="string"&&B.sessionId?B.sessionId:typeof B.instanceId=="string"&&B.instanceId?B.instanceId:(le=t.find(I=>I.ideId===B.id))==null?void 0:le.sessionId;ne&&(F(null),M("done"),_(`${R.providerType} launched`),de(`/dashboard?activeTab=${encodeURIComponent(ne)}`))},[t,n,de,R]),a.useEffect(()=>{if(!R)return;const O=window.setTimeout(()=>{F(B=>!B||B.startedAt!==R.startedAt?B:(M("error"),_("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(O)},[R]);const we=a.useCallback(async O=>{if(te){if(O.kind==="ide"&&O.providerType){await Ze(te.id,O.providerType,{workspacePath:O.workspace||null});return}if((O.kind==="cli"||O.kind==="acp")&&O.providerType){await ve(te.id,O.kind,O.providerType,{workspacePath:O.workspace||null,resumeSessionId:O.providerSessionId||null});return}}},[Ze,ve,te]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:E==="chat"&&H?e.jsx(bc,{selectedConversation:H,isAcp:Ae(H),isStandalone:d,selectedIdeEntry:J,actionLogs:r,userName:l,isSendingChat:xe.isSendingChat,isFocusingAgent:xe.isFocusingAgent,handleModalButton:xe.handleModalButton,handleRelaunch:xe.handleRelaunch,onBack:Ge,onOpenNativeConversation:We,onOpenMachine:De,onHideConversation:j,onOpenHistory:m,onOpenRemote:C,onStopCli:b,cliViewMode:ee,onSetCliViewMode:async O=>{if(H&&ee!==O)try{await i(H.daemonId||H.ideId,"set_cli_view_mode",{targetSessionId:H.sessionId,cliType:H.ideType||H.agentType,mode:O})}catch(B){console.error("Failed to switch CLI view mode:",B)}},handleSendChat:xe.handleSendChat,handleFocusAgent:xe.handleFocusAgent}):E==="machine"&&te?e.jsx(jc,{selectedMachineEntry:te,selectedMachineConversations:S,selectedMachineRecentLaunches:Z,cliProviders:ye,acpProviders:Ce,selectedMachineNeedsUpgrade:re,appVersion:he,machineAction:{state:K,message:P},isStandalone:d,section:A,showBottomNav:z==="inbox",onBack:Oe,onSectionChange:O=>{U(O),$("inbox")},onOpenConversation:Xe,onOpenRecent:we,onOpenMachineDetails:()=>de(`/machines/${te.id}`),onMachineUpgrade:()=>je(te.id),onLaunchDetectedIde:(O,B)=>Ze(te.id,O,B),onAddWorkspace:(O,B)=>oe(te.id,O,B),onBrowseDirectory:async O=>{const B=await i(te.id,"file_list_browse",{path:O});if(!(B!=null&&B.success))throw new Error((B==null?void 0:B.error)||"Could not browse folder");const ne=typeof(B==null?void 0:B.path)=="string"?B.path:O,le=ne.includes("\\")?"\\":"/",I=(ae,V)=>/^[A-Za-z]:\\?$/.test(ae)?`${ae.replace(/\\?$/,"\\")}${V}`:ae==="/"||ae==="\\"?`${le}${V}`:`${ae.replace(/[\\/]+$/,"")}${le}${V}`,q=Array.isArray(B==null?void 0:B.files)?B.files.filter(ae=>(ae==null?void 0:ae.type)==="directory"&&typeof(ae==null?void 0:ae.name)=="string").map(ae=>({name:ae.name,path:I(ne,ae.name)})).sort((ae,V)=>ae.name.localeCompare(V.name)):[];return{path:ne,directories:q}},onLaunchWorkspaceProvider:(O,B,ne)=>ve(te.id,O,B,ne)}):e.jsx(yc,{section:A,attentionItems:se,unreadItems:pe,workingItems:Y,completedItems:ie,hiddenConversations:s,machineCards:Me,getAvatarText:Nc,onOpenConversation:Xe,onShowConversation:D,onShowAllHidden:g,onOpenMachine:Ee,onOpenSettings:()=>de("/settings"),onSectionChange:U,wsStatus:w,isConnected:N,isStandalone:d})})}function Ms(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Mc({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,u]=a.useState(null),x=a.useCallback(()=>{c.current=0,l(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",x),window.addEventListener("drop",x),()=>{window.removeEventListener("dragend",x),window.removeEventListener("drop",x)}),[x]);const h=a.useCallback(C=>{C.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),p=a.useCallback(C=>{if(!C.dataTransfer.types.includes("text/tab-key"))return;if(C.preventDefault(),!Ms(s,n)){u("merge");return}const b=C.currentTarget.getBoundingClientRect(),w=C.clientX-b.left,N=b.width/3;w<N?u("split-left"):w>N*2?u("split-right"):u("merge")},[s,n]),v=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),m=a.useCallback(C=>{c.current=0,l(!1);const b=C.dataTransfer.getData("text/tab-key"),w=b?t.some(D=>D.tabKey===b):!1,N=f;if(u(null),o(),!!b){if(C.preventDefault(),N==="split-left"&&Ms(s,n)){n==null||n(b,"split-left");return}if(N==="split-right"&&Ms(s,n)){n==null||n(b,"split-right");return}if(w){i(b);return}r==null||r(b)}},[t,f,s,n,r,i,o]);return{dragOver:d,dropAction:f,resetDragState:x,handleDragEnter:h,handleDragOver:p,handleDragLeave:v,handleDrop:m}}function _c(t,s){const n=new Set(s.map(o=>o.tabKey)),r=t.filter(o=>n.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...r,...i]}function Tc({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,u]=a.useState(null),x=a.useRef(null),h=a.useRef(null),p=a.useRef(r),v=a.useRef(i);a.useEffect(()=>{p.current=r},[r]),a.useEffect(()=>{v.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(y=>{const k=_c(y,t);return k.length===y.length&&k.every((E,$)=>E===y[$])?y:k})},[t]);const m=a.useMemo(()=>{const y=f??d;if(y.length===0)return t;const k=new Map(y.map((E,$)=>[E,$]));return[...t].sort((E,$)=>{const A=k.get(E.tabKey)??999,U=k.get($.tabKey)??999;return A-U})},[t,f,d]);a.useEffect(()=>{var k,E;if(m.length===0){o!==null&&(c(null),(k=p.current)==null||k.call(p,null));return}if(o&&m.some($=>$.tabKey===o))return;const y=m[0].tabKey;y!==o&&(c(y),(E=p.current)==null||E.call(p,y))},[m,o]);const C=a.useMemo(()=>m.find(y=>y.tabKey===o),[m,o]),b=a.useCallback(y=>{var k;c(y),(k=p.current)==null||k.call(p,y)},[]),w=a.useCallback((y,k,E)=>{l($=>{var T;const A=$.filter(z=>z!==y),U=A.indexOf(k);if(U<0)return $;const L=E==="left"?U:U+1;return A.splice(L,0,y),(T=v.current)==null||T.call(v,A),A}),u(null)},[]),N=a.useCallback((y,k,E)=>{const A=(d.length>0?d:t.map(T=>T.tabKey)).filter(T=>T!==y),U=A.indexOf(k);if(U<0)return;const L=E==="left"?U:U+1;A.splice(L,0,y),x.current=A,u(A)},[d,t]),D=a.useCallback(()=>{var k;const y=x.current;y&&(l(y),(k=v.current)==null||k.call(v,y))},[]),g=a.useCallback(()=>{x.current=null,u(null)},[]),j=a.useCallback(y=>{l(k=>{var $;const E=k.filter(A=>A!==y);return E.push(y),($=v.current)==null||$.call(v,E),E})},[]);return{activeTabId:o,activeConv:C,sortedConversations:m,previewOrderRef:x,draggingTabRef:h,selectTab:b,handleTabReorder:w,updatePreviewOrder:N,commitPreviewOrder:D,clearPreviewOrder:g,moveTabToEnd:j,setDraggingTabKey:y=>{h.current=y}}}function Ac({dropAction:t,canSplit:s}){return e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function an({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:i}){return t===0&&!s&&r&&i?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(zr,{}),n&&r.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(o=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>i(o.type),children:[e.jsx(ur,{size:14,className:"opacity-70"})," Launch ",o.name]},o.type))})]}),!n&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}const Fr="adhdev-tab-shortcuts";function Lc(){try{return JSON.parse(localStorage.getItem(Fr)||"{}")}catch{return{}}}function Rc({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Lc()),[c,d]=a.useState(null),l=a.useCallback(u=>{const x=[];return u.metaKey&&x.push(r?"⌘":"Meta"),u.ctrlKey&&x.push("Ctrl"),u.altKey&&x.push(r?"⌥":"Alt"),u.shiftKey&&x.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(x.push(u.key.length===1?u.key.toUpperCase():u.key),x.join("+"))},[r]),f=a.useCallback(u=>{o(u);try{localStorage.setItem(Fr,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=x=>{if(x.preventDefault(),x.stopPropagation(),x.key==="Escape"){d(null);return}const h=l(x);if(!h)return;const p={...i};for(const[v,m]of Object.entries(p))m===h&&delete p[v];p[c]=h,f(p),d(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,f,l]),a.useEffect(()=>{const u=x=>{if(!(!x.ctrlKey&&!x.metaKey&&!x.altKey)){for(const[h,p]of Object.entries(i))if(t.includes(h)&&l(x)===p){x.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const $c=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:u,onPreviewReorder:x,onReorderTab:h,onCommitPreviewOrder:p,onClearPreviewOrder:v,onDragStateReset:m,onDragTabKeyChange:C,onReceiveTab:b,onOpenContextMenu:w,longPressTimer:N,isGroupActive:D}){const g=ms(s),j=g.isGenerating?"agent-tab-generating":g.isWaiting?"agent-tab-waiting":"",y=g.isReconnecting,k=a.useCallback(K=>{d.current=s.tabKey,C(s.tabKey),K.dataTransfer.setData("text/tab-key",s.tabKey),K.dataTransfer.effectAllowed="move"},[s.tabKey,d,C]),E=a.useCallback(()=>{d.current=null,C(null),p(),v(),m()},[d,C,p,v,m]),$=a.useCallback(K=>{const M=d.current;if(!(!M||M===s.tabKey)&&K.dataTransfer.types.includes("text/tab-key")){K.preventDefault(),K.stopPropagation();const P=K.currentTarget.getBoundingClientRect(),_=K.clientX<P.left+P.width/2?"left":"right";x(M,s.tabKey,_)}},[s.tabKey,d,x]),A=a.useCallback(K=>{K.preventDefault(),K.stopPropagation();const M=K.dataTransfer.getData("text/tab-key");if(M&&M!==s.tabKey){const P=K.currentTarget.getBoundingClientRect(),_=K.clientX<P.left+P.width/2?"left":"right";c.includes(M)?h(M,s.tabKey,_):b&&b(M)}v()},[s.tabKey,c,h,b,v]),U=a.useCallback(K=>{K.stopPropagation(),l(),f(s.tabKey),u(s)},[s,u,l,f]),L=a.useCallback(K=>{K.preventDefault(),w(K.clientX,K.clientY,s.tabKey)},[s.tabKey,w]),T=a.useCallback(K=>{const M=K.touches[0];N.current=setTimeout(()=>{w(M.clientX,M.clientY,s.tabKey)},600)},[s.tabKey,N,w]),z=a.useCallback(()=>{N.current&&clearTimeout(N.current)},[N]),W=["adhdev-dockview-tab",j,n&&"is-active",D&&"is-group-active",y&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:W,draggable:!0,onDragStart:k,onDragEnd:E,onDragOver:$,onDrop:A,onClick:U,onContextMenu:L,onTouchStart:T,onTouchEnd:z,onTouchMove:z,style:{cursor:"pointer",opacity:r?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:g.isGenerating?e.jsx("div",{className:"tab-spinner"}):g.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):y?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):g.isConnecting?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("span",{className:"adhdev-dockview-tab-primary",title:s.displayPrimary,children:s.displayPrimary}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:y?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):g.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[s.displaySecondary,s.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",s.machineName]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.isTaskCompleteUnread===s.isTaskCompleteUnread&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys&&t.isGroupActive===s.isGroupActive);function Pc({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:v,onMoveTab:m,onReceiveTab:C,onHideTab:b,isGroupActive:w}){const[N,D]=a.useState(null),g=a.useRef(null),j=a.useRef(null),y=a.useMemo(()=>t.map(T=>T.tabKey),[t]);Bt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(N==null?void 0:N.tabKey)||null});const{isMac:k,tabShortcuts:E,shortcutListening:$,setShortcutListening:A,saveShortcuts:U}=Rc({sortedTabKeys:t.map(T=>T.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!N)return;const T=z=>{const W=document.querySelector("[data-pane-context-menu]");W&&W.contains(z.target)||D(null)};return window.addEventListener("mousedown",T,!0),()=>window.removeEventListener("mousedown",T,!0)},[N]),a.useEffect(()=>{const T=j.current;if(!T)return;const z=W=>{Math.abs(W.deltaY)>Math.abs(W.deltaX)&&(W.preventDefault(),T.scrollLeft+=W.deltaY)};return T.addEventListener("wheel",z,{passive:!1}),()=>T.removeEventListener("wheel",z)},[]);const L=a.useCallback((T,z,W)=>{D({x:T,y:z,tabKey:W})},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:e.jsxs("div",{ref:j,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(T=>e.jsx($c,{conv:T,isActive:s===T.tabKey,isDraggedTab:o.current===T.tabKey,isTaskCompleteUnread:i.has(T.tabKey),shortcut:E[T.tabKey],conversationKeys:y,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:v,onReceiveTab:C,onOpenContextMenu:L,longPressTimer:g,isGroupActive:w},T.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),N&&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:N.x,top:N.y},children:[m&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(N.tabKey,"left"),D(null)},children:"← Move to Left Group"}),m&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(N.tabKey,"right"),D(null)},children:"Move to Right Group →"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(N.tabKey,"split-left"),D(null)},children:"⇤ Split Left"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(N.tabKey,"split-right"),D(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:T=>{T.stopPropagation(),A(N.tabKey),D(null)},children:["⌨ ",E[N.tabKey]?`Change shortcut (${E[N.tabKey]})`:"Set shortcut"]}),E[N.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 T={...E};delete T[N.tabKey],U(T),D(null)},children:"✕ Remove shortcut"}),b&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{b(N.tabKey),D(null)},children:"🚫 Hide from Dashboard"})]}),!m&&!b&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),$&&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:T=>T.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",k?"⌘+1":"Ctrl+1",", ",k?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function Ec({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:u,isSplitMode:x,numGroups:h,onMoveTab:p,onReceiveTab:v,style:m,detectedIdes:C,handleLaunchIde:b,onActiveTabChange:w,initialActiveTabId:N,initialTabOrder:D,onTabOrderChange:g,onHideTab:j,isFocused:y}){const{sendCommand:k}=ut(),E=a.useRef(null),{activeTabId:$,activeConv:A,sortedConversations:U,draggingTabRef:L,selectTab:T,handleTabReorder:z,updatePreviewOrder:W,commitPreviewOrder:K,clearPreviewOrder:M,moveTabToEnd:P,setDraggingTabKey:_}=Tc({conversations:t,initialActiveTabId:N,initialTabOrder:D,onActiveTabChange:w,onTabOrderChange:g}),R=xs({sendDaemonCommand:i,activeConv:A,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:F,dropAction:ce,resetDragState:de,handleDragEnter:he,handleDragOver:H,handleDragLeave:J,handleDrop:ee}=Mc({conversations:t,numGroups:h,onMoveTab:p,onReceiveTab:v,onOwnTabDrop:P,onClearPreviewOrder:M}),ge=A&&!Ae(A)&&Nt(A)==="terminal",te=a.useMemo(()=>A?s.find(se=>se.id===A.ideId):void 0,[s,A]),ue=a.useMemo(()=>A?r.filter(se=>se.ideId===A.tabKey):[],[r,A]),xe=a.useMemo(()=>Kt(s),[s]),X=a.useMemo(()=>new Set(U.filter(se=>hi(se,xe,{isOpenConversation:se.tabKey===$})).map(se=>se.tabKey)),[$,xe,U]);Bt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:$,dragOver:F});const me=a.useCallback(se=>{se.streamSource==="agent-stream"&&se.agentType&&k(se.ideId,"focus_session",{agentType:se.agentType,...se.sessionId&&{targetSessionId:se.sessionId}}).catch(()=>{})},[k]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...m,outline:F?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Pc,{conversations:U,activeTabId:$,groupIndex:f,numGroups:h,unreadTabKeys:X,draggingTabRef:L,onFocus:u,onSelectTab:T,onConversationActivated:me,onPreviewReorder:W,onReorderTab:z,onCommitPreviewOrder:K,onClearPreviewOrder:M,onDragStateReset:de,onDragTabKeyChange:_,onMoveTab:p,onReceiveTab:v,onHideTab:j,isGroupActive:y??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:he,onDragOver:H,onDragLeave:J,onDrop:ee,children:[F&&e.jsx(Ac,{dropAction:ce,canSplit:!!(h<4&&p)}),A?e.jsx(tn,{activeConv:A,clearToken:n[A.tabKey]||0,isCliTerminal:!!ge,ideEntry:te,terminalRef:E,handleModalButton:R.handleModalButton,handleRelaunch:R.handleRelaunch,handleSendChat:R.handleSendChat,isSendingChat:R.isSendingChat,handleFocusAgent:R.handleFocusAgent,isFocusingAgent:R.isFocusingAgent,actionLogs:ue,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(an,{conversationsCount:t.length,isSplitMode:x,isStandalone:d,detectedIdes:C,handleLaunchIde:b})})]})]})}function Dc({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,focusedGroup:p,setFocusedGroup:v,moveTabToGroup:m,splitTabRelative:C,closeGroup:b,handleResizeStart:w,detectedIdes:N,handleLaunchIde:D,groupActiveTabIds:g,setGroupActiveTabIds:j,groupTabOrders:y,setGroupTabOrders:k,toggleHiddenTab:E}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map(($,A)=>{const U=s&&r.length===n?`${r[A]}%`:void 0;return e.jsxs(Os.Fragment,{children:[s&&A>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:L=>w(A-1,L),onDoubleClick:()=>b(A),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(Ec,{style:s?{flexBasis:U??`${100/n}%`,flexGrow:U?0:1,flexShrink:U?0:1}:void 0,conversations:$,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,groupIndex:A,isFocused:s&&p===A,onFocus:()=>v(A),isSplitMode:s,numGroups:n,onMoveTab:(L,T)=>{T==="left"&&A>0?m(L,A-1):T==="right"&&A<n-1?m(L,A+1):T==="split-left"&&n<4?C(L,A,"left"):T==="split-right"&&n<4&&C(L,A,"right")},onReceiveTab:L=>m(L,A),detectedIdes:A===0?N:void 0,handleLaunchIde:A===0?D:void 0,onActiveTabChange:L=>j(T=>(T[A]??null)===(L??null)?T:{...T,[A]:L}),initialActiveTabId:g[A],initialTabOrder:y[A],onTabOrderChange:L=>k(T=>{const z=T[A]||[];return z.length===L.length&&z.every((W,K)=>W===L[K])?T:{...T,[A]:L}}),onHideTab:E})]},A)})})}function Vr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?$e.onScreenshot("ide-page",(p,v)=>{if(p!==t)return;const m=new FileReader;m.onload=()=>d(m.result),m.readAsDataURL(v)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var p;return t?((p=$e.onStatus)==null?void 0:p.call($e,(v,m)=>{v===t&&m!=null&&m.screenshotUsage&&f(m.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,u]),a.useEffect(()=>{const h=t?$e.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&u?h.startScreenshots(u):h.stopScreenshots(u),()=>{h.stopScreenshots(u)}},[i,r,u,t]);const x=a.useCallback(async(h,p)=>{const v=t?$e.get(t):null;return!v||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):v.sendInput(h,p,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:x}}const qr=a.createContext(null);function fs(){const t=a.useContext(qr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function es(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Bc(t){return`remote:${t}`}function ls(t){return t.startsWith("remote:")}function hs(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function Kc(t){const[,s]=a.useState(0);a.useEffect(()=>{const n=()=>s(i=>i+1),r=[t.api.onDidActiveGroupChange(n),t.api.onDidTitleChange(n),t.api.onDidGroupChange(n),t.containerApi.onDidActivePanelChange(n)];return()=>{for(const i of r)i.dispose()}},[t.api,t.containerApi])}function Wc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const u of l){const x=t.addPanel({id:u.tabKey,component:"conversation",title:es(u),params:{kind:"conversation",tabKey:u.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=x.id)}i=f??i}const o=n??((d=s[0])==null?void 0:d.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Fn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])ls(r.id)||n.has(r.id)||t.removePanel(r);for(const r of s){const i=t.getPanel(r.tabKey);if(i){i.update({params:{tabKey:r.tabKey}}),i.title!==es(r)&&i.api.setTitle(es(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:es(r),params:{kind:"conversation",tabKey:r.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Vn(t,s,n){var l,f;const r=n?Bc(n):null;for(const u of[...t.panels])ls(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=hs(s,n);if(!i&&t.totalPanels===0)return;const o=t.getPanel(r),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const d=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(u=>!ls(u.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...d?{position:{referencePanel:d,direction:"right"},inactive:!0}:{}})}function Oc({params:t}){const s=fs(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=xs({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(l=>l.id===r.ideId):void 0,[s.ides,r]),c=a.useMemo(()=>r?s.actionLogs.filter(l=>l.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(an,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!Ae(r)&&Nt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(tn,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:d,ideEntry:o,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:c,userName:s.userName})})}function zc({params:t}){var l;const s=fs(),n=a.useMemo(()=>hs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:d}=Vr({doId:i,ideId:t.ideId,ideType:(n==null?void 0:n.ideType)||(r==null?void 0:r.type),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote",instanceId:r==null?void 0:r.instanceId});return n?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(mr,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:d})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function Uc(){const t=fs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(an,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Hc(t){var x,h;Kc(t);const s=fs();if(t.params.kind==="remote"){const p=hs([...s.conversationsByTabKey.values()],t.params.ideId),v=((x=t.api.group.activePanel)==null?void 0:x.id)===t.api.id,m=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${v?" is-active":""}${m?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:p!=null&&p.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:p.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const r=((h=t.api.group.activePanel)==null?void 0:h.id)===t.api.id,i=t.api.isGroupActive,o=Dt(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,u=o.unread;return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,children:[u&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:l?e.jsx("div",{className:"tab-spinner"}):f?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:c?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]})]})}function Fc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:u,toggleHiddenTab:x,onActiveTabChange:h,requestedActiveTabKey:p,requestedRemoteIdeId:v,onRequestedActiveTabConsumed:m}){const{theme:C}=Tr(),{sendCommand:b}=ut(),w=a.useRef(null),N=a.useRef(null),D=a.useRef(!1),[g,j]=a.useState(!1),[y,k]=a.useState(!1),E=a.useRef(null),$=a.useMemo(()=>Kr(typeof window<"u"?window.innerWidth:1280),[]),A=a.useMemo(()=>new Map(t.map(R=>[R.tabKey,R])),[t]),U=a.useMemo(()=>Kt(n),[n]),L=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:A,detectedIdes:f,handleLaunchIde:u,ides:n,isStandalone:d,liveSessionInboxState:U,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:x,userName:l}),[r,s,A,f,u,n,d,U,i,c,o,x,l]),T=a.useCallback(R=>{if(!R)return!1;const F=w.current;if(!F)return!1;const ce=F.getPanel(R);return ce?(ce.group.model.openPanel(ce),m==null||m(),!0):!1},[m]),z=a.useCallback(()=>{const R=N.current;if(!R)return;const F=R.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const ce of F)ce.setAttribute("data-adhdev-force-hidden","true")},[]),W=a.useCallback(()=>{const R=N.current;if(!R)return;const F=R.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const ce of F)ce.removeAttribute("data-adhdev-force-hidden")},[]),K=a.useCallback(()=>{const R=N.current;if(!R)return;const F=R.querySelectorAll(".dv-drop-target-container");for(const he of F)he.remove();const ce=R.querySelectorAll(".dv-drop-target-dropzone");for(const he of ce)he.remove();const de=R.querySelectorAll(".dv-drop-target");for(const he of de)he.classList.remove("dv-drop-target")},[]),M=a.useCallback(()=>{j(!1),k(!1),W(),z(),K(),!(typeof window>"u")&&(E.current!=null&&window.clearTimeout(E.current),window.requestAnimationFrame(()=>{z(),K()}),E.current=window.setTimeout(()=>{z(),K(),E.current=null},80))},[W,z,K]),P=a.useCallback(R=>{var ce;w.current=R.api;const F=ac($);F!=null&&F.layout&&R.api.fromJSON(F.layout,{reuseExistingPanels:!1}),Fn(R.api,t),Vn(R.api,t,v),R.api.totalPanels===0&&t.length>0?Wc(R.api,t,p):T(p)||T(F==null?void 0:F.activeTabId),D.current=!0,R.api.onDidActivePanelChange(de=>{var H;if(de&&ls(de.id)){const J=((H=de.params)==null?void 0:H.ideId)||de.id.slice(7),ee=hs(t,J);h((ee==null?void 0:ee.tabKey)??null);return}if(h((de==null?void 0:de.id)??null),!de)return;const he=A.get(de.id);(he==null?void 0:he.streamSource)==="agent-stream"&&he.agentType&&b(he.ideId,"focus_session",{agentType:he.agentType,...he.sessionId&&{targetSessionId:he.sessionId}}).catch(()=>{})}),R.api.onDidLayoutChange(()=>{var de;ic($,{activeTabId:((de=R.api.activePanel)==null?void 0:de.id)??null,layout:R.api.toJSON()})}),R.api.onWillDragPanel(()=>{j(!0),k(!1),z()}),R.api.onWillDragGroup(()=>{j(!0),k(!1),z()}),R.api.onWillShowOverlay(()=>{W(),k(!0)}),R.api.onDidMovePanel(M),R.api.onDidDrop(M),h(((ce=R.api.activePanel)==null?void 0:ce.id)??null)},[T,M,W,A,$,z,K,h,p,b,t]);a.useEffect(()=>{const R=w.current;!R||!D.current||(Fn(R,t),Vn(R,t,v),!R.activePanel&&R.panels[0]&&R.panels[0].group.model.openPanel(R.panels[0]))},[v,t]),a.useEffect(()=>{D.current&&T(p)},[T,p]),a.useEffect(()=>{if(!g||typeof window>"u")return;const R=()=>M();return window.addEventListener("pointerup",R),window.addEventListener("mouseup",R),window.addEventListener("dragend",R),()=>{window.removeEventListener("pointerup",R),window.removeEventListener("mouseup",R),window.removeEventListener("dragend",R)}},[M,g]),a.useEffect(()=>()=>{typeof window>"u"||E.current!=null&&window.clearTimeout(E.current)},[]),a.useEffect(()=>{const R=F=>{const ce=F.target;if(!ce)return;const de=ce.querySelector("[data-tab-key]")||ce.closest("[data-tab-key]");if(de){const he=de.getAttribute("data-tab-key");he&&F.dataTransfer&&F.dataTransfer.setData("text/tab-key",he)}};return window.addEventListener("dragstart",R),()=>window.removeEventListener("dragstart",R)},[]);const _=C==="light"?Ia:Ma;return e.jsx(qr.Provider,{value:L,children:e.jsx("div",{ref:N,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(Ca,{className:`h-full min-h-0 min-w-0 adhdev-dockview${g?" is-dragging-dockview":""}${y?" is-showing-dockview-overlay":""}`,components:{conversation:Oc,remote:zc},defaultTabComponent:Hc,watermarkComponent:Uc,onReady:P,singleTabMode:"default",tabAnimation:"smooth",theme:_})})})}function Vc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:u,mobileChatConversations:x,hiddenConversations:h,ides:p,actionLogs:v,sendDaemonCommand:m,setLocalUserMessages:C,setActionLogs:b,isStandalone:w,userName:N,requestedMobileTabKey:D,onRequestedMobileTabConsumed:g,requestedMachineId:j,onRequestedMachineConsumed:y,requestedMobileSection:k,onRequestedMobileSectionConsumed:E,containerRef:$,isSplitMode:A,numGroups:U,groupSizes:L,groupedConvs:T,clearedTabs:z,focusedGroup:W,setFocusedGroup:K,moveTabToGroup:M,splitTabRelative:P,closeGroup:_,handleResizeStart:R,detectedIdes:F,handleLaunchIde:ce,groupActiveTabIds:de,setGroupActiveTabIds:he,groupTabOrders:H,setGroupTabOrders:J,toggleHiddenTab:ee,visibleConversations:ge,requestedDesktopTabKey:te,onRequestedDesktopTabConsumed:ue,onDesktopActiveTabChange:xe,onHideConversation:X,onShowHiddenConversation:me,onShowAllHiddenConversations:se}){return Os.useEffect(()=>{const pe=Y=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?Y.metaKey&&Y.key.toLowerCase()==="w":Y.ctrlKey&&Y.key.toLowerCase()==="w")&&(Y.preventDefault(),n&&X&&X(n))};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[n,X]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Hi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:ge,hiddenConversations:h,onOpenHistory:c,onOpenConversation:me,onHideConversation:X,onShowConversation:me,onShowAllHidden:se,onOpenRemote:()=>{!n||Pe(n)||Ae(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:u}),t?e.jsx(Ic,{conversations:x,hiddenConversations:h,ides:p,actionLogs:v,sendDaemonCommand:m,setLocalUserMessages:C,setActionLogs:b,isStandalone:w,userName:N,requestedActiveTabKey:D,onRequestedActiveTabConsumed:g,requestedMachineId:j,onRequestedMachineConsumed:y,requestedMobileSection:k,onRequestedMobileSectionConsumed:E,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:me,onShowAllHiddenConversations:se}):s?e.jsx(Dc,{containerRef:$,isSplitMode:A,numGroups:U,groupSizes:L,groupedConvs:T,clearedTabs:z,ides:p,actionLogs:v,sendDaemonCommand:m,setLocalUserMessages:C,setActionLogs:b,isStandalone:w,userName:N,focusedGroup:W,setFocusedGroup:K,moveTabToGroup:M,splitTabRelative:P,closeGroup:_,handleResizeStart:R,detectedIdes:F,handleLaunchIde:ce,groupActiveTabIds:de,setGroupActiveTabIds:he,groupTabOrders:H,setGroupTabOrders:J,toggleHiddenTab:ee}):e.jsx(Fc,{visibleConversations:ge,clearedTabs:z,ides:p,actionLogs:v,sendDaemonCommand:m,setLocalUserMessages:C,setActionLogs:b,isStandalone:w,userName:N,detectedIdes:F,handleLaunchIde:ce,toggleHiddenTab:ee,onActiveTabChange:xe,requestedActiveTabKey:te,onRequestedActiveTabConsumed:ue})]})}const _s=[{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 qc({onClose:t}){const[s,n]=a.useState(0),r=_s[s],i=s===_s.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:_s.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
48
- @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
49
- @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
50
- `})]})}function Gc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:i}){return t?e.jsxs("div",{className:"flex border-b border-border-subtle bg-surface-primary shrink-0",children:[e.jsx("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] ${n==="native"?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i("native"),children:s}),r.map(o=>{const c=n===o.tabKey,d=o.status==="waiting_approval",l=o.status==="generating";return e.jsxs("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] flex items-center justify-center gap-1.5 ${c?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{className:"shrink-0",style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:d?"var(--status-warning)":l?"var(--accent-primary)":"var(--text-muted)",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&e.jsx("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-[10px] font-bold ml-0.5",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)"},children:"!"})]},o.tabKey)})]}):null}function Yc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>kr(s),[s]),f=a.useMemo(()=>{var C;if(!t)return[];const m=t.daemonId||((C=t.id)==null?void 0:C.split(":")[0])||t.id;return Nr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[m]||"new"})},[t,r,l,n]),u=a.useMemo(()=>f.find(m=>m.streamSource==="native"),[f]),x=a.useMemo(()=>f.filter(m=>m.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var m;c!=="native"&&(x.some(C=>C.tabKey===c)||d(((m=x[0])==null?void 0:m.tabKey)||"native"))},[c,x]),a.useEffect(()=>{c==="native"&&(u||x[0]&&d(x[0].tabKey))},[c,u,x]);const h=a.useMemo(()=>c==="native"&&u?u:x.find(m=>m.tabKey===c)||u||x[0],[c,u,x]),p=a.useMemo(()=>x.map(m=>({tabKey:m.tabKey,title:m.title||m.agentName||i,status:m.status})),[x,i]),v=a.useCallback(m=>{if(m)return f.find(C=>C.sessionId===m||C.ideId===m||C.tabKey===m||C.ideType===m||C.agentType===m)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:v}}function Xc({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:u,onOpenHistory:x,onConversationChange:h,onClose:p}){var z;const[v,m]=a.useState("split"),[C,b]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),w=a.useMemo(()=>s||n.find(W=>W.id===t.ideId),[t.ideId,s,n]),N=a.useMemo(()=>Te((w==null?void 0:w.type)||""),[w==null?void 0:w.type]),{conversations:D,extensionTabs:g,hasExtensions:j}=Yc({ideData:w,allIdes:n,connectionStates:r,localUserMessages:o,ideName:N||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{b(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const y=a.useMemo(()=>C==="native"?D.find(W=>W.streamSource==="native")||t:D.find(W=>W.tabKey===C)||t,[t,D,C]),k=y.daemonId||((z=y.ideId)==null?void 0:z.split(":")[0])||y.ideId,E=xs({sendDaemonCommand:c,activeConv:y,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:$,screenshotUsage:A,handleRemoteAction:U}=Vr({doId:k,ideId:y.ideId,ideType:y.ideType,connState:y.connectionState||"new",viewMode:v,instanceId:w==null?void 0:w.instanceId}),L=a.useMemo(()=>i.filter(W=>W.ideId===y.tabKey),[i,y.tabKey]);a.useEffect(()=>{h==null||h(y)},[y,h]),a.useEffect(()=>{const W=K=>{K.key==="Escape"&&p()};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[p]);const T=a.useCallback(W=>{W.stopPropagation()},[]);return e.jsx("div",{className:"fixed inset-0 z-[1200] flex items-center justify-center p-0 md:p-3 bg-[#030617]/[0.56] backdrop-blur-md",onClick:p,children:e.jsxs("div",{className:"w-full h-[100dvh] md:h-[calc(100vh-24px)] md:w-[calc(100vw-24px)] flex flex-col overflow-hidden md:rounded-[14px] md:border border-border-default bg-surface-primary shadow-[0_24px_80px_rgba(2,6,23,0.32)]",role:"dialog","aria-modal":"true",onClick:T,children:[e.jsxs("div",{className:"sticky top-0 z-20 flex flex-col gap-3 md:flex-row md:items-center md:justify-between px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-3 border-b border-border-subtle bg-bg-primary/96 backdrop-blur-md shrink-0 overflow-visible",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 min-w-0 w-full md:w-auto md:flex-1",children:[e.jsx("div",{className:"min-w-0 flex-1 flex flex-col justify-center",children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 font-extrabold text-[18px] md:text-xl tracking-tight text-text-primary",children:[e.jsx("span",{className:"w-7 h-7 flex items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Ve,{size:16})}),e.jsx("span",{className:"truncate",children:y.displayPrimary||y.agentName||"Remote"})]})}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold md:hidden shrink-0",onClick:p,children:"Close"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full md:w-auto justify-between md:justify-end",children:[e.jsx("div",{className:"flex items-center gap-2 mr-auto md:mr-0",children:["split","remote"].map(W=>{const K=v===W;return e.jsx("button",{className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${K?"bg-accent-primary/12 border border-accent-primary/35 text-accent-primary shadow-glow":"bg-bg-secondary border border-border-subtle text-text-secondary hover:bg-bg-glass hover:text-text-primary"}`,onClick:()=>m(W),title:W==="split"?"Split view":"Remote only",children:W==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(Ve,{size:15})},W)})}),e.jsx("div",{className:"hidden md:block w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-2.5 md:px-3 rounded-lg",onClick:()=>x(y),title:"Chat History",children:[e.jsx(Hs,{size:14,className:"md:mr-1.5"}),e.jsx("span",{className:"hidden md:inline",children:"History"})]}),e.jsx("button",{className:"hidden md:inline-flex btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:p,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${v==="split"?"grid-cols-1 grid-rows-[1fr_minmax(320px,42vh)] md:grid-cols-[minmax(360px,0.92fr)_minmax(420px,1.08fr)] md:grid-rows-1":"grid-cols-1 grid-rows-1"}`,children:[v!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${v==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(Gc,{hasExtensions:j,ideName:N||"IDE",activeChatTab:C,extensionTabs:g,onSelectTab:b}),e.jsx(fr,{activeConv:y,onModalButton:E.handleModalButton}),e.jsx(Ps,{activeConv:y,ideEntry:w,showMetaChips:!1,handleSendChat:E.handleSendChat,isSendingChat:E.isSendingChat,handleFocusAgent:E.handleFocusAgent,isFocusingAgent:E.isFocusingAgent,actionLogs:L,userName:u})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${v==="split"?"order-1 md:order-2":""}`,children:e.jsx(mr,{addLog:()=>{},connState:y.connectionState||"new",connScreenshot:$,screenshotUsage:A,transportType:y.transport,onAction:U})})]})]})})}function Zc({activeConv:t,canSaveAndStop:s=!1,onCancel:n,onStopNow:r,onSaveAndStop:i}){const o=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1400] flex items-center justify-center p-4",children:[e.jsx("div",{onClick:n,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[min(92vw,420px)] md:w-[92%] md:max-w-[420px] flex flex-col overflow-hidden rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-base md:text-lg font-extrabold",children:["Stop ",o,"?"]}),e.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:s?"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first.":"The CLI runtime will stop immediately. This provider does not expose save-and-stop."})]}),e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s&&e.jsx("button",{onClick:i,className:"btn btn-primary w-full justify-center min-h-[42px]",children:"Save and stop"}),e.jsx("button",{onClick:r,className:"btn btn-secondary w-full justify-center min-h-[42px] text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:"Cancel"})]})]})]})}function Jc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:u,onRefreshHistory:x,onResumeSavedHistorySession:h,remoteDialogConv:p,remoteDialogIdeEntry:v,connectionStates:m,actionLogs:C,localUserMessages:b,sendDaemonCommand:w,setLocalUserMessages:N,setActionLogs:D,isStandalone:g,userName:j,onOpenRemoteHistory:y,onRemoteConversationChange:k,onCloseRemoteDialog:E,cliStopDialogOpen:$,cliStopTargetConv:A,onCancelCliStop:U,onStopCliNow:L,onSaveCliAndStop:T,toasts:z,onDismissToast:W,onClickToast:K,showOnboarding:M,onCloseOnboarding:P}){var _;return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Vi,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:u,onRefreshHistory:x,onResumeSavedSession:h}),p&&e.jsx(Xc,{activeConv:p,ideEntry:v,ides:n,connectionStates:m,actionLogs:C,localUserMessages:b,sendDaemonCommand:w,setLocalUserMessages:N,setActionLogs:D,isStandalone:g,userName:j,onOpenHistory:y,onConversationChange:k,onClose:E}),$&&A&&Pe(A)&&!Ae(A)&&e.jsx(Zc,{activeConv:A,canSaveAndStop:!!((_=A.resume)!=null&&_.supported),onCancel:U,onStopNow:L,onSaveAndStop:T}),e.jsx(jr,{toasts:z,onDismiss:W,onClickToast:K}),M&&e.jsx(qc,{onClose:P})]})}function Qc({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,onDismiss:i}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 border-b text-xs text-text-secondary shrink-0 flex-wrap",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",borderColor:"color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",style:{color:"var(--status-warning)"},children:e.jsx(Fs,{size:14})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available",s?e.jsxs(e.Fragment,{children:[": ",e.jsxs("strong",{children:["v",s]})]}):null]}),t.map(o=>{const c=nt(o,{fallbackId:o.id}),d=n[o.id],l=o.version||o.daemonVersion||"unknown";return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 15%, transparent)"},children:[e.jsx("span",{className:"font-medium text-text-primary",children:c}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",l]}),d==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):d==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):d==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(o.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold cursor-pointer px-1.5 py-px rounded transition-colors",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},onClick:()=>r(o.id),children:"Upgrade"})]},o.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:i,title:"Dismiss",children:"✕"})]})}function el(){var ln,dn,un;const{sendCommand:t}=ut(),s=zs(),n=St(),[r,i]=_a(),o=r.get("activeTab"),c=((ln=s.state)==null?void 0:ln.openRemoteForTabKey)||null,d=((dn=s.state)==null?void 0:dn.openMachineId)||null,l=((un=s.state)==null?void 0:un.mobileSection)||null,f=Ys(),u=f.ides||[],{updateIdeChats:x}=f,[h,p]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),v=f.toasts||[],m=f.setToasts||(()=>{}),C=f.wsStatus||"connected",b=f.isConnected??!0,w=f.connectionStates||{},N=f.showReconnected||!1,{groupAssignments:D,setGroupAssignments:g,focusedGroup:j,setFocusedGroup:y,groupActiveTabIds:k,setGroupActiveTabIds:E,groupTabOrders:$,setGroupTabOrders:A,groupSizes:U,setGroupSizes:L,isMobile:T,hasHydratedStoredLayout:z,hydrateStoredLayout:W}=cc(),[K,M]=a.useState(!1),[P,_]=a.useState(!1),[R,F]=a.useState(null),[ce,de]=a.useState([]),[he,H]=a.useState(!1),[J,ee]=a.useState(null),[ge]=a.useState(()=>Pr()),[te,ue]=a.useState([]),[xe,X]=a.useState({}),[me,se]=a.useState({}),[pe,Y]=a.useState(null),ie=a.useRef(null);Bt("Dashboard",{ideCount:u.length,toastCount:v.length,focusedGroup:j,groupCount:Object.keys(D).length,localMessageTabs:Object.keys(xe).length,actionLogCount:te.length});const S=u.find(be=>be.type==="adhdev-daemon"),Z=(S==null?void 0:S.detectedIdes)||[],Q=!!S,re=(S==null?void 0:S.terminalBackend)||null,fe=S?nt(S,{fallbackId:S.id}):null,ye=(S==null?void 0:S.id)||null,{hiddenTabs:Ce,hideTab:Me,toggleTab:Xe,showTab:We,showAllTabs:Ge}=Uo(),{chatIdes:Ee,conversations:De,visibleConversations:Oe,visibleTabKeys:Ze,resolveConversationBySessionId:oe,resolveConversationByTarget:je}=Jo({ides:u,connectionStates:w,localUserMessages:xe,clearedTabs:me,hiddenTabs:Ce}),ve=a.useMemo(()=>Kt(u),[u]),we=a.useRef(null),{containerRef:O,normalizedGroupAssignments:B,numGroups:ne,isSplitMode:le,groupedConvs:I,moveTabToGroup:q,closeGroup:ae,handleResizeStart:V,splitTabRelative:ke}=fc({groupAssignments:D,setGroupAssignments:g,setFocusedGroup:y,setGroupActiveTabIds:E,setGroupTabOrders:A,groupSizes:U,setGroupSizes:L,isMobile:T,visibleConversations:Oe,visibleTabKeys:Ze}),G=a.useMemo(()=>{var _e,Ie;if(!T){if(pe){const Be=De.find(Ye=>Ye.tabKey===pe);if(Be)return Be}return Oe[0]}const be=k[j];if(be){const Be=De.find(Ye=>Ye.tabKey===be);if(Be)return Be}return((_e=I[j])==null?void 0:_e[0])||((Ie=I[0])==null?void 0:Ie[0])},[pe,T,k,j,De,I,Oe]);a.useEffect(()=>{if(T){we.current=null;return}if(!(G!=null&&G.sessionId)){we.current=null;return}const be=`${G.tabKey}:${G.sessionId}`;if(we.current===be)return;we.current=be;const _e=Et(G,ve),Ie=Math.max(Date.now(),jt(G),_e.lastUpdated||0);t(G.daemonId||G.ideId,"mark_session_seen",{sessionId:G.sessionId,seenAt:Ie}).catch(()=>{})},[G,T,ve,t]);const{requestedDesktopTabKey:Se,requestedMobileTabKey:ze,consumeRequestedActiveTab:Ue}=Qo({isMobile:T,urlActiveTab:o,resolveConversationBySessionId:oe,setSearchParams:i}),{remoteDialogConv:Re,remoteDialogIdeEntry:ot,remoteDialogActiveConv:Gr,setRemoteDialogActiveConv:bs,openRemoteDialog:Yr,closeRemoteDialog:Xr}=dc({isMobile:T,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Se,conversations:De,ides:u,resolveConversationByTarget:je}),Le=Gr||Re||G,tt=!!Le&&Pe(Le)&&!Ae(Le),Wt=a.useMemo(()=>{if(!Le||!tt)return null;const be=Le.daemonId||Le.ideId||"",_e=Le.agentType||Le.ideType||"";return`${be}:${_e}`},[Le,tt]),Zr=a.useMemo(()=>Oe,[Oe]),Ot=T&&ge==="chat",Jr=a.useMemo(()=>De.filter(be=>Ce.has(be.tabKey)),[De,Ce]);Ho({visibleConversations:Oe,clearedTabs:me,setClearedTabs:se,setActionLogs:ue}),ec({ides:u,sendDaemonCommand:t,setToasts:m,setLocalUserMessages:X,resolveConversationByTarget:je});const{isRefreshingHistory:Qr,handleLaunchIde:ea,handleRefreshHistory:ta}=En({sendDaemonCommand:t,activeConv:G,updateIdeChats:x,setToasts:m,setLocalUserMessages:X,setClearedTabs:se}),{isCreatingChat:sa,isRefreshingHistory:na,handleSwitchSession:ra,handleNewChat:aa,handleRefreshHistory:ia}=En({sendDaemonCommand:t,activeConv:Le,updateIdeChats:x,setToasts:m,setLocalUserMessages:X,setClearedTabs:se}),gs=a.useCallback(async()=>{if(!(!Le||!tt||he)){H(!0);try{const be=Le.daemonId||Le.ideId,_e=Le.agentType||Le.ideType,Ie=await t(be,"list_saved_sessions",{agentType:_e,providerType:_e,kind:"cli",limit:50}),Be=(Ie==null?void 0:Ie.result)??Ie;de(Array.isArray(Be==null?void 0:Be.sessions)?Be.sessions:[])}catch(be){console.error("Refresh saved sessions failed",be),de([])}finally{H(!1)}}},[Le,he,tt,t]);a.useEffect(()=>{if(!K){ie.current=null;return}if(!tt){ie.current=null,de([]),H(!1);return}!Wt||he||ie.current!==Wt&&(ie.current=Wt,gs())},[gs,K,he,tt,Wt]);const oa=a.useCallback(async be=>{if(!Le||!tt||!be.providerSessionId||!be.workspace)return;const _e=Le.daemonId||Le.ideId,Ie=Le.agentType||Le.ideType;try{ee(be.providerSessionId);const Be=await t(_e,"launch_cli",{cliType:Ie,dir:be.workspace,resumeSessionId:be.providerSessionId,initialModel:be.currentModel}),Ye=(Be==null?void 0:Be.result)??Be,zt=typeof(Ye==null?void 0:Ye.sessionId)=="string"?Ye.sessionId:typeof(Ye==null?void 0:Ye.id)=="string"?Ye.id:"";zt&&i(ga=>{const pn=new URLSearchParams(ga);return pn.set("activeTab",zt),pn},{replace:!0}),M(!1)}catch(Be){console.error("Resume saved session failed",Be)}finally{ee(null)}},[Le,tt,t,i]);lc({urlActiveTab:T&&!Ot?o:null,conversations:De,resolveConversationBySessionId:oe,normalizedGroupAssignments:B,hasHydratedStoredLayout:T&&!Ot?z:!0,hydrateStoredLayout:T&&!Ot?W:()=>{},setGroupActiveTabIds:E,setFocusedGroup:y,setSearchParams:i,historyModalOpen:K,activeConv:G,isRefreshingHistory:Qr,ides:u,handleRefreshHistory:ta});const ys=a.useCallback(async(be,_e)=>{const Ie=_e||R||G;if(!Ie||!Pe(Ie)||Ae(Ie))return;const Be=Ie.ideType||Ie.agentType||"",Ye=Ie.ideId||Ie.daemonId||"";try{await t(Ye,"stop_cli",{cliType:Be,targetSessionId:Ie.sessionId,mode:be})}catch(zt){console.error("Stop CLI failed:",zt)}},[G,R,t]),ca=a.useCallback(async be=>{const _e=be||G;!_e||!Pe(_e)||Ae(_e)||(F(_e),_(!0))},[G,ys]),la=a.useMemo(()=>!G||!Pe(G)||Ae(G)?null:Nt(G),[G]),da=a.useCallback(async be=>{if(!(!G||!Pe(G)||Ae(G)||Nt(G)===be))try{await t(G.daemonId||G.ideId,"set_cli_view_mode",{targetSessionId:G.sessionId,cliType:G.ideType||G.agentType,mode:be})}catch(Ie){console.error("Failed to switch CLI view mode:",Ie)}},[G,t]),{versionMismatchDaemons:ua,appVersion:pa,versionBannerDismissed:ma,setVersionBannerDismissed:xa,upgradingDaemons:fa,handleBannerUpgrade:ha}=hc({ides:u,sendDaemonCommand:t}),on=a.useCallback(be=>{Y(be.tabKey),i(_e=>{const Ie=new URLSearchParams(_e);return be.sessionId?Ie.set("activeTab",be.sessionId):Ie.delete("activeTab"),Ie},{replace:!0})},[i]),cn=a.useCallback(be=>{We(be.tabKey),on(be)},[on,We]),ba=a.useCallback(be=>{Me(be.tabKey)},[Me]);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(zi,{wsStatus:C,showReconnected:N}),e.jsx(Ui,{terminalBackend:re,isStandalone:Q,machineLabel:fe,machineKey:ye}),!ma&&e.jsx(Qc,{daemons:ua,targetVersion:pa,upgradingDaemons:fa,onUpgrade:ha,onDismiss:()=>xa(!0)}),e.jsx(Vc,{showMobileChatMode:Ot,isMobile:T,activeConv:G,chatIdes:Ee,wsStatus:C,isConnected:b,onOpenHistory:be=>{be&&bs(be),M(!0)},onOpenRemote:Yr,onStopCli:ca,activeCliViewMode:la,onSetActiveCliViewMode:da,mobileChatConversations:Zr,ides:u,actionLogs:te,sendDaemonCommand:t,setLocalUserMessages:X,setActionLogs:ue,isStandalone:Q,userName:f.userName,requestedMobileTabKey:ze,onRequestedMobileTabConsumed:Ue,requestedMachineId:d,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:l,onRequestedMobileSectionConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:O,isSplitMode:le,numGroups:ne,groupSizes:U,groupedConvs:I,clearedTabs:me,focusedGroup:j,setFocusedGroup:y,moveTabToGroup:q,splitTabRelative:ke,closeGroup:ae,handleResizeStart:V,detectedIdes:Z,handleLaunchIde:ea,groupActiveTabIds:k,setGroupActiveTabIds:E,groupTabOrders:$,setGroupTabOrders:A,toggleHiddenTab:Xe,visibleConversations:Oe,hiddenConversations:Jr,requestedDesktopTabKey:Se,onRequestedDesktopTabConsumed:Ue,onDesktopActiveTabChange:Y,onHideConversation:ba,onShowHiddenConversation:cn,onShowAllHiddenConversations:Ge}),e.jsx("style",{children:`
51
- body { overflow: hidden; overscroll-behavior: none; }
52
- `}),e.jsx(Jc,{historyModalOpen:K,historyTargetConv:Le,ides:u,isHistoryCreatingChat:sa,isHistoryRefreshingHistory:tt?!1:na,savedHistorySessions:ce,isSavedHistoryLoading:he,isResumingSavedHistorySessionId:J,onCloseHistory:()=>M(!1),onNewHistoryChat:aa,onSwitchHistorySession:ra,onRefreshHistory:tt?gs:ia,onResumeSavedHistorySession:oa,remoteDialogConv:Re,remoteDialogIdeEntry:ot,connectionStates:w,actionLogs:te,localUserMessages:xe,sendDaemonCommand:t,setLocalUserMessages:X,setActionLogs:ue,isStandalone:Q,userName:f.userName,onOpenRemoteHistory:be=>{be&&bs(be),M(!0)},onRemoteConversationChange:bs,onCloseRemoteDialog:Xr,cliStopDialogOpen:P,cliStopTargetConv:R,onCancelCliStop:()=>{_(!1),F(null)},onStopCliNow:async()=>{_(!1),await ys("hard",R),F(null)},onSaveCliAndStop:async()=>{_(!1),await ys("save",R),F(null)},toasts:v,onDismissToast:be=>m(_e=>_e.filter(Ie=>Ie.id!==be)),onClickToast:be=>{if(be.targetKey){const _e=je(be.targetKey);_e&&(y(B.get(_e.tabKey)??0),cn(_e))}},showOnboarding:h,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}p(!1)}})]})}function tl({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[d,l]=a.useState(null),[f,u]=a.useState(null),[x,h]=a.useState(!1),[p,v]=a.useState(null),[m,C]=a.useState(!1),[b,w]=a.useState(""),N=a.useRef(null),D=a.useCallback(P=>{N.current=P},[]),g=a.useCallback((P,_,R=!1)=>{c(F=>[...F.slice(-100),{timestamp:Date.now(),level:P,message:_}]),setTimeout(()=>{var F;return(F=i.current)==null?void 0:F.scrollIntoView({behavior:"smooth"})},100),R&&lt.showToast(_,P==="error"||P==="warn"?"warning":"success")},[i]),j=a.useCallback(P=>{const _=P instanceof Error?P.message:String(P||"");return _.includes("P2P command timeout")||_.includes("P2P not connected")||_.includes("P2P not available")},[]),y=a.useCallback(async(P,_)=>{var R;if(!t||d)return!1;l(P),g("info",`Launching ${Te(P)}${_!=null&&_.workspace?` in ${_.workspace}`:""}...`);try{const F={ideType:P,enableCdp:!0};(R=_==null?void 0:_.workspace)!=null&&R.trim()?F.workspace=_.workspace.trim():_!=null&&_.useDefaultWorkspace&&(F.useDefaultWorkspace=!0);const ce=await n(t,"launch_ide",F);return g(ce!=null&&ce.success?"info":"error",ce!=null&&ce.success?`${Te(P)} launched`:`Failed: ${ce==null?void 0:ce.error}`,!0),!!(ce!=null&&ce.success)}catch(F){return g("error",`Launch error: ${F.message}`,!0),!1}finally{l(null)}},[t,d,g,n]),k=a.useCallback(async P=>{if(!t)return{success:!1};const{cliType:_,dir:R,workspaceId:F,useDefaultWorkspace:ce,useHome:de,argsStr:he,model:H,resumeSessionId:J}=P;if(!_)return g("warn","Select a CLI or ACP provider first",!0),{success:!1};const ee=he?he.split(/\s+/).filter(Boolean):void 0,ge=(R==null?void 0:R.trim())||(F?"(saved id)":ce?"(default workspace)":de?"(home)":"");g("info",`Launching ${_}${ge?` in ${ge}`:""}${H?` (model: ${H})`:""}...`),u(_);try{const te={cliType:_,cliArgs:ee,initialModel:H||void 0};R!=null&&R.trim()?te.dir=R.trim():F?te.workspaceId=F:ce?te.useDefaultWorkspace=!0:de&&(te.useHome=!0),J&&(te.resumeSessionId=J);const ue=await n(t,"launch_cli",te),xe=(ue==null?void 0:ue.result)||ue;return ue!=null&&ue.success?(g("info",`${_} launched`,!0),(xe==null?void 0:xe.launchSource)==="home"?g("info","📂 Running in home directory (explicit choice)"):(xe==null?void 0:xe.launchSource)==="defaultWorkspace"&&g("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:xe==null?void 0:xe.sessionId}):(g("error",`Failed: ${(ue==null?void 0:ue.error)||(xe==null?void 0:xe.error)}`,!0),(ue==null?void 0:ue.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&v({cliType:_,argsStr:he,model:H}),{success:!1,sessionId:xe==null?void 0:xe.sessionId})}catch(te){return j(te)?(g("warn",`${_} launch requested — waiting for session to appear...`,!0),{success:!1,pending:!0}):(g("error",`Launch error: ${te.message}`,!0),{success:!1})}finally{u(null)}},[t,g,j,n]),E=a.useCallback(async(P,_,R,F)=>t?P?_.trim()?k({cliType:P,dir:_,argsStr:R,model:F}):(v({cliType:P,argsStr:R,model:F}),{success:!1}):(g("warn","Select a provider",!0),{success:!1}):{success:!1},[t,g,k]),$=a.useCallback(async(P,_,R)=>{if(t&&window.confirm(`Stop ${P}?
53
- This will terminate the process.`))try{const F=await n(t,"stop_cli",{cliType:P,dir:_,targetSessionId:R});F!=null&&F.success?g("info",`${P} stopped`,!0):g("error",`Stop failed: ${(F==null?void 0:F.error)||"Unknown error"}`,!0)}catch(F){g("error",`Stop failed: ${F.message}`,!0)}},[t,g,n]),A=a.useCallback(async P=>{try{await n(P.daemonId,"restart_ide",{ideType:P.type}),g("info",`${Te(P.type)} restart initiated`,!0)}catch(_){g("error",`Restart failed: ${_.message}`,!0)}},[g,n]),U=a.useCallback(async P=>{if(window.confirm(`Stop ${Te(P.type)}?
54
- This will disconnect CDP and optionally kill the process.`))try{const _=await n(P.daemonId,"stop_ide",{ideType:P.type,killProcess:!0});_!=null&&_.success?g("info",`${Te(P.type)} stopped`,!0):g("error",`Stop failed: ${(_==null?void 0:_.error)||"Unknown error"}`,!0)}catch(_){g("error",`Stop failed: ${_.message}`,!0)}},[g,n]),L=a.useCallback(async()=>{if(t)try{const P=await n(t,"detect_ides",{});g("info",`Found ${((P==null?void 0:P.result)||[]).length} IDE(s)`,!0)}catch(P){g("error",`Detection failed: ${P.message}`,!0)}},[t,g,n]),T=a.useCallback(async P=>{if(!t||!P.trim())return!1;h(!0);try{const _=await n(t,"workspace_add",{path:P.trim()});return _!=null&&_.success?(g("info",`Workspace added: ${P.trim()}`),!0):(g("error",(_==null?void 0:_.error)||"workspace_add failed"),!1)}catch(_){return g("error",_.message),!1}finally{h(!1)}},[t,g,n]),z=a.useCallback(async P=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const _=await n(t,"workspace_remove",{id:P});_!=null&&_.success?g("info","Workspace removed",!0):g("error",(_==null?void 0:_.error)||"workspace_remove failed",!0)}catch(_){g("error",_.message,!0)}finally{h(!1)}}},[t,g,n]),W=a.useCallback(async P=>{var _;if(t){h(!0);try{const R=await n(t,"workspace_set_default",P===null?{clear:!0}:{id:P});if(R!=null&&R.success){g("info",P?"Default workspace updated":"Default workspace cleared",!0);const F=typeof R.defaultWorkspacePath=="string"?R.defaultWorkspacePath:"";F&&((_=N.current)==null||_.call(N,F))}else g("error",(R==null?void 0:R.error)||"workspace_set_default failed",!0)}catch(R){g("error",R.message,!0)}finally{h(!1)}}},[t,g,n]),K=a.useCallback(async P=>{var R;if(!t||!P.trim())return;const _=P.trim();h(!0);try{const F=await n(t,"workspace_set_default",{path:_});F!=null&&F.success?(g("info","Default workspace set from history"),(R=N.current)==null||R.call(N,_)):g("error",(F==null?void 0:F.error)||"Could not set default (path missing on disk?)")}catch(F){g("error",F.message)}finally{h(!1)}},[t,g,n]),M=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:b}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:b})}catch(P){g("warn",`Live nickname updated, but account sync failed: ${P.message}`)}g("info",`Nickname set to "${b||"(cleared)"}"`),C(!1)}catch(P){g("error",`Failed: ${P.message}`)}},[t,b,s,g,r,n]);return{logs:o,launchingIde:d,launchingAgentType:f,workspaceBusy:x,launchPick:p,setLaunchPick:v,editingNickname:m,setEditingNickname:C,nicknameInput:b,setNicknameInput:w,addLog:g,handleLaunchIde:y,runLaunchCliCore:k,handleLaunchCli:E,handleStopCli:$,handleRestartIde:A,handleStopIde:U,handleDetectIdes:L,handleWorkspaceAdd:T,handleWorkspaceRemove:z,handleWorkspaceSetDefault:W,handleWorkspaceResumePath:K,handleSaveNickname:M,setOnDefaultWorkspaceChanged:D}}function sl({machineId:t,machine:s,ideSessions:n,cliSessions:r,acpSessions:i,actions:o,sendDaemonCommand:c}){const{workspaceBusy:d,handleWorkspaceAdd:l,handleWorkspaceRemove:f,handleWorkspaceSetDefault:u}=o,[x,h]=a.useState(!1),[p,v]=a.useState(""),[m,C]=a.useState([]),[b,w]=a.useState(!1),[N,D]=a.useState(""),g=a.useCallback(async $=>{w(!0),D("");try{const A=await Hr(c,t,$);v(A.path),C(A.directories)}catch(A){D(A instanceof Error?A.message:"Could not load folder")}finally{w(!1)}},[t,c]),j=a.useCallback(()=>{var A;h(!0);const $=sn(s.platform,[s.defaultWorkspacePath,(A=s.workspaces[0])==null?void 0:A.path]);g($)},[g,s.defaultWorkspacePath,s.platform,s.workspaces]),y=s.availableMem??s.freeMem,k=s.totalMem>0?Math.min(100,Math.max(0,Math.round((s.totalMem-y)/s.totalMem*100))):0,E=s.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(Ut,{icon:e.jsx(lr,{size:16}),label:"Uptime",value:ki(s.uptime)}),e.jsx(Ut,{icon:e.jsx(Ve,{size:16}),label:"IDEs",value:`${n.length}`}),e.jsx(Ut,{icon:e.jsx(qs,{size:16}),label:"CLIs",value:`${r.length}`}),e.jsx(Ut,{icon:e.jsx(Xa,{size:16}),label:"ACPs",value:`${i.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(bn,{value:Math.min(Math.round(E/s.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${E.toFixed(2)} avg / ${s.cpus} cores`}),e.jsx(bn,{value:k,max:100,label:"Memory",color:"#3b82f6",detail:`${vn(s.totalMem-y)} / ${vn(s.totalMem)}${s.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(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:d,value:s.defaultWorkspaceId||"",onChange:$=>void u($.target.value===""?null:$.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(s.workspaces||[]).map($=>e.jsx("option",{value:$.id,children:$.label||$.path},$.id))]}),s.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:s.defaultWorkspacePath,children:s.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("button",{type:"button",className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded transition-colors text-xs",disabled:d,onClick:j,children:"Select workspace…"}),e.jsx("span",{className:"text-[11px] text-text-muted",children:"Add workspaces by selecting a folder in the explorer."})]}),(s.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(s.workspaces||[]).map($=>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:[$.id===s.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Gs($.path,$.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:$.path,children:$.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:d,onClick:()=>void f($.id),children:"Remove"})]},$.id))})]}),x&&e.jsx(nn,{title:"Add workspace",description:"Browse the machine like a normal explorer, then add the current folder as a saved workspace.",currentPath:p,directories:m,busy:b,error:N,confirmLabel:"Add workspace",onClose:()=>h(!1),onNavigate:$=>{g($)},onConfirm:$=>{(async()=>{if(!$)return;await l($)&&h(!1)})()}})]})}const qn=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],nl=[{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 rl({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,d]=a.useState("codex-cli"),[l,f]=a.useState([]),[u,x]=a.useState(""),[h,p]=a.useState([]),[v,m]=a.useState(""),C=a.useRef(null),b=a.useRef(null),w=k=>{f(E=>E.includes(k)?E.filter($=>$!==k):[...E,k])},N=()=>f([...qn]),D=()=>f([]);a.useEffect(()=>{var k;(k=C.current)==null||k.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{b.current&&clearInterval(b.current)},[]);const g=a.useCallback(()=>{b.current&&clearInterval(b.current),b.current=setInterval(async()=>{try{const k=await n(t,"provider_auto_fix_status",{providerType:s.type});(k==null?void 0:k.running)===!1&&i==="running"&&(o("done"),p(E=>[...E,`
55
- ✅ Auto-fix completed!`]),b.current&&clearInterval(b.current))}catch{}},3e3)},[t,s.type,n,i]),j=async()=>{if(l.length!==0){o("running"),p(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),m("");try{const k=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...u?{comment:u}:{}});k!=null&&k.success&&(k!=null&&k.started||k!=null&&k.running)?(p(E=>[...E,"✅ Agent started. Monitoring progress..."]),g()):(o("error"),m((k==null?void 0:k.error)||"Failed to start auto-fix"))}catch(k){o("error"),m((k==null?void 0:k.message)||"Connection failed")}}},y=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),p(k=>[...k,`
56
- ⚠️ Auto-fix cancelled.`]),o("done"),b.current&&clearInterval(b.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:nl.map(k=>e.jsxs("button",{onClick:()=>d(k.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===k.value?k.color+"66":"var(--border-subtle)",background:c===k.value?k.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===k.value?k.color:"var(--text-primary)"},children:k.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:k.desc})]},k.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:N,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:D,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:qn.map(k=>e.jsxs("button",{onClick:()=>w(k),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(k)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:l.includes(k)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:l.includes(k)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(k)?"☑ ":"☐ ",k]},k))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:u,onChange:k=>x(k.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[h.map((k,E)=>e.jsx("div",{className:k.startsWith("✅")?"text-green-400":"",style:k.startsWith("❌")||k.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:k},E)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:C})]}),v&&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:v})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&l.length>0&&`${l.length} script(s) selected`,i==="running"&&"Agent is generating...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:j,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"color-mix(in srgb, var(--accent-primary) 15%, transparent)":void 0,borderColor:l.length>0?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:y,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),p([]),m("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function al({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var g;const o=s.filter(j=>j.category==="ide"),[c,d]=a.useState(((g=o[0])==null?void 0:g.type)||""),[l,f]=a.useState(""),[u,x]=a.useState(""),[h,p]=a.useState(!1),[v,m]=a.useState(""),[C,b]=a.useState(!1),w=j=>{const y=j.toLowerCase().replace(/[^a-z0-9-]/g,"");f(y),(!u||u===N(l))&&x(N(y))},N=j=>j.split("-").map(y=>y.charAt(0).toUpperCase()+y.slice(1)).join(" "),D=async()=>{if(!(!l||!u||!c)){p(!0),m("");try{const j=await n(t,"provider_clone",{type:l,name:u,category:"ide",location:"user",cloneFrom:c});j!=null&&j.success||j!=null&&j.created?(b(!0),i==null||i(l)):m((j==null?void 0:j.error)||"Failed to create provider")}catch(j){m((j==null?void 0:j.message)||"Connection failed")}p(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[480px] rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:j=>j.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:C?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(j=>e.jsxs("button",{onClick:()=>d(j.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===j.type?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:c===j.type?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:j.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===j.type?"#a78bfa":"var(--text-secondary)"},children:j.displayName})]},j.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:j=>w(j.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:u,onChange:j=>x(j.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"})]}),v&&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:v})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:C?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:D,disabled:!l||!u||h,className:"machine-btn",style:{background:l&&u?"rgba(34,197,94,0.12)":void 0,borderColor:l&&u?"rgba(34,197,94,0.3)":void 0,color:l&&u?"#86efac":void 0,opacity:!l||!u||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function il({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[f,u]=a.useState("all"),[x,h]=a.useState(null),[p,v]=a.useState(!1),m=a.useCallback(async()=>{var b;if(t){c(!0);try{const w=await n(t,"get_provider_settings",{}),N=(w==null?void 0:w.result)||w;if(w!=null&&w.success&&(N!=null&&N.settings)){const D=[];for(const[g,j]of Object.entries(N.settings)){const y=s.find(k=>k.type===g);D.push({type:g,displayName:(y==null?void 0:y.displayName)||g,icon:(y==null?void 0:y.icon)||"",category:(y==null?void 0:y.category)||"unknown",schema:j,values:((b=N.values)==null?void 0:b[g])||{}})}D.sort((g,j)=>g.category.localeCompare(j.category)||g.displayName.localeCompare(j.displayName)),i(D)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&m()},[]);const C=async(b,w,N)=>{l(`${b}.${w}`),i(D=>D.map(g=>g.type===b?{...g,values:{...g.values,[w]:N}}:g));try{const D=await n(t,"set_provider_setting",{providerType:b,key:w,value:N});D!=null&&D.success||m()}catch{m()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(b=>e.jsx("button",{onClick:()=>u(b),className:`machine-btn text-[10px] px-2 py-0.5 ${f===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>v(!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:m,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(b=>b.category===f).length>1&&(()=>{const b=r.filter(g=>g.category===f),w=new Map;for(const g of b)for(const j of g.schema){if(j.type!=="boolean")continue;const y=w.get(j.key),k=!!(g.values[j.key]??j.default);y?(y.onCount+=k?1:0,y.total+=1):w.set(j.key,{label:j.label||j.key,onCount:k?1:0,total:1})}const N=[...w.entries()].filter(([,g])=>g.total===b.length);if(N.length===0)return null;const D=async(g,j)=>{for(const y of b)await C(y.type,g,j)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",f.toUpperCase()," providers (",b.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(([g,j])=>{const y=j.onCount===j.total,k=j.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:j.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",j.onCount,"/",j.total,")"]}),e.jsx("button",{onClick:()=>void D(g,!0),disabled:y,className:`machine-btn text-[9px] px-1.5 py-px ${y?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void D(g,!1),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},g)})})]})})(),o&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(b=>f==="all"||b.category===f).map(b=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:b.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:b.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:b.category==="acp"?"rgba(139,92,246,0.08)":b.category==="cli"?"rgba(59,130,246,0.08)":b.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:b.category==="acp"?"#a78bfa":b.category==="cli"?"#60a5fa":b.category==="ide"?"#86efac":"var(--status-warning)"},children:b.category}),b.category==="ide"&&e.jsx("button",{onClick:()=>h(s.find(w=>w.type===b.type)||{type:b.type,name:b.displayName,displayName:b.displayName,icon:b.icon,category:b.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:b.schema.map(w=>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:[w.label||w.key,d===`${b.type}.${w.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),w.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:w.description})]}),e.jsx("div",{className:"shrink-0",children:w.type==="boolean"?e.jsx("button",{onClick:()=>C(b.type,w.key,!(b.values[w.key]??w.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:b.values[w.key]??w.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:b.values[w.key]??w.default?21:3}})}):w.type==="number"?e.jsx("input",{type:"number",value:b.values[w.key]??w.default??0,min:w.min,max:w.max,onChange:N=>{const D=parseInt(N.target.value)||0;w.min!==void 0&&D<w.min||w.max!==void 0&&D>w.max||C(b.type,w.key,D)},className:"machine-input w-20 text-center text-[11px]"}):w.type==="select"&&w.options?e.jsx("select",{value:b.values[w.key]??w.default??"",onChange:N=>C(b.type,w.key,N.target.value),className:"machine-input text-[11px]",children:w.options.map(N=>e.jsx("option",{value:N,children:N},N))}):e.jsx("input",{type:"text",value:b.values[w.key]??w.default??"",onBlur:N=>C(b.type,w.key,N.target.value),className:"machine-input w-[120px] text-[11px]"})})]},w.key))})]},b.type))}),x&&e.jsx(rl,{machineId:t,provider:x,sendDaemonCommand:n,onClose:()=>h(null)}),p&&e.jsx(al,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>v(!1),onCreated:()=>{v(!1),m()}})]})}function ol({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,f]=a.useState("debug"),u=a.useRef(null),x=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const v=await s(t,"get_logs",{count:200,minLevel:l,since:i}),m=(v==null?void 0:v.result)||v;if(v!=null&&v.success&&Array.isArray(m==null?void 0:m.logs)&&m.logs.length>0){r(b=>[...b,...m.logs.map(N=>({timestamp:N.ts,level:N.level,message:`[${N.category}] ${N.message}`}))].slice(-300));const C=Math.max(...m.logs.map(b=>b.ts));o(C)}}catch{}};h();const p=setInterval(h,3e3);return()=>clearInterval(p)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=x.current?"smooth":"instant";setTimeout(()=>{var p;(p=u.current)==null||p.scrollIntoView({behavior:h}),x.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(h=>e.jsx("button",{onClick:()=>{f(h),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((h,p)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(h.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#475569":"#8b5cf6"},children:h.level==="error"?"ERR":h.level==="warn"?"WRN":h.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:h.message})]},p)),e.jsx("div",{ref:u})]})]})}function cl({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:i}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(o=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:o.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:o.label||o.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:o.path})]},o.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function ll({children:t}){return e.jsx("div",{className:"text-xs font-semibold text-text-muted mb-2 tracking-wide uppercase",children:t})}function dl({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenRecent:i}){const o=n.slice(0,4),c=d=>d==="ide"?"IDE":d==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-6 md:min-w-[280px] md:max-w-[340px] shrink-0 border-r border-[#ffffff0a] pr-4 md:pr-6 md:h-full overflow-y-auto",children:[o.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ll,{children:"Recent Activity"}),e.jsx("div",{className:"flex flex-col gap-1.5",children:o.map(d=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-bg-surface border border-[#ffffff08] hover:bg-[#ffffff0a] hover:border-[#ffffff10] transition-colors cursor-pointer group",onClick:()=>i(d),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:d.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[c(d.kind),d.subtitle?` · ${d.subtitle}`:""]})]},d.id))})]}),e.jsx("div",{className:"flex flex-col gap-2 mt-auto pt-4 border-t border-[#ffffff08]",children:t.versionMismatch&&e.jsx("button",{type:"button",className:"btn btn-sm w-full bg-accent-primary/20 text-accent-primary border-accent-primary/30 hover:bg-accent-primary/30",onClick:r,children:"Update Daemon"})})]})}function ul(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const pl={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 Ts({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d,initialWorkspaceId:l,initialWorkspacePath:f}){const u=St(),{handleLaunchIde:x,handleStopCli:h,handleRestartIde:p,handleStopIde:v,handleDetectIdes:m,launchingIde:C,launchingAgentType:b,addLog:w}=c,[N,D]=a.useState(null),g=a.useCallback(I=>{I&&u({pathname:"/",search:`?activeTab=${encodeURIComponent(I)}`})},[u]),j=pl[t],y=t==="ide",k=t==="acp",E=r.filter(I=>I.category===t),$=new Map(E.map(I=>[I.type,I.displayName||I.type])),[A,U]=a.useState(""),[L,T]=a.useState(""),[z,W]=a.useState(""),[K,M]=a.useState(f?"__custom__":l||s.defaultWorkspaceId||""),[P,_]=a.useState(f||""),[R,F]=a.useState([]),[ce,de]=a.useState(!1),[he,H]=a.useState(""),[J,ee]=a.useState([]),[ge,te]=a.useState(!1),[ue,xe]=a.useState(""),X=a.useRef(null),[me,se]=a.useState(null),pe=a.useRef("__home__"),[Y,ie]=a.useState("__home__"),[S,Z]=a.useState(!1),Q=R.filter(I=>!i.some(q=>q.type===I&&qe(q.status)!=="stopped")),re=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!K&&M(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){M("__custom__"),_(f);return}l&&(M(l),_(""))},[l,f]);const fe=(()=>{if(K==="__custom__")return P.trim();if(!K)return"";const I=(s.workspaces||[]).find(q=>q.id===K);return(I==null?void 0:I.path)||""})(),ye=a.useCallback(I=>{const q=re.current[I];q&&(clearTimeout(q),delete re.current[I]),F(ae=>ae.filter(V=>V!==I))},[]),Ce=a.useRef(new Set),Me=a.useCallback(async I=>{if(d){te(!0),xe("");try{const q=await Hr(d,n,I);H(q.path),_(q.path),ee(q.directories)}catch(q){xe(q instanceof Error?q.message:"Could not load folder")}finally{te(!1)}}},[n,d]),Xe=a.useCallback(()=>{var q;if(!d)return;M("__custom__"),de(!0);const I=sn(s.platform,[P.trim(),fe,s.defaultWorkspacePath,(q=s.workspaces[0])==null?void 0:q.path]);Me(I)},[P,Me,s.defaultWorkspacePath,s.platform,s.workspaces,fe,d]),We=a.useCallback((I,q)=>{X.current=q,pe.current=I.selectedWorkspaceKey||"__home__",ie(I.selectedWorkspaceKey||"__home__"),se(I)},[]),Ge=a.useCallback(()=>{X.current&&(Z(!0),X.current().finally(()=>{X.current=null,Z(!1),se(null)}))},[]),Ee=a.useCallback(I=>{if(!I)return;F(ae=>ae.includes(I)?ae:[...ae,I]);const q=re.current[I];q&&clearTimeout(q),re.current[I]=setTimeout(()=>{F(ae=>ae.filter(V=>V!==I)),delete re.current[I]},2e4)},[]);a.useEffect(()=>{for(const q of i)qe(q.status)!=="stopped"&&(R.includes(q.type)&&!Ce.current.has(q.type)&&(Ce.current.add(q.type),w("info",`${$.get(q.type)||q.type} launched`,!0)),ye(q.type));const I=new Set(i.filter(q=>qe(q.status)!=="stopped").map(q=>q.type));Ce.current.forEach(q=>{!R.includes(q)&&!I.has(q)&&Ce.current.delete(q)})},[w,ye,i,R,$]),a.useEffect(()=>()=>{Object.values(re.current).forEach(clearTimeout),re.current={}},[]);const[De,Oe]=a.useState({}),[Ze,oe]=a.useState(null);a.useEffect(()=>{if(!y||!n||!d)return;(async()=>{try{const q=await d(n,"get_ide_extensions",{}),ae=(q==null?void 0:q.result)||q;ae!=null&&ae.success&&(ae!=null&&ae.ideExtensions)&&Oe(ae.ideExtensions)}catch{}})()},[y,n,d]);const je=I=>y?Te(I.type):t==="cli"?I.cliName:I.acpName,ve=y?s.detectedIdes||[]:[],we=a.useCallback(async I=>{const q=(I==null?void 0:I.type)||A,ae=(I==null?void 0:I.workspacePath)??fe;if(y){await x(q,ae?{workspace:ae}:void 0)&&Ee(q);return}const V=await c.runLaunchCliCore({cliType:q,dir:I!=null&&I.workspaceId?void 0:ae||void 0,workspaceId:(I==null?void 0:I.workspaceId)||void 0,useHome:(I==null?void 0:I.useHome)||!(I!=null&&I.workspaceId)&&!ae,argsStr:(I==null?void 0:I.argsStr)??(L||void 0),model:(I==null?void 0:I.model)??(k&&z||void 0)});(V.success||V.pending)&&(Ee(q),V.success&&V.sessionId&&g(V.sessionId))},[c,x,k,y,L,z,Ee,g,fe,A]),O=()=>{const I=y?Te(A):$.get(A)||A,{options:q,selectedKey:ae}=ht({machine:s,currentWorkspaceId:K&&K!=="__custom__"?K:null,currentWorkspacePath:fe});We({title:`Launch ${I}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:q,selectedWorkspaceKey:ae,details:[{label:"Mode",value:j.label},{label:"Provider",value:I},...!y&&L.trim()?[{label:"Arguments",value:L.trim()}]:[],...k&&z.trim()?[{label:"Model",value:z.trim()}]:[]]},async()=>{const V=q.find(ke=>ke.key===pe.current);V!=null&&V.workspaceId?(M(V.workspaceId),_("")):V!=null&&V.workspacePath?(M("__custom__"),_(V.workspacePath)):(M(""),_("")),await we({workspaceId:(V==null?void 0:V.workspaceId)??null,workspacePath:(V==null?void 0:V.workspacePath)??"",useHome:!(V!=null&&V.workspaceId)&&!(V!=null&&V.workspacePath)})})},B=I=>{y?v(I):h(I.type,I.workspace,I.id)},ne=a.useCallback(async(I,q,ae=!1)=>{if(I.mode===q){ae&&I.sessionId&&g(I.sessionId);return}if(!d||!I.sessionId){ae&&I.sessionId&&g(I.sessionId);return}try{await d(n,"set_cli_view_mode",{targetSessionId:I.sessionId,cliType:I.type,mode:q}),ae&&g(I.sessionId)}catch(V){console.error("Failed to switch CLI view mode:",V)}},[n,g,d]),le=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:K,onChange:I=>{const q=I.target.value;if(M(q),q==="__custom__"&&d){Xe();return}q!=="__custom__"&&_("")},className:"px-3 py-1.5 rounded-md min-w-[200px] flex-1 text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(I=>e.jsxs("option",{value:I.id,children:[I.id===s.defaultWorkspaceId?"⭐ ":"",Gs(I.path,I.label)]},I.id)),e.jsx("option",{value:"__custom__",children:d?"📁 Select workspace…":"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:d?"📁 Select workspace…":"✏️ Custom path…"})]})}),K==="__custom__"&&(d?e.jsx("button",{type:"button",className:"px-3 py-1.5 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] hover:border-accent-primary text-text-secondary hover:text-text-primary transition-colors",onClick:Xe,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:P,onChange:I=>_(I.target.value),className:"px-3 py-1.5 rounded-md flex-1 min-w-[200px] text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",autoFocus:!0}))]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:K==="__custom__"?fe?e.jsx("span",{className:"font-mono truncate block",title:fe,children:fe}):d?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":fe?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:K===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:fe,children:fe})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-5 rounded-xl mb-6 bg-bg-secondary border ${j.accent} relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 left-0 w-full height-[1px] bg-gradient-to-r from-transparent via-[#ffffff20] to-transparent"}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-primary/60"}),"Select ",j.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:y?ve.length>0?ve.map(I=>{const q=i.find(Se=>(Se.type||"").toLowerCase()===(I.type||"").toLowerCase()&&qe(Se.status)!=="stopped"),ae=I.running||!!q,V=!!q&&q.cdpConnected,ke=R.includes(I.type||I.id||""),G=A===(I.type||"");return e.jsxs("button",{onClick:()=>{if(V&&q){const Se=q.sessionId;Se?u(`/dashboard?activeTab=${encodeURIComponent(Se)}`,{state:{openRemoteForTabKey:Se}}):u("/dashboard",{state:{openRemoteForTabKey:q.id}});return}ke||U(Se=>Se===(I.type||"")?"":I.type||"")},disabled:!!C||ke,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${V?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":G?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,style:{opacity:C&&C!==I.type?.4:1},children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:o(I.type)}),ae&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${V?"bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]":"bg-orange-500 shadow-[0_0_6px_rgba(249,115,22,0.6)] animate-pulse"}`})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:I.name||Te(I.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${V?"text-green-400":ke?"text-orange-400":G?"text-accent-primary":"text-text-muted"}`,children:V?"Open Session":ke?"Starting...":G?"Configure":"Select"})]})]},I.type)}):e.jsxs("div",{className:"col-span-full py-6 flex flex-col items-center justify-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted italic gap-2",children:["No IDEs detected.",e.jsxs("button",{onClick:m,className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded-lg flex items-center gap-1.5",children:[e.jsx(qa,{size:14})," Scan System"]})]}):E.length>0?E.map(I=>{const q=A===I.type,ae=R.includes(I.type),ke=!!i.find(G=>G.type===I.type&&qe(G.status)!=="stopped");return e.jsxs("button",{onClick:()=>U(G=>G===I.type?"":I.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${q?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:I.icon}),ke&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:I.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ae?"text-orange-400":q?"text-accent-primary":"text-text-muted"}`,children:ae?"Starting...":q?"Configure":"Select"})]})]},I.type)}):e.jsxs("div",{className:"col-span-full py-6 text-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted",children:["No ",t.toUpperCase()," providers available"]})}),A&&(y?ve.find(I=>I.type===A):E.find(I=>I.type===A))&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-[#ffffff1a] flex flex-col gap-4 animate-in slide-in-from-top-2 fade-in duration-200",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center justify-between",children:[e.jsx("span",{children:"Launch Settings"}),e.jsx("span",{className:"text-accent-primary font-bold",children:y?Te(A):$.get(A)||A})]}),le,!y&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[k&&e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Target Model"}),e.jsx("input",{type:"text",placeholder:"Leave empty for default",value:z,onChange:I=>W(I.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Startup Arguments"}),e.jsx("input",{type:"text",placeholder:"Optional flags...",value:L,onChange:I=>T(I.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:O,disabled:!!b||!!C||R.includes(A),className:"btn btn-primary h-9 px-6 font-bold transition-all flex items-center gap-2 hover:shadow-glow hover:-translate-y-px",children:b===A||C===A?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+R.filter(I=>!i.some(q=>q.type===I&&qe(q.status)!=="stopped")).length,")"]}),i.length===0&&Q.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 ",j.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[Q.map(I=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(I)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:y?Te(I):$.get(I)||I}),e.jsx("div",{className:"text-[11px] text-text-muted",children:b===I?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${I}`)),i.map(I=>{const q=y?I:null,ae=k?I:null,V=!y&&!k?I:null,ke=qe(I.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(I.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[je(I),(q==null?void 0:q.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",q.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:I.workspace||"—"}),(ae==null?void 0:ae.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",ae.currentModel]}),(ae==null?void 0:ae.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",ae.currentPlan]}),(V==null?void 0:V.mode)&&e.jsx("span",{className:V.mode==="chat"?"text-violet-400":"text-text-secondary",children:V.mode==="chat"?"Chat view":"Terminal view"})]}),V&&(V.runtimeKey||V.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[V.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 ",V.runtimeKey]}),e.jsx("button",{type:"button",className:"flex items-center justify-center px-1.5 py-0.5 rounded text-[9px] bg-[#ffffff0a] hover:bg-[#ffffff14] border border-[#ffffff0a] text-text-muted hover:text-text-primary transition-colors cursor-pointer",onClick:()=>{var G;(G=navigator.clipboard)==null||G.writeText(`adhdev attach ${V.runtimeKey}`),D(V.runtimeKey||null),window.setTimeout(()=>{D(Se=>Se===V.runtimeKey?null:Se)},1200)},children:N===V.runtimeKey?"Copied":"Copy"})]}),V.runtimeWriteOwner&&e.jsx("span",{style:{color:V.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:V.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:ul(V.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${ke==="stopped"?"bg-red-500/[0.08] text-red-500":ke==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:ke}),y&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const G=I.sessionId;if(G){u(`/dashboard?activeTab=${encodeURIComponent(G)}`,{state:{openRemoteForTabKey:G}});return}u("/dashboard",{state:{openRemoteForTabKey:I.id}})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-primary transition-colors cursor-pointer",title:"Open remote control",children:e.jsx(Ve,{size:13})}),e.jsx("button",{onClick:()=>{const G=I.workspace||"",{options:Se,selectedKey:ze}=ht({machine:s,currentWorkspacePath:G});We({title:`Restart ${Te(I.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:Se,selectedWorkspaceKey:ze,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Te(I.type)}]},async()=>{const Ue=Se.find(ot=>ot.key===pe.current),Re=(Ue==null?void 0:Ue.workspacePath)??"";if(Re&&Re!==G){await we({type:I.type,workspacePath:Re});return}await p(I)})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-orange-500/20 text-orange-400 transition-colors cursor-pointer",title:"Restart",children:e.jsx(Fs,{size:14})})]}),k&&e.jsx("button",{onClick:()=>{const G=I.sessionId;G&&g(G)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"View chat",disabled:!I.sessionId,children:e.jsx(it,{size:14})}),V&&ke!=="stopped"&&e.jsxs(e.Fragment,{children:[V.mode&&e.jsx(Xs,{mode:V.mode,onChange:G=>void ne(V,G,!1),compact:!0}),e.jsx("button",{onClick:()=>{const G=I.sessionId;G&&g(G)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"Open current view in dashboard",disabled:!I.sessionId,children:V.mode==="chat"?e.jsx(it,{size:14}):e.jsx(Ve,{size:13})})]}),ke==="stopped"?e.jsx("button",{onClick:()=>{const G=I.workspace||"",Se=y?Te(I.type):je(I),{options:ze,selectedKey:Ue}=ht({machine:s,currentWorkspacePath:G});We({title:`Launch ${Se}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:ze,selectedWorkspaceKey:Ue,details:[{label:"Mode",value:j.label},{label:"Provider",value:Se}]},async()=>{const Re=ze.find(ot=>ot.key===pe.current);await we({type:I.type,workspaceId:(Re==null?void 0:Re.workspaceId)??null,workspacePath:(Re==null?void 0:Re.workspacePath)??"",useHome:!(Re!=null&&Re.workspaceId)&&!(Re!=null&&Re.workspacePath),model:ae==null?void 0:ae.currentModel})})},disabled:R.includes(I.type),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-green-500/20 text-green-400 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Restart",children:R.includes(I.type)?"⏳":e.jsx(dr,{size:14})}):e.jsx("button",{onClick:()=>B(I),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-red-500/20 text-red-400 transition-colors cursor-pointer",title:"Stop",children:e.jsx(kt,{size:14})})]})]}),q&&q.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:q.aiAgents.map(G=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${hr(G.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[G.name," · ",qe(G.status)]},G.id))}),q&&(De[q.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(De[q.type]||[]).map(G=>e.jsxs("button",{disabled:Ze===`${q.type}.${G.type}`,onClick:async()=>{const Se=`${q.type}.${G.type}`;oe(Se);try{await d(n,"set_ide_extension",{ideType:q.type,extensionType:G.type,enabled:!G.enabled}),Oe(ze=>({...ze,[q.type]:(ze[q.type]||[]).map(Ue=>Ue.type===G.type?{...Ue,enabled:!Ue.enabled}:Ue)}))}catch(ze){console.error("Extension toggle failed:",ze)}finally{oe(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 ${G.enabled?"bg-accent-primary/10 border-accent-primary/20 text-accent-primary-light":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${G.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),G.name,e.jsx("span",{className:"text-[9px] font-normal",children:G.enabled?"ON":"OFF"})]},G.type))})]})]},I.id)})]}),ce&&d&&e.jsx(nn,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:he,directories:J,busy:ge,error:ue,confirmLabel:"Use this folder",onClose:()=>de(!1),onNavigate:I=>{Me(I)},onConfirm:I=>{_(I),M("__custom__"),de(!1)}}),me&&e.jsx(rn,{title:me.title,description:me.description,details:me.details,workspaceOptions:me.workspaceOptions,selectedWorkspaceKey:Y,onWorkspaceChange:I=>{pe.current=I,ie(I)},confirmLabel:me.confirmLabel,busy:S,onConfirm:Ge,onCancel:()=>{X.current=null,se(null)}})]})}const Gn=[{id:"ide",label:"IDE",helper:"Open a graphical workspace and attach CDP"},{id:"cli",label:"CLI",helper:"Launch a terminal-first workspace on this machine"},{id:"acp",label:"ACP",helper:"Launch an ACP-backed workspace on this machine"}];function ml({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:d,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:u,sendDaemonCommand:x}){var m;const[h,p]=a.useState(l);a.useEffect(()=>{p(l)},[l]);const v=a.useMemo(()=>({ide:r.length,cli:i.length,acp:o.length}),[r.length,i.length,o.length]);return e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 h-full",children:[e.jsxs("div",{className:"flex flex-col gap-1 pb-4 border-b border-[#ffffff0a] mb-4",children:[e.jsx("div",{className:"text-lg font-semibold text-text-primary",children:"Workspace Launcher"}),e.jsx("div",{className:"text-sm text-text-secondary",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-baseline gap-4 mb-4",children:[e.jsx("div",{className:"flex bg-bg-surface p-1 rounded-lg border border-[#ffffff0a] w-fit",children:Gn.map(C=>e.jsxs("button",{type:"button",className:`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${h===C.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>p(C.id),children:[e.jsx("span",{children:C.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===C.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:v[C.id]})]},C.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(m=Gn.find(C=>C.id===h))==null?void 0:m.helper})]}),h==="ide"&&e.jsx(Ts,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:d,actions:c,sendDaemonCommand:x,initialWorkspaceId:f,initialWorkspacePath:u}),h==="cli"&&e.jsx(Ts,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:d,actions:c,sendDaemonCommand:x,initialWorkspaceId:f,initialWorkspacePath:u}),h==="acp"&&e.jsx(Ts,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:d,actions:c,sendDaemonCommand:x,initialWorkspaceId:f,initialWorkspacePath:u})]})}function xl({onNicknameSynced:t}={}){var te,ue,xe,X,me,se,pe,Y,ie;const{id:s}=Ta(),n=St(),r=zs(),{sendCommand:i}=ut(),o=Ys(),c=o.ides||[],d=o.initialLoaded??!0,l=c.find(S=>S.id===s&&S.daemonMode),f=c.some(S=>S.type==="adhdev-daemon"),[u,x]=a.useState("workspace"),[h,p]=a.useState("ide"),v=a.useRef(null),[m,C]=a.useState(null),b=a.useRef("__home__"),[w,N]=a.useState("__home__"),[D,g]=a.useState(!1),j=a.useRef(null),y=()=>{if(f){n("/dashboard",{state:{mobileSection:"machines"}});return}n("/machines")},k=tl({machineId:s,registeredMachineId:(l==null?void 0:l.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:j});a.useEffect(()=>lt.onToast(Z=>{o.setToasts(re=>{if(re.some(Ce=>Ce.message===Z.message&&Z.timestamp-Ce.timestamp<3e3))return re;const ye={id:Z.id,message:Z.message,type:Z.type,timestamp:Z.timestamp,targetKey:Z.targetKey,actions:Z.actions};return[...re.slice(-4),ye]});const Q=Z.duration||5e3;setTimeout(()=>o.setToasts(re=>re.filter(fe=>fe.id!==Z.id)),Q)}),[o]);const E=(l==null?void 0:l.availableProviders)||[],$={};for(const S of E)$[S.type]=S.icon;const A=S=>$[S]||"",U=l?{id:l.id,hostname:br(l,{fallbackId:l.id}),platform:((te=l.machine)==null?void 0:te.platform)||"unknown",arch:((ue=l.machine)==null?void 0:ue.arch)||"",cpus:((xe=l.machine)==null?void 0:xe.cpus)||0,totalMem:((X=l.machine)==null?void 0:X.totalMem)||0,freeMem:((me=l.machine)==null?void 0:me.freeMem)||0,availableMem:(se=l.machine)==null?void 0:se.availableMem,loadavg:((pe=l.machine)==null?void 0:pe.loadavg)||[],uptime:((Y=l.machine)==null?void 0:Y.uptime)||0,release:((ie=l.machine)==null?void 0:ie.release)||"",cdpConnected:!!l.cdpConnected,machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null}:null,L=c.filter(S=>S.daemonId===s&&!S.daemonMode).filter(S=>!rs(S)&&!_t(S)).map(S=>({id:S.id,sessionId:S.sessionId,type:S.type,version:S.version||"",instanceId:S.instanceId||"",status:S.status,workspace:S.workspace||null,terminals:S.terminals||0,aiAgents:_i(S.aiAgents||S.agents||[]),activeChat:S.activeChat||null,chats:S.chats||[],childSessions:S.childSessions||[],cdpConnected:S.cdpConnected||!1,daemonId:s})),T=c.filter(S=>S.daemonId===s&&rs(S)).map(S=>({id:S.id,sessionId:S.sessionId,type:S.type,cliName:S.cliName||S.type,status:S.status,workspace:S.workspace||"",activeChat:S.activeChat||null,providerSessionId:S.providerSessionId,mode:S.mode,daemonId:s})),z=c.filter(S=>S.daemonId===s&&_t(S)).map(S=>({id:S.id,sessionId:S.sessionId,type:S.type,acpName:S.cliName||S.type,status:S.status,workspace:S.workspace||"",activeChat:S.activeChat||null,providerSessionId:S.providerSessionId,currentModel:S.currentModel,currentPlan:S.currentPlan,daemonId:s}));if(!U)return d?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:y,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const W=nt(l,{fallbackId:U.id}),K="workspace",M=r.state,P=M==null?void 0:M.initialMachineTab,_=M==null?void 0:M.initialWorkspaceCategory,R=M==null?void 0:M.initialWorkspaceId,F=M==null?void 0:M.initialWorkspacePath,ce=P==="ides"||P==="clis"||P==="acps"?"workspace":P||K,de=P==="ides"?"ide":P==="clis"?"cli":P==="acps"?"acp":_,he=[...L.map(S=>{var Z,Q,re,fe,ye;return{id:`ide:${S.type}:${S.workspace||""}`,label:((Z=S.activeChat)==null?void 0:Z.title)||S.type,kind:"ide",providerType:S.type,subtitle:S.workspace||void 0,workspace:S.workspace||void 0,timestamp:((ye=(fe=(re=(Q=S.activeChat)==null?void 0:Q.messages)==null?void 0:re.at)==null?void 0:fe.call(re,-1))==null?void 0:ye.timestamp)||0}}),...T.map(S=>{var Z,Q,re,fe,ye;return{id:`cli:${S.type}:${S.workspace||""}`,label:((Z=S.activeChat)==null?void 0:Z.title)||S.cliName,kind:"cli",providerType:S.type,providerSessionId:S.providerSessionId,subtitle:S.workspace||void 0,workspace:S.workspace||void 0,timestamp:((ye=(fe=(re=(Q=S.activeChat)==null?void 0:Q.messages)==null?void 0:re.at)==null?void 0:fe.call(re,-1))==null?void 0:ye.timestamp)||0}}),...z.map(S=>{var Z,Q,re,fe,ye;return{id:`acp:${S.type}:${S.workspace||""}`,label:((Z=S.activeChat)==null?void 0:Z.title)||S.acpName,kind:"acp",providerType:S.type,providerSessionId:S.providerSessionId,subtitle:S.currentModel||S.workspace||void 0,workspace:S.workspace||void 0,currentModel:S.currentModel,timestamp:((ye=(fe=(re=(Q=S.activeChat)==null?void 0:Q.messages)==null?void 0:re.at)==null?void 0:fe.call(re,-1))==null?void 0:ye.timestamp)||0}})].sort((S,Z)=>Z.timestamp-S.timestamp).map(({timestamp:S,...Z})=>Z),H=(l.recentLaunches||[]).length>0?l.recentLaunches.map(S=>({id:S.id,label:S.title||S.providerName||S.providerType,kind:S.kind,providerType:S.providerType,providerSessionId:S.providerSessionId,subtitle:S.currentModel||S.workspace||void 0,workspace:S.workspace,currentModel:S.currentModel})):he,J=a.useCallback(()=>{v.current&&(g(!0),v.current().finally(()=>{v.current=null,g(!1),C(null)}))},[]),ee=a.useCallback(S=>{const{options:Z,selectedKey:Q}=ht({machine:U,currentWorkspacePath:S.workspace}),re=async()=>{p(S.kind),x("workspace")};v.current=async()=>{const fe=Z.find(Me=>Me.key===b.current),ye=(fe==null?void 0:fe.workspacePath)??null,Ce=(fe==null?void 0:fe.workspaceId)??null;if(S.kind==="ide"&&S.providerType){await k.handleLaunchIde(S.providerType,ye?{workspace:ye}:void 0);return}if((S.kind==="cli"||S.kind==="acp")&&S.providerType){await k.runLaunchCliCore({cliType:S.providerType,dir:Ce?void 0:ye||"",workspaceId:Ce||void 0,model:S.kind==="acp"?S.currentModel:void 0,resumeSessionId:S.providerSessionId});return}await re()},b.current=Q,N(Q),C({title:`Launch ${S.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:Z,details:[{label:"Mode",value:S.kind.toUpperCase()},...S.providerType?[{label:"Provider",value:S.providerType}]:[]]})},[k,U]);a.useEffect(()=>{x(ce)},[K,ce,U.id]),a.useEffect(()=>{de&&p(de)},[de,U.id]);const ge=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ve,{size:14})," Workspace"]}),count:L.length+T.length+z.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ya,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Va,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:y,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[k.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:k.nicknameInput,onChange:S=>k.setNicknameInput(S.target.value),onKeyDown:S=>{S.key==="Enter"&&k.handleSaveNickname(),S.key==="Escape"&&k.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:k.handleSaveNickname,className:"flex items-center justify-center px-3 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 text-sm font-medium transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>k.setEditingNickname(!1),className:"flex items-center justify-center px-3 py-1 rounded bg-[#ffffff0a] text-text-muted hover:bg-[#ffffff14] hover:text-text-primary text-sm font-medium transition-colors",children:"Cancel"})]}):e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-text-primary cursor-pointer truncate hover:text-accent-primary transition-colors",onClick:()=>{k.setEditingNickname(!0),k.setNicknameInput(U.machineNickname||"")},title:"Click to set nickname",children:W}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)] shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 items-center mt-1.5 text-xs text-text-secondary opacity-80",children:[e.jsxs("span",{className:"font-mono bg-[#ffffff08] px-1.5 py-0.5 rounded",children:[U.platform," · ",U.arch]}),e.jsxs("span",{children:[U.cpus," cores"]}),(l==null?void 0:l.version)&&e.jsxs("span",{children:["v",l.version]}),U.p2p.available&&e.jsxs("span",{children:["P2P ",U.p2p.state==="connected"?"connected":U.p2p.state]}),U.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:U.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:ge.map(S=>e.jsxs("button",{onClick:()=>x(S.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${u===S.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[S.label,S.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${u===S.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:S.count})]},S.id))})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 md:px-8 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto h-full",children:e.jsxs("div",{className:"h-full",children:[u==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(dl,{machineEntry:l,providers:E,recentLaunches:H,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenRecent:ee}),e.jsx(ml,{machine:U,machineId:s,providers:E,ideSessions:L,cliSessions:T,acpSessions:z,actions:k,getIcon:A,initialCategory:h,initialWorkspaceId:R,initialWorkspacePath:F,sendDaemonCommand:i})]}),u==="providers"&&e.jsx(il,{machineId:s,providers:E,sendDaemonCommand:i}),u==="overview"&&e.jsx(sl,{machineId:s,machine:U,ideSessions:L,cliSessions:T,acpSessions:z,actions:k,sendDaemonCommand:i}),u==="logs"&&e.jsx(ol,{machineId:s,sendDaemonCommand:i})]})})}),k.launchPick&&U&&e.jsx(cl,{machine:U,launchPick:k.launchPick,actions:k}),m&&e.jsx(rn,{title:m.title,description:m.description,details:m.details,workspaceOptions:m.workspaceOptions,selectedWorkspaceKey:w,onWorkspaceChange:S=>{b.current=S,N(S)},confirmLabel:m.confirmLabel,busy:D,onConfirm:J,onCancel:()=>{v.current=null,C(null)}}),e.jsx(jr,{toasts:o.toasts||[],onDismiss:S=>o.setToasts(Z=>Z.filter(Q=>Q.id!==S)),onClickToast:S=>{S.targetKey}}),e.jsx("style",{children:`
57
- @keyframes toast-in {
58
- from { opacity: 0; transform: translateX(40px); }
59
- to { opacity: 1; transform: translateX(0); }
60
- }
61
- `})]})}function fl(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],f=[],u=[];Object.values(c.providers||{}).forEach(h=>{const p={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(p):h.category==="cli"?l.push(p):h.category==="extension"?f.push(p):h.category==="acp"&&u.push(p)});const x=(h,p)=>{const v={Stable:1,Beta:2,WIP:3},m=v[h.status]||99,C=v[p.status]||99;return m!==C?m-C:h.name.localeCompare(p.name)};s({ide:d.sort(x),cli:l.sort(x),ext:f.sort(x),acp:u.sort(x)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(or,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Vs,{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(lr,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),widthClassName:"max-w-5xl",children:e.jsx(Js,{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(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),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(Ve,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Fe,{title:"Standalone CLI agents",icon:e.jsx(qs,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Fe,{title:"AI extensions",icon:e.jsx(bt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Fe,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(bt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class hl{constructor(){Ke(this,"adapters",new Map);Ke(this,"states",new Map);Ke(this,"runtimeListeners",new Map);Ke(this,"screenshotCallbacks",new Map);Ke(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}emitSessionOutput(s,n,r){!s||typeof n!="string"||!n||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof r=="number"?{seq:r}:{},data:n})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(n),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const i=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const rt=new hl;function bl(){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 Yn=bl(),Xn=3e3,gl=3e4;let at=null,yl=0;const ds=new Map;let mt=null,Rt=null;function Zn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function vl(t){return t==="connected"?"connected":t}async function ts(t,s,n){const r=Qi(t,n||{}),i=at;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++yl}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{ds.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);ds.set(o,{resolve:f=>{clearTimeout(l),c(f)},reject:f=>{clearTimeout(l),d(f)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class wl{constructor(s){Ke(this,"daemonId");Ke(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(at==null?void 0:at.readyState)===WebSocket.OPEN}get connectionState(){return(at==null?void 0:at.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return ts(this.daemonId,s,n)}async sendInput(s,n){return ts(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,mt&&(clearInterval(mt),mt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await ts(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());rt.emitScreenshot(this.daemonId,i)}}catch{}};n(),mt=setInterval(n,2e3)}stopScreenshots(s){mt&&(clearInterval(mt),mt=null)}}let Qe=null;function jl(t){return(!Qe||Qe.daemonId!==t)&&(Qe=new wl(t)),Qe}function kl({children:t}){const s=a.useRef(xn()),n=xn();s.current=n;const{setUserName:r}=$t(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,p)=>{o(h),Rt==null||Rt(h,p)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Xn),u=a.useRef(!0),x=a.useRef(!1);return a.useEffect(()=>{u.current=!0,x.current=!1;function h(){var m,C;if(!u.current||((m=d.current)==null?void 0:m.readyState)===WebSocket.OPEN||((C=d.current)==null?void 0:C.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Yn}...`);let v;try{v=new WebSocket(Yn)}catch(b){console.error("[Standalone WS] Failed to create WebSocket:",b),p();return}d.current=v,v.onopen=()=>{if(!u.current){v.close();return}c("connected"),f.current=Xn,console.log("[Standalone WS] Connected")},at=v,v.onmessage=b=>{var w;try{const N=JSON.parse(b.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const D=ds.get(N.requestId);D&&(ds.delete(N.requestId),N.type==="error"?D.reject(new Error(((w=N.data)==null?void 0:w.message)||"Command failed")):D.resolve(N.data));return}if(N.type==="session_output"){const D=N.sessionId||N.cliId||N.cliType;D&&rt.emitSessionOutput(D,typeof N.data=="string"?N.data:"",typeof N.seq=="number"?N.seq:void 0);return}if(N.type==="runtime_snapshot"){rt.emitRuntimeSnapshot(N.sessionId,typeof N.text=="string"?N.text:"",typeof N.seq=="number"?N.seq:0,!!N.truncated);return}if(N.type==="status"||N.type==="initial_state"){const D=N.data;if(!D)return;const{injectEntries:g,markLoaded:j}=s.current,y=D.id||"standalone",k=jl(y);rt.register(y,k),rt.setState(y,"connected"),c("connected",y),rt.emitStatus(y,D);const E=Zi(D,{daemonId:y});Zn("ws_status",{type:N.type,daemonId:y,sessions:(D.sessions||[]).map($=>({id:$.id,parentId:$.parentId,providerType:$.providerType,kind:$.kind,transport:$.transport,unread:$.unread,inboxBucket:$.inboxBucket,lastSeenAt:$.lastSeenAt,lastUpdated:$.lastUpdated,title:$.title})),recentLaunches:(D.recentLaunches||[]).map($=>({id:$.id,providerType:$.providerType,kind:$.kind,workspace:$.workspace,lastLaunchedAt:$.lastLaunchedAt}))}),Zn("entries",{daemonId:y,entries:E.filter($=>$.type!=="adhdev-daemon").map($=>({id:$.id,type:$.type,unread:$.unread,inboxBucket:$.inboxBucket,lastSeenAt:$.lastSeenAt,lastUpdated:$.lastUpdated,sessionId:$.sessionId}))}),E.length>0&&g(E,{authoritativeDaemonIds:[y]}),j(),D.userName&&i.current&&i.current(D.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},v.onclose=()=>{u.current&&(Qe==null||Qe.stopScreenshots(),Qe&&rt.setState(Qe.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},v.onerror=b=>{x.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",b)}}function p(){if(!u.current)return;clearTimeout(l.current);const v=f.current;console.log(`[Standalone WS] Reconnecting in ${v}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,gl),h()},v)}return h(),()=>{u.current=!1,x.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,at=null),Qe&&(Qe.stopScreenshots(),rt.unregister(Qe.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Nl({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(Rt=(c,d)=>{n(c),d&&i(d)},()=>{Rt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=vl(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(Da,{connectionOverrides:o,children:e.jsx(kl,{children:t})})}const Sl=[{id:"dashboard",path:"/dashboard",icon:e.jsx(ar,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ss,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(us,{}),label:"Settings"}];function Cl({children:t}){const s=St(),n=zs(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const x=!u;try{localStorage.setItem("sidebar-collapsed",x?"1":"0")}catch{}return x})},f=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Sl.map(u=>e.jsxs("div",{className:f(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ns,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ir,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.17"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Il=[{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(it,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(cr,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Ve,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(bt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(ns,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Ml=[{icon:e.jsx(ur,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(ar,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(ps,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Fa,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ua,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(or,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],_l=[{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 Tl(){return e.jsxs(is,{icon:e.jsx(ir,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.8.17"]}),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:Il.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-bg-secondary text-text-secondary border border-border-subtle",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(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:Sr.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Ir.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Cr.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:Ml.map(t=>e.jsxs("div",{className:"rounded-xl border border-accent-primary/20 bg-accent-primary/5 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(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-accent-primary text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:_l.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(Js,{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(si,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Al(){const{ides:t}=$t(),s=t.find(x=>x.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=ut(),{userName:i}=$t(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=x=>{const h=x.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=x=>{f(x);try{localStorage.setItem("adhdev_sound",x?"1":"0")}catch{}};return e.jsxs(is,{icon:e.jsx(us,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(fo,{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.8.17"]}),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(x=>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 ${x.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:x.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:x.type})]},x.type))})}),e.jsx(Fe,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(jo,{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(Co,{})]}),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(Ko,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Mobile"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose whether phones open the dashboard as a chat app first or in the full workspace layout."}),e.jsx(Oo,{})]})]})}),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(wo,{}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ti,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),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(Ha,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:x=>c(x.target.value),onBlur:d,onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()}})]})})})]})}vo();Do();Ro();const Ll=nr({baseUrl:""});function Jn(){const{ides:t,initialLoaded:s}=$t();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const n=t.find(r=>r.daemonMode||r.type==="adhdev-daemon");return n?e.jsx(As,{to:`/machines/${n.id}`,replace:!0}):e.jsx(As,{to:"/dashboard",replace:!0})}function Rl(){return e.jsx(Aa,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Wa,{client:Ll,children:e.jsx(Nl,{children:e.jsx(za,{value:{sendCommand:ts,sendData:()=>!1},children:e.jsx(Cl,{children:e.jsxs(La,{children:[e.jsx(ct,{path:"/dashboard",element:e.jsx(el,{})}),e.jsx(ct,{path:"/machine",element:e.jsx(Jn,{})}),e.jsx(ct,{path:"/machines/:id",element:e.jsx(xl,{})}),e.jsx(ct,{path:"/machines",element:e.jsx(Jn,{})}),e.jsx(ct,{path:"/capabilities",element:e.jsx(fl,{})}),e.jsx(ct,{path:"/about",element:e.jsx(Tl,{})}),e.jsx(ct,{path:"/settings",element:e.jsx(Al,{})}),e.jsx(ct,{path:"*",element:e.jsx(As,{to:"/dashboard",replace:!0})})]})})})})})})}Wi({connectionManager:rt});Ra(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Rl,{})}));