@adhdev/daemon-standalone 0.8.21 → 0.8.22
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.
- package/dist/index.js +26 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-BzvPgD4B.js +61 -0
- package/public/index.html +1 -1
- package/public/assets/index-C8mhaDTP.js +0 -61
|
@@ -0,0 +1,61 @@
|
|
|
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 ci=Object.defineProperty;var li=(t,s,r)=>s in t?ci(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var tt=(t,s,r)=>li(t,typeof s!="symbol"?s+"":s,r);import{r as a,j as e,M as Dn,a as Bn,b as di,c as ui,u as Yt,R as et,t as pi,d as mi,e as fi,D as xi,f as hi,g as bi,h as yr,i as gi,k as yi,B as vi,l as wi,m as Nt,N as lr,n as ji}from"./vendor-CPghmr9Y.js";import{_ as ki}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"]'))n(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"&&n(c)}).observe(document,{childList:!0,subtree:!0});function r(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 n(i){if(i.ep)return;i.ep=!0;const o=r(i);fetch(i.href,o)}})();const Kn=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}),Wn=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function zr(t){var r,n;let s=0;return"activeChat"in t&&(s+=4),(r=t.childSessions)!=null&&r.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(n=t.agents)!=null&&n.length&&(s+=1),s}function Ys(t,s,r){if(r.type!=="adhdev-daemon")return r;const n={...r},i=s.version??r.version??t.version,o=s.serverVersion??t.serverVersion??r.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(n.version=i),o&&(n.serverVersion=o),i&&o&&i===o?(delete n.versionMismatch,delete n.serverVersion,n):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(n.versionMismatch=!0),n)}function As(t){return Array.isArray(t)?t.map(As):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).filter(([s])=>s!=="timestamp"&&s!=="_lastUpdate").sort(([s],[r])=>s.localeCompare(r)).map(([s,r])=>[s,As(r)]))}function Ni(t,s){try{return JSON.stringify(As(t))===JSON.stringify(As(s))}catch{return!1}}function xs(t,s,r){return Ni(t,s)?(t._lastUpdate=r,typeof s.timestamp=="number"&&(t.timestamp=s.timestamp),t):s}function Si(t,s,r){var d,x,l,f,h,m,y;const n=Date.now(),i=new Set((r==null?void 0:r.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(p=>({...p,_lastUpdate:n}));const o=new Map;for(const p of s)o.set(p.id,p);for(const p of t){const g=o.get(p.id);if(!g){o.set(p.id,{...p,_lastUpdate:n});continue}const b=zr(p),v=zr(g);if(b>v){const S=(d=p.chats)!=null&&d.length?p.chats:g.chats,B=Ys(g,p,{...g,...p,chats:S,_lastUpdate:n});o.set(p.id,xs(g,B,n))}else if(b<v){const S={};if(p.status&&p.status!==g.status&&(S.status=p.status),p.cdpConnected!==void 0&&(S.cdpConnected=p.cdpConnected),(x=p.chats)!=null&&x.length&&!((l=g.chats)!=null&&l.length)&&(S.chats=p.chats),p.machineNickname!==void 0&&p.machineNickname!==g.machineNickname&&(S.machineNickname=p.machineNickname),p.version!==void 0&&(S.version=p.version),p.serverVersion!==void 0&&(S.serverVersion=p.serverVersion),p.versionMismatch===!0&&(S.versionMismatch=!0),Object.keys(S).length>0){const B=Ys(g,p,{...g,...S,_lastUpdate:g._lastUpdate});o.set(p.id,xs(g,B,n))}else xs(g,{...g,_lastUpdate:g._lastUpdate},n)}else{const S=p.timestamp||n,B=g._lastUpdate||g.timestamp||0;if(S>=B){const j=(f=p.chats)!=null&&f.length?p.chats:g.chats,C=Ys(g,p,{...g,...p,chats:j,_lastUpdate:n});o.set(p.id,xs(g,C,n))}else(h=p.chats)!=null&&h.length&&!((m=g.chats)!=null&&m.length)&&o.set(p.id,{...g,chats:p.chats})}}const c=new Set(t.map(p=>p.id)),u=new Set;for(const p of t){const g=p.daemonId||((y=p.id)==null?void 0:y.split(":")[0]);g&&u.add(g)}for(const[p,g]of o){const b=g.daemonId||p.split(":")[0];if(!u.has(b))continue;if(i.has(b)&&!c.has(p)){o.delete(p);continue}const v=n-(g._lastUpdate||g.timestamp||0);(g.transport==="pty"&&!c.has(p)&&v>1e4||g.transport==="acp"&&!c.has(p)&&v>1e4||g.transport==="cdp-page"&&!c.has(p)&&v>3e4)&&o.delete(p)}for(const[p,g]of o)n-(g._lastUpdate||g.timestamp||0)>3e5&&g.status!=="online"&&o.delete(p);return Array.from(o.values())}function Ci(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Ii({children:t,connectionOverrides:s}){const[r,n]=a.useState([]),[i,o]=a.useState(!1),[c,u]=a.useState([]),[d,x]=a.useState(void 0),l=a.useRef(r);a.useEffect(()=>{l.current=r},[r]);const f=a.useCallback((b,v)=>{n(S=>{let B=!1;const j=S.map(C=>C.id!==b||C.chats===v?C:(B=!0,{...C,chats:v}));return B?j:S})},[]),h=a.useCallback((b,v)=>{n(S=>{const B=S.length===0?b:Si(b,S,v);return Ci(S,B)?S:B})},[]),m=a.useCallback(()=>o(!0),[]),y=a.useMemo(()=>({injectEntries:h,markLoaded:m,getIdes:()=>l.current}),[h,m]),p=s,g=a.useMemo(()=>({ides:r,updateIdeChats:f,initialLoaded:i,toasts:c,setToasts:u,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:d,setUserName:x}),[r,f,i,c,p==null?void 0:p.wsStatus,p==null?void 0:p.isConnected,p==null?void 0:p.connectionStates,p==null?void 0:p.connectionTransports,p==null?void 0:p.showReconnected,p==null?void 0:p.retryConnection,p==null?void 0:p.isP2PActive,p==null?void 0:p.p2pStates,p==null?void 0:p.userRole,d]);return e.jsx(Wn.Provider,{value:y,children:e.jsx(Kn.Provider,{value:g,children:t})})}function as(){return a.useContext(Kn)}function Fr(){return a.useContext(Wn)}function On(t){const{baseUrl:s,getToken:r,onUnauthorized:n}=t;function i(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function o(u){const d=r==null?void 0:r(),x=i(u),l=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return d&&l.searchParams.set("token",d),!u.startsWith("http")&&!s?`${l.pathname}${l.search}${l.hash}`:l.toString()}async function c(u,d={}){const x={"Content-Type":"application/json",...d.headers||{}},l=r==null?void 0:r();l&&(x.Authorization=`Bearer ${l}`);const f=i(u),h=await fetch(f,{...d,headers:x});if(h.status===401)throw n==null||n(),new Error("Unauthorized");if(!h.ok){const m=await h.json().catch(()=>({error:h.statusText}));throw new Error(m.error||`API Error: ${h.status}`)}return h.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:u=>c(`/api/v1/daemons/${u}/status`),sendCommand:(u,d,x={})=>c(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),execTerminal:(u,d,x)=>c(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:d,name:x})}),sendAgentMessage:(u,d,x)=>c(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:d,message:x})}),getAgentStatus:u=>c(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,d,x)=>c(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:d,action:x?"approve":"reject"})}),getMuxState:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,d,x={})=>c(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),getMuxEventsUrl:u=>o(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeEventsUrl:u=>o(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:c}}const Ti=On({baseUrl:"http://localhost:3847"}),Ai=a.createContext(Ti);function _i({client:t,children:s}){return e.jsx(Ai.Provider,{value:t,children:s})}const Mi={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Un=a.createContext(Mi);function Pi({value:t,children:s}){return e.jsx(Un.Provider,{value:t,children:s})}function It(){return a.useContext(Un)}const Be={size:18};function zn({size:t=Be.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 vr({size:t=Be.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 _s({size:t=Be.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 Li({size:t=Be.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 Ri({size:t=Be.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 Ei({size:t=Be.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 Ms({size:t=Be.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 $i({size:t=Be.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 $s({size:t=Be.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 Fn({size:t=Be.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 Hn({size:t=Be.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 vt({size:t=Be.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 ot({size:t=Be.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 wr({size:t=Be.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 Di({size:t=Be.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 Gt({size:t=Be.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 Ds({size:t=Be.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 Bs({size:t=Be.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 $t({size:t=Be.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 Vn({size:t=Be.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 Bi({size:t=Be.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 jr({size:t=Be.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 Ki({size:t=Be.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 kr({size:t=Be.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 Wi({size:t=Be.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:"5",width:"18",height:"14",rx:"2"}),e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"})]})}function Nr({size:t=Be.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 Oi({size:t=Be.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:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Dt({size:t=Be.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 Gn({size:t=Be.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 Ui({size:t=Be.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 zi({size:t=Be.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 Fi({size:t=Be.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 Ks({size:t=Be.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 Hi({size:t=Be.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 Vi({size:t=Be.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 Gi({size:t=Be.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 qi({size:t=Be.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 Yi(t){var d,x;const s=l=>l.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),n=t.split(`
|
|
3
|
+
`).map(l=>{if(!l.includes("\r"))return l;const f=l.split("\r").map(y=>y.trim()).filter(Boolean);if(f.length===0)return"";const h=f.filter(y=>y.startsWith("⏺"));if(h.length>0)return h[h.length-1];const m=f.filter(y=>!(/^[❯›>]\s*$/.test(y)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(y)&&y.length<40||/^[╭╰│├╮╯─═]+$/.test(y)));return m.length>0?m[m.length-1]:f[f.length-1]}).join(`
|
|
4
|
+
`).split(`
|
|
5
|
+
`),i={},o=[];let c=!1;for(const l of n){const f=s(l);if(f===""){c=!1,o.push("");continue}if(/^❯\s*$/.test(f)||/^>\s*$/.test(f)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(f)||/^◐\s/.test(f)||/\/effort/.test(f)||/^⎿\s+(Tip|Note|Hint):/.test(f)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(f)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(f)||/Brewing[…\.]{0,3}\s*\d*$/i.test(f)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(f)||/^Auto-updating/i.test(f)||/^✳\s*Debug (?:Claude Code|Codex) CLI/i.test(f)||/^(?:─|═|╭|╰|│|├|╮|╯|┌|┐|└|┘|┬|┴|┼)+$/.test(f))continue;if(/^[⏺●·⏵]/.test(l)){const m=l.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(m)i[m[1]]=(i[m[1]]||0)+1;else{const y=l.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);y&&(i[y]=(i[y]||0)+1)}c=!0;continue}if(/^(?:Bash|Read|Write|Edit|MultiEdit|Task|Glob|Grep|LS|NotebookEdit|Exact output)(?:\(|:)/.test(f)){const m=((x=(d=f.match(/^([A-Za-z][A-Za-z0-9_ ]+)/))==null?void 0:d[1])==null?void 0:x.trim())||"Tool";i[m]=(i[m]||0)+1,c=!0;continue}if(/^Read\s+\d+\s+files?(?:\s+\(.*\))?$/i.test(f)){i.Read=(i.Read||0)+1,c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(l)||/^[╭╰│├╮╯─]+/.test(f)||/^\s+[⊙✓✗○◎▸►✦]/.test(l)||c&&/^\s{2,}/.test(l))continue;c=!1;const h=f.replace(/^❯\s+/,"");o.push(h)}const u=o.join(`
|
|
6
|
+
`).replace(/\n{3,}/g,`
|
|
7
|
+
|
|
8
|
+
`).trim();return{toolCounts:i,textContent:u,hasTools:Object.keys(i).length>0}}function dr(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Xi(t,s,r){const n=t;return Number(n.timestamp||n.receivedAt||n.createdAt||r[Ft(t,s)]||0)||0}function Ji(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ft(t,s){const r=t,n=typeof r.content=="string"?r.content:Array.isArray(r.content)?r.content.map(o=>(o==null?void 0:o.text)||"").join(`
|
|
9
|
+
`):String(r.content||"");return[r.id?`id:${r.id}`:"",r._localId?`local:${r._localId}`:"",r._turnKey?`turn:${r._turnKey}`:"",typeof r.index=="number"?`msgIndex:${r.index}`:"",r.timestamp?`ts:${r.timestamp}`:"",r.role?`role:${r.role}`:"",n?`content:${n.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const Hr=700,Zi=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Dn,{remarkPlugins:[Bn],children:s.text}),e.jsx("span",{className:"action-time",children:dr(s.timestamp)})]})},(t,s)=>t.log===s.log),Qi=a.memo(function({message:s,receivedAt:r,agentName:n,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:u,onToggleExpanded:d,onToggleTextExpanded:x}){var B;const l=(s.role||"").toLowerCase(),f=l==="user"||l==="human",h=s.kind||(l==="tool"?"tool":"standard"),m=typeof s.content=="string"?s.content:(s.content||[]).map(j=>j.text||"").join(`
|
|
10
|
+
`);if(h==="thought"){const j=((B=s.meta)==null?void 0:B.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(zi,{size:13}),e.jsx("span",{children:j})]}),e.jsx("div",{className:"chat-msg-body",children:m})]})}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:m.split(`
|
|
11
|
+
`)[0].slice(0,80)})]});if(h==="terminal"){const j=s.meta||{},C=j.isRunning?"⏳":"✅",w=j.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:C}),e.jsx("span",{children:w})]}),e.jsx("pre",{className:"chat-msg-body",children:m})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:m.slice(0,100)});const y=!f&&o?Yi(m):null,p=y?y.textContent:m,g=y?Object.entries(y.toolCounts):[],b=o&&!f&&!c&&p.length>Hr,v=c?m:b&&!u?p.slice(0,Hr):p,S=Ji(v);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${f?"self-end":"self-start"}`,children:[g.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[g.map(([j,C])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",j,C>1?` ×${C}`:""]},j)),(y==null?void 0:y.hasTools)&&e.jsx("button",{onClick:d,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!p&&r!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:dr(r)})]}),(p||f)&&e.jsxs("div",{className:`chat-bubble ${f?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${p?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:f?i||"You":s.senderName||n}),r!=null&&e.jsx("span",{className:"chat-time",children:dr(r)})]}),p&&e.jsx("div",{className:"chat-markdown",children:S?e.jsx(Dn,{remarkPlugins:[Bn,di,ui],children:v}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:v})}),b&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:u?"Collapse ↑":`Show more (${Math.round(p.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),eo=a.forwardRef(function({messages:s,actionLogs:r,agentName:n="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:u="",receivedAtMap:d={},emptyState:x,onLoadMore:l,isLoadingMore:f,hasMoreHistory:h,hiddenLiveCount:m=0,loadError:y,scrollToBottomRequestNonce:p},g){var Me;const b=a.useRef(null),v=a.useRef(null),S=a.useRef(null),B=a.useRef(0),j=a.useRef(""),C=a.useRef(!1),w=a.useRef(null),k=a.useRef(!1),E=a.useRef(null),L=a.useRef(!1),[$,R]=a.useState(new Set),[T,O]=a.useState(new Set),H=a.useRef(!1),D=()=>{const U=b.current;return U?U.scrollHeight-U.scrollTop-U.clientHeight<200:!0},F=a.useCallback((U="auto")=>{const ae=b.current;ae&&ae.scrollTo({top:ae.scrollHeight,behavior:U})},[]),_=a.useCallback(()=>{var me;const U=b.current,ae=(me=window.getSelection)==null?void 0:me.call(window);if(!U||!ae||ae.rangeCount===0||ae.isCollapsed){L.current=!1;return}const X=ae.anchorNode,pe=ae.focusNode;L.current=!!(X&&pe&&U.contains(X)&&U.contains(pe))},[]),A=a.useCallback((U="auto")=>{w.current!=null&&cancelAnimationFrame(w.current),w.current=requestAnimationFrame(()=>{w.current=null,F(U)})},[F]),M=s.length>0?`${s.length}:${(((Me=s[s.length-1])==null?void 0:Me.content)||"").length}`:"0:0";a.useEffect(()=>{const U=!C.current,ae=j.current!==u;if(j.current=u,U||ae){C.current=!0,H.current=!1,k.current=!0,L.current||A("auto"),B.current=s.length;return}s.length>B.current?!H.current&&!L.current&&A("auto"):D()&&!H.current&&!L.current&&A("auto"),B.current=s.length},[M,u,c,s.length,A]),a.useEffect(()=>{p&&(H.current=!1,k.current=!0,E.current!=null&&window.clearTimeout(E.current),E.current=window.setTimeout(()=>{k.current=!1,E.current=null},180),L.current||A("auto"))},[A,p]),a.useEffect(()=>()=>{w.current!=null&&cancelAnimationFrame(w.current),E.current!=null&&window.clearTimeout(E.current)},[]),a.useEffect(()=>{const U=v.current;if(!U)return;const ae=()=>{E.current!=null&&window.clearTimeout(E.current),E.current=window.setTimeout(()=>{k.current=!1,E.current=null},180)},X=new ResizeObserver(()=>{k.current&&(L.current||(A("auto"),ae()))});return X.observe(U),()=>{X.disconnect(),E.current!=null&&(window.clearTimeout(E.current),E.current=null)}},[A,u]),a.useImperativeHandle(g,()=>({scrollToBottom:(U="smooth")=>{F(U)}}),[F]),a.useEffect(()=>{const U=b.current;if(!U)return;let ae;const X=()=>{clearTimeout(ae),ae=setTimeout(()=>{H.current=!D()},50)};return U.addEventListener("scroll",X,{passive:!0}),()=>{U.removeEventListener("scroll",X),clearTimeout(ae)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",_),()=>document.removeEventListener("selectionchange",_)),[_]);const G=a.useRef(0),Y=a.useRef(!1);a.useEffect(()=>{const U=b.current;if(!U||!Y.current||G.current===0)return;const ae=U.scrollHeight-G.current;ae>0&&(U.scrollTop=ae),G.current=0,Y.current=!1},[s.length]);const ue=()=>{const U=b.current;U&&(G.current=U.scrollHeight),Y.current=!0,l==null||l()},ve=a.useMemo(()=>{const U=s.map((me,se)=>({type:"message",data:me,index:se,ts:Xi(me,se,d)}));if(!r||r.length===0)return U;const ae=[...r].sort((me,se)=>me.timestamp-se.timestamp).map((me,se)=>({type:"action",data:me,index:se,ts:me.timestamp})),X=[];let pe=0;for(const me of U){for(;pe<ae.length&&me.ts>0&&ae[pe].ts<me.ts;)X.push(ae[pe++]);X.push(me)}for(;pe<ae.length;)X.push(ae[pe++]);return X},[s,r,d]),Te=m>0||!!h,ee=m>0?`↑ Show ${Math.min(m,80)} earlier messages${m>80?` (${m} hidden)`:""}`:y?`↻ ${y}`:"↑ Load older messages";return e.jsx("div",{ref:b,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:v,className:"chat-container-content",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),Te&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:ue,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${y&&m===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:ee})}),ve.length===0&&!Te&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),ve.map(U=>{if(U.type==="action"){const oe=U.data;return e.jsx(Zi,{log:oe},`action-${U.index}`)}const ae=U.data,X=U.index,pe=Ft(ae,X),me=ae.receivedAt||d[pe],se=`${u}-${pe}`,de=$.has(se),xe=T.has(se);return e.jsx(Qi,{message:ae,receivedAt:me,agentName:n,userName:i,isCliMode:o,isExpanded:de,isTextExpanded:xe,onToggleExpanded:()=>R(oe=>{const J=new Set(oe);return de?J.delete(se):J.add(se),J}),onToggleTextExpanded:()=>O(oe=>{const J=new Set(oe);return xe?J.delete(se):J.add(se),J})},`msg-${pe}`)}),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:S})]})})}),to=a.memo(eo,(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&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce);let Vr=!1;const qn=a.forwardRef(({onInput:t,onResize:s,fontSize:r=13,readOnly:n=!1},i)=>{const o=a.useRef(null),[c,u]=a.useState(null),d=a.useRef([]),x=a.useRef(!1),l=a.useRef(!1),f=a.useRef(!1),h=()=>{const m=o.current;if(m){x.current&&(m.clear(),x.current=!1);for(const y of d.current)m.write(y);d.current=[],l.current&&(m.fit(),l.current=!1),f.current&&(m.bumpResize(),f.current=!1)}};return a.useImperativeHandle(i,()=>({write:m=>{o.current?o.current.write(m):d.current.push(m)},clear:()=>{o.current?o.current.clear():(d.current=[],x.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(d.current=[],x.current=!0)},resize:(m,y)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(m,y)},fit:()=>{o.current?o.current.fit():l.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():f.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const m=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(m)},[c]),a.useEffect(()=>{let m=!1;return ki(()=>import("./terminal-CKqklWLC.js").then(y=>y.i),__vite__mapDeps([0,1,2])).then(y=>{Vr||(Vr=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),m||u(()=>y.GhosttyTerminalView)}).catch(y=>{console.error("[CliTerminal] failed to load terminal renderer",y)}),()=>{m=!0}},[]),c?e.jsx(c,{ref:o,onInput:t,onResize:s,fontSize:r,readOnly:n,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"}})});qn.displayName="CliTerminal";function hs({label:t,value:s,sub:r,icon:n}){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:n}),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}),r&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:r})]})}function Gr({value:t,max:s,label:r,color:n="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,u=c>85?"#ef4444":c>60?"var(--status-warning)":n;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:r}),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:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:r}),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, ${u}, ${u}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function so({cursorPos:t,viewportRef:s,imgRef:r}){var v;if(!t||!r.current)return null;const n=r.current,i=n.getBoundingClientRect(),o=(v=s.current)==null?void 0:v.getBoundingClientRect();if(!o)return null;const c=n.naturalWidth||i.width,u=n.naturalHeight||i.height,d=c/u,x=i.width/i.height;let l,f,h,m;d>x?(l=i.width,f=i.width/d,h=0,m=(i.height-f)/2):(f=i.height,l=i.height*d,h=(i.width-l)/2,m=0);const y=i.left-o.left+h+l*t.nx,p=i.top-o.top+m+f*t.ny,g=Math.max(8,Math.min(o.width-8,y)),b=Math.max(8,Math.min(o.height-8,p));return e.jsxs("div",{style:{position:"absolute",left:g-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 ro({inputMode:t,onToggleInputMode:s,isImeOpen:r,setIsImeOpen:n,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:u,handleImeSubmit:d,isConnActive:x,zoom:l,isMobile:f,mobileFillZoom:h,onZoomOut:m,onZoomReset:y,onZoomIn:p,transportType:g,screenshotUsage:b,lastActionStatus:v}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:S=>S.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:()=>{n(S=>!S),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${r?"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:"⌨️"})}),r&&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:S=>S.stopPropagation(),onChange:S=>u(S.target.value),onKeyDown:S=>{d(S)},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(S=>!S),n(!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:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),l>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(l*100),"%"]}),g==="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"}),g==="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`}),v&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:v})]})]}),i&&e.jsxs("div",{onTouchStart:S=>S.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: ",l<=(f?h:1)+.01?f?"FILL":"FIT":`${Math.round(l*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:S=>{S.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:S=>{S.stopPropagation(),y()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:S=>{S.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:"+"})]})]})]})]})}function no({waitingLabel:t,waitingHint:s,transportType:r}){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}),r==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function ao(){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 qr(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 ps(t,s){const r=a.useRef(null),n=a.useRef(0);a.useEffect(()=>{if(!ao())return;n.current+=1;const i=r.current;if(!i){console.debug(`[render-trace] ${t}#${n.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,u])=>[c,qr(u)]))}),r.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}#${n.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,qr(s[c])]))}),r.current=s})}function io({containerRef:t,viewportRef:s,imgRef:r,inputMode:n,setInputMode:i,minZoom:o,zoomRef:c,panXRef:u,panYRef:d,setPanX:x,setPanY:l,setZoom:f,lastWheelTimeRef:h,onAction:m,setLastActionStatus:y,spawnRippleFromNormalized:p,clampPan:g,isMobile:b,mobileFillZoom:v}){const[S,B]=a.useState(null),j=a.useRef(null),C=a.useRef(null),w=a.useRef(null),k=a.useRef(!1),E=a.useRef(null),L=a.useRef(0),$=a.useRef(null),R=a.useRef(1),T=a.useRef({x:0,y:0}),O=a.useRef(!1),H=a.useRef(n),D=a.useRef(m),F=30,_=550,A=18,M=60,G=400,Y=12,ue=()=>{if(j.current)return;const ee={nx:.5,ny:.5};j.current=ee,B(ee)};return a.useEffect(()=>{H.current=n,n==="mouse"&&ue()},[n]),a.useEffect(()=>{D.current=m},[m]),a.useEffect(()=>{const ee=t.current;if(!ee)return;const Me=se=>{if(!r.current)return null;const de=r.current.getBoundingClientRect();return!de.width||!de.height?null:{nx:Math.max(0,Math.min(1,(se.clientX-de.left)/de.width)),ny:Math.max(0,Math.min(1,(se.clientY-de.top)/de.height))}},U=(se,de)=>{if(!r.current)return{dnx:0,dny:0};const xe=r.current,oe=xe.getBoundingClientRect(),J=xe.naturalWidth||oe.width,ce=xe.naturalHeight||oe.height,Q=J/ce,he=oe.width/oe.height;let I,re;return Q>he?(I=oe.width,re=oe.width/Q):(re=oe.height,I=oe.height*Q),{dnx:se/I,dny:de/re}},ae=(se,de,xe)=>{if(xe<=1.05)return;const oe=-(se-.5)*100,J=-(de-.5)*100,ce=g(oe,J,xe);(Math.abs(ce.x-u.current)>.1||Math.abs(ce.y-d.current)>.1)&&(x(ce.x),l(ce.y),u.current=ce.x,d.current=ce.y)},X=se=>{const de=s.current;if(de&&se.target instanceof Node&&de.contains(se.target))se.preventDefault();else return;if(se.touches.length===1){const xe=se.touches[0];C.current={x:xe.clientX,y:xe.clientY,time:Date.now()},w.current={x:xe.clientX,y:xe.clientY},O.current||(k.current=!1),E.current=setTimeout(()=>{if(!k.current&&!O.current)if(k.current=!0,H.current==="mouse"){const oe=j.current||{nx:.5,ny:.5};y("Right Click"),p(oe.nx,oe.ny,"right"),D.current("input_click",{...oe,button:"right"}).catch(()=>{})}else{const oe=Me(xe);oe&&(y("Right Click"),p(oe.nx,oe.ny,"right"),D.current("input_click",{...oe,button:"right"}).catch(()=>{}))}},500);return}if(se.touches.length===2){E.current&&clearTimeout(E.current),k.current=!0,O.current=!0;const xe=se.touches[1].clientX-se.touches[0].clientX,oe=se.touches[1].clientY-se.touches[0].clientY;$.current=Math.sqrt(xe*xe+oe*oe),R.current=c.current,T.current={x:(se.touches[0].clientX+se.touches[1].clientX)/2,y:(se.touches[0].clientY+se.touches[1].clientY)/2}}},pe=se=>{const de=s.current;if(de&&se.target instanceof Node&&de.contains(se.target)&&se.preventDefault(),se.touches.length===1&&w.current){const xe=se.touches[0],oe=xe.clientX-w.current.x,J=xe.clientY-w.current.y;if(!k.current&&C.current){const ce=xe.clientX-C.current.x,Q=xe.clientY-C.current.y;Math.sqrt(ce*ce+Q*Q)>8&&(k.current=!0,E.current&&clearTimeout(E.current))}if(k.current)if(H.current==="mouse"){const ce=U(oe,J),Q=j.current||{nx:.5,ny:.5},he=Math.max(0,Math.min(1,Q.nx+ce.dnx)),I=Math.max(0,Math.min(1,Q.ny+ce.dny));j.current={nx:he,ny:I},B({nx:he,ny:I}),y(`Cursor: ${Math.round(he*100)}%, ${Math.round(I*100)}%`),ae(he,I,c.current);const re=Date.now();re-h.current>=30&&(h.current=re,D.current("input_mouseMoved",{nx:he,ny:I}).catch(()=>{}))}else if(c.current>1){const ce=s.current;if(ce){const Q=ce.clientWidth,he=ce.clientHeight,I=u.current+oe/Q*100,re=d.current+J/he*100,W=g(I,re,c.current);x(W.x),l(W.y),u.current=W.x,d.current=W.y}}else{const ce=Me(xe);if(ce){const Q=Date.now();Q-h.current>=40&&(h.current=Q,y("Scroll"),D.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-oe*2.5),deltaY:Math.round(-J*2.5)}).catch(()=>{}))}}w.current={x:xe.clientX,y:xe.clientY};return}if(se.touches.length===2&&$.current!==null){const xe=se.touches[1].clientX-se.touches[0].clientX,oe=se.touches[1].clientY-se.touches[0].clientY,ce=Math.sqrt(xe*xe+oe*oe)/$.current,Q=(se.touches[0].clientX+se.touches[1].clientX)/2,he=(se.touches[0].clientY+se.touches[1].clientY)/2,I=Q-T.current.x,re=he-T.current.y,W=Math.abs(ce-1)>.03;if(H.current==="mouse"){if(W){const z=Math.max(o,Math.min(5,R.current*ce));f(z),c.current=z}else if(Math.abs(I)>2||Math.abs(re)>2){const z=j.current||{nx:.5,ny:.5},te=Date.now();te-h.current>=30&&(h.current=te,y("Scroll"),D.current("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(-I*3),deltaY:Math.round(-re*3)}).catch(()=>{}))}}else{const z=Math.max(o,Math.min(5,R.current*ce));f(z),c.current=z;const te=s.current;if(te&&z>1){const le=te.clientWidth,Ne=te.clientHeight,Pe=u.current+I/le*100,q=d.current+re/Ne*100,be=g(Pe,q,z);x(be.x),l(be.y),u.current=be.x,d.current=be.y}}T.current={x:Q,y:he}}},me=se=>{var de;if(E.current&&clearTimeout(E.current),$.current=null,se.touches.length===1&&O.current){const xe=se.touches[0];C.current={x:xe.clientX,y:xe.clientY,time:Date.now()},w.current={x:xe.clientX,y:xe.clientY},k.current=!0;return}if(se.touches.length===0){if(O.current){O.current=!1,k.current=!1;return}if(se.changedTouches.length===1){const xe=se.changedTouches[0],oe=Date.now(),J=oe-(((de=C.current)==null?void 0:de.time)||0),ce=C.current?xe.clientX-C.current.x:0,Q=C.current?xe.clientY-C.current.y:0,he=Math.sqrt(ce*ce+Q*Q);if(H.current==="mouse"){if(J<F||J>_||he>A){k.current=!1;return}const I=j.current||Me(xe);I&&(y(`Click: ${Math.round(I.nx*100)}%, ${Math.round(I.ny*100)}%`),p(I.nx,I.ny,"left"),D.current("input_click",{...I}).catch(()=>{}))}else{if(k.current){k.current=!1;return}if(J<M||J>G||he>Y){k.current=!1;return}const I=Me(xe);if(!I)return;oe-L.current<300?(y("Double tap"),p(I.nx,I.ny,"double"),D.current("input_click",{...I,clickCount:2}).catch(()=>{}),L.current=0):(y(`Tap: ${Math.round(I.nx*100)}%, ${Math.round(I.ny*100)}%`),p(I.nx,I.ny,"left"),D.current("input_click",{...I}).catch(()=>{}),L.current=oe)}}k.current=!1}};return ee.addEventListener("touchstart",X,{passive:!1}),ee.addEventListener("touchmove",pe,{passive:!1}),ee.addEventListener("touchend",me,{passive:!1}),()=>{ee.removeEventListener("touchstart",X),ee.removeEventListener("touchmove",pe),ee.removeEventListener("touchend",me),E.current&&clearTimeout(E.current)}},[t,s,r,o,c,u,d,x,l,f,h,y,p,g]),{cursorPos:S,cursorPosRef:j,handleToggleInputMode:()=>{i(ee=>{const Me=ee==="touch"?"mouse":"touch";return Me==="mouse"&&ue(),Me})},handleZoomReset:()=>{const ee=b?v:1;f(ee),c.current=ee,x(0),l(0),u.current=0,d.current=0}}}function Yn({onAction:t,addLog:s,connState:r,connScreenshot:n,screenshotUsage:i,transportType:o}){const c=a.useRef(null),u=a.useRef(null),d=a.useRef(null),[x,l]=a.useState(null),[f,h]=a.useState(""),[,m]=a.useState(!1),[y,p]=a.useState([]),g=a.useRef(0),[b,v]=a.useState(!1),[S,B]=a.useState(!1),j=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[C,w]=a.useState(j?"mouse":"touch"),[k,E]=a.useState(1),L=a.useRef(!1),[$,R]=a.useState(1),[T,O]=a.useState(0),[H,D]=a.useState(0);ps("RemoteView",{connState:r,hasScreenshot:!!n,inputMode:C,zoom:$,panX:T,panY:H,isMenuOpen:b,isImeOpen:S});const F=a.useRef(0),_=a.useRef($),A=a.useRef(T),M=a.useRef(H);a.useEffect(()=>{_.current=$},[$]),a.useEffect(()=>{A.current=T},[T]),a.useEffect(()=>{M.current=H},[H]),a.useEffect(()=>{var J;(J=c.current)==null||J.focus()},[]);const G=r==="connected",Y=n,ue=G?"Connected. Waiting for first frame...":r==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ve=G?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!j||L.current||!Y)return;const J=d.current,ce=u.current;if(!J||!ce)return;const Q=()=>{const he=ce.clientWidth,I=ce.clientHeight,re=J.naturalWidth,W=J.naturalHeight;if(!re||!W||!he||!I)return;const z=Math.min(he/re,I/W),le=Math.max(he/re,I/W)/z;le>1.01&&(E(le),R(le),_.current=le),L.current=!0};J.complete&&J.naturalWidth?Q():J.addEventListener("load",Q,{once:!0})},[Y,j]);const Te=.5;a.useEffect(()=>{$<=Te&&(O(0),D(0))},[$,Te]);const ee=(J,ce,Q)=>{if(Q<=Te)return{x:0,y:0};const he=(Q-1)/(2*Q)*100,I=(Q-1)/(2*Q)*100;return{x:Math.max(-he,Math.min(he,J)),y:Math.max(-I,Math.min(I,ce))}},Me=(J,ce)=>{if(!d.current)return null;const Q=d.current.getBoundingClientRect();return!Q.width||!Q.height?null:{nx:Math.max(0,Math.min(1,(J-Q.left)/Q.width)),ny:Math.max(0,Math.min(1,(ce-Q.top)/Q.height))}},U=(J,ce,Q)=>{const he=u.current;if(!he)return;const I=he.getBoundingClientRect(),re=++g.current;p(W=>[...W,{id:re,x:J-I.left,y:ce-I.top,type:Q}]),setTimeout(()=>p(W=>W.filter(z=>z.id!==re)),600)},ae=(J,ce,Q)=>{const he=d.current,I=u.current;if(!he||!I)return;const re=he.getBoundingClientRect(),W=I.getBoundingClientRect(),z=he.naturalWidth||re.width,te=he.naturalHeight||re.height,le=z/te,Ne=re.width/re.height;let Pe,q,be,Ae;le>Ne?(Pe=re.width,q=re.width/le,be=0,Ae=(re.height-q)/2):(q=re.height,Pe=re.height*le,be=(re.width-Pe)/2,Ae=0);const $e=re.left-W.left+be+Pe*J,He=re.top-W.top+Ae+q*ce,Oe=++g.current;p(Qe=>[...Qe,{id:Oe,x:$e,y:He,type:Q}]),setTimeout(()=>p(Qe=>Qe.filter(Z=>Z.id!==Oe)),600)},X=async J=>{var Q;const ce=Me(J.clientX,J.clientY);if(ce){l(`Click: ${Math.round(ce.nx*100)}%, ${Math.round(ce.ny*100)}%`),U(J.clientX,J.clientY,"left"),(Q=c.current)==null||Q.focus();try{const he=await t("input_click",{nx:ce.nx,ny:ce.ny});he!=null&&he.success||s(`❌ Click failed: ${he==null?void 0:he.error}`)}catch(he){s(`❌ Click error: ${he.message||he}`)}}},pe=async(J,ce,Q,he=0)=>{try{await t("input_key",{type:Q?"char":"keyDown",key:J,code:ce,text:Q?J:void 0,unmodifiedText:Q?J:void 0,modifiers:he})}catch(I){s(`❌ Key error: ${I.message||I}`)}},me=async J=>{if(J.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(J.key)&&J.preventDefault();let Q=0;J.altKey&&(Q|=1),J.ctrlKey&&(Q|=2),J.metaKey&&(Q|=4),J.shiftKey&&(Q|=8),l(`Key: ${J.key}`),await pe(J.key,J.code,J.key.length===1,Q)},se=async J=>{if(J.key==="Enter"){if(J.nativeEvent.isComposing)return;if(f){const ce=f;h(""),l(`IME Sent: ${ce}`);try{const Q=await t("input_type",{text:ce});Q!=null&&Q.success||s(`❌ IME error: ${Q==null?void 0:Q.error}`)}catch(Q){s(`❌ IME error: ${Q.message}`)}}else l("Key: Enter"),await pe("Enter","Enter",!1)}};a.useEffect(()=>{const J=c.current;if(!J)return;const ce=Q=>{var he;if((he=d.current)!=null&&he.contains(Q.target)){Q.preventDefault();const I=Date.now();if(I-F.current<40)return;F.current=I;const re=Me(Q.clientX,Q.clientY);if(!re)return;l(`Scroll: ${Math.round(Q.deltaY)}`),t("input_wheel",{nx:re.nx,ny:re.ny,deltaX:Math.round(Q.deltaX),deltaY:Math.round(Q.deltaY)}).catch(()=>{})}};return J.addEventListener("wheel",ce,{passive:!1}),()=>J.removeEventListener("wheel",ce)},[t]);const{cursorPos:de,handleToggleInputMode:xe,handleZoomReset:oe}=io({containerRef:c,viewportRef:u,imgRef:d,inputMode:C,setInputMode:w,minZoom:Te,zoomRef:_,panXRef:A,panYRef:M,setPanX:O,setPanY:D,setZoom:R,lastWheelTimeRef:F,onAction:t,setLastActionStatus:l,spawnRippleFromNormalized:ae,clampPan:ee,isMobile:j,mobileFillZoom:k});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:me,onContextMenu:J=>J.preventDefault(),onFocus:()=>m(!0),onBlur:()=>m(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[Y?e.jsx("img",{ref:d,src:Y,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${$}) translate(${T}%, ${H}%)`,transformOrigin:"center center",cursor:C==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:X,onContextMenu:J=>J.preventDefault(),onDragStart:J=>J.preventDefault()}):e.jsx(no,{waitingLabel:ue,waitingHint:ve,transportType:o}),C==="mouse"&&Y&&e.jsx(so,{cursorPos:de,viewportRef:u,imgRef:d}),y.map(J=>{const Q={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[J.type];return e.jsxs("div",{style:{position:"absolute",left:J.x,top:J.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${Q}, 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(${Q}, 0.9)`,boxShadow:`0 0 12px rgba(${Q}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},J.id)})]}),e.jsx(ro,{inputMode:C,onToggleInputMode:xe,isImeOpen:S,setIsImeOpen:B,isMenuOpen:b,setIsMenuOpen:v,imeText:f,setImeText:h,handleImeSubmit:se,isConnActive:G,zoom:$,isMobile:j,mobileFillZoom:k,onZoomOut:()=>R(J=>Math.max(.5,J-.25)),onZoomReset:oe,onZoomIn:()=>R(J=>Math.min(5,J+.25)),transportType:o,screenshotUsage:i,lastActionStatus:x}),e.jsx("style",{children:`
|
|
12
|
+
@keyframes slideUp {
|
|
13
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
14
|
+
to { opacity: 1; transform: translateY(0); }
|
|
15
|
+
}
|
|
16
|
+
@keyframes slideUpSidebar {
|
|
17
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
18
|
+
to { opacity: 1; transform: translateY(0); }
|
|
19
|
+
}
|
|
20
|
+
@keyframes click-ripple-ring {
|
|
21
|
+
0% { transform: scale(0.3); opacity: 1; }
|
|
22
|
+
100% { transform: scale(2.2); opacity: 0; }
|
|
23
|
+
}
|
|
24
|
+
@keyframes click-ripple-dot {
|
|
25
|
+
0% { transform: scale(1); opacity: 0.9; }
|
|
26
|
+
50% { transform: scale(1.8); opacity: 0.6; }
|
|
27
|
+
100% { transform: scale(0.5); opacity: 0; }
|
|
28
|
+
}
|
|
29
|
+
@keyframes remote-float {
|
|
30
|
+
0% { transform: translateY(0px); }
|
|
31
|
+
50% { transform: translateY(-7px); }
|
|
32
|
+
100% { transform: translateY(0px); }
|
|
33
|
+
}
|
|
34
|
+
`})]})}function Xn(t,s={}){if(!t)return"";const{suffix:r="",nowLabel:n="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return n;const u=Math.floor(c/60);if(u<60)return`${u}m${r}`;const d=Math.floor(u/60);if(d<24)return`${d}h${r}`;const x=Math.floor(d/24);return x<7?`${x}d${r}`:new Date(t).toLocaleDateString()}const Jn=t=>Xn(t);function oo(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function Ws(t){const s=t.connectionState==="failed"||t.connectionState==="closed",r=t.connectionState==="connecting"||t.connectionState==="new",n=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:r,isGenerating:n,isWaiting:i}}function ms(t){const s=new Map,r=(n,i)=>{n&&s.set(n,{sessionId:n,...oo(i)})};for(const n of t)if(!n.daemonMode){r(n.sessionId,n);for(const i of n.childSessions||[])r(i.id,i)}return s}function is(t,s){if(t.sessionId){const r=s.get(t.sessionId);if(r)return r}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function os(t,s,r){const n=is(t,s),i=Ws(t),o=i.isReconnecting,c=i.isConnecting,u=i.isGenerating,d=i.isWaiting,x=n.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||d,l=n.inboxBucket==="working"||u,f=n.inboxBucket==="task_complete"&&n.unread&&!(r!=null&&r.hideOpenTaskCompleteUnread&&(r!=null&&r.isOpenConversation));return{unread:f,requiresAction:x,isWorking:l,isReconnecting:o,isConnecting:c,isGenerating:u,isWaiting:d,inboxBucket:x?"needs_attention":l?"working":f?"task_complete":"idle"}}function co(t,s,r){return os(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:r==null?void 0:r.isOpenConversation}).unread}function lo(t,s,r){return is(t,r||new Map).surfaceHidden}function Zn({activeConv:t,onModalButton:s}){const[r,n]=a.useState(null);if(a.useEffect(()=>{n(null)},[t.modalMessage,t.status,t.connectionState]),!Ws(t).isWaiting||!t.modalButtons)return null;const o=u=>{r||(n(u),s(u))},c=u=>u.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(Bs,{size:14})," ",r?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((u,d)=>{const x=c(u).toLowerCase(),l=/^(run|approve|accept|yes|allow|always)/.test(x),f=/^(reject|deny|delete|remove|abort)/.test(x),h=r===u,m=r!==null;return e.jsx("button",{onClick:()=>o(u),disabled:m,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${l?"bg-white font-extrabold":f?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${m&&!h?"opacity-40":"opacity-100"} ${m?"cursor-not-allowed":"cursor-pointer"}`,style:l?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(u)},d)})})]})]})}const Yr=new Map,uo={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function po({ideId:t,sessionId:s,ideType:r,providerType:n,displayLabel:i,controls:o,controlValues:c,serverModel:u,serverMode:d}){const{sendCommand:x}=It(),l=`${t}:${s||n}`,f=uo[n]||"#94a3b8",[h,m]=a.useState({}),y=a.useRef(0),p={...u?{model:u}:{},...d?{mode:d}:{},...c||{},...Date.now()<y.current?h:{}};a.useEffect(()=>{c&&Date.now()>y.current&&m({})},[c]);const[g,b]=a.useState(Yr.get(l)||{}),[v,S]=a.useState(null),[B,j]=a.useState(null),C=a.useCallback(async(T,O={})=>{const H={...O,...s&&{targetSessionId:s}};return await x(t,T,H)},[t,s,x]);if(!o||o.length===0)return null;const w=o.filter(T=>T.placement==="bar").sort((T,O)=>(T.order??50)-(O.order??50));if(w.length===0)return null;const k=async T=>{var H,D,F;if(v===T.id){S(null);return}if((((H=T.options)==null?void 0:H.map(_=>_.value))||g[T.id]||[]).length>0){S(T.id);return}if(T.dynamic&&T.listScript){j(T.id);try{const _=await C(T.listScript==="listModels"?"list_extension_models":T.listScript==="listModes"?"list_extension_modes":T.listScript,{agentType:n,ideType:r}),M=((_==null?void 0:_.models)||(_==null?void 0:_.modes)||((D=_==null?void 0:_.result)==null?void 0:D.models)||((F=_==null?void 0:_.result)==null?void 0:F.modes)||(_==null?void 0:_.options)||[]).map(G=>typeof G=="string"?G:(G==null?void 0:G.name)||(G==null?void 0:G.id)||(G==null?void 0:G.value)||String(G));b(G=>{const Y={...G,[T.id]:M};return Yr.set(l,Y),Y}),S(T.id)}catch{}finally{j(null)}}},E=async(T,O)=>{S(null),m(H=>({...H,[T.id]:O})),y.current=Date.now()+5e3;try{if(!T.setScript)return;const H=Xs(T.setScript,n);await C(H,{agentType:n,ideType:r,model:T.id==="model"?O:void 0,mode:T.id==="mode"?O:void 0,value:O})}catch{}},L=async T=>{var A;const O=((A=T.options)==null?void 0:A.map(M=>M.value))||g[T.id]||[];if(O.length===0)return;const H=String(p[T.id]||""),F=(O.indexOf(H)+1)%O.length,_=O[F];if(typeof _=="string"){m(M=>({...M,[T.id]:_})),y.current=Date.now()+5e3;try{if(!T.setScript)return;const M=Xs(T.setScript,n);await C(M,{agentType:n,ideType:r,value:_})}catch{}}},$=async T=>{const H=!p[T.id];m(D=>({...D,[T.id]:H})),y.current=Date.now()+5e3;try{if(!T.setScript)return;const D=Xs(T.setScript,n);await C(D,{agentType:n,ideType:r,value:H})}catch{}},R=async T=>{if(T.invokeScript)try{await C("invoke_extension_script",{agentType:n,ideType:r,scriptName:T.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:f},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),w.map(T=>{var _;const O=String(p[T.id]||""),H=v===T.id,D=B===T.id,F=((_=T.options)==null?void 0:_.map(A=>A.value))||g[T.id]||[];switch(T.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:H?`${f}55`:"transparent",border:"1px solid",color:O?"var(--text-primary)":"var(--text-muted)"},onClick:()=>k(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),D?"...":O||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),H&&F.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(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:T.label.toUpperCase()}),F.map(A=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:A===O?`${f}18`:"transparent",color:A===O?f:"var(--text-secondary)",fontWeight:A===O?600:400,borderLeft:A===O?`2px solid ${f}`:"2px solid transparent"},onMouseEnter:M=>{M.currentTarget.style.background=`${f}12`},onMouseLeave:M=>{M.currentTarget.style.background=A===O?`${f}18`:"transparent"},onClick:()=>E(T,A),children:A},A))]})]})]},T.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:O?"var(--text-primary)":"var(--text-muted)"},onClick:()=>L(T),title:`Click to cycle: ${F.join(" → ")}`,children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),O||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},T.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:O?`${f}44`:"transparent",background:O?`${f}14`:"var(--surface-tertiary)",color:O?f:"var(--text-muted)"},onClick:()=>$(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.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:()=>R(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.id);default:return null}})]})}function Xs(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const mo=a.memo(function({contextKey:s,panelLabel:r,isSending:n,onSend:i,isActive:o=!0}){const c=a.useRef(null),[u,d]=a.useState("");a.useEffect(()=>{d("")},[s]),a.useEffect(()=>{var l;o&&((l=c.current)==null||l.focus())},[s,o]);const x=()=>{const l=u.trim();!l||n||(d(""),i(l))};return e.jsx("div",{className:"dashboard-input-area bg-[var(--surface-primary)] shrink-0 overflow-hidden transition-all duration-200 ease-out",style:{borderTop:o?"1px solid var(--border-subtle)":"1px solid transparent",maxHeight:o?72:0,opacity:o?1:0,transform:o?"translateY(0)":"translateY(10px)",padding:o?"10px 12px":"0 12px",pointerEvents:o?"auto":"none"},"aria-hidden":!o,children:e.jsxs("div",{className:"flex gap-2.5 items-center",title:o?`Send message to ${r}`:void 0,children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${r}...`,value:u,onChange:l=>d(l.target.value),onPaste:l=>{const f=l.clipboardData.getData("text");f&&d(h=>h+f),l.preventDefault()},onKeyDown:l=>{if(l.key==="Enter"){if(l.nativeEvent.isComposing){l.preventDefault();return}l.preventDefault(),x()}},onBlur:l=>{if(window.innerWidth<768){const f=l.relatedTarget;if((f==null?void 0:f.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:x,disabled:!u.trim()||n,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${u.trim()&&!n?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:u.trim()&&!n?{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:u.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var fo=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function xo(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function ct(t,s){if(xo(s==null?void 0:s.activeModal))return"waiting_approval";const r=String(t||"idle").trim().toLowerCase();return r==="waiting_approval"?"waiting_approval":fo.has(r)?"generating":r==="error"?"error":r==="stopped"?"stopped":r==="starting"?"starting":r==="panel_hidden"?"panel_hidden":r==="not_monitored"?"not_monitored":r==="disconnected"?"disconnected":"idle"}function Qn(t){return ct(t)==="generating"}function Ye(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ho(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const r=Math.floor(s/60),n=s%60;if(r<24)return n>0?`${r}h ${n}m`:`${r}h`;const i=Math.floor(r/24),o=r%24;return`${i}d ${o}h`}function Xr(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Os(t,s){const r=typeof s=="string"?s.trim():"";if(r)return r;const n=typeof t=="string"?t.trim():"";if(!n)return"";const i=n.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function bo(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),r=s[s.length-1];return r.length>12?`Machine-${r.substring(0,8)}`:r}return t}function go(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function yo(t){return bo(t.trim().replace(/\.local$/i,""))}function vo(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function ea(t,s={}){var i,o;const r=[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&&!go(c));if(r&&r!=="Unknown")return yo(r);const n=s.fallbackId||t.id;return n?`Machine-${n.substring(0,8)}`:s.fallbackLabel||"Machine"}function gt(t,s={}){return vo(t)||ea(t,s)}function cs(t){return t.transport==="pty"}function Ht(t){return t.transport==="acp"}function Jr(t,s){return Ye(t)}function Zr(t,s,r){const n=(t||"").trim().toLowerCase();if(!n)return!0;const i=(s||"").trim().toLowerCase(),o=(r||"").trim().toLowerCase(),c=Ye(r||"").trim().toLowerCase();return n===i||n===o||n===c}function wo(t){return ct(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function jo(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,r=["generating","waiting_approval","connected","idle","panel_hidden"];for(const n of t){const i=(n.name||n.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=ct(n.status);if(!o){s.set(i,{...n,status:c});continue}const u=r.indexOf(o.status||"idle"),d=r.indexOf(c||"idle");d>=0&&(u<0||d<u)&&s.set(i,{...n,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 ko(t){var r,n;const s=(n=(r=t==null?void 0:t.messages)==null?void 0:r.at)==null?void 0:n.call(r,-1);return s&&(Js(s.timestamp)||Js(s.receivedAt)||Js(s.createdAt))||0}function No(t){return(t.recentLaunches||[]).reduce((r,n)=>Math.max(r,n.lastLaunchedAt||0),0)}function ur(t){return Math.max(No(t),ko(t.activeChat))}function So(t,s,r,n,i,o){const c=s-t;if(c!==0)return c;const u=r.localeCompare(n);return u!==0?u:i.localeCompare(o)}function Sr(t,s){return So(ur(t),ur(s),gt(t,{fallbackId:t.id}),gt(s,{fallbackId:s.id}),t.id,s.id)}function ta({conversation:t,className:s="",onOpenNativeConversation:r,onOpenMachine:n,interactive:i=!0}){var y;const o=Yt(),c=t.daemonId||((y=t.ideId)==null?void 0:y.split(":")[0])||t.ideId,u=t.transport==="cdp-page"||t.transport==="cdp-webview",d=t.streamSource==="agent-stream"&&!!t.agentName,x=!d&&(t.transport==="pty"||t.transport==="acp"),l=t.agentName||Ye(t.agentType||t.ideType||""),f=(()=>{var p,g;if(t.streamSource==="agent-stream"){const b=(g=(p=t.displaySecondary)==null?void 0:p.split("·")[0])==null?void 0:g.trim();if(b)return b}return Ye(t.ideType||"")})(),h=a.useCallback(()=>{if(n){n();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,n]),m=a.useCallback(()=>{if(r){r();return}const p=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;p&&o(`/dashboard?activeTab=${encodeURIComponent(p)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,r]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[u&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:m,title:f,children:[e.jsx(ot,{size:12}),e.jsx("span",{children:f})]}):e.jsxs("span",{className:"conversation-meta-chip",title:f,children:[e.jsx(ot,{size:12}),e.jsx("span",{children:f})]})),d&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx($t,{size:12}),e.jsx("span",{children:t.agentName})]}),x&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:l,children:[e.jsx($t,{size:12}),e.jsx("span",{children:l})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:h,title:t.machineName,children:[e.jsx(_s,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(_s,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Xe=t=>t.transport==="pty",qt=(t,s)=>Xe(t)?s||t.mode||"terminal":"chat",sa=(t,s)=>Xe(t)&&qt(t,s)==="terminal",ze=t=>t.transport==="acp";function Ps(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 Bt(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 Qr(t){return[...t].sort((s,r)=>{const n=Bt(s),i=Bt(r);return n&&i&&n!==i?n-i:0})}function Co(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 r=String((t==null?void 0:t.role)||"").toLowerCase(),n=String((s==null?void 0:s.role)||"").toLowerCase();if(r!==n)return!1;const i=Ps(t==null?void 0:t.content),o=Ps(s==null?void 0:s.content);if(!i||i!==o)return!1;const c=Bt(t),u=Bt(s);return c&&u?Math.abs(c-u)<=15e3:!!(t!=null&&t._localId)!=!!(s!=null&&s._localId)}function en(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),Bt(t)&&(s+=1),s}function Io(t,s){const r=en(t),n=en(s);return n!==r?n>r?s:t:Ps(s==null?void 0:s.content).length>=Ps(t==null?void 0:t.content).length?s:t}function tn(t){const s=[];for(const r of t){const n=s.findIndex(i=>Co(i,r));if(n>=0){s.splice(n,1,Io(s[n],r));continue}s.push(r)}return s}const To=60,Ao=60;function pr({activeConv:t,ideEntry:s,handleSendChat:r,isSendingChat:n=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:u,showMetaChips:d=!1,scrollToBottomRequestNonce:x,isInputActive:l=!0}){const f=a.useRef(new Map),{sendCommand:h}=It();ps("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:n});const m=et.useMemo(()=>Ws(t),[t.status,t.connectionState]),y=a.useRef(new Map),p=a.useCallback(D=>(y.current.has(D)||y.current.set(D,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:To}),y.current.get(D)),[]),g=a.useCallback((D,F)=>{const _=p(D);y.current.set(D,{..._,...F}),b(A=>A+1)},[p]),[,b]=a.useState(0),v=t.tabKey,S=p(v),B=S.messages,j=S.hasMore,C=S.error,w=Math.max(0,t.messages.length-S.visibleLiveCount),[k,E]=a.useState(!1),L=a.useCallback(async()=>{var _,A;if(k)return;const D=t.tabKey,F=p(D);if(t.messages.length>F.visibleLiveCount){g(D,{visibleLiveCount:Math.min(t.messages.length,F.visibleLiveCount+Ao),error:null});return}E(!0),g(D,{error:null});try{const M=(s==null?void 0:s.daemonId)||((_=t.ideId)==null?void 0:_.split(":")[0])||"";if(!M){g(D,{hasMore:!1});return}const G=t.ideType||t.agentType||"",Y=await h(M,"chat_history",{agentType:G,offset:F.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),ue=(Y==null?void 0:Y.result)??Y;if(((A=ue.messages)==null?void 0:A.length)>0){const ve=p(D);g(D,{messages:[...ue.messages,...ve.messages],offset:ve.offset+ue.messages.length,hasMore:!!ue.hasMore})}else g(D,{hasMore:!!ue.hasMore})}catch(M){const G=(M==null?void 0:M.message)||"";G.includes("P2P not available")||G.includes("channel not open")||G.includes("P2P not connected")||G.includes("timeout")?g(D,{error:"Connection not ready — tap to retry"}):g(D,{hasMore:!1,error:"Failed to load history"})}finally{E(!1)}},[k,s,t,h,p,g]),{allMessages:$,receivedAtMap:R}=a.useMemo(()=>{const D=w>0?t.messages.slice(-S.visibleLiveCount):t.messages;if(B.length===0){const G=Qr(tn(D)),Y={};return G.forEach((ue,ve)=>{const Te=`${t.tabKey}:${Ft(ue,ve)}`;let ee=Bt(ue)||f.current.get(Te)||0;ee||(ee=Date.now(),f.current.set(Te,ee)),Y[Ft(ue,ve)]=ee}),{allMessages:G,receivedAtMap:Y}}const F=new Set(D.map(G=>`${G.role}:${(G.content||"").slice(0,100)}`)),_=B.filter(G=>!F.has(`${G.role}:${(G.content||"").slice(0,100)}`)),A=Qr(tn([..._,...D])),M={};return A.forEach((G,Y)=>{const ue=`${t.tabKey}:${Ft(G,Y)}`;let ve=Bt(G)||f.current.get(ue)||0;ve||(ve=Date.now(),f.current.set(ue,ve)),M[Ft(G,Y)]=ve}),{allMessages:A,receivedAtMap:M}},[t.messages,t.tabKey,w,B,S.visibleLiveCount]),T=a.useMemo(()=>c.filter(D=>D.ideId===t.tabKey).sort((D,F)=>D.timestamp-F.timestamp),[c,t.tabKey]),O=t.displayPrimary||t.agentName||"Agent",H=a.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if((m.isGenerating||t.status==="streaming")&&E(!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($t,{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(Gt,{size:14})," Open ",O," 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(Vn,{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(Gt,{size:14})," Open ",O," 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"&&!k)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,k,O,m.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[d&&e.jsx(ta,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(to,{messages:$,actionLogs:T,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:Xe(t)||ze(t),isWorking:m.isGenerating,contextKey:t.tabKey,receivedAtMap:R,onLoadMore:L,isLoadingMore:k,hasMoreHistory:j,hiddenLiveCount:w,loadError:C??void 0,emptyState:H,scrollToBottomRequestNonce:x}),l&&!sa(t)&&(()=>{const D=t.streamSource!=="agent-stream",F=D?t.ideType:t.agentType,_=D?s!=null&&s.type?Ye(s.type):Ye(t.ideType||""):t.agentName||Ye(t.agentType||""),A=!D&&(s!=null&&s.childSessions)&&s.childSessions.find(Y=>Y.id===t.sessionId||Y.providerType===t.agentType)||s,M=A==null?void 0:A.providerControls,G=A==null?void 0:A.controlValues;return e.jsx(po,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:F,displayLabel:_,controls:M,controlValues:G,serverModel:(A==null?void 0:A.currentModel)||void 0,serverMode:(A==null?void 0:A.currentPlan)||void 0,acpConfigOptions:ze(t)?A==null?void 0:A.acpConfigOptions:void 0,acpModes:ze(t)?A==null?void 0:A.acpModes:void 0})})(),e.jsx(mo,{contextKey:t.tabKey,panelLabel:O,isSending:n,onSend:r,isActive:l})]})}let ra=as;function Cr(){return ra()}class _o{constructor(){tt(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,r){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(r),()=>{var n;(n=this.listeners.get(s))==null||n.delete(r)}}emit(s,...r){var n;(n=this.listeners.get(s))==null||n.forEach(i=>i(...r))}}let na=new _o;class Mo{sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,r){return!1}get(s){}onScreenshot(s,r){return()=>{}}onRuntimeEvent(s,r){return()=>{}}requestRuntimeSnapshot(s,r){return Promise.resolve()}}let Ze=new Mo;function Po(t){t.dashboardWS&&(na=t.dashboardWS),t.connectionManager&&(Ze=t.connectionManager),t.useDaemonsHook&&(ra=t.useDaemonsHook)}function Lo({activeConv:t,clearToken:s=0,terminalRef:r,handleSendChat:n,isSendingChat:i=!1,isVisible:o=!0}){var F;const c=a.useRef(null),{sendCommand:u,sendData:d}=It(),[x,l]=a.useState(""),[f,h]=a.useState(!1),[m,y]=a.useState(1),p=a.useRef(!1),g=a.useRef(0),b=a.useRef(!1),v=a.useRef(""),S=a.useRef(null),B=a.useRef(!1),j=a.useRef(null),C=t.tabKey,w=t.sessionId||"",k=t.daemonId||((F=t.ideId)==null?void 0:F.split(":")[0])||t.ideId||"",E=.6,L=1.15,$=()=>{if(typeof window>"u")return 1;const _=window.innerWidth||0;return _<=360?.68:_<=390?.74:_<=430?.82:_<=480?.9:1},R=()=>{var _,A;g.current=0,b.current=!1,v.current="",S.current=null,B.current=!1,j.current!==null&&(cancelAnimationFrame(j.current),j.current=null),h(!1),(A=(_=r.current)==null?void 0:_.reset)==null||A.call(_)},T=()=>{var _,A;g.current=0,b.current=!1,v.current="",S.current=null,B.current=!1,j.current!==null&&(cancelAnimationFrame(j.current),j.current=null),h(!0),(A=(_=r.current)==null?void 0:_.reset)==null||A.call(_)},O=()=>{var A;if(j.current=null,!o)return;const _=v.current;_&&(v.current="",(A=r.current)==null||A.write(_))},H=_=>{_&&(v.current+=_,o&&j.current===null&&(j.current=requestAnimationFrame(O)))},D=(_,A=0,M,G)=>{var Y,ue,ve,Te,ee;A>0&&g.current>=A||A===0&&b.current||(g.current=A,h(!0),typeof M=="number"&&typeof G=="number"&&M>0&&G>0&&((ue=(Y=r.current)==null?void 0:Y.resize)==null||ue.call(Y,M,G)),(Te=(ve=r.current)==null?void 0:ve.reset)==null||Te.call(ve),_&&((ee=r.current)==null||ee.write(_)))};return a.useEffect(()=>{R()},[w]),a.useEffect(()=>{var A;if(!w)return;const _=((A=Ze.onRuntimeEvent)==null?void 0:A.call(Ze,w,M=>{if(!(!M||M.sessionId!==w)){if(M.type==="runtime_snapshot"){if(!o){S.current={text:M.text||"",seq:M.seq||0,cols:M.cols,rows:M.rows};return}D(M.text||"",M.seq||0,M.cols,M.rows);return}if(M.type==="session_output"){b.current=!0,typeof M.seq=="number"&&(g.current=Math.max(g.current,M.seq)),f||h(!0),typeof M.data=="string"&&H(M.data);return}if(M.type==="session_cleared"){if(!o){B.current=!0,v.current="",S.current=null;return}T()}}}))||(()=>{});return()=>{_()}},[k,w,r,o,f]),a.useEffect(()=>{var A,M,G;if(!w)return;k&&((A=Ze.getState)==null?void 0:A.call(Ze,k))==="connected"&&(h(!0),(M=Ze.requestRuntimeSnapshot)==null||M.call(Ze,k,w).catch(()=>{}));const _=(G=Ze.onStateChange)==null?void 0:G.call(Ze,(Y,ue)=>{var ve;Y!==k||ue!=="connected"||(h(!0),(ve=Ze.requestRuntimeSnapshot)==null||ve.call(Ze,k,w).catch(()=>{}))});return()=>{_==null||_()}},[k,w,r]),a.useEffect(()=>{s&&R()},[s,C,r]),a.useEffect(()=>{l("")},[t.tabKey]),a.useEffect(()=>{const _=()=>{p.current||y($())};return _(),window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[]),a.useEffect(()=>{var A;if(!o){(A=c.current)==null||A.blur();return}B.current&&(B.current=!1,T());const _=S.current;_&&(S.current=null,D(_.text,_.seq,_.cols,_.rows)),v.current&&j.current===null&&(j.current=requestAnimationFrame(O))},[o]),a.useEffect(()=>()=>{j.current!==null&&(cancelAnimationFrame(j.current),j.current=null)},[]),a.useEffect(()=>{const _=A=>{var G;const M=A.detail;M!=null&&M.sessionId&&M.sessionId!==w||f&&((G=r.current)==null||G.fit())};return window.addEventListener("adhdev:fit-cli-terminal",_),()=>{window.removeEventListener("adhdev:fit-cli-terminal",_)}},[f,w,r]),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:()=>{p.current=!0,y(_=>Math.max(E,Number((_-.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:()=>{p.current=!0,y(_=>Math.min(L,Number((_+.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/m}%`,height:`${100/m}%`,transform:`scale(${m})`,transformOrigin:"top left"},children:e.jsx(qn,{ref:r,readOnly:!f||!o,onInput:_=>{f&&(d!=null&&d(k,{type:"pty_input",targetSessionId:w,data:_})||u(k,"pty_input",{targetSessionId:w,data:_}).catch(console.error))},onResize:(_,A)=>{f&&(d!=null&&d(k,{type:"pty_resize",targetSessionId:w,cols:_,rows:A})||u(k,"pty_resize",{targetSessionId:w,cols:_,rows:A,force:!0}).catch(()=>{}))}})})}),!f&&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:x,disabled:!f||!o||i,onChange:_=>l(_.target.value),onPaste:_=>{const A=_.clipboardData.getData("text");A&&l(M=>M+A),_.preventDefault()},onKeyDown:_=>{if(_.key!=="Enter")return;if(_.nativeEvent.isComposing){_.preventDefault();return}_.preventDefault();const A=x.trim();!f||!A||i||(l(""),n(A))},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:()=>{const _=x.trim();!f||!_||i||(l(""),n(_))},disabled:!f||!o||!x.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${x.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:x.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:x.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Ro({wsStatus:t,showReconnected:s,loginUrl:r}){const n=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)"},u={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[n&&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:u[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"&&(r?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:r,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 Eo({terminalBackend:t,isStandalone:s=!1,machineLabel:r,machineKey:n}){const i=a.useMemo(()=>!n||!t?null:`adhdev:terminal-backend-banner:dismissed:${n}:${t.backend}`,[n,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 u=(r==null?void 0:r.trim())||"This machine",d=()=>{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:[u," 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:d,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 Ir({mode:t,onChange:s,compact:r=!1}){const n=r?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(kr,{size:n}):e.jsx(vt,{size:n})})}function sn({conversation:t,isAttention:s,shortcutIndex:r,onClick:n}){const i=[t.displaySecondary,t.machineName].filter(Boolean);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}),(r||i.length>0)&&e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[r?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",r]}):null,i.join(" · ")]})]})}function $o({activeConv:t,agentCount:s,wsStatus:r,isConnected:n,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:u,activeCliViewMode:d,onSetCliViewMode:x,onOpenConversation:l,onHideConversation:f,hiddenConversations:h=[],onShowConversation:m,onShowAllHidden:y,inboxOpen:p,onInboxOpenChange:g,hiddenOpen:b,onHiddenOpenChange:v,onOpenNewSession:S}){const B=Cr(),j=B.p2pStates||{},C=B.ides||[],w=!!t&&Xe(t)&&!ze(t),k=d||(t?sa(t)?"terminal":"chat":null),[E,L]=a.useState(!1),$=a.useRef(null),R=a.useRef(null),T=n?"#22c55e":r==="connected"?"#eab308":"#ef4444",O=n?"0 0 4px #22c55e80":r==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",H=C.filter(U=>U.type==="adhdev-daemon"),D=a.useMemo(()=>ms(C),[C]),F=Object.values(j),_=F.filter(U=>U==="connected").length,A=F.filter(U=>U==="connecting"||U==="new"||U==="checking").length,G=r!=="connected"||H.length===0?null:A>0&&_===0?"P2P connecting...":_>0&&s===0?"Waiting for IDE...":null,Y=a.useMemo(()=>i.filter(U=>!lo(U,i,D)),[i,D]),ue=a.useMemo(()=>Y.filter(U=>os(U,D).requiresAction),[Y,D]),ve=a.useMemo(()=>Y.filter(U=>{const ae=(t==null?void 0:t.tabKey)===U.tabKey;return os(U,D,{hideOpenTaskCompleteUnread:!0,isOpenConversation:ae}).unread}),[t,Y,D]),Te=a.useMemo(()=>[...ue,...ve].slice(0,9),[ue,ve]),ee=ue.length+ve.length;a.useEffect(()=>{if(!p)return;const U=ae=>{var X;(X=$.current)!=null&&X.contains(ae.target)||g(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[p,g]),a.useEffect(()=>{if(!b)return;const U=ae=>{var X;(X=R.current)!=null&&X.contains(ae.target)||v(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[b,v]),a.useEffect(()=>{if(!b&&!p)return;const U=ae=>{if(!ae.altKey)return;const X=ae.code.match(/^Digit([1-9])$/);if(!X)return;const pe=Number(X[1])-1,me=b?h[pe]:void 0,se=p?Te[pe]:void 0,de=me||se;if(de){if(ae.preventDefault(),ae.stopPropagation(),me){m==null||m(me),v(!1);return}l==null||l(de),g(!1)}};return window.addEventListener("keydown",U,!0),()=>window.removeEventListener("keydown",U,!0)},[h,b,p,Te,v,g,l,m]);const Me=U=>{if(!U)return;const ae=i.find(X=>X.tabKey===U);ae&&(f==null||f(ae))};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(vt,{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:T,boxShadow:O}})})]}),e.jsxs("div",{className:"header-subtitle",children:[S&&e.jsx("button",{type:"button",onClick:S,className:"btn btn-secondary btn-sm",title:"Start a new session","aria-label":"Start a new session",children:e.jsx(Oi,{size:14})}),e.jsx("span",{title:n?"Connected":r==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:T,boxShadow:O}}),G&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",G]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(w||!ze(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&&u&&e.jsxs(e.Fragment,{children:[x&&k&&e.jsx(Ir,{mode:k,onChange:x,compact:!0}),e.jsx("button",{onClick:()=>u(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(Dt,{size:14})})]}),!ze(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(wr,{size:14})}),!w&&!ze(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(ot,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:$,children:[e.jsxs("div",{className:`dashboard-header-hidden${E?" is-drop-target":""}`,ref:R,onDragEnter:U=>{U.dataTransfer.types.includes("text/tab-key")&&(U.preventDefault(),L(!0))},onDragOver:U=>{U.dataTransfer.types.includes("text/tab-key")&&(U.preventDefault(),U.dataTransfer.dropEffect="move",L(!0))},onDragLeave:U=>{U.currentTarget.contains(U.relatedTarget)||L(!1)},onDrop:U=>{const ae=U.dataTransfer.getData("text/tab-key");U.preventDefault(),L(!1),Me(ae)},children:[e.jsxs("button",{type:"button",onClick:()=>v(!b),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Bi,{size:16}),h.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:h.length})]}),b&&e.jsxs("div",{className:"dashboard-header-hidden-popover",children:[e.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),h.length>0&&y&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{y(),v(!1)},children:"Restore all"})]}),t&&f&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>f(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(U=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{m==null||m(U),v(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:U.displayPrimary}),e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[h.indexOf(U)<9?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",h.indexOf(U)+1]}):null,[U.displaySecondary,U.machineName].filter(Boolean).join(" · ")]})]},U.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>g(!p),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(Ks,{size:16}),ee>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:ee})]}),p&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[ue.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),ue.map(U=>e.jsx(sn,{conversation:U,isAttention:!0,shortcutIndex:Te.indexOf(U)>=0?Te.indexOf(U)+1:void 0,onClick:()=>{l==null||l(U),g(!1)}},U.tabKey))]}),ve.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),ve.map(U=>e.jsx(sn,{conversation:U,shortcutIndex:Te.indexOf(U)>=0?Te.indexOf(U)+1:void 0,onClick:()=>{l==null||l(U),g(!1)}},U.tabKey))]}),ee===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Do(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 Bo({activeConv:t,ides:s,isCreatingChat:r,isRefreshingHistory:n,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:u,onNewChat:d,onSwitchSession:x,onRefreshHistory:l,onResumeSavedSession:f}){var g;const h=s.find(b=>b.id===t.ideId),m=(h==null?void 0:h.chats)||[],y=(g=h==null?void 0:h.activeChat)==null?void 0:g.id,p=Xe(t)&&!ze(t);return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:u,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:p?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Ye(t.ideType)]})]}),e.jsx("button",{onClick:u,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:[!p&&e.jsx("button",{onClick:d,disabled:r,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:r?"⌛ Creating...":"+ Start New Chat Session"}),p?e.jsx(e.Fragment,{children:i.map(b=>{const v=t.providerSessionId===b.providerSessionId,S=v||!b.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{S||!f||f(b)},disabled:S,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${v?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${S?"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 ${v?"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:Do(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:v?"ACTIVE":b.canResume?c===b.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},b.id)})}):m.map(b=>e.jsxs("div",{onClick:()=>{x(t.ideId,b.id),u()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${y===b.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${y===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[b.id.substring(0,12),"..."]}),y===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),(p&&!o&&i.length===0||!p&&m.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(Fi,{size:32})}),e.jsx("div",{className:"text-[13px]",children:p?"No saved sessions found yet.":"No recent chat sessions found."})]}),p&&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:l,disabled:n||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ds,{size:13})," ",p?"Refresh Sessions":"Refresh History"]})})})]})]})}const rn={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 aa({toasts:t,onDismiss:s,onClickToast:r}){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(n=>{const i=rn[n.type]||rn.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=n.actions)!=null&&o.length||r&&r(n)},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(n.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:n.message}),n.actions&&n.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-3",children:n.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:u=>{u.stopPropagation(),o.onClick(),s(n.id)},children:o.label},c))})]})]},n.id)})})}function Tr(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 Ko=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Wo(t){const s=t.workspace||"";if(!s)return"";const r=s.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:s}function Oo(t){return t.sessionId||t.instanceId||t.agentType}function Zs(t,s){return t||s}function nn(t){return Tr(t)}function an(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 on(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 r=String(t.role||"").toLowerCase(),n=String(s.role||"").toLowerCase();if(r!==n)return!1;const i=nn(t.content),o=nn(s.content);if(!i||i!==o)return!1;const c=an(t),u=an(s);return c&&u?Math.abs(c-u)<=15e3:!!t._localId!=!!s._localId}function cn(t,s){const r=new Set,n=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;r.has(c)||(r.add(c),n.push(o))}return n.sort((i,o)=>i.timestamp-o.timestamp)}function ia(t=[]){const s={};for(const r of t){const n=r;(n.type==="adhdev-daemon"||n.daemonMode)&&(s[n.id]=gt(n,{fallbackId:n.id}))}return s}function Ar(t,s,r={}){var h,m,y,p,g,b;const n=[],i=r.machineName,o=r.connectionState,c=Wo(t),u=Ye(t.type),d=Array.isArray(t.childSessions)?t.childSessions.map(v=>{var S,B;return{sessionId:v.id,instanceId:v.id,providerSessionId:v.providerSessionId,transport:v.transport,agentType:v.providerType,agentName:v.providerName,status:v.status,title:v.title,messages:((S=v.activeChat)==null?void 0:S.messages)||[],activeModal:((B=v.activeChat)==null?void 0:B.activeModal)||void 0,unread:v.unread,lastSeenAt:v.lastSeenAt,lastUpdated:v.lastUpdated,inboxBucket:v.inboxBucket,surfaceHidden:v.surfaceHidden}}):[],x=Ko(t),l=t.activeChat||{title:""},f=l.title&&String(l.title).trim()?String(l.title).trim():"";if(x){const v=t.sessionId||t.instanceId,S=Jr(t.type),B=(h=t.activeChat)==null?void 0:h.activeModal,j=B&&Array.isArray(B.buttons)&&B.buttons.length>0,C=ct((m=t.activeChat)==null?void 0:m.status,{activeModal:(y=t.activeChat)==null?void 0:y.activeModal})||ct((g=(p=t.agents)==null?void 0:p[0])==null?void 0:g.status)||"idle",w=t.activeChat||{title:"",messages:[]};let k=w.title&&String(w.title).trim()?String(w.title).trim():"";const E=(b=t.activeChat)==null?void 0:b.id,L=t.chats;if(E&&Array.isArray(L)&&L.length>0){const F=L.find(_=>_.id===E||_.id&&String(_.id)===String(E));F!=null&&F.title&&String(F.title).trim()&&(k=String(F.title).trim())}const $=(Xe(t)||ze(t))&&(t.cliType||t.acpType)||t.type,R=(Xe(t)||ze(t))&&Zr(k,S,$)?"":k,T=w.messages||[],O=cn(s,[t.id,v]),H=T.filter(F=>String((F==null?void 0:F.role)||"").toLowerCase()==="user").slice(),D=O.filter(F=>{const _=H.findIndex(A=>on(A,F));return _>=0?(H.splice(_,1),!1):!0});n.push({ideId:t.id,sessionId:v,providerSessionId:t.providerSessionId,nativeSessionId:v,transport:t.transport,daemonId:t.daemonId||void 0,mode:Xe(t)?t.mode||"terminal":"chat",agentName:S,agentType:$,status:C,title:R,messages:[...T,...D],resume:t.resume,ideType:$,workspaceName:c,displayPrimary:c||R||(Xe(t)?t.mode==="chat"?S:"Terminal":S),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:j?B.buttons:void 0,modalMessage:j?B.message:void 0,streamSource:"native",tabKey:Zs(v,t.id),machineName:i,connectionState:o})}if(x&&(Xe(t)||ze(t)))return n;for(const v of d){const S=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,B=wo(v),j=Oo(v),C=`${t.id}:${j}`,w=v.title&&String(v.title).trim()||"",k=Zr(w,v.agentName,v.agentType)?"":w,E=v.messages||[],L=cn(s,[C,v.sessionId,v.instanceId]),$=E.filter(O=>String((O==null?void 0:O.role)||"").toLowerCase()==="user").slice(),R=L.filter(O=>{const H=$.findIndex(D=>on(D,O));return H>=0?($.splice(H,1),!1):!0});(v.transport==="cdp-webview"||v.sessionId||v.providerSessionId||E.length>0||R.length>0||S||k||!["idle","panel_hidden","disconnected","not_monitored"].includes(B))&&n.push({ideId:t.id,sessionId:v.sessionId||v.instanceId,providerSessionId:v.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:v.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:B,title:k,messages:[...E,...R],ideType:v.agentType,workspaceName:c,displayPrimary:c||f||k||u,displaySecondary:`${u} · ${v.agentName}`,cdpConnected:t.cdpConnected,modalButtons:S?v.activeModal.buttons:void 0,modalMessage:S?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:Zs(v.sessionId||v.instanceId,C),machineName:i,connectionState:o})}return n.length===0&&n.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:Jr(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:Zs(t.sessionId||t.instanceId,t.id),connectionState:o}),n}function Uo(t){const s=[],r=new Map;for(const n of t)if(n.parentId){const i=r.get(n.parentId)||[];i.push(n),r.set(n.parentId,i)}else s.push(n);return{topLevel:s,childrenByParent:r}}function zo(t,s){const r=[],{daemonId:n,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:d,childrenByParent:x}=Uo(u),l=d.filter(m=>m.kind==="workspace"&&m.transport==="cdp-page"),f=d.filter(m=>m.kind==="agent"&&m.transport==="pty"),h=d.filter(m=>m.kind==="agent"&&m.transport==="acp");r.push({...i||{},id:n,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:l.some(m=>!!m.cdpConnected)});for(const m of l){const y=x.get(m.id)||[];r.push({id:`${n}:ide:${m.id}`,sessionId:m.id,providerSessionId:m.providerSessionId,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,status:m.cdpConnected?"online":"detected",daemonId:n,instanceId:m.id,workspace:m.workspace,terminals:0,childSessions:y,agents:y.map(p=>({id:p.id,name:p.providerName,type:p.providerType,status:p.status})),activeChat:m.activeChat,chats:[],cdpConnected:m.cdpConnected,currentModel:m.currentModel,currentPlan:m.currentPlan,currentAutoApprove:m.currentAutoApprove,lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c})}for(const m of f)r.push({id:`${n}:cli:${m.id}`,sessionId:m.id,providerSessionId:m.providerSessionId,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:n,instanceId:m.id,cliName:m.providerName,mode:m.mode||"terminal",workspace:m.workspace||"",activeChat:m.activeChat,resume:m.resume,runtimeKey:m.runtimeKey,runtimeDisplayName:m.runtimeDisplayName,runtimeWorkspaceLabel:m.runtimeWorkspaceLabel,runtimeWriteOwner:m.runtimeWriteOwner??null,runtimeAttachedClients:m.runtimeAttachedClients??[],lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c,_isCli:!0});for(const m of h)r.push({id:`${n}:acp:${m.id}`,sessionId:m.id,providerSessionId:m.providerSessionId,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:n,instanceId:m.id,cliName:m.providerName,mode:"chat",workspace:m.workspace||"",activeChat:m.activeChat,runtimeKey:m.runtimeKey,runtimeDisplayName:m.runtimeDisplayName,runtimeWorkspaceLabel:m.runtimeWorkspaceLabel,runtimeWriteOwner:m.runtimeWriteOwner??null,runtimeAttachedClients:m.runtimeAttachedClients??[],currentModel:m.currentModel,currentPlan:m.currentPlan,lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,acpConfigOptions:m.acpConfigOptions,acpModes:m.acpModes,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c,_isAcp:!0});return r}function Fo(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 Ho(t,s){const r=Fo(t);return{daemonId:r.daemonId,payload:{...s,...r.targetSessionId&&!s.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const oa=[{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:"💚"}],ca=[{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:"🧩"}],la=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],da="adhdev_notification_prefs",ln={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Vo(){try{const t=localStorage.getItem(da);if(t){const s=JSON.parse(t);return{...ln,...s}}}catch{}return{...ln}}function Go(t){try{localStorage.setItem(da,JSON.stringify(t))}catch{}}let yt=Vo(),Ns=[];function qo(){Ns.forEach(t=>t())}function Yo(){return{...yt}}function Xo(t){yt={...yt,...t},Go(yt),qo()}function Jo(){const[,t]=a.useState(0);a.useEffect(()=>{const r=()=>t(n=>n+1);return Ns.push(r),()=>{Ns=Ns.filter(n=>n!==r)}},[]);const s=a.useCallback(r=>{Xo(r)},[]);return[{...yt},s]}function ss(t){if(!yt.globalEnabled)return!1;switch(t){case"disconnect":return yt.disconnectAlert;case"completion":return yt.completionAlert;case"approval":return yt.approvalAlert;case"browser":return yt.browserNotifications;default:return!0}}const Zo={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Qo(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function ua(){return"Notification"in window&&Notification.permission==="granted"}let _t=null;async function ec(){if(_t!==null)return _t;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return _t=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(_t=!!await t.pushManager.getSubscription(),_t):(_t=!1,!1)}catch{return _t=!1,!1}}function mr(t,s,r){if(ua())try{const n=new Notification(t,{body:s,icon:"/otter-logo.png",tag:r||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>n.close(),8e3),n.onclick=()=>{window.focus(),n.close()}}catch{}}function tc(t,s={}){const r={...Zo,...s},n=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{ec().then(u=>{o.current=u})},[]);const c=a.useCallback((u,d,x)=>{const l=Date.now();l-i.current<r.throttleMs||(i.current=l,mr(u,d,x))},[r.throttleMs]);a.useEffect(()=>{var u;if(!(!r.enabled||!ua())&&ss("browser")&&o.current!==!0){if(document.hasFocus()){for(const d of t)n.current.set(d.id,ct(d.status,{activeModal:d.activeModal}));return}for(const d of t){const x=n.current.get(d.id),l=ct(d.status,{activeModal:d.activeModal}),f=d.name||d.id;if(r.onApproval&&ss("approval")&&l==="waiting_approval"&&x!=="waiting_approval"){const h=((u=d.activeModal)==null?void 0:u.message)||"Action requires your approval";c(`🔔 ${f} — Approval needed`,h.slice(0,120),`approval-${d.id}`)}r.onComplete&&ss("completion")&&Qn(x)&&l==="idle"&&c(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${d.id}`),r.onError&&l==="error"&&x!=="error"&&c(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${d.id}`),n.current.set(d.id,l)}}},[t,r.enabled,r.onApproval,r.onComplete,r.onError,c])}class sc{constructor(){tt(this,"dedupMap",new Map);tt(this,"DEDUP_WINDOW_MS",5e3);tt(this,"DEDUP_MAX_SIZE",50);tt(this,"DEDUP_CLEANUP_AGE_MS",1e4);tt(this,"toastCallbacks",[]);tt(this,"systemMessageCallbacks",[]);tt(this,"clearSystemMessageCallbacks",[]);tt(this,"resolveActionFn",null);tt(this,"viewRequestRespondFn",null);tt(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(r=>r!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(r=>r!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(r=>r!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const r of this.toastCallbacks)r(s)}showToast(s,r="info",n){const i=(n==null?void 0:n.id)||Date.now();this.emitToast({id:i,message:s,type:r,timestamp:i,duration:5e3,...n})}emitSystemMessage(s,r){for(const n of this.systemMessageCallbacks)n(s,r)}emitClearSystemMessage(s,r){for(const n of this.clearSystemMessageCallbacks)n(s,r)}isDuplicate(s){const r=Date.now(),n=this.dedupMap.get(s)||0;if(r-n<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,r),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)r-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 r;if(s.targetSessionId&&(r=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(r=r||this.ides.find(i=>i.id===s.ideId)),!r&&s.instanceId&&(r=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),r){const i=r.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const n=this.ides.filter(i=>i.type==="adhdev-daemon");return n.length===1?n[0]:null}resolveRouteId(s,r){for(const n of this.ides)if(n.id.startsWith(s)&&(!r||r===n.type))return n.id;return s}findOwningSession(s){for(const r of this.ides)if(r.id===s||r.sessionId===s||(Array.isArray(r.childSessions)?r.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return r;return null}resolveActionRouteTarget(s){if(s.ideId){const r=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,r)}if(s.targetSessionId){const r=this.findOwningSession(s.targetSessionId);return(r==null?void 0:r.id)||(r==null?void 0:r.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,r){var f,h,m;if(!s.ideId&&s.instanceId){for(const y of this.ides)if(y.id.endsWith(`:ide:${s.instanceId}`)||y.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=y.id;break}}const n=this.resolveConversationKey(s),o=`${n||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=Ye(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const y=gt(u,{fallbackId:u.id});y&&(c=s.ideType==="adhdev-daemon"?y:`${y}/${c}`)}const d=Number.isFinite(s.timestamp)?Number(s.timestamp):Date.now();let x="",l="info";if(s.event==="agent:generating_completed"){const y=s.duration?` (${s.duration}s)`:"";x=`✅ ${c} agent task completed${y}`,l="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}n&&Yo().chatTaskCompletionBubble&&this.emitSystemMessage(n,{role:"system",timestamp:d,content:`✅ Task completed${y}`,_localId:`sys_complete_${d}`})}else if(s.event==="agent:generating_started")n&&this.emitClearSystemMessage(n,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(x=`⚡ ${c} approval needed`,l="warning",n&&!((f=s.modalButtons)!=null&&f.length)){const y=s.modalMessage||"Approval requested",p=(h=s.modalButtons)!=null&&h.length?s.modalButtons.map(g=>`[${g}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(n,{role:"system",timestamp:d,content:`⚡ Approval requested: ${y}
|
|
36
|
+
${p}`,_localId:`sys_approval_${d}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const y=this.resolveActionRouteTarget(s);if(!y)return;const p=s.agentType||s.ideType||"",g=s.ideType||"",b=s.modalButtons,v=w=>w.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),S=this.resolveActionFn,B=b.map((w,k)=>{const E=v(w).toLowerCase(),L=/^(run|approve|accept|yes|allow|always)/.test(E),$=/^(reject|deny|delete|remove|abort|cancel|no)/.test(E);return{label:v(w),variant:L?"primary":$?"danger":"default",onClick:()=>{const R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(E);S(y,"resolve_action",{action:R?"approve":"reject",button:w,buttonIndex:k,agentType:p,ideType:g,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),j=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:x,C=Date.now();this.emitToast({id:C,message:j,type:l,timestamp:C,targetKey:n||y,actions:B,duration:15e3}),x=""}}else if(s.event==="monitor:long_generating"){const y=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";x=`⚠️ ${c} agent is taking a long time${y}`,l="warning",ss("browser")&&!document.hasFocus()&&mr(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${y.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const y=s.requesterName||"A team member",p=s.requestId,g=s.orgId;if(x=`👁️ ${y} wants to view your session`,l="warning",p&&g&&this.viewRequestRespondFn){const b=this.viewRequestRespondFn,v=Date.now(),S=[{label:"Approve",variant:"primary",onClick:()=>{b(g,p,"approve").catch(B=>console.error("[EventManager] approve view request failed:",B))}},{label:"Decline",variant:"danger",onClick:()=>{b(g,p,"reject").catch(B=>console.error("[EventManager] reject view request failed:",B))}}];this.emitToast({id:v,message:x,type:l,timestamp:v,actions:S,duration:3e4}),x=""}ss("browser")&&!document.hasFocus()&&mr("👁️ View Request",`${y} wants to view your session`,`view-request-${p}`)}else s.event==="team:view_request_approved"?(x="✅ View request approved",l="success"):s.event==="team:view_request_rejected"&&(x=`❌ ${s.targetName||"Team member"} declined your view request`,l="warning");if(x){const y=Date.now();this.emitToast({id:y,message:x,type:l,timestamp:y,targetKey:n||s.ideId,duration:5e3})}}}const St=new sc;function Kt(...t){return pi(mi(t))}function rc({icon:t,title:s,subtitle:r,badge:n,actions:i,className:o}){return e.jsxs("div",{className:Kt("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,n&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Ls({icon:t,title:s,subtitle:r,badge:n,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(rc,{icon:t,title:s,subtitle:r,badge:n,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Kt("mx-auto flex w-full flex-col gap-4",o,c),children:u})})]})}function it({title:t,icon:s,description:r,accentColor:n,className:i,children:o}){return e.jsxs("div",{className:Kt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",i),style:n?{borderLeftColor:n}:void 0,children:[(t||r)&&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]}),r&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o]})}function _r({icon:t,title:s,description:r,action:n,className:i}){return e.jsxs("div",{className:Kt("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:r}),n]})}const nc={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"},ac={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function ic({variant:t,children:s,onDismiss:r,className:n}){return e.jsxs("div",{className:Kt("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",nc[t],n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ac[t]}),e.jsx("span",{children:s})]}),r&&e.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const oc={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"},cc={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function lc({status:t,label:s,className:r}){const n=s||t;return e.jsxs("span",{className:Kt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",oc[t],r),children:[e.jsx("span",{className:Kt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",cc[t])}),n]})}function dc(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function fr(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ss(t){return t==="system"?dc():t}function uc(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ss(fr()))}function pa(){const[t,s]=a.useState(fr),[r,n]=a.useState(()=>Ss(fr()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",r)},[r]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),u=d=>{t==="system"&&n(d.matches?"light":"dark")};return c.addEventListener("change",u),()=>c.removeEventListener("change",u)},[t]);const i=a.useCallback(c=>{s(c),n(Ss(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const u=c==="dark"?"light":c==="light"?"system":"dark";n(Ss(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:r,preference:t,setPreference:i,cycleTheme:o,isDark:r==="dark"}}function Ct({label:t,description:s,checked:r,disabled:n,onChange:i,extra:o}){return e.jsxs("div",{className:`flex justify-between items-center ${n?"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":r,"aria-disabled":n,disabled:n,onClick:()=>i(!r),className:`relative inline-flex items-center ${n?"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:r?"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)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function pc({onPrefChange:t}){const[s,r]=Jo(),n=(i,o)=>{r({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ks,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>n("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>n("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(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Hi,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>n("completionAlert",i)}),e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vi,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>n("approvalAlert",i)}),e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>n("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(vt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>n("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 mc({ides:t,emptyMessage:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(_r,{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(xc,{ide:c,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i},c.id))})}function dn({title:t,message:s,confirmLabel:r,confirmColor:n,onConfirm:i,onCancel:o}){const c=n==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return fi.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:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick: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:n==="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:r})]})]})}),document.body)}function fc(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...oa,...ca,...la].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:t}}function xc({ide:t,allIdes:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){var O,H;const[o,c]=a.useState("idle"),[u,d]=a.useState(""),[x,l]=a.useState(null),[f,h]=a.useState("idle"),[m,y]=a.useState(""),p=t,g=p.version||p.daemonVersion||null,b=((O=p.machine)==null?void 0:O.platform)||((H=p.system)==null?void 0:H.platform)||"",v=gt(p,{fallbackId:t.id}),S=b==="win32"?"🪟":b==="darwin"?"🍎":"🐧",B=s.filter(D=>D.daemonId===t.id&&D.transport==="cdp-page"),j=s.filter(D=>D.daemonId===t.id&&D.transport==="pty"),C=s.filter(D=>D.daemonId===t.id&&D.transport==="acp"),w=p.p2p,k=async()=>{var D,F,_,A;if(r){c("upgrading"),d("Starting upgrade...");try{const M=await r(t.id,"daemon_upgrade",{});(D=M==null?void 0:M.result)!=null&&D.alreadyLatest?(c("done"),d(`Already on v${M.result.version||"latest"}.`)):(F=M==null?void 0:M.result)!=null&&F.upgraded||(_=M==null?void 0:M.result)!=null&&_.success?(c("done"),d(`Upgrade to v${M.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),d(((A=M==null?void 0:M.result)==null?void 0:A.error)||"Upgrade failed"))}catch(M){c("error"),d((M==null?void 0:M.message)||"Connection lost during upgrade")}}},E=async()=>{if(l(null),!!n){h("loading");try{await n(t.id),h("done"),y("Machine disconnected.")}catch(D){h("error"),y((D==null?void 0:D.message)||"Failed to disconnect")}}},L=async()=>{if(l(null),!!i){h("loading");try{await i(t.id),h("done"),y('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(D){h("error"),y((D==null?void 0:D.message)||"Failed to revoke token")}}},$="0.8.22",R=!g||g!==$,T=B.length+j.length+C.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:S}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:v}),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),"…"]}),g&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${R?"":"bg-bg-secondary"}`,style:R?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",g,!R&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&R&&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${$}`,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${$}`}`}),n&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:f==="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:()=>l("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(lc,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[w&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${w.state==="connecting"||w.state==="new"?"animate-pulse":""}`,style:w.state==="connecting"||w.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",w.state==="connected"?"connected":w.state==="connecting"||w.state==="new"?"connecting...":w.state||"off"]}),w.peers!==void 0&&w.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",w.peers," peer",w.peers!==1?"s":"",")"]})]}),w&&T>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),T>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[B.map(D=>{const F=fc(D.type),_=D.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:F.icon}),e.jsx("span",{children:F.name}),_!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${_?"bg-green-400":"animate-pulse"}`,style:_?void 0:{background:"var(--status-warning)"},title:_?"CDP connected":"CDP connecting..."})]},D.id)}),j.map(D=>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:D.cliName||"CLI"})]},D.id)),C.map(D=>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:D.cliName||"ACP"})]},D.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||m)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:m||u})]}),x==="disconnect"&&e.jsx(dn,{title:"🔌 Disconnect Machine",message:`Disconnect "${v}" 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:()=>l(null)}),x==="revoke"&&e.jsx(dn,{title:"⚠️ Remove Machine",message:`Remove "${v}" 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:L,onCancel:()=>l(null)})]})}const hc=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function bc(){const{preference:t,setPreference:s}=pa();return e.jsx("div",{className:"flex gap-2",children:hc.map(r=>e.jsxs("button",{onClick:()=>s(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:r.icon}),r.label]},r.id))})}function gc(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 yc(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Qs(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function un(t){const{r:s,g:r,b:n}=yc(t);return .2126*Qs(s)+.7152*Qs(r)+.0722*Qs(n)}function pn(t,s){const r=un(t),n=un(s),i=Math.max(r,n),o=Math.min(r,n);return(i+.05)/(o+.05)}function Mr(t){const s=gc(t);if(!s)return"#111827";const r="#111827",n="#ffffff";return pn(s,r)>=pn(s,n)?r:n}const ma="adhdev-accent-color",xr="#cf7a45";function vc(t){const s=parseInt(t.slice(1,3),16)/255,r=parseInt(t.slice(3,5),16)/255,n=parseInt(t.slice(5,7),16)/255,i=Math.max(s,r,n),o=Math.min(s,r,n);let c=0,u=0;const d=(i+o)/2;if(i!==o){const x=i-o;switch(u=d>.5?x/(2-i-o):x/(i+o),i){case s:c=((r-n)/x+(r<n?6:0))/6;break;case r:c=((n-s)/x+2)/6;break;case n:c=((s-r)/x+4)/6;break}}return{h:Math.round(c*360),s:Math.round(u*100),l:Math.round(d*100)}}function mn(t,s){const{h:r,s:n,l:i}=vc(t),o=Math.min(100,i+s);return`hsl(${r}, ${n}%, ${o}%)`}function er(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function wc(){return typeof window>"u"?xr:localStorage.getItem(ma)||xr}function jc(){if(typeof window>"u")return!1;try{return localStorage.getItem(ma)!=null}catch{return!1}}function kc(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",mn(t,15)),s.style.setProperty("--accent-on-primary",Mr(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${mn(t,20)})`),s.style.setProperty("--border-accent",er(t,.4)),s.style.setProperty("--nav-active-bg",er(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${er(t,.06)}`)}function Nc(){const t=wc();t!==xr&&kc(t)}const hr={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},br={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},Sc=[{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"}}}],fa="adhdev-chat-theme",xa="adhdev-chat-theme-custom";function Cs(){if(typeof window>"u")return"ember";try{return localStorage.getItem(fa)||"ember"}catch{return"ember"}}function bt(t){try{const s=localStorage.getItem(xa);if(s){const r=JSON.parse(s);return{...t==="dark"?hr:br,...r[t]}}}catch{}return t==="dark"?hr:br}function bs(t,s){try{localStorage.setItem(xa,JSON.stringify({dark:t,light:s}))}catch{}}function mt(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function Rs(t,s){const r=Math.min(255,parseInt(t.slice(1,3),16)+s),n=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Cc={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function rs(t,s){var i;if(jc())return;const r=(i=Cc[t])==null?void 0:i[s];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",Rs(r,24)),n.style.setProperty("--accent-on-primary",Mr(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${Rs(r,18)})`),n.style.setProperty("--border-accent",mt(r,.35)),n.style.setProperty("--nav-active-bg",mt(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${mt(r,.06)}`)}function Lt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",mt(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",mt(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",mt(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",mt(t.borderSubtle,.5)),s.style.setProperty("--border-default",mt(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Rs(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Mr(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Rs(t.accentColor,40)})`),s.style.setProperty("--border-accent",mt(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",mt(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${mt(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 ${mt(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 Pr(){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(r=>t.style.removeProperty(r))}function Ic(t){try{localStorage.setItem(fa,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Rt()?"dark":"light";Lt(bt(s))}else Pr(),rs(t,Rt()?"dark":"light")}function Tc(){const t=Cs();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Rt()?"dark":"light";Lt(bt(s))}else Pr(),rs(t,Rt()?"dark":"light")}function Rt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function at({label:t,value:s,onChange:r}){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:n=>r(n.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:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.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 Qt({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 Ac({dark:t,onColorsChange:s}){const r=t?"dark":"light",[n,i]=a.useState(()=>bt(r));a.useEffect(()=>{i(bt(r))},[r]);const o=a.useCallback((c,u)=>{i(d=>{const x={...d,[c]:u},f=bt(r==="dark"?"light":"dark");return r==="dark"?bs(x,f):bs(f,x),Lt(x),s(x),x})},[r,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(Qt,{title:"App Background",children:[e.jsx(at,{label:"Background",value:n.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(at,{label:"Surface",value:n.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(at,{label:"Card",value:n.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Qt,{title:"App Text",children:[e.jsx(at,{label:"Primary",value:n.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(at,{label:"Secondary",value:n.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(at,{label:"Muted",value:n.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Qt,{title:"Borders & Accent",children:[e.jsx(at,{label:"Border subtle",value:n.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(at,{label:"Border default",value:n.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(at,{label:"Accent",value:n.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Qt,{title:"Chat Bubbles",children:[e.jsx(at,{label:"User bubble",value:n.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(at,{label:"User text",value:n.userText,onChange:c=>o("userText",c)}),e.jsx(at,{label:"Agent bubble",value:n.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(at,{label:"Agent text",value:n.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Qt,{title:"Chat Layout",children:[e.jsx(at,{label:"Chat BG",value:n.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(at,{label:"Send button",value:n.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(at,{label:"Input border",value:n.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:n.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:[n.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?hr:br,d=bt(t?"light":"dark");t?bs(c,d):bs(d,c),i(c),Lt(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 _c(){const[t,s]=a.useState(Cs),[r,n]=a.useState(!0),[i,o]=a.useState(()=>bt("dark"));a.useEffect(()=>{n(Rt());const d=new MutationObserver(()=>{const f=Rt();n(f);const h=Cs();h==="custom"?Lt(bt(f?"dark":"light")):rs(h,f?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const f=Rt();n(f);const h=Cs();h==="custom"?Lt(bt(f?"dark":"light")):rs(h,f?"dark":"light")};return x.addEventListener("change",l),()=>{d.disconnect(),x.removeEventListener("change",l)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Lt(bt(r?"dark":"light")):(Pr(),rs(t,r?"dark":"light"))},[t,r]),a.useEffect(()=>{o(bt(r?"dark":"light"))},[r]);const c=d=>{s(d),Ic(d)},u=[...Sc,{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:u.map(d=>{const x=t===d.id,l=r?d.preview.dark:d.preview.light,f=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.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:l.userBubble,color:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),t==="custom"&&e.jsx(Ac,{dark:r,onColorsChange:d=>o(d)})]})}const ha="adhdev_mobileDashboardMode_v1";function ba(){try{return localStorage.getItem(ha)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Mc(t){try{localStorage.setItem(ha,t)}catch{}}function Pc(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(ba()==="chat")},[]),e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(vt,{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:r=>{s(r),Mc(r?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const ga="adhdev_hiddenTabs";function Lc(){try{const t=localStorage.getItem(ga);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Ut(t){try{localStorage.setItem(ga,JSON.stringify([...t]))}catch{}}function Rc(){const[t,s]=a.useState(Lc),r=a.useCallback(x=>{s(l=>{const f=new Set(l);return f.has(x)?f.delete(x):f.add(x),Ut(f),f})},[]),n=a.useCallback(x=>{s(l=>{if(l.has(x))return l;const f=new Set(l);return f.add(x),Ut(f),f})},[]),i=a.useCallback(x=>{s(l=>{if(!l.has(x))return l;const f=new Set(l);return f.delete(x),Ut(f),f})},[]),o=a.useCallback(()=>{s(x=>{if(x.size===0)return x;const l=new Set;return Ut(l),l})},[]),c=a.useCallback((x,l)=>{s(f=>{const h=new Set(f);for(const m of l)h.add(m);return Ut(h),h})},[]),u=a.useCallback((x,l)=>{s(f=>{const h=new Set(f);for(const m of l)h.delete(m);return Ut(h),h})},[]),d=a.useCallback(x=>t.has(x),[t]);return{hiddenTabs:t,toggleTab:r,hideTab:n,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:u,isHidden:d}}function Ec({visibleConversations:t,clearedTabs:s,setClearedTabs:r,setActionLogs:n}){a.useEffect(()=>{Qo()},[]);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 tc(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{r(u=>{const d=Date.now(),x={};for(const[l,f]of Object.entries(u))d-f<5e3&&(x[l]=f);return Object.keys(x).length===Object.keys(u).length?u:x})},5500);return()=>clearTimeout(c)},[s,r]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;n(u=>{const d=u.filter(x=>x.timestamp>c).slice(-100);return d.length===u.length?u:d})},6e4);return()=>clearInterval(o)},[n]),null}function tr(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 Pt(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1];return tr(s==null?void 0:s.timestamp)||tr(s==null?void 0:s.receivedAt)||tr(s==null?void 0:s.createdAt)||0}function gr(t,s=0){return Pt(t)||s||0}function ya(t){return Pt(t)}function $c(t,s,r=ya){const n=r(s)-r(t);if(n!==0)return n;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 Dc(t){const s=t.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of s){const i=r.get(n.id);if(!i){r.set(n.id,n);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>o||(n.timestamp||0)>(i.timestamp||0))&&r.set(n.id,n)}return Array.from(r.values())}function gs(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Bc(t,s){const r=Date.now();return t.map(n=>{const i=s[n.tabKey];return i&&r-i<5e3?{...n,messages:[],title:""}:n})}function Kc(t,s){const r=[],n=t.sessionId||t.instanceId;r.push({key:t.id,ref:s[t.id]}),n&&r.push({key:n,ref:s[n]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;r.push({key:c,ref:s[c]}),r.push({key:i.id,ref:s[i.id]})}return r}function Wc(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].key!==s[r].key||t[r].ref!==s[r].ref)return!1;return!0}function Oc(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Uc(t){const s=Oc(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 r=String(s.role||""),n=Tr(s.content).slice(0,240);return`${t.messages.length}:${r}:${n}`}function zc({ides:t,connectionStates:s,localUserMessages:r,clearedTabs:n,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),u=a.useRef([]),d=a.useRef([]),x=a.useMemo(()=>{const j=Dc(t);return gs(o.current,j)?o.current:(o.current=j,j)},[t]),l=a.useMemo(()=>ia(t),[t]),f=a.useRef(new Map),h=a.useRef(new Map),m=a.useMemo(()=>{var L;const j=new Map,C=[];for(const $ of x){const R=$.daemonId||((L=$.id)==null?void 0:L.split(":")[0])||$.id,T=s[R]||"new",O=$.daemonId&&l[$.daemonId]||void 0,H=Kc($,r),D=f.current.get($.id);if(D&&D.ide===$&&D.connectionState===T&&D.machineName===O&&Wc(D.localRefs,H)){j.set($.id,D),C.push(...D.conversations);continue}const F=Ar($,r,{machineName:O,connectionState:T}),_={ide:$,connectionState:T,machineName:O,localRefs:H,conversations:F};j.set($.id,_),C.push(...F)}f.current=j;const w=new Map,k=$=>{const R=Uc($),T=h.current.get($.tabKey);if(T&&T.signature===R)return w.set($.tabKey,T),T.timestamp;const O={signature:R,timestamp:ya($)||(T==null?void 0:T.timestamp)||0};return w.set($.tabKey,O),O.timestamp},E=[...C].sort(($,R)=>$c($,R,k));return h.current=w,E},[x,r,s,l]),y=a.useMemo(()=>{const j=Bc(m,n);return gs(c.current,j)?c.current:(c.current=j,j)},[m,n]),p=a.useMemo(()=>{const j=new Map;for(const C of y)C.sessionId&&j.set(C.sessionId,C);return j},[y]),g=a.useMemo(()=>{const j=new Map;for(const C of y)C.sessionId&&j.set(C.sessionId,C),j.set(C.ideId,C),j.set(C.tabKey,C);return j},[y]),b=a.useCallback(j=>{if(j)return p.get(j)},[p]),v=a.useCallback(j=>{if(j)return g.get(j)},[g]),S=a.useMemo(()=>{const j=y.filter(C=>!i.has(C.tabKey));return gs(u.current,j)?u.current:(u.current=j,j)},[y,i]),B=a.useMemo(()=>{const j=S.map(C=>C.tabKey);return gs(d.current,j)?d.current:(d.current=j,j)},[S]);return{chatIdes:x,conversations:y,visibleConversations:S,visibleTabKeys:B,resolveConversationBySessionId:b,resolveConversationByTarget:v}}function Fc({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:r,setSearchParams:n}){const i=a.useMemo(()=>{var u;return t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),o=a.useMemo(()=>{var u;return!t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),c=a.useCallback(()=>{s&&n(u=>{const d=new URLSearchParams(u);return d.delete("activeTab"),d},{replace:!0})},[n,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function Hc({ides:t,sendDaemonCommand:s,setToasts:r,setLocalUserMessages:n,resolveConversationByTarget:i}){a.useEffect(()=>{St.setIdes(t)},[t]),a.useEffect(()=>{St.setResolveAction((o,c,u)=>{s(o,c,u).catch(()=>{})})},[s]),a.useEffect(()=>{const o=St.onToast(d=>{r(l=>l.some(h=>h.message===d.message&&d.timestamp-h.timestamp<3e3)?l:[...l.slice(-4),{id:d.id,message:d.message,type:d.type,timestamp:d.timestamp,targetKey:d.targetKey,actions:d.actions}]);const x=d.duration||5e3;setTimeout(()=>r(l=>l.filter(f=>f.id!==d.id)),x)}),c=St.onSystemMessage((d,x)=>{var m,y;const l=i(d),f=(m=x._localId)==null?void 0:m.startsWith("sys_approval_"),h=!!(l&&(l.status==="waiting_approval"||(y=l.modalButtons)!=null&&y.length||l.modalMessage));f&&h||n(p=>({...p,[d]:[...p[d]||[],x]}))}),u=St.onClearSystemMessage((d,x)=>{n(l=>{var f;return(f=l[d])!=null&&f.length?{...l,[d]:l[d].filter(h=>{var m;return!(h.role==="system"&&((m=h._localId)!=null&&m.startsWith(x)))})}:l})});return()=>{o(),c(),u()}},[r,n]),a.useEffect(()=>{const o=na.on("status_event",c=>St.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=u=>{var g;const d=u.data;if((d==null?void 0:d.type)!=="notification_action"||typeof d.action!="string"||!d.action.startsWith("approval_")||!(d.ideId||d.targetSessionId||d.targetKey))return;const x=d.targetSessionId||d.targetKey||d.ideId,l=i(x),f=(l==null?void 0:l.ideId)||d.ideId;if(!f)return;const h=Number(d.buttonIndex),m=d.button||((g=l==null?void 0:l.modalButtons)==null?void 0:g[h])||"Approve",y=String(m).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),p=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y);s(f,"resolve_action",{action:p?"approve":"reject",button:m,...Number.isFinite(h)&&{buttonIndex:h},...(l==null?void 0:l.sessionId)&&{targetSessionId:l.sessionId},...d.targetSessionId&&{targetSessionId:d.targetSessionId}}).catch(b=>console.error("[SW Action] approval failed:",b))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",o)}},[i,s])}const Vc="adhdev_dashboardLayout_v1",Gc="adhdev_dashboardDockview_v1",es={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function va(t,s){try{const r=localStorage.getItem(t);return r?JSON.parse(r):s}catch{return s}}function wa(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function ja(t){return`${Vc}:${t}`}function qc(t){const s=ja(t);return va(s,null)}function Yc(t,s){try{const r=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,n=ja(t);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function ka(t){return`${Gc}:${t}`}function Xc(t){const s=ka(t);return va(s,null)}function Jc(t,s){try{const r=ka(t);if(!s){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Zc(){return{groupAssignments:[...es.groupAssignments],focusedGroup:es.focusedGroup,groupActiveTabIds:{...es.groupActiveTabIds},groupTabOrders:{...es.groupTabOrders},groupSizes:[...es.groupSizes]}}function Qc(){const[t]=a.useState(()=>wa(typeof window<"u"?window.innerWidth:1280)),[s,r]=a.useState(()=>new Map),[n,i]=a.useState(0),[o,c]=a.useState({}),[u,d]=a.useState({}),[x,l]=a.useState([]),[f,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[m,y]=a.useState(!1),p=a.useCallback(()=>{if(m)return;const g=qc(t)??Zc();r(new Map(g.groupAssignments)),i(g.focusedGroup),c(g.groupActiveTabIds),d(g.groupTabOrders),l(g.groupSizes),y(!0)},[m,t]);return a.useEffect(()=>{m&&Yc(t,{groupAssignments:[...s.entries()],focusedGroup:n,groupActiveTabIds:o,groupTabOrders:u,groupSizes:x})},[m,t,s,n,o,u,x]),a.useEffect(()=>{const g=window.matchMedia("(max-width: 767px)"),b=v=>h(v.matches);return g.addEventListener("change",b),()=>g.removeEventListener("change",b)},[]),{groupAssignments:s,setGroupAssignments:r,focusedGroup:n,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:u,setGroupTabOrders:d,groupSizes:x,setGroupSizes:l,isMobile:f,hasHydratedStoredLayout:m,hydrateStoredLayout:p}}function el({urlActiveTab:t,conversations:s,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:u,setSearchParams:d,historyModalOpen:x,activeConv:l,isRefreshingHistory:f,ides:h,handleRefreshHistory:m}){const y=a.useRef(!1),p=a.useRef(!1),g=a.useRef(null),b=a.useRef(!1);a.useEffect(()=>{if(!t||y.current||s.length===0)return;if(!i){o();return}const v=r(t);if(!v)return;const S=n.get(v.tabKey)??0;c(B=>({...B,[S]:v.tabKey})),u(S),y.current=!0,p.current=!0,g.current!=null&&(window.clearTimeout(g.current),g.current=null),d(B=>{const j=new URLSearchParams(B);return j.delete("activeTab"),j},{replace:!0})},[t,s,r,n,i,o,c,u,d]),a.useEffect(()=>{if(!(p.current||i)&&s.length!==0){if(!t){o(),p.current=!0;return}if(y.current){p.current=!0;return}if(g.current==null)return g.current=window.setTimeout(()=>{g.current=null,!(p.current||i)&&(o(),p.current=!0)},1500),()=>{g.current!=null&&(window.clearTimeout(g.current),g.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!x){b.current=!1;return}if(!l||b.current||f)return;const v=h.find(S=>S.id===l.ideId);v&&(!v.chats||v.chats.length===0)&&(b.current=!0,m())},[x,l,f,h,m]),a.useEffect(()=>{if(!l)return;let v=null,S=0,B=-1,j=0;const C=()=>{v=null;const w=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(E=>E.offsetParent!==null);if(w.length===0){S<18&&(S+=1,v=requestAnimationFrame(C));return}let k=0;for(const E of w)E.scrollTop=E.scrollHeight,k+=E.scrollHeight;k===B?j+=1:(j=0,B=k),S+=1,!(j>=2||S>=18)&&(v=requestAnimationFrame(C))};return v=requestAnimationFrame(C),()=>{v!=null&&cancelAnimationFrame(v)}},[l==null?void 0:l.tabKey])}function tl({isMobile:t,location:s,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:u}){const[d,x]=a.useState(null),[l,f]=a.useState(null),h=a.useMemo(()=>{if(t||!n)return null;const b=u(n);return b&&!Xe(b)&&!ze(b)?b:null},[t,n,u]),m=a.useMemo(()=>{const b=d==null?void 0:d.ideId;if(!b)return null;const v=d!=null&&d.tabKey?o.find(S=>S.tabKey===d.tabKey):i?o.find(S=>S.tabKey===i):null;return(v==null?void 0:v.ideId)===b?v:o.find(S=>S.ideId===b&&S.streamSource==="native")||o.find(S=>S.ideId===b)||null},[o,d,i]),y=a.useMemo(()=>{if(m)return c.find(b=>b.id===m.ideId)},[c,m]);a.useEffect(()=>{h&&(x({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),f(h),r({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,r,h]);const p=a.useCallback(b=>{b&&(x({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),f(b))},[]),g=a.useCallback(()=>{x(null),f(null)},[]);return{remoteDialogConv:m,remoteDialogIdeEntry:y,remoteDialogActiveConv:l,setRemoteDialogActiveConv:f,openRemoteDialog:p,closeRemoteDialog:g}}function Vt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Xe(t)||ze(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function ls(t){return t&&(t.ideId||t.daemonId)||""}function ys(t,s){t(r=>[...r,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function fn({sendDaemonCommand:t,activeConv:s,updateIdeChats:r,setToasts:n,setLocalUserMessages:i,setClearedTabs:o}){const[c,u]=a.useState(!1),[d,x]=a.useState(!1),l=a.useCallback(async y=>{try{await t("standalone","launch_ide",{ideType:y,enableCdp:!0})}catch(p){console.error("Launch failed",p)}},[t]),f=a.useCallback(async(y,p)=>{try{const g=y||(s==null?void 0:s.daemonId)||"",b=await t(g,"switch_chat",{id:p,sessionId:p,...Vt(s)}),v=b==null?void 0:b.result;if((b==null?void 0:b.success)===!0||v==="switched"||v==="switched-by-title")return;v===!1||v==="not_found"?ys(n,"⚠️ Session tab not found — try refreshing history"):typeof v=="string"&&v.startsWith("error:")?ys(n,`⚠️ Switch error: ${v}`):ys(n,"⚠️ Session switch failed")}catch(g){console.error("Switch failed",g),ys(n,`❌ Switch failed: ${g.message||"connection error"}`)}},[s,t,n]),h=a.useCallback(async()=>{if(!(!s||c)){u(!0);try{const y=ls(s);await t(y,"new_chat",{...Vt(s)}),o(p=>({...p,[s.tabKey]:Date.now()})),i(p=>({...p,[s.tabKey]:[]}))}catch(y){console.error("New chat failed",y)}finally{u(!1)}}},[s,c,t,o,i]),m=a.useCallback(async()=>{var y;if(!(!s||d)){x(!0);try{const p=ls(s),g=await t(p,"list_chats",{forceExpand:!0,...Vt(s)}),b=(g==null?void 0:g.chats)||((y=g==null?void 0:g.result)==null?void 0:y.chats);g!=null&&g.success&&Array.isArray(b)&&r(s.ideId,b)}catch(p){console.error("Refresh history failed",p)}finally{x(!1)}}},[s,d,t,r]);return{isCreatingChat:c,isRefreshingHistory:d,handleLaunchIde:l,handleSwitchSession:f,handleNewChat:h,handleRefreshHistory:m}}function sl(t,s){if(t.size!==s.size)return!1;for(const[r,n]of t)if(s.get(r)!==n)return!1;return!0}function rl(t,s){return t.length!==s.length?!1:t.every((r,n)=>r===s[n])}function xn(t,s){const r=Object.keys(t),n=Object.keys(s);return r.length!==n.length?!1:r.every(i=>s[Number(i)]===t[Number(i)])}function vs(t,s){const r=new Set(s),n=s.length>0?[0]:[];for(const[c,u]of t)!r.has(c)||u<=0||n.includes(u)||n.push(u);n.sort((c,u)=>c-u);const i={};n.forEach((c,u)=>{i[c]=u}),n.length===0&&(i[0]=0);const o=new Map;for(const[c,u]of t){if(!r.has(c)||u<=0)continue;const d=i[u];typeof d=="number"&&d>0&&o.set(c,d)}return{assignments:o,groupCount:Math.max(1,n.length),mapping:i,usedGroups:n}}function hn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=s[Number(n)];typeof o=="number"&&(r[o]=i)}return r}function nl(t,s,r){if(s.length===0)return 0;if(typeof r[t]=="number")return r[t];const n=[...s].reverse().find(i=>i<t)??s[0];return r[n]??0}function al(t,s,r){if(s.length<=1)return[];const n=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=n.length===s.length?n:Array(r).fill(100/r),o=i.reduce((c,u)=>c+u,0);return o>0?i.map(c=>c/o*100):Array(r).fill(100/r)}function bn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=Number(n);r[o>=s?o+1:o]=i}return r}function gn(t){return Array(t).fill(100/t)}function il({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:r,setGroupActiveTabIds:n,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:u,visibleConversations:d,visibleTabKeys:x}){const l=a.useRef(null),f=a.useMemo(()=>vs(t,x),[t,x]),h=f.assignments,m=a.useMemo(()=>u?1:f.groupCount,[f.groupCount,u]),y=m>1,p=a.useCallback((j,C)=>{s(w=>{const k=new Map(vs(w,x).assignments);return C===0?k.delete(j):k.set(j,C),k}),n(w=>({...w,[C]:j})),r(C)},[s,x,n,r]),g=a.useCallback(j=>{s(C=>{const w=vs(C,x).assignments,k=new Map;for(const[E,L]of w)L!==j&&(L>j?k.set(E,L-1):k.set(E,L));return k}),c(C=>{if(C.length<=1)return[];const w=[...C];w.splice(j,1);const k=w.reduce((E,L)=>E+L,0);return k>0?w.map(E=>E/k*100):[]}),r(0)},[s,x,c,r]),b=a.useCallback((j,C)=>{C.preventDefault();const w=l.current;if(!w)return;const k=C.clientX,E=w.offsetWidth,L=o.length===m?[...o]:gn(m),$=T=>{const H=(T.clientX-k)/E*100,D=[...L];D[j]=Math.max(15,L[j]+H),D[j+1]=Math.max(15,L[j+1]-H),c(D)},R=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",R),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",$),document.addEventListener("mouseup",R)},[o,m,c]),v=a.useCallback((j,C,w)=>{if(m>=4)return;const k=w==="left"?C:C+1;s(E=>{const L=vs(E,x).assignments,$=new Map;for(const R of d){const T=L.get(R.tabKey)??0,O=T>=k?T+1:T;O>0&&$.set(R.tabKey,O)}return k>0&&$.set(j,k),$}),c(E=>{const L=E.length===m?[...E]:gn(m),$=L[C]??100/m,R=Math.max(15,$/2),T=Math.max(15,$/2),O=[...L];O[C]=R,O.splice(k,0,T);const H=O.reduce((D,F)=>D+F,0);return O.map(D=>D/H*100)}),n(E=>{const L=bn(E,k);return L[k]=j,L}),i(E=>{const L=bn(E,k);return L[k]=[j],L}),r(k)},[m,s,x,d,c,n,i,r]);a.useEffect(()=>{sl(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:j,usedGroups:C}=f;n(w=>{const k=hn(w,j);return xn(w,k)?w:k}),i(w=>{const k=hn(w,j);return xn(w,k)?w:k}),r(w=>{const k=u?0:nl(w,C,j);return w===k?w:k}),c(w=>{const k=u?[]:al(w,C,f.groupCount);return rl(w,k)?w:k})},[f,u,n,i,r,c]);const S=a.useMemo(()=>{const j=Array.from({length:m},()=>[]);for(const C of d){const w=h.get(C.tabKey)??0,k=Math.min(w,m-1);j[k].push(C)}return j},[d,h,m]),B=a.useCallback(()=>{s(new Map),r(0)},[s,r]);return{containerRef:l,normalizedGroupAssignments:h,numGroups:m,isSplitMode:y,groupedConvs:S,moveTabToGroup:p,closeGroup:g,handleResizeStart:b,splitTabRelative:v,clearAllSplits:B}}function ol({ides:t,sendDaemonCommand:s}){const r="0.8.22",n=a.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const l=x.version||x.daemonVersion||null;return!l||!r?!1:l!==r}),[r,t]),[i,o]=a.useState(!1),[c,u]=a.useState({}),d=a.useCallback(async x=>{var l,f;u(h=>({...h,[x]:"upgrading"}));try{const h=await s(x,"daemon_upgrade",{});(l=h==null?void 0:h.result)!=null&&l.upgraded||(f=h==null?void 0:h.result)!=null&&f.success?u(m=>({...m,[x]:"done"})):u(m=>({...m,[x]:"error"}))}catch{u(h=>({...h,[x]:"error"}))}},[s]);return{versionMismatchDaemons:n,appVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:d}}function yn(t){return!t||typeof t!="object"?t:t.result&&typeof t.result=="object"?t.result:t}function Na(t){return t instanceof Error?t.message:String(t||"")}function vn(t){const s=Na(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Us({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:r,setActionLogs:n,isStandalone:i}){const[o,c]=a.useState(!1),[u,d]=a.useState(!1),x=a.useRef(!1),l=a.useRef(null),f=a.useCallback(async p=>{if(!s)return;const g=p.trim();if(!g||x.current)return;const b=s.tabKey,v=Date.now(),S=l.current;if(S&&S.tabKey===b&&S.message===g&&v-S.timestamp<2e3)return;x.current=!0,d(!0),l.current={tabKey:b,message:g,timestamp:v};const B=`${v}-${Math.random().toString(36).slice(2,8)}`,j={role:"user",content:g,timestamp:v,_localId:B};r(C=>({...C,[b]:[...C[b]||[],j]}));try{const C=ls(s);if(!C)return;const w=await t(C,"send_chat",{message:g,text:g,...Vt(s)}),k=yn(w);if(k!=null&&k.deduplicated||(k==null?void 0:k.sent)===!1){r(E=>({...E,[b]:(E[b]||[]).filter(L=>L._localId!==B)}));return}if((k==null?void 0:k.success)===!1)throw new Error((k==null?void 0:k.error)||"Send failed");setTimeout(()=>{const E=Date.now()-6e4;r(L=>{const $=L[b];if(!$)return L;const R=$.filter(T=>T.timestamp>E);return R.length===$.length?L:{...L,[b]:R}})},6e4)}catch(C){const w=Na(C);w.toLowerCase().includes("provider sendmessage did not confirm send")?console.warn("Send not confirmed by provider script:",w):console.error("Send failed",C),r(k=>({...k,[b]:(k[b]||[]).filter(E=>E._localId!==B)}))}finally{x.current=!1,d(!1)}},[s,t,r]),h=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(p){console.error("Relaunch failed",p)}},[s,t]),m=a.useCallback(async p=>{if(s)try{const b=(s.modalButtons||[]).indexOf(p),v=p.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),S=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v),B=ls(s);if(!B)return;const j=await t(B,"resolve_action",{button:p,action:S?"approve":"reject",...b>=0&&{buttonIndex:b},...Vt(s)});yn(j).success||n(w=>[...w,{ideId:s.tabKey,text:`⚠️ **${p}** failed — button not found`,timestamp:Date.now()}])}catch(g){vn(g)||console.error("[ModalButton] Error:",g),n(b=>[...b,{ideId:s.tabKey,text:vn(g)?`⚠️ **${p}** unavailable`:`❌ **${p}** error`,timestamp:Date.now()}])}},[s,t,n]),y=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(p){console.error("Focus agent failed",p)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:u,isFocusingAgent:o,handleSendChat:f,handleRelaunch:h,handleModalButton:m,handleFocusAgent:y}}const Lr=a.memo(function({activeConv:s,clearToken:r,isCliTerminal:n,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:u,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:h,userName:m,scrollToBottomRequestNonce:y,isInputActive:p=!0}){return e.jsxs(e.Fragment,{children:[e.jsx(Zn,{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(Bs,{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:u,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:n?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Lo,{activeConv:s,clearToken:r,terminalRef:o,handleSendChat:d,isSendingChat:x,isVisible:n})}),!n&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(pr,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:h,userName:m,scrollToBottomRequestNonce:y,isInputActive:p})})]}):e.jsx(pr,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:h,userName:m,scrollToBottomRequestNonce:y,isInputActive: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&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce&&t.isInputActive===s.isInputActive);function cl({selectedConversation:t,isAcp:s,isStandalone:r,selectedIdeEntry:n,actionLogs:i,userName:o,isSendingChat:c,isFocusingAgent:u,onBack:d,onOpenNativeConversation:x,onOpenMachine:l,onOpenHistory:f,onOpenRemote:h,onHideConversation:m,onStopCli:y,cliViewMode:p,onSetCliViewMode:g,handleSendChat:b,handleFocusAgent:v,handleModalButton:S,handleRelaunch:B}){const j=a.useRef(null),C=Xe(t)&&!s,w=C&&p==="terminal",k=r?"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:d,type:"button","aria-label":"Back",children:e.jsx(vr,{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(ta,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>x(t),onOpenMachine:()=>l(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[C&&p&&e.jsx(Ir,{mode:p,onChange:g,compact:!0}),C&&y&&e.jsx("button",{onClick:()=>{y(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(Dt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(wr,{size:14})}),!s&&!C&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",children:e.jsx(ot,{size:14})}),m&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(t),type:"button",title:"Close chat",children:e.jsx(Dt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Lr,{activeConv:t,clearToken:0,isCliTerminal:w,ideEntry:n,terminalRef:j,handleModalButton:S,handleRelaunch:B,handleSendChat:b,isSendingChat:c,handleFocusAgent:v,isFocusingAgent:u,actionLogs:i,userName:o})})]})}const sr={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 ll(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Sa(){const[t,s]=a.useState("unix"),[r,n]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":r;a.useEffect(()=>{s(ll())},[]);const u=a.useCallback(()=>{navigator.clipboard.writeText(sr[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 ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:sr[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:sr[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 Ca({section:t,onSectionChange:s}){const r=[{key:"machines",label:"Machines",icon:ot},{key:"chats",label:"Chats",icon:vt}];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:r.map(({key:n,label:i,icon:o})=>{const c=t===n;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(n),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})]},n)})})})}function ws({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 zt({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 ts({icon:t,title:s,subtitle:r,children:n}){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:r}),n]})}function js({item:t,type:s,getAvatarText:r,onOpenConversation:n}){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:()=>n(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:r(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:Jn(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(ot,{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 wn({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 dl({section:t,attentionItems:s,unreadItems:r,workingItems:n,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:u,onOpenConversation:d,onShowConversation:x,onShowAllHidden:l,onOpenMachine:f,onOpenSettings:h,onSectionChange:m,wsStatus:y="connected",isStandalone:p=!1}){const g=y==="disconnected"||y==="reconnecting"||y==="offline"||y==="auth_failed",b=c.length>0,v=s.length>0||r.length>0||n.length>0||i.length>0,S=t==="machines"?"Machines":"Chats",B=p?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",j=p?"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 ${B}`,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:S}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||r.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(Ks,{size:13}),e.jsx("span",{children:s.length+r.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($s,{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] ${j}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:g?e.jsx(ts,{icon:e.jsx(wn,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:y==="offline"?"Your device appears to be offline. Waiting for network…":y==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(ts,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:p?"Waiting for your IDE":"Connect your first machine",subtitle:p?"Open an IDE directly, or choose a workspace before launching CLI or ACP sessions.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!p&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Sa,{})})}):e.jsx(zt,{children:c.map((C,w)=>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] ${w>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(C.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:u(C.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:C.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:C.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[C.unread," new"]}):C.total>0?`${C.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:C.subtitle}),C.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[C.total," chat",C.total!==1?"s":"",C.unread>0?` · ${C.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},C.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(ws,{title:"Needs attention",className:"mb-0"}),e.jsx(zt,{children:s.map((C,w)=>e.jsx("div",{className:w>0?"border-t border-border-subtle/70":"",children:e.jsx(js,{item:C,type:"needs_attention",getAvatarText:u,onOpenConversation:d})},C.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(ws,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(zt,{children:r.map((C,w)=>e.jsx("div",{className:w>0?"border-t border-border-subtle/70":"",children:e.jsx(js,{item:C,type:"task_complete",getAvatarText:u,onOpenConversation:d})},C.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(ws,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(zt,{children:n.map((C,w)=>e.jsx("div",{className:w>0?"border-t border-border-subtle/70":"",children:e.jsx(js,{item:C,type:"working",getAvatarText:u,onOpenConversation:d})},C.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(ws,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(zt,{children:i.map((C,w)=>e.jsx("div",{className:w>0?"border-t border-border-subtle/70":"",children:e.jsx(js,{item:C,type:"earlier",getAvatarText:u,onOpenConversation:d})},C.conversation.tabKey))}):v?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):g?e.jsx(ts,{icon:e.jsx(wn,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):b?e.jsx(ts,{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(vt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open the machine screen, choose a workspace, then launch your first IDE, CLI, or ACP session."}):e.jsx(ts,{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:l,children:"Restore all"})]}),e.jsx(zt,{className:"bg-bg-secondary/25",children:o.map((C,w)=>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 ${w>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(C),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:u(C.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:C.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:[C.displaySecondary,C.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(ot,{size:11})," ",C.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},C.tabKey))})]})]}),e.jsx(Ca,{section:t,onSectionChange:m})]})}function ul(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 r=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),i=(r[2]||"").replace(/[\\/]+/g,"\\");return i?`${n}:\\${i}`:`${n}:\\`}return null}function zs(t,s=[]){if(t==="win32"){for(const r of s){if(typeof r!="string")continue;const n=ul(r);if(n)return n}return"C:\\"}for(const r of s){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function pl(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const r=s.includes("\\")?"\\":"/",n=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}async function Rr(t,s,r){const n=await t(s,"file_list_browse",{path:r});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Could not browse folder");const i=typeof(n==null?void 0:n.path)=="string"?n.path:r,o=i.includes("\\")?"\\":"/",c=(d,x)=>/^[A-Za-z]:\\?$/.test(d)?`${d.replace(/\\?$/,"\\")}${x}`:d==="/"||d==="\\"?`${o}${x}`:`${d.replace(/[\\/]+$/,"")}${o}${x}`,u=Array.isArray(n==null?void 0:n.files)?n.files.filter(d=>(d==null?void 0:d.type)==="directory"&&typeof(d==null?void 0:d.name)=="string").map(d=>({name:d.name,path:c(i,d.name)})).sort((d,x)=>d.name.localeCompare(x.name)):[];return{path:i,directories:u}}function Fs({title:t,description:s,currentPath:r,directories:n,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:u,onNavigate:d,onConfirm:x}){const[l,f]=a.useState(r);a.useEffect(()=>{f(r)},[r]);const h=pl(r),m=l.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:u,"aria-label":"Close folder browser",children:e.jsx(Dt,{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||d(h)},disabled:!h||i,children:[e.jsx(vr,{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:l,onChange:y=>f(y.target.value),onKeyDown:y=>{y.key!=="Enter"||!m||i||(y.preventDefault(),d(m))},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:()=>{!m||i||d(m)},disabled:!m||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}):n.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:n.map(y=>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:()=>d(y.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(Gt,{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:y.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:y.path})]})]},y.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:u,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>x(m||r),disabled:!m&&!r||i,children:c})]})]})})}function Er({title:t,description:s,details:r,workspaceOptions:n,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:u=!1,onConfirm:d,onCancel:x}){const l=n==null?void 0:n.find(f=>f.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:x,"aria-label":"Close launch confirmation",children:e.jsx(Dt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n&&n.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:f=>o(f.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:u,children:n.map(f=>e.jsx("option",{value:f.key,children:f.label},f.key))}),(l==null?void 0:l.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:l.description})]}),r.map(f=>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:f.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:f.value})]},`${f.label}:${f.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:x,disabled:u,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:d,disabled:u,children:[e.jsx(Nr,{size:14}),u?"Launching…":c]})]})]})})}function jn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function Et(t){const{machine:s,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const d of s.workspaces||[])o.push({key:`saved:${d.id}`,label:`${d.id===s.defaultWorkspaceId?"⭐ ":""}${jn(d.path,d.label)}`,description:d.path,workspaceId:d.id,workspacePath:d.path});const c=(r==null?void 0:r.trim())||"",u=c?(s.workspaces||[]).find(d=>d.path===c):null;if(c&&!u&&o.push({key:`custom:${c}`,label:jn(c),description:c,workspaceId:null,workspacePath:c}),n){const d=`saved:${n}`;if(o.some(x=>x.key===d))return{options:o,selectedKey:d}}return u?{options:o,selectedKey:`saved:${u.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function ml({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:u,isStandalone:d,section:x,showBottomNav:l,onBack:f,onSectionChange:h,onOpenConversation:m,onOpenRecent:y,onOpenMachineDetails:p,onMachineUpgrade:g,onLaunchDetectedIde:b,onAddWorkspace:v,onBrowseDirectory:S,onLaunchWorkspaceProvider:B}){var $e,He,Oe,Qe;const j=(Z,ge,K)=>Z?"ide":ge>0?"cli":K>0?"acp":null,[C,w]=a.useState(!1),k=Z=>Z==="ide"?"IDE":Z==="cli"?"CLI":"ACP",E=r.slice(0,4),L=s.slice(0,3),$=((($e=t.detectedIdes)==null?void 0:$e.length)||0)>0,R=a.useMemo(()=>t.workspaces||[],[t]),T=t.defaultWorkspaceId||null,[O,H]=a.useState(T||((He=R[0])==null?void 0:He.id)||""),[D,F]=a.useState(""),[_,A]=a.useState(""),[M,G]=a.useState([]),[Y,ue]=a.useState(!1),[ve,Te]=a.useState(""),[ee,Me]=a.useState(!1),[U,ae]=a.useState(j($,n.length,i.length)),X=a.useRef(null),[pe,me]=a.useState(null),se=a.useRef("__home__"),[de,xe]=a.useState("__home__"),[oe,J]=a.useState(!1),ce=a.useRef(null),Q=O==="__custom__"?D.trim():((Oe=R.find(Z=>Z.id===O))==null?void 0:Oe.path)||"",he=O==="__custom__"&&!!Q&&u.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(u.message),I=O!=="__custom__"&&((Qe=R.find(Z=>Z.id===O))==null?void 0:Qe.path)||"",re=a.useCallback(async Z=>{ue(!0),Te("");try{const ge=await S(Z);A(ge.path),F(ge.path),G(ge.directories)}catch(ge){Te(ge instanceof Error?ge.message:"Could not load folder")}finally{ue(!1)}},[S]),W=a.useCallback(()=>{var ge,K;H("__custom__"),Me(!0);const Z=zs(t.platform,[D.trim(),I,(ge=R.find(P=>P.id===T))==null?void 0:ge.path,(K=R[0])==null?void 0:K.path]);re(Z)},[D,T,re,I,t.platform,R]),z=a.useCallback((Z,ge)=>{X.current=ge,se.current=Z.selectedWorkspaceKey||"__home__",xe(Z.selectedWorkspaceKey||"__home__"),me(Z)},[]),te=a.useCallback(()=>{X.current&&(J(!0),X.current().finally(()=>{X.current=null,J(!1),me(null)}))},[]);a.useEffect(()=>{var Z;ce.current!==t.id&&(ce.current=t.id,H(T||((Z=R[0])==null?void 0:Z.id)||"__custom__"),F(""),A(""),G([]),Te(""),Me(!1),ae(j($,n.length,i.length)))},[i.length,n.length,T,$,t.id,R]),a.useEffect(()=>{var Z;O!=="__custom__"&&(O&&R.some(ge=>ge.id===O)||H(T||((Z=R[0])==null?void 0:Z.id)||"__custom__"))},[T,O,R]),a.useEffect(()=>{U==="ide"&&$||U==="cli"&&n.length>0||U==="acp"&&i.length>0||ae(j($,n.length,i.length))},[U,i.length,n.length,$]);const le=a.useMemo(()=>E.map(Z=>({key:`recent-launch:${Z.id}`,primary:Z.label,secondary:`${k(Z.kind)}${Z.subtitle?` · ${Z.subtitle}`:""}`,onClick:()=>{const{options:ge,selectedKey:K}=Et({machine:{workspaces:R,defaultWorkspaceId:T},currentWorkspacePath:Z.workspace});z({title:`Launch ${Z.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:ge,selectedWorkspaceKey:K,details:[{label:"Mode",value:k(Z.kind)},...Z.providerType?[{label:"Provider",value:Z.providerType}]:[]]},async()=>{const P=ge.find(ne=>ne.key===se.current);P!=null&&P.workspaceId?(H(P.workspaceId),F("")):P!=null&&P.workspacePath?(H("__custom__"),F(P.workspacePath)):(H(""),F("")),await y({...Z,workspace:(P==null?void 0:P.workspacePath)??null})})}})),[T,y,z,E,R]),Ne=a.useMemo(()=>L.map(Z=>({key:`recent-chat:${Z.conversation.tabKey}`,primary:Z.conversation.displayPrimary,secondary:`Chat${Z.conversation.displaySecondary?` · ${Z.conversation.displaySecondary}`:""}${Z.timestamp?` · ${Jn(Z.timestamp)}`:""}`,unread:Z.unread,onClick:()=>m(Z.conversation)})),[m,L]),Pe=C?le:le.slice(0,4),q=le.length>0,be=Ne.length>0,Ae=d?"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 ${Ae} 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:f,type:"button","aria-label":"Back",children:e.jsx(vr,{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:gt(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:[be&&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:"Current Chats"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Ne.map(Z=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${Z.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:Z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:Z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:Z.secondary})]},Z.key))})]}),q&&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 Launches"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Pe.map(Z=>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:Z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:Z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:Z.secondary})]},Z.key))}),le.length>4&&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:()=>w(Z=>!Z),children:C?"Show fewer":`Show ${le.length-4} more`})})]}),($||n.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:O,onChange:Z=>{const ge=Z.target.value;if(H(ge),ge==="__custom__"){W();return}F("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:R.length>0?e.jsxs(e.Fragment,{children:[R.map(Z=>e.jsxs("option",{value:Z.id,children:[Z.id===T?"⭐ ":"",Os(Z.path,Z.label)||Z.path]},Z.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),O==="__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(Gt,{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:Q||_||"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:W,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:()=>{Q&&v(Q)},disabled:!Q||Y,children:"Save as workspace"})]})]}),Q&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:Q})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[$&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${U==="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:()=>ae("ide"),children:"IDE"}),n.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${U==="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:()=>ae("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${U==="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:()=>ae("acp"),children:"ACP"})]}),U&&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:U==="ide"?"Choose an IDE":U==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:U==="ide"?(t.detectedIdes||[]).slice(0,6).map(Z=>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:ge,selectedKey:K}=Et({machine:{workspaces:R,defaultWorkspaceId:T},currentWorkspaceId:O!=="__custom__"?O:null,currentWorkspacePath:Q});z({title:`Launch ${Z.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:ge,selectedWorkspaceKey:K,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Z.name}]},async()=>{const P=ge.find(ne=>ne.key===se.current);P!=null&&P.workspaceId?(H(P.workspaceId),F("")):P!=null&&P.workspacePath?(H("__custom__"),F(P.workspacePath)):(H(""),F("")),b(Z.type,{workspacePath:(P==null?void 0:P.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:Z.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:Q||"Use selected workspace"})]},Z.type)):(U==="cli"?n:i).map(Z=>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:ge,selectedKey:K}=Et({machine:{workspaces:R,defaultWorkspaceId:T},currentWorkspaceId:O!=="__custom__"?O:null,currentWorkspacePath:Q});z({title:`Launch ${Z.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${U.toUpperCase()}`,workspaceOptions:ge,selectedWorkspaceKey:K,details:[{label:"Mode",value:U.toUpperCase()},{label:"Provider",value:Z.displayName}]},async()=>{const P=ge.find(ne=>ne.key===se.current);P!=null&&P.workspaceId?(H(P.workspaceId),F("")):P!=null&&P.workspacePath?(H("__custom__"),F(P.workspacePath)):(H(""),F("")),B(U,Z.type,{workspaceId:(P==null?void 0:P.workspaceId)??null,workspacePath:(P==null?void 0:P.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[Z.icon?`${Z.icon} `:"",Z.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:Q||"Use selected workspace"})]},Z.type))})]}),u.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${u.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[u.message,he&&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:()=>v(Q,{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:g,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:p,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"})]})]})]})]}),ee&&e.jsx(Fs,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:_,directories:M,busy:Y,error:ve,confirmLabel:"Use this folder",onClose:()=>Me(!1),onNavigate:Z=>{re(Z)},onConfirm:Z=>{F(Z),H("__custom__"),Me(!1)}}),pe&&e.jsx(Er,{title:pe.title,description:pe.description,details:pe.details,workspaceOptions:pe.workspaceOptions,selectedWorkspaceKey:de,onWorkspaceChange:Z=>{se.current=Z,xe(Z)},confirmLabel:pe.confirmLabel,busy:oe,onConfirm:te,onCancel:()=>{X.current=null,me(null)}}),l&&e.jsx(Ca,{section:x,onSectionChange:h})]})}function fl(t){return Tr(t)}function kn(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1],r=fl(s==null?void 0:s.content);return r||(t.title?t.title:t.displaySecondary||"No messages yet")}function xl(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function ks(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function hl(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function Nn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function bl(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function gl(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function yl({conversations:t,hiddenConversations:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,userName:d,requestedActiveTabKey:x,onRequestedActiveTabConsumed:l,requestedMachineId:f,onRequestedMachineConsumed:h,requestedMobileSection:m,onRequestedMobileSectionConsumed:y,onOpenHistory:p,onOpenRemote:g,onStopCli:b,wsStatus:v,isConnected:S,onShowHiddenConversation:B,onShowAllHiddenConversations:j,onHideConversation:C}){const[w,k]=a.useState(()=>{var K;return((K=t[0])==null?void 0:K.tabKey)||null}),[E,L]=a.useState(()=>t[0]?"chat":"inbox"),[$,R]=a.useState("chats"),[T,O]=a.useState(null),[H,D]=a.useState("inbox"),[F,_]=a.useState("idle"),[A,M]=a.useState(""),[G,Y]=a.useState(null),ue=a.useRef(null),ve=Yt(),Te="0.8.22",ee=a.useMemo(()=>t.find(K=>K.tabKey===w)||t[0]||null,[t,w]),Me=a.useMemo(()=>ee?r.find(K=>K.id===ee.ideId):void 0,[r,ee]),U=a.useMemo(()=>!ee||ze(ee)||!Xe(ee)?null:qt(ee),[ee]),ae=a.useMemo(()=>r.filter(K=>K.type==="adhdev-daemon"||K.daemonMode).sort(Sr),[r]),X=a.useMemo(()=>ae.find(K=>K.id===T)||null,[ae,T]),pe=a.useMemo(()=>ms(r),[r]),me=Us({sendDaemonCommand:i,activeConv:ee||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),se=a.useCallback(K=>{if(!K||!K.sessionId)return;const P=is(K,pe),ne=Math.max(Date.now(),Pt(K),P.lastUpdated||0);ks("mark_read:start",{tabKey:K.tabKey,sessionId:K.sessionId,displayPrimary:K.displayPrimary,inboxBucket:P.inboxBucket,unread:P.unread,lastSeenAt:P.lastSeenAt,lastUpdated:P.lastUpdated,activityAt:Pt(K),readAt:ne}),i(K.daemonId||K.ideId,"mark_session_seen",{sessionId:K.sessionId,seenAt:ne}).then(ie=>{ks("mark_read:result",{tabKey:K.tabKey,sessionId:K.sessionId,result:ie})}).catch(ie=>{ks("mark_read:error",{tabKey:K.tabKey,sessionId:K.sessionId,error:ie instanceof Error?ie.message:String(ie)})})},[pe,i]);a.useEffect(()=>{var P;if(!ee){L("inbox"),k(((P=t[0])==null?void 0:P.tabKey)||null),ue.current=null;return}if(E!=="chat"){ue.current=null;return}const K=`${ee.tabKey}:${ee.sessionId||""}`;ue.current!==K&&(ue.current=K,se(ee))},[t,se,E,ee]),a.useEffect(()=>{if(!x)return;const K=t.find(P=>P.tabKey===x);K&&(k(K.tabKey),L("chat"),l==null||l())},[t,l,x]),a.useEffect(()=>{if(!f)return;const K=ae.find(P=>P.id===f);K&&(O(K.id),_("idle"),M(""),R("machines"),D("inbox"),L("machine"),h==null||h())},[ae,h,f]),a.useEffect(()=>{m&&(R(m),L("inbox"),y==null||y())},[y,m]);const de=a.useMemo(()=>t.map(K=>{const P=E==="chat"&&(ee==null?void 0:ee.tabKey)===K.tabKey,ne=os(K,pe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:P}),ie=Pt(K),Se=kn(K);return{conversation:K,timestamp:ie,preview:Se,unread:ne.unread,requiresAction:ne.requiresAction,isWorking:ne.isWorking,inboxBucket:ne.inboxBucket}}),[t,pe,E,ee]);a.useEffect(()=>{const K=de.filter(P=>P.inboxBucket==="task_complete"||P.unread);K.length!==0&&ks("inbox_state",{screen:E,selectedTabKey:w,items:K.map(P=>{const ne=is(P.conversation,pe);return{liveState:ne,tabKey:P.conversation.tabKey,sessionId:P.conversation.sessionId,displayPrimary:P.conversation.displayPrimary,serverBucket:ne.inboxBucket,computedBucket:P.inboxBucket,serverUnread:ne.unread,computedUnread:P.unread,lastSeenAt:ne.lastSeenAt,lastUpdated:ne.lastUpdated,activityAt:Pt(P.conversation)}})})},[de,pe,E,w]);const xe=a.useMemo(()=>de.filter(K=>K.requiresAction),[de]),oe=a.useMemo(()=>de.filter(K=>K.unread&&!K.requiresAction),[de]),J=a.useMemo(()=>de.filter(K=>!K.unread&&!K.requiresAction&&K.isWorking),[de]),ce=a.useMemo(()=>de.filter(K=>!K.unread&&!K.requiresAction&&!K.isWorking),[de]),Q=a.useMemo(()=>X?de.filter(K=>K.conversation.daemonId===X.id||K.conversation.ideId===X.id):[],[de,X]),he=a.useMemo(()=>{if(!X)return[];const K=X.recentLaunches||[];return K.length>0?K.map(P=>({id:P.id,label:P.title||P.providerName||P.providerType,kind:P.kind,providerType:P.providerType,providerSessionId:P.providerSessionId,subtitle:P.currentModel||P.workspace||void 0,workspace:P.workspace,currentModel:P.currentModel})):r.filter(P=>!P.daemonMode&&P.daemonId===X.id).map(P=>{var ie,Se,We,Ee,Ie;const ne=cs(P)?"cli":Ht(P)?"acp":"ide";return{id:`${ne}:${P.type}:${P.workspace||""}`,label:((ie=P.activeChat)==null?void 0:ie.title)||(cs(P)?P.cliName||P.type:Ht(P)&&P.cliName||P.type),kind:ne,providerType:P.type,providerSessionId:P.providerSessionId,subtitle:Ht(P)?P.currentModel||P.workspace||void 0:P.workspace||void 0,workspace:P.workspace||void 0,currentModel:P.currentModel,timestamp:((Ie=(Ee=(We=(Se=P.activeChat)==null?void 0:Se.messages)==null?void 0:We.at)==null?void 0:Ee.call(We,-1))==null?void 0:Ie.timestamp)||0}}).sort((P,ne)=>ne.timestamp-P.timestamp).map(({timestamp:P,...ne})=>ne)},[r,X]),I=(X==null?void 0:X.version)||(X==null?void 0:X.daemonVersion)||null,re=!!X&&!!I&&!0&&I!==Te,W=a.useMemo(()=>(X==null?void 0:X.availableProviders)||[],[X]),z=a.useMemo(()=>W.filter(K=>K.category==="cli").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[W]),te=a.useMemo(()=>W.filter(K=>K.category==="acp").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[W]),le=a.useMemo(()=>{const K=new Map;for(const P of de){const ne=P.conversation.daemonId||P.conversation.ideId,ie=K.get(ne);ie?ie.push(P):K.set(ne,[P])}return ae.map(P=>{const ne=K.get(P.id)||[],ie=[...ne].sort((Ve,st)=>st.timestamp-Ve.timestamp)[0]||null,Se=(ie==null?void 0:ie.conversation)||null,We=ur(P),Ee=ne.filter(Ve=>Ve.unread||Ve.requiresAction).length,Ie=P.status==="online"?"Connected":P.status||"Unknown",Fe=[P.platform||"machine",Ie].filter(Boolean);return{id:P.id,label:gt(P,{fallbackId:P.id}),subtitle:Fe.join(" · "),unread:Ee,total:ne.length,latestConversation:Se,latestTimestamp:(ie==null?void 0:ie.timestamp)||0,fallbackActivityAt:We,preview:Se?`${Se.displayPrimary} · ${kn(Se)}`:"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((P,ne)=>{const ie=P.latestTimestamp||P.fallbackActivityAt||0,Se=ne.latestTimestamp||ne.fallbackActivityAt||0;return Se!==ie?Se-ie:P.label.localeCompare(ne.label)})},[de,ae]),Ne=a.useCallback(K=>{k(K.tabKey),L("chat"),se(K)},[se]),Pe=a.useCallback(K=>{const P=t.find(ne=>ne.ideId===K.ideId&&ne.streamSource==="native");P&&(k(P.tabKey),L("chat"),se(P))},[t,se]),q=a.useCallback(()=>{se(ee),L("inbox")},[se,ee]),be=a.useCallback(K=>{O(K),_("idle"),M(""),Y(null),R("machines"),D("inbox"),L("machine")},[]),Ae=a.useCallback(K=>{var ne;const P=K.daemonId||((ne=K.ideId)==null?void 0:ne.split(":")[0])||K.ideId;P&&(O(P),_("idle"),M(""),Y(null),R("machines"),D("chat"),L("machine"))},[]),$e=a.useCallback(()=>{Y(null),L(H)},[H]),He=a.useCallback(async(K,P,ne)=>{var ie;try{_("loading"),M(`Launching ${P}…`);const Se={ideType:P,enableCdp:!0};(ie=ne==null?void 0:ne.workspacePath)!=null&&ie.trim()&&(Se.workspace=ne.workspacePath.trim()),await i(K,"launch_ide",Se),_("done"),M(`${P} launch requested`)}catch(Se){_("error"),M(Se instanceof Error?Se.message:"Launch IDE failed"),console.error("Launch IDE failed",Se)}},[i]),Oe=a.useCallback(async(K,P,ne)=>{if(P.trim())try{_("loading"),M(ne!=null&&ne.createIfMissing?"Creating folder…":"Saving workspace…");const ie=await i(K,"workspace_add",{path:P.trim(),createIfMissing:(ne==null?void 0:ne.createIfMissing)===!0});if(ie!=null&&ie.success){_("done"),M(ne!=null&&ne.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}_("error"),M((ie==null?void 0:ie.error)||"Could not save workspace")}catch(ie){_("error"),M(ie instanceof Error?ie.message:"Could not save workspace")}},[i]),Qe=a.useCallback(async K=>{var P,ne,ie,Se,We,Ee;try{_("loading"),M("Starting daemon upgrade…");const Ie=await i(K,"daemon_upgrade",{});if((P=Ie==null?void 0:Ie.result)!=null&&P.alreadyLatest){_("done"),M(`Already on v${((ne=Ie==null?void 0:Ie.result)==null?void 0:ne.version)||"latest"}.`);return}if((ie=Ie==null?void 0:Ie.result)!=null&&ie.upgraded||(Se=Ie==null?void 0:Ie.result)!=null&&Se.success){_("done"),M(`Upgrade to v${((We=Ie==null?void 0:Ie.result)==null?void 0:We.version)||"latest"} started. Daemon is restarting…`);return}_("error"),M(((Ee=Ie==null?void 0:Ie.result)==null?void 0:Ee.error)||"Upgrade failed")}catch(Ie){_("error"),M(Ie instanceof Error?Ie.message:"Upgrade failed")}},[i]),Z=a.useCallback(async(K,P,ne,ie)=>{var Ee;const Se=Date.now(),We={machineId:K,kind:P,providerType:ne,workspaceId:(ie==null?void 0:ie.workspaceId)||null,workspacePath:(ie==null?void 0:ie.workspacePath)||null,resumeSessionId:(ie==null?void 0:ie.resumeSessionId)||null,startedAt:Se};try{_("loading"),M(`Launching ${ne}…`),Y(We);const Ie={cliType:ne};(Ee=ie==null?void 0:ie.workspacePath)!=null&&Ee.trim()?Ie.dir=ie.workspacePath.trim():ie!=null&&ie.workspaceId&&(Ie.workspaceId=ie.workspaceId),ie!=null&&ie.resumeSessionId&&(Ie.resumeSessionId=ie.resumeSessionId);const Fe=await i(K,"launch_cli",Ie),Ve=(Fe==null?void 0:Fe.result)||Fe,st=(Ve==null?void 0:Ve.sessionId)||(Ve==null?void 0:Ve.id);if(Fe!=null&&Fe.success&&st){Y(null),_("done"),M(`${ne} launched`),ve(`/dashboard?activeTab=${encodeURIComponent(st)}`);return}if(Fe!=null&&Fe.success){_("loading"),M(`${ne} launch requested — waiting for session…`);return}Y(null),_("error"),M((Fe==null?void 0:Fe.error)||(Ve==null?void 0:Ve.error)||`Could not launch ${P.toUpperCase()} workspace`)}catch(Ie){if(bl(Ie)){_("loading"),M(`${ne} launch requested — waiting for session…`);return}Y(null),_("error"),M(Ie instanceof Error?Ie.message:`Could not launch ${P.toUpperCase()} workspace`)}},[ve,i]);a.useEffect(()=>{var ie;if(!G)return;const K=Nn(G.workspacePath),P=r.find(Se=>{var st,ut,pt,lt;if(!Se||Se.type==="adhdev-daemon"||Se.daemonMode||hl(Se.daemonId||Se.id)!==G.machineId||(Se.transport==="acp"?"acp":Se.transport==="pty"?"cli":null)!==G.kind||String(Se.agentType||Se.ideType||Se.type||"")!==G.providerType)return!1;const Fe=String(Se.providerSessionId||"");if(G.resumeSessionId&&Fe)return Fe===G.resumeSessionId;if(K){const xt=Nn(Se.workspace||Se.runtimeWorkspaceLabel);return xt?xt===K:!1}return Number(Se.lastUpdated||Se._lastUpdate||Se.timestamp||((lt=(pt=(ut=(st=Se.activeChat)==null?void 0:st.messages)==null?void 0:ut.at)==null?void 0:pt.call(ut,-1))==null?void 0:lt.timestamp)||0)>=G.startedAt-5e3});if(!P)return;const ne=typeof P.sessionId=="string"&&P.sessionId?P.sessionId:typeof P.instanceId=="string"&&P.instanceId?P.instanceId:(ie=t.find(Se=>Se.ideId===P.id))==null?void 0:ie.sessionId;ne&&(Y(null),_("done"),M(`${G.providerType} launched`),ve(`/dashboard?activeTab=${encodeURIComponent(ne)}`))},[t,r,ve,G]),a.useEffect(()=>{if(!G)return;const K=window.setTimeout(()=>{Y(P=>!P||P.startedAt!==G.startedAt?P:(_("error"),M("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(K)},[G]);const ge=a.useCallback(async K=>{if(X){if(K.kind==="ide"&&K.providerType){await He(X.id,K.providerType,{workspacePath:K.workspace||null});return}if((K.kind==="cli"||K.kind==="acp")&&K.providerType){await Z(X.id,K.kind,K.providerType,{workspacePath:K.workspace||null,resumeSessionId:K.providerSessionId||null});return}}},[He,Z,X]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:E==="chat"&&ee?e.jsx(cl,{selectedConversation:ee,isAcp:ze(ee),isStandalone:u,selectedIdeEntry:Me,actionLogs:n,userName:d,isSendingChat:me.isSendingChat,isFocusingAgent:me.isFocusingAgent,handleModalButton:me.handleModalButton,handleRelaunch:me.handleRelaunch,onBack:q,onOpenNativeConversation:Pe,onOpenMachine:Ae,onHideConversation:C,onOpenHistory:p,onOpenRemote:g,onStopCli:b,cliViewMode:U,onSetCliViewMode:async K=>{if(ee&&U!==K)try{await i(ee.daemonId||ee.ideId,"set_cli_view_mode",{targetSessionId:ee.sessionId,cliType:ee.ideType||ee.agentType,mode:K})}catch(P){gl(P)?console.warn("Skipped CLI view mode switch:",P instanceof Error?P.message:String(P)):console.error("Failed to switch CLI view mode:",P)}},handleSendChat:me.handleSendChat,handleFocusAgent:me.handleFocusAgent}):E==="machine"&&X?e.jsx(ml,{selectedMachineEntry:X,selectedMachineConversations:Q,selectedMachineRecentLaunches:he,cliProviders:z,acpProviders:te,selectedMachineNeedsUpgrade:re,appVersion:Te,machineAction:{state:F,message:A},isStandalone:u,section:$,showBottomNav:H==="inbox",onBack:$e,onSectionChange:K=>{R(K),L("inbox")},onOpenConversation:Ne,onOpenRecent:ge,onOpenMachineDetails:()=>ve(`/machines/${X.id}`),onMachineUpgrade:()=>Qe(X.id),onLaunchDetectedIde:(K,P)=>He(X.id,K,P),onAddWorkspace:(K,P)=>Oe(X.id,K,P),onBrowseDirectory:async K=>{const P=await i(X.id,"file_list_browse",{path:K});if(!(P!=null&&P.success))throw new Error((P==null?void 0:P.error)||"Could not browse folder");const ne=typeof(P==null?void 0:P.path)=="string"?P.path:K,ie=ne.includes("\\")?"\\":"/",Se=(Ee,Ie)=>/^[A-Za-z]:\\?$/.test(Ee)?`${Ee.replace(/\\?$/,"\\")}${Ie}`:Ee==="/"||Ee==="\\"?`${ie}${Ie}`:`${Ee.replace(/[\\/]+$/,"")}${ie}${Ie}`,We=Array.isArray(P==null?void 0:P.files)?P.files.filter(Ee=>(Ee==null?void 0:Ee.type)==="directory"&&typeof(Ee==null?void 0:Ee.name)=="string").map(Ee=>({name:Ee.name,path:Se(ne,Ee.name)})).sort((Ee,Ie)=>Ee.name.localeCompare(Ie.name)):[];return{path:ne,directories:We}},onLaunchWorkspaceProvider:(K,P,ne)=>Z(X.id,K,P,ne)}):e.jsx(dl,{section:$,attentionItems:xe,unreadItems:oe,workingItems:J,completedItems:ce,hiddenConversations:s,machineCards:le,getAvatarText:xl,onOpenConversation:Ne,onShowConversation:B,onShowAllHidden:j,onOpenMachine:be,onOpenSettings:()=>ve("/settings"),onSectionChange:R,wsStatus:v,isConnected:S,isStandalone:u})})}function rr(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function vl({conversations:t,numGroups:s,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[u,d]=a.useState(!1),[x,l]=a.useState(null),f=a.useCallback(()=>{c.current=0,d(!1),l(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const h=a.useCallback(g=>{g.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,d(!0))},[]),m=a.useCallback(g=>{if(!g.dataTransfer.types.includes("text/tab-key"))return;if(g.preventDefault(),!rr(s,r)){l("merge");return}const b=g.currentTarget.getBoundingClientRect(),v=g.clientX-b.left,S=b.width/3;v<S?l("split-left"):v>S*2?l("split-right"):l("merge")},[s,r]),y=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,d(!1),l(null))},[]),p=a.useCallback(g=>{c.current=0,d(!1);const b=g.dataTransfer.getData("text/tab-key"),v=b?t.some(B=>B.tabKey===b):!1,S=x;if(l(null),o(),!!b){if(g.preventDefault(),S==="split-left"&&rr(s,r)){r==null||r(b,"split-left");return}if(S==="split-right"&&rr(s,r)){r==null||r(b,"split-right");return}if(v){i(b);return}n==null||n(b)}},[t,x,s,r,n,i,o]);return{dragOver:u,dropAction:x,resetDragState:f,handleDragEnter:h,handleDragOver:m,handleDragLeave:y,handleDrop:p}}function wl(t,s){const r=new Set(s.map(o=>o.tabKey)),n=t.filter(o=>r.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...n,...i]}function jl({conversations:t,initialActiveTabId:s,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[u,d]=a.useState(r??[]),[x,l]=a.useState(null),f=a.useRef(null),h=a.useRef(null),m=a.useRef(n),y=a.useRef(i);a.useEffect(()=>{m.current=n},[n]),a.useEffect(()=>{y.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{d(w=>{const k=wl(w,t);return k.length===w.length&&k.every((E,L)=>E===w[L])?w:k})},[t]);const p=a.useMemo(()=>{const w=x??u;if(w.length===0)return t;const k=new Map(w.map((E,L)=>[E,L]));return[...t].sort((E,L)=>{const $=k.get(E.tabKey)??999,R=k.get(L.tabKey)??999;return $-R})},[t,x,u]);a.useEffect(()=>{var k,E;if(p.length===0){o!==null&&(c(null),(k=m.current)==null||k.call(m,null));return}if(o&&p.some(L=>L.tabKey===o))return;const w=p[0].tabKey;w!==o&&(c(w),(E=m.current)==null||E.call(m,w))},[p,o]);const g=a.useMemo(()=>p.find(w=>w.tabKey===o),[p,o]),b=a.useCallback(w=>{var k;c(w),(k=m.current)==null||k.call(m,w)},[]),v=a.useCallback((w,k,E)=>{d(L=>{var O;const $=L.filter(H=>H!==w),R=$.indexOf(k);if(R<0)return L;const T=E==="left"?R:R+1;return $.splice(T,0,w),(O=y.current)==null||O.call(y,$),$}),l(null)},[]),S=a.useCallback((w,k,E)=>{const $=(u.length>0?u:t.map(O=>O.tabKey)).filter(O=>O!==w),R=$.indexOf(k);if(R<0)return;const T=E==="left"?R:R+1;$.splice(T,0,w),f.current=$,l($)},[u,t]),B=a.useCallback(()=>{var k;const w=f.current;w&&(d(w),(k=y.current)==null||k.call(y,w))},[]),j=a.useCallback(()=>{f.current=null,l(null)},[]),C=a.useCallback(w=>{d(k=>{var L;const E=k.filter($=>$!==w);return E.push(w),(L=y.current)==null||L.call(y,E),E})},[]);return{activeTabId:o,activeConv:g,sortedConversations:p,previewOrderRef:f,draggingTabRef:h,selectTab:b,handleTabReorder:v,updatePreviewOrder:S,commitPreviewOrder:B,clearPreviewOrder:j,moveTabToEnd:C,setDraggingTabKey:w=>{h.current=w}}}function kl({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 $r({conversationsCount:t,isSplitMode:s,isStandalone:r,detectedIdes:n,handleLaunchIde:i}){return t===0&&!s&&n&&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:r?"Open an IDE directly, or choose a workspace first before launching CLI or ACP sessions.":"Install the ADHDev daemon and link your dashboard to start."}),!r&&e.jsx(Sa,{}),r&&n.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Detected IDEs"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:n.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(Gn,{size:14,className:"opacity-70"})," Open ",o.name]},o.type))})]}),!r&&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 Ia="adhdev-tab-shortcuts";function Nl(){try{return JSON.parse(localStorage.getItem(Ia)||"{}")}catch{return{}}}function Ta({enabled:t=!0,sortedTabKeys:s,onFocus:r,onSelectTab:n}){const i=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,c]=a.useState(()=>Nl()),[u,d]=a.useState(null),x=a.useCallback(f=>{const h=[];return f.metaKey&&h.push(i?"⌘":"Meta"),f.ctrlKey&&h.push("Ctrl"),f.altKey&&h.push(i?"⌥":"Alt"),f.shiftKey&&h.push(i?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(f.key)?null:(h.push(f.key.length===1?f.key.toUpperCase():f.key),h.join("+"))},[i]),l=a.useCallback(f=>{c(f);try{localStorage.setItem(Ia,JSON.stringify(f))}catch{}},[]);return a.useEffect(()=>{if(!t||!u)return;const f=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){d(null);return}const m=x(h);if(!m)return;const y={...o};for(const[p,g]of Object.entries(y))g===m&&delete y[p];y[u]=m,l(y),d(null)};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[t,u,o,l,x]),a.useEffect(()=>{if(!t)return;const f=h=>{if(!(!h.ctrlKey&&!h.metaKey&&!h.altKey)){for(const[m,y]of Object.entries(o))if(s.includes(m)&&x(h)===y){h.preventDefault(),r(),n(m);return}}};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,o,s,r,n,x]),{isMac:i,tabShortcuts:o,shortcutListening:u,setShortcutListening:d,saveShortcuts:l}}const Sl=a.memo(function({conv:s,isActive:r,isDraggedTab:n,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:u,onFocus:d,onSelectTab:x,onConversationActivated:l,onPreviewReorder:f,onReorderTab:h,onCommitPreviewOrder:m,onClearPreviewOrder:y,onDragStateReset:p,onDragTabKeyChange:g,onReceiveTab:b,onOpenContextMenu:v,longPressTimer:S,isGroupActive:B}){const j=Ws(s),C=j.isGenerating?"agent-tab-generating":j.isWaiting?"agent-tab-waiting":"",w=j.isReconnecting,k=a.useCallback(F=>{u.current=s.tabKey,g(s.tabKey),F.dataTransfer.setData("text/tab-key",s.tabKey),F.dataTransfer.effectAllowed="move"},[s.tabKey,u,g]),E=a.useCallback(()=>{u.current=null,g(null),m(),y(),p()},[u,g,m,y,p]),L=a.useCallback(F=>{const _=u.current;if(!(!_||_===s.tabKey)&&F.dataTransfer.types.includes("text/tab-key")){F.preventDefault(),F.stopPropagation();const A=F.currentTarget.getBoundingClientRect(),M=F.clientX<A.left+A.width/2?"left":"right";f(_,s.tabKey,M)}},[s.tabKey,u,f]),$=a.useCallback(F=>{F.preventDefault(),F.stopPropagation();const _=F.dataTransfer.getData("text/tab-key");if(_&&_!==s.tabKey){const A=F.currentTarget.getBoundingClientRect(),M=F.clientX<A.left+A.width/2?"left":"right";c.includes(_)?h(_,s.tabKey,M):b&&b(_)}y()},[s.tabKey,c,h,b,y]),R=a.useCallback(F=>{F.stopPropagation(),d(),x(s.tabKey),l(s)},[s,l,d,x]),T=a.useCallback(F=>{F.preventDefault(),v(F.clientX,F.clientY,s.tabKey)},[s.tabKey,v]),O=a.useCallback(F=>{const _=F.touches[0];S.current=setTimeout(()=>{v(_.clientX,_.clientY,s.tabKey)},600)},[s.tabKey,S,v]),H=a.useCallback(()=>{S.current&&clearTimeout(S.current)},[S]),D=["adhdev-dockview-tab",C,r&&"is-active",B&&"is-group-active",w&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:D,draggable:!0,onDragStart:k,onDragEnd:E,onDragOver:L,onDrop:$,onClick:R,onContextMenu:T,onTouchStart:O,onTouchEnd:H,onTouchMove:H,style:{cursor:"pointer",opacity:n?.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:j.isGenerating?e.jsx("div",{className:"tab-spinner"}):j.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):w?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):j.isConnecting?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("span",{className:"adhdev-dockview-tab-primary",title:s.displayPrimary,children:s.displayPrimary}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:w?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):j.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 Cl({conversations:t,activeTabId:s,groupIndex:r,unreadTabKeys:n,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:h,onDragTabKeyChange:m,onReceiveTab:y,onHideTab:p,isGroupActive:g,allowTabShortcuts:b=!0}){const[v,S]=a.useState(null),B=a.useRef(null),j=a.useRef(null),C=a.useMemo(()=>t.map(T=>T.tabKey),[t]);ps("PaneGroupTabBar",{groupIndex:r,activeTabId:s,tabCount:t.length,ctxMenuTab:(v==null?void 0:v.tabKey)||null});const{isMac:w,tabShortcuts:k,shortcutListening:E,setShortcutListening:L,saveShortcuts:$}=Ta({enabled:b,sortedTabKeys:t.map(T=>T.tabKey),onFocus:o,onSelectTab:c});a.useEffect(()=>{if(!v)return;const T=O=>{const H=document.querySelector("[data-pane-context-menu]");H&&H.contains(O.target)||S(null)};return window.addEventListener("mousedown",T,!0),()=>window.removeEventListener("mousedown",T,!0)},[v]),a.useEffect(()=>{const T=j.current;if(!T)return;const O=H=>{Math.abs(H.deltaY)>Math.abs(H.deltaX)&&(H.preventDefault(),T.scrollLeft+=H.deltaY)};return T.addEventListener("wheel",O,{passive:!1}),()=>T.removeEventListener("wheel",O)},[]);const R=a.useCallback((T,O,H)=>{S({x:T,y:O,tabKey:H})},[]);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(Sl,{conv:T,isActive:s===T.tabKey,isDraggedTab:i.current===T.tabKey,isTaskCompleteUnread:n.has(T.tabKey),shortcut:b?k[T.tabKey]:void 0,conversationKeys:C,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:h,onDragTabKeyChange:m,onReceiveTab:y,onOpenContextMenu:R,longPressTimer:B,isGroupActive:g},T.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),v&&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:v.x,top:v.y},children:[b&&e.jsxs(e.Fragment,{children:[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(),L(v.tabKey),S(null)},children:["⌨ ",k[v.tabKey]?`Change shortcut (${k[v.tabKey]})`:"Set shortcut"]}),k[v.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={...k};delete T[v.tabKey],$(T),S(null)},children:"✕ Remove shortcut"})]}),p&&e.jsxs(e.Fragment,{children:[b&&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:()=>{p(v.tabKey),S(null)},children:"🚫 Hide from Dashboard"})]})]}),b&&E&&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:()=>L(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. ",w?"⌘+1":"Ctrl+1",", ",w?"⌥+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 Il({conversations:t,ides:s,clearedTabs:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,userName:d,groupIndex:x,onFocus:l,isSplitMode:f,numGroups:h,onMoveTab:m,onReceiveTab:y,style:p,detectedIdes:g,handleLaunchIde:b,onActiveTabChange:v,initialActiveTabId:S,initialTabOrder:B,onTabOrderChange:j,onHideTab:C,isFocused:w,allowTabShortcuts:k=!0}){const{sendCommand:E}=It(),L=a.useRef(null),{activeTabId:$,activeConv:R,sortedConversations:T,draggingTabRef:O,selectTab:H,handleTabReorder:D,updatePreviewOrder:F,commitPreviewOrder:_,clearPreviewOrder:A,moveTabToEnd:M,setDraggingTabKey:G}=jl({conversations:t,initialActiveTabId:S,initialTabOrder:B,onActiveTabChange:v,onTabOrderChange:j}),Y=Us({sendDaemonCommand:i,activeConv:R,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),{dragOver:ue,dropAction:ve,resetDragState:Te,handleDragEnter:ee,handleDragOver:Me,handleDragLeave:U,handleDrop:ae}=vl({conversations:t,numGroups:h,onMoveTab:m,onReceiveTab:y,onOwnTabDrop:M,onClearPreviewOrder:A}),X=R&&!ze(R)&&qt(R)==="terminal",pe=a.useMemo(()=>R?s.find(oe=>oe.id===R.ideId):void 0,[s,R]),me=a.useMemo(()=>R?n.filter(oe=>oe.ideId===R.tabKey):[],[n,R]),se=a.useMemo(()=>ms(s),[s]),de=a.useMemo(()=>new Set(T.filter(oe=>co(oe,se,{isOpenConversation:oe.tabKey===$})).map(oe=>oe.tabKey)),[$,se,T]);ps("PaneGroup",{groupIndex:x,conversationCount:t.length,activeTabId:$,dragOver:ue});const xe=a.useCallback(oe=>{oe.streamSource==="agent-stream"&&oe.agentType&&E(oe.ideId,"focus_session",{agentType:oe.agentType,...oe.sessionId&&{targetSessionId:oe.sessionId}}).catch(()=>{})},[E]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:l,style:{...p,outline:ue?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Cl,{conversations:T,activeTabId:$,groupIndex:x,numGroups:h,unreadTabKeys:de,draggingTabRef:O,onFocus:l,onSelectTab:H,onConversationActivated:xe,onPreviewReorder:F,onReorderTab:D,onCommitPreviewOrder:_,onClearPreviewOrder:A,onDragStateReset:Te,onDragTabKeyChange:G,onMoveTab:m,onReceiveTab:y,onHideTab:C,isGroupActive:w??!1,allowTabShortcuts:k}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:ee,onDragOver:Me,onDragLeave:U,onDrop:ae,children:[ue&&e.jsx(kl,{dropAction:ve,canSplit:!!(h<4&&m)}),R?e.jsx(Lr,{activeConv:R,clearToken:r[R.tabKey]||0,isCliTerminal:!!X,ideEntry:pe,terminalRef:L,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,handleSendChat:Y.handleSendChat,isSendingChat:Y.isSendingChat,handleFocusAgent:Y.handleFocusAgent,isFocusingAgent:Y.isFocusingAgent,actionLogs:me,userName:d,isInputActive:!f||!!w}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx($r,{conversationsCount:t.length,isSplitMode:f,isStandalone:u,detectedIdes:g,handleLaunchIde:b})})]})]})}function Tl({containerRef:t,isSplitMode:s,numGroups:r,groupSizes:n,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,userName:h,focusedGroup:m,setFocusedGroup:y,moveTabToGroup:p,splitTabRelative:g,closeGroup:b,handleResizeStart:v,detectedIdes:S,handleLaunchIde:B,groupActiveTabIds:j,setGroupActiveTabIds:C,groupTabOrders:w,setGroupTabOrders:k,toggleHiddenTab:E,allowTabShortcuts:L=!0}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map(($,R)=>{const T=s&&n.length===r?`${n[R]}%`:void 0;return e.jsxs(et.Fragment,{children:[s&&R>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:O=>v(R-1,O),onDoubleClick:()=>b(R),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(Il,{style:s?{flexBasis:T??`${100/r}%`,flexGrow:T?0:1,flexShrink:T?0:1}:void 0,conversations:$,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,userName:h,groupIndex:R,isFocused:s&&m===R,onFocus:()=>y(R),isSplitMode:s,numGroups:r,onMoveTab:(O,H)=>{H==="left"&&R>0?p(O,R-1):H==="right"&&R<r-1?p(O,R+1):H==="split-left"&&r<4?g(O,R,"left"):H==="split-right"&&r<4&&g(O,R,"right")},onReceiveTab:O=>p(O,R),detectedIdes:R===0?S:void 0,handleLaunchIde:R===0?B:void 0,onActiveTabChange:O=>C(H=>(H[R]??null)===(O??null)?H:{...H,[R]:O}),initialActiveTabId:j[R],initialTabOrder:w[R],onTabOrderChange:O=>k(H=>{const D=H[R]||[];return D.length===O.length&&D.every((F,_)=>F===O[_])?H:{...H,[R]:O}}),onHideTab:E,allowTabShortcuts:L})]},R)})})}function Aa({doId:t,ideId:s,ideType:r,connState:n,viewMode:i,instanceId:o}){const[c,u]=a.useState(null),[d,x]=a.useState(null),l=a.useMemo(()=>{if(!s)return r;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):r},[s,r]);a.useEffect(()=>t?Ze.onScreenshot("ide-page",(m,y)=>{if(m!==t)return;const p=new FileReader;p.onload=()=>u(p.result),p.readAsDataURL(y)}):void 0,[t]),a.useEffect(()=>{n!=="connected"&&u(null)},[n]),a.useEffect(()=>{var m;return t?((m=Ze.onStatus)==null?void 0:m.call(Ze,(y,p)=>{y===t&&p!=null&&p.screenshotUsage&&x(p.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,l]),a.useEffect(()=>{const h=t?Ze.get(t):null;if(!(!h||n!=="connected"))return i!=="chat"&&l?h.startScreenshots(l):h.stopScreenshots(l),()=>{h.stopScreenshots(l)}},[i,n,l,t]);const f=a.useCallback(async(h,m)=>{const y=t?Ze.get(t):null;return!y||n!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):y.sendInput(h,m,o||l)},[t,n,o,l]);return{connScreenshot:c,screenshotUsage:d,handleRemoteAction:f}}const _a=a.createContext(null);function Hs(){const t=a.useContext(_a);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Is(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Al(t){return`remote:${t}`}function ds(t){return t.startsWith("remote:")}function us(t,s){return t.find(r=>r.ideId===s&&r.streamSource==="native")??t.find(r=>r.ideId===s)??null}function _l(t){const[,s]=a.useState(0);a.useEffect(()=>{const r=()=>s(i=>i+1),n=[t.api.onDidActiveGroupChange(r),t.api.onDidTitleChange(r),t.api.onDidGroupChange(r),t.containerApi.onDidActivePanelChange(r)];return()=>{for(const i of n)i.dispose()}},[t.api,t.containerApi])}function Ml(t,s,r){var u;const n=[s];let i;for(const d of n){let x;for(const l of d){const f=t.addPanel({id:l.tabKey,component:"conversation",title:Is(l),params:{kind:"conversation",tabKey:l.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});x||(x=f.id)}i=x??i}const o=r??((u=s[0])==null?void 0:u.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Sn(t,s){const r=new Set(s.map(n=>n.tabKey));for(const n of[...t.panels])ds(n.id)||r.has(n.id)||t.removePanel(n);for(const n of s){const i=t.getPanel(n.tabKey);if(i){i.update({params:{tabKey:n.tabKey}}),i.title!==Is(n)&&i.api.setTitle(Is(n));continue}t.addPanel({id:n.tabKey,component:"conversation",title:Is(n),params:{kind:"conversation",tabKey:n.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 Cn(t,s,r){var d,x;const n=r?Al(r):null;for(const l of[...t.panels])ds(l.id)&&(!n||l.id!==n)&&t.removePanel(l);if(!r||!n)return;const i=us(s,r);if(!i&&t.totalPanels===0)return;const o=t.getPanel(n),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const u=(i==null?void 0:i.tabKey)??((d=t.activePanel)==null?void 0:d.id)??((x=t.panels.find(l=>!ds(l.id)))==null?void 0:x.id);t.addPanel({id:n,component:"remote",title:c,params:{kind:"remote",ideId:r},...u?{position:{referencePanel:u,direction:"right"},inactive:!0}:{}})}function Pl({params:t,api:s}){var f;const r=Hs(),n=a.useRef(null),[i,o]=a.useState(s.isActive),c=r.conversationsByTabKey.get(t.tabKey),u=Us({sendDaemonCommand:r.sendDaemonCommand,activeConv:c,setLocalUserMessages:r.setLocalUserMessages,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});a.useEffect(()=>{o(s.isActive);const h=[s.onDidActiveChange(m=>o(m.isActive)),s.onDidActiveGroupChange(m=>{if(!s.isActive&&!m.isActive){o(!1);return}o(s.isActive)})];return()=>{for(const m of h)m.dispose()}},[s]);const d=a.useMemo(()=>c?r.ides.find(h=>h.id===c.ideId):void 0,[r.ides,c]),x=a.useMemo(()=>c?r.actionLogs.filter(h=>h.ideId===c.tabKey):[],[r.actionLogs,c]);if(!c)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx($r,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,detectedIdes:r.detectedIdes,handleLaunchIde:r.handleLaunchIde})});const l=!ze(c)&&qt(c)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Lr,{activeConv:c,clearToken:r.clearedTabs[c.tabKey]||0,isCliTerminal:l,ideEntry:d,terminalRef:n,handleModalButton:u.handleModalButton,handleRelaunch:u.handleRelaunch,handleSendChat:u.handleSendChat,isSendingChat:u.isSendingChat,handleFocusAgent:u.handleFocusAgent,isFocusingAgent:u.isFocusingAgent,actionLogs:x,userName:r.userName,scrollToBottomRequestNonce:((f=r.scrollToBottomRequest)==null?void 0:f.tabKey)===c.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:i})})}function Ll({params:t}){var d;const s=Hs(),r=a.useMemo(()=>us([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),n=a.useMemo(()=>s.ides.find(x=>x.id===t.ideId),[s.ides,t.ideId]),i=(r==null?void 0:r.daemonId)||((d=r==null?void 0:r.ideId)==null?void 0:d.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:u}=Aa({doId:i,ideId:t.ideId,ideType:(r==null?void 0:r.ideType)||(n==null?void 0:n.type),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote",instanceId:n==null?void 0:n.instanceId});return r?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(Yn,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:r.transport,onAction:u})}):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 Rl(){const t=Hs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx($r,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function El(t){var m,y;_l(t);const s=Hs(),r=a.useCallback(p=>{"button"in p&&p.button!==0||t.api.setActive()},[t.api]);if(t.params.kind==="remote"){const p=us([...s.conversationsByTabKey.values()],t.params.ideId),g=((m=t.api.group.activePanel)==null?void 0:m.id)===t.api.id,b=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${g?" is-active":""}${b?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",onMouseDown:r,onTouchStart:r,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 i=((y=t.api.group.activePanel)==null?void 0:y.id)===t.api.id,o=t.api.isGroupActive,c=os(n,s.liveSessionInboxState,{isOpenConversation:i}),u=c.isReconnecting,d=c.isConnecting,x=c.isGenerating,l=c.isWaiting,f=c.unread,h=s.tabShortcuts[n.tabKey];return e.jsxs("div",{className:`adhdev-dockview-tab${i?" is-active":""}${o?" is-group-active":""}${u?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:p=>{p.preventDefault(),r(p),s.openTabContextMenu({x:p.clientX,y:p.clientY,tabKey:n.tabKey})},children:[f&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?e.jsx("div",{className:"tab-spinner"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):u?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:u?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]})]})]})})]}),h&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:h,children:h})]})}function $l({visibleConversations:t,clearedTabs:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,initialDataLoaded:d,userName:x,detectedIdes:l,handleLaunchIde:f,toggleHiddenTab:h,registerActionHandlers:m,onActiveTabChange:y,requestedActiveTabKey:p,requestedRemoteIdeId:g,onRequestedActiveTabConsumed:b,scrollToBottomRequest:v}){const{theme:S}=pa(),{sendCommand:B}=It(),j=a.useRef(null),C=a.useRef(null),w=a.useRef(!1),k=a.useRef(!1),E=a.useRef(!1),L=a.useRef(null),[$,R]=a.useState(null),[T,O]=a.useState(!1),[H,D]=a.useState(!1),F=a.useRef(null),_=a.useMemo(()=>wa(typeof window<"u"?window.innerWidth:1280),[]),A=a.useMemo(()=>new Map(t.map(W=>[W.tabKey,W])),[t]),M=a.useMemo(()=>ms(r),[r]),G=a.useCallback(()=>{var W;(W=j.current)==null||W.focus()},[]),Y=a.useCallback(W=>{const z=j.current;if(!z)return;const te=z.getPanel(W);te&&(te.group.model.openPanel(te),te.api.setActive())},[]),ue=a.useCallback(W=>{const z=j.current,te=z==null?void 0:z.activePanel,le=(z==null?void 0:z.activeGroup)||(te==null?void 0:te.group);if(!z||!te||!le)return;const Ne=le.panels||[];if(Ne.length<=1)return;const Pe=Ne.findIndex(Ae=>Ae.id===te.id);if(Pe<0)return;const q=(Pe+W+Ne.length)%Ne.length,be=Ne[q];be&&(be.group.model.openPanel(be),be.api.setActive())},[]),ve=a.useCallback(W=>{var Qe;const z=j.current,te=(z==null?void 0:z.activeGroup)||((Qe=z==null?void 0:z.activePanel)==null?void 0:Qe.group);if(!z||!te)return;const le=z.groups||[],Ne=le.find(Z=>Z.id===te.id);if(!Ne)return;const Pe=Ne.element.getBoundingClientRect(),q=Pe.left+Pe.width/2,be=Pe.top+Pe.height/2,Ae=(Z,ge,K,P)=>Math.max(0,Math.min(ge,P)-Math.max(Z,K)),$e=Z=>{const ge=Z.element.getBoundingClientRect(),K=ge.left+ge.width/2,P=ge.top+ge.height/2;let ne=0,ie=0,Se=0,We=!1;if(W==="left"?(We=K<q,ne=Math.max(0,Pe.left-ge.right),ie=Math.abs(P-be),Se=Ae(Pe.top,Pe.bottom,ge.top,ge.bottom)):W==="right"?(We=K>q,ne=Math.max(0,ge.left-Pe.right),ie=Math.abs(P-be),Se=Ae(Pe.top,Pe.bottom,ge.top,ge.bottom)):W==="above"?(We=P<be,ne=Math.max(0,Pe.top-ge.bottom),ie=Math.abs(K-q),Se=Ae(Pe.left,Pe.right,ge.left,ge.right)):(We=P>be,ne=Math.max(0,ge.top-Pe.bottom),ie=Math.abs(K-q),Se=Ae(Pe.left,Pe.right,ge.left,ge.right)),!We)return Number.POSITIVE_INFINITY;const Ee=Se>0?0:120;return ne*3+ie+Ee};let He=null,Oe=Number.POSITIVE_INFINITY;for(const Z of le){if(Z.id===Ne.id)continue;const ge=$e(Z);Number.isFinite(ge)&&(ge>=Oe||(Oe=ge,He=Z))}return He||void 0},[]),Te=a.useCallback(W=>{const z=ve(W);if(!z)return;const te=z.activePanel||z.panels[0];te&&(z.model.openPanel(te),te.api.setActive())},[ve]),ee=a.useCallback((W,z)=>{const te=j.current,le=te==null?void 0:te.activePanel,Ne=(te==null?void 0:te.activeGroup)||(le==null?void 0:le.group);if(!te||!le||!Ne)return;let Pe=ve(W);!Pe&&(z!=null&&z.createGroupIfMissing)&&(Pe=te.addGroup({referenceGroup:Ne,direction:W})),Pe&&(le.api.moveTo({group:Pe,position:"center"}),le.group.model.openPanel(le),le.api.setActive())},[ve]),{isMac:Me,tabShortcuts:U,shortcutListening:ae,setShortcutListening:X,saveShortcuts:pe}=Ta({sortedTabKeys:t.map(W=>W.tabKey),onFocus:G,onSelectTab:Y}),me=a.useCallback(()=>{var te;const W=j.current;if(!W)return;const z=W.activePanel;if(z){if(ds(z.id)){const le=((te=z.params)==null?void 0:te.ideId)||z.id.slice(7),Ne=us(t,le);Ne!=null&&Ne.tabKey&&X(Ne.tabKey);return}A.has(z.id)&&X(z.id)}},[A,X,t]);a.useEffect(()=>(m==null||m({setShortcutForActiveTab:me,activatePreviousTabInGroup:()=>ue(-1),activateNextTabInGroup:()=>ue(1),splitActiveTabRight:()=>ee("right",{createGroupIfMissing:!0}),splitActiveTabDown:()=>ee("below",{createGroupIfMissing:!0}),focusLeftPane:()=>Te("left"),focusRightPane:()=>Te("right"),focusUpPane:()=>Te("above"),focusDownPane:()=>Te("below"),moveActiveTabToLeftPane:()=>ee("left"),moveActiveTabToRightPane:()=>ee("right"),moveActiveTabToUpPane:()=>ee("above"),moveActiveTabToDownPane:()=>ee("below")}),()=>m==null?void 0:m(null)),[ue,Te,ee,m,me]),a.useEffect(()=>{if(!$)return;const W=z=>{const te=document.querySelector("[data-dockview-tab-context-menu]");te&&te.contains(z.target)||R(null)};return window.addEventListener("mousedown",W,!0),()=>window.removeEventListener("mousedown",W,!0)},[$]);const se=a.useMemo(()=>({actionLogs:n,clearedTabs:s,conversationsByTabKey:A,detectedIdes:l,handleLaunchIde:f,ides:r,isStandalone:u,liveSessionInboxState:M,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:h,userName:x,scrollToBottomRequest:v,tabShortcuts:U,openTabContextMenu:({x:W,y:z,tabKey:te})=>R({x:W,y:z,tabKey:te})}),[n,s,A,l,f,r,u,M,i,c,o,h,x,v,U]),de=a.useCallback(W=>{if(!W)return!1;const z=j.current;if(!z)return!1;const te=z.getPanel(W);return te?(te.group.model.openPanel(te),te.api.setActive(),b==null||b(),!0):!1},[b]),xe=a.useCallback(()=>{if(E.current)return!1;const W=de(L.current);return W&&(E.current=!0),W},[de]),oe=a.useCallback(()=>{var z;const W=j.current;W&&Jc(_,{activeTabId:((z=W.activePanel)==null?void 0:z.id)??null,layout:W.toJSON()})},[_]),J=a.useCallback(()=>{const W=C.current;if(!W)return;const z=W.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const te of z)te.setAttribute("data-adhdev-force-hidden","true")},[]),ce=a.useCallback(()=>{const W=C.current;if(!W)return;const z=W.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const te of z)te.removeAttribute("data-adhdev-force-hidden")},[]),Q=a.useCallback(()=>{const W=C.current;if(!W)return;const z=W.querySelectorAll(".dv-drop-target-container");for(const Ne of z)Ne.remove();const te=W.querySelectorAll(".dv-drop-target-dropzone");for(const Ne of te)Ne.remove();const le=W.querySelectorAll(".dv-drop-target");for(const Ne of le)Ne.classList.remove("dv-drop-target")},[]),he=a.useCallback(()=>{O(!1),D(!1),ce(),J(),Q(),!(typeof window>"u")&&(F.current!=null&&window.clearTimeout(F.current),window.requestAnimationFrame(()=>{J(),Q()}),F.current=window.setTimeout(()=>{J(),Q(),F.current=null},80))},[ce,J,Q]),I=a.useCallback(W=>{var te;j.current=W.api;const z=Xc(_);L.current=(z==null?void 0:z.activeTabId)??null,z!=null&&z.layout&&W.api.fromJSON(z.layout,{reuseExistingPanels:!1}),k.current=!!(z!=null&&z.layout)&&!d&&t.length===0,k.current||(Sn(W.api,t),Cn(W.api,t,g)),W.api.totalPanels===0&&t.length>0?Ml(W.api,t,p):!k.current&&!de(p)&&xe(),w.current=!0,W.api.onDidActivePanelChange(le=>{var Pe;if(L.current=(le==null?void 0:le.id)??null,E.current=!0,le&&ds(le.id)){const q=((Pe=le.params)==null?void 0:Pe.ideId)||le.id.slice(7),be=us(t,q);y((be==null?void 0:be.tabKey)??null),oe();return}if(y((le==null?void 0:le.id)??null),oe(),!le)return;const Ne=A.get(le.id);(Ne==null?void 0:Ne.streamSource)==="agent-stream"&&Ne.agentType&&B(Ne.ideId,"focus_session",{agentType:Ne.agentType,...Ne.sessionId&&{targetSessionId:Ne.sessionId}}).catch(()=>{})}),W.api.onDidLayoutChange(()=>{oe()}),W.api.onWillDragPanel(()=>{O(!0),D(!1),J()}),W.api.onWillDragGroup(()=>{O(!0),D(!1),J()}),W.api.onWillShowOverlay(()=>{ce(),D(!0)}),W.api.onDidMovePanel(he),W.api.onDidDrop(he),y(((te=W.api.activePanel)==null?void 0:te.id)??null)},[de,he,ce,A,d,_,J,Q,y,oe,p,g,B,t]);a.useEffect(()=>{const W=j.current;if(!W||!w.current||k.current&&!d||(k.current&&(k.current=!1),Sn(W,t),Cn(W,t,g),p&&de(p)))return;!W.activePanel&&W.panels[0]&&(W.panels[0].group.model.openPanel(W.panels[0]),W.panels[0].api.setActive()),!!(W.activePanel&&W.getPanel(W.activePanel.id))||xe()},[de,xe,d,p,g,t]),a.useEffect(()=>{w.current&&de(p)},[de,p]),a.useEffect(()=>{if(!T||typeof window>"u")return;const W=()=>he();return window.addEventListener("pointerup",W),window.addEventListener("mouseup",W),window.addEventListener("dragend",W),()=>{window.removeEventListener("pointerup",W),window.removeEventListener("mouseup",W),window.removeEventListener("dragend",W)}},[he,T]),a.useEffect(()=>()=>{typeof window>"u"||F.current!=null&&window.clearTimeout(F.current)},[]),a.useEffect(()=>{const W=z=>{const te=z.target;if(!te)return;const le=te.querySelector("[data-tab-key]")||te.closest("[data-tab-key]");if(le){const Ne=le.getAttribute("data-tab-key");Ne&&z.dataTransfer&&z.dataTransfer.setData("text/tab-key",Ne)}};return window.addEventListener("dragstart",W),()=>window.removeEventListener("dragstart",W)},[]);const re=S==="light"?hi:bi;return e.jsxs(_a.Provider,{value:se,children:[e.jsx("div",{ref:C,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(xi,{className:`h-full min-h-0 min-w-0 adhdev-dockview${T?" is-dragging-dockview":""}${H?" is-showing-dockview-overlay":""}`,components:{conversation:Pl,remote:Ll},defaultTabComponent:El,watermarkComponent:Rl,onReady:I,singleTabMode:"default",tabAnimation:"smooth",theme:re})}),$&&e.jsxs("div",{"data-dockview-tab-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:$.x,top:$.y},children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors",onClick:W=>{W.stopPropagation(),X($.tabKey),R(null)},children:["⌨ ",U[$.tabKey]?`Change shortcut (${U[$.tabKey]})`:"Set shortcut"]}),U[$.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 W={...U};delete W[$.tabKey],pe(W),R(null)},children:"✕ Remove shortcut"})]}),ae&&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:()=>X(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:W=>W.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. ",Me?"⌘+1":"Ctrl+1",", ",Me?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const Ma="adhdev-recent-launch-args-v1",Dl=8;function Bl(t){return String(t||"").trim().replace(/\s+/g," ")}function Pa(t,s){return`${t.trim()}::${s.trim()}`}function La(){if(typeof window>"u")return{byKey:{}};try{const t=JSON.parse(window.localStorage.getItem(Ma)||"{}");return{byKey:typeof t.byKey=="object"&&t.byKey?t.byKey:{}}}catch{return{byKey:{}}}}function Kl(t){if(!(typeof window>"u"))try{window.localStorage.setItem(Ma,JSON.stringify(t))}catch{}}function Ra(t,s){var o;const r=String(t||"").trim(),n=String(s||"").trim();return!r||!n?[]:((o=La().byKey[Pa(r,n)])==null?void 0:o.items)||[]}function Ea(t,s,r){var l;const n=String(t||"").trim(),i=String(s||"").trim(),o=Bl(r);if(!n||!i||!o)return;const c=La(),u=Pa(n,i),d=((l=c.byKey[u])==null?void 0:l.items)||[],x=[o,...d.filter(f=>f!==o)].slice(0,Dl);c.byKey[u]={items:x},Kl(c)}function nr(t){var n;if(!t)return null;const s=(((n=t.detectedIdes)==null?void 0:n.length)||0)>0,r=t.availableProviders||[];return s?"ide":r.some(i=>i.category==="cli")?"cli":r.some(i=>i.category==="acp")?"acp":null}function In(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Wl({machines:t,onClose:s,onBrowseDirectory:r,onSaveWorkspace:n,onLaunchIde:i,onLaunchProvider:o,onListSavedSessions:c}){var Ne,Pe;const u=a.useMemo(()=>[...t].sort(Sr),[t]),[d,x]=a.useState(((Ne=u[0])==null?void 0:Ne.id)||""),l=a.useMemo(()=>u.find(q=>q.id===d)||u[0],[d,u]),f=a.useMemo(()=>(l==null?void 0:l.workspaces)||[],[l]),h=(l==null?void 0:l.defaultWorkspaceId)||null,[m,y]=a.useState(""),[p,g]=a.useState(""),[b,v]=a.useState(nr(u[0])),[S,B]=a.useState(""),[j,C]=a.useState(""),[w,k]=a.useState([]),[E,L]=a.useState(""),[$,R]=a.useState([]),[T,O]=a.useState(!1),[H,D]=a.useState(""),[F,_]=a.useState(!1),[A,M]=a.useState(""),[G,Y]=a.useState(!1),[ue,ve]=a.useState(""),[Te,ee]=a.useState([]),[Me,U]=a.useState(!1),[ae,X]=a.useState(""),[pe,me]=a.useState(!1),se=a.useRef(null),de=a.useRef(0);a.useEffect(()=>{var q;!d&&((q=u[0])!=null&&q.id)&&x(u[0].id)},[d,u]);const xe=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="cli"),[l]),oe=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="acp"),[l]),J=a.useMemo(()=>((l==null?void 0:l.detectedIdes)||[]).map(q=>({id:q.type,label:q.name||q.type,meta:q.running?"Detected locally":"Available to open"})),[l]),ce=a.useMemo(()=>b==="cli"?xe.map(q=>({id:q.type,label:q.displayName||q.type,meta:"CLI provider"})):b==="acp"?oe.map(q=>({id:q.type,label:q.displayName||q.type,meta:"ACP provider"})):J,[oe,b,xe,J]);a.useEffect(()=>{var be;if(!l)return;if(se.current!==l.id){se.current=l.id,y(h||((be=f[0])==null?void 0:be.id)||"__home__"),g(""),v(nr(l)),B(""),C(""),L(""),R([]),D(""),M("");return}y(Ae=>{var $e;return Ae==="__custom__"||Ae==="__home__"||f.some(He=>He.id===Ae)?Ae:h||(($e=f[0])==null?void 0:$e.id)||"__home__"}),v(Ae=>Ae==="ide"&&J.length>0||Ae==="cli"&&xe.length>0||Ae==="acp"&&oe.length>0?Ae:nr(l))},[oe.length,xe.length,h,J.length,l,f]),a.useEffect(()=>{var q;b&&(ce.some(be=>be.id===S)||B(((q=ce[0])==null?void 0:q.id)||""))},[b,ce,S]);const Q=a.useCallback(async(q,be)=>{const Ae=de.current+1;return de.current=Ae,O(!0),D(""),c(q,be).then($e=>{de.current===Ae&&R($e)}).catch($e=>{de.current===Ae&&(R([]),D($e instanceof Error?$e.message:"Could not load saved sessions"))}).finally(()=>{de.current===Ae&&O(!1)})},[c]),he=a.useCallback((q,be)=>{k(Ra(q,be))},[]);a.useEffect(()=>{if(L(""),!l||!S||b==="ide"?k([]):he(l.id,S),b!=="cli"){R([]),D(""),O(!1);return}if(!l||!S){R([]),D(""),O(!1);return}Q(l.id,S)},[b,he,Q,l,S]),a.useEffect(()=>{if(!E)return;const q=$.find(be=>be.providerSessionId===E);q!=null&&q.canResume||L("")},[$,E]);const I=m==="__custom__"?p.trim():m==="__home__"?"":((Pe=f.find(q=>q.id===m))==null?void 0:Pe.path)||"",re=a.useCallback(q=>{const be=String(q.workspace||"").trim();if(!be)return;const Ae=f.find($e=>In($e.path)===In(be));if(Ae){y(Ae.id),g("");return}y("__custom__"),g(be)},[f]),W=a.useCallback(()=>{var be,Ae;if(!l)return;y("__custom__"),Y(!0),X("");const q=zs(l.platform,[p.trim(),I,(be=f.find($e=>$e.id===h))==null?void 0:be.path,(Ae=f[0])==null?void 0:Ae.path]);U(!0),r(l.id,q).then($e=>{ve($e.path),g($e.path),ee($e.directories)}).catch($e=>{X($e instanceof Error?$e.message:"Could not load folder")}).finally(()=>U(!1))},[p,h,r,I,l,f]),z=a.useCallback(q=>{l&&(U(!0),X(""),r(l.id,q).then(be=>{ve(be.path),g(be.path),ee(be.directories)}).catch(be=>{X(be instanceof Error?be.message:"Could not load folder")}).finally(()=>U(!1)))},[r,l]),te=a.useCallback(async()=>{if(!l||!I)return;me(!0),M("");const q=await n(l.id,I);if(me(!1),!q.ok){M(q.error||"Could not save workspace");return}M("Workspace saved. It will appear in the list once the machine state refreshes.")},[n,I,l]),le=a.useCallback(async()=>{if(!l||!b||!S)return;_(!0),M("");const q=j.trim()?j.trim().split(/\s+/).filter(Boolean):[],be=b==="ide"?await i(l.id,S,{workspacePath:I||null}):await o(l.id,b,S,{workspaceId:m!=="__home__"&&m!=="__custom__"?m:null,workspacePath:m==="__custom__"&&I||null,resumeSessionId:b==="cli"&&E?E:null,cliArgs:q});if(_(!1),!be.ok){M(be.error||"Could not start session");return}b!=="ide"&&j.trim()&&(Ea(l.id,S,j),he(l.id,S)),s()},[b,j,he,s,i,o,I,l,E,S,m]);return l?e.jsxs(e.Fragment,{children:[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":"dashboard-new-title",children:e.jsxs("div",{className:"w-full max-w-3xl max-h-[min(88vh,860px)] 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:"dashboard-new-title",className:"m-0 text-base font-semibold text-text-primary",children:"New session"}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:"Pick a machine, choose a workspace, then start IDE, CLI, or ACP without leaving the dashboard."})]}),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:s,"aria-label":"Close new session dialog",children:e.jsx(Dt,{size:16})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Machine"}),e.jsx("select",{value:l.id,onChange:q=>x(q.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:F,children:u.map(q=>e.jsx("option",{value:q.id,children:gt(q,{fallbackId:q.id})},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Workspace"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Saved workspace is preferred. Home and custom folders are still available."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:W,disabled:F,children:"Browse…"})]}),e.jsxs("select",{value:m,onChange:q=>{const be=q.target.value;y(be),be==="__custom__"?W():M("")},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:F,children:[e.jsx("option",{value:"__home__",children:"Home directory"}),f.map(q=>e.jsxs("option",{value:q.id,children:[q.id===h?"⭐ ":"",Os(q.path,q.label)||q.path]},q.id)),e.jsx("option",{value:"__custom__",children:"Custom folder…"})]}),e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:m==="__home__"?"Launch without a workspace.":I||"Select a workspace folder."}),m==="__custom__"&&I&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:W,disabled:F,children:[e.jsx(Gt,{size:14}),"Select folder"]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:te,disabled:F||pe,children:pe?"Saving…":"Save workspace"})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:"Category"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"ide",label:"IDE",enabled:J.length>0},{id:"cli",label:"CLI",enabled:xe.length>0},{id:"acp",label:"ACP",enabled:oe.length>0}].map(q=>e.jsx("button",{type:"button",className:`btn btn-sm ${b===q.id?"btn-primary":"btn-secondary"}`,onClick:()=>v(q.id),disabled:!q.enabled||F,children:q.label},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:b==="ide"?"Choose IDE":b==="cli"?"Choose CLI provider":"Choose ACP provider"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[ce.map(q=>e.jsxs("button",{type:"button",className:`w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${S===q.id?"border-accent bg-accent/10":"border-border-subtle bg-bg-secondary/40 hover:bg-bg-secondary/70"}`,onClick:()=>B(q.id),disabled:F,children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:q.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:q.meta})]},q.id)),ce.length===0&&e.jsx("div",{className:"text-sm text-text-muted",children:"Nothing available for this category on the selected machine."})]})]}),b!=="ide"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Startup arguments"}),e.jsx("input",{type:"text",value:j,onChange:q=>C(q.target.value),placeholder:"Optional flags...",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:F}),w.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:w.map(q=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>C(q),disabled:F,title:q,children:q},q))})]}),b==="cli"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume from history"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Pick a saved CLI session, then launch with optional args."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:F||!l||!S||T,onClick:()=>{!l||!S||Q(l.id,S)},children:T?"Loading…":"Refresh"})]}),e.jsx("div",{className:"mt-2",children:e.jsxs("select",{value:E,onChange:q=>{const be=q.target.value;if(L(be),!be)return;const Ae=$.find($e=>$e.providerSessionId===be);!Ae||!Ae.canResume||re(Ae)},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:F||T,children:[e.jsx("option",{value:"",children:"Start a new CLI session"}),$.map(q=>e.jsxs("option",{value:q.providerSessionId,disabled:!q.canResume,children:[q.title||q.providerSessionId,q.canResume?"":" (workspace missing)"]},q.providerSessionId))]})}),E&&(()=>{const q=$.find(be=>be.providerSessionId===E);return q?e.jsxs("div",{className:"mt-2 text-[11px] text-text-muted leading-relaxed",children:[e.jsx("div",{className:"font-mono break-all",children:q.providerSessionId}),e.jsxs("div",{className:"mt-1",children:[q.workspace||"Workspace unknown",q.currentModel?` · ${q.currentModel}`:""]})]}):null})(),H&&e.jsx("div",{className:"mt-2 text-[11px] text-status-error",children:H}),!T&&!H&&$.length===0&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"No saved sessions found for this provider yet."})]}),A&&e.jsx("div",{className:`rounded-xl border px-4 py-3 text-sm ${A.includes("saved")||A.includes("requested")?"border-accent/25 bg-accent/10 text-text-primary":"border-status-error/25 bg-status-error/10 text-status-error"}`,children:A})]}),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:s,disabled:F,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:le,disabled:F||!b||!S||m==="__custom__"&&!I,children:[e.jsx(Nr,{size:14}),F?"Starting…":"Start session"]})]})]})}),G&&e.jsx(Fs,{title:"Select workspace",description:"Pick the folder that should be used for this new session.",currentPath:ue,directories:Te,busy:Me,error:ae,onClose:()=>Y(!1),onNavigate:z,onConfirm:q=>{g(q),ve(q),y("__custom__"),Y(!1)}})]}):null}const $a="adhdev-dashboard-action-shortcuts",Ol=1200,Ul={toggleHiddenTabs:"G H",setActiveTabShortcut:"G S",selectPreviousGroupTab:"G K",selectNextGroupTab:"G J",splitActiveTabRight:"⌘+⌥+\\",focusLeftPane:"⌘+⌥+←",focusRightPane:"⌘+⌥+→",moveActiveTabToLeftPane:"⌘+⌥+⇧+←",moveActiveTabToRightPane:"⌘+⌥+⇧+→",triggerPrimaryApprovalAction:"⌥+A",triggerSecondaryApprovalAction:"⌥+D",toggleCliView:"T"};function zl(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function Je(t,s){switch(t){case"openShortcutHelp":return"?";case"hideCurrentTab":return s?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return s?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return s?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return s?"⌥+R":"Ctrl+Alt+R";case"splitActiveTabRight":return s?"⌘+⌥+=":"Ctrl+Alt+\\";case"splitActiveTabDown":return s?"⌘+⌥+-":"Ctrl+Alt+-";case"focusLeftPane":return s?"⌘+⌥+[":"Ctrl+Alt+←";case"focusRightPane":return s?"⌘+⌥+]":"Ctrl+Alt+→";case"focusUpPane":return s?"⌘+⌥+U":"Ctrl+Alt+↑";case"focusDownPane":return s?"⌘+⌥+J":"Ctrl+Alt+↓";case"moveActiveTabToLeftPane":return s?"⌘+⌥+,":"Ctrl+Alt+Shift+←";case"moveActiveTabToRightPane":return s?"⌘+⌥+.":"Ctrl+Alt+Shift+→";case"moveActiveTabToUpPane":return s?"⌘+⌥+I":"Ctrl+Alt+Shift+↑";case"moveActiveTabToDownPane":return s?"⌘+⌥+K":"Ctrl+Alt+Shift+↓";case"triggerPrimaryApprovalAction":return s?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return s?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return s?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return s?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return s?"⌥+[":"Ctrl+Alt+[";case"selectNextGroupTab":return s?"⌥+]":"Ctrl+Alt+]";case"toggleCliView":return s?"⌥+T":"Ctrl+Alt+T"}}function Da(t){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:Je("openShortcutHelp",t)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:Je("hideCurrentTab",t)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:Je("toggleHiddenTabs",t)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:Je("openHistoryForActiveTab",t)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:Je("openRemoteForActiveTab",t)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:Je("splitActiveTabRight",t)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:Je("splitActiveTabDown",t)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:Je("focusLeftPane",t)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:Je("focusRightPane",t)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:Je("focusUpPane",t)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:Je("focusDownPane",t)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:Je("moveActiveTabToLeftPane",t)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:Je("moveActiveTabToRightPane",t)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:Je("moveActiveTabToUpPane",t)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:Je("moveActiveTabToDownPane",t)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:Je("triggerPrimaryApprovalAction",t)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:Je("triggerSecondaryApprovalAction",t)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:Je("triggerTertiaryApprovalAction",t)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:Je("setActiveTabShortcut",t)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:Je("selectPreviousGroupTab",t)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:Je("selectNextGroupTab",t)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:Je("toggleCliView",t)}]}function Fl(t){if(!(t instanceof HTMLElement))return!1;if(t.isContentEditable)return!0;const s=t.tagName;return s==="INPUT"||s==="TEXTAREA"||s==="SELECT"}function Tn(t){const s=Object.fromEntries(Da(t).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem($a)||"{}"),n={...s,...r};for(const[i,o]of Object.entries(Ul))n[i]===o&&(n[i]=s[i]);return n}catch{return s}}function Hl(t){return t===" "?"Space":t==="Escape"?"Esc":t==="ArrowLeft"?"←":t==="ArrowRight"?"→":t==="ArrowUp"?"↑":t==="ArrowDown"?"↓":t.length===1?t.toUpperCase():t}function Vl({enabled:t=!0,onTrigger:s}){const r=zl(),[n,i]=a.useState(()=>Tn(r)),[o,c]=a.useState(null),[u,d]=a.useState([]),x=a.useRef({parts:[],timer:null}),l=a.useCallback(p=>{const g=[];return p.metaKey&&g.push(r?"⌘":"Meta"),p.ctrlKey&&g.push("Ctrl"),p.altKey&&g.push(r?"⌥":"Alt"),p.shiftKey&&p.key.length!==1&&g.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(p.key)?null:(g.push(Hl(p.key)),g.join("+"))},[r]),f=a.useCallback(p=>{i(p);try{localStorage.setItem($a,JSON.stringify(p))}catch{}},[]);a.useEffect(()=>{const p=Tn(r),g=Object.entries(n),b=Object.entries(p);g.length===b.length&&g.every(([v,S])=>p[v]===S)||f(p)},[n,r,f]);const h=a.useCallback(()=>{typeof window<"u"&&x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current={parts:[],timer:null}},[]),m=a.useCallback(()=>{typeof window>"u"||(x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current.timer=window.setTimeout(()=>{x.current={parts:[],timer:null}},Ol))},[]);a.useEffect(()=>{if(!o)return;const p=g=>{if(g.preventDefault(),g.stopPropagation(),g.key==="Escape"){c(null),d([]);return}const b=l(g);if(!b)return;const S=!(g.metaKey||g.ctrlKey||g.altKey)&&/^[A-Z0-9]$/.test(b);if(u.length===0&&S){d([b]);return}const j=[...u,b].slice(0,2).join(" "),C={...n};for(const[w,k]of Object.entries(C))k===j&&delete C[w];C[o]=j,f(C),c(null),d([])};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)},[n,l,f,o,u]),a.useEffect(()=>{if(!t||o)return;const p=g=>{if(g.defaultPrevented)return;const b=l(g);if(!b)return;const v=g.metaKey||g.ctrlKey||g.altKey;if(Fl(g.target)&&!v)return;const S=x.current.parts,B=v?[b]:[...S.slice(-1),b].slice(-2),j=B.join(" "),C=B[B.length-1],w=Object.entries(n).filter(([,R])=>!!R),k=w.find(([,R])=>R===j);if(k){g.preventDefault(),h(),s(k[0]);return}if(w.some(([,R])=>R.startsWith(`${j} `))){g.preventDefault(),x.current.parts=B,m();return}const L=w.find(([,R])=>R===C);if(L){g.preventDefault(),h(),s(L[0]);return}if(w.some(([,R])=>R.startsWith(`${C} `))){g.preventDefault(),x.current.parts=[C],m();return}h()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[n,m,t,l,s,h,o]),a.useEffect(()=>()=>h(),[h]);const y=a.useMemo(()=>Da(r),[r]);return{isMac:r,actionDefinitions:y,actionShortcuts:n,shortcutListening:o,shortcutListeningDraft:u,setShortcutListening:c,setShortcutListeningDraft:d,saveShortcuts:f}}function Gl(t){switch(t.id){case"triggerPrimaryApprovalAction":case"triggerSecondaryApprovalAction":case"triggerTertiaryApprovalAction":return"approvals";case"splitActiveTabRight":case"splitActiveTabDown":case"focusLeftPane":case"focusRightPane":case"focusUpPane":case"focusDownPane":case"moveActiveTabToLeftPane":case"moveActiveTabToRightPane":case"moveActiveTabToUpPane":case"moveActiveTabToDownPane":return"panes";default:return"workspace"}}function ql(t){return t instanceof Error?t.message:String(t||"")}function Yl(t){const s=ql(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Xl({showMobileChatMode:t,isMobile:s,activeConv:r,chatIdes:n,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:u,onStopCli:d,activeCliViewMode:x,onSetActiveCliViewMode:l,mobileChatConversations:f,hiddenConversations:h,ides:m,actionLogs:y,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:b,isStandalone:v,initialDataLoaded:S,userName:B,requestedMobileTabKey:j,onRequestedMobileTabConsumed:C,requestedMachineId:w,onRequestedMachineConsumed:k,requestedMobileSection:E,onRequestedMobileSectionConsumed:L,containerRef:$,isSplitMode:R,numGroups:T,groupSizes:O,groupedConvs:H,clearedTabs:D,focusedGroup:F,setFocusedGroup:_,moveTabToGroup:A,splitTabRelative:M,closeGroup:G,handleResizeStart:Y,detectedIdes:ue,handleLaunchIde:ve,groupActiveTabIds:Te,setGroupActiveTabIds:ee,groupTabOrders:Me,setGroupTabOrders:U,toggleHiddenTab:ae,visibleConversations:X,requestedDesktopTabKey:pe,onRequestedDesktopTabConsumed:me,onDesktopActiveTabChange:se,onHideConversation:de,onShowHiddenConversation:xe,onShowAllHiddenConversations:oe,scrollToBottomRequest:J,machineEntries:ce,onBrowseMachineDirectory:Q,onSaveMachineWorkspace:he,onLaunchMachineIde:I,onLaunchMachineProvider:re,onListMachineSavedSessions:W}){const z=et.useRef(null),[te,le]=et.useState(!1),[Ne,Pe]=et.useState(!1),[q,be]=et.useState(!1),[Ae,$e]=et.useState(!1),[He,Oe]=et.useState(!1),[Qe,Z]=et.useState("quickstart"),[ge,K]=et.useState("workspace"),P=!t&&!s,ne=et.useCallback(N=>{le(N),N&&Pe(!1)},[]),ie=et.useCallback(N=>{Pe(N),N&&le(!1)},[]),Se=et.useCallback(()=>{Z(X.length===0?"quickstart":"shortcuts"),K("workspace"),be(!0),le(!1),Pe(!1)},[X.length]),We=et.useCallback(async N=>{var _e;if(!r)return;const V=(_e=r.modalButtons)==null?void 0:_e[N];if(!V)return;const ye=ls(r);if(!ye)return;const we=V.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),Le=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(we);try{await p(ye,"resolve_action",{button:V,action:Le?"approve":"reject",buttonIndex:N,...Vt(r)})}catch(Ue){Yl(Ue)||console.error("[Shortcut approval] Failed:",Ue)}},[r,p]),{isMac:Ee,actionDefinitions:Ie,actionShortcuts:Fe,shortcutListening:Ve,shortcutListeningDraft:st,setShortcutListening:ut,setShortcutListeningDraft:pt,saveShortcuts:lt}=Vl({enabled:P&&!q,onTrigger:N=>{var V,ye,we,Le,_e,Ue,Ke,Ge,qe,kt,Tt,fs,At;if(N==="openShortcutHelp"){Se();return}if(N==="hideCurrentTab"){r&&de(r);return}if(N==="toggleHiddenTabs"){ie(!Ne);return}if(N==="openHistoryForActiveTab"){r&&!ze(r)&&c(r);return}if(N==="openRemoteForActiveTab"){r&&!Xe(r)&&!ze(r)&&u(r);return}if(N==="splitActiveTabRight"){(V=z.current)==null||V.splitActiveTabRight();return}if(N==="splitActiveTabDown"){(ye=z.current)==null||ye.splitActiveTabDown();return}if(N==="focusLeftPane"){(we=z.current)==null||we.focusLeftPane();return}if(N==="focusRightPane"){(Le=z.current)==null||Le.focusRightPane();return}if(N==="focusUpPane"){(_e=z.current)==null||_e.focusUpPane();return}if(N==="focusDownPane"){(Ue=z.current)==null||Ue.focusDownPane();return}if(N==="moveActiveTabToLeftPane"){(Ke=z.current)==null||Ke.moveActiveTabToLeftPane();return}if(N==="moveActiveTabToRightPane"){(Ge=z.current)==null||Ge.moveActiveTabToRightPane();return}if(N==="moveActiveTabToUpPane"){(qe=z.current)==null||qe.moveActiveTabToUpPane();return}if(N==="moveActiveTabToDownPane"){(kt=z.current)==null||kt.moveActiveTabToDownPane();return}if(N==="triggerPrimaryApprovalAction"){We(0);return}if(N==="triggerSecondaryApprovalAction"){We(1);return}if(N==="triggerTertiaryApprovalAction"){We(2);return}if(N==="setActiveTabShortcut"){(Tt=z.current)==null||Tt.setShortcutForActiveTab();return}if(N==="selectPreviousGroupTab"){(fs=z.current)==null||fs.activatePreviousTabInGroup();return}if(N==="selectNextGroupTab"){(At=z.current)==null||At.activateNextTabInGroup();return}!r||!Xe(r)||ze(r)||N==="toggleCliView"&&l(x==="chat"?"terminal":"chat")}}),xt=et.useCallback(()=>{be(!1),ut(null),pt([])},[ut,pt]),De=et.useMemo(()=>ge==="all"?Ie:Ie.filter(N=>Gl(N)===ge),[Ie,ge]),Wt=et.useCallback(()=>{const N=Object.fromEntries(Ie.map(V=>[V.id,""]));lt(N)},[Ie,lt]),Xt=et.useCallback(()=>{if(typeof window<"u"&&!window.confirm("Reset all dashboard shortcuts back to their default values?"))return;const N=Object.fromEntries(Ie.map(V=>[V.id,V.defaultShortcut]));lt(N)},[Ie,lt]);return et.useEffect(()=>{const N=V=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?V.metaKey&&V.key.toLowerCase()==="w":V.ctrlKey&&V.key.toLowerCase()==="w")&&(V.preventDefault(),r&&de&&de(r))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[r,de]),et.useEffect(()=>{if(!q||Ve)return;const N=V=>{V.key==="Escape"&&(V.preventDefault(),xt())};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[xt,q,Ve]),et.useEffect(()=>{if(!P||X.length>0){Oe(!1);return}Oe(!0);const N=window.setTimeout(()=>{Oe(!1)},1e4);return()=>window.clearTimeout(N)},[P,X.length]),e.jsxs(e.Fragment,{children:[!t&&e.jsx($o,{activeConv:r,agentCount:n.length,wsStatus:i,isConnected:o,conversations:X,hiddenConversations:h,onOpenHistory:c,onOpenConversation:xe,onHideConversation:de,onShowConversation:xe,onShowAllHidden:oe,inboxOpen:te,onInboxOpenChange:ne,hiddenOpen:Ne,onHiddenOpenChange:ie,onOpenNewSession:s?void 0:()=>$e(!0),onOpenRemote:()=>{!r||Xe(r)||ze(r)||u(r)},onStopCli:d,activeCliViewMode:x,onSetCliViewMode:l}),t?e.jsx(yl,{conversations:f,hiddenConversations:h,ides:m,actionLogs:y,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:b,isStandalone:v,userName:B,requestedActiveTabKey:j,onRequestedActiveTabConsumed:C,requestedMachineId:w,onRequestedMachineConsumed:k,requestedMobileSection:E,onRequestedMobileSectionConsumed:L,onOpenHistory:c,onOpenRemote:u,onStopCli:d,wsStatus:i,isConnected:o,onShowHiddenConversation:xe,onShowAllHiddenConversations:oe}):s?e.jsx(Tl,{containerRef:$,isSplitMode:R,numGroups:T,groupSizes:O,groupedConvs:H,clearedTabs:D,ides:m,actionLogs:y,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:b,isStandalone:v,userName:B,focusedGroup:F,setFocusedGroup:_,moveTabToGroup:A,splitTabRelative:M,closeGroup:G,handleResizeStart:Y,detectedIdes:ue,handleLaunchIde:ve,groupActiveTabIds:Te,setGroupActiveTabIds:ee,groupTabOrders:Me,setGroupTabOrders:U,toggleHiddenTab:ae,allowTabShortcuts:!1}):e.jsx($l,{visibleConversations:X,clearedTabs:D,ides:m,actionLogs:y,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:b,isStandalone:v,initialDataLoaded:S,userName:B,detectedIdes:ue,handleLaunchIde:ve,toggleHiddenTab:ae,registerActionHandlers:N=>{z.current=N},onActiveTabChange:se,requestedActiveTabKey:pe,onRequestedActiveTabConsumed:me,scrollToBottomRequest:J}),Ae&&e.jsx(Wl,{machines:ce,onClose:()=>$e(!1),onBrowseDirectory:Q,onSaveWorkspace:he,onLaunchIde:I,onLaunchProvider:re,onListSavedSessions:W}),q&&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:xt,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl w-[min(560px,calc(100vw-32px))] max-h-[min(80vh,720px)] overflow-y-auto px-6 py-5 shadow-xl",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Dashboard guide"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"A quick guide to the dashboard flow, plus grouped shortcuts you can tune."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:xt,children:"Close"})]}),e.jsx("div",{className:"flex gap-2 mb-4 overflow-x-auto",children:[{id:"overview",label:"Overview"},{id:"quickstart",label:"Quick start"},{id:"shortcuts",label:"Shortcuts"}].map(N=>e.jsx("button",{type:"button",className:`btn btn-sm ${Qe===N.id?"btn-primary":"btn-secondary"}`,onClick:()=>Z(N.id),children:N.label},N.id))}),Qe==="overview"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3 mb-4",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"What lives where"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Tabs:"})," active sessions across IDE, CLI, and ACP agents."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Hidden tabs:"})," stash sessions you do not want in the main strip but still want to keep around."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Activity inbox:"})," sessions waiting for approval or finished tasks you have not reviewed yet."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"CLI view toggle:"})," switch a PTY session between terminal and chat rendering without relaunching it."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Useful flows"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Review notifications:"})," open the inbox, jump to the session, then use the conversation or approval controls directly from the active pane."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Reduce clutter:"})," hide less important sessions instead of closing them, then restore from hidden tabs when needed."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Split work:"})," keep one pane active for input and let secondary panes stay read-only until you focus them."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Per-tab shortcuts:"})," right-click a Dockview tab to assign a direct shortcut for that specific session."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Approval buttons:"})," use ",Ee?"⌥J / ⌥K / ⌥L":"Ctrl+Alt+J / K / L"," for the first three visible approval actions on the active session."]})]})]})]}),Qe==="quickstart"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Desktop quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Start from the machine or workspace flow first. Pick or save a workspace before launching CLI or ACP sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Keep the main strip focused on active work and push overflow into Hidden tabs."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Use the inbox for approval-required or completed sessions instead of scanning every tab."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"4."})," Split only when you need parallel reading; one active pane is usually the cleanest default."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Mobile quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Stay in chat mode for review and replies; use workspace mode mainly to launch or reopen sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Start from the machine screen, choose a workspace, then launch IDE, CLI, or ACP from there."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Treat mobile as the simpler control surface: no split workflow, fewer tab mechanics, faster session switching."]})]})]})]}),Qe==="shortcuts"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"all",label:"All"},{id:"workspace",label:"Workspace"},{id:"panes",label:"Panes"},{id:"approvals",label:"Approvals"}].map(N=>e.jsx("button",{type:"button",className:`btn btn-sm ${ge===N.id?"btn-primary":"btn-secondary"}`,onClick:()=>K(N.id),children:N.label},N.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Wt,children:"Disable all"}),e.jsx("button",{type:"button",className:"btn btn-sm",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, var(--border-subtle, transparent))",background:"color-mix(in srgb, var(--status-error, #ef4444) 8%, var(--bg-primary, transparent))"},onClick:Xt,children:"Reset to defaults"})]})]}),e.jsx("div",{className:"space-y-2",children:De.map(N=>e.jsx("div",{className:`rounded-xl border px-4 py-3 ${Ve===N.id?"border-accent bg-bg-secondary/70":"border-border-subtle bg-bg-secondary/30"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:N.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:N.description}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-2",children:["Default: ",e.jsx("span",{className:"font-mono",children:N.defaultShortcut})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-[11px] font-mono px-2 py-1 rounded bg-bg-tertiary border border-border-subtle min-w-[72px] text-center",children:Ve===N.id?st.length>0?`${st.join(" ")} ...`:"Listening...":Fe[N.id]||"Off"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{ut(N.id),pt([])},children:Ve===N.id?"Listening":"Set"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{const V={...Fe};V[N.id]="",lt(V)},children:"Disable"})]})]})},N.id))}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-4",children:["Use modifier shortcuts like ",Ee?"⌥S":"Ctrl+Alt+S",". Press Esc to stop listening."]})]})]})}),!t&&He&&e.jsxs("button",{type:"button",onClick:Se,className:"fixed right-4 bottom-24 z-40 hidden md:inline-flex items-center gap-2 rounded-full border border-border-subtle bg-bg-primary/88 backdrop-blur px-2.5 py-2 text-xs text-text-secondary hover:text-text-primary transition-colors",style:{boxShadow:"0 6px 18px rgba(0,0,0,0.12)"},title:"Dashboard guide","aria-label":"Open dashboard guide",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full bg-bg-secondary text-[11px] font-semibold text-text-primary shrink-0",children:"?"}),e.jsx("span",{children:"Guide"})]})]})}const ar=[{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 Jl({onClose:t}){const[s,r]=a.useState(0),n=ar[s],i=s===ar.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:ar.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:n.visual||n.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:n.icon})," ",n.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:n.desc}),n.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:"$"}),n.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():r(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 Zl({hasExtensions:t,ideName:s,activeChatTab:r,extensionTabs:n,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)] ${r==="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}),n.map(o=>{const c=r===o.tabKey,u=o.status==="waiting_approval",d=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:u?"var(--status-warning)":d?"var(--accent-primary)":"var(--text-muted)",boxShadow:d?"0 0 6px var(--accent-primary)":"none"}}),o.title,u&&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 Ql({ideData:t,allIdes:s,connectionStates:r,localUserMessages:n,ideName:i,preferredTabKey:o}){const[c,u]=a.useState(()=>o||"native"),d=a.useMemo(()=>ia(s),[s]),x=a.useMemo(()=>{var g;if(!t)return[];const p=t.daemonId||((g=t.id)==null?void 0:g.split(":")[0])||t.id;return Ar(t,n,{machineName:t.daemonId&&d[t.daemonId]||void 0,connectionState:r[p]||"new"})},[t,n,d,r]),l=a.useMemo(()=>x.find(p=>p.streamSource==="native"),[x]),f=a.useMemo(()=>x.filter(p=>p.streamSource==="agent-stream"),[x]);a.useEffect(()=>{o&&u(o)},[o]),a.useEffect(()=>{var p;c!=="native"&&(f.some(g=>g.tabKey===c)||u(((p=f[0])==null?void 0:p.tabKey)||"native"))},[c,f]),a.useEffect(()=>{c==="native"&&(l||f[0]&&u(f[0].tabKey))},[c,l,f]);const h=a.useMemo(()=>c==="native"&&l?l:f.find(p=>p.tabKey===c)||l||f[0],[c,l,f]),m=a.useMemo(()=>f.map(p=>({tabKey:p.tabKey,title:p.title||p.agentName||i,status:p.status})),[f,i]),y=a.useCallback(p=>{if(p)return x.find(g=>g.sessionId===p||g.ideId===p||g.tabKey===p||g.ideType===p||g.agentType===p)},[x]);return{activeChatTab:c,setActiveChatTab:u,activeConv:h,conversations:x,extensionTabs:m,hasExtensions:m.length>0,resolveConversationByTarget:y}}function ed({activeConv:t,ideEntry:s,ides:r,connectionStates:n,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:u,setActionLogs:d,isStandalone:x,userName:l,onOpenHistory:f,onConversationChange:h,onClose:m}){var H;const[y,p]=a.useState("split"),[g,b]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),v=a.useMemo(()=>s||r.find(D=>D.id===t.ideId),[t.ideId,s,r]),S=a.useMemo(()=>Ye((v==null?void 0:v.type)||""),[v==null?void 0:v.type]),{conversations:B,extensionTabs:j,hasExtensions:C}=Ql({ideData:v,allIdes:r,connectionStates:n,localUserMessages:o,ideName:S||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{b(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const w=a.useMemo(()=>g==="native"?B.find(D=>D.streamSource==="native")||t:B.find(D=>D.tabKey===g)||t,[t,B,g]),k=w.daemonId||((H=w.ideId)==null?void 0:H.split(":")[0])||w.ideId,E=Us({sendDaemonCommand:c,activeConv:w,setLocalUserMessages:u,setActionLogs:d,isStandalone:x}),{connScreenshot:L,screenshotUsage:$,handleRemoteAction:R}=Aa({doId:k,ideId:w.ideId,ideType:w.ideType,connState:w.connectionState||"new",viewMode:y,instanceId:v==null?void 0:v.instanceId}),T=a.useMemo(()=>i.filter(D=>D.ideId===w.tabKey),[i,w.tabKey]);a.useEffect(()=>{h==null||h(w)},[w,h]),a.useEffect(()=>{const D=F=>{F.key==="Escape"&&m()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[m]);const O=a.useCallback(D=>{D.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:m,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:O,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(ot,{size:16})}),e.jsx("span",{className:"truncate",children:w.displayPrimary||w.agentName||"Remote"})]})}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold md:hidden shrink-0",onClick:m,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(D=>{const F=y===D;return e.jsx("button",{className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${F?"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:()=>p(D),title:D==="split"?"Split view":"Remote only",children:D==="split"?e.jsx(Wi,{size:15}):e.jsx(ot,{size:15})},D)})}),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:()=>f(w),title:"Chat History",children:[e.jsx(wr,{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:m,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${y==="split"?"grid-cols-1 grid-rows-[1fr_minmax(320px,42vh)] md:grid-cols-[minmax(360px,0.92fr)_minmax(420px,1.08fr)] md:grid-rows-1":"grid-cols-1 grid-rows-1"}`,children:[y!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${y==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(Zl,{hasExtensions:C,ideName:S||"IDE",activeChatTab:g,extensionTabs:j,onSelectTab:b}),e.jsx(Zn,{activeConv:w,onModalButton:E.handleModalButton}),e.jsx(pr,{activeConv:w,ideEntry:v,showMetaChips:!1,handleSendChat:E.handleSendChat,isSendingChat:E.isSendingChat,handleFocusAgent:E.handleFocusAgent,isFocusingAgent:E.isFocusingAgent,actionLogs:T,userName:l})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${y==="split"?"order-1 md:order-2":""}`,children:e.jsx(Yn,{addLog:()=>{},connState:w.connectionState||"new",connScreenshot:L,screenshotUsage:$,transportType:w.transport,onAction:R})})]})]})})}function td({activeConv:t,canSaveAndStop:s=!1,onCancel:r,onStopNow:n,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:r,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:n,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:r,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:"Cancel"})]})]})]})}function sd({historyModalOpen:t,historyTargetConv:s,ides:r,isHistoryCreatingChat:n,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:u,onCloseHistory:d,onNewHistoryChat:x,onSwitchHistorySession:l,onRefreshHistory:f,onResumeSavedHistorySession:h,remoteDialogConv:m,remoteDialogIdeEntry:y,connectionStates:p,actionLogs:g,localUserMessages:b,sendDaemonCommand:v,setLocalUserMessages:S,setActionLogs:B,isStandalone:j,userName:C,onOpenRemoteHistory:w,onRemoteConversationChange:k,onCloseRemoteDialog:E,cliStopDialogOpen:L,cliStopTargetConv:$,onCancelCliStop:R,onStopCliNow:T,onSaveCliAndStop:O,toasts:H,onDismissToast:D,onClickToast:F,showOnboarding:_,onCloseOnboarding:A}){var M;return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Bo,{activeConv:s,ides:r,isCreatingChat:n,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:u,onClose:d,onNewChat:x,onSwitchSession:l,onRefreshHistory:f,onResumeSavedSession:h}),m&&e.jsx(ed,{activeConv:m,ideEntry:y,ides:r,connectionStates:p,actionLogs:g,localUserMessages:b,sendDaemonCommand:v,setLocalUserMessages:S,setActionLogs:B,isStandalone:j,userName:C,onOpenHistory:w,onConversationChange:k,onClose:E}),L&&$&&Xe($)&&!ze($)&&e.jsx(td,{activeConv:$,canSaveAndStop:!!((M=$.resume)!=null&&M.supported),onCancel:R,onStopNow:T,onSaveAndStop:O}),e.jsx(aa,{toasts:H,onDismiss:D,onClickToast:F}),_&&e.jsx(Jl,{onClose:A})]})}function rd({daemons:t,targetVersion:s,upgradingDaemons:r,onUpgrade:n,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(Ds,{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=gt(o,{fallbackId:o.id}),u=r[o.id],d=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",d]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(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:()=>n(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 nd(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function An(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function ad(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function id(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function od(){var Kr,Wr,Or;const{sendCommand:t}=It(),s=yr(),r=Yt(),[n,i]=gi(),o=n.get("activeTab"),c=((Kr=s.state)==null?void 0:Kr.openRemoteForTabKey)||null,u=((Wr=s.state)==null?void 0:Wr.openMachineId)||null,d=((Or=s.state)==null?void 0:Or.mobileSection)||null,x=Cr(),l=x.ides||[],f=x.initialLoaded??!0,{updateIdeChats:h}=x,[m,y]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),p=x.toasts||[],g=x.setToasts||(()=>{}),b=x.wsStatus||"connected",v=x.isConnected??!0,S=x.connectionStates||{},B=x.showReconnected||!1,{groupAssignments:j,setGroupAssignments:C,focusedGroup:w,setFocusedGroup:k,groupActiveTabIds:E,setGroupActiveTabIds:L,groupTabOrders:$,setGroupTabOrders:R,groupSizes:T,setGroupSizes:O,isMobile:H,hasHydratedStoredLayout:D,hydrateStoredLayout:F}=Qc(),[_,A]=a.useState(!1),[M,G]=a.useState(!1),[Y,ue]=a.useState(null),[ve,Te]=a.useState([]),[ee,Me]=a.useState(!1),[U,ae]=a.useState(null),[X]=a.useState(()=>ba()),[pe,me]=a.useState([]),[se,de]=a.useState({}),[xe,oe]=a.useState({}),[J,ce]=a.useState(null),[Q,he]=a.useState(null),[I,re]=a.useState(null),W=a.useRef(null);ps("Dashboard",{ideCount:l.length,toastCount:p.length,focusedGroup:w,groupCount:Object.keys(j).length,localMessageTabs:Object.keys(se).length,actionLogCount:pe.length});const z=l.find(fe=>fe.type==="adhdev-daemon"),te=(z==null?void 0:z.detectedIdes)||[],le=a.useMemo(()=>l.filter(fe=>fe.type==="adhdev-daemon"||fe.daemonMode).sort(Sr),[l]),Ne=!!z,Pe=(z==null?void 0:z.terminalBackend)||null,q=z?gt(z,{fallbackId:z.id}):null,be=(z==null?void 0:z.id)||null,{hiddenTabs:Ae,hideTab:$e,toggleTab:He,showTab:Oe,showAllTabs:Qe}=Rc(),{chatIdes:Z,conversations:ge,visibleConversations:K,visibleTabKeys:P,resolveConversationBySessionId:ne,resolveConversationByTarget:ie}=zc({ides:l,connectionStates:S,localUserMessages:se,clearedTabs:xe,hiddenTabs:Ae}),Se=a.useMemo(()=>ms(l),[l]),We=a.useRef(null),{containerRef:Ee,normalizedGroupAssignments:Ie,numGroups:Fe,isSplitMode:Ve,groupedConvs:st,moveTabToGroup:ut,closeGroup:pt,handleResizeStart:lt,splitTabRelative:xt}=il({groupAssignments:j,setGroupAssignments:C,setFocusedGroup:k,setGroupActiveTabIds:L,setGroupTabOrders:R,groupSizes:T,setGroupSizes:O,isMobile:H,visibleConversations:K,visibleTabKeys:P}),De=a.useMemo(()=>{var Ce,je;if(!H){if(J){const ke=ge.find(Re=>Re.tabKey===J);if(ke)return ke}return K[0]}const fe=E[w];if(fe){const ke=ge.find(Re=>Re.tabKey===fe);if(ke)return ke}return((Ce=st[w])==null?void 0:Ce[0])||((je=st[0])==null?void 0:je[0])},[J,H,E,w,ge,st,K]);a.useEffect(()=>{if(H){We.current=null;return}if(!(De!=null&&De.sessionId)){We.current=null;return}const fe=`${De.tabKey}:${De.sessionId}`;if(We.current===fe)return;We.current=fe;const Ce=is(De,Se),je=Math.max(Date.now(),Pt(De),Ce.lastUpdated||0);t(De.daemonId||De.ideId,"mark_session_seen",{sessionId:De.sessionId,seenAt:je}).catch(()=>{})},[De,H,Se,t]);const{requestedDesktopTabKey:Wt,requestedMobileTabKey:Xt,consumeRequestedActiveTab:N}=Fc({isMobile:H,urlActiveTab:o,resolveConversationBySessionId:ne,setSearchParams:i}),{remoteDialogConv:V,remoteDialogIdeEntry:ye,remoteDialogActiveConv:we,setRemoteDialogActiveConv:Le,openRemoteDialog:_e,closeRemoteDialog:Ue}=tl({isMobile:H,location:s,navigate:r,requestedRemoteTabTarget:c,requestedDesktopTabKey:Wt,conversations:ge,ides:l,resolveConversationByTarget:ie}),Ke=we||V||De,Ge=!!Ke&&Xe(Ke)&&!ze(Ke),qe=a.useMemo(()=>{if(!Ke||!Ge)return null;const fe=Ke.daemonId||Ke.ideId||"",Ce=Ke.agentType||Ke.ideType||"";return`${fe}:${Ce}`},[Ke,Ge]),kt=a.useMemo(()=>K,[K]),Tt=H&&X==="chat",fs=a.useMemo(()=>ge.filter(fe=>Ae.has(fe.tabKey)),[ge,Ae]),At=a.useCallback(fe=>{const Ce=new URLSearchParams(n);Ce.set("activeTab",fe),i(Ce,{replace:!0})},[n,i]),Ba=a.useCallback(async(fe,Ce)=>Rr(t,fe,Ce),[t]),Ka=a.useCallback(async(fe,Ce)=>{if(!Ce.trim())return{ok:!1,error:"Choose a workspace path first."};try{const je=await t(fe,"workspace_add",{path:Ce.trim()});return je!=null&&je.success?{ok:!0}:{ok:!1,error:(je==null?void 0:je.error)||"Could not save workspace"}}catch(je){return{ok:!1,error:je instanceof Error?je.message:"Could not save workspace"}}},[t]),Wa=a.useCallback(async(fe,Ce,je)=>{var ke;try{const Re={ideType:Ce,enableCdp:!0};(ke=je==null?void 0:je.workspacePath)!=null&&ke.trim()&&(Re.workspace=je.workspacePath.trim());const rt=await t(fe,"launch_ide",Re);return!(rt!=null&&rt.success)&&(rt==null?void 0:rt.success)!==void 0?{ok:!1,error:(rt==null?void 0:rt.error)||"Could not launch IDE"}:(re({machineId:fe,kind:"ide",providerType:Ce,workspacePath:(je==null?void 0:je.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(Re){return{ok:!1,error:Re instanceof Error?Re.message:"Could not launch IDE"}}},[t]),Oa=a.useCallback(async(fe,Ce,je,ke)=>{var rt,Jt,Ot;const Re=Date.now();try{const ht={cliType:je};(rt=ke==null?void 0:ke.workspacePath)!=null&&rt.trim()?ht.dir=ke.workspacePath.trim():ke!=null&&ke.workspaceId&&(ht.workspaceId=ke.workspaceId),(Jt=ke==null?void 0:ke.resumeSessionId)!=null&&Jt.trim()&&(ht.resumeSessionId=ke.resumeSessionId.trim()),Array.isArray(ke==null?void 0:ke.cliArgs)&&ke.cliArgs.length>0&&(ht.cliArgs=ke.cliArgs),(Ot=ke==null?void 0:ke.initialModel)!=null&&Ot.trim()&&(ht.initialModel=ke.initialModel.trim());const nt=await t(fe,"launch_cli",ht),dt=(nt==null?void 0:nt.result)||nt,Zt=(dt==null?void 0:dt.sessionId)||(dt==null?void 0:dt.id);return nt!=null&&nt.success&&Zt?(At(Zt),{ok:!0}):nt!=null&&nt.success?(re({machineId:fe,kind:Ce,providerType:je,workspacePath:(ke==null?void 0:ke.workspacePath)||null,resumeSessionId:(ke==null?void 0:ke.resumeSessionId)||null,startedAt:Re}),{ok:!0}):{ok:!1,error:(nt==null?void 0:nt.error)||(dt==null?void 0:dt.error)||`Could not launch ${Ce.toUpperCase()} session`}}catch(ht){return ad(ht)?(re({machineId:fe,kind:Ce,providerType:je,workspacePath:(ke==null?void 0:ke.workspacePath)||null,resumeSessionId:(ke==null?void 0:ke.resumeSessionId)||null,startedAt:Re}),{ok:!0}):{ok:!1,error:ht instanceof Error?ht.message:`Could not launch ${Ce.toUpperCase()} session`}}},[At,t]),Ua=a.useCallback(async(fe,Ce)=>{if(!fe||!Ce)return[];try{const je=await t(fe,"list_saved_sessions",{providerType:Ce,kind:"cli",limit:30}),ke=(je==null?void 0:je.result)??je;return Array.isArray(ke==null?void 0:ke.sessions)?ke.sessions:[]}catch(je){return console.error("List saved sessions failed",je),[]}},[t]);a.useEffect(()=>{var ke;if(!I)return;const fe=An(I.workspacePath),Ce=l.find(Re=>{var nt,dt,Zt,Ur;if(!Re||Re.type==="adhdev-daemon"||Re.daemonMode||nd(Re.daemonId||Re.id)!==I.machineId||(cs(Re)?"cli":Ht(Re)?"acp":"ide")!==I.kind||String(Re.agentType||Re.ideType||Re.type||"")!==I.providerType)return!1;if(I.resumeSessionId)return String(Re.providerSessionId||"")===I.resumeSessionId;if(fe){const qs=An(Re.workspace||Re.runtimeWorkspaceLabel);return qs?qs===fe:!1}return Number(Re.lastUpdated||Re._lastUpdate||Re.timestamp||((Ur=(Zt=(dt=(nt=Re.activeChat)==null?void 0:nt.messages)==null?void 0:dt.at)==null?void 0:Zt.call(dt,-1))==null?void 0:Ur.timestamp)||0)>=I.startedAt-5e3});if(!Ce)return;const je=typeof Ce.sessionId=="string"&&Ce.sessionId?Ce.sessionId:typeof Ce.instanceId=="string"&&Ce.instanceId?Ce.instanceId:(ke=ge.find(Re=>Re.ideId===Ce.id))==null?void 0:ke.sessionId;je&&(re(null),At(je))},[ge,At,l,I]),a.useEffect(()=>{if(!I)return;const fe=window.setTimeout(()=>{re(Ce=>!Ce||Ce.startedAt!==I.startedAt?Ce:null)},45e3);return()=>window.clearTimeout(fe)},[I]),Ec({visibleConversations:K,clearedTabs:xe,setClearedTabs:oe,setActionLogs:me}),Hc({ides:l,sendDaemonCommand:t,setToasts:g,setLocalUserMessages:de,resolveConversationByTarget:ie});const{isRefreshingHistory:za,handleLaunchIde:Fa,handleRefreshHistory:Ha}=fn({sendDaemonCommand:t,activeConv:De,updateIdeChats:h,setToasts:g,setLocalUserMessages:de,setClearedTabs:oe}),{isCreatingChat:Va,isRefreshingHistory:Ga,handleSwitchSession:qa,handleNewChat:Ya,handleRefreshHistory:Xa}=fn({sendDaemonCommand:t,activeConv:Ke,updateIdeChats:h,setToasts:g,setLocalUserMessages:de,setClearedTabs:oe}),Vs=a.useCallback(async()=>{if(!(!Ke||!Ge||ee)){Me(!0);try{const fe=Ke.daemonId||Ke.ideId,Ce=Ke.agentType||Ke.ideType,je=await t(fe,"list_saved_sessions",{agentType:Ce,providerType:Ce,kind:"cli",limit:50}),ke=(je==null?void 0:je.result)??je;Te(Array.isArray(ke==null?void 0:ke.sessions)?ke.sessions:[])}catch(fe){console.error("Refresh saved sessions failed",fe),Te([])}finally{Me(!1)}}},[Ke,ee,Ge,t]);a.useEffect(()=>{if(!_){W.current=null;return}if(!Ge){W.current=null,Te([]),Me(!1);return}!qe||ee||W.current!==qe&&(W.current=qe,Vs())},[Vs,_,ee,Ge,qe]);const Ja=a.useCallback(async fe=>{if(!Ke||!Ge||!fe.providerSessionId||!fe.workspace)return;const Ce=Ke.daemonId||Ke.ideId,je=Ke.agentType||Ke.ideType;try{ae(fe.providerSessionId);const ke=await t(Ce,"launch_cli",{cliType:je,dir:fe.workspace,resumeSessionId:fe.providerSessionId,initialModel:fe.currentModel}),Re=(ke==null?void 0:ke.result)??ke,rt=typeof(Re==null?void 0:Re.sessionId)=="string"?Re.sessionId:typeof(Re==null?void 0:Re.id)=="string"?Re.id:"";rt&&i(Jt=>{const Ot=new URLSearchParams(Jt);return Ot.set("activeTab",rt),Ot},{replace:!0}),A(!1)}catch(ke){console.error("Resume saved session failed",ke)}finally{ae(null)}},[Ke,Ge,t,i]);el({urlActiveTab:H&&!Tt?o:null,conversations:ge,resolveConversationBySessionId:ne,normalizedGroupAssignments:Ie,hasHydratedStoredLayout:H&&!Tt?D:!0,hydrateStoredLayout:H&&!Tt?F:()=>{},setGroupActiveTabIds:L,setFocusedGroup:k,setSearchParams:i,historyModalOpen:_,activeConv:De,isRefreshingHistory:za,ides:l,handleRefreshHistory:Ha});const Gs=a.useCallback(async(fe,Ce)=>{const je=Ce||Y||De;if(!je||!Xe(je)||ze(je))return;const ke=je.ideType||je.agentType||"",Re=je.ideId||je.daemonId||"";try{await t(Re,"stop_cli",{cliType:ke,targetSessionId:je.sessionId,mode:fe})}catch(rt){console.error("Stop CLI failed:",rt)}},[De,Y,t]),Za=a.useCallback(async fe=>{const Ce=fe||De;!Ce||!Xe(Ce)||ze(Ce)||(ue(Ce),G(!0))},[De,Gs]),Qa=a.useMemo(()=>!De||!Xe(De)||ze(De)?null:qt(De),[De]),ei=a.useCallback(async fe=>{if(!(!De||!Xe(De)||ze(De)||qt(De)===fe))try{await t(De.daemonId||De.ideId,"set_cli_view_mode",{targetSessionId:De.sessionId,cliType:De.ideType||De.agentType,mode:fe})}catch(je){id(je)?console.warn("Skipped CLI view mode switch:",je instanceof Error?je.message:String(je)):console.error("Failed to switch CLI view mode:",je)}},[De,t]),{versionMismatchDaemons:ti,appVersion:si,versionBannerDismissed:ri,setVersionBannerDismissed:ni,upgradingDaemons:ai,handleBannerUpgrade:ii}=ol({ides:l,sendDaemonCommand:t}),Dr=a.useCallback(fe=>{ce(fe.tabKey),i(Ce=>{const je=new URLSearchParams(Ce);return fe.sessionId?je.set("activeTab",fe.sessionId):je.delete("activeTab"),je},{replace:!0})},[i]),Br=a.useCallback(fe=>{Oe(fe.tabKey),Dr(fe)},[Dr,Oe]),oi=a.useCallback(fe=>{$e(fe.tabKey)},[$e]);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(Ro,{wsStatus:b,showReconnected:B}),e.jsx(Eo,{terminalBackend:Pe,isStandalone:Ne,machineLabel:q,machineKey:be}),!ri&&e.jsx(rd,{daemons:ti,targetVersion:si,upgradingDaemons:ai,onUpgrade:ii,onDismiss:()=>ni(!0)}),e.jsx(Xl,{showMobileChatMode:Tt,isMobile:H,activeConv:De,chatIdes:Z,wsStatus:b,isConnected:v,onOpenHistory:fe=>{fe&&Le(fe),A(!0)},onOpenRemote:_e,onStopCli:Za,activeCliViewMode:Qa,onSetActiveCliViewMode:ei,mobileChatConversations:kt,ides:l,actionLogs:pe,sendDaemonCommand:t,setLocalUserMessages:de,setActionLogs:me,isStandalone:Ne,initialDataLoaded:f,userName:x.userName,requestedMobileTabKey:Xt,onRequestedMobileTabConsumed:N,requestedMachineId:u,onRequestedMachineConsumed:()=>{r(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:d,onRequestedMobileSectionConsumed:()=>{r(s.pathname+s.search,{replace:!0,state:null})},containerRef:Ee,isSplitMode:Ve,numGroups:Fe,groupSizes:T,groupedConvs:st,clearedTabs:xe,focusedGroup:w,setFocusedGroup:k,moveTabToGroup:ut,splitTabRelative:xt,closeGroup:pt,handleResizeStart:lt,detectedIdes:te,handleLaunchIde:Fa,groupActiveTabIds:E,setGroupActiveTabIds:L,groupTabOrders:$,setGroupTabOrders:R,toggleHiddenTab:He,visibleConversations:K,hiddenConversations:fs,requestedDesktopTabKey:Wt,onRequestedDesktopTabConsumed:N,onDesktopActiveTabChange:ce,onHideConversation:oi,onShowHiddenConversation:Br,onShowAllHiddenConversations:Qe,scrollToBottomRequest:Q,machineEntries:le,onBrowseMachineDirectory:Ba,onSaveMachineWorkspace:Ka,onLaunchMachineIde:Wa,onLaunchMachineProvider:Oa,onListMachineSavedSessions:Ua}),e.jsx("style",{children:`
|
|
51
|
+
body { overflow: hidden; overscroll-behavior: none; }
|
|
52
|
+
`}),e.jsx(sd,{historyModalOpen:_,historyTargetConv:Ke,ides:l,isHistoryCreatingChat:Va,isHistoryRefreshingHistory:Ge?!1:Ga,savedHistorySessions:ve,isSavedHistoryLoading:ee,isResumingSavedHistorySessionId:U,onCloseHistory:()=>A(!1),onNewHistoryChat:Ya,onSwitchHistorySession:qa,onRefreshHistory:Ge?Vs:Xa,onResumeSavedHistorySession:Ja,remoteDialogConv:V,remoteDialogIdeEntry:ye,connectionStates:S,actionLogs:pe,localUserMessages:se,sendDaemonCommand:t,setLocalUserMessages:de,setActionLogs:me,isStandalone:Ne,userName:x.userName,onOpenRemoteHistory:fe=>{fe&&Le(fe),A(!0)},onRemoteConversationChange:Le,onCloseRemoteDialog:Ue,cliStopDialogOpen:M,cliStopTargetConv:Y,onCancelCliStop:()=>{G(!1),ue(null)},onStopCliNow:async()=>{G(!1),await Gs("hard",Y),ue(null)},onSaveCliAndStop:async()=>{G(!1),await Gs("save",Y),ue(null)},toasts:p,onDismissToast:fe=>g(Ce=>Ce.filter(je=>je.id!==fe)),onClickToast:fe=>{if(fe.targetKey){const Ce=ie(fe.targetKey);Ce&&(k(Ie.get(Ce.tabKey)??0),Br(Ce),he({tabKey:Ce.tabKey,nonce:Date.now()}))}},showOnboarding:m,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}y(!1)}})]})}function cd({machineId:t,registeredMachineId:s,sendDaemonCommand:r,onNicknameSynced:n,logsEndRef:i}){const[o,c]=a.useState([]),[u,d]=a.useState(null),[x,l]=a.useState(null),[f,h]=a.useState(!1),[m,y]=a.useState(null),[p,g]=a.useState(!1),[b,v]=a.useState(""),S=a.useRef(null),B=a.useCallback(A=>{S.current=A},[]),j=a.useCallback((A,M,G=!1)=>{c(Y=>[...Y.slice(-100),{timestamp:Date.now(),level:A,message:M}]),setTimeout(()=>{var Y;return(Y=i.current)==null?void 0:Y.scrollIntoView({behavior:"smooth"})},100),G&&St.showToast(M,A==="error"||A==="warn"?"warning":"success")},[i]),C=a.useCallback(A=>{const M=A instanceof Error?A.message:String(A||"");return M.includes("P2P command timeout")||M.includes("P2P not connected")||M.includes("P2P not available")},[]),w=a.useCallback(async(A,M)=>{var G;if(!t||u)return!1;d(A),j("info",`Launching ${Ye(A)}${M!=null&&M.workspace?` in ${M.workspace}`:""}...`);try{const Y={ideType:A,enableCdp:!0};(G=M==null?void 0:M.workspace)!=null&&G.trim()?Y.workspace=M.workspace.trim():M!=null&&M.useDefaultWorkspace&&(Y.useDefaultWorkspace=!0);const ue=await r(t,"launch_ide",Y);return j(ue!=null&&ue.success?"info":"error",ue!=null&&ue.success?`${Ye(A)} launched`:`Failed: ${ue==null?void 0:ue.error}`,!0),!!(ue!=null&&ue.success)}catch(Y){return j("error",`Launch error: ${Y.message}`,!0),!1}finally{d(null)}},[t,u,j,r]),k=a.useCallback(async A=>{if(!t)return{success:!1};const{cliType:M,dir:G,workspaceId:Y,useDefaultWorkspace:ue,useHome:ve,argsStr:Te,model:ee,resumeSessionId:Me}=A;if(!M)return j("warn","Select a CLI or ACP provider first",!0),{success:!1};const U=Te?Te.split(/\s+/).filter(Boolean):void 0,ae=(G==null?void 0:G.trim())||(Y?"(saved id)":ue?"(default workspace)":ve?"(home)":"");j("info",`Launching ${M}${ae?` in ${ae}`:""}${ee?` (model: ${ee})`:""}...`),l(M);try{const X={cliType:M,cliArgs:U,initialModel:ee||void 0};G!=null&&G.trim()?X.dir=G.trim():Y?X.workspaceId=Y:ue?X.useDefaultWorkspace=!0:ve&&(X.useHome=!0),Me&&(X.resumeSessionId=Me);const pe=await r(t,"launch_cli",X),me=(pe==null?void 0:pe.result)||pe;return pe!=null&&pe.success?(j("info",`${M} launched`,!0),(me==null?void 0:me.launchSource)==="home"?j("info","📂 Running in home directory (explicit choice)"):(me==null?void 0:me.launchSource)==="defaultWorkspace"&&j("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:me==null?void 0:me.sessionId}):(j("error",`Failed: ${(pe==null?void 0:pe.error)||(me==null?void 0:me.error)}`,!0),(pe==null?void 0:pe.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&y({cliType:M,argsStr:Te,model:ee}),{success:!1,sessionId:me==null?void 0:me.sessionId})}catch(X){return C(X)?(j("warn",`${M} launch requested — waiting for session to appear...`,!0),{success:!1,pending:!0}):(j("error",`Launch error: ${X.message}`,!0),{success:!1})}finally{l(null)}},[t,j,C,r]),E=a.useCallback(async(A,M,G,Y)=>t?A?M.trim()?k({cliType:A,dir:M,argsStr:G,model:Y}):(y({cliType:A,argsStr:G,model:Y}),{success:!1}):(j("warn","Select a provider",!0),{success:!1}):{success:!1},[t,j,k]),L=a.useCallback(async(A,M,G)=>{if(t&&window.confirm(`Stop ${A}?
|
|
53
|
+
This will terminate the process.`))try{const Y=await r(t,"stop_cli",{cliType:A,dir:M,targetSessionId:G});Y!=null&&Y.success?j("info",`${A} stopped`,!0):j("error",`Stop failed: ${(Y==null?void 0:Y.error)||"Unknown error"}`,!0)}catch(Y){j("error",`Stop failed: ${Y.message}`,!0)}},[t,j,r]),$=a.useCallback(async A=>{try{await r(A.daemonId,"restart_ide",{ideType:A.type}),j("info",`${Ye(A.type)} restart initiated`,!0)}catch(M){j("error",`Restart failed: ${M.message}`,!0)}},[j,r]),R=a.useCallback(async A=>{if(window.confirm(`Stop ${Ye(A.type)}?
|
|
54
|
+
This will disconnect CDP and optionally kill the process.`))try{const M=await r(A.daemonId,"stop_ide",{ideType:A.type,killProcess:!0});M!=null&&M.success?j("info",`${Ye(A.type)} stopped`,!0):j("error",`Stop failed: ${(M==null?void 0:M.error)||"Unknown error"}`,!0)}catch(M){j("error",`Stop failed: ${M.message}`,!0)}},[j,r]),T=a.useCallback(async()=>{if(t)try{const A=await r(t,"detect_ides",{});j("info",`Found ${((A==null?void 0:A.result)||[]).length} IDE(s)`,!0)}catch(A){j("error",`Detection failed: ${A.message}`,!0)}},[t,j,r]),O=a.useCallback(async A=>{if(!t||!A.trim())return!1;h(!0);try{const M=await r(t,"workspace_add",{path:A.trim()});return M!=null&&M.success?(j("info",`Workspace added: ${A.trim()}`),!0):(j("error",(M==null?void 0:M.error)||"workspace_add failed"),!1)}catch(M){return j("error",M.message),!1}finally{h(!1)}},[t,j,r]),H=a.useCallback(async A=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const M=await r(t,"workspace_remove",{id:A});M!=null&&M.success?j("info","Workspace removed",!0):j("error",(M==null?void 0:M.error)||"workspace_remove failed",!0)}catch(M){j("error",M.message,!0)}finally{h(!1)}}},[t,j,r]),D=a.useCallback(async A=>{var M;if(t){h(!0);try{const G=await r(t,"workspace_set_default",A===null?{clear:!0}:{id:A});if(G!=null&&G.success){j("info",A?"Default workspace updated":"Default workspace cleared",!0);const Y=typeof G.defaultWorkspacePath=="string"?G.defaultWorkspacePath:"";Y&&((M=S.current)==null||M.call(S,Y))}else j("error",(G==null?void 0:G.error)||"workspace_set_default failed",!0)}catch(G){j("error",G.message,!0)}finally{h(!1)}}},[t,j,r]),F=a.useCallback(async A=>{var G;if(!t||!A.trim())return;const M=A.trim();h(!0);try{const Y=await r(t,"workspace_set_default",{path:M});Y!=null&&Y.success?(j("info","Default workspace set from history"),(G=S.current)==null||G.call(S,M)):j("error",(Y==null?void 0:Y.error)||"Could not set default (path missing on disk?)")}catch(Y){j("error",Y.message)}finally{h(!1)}},[t,j,r]),_=a.useCallback(async()=>{if(t)try{if(await r(t,"set_machine_nickname",{nickname:b}),n)try{await n({machineRuntimeId:t,registeredMachineId:s,nickname:b})}catch(A){j("warn",`Live nickname updated, but account sync failed: ${A.message}`)}j("info",`Nickname set to "${b||"(cleared)"}"`),g(!1)}catch(A){j("error",`Failed: ${A.message}`)}},[t,b,s,j,n,r]);return{logs:o,launchingIde:u,launchingAgentType:x,workspaceBusy:f,launchPick:m,setLaunchPick:y,editingNickname:p,setEditingNickname:g,nicknameInput:b,setNicknameInput:v,addLog:j,handleLaunchIde:w,runLaunchCliCore:k,handleLaunchCli:E,handleStopCli:L,handleRestartIde:$,handleStopIde:R,handleDetectIdes:T,handleWorkspaceAdd:O,handleWorkspaceRemove:H,handleWorkspaceSetDefault:D,handleWorkspaceResumePath:F,handleSaveNickname:_,setOnDefaultWorkspaceChanged:B}}function ld({machineId:t,machine:s,ideSessions:r,cliSessions:n,acpSessions:i,actions:o,sendDaemonCommand:c}){const{workspaceBusy:u,handleWorkspaceAdd:d,handleWorkspaceRemove:x,handleWorkspaceSetDefault:l}=o,[f,h]=a.useState(!1),[m,y]=a.useState(""),[p,g]=a.useState([]),[b,v]=a.useState(!1),[S,B]=a.useState(""),j=a.useCallback(async L=>{v(!0),B("");try{const $=await Rr(c,t,L);y($.path),g($.directories)}catch($){B($ instanceof Error?$.message:"Could not load folder")}finally{v(!1)}},[t,c]),C=a.useCallback(()=>{var $;h(!0);const L=zs(s.platform,[s.defaultWorkspacePath,($=s.workspaces[0])==null?void 0:$.path]);j(L)},[j,s.defaultWorkspacePath,s.platform,s.workspaces]),w=s.availableMem??s.freeMem,k=s.totalMem>0?Math.min(100,Math.max(0,Math.round((s.totalMem-w)/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(hs,{icon:e.jsx(jr,{size:16}),label:"Uptime",value:ho(s.uptime)}),e.jsx(hs,{icon:e.jsx(ot,{size:16}),label:"IDEs",value:`${r.length}`}),e.jsx(hs,{icon:e.jsx(kr,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(hs,{icon:e.jsx(Ui,{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(Gr,{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(Gr,{value:k,max:100,label:"Memory",color:"#3b82f6",detail:`${Xr(s.totalMem-w)} / ${Xr(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(Gt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:u,value:s.defaultWorkspaceId||"",onChange:L=>void l(L.target.value===""?null:L.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(s.workspaces||[]).map(L=>e.jsx("option",{value:L.id,children:L.label||L.path},L.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:u,onClick:C,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(L=>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:[L.id===s.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Os(L.path,L.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:L.path,children:L.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:u,onClick:()=>void x(L.id),children:"Remove"})]},L.id))})]}),f&&e.jsx(Fs,{title:"Add workspace",description:"Browse the machine like a normal explorer, then add the current folder as a saved workspace.",currentPath:m,directories:p,busy:b,error:S,confirmLabel:"Add workspace",onClose:()=>h(!1),onNavigate:L=>{j(L)},onConfirm:L=>{(async()=>{if(!L)return;await d(L)&&h(!1)})()}})]})}const _n=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],dd=[{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 ud({machineId:t,provider:s,sendDaemonCommand:r,onClose:n}){const[i,o]=a.useState("config"),[c,u]=a.useState("codex-cli"),[d,x]=a.useState([]),[l,f]=a.useState(""),[h,m]=a.useState([]),[y,p]=a.useState(""),g=a.useRef(null),b=a.useRef(null),v=k=>{x(E=>E.includes(k)?E.filter(L=>L!==k):[...E,k])},S=()=>x([..._n]),B=()=>x([]);a.useEffect(()=>{var k;(k=g.current)==null||k.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{b.current&&clearInterval(b.current)},[]);const j=a.useCallback(()=>{b.current&&clearInterval(b.current),b.current=setInterval(async()=>{try{const k=await r(t,"provider_auto_fix_status",{providerType:s.type});(k==null?void 0:k.running)===!1&&i==="running"&&(o("done"),m(E=>[...E,`
|
|
55
|
+
✅ Auto-fix completed!`]),b.current&&clearInterval(b.current))}catch{}},3e3)},[t,s.type,r,i]),C=async()=>{if(d.length!==0){o("running"),m(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${d.join(", ")}`,l?`💬 Comment: ${l}`:"",""]),p("");try{const k=await r(t,"provider_auto_fix",{providerType:s.type,functions:d,agent:c,...l?{comment:l}:{}});k!=null&&k.success&&(k!=null&&k.started||k!=null&&k.running)?(m(E=>[...E,"✅ Agent started. Monitoring progress..."]),j()):(o("error"),p((k==null?void 0:k.error)||"Failed to start auto-fix"))}catch(k){o("error"),p((k==null?void 0:k.message)||"Connection failed")}}},w=async()=>{try{await r(t,"provider_auto_fix_cancel",{providerType:s.type}),m(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:n,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:n,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:dd.map(k=>e.jsxs("button",{onClick:()=>u(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:S,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:B,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:_n.map(k=>e.jsxs("button",{onClick:()=>v(k),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:d.includes(k)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:d.includes(k)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:d.includes(k)?"#a78bfa":"var(--text-secondary)"},children:[d.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:l,onChange:k=>f(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:g})]}),y&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:y})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&d.length>0&&`${d.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:n,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:C,disabled:d.length===0,className:"machine-btn",style:{background:d.length>0?"color-mix(in srgb, var(--accent-primary) 15%, transparent)":void 0,borderColor:d.length>0?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":void 0,color:d.length>0?"#a78bfa":void 0,opacity:d.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:w,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),m([]),p("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:n,className:"machine-btn",children:"Close"})]})]})]})]})})}function pd({machineId:t,providers:s,sendDaemonCommand:r,onClose:n,onCreated:i}){var j;const o=s.filter(C=>C.category==="ide"),[c,u]=a.useState(((j=o[0])==null?void 0:j.type)||""),[d,x]=a.useState(""),[l,f]=a.useState(""),[h,m]=a.useState(!1),[y,p]=a.useState(""),[g,b]=a.useState(!1),v=C=>{const w=C.toLowerCase().replace(/[^a-z0-9-]/g,"");x(w),(!l||l===S(d))&&f(S(w))},S=C=>C.split("-").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" "),B=async()=>{if(!(!d||!l||!c)){m(!0),p("");try{const C=await r(t,"provider_clone",{type:d,name:l,category:"ide",location:"user",cloneFrom:c});C!=null&&C.success||C!=null&&C.created?(b(!0),i==null||i(d)):p((C==null?void 0:C.error)||"Failed to create provider")}catch(C){p((C==null?void 0:C.message)||"Connection failed")}m(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:n,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:C=>C.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:g?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:d})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",d,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",d]})," 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(C=>e.jsxs("button",{onClick:()=>u(C.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===C.type?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:c===C.type?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:C.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===C.type?"#a78bfa":"var(--text-secondary)"},children:C.displayName})]},C.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:d,onChange:C=>v(C.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/",d||"...","/"]})]})]}),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:l,onChange:C=>f(C.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),y&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:y})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:g?e.jsx("button",{onClick:n,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:n,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:B,disabled:!d||!l||h,className:"machine-btn",style:{background:d&&l?"rgba(34,197,94,0.12)":void 0,borderColor:d&&l?"rgba(34,197,94,0.3)":void 0,color:d&&l?"#86efac":void 0,opacity:!d||!l||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function md({machineId:t,providers:s,sendDaemonCommand:r}){const[n,i]=a.useState([]),[o,c]=a.useState(!1),[u,d]=a.useState(null),[x,l]=a.useState("all"),[f,h]=a.useState(null),[m,y]=a.useState(!1),p=a.useCallback(async()=>{var b;if(t){c(!0);try{const v=await r(t,"get_provider_settings",{}),S=(v==null?void 0:v.result)||v;if(v!=null&&v.success&&(S!=null&&S.settings)){const B=[];for(const[j,C]of Object.entries(S.settings)){const w=s.find(k=>k.type===j);B.push({type:j,displayName:(w==null?void 0:w.displayName)||j,icon:(w==null?void 0:w.icon)||"",category:(w==null?void 0:w.category)||"unknown",schema:C,values:((b=S.values)==null?void 0:b[j])||{}})}B.sort((j,C)=>j.category.localeCompare(C.category)||j.displayName.localeCompare(C.displayName)),i(B)}}catch{}c(!1)}},[t,s,r]);a.useEffect(()=>{n.length===0&&p()},[]);const g=async(b,v,S)=>{d(`${b}.${v}`),i(B=>B.map(j=>j.type===b?{...j,values:{...j.values,[v]:S}}:j));try{const B=await r(t,"set_provider_setting",{providerType:b,key:v,value:S});B!=null&&B.success||p()}catch{p()}d(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:()=>l(b),className:`machine-btn text-[10px] px-2 py-0.5 ${x===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>y(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:p,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&n.filter(b=>b.category===x).length>1&&(()=>{const b=n.filter(j=>j.category===x),v=new Map;for(const j of b)for(const C of j.schema){if(C.type!=="boolean")continue;const w=v.get(C.key),k=!!(j.values[C.key]??C.default);w?(w.onCount+=k?1:0,w.total+=1):v.set(C.key,{label:C.label||C.key,onCount:k?1:0,total:1})}const S=[...v.entries()].filter(([,j])=>j.total===b.length);if(S.length===0)return null;const B=async(j,C)=>{for(const w of b)await g(w.type,j,C)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",x.toUpperCase()," providers (",b.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(([j,C])=>{const w=C.onCount===C.total,k=C.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:C.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",C.onCount,"/",C.total,")"]}),e.jsx("button",{onClick:()=>void B(j,!0),disabled:w,className:`machine-btn text-[9px] px-1.5 py-px ${w?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void B(j,!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"})]},j)})})]})})(),o&&n.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:n.filter(b=>x==="all"||b.category===x).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(v=>v.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(v=>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:[v.label||v.key,u===`${b.type}.${v.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),v.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:v.description})]}),e.jsx("div",{className:"shrink-0",children:v.type==="boolean"?e.jsx("button",{onClick:()=>g(b.type,v.key,!(b.values[v.key]??v.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:b.values[v.key]??v.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[v.key]??v.default?21:3}})}):v.type==="number"?e.jsx("input",{type:"number",value:b.values[v.key]??v.default??0,min:v.min,max:v.max,onChange:S=>{const B=parseInt(S.target.value)||0;v.min!==void 0&&B<v.min||v.max!==void 0&&B>v.max||g(b.type,v.key,B)},className:"machine-input w-20 text-center text-[11px]"}):v.type==="select"&&v.options?e.jsx("select",{value:b.values[v.key]??v.default??"",onChange:S=>g(b.type,v.key,S.target.value),className:"machine-input text-[11px]",children:v.options.map(S=>e.jsx("option",{value:S,children:S},S))}):e.jsx("input",{type:"text",value:b.values[v.key]??v.default??"",onBlur:S=>g(b.type,v.key,S.target.value),className:"machine-input w-[120px] text-[11px]"})})]},v.key))})]},b.type))}),f&&e.jsx(ud,{machineId:t,provider:f,sendDaemonCommand:r,onClose:()=>h(null)}),m&&e.jsx(pd,{machineId:t,providers:s,sendDaemonCommand:r,onClose:()=>y(!1),onCreated:()=>{y(!1),p()}})]})}function fd({machineId:t,sendDaemonCommand:s}){const[r,n]=a.useState([]),[i,o]=a.useState(0),[c,u]=a.useState(!0),[d,x]=a.useState("debug"),l=a.useRef(null),f=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const y=await s(t,"get_logs",{count:200,minLevel:d,since:i}),p=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&Array.isArray(p==null?void 0:p.logs)&&p.logs.length>0){n(b=>[...b,...p.logs.map(S=>({timestamp:S.ts,level:S.level,message:`[${S.category}] ${S.message}`}))].slice(-300));const g=Math.max(...p.logs.map(b=>b.ts));o(g)}}catch{}};h();const m=setInterval(h,3e3);return()=>clearInterval(m)},[t,c,i,d,s]),a.useEffect(()=>{if(c&&r.length>0){const h=f.current?"smooth":"instant";setTimeout(()=>{var m;(m=l.current)==null||m.scrollIntoView({behavior:h}),f.current=!0},50)}},[r.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:()=>{x(h),n([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${d===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:[r.length," entries"]}),e.jsx("button",{onClick:()=>u(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{n([]),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:[r.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),r.map((h,m)=>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})]},m)),e.jsx("div",{ref:l})]})]})}function xd({machine:t,launchPick:s,actions:r}){const{runLaunchCliCore:n,setLaunchPick:i}=r;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),n({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),n({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),n({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 ir({icon:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-text-muted tracking-[0.14em] uppercase",children:[t,e.jsx("span",{children:s})]})}function or({children:t,className:s=""}){return e.jsx("div",{className:`rounded-2xl border border-[#ffffff0a] bg-bg-surface/70 backdrop-blur-sm p-3 ${s}`,children:t})}function hd({machineEntry:t,providers:s,recentLaunches:r,currentConversations:n,onUpgradeDaemon:i,onOpenRecent:o,onOpenConversation:c}){const u=n.slice(0,6),d=r.slice(0,4),x=l=>l==="ide"?"IDE":l==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-4 md:min-w-[300px] md:max-w-[360px] shrink-0 md:h-full overflow-y-auto",children:[u.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ir,{icon:e.jsx(vt,{size:13}),children:"Current Chats"}),e.jsx(or,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:u.map(l=>{const f=gr(l);return e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>c(l),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate group-hover:text-accent-primary transition-colors",children:l.displayPrimary}),f>0&&e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:Xn(f)})]}),e.jsx("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:l.displaySecondary})]},l.tabKey)})})})]}),d.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ir,{icon:e.jsx(jr,{size:13}),children:"Recent Launches"}),e.jsx(or,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:d.map(l=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>o(l),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:l.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[x(l.kind),l.subtitle?` · ${l.subtitle}`:""]})]},l.id))})})]}),t.versionMismatch&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ir,{icon:e.jsx(Bs,{size:13}),children:"Daemon Update"}),e.jsx(or,{className:"border-amber-500/20 bg-amber-500/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Version mismatch detected"}),e.jsx("div",{className:"text-xs text-text-secondary leading-relaxed",children:"This machine is running a different daemon version than the current app. Update it before starting more sessions."}),e.jsxs("button",{type:"button",className:"inline-flex items-center justify-center gap-2 px-3 py-2 rounded-xl bg-amber-500/12 border border-amber-500/20 text-amber-300 hover:bg-amber-500/18 transition-colors",onClick:i,children:[e.jsx(Ds,{size:13}),e.jsx("span",{className:"text-sm font-medium",children:"Update daemon"})]})]})})]})]})}function bd(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const gd={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 Mn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function yd(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function cr({category:t,machine:s,machineId:r,providers:n,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:u,initialWorkspaceId:d,initialWorkspacePath:x}){const l=Yt(),{handleLaunchIde:f,handleStopCli:h,handleRestartIde:m,handleStopIde:y,handleDetectIdes:p,launchingIde:g,launchingAgentType:b,addLog:v}=c,[S,B]=a.useState(null),j=a.useCallback(N=>{N&&l({pathname:"/",search:`?activeTab=${encodeURIComponent(N)}`})},[l]),C=gd[t],w=t==="ide",k=t==="acp",E=a.useMemo(()=>n.filter(N=>N.category===t),[t,n]),L=a.useMemo(()=>new Map(E.map(N=>[N.type,N.displayName||N.type])),[E]),[$,R]=a.useState(""),[T,O]=a.useState(""),[H,D]=a.useState([]),[F,_]=a.useState(""),[A,M]=a.useState(""),[G,Y]=a.useState([]),[ue,ve]=a.useState(!1),[Te,ee]=a.useState(""),[Me,U]=a.useState(x?"__custom__":d||s.defaultWorkspaceId||""),[ae,X]=a.useState(x||""),[pe,me]=a.useState([]),[se,de]=a.useState(!1),[xe,oe]=a.useState(""),[J,ce]=a.useState([]),[Q,he]=a.useState(!1),[I,re]=a.useState(""),W=a.useRef(null),[z,te]=a.useState(null),le=a.useRef("__home__"),[Ne,Pe]=a.useState("__home__"),[q,be]=a.useState(!1),Ae=a.useRef(0),$e=pe.filter(N=>!i.some(V=>V.type===N&&ct(V.status)!=="stopped")),He=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!Me&&U(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(x){U("__custom__"),X(x);return}d&&(U(d),X(""))},[d,x]);const Oe=(()=>{if(Me==="__custom__")return ae.trim();if(!Me)return"";const N=(s.workspaces||[]).find(V=>V.id===Me);return(N==null?void 0:N.path)||""})(),Qe=a.useCallback(N=>{const V=He.current[N];V&&(clearTimeout(V),delete He.current[N]),me(ye=>ye.includes(N)?ye.filter(we=>we!==N):ye)},[]),Z=a.useRef(new Set),ge=a.useCallback(async N=>{if(u){he(!0),re("");try{const V=await Rr(u,r,N);oe(V.path),X(V.path),ce(V.directories)}catch(V){re(V instanceof Error?V.message:"Could not load folder")}finally{he(!1)}}},[r,u]),K=a.useCallback(()=>{var V;if(!u)return;U("__custom__"),de(!0);const N=zs(s.platform,[ae.trim(),Oe,s.defaultWorkspacePath,(V=s.workspaces[0])==null?void 0:V.path]);ge(N)},[ae,ge,s.defaultWorkspacePath,s.platform,s.workspaces,Oe,u]),P=a.useCallback(N=>{const V=String(N.workspace||"").trim();if(!V)return;const ye=(s.workspaces||[]).find(we=>Mn(we.path)===Mn(V));if(ye){U(ye.id),X("");return}U("__custom__"),X(V)},[s.workspaces]),ne=a.useCallback(async N=>{if(!u||!N||t!=="cli"){Y([]),ve(!1),ee("");return}const V=Ae.current+1;Ae.current=V,ve(!0),ee("");try{const ye=await u(r,"list_saved_sessions",{providerType:N,kind:"cli",limit:30});if(Ae.current!==V)return;const we=(ye==null?void 0:ye.result)??ye;Y(Array.isArray(we==null?void 0:we.sessions)?we.sessions:[])}catch(ye){if(Ae.current!==V)return;Y([]),ee(ye instanceof Error?ye.message:"Could not load saved sessions")}finally{if(Ae.current!==V)return;ve(!1)}},[t,r,u]),ie=a.useCallback(N=>{if(t==="ide"||!N){D([]);return}D(Ra(r,N))},[t,r]);a.useEffect(()=>{if(M(""),ie($),t!=="cli"||!$){Y([]),ee(""),ve(!1);return}ne($)},[t,ie,ne,$]),a.useEffect(()=>{if(!A)return;const N=G.find(V=>V.providerSessionId===A);N!=null&&N.canResume||M("")},[G,A]);const Se=a.useCallback((N,V)=>{W.current=V,le.current=N.selectedWorkspaceKey||"__home__",Pe(N.selectedWorkspaceKey||"__home__"),te(N)},[]),We=a.useCallback(()=>{W.current&&(be(!0),W.current().finally(()=>{W.current=null,be(!1),te(null)}))},[]),Ee=a.useCallback(N=>{if(!N)return;me(ye=>ye.includes(N)?ye:[...ye,N]);const V=He.current[N];V&&clearTimeout(V),He.current[N]=setTimeout(()=>{me(ye=>ye.includes(N)?ye.filter(we=>we!==N):ye),delete He.current[N]},2e4)},[]);a.useEffect(()=>{for(const V of i)ct(V.status)!=="stopped"&&(pe.includes(V.type)&&!Z.current.has(V.type)&&(Z.current.add(V.type),v("info",`${L.get(V.type)||V.type} launched`,!0)),Qe(V.type));const N=new Set(i.filter(V=>ct(V.status)!=="stopped").map(V=>V.type));Z.current.forEach(V=>{!pe.includes(V)&&!N.has(V)&&Z.current.delete(V)})},[v,Qe,i,pe,L]),a.useEffect(()=>()=>{Object.values(He.current).forEach(clearTimeout),He.current={}},[]);const[Ie,Fe]=a.useState({}),[Ve,st]=a.useState(null);a.useEffect(()=>{if(!w||!r||!u)return;(async()=>{try{const V=await u(r,"get_ide_extensions",{}),ye=(V==null?void 0:V.result)||V;ye!=null&&ye.success&&(ye!=null&&ye.ideExtensions)&&Fe(ye.ideExtensions)}catch{}})()},[w,r,u]);const ut=N=>w?Ye(N.type):t==="cli"?N.cliName:N.acpName,pt=w?s.detectedIdes||[]:[],lt=a.useCallback(async N=>{const V=(N==null?void 0:N.type)||$,ye=(N==null?void 0:N.workspacePath)??Oe;if(w){await f(V,ye?{workspace:ye}:void 0)&&Ee(V);return}const we=await c.runLaunchCliCore({cliType:V,dir:N!=null&&N.workspaceId?void 0:ye||void 0,workspaceId:(N==null?void 0:N.workspaceId)||void 0,useHome:(N==null?void 0:N.useHome)||!(N!=null&&N.workspaceId)&&!ye,argsStr:(N==null?void 0:N.argsStr)??(T||void 0),model:(N==null?void 0:N.model)??(k&&F||void 0),resumeSessionId:(N==null?void 0:N.resumeSessionId)||!k&&t==="cli"&&V===$&&A||void 0});if(we.success||we.pending){const Le=(N==null?void 0:N.argsStr)??T;!w&&(Le!=null&&Le.trim())&&(Ea(r,V,Le),ie(V)),Ee(V),we.success&&we.sessionId&&j(we.sessionId)}},[c,f,k,w,T,F,ie,Ee,r,j,Oe,A,$]),xt=()=>{var we;const N=w?Ye($):L.get($)||$,{options:V,selectedKey:ye}=Et({machine:s,currentWorkspaceId:Me&&Me!=="__custom__"?Me:null,currentWorkspacePath:Oe});Se({title:`Launch ${N}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:V,selectedWorkspaceKey:ye,details:[{label:"Mode",value:C.label},{label:"Provider",value:N},...!w&&t==="cli"&&A?[{label:"Resume",value:((we=G.find(Le=>Le.providerSessionId===A))==null?void 0:we.title)||A}]:[],...!w&&T.trim()?[{label:"Arguments",value:T.trim()}]:[],...k&&F.trim()?[{label:"Model",value:F.trim()}]:[]]},async()=>{const Le=V.find(_e=>_e.key===le.current);Le!=null&&Le.workspaceId?(U(Le.workspaceId),X("")):Le!=null&&Le.workspacePath?(U("__custom__"),X(Le.workspacePath)):(U(""),X("")),await lt({workspaceId:(Le==null?void 0:Le.workspaceId)??null,workspacePath:(Le==null?void 0:Le.workspacePath)??"",useHome:!(Le!=null&&Le.workspaceId)&&!(Le!=null&&Le.workspacePath)})})},De=N=>{w?y(N):h(N.type,N.workspace,N.id)},Wt=a.useCallback(async(N,V,ye=!1)=>{if(N.mode===V){ye&&N.sessionId&&j(N.sessionId);return}if(!u||!N.sessionId){ye&&N.sessionId&&j(N.sessionId);return}try{await u(r,"set_cli_view_mode",{targetSessionId:N.sessionId,cliType:N.type,mode:V}),ye&&j(N.sessionId)}catch(we){yd(we)?console.warn("Skipped CLI view mode switch:",we instanceof Error?we.message:String(we)):console.error("Failed to switch CLI view mode:",we)}},[r,j,u]),Xt=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:Me,onChange:N=>{const V=N.target.value;if(U(V),V==="__custom__"&&u){K();return}V!=="__custom__"&&X("")},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(N=>e.jsxs("option",{value:N.id,children:[N.id===s.defaultWorkspaceId?"⭐ ":"",Os(N.path,N.label)]},N.id)),e.jsx("option",{value:"__custom__",children:u?"📁 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:u?"📁 Select workspace…":"✏️ Custom path…"})]})}),Me==="__custom__"&&(u?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:K,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:ae,onChange:N=>X(N.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:Me==="__custom__"?Oe?e.jsx("span",{className:"font-mono truncate block",title:Oe,children:Oe}):u?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":Oe?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:Me===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:Oe,children:Oe})]}):"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 ${C.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 ",C.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:w?pt.length>0?pt.map(N=>{const V=i.find(Ue=>(Ue.type||"").toLowerCase()===(N.type||"").toLowerCase()&&ct(Ue.status)!=="stopped"),ye=N.running||!!V,we=!!V&&V.cdpConnected,Le=pe.includes(N.type||N.id||""),_e=$===(N.type||"");return e.jsxs("button",{onClick:()=>{if(we&&V){const Ue=V.sessionId;Ue?l(`/dashboard?activeTab=${encodeURIComponent(Ue)}`,{state:{openRemoteForTabKey:Ue}}):l("/dashboard",{state:{openRemoteForTabKey:V.id}});return}Le||R(Ue=>Ue===(N.type||"")?"":N.type||"")},disabled:!!g||Le,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${we?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":_e?"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:g&&g!==N.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(N.type)}),ye&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${we?"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:N.name||Ye(N.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${we?"text-green-400":Le?"text-orange-400":_e?"text-accent-primary":"text-text-muted"}`,children:we?"Open Session":Le?"Starting...":_e?"Configure":"Select"})]})]},N.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:p,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(Di,{size:14})," Scan System"]})]}):E.length>0?E.map(N=>{const V=$===N.type,ye=pe.includes(N.type),Le=!!i.find(_e=>_e.type===N.type&&ct(_e.status)!=="stopped");return e.jsxs("button",{onClick:()=>R(_e=>_e===N.type?"":N.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${V?"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:N.icon}),Le&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:N.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ye?"text-orange-400":V?"text-accent-primary":"text-text-muted"}`,children:ye?"Starting...":V?"Configure":"Select"})]})]},N.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"]})}),$&&(w?pt.find(N=>N.type===$):E.find(N=>N.type===$))&&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:w?Ye($):L.get($)||$})]}),Xt,!w&&e.jsxs("div",{className:"flex flex-col gap-3",children:[!k&&t==="cli"&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Resume from History"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void ne($),disabled:!$||ue,children:ue?"Loading…":"Refresh"})]}),e.jsxs("select",{value:A,onChange:N=>{const V=N.target.value;if(M(V),!V)return;const ye=G.find(we=>we.providerSessionId===V);!ye||!ye.canResume||P(ye)},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",children:[e.jsx("option",{value:"",children:"Start a new CLI session"}),G.map(N=>e.jsxs("option",{value:N.providerSessionId,disabled:!N.canResume,children:[N.title||N.providerSessionId,N.canResume?"":" (workspace missing)"]},N.providerSessionId))]}),A&&(()=>{const N=G.find(V=>V.providerSessionId===A);return N?e.jsxs("div",{className:"text-[10px] text-text-muted break-all leading-relaxed",children:[e.jsx("div",{className:"font-mono",children:N.providerSessionId}),e.jsx("div",{children:N.workspace||"Workspace unknown"})]}):null})(),Te&&e.jsx("div",{className:"text-[10px] text-red-400",children:Te}),!ue&&!Te&&G.length===0&&e.jsx("div",{className:"text-[10px] text-text-muted",children:"No saved sessions found for this provider."})]}),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:F,onChange:N=>_(N.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:T,onChange:N=>O(N.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"}),H.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:H.map(N=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>O(N),title:N,children:N},N))})]})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:xt,disabled:!!b||!!g||pe.includes($),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===$||g===$?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+pe.filter(N=>!i.some(V=>V.type===N&&ct(V.status)!=="stopped")).length,")"]}),i.length===0&&$e.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 ",C.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[$e.map(N=>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(N)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:w?Ye(N):L.get(N)||N}),e.jsx("div",{className:"text-[11px] text-text-muted",children:b===N?"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:${N}`)),i.map(N=>{const V=w?N:null,ye=k?N:null,we=!w&&!k?N:null,Le=ct(N.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(N.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ut(N),(V==null?void 0:V.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",V.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:N.workspace||"—"}),(ye==null?void 0:ye.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",ye.currentModel]}),(ye==null?void 0:ye.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",ye.currentPlan]}),(we==null?void 0:we.mode)&&e.jsx("span",{className:we.mode==="chat"?"text-violet-400":"text-text-secondary",children:we.mode==="chat"?"Chat view":"Terminal view"})]}),we&&(we.runtimeKey||we.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[we.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 ",we.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 _e;(_e=navigator.clipboard)==null||_e.writeText(`adhdev attach ${we.runtimeKey}`),B(we.runtimeKey||null),window.setTimeout(()=>{B(Ue=>Ue===we.runtimeKey?null:Ue)},1200)},children:S===we.runtimeKey?"Copied":"Copy"})]}),we.runtimeWriteOwner&&e.jsx("span",{style:{color:we.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:we.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:bd(we.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Le==="stopped"?"bg-red-500/[0.08] text-red-500":Le==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Le}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const _e=N.sessionId;if(_e){l(`/dashboard?activeTab=${encodeURIComponent(_e)}`,{state:{openRemoteForTabKey:_e}});return}l("/dashboard",{state:{openRemoteForTabKey:N.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(ot,{size:13})}),e.jsx("button",{onClick:()=>{const _e=N.workspace||"",{options:Ue,selectedKey:Ke}=Et({machine:s,currentWorkspacePath:_e});Se({title:`Restart ${Ye(N.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:Ue,selectedWorkspaceKey:Ke,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Ye(N.type)}]},async()=>{const Ge=Ue.find(kt=>kt.key===le.current),qe=(Ge==null?void 0:Ge.workspacePath)??"";if(qe&&qe!==_e){await lt({type:N.type,workspacePath:qe});return}await m(N)})},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(Ds,{size:14})})]}),k&&e.jsx("button",{onClick:()=>{const _e=N.sessionId;_e&&j(_e)},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:!N.sessionId,children:e.jsx(vt,{size:14})}),we&&Le!=="stopped"&&e.jsxs(e.Fragment,{children:[we.mode&&e.jsx(Ir,{mode:we.mode,onChange:_e=>void Wt(we,_e,!1),compact:!0}),e.jsx("button",{onClick:()=>{const _e=N.sessionId;_e&&j(_e)},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:!N.sessionId,children:we.mode==="chat"?e.jsx(vt,{size:14}):e.jsx(ot,{size:13})})]}),Le==="stopped"?e.jsx("button",{onClick:()=>{const _e=N.workspace||"",Ue=w?Ye(N.type):ut(N),{options:Ke,selectedKey:Ge}=Et({machine:s,currentWorkspacePath:_e});Se({title:`Launch ${Ue}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:Ke,selectedWorkspaceKey:Ge,details:[{label:"Mode",value:C.label},{label:"Provider",value:Ue}]},async()=>{const qe=Ke.find(kt=>kt.key===le.current);await lt({type:N.type,workspaceId:(qe==null?void 0:qe.workspaceId)??null,workspacePath:(qe==null?void 0:qe.workspacePath)??"",useHome:!(qe!=null&&qe.workspaceId)&&!(qe!=null&&qe.workspacePath),model:ye==null?void 0:ye.currentModel})})},disabled:pe.includes(N.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:pe.includes(N.type)?"⏳":e.jsx(Nr,{size:14})}):e.jsx("button",{onClick:()=>De(N),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(Dt,{size:14})})]})]}),V&&V.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:V.aiAgents.map(_e=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Qn(_e.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[_e.name," · ",ct(_e.status)]},_e.id))}),V&&(Ie[V.type]||[]).length>0&&u&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(Ie[V.type]||[]).map(_e=>e.jsxs("button",{disabled:Ve===`${V.type}.${_e.type}`,onClick:async()=>{const Ue=`${V.type}.${_e.type}`;st(Ue);try{await u(r,"set_ide_extension",{ideType:V.type,extensionType:_e.type,enabled:!_e.enabled}),Fe(Ke=>({...Ke,[V.type]:(Ke[V.type]||[]).map(Ge=>Ge.type===_e.type?{...Ge,enabled:!Ge.enabled}:Ge)}))}catch(Ke){console.error("Extension toggle failed:",Ke)}finally{st(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 ${_e.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 ${_e.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),_e.name,e.jsx("span",{className:"text-[9px] font-normal",children:_e.enabled?"ON":"OFF"})]},_e.type))})]})]},N.id)})]}),se&&u&&e.jsx(Fs,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:xe,directories:J,busy:Q,error:I,confirmLabel:"Use this folder",onClose:()=>de(!1),onNavigate:N=>{ge(N)},onConfirm:N=>{X(N),U("__custom__"),de(!1)}}),z&&e.jsx(Er,{title:z.title,description:z.description,details:z.details,workspaceOptions:z.workspaceOptions,selectedWorkspaceKey:Ne,onWorkspaceChange:N=>{le.current=N,Pe(N)},confirmLabel:z.confirmLabel,busy:q,onConfirm:We,onCancel:()=>{W.current=null,te(null)}})]})}const Pn=[{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 vd({machine:t,machineId:s,providers:r,ideSessions:n,cliSessions:i,acpSessions:o,actions:c,getIcon:u,initialCategory:d="ide",initialWorkspaceId:x,initialWorkspacePath:l,sendDaemonCommand:f}){var p;const[h,m]=a.useState(d);a.useEffect(()=>{m(d)},[d]);const y=a.useMemo(()=>({ide:n.length,cli:i.length,acp:o.length}),[n.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:Pn.map(g=>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===g.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>m(g.id),children:[e.jsx("span",{children:g.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===g.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:y[g.id]})]},g.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(p=Pn.find(g=>g.id===h))==null?void 0:p.helper})]}),h==="ide"&&e.jsx(cr,{category:"ide",machine:t,machineId:s,providers:r,managedEntries:n,getIcon:u,actions:c,sendDaemonCommand:f,initialWorkspaceId:x,initialWorkspacePath:l}),h==="cli"&&e.jsx(cr,{category:"cli",machine:t,machineId:s,providers:r,managedEntries:i,getIcon:u,actions:c,sendDaemonCommand:f,initialWorkspaceId:x,initialWorkspacePath:l}),h==="acp"&&e.jsx(cr,{category:"acp",machine:t,machineId:s,providers:r,managedEntries:o,getIcon:u,actions:c,sendDaemonCommand:f,initialWorkspaceId:x,initialWorkspacePath:l})]})}function wd({onNicknameSynced:t}={}){var me,se,de,xe,oe,J,ce,Q,he;const{id:s}=yi(),r=Yt(),n=yr(),{sendCommand:i}=It(),o=Cr(),c=o.ides||[],u=o.initialLoaded??!0,d=c.find(I=>I.id===s&&I.daemonMode),x=c.some(I=>I.type==="adhdev-daemon"),[l,f]=a.useState("workspace"),[h,m]=a.useState("ide"),y=a.useRef(null),[p,g]=a.useState(null),b=a.useRef("__home__"),[v,S]=a.useState("__home__"),[B,j]=a.useState(!1),C=a.useRef(null),w=()=>{if(x){r("/dashboard",{state:{mobileSection:"machines"}});return}r("/machines")},k=cd({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:C});a.useEffect(()=>St.onToast(re=>{o.setToasts(z=>{if(z.some(Ne=>Ne.message===re.message&&re.timestamp-Ne.timestamp<3e3))return z;const le={id:re.id,message:re.message,type:re.type,timestamp:re.timestamp,targetKey:re.targetKey,actions:re.actions};return[...z.slice(-4),le]});const W=re.duration||5e3;setTimeout(()=>o.setToasts(z=>z.filter(te=>te.id!==re.id)),W)}),[o]);const E=(d==null?void 0:d.availableProviders)||[],L={};for(const I of E)L[I.type]=I.icon;const $=I=>L[I]||"",R=d?{id:d.id,hostname:ea(d,{fallbackId:d.id}),platform:((me=d.machine)==null?void 0:me.platform)||"unknown",arch:((se=d.machine)==null?void 0:se.arch)||"",cpus:((de=d.machine)==null?void 0:de.cpus)||0,totalMem:((xe=d.machine)==null?void 0:xe.totalMem)||0,freeMem:((oe=d.machine)==null?void 0:oe.freeMem)||0,availableMem:(J=d.machine)==null?void 0:J.availableMem,loadavg:((ce=d.machine)==null?void 0:ce.loadavg)||[],uptime:((Q=d.machine)==null?void 0:Q.uptime)||0,release:((he=d.machine)==null?void 0:he.release)||"",cdpConnected:!!d.cdpConnected,machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null}:null,T=c.filter(I=>I.daemonId===s&&!I.daemonMode).filter(I=>!cs(I)&&!Ht(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,version:I.version||"",instanceId:I.instanceId||"",status:I.status,workspace:I.workspace||null,terminals:I.terminals||0,aiAgents:jo(I.aiAgents||I.agents||[]),activeChat:I.activeChat||null,chats:I.chats||[],childSessions:I.childSessions||[],cdpConnected:I.cdpConnected||!1,daemonId:s})),O=c.filter(I=>I.daemonId===s&&cs(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,cliName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,providerSessionId:I.providerSessionId,mode:I.mode,daemonId:s})),H=c.filter(I=>I.daemonId===s&&Ht(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,acpName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,providerSessionId:I.providerSessionId,currentModel:I.currentModel,currentPlan:I.currentPlan,daemonId:s}));if(!R)return u?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:w,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const D=gt(d,{fallbackId:R.id}),F="workspace",_=n.state,A=_==null?void 0:_.initialMachineTab,M=_==null?void 0:_.initialWorkspaceCategory,G=_==null?void 0:_.initialWorkspaceId,Y=_==null?void 0:_.initialWorkspacePath,ue=A==="ides"||A==="clis"||A==="acps"?"workspace":A||F,ve=A==="ides"?"ide":A==="clis"?"cli":A==="acps"?"acp":M,Te=[...T.map(I=>{var re,W,z,te,le;return{id:`ide:${I.type}:${I.workspace||""}`,label:((re=I.activeChat)==null?void 0:re.title)||I.type,kind:"ide",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((le=(te=(z=(W=I.activeChat)==null?void 0:W.messages)==null?void 0:z.at)==null?void 0:te.call(z,-1))==null?void 0:le.timestamp)||0}}),...O.map(I=>{var re,W,z,te,le;return{id:`cli:${I.type}:${I.workspace||""}`,label:((re=I.activeChat)==null?void 0:re.title)||I.cliName,kind:"cli",providerType:I.type,providerSessionId:I.providerSessionId,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((le=(te=(z=(W=I.activeChat)==null?void 0:W.messages)==null?void 0:z.at)==null?void 0:te.call(z,-1))==null?void 0:le.timestamp)||0}}),...H.map(I=>{var re,W,z,te,le;return{id:`acp:${I.type}:${I.workspace||""}`,label:((re=I.activeChat)==null?void 0:re.title)||I.acpName,kind:"acp",providerType:I.type,providerSessionId:I.providerSessionId,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace||void 0,currentModel:I.currentModel,timestamp:((le=(te=(z=(W=I.activeChat)==null?void 0:W.messages)==null?void 0:z.at)==null?void 0:te.call(z,-1))==null?void 0:le.timestamp)||0}})].sort((I,re)=>re.timestamp-I.timestamp).map(({timestamp:I,...re})=>re),ee=(d.recentLaunches||[]).length>0?d.recentLaunches.map(I=>({id:I.id,label:I.title||I.providerName||I.providerType,kind:I.kind,providerType:I.providerType,providerSessionId:I.providerSessionId,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace,currentModel:I.currentModel})):Te,Me=a.useMemo(()=>{var re;const I=((re=o.connectionStates)==null?void 0:re[s||""])||void 0;return c.filter(W=>W.daemonId===s&&!W.daemonMode).flatMap(W=>Ar(W,{},{connectionState:I})).filter(W=>!(W.transport==="pty"&&W.mode==="terminal")).sort((W,z)=>gr(z)-gr(W))},[c,o.connectionStates,s]),U=a.useCallback(I=>{const re=I.sessionId||I.tabKey;re&&r(`/dashboard?activeTab=${encodeURIComponent(re)}`)},[r]),ae=a.useCallback(()=>{y.current&&(j(!0),y.current().finally(()=>{y.current=null,j(!1),g(null)}))},[]),X=a.useCallback(I=>{const{options:re,selectedKey:W}=Et({machine:R,currentWorkspacePath:I.workspace}),z=async()=>{m(I.kind),f("workspace")};y.current=async()=>{const te=re.find(Pe=>Pe.key===b.current),le=(te==null?void 0:te.workspacePath)??null,Ne=(te==null?void 0:te.workspaceId)??null;if(I.kind==="ide"&&I.providerType){await k.handleLaunchIde(I.providerType,le?{workspace:le}:void 0);return}if((I.kind==="cli"||I.kind==="acp")&&I.providerType){await k.runLaunchCliCore({cliType:I.providerType,dir:Ne?void 0:le||"",workspaceId:Ne||void 0,model:I.kind==="acp"?I.currentModel:void 0,resumeSessionId:I.providerSessionId});return}await z()},b.current=W,S(W),g({title:`Launch ${I.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:re,details:[{label:"Mode",value:I.kind.toUpperCase()},...I.providerType?[{label:"Provider",value:I.providerType}]:[]]})},[k,R]);a.useEffect(()=>{f(ue)},[F,ue,R.id]),a.useEffect(()=>{ve&&m(ve)},[ve,R.id]);const pe=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{size:14})," Workspace"]}),count:T.length+O.length+H.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($s,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ki,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($i,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:w,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[k.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:k.nicknameInput,onChange:I=>k.setNicknameInput(I.target.value),onKeyDown:I=>{I.key==="Enter"&&k.handleSaveNickname(),I.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(R.machineNickname||"")},title:"Click to set nickname",children:D}),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:[R.platform," · ",R.arch]}),e.jsxs("span",{children:[R.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{children:["v",d.version]}),R.p2p.available&&e.jsxs("span",{children:["P2P ",R.p2p.state==="connected"?"connected":R.p2p.state]}),R.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:R.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:pe.map(I=>e.jsxs("button",{onClick:()=>f(I.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${l===I.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[I.label,I.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${l===I.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:I.count})]},I.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:[l==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(hd,{machineEntry:d,providers:E,recentLaunches:ee,currentConversations:Me,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenRecent:X,onOpenConversation:U}),e.jsx(vd,{machine:R,machineId:s,providers:E,ideSessions:T,cliSessions:O,acpSessions:H,actions:k,getIcon:$,initialCategory:h,initialWorkspaceId:G,initialWorkspacePath:Y,sendDaemonCommand:i})]}),l==="providers"&&e.jsx(md,{machineId:s,providers:E,sendDaemonCommand:i}),l==="overview"&&e.jsx(ld,{machineId:s,machine:R,ideSessions:T,cliSessions:O,acpSessions:H,actions:k,sendDaemonCommand:i}),l==="logs"&&e.jsx(fd,{machineId:s,sendDaemonCommand:i})]})})}),k.launchPick&&R&&e.jsx(xd,{machine:R,launchPick:k.launchPick,actions:k}),p&&e.jsx(Er,{title:p.title,description:p.description,details:p.details,workspaceOptions:p.workspaceOptions,selectedWorkspaceKey:v,onWorkspaceChange:I=>{b.current=I,S(I)},confirmLabel:p.confirmLabel,busy:B,onConfirm:ae,onCancel:()=>{y.current=null,g(null)}}),e.jsx(aa,{toasts:o.toasts||[],onDismiss:I=>o.setToasts(re=>re.filter(W=>W.id!==I)),onClickToast:I=>{I.targetKey&&r(`/dashboard?activeTab=${encodeURIComponent(I.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 jd(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[r,n]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const u=[],d=[],x=[],l=[];Object.values(c.providers||{}).forEach(h=>{const m={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?u.push(m):h.category==="cli"?d.push(m):h.category==="extension"?x.push(m):h.category==="acp"&&l.push(m)});const f=(h,m)=>{const y={Stable:1,Beta:2,WIP:3},p=y[h.status]||99,g=y[m.status]||99;return p!==g?p-g:h.name.localeCompare(m.name)};s({ide:u.sort(f),cli:d.sort(f),ext:x.sort(f),acp:l.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>n(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Hn,{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(Bs,{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(jr,{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((u,d)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:u.name}),e.jsx("td",{className:"py-3 px-4",children:i(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},d))})]})});return r?e.jsx(Ls,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ms,{}),widthClassName:"max-w-5xl",children:e.jsx(_r,{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(Ls,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ms,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(it,{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(it,{title:"IDE support",icon:e.jsx(ot,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(it,{title:"Standalone CLI agents",icon:e.jsx(kr,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(it,{title:"AI extensions",icon:e.jsx($t,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(it,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx($t,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class kd{constructor(){tt(this,"adapters",new Map);tt(this,"states",new Map);tt(this,"runtimeListeners",new Map);tt(this,"screenshotCallbacks",new Map);tt(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const r of this.adapters.keys())if(r.startsWith("standalone"))return r}return null}register(s,r){this.adapters.set(s,r),this.states.set(s,r.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,r){this.states.set(s,r)}retryConnection(s){}get(s){const r=this.resolveDaemonId(s);return r?this.adapters.get(r):void 0}getState(s){const r=this.resolveDaemonId(s);return r&&this.states.get(r)||"disconnected"}sendData(s,r){return!1}sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,i){return!1}onScreenshot(s,r){return this.screenshotCallbacks.set(s,r),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,r){this.screenshotCallbacks.forEach(n=>n(s,r))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,r){this.statusCallbacks.forEach(n=>n(s,r))}emitRuntimeSnapshot(s,r,n=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:n,text:r,truncated:i})}emitSessionOutput(s,r,n){!s||typeof r!="string"||!r||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof n=="number"?{seq:n}:{},data:r})}onRuntimeEvent(s,r){const n=this.runtimeListeners.get(s)||new Set;return n.add(r),this.runtimeListeners.set(s,n),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(r),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,r){if(!r)return;const n=await fetch(`/api/v1/runtime/${encodeURIComponent(r)}/snapshot`);if(!n.ok)return;const i=await n.json();this.emitRuntimeEvent(r,{type:"runtime_snapshot",sessionId:r,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,r){var n;(n=this.runtimeListeners.get(s))==null||n.forEach(i=>i(r))}}const wt=new kd;function Nd(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,n=new URLSearchParams(window.location.search).get("token");return n?`${s}?token=${encodeURIComponent(n)}`:s}const Ln=Nd(),Rn=3e3,Sd=3e4;let jt=null,Cd=0;const Es=new Map;let Mt=null,ns=null;function En(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Id(t){return t==="connected"?"connected":t}async function Ts(t,s,r){const n=Ho(t,r||{}),i=jt;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++Cd}_${Date.now()}`;return new Promise((c,u)=>{const d=setTimeout(()=>{Es.delete(o),u(new Error(`WS command timeout: ${s}`))},3e4);Es.set(o,{resolve:x=>{clearTimeout(d),c(x)},reject:x=>{clearTimeout(d),u(x)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:n.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class Td{constructor(s){tt(this,"daemonId");tt(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(jt==null?void 0:jt.readyState)===WebSocket.OPEN}get connectionState(){return(jt==null?void 0:jt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,r){return Ts(this.daemonId,s,r)}async sendInput(s,r){return Ts(this.daemonId,"cdp_remote_action",{action:s,params:r,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Mt&&(clearInterval(Mt),Mt=null);const r=async()=>{if(this.hasCommandChannel)try{const n=await Ts(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(n!=null&&n.success&&(n!=null&&n.base64)){const i=await fetch(`data:image/jpeg;base64,${n.base64}`).then(o=>o.blob());wt.emitScreenshot(this.daemonId,i)}}catch{}};r(),Mt=setInterval(r,2e3)}stopScreenshots(s){Mt&&(clearInterval(Mt),Mt=null)}}let ft=null;function Ad(t){return(!ft||ft.daemonId!==t)&&(ft=new Td(t)),ft}function _d({children:t}){const s=a.useRef(Fr()),r=Fr();s.current=r;const{setUserName:n}=as(),i=a.useRef(n);i.current=n;const[,o]=a.useState("disconnected"),c=a.useCallback((h,m)=>{o(h),ns==null||ns(h,m)},[]),u=a.useRef(null),d=a.useRef(),x=a.useRef(Rn),l=a.useRef(!0),f=a.useRef(!1);return a.useEffect(()=>{l.current=!0,f.current=!1;function h(){var p,g;if(!l.current||((p=u.current)==null?void 0:p.readyState)===WebSocket.OPEN||((g=u.current)==null?void 0:g.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Ln}...`);let y;try{y=new WebSocket(Ln)}catch(b){console.error("[Standalone WS] Failed to create WebSocket:",b),m();return}u.current=y,y.onopen=()=>{if(!l.current){y.close();return}c("connected"),x.current=Rn,console.log("[Standalone WS] Connected")},jt=y,y.onmessage=b=>{var v;try{const S=JSON.parse(b.data);if((S.type==="command_result"||S.type==="error")&&S.requestId){const B=Es.get(S.requestId);B&&(Es.delete(S.requestId),S.type==="error"?B.reject(new Error(((v=S.data)==null?void 0:v.message)||"Command failed")):B.resolve(S.data));return}if(S.type==="session_output"){const B=S.sessionId||S.cliId||S.cliType;B&&wt.emitSessionOutput(B,typeof S.data=="string"?S.data:"",typeof S.seq=="number"?S.seq:void 0);return}if(S.type==="runtime_snapshot"){wt.emitRuntimeSnapshot(S.sessionId,typeof S.text=="string"?S.text:"",typeof S.seq=="number"?S.seq:0,!!S.truncated);return}if(S.type==="status"||S.type==="initial_state"){const B=S.data;if(!B)return;const{injectEntries:j,markLoaded:C}=s.current,w=B.id||"standalone",k=Ad(w);wt.register(w,k),wt.setState(w,"connected"),c("connected",w),wt.emitStatus(w,B);const E=zo(B,{daemonId:w});En("ws_status",{type:S.type,daemonId:w,sessions:(B.sessions||[]).map(L=>({id:L.id,parentId:L.parentId,providerType:L.providerType,kind:L.kind,transport:L.transport,unread:L.unread,inboxBucket:L.inboxBucket,lastSeenAt:L.lastSeenAt,lastUpdated:L.lastUpdated,title:L.title})),recentLaunches:(B.recentLaunches||[]).map(L=>({id:L.id,providerType:L.providerType,kind:L.kind,workspace:L.workspace,lastLaunchedAt:L.lastLaunchedAt}))}),En("entries",{daemonId:w,entries:E.filter(L=>L.type!=="adhdev-daemon").map(L=>({id:L.id,type:L.type,unread:L.unread,inboxBucket:L.inboxBucket,lastSeenAt:L.lastSeenAt,lastUpdated:L.lastUpdated,sessionId:L.sessionId}))}),E.length>0&&j(E,{authoritativeDaemonIds:[w]}),C(),B.userName&&i.current&&i.current(B.userName)}}catch(S){console.error("[Standalone WS] Parse error:",S)}},y.onclose=()=>{l.current&&(ft==null||ft.stopScreenshots(),ft&&wt.setState(ft.daemonId,"disconnected"),c("disconnected"),u.current=null,m())},y.onerror=b=>{f.current||!l.current||console.warn("[Standalone WS] Error, will reconnect:",b)}}function m(){if(!l.current)return;clearTimeout(d.current);const y=x.current;console.log(`[Standalone WS] Reconnecting in ${y}ms...`),d.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,Sd),h()},y)}return h(),()=>{l.current=!1,f.current=!0,clearTimeout(d.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,jt=null),ft&&(ft.stopScreenshots(),wt.unregister(ft.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Md({children:t}){const[s,r]=a.useState("disconnected"),[n,i]=a.useState(null);a.useEffect(()=>(ns=(c,u)=>{r(c),u&&i(u)},()=>{ns=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",u=Id(s),d={};return n&&(d[n]=u),d.standalone=u,{wsStatus:s,isConnected:c,connectionStates:d}},[s,n]);return e.jsx(Ii,{connectionOverrides:o,children:e.jsx(_d,{children:t})})}const Pd=[{id:"dashboard",path:"/dashboard",icon:e.jsx(zn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(_s,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx($s,{}),label:"Settings"}];function Ld({children:t}){const s=Yt(),r=yr(),[n,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=l=>{s(l),i(!1)},d=()=>{c(l=>{const f=!l;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=l=>`nav-item${r.pathname.startsWith(l)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${n?" 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"})]}),n&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:l=>l.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${n?"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:Pd.map(l=>e.jsxs("div",{className:x(l.path),id:`nav-${l.id}`,onClick:()=>u(l.path),title:o?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!o&&l.label]},l.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(Ms,{})}),!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${r.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(Fn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.22"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:d,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 Rd=[{icon:e.jsx(_s,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(vt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Vn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(ot,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx($t,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Ms,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Ed=[{icon:e.jsx(Gn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(zn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Ks,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Ei,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Li,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Hn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],$d=[{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 Dd(){return e.jsxs(Ls,{icon:e.jsx(Fn,{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.22"]}),children:[e.jsx(it,{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(it,{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:Rd.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(it,{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:oa.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:la.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:ca.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(it,{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:Ed.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(it,{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:$d.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(_r,{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(qi,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Bd(){const{ides:t}=as(),s=t.find(f=>f.type==="adhdev-daemon"),r=(s==null?void 0:s.detectedIdes)||[],{sendCommand:n}=It(),{userName:i}=as(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const u=f=>{const h=f.target.value.trim();s!=null&&s.id&&h!==i&&n(s.id,"set_user_name",{userName:h}).catch(console.error)},[d,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(Ls,{icon:e.jsx($s,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(ic,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(it,{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.22"]}),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(it,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:r.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:r.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(it,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(mc,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(it,{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(bc,{})]}),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(_c,{})]}),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(Pc,{})]})]})}),e.jsx(it,{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(pc,{}),e.jsx(Ct,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gi,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:d,onChange:l})]})}),e.jsx(it,{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(Ri,{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:f=>c(f.target.value),onBlur:u,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}uc();Tc();Nc();const Kd=On({baseUrl:""});function $n(){const{ides:t,initialLoaded:s}=as();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const r=t.find(n=>n.daemonMode||n.type==="adhdev-daemon");return r?e.jsx(lr,{to:`/machines/${r.id}`,replace:!0}):e.jsx(lr,{to:"/dashboard",replace:!0})}function Wd(){return e.jsx(vi,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(_i,{client:Kd,children:e.jsx(Md,{children:e.jsx(Pi,{value:{sendCommand:Ts,sendData:()=>!1},children:e.jsx(Ld,{children:e.jsxs(wi,{children:[e.jsx(Nt,{path:"/dashboard",element:e.jsx(od,{})}),e.jsx(Nt,{path:"/machine",element:e.jsx($n,{})}),e.jsx(Nt,{path:"/machines/:id",element:e.jsx(wd,{})}),e.jsx(Nt,{path:"/machines",element:e.jsx($n,{})}),e.jsx(Nt,{path:"/capabilities",element:e.jsx(jd,{})}),e.jsx(Nt,{path:"/about",element:e.jsx(Dd,{})}),e.jsx(Nt,{path:"/settings",element:e.jsx(Bd,{})}),e.jsx(Nt,{path:"*",element:e.jsx(lr,{to:"/dashboard",replace:!0})})]})})})})})})}Po({connectionManager:wt});ji(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Wd,{})}));
|