@adhdev/daemon-standalone 0.8.8 → 0.8.10

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.
@@ -33,7 +33,7 @@ var wa=Object.defineProperty;var ja=(t,s,n)=>s in t?wa(t,s,{enumerable:!0,config
33
33
  }
34
34
  `})]})}function hi(t,s={}){if(!t)return"";const{suffix:n="",nowLabel:r="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return r;const d=Math.floor(c/60);if(d<60)return`${d}m${n}`;const l=Math.floor(d/60);if(l<24)return`${l}h${n}`;const f=Math.floor(l/24);return f<7?`${f}d${n}`:new Date(t).toLocaleDateString()}const fr=t=>hi(t);function bi(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ms(t){const s=t.connectionState==="failed"||t.connectionState==="closed",n=t.connectionState==="connecting"||t.connectionState==="new",r=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:n,isGenerating:r,isWaiting:i}}function Kt(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...bi(i)})};for(const r of t)if(!r.daemonMode){n(r.sessionId,r);for(const i of r.childSessions||[])n(i.id,i)}return s}function Et(t,s){if(t.sessionId){const n=s.get(t.sessionId);if(n)return n}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function Dt(t,s,n){const r=Et(t,s),i=ms(t),o=i.isReconnecting,c=i.isConnecting,d=i.isGenerating,l=i.isWaiting,f=r.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||l,u=r.inboxBucket==="working"||d,x=r.inboxBucket==="task_complete"&&r.unread&&!(n!=null&&n.hideOpenTaskCompleteUnread&&(n!=null&&n.isOpenConversation));return{unread:x,requiresAction:f,isWorking:u,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":u?"working":x?"task_complete":"idle"}}function gi(t,s,n){return Dt(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function yi(t,s,n){return Et(t,n||new Map).surfaceHidden}function hr({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ms(t).isWaiting||!t.modalButtons)return null;const o=d=>{n||(r(d),s(d))},c=d=>d.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"text-white py-2.5 px-4 shrink-0 z-[5]",style:{background:"linear-gradient(135deg, var(--status-warning), color-mix(in srgb, var(--status-warning) 85%, #000))"},children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Vs,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((d,l)=>{const f=c(d).toLowerCase(),u=/^(run|approve|accept|yes|allow|always)/.test(f),x=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,p=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${u?"bg-white font-extrabold":x?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!h?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:u?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const gn=new Map,vi={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function wi({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=ut(),u=`${t}:${s||r}`,x=vi[r]||"#94a3b8",[h,p]=a.useState({}),b=a.useRef(0),m={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<b.current?h:{}};a.useEffect(()=>{c&&Date.now()>b.current&&p({})},[c]);const[N,g]=a.useState(gn.get(u)||{}),[w,k]=a.useState(null),[C,y]=a.useState(null),T=a.useCallback(async($,A={})=>{const F={...A,...s&&{targetSessionId:s}};return await f(t,$,F)},[t,s,f]);if(!o||o.length===0)return null;const v=o.filter($=>$.placement==="bar").sort(($,A)=>($.order??50)-(A.order??50));if(v.length===0)return null;const j=async $=>{var F,B,O;if(w===$.id){k(null);return}if((((F=$.options)==null?void 0:F.map(M=>M.value))||N[$.id]||[]).length>0){k($.id);return}if($.dynamic&&$.listScript){y($.id);try{const M=await T($.listScript==="listModels"?"list_extension_models":$.listScript==="listModes"?"list_extension_modes":$.listScript,{agentType:r,ideType:n}),_=((M==null?void 0:M.models)||(M==null?void 0:M.modes)||((B=M==null?void 0:M.result)==null?void 0:B.models)||((O=M==null?void 0:M.result)==null?void 0:O.modes)||(M==null?void 0:M.options)||[]).map(R=>typeof R=="string"?R:(R==null?void 0:R.name)||(R==null?void 0:R.id)||(R==null?void 0:R.value)||String(R));g(R=>{const H={...R,[$.id]:_};return gn.set(u,H),H}),k($.id)}catch{}finally{y(null)}}},D=async($,A)=>{k(null),p(F=>({...F,[$.id]:A})),b.current=Date.now()+5e3;try{if(!$.setScript)return;const F=ws($.setScript,r);await T(F,{agentType:r,ideType:n,model:$.id==="model"?A:void 0,mode:$.id==="mode"?A:void 0,value:A})}catch{}},L=async $=>{var E;const A=((E=$.options)==null?void 0:E.map(_=>_.value))||N[$.id]||[];if(A.length===0)return;const F=String(m[$.id]||""),O=(A.indexOf(F)+1)%A.length,M=A[O];if(typeof M=="string"){p(_=>({..._,[$.id]:M})),b.current=Date.now()+5e3;try{if(!$.setScript)return;const _=ws($.setScript,r);await T(_,{agentType:r,ideType:n,value:M})}catch{}}},P=async $=>{const F=!m[$.id];p(B=>({...B,[$.id]:F})),b.current=Date.now()+5e3;try{if(!$.setScript)return;const B=ws($.setScript,r);await T(B,{agentType:r,ideType:n,value:F})}catch{}},U=async $=>{if($.invokeScript)try{await T("invoke_extension_script",{agentType:r,ideType:n,scriptName:$.invokeScript})}catch{}};return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-surface-primary font-[var(--font)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:x},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),v.map($=>{var M;const A=String(m[$.id]||""),F=w===$.id,B=C===$.id,O=((M=$.options)==null?void 0:M.map(E=>E.value))||N[$.id]||[];switch($.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:F?`${x}55`:"transparent",border:"1px solid",color:A?"var(--text-primary)":"var(--text-muted)"},onClick:()=>j($),children:[$.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:$.icon}),B?"...":A||$.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),F&&O.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>k(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:$.label.toUpperCase()}),O.map(E=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:E===A?`${x}18`:"transparent",color:E===A?x:"var(--text-secondary)",fontWeight:E===A?600:400,borderLeft:E===A?`2px solid ${x}`:"2px solid transparent"},onMouseEnter:_=>{_.currentTarget.style.background=`${x}12`},onMouseLeave:_=>{_.currentTarget.style.background=E===A?`${x}18`:"transparent"},onClick:()=>D($,E),children:E},E))]})]})]},$.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:A?"var(--text-primary)":"var(--text-muted)"},onClick:()=>L($),title:`Click to cycle: ${O.join(" → ")}`,children:[$.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:$.icon}),A||$.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},$.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:A?`${x}44`:"transparent",background:A?`${x}14`:"var(--surface-tertiary)",color:A?x:"var(--text-muted)"},onClick:()=>P($),children:[$.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:$.icon}),$.label]},$.id);case"action":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>U($),children:[$.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:$.icon}),$.label]},$.id);default:return null}})]})}function ws(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const ji=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,d]=a.useState("");a.useEffect(()=>{d("")},[s]);const l=()=>{const f=c.trim();!f||r||(d(""),i(f))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:f=>d(f.target.value),onPaste:f=>{const u=f.clipboardData.getData("text");u&&d(x=>x+u),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),l()}},onBlur:f=>{if(window.innerWidth<768){const u=f.relatedTarget;if((u==null?void 0:u.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:l,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.trim()&&!r?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var ki=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Ni(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Ye(t,s){if(Ni(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":ki.has(n)?"generating":n==="error"?"error":n==="stopped"?"stopped":n==="starting"?"starting":n==="panel_hidden"?"panel_hidden":n==="not_monitored"?"not_monitored":n==="disconnected"?"disconnected":"idle"}function br(t){return Ye(t)==="generating"}function _e(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Si(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function yn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gs(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const i=r.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function Ci(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function Ii(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function Mi(t){return Ci(t.trim().replace(/\.local$/i,""))}function _i(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function gr(t,s={}){var i,o;const n=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0&&!Ii(c));if(n&&n!=="Unknown")return Mi(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function nt(t,s={}){return _i(t)||gr(t,s)}function rs(t){return t.transport==="pty"}function _t(t){return t.transport==="acp"}function vn(t,s){return _e(t)}function wn(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=_e(n||"").trim().toLowerCase();return r===i||r===o||r===c}function Ti(t){return Ye(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Ai(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=Ye(r.status);if(!o){s.set(i,{...r,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function js(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function Li(t){var n,r;const s=(r=(n=t==null?void 0:t.messages)==null?void 0:n.at)==null?void 0:r.call(n,-1);return s&&(js(s.timestamp)||js(s.receivedAt)||js(s.createdAt))||0}function Ri(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function Rs(t){return Math.max(Ri(t),Li(t.activeChat))}function Pi(t,s,n,r,i,o){const c=s-t;if(c!==0)return c;const d=n.localeCompare(r);return d!==0?d:i.localeCompare(o)}function $i(t,s){return Pi(Rs(t),Rs(s),nt(t,{fallbackId:t.id}),nt(s,{fallbackId:s.id}),t.id,s.id)}function yr({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r,interactive:i=!0}){var b;const o=St(),c=t.daemonId||((b=t.ideId)==null?void 0:b.split(":")[0])||t.ideId,d=t.transport==="cdp-page"||t.transport==="cdp-webview",l=t.streamSource==="agent-stream"&&!!t.agentName,f=!l&&(t.transport==="pty"||t.transport==="acp"),u=t.agentName||_e(t.agentType||t.ideType||""),x=(()=>{var m,N;if(t.streamSource==="agent-stream"){const g=(N=(m=t.displaySecondary)==null?void 0:m.split("·")[0])==null?void 0:N.trim();if(g)return g}return _e(t.ideType||"")})(),h=a.useCallback(()=>{if(r){r();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,r]),p=a.useCallback(()=>{if(n){n();return}const m=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;m&&o(`/dashboard?activeTab=${encodeURIComponent(m)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[d&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:x,children:[e.jsx(qe,{size:12}),e.jsx("span",{children:x})]}):e.jsxs("span",{className:"conversation-meta-chip",title:x,children:[e.jsx(qe,{size:12}),e.jsx("span",{children:x})]})),l&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(bt,{size:12}),e.jsx("span",{children:t.agentName})]}),f&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:u,children:[e.jsx(bt,{size:12}),e.jsx("span",{children:u})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:h,title:t.machineName,children:[e.jsx(ss,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(ss,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Ee=t=>t.transport==="pty",Nt=(t,s)=>Ee(t)?s||t.mode||"terminal":"chat",vr=(t,s)=>Ee(t)&&Nt(t,s)==="terminal",Te=t=>t.transport==="acp";function as(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
35
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 Ps(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 Ei(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const n=String((t==null?void 0:t.role)||"").toLowerCase(),r=String((s==null?void 0:s.role)||"").toLowerCase();if(n!==r)return!1;const i=as(t==null?void 0:t.content),o=as(s==null?void 0:s.content);if(!i||i!==o)return!1;const c=Ps(t),d=Ps(s);return c&&d?Math.abs(c-d)<=15e3:!!(t!=null&&t._localId)!=!!(s!=null&&s._localId)}function jn(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),Ps(t)&&(s+=1),s}function Di(t,s){const n=jn(t),r=jn(s);return r!==n?r>n?s:t:as(s==null?void 0:s.content).length>=as(t==null?void 0:t.content).length?s:t}function kn(t){const s=[];for(const n of t){const r=s.findIndex(i=>Ei(i,n));if(r>=0){s.splice(r,1,Di(s[r],n));continue}s.push(n)}return s}const Bi=60,Ki=60;function $s({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:d,showMetaChips:l=!1}){const f=a.useRef(new Map),{sendCommand:u}=ut();Bt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const x=Os.useMemo(()=>ms(t),[t.status,t.connectionState]),h=a.useRef(new Map),p=a.useCallback(A=>(h.current.has(A)||h.current.set(A,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Bi}),h.current.get(A)),[]),b=a.useCallback((A,F)=>{const B=p(A);h.current.set(A,{...B,...F}),m(O=>O+1)},[p]),[,m]=a.useState(0),N=t.tabKey,g=p(N),w=g.messages,k=g.hasMore,C=g.error,y=Math.max(0,t.messages.length-g.visibleLiveCount),[T,v]=a.useState(!1),j=a.useCallback(async()=>{var B,O;if(T)return;const A=t.tabKey,F=p(A);if(t.messages.length>F.visibleLiveCount){b(A,{visibleLiveCount:Math.min(t.messages.length,F.visibleLiveCount+Ki),error:null});return}v(!0),b(A,{error:null});try{const M=(s==null?void 0:s.daemonId)||((B=t.ideId)==null?void 0:B.split(":")[0])||"";if(!M){b(A,{hasMore:!1});return}const E=t.ideType||t.agentType||"",_=await u(M,"chat_history",{agentType:E,offset:F.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),R=(_==null?void 0:_.result)??_;if(((O=R.messages)==null?void 0:O.length)>0){const H=p(A);b(A,{messages:[...R.messages,...H.messages],offset:H.offset+R.messages.length,hasMore:!!R.hasMore})}else b(A,{hasMore:!!R.hasMore})}catch(M){const E=(M==null?void 0:M.message)||"";E.includes("P2P not available")||E.includes("channel not open")||E.includes("P2P not connected")||E.includes("timeout")?b(A,{error:"Connection not ready — tap to retry"}):b(A,{hasMore:!1,error:"Failed to load history"})}finally{v(!1)}},[T,s,t,u,p,b]),{allMessages:D,receivedAtMap:L}=a.useMemo(()=>{const A=y>0?t.messages.slice(-g.visibleLiveCount):t.messages;if(w.length===0){const E=kn(A),_={};return E.forEach((R,H)=>{const oe=`${t.tabKey}:${wt(R,H)}`;let le=R.receivedAt||f.current.get(oe)||0;le||(le=Date.now(),f.current.set(oe,le)),_[wt(R,H)]=le}),{allMessages:E,receivedAtMap:_}}const F=new Set(A.map(E=>`${E.role}:${(E.content||"").slice(0,100)}`)),B=w.filter(E=>!F.has(`${E.role}:${(E.content||"").slice(0,100)}`)),O=kn([...B,...A]),M={};return O.forEach((E,_)=>{const R=`${t.tabKey}:${wt(E,_)}`;let H=E.receivedAt||f.current.get(R)||0;H||(H=Date.now(),f.current.set(R,H)),M[wt(E,_)]=H}),{allMessages:O,receivedAtMap:M}},[t.messages,t.tabKey,y,w,g.visibleLiveCount]),P=a.useMemo(()=>c.filter(A=>A.ideId===t.tabKey).sort((A,F)=>A.timestamp-F.timestamp),[c,t.tabKey]),U=t.displayPrimary||t.agentName||"Agent",$=a.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if((x.isGenerating||t.status==="streaming")&&v(!1),t.status==="not_monitored")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(bt,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:14})," Open ",U," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(lr,{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($t,{size:14})," Open ",U," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]});if(t.status==="idle"&&!T)return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]})}},[t.messages.length,t.connectionState,t.status,i,o,T,U,x.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(yr,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(di,{messages:D,actionLogs:P,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Ee(t)||Te(t),isWorking:x.isGenerating,contextKey:t.tabKey,receivedAtMap:L,onLoadMore:j,isLoadingMore:T,hasMoreHistory:k,hiddenLiveCount:y,loadError:C??void 0,emptyState:$}),!vr(t)&&(()=>{const A=t.streamSource!=="agent-stream",F=A?t.ideType:t.agentType,B=A?s!=null&&s.type?_e(s.type):_e(t.ideType||""):t.agentName||_e(t.agentType||""),O=!A&&(s!=null&&s.childSessions)&&s.childSessions.find(_=>_.id===t.sessionId||_.providerType===t.agentType)||s,M=O==null?void 0:O.providerControls,E=O==null?void 0:O.controlValues;return e.jsx(wi,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:F,displayLabel:B,controls:M,controlValues:E,serverModel:(O==null?void 0:O.currentModel)||void 0,serverMode:(O==null?void 0:O.currentPlan)||void 0,acpConfigOptions:Te(t)?O==null?void 0:O.acpConfigOptions:void 0,acpModes:Te(t)?O==null?void 0:O.acpModes:void 0})})(),e.jsx(ji,{contextKey:t.tabKey,panelLabel:U,isSending:r,onSend:n})]})}let wr=Pt;function Ys(){return wr()}class Wi{constructor(){We(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let jr=new Wi;class Oi{sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let $e=new Oi;function zi(t){t.dashboardWS&&(jr=t.dashboardWS),t.connectionManager&&($e=t.connectionManager),t.useDaemonsHook&&(wr=t.useDaemonsHook)}function Ui({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var O;const c=a.useRef(null),{sendCommand:d,sendData:l}=ut(),[f,u]=a.useState(""),[x,h]=a.useState(!1),[p,b]=a.useState(1),m=a.useRef(!1),N=a.useRef(0),g=a.useRef(!1),w=a.useRef(""),k=a.useRef(null),C=a.useRef(!1),y=a.useRef(null),T=t.tabKey,v=t.sessionId||"",j=t.daemonId||((O=t.ideId)==null?void 0:O.split(":")[0])||t.ideId||"",D=.6,L=1.15,P=()=>{if(typeof window>"u")return 1;const M=window.innerWidth||0;return M<=360?.68:M<=390?.74:M<=430?.82:M<=480?.9:1},U=()=>{var M,E;N.current=0,g.current=!1,w.current="",k.current=null,C.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!1),(E=(M=n.current)==null?void 0:M.reset)==null||E.call(M)},$=()=>{var M,E;N.current=0,g.current=!1,w.current="",k.current=null,C.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!0),(E=(M=n.current)==null?void 0:M.reset)==null||E.call(M)},A=()=>{var E;if(y.current=null,!o)return;const M=w.current;M&&(w.current="",(E=n.current)==null||E.write(M))},F=M=>{M&&(w.current+=M,o&&y.current===null&&(y.current=requestAnimationFrame(A)))},B=(M,E=0,_,R)=>{var H,oe,le,he,z;E>0&&N.current>=E||E===0&&g.current||(N.current=E,h(!0),typeof _=="number"&&typeof R=="number"&&_>0&&R>0&&((oe=(H=n.current)==null?void 0:H.resize)==null||oe.call(H,_,R)),(he=(le=n.current)==null?void 0:le.reset)==null||he.call(le),M&&((z=n.current)==null||z.write(M)))};return a.useEffect(()=>{U()},[v]),a.useEffect(()=>{var E;if(!v)return;const M=((E=$e.onRuntimeEvent)==null?void 0:E.call($e,v,_=>{if(!(!_||_.sessionId!==v)){if(_.type==="runtime_snapshot"){if(!o){k.current={text:_.text||"",seq:_.seq||0,cols:_.cols,rows:_.rows};return}B(_.text||"",_.seq||0,_.cols,_.rows);return}if(_.type==="session_output"){g.current=!0,typeof _.seq=="number"&&(N.current=Math.max(N.current,_.seq)),x||h(!0),typeof _.data=="string"&&F(_.data);return}if(_.type==="session_cleared"){if(!o){C.current=!0,w.current="",k.current=null;return}$()}}}))||(()=>{});return()=>{M()}},[j,v,n,o,x]),a.useEffect(()=>{var E,_,R;if(!v)return;j&&((E=$e.getState)==null?void 0:E.call($e,j))==="connected"&&(h(!0),(_=$e.requestRuntimeSnapshot)==null||_.call($e,j,v).catch(()=>{}));const M=(R=$e.onStateChange)==null?void 0:R.call($e,(H,oe)=>{var le;H!==j||oe!=="connected"||(h(!0),(le=$e.requestRuntimeSnapshot)==null||le.call($e,j,v).catch(()=>{}))});return()=>{M==null||M()}},[j,v,n]),a.useEffect(()=>{s&&U()},[s,T,n]),a.useEffect(()=>{u("")},[t.tabKey]),a.useEffect(()=>{const M=()=>{m.current||b(P())};return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),a.useEffect(()=>{var E;if(!o){(E=c.current)==null||E.blur();return}C.current&&(C.current=!1,$());const M=k.current;M&&(k.current=null,B(M.text,M.seq,M.cols,M.rows)),w.current&&y.current===null&&(y.current=requestAnimationFrame(A))},[o]),a.useEffect(()=>()=>{y.current!==null&&(cancelAnimationFrame(y.current),y.current=null)},[]),a.useEffect(()=>{const M=E=>{var R;const _=E.detail;_!=null&&_.sessionId&&_.sessionId!==v||x&&((R=n.current)==null||R.fit())};return window.addEventListener("adhdev:fit-cli-terminal",M),()=>{window.removeEventListener("adhdev:fit-cli-terminal",M)}},[x,v,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[e.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{m.current=!0,b(M=>Math.max(D,Number((M-.1).toFixed(2))))},title:"Shrink terminal viewport",children:"-"}),e.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{m.current=!0,b(M=>Math.min(L,Number((M+.1).toFixed(2))))},title:"Increase terminal viewport",children:"+"})]}),e.jsx("div",{className:"w-full h-full overflow-auto rounded-lg",children:e.jsx("div",{style:{width:`${100/p}%`,height:`${100/p}%`,transform:`scale(${p})`,transformOrigin:"top left"},children:e.jsx(mr,{ref:n,readOnly:!x||!o,onInput:M=>{x&&(l!=null&&l(j,{type:"pty_input",targetSessionId:v,data:M})||d(j,"pty_input",{targetSessionId:v,data:M}).catch(console.error))},onResize:(M,E)=>{x&&(l!=null&&l(j,{type:"pty_resize",targetSessionId:v,cols:M,rows:E})||d(j,"pty_resize",{targetSessionId:v,cols:M,rows:E,force:!0}).catch(()=>{}))}})})}),!x&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:f,disabled:!x||!o||i,onChange:M=>u(M.target.value),onPaste:M=>{const E=M.clipboardData.getData("text");E&&u(_=>_+E),M.preventDefault()},onKeyDown:M=>{if(M.key!=="Enter")return;if(M.nativeEvent.isComposing){M.preventDefault();return}M.preventDefault();const E=f.trim();!x||!E||i||(u(""),r(E))},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:()=>{const M=f.trim();!x||!M||i||(u(""),r(M))},disabled:!x||!o||!f.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${f.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:f.trim()&&!i?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:f.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Hi({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"accent",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},d={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function Fi({terminalBackend:t,isStandalone:s=!1,machineLabel:n,machineKey:r}){const i=a.useMemo(()=>!r||!t?null:`adhdev:terminal-backend-banner:dismissed:${r}:${t.backend}`,[r,t]),[o,c]=a.useState(!1);if(a.useEffect(()=>{if(!i){c(!1);return}try{c(localStorage.getItem(i)==="1")}catch{c(!1)}},[i]),!s||!t||t.backend!=="xterm"||o)return null;const d=(n==null?void 0:n.trim())||"This machine",l=()=>{if(i)try{localStorage.setItem(i,"1")}catch{}c(!0)};return e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5",style:{background:"linear-gradient(90deg, rgba(245,158,11,0.12), rgba(245,158,11,0.04))",borderBottom:"1px solid rgba(245,158,11,0.2)",color:"#d97706"},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5 justify-center flex-wrap",children:[e.jsxs("span",{children:[d," is using `xterm` fallback."]}),e.jsx("span",{style:{opacity:.8},children:"ghostty-vt is unavailable on this machine, so terminal rendering may be less accurate."})]}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 text-[12px] font-semibold px-2 py-1 rounded-md transition-colors",style:{color:"#b45309",background:"rgba(245,158,11,0.1)",border:"1px solid rgba(245,158,11,0.18)"},"aria-label":"Dismiss terminal backend warning",title:"Dismiss",children:"Dismiss"})]})}function Xs({mode:t,onChange:s,compact:n=!1}){const r=n?14:15;return e.jsx("button",{type:"button",onClick:()=>s(t==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:t==="chat"?"Switch to Terminal view":"Switch to Chat view",children:t==="chat"?e.jsx(qs,{size:r}):e.jsx(it,{size:r})})}function Nn({conversation:t,isAttention:s,onClick:n}){return e.jsxs("button",{type:"button",className:`dashboard-header-inbox-item ${s?"is-attention":""}`.trim(),onClick:n,children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:t.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:t.displaySecondary})]})}function Vi({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:u,onHideConversation:x,hiddenConversations:h=[],onShowConversation:p,onShowAllHidden:b}){const m=Ys(),N=m.p2pStates||{},g=m.ides||[],w=!!t&&Ee(t)&&!Te(t),k=l||(t?vr(t)?"terminal":"chat":null),[C,y]=a.useState(!1),[T,v]=a.useState(!1),[j,D]=a.useState(!1),L=a.useRef(null),P=a.useRef(null),U=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",$=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",A=g.filter(z=>z.type==="adhdev-daemon"),F=a.useMemo(()=>Kt(g),[g]),B=Object.values(N),O=B.filter(z=>z==="connected").length,M=B.filter(z=>z==="connecting"||z==="new"||z==="checking").length,_=n!=="connected"||A.length===0?null:M>0&&O===0?"P2P connecting...":O>0&&s===0?"Waiting for IDE...":null,R=a.useMemo(()=>i.filter(z=>!yi(z,i,F)),[i,F]),H=a.useMemo(()=>R.filter(z=>Dt(z,F).requiresAction),[R,F]),oe=a.useMemo(()=>R.filter(z=>{const Y=(t==null?void 0:t.tabKey)===z.tabKey;return Dt(z,F,{hideOpenTaskCompleteUnread:!0,isOpenConversation:Y}).unread}),[t,R,F]),le=H.length+oe.length;a.useEffect(()=>{if(!C)return;const z=Y=>{var de;(de=L.current)!=null&&de.contains(Y.target)||y(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[C]),a.useEffect(()=>{if(!T)return;const z=Y=>{var de;(de=P.current)!=null&&de.contains(Y.target)||v(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[T]);const he=z=>{if(!z)return;const Y=i.find(de=>de.tabKey===z);Y&&(x==null||x(Y))};return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"header-title-block",children:e.jsxs("div",{className:"header-title-row",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(it,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:U,boxShadow:$}})})]}),e.jsxs("div",{className:"header-subtitle",children:[e.jsxs("span",{className:"header-subtitle-copy",children:[s," agent",s!==1?"s":""," active"]}),e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:U,boxShadow:$}}),_&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",_]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(w||!Te(t))&&e.jsxs("div",{className:"dashboard-header-actions-group",children:[e.jsx("span",{className:"dashboard-header-action-target",title:t.displaySecondary||t.displayPrimary,children:t.displayPrimary}),w&&d&&e.jsxs(e.Fragment,{children:[f&&k&&e.jsx(Xs,{mode:k,onChange:f,compact:!0}),e.jsx("button",{onClick:()=>d(t),className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(kt,{size:14})})]}),!Te(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Hs,{size:14})}),!w&&!Te(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(qe,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:L,children:[e.jsxs("div",{className:`dashboard-header-hidden${j?" is-drop-target":""}`,ref:P,onDragEnter:z=>{z.dataTransfer.types.includes("text/tab-key")&&(z.preventDefault(),D(!0))},onDragOver:z=>{z.dataTransfer.types.includes("text/tab-key")&&(z.preventDefault(),z.dataTransfer.dropEffect="move",D(!0))},onDragLeave:z=>{z.currentTarget.contains(z.relatedTarget)||D(!1)},onDrop:z=>{const Y=z.dataTransfer.getData("text/tab-key");z.preventDefault(),D(!1),he(Y)},children:[e.jsxs("button",{type:"button",onClick:()=>v(z=>!z),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Xa,{size:16}),h.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:h.length})]}),T&&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&&b&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{b(),v(!1)},children:"Restore all"})]}),t&&x&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>x(t),children:[e.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),e.jsx("span",{className:"dashboard-header-hidden-current-title",children:t.displayPrimary})]}),h.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:h.map(z=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{p==null||p(z),v(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:z.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:z.displaySecondary})]},z.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>y(z=>!z),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(ps,{size:16}),le>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:le})]}),C&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[H.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),H.map(z=>e.jsx(Nn,{conversation:z,isAttention:!0,onClick:()=>{u==null||u(z),y(!1)}},z.tabKey))]}),oe.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),oe.map(z=>e.jsx(Nn,{conversation:z,onClick:()=>{u==null||u(z),y(!1)}},z.tabKey))]}),le===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function qi(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 Gi({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:u,onResumeSavedSession:x}){var N;const h=s.find(g=>g.id===t.ideId),p=(h==null?void 0:h.chats)||[],b=(N=h==null?void 0:h.activeChat)==null?void 0:N.id,m=Ee(t)&&!Te(t);return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:d,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:m?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",_e(t.ideType)]})]}),e.jsx("button",{onClick:d,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[!m&&e.jsx("button",{onClick:l,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),m?e.jsx(e.Fragment,{children:i.map(g=>{const w=t.providerSessionId===g.providerSessionId,k=w||!g.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{k||!x||x(g)},disabled:k,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${w?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${k?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:`font-bold text-sm mb-1 truncate ${w?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:g.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:qi(g.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:g.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:[g.workspace||"Workspace unknown",g.currentModel?` · ${g.currentModel}`:"",g.messageCount>0?` · ${g.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:w?"ACTIVE":g.canResume?c===g.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},g.id)})}):p.map(g=>e.jsxs("div",{onClick:()=>{f(t.ideId,g.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${b===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${b===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[g.id.substring(0,12),"..."]}),b===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),(m&&!o&&i.length===0||!m&&p.length===0)&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(ei,{size:32})}),e.jsx("div",{className:"text-[13px]",children:m?"No saved sessions found yet.":"No recent chat sessions found."})]}),m&&o&&e.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:e.jsx("div",{className:"text-[13px]",children:"Refreshing saved sessions…"})})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,disabled:r||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:r||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fs,{size:13})," ",m?"Refresh Sessions":"Refresh History"]})})})]})]})}const Sn={success:"rgba(16, 185, 129, 0.95)",warning:"color-mix(in srgb, var(--status-warning) 95%, transparent)",info:"rgba(99, 102, 241, 0.95)"};function kr({toasts:t,onDismiss:s,onClickToast:n}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(r=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px] relative group",style:{background:Sn[r.type]||Sn.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(n&&n(r),s(r.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:i=>{i.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(r.id)},children:i.label},o))})]},r.id))})}function Nr(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 Yi=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Xi(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Zi(t){return t.sessionId||t.instanceId||t.agentType}function ks(t,s){return t||s}function Cn(t){return Nr(t)}function In(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 Mn(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const n=String(t.role||"").toLowerCase(),r=String(s.role||"").toLowerCase();if(n!==r)return!1;const i=Cn(t.content),o=Cn(s.content);if(!i||i!==o)return!1;const c=In(t),d=In(s);return c&&d?Math.abs(c-d)<=15e3:!!t._localId!=!!s._localId}function _n(t,s){const n=new Set,r=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;n.has(c)||(n.add(c),r.push(o))}return r.sort((i,o)=>i.timestamp-o.timestamp)}function Sr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=nt(r,{fallbackId:r.id}))}return s}function Cr(t,s,n={}){var h,p,b,m,N,g;const r=[],i=n.machineName,o=n.connectionState,c=Xi(t),d=_e(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(w=>{var k,C;return{sessionId:w.id,instanceId:w.id,providerSessionId:w.providerSessionId,agentType:w.providerType,agentName:w.providerName,status:w.status,title:w.title,messages:((k=w.activeChat)==null?void 0:k.messages)||[],activeModal:((C=w.activeChat)==null?void 0:C.activeModal)||void 0,unread:w.unread,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,inboxBucket:w.inboxBucket,surfaceHidden:w.surfaceHidden}}):[],f=Yi(t),u=t.activeChat||{title:""},x=u.title&&String(u.title).trim()?String(u.title).trim():"";if(f){const w=t.sessionId||t.instanceId,k=vn(t.type),C=(h=t.activeChat)==null?void 0:h.activeModal,y=C&&Array.isArray(C.buttons)&&C.buttons.length>0,T=Ye((p=t.activeChat)==null?void 0:p.status,{activeModal:(b=t.activeChat)==null?void 0:b.activeModal})||Ye((N=(m=t.agents)==null?void 0:m[0])==null?void 0:N.status)||"idle",v=t.activeChat||{title:"",messages:[]};let j=v.title&&String(v.title).trim()?String(v.title).trim():"";const D=(g=t.activeChat)==null?void 0:g.id,L=t.chats;if(D&&Array.isArray(L)&&L.length>0){const O=L.find(M=>M.id===D||M.id&&String(M.id)===String(D));O!=null&&O.title&&String(O.title).trim()&&(j=String(O.title).trim())}const P=(Ee(t)||Te(t))&&(t.cliType||t.acpType)||t.type,U=(Ee(t)||Te(t))&&wn(j,k,P)?"":j,$=v.messages||[],A=_n(s,[t.id,w]),F=$.filter(O=>String((O==null?void 0:O.role)||"").toLowerCase()==="user").slice(),B=A.filter(O=>{const M=F.findIndex(E=>Mn(E,O));return M>=0?(F.splice(M,1),!1):!0});r.push({ideId:t.id,sessionId:w,providerSessionId:t.providerSessionId,nativeSessionId:w,transport:t.transport,daemonId:t.daemonId||void 0,mode:Ee(t)?t.mode||"terminal":"chat",agentName:k,agentType:P,status:T,title:U,messages:[...$,...B],resume:t.resume,ideType:P,workspaceName:c,displayPrimary:c||U||(Ee(t)?t.mode==="chat"?k:"Terminal":k),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:y?C.buttons:void 0,modalMessage:y?C.message:void 0,streamSource:"native",tabKey:ks(w,t.id),machineName:i,connectionState:o})}if(f&&(Ee(t)||Te(t)))return r;for(const w of l){const k=w.activeModal&&Array.isArray(w.activeModal.buttons)&&w.activeModal.buttons.length>0,C=Ti(w),y=Zi(w),T=`${t.id}:${y}`,v=w.title&&String(w.title).trim()||"",j=wn(v,w.agentName,w.agentType)?"":v,D=w.messages||[],L=_n(s,[T,w.sessionId,w.instanceId]),P=D.filter(A=>String((A==null?void 0:A.role)||"").toLowerCase()==="user").slice(),U=L.filter(A=>{const F=P.findIndex(B=>Mn(B,A));return F>=0?(P.splice(F,1),!1):!0});(D.length>0||U.length>0||k||j||!["idle","panel_hidden","disconnected","not_monitored"].includes(C))&&r.push({ideId:t.id,sessionId:w.sessionId||w.instanceId,providerSessionId:w.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:w.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:w.agentName,agentType:w.agentType,status:C,title:j,messages:[...D,...U],ideType:w.agentType,workspaceName:c,displayPrimary:j||x||c||d,displaySecondary:`${d}·${w.agentName}`,cdpConnected:t.cdpConnected,modalButtons:k?w.activeModal.buttons:void 0,modalMessage:k?w.activeModal.message:void 0,streamSource:"agent-stream",tabKey:ks(w.sessionId||w.instanceId,T),machineName:i,connectionState:o})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,providerSessionId:t.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:vn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||d,displaySecondary:d,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:ks(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Ji(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const i=n.get(r.parentId)||[];i.push(r),n.set(r.parentId,i)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Qi(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Ji(d),u=l.filter(p=>p.kind==="workspace"&&p.transport==="cdp-page"),x=l.filter(p=>p.kind==="agent"&&p.transport==="pty"),h=l.filter(p=>p.kind==="agent"&&p.transport==="acp");n.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:u.some(p=>!!p.cdpConnected)});for(const p of u){const b=f.get(p.id)||[];n.push({id:`${r}:ide:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,status:p.cdpConnected?"online":"detected",daemonId:r,instanceId:p.id,workspace:p.workspace,terminals:0,childSessions:b,agents:b.map(m=>({id:m.id,name:m.providerName,type:m.providerType,status:m.status})),activeChat:p.activeChat,chats:[],cdpConnected:p.cdpConnected,currentModel:p.currentModel,currentPlan:p.currentPlan,currentAutoApprove:p.currentAutoApprove,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c})}for(const p of x)n.push({id:`${r}:cli:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:p.mode||"terminal",workspace:p.workspace||"",activeChat:p.activeChat,resume:p.resume,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isCli:!0});for(const p of h)n.push({id:`${r}:acp:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:"chat",workspace:p.workspace||"",activeChat:p.activeChat,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],currentModel:p.currentModel,currentPlan:p.currentPlan,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,acpConfigOptions:p.acpConfigOptions,acpModes:p.acpModes,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isAcp:!0});return n}function eo(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 to(t,s){const n=eo(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Ir=[{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:"💚"}],Mr=[{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:"🧩"}],_r=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Tr="adhdev_notification_prefs",Tn={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function so(){try{const t=localStorage.getItem(Tr);if(t){const s=JSON.parse(t);return{...Tn,...s}}}catch{}return{...Tn}}function no(t){try{localStorage.setItem(Tr,JSON.stringify(t))}catch{}}let st=so(),Zt=[];function ro(){Zt.forEach(t=>t())}function ao(){return{...st}}function io(t){st={...st,...t},no(st),ro()}function oo(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Zt.push(n),()=>{Zt=Zt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{io(n)},[]);return[{...st},s]}function Tt(t){if(!st.globalEnabled)return!1;switch(t){case"disconnect":return st.disconnectAlert;case"completion":return st.completionAlert;case"approval":return st.approvalAlert;case"browser":return st.browserNotifications;default:return!0}}const co={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function lo(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Ar(){return"Notification"in window&&Notification.permission==="granted"}let pt=null;async function uo(){if(pt!==null)return pt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return pt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(pt=!!await t.pushManager.getSubscription(),pt):(pt=!1,!1)}catch{return pt=!1,!1}}function Es(t,s,n){if(Ar())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:n||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function po(t,s={}){const n={...co,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{uo().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Es(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!Ar())&&Tt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Ye(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),u=Ye(l.status,{activeModal:l.activeModal}),x=l.name||l.id;if(n.onApproval&&Tt("approval")&&u==="waiting_approval"&&f!=="waiting_approval"){const h=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${x} — Approval needed`,h.slice(0,120),`approval-${l.id}`)}n.onComplete&&Tt("completion")&&br(f)&&u==="idle"&&c(`✅ ${x} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&f!=="error"&&c(`⚠️ ${x} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class mo{constructor(){We(this,"dedupMap",new Map);We(this,"DEDUP_WINDOW_MS",5e3);We(this,"DEDUP_MAX_SIZE",50);We(this,"DEDUP_CLEANUP_AGE_MS",1e4);We(this,"toastCallbacks",[]);We(this,"systemMessageCallbacks",[]);We(this,"clearSystemMessageCallbacks",[]);We(this,"resolveActionFn",null);We(this,"viewRequestRespondFn",null);We(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,x;if(!s.ideId&&s.instanceId){for(const h of this.ides)if(h.id.endsWith(`:ide:${s.instanceId}`)||h.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=h.id;break}}const r=this.resolveConversationKey(s),o=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=_e(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=nt(d,{fallbackId:d.id});h&&(c=s.ideType==="adhdev-daemon"?h:`${h}/${c}`)}let l="",f="info";if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${h}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&ao().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${h}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,f="warning",r){const h=s.modalMessage||"Approval requested",p=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
36
- ${p}`,_localId:`sys_approval_${Date.now()}`})}if((x=s.modalButtons)!=null&&x.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const p=s.agentType||s.ideType||"",b=s.ideType||"",m=s.modalButtons,N=y=>y.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),g=this.resolveActionFn,w=m.map((y,T)=>{const v=N(y).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(v),D=/^(reject|deny|delete|remove|abort|cancel|no)/.test(v);return{label:N(y),variant:j?"primary":D?"danger":"default",onClick:()=>{const L=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v);g(h,"resolve_action",{action:L?"approve":"reject",button:y,buttonIndex:T,agentType:p,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),k=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,C=Date.now();this.emitToast({id:C,message:k,type:f,timestamp:C,targetKey:r||h,actions:w,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${h}`,f="warning",Tt("browser")&&!document.hasFocus()&&Es(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",p=s.requestId,b=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",p&&b&&this.viewRequestRespondFn){const m=this.viewRequestRespondFn,N=Date.now(),g=[{label:"Approve",variant:"primary",onClick:()=>{m(b,p,"approve").catch(w=>console.error("[EventManager] approve view request failed:",w))}},{label:"Decline",variant:"danger",onClick:()=>{m(b,p,"reject").catch(w=>console.error("[EventManager] reject view request failed:",w))}}];this.emitToast({id:N,message:l,type:f,timestamp:N,actions:g,duration:3e4}),l=""}Tt("browser")&&!document.hasFocus()&&Es("👁️ View Request",`${h} wants to view your session`,`view-request-${p}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:r||s.ideId,duration:5e3})}}}const lt=new mo;function gt(...t){return Sa(Ca(t))}function xo({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:gt("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function is({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(xo,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:gt("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function Ve({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:gt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Zs({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:gt("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const fo={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"},ho={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function bo({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:gt("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",fo[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ho[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const go={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"},yo={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function vo({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:gt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",go[t],n),children:[e.jsx("span",{className:gt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",yo[t])}),r]})}function wo(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ds(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Jt(t){return t==="system"?wo():t}function jo(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Jt(Ds()))}function Lr(){const[t,s]=a.useState(Ds),[n,r]=a.useState(()=>Jt(Ds()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Jt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Jt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function dt({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:`flex justify-between items-center ${r?"cursor-not-allowed opacity-60":"cursor-pointer"}`,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("div",{className:"relative inline-flex items-center",children:[e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function ko({onPrefChange:t}){const[s,n]=oo(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ti,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(si,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(bt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function No({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Zs,{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(Co,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function An({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return Ia.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:r==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:n})]})]})}),document.body)}function So(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Ir,...Mr,..._r].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Co({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var A,F;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,u]=a.useState(null),[x,h]=a.useState("idle"),[p,b]=a.useState(""),m=t,N=m.version||m.daemonVersion||null,g=((A=m.machine)==null?void 0:A.platform)||((F=m.system)==null?void 0:F.platform)||"",w=nt(m,{fallbackId:t.id}),k=g==="win32"?"🪟":g==="darwin"?"🍎":"🐧",C=s.filter(B=>B.daemonId===t.id&&B.transport==="cdp-page"),y=s.filter(B=>B.daemonId===t.id&&B.transport==="pty"),T=s.filter(B=>B.daemonId===t.id&&B.transport==="acp"),v=m.p2p,j=async()=>{var B,O,M,E;if(n){c("upgrading"),l("Starting upgrade...");try{const _=await n(t.id,"daemon_upgrade",{});(B=_==null?void 0:_.result)!=null&&B.alreadyLatest?(c("done"),l(`Already on v${_.result.version||"latest"}.`)):(O=_==null?void 0:_.result)!=null&&O.upgraded||(M=_==null?void 0:_.result)!=null&&M.success?(c("done"),l(`Upgrade to v${_.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((E=_==null?void 0:_.result)==null?void 0:E.error)||"Upgrade failed"))}catch(_){c("error"),l((_==null?void 0:_.message)||"Connection lost during upgrade")}}},D=async()=>{if(u(null),!!r){h("loading");try{await r(t.id),h("done"),b("Machine disconnected.")}catch(B){h("error"),b((B==null?void 0:B.message)||"Failed to disconnect")}}},L=async()=>{if(u(null),!!i){h("loading");try{await i(t.id),h("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(B){h("error"),b((B==null?void 0:B.message)||"Failed to revoke token")}}},P="0.8.8",U=!N||N!==P,$=C.length+y.length+T.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:k}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:w}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),N&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${U?"":"bg-bg-secondary"}`,style:U?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",N,!U&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&U&&e.jsx("button",{onClick:j,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${P}`,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${P}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:x==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:x==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(vo,{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:[v&&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 ${v.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${v.state==="connecting"||v.state==="new"?"animate-pulse":""}`,style:v.state==="connecting"||v.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",v.state==="connected"?"connected":v.state==="connecting"||v.state==="new"?"connecting...":v.state||"off"]}),v.peers!==void 0&&v.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",v.peers," peer",v.peers!==1?"s":"",")"]})]}),v&&$>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),$>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[C.map(B=>{const O=So(B.type),M=B.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:O.icon}),e.jsx("span",{children:O.name}),M!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${M?"bg-green-400":"animate-pulse"}`,style:M?void 0:{background:"var(--status-warning)"},title:M?"CDP connected":"CDP connecting..."})]},B.id)}),y.map(B=>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:B.cliName||"CLI"})]},B.id)),T.map(B=>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:B.cliName||"ACP"})]},B.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||x==="error"?"text-red-400":o==="done"||x==="done"?"text-green-400":"text-text-muted"}`,children:p||d})]}),f==="disconnect"&&e.jsx(An,{title:"🔌 Disconnect Machine",message:`Disconnect "${w}" from ADHDev?
36
+ ${p}`,_localId:`sys_approval_${Date.now()}`})}if((x=s.modalButtons)!=null&&x.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const p=s.agentType||s.ideType||"",b=s.ideType||"",m=s.modalButtons,N=y=>y.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),g=this.resolveActionFn,w=m.map((y,T)=>{const v=N(y).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(v),D=/^(reject|deny|delete|remove|abort|cancel|no)/.test(v);return{label:N(y),variant:j?"primary":D?"danger":"default",onClick:()=>{const L=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v);g(h,"resolve_action",{action:L?"approve":"reject",button:y,buttonIndex:T,agentType:p,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),k=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,C=Date.now();this.emitToast({id:C,message:k,type:f,timestamp:C,targetKey:r||h,actions:w,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${h}`,f="warning",Tt("browser")&&!document.hasFocus()&&Es(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",p=s.requestId,b=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",p&&b&&this.viewRequestRespondFn){const m=this.viewRequestRespondFn,N=Date.now(),g=[{label:"Approve",variant:"primary",onClick:()=>{m(b,p,"approve").catch(w=>console.error("[EventManager] approve view request failed:",w))}},{label:"Decline",variant:"danger",onClick:()=>{m(b,p,"reject").catch(w=>console.error("[EventManager] reject view request failed:",w))}}];this.emitToast({id:N,message:l,type:f,timestamp:N,actions:g,duration:3e4}),l=""}Tt("browser")&&!document.hasFocus()&&Es("👁️ View Request",`${h} wants to view your session`,`view-request-${p}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:r||s.ideId,duration:5e3})}}}const lt=new mo;function gt(...t){return Sa(Ca(t))}function xo({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:gt("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function is({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(xo,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:gt("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function Ve({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:gt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Zs({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:gt("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const fo={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"},ho={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function bo({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:gt("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",fo[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ho[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const go={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"},yo={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function vo({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:gt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",go[t],n),children:[e.jsx("span",{className:gt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",yo[t])}),r]})}function wo(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ds(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Jt(t){return t==="system"?wo():t}function jo(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Jt(Ds()))}function Lr(){const[t,s]=a.useState(Ds),[n,r]=a.useState(()=>Jt(Ds()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Jt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Jt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function dt({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:`flex justify-between items-center ${r?"cursor-not-allowed opacity-60":"cursor-pointer"}`,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("div",{className:"relative inline-flex items-center",children:[e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function ko({onPrefChange:t}){const[s,n]=oo(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ti,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(si,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(bt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function No({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Zs,{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(Co,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function An({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return Ia.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:r==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:n})]})]})}),document.body)}function So(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Ir,...Mr,..._r].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Co({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var A,F;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,u]=a.useState(null),[x,h]=a.useState("idle"),[p,b]=a.useState(""),m=t,N=m.version||m.daemonVersion||null,g=((A=m.machine)==null?void 0:A.platform)||((F=m.system)==null?void 0:F.platform)||"",w=nt(m,{fallbackId:t.id}),k=g==="win32"?"🪟":g==="darwin"?"🍎":"🐧",C=s.filter(B=>B.daemonId===t.id&&B.transport==="cdp-page"),y=s.filter(B=>B.daemonId===t.id&&B.transport==="pty"),T=s.filter(B=>B.daemonId===t.id&&B.transport==="acp"),v=m.p2p,j=async()=>{var B,O,M,E;if(n){c("upgrading"),l("Starting upgrade...");try{const _=await n(t.id,"daemon_upgrade",{});(B=_==null?void 0:_.result)!=null&&B.alreadyLatest?(c("done"),l(`Already on v${_.result.version||"latest"}.`)):(O=_==null?void 0:_.result)!=null&&O.upgraded||(M=_==null?void 0:_.result)!=null&&M.success?(c("done"),l(`Upgrade to v${_.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((E=_==null?void 0:_.result)==null?void 0:E.error)||"Upgrade failed"))}catch(_){c("error"),l((_==null?void 0:_.message)||"Connection lost during upgrade")}}},D=async()=>{if(u(null),!!r){h("loading");try{await r(t.id),h("done"),b("Machine disconnected.")}catch(B){h("error"),b((B==null?void 0:B.message)||"Failed to disconnect")}}},L=async()=>{if(u(null),!!i){h("loading");try{await i(t.id),h("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(B){h("error"),b((B==null?void 0:B.message)||"Failed to revoke token")}}},P="0.8.10",U=!N||N!==P,$=C.length+y.length+T.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:k}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:w}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),N&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${U?"":"bg-bg-secondary"}`,style:U?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",N,!U&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&U&&e.jsx("button",{onClick:j,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${P}`,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${P}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:x==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:x==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(vo,{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:[v&&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 ${v.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${v.state==="connecting"||v.state==="new"?"animate-pulse":""}`,style:v.state==="connecting"||v.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",v.state==="connected"?"connected":v.state==="connecting"||v.state==="new"?"connecting...":v.state||"off"]}),v.peers!==void 0&&v.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",v.peers," peer",v.peers!==1?"s":"",")"]})]}),v&&$>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),$>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[C.map(B=>{const O=So(B.type),M=B.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:O.icon}),e.jsx("span",{children:O.name}),M!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${M?"bg-green-400":"animate-pulse"}`,style:M?void 0:{background:"var(--status-warning)"},title:M?"CDP connected":"CDP connecting..."})]},B.id)}),y.map(B=>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:B.cliName||"CLI"})]},B.id)),T.map(B=>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:B.cliName||"ACP"})]},B.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||x==="error"?"text-red-400":o==="done"||x==="done"?"text-green-400":"text-text-muted"}`,children:p||d})]}),f==="disconnect"&&e.jsx(An,{title:"🔌 Disconnect Machine",message:`Disconnect "${w}" from ADHDev?
37
37
 
38
38
  This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
39
39
 
@@ -44,7 +44,7 @@ This will:
44
44
  • Delete the machine registration
45
45
  • Require restarting "adhdev-standalone" on that machine
46
46
 
47
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:L,onCancel:()=>u(null)})]})}const Io=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Mo(){const{preference:t,setPreference:s}=Lr();return e.jsx("div",{className:"flex gap-2",children:Io.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===n.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}function _o(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 To(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Ns(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function Ln(t){const{r:s,g:n,b:r}=To(t);return .2126*Ns(s)+.7152*Ns(n)+.0722*Ns(r)}function Rn(t,s){const n=Ln(t),r=Ln(s),i=Math.max(n,r),o=Math.min(n,r);return(i+.05)/(o+.05)}function Js(t){const s=_o(t);if(!s)return"#111827";const n="#111827",r="#ffffff";return Rn(s,n)>=Rn(s,r)?n:r}const Rr="adhdev-accent-color",Bs="#cf7a45";function Ao(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,r),o=Math.min(s,n,r);let c=0,d=0;const l=(i+o)/2;if(i!==o){const f=i-o;switch(d=l>.5?f/(2-i-o):f/(i+o),i){case s:c=((n-r)/f+(n<r?6:0))/6;break;case n:c=((r-s)/f+2)/6;break;case r:c=((s-n)/f+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)}}function Pn(t,s){const{h:n,s:r,l:i}=Ao(t),o=Math.min(100,i+s);return`hsl(${n}, ${r}%, ${o}%)`}function Ss(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function Lo(){return typeof window>"u"?Bs:localStorage.getItem(Rr)||Bs}function Ro(){if(typeof window>"u")return!1;try{return localStorage.getItem(Rr)!=null}catch{return!1}}function Po(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",Pn(t,15)),s.style.setProperty("--accent-on-primary",Js(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${Pn(t,20)})`),s.style.setProperty("--border-accent",Ss(t,.4)),s.style.setProperty("--nav-active-bg",Ss(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${Ss(t,.06)}`)}function $o(){const t=Lo();t!==Bs&&Po(t)}const Ks={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},Ws={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},Eo=[{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"}}}],Pr="adhdev-chat-theme",$r="adhdev-chat-theme-custom";function Qt(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Pr)||"ember"}catch{return"ember"}}function et(t){try{const s=localStorage.getItem($r);if(s){const n=JSON.parse(s);return{...t==="dark"?Ks:Ws,...n[t]}}}catch{}return t==="dark"?Ks:Ws}function Ht(t,s){try{localStorage.setItem($r,JSON.stringify({dark:t,light:s}))}catch{}}function Je(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function os(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Do={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function At(t,s){var i;if(Ro())return;const n=(i=Do[t])==null?void 0:i[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",os(n,24)),r.style.setProperty("--accent-on-primary",Js(n)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${os(n,18)})`),r.style.setProperty("--border-accent",Je(n,.35)),r.style.setProperty("--nav-active-bg",Je(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Je(n,.06)}`)}function xt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Je(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Je(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Je(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Je(t.borderSubtle,.5)),s.style.setProperty("--border-default",Je(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",os(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Js(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${os(t.accentColor,40)})`),s.style.setProperty("--border-accent",Je(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Je(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Je(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Je(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Qs(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function Bo(t){try{localStorage.setItem(Pr,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else Qs(),At(t,ft()?"dark":"light")}function Ko(){const t=Qt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else Qs(),At(t,ft()?"dark":"light")}function ft(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Fe({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function Ct({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function Wo({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>et(n));a.useEffect(()=>{i(et(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},x=et(n==="dark"?"light":"dark");return n==="dark"?Ht(f,x):Ht(x,f),xt(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(Ct,{title:"App Background",children:[e.jsx(Fe,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Fe,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Fe,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Ct,{title:"App Text",children:[e.jsx(Fe,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Fe,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Fe,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Ct,{title:"Borders & Accent",children:[e.jsx(Fe,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Fe,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Fe,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Ct,{title:"Chat Bubbles",children:[e.jsx(Fe,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Fe,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Fe,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Fe,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Ct,{title:"Chat Layout",children:[e.jsx(Fe,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Fe,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Fe,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ks:Ws,l=et(t?"light":"dark");t?Ht(c,l):Ht(l,c),i(c),xt(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Oo(){const[t,s]=a.useState(Qt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>et("dark"));a.useEffect(()=>{r(ft());const l=new MutationObserver(()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")};return f.addEventListener("change",u),()=>{l.disconnect(),f.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?xt(et(n?"dark":"light")):(Qs(),At(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(et(n?"dark":"light"))},[n]);const c=l=>{s(l),Bo(l)},d=[...Eo,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const f=t===l.id,u=n?l.preview.dark:l.preview.light,x=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:x},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Wo,{dark:n,onColorsChange:l=>o(l)})]})}const Er="adhdev_mobileDashboardMode_v1";function Dr(){try{return localStorage.getItem(Er)==="workspace"?"workspace":"chat"}catch{return"chat"}}function zo(t){try{localStorage.setItem(Er,t)}catch{}}function Uo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Dr()==="chat")},[]),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:n=>{s(n),zo(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Br="adhdev_hiddenTabs";function Ho(){try{const t=localStorage.getItem(Br);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function yt(t){try{localStorage.setItem(Br,JSON.stringify([...t]))}catch{}}function Fo(){const[t,s]=a.useState(Ho),n=a.useCallback(f=>{s(u=>{const x=new Set(u);return x.has(f)?x.delete(f):x.add(f),yt(x),x})},[]),r=a.useCallback(f=>{s(u=>{if(u.has(f))return u;const x=new Set(u);return x.add(f),yt(x),x})},[]),i=a.useCallback(f=>{s(u=>{if(!u.has(f))return u;const x=new Set(u);return x.delete(f),yt(x),x})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const u=new Set;return yt(u),u})},[]),c=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.add(p);return yt(h),h})},[]),d=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.delete(p);return yt(h),h})},[]),l=a.useCallback(f=>t.has(f),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:d,isHidden:l}}function Vo({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{lo()},[]);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 po(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[u,x]of Object.entries(d))l-x<5e3&&(f[u]=x);return Object.keys(f).length===Object.keys(d).length?d:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(d=>{const l=d.filter(f=>f.timestamp>c).slice(-100);return l.length===d.length?d:l})},6e4);return()=>clearInterval(o)},[r]),null}function Cs(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function jt(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return Cs(s==null?void 0:s.timestamp)||Cs(s==null?void 0:s.receivedAt)||Cs(s==null?void 0:s.createdAt)||0}function $n(t){return jt(t)}function Kr(t,s){const n=$n(s)-$n(t);if(n!==0)return n;const r=(t.machineName||"").localeCompare(s.machineName||"");if(r!==0)return r;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const o=t.displaySecondary.localeCompare(s.displaySecondary);return o!==0?o:t.tabKey.localeCompare(s.tabKey)}function qo(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const i=n.get(r.id);if(!i){n.set(r.id,r);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>o||(r.timestamp||0)>(i.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function Ft(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function Go(t,s){const n=Date.now();return t.map(r=>{const i=s[r.tabKey];return i&&n-i<5e3?{...r,messages:[],title:""}:r})}function Yo(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;n.push({key:c,ref:s[c]}),n.push({key:i.id,ref:s[i.id]})}return n}function Xo(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n].key!==s[n].key||t[n].ref!==s[n].ref)return!1;return!0}function Zo({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),d=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const C=qo(t);return Ft(o.current,C)?o.current:(o.current=C,C)},[t]),u=a.useMemo(()=>Sr(t),[t]),x=a.useRef(new Map),h=a.useMemo(()=>{var T;const C=new Map,y=[];for(const v of f){const j=v.daemonId||((T=v.id)==null?void 0:T.split(":")[0])||v.id,D=s[j]||"new",L=v.daemonId&&u[v.daemonId]||void 0,P=Yo(v,n),U=x.current.get(v.id);if(U&&U.ide===v&&U.connectionState===D&&U.machineName===L&&Xo(U.localRefs,P)){C.set(v.id,U),y.push(...U.conversations);continue}const $=Cr(v,n,{machineName:L,connectionState:D}),A={ide:v,connectionState:D,machineName:L,localRefs:P,conversations:$};C.set(v.id,A),y.push(...$)}return x.current=C,[...y].sort(Kr)},[f,n,s,u]),p=a.useMemo(()=>{const C=Go(h,r);return Ft(c.current,C)?c.current:(c.current=C,C)},[h,r]),b=a.useMemo(()=>{const C=new Map;for(const y of p)y.sessionId&&C.set(y.sessionId,y);return C},[p]),m=a.useMemo(()=>{const C=new Map;for(const y of p)y.sessionId&&C.set(y.sessionId,y),C.set(y.ideId,y),C.set(y.tabKey,y);return C},[p]),N=a.useCallback(C=>{if(C)return b.get(C)},[b]),g=a.useCallback(C=>{if(C)return m.get(C)},[m]),w=a.useMemo(()=>{const C=p.filter(y=>!i.has(y.tabKey));return Ft(d.current,C)?d.current:(d.current=C,C)},[p,i]),k=a.useMemo(()=>{const C=w.map(y=>y.tabKey);return Ft(l.current,C)?l.current:(l.current=C,C)},[w]);return{chatIdes:f,conversations:p,visibleConversations:w,visibleTabKeys:k,resolveConversationBySessionId:N,resolveConversationByTarget:g}}function Jo({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var d;return t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var d;return!t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(d=>{const l=new URLSearchParams(d);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function Qo({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{lt.setIdes(t)},[t]),a.useEffect(()=>{lt.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=lt.onToast(l=>{n(u=>u.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?u:[...u.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const f=l.duration||5e3;setTimeout(()=>n(u=>u.filter(x=>x.id!==l.id)),f)}),c=lt.onSystemMessage((l,f)=>{var p,b;const u=i(l),x=(p=f._localId)==null?void 0:p.startsWith("sys_approval_"),h=!!(u&&(u.status==="waiting_approval"||(b=u.modalButtons)!=null&&b.length||u.modalMessage));x&&h||r(m=>({...m,[l]:[...m[l]||[],f]}))}),d=lt.onClearSystemMessage((l,f)=>{r(u=>{var x;return(x=u[l])!=null&&x.length?{...u,[l]:u[l].filter(h=>{var p;return!(h.role==="system"&&((p=h._localId)!=null&&p.startsWith(f)))})}:u})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=jr.on("status_event",c=>lt.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=d=>{const l=d.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,u=i(f),x=(u==null?void 0:u.ideId)||l.ideId;x&&s(x,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(h=>console.error("[SW Action] approve failed:",h))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var d;return(d=navigator.serviceWorker)==null?void 0:d.removeEventListener("message",o)}},[i,s])}const ec="adhdev_dashboardLayout_v1",tc="adhdev_dashboardDockview_v1",It={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Wr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Or(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function zr(t){return`${ec}:${t}`}function sc(t){const s=zr(t);return Wr(s,null)}function nc(t,s){try{const n=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,r=zr(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Ur(t){return`${tc}:${t}`}function rc(t){const s=Ur(t);return Wr(s,null)}function ac(t,s){try{const n=Ur(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function ic(){return{groupAssignments:[...It.groupAssignments],focusedGroup:It.focusedGroup,groupActiveTabIds:{...It.groupActiveTabIds},groupTabOrders:{...It.groupTabOrders},groupSizes:[...It.groupSizes]}}function oc(){const[t]=a.useState(()=>Or(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[d,l]=a.useState({}),[f,u]=a.useState([]),[x,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,b]=a.useState(!1),m=a.useCallback(()=>{if(p)return;const N=sc(t)??ic();n(new Map(N.groupAssignments)),i(N.focusedGroup),c(N.groupActiveTabIds),l(N.groupTabOrders),u(N.groupSizes),b(!0)},[p,t]);return a.useEffect(()=>{p&&nc(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[p,t,s,r,o,d,f]),a.useEffect(()=>{const N=window.matchMedia("(max-width: 767px)"),g=w=>h(w.matches);return N.addEventListener("change",g),()=>N.removeEventListener("change",g)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:u,isMobile:x,hasHydratedStoredLayout:p,hydrateStoredLayout:m}}function cc({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:u,isRefreshingHistory:x,ides:h,handleRefreshHistory:p}){const b=a.useRef(!1),m=a.useRef(!1),N=a.useRef(null),g=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!i){o();return}const w=n(t);if(!w)return;const k=r.get(w.tabKey)??0;c(C=>({...C,[k]:w.tabKey})),d(k),b.current=!0,m.current=!0,N.current!=null&&(window.clearTimeout(N.current),N.current=null),l(C=>{const y=new URLSearchParams(C);return y.delete("activeTab"),y},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(m.current||i)&&s.length!==0){if(!t){o(),m.current=!0;return}if(b.current){m.current=!0;return}if(N.current==null)return N.current=window.setTimeout(()=>{N.current=null,!(m.current||i)&&(o(),m.current=!0)},1500),()=>{N.current!=null&&(window.clearTimeout(N.current),N.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){g.current=!1;return}if(!u||g.current||x)return;const w=h.find(k=>k.id===u.ideId);w&&(!w.chats||w.chats.length===0)&&(g.current=!0,p())},[f,u,x,h,p]),a.useEffect(()=>{if(!u)return;let w=null,k=0,C=-1,y=0;const T=()=>{w=null;const v=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(D=>D.offsetParent!==null);if(v.length===0){k<18&&(k+=1,w=requestAnimationFrame(T));return}let j=0;for(const D of v)D.scrollTop=D.scrollHeight,j+=D.scrollHeight;j===C?y+=1:(y=0,C=j),k+=1,!(y>=2||k>=18)&&(w=requestAnimationFrame(T))};return w=requestAnimationFrame(T),()=>{w!=null&&cancelAnimationFrame(w)}},[u==null?void 0:u.tabKey])}function lc({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[u,x]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const g=d(r);return g&&!Ee(g)&&!Te(g)?g:null},[t,r,d]),p=a.useMemo(()=>{const g=l==null?void 0:l.ideId;if(!g)return null;const w=l!=null&&l.tabKey?o.find(k=>k.tabKey===l.tabKey):i?o.find(k=>k.tabKey===i):null;return(w==null?void 0:w.ideId)===g?w:o.find(k=>k.ideId===g&&k.streamSource==="native")||o.find(k=>k.ideId===g)||null},[o,l,i]),b=a.useMemo(()=>{if(p)return c.find(g=>g.id===p.ideId)},[c,p]);a.useEffect(()=>{h&&(f({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),x(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const m=a.useCallback(g=>{g&&(f({ideId:g.ideId,tabKey:g.streamSource==="native"?"native":g.tabKey}),x(g))},[]),N=a.useCallback(()=>{f(null),x(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:b,remoteDialogActiveConv:u,setRemoteDialogActiveConv:x,openRemoteDialog:m,closeRemoteDialog:N}}function Lt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ee(t)||Te(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function cs(t){return t&&(t.ideId||t.daemonId)||""}function Vt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function En({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),u=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(m){console.error("Launch failed",m)}},[t]),x=a.useCallback(async(b,m)=>{try{const N=b||(s==null?void 0:s.daemonId)||"",g=await t(N,"switch_chat",{id:m,sessionId:m,...Lt(s)}),w=g==null?void 0:g.result;if((g==null?void 0:g.success)===!0||w==="switched"||w==="switched-by-title")return;w===!1||w==="not_found"?Vt(r,"⚠️ Session tab not found — try refreshing history"):typeof w=="string"&&w.startsWith("error:")?Vt(r,`⚠️ Switch error: ${w}`):Vt(r,"⚠️ Session switch failed")}catch(N){console.error("Switch failed",N),Vt(r,`❌ Switch failed: ${N.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const b=cs(s);await t(b,"new_chat",{...Lt(s)}),o(m=>({...m,[s.tabKey]:Date.now()})),i(m=>({...m,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{d(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var b;if(!(!s||l)){f(!0);try{const m=cs(s),N=await t(m,"list_chats",{forceExpand:!0,...Lt(s)}),g=(N==null?void 0:N.chats)||((b=N==null?void 0:N.result)==null?void 0:b.chats);N!=null&&N.success&&Array.isArray(g)&&n(s.ideId,g)}catch(m){console.error("Refresh history failed",m)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:x,handleNewChat:h,handleRefreshHistory:p}}function dc(t,s){if(t.size!==s.size)return!1;for(const[n,r]of t)if(s.get(n)!==r)return!1;return!0}function uc(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Dn(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[Number(i)]===t[Number(i)])}function qt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Bn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function pc(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function mc(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Kn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=Number(r);n[o>=s?o+1:o]=i}return n}function Wn(t){return Array(t).fill(100/t)}function xc({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const u=a.useRef(null),x=a.useMemo(()=>qt(t,f),[t,f]),h=x.assignments,p=a.useMemo(()=>d?1:x.groupCount,[x.groupCount,d]),b=p>1,m=a.useCallback((y,T)=>{s(v=>{const j=new Map(qt(v,f).assignments);return T===0?j.delete(y):j.set(y,T),j}),r(v=>({...v,[T]:y})),n(T)},[s,f,r,n]),N=a.useCallback(y=>{s(T=>{const v=qt(T,f).assignments,j=new Map;for(const[D,L]of v)L!==y&&(L>y?j.set(D,L-1):j.set(D,L));return j}),c(T=>{if(T.length<=1)return[];const v=[...T];v.splice(y,1);const j=v.reduce((D,L)=>D+L,0);return j>0?v.map(D=>D/j*100):[]}),n(0)},[s,f,c,n]),g=a.useCallback((y,T)=>{T.preventDefault();const v=u.current;if(!v)return;const j=T.clientX,D=v.offsetWidth,L=o.length===p?[...o]:Wn(p),P=$=>{const F=($.clientX-j)/D*100,B=[...L];B[y]=Math.max(15,L[y]+F),B[y+1]=Math.max(15,L[y+1]-F),c(B)},U=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",U),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",P),document.addEventListener("mouseup",U)},[o,p,c]),w=a.useCallback((y,T,v)=>{if(p>=4)return;const j=v==="left"?T:T+1;s(D=>{const L=qt(D,f).assignments,P=new Map;for(const U of l){const $=L.get(U.tabKey)??0,A=$>=j?$+1:$;A>0&&P.set(U.tabKey,A)}return j>0&&P.set(y,j),P}),c(D=>{const L=D.length===p?[...D]:Wn(p),P=L[T]??100/p,U=Math.max(15,P/2),$=Math.max(15,P/2),A=[...L];A[T]=U,A.splice(j,0,$);const F=A.reduce((B,O)=>B+O,0);return A.map(B=>B/F*100)}),r(D=>{const L=Kn(D,j);return L[j]=y,L}),i(D=>{const L=Kn(D,j);return L[j]=[y],L}),n(j)},[p,s,f,l,c,r,i,n]);a.useEffect(()=>{dc(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:y,usedGroups:T}=x;r(v=>{const j=Bn(v,y);return Dn(v,j)?v:j}),i(v=>{const j=Bn(v,y);return Dn(v,j)?v:j}),n(v=>{const j=d?0:pc(v,T,y);return v===j?v:j}),c(v=>{const j=d?[]:mc(v,T,x.groupCount);return uc(v,j)?v:j})},[x,d,r,i,n,c]);const k=a.useMemo(()=>{const y=Array.from({length:p},()=>[]);for(const T of l){const v=h.get(T.tabKey)??0,j=Math.min(v,p-1);y[j].push(T)}return y},[l,h,p]),C=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:h,numGroups:p,isSplitMode:b,groupedConvs:k,moveTabToGroup:m,closeGroup:N,handleResizeStart:g,splitTabRelative:w,clearAllSplits:C}}function fc({ides:t,sendDaemonCommand:s}){const n="0.8.8",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const u=f.version||f.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var u,x;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(u=h==null?void 0:h.result)!=null&&u.upgraded||(x=h==null?void 0:h.result)!=null&&x.success?d(p=>({...p,[f]:"done"})):d(p=>({...p,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function xs({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[d,l]=a.useState(!1),f=a.useRef(!1),u=a.useRef(null),x=a.useCallback(async m=>{if(!s)return;const N=m.trim();if(!N||f.current)return;const g=s.tabKey,w=Date.now(),k=u.current;if(k&&k.tabKey===g&&k.message===N&&w-k.timestamp<2e3)return;f.current=!0,l(!0),u.current={tabKey:g,message:N,timestamp:w};const C=`${w}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:N,timestamp:w,_localId:C};n(T=>({...T,[g]:[...T[g]||[],y]}));try{const T=cs(s);if(!T)return;const v=await t(T,"send_chat",{message:N,text:N,...Lt(s)});if(v!=null&&v.deduplicated||(v==null?void 0:v.sent)===!1){n(j=>({...j,[g]:(j[g]||[]).filter(D=>D._localId!==C)}));return}setTimeout(()=>{const j=Date.now()-6e4;n(D=>{const L=D[g];if(!L)return D;const P=L.filter(U=>U.timestamp>j);return P.length===L.length?D:{...D,[g]:P}})},6e4)}catch(T){console.error("Send failed",T),n(v=>({...v,[g]:(v[g]||[]).filter(j=>j._localId!==C)}))}finally{f.current=!1,l(!1)}},[s,t,n]),h=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(m){console.error("Relaunch failed",m)}},[s,t]),p=a.useCallback(async m=>{if(s)try{const g=(s.modalButtons||[]).indexOf(m),w=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),k=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w),C=cs(s);if(!C)return;(await t(C,"resolve_action",{button:m,action:k?"approve":"reject",...g>=0&&{buttonIndex:g},...Lt(s)})).success||r(T=>[...T,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(N){console.error("[ModalButton] Error:",N),r(g=>[...g,{ideId:s.tabKey,text:`❌ **${m}** error`,timestamp:Date.now()}])}},[s,t,r]),b=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:x,handleRelaunch:h,handleModalButton:p,handleFocusAgent:b}}const en=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p}){return e.jsxs(e.Fragment,{children:[e.jsx(hr,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(Vs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:d,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:r?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Ui,{activeConv:s,clearToken:n,terminalRef:o,handleSendChat:l,isSendingChat:f,isVisible:r})}),!r&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx($s,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})})]}):e.jsx($s,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function hc({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:u,onOpenRemote:x,onHideConversation:h,onStopCli:p,cliViewMode:b,onSetCliViewMode:m,handleSendChat:N,handleFocusAgent:g,handleModalButton:w,handleRelaunch:k}){const C=a.useRef(null),y=Ee(t)&&!s,T=y&&b==="terminal";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5 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(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(yr,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[y&&b&&e.jsx(Xs,{mode:b,onChange:m,compact:!0}),y&&p&&e.jsx("button",{onClick:()=>{p(t)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(kt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(t),type:"button",children:e.jsx(Hs,{size:14})}),!s&&!y&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(t),type:"button",children:e.jsx(qe,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(kt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(en,{activeConv:t,clearToken:0,isCliTerminal:T,ideEntry:n,terminalRef:C,handleModalButton:w,handleRelaunch:k,handleSendChat:N,isSendingChat:o,handleFocusAgent:g,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const Is={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function bc(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Hr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(bc())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(Is[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Is[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Is[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Fr({section:t,onSectionChange:s}){const n=[{key:"machines",label:"Machines",icon:qe},{key:"chats",label:"Chats",icon:it}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:n.map(({key:r,label:i,icon:o})=>{const c=t===r;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(r),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(o,{size:15})}),e.jsx("span",{children:i})]},r)})})})}function Gt({title:t,className:s=""}){return e.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${s}`,children:e.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:t})})}function vt({children:t,className:s=""}){return e.jsx("div",{className:`overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function Mt({icon:t,title:s,subtitle:n,children:r}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 pt-12 pb-8 px-6 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),r]})}function Yt({item:t,type:s,getAvatarText:n,onOpenConversation:r}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`group flex items-start gap-3.5 px-4 py-3.5 w-full text-left relative overflow-hidden transition-colors active:scale-[0.995] ${i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":"bg-transparent"} ${c?"opacity-70 saturate-50":""}`,onClick:()=>r(t.conversation),type:"button",children:[i||o?e.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,e.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary shadow-glow":o?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":"bg-bg-primary border border-border-subtle text-text-secondary"}`,style:i?{color:"var(--accent-on-primary)"}:void 0,children:n(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:fr(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(qe,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]},t.conversation.tabKey)}function On({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function gc({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:u,onOpenMachine:x,onOpenSettings:h,onSectionChange:p,wsStatus:b="connected",isStandalone:m=!1}){const N=b==="disconnected"||b==="reconnecting"||b==="offline"||b==="auth_failed",g=c.length>0,w=s.length>0||n.length>0||r.length>0||i.length>0,k=t==="machines"?"Machines":"Chats";return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4 shrink-0 bg-bg-primary z-10",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:k}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(ps,{size:13}),e.jsx("span",{children:s.length+n.length})]}),e.jsx("button",{onClick:h,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:e.jsx(us,{size:18})})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))] flex flex-col gap-3 -webkit-overflow-scrolling-touch",children:[t==="machines"&&e.jsx("section",{className:"flex flex-col gap-2",children:N?e.jsx(Mt,{icon:e.jsx(On,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:b==="offline"?"Your device appears to be offline. Waiting for network…":b==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:m?"Waiting for your IDE":"Connect your first machine",subtitle:m?"Launch any supported IDE or CLI agent — it will appear here automatically.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!m&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Hr,{})})}):e.jsx(vt,{children:c.map((C,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(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:d(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 flex-col gap-2",children:[e.jsx(Gt,{title:"Needs attention",className:"mb-0"}),e.jsx(vt,{children:s.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"needs_attention",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(Gt,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(vt,{children:n.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"task_complete",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(Gt,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(vt,{children:r.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"working",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex flex-col gap-2",children:[i.length>0&&e.jsx(Gt,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(vt,{children:i.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"earlier",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))}):w?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):N?e.jsx(Mt,{icon:e.jsx(On,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):g?e.jsx(Mt,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(it,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open an IDE or launch a CLI agent to start your first conversation."}):e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:u,children:"Restore all"})]}),e.jsx(vt,{className:"bg-bg-secondary/25",children:o.map((C,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] opacity-50 saturate-0 ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(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:d(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(qe,{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(Fr,{section:t,onSectionChange:p})]})}function tn(t,s=[]){for(const n of s){const r=typeof n=="string"?n.trim():"";if(r)return r}return t==="win32"?"C:\\":"~"}function yc(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const n=s.includes("\\")?"\\":"/",r=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(r[0]||"")?r.length<=2?`${r[0]}\\`:r.slice(0,-1).join("\\"):r.length<=2?n:r.slice(0,-1).join(n)||n}async function Vr(t,s,n){const r=await t(s,"file_list_browse",{path:n});if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Could not browse folder");const i=typeof(r==null?void 0:r.path)=="string"?r.path:n,o=i.includes("\\")?"\\":"/",c=(l,f)=>/^[A-Za-z]:\\?$/.test(l)?`${l.replace(/\\?$/,"\\")}${f}`:l==="/"||l==="\\"?`${o}${f}`:`${l.replace(/[\\/]+$/,"")}${o}${f}`,d=Array.isArray(r==null?void 0:r.files)?r.files.filter(l=>(l==null?void 0:l.type)==="directory"&&typeof(l==null?void 0:l.name)=="string").map(l=>({name:l.name,path:c(i,l.name)})).sort((l,f)=>l.name.localeCompare(f.name)):[];return{path:i,directories:d}}function sn({title:t,description:s,currentPath:n,directories:r,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:d,onNavigate:l,onConfirm:f}){const[u,x]=a.useState(n);a.useEffect(()=>{x(n)},[n]);const h=yc(n),p=u.trim();return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:d,"aria-label":"Close folder browser",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!h||i||l(h)},disabled:!h||i,children:[e.jsx(Us,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:b=>x(b.target.value),onKeyDown:b=>{b.key!=="Enter"||!p||i||(b.preventDefault(),l(p))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!p||i||l(p)},disabled:!p||i,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):r.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:r.map(b=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>l(b.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($t,{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:b.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:b.path})]})]},b.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>f(p||n),disabled:!p&&!n||i,children:c})]})]})})}function nn({title:t,description:s,details:n,workspaceOptions:r,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:d=!1,onConfirm:l,onCancel:f}){const u=r==null?void 0:r.find(x=>x.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:f,"aria-label":"Close launch confirmation",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[r&&r.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:x=>o(x.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:r.map(x=>e.jsx("option",{value:x.key,children:x.label},x.key))}),(u==null?void 0:u.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:u.description})]}),n.map(x=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:x.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:x.value})]},`${x.label}:${x.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:f,disabled:d,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:l,disabled:d,children:[e.jsx(ur,{size:14}),d?"Launching…":c]})]})]})})}function zn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function ht(t){const{machine:s,currentWorkspacePath:n,currentWorkspaceId:r,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const l of s.workspaces||[])o.push({key:`saved:${l.id}`,label:`${l.id===s.defaultWorkspaceId?"⭐ ":""}${zn(l.path,l.label)}`,description:l.path,workspaceId:l.id,workspacePath:l.path});const c=(n==null?void 0:n.trim())||"",d=c?(s.workspaces||[]).find(l=>l.path===c):null;if(c&&!d&&o.push({key:`custom:${c}`,label:zn(c),description:c,workspaceId:null,workspacePath:c}),r){const l=`saved:${r}`;if(o.some(f=>f.key===l))return{options:o,selectedKey:l}}return d?{options:o,selectedKey:`saved:${d.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function vc({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:u,onSectionChange:x,onOpenConversation:h,onOpenRecent:p,onOpenMachineDetails:b,onMachineUpgrade:m,onLaunchDetectedIde:N,onAddWorkspace:g,onBrowseDirectory:w,onLaunchWorkspaceProvider:k}){var Oe,Ge,De,Be;const C=(ne,je,we)=>ne?"ide":je>0?"cli":we>0?"acp":null,[y,T]=a.useState(!1),v=ne=>ne==="ide"?"IDE":ne==="cli"?"CLI":"ACP",j=n.slice(0,4),D=s.slice(0,3),L=(((Oe=t.detectedIdes)==null?void 0:Oe.length)||0)>0,P=a.useMemo(()=>t.workspaces||[],[t]),U=t.defaultWorkspaceId||null,[$,A]=a.useState(U||((Ge=P[0])==null?void 0:Ge.id)||""),[F,B]=a.useState(""),[O,M]=a.useState(""),[E,_]=a.useState([]),[R,H]=a.useState(!1),[oe,le]=a.useState(""),[he,z]=a.useState(!1),[Y,de]=a.useState(C(L,r.length,i.length)),ge=a.useRef(null),[ee,xe]=a.useState(null),pe=a.useRef("__home__"),[te,me]=a.useState("__home__"),[se,ue]=a.useState(!1),X=a.useRef(null),J=$==="__custom__"?F.trim():((De=P.find(ne=>ne.id===$))==null?void 0:De.path)||"",S=$==="__custom__"&&!!J&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message),Z=$!=="__custom__"&&((Be=P.find(ne=>ne.id===$))==null?void 0:Be.path)||"",Q=a.useCallback(async ne=>{H(!0),le("");try{const je=await w(ne);M(je.path),B(je.path),_(je.directories)}catch(je){le(je instanceof Error?je.message:"Could not load folder")}finally{H(!1)}},[w]),ie=a.useCallback(()=>{var je,we;A("__custom__"),z(!0);const ne=tn(t.platform,[F.trim(),Z,(je=P.find(ye=>ye.id===U))==null?void 0:je.path,(we=P[0])==null?void 0:we.path]);Q(ne)},[F,U,Q,Z,t.platform,P]),fe=a.useCallback((ne,je)=>{ge.current=je,pe.current=ne.selectedWorkspaceKey||"__home__",me(ne.selectedWorkspaceKey||"__home__"),xe(ne)},[]),ve=a.useCallback(()=>{ge.current&&(ue(!0),ge.current().finally(()=>{ge.current=null,ue(!1),xe(null)}))},[]);a.useEffect(()=>{var ne;X.current!==t.id&&(X.current=t.id,A(U||((ne=P[0])==null?void 0:ne.id)||"__custom__"),B(""),M(""),_([]),le(""),z(!1),de(C(L,r.length,i.length)))},[i.length,r.length,U,L,t.id,P]),a.useEffect(()=>{var ne;$!=="__custom__"&&($&&P.some(je=>je.id===$)||A(U||((ne=P[0])==null?void 0:ne.id)||"__custom__"))},[U,$,P]),a.useEffect(()=>{Y==="ide"&&L||Y==="cli"&&r.length>0||Y==="acp"&&i.length>0||de(C(L,r.length,i.length))},[Y,i.length,r.length,L]);const Se=a.useMemo(()=>{const ne=j.map(we=>({key:`recent-launch:${we.id}`,type:"session",primary:we.label,secondary:`${v(we.kind)}${we.subtitle?` · ${we.subtitle}`:""}`,unread:!1,onClick:()=>{const{options:ye,selectedKey:ze}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspacePath:we.workspace});fe({title:`Launch ${we.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:ye,selectedWorkspaceKey:ze,details:[{label:"Mode",value:v(we.kind)},...we.providerType?[{label:"Provider",value:we.providerType}]:[]]},async()=>{const Re=ye.find(W=>W.key===pe.current);Re!=null&&Re.workspaceId?(A(Re.workspaceId),B("")):Re!=null&&Re.workspacePath?(A("__custom__"),B(Re.workspacePath)):(A(""),B("")),await p({...we,workspace:(Re==null?void 0:Re.workspacePath)??null})})}})),je=D.map(we=>({key:`recent-chat:${we.conversation.tabKey}`,type:"conversation",primary:we.conversation.displayPrimary,secondary:`Chat${we.conversation.displaySecondary?` · ${we.conversation.displaySecondary}`:""}${we.timestamp?` · ${fr(we.timestamp)}`:""}`,unread:we.unread,onClick:()=>h(we.conversation)}));return[...ne,...je]},[U,h,p,fe,D,j,P]),Ae=y?Se:Se.slice(0,5),Ze=Se.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3 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:u,type:"button","aria-label":"Back",children:e.jsx(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:nt(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[Ze&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Ae.map(ne=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${ne.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:ne.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:ne.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:ne.secondary})]},ne.key))}),Se.length>5&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>T(ne=>!ne),children:y?"Show fewer":`Show ${Se.length-5} more`})})]}),(L||r.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:$,onChange:ne=>{const je=ne.target.value;if(A(je),je==="__custom__"){ie();return}B("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:P.length>0?e.jsxs(e.Fragment,{children:[P.map(ne=>e.jsxs("option",{value:ne.id,children:[ne.id===U?"⭐ ":"",Gs(ne.path,ne.label)||ne.path]},ne.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),$==="__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($t,{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:J||O||"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:ie,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:()=>{J&&g(J)},disabled:!J||R,children:"Save as workspace"})]})]}),J&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[L&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("acp"),children:"ACP"})]}),Y&&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:Y==="ide"?"Choose an IDE":Y==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:Y==="ide"?(t.detectedIdes||[]).slice(0,6).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:we}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspaceId:$!=="__custom__"?$:null,currentWorkspacePath:J});fe({title:`Launch ${ne.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:je,selectedWorkspaceKey:we,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:ne.name}]},async()=>{const ye=je.find(ze=>ze.key===pe.current);ye!=null&&ye.workspaceId?(A(ye.workspaceId),B("")):ye!=null&&ye.workspacePath?(A("__custom__"),B(ye.workspacePath)):(A(""),B("")),N(ne.type,{workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:ne.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J||"Use selected workspace"})]},ne.type)):(Y==="cli"?r:i).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:we}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspaceId:$!=="__custom__"?$:null,currentWorkspacePath:J});fe({title:`Launch ${ne.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${Y.toUpperCase()}`,workspaceOptions:je,selectedWorkspaceKey:we,details:[{label:"Mode",value:Y.toUpperCase()},{label:"Provider",value:ne.displayName}]},async()=>{const ye=je.find(ze=>ze.key===pe.current);ye!=null&&ye.workspaceId?(A(ye.workspaceId),B("")):ye!=null&&ye.workspacePath?(A("__custom__"),B(ye.workspacePath)):(A(""),B("")),k(Y,ne.type,{workspaceId:(ye==null?void 0:ye.workspaceId)??null,workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[ne.icon?`${ne.icon} `:"",ne.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J||"Use selected workspace"})]},ne.type))})]}),d.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${d.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[d.message,S&&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:()=>g(J,{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:m,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:b,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"})]})]})]})]}),he&&e.jsx(sn,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:O,directories:E,busy:R,error:oe,confirmLabel:"Use this folder",onClose:()=>z(!1),onNavigate:ne=>{Q(ne)},onConfirm:ne=>{B(ne),A("__custom__"),z(!1)}}),ee&&e.jsx(nn,{title:ee.title,description:ee.description,details:ee.details,workspaceOptions:ee.workspaceOptions,selectedWorkspaceKey:te,onWorkspaceChange:ne=>{pe.current=ne,me(ne)},confirmLabel:ee.confirmLabel,busy:se,onConfirm:ve,onCancel:()=>{ge.current=null,xe(null)}}),f&&e.jsx(Fr,{section:l,onSectionChange:x})]})}function wc(t){return Nr(t)}function Un(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=wc(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function jc(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Xt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function kc(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function Hn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Nc(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function Sc({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:u,requestedMachineId:x,onRequestedMachineConsumed:h,requestedMobileSection:p,onRequestedMobileSectionConsumed:b,onOpenHistory:m,onOpenRemote:N,onStopCli:g,wsStatus:w,isConnected:k,onShowHiddenConversation:C,onShowAllHiddenConversations:y,onHideConversation:T}){const[v,j]=a.useState(()=>{var W;return((W=t[0])==null?void 0:W.tabKey)||null}),[D,L]=a.useState(()=>t[0]?"chat":"inbox"),[P,U]=a.useState("chats"),[$,A]=a.useState(null),[F,B]=a.useState("inbox"),[O,M]=a.useState("idle"),[E,_]=a.useState(""),[R,H]=a.useState(null),oe=a.useRef(null),le=St(),he="0.8.8",z=a.useMemo(()=>t.find(W=>W.tabKey===v)||t[0]||null,[t,v]),Y=a.useMemo(()=>z?n.find(W=>W.id===z.ideId):void 0,[n,z]),de=a.useMemo(()=>!z||Te(z)||!Ee(z)?null:Nt(z),[z]),ge=a.useMemo(()=>n.filter(W=>W.type==="adhdev-daemon"||W.daemonMode).sort($i),[n]),ee=a.useMemo(()=>ge.find(W=>W.id===$)||null,[ge,$]),xe=a.useMemo(()=>Kt(n),[n]),pe=xs({sendDaemonCommand:i,activeConv:z||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),te=a.useCallback(W=>{if(!W||!W.sessionId)return;const K=Et(W,xe),re=Math.max(Date.now(),jt(W),K.lastUpdated||0);Xt("mark_read:start",{tabKey:W.tabKey,sessionId:W.sessionId,displayPrimary:W.displayPrimary,inboxBucket:K.inboxBucket,unread:K.unread,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,activityAt:jt(W),readAt:re}),i(W.daemonId||W.ideId,"mark_session_seen",{sessionId:W.sessionId,seenAt:re}).then(ce=>{Xt("mark_read:result",{tabKey:W.tabKey,sessionId:W.sessionId,result:ce})}).catch(ce=>{Xt("mark_read:error",{tabKey:W.tabKey,sessionId:W.sessionId,error:ce instanceof Error?ce.message:String(ce)})})},[xe,i]);a.useEffect(()=>{var K;if(!z){L("inbox"),j(((K=t[0])==null?void 0:K.tabKey)||null),oe.current=null;return}if(D!=="chat"){oe.current=null;return}const W=`${z.tabKey}:${z.sessionId||""}`;oe.current!==W&&(oe.current=W,te(z))},[t,te,D,z]),a.useEffect(()=>{if(!f)return;const W=t.find(K=>K.tabKey===f);W&&(j(W.tabKey),L("chat"),u==null||u())},[t,u,f]),a.useEffect(()=>{if(!x)return;const W=ge.find(K=>K.id===x);W&&(A(W.id),M("idle"),_(""),U("machines"),B("inbox"),L("machine"),h==null||h())},[ge,h,x]),a.useEffect(()=>{p&&(U(p),L("inbox"),b==null||b())},[b,p]);const me=a.useMemo(()=>t.map(W=>{const K=D==="chat"&&(z==null?void 0:z.tabKey)===W.tabKey,re=Dt(W,xe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:K}),ce=jt(W),I=Un(W);return{conversation:W,timestamp:ce,preview:I,unread:re.unread,requiresAction:re.requiresAction,isWorking:re.isWorking,inboxBucket:re.inboxBucket}}).sort((W,K)=>Kr(W.conversation,K.conversation)),[t,xe,D,z]);a.useEffect(()=>{const W=me.filter(K=>K.inboxBucket==="task_complete"||K.unread);W.length!==0&&Xt("inbox_state",{screen:D,selectedTabKey:v,items:W.map(K=>{const re=Et(K.conversation,xe);return{liveState:re,tabKey:K.conversation.tabKey,sessionId:K.conversation.sessionId,displayPrimary:K.conversation.displayPrimary,serverBucket:re.inboxBucket,computedBucket:K.inboxBucket,serverUnread:re.unread,computedUnread:K.unread,lastSeenAt:re.lastSeenAt,lastUpdated:re.lastUpdated,activityAt:jt(K.conversation)}})})},[me,xe,D,v]);const se=a.useMemo(()=>me.filter(W=>W.requiresAction),[me]),ue=a.useMemo(()=>me.filter(W=>W.unread&&!W.requiresAction),[me]),X=a.useMemo(()=>me.filter(W=>!W.unread&&!W.requiresAction&&W.isWorking),[me]),J=a.useMemo(()=>me.filter(W=>!W.unread&&!W.requiresAction&&!W.isWorking),[me]),S=a.useMemo(()=>ee?me.filter(W=>W.conversation.daemonId===ee.id||W.conversation.ideId===ee.id):[],[me,ee]),Z=a.useMemo(()=>{if(!ee)return[];const W=ee.recentLaunches||[];return W.length>0?W.map(K=>({id:K.id,label:K.title||K.providerName||K.providerType,kind:K.kind,providerType:K.providerType,providerSessionId:K.providerSessionId,subtitle:K.currentModel||K.workspace||void 0,workspace:K.workspace,currentModel:K.currentModel})):n.filter(K=>!K.daemonMode&&K.daemonId===ee.id).map(K=>{var ce,I,q,ae,V;const re=rs(K)?"cli":_t(K)?"acp":"ide";return{id:`${re}:${K.type}:${K.workspace||""}`,label:((ce=K.activeChat)==null?void 0:ce.title)||(rs(K)?K.cliName||K.type:_t(K)&&K.cliName||K.type),kind:re,providerType:K.type,providerSessionId:K.providerSessionId,subtitle:_t(K)?K.currentModel||K.workspace||void 0:K.workspace||void 0,workspace:K.workspace||void 0,currentModel:K.currentModel,timestamp:((V=(ae=(q=(I=K.activeChat)==null?void 0:I.messages)==null?void 0:q.at)==null?void 0:ae.call(q,-1))==null?void 0:V.timestamp)||0}}).sort((K,re)=>re.timestamp-K.timestamp).map(({timestamp:K,...re})=>re)},[n,ee]),Q=(ee==null?void 0:ee.version)||(ee==null?void 0:ee.daemonVersion)||null,ie=!!ee&&!!Q&&!0&&Q!==he,fe=a.useMemo(()=>(ee==null?void 0:ee.availableProviders)||[],[ee]),ve=a.useMemo(()=>fe.filter(W=>W.category==="cli").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[fe]),Se=a.useMemo(()=>fe.filter(W=>W.category==="acp").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[fe]),Ae=a.useMemo(()=>{const W=new Map;for(const K of me){const re=K.conversation.daemonId||K.conversation.ideId,ce=W.get(re);ce?ce.push(K):W.set(re,[K])}return ge.map(K=>{const re=W.get(K.id)||[],ce=[...re].sort((G,Ce)=>Ce.timestamp-G.timestamp)[0]||null,I=(ce==null?void 0:ce.conversation)||null,q=Rs(K),ae=re.filter(G=>G.unread||G.requiresAction).length,V=K.status==="online"?"Connected":K.status||"Unknown",ke=[K.platform||"machine",V].filter(Boolean);return{id:K.id,label:nt(K,{fallbackId:K.id}),subtitle:ke.join(" · "),unread:ae,total:re.length,latestConversation:I,latestTimestamp:(ce==null?void 0:ce.timestamp)||0,fallbackActivityAt:q,preview:I?`${I.displayPrimary} · ${Un(I)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((K,re)=>{const ce=K.latestTimestamp||K.fallbackActivityAt||0,I=re.latestTimestamp||re.fallbackActivityAt||0;return I!==ce?I-ce:K.label.localeCompare(re.label)})},[me,ge]),Ze=a.useCallback(W=>{j(W.tabKey),L("chat"),te(W)},[te]),Oe=a.useCallback(W=>{const K=t.find(re=>re.ideId===W.ideId&&re.streamSource==="native");K&&(j(K.tabKey),L("chat"),te(K))},[t,te]),Ge=a.useCallback(()=>{te(z),L("inbox")},[te,z]),De=a.useCallback(W=>{A(W),M("idle"),_(""),H(null),U("machines"),B("inbox"),L("machine")},[]),Be=a.useCallback(W=>{var re;const K=W.daemonId||((re=W.ideId)==null?void 0:re.split(":")[0])||W.ideId;K&&(A(K),M("idle"),_(""),H(null),U("machines"),B("chat"),L("machine"))},[]),ne=a.useCallback(()=>{H(null),L(F)},[F]),je=a.useCallback(async(W,K,re)=>{var ce;try{M("loading"),_(`Launching ${K}…`);const I={ideType:K,enableCdp:!0};(ce=re==null?void 0:re.workspacePath)!=null&&ce.trim()&&(I.workspace=re.workspacePath.trim()),await i(W,"launch_ide",I),M("done"),_(`${K} launch requested`)}catch(I){M("error"),_(I instanceof Error?I.message:"Launch IDE failed"),console.error("Launch IDE failed",I)}},[i]),we=a.useCallback(async(W,K,re)=>{if(K.trim())try{M("loading"),_(re!=null&&re.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await i(W,"workspace_add",{path:K.trim(),createIfMissing:(re==null?void 0:re.createIfMissing)===!0});if(ce!=null&&ce.success){M("done"),_(re!=null&&re.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}M("error"),_((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){M("error"),_(ce instanceof Error?ce.message:"Could not save workspace")}},[i]),ye=a.useCallback(async W=>{var K,re,ce,I,q,ae;try{M("loading"),_("Starting daemon upgrade…");const V=await i(W,"daemon_upgrade",{});if((K=V==null?void 0:V.result)!=null&&K.alreadyLatest){M("done"),_(`Already on v${((re=V==null?void 0:V.result)==null?void 0:re.version)||"latest"}.`);return}if((ce=V==null?void 0:V.result)!=null&&ce.upgraded||(I=V==null?void 0:V.result)!=null&&I.success){M("done"),_(`Upgrade to v${((q=V==null?void 0:V.result)==null?void 0:q.version)||"latest"} started. Daemon is restarting…`);return}M("error"),_(((ae=V==null?void 0:V.result)==null?void 0:ae.error)||"Upgrade failed")}catch(V){M("error"),_(V instanceof Error?V.message:"Upgrade failed")}},[i]),ze=a.useCallback(async(W,K,re,ce)=>{var ae;const I=Date.now(),q={machineId:W,kind:K,providerType:re,workspaceId:(ce==null?void 0:ce.workspaceId)||null,workspacePath:(ce==null?void 0:ce.workspacePath)||null,resumeSessionId:(ce==null?void 0:ce.resumeSessionId)||null,startedAt:I};try{M("loading"),_(`Launching ${re}…`),H(q);const V={cliType:re};(ae=ce==null?void 0:ce.workspacePath)!=null&&ae.trim()?V.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(V.workspaceId=ce.workspaceId),ce!=null&&ce.resumeSessionId&&(V.resumeSessionId=ce.resumeSessionId);const ke=await i(W,"launch_cli",V),G=(ke==null?void 0:ke.result)||ke,Ce=(G==null?void 0:G.sessionId)||(G==null?void 0:G.id);if(ke!=null&&ke.success&&Ce){H(null),M("done"),_(`${re} launched`),le(`/dashboard?activeTab=${encodeURIComponent(Ce)}`);return}if(ke!=null&&ke.success){M("loading"),_(`${re} launch requested — waiting for session…`);return}H(null),M("error"),_((ke==null?void 0:ke.error)||(G==null?void 0:G.error)||`Could not launch ${K.toUpperCase()} workspace`)}catch(V){if(Nc(V)){M("loading"),_(`${re} launch requested — waiting for session…`);return}H(null),M("error"),_(V instanceof Error?V.message:`Could not launch ${K.toUpperCase()} workspace`)}},[le,i]);a.useEffect(()=>{var ce;if(!R)return;const W=Hn(R.workspacePath),K=n.find(I=>{var Ce,Ue,He,Pe;if(!I||I.type==="adhdev-daemon"||I.daemonMode||kc(I.daemonId||I.id)!==R.machineId||(I.transport==="acp"?"acp":I.transport==="pty"?"cli":null)!==R.kind||String(I.agentType||I.ideType||I.type||"")!==R.providerType)return!1;const ke=String(I.providerSessionId||"");if(R.resumeSessionId&&ke)return ke===R.resumeSessionId;if(W){const ot=Hn(I.workspace||I.runtimeWorkspaceLabel);return ot?ot===W:!1}return Number(I.lastUpdated||I._lastUpdate||I.timestamp||((Pe=(He=(Ue=(Ce=I.activeChat)==null?void 0:Ce.messages)==null?void 0:Ue.at)==null?void 0:He.call(Ue,-1))==null?void 0:Pe.timestamp)||0)>=R.startedAt-5e3});if(!K)return;const re=typeof K.sessionId=="string"&&K.sessionId?K.sessionId:typeof K.instanceId=="string"&&K.instanceId?K.instanceId:(ce=t.find(I=>I.ideId===K.id))==null?void 0:ce.sessionId;re&&(H(null),M("done"),_(`${R.providerType} launched`),le(`/dashboard?activeTab=${encodeURIComponent(re)}`))},[t,n,le,R]),a.useEffect(()=>{if(!R)return;const W=window.setTimeout(()=>{H(K=>!K||K.startedAt!==R.startedAt?K:(M("error"),_("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(W)},[R]);const Re=a.useCallback(async W=>{if(ee){if(W.kind==="ide"&&W.providerType){await je(ee.id,W.providerType,{workspacePath:W.workspace||null});return}if((W.kind==="cli"||W.kind==="acp")&&W.providerType){await ze(ee.id,W.kind,W.providerType,{workspacePath:W.workspace||null,resumeSessionId:W.providerSessionId||null});return}}},[je,ze,ee]);return e.jsx("div",{className:"dashboard-mobile-chat",children:D==="chat"&&z?e.jsx(hc,{selectedConversation:z,isAcp:Te(z),selectedIdeEntry:Y,actionLogs:r,userName:l,isSendingChat:pe.isSendingChat,isFocusingAgent:pe.isFocusingAgent,handleModalButton:pe.handleModalButton,handleRelaunch:pe.handleRelaunch,onBack:Ge,onOpenNativeConversation:Oe,onOpenMachine:Be,onHideConversation:T,onOpenHistory:m,onOpenRemote:N,onStopCli:g,cliViewMode:de,onSetCliViewMode:async W=>{if(z&&de!==W)try{await i(z.daemonId||z.ideId,"set_cli_view_mode",{targetSessionId:z.sessionId,cliType:z.ideType||z.agentType,mode:W})}catch(K){console.error("Failed to switch CLI view mode:",K)}},handleSendChat:pe.handleSendChat,handleFocusAgent:pe.handleFocusAgent}):D==="machine"&&ee?e.jsx(vc,{selectedMachineEntry:ee,selectedMachineConversations:S,selectedMachineRecentLaunches:Z,cliProviders:ve,acpProviders:Se,selectedMachineNeedsUpgrade:ie,appVersion:he,machineAction:{state:O,message:E},section:P,showBottomNav:F==="inbox",onBack:ne,onSectionChange:W=>{U(W),L("inbox")},onOpenConversation:Ze,onOpenRecent:Re,onOpenMachineDetails:()=>le(`/machines/${ee.id}`),onMachineUpgrade:()=>ye(ee.id),onLaunchDetectedIde:(W,K)=>je(ee.id,W,K),onAddWorkspace:(W,K)=>we(ee.id,W,K),onBrowseDirectory:async W=>{const K=await i(ee.id,"file_list_browse",{path:W});if(!(K!=null&&K.success))throw new Error((K==null?void 0:K.error)||"Could not browse folder");const re=typeof(K==null?void 0:K.path)=="string"?K.path:W,ce=re.includes("\\")?"\\":"/",I=(ae,V)=>/^[A-Za-z]:\\?$/.test(ae)?`${ae.replace(/\\?$/,"\\")}${V}`:ae==="/"||ae==="\\"?`${ce}${V}`:`${ae.replace(/[\\/]+$/,"")}${ce}${V}`,q=Array.isArray(K==null?void 0:K.files)?K.files.filter(ae=>(ae==null?void 0:ae.type)==="directory"&&typeof(ae==null?void 0:ae.name)=="string").map(ae=>({name:ae.name,path:I(re,ae.name)})).sort((ae,V)=>ae.name.localeCompare(V.name)):[];return{path:re,directories:q}},onLaunchWorkspaceProvider:(W,K,re)=>ze(ee.id,W,K,re)}):e.jsx(gc,{section:P,attentionItems:se,unreadItems:ue,workingItems:X,completedItems:J,hiddenConversations:s,machineCards:Ae,getAvatarText:jc,onOpenConversation:Ze,onShowConversation:C,onShowAllHidden:y,onOpenMachine:De,onOpenSettings:()=>le("/settings"),onSectionChange:U,wsStatus:w,isConnected:k,isStandalone:d})})}function Ms(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Cc({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,u]=a.useState(null),x=a.useCallback(()=>{c.current=0,l(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",x),window.addEventListener("drop",x),()=>{window.removeEventListener("dragend",x),window.removeEventListener("drop",x)}),[x]);const h=a.useCallback(N=>{N.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),p=a.useCallback(N=>{if(!N.dataTransfer.types.includes("text/tab-key"))return;if(N.preventDefault(),!Ms(s,n)){u("merge");return}const g=N.currentTarget.getBoundingClientRect(),w=N.clientX-g.left,k=g.width/3;w<k?u("split-left"):w>k*2?u("split-right"):u("merge")},[s,n]),b=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),m=a.useCallback(N=>{c.current=0,l(!1);const g=N.dataTransfer.getData("text/tab-key"),w=g?t.some(C=>C.tabKey===g):!1,k=f;if(u(null),o(),!!g){if(N.preventDefault(),k==="split-left"&&Ms(s,n)){n==null||n(g,"split-left");return}if(k==="split-right"&&Ms(s,n)){n==null||n(g,"split-right");return}if(w){i(g);return}r==null||r(g)}},[t,f,s,n,r,i,o]);return{dragOver:d,dropAction:f,resetDragState:x,handleDragEnter:h,handleDragOver:p,handleDragLeave:b,handleDrop:m}}function Ic(t,s){const n=new Set(s.map(o=>o.tabKey)),r=t.filter(o=>n.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...r,...i]}function Mc({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,u]=a.useState(null),x=a.useRef(null),h=a.useRef(null),p=a.useRef(r),b=a.useRef(i);a.useEffect(()=>{p.current=r},[r]),a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(v=>{const j=Ic(v,t);return j.length===v.length&&j.every((D,L)=>D===v[L])?v:j})},[t]);const m=a.useMemo(()=>{const v=f??d;if(v.length===0)return t;const j=new Map(v.map((D,L)=>[D,L]));return[...t].sort((D,L)=>{const P=j.get(D.tabKey)??999,U=j.get(L.tabKey)??999;return P-U})},[t,f,d]);a.useEffect(()=>{var j,D;if(m.length===0){o!==null&&(c(null),(j=p.current)==null||j.call(p,null));return}if(o&&m.some(L=>L.tabKey===o))return;const v=m[0].tabKey;v!==o&&(c(v),(D=p.current)==null||D.call(p,v))},[m,o]);const N=a.useMemo(()=>m.find(v=>v.tabKey===o),[m,o]),g=a.useCallback(v=>{var j;c(v),(j=p.current)==null||j.call(p,v)},[]),w=a.useCallback((v,j,D)=>{l(L=>{var A;const P=L.filter(F=>F!==v),U=P.indexOf(j);if(U<0)return L;const $=D==="left"?U:U+1;return P.splice($,0,v),(A=b.current)==null||A.call(b,P),P}),u(null)},[]),k=a.useCallback((v,j,D)=>{const P=(d.length>0?d:t.map(A=>A.tabKey)).filter(A=>A!==v),U=P.indexOf(j);if(U<0)return;const $=D==="left"?U:U+1;P.splice($,0,v),x.current=P,u(P)},[d,t]),C=a.useCallback(()=>{var j;const v=x.current;v&&(l(v),(j=b.current)==null||j.call(b,v))},[]),y=a.useCallback(()=>{x.current=null,u(null)},[]),T=a.useCallback(v=>{l(j=>{var L;const D=j.filter(P=>P!==v);return D.push(v),(L=b.current)==null||L.call(b,D),D})},[]);return{activeTabId:o,activeConv:N,sortedConversations:m,previewOrderRef:x,draggingTabRef:h,selectTab:g,handleTabReorder:w,updatePreviewOrder:k,commitPreviewOrder:C,clearPreviewOrder:y,moveTabToEnd:T,setDraggingTabKey:v=>{h.current=v}}}function _c({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 rn({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:i}){return t===0&&!s&&r&&i?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(Hr,{}),n&&r.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(o=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>i(o.type),children:[e.jsx(pr,{size:14,className:"opacity-70"})," Launch ",o.name]},o.type))})]}),!n&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}const qr="adhdev-tab-shortcuts";function Tc(){try{return JSON.parse(localStorage.getItem(qr)||"{}")}catch{return{}}}function Ac({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Tc()),[c,d]=a.useState(null),l=a.useCallback(u=>{const x=[];return u.metaKey&&x.push(r?"⌘":"Meta"),u.ctrlKey&&x.push("Ctrl"),u.altKey&&x.push(r?"⌥":"Alt"),u.shiftKey&&x.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(x.push(u.key.length===1?u.key.toUpperCase():u.key),x.join("+"))},[r]),f=a.useCallback(u=>{o(u);try{localStorage.setItem(qr,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=x=>{if(x.preventDefault(),x.stopPropagation(),x.key==="Escape"){d(null);return}const h=l(x);if(!h)return;const p={...i};for(const[b,m]of Object.entries(p))m===h&&delete p[b];p[c]=h,f(p),d(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,f,l]),a.useEffect(()=>{const u=x=>{if(!(!x.ctrlKey&&!x.metaKey&&!x.altKey)){for(const[h,p]of Object.entries(i))if(t.includes(h)&&l(x)===p){x.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const Lc=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:u,onPreviewReorder:x,onReorderTab:h,onCommitPreviewOrder:p,onClearPreviewOrder:b,onDragStateReset:m,onDragTabKeyChange:N,onReceiveTab:g,onOpenContextMenu:w,longPressTimer:k,isGroupActive:C}){const y=ms(s),T=y.isGenerating?"agent-tab-generating":y.isWaiting?"agent-tab-waiting":"",v=y.isReconnecting,j=a.useCallback(O=>{d.current=s.tabKey,N(s.tabKey),O.dataTransfer.setData("text/tab-key",s.tabKey),O.dataTransfer.effectAllowed="move"},[s.tabKey,d,N]),D=a.useCallback(()=>{d.current=null,N(null),p(),b(),m()},[d,N,p,b,m]),L=a.useCallback(O=>{const M=d.current;if(!(!M||M===s.tabKey)&&O.dataTransfer.types.includes("text/tab-key")){O.preventDefault(),O.stopPropagation();const E=O.currentTarget.getBoundingClientRect(),_=O.clientX<E.left+E.width/2?"left":"right";x(M,s.tabKey,_)}},[s.tabKey,d,x]),P=a.useCallback(O=>{O.preventDefault(),O.stopPropagation();const M=O.dataTransfer.getData("text/tab-key");if(M&&M!==s.tabKey){const E=O.currentTarget.getBoundingClientRect(),_=O.clientX<E.left+E.width/2?"left":"right";c.includes(M)?h(M,s.tabKey,_):g&&g(M)}b()},[s.tabKey,c,h,g,b]),U=a.useCallback(O=>{O.stopPropagation(),l(),f(s.tabKey),u(s)},[s,u,l,f]),$=a.useCallback(O=>{O.preventDefault(),w(O.clientX,O.clientY,s.tabKey)},[s.tabKey,w]),A=a.useCallback(O=>{const M=O.touches[0];k.current=setTimeout(()=>{w(M.clientX,M.clientY,s.tabKey)},600)},[s.tabKey,k,w]),F=a.useCallback(()=>{k.current&&clearTimeout(k.current)},[k]),B=["adhdev-dockview-tab",T,n&&"is-active",C&&"is-group-active",v&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:B,draggable:!0,onDragStart:j,onDragEnd:D,onDragOver:L,onDrop:P,onClick:U,onContextMenu:$,onTouchStart:A,onTouchEnd:F,onTouchMove:F,style:{cursor:"pointer",opacity:r?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:y.isGenerating?e.jsx("div",{className:"tab-spinner"}):y.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):v?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):y.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:v?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):y.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 Rc({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:b,onMoveTab:m,onReceiveTab:N,onHideTab:g,isGroupActive:w}){const[k,C]=a.useState(null),y=a.useRef(null),T=a.useRef(null),v=a.useMemo(()=>t.map(A=>A.tabKey),[t]);Bt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(k==null?void 0:k.tabKey)||null});const{isMac:j,tabShortcuts:D,shortcutListening:L,setShortcutListening:P,saveShortcuts:U}=Ac({sortedTabKeys:t.map(A=>A.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!k)return;const A=F=>{const B=document.querySelector("[data-pane-context-menu]");B&&B.contains(F.target)||C(null)};return window.addEventListener("mousedown",A,!0),()=>window.removeEventListener("mousedown",A,!0)},[k]),a.useEffect(()=>{const A=T.current;if(!A)return;const F=B=>{Math.abs(B.deltaY)>Math.abs(B.deltaX)&&(B.preventDefault(),A.scrollLeft+=B.deltaY)};return A.addEventListener("wheel",F,{passive:!1}),()=>A.removeEventListener("wheel",F)},[]);const $=a.useCallback((A,F,B)=>{C({x:A,y:F,tabKey:B})},[]);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:T,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(A=>e.jsx(Lc,{conv:A,isActive:s===A.tabKey,isDraggedTab:o.current===A.tabKey,isTaskCompleteUnread:i.has(A.tabKey),shortcut:D[A.tabKey],conversationKeys:v,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:b,onReceiveTab:N,onOpenContextMenu:$,longPressTimer:y,isGroupActive:w},A.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),k&&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:k.x,top:k.y},children:[m&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"left"),C(null)},children:"← Move to Left Group"}),m&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"right"),C(null)},children:"Move to Right Group →"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"split-left"),C(null)},children:"⇤ Split Left"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"split-right"),C(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:A=>{A.stopPropagation(),P(k.tabKey),C(null)},children:["⌨ ",D[k.tabKey]?`Change shortcut (${D[k.tabKey]})`:"Set shortcut"]}),D[k.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 A={...D};delete A[k.tabKey],U(A),C(null)},children:"✕ Remove shortcut"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{g(k.tabKey),C(null)},children:"🚫 Hide from Dashboard"})]}),!m&&!g&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),L&&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:()=>P(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:A=>A.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. ",j?"⌘+1":"Ctrl+1",", ",j?"⌥+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 Pc({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:u,isSplitMode:x,numGroups:h,onMoveTab:p,onReceiveTab:b,style:m,detectedIdes:N,handleLaunchIde:g,onActiveTabChange:w,initialActiveTabId:k,initialTabOrder:C,onTabOrderChange:y,onHideTab:T,isFocused:v}){const{sendCommand:j}=ut(),D=a.useRef(null),{activeTabId:L,activeConv:P,sortedConversations:U,draggingTabRef:$,selectTab:A,handleTabReorder:F,updatePreviewOrder:B,commitPreviewOrder:O,clearPreviewOrder:M,moveTabToEnd:E,setDraggingTabKey:_}=Mc({conversations:t,initialActiveTabId:k,initialTabOrder:C,onActiveTabChange:w,onTabOrderChange:y}),R=xs({sendDaemonCommand:i,activeConv:P,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:H,dropAction:oe,resetDragState:le,handleDragEnter:he,handleDragOver:z,handleDragLeave:Y,handleDrop:de}=Cc({conversations:t,numGroups:h,onMoveTab:p,onReceiveTab:b,onOwnTabDrop:E,onClearPreviewOrder:M}),ge=P&&!Te(P)&&Nt(P)==="terminal",ee=a.useMemo(()=>P?s.find(se=>se.id===P.ideId):void 0,[s,P]),xe=a.useMemo(()=>P?r.filter(se=>se.ideId===P.tabKey):[],[r,P]),pe=a.useMemo(()=>Kt(s),[s]),te=a.useMemo(()=>new Set(U.filter(se=>gi(se,pe,{isOpenConversation:se.tabKey===L})).map(se=>se.tabKey)),[L,pe,U]);Bt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:L,dragOver:H});const me=a.useCallback(se=>{se.streamSource==="agent-stream"&&se.agentType&&j(se.ideId,"focus_session",{agentType:se.agentType,...se.sessionId&&{targetSessionId:se.sessionId}}).catch(()=>{})},[j]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...m,outline:H?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Rc,{conversations:U,activeTabId:L,groupIndex:f,numGroups:h,unreadTabKeys:te,draggingTabRef:$,onFocus:u,onSelectTab:A,onConversationActivated:me,onPreviewReorder:B,onReorderTab:F,onCommitPreviewOrder:O,onClearPreviewOrder:M,onDragStateReset:le,onDragTabKeyChange:_,onMoveTab:p,onReceiveTab:b,onHideTab:T,isGroupActive:v??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:he,onDragOver:z,onDragLeave:Y,onDrop:de,children:[H&&e.jsx(_c,{dropAction:oe,canSplit:!!(h<4&&p)}),P?e.jsx(en,{activeConv:P,clearToken:n[P.tabKey]||0,isCliTerminal:!!ge,ideEntry:ee,terminalRef:D,handleModalButton:R.handleModalButton,handleRelaunch:R.handleRelaunch,handleSendChat:R.handleSendChat,isSendingChat:R.isSendingChat,handleFocusAgent:R.handleFocusAgent,isFocusingAgent:R.isFocusingAgent,actionLogs:xe,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(rn,{conversationsCount:t.length,isSplitMode:x,isStandalone:d,detectedIdes:N,handleLaunchIde:g})})]})]})}function $c({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,focusedGroup:p,setFocusedGroup:b,moveTabToGroup:m,splitTabRelative:N,closeGroup:g,handleResizeStart:w,detectedIdes:k,handleLaunchIde:C,groupActiveTabIds:y,setGroupActiveTabIds:T,groupTabOrders:v,setGroupTabOrders:j,toggleHiddenTab:D}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((L,P)=>{const U=s&&r.length===n?`${r[P]}%`:void 0;return e.jsxs(Os.Fragment,{children:[s&&P>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:$=>w(P-1,$),onDoubleClick:()=>g(P),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(Pc,{style:s?{flexBasis:U??`${100/n}%`,flexGrow:U?0:1,flexShrink:U?0:1}:void 0,conversations:L,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,groupIndex:P,isFocused:s&&p===P,onFocus:()=>b(P),isSplitMode:s,numGroups:n,onMoveTab:($,A)=>{A==="left"&&P>0?m($,P-1):A==="right"&&P<n-1?m($,P+1):A==="split-left"&&n<4?N($,P,"left"):A==="split-right"&&n<4&&N($,P,"right")},onReceiveTab:$=>m($,P),detectedIdes:P===0?k:void 0,handleLaunchIde:P===0?C:void 0,onActiveTabChange:$=>T(A=>(A[P]??null)===($??null)?A:{...A,[P]:$}),initialActiveTabId:y[P],initialTabOrder:v[P],onTabOrderChange:$=>j(A=>{const F=A[P]||[];return F.length===$.length&&F.every((B,O)=>B===$[O])?A:{...A,[P]:$}}),onHideTab:D})]},P)})})}function Gr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?$e.onScreenshot("ide-page",(p,b)=>{if(p!==t)return;const m=new FileReader;m.onload=()=>d(m.result),m.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var p;return t?((p=$e.onStatus)==null?void 0:p.call($e,(b,m)=>{b===t&&m!=null&&m.screenshotUsage&&f(m.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,u]),a.useEffect(()=>{const h=t?$e.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&u?h.startScreenshots(u):h.stopScreenshots(u),()=>{h.stopScreenshots(u)}},[i,r,u,t]);const x=a.useCallback(async(h,p)=>{const b=t?$e.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(h,p,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:x}}const Yr=a.createContext(null);function fs(){const t=a.useContext(Yr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function es(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Ec(t){return`remote:${t}`}function ls(t){return t.startsWith("remote:")}function hs(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function Dc(t){const[,s]=a.useState(0);a.useEffect(()=>{const n=()=>s(i=>i+1),r=[t.api.onDidActiveGroupChange(n),t.api.onDidTitleChange(n),t.api.onDidGroupChange(n),t.containerApi.onDidActivePanelChange(n)];return()=>{for(const i of r)i.dispose()}},[t.api,t.containerApi])}function Bc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const u of l){const x=t.addPanel({id:u.tabKey,component:"conversation",title:es(u),params:{kind:"conversation",tabKey:u.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=x.id)}i=f??i}const o=n??((d=s[0])==null?void 0:d.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Fn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])ls(r.id)||n.has(r.id)||t.removePanel(r);for(const r of s){const i=t.getPanel(r.tabKey);if(i){i.update({params:{tabKey:r.tabKey}}),i.title!==es(r)&&i.api.setTitle(es(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:es(r),params:{kind:"conversation",tabKey:r.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Vn(t,s,n){var l,f;const r=n?Ec(n):null;for(const u of[...t.panels])ls(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=hs(s,n);if(!i&&t.totalPanels===0)return;const o=t.getPanel(r),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const d=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(u=>!ls(u.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...d?{position:{referencePanel:d,direction:"right"},inactive:!0}:{}})}function Kc({params:t}){const s=fs(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=xs({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(l=>l.id===r.ideId):void 0,[s.ides,r]),c=a.useMemo(()=>r?s.actionLogs.filter(l=>l.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(rn,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!Te(r)&&Nt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(en,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:d,ideEntry:o,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:c,userName:s.userName})})}function Wc({params:t}){var l;const s=fs(),n=a.useMemo(()=>hs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:d}=Gr({doId:i,ideId:t.ideId,ideType:(n==null?void 0:n.ideType)||(r==null?void 0:r.type),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote",instanceId:r==null?void 0:r.instanceId});return n?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(xr,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:d})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function Oc(){const t=fs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(rn,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function zc(t){var x,h;Dc(t);const s=fs();if(t.params.kind==="remote"){const p=hs([...s.conversationsByTabKey.values()],t.params.ideId),b=((x=t.api.group.activePanel)==null?void 0:x.id)===t.api.id,m=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${m?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:p!=null&&p.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:p.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const r=((h=t.api.group.activePanel)==null?void 0:h.id)===t.api.id,i=t.api.isGroupActive,o=Dt(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,u=o.unread;return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,children:[u&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:l?e.jsx("div",{className:"tab-spinner"}):f?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:c?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]})]})}function Uc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:u,toggleHiddenTab:x,onActiveTabChange:h,requestedActiveTabKey:p,requestedRemoteIdeId:b,onRequestedActiveTabConsumed:m}){const{theme:N}=Lr(),{sendCommand:g}=ut(),w=a.useRef(null),k=a.useRef(null),C=a.useRef(!1),[y,T]=a.useState(!1),[v,j]=a.useState(!1),D=a.useRef(null),L=a.useMemo(()=>Or(typeof window<"u"?window.innerWidth:1280),[]),P=a.useMemo(()=>new Map(t.map(R=>[R.tabKey,R])),[t]),U=a.useMemo(()=>Kt(n),[n]),$=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:P,detectedIdes:f,handleLaunchIde:u,ides:n,isStandalone:d,liveSessionInboxState:U,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:x,userName:l}),[r,s,P,f,u,n,d,U,i,c,o,x,l]),A=a.useCallback(R=>{if(!R)return!1;const H=w.current;if(!H)return!1;const oe=H.getPanel(R);return oe?(oe.group.model.openPanel(oe),m==null||m(),!0):!1},[m]),F=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const oe of H)oe.setAttribute("data-adhdev-force-hidden","true")},[]),B=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const oe of H)oe.removeAttribute("data-adhdev-force-hidden")},[]),O=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll(".dv-drop-target-container");for(const he of H)he.remove();const oe=R.querySelectorAll(".dv-drop-target-dropzone");for(const he of oe)he.remove();const le=R.querySelectorAll(".dv-drop-target");for(const he of le)he.classList.remove("dv-drop-target")},[]),M=a.useCallback(()=>{T(!1),j(!1),B(),F(),O(),!(typeof window>"u")&&(D.current!=null&&window.clearTimeout(D.current),window.requestAnimationFrame(()=>{F(),O()}),D.current=window.setTimeout(()=>{F(),O(),D.current=null},80))},[B,F,O]),E=a.useCallback(R=>{var oe;w.current=R.api;const H=rc(L);H!=null&&H.layout&&R.api.fromJSON(H.layout,{reuseExistingPanels:!1}),Fn(R.api,t),Vn(R.api,t,b),R.api.totalPanels===0&&t.length>0?Bc(R.api,t,p):A(p)||A(H==null?void 0:H.activeTabId),C.current=!0,R.api.onDidActivePanelChange(le=>{var z;if(le&&ls(le.id)){const Y=((z=le.params)==null?void 0:z.ideId)||le.id.slice(7),de=hs(t,Y);h((de==null?void 0:de.tabKey)??null);return}if(h((le==null?void 0:le.id)??null),!le)return;const he=P.get(le.id);(he==null?void 0:he.streamSource)==="agent-stream"&&he.agentType&&g(he.ideId,"focus_session",{agentType:he.agentType,...he.sessionId&&{targetSessionId:he.sessionId}}).catch(()=>{})}),R.api.onDidLayoutChange(()=>{var le;ac(L,{activeTabId:((le=R.api.activePanel)==null?void 0:le.id)??null,layout:R.api.toJSON()})}),R.api.onWillDragPanel(()=>{T(!0),j(!1),F()}),R.api.onWillDragGroup(()=>{T(!0),j(!1),F()}),R.api.onWillShowOverlay(()=>{B(),j(!0)}),R.api.onDidMovePanel(M),R.api.onDidDrop(M),h(((oe=R.api.activePanel)==null?void 0:oe.id)??null)},[A,M,B,P,L,F,O,h,p,g,t]);a.useEffect(()=>{const R=w.current;!R||!C.current||(Fn(R,t),Vn(R,t,b),!R.activePanel&&R.panels[0]&&R.panels[0].group.model.openPanel(R.panels[0]))},[b,t]),a.useEffect(()=>{C.current&&A(p)},[A,p]),a.useEffect(()=>{if(!y||typeof window>"u")return;const R=()=>M();return window.addEventListener("pointerup",R),window.addEventListener("mouseup",R),window.addEventListener("dragend",R),()=>{window.removeEventListener("pointerup",R),window.removeEventListener("mouseup",R),window.removeEventListener("dragend",R)}},[M,y]),a.useEffect(()=>()=>{typeof window>"u"||D.current!=null&&window.clearTimeout(D.current)},[]),a.useEffect(()=>{const R=H=>{const oe=H.target;if(!oe)return;const le=oe.querySelector("[data-tab-key]")||oe.closest("[data-tab-key]");if(le){const he=le.getAttribute("data-tab-key");he&&H.dataTransfer&&H.dataTransfer.setData("text/tab-key",he)}};return window.addEventListener("dragstart",R),()=>window.removeEventListener("dragstart",R)},[]);const _=N==="light"?_a:Ta;return e.jsx(Yr.Provider,{value:$,children:e.jsx("div",{ref:k,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(Ma,{className:`h-full min-h-0 min-w-0 adhdev-dockview${y?" is-dragging-dockview":""}${v?" is-showing-dockview-overlay":""}`,components:{conversation:Kc,remote:Wc},defaultTabComponent:zc,watermarkComponent:Oc,onReady:E,singleTabMode:"default",tabAnimation:"smooth",theme:_})})})}function Hc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:u,mobileChatConversations:x,hiddenConversations:h,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,requestedMobileTabKey:C,onRequestedMobileTabConsumed:y,requestedMachineId:T,onRequestedMachineConsumed:v,requestedMobileSection:j,onRequestedMobileSectionConsumed:D,containerRef:L,isSplitMode:P,numGroups:U,groupSizes:$,groupedConvs:A,clearedTabs:F,focusedGroup:B,setFocusedGroup:O,moveTabToGroup:M,splitTabRelative:E,closeGroup:_,handleResizeStart:R,detectedIdes:H,handleLaunchIde:oe,groupActiveTabIds:le,setGroupActiveTabIds:he,groupTabOrders:z,setGroupTabOrders:Y,toggleHiddenTab:de,visibleConversations:ge,requestedDesktopTabKey:ee,onRequestedDesktopTabConsumed:xe,onDesktopActiveTabChange:pe,onHideConversation:te,onShowHiddenConversation:me,onShowAllHiddenConversations:se}){return Os.useEffect(()=>{const ue=X=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?X.metaKey&&X.key.toLowerCase()==="w":X.ctrlKey&&X.key.toLowerCase()==="w")&&(X.preventDefault(),n&&te&&te(n))};return window.addEventListener("keydown",ue),()=>window.removeEventListener("keydown",ue)},[n,te]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Vi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:ge,hiddenConversations:h,onOpenHistory:c,onOpenConversation:me,onHideConversation:te,onShowConversation:me,onShowAllHidden:se,onOpenRemote:()=>{!n||Ee(n)||Te(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:u}),t?e.jsx(Sc,{conversations:x,hiddenConversations:h,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,requestedActiveTabKey:C,onRequestedActiveTabConsumed:y,requestedMachineId:T,onRequestedMachineConsumed:v,requestedMobileSection:j,onRequestedMobileSectionConsumed:D,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:me,onShowAllHiddenConversations:se}):s?e.jsx($c,{containerRef:L,isSplitMode:P,numGroups:U,groupSizes:$,groupedConvs:A,clearedTabs:F,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,focusedGroup:B,setFocusedGroup:O,moveTabToGroup:M,splitTabRelative:E,closeGroup:_,handleResizeStart:R,detectedIdes:H,handleLaunchIde:oe,groupActiveTabIds:le,setGroupActiveTabIds:he,groupTabOrders:z,setGroupTabOrders:Y,toggleHiddenTab:de}):e.jsx(Uc,{visibleConversations:ge,clearedTabs:F,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,detectedIdes:H,handleLaunchIde:oe,toggleHiddenTab:de,onActiveTabChange:pe,requestedActiveTabKey:ee,onRequestedActiveTabConsumed:xe})]})}const _s=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Fc({onClose:t}){const[s,n]=a.useState(0),r=_s[s],i=s===_s.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:_s.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
47
+ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:L,onCancel:()=>u(null)})]})}const Io=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Mo(){const{preference:t,setPreference:s}=Lr();return e.jsx("div",{className:"flex gap-2",children:Io.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===n.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}function _o(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 To(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Ns(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function Ln(t){const{r:s,g:n,b:r}=To(t);return .2126*Ns(s)+.7152*Ns(n)+.0722*Ns(r)}function Rn(t,s){const n=Ln(t),r=Ln(s),i=Math.max(n,r),o=Math.min(n,r);return(i+.05)/(o+.05)}function Js(t){const s=_o(t);if(!s)return"#111827";const n="#111827",r="#ffffff";return Rn(s,n)>=Rn(s,r)?n:r}const Rr="adhdev-accent-color",Bs="#cf7a45";function Ao(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,r),o=Math.min(s,n,r);let c=0,d=0;const l=(i+o)/2;if(i!==o){const f=i-o;switch(d=l>.5?f/(2-i-o):f/(i+o),i){case s:c=((n-r)/f+(n<r?6:0))/6;break;case n:c=((r-s)/f+2)/6;break;case r:c=((s-n)/f+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)}}function Pn(t,s){const{h:n,s:r,l:i}=Ao(t),o=Math.min(100,i+s);return`hsl(${n}, ${r}%, ${o}%)`}function Ss(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function Lo(){return typeof window>"u"?Bs:localStorage.getItem(Rr)||Bs}function Ro(){if(typeof window>"u")return!1;try{return localStorage.getItem(Rr)!=null}catch{return!1}}function Po(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",Pn(t,15)),s.style.setProperty("--accent-on-primary",Js(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${Pn(t,20)})`),s.style.setProperty("--border-accent",Ss(t,.4)),s.style.setProperty("--nav-active-bg",Ss(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${Ss(t,.06)}`)}function $o(){const t=Lo();t!==Bs&&Po(t)}const Ks={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},Ws={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},Eo=[{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"}}}],Pr="adhdev-chat-theme",$r="adhdev-chat-theme-custom";function Qt(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Pr)||"ember"}catch{return"ember"}}function et(t){try{const s=localStorage.getItem($r);if(s){const n=JSON.parse(s);return{...t==="dark"?Ks:Ws,...n[t]}}}catch{}return t==="dark"?Ks:Ws}function Ht(t,s){try{localStorage.setItem($r,JSON.stringify({dark:t,light:s}))}catch{}}function Je(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function os(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Do={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function At(t,s){var i;if(Ro())return;const n=(i=Do[t])==null?void 0:i[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",os(n,24)),r.style.setProperty("--accent-on-primary",Js(n)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${os(n,18)})`),r.style.setProperty("--border-accent",Je(n,.35)),r.style.setProperty("--nav-active-bg",Je(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Je(n,.06)}`)}function xt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Je(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Je(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Je(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Je(t.borderSubtle,.5)),s.style.setProperty("--border-default",Je(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",os(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Js(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${os(t.accentColor,40)})`),s.style.setProperty("--border-accent",Je(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Je(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Je(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Je(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Qs(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function Bo(t){try{localStorage.setItem(Pr,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else Qs(),At(t,ft()?"dark":"light")}function Ko(){const t=Qt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";xt(et(s))}else Qs(),At(t,ft()?"dark":"light")}function ft(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Fe({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function Ct({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function Wo({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>et(n));a.useEffect(()=>{i(et(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},x=et(n==="dark"?"light":"dark");return n==="dark"?Ht(f,x):Ht(x,f),xt(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(Ct,{title:"App Background",children:[e.jsx(Fe,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Fe,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Fe,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Ct,{title:"App Text",children:[e.jsx(Fe,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Fe,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Fe,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Ct,{title:"Borders & Accent",children:[e.jsx(Fe,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Fe,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Fe,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Ct,{title:"Chat Bubbles",children:[e.jsx(Fe,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Fe,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Fe,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Fe,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Ct,{title:"Chat Layout",children:[e.jsx(Fe,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Fe,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Fe,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ks:Ws,l=et(t?"light":"dark");t?Ht(c,l):Ht(l,c),i(c),xt(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Oo(){const[t,s]=a.useState(Qt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>et("dark"));a.useEffect(()=>{r(ft());const l=new MutationObserver(()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const x=ft();r(x);const h=Qt();h==="custom"?xt(et(x?"dark":"light")):At(h,x?"dark":"light")};return f.addEventListener("change",u),()=>{l.disconnect(),f.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?xt(et(n?"dark":"light")):(Qs(),At(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(et(n?"dark":"light"))},[n]);const c=l=>{s(l),Bo(l)},d=[...Eo,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const f=t===l.id,u=n?l.preview.dark:l.preview.light,x=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:x},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Wo,{dark:n,onColorsChange:l=>o(l)})]})}const Er="adhdev_mobileDashboardMode_v1";function Dr(){try{return localStorage.getItem(Er)==="workspace"?"workspace":"chat"}catch{return"chat"}}function zo(t){try{localStorage.setItem(Er,t)}catch{}}function Uo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Dr()==="chat")},[]),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:n=>{s(n),zo(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Br="adhdev_hiddenTabs";function Ho(){try{const t=localStorage.getItem(Br);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function yt(t){try{localStorage.setItem(Br,JSON.stringify([...t]))}catch{}}function Fo(){const[t,s]=a.useState(Ho),n=a.useCallback(f=>{s(u=>{const x=new Set(u);return x.has(f)?x.delete(f):x.add(f),yt(x),x})},[]),r=a.useCallback(f=>{s(u=>{if(u.has(f))return u;const x=new Set(u);return x.add(f),yt(x),x})},[]),i=a.useCallback(f=>{s(u=>{if(!u.has(f))return u;const x=new Set(u);return x.delete(f),yt(x),x})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const u=new Set;return yt(u),u})},[]),c=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.add(p);return yt(h),h})},[]),d=a.useCallback((f,u)=>{s(x=>{const h=new Set(x);for(const p of u)h.delete(p);return yt(h),h})},[]),l=a.useCallback(f=>t.has(f),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:d,isHidden:l}}function Vo({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{lo()},[]);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 po(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[u,x]of Object.entries(d))l-x<5e3&&(f[u]=x);return Object.keys(f).length===Object.keys(d).length?d:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(d=>{const l=d.filter(f=>f.timestamp>c).slice(-100);return l.length===d.length?d:l})},6e4);return()=>clearInterval(o)},[r]),null}function Cs(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function jt(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return Cs(s==null?void 0:s.timestamp)||Cs(s==null?void 0:s.receivedAt)||Cs(s==null?void 0:s.createdAt)||0}function $n(t){return jt(t)}function Kr(t,s){const n=$n(s)-$n(t);if(n!==0)return n;const r=(t.machineName||"").localeCompare(s.machineName||"");if(r!==0)return r;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const o=t.displaySecondary.localeCompare(s.displaySecondary);return o!==0?o:t.tabKey.localeCompare(s.tabKey)}function qo(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const i=n.get(r.id);if(!i){n.set(r.id,r);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>o||(r.timestamp||0)>(i.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function Ft(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function Go(t,s){const n=Date.now();return t.map(r=>{const i=s[r.tabKey];return i&&n-i<5e3?{...r,messages:[],title:""}:r})}function Yo(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;n.push({key:c,ref:s[c]}),n.push({key:i.id,ref:s[i.id]})}return n}function Xo(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n].key!==s[n].key||t[n].ref!==s[n].ref)return!1;return!0}function Zo({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),d=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const C=qo(t);return Ft(o.current,C)?o.current:(o.current=C,C)},[t]),u=a.useMemo(()=>Sr(t),[t]),x=a.useRef(new Map),h=a.useMemo(()=>{var T;const C=new Map,y=[];for(const v of f){const j=v.daemonId||((T=v.id)==null?void 0:T.split(":")[0])||v.id,D=s[j]||"new",L=v.daemonId&&u[v.daemonId]||void 0,P=Yo(v,n),U=x.current.get(v.id);if(U&&U.ide===v&&U.connectionState===D&&U.machineName===L&&Xo(U.localRefs,P)){C.set(v.id,U),y.push(...U.conversations);continue}const $=Cr(v,n,{machineName:L,connectionState:D}),A={ide:v,connectionState:D,machineName:L,localRefs:P,conversations:$};C.set(v.id,A),y.push(...$)}return x.current=C,[...y].sort(Kr)},[f,n,s,u]),p=a.useMemo(()=>{const C=Go(h,r);return Ft(c.current,C)?c.current:(c.current=C,C)},[h,r]),b=a.useMemo(()=>{const C=new Map;for(const y of p)y.sessionId&&C.set(y.sessionId,y);return C},[p]),m=a.useMemo(()=>{const C=new Map;for(const y of p)y.sessionId&&C.set(y.sessionId,y),C.set(y.ideId,y),C.set(y.tabKey,y);return C},[p]),N=a.useCallback(C=>{if(C)return b.get(C)},[b]),g=a.useCallback(C=>{if(C)return m.get(C)},[m]),w=a.useMemo(()=>{const C=p.filter(y=>!i.has(y.tabKey));return Ft(d.current,C)?d.current:(d.current=C,C)},[p,i]),k=a.useMemo(()=>{const C=w.map(y=>y.tabKey);return Ft(l.current,C)?l.current:(l.current=C,C)},[w]);return{chatIdes:f,conversations:p,visibleConversations:w,visibleTabKeys:k,resolveConversationBySessionId:N,resolveConversationByTarget:g}}function Jo({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var d;return t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var d;return!t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(d=>{const l=new URLSearchParams(d);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function Qo({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{lt.setIdes(t)},[t]),a.useEffect(()=>{lt.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=lt.onToast(l=>{n(u=>u.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?u:[...u.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const f=l.duration||5e3;setTimeout(()=>n(u=>u.filter(x=>x.id!==l.id)),f)}),c=lt.onSystemMessage((l,f)=>{var p,b;const u=i(l),x=(p=f._localId)==null?void 0:p.startsWith("sys_approval_"),h=!!(u&&(u.status==="waiting_approval"||(b=u.modalButtons)!=null&&b.length||u.modalMessage));x&&h||r(m=>({...m,[l]:[...m[l]||[],f]}))}),d=lt.onClearSystemMessage((l,f)=>{r(u=>{var x;return(x=u[l])!=null&&x.length?{...u,[l]:u[l].filter(h=>{var p;return!(h.role==="system"&&((p=h._localId)!=null&&p.startsWith(f)))})}:u})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=jr.on("status_event",c=>lt.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=d=>{const l=d.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,u=i(f),x=(u==null?void 0:u.ideId)||l.ideId;x&&s(x,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(h=>console.error("[SW Action] approve failed:",h))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var d;return(d=navigator.serviceWorker)==null?void 0:d.removeEventListener("message",o)}},[i,s])}const ec="adhdev_dashboardLayout_v1",tc="adhdev_dashboardDockview_v1",It={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Wr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Or(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function zr(t){return`${ec}:${t}`}function sc(t){const s=zr(t);return Wr(s,null)}function nc(t,s){try{const n=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,r=zr(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Ur(t){return`${tc}:${t}`}function rc(t){const s=Ur(t);return Wr(s,null)}function ac(t,s){try{const n=Ur(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function ic(){return{groupAssignments:[...It.groupAssignments],focusedGroup:It.focusedGroup,groupActiveTabIds:{...It.groupActiveTabIds},groupTabOrders:{...It.groupTabOrders},groupSizes:[...It.groupSizes]}}function oc(){const[t]=a.useState(()=>Or(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[d,l]=a.useState({}),[f,u]=a.useState([]),[x,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,b]=a.useState(!1),m=a.useCallback(()=>{if(p)return;const N=sc(t)??ic();n(new Map(N.groupAssignments)),i(N.focusedGroup),c(N.groupActiveTabIds),l(N.groupTabOrders),u(N.groupSizes),b(!0)},[p,t]);return a.useEffect(()=>{p&&nc(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[p,t,s,r,o,d,f]),a.useEffect(()=>{const N=window.matchMedia("(max-width: 767px)"),g=w=>h(w.matches);return N.addEventListener("change",g),()=>N.removeEventListener("change",g)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:u,isMobile:x,hasHydratedStoredLayout:p,hydrateStoredLayout:m}}function cc({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:u,isRefreshingHistory:x,ides:h,handleRefreshHistory:p}){const b=a.useRef(!1),m=a.useRef(!1),N=a.useRef(null),g=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!i){o();return}const w=n(t);if(!w)return;const k=r.get(w.tabKey)??0;c(C=>({...C,[k]:w.tabKey})),d(k),b.current=!0,m.current=!0,N.current!=null&&(window.clearTimeout(N.current),N.current=null),l(C=>{const y=new URLSearchParams(C);return y.delete("activeTab"),y},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(m.current||i)&&s.length!==0){if(!t){o(),m.current=!0;return}if(b.current){m.current=!0;return}if(N.current==null)return N.current=window.setTimeout(()=>{N.current=null,!(m.current||i)&&(o(),m.current=!0)},1500),()=>{N.current!=null&&(window.clearTimeout(N.current),N.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){g.current=!1;return}if(!u||g.current||x)return;const w=h.find(k=>k.id===u.ideId);w&&(!w.chats||w.chats.length===0)&&(g.current=!0,p())},[f,u,x,h,p]),a.useEffect(()=>{if(!u)return;let w=null,k=0,C=-1,y=0;const T=()=>{w=null;const v=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(D=>D.offsetParent!==null);if(v.length===0){k<18&&(k+=1,w=requestAnimationFrame(T));return}let j=0;for(const D of v)D.scrollTop=D.scrollHeight,j+=D.scrollHeight;j===C?y+=1:(y=0,C=j),k+=1,!(y>=2||k>=18)&&(w=requestAnimationFrame(T))};return w=requestAnimationFrame(T),()=>{w!=null&&cancelAnimationFrame(w)}},[u==null?void 0:u.tabKey])}function lc({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[u,x]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const g=d(r);return g&&!Ee(g)&&!Te(g)?g:null},[t,r,d]),p=a.useMemo(()=>{const g=l==null?void 0:l.ideId;if(!g)return null;const w=l!=null&&l.tabKey?o.find(k=>k.tabKey===l.tabKey):i?o.find(k=>k.tabKey===i):null;return(w==null?void 0:w.ideId)===g?w:o.find(k=>k.ideId===g&&k.streamSource==="native")||o.find(k=>k.ideId===g)||null},[o,l,i]),b=a.useMemo(()=>{if(p)return c.find(g=>g.id===p.ideId)},[c,p]);a.useEffect(()=>{h&&(f({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),x(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const m=a.useCallback(g=>{g&&(f({ideId:g.ideId,tabKey:g.streamSource==="native"?"native":g.tabKey}),x(g))},[]),N=a.useCallback(()=>{f(null),x(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:b,remoteDialogActiveConv:u,setRemoteDialogActiveConv:x,openRemoteDialog:m,closeRemoteDialog:N}}function Lt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ee(t)||Te(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function cs(t){return t&&(t.ideId||t.daemonId)||""}function Vt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function En({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),u=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(m){console.error("Launch failed",m)}},[t]),x=a.useCallback(async(b,m)=>{try{const N=b||(s==null?void 0:s.daemonId)||"",g=await t(N,"switch_chat",{id:m,sessionId:m,...Lt(s)}),w=g==null?void 0:g.result;if((g==null?void 0:g.success)===!0||w==="switched"||w==="switched-by-title")return;w===!1||w==="not_found"?Vt(r,"⚠️ Session tab not found — try refreshing history"):typeof w=="string"&&w.startsWith("error:")?Vt(r,`⚠️ Switch error: ${w}`):Vt(r,"⚠️ Session switch failed")}catch(N){console.error("Switch failed",N),Vt(r,`❌ Switch failed: ${N.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const b=cs(s);await t(b,"new_chat",{...Lt(s)}),o(m=>({...m,[s.tabKey]:Date.now()})),i(m=>({...m,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{d(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var b;if(!(!s||l)){f(!0);try{const m=cs(s),N=await t(m,"list_chats",{forceExpand:!0,...Lt(s)}),g=(N==null?void 0:N.chats)||((b=N==null?void 0:N.result)==null?void 0:b.chats);N!=null&&N.success&&Array.isArray(g)&&n(s.ideId,g)}catch(m){console.error("Refresh history failed",m)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:x,handleNewChat:h,handleRefreshHistory:p}}function dc(t,s){if(t.size!==s.size)return!1;for(const[n,r]of t)if(s.get(n)!==r)return!1;return!0}function uc(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Dn(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[Number(i)]===t[Number(i)])}function qt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Bn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function pc(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function mc(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Kn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=Number(r);n[o>=s?o+1:o]=i}return n}function Wn(t){return Array(t).fill(100/t)}function xc({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const u=a.useRef(null),x=a.useMemo(()=>qt(t,f),[t,f]),h=x.assignments,p=a.useMemo(()=>d?1:x.groupCount,[x.groupCount,d]),b=p>1,m=a.useCallback((y,T)=>{s(v=>{const j=new Map(qt(v,f).assignments);return T===0?j.delete(y):j.set(y,T),j}),r(v=>({...v,[T]:y})),n(T)},[s,f,r,n]),N=a.useCallback(y=>{s(T=>{const v=qt(T,f).assignments,j=new Map;for(const[D,L]of v)L!==y&&(L>y?j.set(D,L-1):j.set(D,L));return j}),c(T=>{if(T.length<=1)return[];const v=[...T];v.splice(y,1);const j=v.reduce((D,L)=>D+L,0);return j>0?v.map(D=>D/j*100):[]}),n(0)},[s,f,c,n]),g=a.useCallback((y,T)=>{T.preventDefault();const v=u.current;if(!v)return;const j=T.clientX,D=v.offsetWidth,L=o.length===p?[...o]:Wn(p),P=$=>{const F=($.clientX-j)/D*100,B=[...L];B[y]=Math.max(15,L[y]+F),B[y+1]=Math.max(15,L[y+1]-F),c(B)},U=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",U),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",P),document.addEventListener("mouseup",U)},[o,p,c]),w=a.useCallback((y,T,v)=>{if(p>=4)return;const j=v==="left"?T:T+1;s(D=>{const L=qt(D,f).assignments,P=new Map;for(const U of l){const $=L.get(U.tabKey)??0,A=$>=j?$+1:$;A>0&&P.set(U.tabKey,A)}return j>0&&P.set(y,j),P}),c(D=>{const L=D.length===p?[...D]:Wn(p),P=L[T]??100/p,U=Math.max(15,P/2),$=Math.max(15,P/2),A=[...L];A[T]=U,A.splice(j,0,$);const F=A.reduce((B,O)=>B+O,0);return A.map(B=>B/F*100)}),r(D=>{const L=Kn(D,j);return L[j]=y,L}),i(D=>{const L=Kn(D,j);return L[j]=[y],L}),n(j)},[p,s,f,l,c,r,i,n]);a.useEffect(()=>{dc(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:y,usedGroups:T}=x;r(v=>{const j=Bn(v,y);return Dn(v,j)?v:j}),i(v=>{const j=Bn(v,y);return Dn(v,j)?v:j}),n(v=>{const j=d?0:pc(v,T,y);return v===j?v:j}),c(v=>{const j=d?[]:mc(v,T,x.groupCount);return uc(v,j)?v:j})},[x,d,r,i,n,c]);const k=a.useMemo(()=>{const y=Array.from({length:p},()=>[]);for(const T of l){const v=h.get(T.tabKey)??0,j=Math.min(v,p-1);y[j].push(T)}return y},[l,h,p]),C=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:h,numGroups:p,isSplitMode:b,groupedConvs:k,moveTabToGroup:m,closeGroup:N,handleResizeStart:g,splitTabRelative:w,clearAllSplits:C}}function fc({ides:t,sendDaemonCommand:s}){const n="0.8.10",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const u=f.version||f.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var u,x;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(u=h==null?void 0:h.result)!=null&&u.upgraded||(x=h==null?void 0:h.result)!=null&&x.success?d(p=>({...p,[f]:"done"})):d(p=>({...p,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function xs({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[d,l]=a.useState(!1),f=a.useRef(!1),u=a.useRef(null),x=a.useCallback(async m=>{if(!s)return;const N=m.trim();if(!N||f.current)return;const g=s.tabKey,w=Date.now(),k=u.current;if(k&&k.tabKey===g&&k.message===N&&w-k.timestamp<2e3)return;f.current=!0,l(!0),u.current={tabKey:g,message:N,timestamp:w};const C=`${w}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:N,timestamp:w,_localId:C};n(T=>({...T,[g]:[...T[g]||[],y]}));try{const T=cs(s);if(!T)return;const v=await t(T,"send_chat",{message:N,text:N,...Lt(s)});if(v!=null&&v.deduplicated||(v==null?void 0:v.sent)===!1){n(j=>({...j,[g]:(j[g]||[]).filter(D=>D._localId!==C)}));return}setTimeout(()=>{const j=Date.now()-6e4;n(D=>{const L=D[g];if(!L)return D;const P=L.filter(U=>U.timestamp>j);return P.length===L.length?D:{...D,[g]:P}})},6e4)}catch(T){console.error("Send failed",T),n(v=>({...v,[g]:(v[g]||[]).filter(j=>j._localId!==C)}))}finally{f.current=!1,l(!1)}},[s,t,n]),h=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(m){console.error("Relaunch failed",m)}},[s,t]),p=a.useCallback(async m=>{if(s)try{const g=(s.modalButtons||[]).indexOf(m),w=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),k=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w),C=cs(s);if(!C)return;(await t(C,"resolve_action",{button:m,action:k?"approve":"reject",...g>=0&&{buttonIndex:g},...Lt(s)})).success||r(T=>[...T,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(N){console.error("[ModalButton] Error:",N),r(g=>[...g,{ideId:s.tabKey,text:`❌ **${m}** error`,timestamp:Date.now()}])}},[s,t,r]),b=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:x,handleRelaunch:h,handleModalButton:p,handleFocusAgent:b}}const en=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p}){return e.jsxs(e.Fragment,{children:[e.jsx(hr,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(Vs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:d,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:r?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Ui,{activeConv:s,clearToken:n,terminalRef:o,handleSendChat:l,isSendingChat:f,isVisible:r})}),!r&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx($s,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})})]}):e.jsx($s,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:x,actionLogs:h,userName:p})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function hc({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:u,onOpenRemote:x,onHideConversation:h,onStopCli:p,cliViewMode:b,onSetCliViewMode:m,handleSendChat:N,handleFocusAgent:g,handleModalButton:w,handleRelaunch:k}){const C=a.useRef(null),y=Ee(t)&&!s,T=y&&b==="terminal";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5 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(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(yr,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[y&&b&&e.jsx(Xs,{mode:b,onChange:m,compact:!0}),y&&p&&e.jsx("button",{onClick:()=>{p(t)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(kt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(t),type:"button",children:e.jsx(Hs,{size:14})}),!s&&!y&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(t),type:"button",children:e.jsx(qe,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(kt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(en,{activeConv:t,clearToken:0,isCliTerminal:T,ideEntry:n,terminalRef:C,handleModalButton:w,handleRelaunch:k,handleSendChat:N,isSendingChat:o,handleFocusAgent:g,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const Is={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function bc(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Hr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(bc())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(Is[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Is[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Is[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Fr({section:t,onSectionChange:s}){const n=[{key:"machines",label:"Machines",icon:qe},{key:"chats",label:"Chats",icon:it}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:n.map(({key:r,label:i,icon:o})=>{const c=t===r;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(r),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(o,{size:15})}),e.jsx("span",{children:i})]},r)})})})}function Gt({title:t,className:s=""}){return e.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${s}`,children:e.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:t})})}function vt({children:t,className:s=""}){return e.jsx("div",{className:`overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function Mt({icon:t,title:s,subtitle:n,children:r}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 pt-12 pb-8 px-6 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),r]})}function Yt({item:t,type:s,getAvatarText:n,onOpenConversation:r}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`group flex items-start gap-3.5 px-4 py-3.5 w-full text-left relative overflow-hidden transition-colors active:scale-[0.995] ${i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":"bg-transparent"} ${c?"opacity-70 saturate-50":""}`,onClick:()=>r(t.conversation),type:"button",children:[i||o?e.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,e.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary shadow-glow":o?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":"bg-bg-primary border border-border-subtle text-text-secondary"}`,style:i?{color:"var(--accent-on-primary)"}:void 0,children:n(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:fr(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(qe,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]},t.conversation.tabKey)}function On({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function gc({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:u,onOpenMachine:x,onOpenSettings:h,onSectionChange:p,wsStatus:b="connected",isStandalone:m=!1}){const N=b==="disconnected"||b==="reconnecting"||b==="offline"||b==="auth_failed",g=c.length>0,w=s.length>0||n.length>0||r.length>0||i.length>0,k=t==="machines"?"Machines":"Chats";return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4 shrink-0 bg-bg-primary z-10",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:k}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(ps,{size:13}),e.jsx("span",{children:s.length+n.length})]}),e.jsx("button",{onClick:h,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:e.jsx(us,{size:18})})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))] flex flex-col gap-3 -webkit-overflow-scrolling-touch",children:[t==="machines"&&e.jsx("section",{className:"flex flex-col gap-2",children:N?e.jsx(Mt,{icon:e.jsx(On,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:b==="offline"?"Your device appears to be offline. Waiting for network…":b==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:m?"Waiting for your IDE":"Connect your first machine",subtitle:m?"Launch any supported IDE or CLI agent — it will appear here automatically.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!m&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Hr,{})})}):e.jsx(vt,{children:c.map((C,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(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:d(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 flex-col gap-2",children:[e.jsx(Gt,{title:"Needs attention",className:"mb-0"}),e.jsx(vt,{children:s.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"needs_attention",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(Gt,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(vt,{children:n.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"task_complete",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(Gt,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(vt,{children:r.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"working",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex flex-col gap-2",children:[i.length>0&&e.jsx(Gt,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(vt,{children:i.map((C,y)=>e.jsx("div",{className:y>0?"border-t border-border-subtle/70":"",children:e.jsx(Yt,{item:C,type:"earlier",getAvatarText:d,onOpenConversation:l})},C.conversation.tabKey))}):w?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):N?e.jsx(Mt,{icon:e.jsx(On,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):g?e.jsx(Mt,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(it,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open an IDE or launch a CLI agent to start your first conversation."}):e.jsx(Mt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:u,children:"Restore all"})]}),e.jsx(vt,{className:"bg-bg-secondary/25",children:o.map((C,y)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] opacity-50 saturate-0 ${y>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(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:d(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(qe,{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(Fr,{section:t,onSectionChange:p})]})}function tn(t,s=[]){for(const n of s){const r=typeof n=="string"?n.trim():"";if(r)return r}return t==="win32"?"C:\\":"~"}function yc(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const n=s.includes("\\")?"\\":"/",r=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(r[0]||"")?r.length<=2?`${r[0]}\\`:r.slice(0,-1).join("\\"):r.length<=2?n:r.slice(0,-1).join(n)||n}async function Vr(t,s,n){const r=await t(s,"file_list_browse",{path:n});if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Could not browse folder");const i=typeof(r==null?void 0:r.path)=="string"?r.path:n,o=i.includes("\\")?"\\":"/",c=(l,f)=>/^[A-Za-z]:\\?$/.test(l)?`${l.replace(/\\?$/,"\\")}${f}`:l==="/"||l==="\\"?`${o}${f}`:`${l.replace(/[\\/]+$/,"")}${o}${f}`,d=Array.isArray(r==null?void 0:r.files)?r.files.filter(l=>(l==null?void 0:l.type)==="directory"&&typeof(l==null?void 0:l.name)=="string").map(l=>({name:l.name,path:c(i,l.name)})).sort((l,f)=>l.name.localeCompare(f.name)):[];return{path:i,directories:d}}function sn({title:t,description:s,currentPath:n,directories:r,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:d,onNavigate:l,onConfirm:f}){const[u,x]=a.useState(n);a.useEffect(()=>{x(n)},[n]);const h=yc(n),p=u.trim();return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:d,"aria-label":"Close folder browser",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!h||i||l(h)},disabled:!h||i,children:[e.jsx(Us,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:b=>x(b.target.value),onKeyDown:b=>{b.key!=="Enter"||!p||i||(b.preventDefault(),l(p))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!p||i||l(p)},disabled:!p||i,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):r.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:r.map(b=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>l(b.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($t,{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:b.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:b.path})]})]},b.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>f(p||n),disabled:!p&&!n||i,children:c})]})]})})}function nn({title:t,description:s,details:n,workspaceOptions:r,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:d=!1,onConfirm:l,onCancel:f}){const u=r==null?void 0:r.find(x=>x.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:f,"aria-label":"Close launch confirmation",children:e.jsx(kt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[r&&r.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:x=>o(x.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:r.map(x=>e.jsx("option",{value:x.key,children:x.label},x.key))}),(u==null?void 0:u.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:u.description})]}),n.map(x=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:x.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:x.value})]},`${x.label}:${x.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:f,disabled:d,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:l,disabled:d,children:[e.jsx(ur,{size:14}),d?"Launching…":c]})]})]})})}function zn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function ht(t){const{machine:s,currentWorkspacePath:n,currentWorkspaceId:r,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const l of s.workspaces||[])o.push({key:`saved:${l.id}`,label:`${l.id===s.defaultWorkspaceId?"⭐ ":""}${zn(l.path,l.label)}`,description:l.path,workspaceId:l.id,workspacePath:l.path});const c=(n==null?void 0:n.trim())||"",d=c?(s.workspaces||[]).find(l=>l.path===c):null;if(c&&!d&&o.push({key:`custom:${c}`,label:zn(c),description:c,workspaceId:null,workspacePath:c}),r){const l=`saved:${r}`;if(o.some(f=>f.key===l))return{options:o,selectedKey:l}}return d?{options:o,selectedKey:`saved:${d.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function vc({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:u,onSectionChange:x,onOpenConversation:h,onOpenRecent:p,onOpenMachineDetails:b,onMachineUpgrade:m,onLaunchDetectedIde:N,onAddWorkspace:g,onBrowseDirectory:w,onLaunchWorkspaceProvider:k}){var Oe,Ge,De,Be;const C=(ne,je,we)=>ne?"ide":je>0?"cli":we>0?"acp":null,[y,T]=a.useState(!1),v=ne=>ne==="ide"?"IDE":ne==="cli"?"CLI":"ACP",j=n.slice(0,4),D=s.slice(0,3),L=(((Oe=t.detectedIdes)==null?void 0:Oe.length)||0)>0,P=a.useMemo(()=>t.workspaces||[],[t]),U=t.defaultWorkspaceId||null,[$,A]=a.useState(U||((Ge=P[0])==null?void 0:Ge.id)||""),[F,B]=a.useState(""),[O,M]=a.useState(""),[E,_]=a.useState([]),[R,H]=a.useState(!1),[oe,le]=a.useState(""),[he,z]=a.useState(!1),[Y,de]=a.useState(C(L,r.length,i.length)),ge=a.useRef(null),[ee,xe]=a.useState(null),pe=a.useRef("__home__"),[te,me]=a.useState("__home__"),[se,ue]=a.useState(!1),X=a.useRef(null),J=$==="__custom__"?F.trim():((De=P.find(ne=>ne.id===$))==null?void 0:De.path)||"",S=$==="__custom__"&&!!J&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message),Z=$!=="__custom__"&&((Be=P.find(ne=>ne.id===$))==null?void 0:Be.path)||"",Q=a.useCallback(async ne=>{H(!0),le("");try{const je=await w(ne);M(je.path),B(je.path),_(je.directories)}catch(je){le(je instanceof Error?je.message:"Could not load folder")}finally{H(!1)}},[w]),ie=a.useCallback(()=>{var je,we;A("__custom__"),z(!0);const ne=tn(t.platform,[F.trim(),Z,(je=P.find(ye=>ye.id===U))==null?void 0:je.path,(we=P[0])==null?void 0:we.path]);Q(ne)},[F,U,Q,Z,t.platform,P]),fe=a.useCallback((ne,je)=>{ge.current=je,pe.current=ne.selectedWorkspaceKey||"__home__",me(ne.selectedWorkspaceKey||"__home__"),xe(ne)},[]),ve=a.useCallback(()=>{ge.current&&(ue(!0),ge.current().finally(()=>{ge.current=null,ue(!1),xe(null)}))},[]);a.useEffect(()=>{var ne;X.current!==t.id&&(X.current=t.id,A(U||((ne=P[0])==null?void 0:ne.id)||"__custom__"),B(""),M(""),_([]),le(""),z(!1),de(C(L,r.length,i.length)))},[i.length,r.length,U,L,t.id,P]),a.useEffect(()=>{var ne;$!=="__custom__"&&($&&P.some(je=>je.id===$)||A(U||((ne=P[0])==null?void 0:ne.id)||"__custom__"))},[U,$,P]),a.useEffect(()=>{Y==="ide"&&L||Y==="cli"&&r.length>0||Y==="acp"&&i.length>0||de(C(L,r.length,i.length))},[Y,i.length,r.length,L]);const Se=a.useMemo(()=>{const ne=j.map(we=>({key:`recent-launch:${we.id}`,type:"session",primary:we.label,secondary:`${v(we.kind)}${we.subtitle?` · ${we.subtitle}`:""}`,unread:!1,onClick:()=>{const{options:ye,selectedKey:ze}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspacePath:we.workspace});fe({title:`Launch ${we.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:ye,selectedWorkspaceKey:ze,details:[{label:"Mode",value:v(we.kind)},...we.providerType?[{label:"Provider",value:we.providerType}]:[]]},async()=>{const Re=ye.find(W=>W.key===pe.current);Re!=null&&Re.workspaceId?(A(Re.workspaceId),B("")):Re!=null&&Re.workspacePath?(A("__custom__"),B(Re.workspacePath)):(A(""),B("")),await p({...we,workspace:(Re==null?void 0:Re.workspacePath)??null})})}})),je=D.map(we=>({key:`recent-chat:${we.conversation.tabKey}`,type:"conversation",primary:we.conversation.displayPrimary,secondary:`Chat${we.conversation.displaySecondary?` · ${we.conversation.displaySecondary}`:""}${we.timestamp?` · ${fr(we.timestamp)}`:""}`,unread:we.unread,onClick:()=>h(we.conversation)}));return[...ne,...je]},[U,h,p,fe,D,j,P]),Ae=y?Se:Se.slice(0,5),Ze=Se.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3 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:u,type:"button","aria-label":"Back",children:e.jsx(Us,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:nt(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[Ze&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Ae.map(ne=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${ne.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:ne.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:ne.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:ne.secondary})]},ne.key))}),Se.length>5&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>T(ne=>!ne),children:y?"Show fewer":`Show ${Se.length-5} more`})})]}),(L||r.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:$,onChange:ne=>{const je=ne.target.value;if(A(je),je==="__custom__"){ie();return}B("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:P.length>0?e.jsxs(e.Fragment,{children:[P.map(ne=>e.jsxs("option",{value:ne.id,children:[ne.id===U?"⭐ ":"",Gs(ne.path,ne.label)||ne.path]},ne.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),$==="__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($t,{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:J||O||"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:ie,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:()=>{J&&g(J)},disabled:!J||R,children:"Save as workspace"})]})]}),J&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[L&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${Y==="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:()=>de("acp"),children:"ACP"})]}),Y&&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:Y==="ide"?"Choose an IDE":Y==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:Y==="ide"?(t.detectedIdes||[]).slice(0,6).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:we}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspaceId:$!=="__custom__"?$:null,currentWorkspacePath:J});fe({title:`Launch ${ne.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:je,selectedWorkspaceKey:we,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:ne.name}]},async()=>{const ye=je.find(ze=>ze.key===pe.current);ye!=null&&ye.workspaceId?(A(ye.workspaceId),B("")):ye!=null&&ye.workspacePath?(A("__custom__"),B(ye.workspacePath)):(A(""),B("")),N(ne.type,{workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:ne.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J||"Use selected workspace"})]},ne.type)):(Y==="cli"?r:i).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:je,selectedKey:we}=ht({machine:{workspaces:P,defaultWorkspaceId:U},currentWorkspaceId:$!=="__custom__"?$:null,currentWorkspacePath:J});fe({title:`Launch ${ne.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${Y.toUpperCase()}`,workspaceOptions:je,selectedWorkspaceKey:we,details:[{label:"Mode",value:Y.toUpperCase()},{label:"Provider",value:ne.displayName}]},async()=>{const ye=je.find(ze=>ze.key===pe.current);ye!=null&&ye.workspaceId?(A(ye.workspaceId),B("")):ye!=null&&ye.workspacePath?(A("__custom__"),B(ye.workspacePath)):(A(""),B("")),k(Y,ne.type,{workspaceId:(ye==null?void 0:ye.workspaceId)??null,workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[ne.icon?`${ne.icon} `:"",ne.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:J||"Use selected workspace"})]},ne.type))})]}),d.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${d.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[d.message,S&&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:()=>g(J,{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:m,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:b,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"})]})]})]})]}),he&&e.jsx(sn,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:O,directories:E,busy:R,error:oe,confirmLabel:"Use this folder",onClose:()=>z(!1),onNavigate:ne=>{Q(ne)},onConfirm:ne=>{B(ne),A("__custom__"),z(!1)}}),ee&&e.jsx(nn,{title:ee.title,description:ee.description,details:ee.details,workspaceOptions:ee.workspaceOptions,selectedWorkspaceKey:te,onWorkspaceChange:ne=>{pe.current=ne,me(ne)},confirmLabel:ee.confirmLabel,busy:se,onConfirm:ve,onCancel:()=>{ge.current=null,xe(null)}}),f&&e.jsx(Fr,{section:l,onSectionChange:x})]})}function wc(t){return Nr(t)}function Un(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=wc(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function jc(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Xt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function kc(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function Hn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Nc(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function Sc({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:u,requestedMachineId:x,onRequestedMachineConsumed:h,requestedMobileSection:p,onRequestedMobileSectionConsumed:b,onOpenHistory:m,onOpenRemote:N,onStopCli:g,wsStatus:w,isConnected:k,onShowHiddenConversation:C,onShowAllHiddenConversations:y,onHideConversation:T}){const[v,j]=a.useState(()=>{var W;return((W=t[0])==null?void 0:W.tabKey)||null}),[D,L]=a.useState(()=>t[0]?"chat":"inbox"),[P,U]=a.useState("chats"),[$,A]=a.useState(null),[F,B]=a.useState("inbox"),[O,M]=a.useState("idle"),[E,_]=a.useState(""),[R,H]=a.useState(null),oe=a.useRef(null),le=St(),he="0.8.10",z=a.useMemo(()=>t.find(W=>W.tabKey===v)||t[0]||null,[t,v]),Y=a.useMemo(()=>z?n.find(W=>W.id===z.ideId):void 0,[n,z]),de=a.useMemo(()=>!z||Te(z)||!Ee(z)?null:Nt(z),[z]),ge=a.useMemo(()=>n.filter(W=>W.type==="adhdev-daemon"||W.daemonMode).sort($i),[n]),ee=a.useMemo(()=>ge.find(W=>W.id===$)||null,[ge,$]),xe=a.useMemo(()=>Kt(n),[n]),pe=xs({sendDaemonCommand:i,activeConv:z||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),te=a.useCallback(W=>{if(!W||!W.sessionId)return;const K=Et(W,xe),re=Math.max(Date.now(),jt(W),K.lastUpdated||0);Xt("mark_read:start",{tabKey:W.tabKey,sessionId:W.sessionId,displayPrimary:W.displayPrimary,inboxBucket:K.inboxBucket,unread:K.unread,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,activityAt:jt(W),readAt:re}),i(W.daemonId||W.ideId,"mark_session_seen",{sessionId:W.sessionId,seenAt:re}).then(ce=>{Xt("mark_read:result",{tabKey:W.tabKey,sessionId:W.sessionId,result:ce})}).catch(ce=>{Xt("mark_read:error",{tabKey:W.tabKey,sessionId:W.sessionId,error:ce instanceof Error?ce.message:String(ce)})})},[xe,i]);a.useEffect(()=>{var K;if(!z){L("inbox"),j(((K=t[0])==null?void 0:K.tabKey)||null),oe.current=null;return}if(D!=="chat"){oe.current=null;return}const W=`${z.tabKey}:${z.sessionId||""}`;oe.current!==W&&(oe.current=W,te(z))},[t,te,D,z]),a.useEffect(()=>{if(!f)return;const W=t.find(K=>K.tabKey===f);W&&(j(W.tabKey),L("chat"),u==null||u())},[t,u,f]),a.useEffect(()=>{if(!x)return;const W=ge.find(K=>K.id===x);W&&(A(W.id),M("idle"),_(""),U("machines"),B("inbox"),L("machine"),h==null||h())},[ge,h,x]),a.useEffect(()=>{p&&(U(p),L("inbox"),b==null||b())},[b,p]);const me=a.useMemo(()=>t.map(W=>{const K=D==="chat"&&(z==null?void 0:z.tabKey)===W.tabKey,re=Dt(W,xe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:K}),ce=jt(W),I=Un(W);return{conversation:W,timestamp:ce,preview:I,unread:re.unread,requiresAction:re.requiresAction,isWorking:re.isWorking,inboxBucket:re.inboxBucket}}).sort((W,K)=>Kr(W.conversation,K.conversation)),[t,xe,D,z]);a.useEffect(()=>{const W=me.filter(K=>K.inboxBucket==="task_complete"||K.unread);W.length!==0&&Xt("inbox_state",{screen:D,selectedTabKey:v,items:W.map(K=>{const re=Et(K.conversation,xe);return{liveState:re,tabKey:K.conversation.tabKey,sessionId:K.conversation.sessionId,displayPrimary:K.conversation.displayPrimary,serverBucket:re.inboxBucket,computedBucket:K.inboxBucket,serverUnread:re.unread,computedUnread:K.unread,lastSeenAt:re.lastSeenAt,lastUpdated:re.lastUpdated,activityAt:jt(K.conversation)}})})},[me,xe,D,v]);const se=a.useMemo(()=>me.filter(W=>W.requiresAction),[me]),ue=a.useMemo(()=>me.filter(W=>W.unread&&!W.requiresAction),[me]),X=a.useMemo(()=>me.filter(W=>!W.unread&&!W.requiresAction&&W.isWorking),[me]),J=a.useMemo(()=>me.filter(W=>!W.unread&&!W.requiresAction&&!W.isWorking),[me]),S=a.useMemo(()=>ee?me.filter(W=>W.conversation.daemonId===ee.id||W.conversation.ideId===ee.id):[],[me,ee]),Z=a.useMemo(()=>{if(!ee)return[];const W=ee.recentLaunches||[];return W.length>0?W.map(K=>({id:K.id,label:K.title||K.providerName||K.providerType,kind:K.kind,providerType:K.providerType,providerSessionId:K.providerSessionId,subtitle:K.currentModel||K.workspace||void 0,workspace:K.workspace,currentModel:K.currentModel})):n.filter(K=>!K.daemonMode&&K.daemonId===ee.id).map(K=>{var ce,I,q,ae,V;const re=rs(K)?"cli":_t(K)?"acp":"ide";return{id:`${re}:${K.type}:${K.workspace||""}`,label:((ce=K.activeChat)==null?void 0:ce.title)||(rs(K)?K.cliName||K.type:_t(K)&&K.cliName||K.type),kind:re,providerType:K.type,providerSessionId:K.providerSessionId,subtitle:_t(K)?K.currentModel||K.workspace||void 0:K.workspace||void 0,workspace:K.workspace||void 0,currentModel:K.currentModel,timestamp:((V=(ae=(q=(I=K.activeChat)==null?void 0:I.messages)==null?void 0:q.at)==null?void 0:ae.call(q,-1))==null?void 0:V.timestamp)||0}}).sort((K,re)=>re.timestamp-K.timestamp).map(({timestamp:K,...re})=>re)},[n,ee]),Q=(ee==null?void 0:ee.version)||(ee==null?void 0:ee.daemonVersion)||null,ie=!!ee&&!!Q&&!0&&Q!==he,fe=a.useMemo(()=>(ee==null?void 0:ee.availableProviders)||[],[ee]),ve=a.useMemo(()=>fe.filter(W=>W.category==="cli").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[fe]),Se=a.useMemo(()=>fe.filter(W=>W.category==="acp").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[fe]),Ae=a.useMemo(()=>{const W=new Map;for(const K of me){const re=K.conversation.daemonId||K.conversation.ideId,ce=W.get(re);ce?ce.push(K):W.set(re,[K])}return ge.map(K=>{const re=W.get(K.id)||[],ce=[...re].sort((G,Ce)=>Ce.timestamp-G.timestamp)[0]||null,I=(ce==null?void 0:ce.conversation)||null,q=Rs(K),ae=re.filter(G=>G.unread||G.requiresAction).length,V=K.status==="online"?"Connected":K.status||"Unknown",ke=[K.platform||"machine",V].filter(Boolean);return{id:K.id,label:nt(K,{fallbackId:K.id}),subtitle:ke.join(" · "),unread:ae,total:re.length,latestConversation:I,latestTimestamp:(ce==null?void 0:ce.timestamp)||0,fallbackActivityAt:q,preview:I?`${I.displayPrimary} · ${Un(I)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((K,re)=>{const ce=K.latestTimestamp||K.fallbackActivityAt||0,I=re.latestTimestamp||re.fallbackActivityAt||0;return I!==ce?I-ce:K.label.localeCompare(re.label)})},[me,ge]),Ze=a.useCallback(W=>{j(W.tabKey),L("chat"),te(W)},[te]),Oe=a.useCallback(W=>{const K=t.find(re=>re.ideId===W.ideId&&re.streamSource==="native");K&&(j(K.tabKey),L("chat"),te(K))},[t,te]),Ge=a.useCallback(()=>{te(z),L("inbox")},[te,z]),De=a.useCallback(W=>{A(W),M("idle"),_(""),H(null),U("machines"),B("inbox"),L("machine")},[]),Be=a.useCallback(W=>{var re;const K=W.daemonId||((re=W.ideId)==null?void 0:re.split(":")[0])||W.ideId;K&&(A(K),M("idle"),_(""),H(null),U("machines"),B("chat"),L("machine"))},[]),ne=a.useCallback(()=>{H(null),L(F)},[F]),je=a.useCallback(async(W,K,re)=>{var ce;try{M("loading"),_(`Launching ${K}…`);const I={ideType:K,enableCdp:!0};(ce=re==null?void 0:re.workspacePath)!=null&&ce.trim()&&(I.workspace=re.workspacePath.trim()),await i(W,"launch_ide",I),M("done"),_(`${K} launch requested`)}catch(I){M("error"),_(I instanceof Error?I.message:"Launch IDE failed"),console.error("Launch IDE failed",I)}},[i]),we=a.useCallback(async(W,K,re)=>{if(K.trim())try{M("loading"),_(re!=null&&re.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await i(W,"workspace_add",{path:K.trim(),createIfMissing:(re==null?void 0:re.createIfMissing)===!0});if(ce!=null&&ce.success){M("done"),_(re!=null&&re.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}M("error"),_((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){M("error"),_(ce instanceof Error?ce.message:"Could not save workspace")}},[i]),ye=a.useCallback(async W=>{var K,re,ce,I,q,ae;try{M("loading"),_("Starting daemon upgrade…");const V=await i(W,"daemon_upgrade",{});if((K=V==null?void 0:V.result)!=null&&K.alreadyLatest){M("done"),_(`Already on v${((re=V==null?void 0:V.result)==null?void 0:re.version)||"latest"}.`);return}if((ce=V==null?void 0:V.result)!=null&&ce.upgraded||(I=V==null?void 0:V.result)!=null&&I.success){M("done"),_(`Upgrade to v${((q=V==null?void 0:V.result)==null?void 0:q.version)||"latest"} started. Daemon is restarting…`);return}M("error"),_(((ae=V==null?void 0:V.result)==null?void 0:ae.error)||"Upgrade failed")}catch(V){M("error"),_(V instanceof Error?V.message:"Upgrade failed")}},[i]),ze=a.useCallback(async(W,K,re,ce)=>{var ae;const I=Date.now(),q={machineId:W,kind:K,providerType:re,workspaceId:(ce==null?void 0:ce.workspaceId)||null,workspacePath:(ce==null?void 0:ce.workspacePath)||null,resumeSessionId:(ce==null?void 0:ce.resumeSessionId)||null,startedAt:I};try{M("loading"),_(`Launching ${re}…`),H(q);const V={cliType:re};(ae=ce==null?void 0:ce.workspacePath)!=null&&ae.trim()?V.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(V.workspaceId=ce.workspaceId),ce!=null&&ce.resumeSessionId&&(V.resumeSessionId=ce.resumeSessionId);const ke=await i(W,"launch_cli",V),G=(ke==null?void 0:ke.result)||ke,Ce=(G==null?void 0:G.sessionId)||(G==null?void 0:G.id);if(ke!=null&&ke.success&&Ce){H(null),M("done"),_(`${re} launched`),le(`/dashboard?activeTab=${encodeURIComponent(Ce)}`);return}if(ke!=null&&ke.success){M("loading"),_(`${re} launch requested — waiting for session…`);return}H(null),M("error"),_((ke==null?void 0:ke.error)||(G==null?void 0:G.error)||`Could not launch ${K.toUpperCase()} workspace`)}catch(V){if(Nc(V)){M("loading"),_(`${re} launch requested — waiting for session…`);return}H(null),M("error"),_(V instanceof Error?V.message:`Could not launch ${K.toUpperCase()} workspace`)}},[le,i]);a.useEffect(()=>{var ce;if(!R)return;const W=Hn(R.workspacePath),K=n.find(I=>{var Ce,Ue,He,Pe;if(!I||I.type==="adhdev-daemon"||I.daemonMode||kc(I.daemonId||I.id)!==R.machineId||(I.transport==="acp"?"acp":I.transport==="pty"?"cli":null)!==R.kind||String(I.agentType||I.ideType||I.type||"")!==R.providerType)return!1;const ke=String(I.providerSessionId||"");if(R.resumeSessionId&&ke)return ke===R.resumeSessionId;if(W){const ot=Hn(I.workspace||I.runtimeWorkspaceLabel);return ot?ot===W:!1}return Number(I.lastUpdated||I._lastUpdate||I.timestamp||((Pe=(He=(Ue=(Ce=I.activeChat)==null?void 0:Ce.messages)==null?void 0:Ue.at)==null?void 0:He.call(Ue,-1))==null?void 0:Pe.timestamp)||0)>=R.startedAt-5e3});if(!K)return;const re=typeof K.sessionId=="string"&&K.sessionId?K.sessionId:typeof K.instanceId=="string"&&K.instanceId?K.instanceId:(ce=t.find(I=>I.ideId===K.id))==null?void 0:ce.sessionId;re&&(H(null),M("done"),_(`${R.providerType} launched`),le(`/dashboard?activeTab=${encodeURIComponent(re)}`))},[t,n,le,R]),a.useEffect(()=>{if(!R)return;const W=window.setTimeout(()=>{H(K=>!K||K.startedAt!==R.startedAt?K:(M("error"),_("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(W)},[R]);const Re=a.useCallback(async W=>{if(ee){if(W.kind==="ide"&&W.providerType){await je(ee.id,W.providerType,{workspacePath:W.workspace||null});return}if((W.kind==="cli"||W.kind==="acp")&&W.providerType){await ze(ee.id,W.kind,W.providerType,{workspacePath:W.workspace||null,resumeSessionId:W.providerSessionId||null});return}}},[je,ze,ee]);return e.jsx("div",{className:"dashboard-mobile-chat",children:D==="chat"&&z?e.jsx(hc,{selectedConversation:z,isAcp:Te(z),selectedIdeEntry:Y,actionLogs:r,userName:l,isSendingChat:pe.isSendingChat,isFocusingAgent:pe.isFocusingAgent,handleModalButton:pe.handleModalButton,handleRelaunch:pe.handleRelaunch,onBack:Ge,onOpenNativeConversation:Oe,onOpenMachine:Be,onHideConversation:T,onOpenHistory:m,onOpenRemote:N,onStopCli:g,cliViewMode:de,onSetCliViewMode:async W=>{if(z&&de!==W)try{await i(z.daemonId||z.ideId,"set_cli_view_mode",{targetSessionId:z.sessionId,cliType:z.ideType||z.agentType,mode:W})}catch(K){console.error("Failed to switch CLI view mode:",K)}},handleSendChat:pe.handleSendChat,handleFocusAgent:pe.handleFocusAgent}):D==="machine"&&ee?e.jsx(vc,{selectedMachineEntry:ee,selectedMachineConversations:S,selectedMachineRecentLaunches:Z,cliProviders:ve,acpProviders:Se,selectedMachineNeedsUpgrade:ie,appVersion:he,machineAction:{state:O,message:E},section:P,showBottomNav:F==="inbox",onBack:ne,onSectionChange:W=>{U(W),L("inbox")},onOpenConversation:Ze,onOpenRecent:Re,onOpenMachineDetails:()=>le(`/machines/${ee.id}`),onMachineUpgrade:()=>ye(ee.id),onLaunchDetectedIde:(W,K)=>je(ee.id,W,K),onAddWorkspace:(W,K)=>we(ee.id,W,K),onBrowseDirectory:async W=>{const K=await i(ee.id,"file_list_browse",{path:W});if(!(K!=null&&K.success))throw new Error((K==null?void 0:K.error)||"Could not browse folder");const re=typeof(K==null?void 0:K.path)=="string"?K.path:W,ce=re.includes("\\")?"\\":"/",I=(ae,V)=>/^[A-Za-z]:\\?$/.test(ae)?`${ae.replace(/\\?$/,"\\")}${V}`:ae==="/"||ae==="\\"?`${ce}${V}`:`${ae.replace(/[\\/]+$/,"")}${ce}${V}`,q=Array.isArray(K==null?void 0:K.files)?K.files.filter(ae=>(ae==null?void 0:ae.type)==="directory"&&typeof(ae==null?void 0:ae.name)=="string").map(ae=>({name:ae.name,path:I(re,ae.name)})).sort((ae,V)=>ae.name.localeCompare(V.name)):[];return{path:re,directories:q}},onLaunchWorkspaceProvider:(W,K,re)=>ze(ee.id,W,K,re)}):e.jsx(gc,{section:P,attentionItems:se,unreadItems:ue,workingItems:X,completedItems:J,hiddenConversations:s,machineCards:Ae,getAvatarText:jc,onOpenConversation:Ze,onShowConversation:C,onShowAllHidden:y,onOpenMachine:De,onOpenSettings:()=>le("/settings"),onSectionChange:U,wsStatus:w,isConnected:k,isStandalone:d})})}function Ms(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Cc({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,u]=a.useState(null),x=a.useCallback(()=>{c.current=0,l(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",x),window.addEventListener("drop",x),()=>{window.removeEventListener("dragend",x),window.removeEventListener("drop",x)}),[x]);const h=a.useCallback(N=>{N.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),p=a.useCallback(N=>{if(!N.dataTransfer.types.includes("text/tab-key"))return;if(N.preventDefault(),!Ms(s,n)){u("merge");return}const g=N.currentTarget.getBoundingClientRect(),w=N.clientX-g.left,k=g.width/3;w<k?u("split-left"):w>k*2?u("split-right"):u("merge")},[s,n]),b=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),m=a.useCallback(N=>{c.current=0,l(!1);const g=N.dataTransfer.getData("text/tab-key"),w=g?t.some(C=>C.tabKey===g):!1,k=f;if(u(null),o(),!!g){if(N.preventDefault(),k==="split-left"&&Ms(s,n)){n==null||n(g,"split-left");return}if(k==="split-right"&&Ms(s,n)){n==null||n(g,"split-right");return}if(w){i(g);return}r==null||r(g)}},[t,f,s,n,r,i,o]);return{dragOver:d,dropAction:f,resetDragState:x,handleDragEnter:h,handleDragOver:p,handleDragLeave:b,handleDrop:m}}function Ic(t,s){const n=new Set(s.map(o=>o.tabKey)),r=t.filter(o=>n.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...r,...i]}function Mc({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,u]=a.useState(null),x=a.useRef(null),h=a.useRef(null),p=a.useRef(r),b=a.useRef(i);a.useEffect(()=>{p.current=r},[r]),a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(v=>{const j=Ic(v,t);return j.length===v.length&&j.every((D,L)=>D===v[L])?v:j})},[t]);const m=a.useMemo(()=>{const v=f??d;if(v.length===0)return t;const j=new Map(v.map((D,L)=>[D,L]));return[...t].sort((D,L)=>{const P=j.get(D.tabKey)??999,U=j.get(L.tabKey)??999;return P-U})},[t,f,d]);a.useEffect(()=>{var j,D;if(m.length===0){o!==null&&(c(null),(j=p.current)==null||j.call(p,null));return}if(o&&m.some(L=>L.tabKey===o))return;const v=m[0].tabKey;v!==o&&(c(v),(D=p.current)==null||D.call(p,v))},[m,o]);const N=a.useMemo(()=>m.find(v=>v.tabKey===o),[m,o]),g=a.useCallback(v=>{var j;c(v),(j=p.current)==null||j.call(p,v)},[]),w=a.useCallback((v,j,D)=>{l(L=>{var A;const P=L.filter(F=>F!==v),U=P.indexOf(j);if(U<0)return L;const $=D==="left"?U:U+1;return P.splice($,0,v),(A=b.current)==null||A.call(b,P),P}),u(null)},[]),k=a.useCallback((v,j,D)=>{const P=(d.length>0?d:t.map(A=>A.tabKey)).filter(A=>A!==v),U=P.indexOf(j);if(U<0)return;const $=D==="left"?U:U+1;P.splice($,0,v),x.current=P,u(P)},[d,t]),C=a.useCallback(()=>{var j;const v=x.current;v&&(l(v),(j=b.current)==null||j.call(b,v))},[]),y=a.useCallback(()=>{x.current=null,u(null)},[]),T=a.useCallback(v=>{l(j=>{var L;const D=j.filter(P=>P!==v);return D.push(v),(L=b.current)==null||L.call(b,D),D})},[]);return{activeTabId:o,activeConv:N,sortedConversations:m,previewOrderRef:x,draggingTabRef:h,selectTab:g,handleTabReorder:w,updatePreviewOrder:k,commitPreviewOrder:C,clearPreviewOrder:y,moveTabToEnd:T,setDraggingTabKey:v=>{h.current=v}}}function _c({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 rn({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:i}){return t===0&&!s&&r&&i?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(Hr,{}),n&&r.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(o=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>i(o.type),children:[e.jsx(pr,{size:14,className:"opacity-70"})," Launch ",o.name]},o.type))})]}),!n&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}const qr="adhdev-tab-shortcuts";function Tc(){try{return JSON.parse(localStorage.getItem(qr)||"{}")}catch{return{}}}function Ac({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Tc()),[c,d]=a.useState(null),l=a.useCallback(u=>{const x=[];return u.metaKey&&x.push(r?"⌘":"Meta"),u.ctrlKey&&x.push("Ctrl"),u.altKey&&x.push(r?"⌥":"Alt"),u.shiftKey&&x.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(x.push(u.key.length===1?u.key.toUpperCase():u.key),x.join("+"))},[r]),f=a.useCallback(u=>{o(u);try{localStorage.setItem(qr,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=x=>{if(x.preventDefault(),x.stopPropagation(),x.key==="Escape"){d(null);return}const h=l(x);if(!h)return;const p={...i};for(const[b,m]of Object.entries(p))m===h&&delete p[b];p[c]=h,f(p),d(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,f,l]),a.useEffect(()=>{const u=x=>{if(!(!x.ctrlKey&&!x.metaKey&&!x.altKey)){for(const[h,p]of Object.entries(i))if(t.includes(h)&&l(x)===p){x.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const Lc=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:u,onPreviewReorder:x,onReorderTab:h,onCommitPreviewOrder:p,onClearPreviewOrder:b,onDragStateReset:m,onDragTabKeyChange:N,onReceiveTab:g,onOpenContextMenu:w,longPressTimer:k,isGroupActive:C}){const y=ms(s),T=y.isGenerating?"agent-tab-generating":y.isWaiting?"agent-tab-waiting":"",v=y.isReconnecting,j=a.useCallback(O=>{d.current=s.tabKey,N(s.tabKey),O.dataTransfer.setData("text/tab-key",s.tabKey),O.dataTransfer.effectAllowed="move"},[s.tabKey,d,N]),D=a.useCallback(()=>{d.current=null,N(null),p(),b(),m()},[d,N,p,b,m]),L=a.useCallback(O=>{const M=d.current;if(!(!M||M===s.tabKey)&&O.dataTransfer.types.includes("text/tab-key")){O.preventDefault(),O.stopPropagation();const E=O.currentTarget.getBoundingClientRect(),_=O.clientX<E.left+E.width/2?"left":"right";x(M,s.tabKey,_)}},[s.tabKey,d,x]),P=a.useCallback(O=>{O.preventDefault(),O.stopPropagation();const M=O.dataTransfer.getData("text/tab-key");if(M&&M!==s.tabKey){const E=O.currentTarget.getBoundingClientRect(),_=O.clientX<E.left+E.width/2?"left":"right";c.includes(M)?h(M,s.tabKey,_):g&&g(M)}b()},[s.tabKey,c,h,g,b]),U=a.useCallback(O=>{O.stopPropagation(),l(),f(s.tabKey),u(s)},[s,u,l,f]),$=a.useCallback(O=>{O.preventDefault(),w(O.clientX,O.clientY,s.tabKey)},[s.tabKey,w]),A=a.useCallback(O=>{const M=O.touches[0];k.current=setTimeout(()=>{w(M.clientX,M.clientY,s.tabKey)},600)},[s.tabKey,k,w]),F=a.useCallback(()=>{k.current&&clearTimeout(k.current)},[k]),B=["adhdev-dockview-tab",T,n&&"is-active",C&&"is-group-active",v&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:B,draggable:!0,onDragStart:j,onDragEnd:D,onDragOver:L,onDrop:P,onClick:U,onContextMenu:$,onTouchStart:A,onTouchEnd:F,onTouchMove:F,style:{cursor:"pointer",opacity:r?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:y.isGenerating?e.jsx("div",{className:"tab-spinner"}):y.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):v?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):y.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:v?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):y.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 Rc({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:b,onMoveTab:m,onReceiveTab:N,onHideTab:g,isGroupActive:w}){const[k,C]=a.useState(null),y=a.useRef(null),T=a.useRef(null),v=a.useMemo(()=>t.map(A=>A.tabKey),[t]);Bt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(k==null?void 0:k.tabKey)||null});const{isMac:j,tabShortcuts:D,shortcutListening:L,setShortcutListening:P,saveShortcuts:U}=Ac({sortedTabKeys:t.map(A=>A.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!k)return;const A=F=>{const B=document.querySelector("[data-pane-context-menu]");B&&B.contains(F.target)||C(null)};return window.addEventListener("mousedown",A,!0),()=>window.removeEventListener("mousedown",A,!0)},[k]),a.useEffect(()=>{const A=T.current;if(!A)return;const F=B=>{Math.abs(B.deltaY)>Math.abs(B.deltaX)&&(B.preventDefault(),A.scrollLeft+=B.deltaY)};return A.addEventListener("wheel",F,{passive:!1}),()=>A.removeEventListener("wheel",F)},[]);const $=a.useCallback((A,F,B)=>{C({x:A,y:F,tabKey:B})},[]);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:T,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(A=>e.jsx(Lc,{conv:A,isActive:s===A.tabKey,isDraggedTab:o.current===A.tabKey,isTaskCompleteUnread:i.has(A.tabKey),shortcut:D[A.tabKey],conversationKeys:v,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:x,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:b,onReceiveTab:N,onOpenContextMenu:$,longPressTimer:y,isGroupActive:w},A.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),k&&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:k.x,top:k.y},children:[m&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"left"),C(null)},children:"← Move to Left Group"}),m&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"right"),C(null)},children:"Move to Right Group →"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"split-left"),C(null)},children:"⇤ Split Left"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(k.tabKey,"split-right"),C(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:A=>{A.stopPropagation(),P(k.tabKey),C(null)},children:["⌨ ",D[k.tabKey]?`Change shortcut (${D[k.tabKey]})`:"Set shortcut"]}),D[k.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 A={...D};delete A[k.tabKey],U(A),C(null)},children:"✕ Remove shortcut"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{g(k.tabKey),C(null)},children:"🚫 Hide from Dashboard"})]}),!m&&!g&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),L&&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:()=>P(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:A=>A.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. ",j?"⌘+1":"Ctrl+1",", ",j?"⌥+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 Pc({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:u,isSplitMode:x,numGroups:h,onMoveTab:p,onReceiveTab:b,style:m,detectedIdes:N,handleLaunchIde:g,onActiveTabChange:w,initialActiveTabId:k,initialTabOrder:C,onTabOrderChange:y,onHideTab:T,isFocused:v}){const{sendCommand:j}=ut(),D=a.useRef(null),{activeTabId:L,activeConv:P,sortedConversations:U,draggingTabRef:$,selectTab:A,handleTabReorder:F,updatePreviewOrder:B,commitPreviewOrder:O,clearPreviewOrder:M,moveTabToEnd:E,setDraggingTabKey:_}=Mc({conversations:t,initialActiveTabId:k,initialTabOrder:C,onActiveTabChange:w,onTabOrderChange:y}),R=xs({sendDaemonCommand:i,activeConv:P,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:H,dropAction:oe,resetDragState:le,handleDragEnter:he,handleDragOver:z,handleDragLeave:Y,handleDrop:de}=Cc({conversations:t,numGroups:h,onMoveTab:p,onReceiveTab:b,onOwnTabDrop:E,onClearPreviewOrder:M}),ge=P&&!Te(P)&&Nt(P)==="terminal",ee=a.useMemo(()=>P?s.find(se=>se.id===P.ideId):void 0,[s,P]),xe=a.useMemo(()=>P?r.filter(se=>se.ideId===P.tabKey):[],[r,P]),pe=a.useMemo(()=>Kt(s),[s]),te=a.useMemo(()=>new Set(U.filter(se=>gi(se,pe,{isOpenConversation:se.tabKey===L})).map(se=>se.tabKey)),[L,pe,U]);Bt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:L,dragOver:H});const me=a.useCallback(se=>{se.streamSource==="agent-stream"&&se.agentType&&j(se.ideId,"focus_session",{agentType:se.agentType,...se.sessionId&&{targetSessionId:se.sessionId}}).catch(()=>{})},[j]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...m,outline:H?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Rc,{conversations:U,activeTabId:L,groupIndex:f,numGroups:h,unreadTabKeys:te,draggingTabRef:$,onFocus:u,onSelectTab:A,onConversationActivated:me,onPreviewReorder:B,onReorderTab:F,onCommitPreviewOrder:O,onClearPreviewOrder:M,onDragStateReset:le,onDragTabKeyChange:_,onMoveTab:p,onReceiveTab:b,onHideTab:T,isGroupActive:v??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:he,onDragOver:z,onDragLeave:Y,onDrop:de,children:[H&&e.jsx(_c,{dropAction:oe,canSplit:!!(h<4&&p)}),P?e.jsx(en,{activeConv:P,clearToken:n[P.tabKey]||0,isCliTerminal:!!ge,ideEntry:ee,terminalRef:D,handleModalButton:R.handleModalButton,handleRelaunch:R.handleRelaunch,handleSendChat:R.handleSendChat,isSendingChat:R.isSendingChat,handleFocusAgent:R.handleFocusAgent,isFocusingAgent:R.isFocusingAgent,actionLogs:xe,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(rn,{conversationsCount:t.length,isSplitMode:x,isStandalone:d,detectedIdes:N,handleLaunchIde:g})})]})]})}function $c({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,focusedGroup:p,setFocusedGroup:b,moveTabToGroup:m,splitTabRelative:N,closeGroup:g,handleResizeStart:w,detectedIdes:k,handleLaunchIde:C,groupActiveTabIds:y,setGroupActiveTabIds:T,groupTabOrders:v,setGroupTabOrders:j,toggleHiddenTab:D}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((L,P)=>{const U=s&&r.length===n?`${r[P]}%`:void 0;return e.jsxs(Os.Fragment,{children:[s&&P>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:$=>w(P-1,$),onDoubleClick:()=>g(P),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(Pc,{style:s?{flexBasis:U??`${100/n}%`,flexGrow:U?0:1,flexShrink:U?0:1}:void 0,conversations:L,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:x,userName:h,groupIndex:P,isFocused:s&&p===P,onFocus:()=>b(P),isSplitMode:s,numGroups:n,onMoveTab:($,A)=>{A==="left"&&P>0?m($,P-1):A==="right"&&P<n-1?m($,P+1):A==="split-left"&&n<4?N($,P,"left"):A==="split-right"&&n<4&&N($,P,"right")},onReceiveTab:$=>m($,P),detectedIdes:P===0?k:void 0,handleLaunchIde:P===0?C:void 0,onActiveTabChange:$=>T(A=>(A[P]??null)===($??null)?A:{...A,[P]:$}),initialActiveTabId:y[P],initialTabOrder:v[P],onTabOrderChange:$=>j(A=>{const F=A[P]||[];return F.length===$.length&&F.every((B,O)=>B===$[O])?A:{...A,[P]:$}}),onHideTab:D})]},P)})})}function Gr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?$e.onScreenshot("ide-page",(p,b)=>{if(p!==t)return;const m=new FileReader;m.onload=()=>d(m.result),m.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var p;return t?((p=$e.onStatus)==null?void 0:p.call($e,(b,m)=>{b===t&&m!=null&&m.screenshotUsage&&f(m.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,u]),a.useEffect(()=>{const h=t?$e.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&u?h.startScreenshots(u):h.stopScreenshots(u),()=>{h.stopScreenshots(u)}},[i,r,u,t]);const x=a.useCallback(async(h,p)=>{const b=t?$e.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(h,p,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:x}}const Yr=a.createContext(null);function fs(){const t=a.useContext(Yr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function es(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Ec(t){return`remote:${t}`}function ls(t){return t.startsWith("remote:")}function hs(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function Dc(t){const[,s]=a.useState(0);a.useEffect(()=>{const n=()=>s(i=>i+1),r=[t.api.onDidActiveGroupChange(n),t.api.onDidTitleChange(n),t.api.onDidGroupChange(n),t.containerApi.onDidActivePanelChange(n)];return()=>{for(const i of r)i.dispose()}},[t.api,t.containerApi])}function Bc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const u of l){const x=t.addPanel({id:u.tabKey,component:"conversation",title:es(u),params:{kind:"conversation",tabKey:u.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=x.id)}i=f??i}const o=n??((d=s[0])==null?void 0:d.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Fn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])ls(r.id)||n.has(r.id)||t.removePanel(r);for(const r of s){const i=t.getPanel(r.tabKey);if(i){i.update({params:{tabKey:r.tabKey}}),i.title!==es(r)&&i.api.setTitle(es(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:es(r),params:{kind:"conversation",tabKey:r.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Vn(t,s,n){var l,f;const r=n?Ec(n):null;for(const u of[...t.panels])ls(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=hs(s,n);if(!i&&t.totalPanels===0)return;const o=t.getPanel(r),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const d=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(u=>!ls(u.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...d?{position:{referencePanel:d,direction:"right"},inactive:!0}:{}})}function Kc({params:t}){const s=fs(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=xs({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(l=>l.id===r.ideId):void 0,[s.ides,r]),c=a.useMemo(()=>r?s.actionLogs.filter(l=>l.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(rn,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!Te(r)&&Nt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(en,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:d,ideEntry:o,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:c,userName:s.userName})})}function Wc({params:t}){var l;const s=fs(),n=a.useMemo(()=>hs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:d}=Gr({doId:i,ideId:t.ideId,ideType:(n==null?void 0:n.ideType)||(r==null?void 0:r.type),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote",instanceId:r==null?void 0:r.instanceId});return n?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(xr,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:d})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function Oc(){const t=fs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(rn,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function zc(t){var x,h;Dc(t);const s=fs();if(t.params.kind==="remote"){const p=hs([...s.conversationsByTabKey.values()],t.params.ideId),b=((x=t.api.group.activePanel)==null?void 0:x.id)===t.api.id,m=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${m?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:p!=null&&p.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:p.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const r=((h=t.api.group.activePanel)==null?void 0:h.id)===t.api.id,i=t.api.isGroupActive,o=Dt(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,u=o.unread;return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,children:[u&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:l?e.jsx("div",{className:"tab-spinner"}):f?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:c?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]})]})}function Uc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:u,toggleHiddenTab:x,onActiveTabChange:h,requestedActiveTabKey:p,requestedRemoteIdeId:b,onRequestedActiveTabConsumed:m}){const{theme:N}=Lr(),{sendCommand:g}=ut(),w=a.useRef(null),k=a.useRef(null),C=a.useRef(!1),[y,T]=a.useState(!1),[v,j]=a.useState(!1),D=a.useRef(null),L=a.useMemo(()=>Or(typeof window<"u"?window.innerWidth:1280),[]),P=a.useMemo(()=>new Map(t.map(R=>[R.tabKey,R])),[t]),U=a.useMemo(()=>Kt(n),[n]),$=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:P,detectedIdes:f,handleLaunchIde:u,ides:n,isStandalone:d,liveSessionInboxState:U,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:x,userName:l}),[r,s,P,f,u,n,d,U,i,c,o,x,l]),A=a.useCallback(R=>{if(!R)return!1;const H=w.current;if(!H)return!1;const oe=H.getPanel(R);return oe?(oe.group.model.openPanel(oe),m==null||m(),!0):!1},[m]),F=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const oe of H)oe.setAttribute("data-adhdev-force-hidden","true")},[]),B=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const oe of H)oe.removeAttribute("data-adhdev-force-hidden")},[]),O=a.useCallback(()=>{const R=k.current;if(!R)return;const H=R.querySelectorAll(".dv-drop-target-container");for(const he of H)he.remove();const oe=R.querySelectorAll(".dv-drop-target-dropzone");for(const he of oe)he.remove();const le=R.querySelectorAll(".dv-drop-target");for(const he of le)he.classList.remove("dv-drop-target")},[]),M=a.useCallback(()=>{T(!1),j(!1),B(),F(),O(),!(typeof window>"u")&&(D.current!=null&&window.clearTimeout(D.current),window.requestAnimationFrame(()=>{F(),O()}),D.current=window.setTimeout(()=>{F(),O(),D.current=null},80))},[B,F,O]),E=a.useCallback(R=>{var oe;w.current=R.api;const H=rc(L);H!=null&&H.layout&&R.api.fromJSON(H.layout,{reuseExistingPanels:!1}),Fn(R.api,t),Vn(R.api,t,b),R.api.totalPanels===0&&t.length>0?Bc(R.api,t,p):A(p)||A(H==null?void 0:H.activeTabId),C.current=!0,R.api.onDidActivePanelChange(le=>{var z;if(le&&ls(le.id)){const Y=((z=le.params)==null?void 0:z.ideId)||le.id.slice(7),de=hs(t,Y);h((de==null?void 0:de.tabKey)??null);return}if(h((le==null?void 0:le.id)??null),!le)return;const he=P.get(le.id);(he==null?void 0:he.streamSource)==="agent-stream"&&he.agentType&&g(he.ideId,"focus_session",{agentType:he.agentType,...he.sessionId&&{targetSessionId:he.sessionId}}).catch(()=>{})}),R.api.onDidLayoutChange(()=>{var le;ac(L,{activeTabId:((le=R.api.activePanel)==null?void 0:le.id)??null,layout:R.api.toJSON()})}),R.api.onWillDragPanel(()=>{T(!0),j(!1),F()}),R.api.onWillDragGroup(()=>{T(!0),j(!1),F()}),R.api.onWillShowOverlay(()=>{B(),j(!0)}),R.api.onDidMovePanel(M),R.api.onDidDrop(M),h(((oe=R.api.activePanel)==null?void 0:oe.id)??null)},[A,M,B,P,L,F,O,h,p,g,t]);a.useEffect(()=>{const R=w.current;!R||!C.current||(Fn(R,t),Vn(R,t,b),!R.activePanel&&R.panels[0]&&R.panels[0].group.model.openPanel(R.panels[0]))},[b,t]),a.useEffect(()=>{C.current&&A(p)},[A,p]),a.useEffect(()=>{if(!y||typeof window>"u")return;const R=()=>M();return window.addEventListener("pointerup",R),window.addEventListener("mouseup",R),window.addEventListener("dragend",R),()=>{window.removeEventListener("pointerup",R),window.removeEventListener("mouseup",R),window.removeEventListener("dragend",R)}},[M,y]),a.useEffect(()=>()=>{typeof window>"u"||D.current!=null&&window.clearTimeout(D.current)},[]),a.useEffect(()=>{const R=H=>{const oe=H.target;if(!oe)return;const le=oe.querySelector("[data-tab-key]")||oe.closest("[data-tab-key]");if(le){const he=le.getAttribute("data-tab-key");he&&H.dataTransfer&&H.dataTransfer.setData("text/tab-key",he)}};return window.addEventListener("dragstart",R),()=>window.removeEventListener("dragstart",R)},[]);const _=N==="light"?_a:Ta;return e.jsx(Yr.Provider,{value:$,children:e.jsx("div",{ref:k,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(Ma,{className:`h-full min-h-0 min-w-0 adhdev-dockview${y?" is-dragging-dockview":""}${v?" is-showing-dockview-overlay":""}`,components:{conversation:Kc,remote:Wc},defaultTabComponent:zc,watermarkComponent:Oc,onReady:E,singleTabMode:"default",tabAnimation:"smooth",theme:_})})})}function Hc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:u,mobileChatConversations:x,hiddenConversations:h,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,requestedMobileTabKey:C,onRequestedMobileTabConsumed:y,requestedMachineId:T,onRequestedMachineConsumed:v,requestedMobileSection:j,onRequestedMobileSectionConsumed:D,containerRef:L,isSplitMode:P,numGroups:U,groupSizes:$,groupedConvs:A,clearedTabs:F,focusedGroup:B,setFocusedGroup:O,moveTabToGroup:M,splitTabRelative:E,closeGroup:_,handleResizeStart:R,detectedIdes:H,handleLaunchIde:oe,groupActiveTabIds:le,setGroupActiveTabIds:he,groupTabOrders:z,setGroupTabOrders:Y,toggleHiddenTab:de,visibleConversations:ge,requestedDesktopTabKey:ee,onRequestedDesktopTabConsumed:xe,onDesktopActiveTabChange:pe,onHideConversation:te,onShowHiddenConversation:me,onShowAllHiddenConversations:se}){return Os.useEffect(()=>{const ue=X=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?X.metaKey&&X.key.toLowerCase()==="w":X.ctrlKey&&X.key.toLowerCase()==="w")&&(X.preventDefault(),n&&te&&te(n))};return window.addEventListener("keydown",ue),()=>window.removeEventListener("keydown",ue)},[n,te]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Vi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:ge,hiddenConversations:h,onOpenHistory:c,onOpenConversation:me,onHideConversation:te,onShowConversation:me,onShowAllHidden:se,onOpenRemote:()=>{!n||Ee(n)||Te(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:u}),t?e.jsx(Sc,{conversations:x,hiddenConversations:h,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,requestedActiveTabKey:C,onRequestedActiveTabConsumed:y,requestedMachineId:T,onRequestedMachineConsumed:v,requestedMobileSection:j,onRequestedMobileSectionConsumed:D,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:me,onShowAllHiddenConversations:se}):s?e.jsx($c,{containerRef:L,isSplitMode:P,numGroups:U,groupSizes:$,groupedConvs:A,clearedTabs:F,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,focusedGroup:B,setFocusedGroup:O,moveTabToGroup:M,splitTabRelative:E,closeGroup:_,handleResizeStart:R,detectedIdes:H,handleLaunchIde:oe,groupActiveTabIds:le,setGroupActiveTabIds:he,groupTabOrders:z,setGroupTabOrders:Y,toggleHiddenTab:de}):e.jsx(Uc,{visibleConversations:ge,clearedTabs:F,ides:p,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:N,setActionLogs:g,isStandalone:w,userName:k,detectedIdes:H,handleLaunchIde:oe,toggleHiddenTab:de,onActiveTabChange:pe,requestedActiveTabKey:ee,onRequestedActiveTabConsumed:xe})]})}const _s=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Fc({onClose:t}){const[s,n]=a.useState(0),r=_s[s],i=s===_s.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:_s.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
48
48
  @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
49
49
  @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
50
50
  `})]})}function Vc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:i}){return t?e.jsxs("div",{className:"flex border-b border-border-subtle bg-surface-primary shrink-0",children:[e.jsx("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] ${n==="native"?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i("native"),children:s}),r.map(o=>{const c=n===o.tabKey,d=o.status==="waiting_approval",l=o.status==="generating";return e.jsxs("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] flex items-center justify-center gap-1.5 ${c?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{className:"shrink-0",style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:d?"var(--status-warning)":l?"var(--accent-primary)":"var(--text-muted)",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&e.jsx("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-[10px] font-bold ml-0.5",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)"},children:"!"})]},o.tabKey)})]}):null}function qc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>Sr(s),[s]),f=a.useMemo(()=>{var N;if(!t)return[];const m=t.daemonId||((N=t.id)==null?void 0:N.split(":")[0])||t.id;return Cr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[m]||"new"})},[t,r,l,n]),u=a.useMemo(()=>f.find(m=>m.streamSource==="native"),[f]),x=a.useMemo(()=>f.filter(m=>m.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var m;c!=="native"&&(x.some(N=>N.tabKey===c)||d(((m=x[0])==null?void 0:m.tabKey)||"native"))},[c,x]),a.useEffect(()=>{c==="native"&&(u||x[0]&&d(x[0].tabKey))},[c,u,x]);const h=a.useMemo(()=>c==="native"&&u?u:x.find(m=>m.tabKey===c)||u||x[0],[c,u,x]),p=a.useMemo(()=>x.map(m=>({tabKey:m.tabKey,title:m.title||m.agentName||i,status:m.status})),[x,i]),b=a.useCallback(m=>{if(m)return f.find(N=>N.sessionId===m||N.ideId===m||N.tabKey===m||N.ideType===m||N.agentType===m)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:b}}function Gc({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:u,onOpenHistory:x,onConversationChange:h,onClose:p}){var F;const[b,m]=a.useState("split"),[N,g]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),w=a.useMemo(()=>s||n.find(B=>B.id===t.ideId),[t.ideId,s,n]),k=a.useMemo(()=>_e((w==null?void 0:w.type)||""),[w==null?void 0:w.type]),{conversations:C,extensionTabs:y,hasExtensions:T}=qc({ideData:w,allIdes:n,connectionStates:r,localUserMessages:o,ideName:k||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{g(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const v=a.useMemo(()=>N==="native"?C.find(B=>B.streamSource==="native")||t:C.find(B=>B.tabKey===N)||t,[t,C,N]),j=v.daemonId||((F=v.ideId)==null?void 0:F.split(":")[0])||v.ideId,D=xs({sendDaemonCommand:c,activeConv:v,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:L,screenshotUsage:P,handleRemoteAction:U}=Gr({doId:j,ideId:v.ideId,ideType:v.ideType,connState:v.connectionState||"new",viewMode:b,instanceId:w==null?void 0:w.instanceId}),$=a.useMemo(()=>i.filter(B=>B.ideId===v.tabKey),[i,v.tabKey]);a.useEffect(()=>{h==null||h(v)},[v,h]),a.useEffect(()=>{const B=O=>{O.key==="Escape"&&p()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[p]);const A=a.useCallback(B=>{B.stopPropagation()},[]);return e.jsx("div",{className:"fixed inset-0 z-[1200] flex items-center justify-center p-0 md:p-3 bg-[#030617]/[0.56] backdrop-blur-md",onClick:p,children:e.jsxs("div",{className:"w-full h-[100dvh] md:h-[calc(100vh-24px)] md:w-[calc(100vw-24px)] flex flex-col overflow-hidden md:rounded-[14px] md:border border-border-default bg-surface-primary shadow-[0_24px_80px_rgba(2,6,23,0.32)]",role:"dialog","aria-modal":"true",onClick:A,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(qe,{size:16})}),e.jsx("span",{className:"truncate",children:v.displayPrimary||v.agentName||"Remote"})]})}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold md:hidden shrink-0",onClick:p,children:"Close"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full md:w-auto justify-between md:justify-end",children:[e.jsx("div",{className:"flex items-center gap-2 mr-auto md:mr-0",children:["split","remote"].map(B=>{const O=b===B;return e.jsx("button",{className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${O?"bg-accent-primary/12 border border-accent-primary/35 text-accent-primary shadow-glow":"bg-bg-secondary border border-border-subtle text-text-secondary hover:bg-bg-glass hover:text-text-primary"}`,onClick:()=>m(B),title:B==="split"?"Split view":"Remote only",children:B==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(qe,{size:15})},B)})}),e.jsx("div",{className:"hidden md:block w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-2.5 md:px-3 rounded-lg",onClick:()=>x(v),title:"Chat History",children:[e.jsx(Hs,{size:14,className:"md:mr-1.5"}),e.jsx("span",{className:"hidden md:inline",children:"History"})]}),e.jsx("button",{className:"hidden md:inline-flex btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:p,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${b==="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:[b!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${b==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(Vc,{hasExtensions:T,ideName:k||"IDE",activeChatTab:N,extensionTabs:y,onSelectTab:g}),e.jsx(hr,{activeConv:v,onModalButton:D.handleModalButton}),e.jsx($s,{activeConv:v,ideEntry:w,showMetaChips:!1,handleSendChat:D.handleSendChat,isSendingChat:D.isSendingChat,handleFocusAgent:D.handleFocusAgent,isFocusingAgent:D.isFocusingAgent,actionLogs:$,userName:u})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${b==="split"?"order-1 md:order-2":""}`,children:e.jsx(xr,{addLog:()=>{},connState:v.connectionState||"new",connScreenshot:L,screenshotUsage:P,transportType:v.transport,onAction:U})})]})]})})}function Yc({activeConv:t,canSaveAndStop:s=!1,onCancel:n,onStopNow:r,onSaveAndStop:i}){const o=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1400] flex items-center justify-center p-4",children:[e.jsx("div",{onClick:n,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[min(92vw,420px)] md:w-[92%] md:max-w-[420px] flex flex-col overflow-hidden rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-base md:text-lg font-extrabold",children:["Stop ",o,"?"]}),e.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:s?"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first.":"The CLI runtime will stop immediately. This provider does not expose save-and-stop."})]}),e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s&&e.jsx("button",{onClick:i,className:"btn btn-primary w-full justify-center min-h-[42px]",children:"Save and stop"}),e.jsx("button",{onClick:r,className:"btn btn-secondary w-full justify-center min-h-[42px] text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:"Cancel"})]})]})]})}function Xc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:u,onRefreshHistory:x,onResumeSavedHistorySession:h,remoteDialogConv:p,remoteDialogIdeEntry:b,connectionStates:m,actionLogs:N,localUserMessages:g,sendDaemonCommand:w,setLocalUserMessages:k,setActionLogs:C,isStandalone:y,userName:T,onOpenRemoteHistory:v,onRemoteConversationChange:j,onCloseRemoteDialog:D,cliStopDialogOpen:L,cliStopTargetConv:P,onCancelCliStop:U,onStopCliNow:$,onSaveCliAndStop:A,toasts:F,onDismissToast:B,onClickToast:O,showOnboarding:M,onCloseOnboarding:E}){var _;return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Gi,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:u,onRefreshHistory:x,onResumeSavedSession:h}),p&&e.jsx(Gc,{activeConv:p,ideEntry:b,ides:n,connectionStates:m,actionLogs:N,localUserMessages:g,sendDaemonCommand:w,setLocalUserMessages:k,setActionLogs:C,isStandalone:y,userName:T,onOpenHistory:v,onConversationChange:j,onClose:D}),L&&P&&Ee(P)&&!Te(P)&&e.jsx(Yc,{activeConv:P,canSaveAndStop:!!((_=P.resume)!=null&&_.supported),onCancel:U,onStopNow:$,onSaveAndStop:A}),e.jsx(kr,{toasts:F,onDismiss:B,onClickToast:O}),M&&e.jsx(Fc,{onClose:E})]})}function Zc({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,onDismiss:i}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 border-b text-xs text-text-secondary shrink-0 flex-wrap",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",borderColor:"color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",style:{color:"var(--status-warning)"},children:e.jsx(Fs,{size:14})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available",s?e.jsxs(e.Fragment,{children:[": ",e.jsxs("strong",{children:["v",s]})]}):null]}),t.map(o=>{const c=nt(o,{fallbackId:o.id}),d=n[o.id],l=o.version||o.daemonVersion||"unknown";return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 15%, transparent)"},children:[e.jsx("span",{className:"font-medium text-text-primary",children:c}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",l]}),d==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):d==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):d==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(o.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold cursor-pointer px-1.5 py-px rounded transition-colors",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},onClick:()=>r(o.id),children:"Upgrade"})]},o.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:i,title:"Dismiss",children:"✕"})]})}function Jc(){var cn,ln,dn;const{sendCommand:t}=ut(),s=zs(),n=St(),[r,i]=Aa(),o=r.get("activeTab"),c=((cn=s.state)==null?void 0:cn.openRemoteForTabKey)||null,d=((ln=s.state)==null?void 0:ln.openMachineId)||null,l=((dn=s.state)==null?void 0:dn.mobileSection)||null,f=Ys(),u=f.ides||[],{updateIdeChats:x}=f,[h,p]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),b=f.toasts||[],m=f.setToasts||(()=>{}),N=f.wsStatus||"connected",g=f.isConnected??!0,w=f.connectionStates||{},k=f.showReconnected||!1,{groupAssignments:C,setGroupAssignments:y,focusedGroup:T,setFocusedGroup:v,groupActiveTabIds:j,setGroupActiveTabIds:D,groupTabOrders:L,setGroupTabOrders:P,groupSizes:U,setGroupSizes:$,isMobile:A,hasHydratedStoredLayout:F,hydrateStoredLayout:B}=oc(),[O,M]=a.useState(!1),[E,_]=a.useState(!1),[R,H]=a.useState(null),[oe,le]=a.useState([]),[he,z]=a.useState(!1),[Y,de]=a.useState(null),[ge]=a.useState(()=>Dr()),[ee,xe]=a.useState([]),[pe,te]=a.useState({}),[me,se]=a.useState({}),[ue,X]=a.useState(null),J=a.useRef(null);Bt("Dashboard",{ideCount:u.length,toastCount:b.length,focusedGroup:T,groupCount:Object.keys(C).length,localMessageTabs:Object.keys(pe).length,actionLogCount:ee.length});const S=u.find(be=>be.type==="adhdev-daemon"),Z=(S==null?void 0:S.detectedIdes)||[],Q=!!S,ie=(S==null?void 0:S.terminalBackend)||null,fe=S?nt(S,{fallbackId:S.id}):null,ve=(S==null?void 0:S.id)||null,{hiddenTabs:Se,hideTab:Ae,toggleTab:Ze,showTab:Oe,showAllTabs:Ge}=Fo(),{chatIdes:De,conversations:Be,visibleConversations:ne,visibleTabKeys:je,resolveConversationBySessionId:we,resolveConversationByTarget:ye}=Zo({ides:u,connectionStates:w,localUserMessages:pe,clearedTabs:me,hiddenTabs:Se}),ze=a.useMemo(()=>Kt(u),[u]),Re=a.useRef(null),{containerRef:W,normalizedGroupAssignments:K,numGroups:re,isSplitMode:ce,groupedConvs:I,moveTabToGroup:q,closeGroup:ae,handleResizeStart:V,splitTabRelative:ke}=xc({groupAssignments:C,setGroupAssignments:y,setFocusedGroup:v,setGroupActiveTabIds:D,setGroupTabOrders:P,groupSizes:U,setGroupSizes:$,isMobile:A,visibleConversations:ne,visibleTabKeys:je}),G=a.useMemo(()=>{var Me,Ie;if(!A){if(ue){const Ke=Be.find(Xe=>Xe.tabKey===ue);if(Ke)return Ke}return ne[0]}const be=j[T];if(be){const Ke=Be.find(Xe=>Xe.tabKey===be);if(Ke)return Ke}return((Me=I[T])==null?void 0:Me[0])||((Ie=I[0])==null?void 0:Ie[0])},[ue,A,j,T,Be,I,ne]);a.useEffect(()=>{if(A){Re.current=null;return}if(!(G!=null&&G.sessionId)){Re.current=null;return}const be=`${G.tabKey}:${G.sessionId}`;if(Re.current===be)return;Re.current=be;const Me=Et(G,ze),Ie=Math.max(Date.now(),jt(G),Me.lastUpdated||0);t(G.daemonId||G.ideId,"mark_session_seen",{sessionId:G.sessionId,seenAt:Ie}).catch(()=>{})},[G,A,ze,t]);const{requestedDesktopTabKey:Ce,requestedMobileTabKey:Ue,consumeRequestedActiveTab:He}=Jo({isMobile:A,urlActiveTab:o,resolveConversationBySessionId:we,setSearchParams:i}),{remoteDialogConv:Pe,remoteDialogIdeEntry:ot,remoteDialogActiveConv:Xr,setRemoteDialogActiveConv:bs,openRemoteDialog:Zr,closeRemoteDialog:Jr}=lc({isMobile:A,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Ce,conversations:Be,ides:u,resolveConversationByTarget:ye}),Le=Xr||Pe||G,tt=!!Le&&Ee(Le)&&!Te(Le),Wt=a.useMemo(()=>{if(!Le||!tt)return null;const be=Le.daemonId||Le.ideId||"",Me=Le.agentType||Le.ideType||"";return`${be}:${Me}`},[Le,tt]),Qr=a.useMemo(()=>ne,[ne]),Ot=A&&ge==="chat",ea=a.useMemo(()=>Be.filter(be=>Se.has(be.tabKey)),[Be,Se]);Vo({visibleConversations:ne,clearedTabs:me,setClearedTabs:se,setActionLogs:xe}),Qo({ides:u,sendDaemonCommand:t,setToasts:m,setLocalUserMessages:te,resolveConversationByTarget:ye});const{isRefreshingHistory:ta,handleLaunchIde:sa,handleRefreshHistory:na}=En({sendDaemonCommand:t,activeConv:G,updateIdeChats:x,setToasts:m,setLocalUserMessages:te,setClearedTabs:se}),{isCreatingChat:ra,isRefreshingHistory:aa,handleSwitchSession:ia,handleNewChat:oa,handleRefreshHistory:ca}=En({sendDaemonCommand:t,activeConv:Le,updateIdeChats:x,setToasts:m,setLocalUserMessages:te,setClearedTabs:se}),gs=a.useCallback(async()=>{if(!(!Le||!tt||he)){z(!0);try{const be=Le.daemonId||Le.ideId,Me=Le.agentType||Le.ideType,Ie=await t(be,"list_saved_sessions",{agentType:Me,providerType:Me,kind:"cli",limit:50}),Ke=(Ie==null?void 0:Ie.result)??Ie;le(Array.isArray(Ke==null?void 0:Ke.sessions)?Ke.sessions:[])}catch(be){console.error("Refresh saved sessions failed",be),le([])}finally{z(!1)}}},[Le,he,tt,t]);a.useEffect(()=>{if(!O){J.current=null;return}if(!tt){J.current=null,le([]),z(!1);return}!Wt||he||J.current!==Wt&&(J.current=Wt,gs())},[gs,O,he,tt,Wt]);const la=a.useCallback(async be=>{if(!Le||!tt||!be.providerSessionId||!be.workspace)return;const Me=Le.daemonId||Le.ideId,Ie=Le.agentType||Le.ideType;try{de(be.providerSessionId);const Ke=await t(Me,"launch_cli",{cliType:Ie,dir:be.workspace,resumeSessionId:be.providerSessionId,initialModel:be.currentModel}),Xe=(Ke==null?void 0:Ke.result)??Ke,zt=typeof(Xe==null?void 0:Xe.sessionId)=="string"?Xe.sessionId:typeof(Xe==null?void 0:Xe.id)=="string"?Xe.id:"";zt&&i(va=>{const un=new URLSearchParams(va);return un.set("activeTab",zt),un},{replace:!0}),M(!1)}catch(Ke){console.error("Resume saved session failed",Ke)}finally{de(null)}},[Le,tt,t,i]);cc({urlActiveTab:A&&!Ot?o:null,conversations:Be,resolveConversationBySessionId:we,normalizedGroupAssignments:K,hasHydratedStoredLayout:A&&!Ot?F:!0,hydrateStoredLayout:A&&!Ot?B:()=>{},setGroupActiveTabIds:D,setFocusedGroup:v,setSearchParams:i,historyModalOpen:O,activeConv:G,isRefreshingHistory:ta,ides:u,handleRefreshHistory:na});const ys=a.useCallback(async(be,Me)=>{const Ie=Me||R||G;if(!Ie||!Ee(Ie)||Te(Ie))return;const Ke=Ie.ideType||Ie.agentType||"",Xe=Ie.ideId||Ie.daemonId||"";try{await t(Xe,"stop_cli",{cliType:Ke,targetSessionId:Ie.sessionId,mode:be})}catch(zt){console.error("Stop CLI failed:",zt)}},[G,R,t]),da=a.useCallback(async be=>{const Me=be||G;!Me||!Ee(Me)||Te(Me)||(H(Me),_(!0))},[G,ys]),ua=a.useMemo(()=>!G||!Ee(G)||Te(G)?null:Nt(G),[G]),pa=a.useCallback(async be=>{if(!(!G||!Ee(G)||Te(G)||Nt(G)===be))try{await t(G.daemonId||G.ideId,"set_cli_view_mode",{targetSessionId:G.sessionId,cliType:G.ideType||G.agentType,mode:be})}catch(Ie){console.error("Failed to switch CLI view mode:",Ie)}},[G,t]),{versionMismatchDaemons:ma,appVersion:xa,versionBannerDismissed:fa,setVersionBannerDismissed:ha,upgradingDaemons:ba,handleBannerUpgrade:ga}=fc({ides:u,sendDaemonCommand:t}),an=a.useCallback(be=>{X(be.tabKey),i(Me=>{const Ie=new URLSearchParams(Me);return be.sessionId?Ie.set("activeTab",be.sessionId):Ie.delete("activeTab"),Ie},{replace:!0})},[i]),on=a.useCallback(be=>{Oe(be.tabKey),an(be)},[an,Oe]),ya=a.useCallback(be=>{Ae(be.tabKey)},[Ae]);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(Hi,{wsStatus:N,showReconnected:k}),e.jsx(Fi,{terminalBackend:ie,isStandalone:Q,machineLabel:fe,machineKey:ve}),!fa&&e.jsx(Zc,{daemons:ma,targetVersion:xa,upgradingDaemons:ba,onUpgrade:ga,onDismiss:()=>ha(!0)}),e.jsx(Hc,{showMobileChatMode:Ot,isMobile:A,activeConv:G,chatIdes:De,wsStatus:N,isConnected:g,onOpenHistory:be=>{be&&bs(be),M(!0)},onOpenRemote:Zr,onStopCli:da,activeCliViewMode:ua,onSetActiveCliViewMode:pa,mobileChatConversations:Qr,ides:u,actionLogs:ee,sendDaemonCommand:t,setLocalUserMessages:te,setActionLogs:xe,isStandalone:Q,userName:f.userName,requestedMobileTabKey:Ue,onRequestedMobileTabConsumed:He,requestedMachineId:d,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:l,onRequestedMobileSectionConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:W,isSplitMode:ce,numGroups:re,groupSizes:U,groupedConvs:I,clearedTabs:me,focusedGroup:T,setFocusedGroup:v,moveTabToGroup:q,splitTabRelative:ke,closeGroup:ae,handleResizeStart:V,detectedIdes:Z,handleLaunchIde:sa,groupActiveTabIds:j,setGroupActiveTabIds:D,groupTabOrders:L,setGroupTabOrders:P,toggleHiddenTab:Ze,visibleConversations:ne,hiddenConversations:ea,requestedDesktopTabKey:Ce,onRequestedDesktopTabConsumed:He,onDesktopActiveTabChange:X,onHideConversation:ya,onShowHiddenConversation:on,onShowAllHiddenConversations:Ge}),e.jsx("style",{children:`
@@ -58,4 +58,4 @@ This will disconnect CDP and optionally kill the process.`))try{const _=await n(
58
58
  from { opacity: 0; transform: translateX(40px); }
59
59
  to { opacity: 1; transform: translateX(0); }
60
60
  }
61
- `})]})}function pl(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],f=[],u=[];Object.values(c.providers||{}).forEach(h=>{const p={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(p):h.category==="cli"?l.push(p):h.category==="extension"?f.push(p):h.category==="acp"&&u.push(p)});const x=(h,p)=>{const b={Stable:1,Beta:2,WIP:3},m=b[h.status]||99,N=b[p.status]||99;return m!==N?m-N:h.name.localeCompare(p.name)};s({ide:d.sort(x),cli:l.sort(x),ext:f.sort(x),acp:u.sort(x)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(cr,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Vs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx(dr,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),widthClassName:"max-w-5xl",children:e.jsx(Zs,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Ve,{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(Ve,{title:"IDE support",icon:e.jsx(qe,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Ve,{title:"Standalone CLI agents",icon:e.jsx(qs,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Ve,{title:"AI extensions",icon:e.jsx(bt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Ve,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(bt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class ml{constructor(){We(this,"adapters",new Map);We(this,"states",new Map);We(this,"runtimeListeners",new Map);We(this,"screenshotCallbacks",new Map);We(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}emitSessionOutput(s,n,r){!s||typeof n!="string"||!n||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof r=="number"?{seq:r}:{},data:n})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(n),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const i=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const rt=new ml;function xl(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const Xn=xl(),Zn=3e3,fl=3e4;let at=null,hl=0;const ds=new Map;let mt=null,Rt=null;function Jn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function bl(t){return t==="connected"?"connected":t}async function ts(t,s,n){const r=to(t,n||{}),i=at;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++hl}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{ds.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);ds.set(o,{resolve:f=>{clearTimeout(l),c(f)},reject:f=>{clearTimeout(l),d(f)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class gl{constructor(s){We(this,"daemonId");We(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(at==null?void 0:at.readyState)===WebSocket.OPEN}get connectionState(){return(at==null?void 0:at.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return ts(this.daemonId,s,n)}async sendInput(s,n){return ts(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,mt&&(clearInterval(mt),mt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await ts(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());rt.emitScreenshot(this.daemonId,i)}}catch{}};n(),mt=setInterval(n,2e3)}stopScreenshots(s){mt&&(clearInterval(mt),mt=null)}}let Qe=null;function yl(t){return(!Qe||Qe.daemonId!==t)&&(Qe=new gl(t)),Qe}function vl({children:t}){const s=a.useRef(mn()),n=mn();s.current=n;const{setUserName:r}=Pt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,p)=>{o(h),Rt==null||Rt(h,p)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Zn),u=a.useRef(!0),x=a.useRef(!1);return a.useEffect(()=>{u.current=!0,x.current=!1;function h(){var m,N;if(!u.current||((m=d.current)==null?void 0:m.readyState)===WebSocket.OPEN||((N=d.current)==null?void 0:N.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Xn}...`);let b;try{b=new WebSocket(Xn)}catch(g){console.error("[Standalone WS] Failed to create WebSocket:",g),p();return}d.current=b,b.onopen=()=>{if(!u.current){b.close();return}c("connected"),f.current=Zn,console.log("[Standalone WS] Connected")},at=b,b.onmessage=g=>{var w;try{const k=JSON.parse(g.data);if((k.type==="command_result"||k.type==="error")&&k.requestId){const C=ds.get(k.requestId);C&&(ds.delete(k.requestId),k.type==="error"?C.reject(new Error(((w=k.data)==null?void 0:w.message)||"Command failed")):C.resolve(k.data));return}if(k.type==="session_output"){const C=k.sessionId||k.cliId||k.cliType;C&&rt.emitSessionOutput(C,typeof k.data=="string"?k.data:"",typeof k.seq=="number"?k.seq:void 0);return}if(k.type==="runtime_snapshot"){rt.emitRuntimeSnapshot(k.sessionId,typeof k.text=="string"?k.text:"",typeof k.seq=="number"?k.seq:0,!!k.truncated);return}if(k.type==="status"||k.type==="initial_state"){const C=k.data;if(!C)return;const{injectEntries:y,markLoaded:T}=s.current,v=C.id||"standalone",j=yl(v);rt.register(v,j),rt.setState(v,"connected"),c("connected",v),rt.emitStatus(v,C);const D=Qi(C,{daemonId:v});Jn("ws_status",{type:k.type,daemonId:v,sessions:(C.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:(C.recentLaunches||[]).map(L=>({id:L.id,providerType:L.providerType,kind:L.kind,workspace:L.workspace,lastLaunchedAt:L.lastLaunchedAt}))}),Jn("entries",{daemonId:v,entries:D.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}))}),D.length>0&&y(D,{authoritativeDaemonIds:[v]}),T(),C.userName&&i.current&&i.current(C.userName)}}catch(k){console.error("[Standalone WS] Parse error:",k)}},b.onclose=()=>{u.current&&(Qe==null||Qe.stopScreenshots(),Qe&&rt.setState(Qe.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},b.onerror=g=>{x.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",g)}}function p(){if(!u.current)return;clearTimeout(l.current);const b=f.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,fl),h()},b)}return h(),()=>{u.current=!1,x.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,at=null),Qe&&(Qe.stopScreenshots(),rt.unregister(Qe.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function wl({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(Rt=(c,d)=>{n(c),d&&i(d)},()=>{Rt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=bl(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(Ka,{connectionOverrides:o,children:e.jsx(vl,{children:t})})}const jl=[{id:"dashboard",path:"/dashboard",icon:e.jsx(ir,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ss,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(us,{}),label:"Settings"}];function kl({children:t}){const s=St(),n=zs(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const x=!u;try{localStorage.setItem("sidebar-collapsed",x?"1":"0")}catch{}return x})},f=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:jl.map(u=>e.jsxs("div",{className:f(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ns,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(or,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.8"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Nl=[{icon:e.jsx(ss,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(it,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(lr,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(qe,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(bt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(ns,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Sl=[{icon:e.jsx(pr,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(ir,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(ps,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(qa,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Fa,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(cr,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Cl=[{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 Il(){return e.jsxs(is,{icon:e.jsx(or,{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.8"]}),children:[e.jsx(Ve,{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(Ve,{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:Nl.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(Ve,{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:Ir.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:_r.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Mr.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(Ve,{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:Sl.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(Ve,{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:Cl.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(Zs,{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(ri,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Ml(){const{ides:t}=Pt(),s=t.find(x=>x.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=ut(),{userName:i}=Pt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=x=>{const h=x.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=x=>{f(x);try{localStorage.setItem("adhdev_sound",x?"1":"0")}catch{}};return e.jsxs(is,{icon:e.jsx(us,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(bo,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Ve,{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.8"]}),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(Ve,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(x=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${x.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:x.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:x.type})]},x.type))})}),e.jsx(Ve,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(No,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ve,{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(Mo,{})]}),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(Oo,{})]}),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(Uo,{})]})]})}),e.jsx(Ve,{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(ko,{}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ni,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(Ve,{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(Va,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:x=>c(x.target.value),onBlur:d,onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()}})]})})})]})}jo();Ko();$o();const _l=rr({baseUrl:""});function Qn(){const{ides:t,initialLoaded:s}=Pt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const n=t.find(r=>r.daemonMode||r.type==="adhdev-daemon");return n?e.jsx(As,{to:`/machines/${n.id}`,replace:!0}):e.jsx(As,{to:"/dashboard",replace:!0})}function Tl(){return e.jsx(Ra,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(za,{client:_l,children:e.jsx(wl,{children:e.jsx(Ha,{value:{sendCommand:ts,sendData:()=>!1},children:e.jsx(kl,{children:e.jsxs(Pa,{children:[e.jsx(ct,{path:"/dashboard",element:e.jsx(Jc,{})}),e.jsx(ct,{path:"/machine",element:e.jsx(Qn,{})}),e.jsx(ct,{path:"/machines/:id",element:e.jsx(ul,{})}),e.jsx(ct,{path:"/machines",element:e.jsx(Qn,{})}),e.jsx(ct,{path:"/capabilities",element:e.jsx(pl,{})}),e.jsx(ct,{path:"/about",element:e.jsx(Il,{})}),e.jsx(ct,{path:"/settings",element:e.jsx(Ml,{})}),e.jsx(ct,{path:"*",element:e.jsx(As,{to:"/dashboard",replace:!0})})]})})})})})})}zi({connectionManager:rt});$a(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Tl,{})}));
61
+ `})]})}function pl(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],f=[],u=[];Object.values(c.providers||{}).forEach(h=>{const p={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(p):h.category==="cli"?l.push(p):h.category==="extension"?f.push(p):h.category==="acp"&&u.push(p)});const x=(h,p)=>{const b={Stable:1,Beta:2,WIP:3},m=b[h.status]||99,N=b[p.status]||99;return m!==N?m-N:h.name.localeCompare(p.name)};s({ide:d.sort(x),cli:l.sort(x),ext:f.sort(x),acp:u.sort(x)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(cr,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Vs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx(dr,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),widthClassName:"max-w-5xl",children:e.jsx(Zs,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(is,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ns,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Ve,{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(Ve,{title:"IDE support",icon:e.jsx(qe,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Ve,{title:"Standalone CLI agents",icon:e.jsx(qs,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Ve,{title:"AI extensions",icon:e.jsx(bt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Ve,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(bt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class ml{constructor(){We(this,"adapters",new Map);We(this,"states",new Map);We(this,"runtimeListeners",new Map);We(this,"screenshotCallbacks",new Map);We(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}emitSessionOutput(s,n,r){!s||typeof n!="string"||!n||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof r=="number"?{seq:r}:{},data:n})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(n),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const i=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const rt=new ml;function xl(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const Xn=xl(),Zn=3e3,fl=3e4;let at=null,hl=0;const ds=new Map;let mt=null,Rt=null;function Jn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function bl(t){return t==="connected"?"connected":t}async function ts(t,s,n){const r=to(t,n||{}),i=at;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++hl}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{ds.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);ds.set(o,{resolve:f=>{clearTimeout(l),c(f)},reject:f=>{clearTimeout(l),d(f)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class gl{constructor(s){We(this,"daemonId");We(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(at==null?void 0:at.readyState)===WebSocket.OPEN}get connectionState(){return(at==null?void 0:at.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return ts(this.daemonId,s,n)}async sendInput(s,n){return ts(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,mt&&(clearInterval(mt),mt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await ts(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());rt.emitScreenshot(this.daemonId,i)}}catch{}};n(),mt=setInterval(n,2e3)}stopScreenshots(s){mt&&(clearInterval(mt),mt=null)}}let Qe=null;function yl(t){return(!Qe||Qe.daemonId!==t)&&(Qe=new gl(t)),Qe}function vl({children:t}){const s=a.useRef(mn()),n=mn();s.current=n;const{setUserName:r}=Pt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,p)=>{o(h),Rt==null||Rt(h,p)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Zn),u=a.useRef(!0),x=a.useRef(!1);return a.useEffect(()=>{u.current=!0,x.current=!1;function h(){var m,N;if(!u.current||((m=d.current)==null?void 0:m.readyState)===WebSocket.OPEN||((N=d.current)==null?void 0:N.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Xn}...`);let b;try{b=new WebSocket(Xn)}catch(g){console.error("[Standalone WS] Failed to create WebSocket:",g),p();return}d.current=b,b.onopen=()=>{if(!u.current){b.close();return}c("connected"),f.current=Zn,console.log("[Standalone WS] Connected")},at=b,b.onmessage=g=>{var w;try{const k=JSON.parse(g.data);if((k.type==="command_result"||k.type==="error")&&k.requestId){const C=ds.get(k.requestId);C&&(ds.delete(k.requestId),k.type==="error"?C.reject(new Error(((w=k.data)==null?void 0:w.message)||"Command failed")):C.resolve(k.data));return}if(k.type==="session_output"){const C=k.sessionId||k.cliId||k.cliType;C&&rt.emitSessionOutput(C,typeof k.data=="string"?k.data:"",typeof k.seq=="number"?k.seq:void 0);return}if(k.type==="runtime_snapshot"){rt.emitRuntimeSnapshot(k.sessionId,typeof k.text=="string"?k.text:"",typeof k.seq=="number"?k.seq:0,!!k.truncated);return}if(k.type==="status"||k.type==="initial_state"){const C=k.data;if(!C)return;const{injectEntries:y,markLoaded:T}=s.current,v=C.id||"standalone",j=yl(v);rt.register(v,j),rt.setState(v,"connected"),c("connected",v),rt.emitStatus(v,C);const D=Qi(C,{daemonId:v});Jn("ws_status",{type:k.type,daemonId:v,sessions:(C.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:(C.recentLaunches||[]).map(L=>({id:L.id,providerType:L.providerType,kind:L.kind,workspace:L.workspace,lastLaunchedAt:L.lastLaunchedAt}))}),Jn("entries",{daemonId:v,entries:D.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}))}),D.length>0&&y(D,{authoritativeDaemonIds:[v]}),T(),C.userName&&i.current&&i.current(C.userName)}}catch(k){console.error("[Standalone WS] Parse error:",k)}},b.onclose=()=>{u.current&&(Qe==null||Qe.stopScreenshots(),Qe&&rt.setState(Qe.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},b.onerror=g=>{x.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",g)}}function p(){if(!u.current)return;clearTimeout(l.current);const b=f.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,fl),h()},b)}return h(),()=>{u.current=!1,x.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,at=null),Qe&&(Qe.stopScreenshots(),rt.unregister(Qe.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function wl({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(Rt=(c,d)=>{n(c),d&&i(d)},()=>{Rt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=bl(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(Ka,{connectionOverrides:o,children:e.jsx(vl,{children:t})})}const jl=[{id:"dashboard",path:"/dashboard",icon:e.jsx(ir,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ss,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(us,{}),label:"Settings"}];function kl({children:t}){const s=St(),n=zs(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const x=!u;try{localStorage.setItem("sidebar-collapsed",x?"1":"0")}catch{}return x})},f=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:jl.map(u=>e.jsxs("div",{className:f(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ns,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(or,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.10"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Nl=[{icon:e.jsx(ss,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(it,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(lr,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(qe,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(bt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(ns,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Sl=[{icon:e.jsx(pr,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(ir,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(ps,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(qa,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Fa,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(cr,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Cl=[{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 Il(){return e.jsxs(is,{icon:e.jsx(or,{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.10"]}),children:[e.jsx(Ve,{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(Ve,{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:Nl.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(Ve,{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:Ir.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:_r.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Mr.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(Ve,{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:Sl.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(Ve,{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:Cl.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(Zs,{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(ri,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Ml(){const{ides:t}=Pt(),s=t.find(x=>x.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=ut(),{userName:i}=Pt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=x=>{const h=x.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=x=>{f(x);try{localStorage.setItem("adhdev_sound",x?"1":"0")}catch{}};return e.jsxs(is,{icon:e.jsx(us,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(bo,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Ve,{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.10"]}),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(Ve,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(x=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${x.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:x.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:x.type})]},x.type))})}),e.jsx(Ve,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(No,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ve,{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(Mo,{})]}),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(Oo,{})]}),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(Uo,{})]})]})}),e.jsx(Ve,{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(ko,{}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ni,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(Ve,{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(Va,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:x=>c(x.target.value),onBlur:d,onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()}})]})})})]})}jo();Ko();$o();const _l=rr({baseUrl:""});function Qn(){const{ides:t,initialLoaded:s}=Pt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const n=t.find(r=>r.daemonMode||r.type==="adhdev-daemon");return n?e.jsx(As,{to:`/machines/${n.id}`,replace:!0}):e.jsx(As,{to:"/dashboard",replace:!0})}function Tl(){return e.jsx(Ra,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(za,{client:_l,children:e.jsx(wl,{children:e.jsx(Ha,{value:{sendCommand:ts,sendData:()=>!1},children:e.jsx(kl,{children:e.jsxs(Pa,{children:[e.jsx(ct,{path:"/dashboard",element:e.jsx(Jc,{})}),e.jsx(ct,{path:"/machine",element:e.jsx(Qn,{})}),e.jsx(ct,{path:"/machines/:id",element:e.jsx(ul,{})}),e.jsx(ct,{path:"/machines",element:e.jsx(Qn,{})}),e.jsx(ct,{path:"/capabilities",element:e.jsx(pl,{})}),e.jsx(ct,{path:"/about",element:e.jsx(Il,{})}),e.jsx(ct,{path:"/settings",element:e.jsx(Ml,{})}),e.jsx(ct,{path:"*",element:e.jsx(As,{to:"/dashboard",replace:!0})})]})})})})})})}zi({connectionManager:rt});$a(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Tl,{})}));