@adhdev/daemon-standalone 0.8.44 → 0.8.45
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.
|
@@ -26,7 +26,7 @@ var Ci=Object.defineProperty;var Ii=(t,s,r)=>s in t?Ci(t,s,{enumerable:!0,config
|
|
|
26
26
|
100% { transform: translateY(0px); }
|
|
27
27
|
}
|
|
28
28
|
`})]})}function eo(t,s={}){if(!t)return"";const{suffix:r="",nowLabel:n="now",nowThreshold:o=60}=s,i=Date.now()-t,c=Math.floor(i/1e3);if(c<o)return n;const l=Math.floor(c/60);if(l<60)return`${l}m${r}`;const p=Math.floor(l/60);if(p<24)return`${p}h${r}`;const x=Math.floor(p/24);return x<7?`${x}d${r}`:new Date(t).toLocaleDateString()}const to=t=>eo(t);function Ac(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function xs(t){const s=t.connectionState==="failed"||t.connectionState==="closed",r=t.connectionState==="connecting"||t.connectionState==="new",n=t.status==="generating",o=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:r,isGenerating:n,isWaiting:o}}function Ds(t){const s=new Map,r=(n,o)=>{n&&s.set(n,{sessionId:n,...Ac(o)})};for(const n of t)if(n.type!=="adhdev-daemon"){r(n.sessionId,n);for(const o of n.childSessions||[])r(o.id,o)}return s}function _s(t,s){if(t.sessionId){const r=s.get(t.sessionId);if(r)return r}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function Ps(t,s,r){const n=_s(t,s),o=xs(t),i=o.isReconnecting,c=o.isConnecting,l=o.isGenerating,p=o.isWaiting,x=n.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||p,m=n.inboxBucket==="working"||l,h=n.inboxBucket==="task_complete"&&n.unread&&!(r!=null&&r.hideOpenTaskCompleteUnread&&(r!=null&&r.isOpenConversation));return{unread:h,requiresAction:x,isWorking:m,isReconnecting:i,isConnecting:c,isGenerating:l,isWaiting:p,inboxBucket:x?"needs_attention":m?"working":h?"task_complete":"idle"}}function Tc(t,s,r){return Ps(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:r==null?void 0:r.isOpenConversation}).unread}function _c(t,s,r){return _s(t,r||new Map).surfaceHidden}function so({activeConv:t,onModalButton:s}){const[r,n]=a.useState(null);if(a.useEffect(()=>{n(null)},[t.modalMessage,t.status,t.connectionState]),!xs(t).isWaiting||!t.modalButtons)return null;const i=l=>{r||(n(l),s(l))},c=l=>l.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(es,{size:14})," ",r?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((l,p)=>{const x=c(l).toLowerCase(),m=/^(run|approve|accept|yes|allow|always)/.test(x),h=/^(reject|deny|delete|remove|abort)/.test(x),g=r===l,S=r!==null;return e.jsx("button",{onClick:()=>i(l),disabled:S,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${m?"font-extrabold":h?"bg-red-500/30 text-white font-semibold":"text-white font-semibold"} ${S&&!g?"opacity-40":"opacity-100"} ${S?"cursor-not-allowed":"cursor-pointer"}`,style:m?{color:"var(--status-warning)",background:"var(--surface-primary)",boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--status-warning) 18%, transparent)"}:h?void 0:{background:"color-mix(in srgb, var(--surface-primary) 82%, transparent)",boxShadow:"inset 0 0 0 1px color-mix(in srgb, white 10%, transparent)"},children:g?"⏳ ...":c(l)},p)})})]})]})}const It=new Map;function Vn({routeId:t,sessionId:s,hostIdeType:r,providerType:n,displayLabel:o,serverModel:i,serverMode:c,acpConfigOptions:l,acpModes:p}){var je;const{sendCommand:x}=St(),m=!!(l||p),h=`${t}:${s||n}`,g=It.get(h),[S,I]=a.useState(!1),[u,b]=a.useState(!1),[y,d]=a.useState((g==null?void 0:g.models)||[]),[C,M]=a.useState((g==null?void 0:g.modes)||[]),N=Y=>Y?typeof Y=="string"?Y:typeof Y=="object"?Y.name||Y.id||JSON.stringify(Y):String(Y):"",[f,j]=a.useState(N(i)),[v,k]=a.useState(N(c)),[$,E]=a.useState(!1),[W,T]=a.useState(!1),V=a.useRef(0),R=Y=>Y.map(ne=>typeof ne=="string"?ne:(ne==null?void 0:ne.name)||(ne==null?void 0:ne.id)||String(ne));a.useEffect(()=>{if(l){const Y=l.find(ne=>ne.category==="model");if(Y){const ne=R(Y.options.map(pe=>pe.value));d(ne),Y.currentValue&&j(N(Y.currentValue));const _=It.get(h)||{models:[],modes:[]};It.set(h,{..._,models:ne})}}if(p&&p.length>0){const Y=R(p.map(_=>_.id));M(Y);const ne=It.get(h)||{models:[],modes:[]};It.set(h,{...ne,modes:Y})}else if(l){const Y=l.find(ne=>ne.category!=="model");if(Y){const ne=R(Y.options.map(pe=>pe.value));M(ne),Y.currentValue&&k(N(Y.currentValue));const _=It.get(h)||{models:[],modes:[]};It.set(h,{..._,modes:ne})}}},[l,p,h]),a.useEffect(()=>{I(!1),b(!1),j(N(i)),k(N(c));const Y=It.get(h);Y?(d(Y.models),M(Y.modes)):(d([]),M([]))},[t,n,s]),a.useEffect(()=>{i&&Date.now()>V.current&&j(N(i))},[i]),a.useEffect(()=>{c&&Date.now()>V.current&&k(N(c))},[c]);const w=a.useCallback(async(Y,ne={})=>{const _={...ne,...s&&{targetSessionId:s}};return await x(t,Y,_)},[t,s,x]),B=async()=>{var Y,ne;if(y.length>0){I(!S);return}if(m){I(!0);return}E(!0);try{const _=await w("list_extension_models",s?{}:{agentType:n,...r?{ideType:r}:{}}),pe=(_==null?void 0:_.models)||((Y=_==null?void 0:_.result)==null?void 0:Y.models)||[],me=R(pe);d(me),_!=null&&_.current&&j(N(_.current)),(ne=_==null?void 0:_.result)!=null&&ne.current&&j(N(_.result.current));const J=It.get(h)||{models:[],modes:[]};It.set(h,{...J,models:me}),I(!0)}catch{}finally{E(!1)}},ee=async()=>{var Y,ne;if(C.length>0){b(!u);return}if(m){b(!0);return}T(!0);try{const _=await w("list_extension_modes",s?{}:{agentType:n,...r?{ideType:r}:{}}),pe=(_==null?void 0:_.modes)||((Y=_==null?void 0:_.result)==null?void 0:Y.modes)||[],me=R(pe);M(me),_!=null&&_.current&&k(N(_.current)),(ne=_==null?void 0:_.result)!=null&&ne.current&&k(N(_.result.current));const J=It.get(h)||{models:[],modes:[]};It.set(h,{...J,modes:me}),b(!0)}catch{}finally{T(!1)}},L=async Y=>{I(!1);const ne=f;j(Y),V.current=Date.now()+5e3;try{const _=m?await w("change_model",{...s?{}:{agentType:n,...r?{ideType:r}:{}},model:Y}):await w("set_extension_model",{...s?{}:{agentType:n,...r?{ideType:r}:{}},model:Y});if((_==null?void 0:_.success)===!1)throw new Error((_==null?void 0:_.error)||"Could not change model")}catch(_){console.warn("Model change failed",_),j(ne),V.current=0}},D=m&&!(p&&p.length>0)&&(l==null?void 0:l.some(Y=>Y.category!=="model")),O=D?(je=l==null?void 0:l.find(Y=>Y.category!=="model"))==null?void 0:je.configId:void 0,z=async Y=>{b(!1);const ne=v;k(Y),V.current=Date.now()+5e3;try{let _;if(m&&D&&O?_=await w("set_thought_level",{...s?{}:{agentType:n,...r?{ideType:r}:{}},configId:O,value:Y}):m?_=await w("set_mode",{...s?{}:{agentType:n,...r?{ideType:r}:{}},mode:Y}):_=await w("set_extension_mode",{...s?{}:{agentType:n,...r?{ideType:r}:{}},mode:Y}),(_==null?void 0:_.success)===!1)throw new Error((_==null?void 0:_.error)||"Could not change mode")}catch(_){console.warn("Mode change failed",_),k(ne),V.current=0}},re={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa","claude-code-vscode":"#ea580c",codex:"#10b981",antigravity:"#f97316",windsurf:"#34d399"}[n]||"#94a3b8";return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:re},children:o}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:S?`${re}55`:"transparent",border:"1px solid",color:f?"var(--text-primary)":"var(--text-muted)"},onClick:B,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),$?"...":f||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),S&&y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:"SELECT MODEL"}),y.map(Y=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:Y===f?`${re}18`:"transparent",color:Y===f?re:"var(--text-secondary)",fontWeight:Y===f?600:400,borderLeft:Y===f?`2px solid ${re}`:"2px solid transparent"},onMouseEnter:ne=>{ne.currentTarget.style.background=`${re}12`},onMouseLeave:ne=>{ne.currentTarget.style.background=Y===f?`${re}18`:"transparent"},onClick:()=>L(Y),children:Y},Y))]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:u?`${re}55`:"transparent",border:"1px solid",color:v?"var(--text-primary)":"var(--text-muted)"},onClick:ee,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:D?"🧠":"⚡"}),W?"...":v||(D?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),u&&C.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>b(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:D?"SELECT THINKING LEVEL":"SELECT MODE"}),C.map(Y=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:Y===v?`${re}18`:"transparent",color:Y===v?re:"var(--text-secondary)",fontWeight:Y===v?600:400,borderLeft:Y===v?`2px solid ${re}`:"2px solid transparent"},onMouseEnter:ne=>{ne.currentTarget.style.background=`${re}12`},onMouseLeave:ne=>{ne.currentTarget.style.background=Y===v?`${re}18`:"transparent"},onClick:()=>z(Y),children:Y},Y))]})]})]})]})}const qn=new Map,Pc={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa","claude-code-vscode":"#ea580c",codex:"#10b981",antigravity:"#f97316",windsurf:"#34d399"};function Lc({routeId:t,sessionId:s,hostIdeType:r,providerType:n,displayLabel:o,controls:i,controlValues:c,serverModel:l,serverMode:p,acpConfigOptions:x,acpModes:m}){const{sendCommand:h}=St(),g=`${t}:${s||n}`,S=Pc[n]||"#94a3b8",[I,u]=a.useState({}),b=a.useRef(0),y={...l?{model:l}:{},...p?{mode:p}:{},...c||{},...Date.now()<b.current?I:{}};a.useEffect(()=>{c&&Date.now()>b.current&&u({})},[c]);const[d,C]=a.useState(qn.get(g)||{}),[M,N]=a.useState(null),[f,j]=a.useState(null),v=a.useCallback(async(w,B={})=>{const ee={...B,...s&&{targetSessionId:s}};return await h(t,w,ee)},[t,s,h]),k=a.useCallback(async(w,B={},ee)=>{const L=s?{targetSessionId:s}:{agentType:n,...r?{ideType:r}:{}};try{const D=await v("invoke_provider_script",{...L,scriptName:w,...B});return(D==null?void 0:D.success)===!1&&ee?await v(ee,{...L,...B}):D}catch(D){if(!ee)throw D;return await v(ee,{...L,...B})}},[v,n,r]);if(!i||i.length===0)return e.jsx(Vn,{routeId:t,sessionId:s,hostIdeType:r,providerType:n,displayLabel:o,serverModel:l,serverMode:p,acpConfigOptions:x,acpModes:m});const $=i.filter(w=>w.placement==="bar").sort((w,B)=>(w.order??50)-(B.order??50));if($.length===0)return e.jsx(Vn,{routeId:t,sessionId:s,hostIdeType:r,providerType:n,displayLabel:o,serverModel:l,serverMode:p,acpConfigOptions:x,acpModes:m});const E=async w=>{var ee,L,D;if(M===w.id){N(null);return}if((((ee=w.options)==null?void 0:ee.map(O=>O.value))||d[w.id]||[]).length>0){N(w.id);return}if(w.dynamic&&w.listScript){j(w.id);try{const O=Hs(w.listScript),z=await k(w.listScript,{},O),re=((z==null?void 0:z.models)||(z==null?void 0:z.modes)||((L=z==null?void 0:z.result)==null?void 0:L.models)||((D=z==null?void 0:z.result)==null?void 0:D.modes)||(z==null?void 0:z.options)||[]).map(je=>typeof je=="string"?je:(je==null?void 0:je.name)||(je==null?void 0:je.id)||(je==null?void 0:je.value)||String(je));C(je=>{const Y={...je,[w.id]:re};return qn.set(g,Y),Y}),N(w.id)}catch{}finally{j(null)}}},W=async(w,B)=>{N(null),u(ee=>({...ee,[w.id]:B})),b.current=Date.now()+5e3;try{if(!w.setScript)return;await k(w.setScript,{model:w.id==="model"?B:void 0,mode:w.id==="mode"?B:void 0,value:B},Hs(w.setScript))}catch{}},T=async w=>{var z;const B=((z=w.options)==null?void 0:z.map(Q=>Q.value))||d[w.id]||[];if(B.length===0)return;const ee=String(y[w.id]||""),D=(B.indexOf(ee)+1)%B.length,O=B[D];if(typeof O=="string"){u(Q=>({...Q,[w.id]:O})),b.current=Date.now()+5e3;try{if(!w.setScript)return;await k(w.setScript,{value:O},Hs(w.setScript))}catch{}}},V=async w=>{const ee=!y[w.id];u(L=>({...L,[w.id]:ee})),b.current=Date.now()+5e3;try{if(!w.setScript)return;await k(w.setScript,{value:ee},Hs(w.setScript))}catch{}},R=async w=>{if(w.invokeScript)try{await k(w.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:S},children:o}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),$.map(w=>{var O;const B=String(y[w.id]||""),ee=M===w.id,L=f===w.id,D=((O=w.options)==null?void 0:O.map(z=>z.value))||d[w.id]||[];switch(w.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:ee?`${S}55`:"transparent",border:"1px solid",color:B?"var(--text-primary)":"var(--text-muted)"},onClick:()=>E(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),L?"...":B||w.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),ee&&D.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>N(null)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:w.label.toUpperCase()}),D.map(z=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:z===B?`${S}18`:"transparent",color:z===B?S:"var(--text-secondary)",fontWeight:z===B?600:400,borderLeft:z===B?`2px solid ${S}`:"2px solid transparent"},onMouseEnter:Q=>{Q.currentTarget.style.background=`${S}12`},onMouseLeave:Q=>{Q.currentTarget.style.background=z===B?`${S}18`:"transparent"},onClick:()=>W(w,z),children:z},z))]})]})]},w.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:B?"var(--text-primary)":"var(--text-muted)"},onClick:()=>T(w),title:`Click to cycle: ${D.join(" → ")}`,children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),B||w.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},w.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:B?`${S}44`:"transparent",background:B?`${S}14`:"var(--surface-tertiary)",color:B?S:"var(--text-muted)"},onClick:()=>V(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),w.label]},w.id);case"action":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>R(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),w.resultDisplay==="inline"&&B?`${w.label}: ${B}`:w.label]},w.id);case"display":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:B?"var(--text-primary)":"var(--text-muted)"},children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),B?`${w.label}: ${B}`:w.label]},w.id);default:return null}})]})}function Hs(t){return{setModel:"set_extension_model",setMode:"set_extension_mode",listModels:"list_extension_models",listModes:"list_extension_modes",setThinkingLevel:"set_thought_level"}[t]}const Rc=a.memo(function({contextKey:s,panelLabel:r,isSending:n,onSend:o,isActive:i=!0}){const c=a.useRef(null),[l,p]=a.useState("");a.useEffect(()=>{p("")},[s]),a.useEffect(()=>{var m;i&&((m=c.current)==null||m.focus())},[s,i]);const x=()=>{const m=l.trim();!m||n||(p(""),o(m))};return e.jsx("div",{className:"dashboard-input-area bg-[var(--surface-primary)] shrink-0 overflow-hidden transition-all duration-200 ease-out",style:{borderTop:i?"1px solid var(--border-subtle)":"1px solid transparent",maxHeight:i?72:0,opacity:i?1:0,transform:i?"translateY(0)":"translateY(10px)",padding:i?"10px 12px":"0 12px",pointerEvents:i?"auto":"none"},"aria-hidden":!i,children:e.jsxs("div",{className:"flex gap-2.5 items-center",title:i?`Send message to ${r}`:void 0,children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${r}...`,value:l,onChange:m=>p(m.target.value),onPaste:m=>{const h=m.clipboardData.getData("text");h&&p(g=>g+h),m.preventDefault()},onKeyDown:m=>{if(m.key==="Enter"){if(m.nativeEvent.isComposing){m.preventDefault();return}m.preventDefault(),x()}},onBlur:m=>{if(window.innerWidth<768){const h=m.relatedTarget;if((h==null?void 0:h.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:x,disabled:!l.trim()||n,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!n?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.trim()&&!n?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:l.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var Ec=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Dc(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function bt(t,s){if(Dc(s==null?void 0:s.activeModal))return"waiting_approval";const r=String(t||"idle").trim().toLowerCase();return r==="waiting_approval"?"waiting_approval":Ec.has(r)?"generating":r==="error"?"error":r==="stopped"?"stopped":r==="starting"?"starting":r==="panel_hidden"?"panel_hidden":r==="not_monitored"?"not_monitored":r==="disconnected"?"disconnected":"idle"}function ro(t){return bt(t)==="generating"}function Ze(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function $c(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const r=Math.floor(s/60),n=s%60;if(r<24)return n>0?`${r}h ${n}m`:`${r}h`;const o=Math.floor(r/24),i=r%24;return`${o}d ${i}h`}function Mr(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function br(t,s){const r=typeof s=="string"?s.trim():"";if(r)return r;const n=typeof t=="string"?t.trim():"";if(!n)return"";const o=n.replace(/[\\/]+$/,""),i=o.split(/[\\/]/).filter(Boolean);return i[i.length-1]||o}function Bc(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),r=s[s.length-1];return r.length>12?`Machine-${r.substring(0,8)}`:r}return t}function Kc(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function Wc(t){return Bc(t.trim().replace(/\.local$/i,""))}function Oc(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function no(t,s={}){var o,i;const r=[t.hostname,(o=t.machine)==null?void 0:o.hostname,(i=t.system)==null?void 0:i.hostname].find(c=>typeof c=="string"&&c.trim().length>0&&!Kc(c));if(r&&r!=="Unknown")return Wc(r);const n=s.fallbackId||t.id;return n?`Machine-${n.substring(0,8)}`:s.fallbackLabel||"Machine"}function kt(t,s={}){return Oc(t)||no(t,s)}function Ls(t){return t.transport==="pty"}function ls(t){return t.transport==="acp"}function Gn(t,s){return Ze(t)}function Yn(t,s,r){const n=(t||"").trim().toLowerCase();if(!n)return!0;const o=(s||"").trim().toLowerCase(),i=(r||"").trim().toLowerCase(),c=Ze(r||"").trim().toLowerCase();return n===o||n===i||n===c}function Hc(t){return bt(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Uc(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,r=["generating","waiting_approval","connected","idle","panel_hidden"];for(const n of t){const o=(n.name||n.id||"").toLowerCase().replace(/\s+/g,"-"),i=s.get(o),c=bt(n.status);if(!i){s.set(o,{...n,status:c});continue}const l=r.indexOf(i.status||"idle"),p=r.indexOf(c||"idle");p>=0&&(l<0||p<l)&&s.set(o,{...n,status:c})}return Array.from(s.values())}function zc(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 Fc(t){var r,n;const s=(n=(r=t==null?void 0:t.messages)==null?void 0:r.at)==null?void 0:n.call(r,-1);return s&&zc(s.receivedAt)||0}function Vc(t){return(t.recentLaunches||[]).reduce((r,n)=>Math.max(r,n.lastLaunchedAt||0),0)}function Xr(t){return Math.max(Vc(t),Fc(t.activeChat))}function qc(t,s,r,n,o,i){const c=s-t;if(c!==0)return c;const l=r.localeCompare(n);return l!==0?l:o.localeCompare(i)}function mn(t,s){return qc(Xr(t),Xr(s),kt(t,{fallbackId:t.id}),kt(s,{fallbackId:s.id}),t.id,s.id)}const Ge=t=>t.transport==="pty",ps=(t,s)=>Ge(t)?t.mode||"terminal":"chat",ao=(t,s)=>Ge(t)&&ps(t)==="terminal",qe=t=>t.transport==="acp";function $t(t){return t.streamSource!=="agent-stream"}function Ut(t){var s;return t.daemonId||((s=t.routeId)==null?void 0:s.split(":")[0])||t.routeId||""}function oo(t){return t.machineName||""}function cr(t){return Ut(t)}function jt(t){return t.agentType||""}function fn(t){return t.hostIdeType||""}function gr(t){return t.displayPrimary||t.agentName||"Agent"}function xn(t){return[t.displaySecondary,oo(t)].filter(Boolean)}function $s(t){return t.agentName||Ze(jt(t))}function Gc(t){var s,r;if(!$t(t)){const n=(r=(s=t.displaySecondary)==null?void 0:s.split("·")[0])==null?void 0:r.trim();if(n)return n}return Ze(fn(t)||jt(t))}function hn(t){return $t(t)?t.sessionId:t.nativeSessionId}function Xn(t){return $t(t)?"native":t.tabKey}function Yc(t){return t.sessionId}function Xc(t,s){if(s)return $t(t)||!s.childSessions?s:s.childSessions.find(r=>r.id===t.sessionId||r.providerType===t.agentType)||s}function Jc(t,s){const r=jt(t),n=$t(t)?s!=null&&s.type?Ze(s.type):Ze(fn(t)||r):$s(t);return{isNativeConversation:$t(t),isCli:Ge(t),isAcp:qe(t),isCliTerminal:ao(t),providerType:r,displayLabel:n,targetEntry:Xc(t,s)}}function io({conversation:t,className:s="",onOpenNativeConversation:r,onOpenMachine:n,interactive:o=!0}){const i=ms(),c=Ut(t),l=oo(t),p=t.transport==="cdp-page"||t.transport==="cdp-webview",x=t.streamSource==="agent-stream"&&!!t.agentName,m=!x&&(t.transport==="pty"||t.transport==="acp"),h=$s(t),g=Gc(t),S=a.useCallback(()=>{if(n){n();return}c&&i("/dashboard",{state:{openMachineId:c}})},[c,i,n]),I=a.useCallback(()=>{if(r){r();return}const u=hn(t);u&&i(`/dashboard?activeTab=${encodeURIComponent(u)}`)},[t,i,r]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[p&&(o?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:I,title:g,children:[e.jsx(Nt,{size:12}),e.jsx("span",{children:g})]}):e.jsxs("span",{className:"conversation-meta-chip",title:g,children:[e.jsx(Nt,{size:12}),e.jsx("span",{children:g})]})),x&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:h,children:[e.jsx(Ts,{size:12}),e.jsx("span",{children:h})]}),m&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:h,children:[e.jsx(Ts,{size:12}),e.jsx("span",{children:h})]}),l&&(o?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:S,title:l,children:[e.jsx(Ht,{size:12}),e.jsx("span",{children:l})]}):e.jsxs("span",{className:"conversation-meta-chip",title:l,children:[e.jsx(Ht,{size:12}),e.jsx("span",{children:l})]}))]})}function Jn(t,s){return`${t}:${s}`}function Zc(){if(typeof window>"u")return!1;try{return window.localStorage.getItem("adhdev_mobile_debug")==="1"}catch{return!1}}function Us(t,s){Zc()&&console.debug(`[subscription-manager] ${t}`,s)}class Qc{constructor(){it(this,"active",new Map)}subscribe(s,r,n,o){var l;const i=Jn(n.topic,n.key),c=this.active.get(i);if(c)c.handlers.add(o),c.lastUpdate&&o(c.lastUpdate);else{const p={daemonId:r,request:n,handlers:new Set([o])};this.active.set(i,p),Us("subscribe",{daemonId:r,topic:n.topic,key:n.key}),(l=s.sendData)==null||l.call(s,r,n)}return()=>{var m;const p=this.active.get(i);if(!p||(p.handlers.delete(o),p.handlers.size>0))return;this.active.delete(i);const x={type:"unsubscribe",topic:n.topic,key:n.key};Us("unsubscribe",{daemonId:r,topic:n.topic,key:n.key}),(m=s.sendData)==null||m.call(s,r,x)}}publish(s){const r=Jn(s.topic,s.key),n=this.active.get(r);n&&(n.lastUpdate=s,n.handlers.forEach(o=>{o(s)}))}resubscribeAll(s){var r;Us("resubscribe_all",{count:this.active.size,subscriptions:Array.from(this.active.values()).map(n=>({daemonId:n.daemonId,topic:n.request.topic,key:n.request.key}))});for(const n of this.active.values())(r=s.sendData)==null||r.call(s,n.daemonId,n.request)}resubscribeForDaemon(s,r){var o;const n=Array.from(this.active.values()).filter(i=>i.daemonId===s);Us("resubscribe_daemon",{daemonId:s,count:n.length,subscriptions:n.map(i=>({topic:i.request.topic,key:i.request.key}))});for(const i of n)(o=r.sendData)==null||o.call(r,i.daemonId,i.request)}}const Ot=new Qc;function el(t,s){const r=new Map;for(const n of t||[])if((n.daemonId||n.id.includes(":")&&n.id.split(":")[0]||"")===s&&n.sessionId){r.set(n.sessionId,{parentSessionId:n.parentSessionId,providerSessionId:n.providerSessionId,workspace:n.workspace??null,sessionCapabilities:n.sessionCapabilities,cdpConnected:n.cdpConnected,currentModel:n.currentModel,currentPlan:n.currentPlan,currentAutoApprove:n.currentAutoApprove,controlValues:n.controlValues,providerControls:n.providerControls,acpConfigOptions:n.acpConfigOptions,acpModes:n.acpModes,runtimeWriteOwner:n.runtimeWriteOwner,runtimeAttachedClients:n.runtimeAttachedClients,cliName:n.cliName,type:n.type,status:n.status,lastMessagePreview:n.lastMessagePreview,lastMessageRole:n.lastMessageRole,lastMessageAt:n.lastMessageAt,lastMessageHash:n.lastMessageHash});for(const i of n.childSessions||[]){if(!(i!=null&&i.id))continue;const c=r.get(i.id)||{};r.set(i.id,{...c,...i})}}return r}function zs(t,s){return{...t,parentId:t.parentId??(s==null?void 0:s.parentSessionId)??null,providerName:t.providerName??(s==null?void 0:s.cliName)??(s==null?void 0:s.type)??t.providerType,workspace:t.workspace??(s==null?void 0:s.workspace)??null,capabilities:t.capabilities??(s==null?void 0:s.sessionCapabilities)??[],cdpConnected:t.cdpConnected??(s==null?void 0:s.cdpConnected),lastMessagePreview:t.lastMessagePreview??(s==null?void 0:s.lastMessagePreview),lastMessageRole:t.lastMessageRole??(s==null?void 0:s.lastMessageRole),lastMessageAt:t.lastMessageAt??(s==null?void 0:s.lastMessageAt),lastMessageHash:t.lastMessageHash??(s==null?void 0:s.lastMessageHash)}}function tl(t){const s=[],r=new Map;for(const n of t)if(n.parentId){const o=r.get(n.parentId)||[];o.push(n),r.set(n.parentId,o)}else s.push(n);return{topLevel:s,childrenByParent:r}}function lr(t,s){const r=[],{daemonId:n,existingDaemon:o,existingEntries:i,timestamp:c}=s,l=c||t.timestamp||Date.now(),p=t.sessions||[],{topLevel:x,childrenByParent:m}=tl(p),h=el(i,n),g=t.machine?{...(o==null?void 0:o.machine)||{},...t.machine}:o==null?void 0:o.machine,S=x.filter(b=>b.kind==="workspace"&&b.transport==="cdp-page"),I=x.filter(b=>b.kind==="agent"&&b.transport==="pty"),u=x.filter(b=>b.kind==="agent"&&b.transport==="acp");r.push({...o||{},id:n,type:"adhdev-daemon",status:"online",timestamp:l,...t.version&&{version:t.version},...g&&{machine:g,platform:g.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.terminalSizingMode!==void 0&&{terminalSizingMode:t.terminalSizingMode},...t.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:S.some(b=>!!b.cdpConnected)});for(const b of S){const y=h.get(b.id),d=zs(b,y),C=(m.get(b.id)||[]).map(M=>zs(M,h.get(M.id)));r.push({id:`${n}:ide:${b.id}`,sessionId:b.id,providerSessionId:b.providerSessionId??(y==null?void 0:y.providerSessionId),parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,status:d.cdpConnected?"online":"detected",daemonId:n,instanceId:b.id,workspace:d.workspace,terminals:0,childSessions:C,agents:C.map(M=>({id:M.id,name:M.providerName||M.providerType,type:M.providerType,status:M.status})),activeChat:d.activeChat,chats:[],cdpConnected:d.cdpConnected,...d.currentModel!==void 0&&{currentModel:d.currentModel},...d.currentPlan!==void 0&&{currentPlan:d.currentPlan},...d.currentAutoApprove!==void 0&&{currentAutoApprove:d.currentAutoApprove},...d.lastMessagePreview!==void 0&&{lastMessagePreview:d.lastMessagePreview},...d.lastMessageRole!==void 0&&{lastMessageRole:d.lastMessageRole},...d.lastMessageAt!==void 0&&{lastMessageAt:d.lastMessageAt},...d.lastMessageHash!==void 0&&{lastMessageHash:d.lastMessageHash},lastUpdated:d.lastUpdated,unread:d.unread,lastSeenAt:d.lastSeenAt,inboxBucket:d.inboxBucket,surfaceHidden:d.surfaceHidden,...d.controlValues!==void 0&&{controlValues:d.controlValues},...d.providerControls!==void 0&&{providerControls:d.providerControls},timestamp:l})}for(const b of I){const y=h.get(b.id),d=zs(b,y);r.push({id:`${n}:cli:${b.id}`,sessionId:b.id,providerSessionId:b.providerSessionId??(y==null?void 0:y.providerSessionId),parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,agentType:d.providerType,status:d.status||"running",daemonId:n,instanceId:b.id,cliName:d.providerName||d.providerType,mode:d.mode||(y==null?void 0:y.mode)||"terminal",workspace:d.workspace||"",activeChat:d.activeChat,...d.resume!==void 0&&{resume:d.resume},...d.runtimeKey!==void 0&&{runtimeKey:d.runtimeKey},...d.runtimeDisplayName!==void 0&&{runtimeDisplayName:d.runtimeDisplayName},...d.runtimeWorkspaceLabel!==void 0&&{runtimeWorkspaceLabel:d.runtimeWorkspaceLabel},...d.runtimeWriteOwner!==void 0&&{runtimeWriteOwner:d.runtimeWriteOwner},...d.runtimeAttachedClients!==void 0&&{runtimeAttachedClients:d.runtimeAttachedClients},...d.lastMessagePreview!==void 0&&{lastMessagePreview:d.lastMessagePreview},...d.lastMessageRole!==void 0&&{lastMessageRole:d.lastMessageRole},...d.lastMessageAt!==void 0&&{lastMessageAt:d.lastMessageAt},...d.lastMessageHash!==void 0&&{lastMessageHash:d.lastMessageHash},lastUpdated:d.lastUpdated,unread:d.unread,lastSeenAt:d.lastSeenAt,inboxBucket:d.inboxBucket,surfaceHidden:d.surfaceHidden,...d.controlValues!==void 0&&{controlValues:d.controlValues},...d.providerControls!==void 0&&{providerControls:d.providerControls},timestamp:l,_isCli:!0})}for(const b of u){const y=h.get(b.id),d=zs(b,y);r.push({id:`${n}:acp:${b.id}`,sessionId:b.id,providerSessionId:b.providerSessionId??(y==null?void 0:y.providerSessionId),parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,agentType:d.providerType,status:d.status||"running",daemonId:n,instanceId:b.id,cliName:d.providerName||d.providerType,mode:"chat",workspace:d.workspace||"",activeChat:d.activeChat,...d.runtimeKey!==void 0&&{runtimeKey:d.runtimeKey},...d.runtimeDisplayName!==void 0&&{runtimeDisplayName:d.runtimeDisplayName},...d.runtimeWorkspaceLabel!==void 0&&{runtimeWorkspaceLabel:d.runtimeWorkspaceLabel},...d.runtimeWriteOwner!==void 0&&{runtimeWriteOwner:d.runtimeWriteOwner},...d.runtimeAttachedClients!==void 0&&{runtimeAttachedClients:d.runtimeAttachedClients},...d.currentModel!==void 0&&{currentModel:d.currentModel},...d.currentPlan!==void 0&&{currentPlan:d.currentPlan},...d.lastMessagePreview!==void 0&&{lastMessagePreview:d.lastMessagePreview},...d.lastMessageRole!==void 0&&{lastMessageRole:d.lastMessageRole},...d.lastMessageAt!==void 0&&{lastMessageAt:d.lastMessageAt},...d.lastMessageHash!==void 0&&{lastMessageHash:d.lastMessageHash},lastUpdated:d.lastUpdated,unread:d.unread,lastSeenAt:d.lastSeenAt,inboxBucket:d.inboxBucket,surfaceHidden:d.surfaceHidden,...d.acpConfigOptions!==void 0&&{acpConfigOptions:d.acpConfigOptions},...d.acpModes!==void 0&&{acpModes:d.acpModes},...d.controlValues!==void 0&&{controlValues:d.controlValues},...d.providerControls!==void 0&&{providerControls:d.providerControls},timestamp:l,_isAcp:!0})}return r}const Ar=new Map,Tr=new Map,_r=new Set,ks=new Map,sl=1200;function rl(t){if(!t||typeof t!="object")return null;const s=t,r=s.status;if(r&&typeof r=="object")return r;const n=s.result;if(n&&typeof n=="object"&&"status"in n){const o=n.status;if(o&&typeof o=="object")return o}return s}function Zn(t,s){const r=ks.get(t);!r||r.size===0||(ks.delete(t),r.forEach(n=>n(s)))}function nl(t,s){return new Promise(r=>{const n=ks.get(t)||new Set;ks.set(t,n);const o=c=>{clearTimeout(i),n.delete(o),n.size===0&&ks.delete(t),r(c)},i=setTimeout(()=>o(!1),s);n.add(o)})}function Bs(){const{sendCommand:t,sendData:s}=St(),{injectEntries:r,getIdes:n}=ir();return a.useCallback(async(o,i)=>{if(!o)return;const c=(i==null?void 0:i.minFreshMs)??6e4,l=Tr.get(o)||0;if(!(i!=null&&i.force)&&_r.has(o)&&l>0||!(i!=null&&i.force)&&l>0&&Date.now()-l<c)return;const p=Ar.get(o);if(p)return p;const x=(async()=>{if(s&&!_r.has(o)&&(_r.add(o),Ot.subscribe({sendData:s},o,{type:"subscribe",topic:"daemon.metadata",key:`daemon:metadata:${o}`,params:{includeSessions:!0}},u=>{const b=n(),y=b.find(C=>C.id===o),d=lr(u.status,{daemonId:o,existingDaemon:y,existingEntries:b,timestamp:u.timestamp});d.length>0&&r(d),Tr.set(o,Date.now()),Zn(o,!0)}),!(i!=null&&i.force)&&await nl(o,sl)))return;const m=await t(o,"get_status_metadata"),h=rl(m);if(!h)return;const g=n(),S=g.find(u=>u.id===o),I=lr(h,{daemonId:o,existingDaemon:S,existingEntries:g,timestamp:h.timestamp||Date.now()});I.length>0&&r(I,{authoritativeDaemonIds:[o]}),Tr.set(o,Date.now()),Zn(o,!0)})().finally(()=>{Ar.delete(o)});return Ar.set(o,x),x},[n,r,t,s])}function ss(t){const s=Number((t==null?void 0:t.receivedAt)||(t==null?void 0:t.timestamp)||0);return Number.isFinite(s)?s:0}function co(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const r=String(t.role||"").toLowerCase(),n=String(s.role||"").toLowerCase();if(r!==n)return!1;const o=ts(t.content),i=ts(s.content);if(!o||o!==i)return!1;const c=ss(t),l=ss(s);return c&&l?Math.abs(c-l)<=15e3:!!t._localId!=!!s._localId}function Qn(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),ss(t)&&(s+=1),s}function al(t,s){const r=Qn(t),n=Qn(s);return n!==r?n>r?s:t:ts(s.content).length>=ts(t.content).length?s:t}function Ns(t){const s=[];for(const r of t){const n=s.findIndex(o=>co(o,r));if(n>=0){s.splice(n,1,al(s[n],r));continue}s.push(r)}return s}function ea(t){return[...t].sort((s,r)=>{const n=ss(s),o=ss(r);return n&&o&&n!==o?n-o:0})}function ta(t){return`${String((t==null?void 0:t.role)||"").toLowerCase()}:${ts(t==null?void 0:t.content).slice(0,100)}`}function sa(t,s){const r=t.filter(n=>String((n==null?void 0:n.role)||"").toLowerCase()==="user").slice();return s.filter(n=>{const o=r.findIndex(i=>co(i,n));return o>=0?(r.splice(o,1),!1):!0})}function ol(t,s){const r=new Set(s.map(n=>ta(n)));return t.filter(n=>!r.has(ta(n)))}function il(t){return!t||typeof t!="object"?{}:"result"in t&&t.result&&typeof t.result=="object"?t.result:t}function cl(t){let s=2166136261;for(const r of t){const n=String(r||"");for(let o=0;o<n.length;o+=1)s^=n.charCodeAt(o),s=Math.imul(s,16777619)>>>0;s^=255,s=Math.imul(s,16777619)>>>0}return s.toString(16).padStart(8,"0")}function ra(t,s){const r=t[t.length-1];if(!r)return"empty:";let n="";try{n=JSON.stringify(r.content??"")}catch{n=String(r.content??"")}return["",t.length,String(r.id||""),String(r.index??""),String(r.receivedAt??r.timestamp??""),n].join("|")}function lo(t){if(!t)return"";let s="";try{s=JSON.stringify(t.content??"")}catch{s=String(t.content??"")}return cl([String(t.id||""),String(t.index??""),String(t.role||""),String(t.receivedAt??t.timestamp??""),s])}function ll(t){return{knownMessageCount:t.length,lastMessageSignature:lo(t[t.length-1])}}function dl(t,s){const r=Array.isArray(s.messages)?s.messages:[];switch(s.syncMode){case"noop":return t;case"append":return Ns([...t,...r]);case"replace_tail":{const n=Math.max(0,Math.min(Number(s.replaceFrom??t.length),t.length));return Ns([...t.slice(0,n),...r])}case"full":default:return r}}const ul=60,na=60;function Jr({activeConv:t,ideEntry:s,handleSendChat:r,isSendingChat:n=!1,handleFocusAgent:o,isFocusingAgent:i,actionLogs:c,userName:l,showMetaChips:p=!1,scrollToBottomRequestNonce:x,isInputActive:m=!0}){var ne,_,pe,me;const h=a.useRef(new Map),g=a.useRef(new Map),S=a.useRef(new Map),{sendCommand:I,sendData:u}=St(),b=Bs();Es("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:n});const y=nt.useMemo(()=>xs(t),[t.status,t.connectionState]),d=a.useRef(new Map),C=a.useCallback(J=>(d.current.has(J)||d.current.set(J,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:ul}),d.current.get(J)),[]),M=a.useCallback((J,ie)=>{const se=C(J);d.current.set(J,{...se,...ie}),N(he=>he+1)},[C]),[,N]=a.useState(0),f=t.tabKey,j=C(f),v=j.messages,k=j.hasMore,$=j.error,E=g.current.get(f),W=t.messages.filter(J=>!!(J!=null&&J._localId)),T=E?Ns([...E,...W]):t.messages,V=Math.max(0,T.length-j.visibleLiveCount),R=gr(t),w=cr(t),B=t.sessionId||"",ee=t.providerSessionId||B,L=a.useMemo(()=>Jc(t,s),[t,s]),[D,O]=a.useState(!1);a.useEffect(()=>{const J=L.targetEntry;w&&(!J||J.providerControls===void 0||J.controlValues===void 0||L.isAcp&&(J.acpConfigOptions===void 0||J.acpModes===void 0))&&b(w,{minFreshMs:3e4}).catch(()=>{})},[w,L.isAcp,(ne=L.targetEntry)==null?void 0:ne.providerControls,(_=L.targetEntry)==null?void 0:_.controlValues,(pe=L.targetEntry)==null?void 0:pe.acpConfigOptions,(me=L.targetEntry)==null?void 0:me.acpModes,b]),a.useEffect(()=>{if(!w||!B||!u)return;const J=g.current.get(f)||[],ie=S.current.get(f),se=ie&&ie.knownMessageCount?ie:ll(J),he=`daemon:${w}:session:${B}`;return Ot.subscribe({sendData:u},w,{type:"subscribe",topic:"session.chat_tail",key:he,params:{targetSessionId:B,historySessionId:ee,knownMessageCount:se.knownMessageCount,lastMessageSignature:se.lastMessageSignature,...se.knownMessageCount?{}:{tailLimit:na}}},be=>{const Z=g.current.get(f)||[],oe=dl(Z,be),ae=Math.max(oe.length,Number(be.totalMessages||0));S.current.set(f,{knownMessageCount:ae,lastMessageSignature:typeof be.lastMessageSignature=="string"?be.lastMessageSignature:lo(oe[oe.length-1])}),ra(Z)!==ra(oe)&&(g.current.set(f,oe),N(we=>we+1))})},[w,ee,u,B,f]);const z=a.useCallback(async()=>{if(D)return;const J=t.tabKey,ie=C(J);if(T.length>ie.visibleLiveCount){M(J,{visibleLiveCount:Math.min(T.length,ie.visibleLiveCount+na),error:null});return}O(!0),M(J,{error:null});try{const se=cr(t);if(!se){M(J,{hasMore:!1});return}const he=jt(t),ce=await I(se,"chat_history",{agentType:he,offset:ie.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),be=il(ce),Z=be.messages||[];if(Z.length>0){const oe=C(J);M(J,{messages:[...Z,...oe.messages],offset:oe.offset+Z.length,hasMore:!!be.hasMore})}else M(J,{hasMore:!!be.hasMore})}catch(se){const he=(se==null?void 0:se.message)||"";he.includes("P2P not available")||he.includes("channel not open")||he.includes("P2P not connected")||he.includes("timeout")?M(J,{error:"Connection not ready — tap to retry"}):M(J,{hasMore:!1,error:"Failed to load history"})}finally{O(!1)}},[D,t,T.length,I,C,M]),{allMessages:Q,receivedAtMap:re}=a.useMemo(()=>{const J=V>0?T.slice(-j.visibleLiveCount):T;if(v.length===0){const ce=ea(Ns(J)),be={};return ce.forEach((Z,oe)=>{const ae=`${t.tabKey}:${cs(Z,oe)}`;let ke=ss(Z)||h.current.get(ae)||0;ke||(ke=Date.now(),h.current.set(ae,ke)),be[cs(Z,oe)]=ke}),{allMessages:ce,receivedAtMap:be}}const ie=ol(v,J),se=ea(Ns([...ie,...J])),he={};return se.forEach((ce,be)=>{const Z=`${t.tabKey}:${cs(ce,be)}`;let oe=ss(ce)||h.current.get(Z)||0;oe||(oe=Date.now(),h.current.set(Z,oe)),he[cs(ce,be)]=oe}),{allMessages:se,receivedAtMap:he}},[t.tabKey,V,v,T,j.visibleLiveCount]),je=a.useMemo(()=>c.filter(J=>J.routeId===t.tabKey).sort((J,ie)=>J.timestamp-ie.timestamp),[c,t.tabKey]),Y=a.useMemo(()=>{if(T.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((y.isGenerating||t.status==="streaming")&&O(!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(Ts,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:o,disabled:i,className:"btn btn-primary",children:i?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Open ",R," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(qa,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:o,disabled:i,className:"btn btn-primary",children:i?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Open ",R," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]});if(t.status==="idle"&&!D)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.connectionState,t.status,o,i,D,T.length,R,y.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[p&&e.jsx(io,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(vc,{messages:Q,actionLogs:je,agentName:$s(t)||R||"Agent",userName:l,isCliMode:L.isCli||L.isAcp,isWorking:y.isGenerating,contextKey:t.tabKey,receivedAtMap:re,onLoadMore:z,isLoadingMore:D,hasMoreHistory:k,hiddenLiveCount:V,loadError:$??void 0,emptyState:Y,scrollToBottomRequestNonce:x}),m&&!L.isCliTerminal&&(()=>{var J,ie,se,he,ce,be;return e.jsx(Lc,{routeId:t.routeId,sessionId:t.sessionId,hostIdeType:t.hostIdeType,providerType:L.providerType,displayLabel:L.displayLabel,controls:(J=L.targetEntry)==null?void 0:J.providerControls,controlValues:(ie=L.targetEntry)==null?void 0:ie.controlValues,serverModel:((se=L.targetEntry)==null?void 0:se.currentModel)||void 0,serverMode:((he=L.targetEntry)==null?void 0:he.currentPlan)||void 0,acpConfigOptions:L.isAcp?(ce=L.targetEntry)==null?void 0:ce.acpConfigOptions:void 0,acpModes:L.isAcp?(be=L.targetEntry)==null?void 0:be.acpModes:void 0})})(),!L.isCliTerminal&&e.jsx(Rc,{contextKey:t.tabKey,panelLabel:R,isSending:n,onSend:r,isActive:m})]})}let uo=Qt;function po(){return uo()}class pl{constructor(){it(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,r){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(r),()=>{var n;(n=this.listeners.get(s))==null||n.delete(r)}}emit(s,...r){var n;(n=this.listeners.get(s))==null||n.forEach(o=>o(...r))}}let mo=new pl;class ml{sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,o){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,r){return!1}get(s){}onScreenshot(s,r){return()=>{}}onRuntimeEvent(s,r){return()=>{}}requestRuntimeSnapshot(s,r){return Promise.resolve()}}let at=new ml;function fl(t){t.dashboardWS&&(mo=t.dashboardWS),t.connectionManager&&(at=t.connectionManager),t.useDaemonsHook&&(uo=t.useDaemonsHook)}function Qe(t){return gr(t)}function rs(t){return xn(t).join(" · ")}function fo(t){if(t.lastMessagePreview)return t.lastMessagePreview;const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1],r=ts(s==null?void 0:s.content);return r||(t.title?t.title:rs(t)||"No messages yet")}function xo(t,s){const{isReconnecting:r,isConnecting:n}=xs(t);return r?"Reconnecting…":n?"Connecting…":s!=null&&s.requiresAction?"Action needed":null}function xl(t,s){const r=["Chat",...xn(t)];return s!=null&&s.timestampLabel&&r.push(s.timestampLabel),r.filter(Boolean).join(" · ")}function Gt(t){return xo(t)||rs(t)}function hl(t){return`${Qe(t)} · ${fo(t)}`}function bl(t){const s=fn(t)||jt(t);return`${Qe(t)} — ${Ze(s)}`}function gl(t){return $s(t)||"CLI"}function ho(t){return t.title||$s(t)||t.routeId}function bo(t){return t?`Remote · ${Qe(t)||t.workspaceName||"Session"}`:"Remote"}function yl({activeConv:t,clearToken:s=0,terminalRef:r,handleSendChat:n,isSendingChat:o=!1,isVisible:i=!0}){var D;const{ides:c}=Qt(),l=a.useRef(null),{sendCommand:p,sendData:x}=St(),[m,h]=a.useState(""),[g,S]=a.useState(!1),[I,u]=a.useState(1),b=a.useRef(!1),y=a.useRef(0),d=a.useRef(!1),C=a.useRef(""),M=a.useRef(null),N=a.useRef(!1),f=a.useRef(null),j=t.tabKey,v=t.sessionId||"",k=t.daemonId||((D=t.routeId)==null?void 0:D.split(":")[0])||t.routeId||"",$=c.find(O=>O.id===k&&O.type==="adhdev-daemon"),E=($==null?void 0:$.terminalSizingMode)==="fit"?"fit":"measured",W=.6,T=1.15,V=()=>{if(typeof window>"u")return 1;const O=window.innerWidth||0;return O<=360?.68:O<=390?.74:O<=430?.82:O<=480?.9:1},R=()=>{var O,z;y.current=0,d.current=!1,C.current="",M.current=null,N.current=!1,f.current!==null&&(cancelAnimationFrame(f.current),f.current=null),S(!1),(z=(O=r.current)==null?void 0:O.reset)==null||z.call(O)},w=()=>{var O,z;y.current=0,d.current=!1,C.current="",M.current=null,N.current=!1,f.current!==null&&(cancelAnimationFrame(f.current),f.current=null),S(!0),(z=(O=r.current)==null?void 0:O.reset)==null||z.call(O)},B=()=>{var z;if(f.current=null,!i)return;const O=C.current;O&&(C.current="",(z=r.current)==null||z.write(O))},ee=O=>{O&&(C.current+=O,i&&f.current===null&&(f.current=requestAnimationFrame(B)))},L=(O,z=0,Q,re)=>{var je,Y,ne,_,pe;z>0&&y.current>=z||z===0&&d.current||(y.current=z,S(!0),typeof Q=="number"&&typeof re=="number"&&Q>0&&re>0&&((Y=(je=r.current)==null?void 0:je.resize)==null||Y.call(je,Q,re)),(_=(ne=r.current)==null?void 0:ne.reset)==null||_.call(ne),O&&((pe=r.current)==null||pe.write(O)))};return a.useEffect(()=>{R()},[v]),a.useEffect(()=>{var z;if(!v)return;const O=((z=at.onRuntimeEvent)==null?void 0:z.call(at,v,Q=>{if(!(!Q||Q.sessionId!==v)){if(Q.type==="runtime_snapshot"){if(!i){M.current={text:Q.text||"",seq:Q.seq||0,cols:Q.cols,rows:Q.rows};return}L(Q.text||"",Q.seq||0,Q.cols,Q.rows);return}if(Q.type==="session_output"){d.current=!0,typeof Q.seq=="number"&&(y.current=Math.max(y.current,Q.seq)),g||S(!0),typeof Q.data=="string"&&ee(Q.data);return}if(Q.type==="session_cleared"){if(!i){N.current=!0,C.current="",M.current=null;return}w()}}}))||(()=>{});return()=>{O()}},[k,v,r,i,g]),a.useEffect(()=>{var z,Q,re;if(!v)return;k&&((z=at.getState)==null?void 0:z.call(at,k))==="connected"&&(S(!0),(Q=at.requestRuntimeSnapshot)==null||Q.call(at,k,v).catch(()=>{}));const O=(re=at.onStateChange)==null?void 0:re.call(at,(je,Y)=>{var ne;je!==k||Y!=="connected"||(S(!0),(ne=at.requestRuntimeSnapshot)==null||ne.call(at,k,v).catch(()=>{}))});return()=>{O==null||O()}},[k,v,r]),a.useEffect(()=>{s&&R()},[s,j,r]),a.useEffect(()=>{h("")},[t.tabKey]),a.useEffect(()=>{const O=()=>{b.current||u(V())};return O(),window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]),a.useEffect(()=>{var z;if(!i){(z=l.current)==null||z.blur();return}N.current&&(N.current=!1,w());const O=M.current;O&&(M.current=null,L(O.text,O.seq,O.cols,O.rows)),C.current&&f.current===null&&(f.current=requestAnimationFrame(B)),requestAnimationFrame(()=>{var Q;(Q=r.current)==null||Q.bumpResize()})},[i]),a.useEffect(()=>()=>{f.current!==null&&(cancelAnimationFrame(f.current),f.current=null)},[]),a.useEffect(()=>{const O=z=>{var re;const Q=z.detail;Q!=null&&Q.sessionId&&Q.sessionId!==v||g&&((re=r.current)==null||re.bumpResize())};return window.addEventListener("adhdev:fit-cli-terminal",O),()=>{window.removeEventListener("adhdev:fit-cli-terminal",O)}},[g,v,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[e.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{b.current=!0,u(O=>Math.max(W,Number((O-.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:()=>{b.current=!0,u(O=>Math.min(T,Number((O+.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/I}%`,height:`${100/I}%`,transform:`scale(${I})`,transformOrigin:"top left"},children:e.jsx(Za,{ref:r,readOnly:!g||!i,sizingMode:E,onInput:O=>{g&&(x!=null&&x(k,{type:"pty_input",targetSessionId:v,data:O})||p(k,"pty_input",{targetSessionId:v,data:O}).catch(console.error))}})})}),!g&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:l,type:"text",placeholder:`Send message to ${Qe(t)}...`,value:m,disabled:!g||!i||o,onChange:O=>h(O.target.value),onPaste:O=>{const z=O.clipboardData.getData("text");z&&h(Q=>Q+z),O.preventDefault()},onKeyDown:O=>{if(O.key!=="Enter")return;if(O.nativeEvent.isComposing){O.preventDefault();return}O.preventDefault();const z=m.trim();!g||!z||o||(h(""),n(z))},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 O=m.trim();!g||!O||o||(h(""),n(O))},disabled:!g||!i||!m.trim()||o,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${m.trim()&&!o?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:m.trim()&&!o?{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:m.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function vl({wsStatus:t,showReconnected:s,loginUrl:r}){const n=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",o=t==="auth_failed"?"red":t==="offline"?"orange":"accent",i={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)"},l={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:i[o],borderBottom:c[o],color:l[o]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(r?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:r,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function wl({terminalBackend:t,isStandalone:s=!1,machineLabel:r,machineKey:n}){const o=a.useMemo(()=>!n||!t?null:`adhdev:terminal-backend-banner:dismissed:${n}:${t.backend}`,[n,t]),[i,c]=a.useState(!1);if(a.useEffect(()=>{if(!o){c(!1);return}try{c(localStorage.getItem(o)==="1")}catch{c(!1)}},[o]),!s||!t||t.backend!=="xterm"||i)return null;const l=(r==null?void 0:r.trim())||"This machine",p=()=>{if(o)try{localStorage.setItem(o,"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:[l," 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:p,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 bn({mode:t,onChange:s,compact:r=!1}){const n=r?14:15;return e.jsx("button",{type:"button",onClick:()=>s(t==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:t==="chat"?"Switch to Terminal view":"Switch to Chat view",children:t==="chat"?e.jsx(xr,{size:n}):e.jsx(Bt,{size:n})})}function aa({conversation:t,isAttention:s,shortcutIndex:r,onClick:n}){const o=xn(t);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:gr(t)}),(r||o.length>0)&&e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[r?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",r]}):null,o.join(" · ")]})]})}function jl({activeConv:t,agentCount:s,wsStatus:r,isConnected:n,conversations:o,onOpenHistory:i,onOpenRemote:c,onStopCli:l,activeCliViewMode:p,onSetCliViewMode:x,onOpenConversation:m,onHideConversation:h,hiddenConversations:g=[],onShowConversation:S,onShowAllHidden:I,inboxOpen:u,onInboxOpenChange:b,hiddenOpen:y,onHiddenOpenChange:d,onOpenNewSession:C}){const{ides:M,p2pStates:N={}}=Qt(),f=!!t&&Ge(t)&&!qe(t),j=!!t&&qe(t),v=p||(t?ao(t)?"terminal":"chat":null),[k,$]=a.useState(!1),E=a.useRef(null),W=a.useRef(null),T=n?"#22c55e":r==="connected"?"#eab308":"#ef4444",V=n?"0 0 4px #22c55e80":r==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",R=M.filter(_=>_.type==="adhdev-daemon"),w=a.useMemo(()=>Ds(M),[M]),B=Object.values(N),ee=B.filter(_=>_==="connected").length,L=B.filter(_=>_==="connecting"||_==="new"||_==="checking").length,O=r!=="connected"||R.length===0?null:L>0&&ee===0?"P2P connecting...":ee>0&&s===0?"Waiting for IDE...":null,z=a.useMemo(()=>o.filter(_=>!_c(_,o,w)),[o,w]),Q=a.useMemo(()=>z.filter(_=>Ps(_,w).requiresAction),[z,w]),re=a.useMemo(()=>z.filter(_=>{const pe=(t==null?void 0:t.tabKey)===_.tabKey;return Ps(_,w,{hideOpenTaskCompleteUnread:!0,isOpenConversation:pe}).unread}),[t,z,w]),je=a.useMemo(()=>[...Q,...re].slice(0,9),[Q,re]),Y=Q.length+re.length;a.useEffect(()=>{if(!u)return;const _=pe=>{var me;(me=E.current)!=null&&me.contains(pe.target)||b(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[u,b]),a.useEffect(()=>{if(!y)return;const _=pe=>{var me;(me=W.current)!=null&&me.contains(pe.target)||d(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[y,d]),a.useEffect(()=>{if(!y&&!u)return;const _=pe=>{if(!pe.altKey)return;const me=pe.code.match(/^Digit([1-9])$/);if(!me)return;const J=Number(me[1])-1,ie=y?g[J]:void 0,se=u?je[J]:void 0,he=ie||se;if(he){if(pe.preventDefault(),pe.stopPropagation(),ie){S==null||S(ie),d(!1);return}m==null||m(he),b(!1)}};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[g,y,u,je,d,b,m,S]);const ne=_=>{if(!_)return;const pe=o.find(me=>me.tabKey===_);pe&&(h==null||h(pe))};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(Bt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:t?Qe(t):"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:T,boxShadow:V}})})]}),e.jsxs("div",{className:"header-subtitle flex items-center",children:[e.jsx("span",{title:n?"Connected":r==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:T,boxShadow:V}}),O&&e.jsxs("span",{className:"header-subtitle-status mr-2",children:["· ",O]}),C&&e.jsx("button",{type:"button",onClick:C,className:"btn btn-secondary btn-sm ml-2",title:"Start a new session","aria-label":"Start a new session",children:e.jsx(ec,{size:14})})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(f||j||!qe(t))&&e.jsxs("div",{className:"dashboard-header-actions-group",children:[e.jsx("span",{className:"dashboard-header-action-target",title:rs(t)||Qe(t),children:Qe(t)}),(f||j)&&l&&e.jsxs(e.Fragment,{children:[f&&x&&v&&e.jsx(bn,{mode:v,onChange:x,compact:!0}),e.jsx("button",{onClick:()=>l(t),className:"btn btn-secondary btn-sm",title:j?"Stop ACP session":"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(wt,{size:14})})]}),!qe(t)&&e.jsx("button",{onClick:()=>i(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(dn,{size:14})}),!f&&!qe(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Nt,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:E,children:[e.jsxs("div",{className:`dashboard-header-hidden${k?" is-drop-target":""}`,ref:W,onDragEnter:_=>{_.dataTransfer.types.includes("text/tab-key")&&(_.preventDefault(),$(!0))},onDragOver:_=>{_.dataTransfer.types.includes("text/tab-key")&&(_.preventDefault(),_.dataTransfer.dropEffect="move",$(!0))},onDragLeave:_=>{_.currentTarget.contains(_.relatedTarget)||$(!1)},onDrop:_=>{const pe=_.dataTransfer.getData("text/tab-key");_.preventDefault(),$(!1),ne(pe)},children:[e.jsxs("button",{type:"button",onClick:()=>d(!y),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Ga,{size:16}),g.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:g.length})]}),y&&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"}),g.length>0&&I&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{I(),d(!1)},children:"Restore all"})]}),t&&h&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>h(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:Qe(t)})]}),g.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:g.map(_=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{S==null||S(_),d(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:Qe(_)}),e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[g.indexOf(_)<9?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",g.indexOf(_)+1]}):null,rs(_)]})]},_.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>b(!u),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(hr,{size:16}),Y>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:Y})]}),u&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[Q.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),Q.map(_=>e.jsx(aa,{conversation:_,isAttention:!0,shortcutIndex:je.indexOf(_)>=0?je.indexOf(_)+1:void 0,onClick:()=>{m==null||m(_),b(!1)}},_.tabKey))]}),re.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),re.map(_=>e.jsx(aa,{conversation:_,shortcutIndex:je.indexOf(_)>=0?je.indexOf(_)+1:void 0,onClick:()=>{m==null||m(_),b(!1)}},_.tabKey))]}),Y===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function kl(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 gn({activeConv:t,ides:s,isCreatingChat:r,isRefreshingHistory:n,savedSessions:o=[],isSavedSessionsLoading:i=!1,isResumingSavedSessionId:c=null,onClose:l,onNewChat:p,onSwitchSession:x,onRefreshHistory:m,onResumeSavedSession:h}){var y;const g=s.find(d=>d.id===t.routeId),S=(g==null?void 0:g.chats)||[],I=(y=g==null?void 0:g.activeChat)==null?void 0:y.id,u=Ge(t)&&!qe(t),b=e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:l,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:u?"Saved Sessions":"Chat History"}),e.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:bl(t)})]}),e.jsx("button",{onClick:l,className:"btn btn-secondary btn-sm rounded-md px-1.5 py-1.5 border-transparent bg-transparent hover:bg-bg-secondary",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[!u&&e.jsx("button",{onClick:p,disabled:r,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:r?"⌛ Creating...":"+ Start New Chat Session"}),u?e.jsx(e.Fragment,{children:o.map(d=>{const C=t.providerSessionId===d.providerSessionId,M=C||!d.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{M||!h||h(d)},disabled:M,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${C?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${M?"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 ${C?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:d.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:d.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:kl(d.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:d.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:[d.workspace||"Workspace unknown",d.currentModel?` · ${d.currentModel}`:"",d.messageCount>0?` · ${d.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:C?"ACTIVE":d.canResume?c===d.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},d.id)})}):S.map(d=>e.jsxs("div",{onClick:()=>{x(t.routeId,d.id),l()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${I===d.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 ${I===d.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:d.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:[d.id.substring(0,12),"..."]}),I===d.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},d.id)),(u&&!i&&o.length===0||!u&&S.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(rc,{size:32})}),e.jsx("div",{className:"text-[13px]",children:u?"No saved sessions found yet.":"No recent chat sessions found."})]}),u&&i&&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:m,disabled:n||i,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||i?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fs,{size:13})," ",u?"Refresh Sessions":"Refresh History"]})})})]})]});return typeof document>"u"?b:As.createPortal(b,document.body)}const oa={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Done"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Attention"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Update"}};function go({toasts:t,onDismiss:s,onClickToast:r}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(n=>{const o=oa[n.type]||oa.info;return e.jsxs("div",{className:"fade-in pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[380px] relative group overflow-hidden rounded-[16px] border shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:"color-mix(in srgb, var(--surface-primary) 94%, var(--bg-secondary) 6%)",borderColor:"color-mix(in srgb, var(--border-default) 88%, transparent)",color:"var(--text-primary)"},onClick:()=>{var i;(i=n.actions)!=null&&i.length||r&&r(n)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${o.accent}, color-mix(in srgb, ${o.accent} 55%, transparent))`}}),e.jsx("button",{className:"absolute top-2 right-2 w-7 h-7 rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-glass transition-colors leading-none cursor-pointer",onClick:i=>{i.stopPropagation(),s(n.id)},"aria-label":"Dismiss",children:e.jsx(wt,{size:14})}),e.jsxs("div",{className:"px-4 py-3.5 pl-5",children:[e.jsx("div",{className:"flex items-center gap-2 pr-8",children:e.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-[0.08em]",style:{background:o.chipBg,color:o.chipText,border:`1px solid color-mix(in srgb, ${o.accent} 22%, transparent)`},children:o.label})}),e.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:n.message}),n.actions&&n.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-3",children:n.actions.map((i,c)=>e.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${i.variant==="primary"||i.variant==="danger",""}`,style:i.variant==="primary"?{background:"color-mix(in srgb, var(--accent-primary) 12%, var(--surface-primary))",color:"var(--text-primary)",borderColor:"color-mix(in srgb, var(--accent-primary) 26%, transparent)"}:i.variant==="danger"?{background:"color-mix(in srgb, var(--status-error) 10%, var(--surface-primary))",color:"var(--status-error)",borderColor:"color-mix(in srgb, var(--status-error) 22%, transparent)"}:{background:"var(--surface-secondary)",color:"var(--text-secondary)",borderColor:"var(--border-subtle)"},onClick:l=>{l.stopPropagation(),i.onClick(),s(n.id)},children:i.label},c))})]})]},n.id)})})}const Nl=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Sl(t){const s=t.workspace||"";if(!s)return"";const r=s.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:s}function Cl(t){return t.sessionId||t.instanceId||t.agentType}function Pr(t,s){return t||s}function ia(t,s){const r=new Set,n=[];for(const o of s)if(o)for(const i of t[o]||[]){const c=i._localId||`${i.role}:${i.timestamp}:${i.content}`;r.has(c)||(r.add(c),n.push(i))}return n.sort((o,i)=>o.timestamp-i.timestamp)}function yo(t=[]){const s={};for(const r of t)r.type==="adhdev-daemon"&&(s[r.id]=kt(r,{fallbackId:r.id}));return s}function vo(t,s={}){var n,o;const r=t.daemonId||((n=t.id)==null?void 0:n.split(":")[0])||t.id;return{machineName:t.daemonId&&((o=s.machineNames)==null?void 0:o[t.daemonId])||void 0,connectionState:s.connectionStates?s.connectionStates[r]||s.defaultConnectionState||"new":s.defaultConnectionState}}function yn(t,s,r={}){return Il(t,s,vo(t,r))}function Il(t,s,r={}){var g,S,I,u,b,y;const n=[],o=r.machineName,i=r.connectionState,c=Sl(t),l=Ze(t.type),p=Array.isArray(t.childSessions)?t.childSessions.map(d=>{var C,M;return{sessionId:d.id,instanceId:d.id,providerSessionId:d.providerSessionId,transport:d.transport,agentType:d.providerType,agentName:d.providerName||Ze(d.providerType),status:d.status,title:d.title,lastMessagePreview:d.lastMessagePreview,lastMessageRole:d.lastMessageRole,lastMessageAt:d.lastMessageAt,lastMessageHash:d.lastMessageHash,messages:((C=d.activeChat)==null?void 0:C.messages)||[],activeModal:((M=d.activeChat)==null?void 0:M.activeModal)||void 0,unread:d.unread,lastSeenAt:d.lastSeenAt,lastUpdated:d.lastUpdated,inboxBucket:d.inboxBucket,surfaceHidden:d.surfaceHidden}}):[],x=Nl(t),m=t.activeChat||{title:""},h=m.title&&String(m.title).trim()?String(m.title).trim():"";if(x){const d=t.sessionId||t.instanceId,C=Gn(t.type),M=(g=t.activeChat)==null?void 0:g.activeModal,N=M&&Array.isArray(M.buttons)&&M.buttons.length>0,f=bt((S=t.activeChat)==null?void 0:S.status,{activeModal:(I=t.activeChat)==null?void 0:I.activeModal})||bt((b=(u=t.agents)==null?void 0:u[0])==null?void 0:b.status)||"idle",j=t.activeChat||{title:"",messages:[]};let v=j.title&&String(j.title).trim()?String(j.title).trim():"";const k=(y=t.activeChat)==null?void 0:y.id,$=t.chats;if(k&&Array.isArray($)&&$.length>0){const w=$.find(B=>B.id===k||B.id&&String(B.id)===String(k));w!=null&&w.title&&String(w.title).trim()&&(v=String(w.title).trim())}const E=(Ge(t)||qe(t),t.type),W=(Ge(t)||qe(t))&&Yn(v,C,E)?"":v,T=j.messages||[],V=ia(s,[t.id,d]),R=sa(T,V);n.push({routeId:t.id,sessionId:d,providerSessionId:t.providerSessionId,nativeSessionId:d,transport:t.transport,daemonId:t.daemonId||void 0,mode:Ge(t)?t.mode||"terminal":"chat",agentName:C,agentType:E,status:f,title:W,messages:[...T,...R],resume:t.resume,hostIdeType:!Ge(t)&&!qe(t)?t.type:void 0,workspaceName:c,displayPrimary:c||W||(Ge(t)?t.mode==="chat"?C:"Terminal":C),displaySecondary:l,cdpConnected:t.cdpConnected,lastMessagePreview:t.lastMessagePreview,lastMessageRole:t.lastMessageRole,lastMessageAt:t.lastMessageAt,lastMessageHash:t.lastMessageHash,lastUpdated:t.lastUpdated,modalButtons:N?M.buttons:void 0,modalMessage:N?M.message:void 0,streamSource:"native",tabKey:Pr(d,t.id),machineName:o,connectionState:i})}if(x&&(Ge(t)||qe(t)))return n;for(const d of p){const C=d.activeModal&&Array.isArray(d.activeModal.buttons)&&d.activeModal.buttons.length>0,M=Hc(d),N=Cl(d),f=`${t.id}:${N}`,j=d.title&&String(d.title).trim()||"",v=Yn(j,d.agentName,d.agentType)?"":j,k=d.messages||[],$=ia(s,[f,d.sessionId,d.instanceId]),E=sa(k,$);(d.transport==="cdp-webview"||d.sessionId||d.providerSessionId||k.length>0||E.length>0||C||v||!["idle","panel_hidden","disconnected","not_monitored"].includes(M))&&n.push({routeId:t.id,sessionId:d.sessionId||d.instanceId,providerSessionId:d.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:d.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:d.agentName,agentType:d.agentType,status:M,title:v,messages:[...k,...E],hostIdeType:t.type,workspaceName:c,displayPrimary:c||h||v||l,displaySecondary:`${l} · ${d.agentName}`,cdpConnected:t.cdpConnected,lastMessagePreview:d.lastMessagePreview,lastMessageRole:d.lastMessageRole,lastMessageAt:d.lastMessageAt,lastMessageHash:d.lastMessageHash,lastUpdated:d.lastUpdated||t.lastUpdated,modalButtons:C?d.activeModal.buttons:void 0,modalMessage:C?d.activeModal.message:void 0,streamSource:"agent-stream",tabKey:Pr(d.sessionId||d.instanceId,f),machineName:o,connectionState:i})}return n.length===0&&n.push({routeId: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:Gn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],hostIdeType:t.type,workspaceName:c,displayPrimary:c||l,displaySecondary:l,cdpConnected:t.cdpConnected,lastUpdated:t.lastUpdated,streamSource:"native",tabKey:Pr(t.sessionId||t.instanceId,t.id),connectionState:i}),n}function Ml(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 Al(t,s){const r=Ml(t);return{daemonId:r.daemonId,payload:{...s,...r.targetSessionId&&!s.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const wo=[{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"trae",name:"Trae",icon:"🔮"},{id:"vscode",name:"VS Code",icon:"💙"},{id:"vscodium",name:"VSCodium",icon:"💚"},{id:"windsurf",name:"Windsurf",icon:"🏄"}],jo=[{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],ko=[{id:"cline",name:"Cline",icon:"🧠"},{id:"codex",name:"Codex",icon:"📦"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"claude-code-vscode",name:"Claude Code (VS Code)",icon:"🟠"}],Tl=wo,_l=jo,Pl=ko,No="adhdev_notification_prefs",ca={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function Ll(){try{const t=localStorage.getItem(No);if(t){const s=JSON.parse(t);return{...ca,...s}}}catch{}return{...ca}}function Rl(t){try{localStorage.setItem(No,JSON.stringify(t))}catch{}}let Dt=Ll(),tr=[];function El(){tr.forEach(t=>t())}function Dl(t){Dt={...Dt,...t},Rl(Dt),El()}function $l(){const[,t]=a.useState(0);a.useEffect(()=>{const r=()=>t(n=>n+1);return tr.push(r),()=>{tr=tr.filter(n=>n!==r)}},[]);const s=a.useCallback(r=>{Dl(r)},[]);return[{...Dt},s]}function Ss(t){if(!Dt.globalEnabled)return!1;switch(t){case"disconnect":return Dt.disconnectAlert;case"completion":return Dt.completionAlert;case"approval":return Dt.approvalAlert;case"browser":return Dt.browserNotifications;default:return!0}}const Bl={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Kl(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function So(){return"Notification"in window&&Notification.permission==="granted"}let Ft=null;async function Wl(){if(Ft!==null)return Ft;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Ft=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Ft=!!await t.pushManager.getSubscription(),Ft):(Ft=!1,!1)}catch{return Ft=!1,!1}}function Zr(t,s,r){if(So())try{const n=new Notification(t,{body:s,icon:"/otter-logo.png",tag:r||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>n.close(),8e3),n.onclick=()=>{window.focus(),n.close()}}catch{}}function Ol(t,s={}){const r={...Bl,...s},n=a.useRef(new Map),o=a.useRef(0),i=a.useRef(null);a.useEffect(()=>{Wl().then(l=>{i.current=l})},[]);const c=a.useCallback((l,p,x)=>{const m=Date.now();m-o.current<r.throttleMs||(o.current=m,Zr(l,p,x))},[r.throttleMs]);a.useEffect(()=>{var l;if(!(!r.enabled||!So())&&Ss("browser")&&i.current!==!0){if(document.hasFocus()){for(const p of t)n.current.set(p.id,bt(p.status,{activeModal:p.activeModal}));return}for(const p of t){const x=n.current.get(p.id),m=bt(p.status,{activeModal:p.activeModal}),h=p.name||p.id;if(r.onApproval&&Ss("approval")&&m==="waiting_approval"&&x!=="waiting_approval"){const g=((l=p.activeModal)==null?void 0:l.message)||"Action requires your approval";c(`🔔 ${h} — Approval needed`,g.slice(0,120),`approval-${p.id}`)}r.onComplete&&Ss("completion")&&ro(x)&&m==="idle"&&c(`✅ ${h} — Task complete`,"Agent has finished generating",`complete-${p.id}`),r.onError&&m==="error"&&x!=="error"&&c(`⚠️ ${h} — Error`,"Agent encountered an error",`error-${p.id}`),n.current.set(p.id,m)}}},[t,r.enabled,r.onApproval,r.onComplete,r.onError,c])}const Hl=/^(run|approve|accept|yes|allow|always)/,Ul=/^(run|approve|accept|yes|allow|always|proceed|save)/,zl=/^(reject|deny|delete|remove|abort|cancel|no)/;function vn(t){return t.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim()}function Fl(t){const s=vn(t).toLowerCase();return Hl.test(s)?"primary":zl.test(s)?"danger":"default"}function Vl(t){return Ul.test(vn(t).toLowerCase())?"approve":"reject"}function ql(t){return t.map((s,r)=>({label:vn(s),variant:Fl(s),action:Vl(s),button:s,buttonIndex:r}))}function Gl(t,s){const r=t||"Approval requested",n=s!=null&&s.length?s.map(o=>`[${o}]`).join(" "):"[Approve] [Reject]";return`⚡ Approval requested: ${r}
|
|
29
|
-
${n}`}function Yl(t,s,r){return s?`⚡ ${t}: ${s.replace(/[\n\r]+/g," ").slice(0,80)}`:r}function Xl(t,s,r,n){return[{label:"Approve",variant:"primary",onClick:()=>{r(t,s,"approve").catch(o=>n==null?void 0:n("approve",o))}},{label:"Decline",variant:"danger",onClick:()=>{r(t,s,"reject").catch(o=>n==null?void 0:n("reject",o))}}]}class Jl{constructor(){it(this,"dedupMap",new Map);it(this,"DEDUP_WINDOW_MS",5e3);it(this,"DEDUP_MAX_SIZE",50);it(this,"DEDUP_CLEANUP_AGE_MS",1e4);it(this,"toastCallbacks",[]);it(this,"systemMessageCallbacks",[]);it(this,"clearSystemMessageCallbacks",[]);it(this,"resolveActionFn",null);it(this,"viewRequestRespondFn",null);it(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(r=>r!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(r=>r!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(r=>r!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const r of this.toastCallbacks)r(s)}showToast(s,r="info",n){const o=(n==null?void 0:n.id)||Date.now();this.emitToast({id:o,message:s,type:r,timestamp:o,duration:5e3,...n})}emitSystemMessage(s,r){for(const n of this.systemMessageCallbacks)n(s,r)}isDuplicate(s){const r=Date.now(),n=this.dedupMap.get(s)||0;if(r-n<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,r),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[o,i]of this.dedupMap)r-i>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(o);return!1}resolveOwningDaemon(s){if(s.daemonId){const o=this.ides.find(i=>i.id===s.daemonId&&i.type==="adhdev-daemon");if(o)return o}const r=s.targetSessionId&&this.findOwningSession(s.targetSessionId)||void 0;if(r){const o=r.daemonId;if(o){const i=this.ides.find(c=>c.id===o&&c.type==="adhdev-daemon");if(i)return i}}const n=this.ides.filter(o=>o.type==="adhdev-daemon");return n.length===1?n[0]:null}findOwningSession(s){for(const r of this.ides)if(r.id===s||r.sessionId===s||(Array.isArray(r.childSessions)?r.childSessions:[]).some(o=>(o==null?void 0:o.id)===s))return r;return null}resolveActionRouteTarget(s){if(s.targetSessionId){const r=this.findOwningSession(s.targetSessionId);return(r==null?void 0:r.id)||(r==null?void 0:r.daemonId)||null}return s.daemonId||null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.daemonId?s.daemonId:null}handleRawEvent(s,r){var I,u;const n=this.resolveConversationKey(s),o=Number.isFinite(s.timestamp)?Number(s.timestamp):Date.now(),i=n||s.daemonId||"",c=s.requestId||s.targetName||s.requesterName||s.modalMessage||String(o),l=`${i}:${s.event}:${c}`;if(this.isDuplicate(l))return;const p=s.targetSessionId?this.findOwningSession(s.targetSessionId):null,x=(p==null?void 0:p.type)||"";let m=Ze(x);const h=this.resolveOwningDaemon(s);if(h){const b=kt(h,{fallbackId:h.id});b&&(m=!x||x==="adhdev-daemon"?b:`${b}/${m}`)}let g="",S="info";if(s.event==="agent:generating_completed"){const b=s.duration?` (${s.duration}s)`:"";g=`✅ ${m} agent task completed${b}`,S="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}}else if(s.event!=="agent:generating_started")if(s.event==="agent:waiting_approval"){if(g=`⚡ ${m} approval needed`,S="warning",n&&!((I=s.modalButtons)!=null&&I.length)&&this.emitSystemMessage(n,{role:"system",timestamp:o,content:Gl(s.modalMessage,s.modalButtons),_localId:`sys_approval_${o}`}),(u=s.modalButtons)!=null&&u.length&&this.resolveActionFn){const b=this.resolveActionRouteTarget(s);if(!b)return;const y=this.resolveActionFn,d=ql(s.modalButtons).map(N=>({label:N.label,variant:N.variant,onClick:()=>{y(b,"resolve_action",{action:N.action,button:N.button,buttonIndex:N.buttonIndex,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}})),C=Yl(m,s.modalMessage,g),M=Date.now();this.emitToast({id:M,message:C,type:S,timestamp:M,targetKey:n||b,actions:d,duration:15e3}),g=""}}else if(s.event==="monitor:long_generating"){const b=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";g=`⚠️ ${m} agent is taking a long time${b}`,S="warning",Ss("browser")&&!document.hasFocus()&&Zr(`⚠️ ${m} — Long Running`,`Agent has been generating for over ${b.replace(/[()]/g,"")}`,`long-${s.targetSessionId||s.daemonId||"daemon"}`)}else if(s.event==="team:view_request"){const b=s.requesterName||"A team member",y=s.requestId,d=s.orgId;if(g=`👁️ ${b} wants to view your session`,S="warning",y&&d&&this.viewRequestRespondFn){const C=Date.now(),M=Xl(d,y,this.viewRequestRespondFn,(N,f)=>console.error(`[EventManager] ${N} view request failed:`,f));this.emitToast({id:C,message:g,type:S,timestamp:C,actions:M,duration:3e4}),g=""}Ss("browser")&&!document.hasFocus()&&Zr("👁️ View Request",`${b} wants to view your session`,`view-request-${y}`)}else s.event==="team:view_request_approved"?(g="✅ View request approved",S="success"):s.event==="team:view_request_rejected"&&(g=`❌ ${s.targetName||"Team member"} declined your view request`,S="warning");if(g){const b=Date.now();this.emitToast({id:b,message:g,type:S,timestamp:b,targetKey:n||s.daemonId,duration:5e3})}}}const gt=new Jl;function ns(...t){return Ti(_i(t))}function Zl({icon:t,title:s,subtitle:r,badge:n,actions:o,className:i}){return e.jsxs("div",{className:ns("dashboard-header",i),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,n&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),o&&e.jsx("div",{className:"flex gap-2",children:o})]})}function Co({icon:t,title:s,subtitle:r,badge:n,actions:o,widthClassName:i="max-w-6xl",contentClassName:c,children:l}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Zl,{icon:t,title:s,subtitle:r,badge:n,actions:o}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ns("mx-auto flex w-full flex-col gap-4",i,c),children:l})})]})}function _t({title:t,icon:s,description:r,accentColor:n,className:o,children:i}){return e.jsxs("div",{className:ns("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",o),style:n?{borderLeftColor:n}:void 0,children:[(t||r)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),r&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),i]})}function Io({icon:t,title:s,description:r,action:n,className:o}){return e.jsxs("div",{className:ns("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:r}),n]})}const Ql={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"},ed={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function td({variant:t,children:s,onDismiss:r,className:n}){return e.jsxs("div",{className:ns("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Ql[t],n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ed[t]}),e.jsx("span",{children:s})]}),r&&e.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const sd={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"},rd={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function nd({status:t,label:s,className:r}){const n=s||t;return e.jsxs("span",{className:ns("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",sd[t],r),children:[e.jsx("span",{className:ns("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",rd[t])}),n]})}function ad(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Qr(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function sr(t){return t==="system"?ad():t}function od(){typeof document>"u"||document.documentElement.setAttribute("data-theme",sr(Qr()))}function wn(){const[t,s]=a.useState(Qr),[r,n]=a.useState(()=>sr(Qr()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",r)},[r]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),l=p=>{t==="system"&&n(p.matches?"light":"dark")};return c.addEventListener("change",l),()=>c.removeEventListener("change",l)},[t]);const o=a.useCallback(c=>{s(c),n(sr(c));try{localStorage.setItem("theme",c)}catch{}},[]),i=a.useCallback(()=>{s(c=>{const l=c==="dark"?"light":c==="light"?"system":"dark";n(sr(l));try{localStorage.setItem("theme",l)}catch{}return l})},[]);return{theme:r,preference:t,setPreference:o,cycleTheme:i,isDark:r==="dark"}}const la={dark:"Dark",light:"Light",system:"System"};function id({collapsed:t}){const{preference:s,cycleTheme:r}=wn(),n=s==="dark"?e.jsx(ac,{size:16}):s==="light"?e.jsx(nc,{size:16}):e.jsx(oc,{size:16});return e.jsxs("div",{className:`nav-item cursor-pointer ${t?"justify-center py-2.5 px-0":""}`,onClick:r,title:`Theme: ${la[s]} (click to cycle)`,children:[e.jsx("span",{className:"nav-icon",children:n}),!t&&e.jsx("span",{className:"text-xs",children:la[s]})]})}function qt({label:t,description:s,checked:r,disabled:n,onChange:o,extra:i}){return e.jsxs("div",{className:`flex justify-between items-center ${n?"opacity-60":""}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[i,e.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>o(!r),className:`relative inline-flex items-center ${n?"cursor-not-allowed":"cursor-pointer"}`,children:[e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:r?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function cd({onPrefChange:t}){const[s,r]=$l(),n=(o,i)=>{r({[o]:i}),t==null||t(o,i)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hr,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:o=>n("globalEnabled",o)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:o=>n("browserNotifications",o)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ic,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:o=>n("completionAlert",o)}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(cc,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:o=>n("approvalAlert",o)}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ts,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:o=>n("disconnectAlert",o)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function dr(t){const s=t.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/);return s?[Number(s[1]),Number(s[2]),Number(s[3])]:null}function ld(t,s){const r=dr(t),n=dr(s);if(!r||!n)return t.localeCompare(s);for(let o=0;o<3;o+=1){if(r[o]<n[o])return-1;if(r[o]>n[o])return 1}return 0}function Mo(t,s){const r=t.version||null;return t.versionMismatch===!0?!0:!r||!s?!1:r!==s}function Cs(t,s){if(t.versionUpdateRequired===!0)return!0;const r=t.version||null;if(!r||!s||r===s||ld(r,s)>=0)return!1;const n=dr(r),o=dr(s);return!n||!o?!1:n[0]!==o[0]||n[1]!==o[1]}function dd(t){return!t||typeof t!="object"?{}:"result"in t&&t.result&&typeof t.result=="object"?t.result:t}function Lr(t,s){return t instanceof Error?t.message:s}function ud({ides:t,emptyMessage:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o}){const i=t.filter(c=>c.type==="adhdev-daemon");return i.length===0?e.jsx(Io,{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:i.map(c=>e.jsx(md,{ide:c,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o},c.id))})}function da({title:t,message:s,confirmLabel:r,confirmColor:n,onConfirm:o,onCancel:i}){const c=n==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return As.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:i,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:l=>l.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:i,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:o,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:n==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:r})]})]})}),document.body)}function pd(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...Tl,..._l,...Pl].find(o=>o.id===s||s.includes(o.id)||o.id.includes(s));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:t}}function md({ide:t,allIdes:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o}){var V,R;const[i,c]=a.useState("idle"),[l,p]=a.useState(""),[x,m]=a.useState(null),[h,g]=a.useState("idle"),[S,I]=a.useState(""),u=t.version||null,b=((V=t.machine)==null?void 0:V.platform)||((R=t.system)==null?void 0:R.platform)||"",y=kt(t,{fallbackId:t.id}),d=b==="win32"?"🪟":b==="darwin"?"🍎":"🐧",C=s.filter(w=>w.daemonId===t.id&&w.transport==="cdp-page"),M=s.filter(w=>w.daemonId===t.id&&w.transport==="pty"),N=s.filter(w=>w.daemonId===t.id&&w.transport==="acp"),f=t.p2p,j=async()=>{if(r){c("upgrading"),p("Starting upgrade...");try{const w=dd(await r(t.id,"daemon_upgrade",{}));w.alreadyLatest?(c("done"),p(`Already on v${w.version||"latest"}.`)):w.upgraded||w.success?(c("done"),p(`Upgrade to v${w.version||"latest"} started. Daemon is restarting...`)):(c("error"),p(w.error||"Upgrade failed"))}catch(w){c("error"),p(Lr(w,"Connection lost during upgrade"))}}},v=async()=>{if(m(null),!!n){g("loading");try{await n(t.id),g("done"),I("Machine disconnected.")}catch(w){g("error"),I(Lr(w,"Failed to disconnect"))}}},k=async()=>{if(m(null),!!o){g("loading");try{await o(t.id),g("done"),I('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(w){g("error"),I(Lr(w,"Failed to revoke token"))}}},$="0.8.44",E=Mo(t,$),W=Cs(t,$),T=C.length+M.length+N.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:d}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:y}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),u&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${E?"":"bg-bg-secondary"}`,style:E?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",u,!E&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&E&&e.jsx("button",{onClick:j,disabled:i==="upgrading"||i==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${$}`,children:i==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):i==="done"?"✓ Updated":`${W?"↑ Update now":`↑ Update${` to v${$}`}`}`}),n&&e.jsx("button",{onClick:()=>m("disconnect"),disabled:h==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),o&&e.jsx("button",{onClick:()=>m("revoke"),disabled:h==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(nd,{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:[f&&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 ${f.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${f.state==="connecting"||f.state==="new"?"animate-pulse":""}`,style:f.state==="connecting"||f.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",f.state==="connected"?"connected":f.state==="connecting"||f.state==="new"?"connecting...":f.state||"off"]}),f.peers!==void 0&&f.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",f.peers," peer",f.peers!==1?"s":"",")"]})]}),f&&T>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),T>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[C.map(w=>{const B=pd(w.type),ee=w.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:B.icon}),e.jsx("span",{children:B.name}),ee!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ee?"bg-green-400":"animate-pulse"}`,style:ee?void 0:{background:"var(--status-warning)"},title:ee?"CDP connected":"CDP connecting..."})]},w.id)}),M.map(w=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:w.cliName||"CLI"})]},w.id)),N.map(w=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:w.cliName||"ACP"})]},w.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(l||S)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${i==="error"||h==="error"?"text-red-400":i==="done"||h==="done"?"text-green-400":"text-text-muted"}`,children:S||l})]}),x==="disconnect"&&e.jsx(da,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
|
|
29
|
+
${n}`}function Yl(t,s,r){return s?`⚡ ${t}: ${s.replace(/[\n\r]+/g," ").slice(0,80)}`:r}function Xl(t,s,r,n){return[{label:"Approve",variant:"primary",onClick:()=>{r(t,s,"approve").catch(o=>n==null?void 0:n("approve",o))}},{label:"Decline",variant:"danger",onClick:()=>{r(t,s,"reject").catch(o=>n==null?void 0:n("reject",o))}}]}class Jl{constructor(){it(this,"dedupMap",new Map);it(this,"DEDUP_WINDOW_MS",5e3);it(this,"DEDUP_MAX_SIZE",50);it(this,"DEDUP_CLEANUP_AGE_MS",1e4);it(this,"toastCallbacks",[]);it(this,"systemMessageCallbacks",[]);it(this,"clearSystemMessageCallbacks",[]);it(this,"resolveActionFn",null);it(this,"viewRequestRespondFn",null);it(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(r=>r!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(r=>r!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(r=>r!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const r of this.toastCallbacks)r(s)}showToast(s,r="info",n){const o=(n==null?void 0:n.id)||Date.now();this.emitToast({id:o,message:s,type:r,timestamp:o,duration:5e3,...n})}emitSystemMessage(s,r){for(const n of this.systemMessageCallbacks)n(s,r)}isDuplicate(s){const r=Date.now(),n=this.dedupMap.get(s)||0;if(r-n<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,r),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[o,i]of this.dedupMap)r-i>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(o);return!1}resolveOwningDaemon(s){if(s.daemonId){const o=this.ides.find(i=>i.id===s.daemonId&&i.type==="adhdev-daemon");if(o)return o}const r=s.targetSessionId&&this.findOwningSession(s.targetSessionId)||void 0;if(r){const o=r.daemonId;if(o){const i=this.ides.find(c=>c.id===o&&c.type==="adhdev-daemon");if(i)return i}}const n=this.ides.filter(o=>o.type==="adhdev-daemon");return n.length===1?n[0]:null}findOwningSession(s){for(const r of this.ides)if(r.id===s||r.sessionId===s||(Array.isArray(r.childSessions)?r.childSessions:[]).some(o=>(o==null?void 0:o.id)===s))return r;return null}resolveActionRouteTarget(s){if(s.targetSessionId){const r=this.findOwningSession(s.targetSessionId);return(r==null?void 0:r.id)||(r==null?void 0:r.daemonId)||null}return s.daemonId||null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.daemonId?s.daemonId:null}handleRawEvent(s,r){var I,u;const n=this.resolveConversationKey(s),o=Number.isFinite(s.timestamp)?Number(s.timestamp):Date.now(),i=n||s.daemonId||"",c=s.requestId||s.targetName||s.requesterName||s.modalMessage||String(o),l=`${i}:${s.event}:${c}`;if(this.isDuplicate(l))return;const p=s.targetSessionId?this.findOwningSession(s.targetSessionId):null,x=(p==null?void 0:p.type)||"";let m=Ze(x);const h=this.resolveOwningDaemon(s);if(h){const b=kt(h,{fallbackId:h.id});b&&(m=!x||x==="adhdev-daemon"?b:`${b}/${m}`)}let g="",S="info";if(s.event==="agent:generating_completed"){const b=s.duration?` (${s.duration}s)`:"";g=`✅ ${m} agent task completed${b}`,S="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}}else if(s.event!=="agent:generating_started")if(s.event==="agent:waiting_approval"){if(g=`⚡ ${m} approval needed`,S="warning",n&&!((I=s.modalButtons)!=null&&I.length)&&this.emitSystemMessage(n,{role:"system",timestamp:o,content:Gl(s.modalMessage,s.modalButtons),_localId:`sys_approval_${o}`}),(u=s.modalButtons)!=null&&u.length&&this.resolveActionFn){const b=this.resolveActionRouteTarget(s);if(!b)return;const y=this.resolveActionFn,d=ql(s.modalButtons).map(N=>({label:N.label,variant:N.variant,onClick:()=>{y(b,"resolve_action",{action:N.action,button:N.button,buttonIndex:N.buttonIndex,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}})),C=Yl(m,s.modalMessage,g),M=Date.now();this.emitToast({id:M,message:C,type:S,timestamp:M,targetKey:n||b,actions:d,duration:15e3}),g=""}}else if(s.event==="monitor:long_generating"){const b=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";g=`⚠️ ${m} agent is taking a long time${b}`,S="warning",Ss("browser")&&!document.hasFocus()&&Zr(`⚠️ ${m} — Long Running`,`Agent has been generating for over ${b.replace(/[()]/g,"")}`,`long-${s.targetSessionId||s.daemonId||"daemon"}`)}else if(s.event==="team:view_request"){const b=s.requesterName||"A team member",y=s.requestId,d=s.orgId;if(g=`👁️ ${b} wants to view your session`,S="warning",y&&d&&this.viewRequestRespondFn){const C=Date.now(),M=Xl(d,y,this.viewRequestRespondFn,(N,f)=>console.error(`[EventManager] ${N} view request failed:`,f));this.emitToast({id:C,message:g,type:S,timestamp:C,actions:M,duration:3e4}),g=""}Ss("browser")&&!document.hasFocus()&&Zr("👁️ View Request",`${b} wants to view your session`,`view-request-${y}`)}else s.event==="team:view_request_approved"?(g="✅ View request approved",S="success"):s.event==="team:view_request_rejected"&&(g=`❌ ${s.targetName||"Team member"} declined your view request`,S="warning");if(g){const b=Date.now();this.emitToast({id:b,message:g,type:S,timestamp:b,targetKey:n||s.daemonId,duration:5e3})}}}const gt=new Jl;function ns(...t){return Ti(_i(t))}function Zl({icon:t,title:s,subtitle:r,badge:n,actions:o,className:i}){return e.jsxs("div",{className:ns("dashboard-header",i),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,n&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),o&&e.jsx("div",{className:"flex gap-2",children:o})]})}function Co({icon:t,title:s,subtitle:r,badge:n,actions:o,widthClassName:i="max-w-6xl",contentClassName:c,children:l}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Zl,{icon:t,title:s,subtitle:r,badge:n,actions:o}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ns("mx-auto flex w-full flex-col gap-4",i,c),children:l})})]})}function _t({title:t,icon:s,description:r,accentColor:n,className:o,children:i}){return e.jsxs("div",{className:ns("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",o),style:n?{borderLeftColor:n}:void 0,children:[(t||r)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),r&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),i]})}function Io({icon:t,title:s,description:r,action:n,className:o}){return e.jsxs("div",{className:ns("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:r}),n]})}const Ql={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"},ed={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function td({variant:t,children:s,onDismiss:r,className:n}){return e.jsxs("div",{className:ns("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Ql[t],n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ed[t]}),e.jsx("span",{children:s})]}),r&&e.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const sd={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"},rd={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function nd({status:t,label:s,className:r}){const n=s||t;return e.jsxs("span",{className:ns("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",sd[t],r),children:[e.jsx("span",{className:ns("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",rd[t])}),n]})}function ad(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Qr(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function sr(t){return t==="system"?ad():t}function od(){typeof document>"u"||document.documentElement.setAttribute("data-theme",sr(Qr()))}function wn(){const[t,s]=a.useState(Qr),[r,n]=a.useState(()=>sr(Qr()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",r)},[r]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),l=p=>{t==="system"&&n(p.matches?"light":"dark")};return c.addEventListener("change",l),()=>c.removeEventListener("change",l)},[t]);const o=a.useCallback(c=>{s(c),n(sr(c));try{localStorage.setItem("theme",c)}catch{}},[]),i=a.useCallback(()=>{s(c=>{const l=c==="dark"?"light":c==="light"?"system":"dark";n(sr(l));try{localStorage.setItem("theme",l)}catch{}return l})},[]);return{theme:r,preference:t,setPreference:o,cycleTheme:i,isDark:r==="dark"}}const la={dark:"Dark",light:"Light",system:"System"};function id({collapsed:t}){const{preference:s,cycleTheme:r}=wn(),n=s==="dark"?e.jsx(ac,{size:16}):s==="light"?e.jsx(nc,{size:16}):e.jsx(oc,{size:16});return e.jsxs("div",{className:`nav-item cursor-pointer ${t?"justify-center py-2.5 px-0":""}`,onClick:r,title:`Theme: ${la[s]} (click to cycle)`,children:[e.jsx("span",{className:"nav-icon",children:n}),!t&&e.jsx("span",{className:"text-xs",children:la[s]})]})}function qt({label:t,description:s,checked:r,disabled:n,onChange:o,extra:i}){return e.jsxs("div",{className:`flex justify-between items-center ${n?"opacity-60":""}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[i,e.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>o(!r),className:`relative inline-flex items-center ${n?"cursor-not-allowed":"cursor-pointer"}`,children:[e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:r?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function cd({onPrefChange:t}){const[s,r]=$l(),n=(o,i)=>{r({[o]:i}),t==null||t(o,i)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hr,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:o=>n("globalEnabled",o)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:o=>n("browserNotifications",o)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ic,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:o=>n("completionAlert",o)}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(cc,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:o=>n("approvalAlert",o)}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ts,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:o=>n("disconnectAlert",o)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function dr(t){const s=t.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/);return s?[Number(s[1]),Number(s[2]),Number(s[3])]:null}function ld(t,s){const r=dr(t),n=dr(s);if(!r||!n)return t.localeCompare(s);for(let o=0;o<3;o+=1){if(r[o]<n[o])return-1;if(r[o]>n[o])return 1}return 0}function Mo(t,s){const r=t.version||null;return t.versionMismatch===!0?!0:!r||!s?!1:r!==s}function Cs(t,s){if(t.versionUpdateRequired===!0)return!0;const r=t.version||null;if(!r||!s||r===s||ld(r,s)>=0)return!1;const n=dr(r),o=dr(s);return!n||!o?!1:n[0]!==o[0]||n[1]!==o[1]}function dd(t){return!t||typeof t!="object"?{}:"result"in t&&t.result&&typeof t.result=="object"?t.result:t}function Lr(t,s){return t instanceof Error?t.message:s}function ud({ides:t,emptyMessage:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o}){const i=t.filter(c=>c.type==="adhdev-daemon");return i.length===0?e.jsx(Io,{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:i.map(c=>e.jsx(md,{ide:c,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o},c.id))})}function da({title:t,message:s,confirmLabel:r,confirmColor:n,onConfirm:o,onCancel:i}){const c=n==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return As.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:i,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:l=>l.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:i,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:o,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:n==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:r})]})]})}),document.body)}function pd(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...Tl,..._l,...Pl].find(o=>o.id===s||s.includes(o.id)||o.id.includes(s));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:t}}function md({ide:t,allIdes:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:o}){var V,R;const[i,c]=a.useState("idle"),[l,p]=a.useState(""),[x,m]=a.useState(null),[h,g]=a.useState("idle"),[S,I]=a.useState(""),u=t.version||null,b=((V=t.machine)==null?void 0:V.platform)||((R=t.system)==null?void 0:R.platform)||"",y=kt(t,{fallbackId:t.id}),d=b==="win32"?"🪟":b==="darwin"?"🍎":"🐧",C=s.filter(w=>w.daemonId===t.id&&w.transport==="cdp-page"),M=s.filter(w=>w.daemonId===t.id&&w.transport==="pty"),N=s.filter(w=>w.daemonId===t.id&&w.transport==="acp"),f=t.p2p,j=async()=>{if(r){c("upgrading"),p("Starting upgrade...");try{const w=dd(await r(t.id,"daemon_upgrade",{}));w.alreadyLatest?(c("done"),p(`Already on v${w.version||"latest"}.`)):w.upgraded||w.success?(c("done"),p(`Upgrade to v${w.version||"latest"} started. Daemon is restarting...`)):(c("error"),p(w.error||"Upgrade failed"))}catch(w){c("error"),p(Lr(w,"Connection lost during upgrade"))}}},v=async()=>{if(m(null),!!n){g("loading");try{await n(t.id),g("done"),I("Machine disconnected.")}catch(w){g("error"),I(Lr(w,"Failed to disconnect"))}}},k=async()=>{if(m(null),!!o){g("loading");try{await o(t.id),g("done"),I('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(w){g("error"),I(Lr(w,"Failed to revoke token"))}}},$="0.8.45",E=Mo(t,$),W=Cs(t,$),T=C.length+M.length+N.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:d}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:y}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),u&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${E?"":"bg-bg-secondary"}`,style:E?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",u,!E&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&E&&e.jsx("button",{onClick:j,disabled:i==="upgrading"||i==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${$}`,children:i==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):i==="done"?"✓ Updated":`${W?"↑ Update now":`↑ Update${` to v${$}`}`}`}),n&&e.jsx("button",{onClick:()=>m("disconnect"),disabled:h==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),o&&e.jsx("button",{onClick:()=>m("revoke"),disabled:h==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(nd,{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:[f&&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 ${f.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${f.state==="connecting"||f.state==="new"?"animate-pulse":""}`,style:f.state==="connecting"||f.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",f.state==="connected"?"connected":f.state==="connecting"||f.state==="new"?"connecting...":f.state||"off"]}),f.peers!==void 0&&f.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",f.peers," peer",f.peers!==1?"s":"",")"]})]}),f&&T>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),T>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[C.map(w=>{const B=pd(w.type),ee=w.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:B.icon}),e.jsx("span",{children:B.name}),ee!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ee?"bg-green-400":"animate-pulse"}`,style:ee?void 0:{background:"var(--status-warning)"},title:ee?"CDP connected":"CDP connecting..."})]},w.id)}),M.map(w=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:w.cliName||"CLI"})]},w.id)),N.map(w=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:w.cliName||"ACP"})]},w.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(l||S)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${i==="error"||h==="error"?"text-red-400":i==="done"||h==="done"?"text-green-400":"text-text-muted"}`,children:S||l})]}),x==="disconnect"&&e.jsx(da,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
|
|
30
30
|
|
|
31
31
|
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ This will:
|
|
|
37
37
|
• Delete the machine registration
|
|
38
38
|
• Require restarting "adhdev-standalone" on that machine
|
|
39
39
|
|
|
40
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:k,onCancel:()=>m(null)})]})}const fd=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function xd(){const{preference:t,setPreference:s}=wn();return e.jsx("div",{className:"flex gap-2",children:fd.map(r=>e.jsxs("button",{onClick:()=>s(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:r.icon}),r.label]},r.id))})}function hd(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 bd(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Rr(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function ua(t){const{r:s,g:r,b:n}=bd(t);return .2126*Rr(s)+.7152*Rr(r)+.0722*Rr(n)}function pa(t,s){const r=ua(t),n=ua(s),o=Math.max(r,n),i=Math.min(r,n);return(o+.05)/(i+.05)}function Ao(t){const s=hd(t);if(!s)return"#111827";const r="#111827",n="#ffffff";return pa(s,r)>=pa(s,n)?r:n}const en={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},tn={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},gd=[{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"}}}],To="adhdev-chat-theme",_o="adhdev-chat-theme-custom";function rr(){if(typeof window>"u")return"ember";try{return localStorage.getItem(To)||"ember"}catch{return"ember"}}function Pt(t){try{const s=localStorage.getItem(_o);if(s){const r=JSON.parse(s);return{...t==="dark"?en:tn,...r[t]}}}catch{}return t==="dark"?en:tn}function Fs(t,s){try{localStorage.setItem(_o,JSON.stringify({dark:t,light:s}))}catch{}}function Mt(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${o}, ${s})`}function ur(t,s){const r=Math.min(255,parseInt(t.slice(1,3),16)+s),n=Math.min(255,parseInt(t.slice(3,5),16)+s),o=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const yd={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function Is(t,s){var o;const r=(o=yd[t])==null?void 0:o[s];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",ur(r,24)),n.style.setProperty("--accent-on-primary",Ao(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${ur(r,18)})`),n.style.setProperty("--border-accent",Mt(r,.35)),n.style.setProperty("--nav-active-bg",Mt(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${Mt(r,.06)}`)}function Yt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Mt(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Mt(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Mt(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Mt(t.borderSubtle,.5)),s.style.setProperty("--border-default",Mt(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ur(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Ao(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ur(t.accentColor,40)})`),s.style.setProperty("--border-accent",Mt(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Mt(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Mt(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Mt(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function jn(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>t.style.removeProperty(r))}function vd(t){try{localStorage.setItem(To,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xt()?"dark":"light";Yt(Pt(s))}else jn(),Is(t,Xt()?"dark":"light")}function wd(){try{localStorage.removeItem("adhdev-accent-color")}catch{}const t=rr();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xt()?"dark":"light";Yt(Pt(s))}else jn(),Is(t,Xt()?"dark":"light")}function Xt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function ht({label:t,value:s,onChange:r}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function gs({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 jd({dark:t,onColorsChange:s}){const r=t?"dark":"light",[n,o]=a.useState(()=>Pt(r));a.useEffect(()=>{o(Pt(r))},[r]);const i=a.useCallback((c,l)=>{o(p=>{const x={...p,[c]:l},h=Pt(r==="dark"?"light":"dark");return r==="dark"?Fs(x,h):Fs(h,x),Yt(x),s(x),x})},[r,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(gs,{title:"App Background",children:[e.jsx(ht,{label:"Background",value:n.bgPrimary,onChange:c=>i("bgPrimary",c)}),e.jsx(ht,{label:"Surface",value:n.bgSecondary,onChange:c=>i("bgSecondary",c)}),e.jsx(ht,{label:"Card",value:n.surfacePrimary,onChange:c=>i("surfacePrimary",c)})]}),e.jsxs(gs,{title:"App Text",children:[e.jsx(ht,{label:"Primary",value:n.textPrimary,onChange:c=>i("textPrimary",c)}),e.jsx(ht,{label:"Secondary",value:n.textSecondary,onChange:c=>i("textSecondary",c)}),e.jsx(ht,{label:"Muted",value:n.textMuted,onChange:c=>i("textMuted",c)})]}),e.jsxs(gs,{title:"Borders & Accent",children:[e.jsx(ht,{label:"Border subtle",value:n.borderSubtle,onChange:c=>i("borderSubtle",c)}),e.jsx(ht,{label:"Border default",value:n.borderDefault,onChange:c=>i("borderDefault",c)}),e.jsx(ht,{label:"Accent",value:n.accentColor,onChange:c=>i("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(gs,{title:"Chat Bubbles",children:[e.jsx(ht,{label:"User bubble",value:n.userBubble,onChange:c=>i("userBubble",c)}),e.jsx(ht,{label:"User text",value:n.userText,onChange:c=>i("userText",c)}),e.jsx(ht,{label:"Agent bubble",value:n.assistantBubble,onChange:c=>i("assistantBubble",c)}),e.jsx(ht,{label:"Agent text",value:n.assistantText,onChange:c=>i("assistantText",c)})]}),e.jsxs(gs,{title:"Chat Layout",children:[e.jsx(ht,{label:"Chat BG",value:n.containerBg,onChange:c=>i("containerBg",c)}),e.jsx(ht,{label:"Send button",value:n.sendButton,onChange:c=>i("sendButton",c)}),e.jsx(ht,{label:"Input border",value:n.inputBorder,onChange:c=>i("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:c=>i("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?en:tn,p=Pt(t?"light":"dark");t?Fs(c,p):Fs(p,c),o(c),Yt(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 kd(){const[t,s]=a.useState(rr),[r,n]=a.useState(!0),[o,i]=a.useState(()=>Pt("dark"));a.useEffect(()=>{n(Xt());const p=new MutationObserver(()=>{const h=Xt();n(h);const g=rr();g==="custom"?Yt(Pt(h?"dark":"light")):Is(g,h?"dark":"light")});p.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),m=()=>{const h=Xt();n(h);const g=rr();g==="custom"?Yt(Pt(h?"dark":"light")):Is(g,h?"dark":"light")};return x.addEventListener("change",m),()=>{p.disconnect(),x.removeEventListener("change",m)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Yt(Pt(r?"dark":"light")):(jn(),Is(t,r?"dark":"light"))},[t,r]),a.useEffect(()=>{i(Pt(r?"dark":"light"))},[r]);const c=p=>{s(p),vd(p)},l=[...gd,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText},light:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:l.map(p=>{const x=t===p.id,m=r?p.preview.dark:p.preview.light,h=p.id==="honey"||p.id==="ember"?"#1a1a1a":p.id==="custom"?o.userText:"#fff";return e.jsxs("button",{onClick:()=>c(p.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:m.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.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:m.userBubble,color:h},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:p.id==="custom"?"🎨 Custom":p.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:p.description})]})]})]},p.id)})}),t==="custom"&&e.jsx(jd,{dark:r,onColorsChange:p=>i(p)})]})}const Po="adhdev_mobileDashboardMode_v1";function Lo(){try{return localStorage.getItem(Po)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Nd(t){try{localStorage.setItem(Po,t)}catch{}}function Sd(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Lo()==="chat")},[]),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bt,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:r=>{s(r),Nd(r?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}function Cd(t,s,r){return{...t||{},id:s,type:(t==null?void 0:t.type)||"adhdev-daemon",status:(t==null?void 0:t.status)||"online",timestamp:r.timestamp,platform:r.machine.platform,machine:{...(t==null?void 0:t.machine)||{},...r.machine}}}function Id(t,s){const{sendData:r}=St(),{injectEntries:n,getIdes:o}=ir(),i=Array.from(new Set(t.filter(Boolean))).join("|");a.useEffect(()=>{if(!(s!=null&&s.enabled)||!r)return;const c=i?i.split("|"):[];if(c.length===0)return;const l=c.map(p=>Ot.subscribe({sendData:r},p,{type:"subscribe",topic:"machine.runtime",key:`machine:${p}`,params:{intervalMs:s==null?void 0:s.intervalMs}},x=>{const m=o().find(g=>g.id===p),h=Cd(m,p,x);n([h])}));return()=>{l.forEach(p=>p())}},[i,o,n,s==null?void 0:s.enabled,s==null?void 0:s.intervalMs,r])}function Ro(t,s){const{sendData:r}=St(),[n,o]=a.useState(null),[i,c]=a.useState(!1);return a.useEffect(()=>{if(!t){o(null),c(!1);return}if(!(s!=null&&s.enabled)||!r){c(!1);return}o(null),c(!0);const l=Ot.subscribe({sendData:r},t,{type:"subscribe",topic:"session_host.diagnostics",key:`session_host:${t}`,params:{includeSessions:(s==null?void 0:s.includeSessions)!==!1,...typeof(s==null?void 0:s.limit)=="number"?{limit:s.limit}:{},...typeof(s==null?void 0:s.intervalMs)=="number"?{intervalMs:s.intervalMs}:{}}},p=>{o(p.diagnostics),c(!1)});return()=>{l()}},[t,s==null?void 0:s.enabled,s==null?void 0:s.includeSessions,s==null?void 0:s.intervalMs,s==null?void 0:s.limit,r]),{diagnostics:n,loading:i,applyDiagnostics:o}}function Md(t){return t.daemonId||(t.routeId.includes(":")?t.routeId.split(":")[0]||null:t.routeId||null)}function Eo(t){const{sendData:s}=St(),[r,n]=a.useState({});return a.useEffect(()=>{const o=Md(t);if(!o||!t.sessionId||!s){n({});return}const i=Ot.subscribe({sendData:s},o,{type:"subscribe",topic:"session.modal",key:`daemon:${o}:session-modal:${t.sessionId}`,params:{targetSessionId:t.sessionId}},c=>{n({status:c.status,modalMessage:c.modalMessage,modalButtons:c.modalButtons})});return()=>{i()}},[t.daemonId,t.routeId,t.sessionId,s]),r}const Do="adhdev_hiddenTabs";function Ad(){try{const t=localStorage.getItem(Do);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function os(t){try{localStorage.setItem(Do,JSON.stringify([...t]))}catch{}}function Td(){const[t,s]=a.useState(Ad),r=a.useCallback(x=>{s(m=>{const h=new Set(m);return h.has(x)?h.delete(x):h.add(x),os(h),h})},[]),n=a.useCallback(x=>{s(m=>{if(m.has(x))return m;const h=new Set(m);return h.add(x),os(h),h})},[]),o=a.useCallback(x=>{s(m=>{if(!m.has(x))return m;const h=new Set(m);return h.delete(x),os(h),h})},[]),i=a.useCallback(()=>{s(x=>{if(x.size===0)return x;const m=new Set;return os(m),m})},[]),c=a.useCallback((x,m)=>{s(h=>{const g=new Set(h);for(const S of m)g.add(S);return os(g),g})},[]),l=a.useCallback((x,m)=>{s(h=>{const g=new Set(h);for(const S of m)g.delete(S);return os(g),g})},[]),p=a.useCallback(x=>t.has(x),[t]);return{hiddenTabs:t,toggleTab:r,hideTab:n,showTab:o,showAllTabs:i,hideAllForDaemon:c,showAllForDaemon:l,isHidden:p}}function _d({visibleConversations:t,clearedTabs:s,setClearedTabs:r,setActionLogs:n}){a.useEffect(()=>{Kl()},[]);const o=a.useMemo(()=>t.map(i=>({id:i.tabKey,name:ho(i),status:i.status,activeModal:i.modalMessage?{message:i.modalMessage,buttons:i.modalButtons}:null})),[t]);return Ol(o),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{r(l=>{const p=Date.now(),x={};for(const[m,h]of Object.entries(l))p-h<5e3&&(x[m]=h);return Object.keys(x).length===Object.keys(l).length?l:x})},5500);return()=>clearTimeout(c)},[s,r]),a.useEffect(()=>{const i=setInterval(()=>{const c=Date.now()-3e5;n(l=>{const p=l.filter(x=>x.timestamp>c).slice(-100);return p.length===l.length?l:p})},6e4);return()=>clearInterval(i)},[n]),null}function Pd(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(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1];return Pd(s==null?void 0:s.receivedAt)||0}function sn(t,s=0){return Jt(t)||t.lastUpdated||s||0}function $o(t){return Jt(t)||t.lastUpdated||0}function Bo(t,s,r=$o){const n=r(s)-r(t);if(n!==0)return n;const o=(t.machineName||"").localeCompare(s.machineName||"");if(o!==0)return o;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const c=t.displaySecondary.localeCompare(s.displaySecondary);return c!==0?c:t.tabKey.localeCompare(s.tabKey)}function rn(t){var r;const s=bt(t.status,{activeModal:(r=t.modalButtons)!=null&&r.length?{buttons:t.modalButtons}:null});return s==="generating"||s==="waiting_approval"}function Ld(t){var s;return t.messages.length===0&&!((s=t.modalButtons)!=null&&s.length)&&!rn(t)&&!t.title.trim()}function Rd(t){return t.length===0?null:[...t].sort((s,r)=>{const n=Number(rn(r))-Number(rn(s));if(n!==0)return n;const o=r.messages.length-s.messages.length;return o!==0?o:Bo(s,r)})[0]||null}function Rt(t,s){const r=t.filter(c=>c.routeId===s);if(r.length===0)return null;const n=r.find(c=>c.streamSource==="native")||null,o=r.filter(c=>c.streamSource==="agent-stream"),i=Rd(o);return n?i&&Ld(n)?i:n:i||r[0]||null}function Ed(t){const s=t.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of s){const o=r.get(n.id);if(!o){r.set(n.id,n);continue}const i=(o.workspace?1:0)+(o.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>i||(n.timestamp||0)>(o.timestamp||0))&&r.set(n.id,n)}return Array.from(r.values())}function Vs(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Dd(t,s){const r=Date.now();return t.map(n=>{const o=s[n.tabKey];return o&&r-o<5e3?{...n,messages:[],title:""}:n})}function $d(t,s){const r=[],n=t.sessionId||t.instanceId;r.push({key:t.id,ref:s[t.id]}),n&&r.push({key:n,ref:s[n]});for(const o of t.childSessions||[]){const i=o.id||o.providerType,c=`${t.id}:${i}`;r.push({key:c,ref:s[c]}),r.push({key:o.id,ref:s[o.id]})}return r}function Bd(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].key!==s[r].key||t[r].ref!==s[r].ref)return!1;return!0}function Kd(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Wd(t){const s=Kd(t);if(!s)return`empty:${t.messages.length}`;if(s.id)return`id:${String(s.id)}`;if(s._localId)return`local:${String(s._localId)}`;const r=String(s.role||""),n=ts(s.content).slice(0,240);return`${t.messages.length}:${r}:${n}`}function Od({ides:t,connectionStates:s,localUserMessages:r,clearedTabs:n,hiddenTabs:o}){const i=a.useRef([]),c=a.useRef([]),l=a.useRef([]),p=a.useRef([]),x=a.useMemo(()=>{const f=Ed(t);return Vs(i.current,f)?i.current:(i.current=f,f)},[t]),m=a.useMemo(()=>yo(t),[t]),h=a.useRef(new Map),g=a.useRef(new Map),S=a.useMemo(()=>{const f=new Map,j=[];for(const E of x){const{connectionState:W="new",machineName:T}=vo(E,{machineNames:m,connectionStates:s,defaultConnectionState:"new"}),V=$d(E,r),R=h.current.get(E.id);if(R&&R.ide===E&&R.connectionState===W&&R.machineName===T&&Bd(R.localRefs,V)){f.set(E.id,R),j.push(...R.conversations);continue}const w=yn(E,r,{machineNames:m,connectionStates:s,defaultConnectionState:"new"}),B={ide:E,connectionState:W,machineName:T,localRefs:V,conversations:w};f.set(E.id,B),j.push(...w)}h.current=f;const v=new Map,k=E=>{const W=Wd(E),T=g.current.get(E.tabKey);if(T&&T.signature===W)return v.set(E.tabKey,T),T.timestamp;const V={signature:W,timestamp:$o(E)||(T==null?void 0:T.timestamp)||0};return v.set(E.tabKey,V),V.timestamp},$=[...j].sort((E,W)=>Bo(E,W,k));return g.current=v,$},[x,r,s,m]),I=a.useMemo(()=>{const f=Dd(S,n);return Vs(c.current,f)?c.current:(c.current=f,f)},[S,n]),u=a.useMemo(()=>{const f=new Map,j=Array.from(new Set(I.map(v=>v.routeId)));for(const v of j){const k=Rt(I,v);k&&f.set(v,k)}return f},[I]),b=a.useMemo(()=>{const f=new Map;for(const j of I)if(j.sessionId&&f.set(j.sessionId,j),j.streamSource==="native"&&j.sessionId){const v=u.get(j.routeId);v&&f.set(j.sessionId,v)}return f},[I,u]),y=a.useMemo(()=>{const f=new Map;for(const j of I)j.sessionId&&f.set(j.sessionId,j),f.set(j.routeId,u.get(j.routeId)||j),f.set(j.tabKey,j);return f},[I,u]),d=a.useCallback(f=>{if(f)return b.get(f)},[b]),C=a.useCallback(f=>{if(f)return y.get(f)},[y]),M=a.useMemo(()=>{const f=I.filter(j=>!o.has(j.tabKey));return Vs(l.current,f)?l.current:(l.current=f,f)},[I,o]),N=a.useMemo(()=>{const f=M.map(j=>j.tabKey);return Vs(p.current,f)?p.current:(p.current=f,f)},[M]);return{chatIdes:x,conversations:I,visibleConversations:M,visibleTabKeys:N,resolveConversationBySessionId:d,resolveConversationByTarget:C}}function Hd({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:r,setSearchParams:n}){const o=a.useMemo(()=>{var l;return t||!s?null:((l=r(s))==null?void 0:l.tabKey)??null},[t,r,s]),i=a.useMemo(()=>{var l;return!t||!s?null:((l=r(s))==null?void 0:l.tabKey)??null},[t,r,s]),c=a.useCallback(()=>{s&&n(l=>{const p=new URLSearchParams(l);return p.delete("activeTab"),p},{replace:!0})},[n,s]);return{requestedDesktopTabKey:o,requestedMobileTabKey:i,consumeRequestedActiveTab:c}}function Ud({ides:t,sendDaemonCommand:s,setToasts:r,setLocalUserMessages:n,resolveConversationByTarget:o}){a.useEffect(()=>{gt.setIdes(t)},[t]),a.useEffect(()=>{gt.setResolveAction((i,c,l)=>{s(i,c,l).catch(()=>{})})},[s]),a.useEffect(()=>{const i=gt.onToast(p=>{r(m=>m.some(g=>g.message===p.message&&p.timestamp-g.timestamp<3e3)?m:[...m.slice(-4),{id:p.id,message:p.message,type:p.type,timestamp:p.timestamp,targetKey:p.targetKey,actions:p.actions}]);const x=p.duration||5e3;setTimeout(()=>r(m=>m.filter(h=>h.id!==p.id)),x)}),c=gt.onSystemMessage((p,x)=>{var S,I;const m=o(p),h=(S=x._localId)==null?void 0:S.startsWith("sys_approval_"),g=!!(m&&(m.status==="waiting_approval"||(I=m.modalButtons)!=null&&I.length||m.modalMessage));h&&g||n(u=>({...u,[p]:[...u[p]||[],x]}))}),l=gt.onClearSystemMessage((p,x)=>{n(m=>{var h;return(h=m[p])!=null&&h.length?{...m,[p]:m[p].filter(g=>{var S;return!(g.role==="system"&&((S=g._localId)!=null&&S.startsWith(x)))})}:m})});return()=>{i(),c(),l()}},[r,n]),a.useEffect(()=>{const i=mo.on("status_event",c=>{gt.handleRawEvent(c,"ws")});return()=>{i()}},[]),a.useEffect(()=>{var c;const i=l=>{var b;const p=l.data;if((p==null?void 0:p.type)!=="notification_action"||typeof p.action!="string"||!p.action.startsWith("approval_")||!(p.daemonId||p.targetSessionId||p.targetKey))return;const x=p.targetSessionId||p.targetKey||p.daemonId,m=o(x),h=(m==null?void 0:m.routeId)||p.daemonId;if(!h)return;const g=Number(p.buttonIndex),S=p.button||((b=m==null?void 0:m.modalButtons)==null?void 0:b[g])||"Approve",I=String(S).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),u=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(I);s(h,"resolve_action",{action:u?"approve":"reject",button:S,...Number.isFinite(g)&&{buttonIndex:g},...(m==null?void 0:m.sessionId)&&{targetSessionId:m.sessionId},...p.targetSessionId&&{targetSessionId:p.targetSessionId}}).catch(y=>console.error("[SW Action] approval failed:",y))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",i),()=>{var l;return(l=navigator.serviceWorker)==null?void 0:l.removeEventListener("message",i)}},[o,s])}const zd="adhdev_dashboardLayout_v1",Fd="adhdev_dashboardDockview_v1",Vd="adhdev_dashboardDockviewHiddenRestore_v1",ys={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function kn(t,s){try{const r=localStorage.getItem(t);return r?JSON.parse(r):s}catch{return s}}function Ko(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Wo(t){return`${zd}:${t}`}function qd(t){const s=Wo(t);return kn(s,null)}function Gd(t,s){try{const r=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,n=Wo(t);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Oo(t){return`${Fd}:${t}`}function Yd(t){const s=Oo(t);return kn(s,null)}function Xd(t,s){try{const r=Oo(t);if(!s){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Ho(t){return`${Vd}:${t}`}function Jd(t){const s=Ho(t);return kn(s,{})}function Zd(t,s){try{const r=Ho(t);if(Object.keys(s).length===0){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Qd(){return{groupAssignments:[...ys.groupAssignments],focusedGroup:ys.focusedGroup,groupActiveTabIds:{...ys.groupActiveTabIds},groupTabOrders:{...ys.groupTabOrders},groupSizes:[...ys.groupSizes]}}function eu(){const[t]=a.useState(()=>Ko(typeof window<"u"?window.innerWidth:1280)),[s,r]=a.useState(()=>new Map),[n,o]=a.useState(0),[i,c]=a.useState({}),[l,p]=a.useState({}),[x,m]=a.useState([]),[h,g]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[S,I]=a.useState(!1),u=a.useCallback(()=>{if(S)return;const b=qd(t)??Qd();r(new Map(b.groupAssignments)),o(b.focusedGroup),c(b.groupActiveTabIds),p(b.groupTabOrders),m(b.groupSizes),I(!0)},[S,t]);return a.useEffect(()=>{S&&Gd(t,{groupAssignments:[...s.entries()],focusedGroup:n,groupActiveTabIds:i,groupTabOrders:l,groupSizes:x})},[S,t,s,n,i,l,x]),a.useEffect(()=>{const b=window.matchMedia("(max-width: 767px)"),y=d=>g(d.matches);return b.addEventListener("change",y),()=>b.removeEventListener("change",y)},[]),{groupAssignments:s,setGroupAssignments:r,focusedGroup:n,setFocusedGroup:o,groupActiveTabIds:i,setGroupActiveTabIds:c,groupTabOrders:l,setGroupTabOrders:p,groupSizes:x,setGroupSizes:m,isMobile:h,hasHydratedStoredLayout:S,hydrateStoredLayout:u}}function tu(t,s){if(!Array.isArray(t)||t.length!==1||!s)return!1;const r=t[0],n=[s.providerSessionId,s.sessionId].filter(o=>typeof o=="string"&&o.length>0);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function su({urlActiveTab:t,conversations:s,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:o,hydrateStoredLayout:i,setGroupActiveTabIds:c,setFocusedGroup:l,setSearchParams:p,historyModalOpen:x,activeConv:m,isRefreshingHistory:h,ides:g,handleRefreshHistory:S}){const I=a.useRef(!1),u=a.useRef(!1),b=a.useRef(null),y=a.useRef(!1);a.useEffect(()=>{if(!t||I.current||s.length===0)return;if(!o){i();return}const d=r(t);if(!d)return;const C=n.get(d.tabKey)??0;c(M=>({...M,[C]:d.tabKey})),l(C),I.current=!0,u.current=!0,b.current!=null&&(window.clearTimeout(b.current),b.current=null),p(M=>{const N=new URLSearchParams(M);return N.delete("activeTab"),N},{replace:!0})},[t,s,r,n,o,i,c,l,p]),a.useEffect(()=>{if(!(u.current||o)&&s.length!==0){if(!t){i(),u.current=!0;return}if(I.current){u.current=!0;return}if(b.current==null)return b.current=window.setTimeout(()=>{b.current=null,!(u.current||o)&&(i(),u.current=!0)},1500),()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null)}}},[t,s.length,o,i]),a.useEffect(()=>{if(!x){y.current=!1;return}if(!m||y.current||h)return;const d=g.find(C=>C.id===m.routeId);d&&(!d.chats||d.chats.length===0||tu(d.chats,m))&&(y.current=!0,S())},[x,m,h,g,S]),a.useEffect(()=>{if(!m)return;let d=null,C=0,M=-1,N=0;const f=()=>{d=null;const j=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(k=>k.offsetParent!==null);if(j.length===0){C<18&&(C+=1,d=requestAnimationFrame(f));return}let v=0;for(const k of j)k.scrollTop=k.scrollHeight,v+=k.scrollHeight;v===M?N+=1:(N=0,M=v),C+=1,!(N>=2||C>=18)&&(d=requestAnimationFrame(f))};return d=requestAnimationFrame(f),()=>{d!=null&&cancelAnimationFrame(d)}},[m==null?void 0:m.tabKey])}function ru({isMobile:t,location:s,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:o,conversations:i,ides:c,resolveConversationByTarget:l}){const[p,x]=a.useState(null),[m,h]=a.useState(null),g=a.useMemo(()=>{if(t||!n)return null;const y=l(n);return y&&!Ge(y)&&!qe(y)?y:null},[t,n,l]),S=a.useMemo(()=>{const y=p==null?void 0:p.routeId;if(!y)return null;const d=p!=null&&p.tabKey?i.find(C=>C.tabKey===p.tabKey):o?i.find(C=>C.tabKey===o):null;return(d==null?void 0:d.routeId)===y?d:Rt(i,y)},[i,p,o]),I=a.useMemo(()=>{if(S)return c.find(y=>y.id===S.routeId)},[c,S]);a.useEffect(()=>{g&&(x({routeId:g.routeId,tabKey:Xn(g)}),h(g),r({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,r,g]);const u=a.useCallback(y=>{y&&(x({routeId:y.routeId,tabKey:Xn(y)}),h(y))},[]),b=a.useCallback(()=>{x(null),h(null)},[]);return{remoteDialogConv:S,remoteDialogIdeEntry:I,remoteDialogActiveConv:m,setRemoteDialogActiveConv:h,openRemoteDialog:u,closeRemoteDialog:b}}function ds(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return t.sessionId?s:Ge(t)||qe(t)?{agentType:jt(t)}:t.streamSource==="agent-stream"?{agentType:jt(t)}:s}function Rs(t){return t?cr(t):""}function vs(t,s){t(r=>[...r,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Er(t,s){if(!Array.isArray(t)||t.length!==1||!s)return!1;const r=t[0];if((r==null?void 0:r.active)===!0)return!0;const n=[s.providerSessionId,s.sessionId].filter(o=>typeof o=="string"&&o.length>0);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function ma({sendDaemonCommand:t,activeConv:s,chats:r,updateRouteChats:n,setToasts:o,setLocalUserMessages:i,setClearedTabs:c}){const[l,p]=a.useState(!1),[x,m]=a.useState(!1),h=a.useCallback(async u=>{try{await t("standalone","launch_ide",{ideType:u,enableCdp:!0})}catch(b){console.error("Launch failed",b)}},[t]),g=a.useCallback(async(u,b)=>{try{const y=u||(s==null?void 0:s.daemonId)||"",d=await t(y,"switch_chat",{id:b,sessionId:b,...ds(s)}),C=d==null?void 0:d.result;if((d==null?void 0:d.success)===!0||C==="switched"||C==="switched-by-title")return;C===!1||C==="not_found"?vs(o,"⚠️ Session tab not found — try refreshing history"):typeof C=="string"&&C.startsWith("error:")?vs(o,`⚠️ Switch error: ${C}`):vs(o,"⚠️ Session switch failed")}catch(y){console.error("Switch failed",y),vs(o,`❌ Switch failed: ${y.message||"connection error"}`)}},[s,t,o]),S=a.useCallback(async()=>{if(!(!s||l)){p(!0);try{const u=Rs(s);await t(u,"new_chat",{...ds(s)}),c(b=>({...b,[s.tabKey]:Date.now()})),i(b=>({...b,[s.tabKey]:[]}))}catch(u){console.error("New chat failed",u)}finally{p(!1)}}},[s,l,t,c,i]),I=a.useCallback(async()=>{var u,b;if(!(!s||x)){m(!0);try{const y=Rs(s),d=async()=>t(y,"list_chats",{forceExpand:!0,...ds(s)});let C=await d(),M=(C==null?void 0:C.chats)||((u=C==null?void 0:C.result)==null?void 0:u.chats);Er(M,s)&&(await new Promise(N=>setTimeout(N,450)),C=await d(),M=(C==null?void 0:C.chats)||((b=C==null?void 0:C.result)==null?void 0:b.chats)),C!=null&&C.success&&Array.isArray(M)&&(n(s.routeId,M),Er(M,s)&&!Er(r,s)&&vs(o,"⚠️ History dialog did not fully open — try once more"))}catch(y){console.error("Refresh history failed",y)}finally{m(!1)}}},[s,r,x,t,n,o]);return{isCreatingChat:l,isRefreshingHistory:x,handleLaunchIde:h,handleSwitchSession:g,handleNewChat:S,handleRefreshHistory:I}}function nu(t,s){if(t.size!==s.size)return!1;for(const[r,n]of t)if(s.get(r)!==n)return!1;return!0}function au(t,s){return t.length!==s.length?!1:t.every((r,n)=>r===s[n])}function fa(t,s){const r=Object.keys(t),n=Object.keys(s);return r.length!==n.length?!1:r.every(o=>s[Number(o)]===t[Number(o)])}function qs(t,s){const r=new Set(s),n=s.length>0?[0]:[];for(const[c,l]of t)!r.has(c)||l<=0||n.includes(l)||n.push(l);n.sort((c,l)=>c-l);const o={};n.forEach((c,l)=>{o[c]=l}),n.length===0&&(o[0]=0);const i=new Map;for(const[c,l]of t){if(!r.has(c)||l<=0)continue;const p=o[l];typeof p=="number"&&p>0&&i.set(c,p)}return{assignments:i,groupCount:Math.max(1,n.length),mapping:o,usedGroups:n}}function xa(t,s){const r={};for(const[n,o]of Object.entries(t)){const i=s[Number(n)];typeof i=="number"&&(r[i]=o)}return r}function ou(t,s,r){if(s.length===0)return 0;if(typeof r[t]=="number")return r[t];const n=[...s].reverse().find(o=>o<t)??s[0];return r[n]??0}function iu(t,s,r){if(s.length<=1)return[];const n=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),o=n.length===s.length?n:Array(r).fill(100/r),i=o.reduce((c,l)=>c+l,0);return i>0?o.map(c=>c/i*100):Array(r).fill(100/r)}function ha(t,s){const r={};for(const[n,o]of Object.entries(t)){const i=Number(n);r[i>=s?i+1:i]=o}return r}function ba(t){return Array(t).fill(100/t)}function cu({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:r,setGroupActiveTabIds:n,setGroupTabOrders:o,groupSizes:i,setGroupSizes:c,isMobile:l,visibleConversations:p,visibleTabKeys:x}){const m=a.useRef(null),h=a.useMemo(()=>qs(t,x),[t,x]),g=h.assignments,S=a.useMemo(()=>l?1:h.groupCount,[h.groupCount,l]),I=S>1,u=a.useCallback((N,f)=>{s(j=>{const v=new Map(qs(j,x).assignments);return f===0?v.delete(N):v.set(N,f),v}),n(j=>({...j,[f]:N})),r(f)},[s,x,n,r]),b=a.useCallback(N=>{s(f=>{const j=qs(f,x).assignments,v=new Map;for(const[k,$]of j)$!==N&&($>N?v.set(k,$-1):v.set(k,$));return v}),c(f=>{if(f.length<=1)return[];const j=[...f];j.splice(N,1);const v=j.reduce((k,$)=>k+$,0);return v>0?j.map(k=>k/v*100):[]}),r(0)},[s,x,c,r]),y=a.useCallback((N,f)=>{f.preventDefault();const j=m.current;if(!j)return;const v=f.clientX,k=j.offsetWidth,$=i.length===S?[...i]:ba(S),E=T=>{const R=(T.clientX-v)/k*100,w=[...$];w[N]=Math.max(15,$[N]+R),w[N+1]=Math.max(15,$[N+1]-R),c(w)},W=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",E),document.addEventListener("mouseup",W)},[i,S,c]),d=a.useCallback((N,f,j)=>{if(S>=4)return;const v=j==="left"?f:f+1;s(k=>{const $=qs(k,x).assignments,E=new Map;for(const W of p){const T=$.get(W.tabKey)??0,V=T>=v?T+1:T;V>0&&E.set(W.tabKey,V)}return v>0&&E.set(N,v),E}),c(k=>{const $=k.length===S?[...k]:ba(S),E=$[f]??100/S,W=Math.max(15,E/2),T=Math.max(15,E/2),V=[...$];V[f]=W,V.splice(v,0,T);const R=V.reduce((w,B)=>w+B,0);return V.map(w=>w/R*100)}),n(k=>{const $=ha(k,v);return $[v]=N,$}),o(k=>{const $=ha(k,v);return $[v]=[N],$}),r(v)},[S,s,x,p,c,n,o,r]);a.useEffect(()=>{nu(t,g)||s(g)},[t,g,s]),a.useEffect(()=>{const{mapping:N,usedGroups:f}=h;n(j=>{const v=xa(j,N);return fa(j,v)?j:v}),o(j=>{const v=xa(j,N);return fa(j,v)?j:v}),r(j=>{const v=l?0:ou(j,f,N);return j===v?j:v}),c(j=>{const v=l?[]:iu(j,f,h.groupCount);return au(j,v)?j:v})},[h,l,n,o,r,c]);const C=a.useMemo(()=>{const N=Array.from({length:S},()=>[]);for(const f of p){const j=g.get(f.tabKey)??0,v=Math.min(j,S-1);N[v].push(f)}return N},[p,g,S]),M=a.useCallback(()=>{s(new Map),r(0)},[s,r]);return{containerRef:m,normalizedGroupAssignments:g,numGroups:S,isSplitMode:I,groupedConvs:C,moveTabToGroup:u,closeGroup:b,handleResizeStart:y,splitTabRelative:d,clearAllSplits:M}}function lu({ides:t,sendDaemonCommand:s}){const r="0.8.44",n=a.useMemo(()=>t.filter(m=>m.type!=="adhdev-daemon"?!1:Mo(m,r)).sort((m,h)=>Number(Cs(h,r))-Number(Cs(m,r))),[r,t]),o=a.useMemo(()=>n.some(m=>Cs(m,r)),[r,n]),[i,c]=a.useState(!1),[l,p]=a.useState({}),x=a.useCallback(async m=>{var h,g;p(S=>({...S,[m]:"upgrading"}));try{const S=await s(m,"daemon_upgrade",{});(h=S==null?void 0:S.result)!=null&&h.upgraded||(g=S==null?void 0:S.result)!=null&&g.success?p(I=>({...I,[m]:"done"})):p(I=>({...I,[m]:"error"}))}catch{p(S=>({...S,[m]:"error"}))}},[s]);return{versionMismatchDaemons:n,hasRequiredVersionDaemons:o,appVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:c,upgradingDaemons:l,handleBannerUpgrade:x}}function ga(t){return!t||typeof t!="object"?t:t.result&&typeof t.result=="object"?t.result:t}function Nn(t){return t instanceof Error?t.message:String(t||"")}function ya(t){const s=Nn(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function va(t,s){const r=Nn(s);return r?r.toLowerCase().includes("button not found")?`⚠️ **${t}** failed — button not found`:`⚠️ **${t}** failed — ${r}`:`⚠️ **${t}** unavailable`}function yr({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:r,setActionLogs:n,isStandalone:o}){const[i,c]=a.useState(!1),[l,p]=a.useState(!1),x=a.useRef(!1),m=a.useRef(null),h=a.useCallback(async u=>{if(!s)return;const b=u.trim();if(!b||x.current)return;const y=s.tabKey,d=Date.now(),C=m.current;if(C&&C.tabKey===y&&C.message===b&&d-C.timestamp<2e3)return;x.current=!0,p(!0),m.current={tabKey:y,message:b,timestamp:d};const M=`${d}-${Math.random().toString(36).slice(2,8)}`,N={role:"user",content:b,timestamp:d,_localId:M},f=!(Ge(s)||qe(s));f&&r(j=>({...j,[y]:[...j[y]||[],N]}));try{const j=Rs(s);if(!j)return;const v=await t(j,"send_chat",{message:b,...ds(s)}),k=ga(v);if(f&&(k!=null&&k.deduplicated||(k==null?void 0:k.sent)===!1)){r($=>({...$,[y]:($[y]||[]).filter(E=>E._localId!==M)}));return}if((k==null?void 0:k.success)===!1)throw new Error((k==null?void 0:k.error)||"Send failed");setTimeout(()=>{const $=Date.now()-6e4;r(E=>{const W=E[y];if(!W)return E;const T=W.filter(V=>V.timestamp>$);return T.length===W.length?E:{...E,[y]:T}})},6e4)}catch(j){const v=Nn(j);v.toLowerCase().includes("provider sendmessage did not confirm send")?console.warn("Send not confirmed by provider script:",v):console.error("Send failed",j),f&&r(k=>({...k,[y]:(k[y]||[]).filter($=>$._localId!==M)}))}finally{x.current=!1,p(!1)}},[s,t,r]),g=a.useCallback(async()=>{if(s)try{if(!s.hostIdeType)return;await t(s.routeId,"launch_ide",{ideType:s.hostIdeType,enableCdp:!0})}catch(u){console.error("Relaunch failed",u)}},[s,t]),S=a.useCallback(async u=>{if(s)try{const y=(s.modalButtons||[]).indexOf(u),d=u.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),C=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(d),M=Rs(s);if(!M)return;const N=await t(M,"resolve_action",{button:u,action:C?"approve":"reject",...y>=0&&{buttonIndex:y},...ds(s)}),f=ga(N);f.success||n(j=>[...j,{routeId:s.tabKey,text:va(u,f==null?void 0:f.error),timestamp:Date.now()}])}catch(b){ya(b)||console.error("[ModalButton] Error:",b),n(y=>[...y,{routeId:s.tabKey,text:ya(b)?va(u,b):`❌ **${u}** error`,timestamp:Date.now()}])}},[s,t,n]),I=a.useCallback(async()=>{if(!(!s||i)){c(!0);try{await t(s.routeId,"focus_session",{...s.sessionId&&{targetSessionId:s.sessionId}})}catch(u){console.error("Focus agent failed",u)}finally{c(!1)}}},[s,i,t]);return{isSendingChat:l,isFocusingAgent:i,handleSendChat:h,handleRelaunch:g,handleModalButton:S,handleFocusAgent:I}}const Sn=a.memo(function({activeConv:s,clearToken:r,isCliTerminal:n,ideEntry:o,terminalRef:i,handleModalButton:c,handleRelaunch:l,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u=!0}){const b=Eo(s),y=b.status||b.modalMessage||b.modalButtons?{...s,...b.status?{status:b.status}:{},...b.modalMessage!==void 0?{modalMessage:b.modalMessage}:{},...b.modalButtons!==void 0?{modalButtons:b.modalButtons}:{}}:s;return e.jsxs(e.Fragment,{children:[e.jsx(so,{activeConv:y,onModalButton:c}),y.transport!=="pty"&&y.transport!=="acp"&&y.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(es,{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:l,children:"Relaunch with CDP"})]})}):null,y.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:n?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(yl,{activeConv:y,clearToken:r,terminalRef:i,handleSendChat:p,isSendingChat:x,isVisible:n})}),!n&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Jr,{activeConv:y,ideEntry:o,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u})})]}):e.jsx(Jr,{activeConv:y,ideEntry:o,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce&&t.isInputActive===s.isInputActive);function du({selectedConversation:t,isAcp:s,isStandalone:r,selectedIdeEntry:n,actionLogs:o,userName:i,isSendingChat:c,isFocusingAgent:l,onBack:p,onOpenNativeConversation:x,onOpenMachine:m,onOpenHistory:h,onOpenRemote:g,onHideConversation:S,onStopCli:I,cliViewMode:u,onSetCliViewMode:b,handleSendChat:y,handleFocusAgent:d,handleModalButton:C,handleRelaunch:M}){const N=a.useRef(null),f=Ge(t)&&!s,j=f&&u==="terminal",v=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${v} 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:p,type:"button","aria-label":"Back",children:e.jsx(cn,{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:Qe(t)}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(io,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>x(t),onOpenMachine:()=>m(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[f&&u&&e.jsx(bn,{mode:u,onChange:b,compact:!0}),f&&I&&e.jsx("button",{onClick:()=>{I(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(wt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",children:e.jsx(dn,{size:14})}),!s&&!f&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>g(t),type:"button",children:e.jsx(Nt,{size:14})}),S&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>S(t),type:"button",title:"Close chat",children:e.jsx(wt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Sn,{activeConv:t,clearToken:0,isCliTerminal:j,ideEntry:n,terminalRef:N,handleModalButton:C,handleRelaunch:M,handleSendChat:y,isSendingChat:c,handleFocusAgent:d,isFocusingAgent:l,actionLogs:o,userName:i})})]})}const Dr={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 uu(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Uo(){const[t,s]=a.useState("unix"),[r,n]=a.useState("powershell"),[o,i]=a.useState(!1),c=t==="unix"?"unix":r;a.useEffect(()=>{s(uu())},[]);const l=a.useCallback(()=>{navigator.clipboard.writeText(Dr[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:l,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Dr[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Dr[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:o?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function zo({section:t,onSectionChange:s}){const r=[{key:"machines",label:"Machines",icon:Nt},{key:"chats",label:"Chats",icon:Bt}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:o,icon:i})=>{const c=t===n;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(n),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(i,{size:15})}),e.jsx("span",{children:o})]},n)})})})}function Gs({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 is({children:t,className:s=""}){return e.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function ws({icon:t,title:s,subtitle:r,children:n}){return e.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Ys({item:t,type:s,getAvatarText:r,onOpenConversation:n}){const o=s==="needs_attention"||s==="task_complete",i=s==="working",c=s==="earlier",l=s==="task_complete",{isReconnecting:p,isConnecting:x}=xs(t.conversation),m=Qe(t.conversation),h=rs(t.conversation),g=xo(t.conversation,{requiresAction:s==="needs_attention"}),S=o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":c?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",I=o?"bg-accent-primary shadow-glow":i?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":c?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",u=c?"text-text-secondary":"text-text-primary",b=c?"text-text-muted":"text-text-secondary",y=c?"text-text-secondary opacity-80":"text-text-muted",d=c?"text-text-muted opacity-80":"text-text-muted",C="text-[color:var(--status-warning)]";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] ${S}`,onClick:()=>n(t.conversation),type:"button",children:[o||i?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}`,style:o?{color:"var(--accent-on-primary)"}:void 0,children:r(m)}),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 truncate tracking-tight ${u}`,children:m}),!i&&e.jsx("span",{className:`text-[11px] font-medium shrink-0 ${d}`,children:to(t.timestamp)})]}),e.jsxs("div",{className:`text-[12px] font-medium truncate flex items-center ${b}`,children:[h,p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:`${C} animate-pulse`,children:"Reconnecting…"})]}):x?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-text-muted",children:"Connecting…"})]}):g==="Action needed"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:C,children:"Action needed"})]})]}),e.jsx("div",{className:`mt-0.5 truncate text-[13px] ${y}`,children:t.preview})]}),o&&!l&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),l&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Done"}),i&&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 wa({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 pu({section:t,attentionItems:s,unreadItems:r,workingItems:n,completedItems:o,hiddenConversations:i,machineCards:c,getAvatarText:l,onOpenConversation:p,onShowConversation:x,onShowAllHidden:m,onOpenNewSession:h,onOpenMachine:g,onOpenSettings:S,onSectionChange:I,wsStatus:u="connected",isStandalone:b=!1}){const y=u==="disconnected"||u==="reconnecting"||u==="offline"||u==="auth_failed",d=c.length>0,C=s.length>0||r.length>0||n.length>0||o.length>0,M=t==="machines"?"Machines":"Chats",N=b?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",f=b?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]";return e.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${N}`,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:M}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||r.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(hr,{size:13}),e.jsx("span",{children:s.length+r.length})]}),e.jsx("button",{onClick:S,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(fr,{size:18})})]})]})}),e.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${f}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:y?e.jsx(ws,{icon:e.jsx(wa,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:u==="offline"?"Your device appears to be offline. Waiting for network…":u==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(ws,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:b?"Waiting for your daemon":"Connect your first machine",subtitle:b?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!b&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Uo,{})})}):e.jsx(is,{children:c.map((j,v)=>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] ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>g(j.id),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:l(j.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:j.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[j.unread," new"]}):j.total>0?`${j.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:j.subtitle}),j.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[j.total," chat",j.total!==1?"s":"",j.unread>0?` · ${j.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},j.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Needs attention",className:"mb-0"}),e.jsx(is,{children:s.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"needs_attention",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(is,{children:r.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"task_complete",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(is,{children:n.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"working",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[o.length>0&&e.jsx(Gs,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),o.length>0?e.jsx(is,{children:o.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"earlier",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))}):C?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):y?e.jsx(ws,{icon:e.jsx(wa,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):d?e.jsx(ws,{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(Bt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are available. Open a machine, wait for P2P to connect, then launch your first IDE, CLI, or ACP session."}):e.jsx(ws,{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"&&i.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:m,children:"Restore all"})]}),e.jsx(is,{className:"bg-bg-secondary/25",children:i.map((j,v)=>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 ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(j),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-border-subtle text-text-secondary",children:l(Qe(j))}),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:Qe(j)}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:rs(j)}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},j.tabKey))})]})]}),t==="chats"&&h&&e.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:h,"aria-label":"Start new session",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx(zo,{section:t,onSectionChange:I})]})}function mu(t){const s=t.trim();if(!s)return null;if(s.startsWith("~"))return s;if(/^[A-Za-z]:$/.test(s))return`${s[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(s))return`${s[0].toUpperCase()}:${s.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(s))return`${s[0].toUpperCase()}:\\${s.slice(2).replace(/[\\/]+/g,"\\")}`;const r=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),o=(r[2]||"").replace(/[\\/]+/g,"\\");return o?`${n}:\\${o}`:`${n}:\\`}return null}function vr(t,s=[]){if(t==="win32"){for(const r of s){if(typeof r!="string")continue;const n=mu(r);if(n)return n}return"C:\\"}for(const r of s){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function fu(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const r=s.includes("\\")?"\\":"/",n=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}async function wr(t,s,r){const n=await t(s,"file_list_browse",{path:r});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Could not browse folder");const o=typeof(n==null?void 0:n.path)=="string"?n.path:r,i=o.includes("\\")?"\\":"/",c=(p,x)=>/^[A-Za-z]:\\?$/.test(p)?`${p.replace(/\\?$/,"\\")}${x}`:p==="/"||p==="\\"?`${i}${x}`:`${p.replace(/[\\/]+$/,"")}${i}${x}`,l=Array.isArray(n==null?void 0:n.files)?n.files.filter(p=>(p==null?void 0:p.type)==="directory"&&typeof(p==null?void 0:p.name)=="string").map(p=>({name:p.name,path:c(o,p.name)})).sort((p,x)=>p.name.localeCompare(x.name)):[];return{path:o,directories:l}}function jr({title:t,description:s,currentPath:r,directories:n,busy:o=!1,error:i="",confirmLabel:c="Use this folder",onClose:l,onNavigate:p,onConfirm:x}){const[m,h]=a.useState(r);a.useEffect(()=>{h(r)},[r]);const g=fu(r),S=m.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:l,"aria-label":"Close folder browser",children:e.jsx(wt,{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:()=>{!g||o||p(g)},disabled:!g||o,children:[e.jsx(cn,{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:m,onChange:I=>h(I.target.value),onKeyDown:I=>{I.key!=="Enter"||!S||o||(I.preventDefault(),p(S))},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:()=>{!S||o||p(S)},disabled:!S||o,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:o?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):i?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:i}):n.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:n.map(I=>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:()=>p(I.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(us,{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:I.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:I.path})]})]},I.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:l,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>x(S||r),disabled:!S&&!r||o,children:c})]})]})})}function Cn({title:t,description:s,details:r,workspaceOptions:n,selectedWorkspaceKey:o,onWorkspaceChange:i,confirmLabel:c="Launch",busy:l=!1,showArgsInput:p,argsValue:x,onArgsChange:m,showModelInput:h,modelValue:g,onModelChange:S,historyProviderNode:I,onConfirm:u,onCancel:b}){const y=n==null?void 0:n.find(d=>d.key===o);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:b,"aria-label":"Close launch confirmation",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n&&n.length>0&&i&&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:o||"",onChange:d=>i(d.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:l,children:n.map(d=>e.jsx("option",{value:d.key,children:d.label},d.key))}),(y==null?void 0:y.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:y.description})]}),I,r.map(d=>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:d.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:d.value})]},`${d.label}:${d.value}`)),h&&S&&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:"Language Model (Optional)"}),e.jsx("input",{type:"text",value:g||"",onChange:d=>S(d.target.value),placeholder:"Auto-detect or default",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:l})]}),p&&m&&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:"CLI Arguments (Optional)"}),e.jsx("input",{type:"text",value:x||"",onChange:d=>m(d.target.value),placeholder:"e.g. --experimental",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:l})]})]}),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:b,disabled:l,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:u,disabled:l,children:[e.jsx(un,{size:14}),l?"Launching…":c]})]})]})})}function ja(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function Zt(t){const{machine:s,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:o=!0}=t,i=[];o&&i.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const p of s.workspaces||[])i.push({key:`saved:${p.id}`,label:`${p.id===s.defaultWorkspaceId?"⭐ ":""}${ja(p.path,p.label)}`,description:p.path,workspaceId:p.id,workspacePath:p.path});const c=(r==null?void 0:r.trim())||"",l=c?(s.workspaces||[]).find(p=>p.path===c):null;if(c&&!l&&i.push({key:`custom:${c}`,label:ja(c),description:c,workspaceId:null,workspacePath:c}),n){const p=`saved:${n}`;if(i.some(x=>x.key===p))return{options:i,selectedKey:p}}return l?{options:i,selectedKey:`saved:${l.id}`}:c?{options:i,selectedKey:`custom:${c}`}:{options:i,selectedKey:"__home__"}}function $r(t,s,r){return t?"ide":s>0?"cli":r>0?"acp":null}function xu({selectedMachineEntry:t,cliProviders:s,acpProviders:r,machineAction:n,onBrowseDirectory:o,onListSavedSessions:i}){var fe,F,xe,Ie;const c=Bs(),[l,p]=a.useState(!1),x=(((fe=t.detectedIdes)==null?void 0:fe.length)||0)>0,m=a.useMemo(()=>(t.workspaces||[]).map(ge=>({id:ge.id,path:ge.path,label:ge.label})),[t]),h=t.defaultWorkspaceId||null,[g,S]=a.useState(h||((F=m[0])==null?void 0:F.id)||""),[I,u]=a.useState(""),[b,y]=a.useState(""),[d,C]=a.useState([]),[M,N]=a.useState(!1),[f,j]=a.useState(""),[v,k]=a.useState(!1),[$,E]=a.useState($r(x,s.length,r.length)),W=a.useRef(null),[T,V]=a.useState(null),R=a.useRef("__home__"),[w,B]=a.useState("__home__"),[ee,L]=a.useState(""),[D,O]=a.useState(""),[z,Q]=a.useState(""),[re,je]=a.useState([]),[Y,ne]=a.useState(!1),[_,pe]=a.useState(!1),me=a.useRef(null);a.useEffect(()=>{(!t.workspaces||!t.availableProviders||!t.detectedIdes||!t.recentLaunches)&&c(t.id,{minFreshMs:3e4}).catch(()=>{})},[c,t]);const J=g==="__custom__"?I.trim():((xe=m.find(ge=>ge.id===g))==null?void 0:xe.path)||"",ie=g==="__custom__"&&!!J&&n.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(n.message),se=g!=="__custom__"&&((Ie=m.find(ge=>ge.id===g))==null?void 0:Ie.path)||"",he=a.useCallback(async ge=>{N(!0),j("");try{const Ee=await o(ge);y(Ee.path),u(Ee.path),C(Ee.directories)}catch(Ee){j(Ee instanceof Error?Ee.message:"Could not load folder")}finally{N(!1)}},[o]),ce=a.useCallback(()=>{var Ee,Ke;S("__custom__"),k(!0);const ge=vr(t.platform,[I.trim(),se,(Ee=m.find(He=>He.id===h))==null?void 0:Ee.path,(Ke=m[0])==null?void 0:Ke.path]);he(ge)},[I,h,he,se,t.platform,m]),be=a.useCallback(ge=>{if(ge!=null&&ge.workspaceId){S(ge.workspaceId),u("");return}if(ge!=null&&ge.workspacePath){S("__custom__"),u(ge.workspacePath);return}S(""),u("")},[]),Z=a.useCallback(ge=>{if(S(ge),ge==="__custom__"){ce();return}u("")},[ce]),oe=a.useCallback(ge=>{S("__custom__"),u(ge)},[]),ae=a.useCallback((ge,Ee)=>{W.current=Ee,R.current=ge.selectedWorkspaceKey||"__home__",B(ge.selectedWorkspaceKey||"__home__"),L(ge.initialArgs||""),O(ge.initialModel||""),Q(""),je([]),V(ge),ge.providerType&&i&&(ne(!0),i(ge.providerType).then(Ke=>je(Ke||[])).catch(Ke=>console.warn("Failed to load saved sessions",Ke)).finally(()=>ne(!1)))},[i]),ke=a.useCallback(()=>{W.current&&(pe(!0),W.current().finally(()=>{W.current=null,pe(!1),V(null)}))},[]),we=a.useCallback(()=>{W.current=null,V(null)},[]),P=a.useCallback(ge=>{R.current=ge,B(ge)},[]);return a.useEffect(()=>{var ge;me.current!==t.id&&(me.current=t.id,S(h||((ge=m[0])==null?void 0:ge.id)||"__custom__"),u(""),y(""),C([]),j(""),k(!1),E($r(x,s.length,r.length)))},[r.length,s.length,h,x,t.id,m]),a.useEffect(()=>{var ge;g!=="__custom__"&&(g&&m.some(Ee=>Ee.id===g)||S(h||((ge=m[0])==null?void 0:ge.id)||"__custom__"))},[h,g,m]),a.useEffect(()=>{$==="ide"&&x||$==="cli"&&s.length>0||$==="acp"&&r.length>0||E($r(x,s.length,r.length))},[$,r.length,s.length,x]),{showAllRecent:l,setShowAllRecent:p,hasIdeOptions:x,workspaceRows:m,defaultWorkspaceId:h,workspaceChoice:g,customWorkspacePath:I,browseCurrentPath:b,browseDirectories:d,browseBusy:M,browseError:f,browseDialogOpen:v,activeLauncherKind:$,launchConfirm:T,launchConfirmWorkspaceKeyRef:R,launchConfirmWorkspaceKey:w,launchConfirmArgs:ee,launchConfirmModel:D,launchConfirmResumeId:z,launchConfirmSavedSessions:re,launchConfirmSessionsLoading:Y,launchConfirmBusy:_,resolvedWorkspacePath:J,canCreateMissingWorkspace:ie,openBrowseDialog:ce,loadBrowsePath:he,handleWorkspaceChoiceChange:Z,chooseCustomWorkspacePath:oe,setCustomWorkspacePath:u,setBrowseDialogOpen:k,setActiveLauncherKind:E,openLaunchConfirm:ae,handleConfirmLaunch:ke,closeLaunchConfirm:we,setWorkspaceSelectionFromOption:be,setLaunchConfirmWorkspaceKeyAndSync:P,setLaunchConfirmArgs:L,setLaunchConfirmModel:O,setLaunchConfirmResumeId:Q}}function hu({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:o,selectedMachineNeedsUpgrade:i,appVersion:c,machineAction:l,isStandalone:p,section:x,showBottomNav:m,onBack:h,onSectionChange:g,onOpenConversation:S,onOpenRecent:I,onOpenMachineDetails:u,onMachineUpgrade:b,onLaunchDetectedIde:y,onAddWorkspace:d,onBrowseDirectory:C,onLaunchWorkspaceProvider:M,onListSavedSessions:N}){const f=w=>w==="ide"?"IDE":w==="cli"?"CLI":"ACP",j=r.slice(0,4),v=s.slice(0,3),k=xu({selectedMachineEntry:t,cliProviders:n,acpProviders:o,machineAction:l,onBrowseDirectory:C,onListSavedSessions:N}),$=a.useMemo(()=>j.map(w=>({key:`recent-launch:${w.id}`,primary:w.label,secondary:`${f(w.kind)}${w.subtitle?` · ${w.subtitle}`:""}`,onClick:()=>{const{options:B,selectedKey:ee}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspacePath:w.workspace});k.openLaunchConfirm({title:`Launch ${w.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:B,selectedWorkspaceKey:ee,details:[{label:"Mode",value:f(w.kind)},...w.providerType?[{label:"Provider",value:w.providerType}]:[]]},async()=>{const L=B.find(D=>D.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(L),await I({...w,workspace:(L==null?void 0:L.workspacePath)??null})})}})),[k,I,j]),E=a.useMemo(()=>v.map(w=>({key:`recent-chat:${w.conversation.tabKey}`,primary:Qe(w.conversation),secondary:xl(w.conversation,{timestampLabel:w.timestamp?to(w.timestamp):null}),unread:w.unread,onClick:()=>S(w.conversation)})),[S,v]),W=k.showAllRecent?$:$.slice(0,4),T=$.length>0,V=E.length>0,R=p?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`flex items-center justify-between gap-3 ${R} 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:h,type:"button","aria-label":"Back",children:e.jsx(cn,{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:kt(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:[V&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:E.map(w=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${w.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:w.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:w.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:w.secondary})]},w.key))})]}),T&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:W.map(w=>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:w.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:w.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:w.secondary})]},w.key))}),$.length>4&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>k.setShowAllRecent(w=>!w),children:k.showAllRecent?"Show fewer":`Show ${$.length-4} more`})})]}),(k.hasIdeOptions||n.length>0||o.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:k.workspaceChoice,onChange:w=>k.handleWorkspaceChoiceChange(w.target.value),className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:k.workspaceRows.length>0?e.jsxs(e.Fragment,{children:[k.workspaceRows.map(w=>e.jsxs("option",{value:w.id,children:[w.id===k.defaultWorkspaceId?"⭐ ":"",br(w.path,w.label)||w.path]},w.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),k.workspaceChoice==="__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(us,{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:k.resolvedWorkspacePath||k.browseCurrentPath||"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:k.openBrowseDialog,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:()=>{k.resolvedWorkspacePath&&d(k.resolvedWorkspacePath)},disabled:!k.resolvedWorkspacePath||k.browseBusy,children:"Save as workspace"})]})]}),k.resolvedWorkspacePath&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[k.hasIdeOptions&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("ide"),children:"IDE"}),n.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("cli"),children:"CLI"}),o.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("acp"),children:"ACP"})]}),k.activeLauncherKind&&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:k.activeLauncherKind==="ide"?"Choose an IDE":k.activeLauncherKind==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:k.activeLauncherKind==="ide"?(t.detectedIdes||[]).slice(0,6).map(w=>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:B,selectedKey:ee}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspaceId:k.workspaceChoice!=="__custom__"?k.workspaceChoice:null,currentWorkspacePath:k.resolvedWorkspacePath});k.openLaunchConfirm({title:`Launch ${w.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:B,selectedWorkspaceKey:ee,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:w.name}]},async()=>{const L=B.find(D=>D.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(L),y(w.type,{workspacePath:(L==null?void 0:L.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:w.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath||"Use selected workspace"})]},w.type)):(k.activeLauncherKind==="cli"?n:o).map(w=>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 B=k.activeLauncherKind==="cli"?"cli":"acp",{options:ee,selectedKey:L}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspaceId:k.workspaceChoice!=="__custom__"?k.workspaceChoice:null,currentWorkspacePath:k.resolvedWorkspacePath});k.openLaunchConfirm({title:`Launch ${w.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${B.toUpperCase()}`,workspaceOptions:ee,selectedWorkspaceKey:L,details:[{label:"Mode",value:B.toUpperCase()},{label:"Provider",value:w.displayName}],showArgsInput:!0,showModelInput:B==="acp",initialArgs:"",initialModel:"",providerType:w.type},async()=>{const D=ee.find(O=>O.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(D),M(B,w.type,{workspaceId:(D==null?void 0:D.workspaceId)??null,workspacePath:(D==null?void 0:D.workspacePath)??null,args:k.launchConfirmArgs,model:k.launchConfirmModel,resumeSessionId:k.launchConfirmResumeId||null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[w.icon?`${w.icon} `:"",w.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath||"Use selected workspace"})]},w.type))})]}),l.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${l.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[l.message,k.canCreateMissingWorkspace&&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:()=>d(k.resolvedWorkspacePath,{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:[i&&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:b,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:u,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"})]})]})]})]}),k.browseDialogOpen&&e.jsx(jr,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:k.browseCurrentPath,directories:k.browseDirectories,busy:k.browseBusy,error:k.browseError,confirmLabel:"Use this folder",onClose:()=>k.setBrowseDialogOpen(!1),onNavigate:w=>{k.loadBrowsePath(w)},onConfirm:w=>{k.chooseCustomWorkspacePath(w),k.setBrowseDialogOpen(!1)}}),k.launchConfirm&&e.jsx(Cn,{title:k.launchConfirm.title,description:k.launchConfirm.description,details:k.launchConfirm.details,workspaceOptions:k.launchConfirm.workspaceOptions,selectedWorkspaceKey:k.launchConfirmWorkspaceKey,onWorkspaceChange:k.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:k.launchConfirm.confirmLabel,busy:k.launchConfirmBusy,showArgsInput:k.launchConfirm.showArgsInput,argsValue:k.launchConfirmArgs,onArgsChange:k.setLaunchConfirmArgs,showModelInput:k.launchConfirm.showModelInput,modelValue:k.launchConfirmModel,onModelChange:k.setLaunchConfirmModel,historyProviderNode:k.launchConfirm.providerType&&(k.launchConfirmSessionsLoading||k.launchConfirmSavedSessions.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume from history"}),k.launchConfirmSessionsLoading&&e.jsx("div",{className:"text-[10px] text-text-secondary font-medium",children:"Loading..."})]}),e.jsxs("select",{value:k.launchConfirmResumeId,onChange:w=>k.setLaunchConfirmResumeId(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:k.launchConfirmBusy||k.launchConfirmSessionsLoading,children:[e.jsx("option",{value:"",children:"Start a new session"}),k.launchConfirmSavedSessions.map(w=>e.jsxs("option",{value:w.providerSessionId,disabled:!w.canResume,children:[w.title||w.providerSessionId," ",w.canResume?"":"(workspace missing)"]},w.providerSessionId))]})]}),onConfirm:k.handleConfirmLaunch,onCancel:k.closeLaunchConfirm}),m&&e.jsx(zo,{section:x,onSectionChange:g})]})}function Fo(t){var r;const s=((r=t.p2p)==null?void 0:r.state)||"";return s==="connected"?"Connected":s==="connecting"||s==="new"||s==="checking"?"Connecting":"Offline"}function bu(t,s){if(!t)return[];const r=t.recentLaunches||[];return r.length>0?r.map(n=>({id:n.id,label:n.title||n.providerName||n.providerType,kind:n.kind,providerType:n.providerType,providerSessionId:n.providerSessionId,subtitle:n.currentModel||n.workspace||void 0,workspace:n.workspace,currentModel:n.currentModel})):s.filter(n=>n.type!=="adhdev-daemon"&&n.daemonId===t.id).map(n=>{var i,c,l,p,x;const o=Ls(n)?"cli":ls(n)?"acp":"ide";return{id:`${o}:${n.type}:${n.workspace||""}`,label:((i=n.activeChat)==null?void 0:i.title)||(Ls(n)?n.cliName||n.type:ls(n)&&n.cliName||n.type),kind:o,providerType:n.type,providerSessionId:n.providerSessionId,subtitle:ls(n)?n.currentModel||n.workspace||void 0:n.workspace||void 0,workspace:n.workspace||void 0,currentModel:n.currentModel,timestamp:((x=(p=(l=(c=n.activeChat)==null?void 0:c.messages)==null?void 0:l.at)==null?void 0:p.call(l,-1))==null?void 0:x.timestamp)||0}}).sort((n,o)=>o.timestamp-n.timestamp).map(({timestamp:n,...o})=>o)}function gu(t,s){const r=new Map;for(const n of s){const o=Ut(n.conversation),i=r.get(o);i?i.push(n):r.set(o,[n])}return t.map(n=>{const o=r.get(n.id)||[],i=[...o].sort((h,g)=>g.timestamp-h.timestamp)[0]||null,c=(i==null?void 0:i.conversation)||null,l=Xr(n),p=o.filter(h=>h.unread||h.requiresAction).length,x=Fo(n),m=[n.platform||"machine",x].filter(Boolean);return{id:n.id,label:kt(n,{fallbackId:n.id}),subtitle:m.join(" · "),unread:p,total:o.length,latestConversation:c,latestTimestamp:(i==null?void 0:i.timestamp)||0,fallbackActivityAt:l,preview:c?hl(c):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((n,o)=>{const i=n.latestTimestamp||n.fallbackActivityAt||0,c=o.latestTimestamp||o.fallbackActivityAt||0;return c!==i?c-i:n.label.localeCompare(o.label)})}function Xs(t,s){var r;if(!(typeof window>"u"))try{if(!(!!((r=import.meta.env)!=null&&r.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function yu({conversations:t,machineEntries:s,items:r,selectedConversation:n,selectedTabKey:o,screen:i,liveSessionInboxState:c,sendDaemonCommand:l,requestedActiveTabKey:p,onRequestedActiveTabConsumed:x,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:g,onRequestedMobileSectionConsumed:S,setSelectedTabKey:I,setScreen:u,setSelectedMachineId:b,setSection:y,setMachineBackTarget:d,resetMachineAction:C}){const M=a.useRef(null),N=a.useCallback(f=>{if(!(f!=null&&f.sessionId))return;const j=_s(f,c),v=Math.max(Date.now(),Jt(f),j.lastUpdated||0);Xs("mark_read:start",{tabKey:f.tabKey,sessionId:f.sessionId,displayPrimary:Qe(f),inboxBucket:j.inboxBucket,unread:j.unread,lastSeenAt:j.lastSeenAt,lastUpdated:j.lastUpdated,activityAt:Jt(f),readAt:v}),l(Ut(f)||f.routeId,"mark_session_seen",{sessionId:f.sessionId,seenAt:v}).then(k=>{Xs("mark_read:result",{tabKey:f.tabKey,sessionId:f.sessionId,result:k})}).catch(k=>{Xs("mark_read:error",{tabKey:f.tabKey,sessionId:f.sessionId,error:k instanceof Error?k.message:String(k)})})},[c,l]);return a.useEffect(()=>{var j;if(!n){u("inbox"),I(((j=t[0])==null?void 0:j.tabKey)||null),M.current=null;return}if(i!=="chat"){M.current=null;return}const f=`${n.tabKey}:${n.sessionId||""}`;M.current!==f&&(M.current=f,N(n))},[t,N,i,n,u,I]),a.useEffect(()=>{if(!p)return;const f=t.find(j=>j.tabKey===p);f&&(I(f.tabKey),u("chat"),x==null||x())},[t,x,p,u,I]),a.useEffect(()=>{if(!m)return;const f=s.find(j=>j.id===m);f&&(b(f.id),C(),y("machines"),d("inbox"),u("machine"),h==null||h())},[s,h,m,C,d,u,y,b]),a.useEffect(()=>{g&&(y(g),u("inbox"),S==null||S())},[S,g,u,y]),a.useEffect(()=>{const f=r.filter(j=>j.inboxBucket==="task_complete"||j.unread);f.length!==0&&Xs("inbox_state",{screen:i,selectedTabKey:o,items:f.map(j=>{const v=_s(j.conversation,c);return{liveState:v,tabKey:j.conversation.tabKey,sessionId:j.conversation.sessionId,displayPrimary:Qe(j.conversation),serverBucket:v.inboxBucket,computedBucket:j.inboxBucket,serverUnread:v.unread,computedUnread:j.unread,lastSeenAt:v.lastSeenAt,lastUpdated:v.lastUpdated,activityAt:Jt(j.conversation)}})})},[r,c,i,o]),{markConversationRead:N}}function vu(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function ka(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function wu(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function ju({sendDaemonCommand:t,navigate:s,ides:r,conversations:n}){const[o,i]=a.useState("idle"),[c,l]=a.useState(""),[p,x]=a.useState(null),m=a.useCallback(()=>{i("idle"),l(""),x(null)},[]),h=a.useCallback(async(d,C,M)=>{var N;try{i("loading"),l(`Launching ${C}…`);const f={ideType:C,enableCdp:!0};(N=M==null?void 0:M.workspacePath)!=null&&N.trim()&&(f.workspace=M.workspacePath.trim()),await t(d,"launch_ide",f),i("done"),l(`${C} launch requested`)}catch(f){i("error"),l(f instanceof Error?f.message:"Launch IDE failed"),console.error("Launch IDE failed",f)}},[t]),g=a.useCallback(async(d,C,M)=>{if(C.trim())try{i("loading"),l(M!=null&&M.createIfMissing?"Creating folder…":"Saving workspace…");const N=await t(d,"workspace_add",{path:C.trim(),createIfMissing:(M==null?void 0:M.createIfMissing)===!0});if(N!=null&&N.success){i("done"),l(M!=null&&M.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),l((N==null?void 0:N.error)||"Could not save workspace")}catch(N){i("error"),l(N instanceof Error?N.message:"Could not save workspace")}},[t]),S=a.useCallback(async d=>{var C,M,N,f,j,v;try{i("loading"),l("Starting daemon upgrade…");const k=await t(d,"daemon_upgrade",{});if((C=k==null?void 0:k.result)!=null&&C.alreadyLatest){i("done"),l(`Already on v${((M=k==null?void 0:k.result)==null?void 0:M.version)||"latest"}.`);return}if((N=k==null?void 0:k.result)!=null&&N.upgraded||(f=k==null?void 0:k.result)!=null&&f.success){i("done"),l(`Upgrade to v${((j=k==null?void 0:k.result)==null?void 0:j.version)||"latest"} started. Daemon is restarting…`);return}i("error"),l(((v=k==null?void 0:k.result)==null?void 0:v.error)||"Upgrade failed")}catch(k){i("error"),l(k instanceof Error?k.message:"Upgrade failed")}},[t]),I=a.useCallback(async(d,C,M,N)=>{var v,k,$;const f=Date.now(),j={machineId:d,kind:C,providerType:M,workspaceId:(N==null?void 0:N.workspaceId)||null,workspacePath:(N==null?void 0:N.workspacePath)||null,resumeSessionId:(N==null?void 0:N.resumeSessionId)||null,startedAt:f};try{i("loading"),l(`Launching ${M}…`),x(j);const E={cliType:M};(v=N==null?void 0:N.workspacePath)!=null&&v.trim()?E.dir=N.workspacePath.trim():N!=null&&N.workspaceId&&(E.workspaceId=N.workspaceId),N!=null&&N.resumeSessionId&&(E.resumeSessionId=N.resumeSessionId),(k=N==null?void 0:N.args)!=null&&k.trim()&&(E.cliArgs=N.args.trim().split(/\s+/).filter(Boolean)),($=N==null?void 0:N.model)!=null&&$.trim()&&(E.initialModel=N.model.trim());const W=await t(d,"launch_cli",E),T=(W==null?void 0:W.result)||W,V=(T==null?void 0:T.sessionId)||(T==null?void 0:T.id);if(W!=null&&W.success&&V){x(null),i("done"),l(`${M} launched`),s(`/dashboard?activeTab=${encodeURIComponent(V)}`);return}if(W!=null&&W.success){i("loading"),l(`${M} launch requested — waiting for session…`);return}x(null),i("error"),l((W==null?void 0:W.error)||(T==null?void 0:T.error)||`Could not launch ${C.toUpperCase()} workspace`)}catch(E){if(wu(E)){i("loading"),l(`${M} launch requested — waiting for session…`);return}x(null),i("error"),l(E instanceof Error?E.message:`Could not launch ${C.toUpperCase()} workspace`)}},[s,t]),u=a.useCallback(async(d,C)=>{try{const M=await t(d,"list_saved_sessions",{providerType:C,kind:"cli",limit:30}),N=(M==null?void 0:M.result)??M;return Array.isArray(N==null?void 0:N.sessions)?N.sessions:[]}catch(M){return console.error("Failed to list saved sessions on mobile:",M),[]}},[t]),b=a.useCallback(async(d,C)=>wr(t,d,C),[t]);a.useEffect(()=>{var N;if(!p)return;const d=ka(p.workspacePath),C=r.find(f=>{var W,T,V,R;if(!f||f.type==="adhdev-daemon"||vu(f.daemonId||f.id)!==p.machineId||(f.transport==="acp"?"acp":f.transport==="pty"?"cli":null)!==p.kind||String(f.agentType||f.type||"")!==p.providerType)return!1;const $=String(f.providerSessionId||"");if(p.resumeSessionId&&$)return $===p.resumeSessionId;if(d){const w=ka(f.workspace||f.runtimeWorkspaceLabel);return w?w===d:!1}return Number(f.lastUpdated||f._lastUpdate||f.timestamp||((R=(V=(T=(W=f.activeChat)==null?void 0:W.messages)==null?void 0:T.at)==null?void 0:V.call(T,-1))==null?void 0:R.timestamp)||0)>=p.startedAt-5e3});if(!C)return;const M=typeof C.sessionId=="string"&&C.sessionId?C.sessionId:typeof C.instanceId=="string"&&C.instanceId?C.instanceId:(N=n.find(f=>f.routeId===C.id))==null?void 0:N.sessionId;M&&(x(null),i("done"),l(`${p.providerType} launched`),s(`/dashboard?activeTab=${encodeURIComponent(M)}`))},[n,r,s,p]),a.useEffect(()=>{if(!p)return;const d=window.setTimeout(()=>{x(C=>!C||C.startedAt!==p.startedAt?C:(i("error"),l("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(d)},[p]);const y=a.useCallback(async(d,C)=>{if(C.kind==="ide"&&C.providerType){await h(d,C.providerType,{workspacePath:C.workspace||null});return}(C.kind==="cli"||C.kind==="acp")&&C.providerType&&await I(d,C.kind,C.providerType,{workspacePath:C.workspace||null,resumeSessionId:C.providerSessionId||null})},[h,I]);return{machineAction:{state:o,message:c},resetMachineAction:m,handleLaunchDetectedIde:h,handleAddWorkspace:g,handleMachineUpgrade:S,handleLaunchWorkspaceProvider:I,handleListSavedSessions:u,handleBrowseDirectory:b,handleOpenRecent:y}}function ku({conversations:t,selectedConversation:s,machineBackTarget:r,markConversationRead:n,resetMachineAction:o,setSelectedTabKey:i,setScreen:c,setSelectedMachineId:l,setSection:p,setMachineBackTarget:x}){const m=a.useCallback(y=>{i(y.tabKey),c("chat"),n(y)},[n,c,i]),h=a.useCallback(y=>{const d=t.find(C=>C.routeId===y.routeId&&C.streamSource==="native");d&&(i(d.tabKey),c("chat"),n(d))},[t,n,c,i]),g=a.useCallback(()=>{n(s),c("inbox")},[n,s,c]),S=a.useCallback((y,d="inbox")=>{l(y),o(),p("machines"),x(d),c("machine")},[o,x,c,p,l]),I=a.useCallback(y=>{const d=Ut(y);d&&S(d,"chat")},[S]),u=a.useCallback(()=>{o(),c(r)},[r,o,c]),b=a.useCallback(y=>{p(y),c("inbox")},[c,p]);return{openConversation:m,openNativeConversation:h,backFromConversation:g,openMachine:S,openConversationMachine:I,backFromMachine:u,changeMachineSection:b}}function Nu(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Su(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function Cu({conversations:t,hiddenConversations:s,ides:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,userName:p,requestedActiveTabKey:x,onRequestedActiveTabConsumed:m,requestedMachineId:h,onRequestedMachineConsumed:g,requestedMobileSection:S,onRequestedMobileSectionConsumed:I,onOpenHistory:u,onOpenRemote:b,onStopCli:y,wsStatus:d,isConnected:C,onShowHiddenConversation:M,onShowAllHiddenConversations:N,onHideConversation:f,onOpenNewSession:j}){const[v,k]=a.useState(()=>{var F;return((F=t[0])==null?void 0:F.tabKey)||null}),[$,E]=a.useState(()=>t[0]?"chat":"inbox"),[W,T]=a.useState("chats"),[V,R]=a.useState(null),[w,B]=a.useState("inbox"),ee=ms(),L="0.8.44",D=a.useMemo(()=>t.find(F=>F.tabKey===v)||t[0]||null,[t,v]),O=a.useMemo(()=>D?r.find(F=>F.id===D.routeId):void 0,[r,D]),z=a.useMemo(()=>!D||qe(D)||!Ge(D)?null:ps(D),[D]),Q=a.useMemo(()=>r.filter(F=>F.type==="adhdev-daemon").sort(mn),[r]),re=a.useMemo(()=>Q.find(F=>F.id===V)||null,[Q,V]),je=a.useMemo(()=>Ds(r),[r]),Y=yr({sendDaemonCommand:o,activeConv:D||void 0,setLocalUserMessages:i,setActionLogs:c,isStandalone:l}),ne=ju({sendDaemonCommand:o,navigate:ee,ides:r,conversations:t}),_=a.useMemo(()=>t.map(F=>{const xe=$==="chat"&&(D==null?void 0:D.tabKey)===F.tabKey,Ie=Ps(F,je,{hideOpenTaskCompleteUnread:!0,isOpenConversation:xe}),ge=Jt(F),Ee=fo(F);return{conversation:F,timestamp:ge,preview:Ee,unread:Ie.unread,requiresAction:Ie.requiresAction,isWorking:Ie.isWorking,inboxBucket:Ie.inboxBucket}}),[t,je,$,D]),{markConversationRead:pe}=yu({conversations:t,machineEntries:Q,items:_,selectedConversation:D,selectedTabKey:v,screen:$,liveSessionInboxState:je,sendDaemonCommand:o,requestedActiveTabKey:x,onRequestedActiveTabConsumed:m,requestedMachineId:h,onRequestedMachineConsumed:g,requestedMobileSection:S,onRequestedMobileSectionConsumed:I,setSelectedTabKey:k,setScreen:E,setSelectedMachineId:R,setSection:T,setMachineBackTarget:B,resetMachineAction:ne.resetMachineAction}),me=ku({conversations:t,selectedConversation:D,machineBackTarget:w,markConversationRead:pe,resetMachineAction:ne.resetMachineAction,setSelectedTabKey:k,setScreen:E,setSelectedMachineId:R,setSection:T,setMachineBackTarget:B}),J=a.useMemo(()=>_.filter(F=>F.requiresAction),[_]),ie=a.useMemo(()=>_.filter(F=>F.unread&&!F.requiresAction),[_]),se=a.useMemo(()=>_.filter(F=>!F.unread&&!F.requiresAction&&F.isWorking),[_]),he=a.useMemo(()=>_.filter(F=>!F.unread&&!F.requiresAction&&!F.isWorking),[_]),ce=a.useMemo(()=>re?_.filter(F=>Ut(F.conversation)===re.id):[],[_,re]),be=a.useMemo(()=>bu(re,r),[r,re]),Z=(re==null?void 0:re.version)||null,oe=!!re&&!!Z&&!0&&Z!==L,ae=a.useMemo(()=>(re==null?void 0:re.availableProviders)||[],[re]),ke=a.useMemo(()=>ae.filter(F=>F.category==="cli"&&F.installed!==!1).map(F=>({type:F.type,displayName:F.displayName||F.type,icon:F.icon})),[ae]),we=a.useMemo(()=>ae.filter(F=>F.category==="acp"&&F.installed!==!1).map(F=>({type:F.type,displayName:F.displayName||F.type,icon:F.icon})),[ae]),P=a.useMemo(()=>gu(Q,_),[_,Q]),fe=a.useCallback(async F=>{re&&await ne.handleOpenRecent(re.id,F)},[ne,re]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:$==="chat"&&D?e.jsx(du,{selectedConversation:D,isAcp:qe(D),isStandalone:l,selectedIdeEntry:O,actionLogs:n,userName:p,isSendingChat:Y.isSendingChat,isFocusingAgent:Y.isFocusingAgent,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,onBack:me.backFromConversation,onOpenNativeConversation:me.openNativeConversation,onOpenMachine:me.openConversationMachine,onHideConversation:f,onOpenHistory:u,onOpenRemote:b,onStopCli:y,cliViewMode:z,onSetCliViewMode:async F=>{if(D&&z!==F)try{await o(Ut(D)||D.routeId,"set_cli_view_mode",{targetSessionId:D.sessionId,cliType:jt(D),mode:F})}catch(xe){Su(xe)?console.warn("Skipped CLI view mode switch:",xe instanceof Error?xe.message:String(xe)):console.error("Failed to switch CLI view mode:",xe)}},handleSendChat:Y.handleSendChat,handleFocusAgent:Y.handleFocusAgent}):$==="machine"&&re?e.jsx(hu,{selectedMachineEntry:re,selectedMachineConversations:ce,selectedMachineRecentLaunches:be,cliProviders:ke,acpProviders:we,selectedMachineNeedsUpgrade:oe,appVersion:L,machineAction:ne.machineAction,isStandalone:l,section:W,showBottomNav:w==="inbox",onBack:me.backFromMachine,onSectionChange:me.changeMachineSection,onOpenConversation:me.openConversation,onOpenRecent:fe,onOpenMachineDetails:()=>ee(`/machines/${re.id}`),onMachineUpgrade:()=>ne.handleMachineUpgrade(re.id),onLaunchDetectedIde:(F,xe)=>ne.handleLaunchDetectedIde(re.id,F,xe),onAddWorkspace:(F,xe)=>ne.handleAddWorkspace(re.id,F,xe),onBrowseDirectory:F=>ne.handleBrowseDirectory(re.id,F),onLaunchWorkspaceProvider:(F,xe,Ie)=>ne.handleLaunchWorkspaceProvider(re.id,F,xe,Ie),onListSavedSessions:F=>ne.handleListSavedSessions(re.id,F)}):e.jsx(pu,{section:W,attentionItems:J,unreadItems:ie,workingItems:se,completedItems:he,hiddenConversations:s,machineCards:P,getAvatarText:Nu,onOpenConversation:me.openConversation,onShowConversation:M,onShowAllHidden:N,onOpenNewSession:j,onOpenMachine:me.openMachine,onOpenSettings:()=>ee("/settings"),onSectionChange:T,wsStatus:d,isConnected:C,isStandalone:l})})}function Br(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Iu({conversations:t,numGroups:s,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:o,onClearPreviewOrder:i}){const c=a.useRef(0),[l,p]=a.useState(!1),[x,m]=a.useState(null),h=a.useCallback(()=>{c.current=0,p(!1),m(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const g=a.useCallback(b=>{b.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,p(!0))},[]),S=a.useCallback(b=>{if(!b.dataTransfer.types.includes("text/tab-key"))return;if(b.preventDefault(),!Br(s,r)){m("merge");return}const y=b.currentTarget.getBoundingClientRect(),d=b.clientX-y.left,C=y.width/3;d<C?m("split-left"):d>C*2?m("split-right"):m("merge")},[s,r]),I=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,p(!1),m(null))},[]),u=a.useCallback(b=>{c.current=0,p(!1);const y=b.dataTransfer.getData("text/tab-key"),d=y?t.some(M=>M.tabKey===y):!1,C=x;if(m(null),i(),!!y){if(b.preventDefault(),C==="split-left"&&Br(s,r)){r==null||r(y,"split-left");return}if(C==="split-right"&&Br(s,r)){r==null||r(y,"split-right");return}if(d){o(y);return}n==null||n(y)}},[t,x,s,r,n,o,i]);return{dragOver:l,dropAction:x,resetDragState:h,handleDragEnter:g,handleDragOver:S,handleDragLeave:I,handleDrop:u}}function Mu(t,s){const r=new Set(s.map(i=>i.tabKey)),n=t.filter(i=>r.has(i)),o=s.filter(i=>!t.includes(i.tabKey)).map(i=>i.tabKey);return[...n,...o]}function Au({conversations:t,initialActiveTabId:s,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:o}){const[i,c]=a.useState(s??null),[l,p]=a.useState(r??[]),[x,m]=a.useState(null),h=a.useRef(null),g=a.useRef(null),S=a.useRef(n),I=a.useRef(o);a.useEffect(()=>{S.current=n},[n]),a.useEffect(()=>{I.current=o},[o]),a.useEffect(()=>{s&&s!==i&&c(s)},[s,i]),a.useEffect(()=>{p(j=>{const v=Mu(j,t);return v.length===j.length&&v.every((k,$)=>k===j[$])?j:v})},[t]);const u=a.useMemo(()=>{const j=x??l;if(j.length===0)return t;const v=new Map(j.map((k,$)=>[k,$]));return[...t].sort((k,$)=>{const E=v.get(k.tabKey)??999,W=v.get($.tabKey)??999;return E-W})},[t,x,l]);a.useEffect(()=>{var v,k;if(u.length===0){i!==null&&(c(null),(v=S.current)==null||v.call(S,null));return}if(i&&u.some($=>$.tabKey===i))return;const j=u[0].tabKey;j!==i&&(c(j),(k=S.current)==null||k.call(S,j))},[u,i]);const b=a.useMemo(()=>u.find(j=>j.tabKey===i),[u,i]),y=a.useCallback(j=>{var v;c(j),(v=S.current)==null||v.call(S,j)},[]),d=a.useCallback((j,v,k)=>{p($=>{var V;const E=$.filter(R=>R!==j),W=E.indexOf(v);if(W<0)return $;const T=k==="left"?W:W+1;return E.splice(T,0,j),(V=I.current)==null||V.call(I,E),E}),m(null)},[]),C=a.useCallback((j,v,k)=>{const E=(l.length>0?l:t.map(V=>V.tabKey)).filter(V=>V!==j),W=E.indexOf(v);if(W<0)return;const T=k==="left"?W:W+1;E.splice(T,0,j),h.current=E,m(E)},[l,t]),M=a.useCallback(()=>{var v;const j=h.current;j&&(p(j),(v=I.current)==null||v.call(I,j))},[]),N=a.useCallback(()=>{h.current=null,m(null)},[]),f=a.useCallback(j=>{p(v=>{var $;const k=v.filter(E=>E!==j);return k.push(j),($=I.current)==null||$.call(I,k),k})},[]);return{activeTabId:i,activeConv:b,sortedConversations:u,previewOrderRef:h,draggingTabRef:g,selectTab:y,handleTabReorder:d,updatePreviewOrder:C,commitPreviewOrder:M,clearPreviewOrder:N,moveTabToEnd:f,setDraggingTabKey:j=>{g.current=j}}}function Tu({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 In({conversationsCount:t,isSplitMode:s,isStandalone:r,hasRegisteredMachines:n=!1,detectedIdes:o,handleLaunchIde:i}){const c=!r&&!n,l=r?"Waiting for your daemon":n?"No conversations yet":"Connect your first machine",p=r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":n?"Your machines are connected. Open a machine, choose a workspace, then launch an IDE, CLI, or ACP session.":"Install the ADHDev daemon and link your dashboard to start.";return t===0&&!s&&o&&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:l}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:p}),c&&e.jsx(Uo,{}),r&&o.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Detected IDEs"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:o.map(x=>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(x.type),children:[e.jsx(Xa,{size:14,className:"opacity-70"})," Open ",x.name]},x.type))})]}),c&&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 Vo="adhdev-tab-shortcuts";function qo(){try{return JSON.parse(localStorage.getItem(Vo)||"{}")}catch{return{}}}function Go({enabled:t=!0,sortedTabKeys:s,onFocus:r,onSelectTab:n}){const o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,c]=a.useState(()=>qo()),[l,p]=a.useState(null),x=a.useCallback(h=>{const g=[];return h.metaKey&&g.push(o?"⌘":"Meta"),h.ctrlKey&&g.push("Ctrl"),h.altKey&&g.push(o?"⌥":"Alt"),h.shiftKey&&g.push(o?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(h.key)?null:(g.push(h.key.length===1?h.key.toUpperCase():h.key),g.join("+"))},[o]),m=a.useCallback(h=>{c(h);try{localStorage.setItem(Vo,JSON.stringify(h))}catch{}},[]);return a.useEffect(()=>{if(!t||!l)return;const h=g=>{if(g.preventDefault(),g.stopPropagation(),g.key==="Escape"){p(null);return}const S=x(g);if(!S)return;const I={...i};for(const[u,b]of Object.entries(I))b===S&&delete I[u];I[l]=S,m(I),p(null)};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[t,l,i,m,x]),a.useEffect(()=>{if(!t)return;const h=g=>{if(!(!g.ctrlKey&&!g.metaKey&&!g.altKey)){for(const[S,I]of Object.entries(i))if(s.includes(S)&&x(g)===I){g.preventDefault(),r(),n(S);return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t,i,s,r,n,x]),{isMac:o,tabShortcuts:i,shortcutListening:l,setShortcutListening:p,saveShortcuts:m}}const _u=a.memo(function({conv:s,isActive:r,isDraggedTab:n,isTaskCompleteUnread:o,shortcut:i,conversationKeys:c,draggingTabRef:l,onFocus:p,onSelectTab:x,onConversationActivated:m,onPreviewReorder:h,onReorderTab:g,onCommitPreviewOrder:S,onClearPreviewOrder:I,onDragStateReset:u,onDragTabKeyChange:b,onReceiveTab:y,onOpenContextMenu:d,longPressTimer:C,isGroupActive:M}){const N=xs(s),f=N.isGenerating?"agent-tab-generating":N.isWaiting?"agent-tab-waiting":"",j=N.isReconnecting,v=a.useCallback(B=>{l.current=s.tabKey,b(s.tabKey),B.dataTransfer.setData("text/tab-key",s.tabKey),B.dataTransfer.effectAllowed="move"},[s.tabKey,l,b]),k=a.useCallback(()=>{l.current=null,b(null),S(),I(),u()},[l,b,S,I,u]),$=a.useCallback(B=>{const ee=l.current;if(!(!ee||ee===s.tabKey)&&B.dataTransfer.types.includes("text/tab-key")){B.preventDefault(),B.stopPropagation();const L=B.currentTarget.getBoundingClientRect(),D=B.clientX<L.left+L.width/2?"left":"right";h(ee,s.tabKey,D)}},[s.tabKey,l,h]),E=a.useCallback(B=>{B.preventDefault(),B.stopPropagation();const ee=B.dataTransfer.getData("text/tab-key");if(ee&&ee!==s.tabKey){const L=B.currentTarget.getBoundingClientRect(),D=B.clientX<L.left+L.width/2?"left":"right";c.includes(ee)?g(ee,s.tabKey,D):y&&y(ee)}I()},[s.tabKey,c,g,y,I]),W=a.useCallback(B=>{B.stopPropagation(),p(),x(s.tabKey),m(s)},[s,m,p,x]),T=a.useCallback(B=>{B.preventDefault(),d(B.clientX,B.clientY,s.tabKey)},[s.tabKey,d]),V=a.useCallback(B=>{const ee=B.touches[0];C.current=setTimeout(()=>{d(ee.clientX,ee.clientY,s.tabKey)},600)},[s.tabKey,C,d]),R=a.useCallback(()=>{C.current&&clearTimeout(C.current)},[C]),w=["adhdev-dockview-tab",f,r&&"is-active",M&&"is-group-active",j&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:w,draggable:!0,onDragStart:v,onDragEnd:k,onDragOver:$,onDrop:E,onClick:W,onContextMenu:T,onTouchStart:V,onTouchEnd:R,onTouchMove:R,style:{cursor:"pointer",opacity:n?.4:void 0},children:[o&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:N.isGenerating?e.jsx("div",{className:"tab-spinner"}):N.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):j?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):N.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:Qe(s),children:Qe(s)}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:j?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Gt(s)}):N.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",children:[Gt(s),e.jsx("span",{className:"connecting-dots"})]}):Gt(s)})]}),i&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${i}`,children:i})]})},(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 Pu({conversations:t,activeTabId:s,groupIndex:r,unreadTabKeys:n,draggingTabRef:o,onFocus:i,onSelectTab:c,onConversationActivated:l,onPreviewReorder:p,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:S,onReceiveTab:I,onHideTab:u,isGroupActive:b,allowTabShortcuts:y=!0}){const[d,C]=a.useState(null),M=a.useRef(null),N=a.useRef(null),f=a.useMemo(()=>t.map(T=>T.tabKey),[t]);Es("PaneGroupTabBar",{groupIndex:r,activeTabId:s,tabCount:t.length,ctxMenuTab:(d==null?void 0:d.tabKey)||null});const{isMac:j,tabShortcuts:v,shortcutListening:k,setShortcutListening:$,saveShortcuts:E}=Go({enabled:y,sortedTabKeys:t.map(T=>T.tabKey),onFocus:i,onSelectTab:c});a.useEffect(()=>{if(!d)return;const T=V=>{const R=document.querySelector("[data-pane-context-menu]");R&&R.contains(V.target)||C(null)};return window.addEventListener("mousedown",T,!0),()=>window.removeEventListener("mousedown",T,!0)},[d]),a.useEffect(()=>{const T=N.current;if(!T)return;const V=R=>{Math.abs(R.deltaY)>Math.abs(R.deltaX)&&(R.preventDefault(),T.scrollLeft+=R.deltaY)};return T.addEventListener("wheel",V,{passive:!1}),()=>T.removeEventListener("wheel",V)},[]);const W=a.useCallback((T,V,R)=>{C({x:T,y:V,tabKey:R})},[]);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:N,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(T=>e.jsx(_u,{conv:T,isActive:s===T.tabKey,isDraggedTab:o.current===T.tabKey,isTaskCompleteUnread:n.has(T.tabKey),shortcut:y?v[T.tabKey]:void 0,conversationKeys:f,draggingTabRef:o,onFocus:i,onSelectTab:c,onConversationActivated:l,onPreviewReorder:p,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:S,onReceiveTab:I,onOpenContextMenu:W,longPressTimer:M,isGroupActive:b},T.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),d&&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:d.x,top:d.y},children:[y&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:T=>{T.stopPropagation(),$(d.tabKey),C(null)},children:["⌨ ",v[d.tabKey]?`Change shortcut (${v[d.tabKey]})`:"Set shortcut"]}),v[d.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const T={...v};delete T[d.tabKey],E(T),C(null)},children:"✕ Remove shortcut"})]}),u&&e.jsxs(e.Fragment,{children:[y&&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:()=>{u(d.tabKey),C(null)},children:"🚫 Hide from Dashboard"})]})]}),y&&k&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>$(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:T=>T.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",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 Lu({conversations:t,ides:s,clearedTabs:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,hasRegisteredMachines:p,userName:x,groupIndex:m,onFocus:h,isSplitMode:g,numGroups:S,onMoveTab:I,onReceiveTab:u,style:b,detectedIdes:y,handleLaunchIde:d,onActiveTabChange:C,initialActiveTabId:M,initialTabOrder:N,onTabOrderChange:f,onHideTab:j,isFocused:v,allowTabShortcuts:k=!0}){const{sendCommand:$}=St(),E=a.useRef(null),{activeTabId:W,activeConv:T,sortedConversations:V,draggingTabRef:R,selectTab:w,handleTabReorder:B,updatePreviewOrder:ee,commitPreviewOrder:L,clearPreviewOrder:D,moveTabToEnd:O,setDraggingTabKey:z}=Au({conversations:t,initialActiveTabId:M,initialTabOrder:N,onActiveTabChange:C,onTabOrderChange:f}),Q=yr({sendDaemonCommand:o,activeConv:T,setLocalUserMessages:i,setActionLogs:c,isStandalone:l}),{dragOver:re,dropAction:je,resetDragState:Y,handleDragEnter:ne,handleDragOver:_,handleDragLeave:pe,handleDrop:me}=Iu({conversations:t,numGroups:S,onMoveTab:I,onReceiveTab:u,onOwnTabDrop:O,onClearPreviewOrder:D}),J=T&&!qe(T)&&ps(T)==="terminal",ie=a.useMemo(()=>T?s.find(Z=>Z.id===T.routeId):void 0,[s,T]),se=a.useMemo(()=>T?n.filter(Z=>Z.routeId===T.tabKey):[],[n,T]),he=a.useMemo(()=>Ds(s),[s]),ce=a.useMemo(()=>new Set(V.filter(Z=>Tc(Z,he,{isOpenConversation:Z.tabKey===W})).map(Z=>Z.tabKey)),[W,he,V]);Es("PaneGroup",{groupIndex:m,conversationCount:t.length,activeTabId:W,dragOver:re});const be=a.useCallback(Z=>{Z.streamSource==="agent-stream"&&Z.agentType&&$(Z.routeId,"focus_session",{agentType:Z.agentType,...Z.sessionId&&{targetSessionId:Z.sessionId}}).catch(()=>{})},[$]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:h,style:{...b,outline:re?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Pu,{conversations:V,activeTabId:W,groupIndex:m,numGroups:S,unreadTabKeys:ce,draggingTabRef:R,onFocus:h,onSelectTab:w,onConversationActivated:be,onPreviewReorder:ee,onReorderTab:B,onCommitPreviewOrder:L,onClearPreviewOrder:D,onDragStateReset:Y,onDragTabKeyChange:z,onMoveTab:I,onReceiveTab:u,onHideTab:j,isGroupActive:v??!1,allowTabShortcuts:k}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:ne,onDragOver:_,onDragLeave:pe,onDrop:me,children:[re&&e.jsx(Tu,{dropAction:je,canSplit:!!(S<4&&I)}),T?e.jsx(Sn,{activeConv:T,clearToken:r[T.tabKey]||0,isCliTerminal:!!J,ideEntry:ie,terminalRef:E,handleModalButton:Q.handleModalButton,handleRelaunch:Q.handleRelaunch,handleSendChat:Q.handleSendChat,isSendingChat:Q.isSendingChat,handleFocusAgent:Q.handleFocusAgent,isFocusingAgent:Q.isFocusingAgent,actionLogs:se,userName:x,isInputActive:!g||!!v}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(In,{conversationsCount:t.length,isSplitMode:g,isStandalone:l,hasRegisteredMachines:p,detectedIdes:y,handleLaunchIde:d})})]})]})}function Ru({containerRef:t,isSplitMode:s,numGroups:r,groupSizes:n,groupedConvs:o,clearedTabs:i,ides:c,actionLogs:l,sendDaemonCommand:p,setLocalUserMessages:x,setActionLogs:m,isStandalone:h,hasRegisteredMachines:g,userName:S,focusedGroup:I,setFocusedGroup:u,moveTabToGroup:b,splitTabRelative:y,closeGroup:d,handleResizeStart:C,detectedIdes:M,handleLaunchIde:N,groupActiveTabIds:f,setGroupActiveTabIds:j,groupTabOrders:v,setGroupTabOrders:k,toggleHiddenTab:$,allowTabShortcuts:E=!0}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:o.map((W,T)=>{const V=s&&n.length===r?`${n[T]}%`:void 0;return e.jsxs(nt.Fragment,{children:[s&&T>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:R=>C(T-1,R),onDoubleClick:()=>d(T),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(Lu,{style:s?{flexBasis:V??`${100/r}%`,flexGrow:V?0:1,flexShrink:V?0:1}:void 0,conversations:W,clearedTabs:i,ides:c,actionLogs:l,sendDaemonCommand:p,setLocalUserMessages:x,setActionLogs:m,isStandalone:h,hasRegisteredMachines:g,userName:S,groupIndex:T,isFocused:s&&I===T,onFocus:()=>u(T),isSplitMode:s,numGroups:r,onMoveTab:(R,w)=>{w==="left"&&T>0?b(R,T-1):w==="right"&&T<r-1?b(R,T+1):w==="split-left"&&r<4?y(R,T,"left"):w==="split-right"&&r<4&&y(R,T,"right")},onReceiveTab:R=>b(R,T),detectedIdes:T===0?M:void 0,handleLaunchIde:T===0?N:void 0,onActiveTabChange:R=>j(w=>(w[T]??null)===(R??null)?w:{...w,[T]:R}),initialActiveTabId:f[T],initialTabOrder:v[T],onTabOrderChange:R=>k(w=>{const B=w[T]||[];return B.length===R.length&&B.every((ee,L)=>ee===R[L])?w:{...w,[T]:R}}),onHideTab:$,allowTabShortcuts:E})]},T)})})}function Yo({doId:t,targetSessionId:s,connState:r,viewMode:n}){const[o,i]=a.useState(null),[c,l]=a.useState(null);a.useEffect(()=>t?at.onScreenshot("ide-page",(m,h)=>{if(m!==t)return;const g=new FileReader;g.onload=()=>i(g.result),g.readAsDataURL(h)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&i(null)},[r]),a.useEffect(()=>{var m;return t?((m=at.onStatus)==null?void 0:m.call(at,(h,g)=>{h===t&&g!=null&&g.screenshotUsage&&l(g.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{i(null)},[t,s]),a.useEffect(()=>{const x=t?at.get(t):null;if(!(!x||r!=="connected"))return n!=="chat"&&s?x.startScreenshots(s):x.stopScreenshots(s),()=>{x.stopScreenshots(s)}},[n,r,s,t]);const p=a.useCallback(async(x,m)=>{const h=t?at.get(t):null;return!h||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):h.sendInput(x,m,s)},[t,r,s]);return{connScreenshot:o,screenshotUsage:c,handleRemoteAction:p}}const Xo="adhdev-dashboard-action-shortcuts",Eu=1200,Du={toggleHiddenTabs:"G H",setActiveTabShortcut:"G S",selectPreviousGroupTab:"G K",selectNextGroupTab:"G J",splitActiveTabRight:"⌘+⌥+\\",focusLeftPane:"⌘+⌥+←",focusRightPane:"⌘+⌥+→",moveActiveTabToLeftPane:"⌘+⌥+⇧+←",moveActiveTabToRightPane:"⌘+⌥+⇧+→",triggerPrimaryApprovalAction:"⌥+A",triggerSecondaryApprovalAction:"⌥+D",toggleCliView:"T"};function $u(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function Xe(t,s){switch(t){case"openShortcutHelp":return"?";case"hideCurrentTab":return s?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return s?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return s?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return s?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return s?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return s?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return s?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return s?"⌘+⌥+=":"Ctrl+Alt+\\";case"splitActiveTabDown":return s?"⌘+⌥+-":"Ctrl+Alt+-";case"focusLeftPane":return s?"⌘+⌥+[":"Ctrl+Alt+←";case"focusRightPane":return s?"⌘+⌥+]":"Ctrl+Alt+→";case"focusUpPane":return s?"⌘+⌥+U":"Ctrl+Alt+↑";case"focusDownPane":return s?"⌘+⌥+J":"Ctrl+Alt+↓";case"moveActiveTabToLeftPane":return s?"⌘+⌥+,":"Ctrl+Alt+Shift+←";case"moveActiveTabToRightPane":return s?"⌘+⌥+.":"Ctrl+Alt+Shift+→";case"moveActiveTabToUpPane":return s?"⌘+⌥+I":"Ctrl+Alt+Shift+↑";case"moveActiveTabToDownPane":return s?"⌘+⌥+K":"Ctrl+Alt+Shift+↓";case"triggerPrimaryApprovalAction":return s?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return s?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return s?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return s?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return s?"⌥+[":"Ctrl+Alt+[";case"selectNextGroupTab":return s?"⌥+]":"Ctrl+Alt+]";case"toggleCliView":return s?"⌥+T":"Ctrl+Alt+T"}}function Jo(t){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:Xe("openShortcutHelp",t)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:Xe("hideCurrentTab",t)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:Xe("toggleHiddenTabs",t)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:Xe("openHistoryForActiveTab",t)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:Xe("openRemoteForActiveTab",t)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:Xe("floatActiveTab",t)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:Xe("popoutActiveTab",t)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:Xe("dockActiveTab",t)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:Xe("splitActiveTabRight",t)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:Xe("splitActiveTabDown",t)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:Xe("focusLeftPane",t)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:Xe("focusRightPane",t)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:Xe("focusUpPane",t)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:Xe("focusDownPane",t)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:Xe("moveActiveTabToLeftPane",t)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:Xe("moveActiveTabToRightPane",t)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:Xe("moveActiveTabToUpPane",t)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:Xe("moveActiveTabToDownPane",t)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:Xe("triggerPrimaryApprovalAction",t)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:Xe("triggerSecondaryApprovalAction",t)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:Xe("triggerTertiaryApprovalAction",t)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:Xe("setActiveTabShortcut",t)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:Xe("selectPreviousGroupTab",t)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:Xe("selectNextGroupTab",t)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:Xe("toggleCliView",t)}]}function nn(t){if(!(t instanceof HTMLElement))return!1;if(t.isContentEditable)return!0;const s=t.tagName;return s==="INPUT"||s==="TEXTAREA"||s==="SELECT"}function pr(t){const s=Object.fromEntries(Jo(t).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(Xo)||"{}"),n={...s,...r};for(const[o,i]of Object.entries(Du))n[o]===i&&(n[o]=s[o]);return n}catch{return s}}function Zo(t){return t===" "?"Space":t==="Escape"?"Esc":t==="ArrowLeft"?"←":t==="ArrowRight"?"→":t==="ArrowUp"?"↑":t==="ArrowDown"?"↓":t.length===1?t.toUpperCase():t}function Bu({enabled:t=!0,onTrigger:s}){const r=$u(),[n,o]=a.useState(()=>pr(r)),[i,c]=a.useState(null),[l,p]=a.useState([]),x=a.useRef({parts:[],timer:null}),m=a.useCallback(u=>{const b=[];return u.metaKey&&b.push(r?"⌘":"Meta"),u.ctrlKey&&b.push("Ctrl"),u.altKey&&b.push(r?"⌥":"Alt"),u.shiftKey&&u.key.length!==1&&b.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(b.push(Zo(u.key)),b.join("+"))},[r]),h=a.useCallback(u=>{o(u);try{localStorage.setItem(Xo,JSON.stringify(u))}catch{}},[]);a.useEffect(()=>{const u=pr(r),b=Object.entries(n),y=Object.entries(u);b.length===y.length&&b.every(([d,C])=>u[d]===C)||h(u)},[n,r,h]);const g=a.useCallback(()=>{typeof window<"u"&&x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current={parts:[],timer:null}},[]),S=a.useCallback(()=>{typeof window>"u"||(x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current.timer=window.setTimeout(()=>{x.current={parts:[],timer:null}},Eu))},[]);a.useEffect(()=>{if(!i)return;const u=b=>{if(b.preventDefault(),b.stopPropagation(),b.key==="Escape"){c(null),p([]);return}const y=m(b);if(!y)return;const C=!(b.metaKey||b.ctrlKey||b.altKey)&&/^[A-Z0-9]$/.test(y);if(l.length===0&&C){p([y]);return}const N=[...l,y].slice(0,2).join(" "),f={...n};for(const[j,v]of Object.entries(f))v===N&&delete f[j];f[i]=N,h(f),c(null),p([])};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[n,m,h,i,l]),a.useEffect(()=>{if(!t||i)return;const u=b=>{if(b.defaultPrevented)return;const y=m(b);if(!y)return;const d=b.metaKey||b.ctrlKey||b.altKey;if(nn(b.target)&&!d)return;const C=x.current.parts,M=d?[y]:[...C.slice(-1),y].slice(-2),N=M.join(" "),f=M[M.length-1],j=Object.entries(n).filter(([,W])=>!!W),v=j.find(([,W])=>W===N);if(v){b.preventDefault(),g(),s(v[0]);return}if(j.some(([,W])=>W.startsWith(`${N} `))){b.preventDefault(),x.current.parts=M,S();return}const $=j.find(([,W])=>W===f);if($){b.preventDefault(),g(),s($[0]);return}if(j.some(([,W])=>W.startsWith(`${f} `))){b.preventDefault(),x.current.parts=[f],S();return}g()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n,S,t,m,s,g,i]),a.useEffect(()=>()=>g(),[g]);const I=a.useMemo(()=>Jo(r),[r]);return{isMac:r,actionDefinitions:I,actionShortcuts:n,shortcutListening:i,shortcutListeningDraft:l,setShortcutListening:c,setShortcutListeningDraft:p,saveShortcuts:h}}const Qo=a.createContext(null);function kr(){const t=a.useContext(Qo);if(!t)throw new Error("DashboardDockviewContext missing");return t}function nr(t){return Qe(t)||t.tabKey}function Ku(t){return`remote:${t}`}function Wt(t){return t.startsWith("remote:")}function Na(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Sa(t){var r,n,o,i,c;const s=t==null?void 0:t.defaultView;if(s)try{s.focus(),(n=(r=t==null?void 0:t.body)==null?void 0:r.focus)==null||n.call(r),(i=(o=t==null?void 0:t.documentElement)==null?void 0:o.focus)==null||i.call(o),(c=s.requestAnimationFrame)==null||c.call(s,()=>{var l,p;try{s.focus(),(p=(l=t==null?void 0:t.body)==null?void 0:l.focus)==null||p.call(l)}catch{}})}catch{}}function Js(t,s){t.classList.remove(qr.className,Gr.className),t.classList.add(s==="light"?qr.className:Gr.className)}function Ca(t){return t?Array.from(new Set(t.groups.map(s=>{var r,n;return(n=(r=s.element)==null?void 0:r.ownerDocument)==null?void 0:n.defaultView}).filter(s=>!!s&&s!==window))):[]}function Wu(t){const[,s]=a.useState(0);a.useEffect(()=>{const r=()=>s(o=>o+1),n=[t.api.onDidActiveGroupChange(r),t.api.onDidTitleChange(r),t.api.onDidGroupChange(r),t.containerApi.onDidActivePanelChange(r)];return()=>{for(const o of n)o.dispose()}},[t.api,t.containerApi])}function Ou(t,s,r){var l;const n=[s];let o;for(const p of n){let x;for(const m of p){const h=t.addPanel({id:m.tabKey,component:"conversation",title:nr(m),params:{kind:"conversation",tabKey:m.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:o?{position:{referencePanel:o,direction:"right"},inactive:!0}:{}});x||(x=h.id)}o=x??o}const i=r??((l=s[0])==null?void 0:l.tabKey)??null;if(!i)return;const c=t.getPanel(i);c&&c.group.model.openPanel(c)}function Ia(t,s){const r=new Set(s.map(n=>n.tabKey));for(const n of[...t.panels])Wt(n.id)||r.has(n.id)||t.removePanel(n);for(const n of s){const o=t.getPanel(n.tabKey);if(o){o.update({params:{tabKey:n.tabKey}}),o.title!==nr(n)&&o.api.setTitle(nr(n));continue}t.addPanel({id:n.tabKey,component:"conversation",title:nr(n),params:{kind:"conversation",tabKey:n.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Ma(t,s,r){var p,x;const n=r?Ku(r):null;for(const m of[...t.panels])Wt(m.id)&&(!n||m.id!==n)&&t.removePanel(m);if(!r||!n)return;const o=Rt(s,r);if(!o&&t.totalPanels===0)return;const i=t.getPanel(n),c=bo(o);if(i){i.title!==c&&i.api.setTitle(c);return}const l=(o==null?void 0:o.tabKey)??((p=t.activePanel)==null?void 0:p.id)??((x=t.panels.find(m=>!Wt(m.id)))==null?void 0:x.id);t.addPanel({id:n,component:"remote",title:c,params:{kind:"remote",routeId:r},...l?{position:{referencePanel:l,direction:"right"},inactive:!0}:{}})}function Hu({params:t,api:s}){var h;const r=kr(),n=a.useRef(null),[o,i]=a.useState(s.isActive),c=r.conversationsByTabKey.get(t.tabKey),l=yr({sendDaemonCommand:r.sendDaemonCommand,activeConv:c,setLocalUserMessages:r.setLocalUserMessages,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});a.useEffect(()=>{i(s.isActive);const g=[s.onDidActiveChange(S=>i(S.isActive)),s.onDidActiveGroupChange(S=>{if(!s.isActive&&!S.isActive){i(!1);return}i(s.isActive)})];return()=>{for(const S of g)S.dispose()}},[s]);const p=a.useMemo(()=>c?r.ides.find(g=>g.id===c.routeId):void 0,[r.ides,c]),x=a.useMemo(()=>c?r.actionLogs.filter(g=>g.routeId===c.tabKey):[],[r.actionLogs,c]);if(!c)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(In,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,detectedIdes:r.detectedIdes,handleLaunchIde:r.handleLaunchIde})});const m=!qe(c)&&ps(c)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Sn,{activeConv:c,clearToken:r.clearedTabs[c.tabKey]||0,isCliTerminal:m,ideEntry:p,terminalRef:n,handleModalButton:l.handleModalButton,handleRelaunch:l.handleRelaunch,handleSendChat:l.handleSendChat,isSendingChat:l.isSendingChat,handleFocusAgent:l.handleFocusAgent,isFocusingAgent:l.isFocusingAgent,actionLogs:x,userName:r.userName,scrollToBottomRequestNonce:((h=r.scrollToBottomRequest)==null?void 0:h.tabKey)===c.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:o})})}function Uu({params:t}){var p;const s=kr(),r=a.useMemo(()=>Rt([...s.conversationsByTabKey.values()],t.routeId),[s.conversationsByTabKey,t.routeId]),n=a.useMemo(()=>s.ides.find(x=>x.id===t.routeId),[s.ides,t.routeId]),o=(r==null?void 0:r.daemonId)||((p=r==null?void 0:r.routeId)==null?void 0:p.split(":")[0])||t.routeId.split(":")[0]||t.routeId,{connScreenshot:i,screenshotUsage:c,handleRemoteAction:l}=Yo({doId:o,targetSessionId:r?hn(r):(n==null?void 0:n.sessionId)||(n==null?void 0:n.instanceId),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote"});return r?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(Qa,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:i,screenshotUsage:c,transportType:r.transport,onAction:l})}):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 zu(){const t=kr();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(In,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,hasRegisteredMachines:t.hasRegisteredMachines,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Fu(t){var S,I;Wu(t);const s=kr(),r=a.useCallback(u=>{"button"in u&&u.button!==0||t.api.setActive()},[t.api]);if(t.params.kind==="remote"){const u=Rt([...s.conversationsByTabKey.values()],t.params.routeId),b=((S=t.api.group.activePanel)==null?void 0:S.id)===t.api.id,y=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${y?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(u==null?void 0:u.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:u!=null&&u.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:u.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 o=((I=t.api.group.activePanel)==null?void 0:I.id)===t.api.id,i=t.api.isGroupActive,c=Ps(n,s.liveSessionInboxState,{isOpenConversation:o}),l=c.isReconnecting,p=c.isConnecting,x=c.isGenerating,m=c.isWaiting,h=c.unread,g=s.tabShortcuts[n.tabKey];return e.jsxs("div",{className:`adhdev-dockview-tab${o?" is-active":""}${i?" is-group-active":""}${l?" is-reconnecting":""}`,title:Qe(n),"data-tab-key":t.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:u=>{var b;u.preventDefault(),r(u),s.openTabContextMenu({x:u.clientX,y:u.clientY,tabKey:n.tabKey,sourceDocument:((b=u.target)==null?void 0:b.ownerDocument)??document})},children:[h&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?e.jsx("div",{className:"tab-spinner"}):m?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):p?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:Qe(n)}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:l?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Gt(n)}):p?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:Gt(n)}):e.jsx("span",{children:Gt(n)})})]}),g&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:g,children:g})]})}function Vu({visibleConversations:t,clearedTabs:s,ides:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,hasRegisteredMachines:p,initialDataLoaded:x,userName:m,detectedIdes:h,handleLaunchIde:g,toggleHiddenTab:S,registerActionHandlers:I,onActiveTabChange:u,requestedActiveTabKey:b,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:d,scrollToBottomRequest:C}){var dt,Ct,yt;const{theme:M}=wn(),{sendCommand:N}=St(),f=a.useRef(null),j=a.useRef(null),v=a.useRef(!1),k=a.useRef(!1),$=a.useRef(!1),E=a.useRef(null),W=a.useRef([]),[T,V]=a.useState(null),[R,w]=a.useState(!1),[B,ee]=a.useState(!1),[L,D]=a.useState(0),O=a.useRef(null),z=a.useMemo(()=>Ko(typeof window<"u"?window.innerWidth:1280),[]),Q=a.useRef(typeof window>"u"?{}:Jd(z)),re=a.useMemo(()=>new Map(t.map(K=>[K.tabKey,K])),[t]),je=a.useMemo(()=>Ds(r),[r]),Y=a.useCallback(()=>{var K;(K=f.current)==null||K.focus()},[]),ne=a.useCallback(K=>{const H=document,G=K.document;for(const Pe of H.querySelectorAll('link[rel="stylesheet"]')){const te=G.createElement("link");te.rel="stylesheet",te.href=Pe.href,Pe.crossOrigin&&(te.crossOrigin=Pe.crossOrigin),G.head.appendChild(te)}for(const Pe of H.querySelectorAll("style")){const te=G.createElement("style");te.textContent=Pe.textContent,G.head.appendChild(te)}const X=[];for(const Pe of H.styleSheets)try{for(const te of Pe.cssRules)te instanceof CSSStyleRule&&(te.selectorText===":root"||te.selectorText==="html")&&X.push(te.cssText)}catch{}if(X.length>0){const Pe=G.createElement("style");Pe.textContent=X.join(`
|
|
40
|
+
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:k,onCancel:()=>m(null)})]})}const fd=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function xd(){const{preference:t,setPreference:s}=wn();return e.jsx("div",{className:"flex gap-2",children:fd.map(r=>e.jsxs("button",{onClick:()=>s(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:r.icon}),r.label]},r.id))})}function hd(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 bd(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function Rr(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function ua(t){const{r:s,g:r,b:n}=bd(t);return .2126*Rr(s)+.7152*Rr(r)+.0722*Rr(n)}function pa(t,s){const r=ua(t),n=ua(s),o=Math.max(r,n),i=Math.min(r,n);return(o+.05)/(i+.05)}function Ao(t){const s=hd(t);if(!s)return"#111827";const r="#111827",n="#ffffff";return pa(s,r)>=pa(s,n)?r:n}const en={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},tn={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},gd=[{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"}}}],To="adhdev-chat-theme",_o="adhdev-chat-theme-custom";function rr(){if(typeof window>"u")return"ember";try{return localStorage.getItem(To)||"ember"}catch{return"ember"}}function Pt(t){try{const s=localStorage.getItem(_o);if(s){const r=JSON.parse(s);return{...t==="dark"?en:tn,...r[t]}}}catch{}return t==="dark"?en:tn}function Fs(t,s){try{localStorage.setItem(_o,JSON.stringify({dark:t,light:s}))}catch{}}function Mt(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${o}, ${s})`}function ur(t,s){const r=Math.min(255,parseInt(t.slice(1,3),16)+s),n=Math.min(255,parseInt(t.slice(3,5),16)+s),o=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const yd={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function Is(t,s){var o;const r=(o=yd[t])==null?void 0:o[s];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",ur(r,24)),n.style.setProperty("--accent-on-primary",Ao(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${ur(r,18)})`),n.style.setProperty("--border-accent",Mt(r,.35)),n.style.setProperty("--nav-active-bg",Mt(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${Mt(r,.06)}`)}function Yt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Mt(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Mt(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Mt(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Mt(t.borderSubtle,.5)),s.style.setProperty("--border-default",Mt(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ur(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Ao(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ur(t.accentColor,40)})`),s.style.setProperty("--border-accent",Mt(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Mt(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Mt(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Mt(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function jn(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>t.style.removeProperty(r))}function vd(t){try{localStorage.setItem(To,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xt()?"dark":"light";Yt(Pt(s))}else jn(),Is(t,Xt()?"dark":"light")}function wd(){try{localStorage.removeItem("adhdev-accent-color")}catch{}const t=rr();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xt()?"dark":"light";Yt(Pt(s))}else jn(),Is(t,Xt()?"dark":"light")}function Xt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function ht({label:t,value:s,onChange:r}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function gs({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 jd({dark:t,onColorsChange:s}){const r=t?"dark":"light",[n,o]=a.useState(()=>Pt(r));a.useEffect(()=>{o(Pt(r))},[r]);const i=a.useCallback((c,l)=>{o(p=>{const x={...p,[c]:l},h=Pt(r==="dark"?"light":"dark");return r==="dark"?Fs(x,h):Fs(h,x),Yt(x),s(x),x})},[r,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(gs,{title:"App Background",children:[e.jsx(ht,{label:"Background",value:n.bgPrimary,onChange:c=>i("bgPrimary",c)}),e.jsx(ht,{label:"Surface",value:n.bgSecondary,onChange:c=>i("bgSecondary",c)}),e.jsx(ht,{label:"Card",value:n.surfacePrimary,onChange:c=>i("surfacePrimary",c)})]}),e.jsxs(gs,{title:"App Text",children:[e.jsx(ht,{label:"Primary",value:n.textPrimary,onChange:c=>i("textPrimary",c)}),e.jsx(ht,{label:"Secondary",value:n.textSecondary,onChange:c=>i("textSecondary",c)}),e.jsx(ht,{label:"Muted",value:n.textMuted,onChange:c=>i("textMuted",c)})]}),e.jsxs(gs,{title:"Borders & Accent",children:[e.jsx(ht,{label:"Border subtle",value:n.borderSubtle,onChange:c=>i("borderSubtle",c)}),e.jsx(ht,{label:"Border default",value:n.borderDefault,onChange:c=>i("borderDefault",c)}),e.jsx(ht,{label:"Accent",value:n.accentColor,onChange:c=>i("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(gs,{title:"Chat Bubbles",children:[e.jsx(ht,{label:"User bubble",value:n.userBubble,onChange:c=>i("userBubble",c)}),e.jsx(ht,{label:"User text",value:n.userText,onChange:c=>i("userText",c)}),e.jsx(ht,{label:"Agent bubble",value:n.assistantBubble,onChange:c=>i("assistantBubble",c)}),e.jsx(ht,{label:"Agent text",value:n.assistantText,onChange:c=>i("assistantText",c)})]}),e.jsxs(gs,{title:"Chat Layout",children:[e.jsx(ht,{label:"Chat BG",value:n.containerBg,onChange:c=>i("containerBg",c)}),e.jsx(ht,{label:"Send button",value:n.sendButton,onChange:c=>i("sendButton",c)}),e.jsx(ht,{label:"Input border",value:n.inputBorder,onChange:c=>i("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:c=>i("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?en:tn,p=Pt(t?"light":"dark");t?Fs(c,p):Fs(p,c),o(c),Yt(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 kd(){const[t,s]=a.useState(rr),[r,n]=a.useState(!0),[o,i]=a.useState(()=>Pt("dark"));a.useEffect(()=>{n(Xt());const p=new MutationObserver(()=>{const h=Xt();n(h);const g=rr();g==="custom"?Yt(Pt(h?"dark":"light")):Is(g,h?"dark":"light")});p.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),m=()=>{const h=Xt();n(h);const g=rr();g==="custom"?Yt(Pt(h?"dark":"light")):Is(g,h?"dark":"light")};return x.addEventListener("change",m),()=>{p.disconnect(),x.removeEventListener("change",m)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Yt(Pt(r?"dark":"light")):(jn(),Is(t,r?"dark":"light"))},[t,r]),a.useEffect(()=>{i(Pt(r?"dark":"light"))},[r]);const c=p=>{s(p),vd(p)},l=[...gd,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText},light:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:l.map(p=>{const x=t===p.id,m=r?p.preview.dark:p.preview.light,h=p.id==="honey"||p.id==="ember"?"#1a1a1a":p.id==="custom"?o.userText:"#fff";return e.jsxs("button",{onClick:()=>c(p.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:m.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.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:m.userBubble,color:h},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:p.id==="custom"?"🎨 Custom":p.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:p.description})]})]})]},p.id)})}),t==="custom"&&e.jsx(jd,{dark:r,onColorsChange:p=>i(p)})]})}const Po="adhdev_mobileDashboardMode_v1";function Lo(){try{return localStorage.getItem(Po)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Nd(t){try{localStorage.setItem(Po,t)}catch{}}function Sd(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Lo()==="chat")},[]),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bt,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:r=>{s(r),Nd(r?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}function Cd(t,s,r){return{...t||{},id:s,type:(t==null?void 0:t.type)||"adhdev-daemon",status:(t==null?void 0:t.status)||"online",timestamp:r.timestamp,platform:r.machine.platform,machine:{...(t==null?void 0:t.machine)||{},...r.machine}}}function Id(t,s){const{sendData:r}=St(),{injectEntries:n,getIdes:o}=ir(),i=Array.from(new Set(t.filter(Boolean))).join("|");a.useEffect(()=>{if(!(s!=null&&s.enabled)||!r)return;const c=i?i.split("|"):[];if(c.length===0)return;const l=c.map(p=>Ot.subscribe({sendData:r},p,{type:"subscribe",topic:"machine.runtime",key:`machine:${p}`,params:{intervalMs:s==null?void 0:s.intervalMs}},x=>{const m=o().find(g=>g.id===p),h=Cd(m,p,x);n([h])}));return()=>{l.forEach(p=>p())}},[i,o,n,s==null?void 0:s.enabled,s==null?void 0:s.intervalMs,r])}function Ro(t,s){const{sendData:r}=St(),[n,o]=a.useState(null),[i,c]=a.useState(!1);return a.useEffect(()=>{if(!t){o(null),c(!1);return}if(!(s!=null&&s.enabled)||!r){c(!1);return}o(null),c(!0);const l=Ot.subscribe({sendData:r},t,{type:"subscribe",topic:"session_host.diagnostics",key:`session_host:${t}`,params:{includeSessions:(s==null?void 0:s.includeSessions)!==!1,...typeof(s==null?void 0:s.limit)=="number"?{limit:s.limit}:{},...typeof(s==null?void 0:s.intervalMs)=="number"?{intervalMs:s.intervalMs}:{}}},p=>{o(p.diagnostics),c(!1)});return()=>{l()}},[t,s==null?void 0:s.enabled,s==null?void 0:s.includeSessions,s==null?void 0:s.intervalMs,s==null?void 0:s.limit,r]),{diagnostics:n,loading:i,applyDiagnostics:o}}function Md(t){return t.daemonId||(t.routeId.includes(":")?t.routeId.split(":")[0]||null:t.routeId||null)}function Eo(t){const{sendData:s}=St(),[r,n]=a.useState({});return a.useEffect(()=>{const o=Md(t);if(!o||!t.sessionId||!s){n({});return}const i=Ot.subscribe({sendData:s},o,{type:"subscribe",topic:"session.modal",key:`daemon:${o}:session-modal:${t.sessionId}`,params:{targetSessionId:t.sessionId}},c=>{n({status:c.status,modalMessage:c.modalMessage,modalButtons:c.modalButtons})});return()=>{i()}},[t.daemonId,t.routeId,t.sessionId,s]),r}const Do="adhdev_hiddenTabs";function Ad(){try{const t=localStorage.getItem(Do);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function os(t){try{localStorage.setItem(Do,JSON.stringify([...t]))}catch{}}function Td(){const[t,s]=a.useState(Ad),r=a.useCallback(x=>{s(m=>{const h=new Set(m);return h.has(x)?h.delete(x):h.add(x),os(h),h})},[]),n=a.useCallback(x=>{s(m=>{if(m.has(x))return m;const h=new Set(m);return h.add(x),os(h),h})},[]),o=a.useCallback(x=>{s(m=>{if(!m.has(x))return m;const h=new Set(m);return h.delete(x),os(h),h})},[]),i=a.useCallback(()=>{s(x=>{if(x.size===0)return x;const m=new Set;return os(m),m})},[]),c=a.useCallback((x,m)=>{s(h=>{const g=new Set(h);for(const S of m)g.add(S);return os(g),g})},[]),l=a.useCallback((x,m)=>{s(h=>{const g=new Set(h);for(const S of m)g.delete(S);return os(g),g})},[]),p=a.useCallback(x=>t.has(x),[t]);return{hiddenTabs:t,toggleTab:r,hideTab:n,showTab:o,showAllTabs:i,hideAllForDaemon:c,showAllForDaemon:l,isHidden:p}}function _d({visibleConversations:t,clearedTabs:s,setClearedTabs:r,setActionLogs:n}){a.useEffect(()=>{Kl()},[]);const o=a.useMemo(()=>t.map(i=>({id:i.tabKey,name:ho(i),status:i.status,activeModal:i.modalMessage?{message:i.modalMessage,buttons:i.modalButtons}:null})),[t]);return Ol(o),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{r(l=>{const p=Date.now(),x={};for(const[m,h]of Object.entries(l))p-h<5e3&&(x[m]=h);return Object.keys(x).length===Object.keys(l).length?l:x})},5500);return()=>clearTimeout(c)},[s,r]),a.useEffect(()=>{const i=setInterval(()=>{const c=Date.now()-3e5;n(l=>{const p=l.filter(x=>x.timestamp>c).slice(-100);return p.length===l.length?l:p})},6e4);return()=>clearInterval(i)},[n]),null}function Pd(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(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1];return Pd(s==null?void 0:s.receivedAt)||0}function sn(t,s=0){return Jt(t)||t.lastUpdated||s||0}function $o(t){return Jt(t)||t.lastUpdated||0}function Bo(t,s,r=$o){const n=r(s)-r(t);if(n!==0)return n;const o=(t.machineName||"").localeCompare(s.machineName||"");if(o!==0)return o;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const c=t.displaySecondary.localeCompare(s.displaySecondary);return c!==0?c:t.tabKey.localeCompare(s.tabKey)}function rn(t){var r;const s=bt(t.status,{activeModal:(r=t.modalButtons)!=null&&r.length?{buttons:t.modalButtons}:null});return s==="generating"||s==="waiting_approval"}function Ld(t){var s;return t.messages.length===0&&!((s=t.modalButtons)!=null&&s.length)&&!rn(t)&&!t.title.trim()}function Rd(t){return t.length===0?null:[...t].sort((s,r)=>{const n=Number(rn(r))-Number(rn(s));if(n!==0)return n;const o=r.messages.length-s.messages.length;return o!==0?o:Bo(s,r)})[0]||null}function Rt(t,s){const r=t.filter(c=>c.routeId===s);if(r.length===0)return null;const n=r.find(c=>c.streamSource==="native")||null,o=r.filter(c=>c.streamSource==="agent-stream"),i=Rd(o);return n?i&&Ld(n)?i:n:i||r[0]||null}function Ed(t){const s=t.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of s){const o=r.get(n.id);if(!o){r.set(n.id,n);continue}const i=(o.workspace?1:0)+(o.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>i||(n.timestamp||0)>(o.timestamp||0))&&r.set(n.id,n)}return Array.from(r.values())}function Vs(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Dd(t,s){const r=Date.now();return t.map(n=>{const o=s[n.tabKey];return o&&r-o<5e3?{...n,messages:[],title:""}:n})}function $d(t,s){const r=[],n=t.sessionId||t.instanceId;r.push({key:t.id,ref:s[t.id]}),n&&r.push({key:n,ref:s[n]});for(const o of t.childSessions||[]){const i=o.id||o.providerType,c=`${t.id}:${i}`;r.push({key:c,ref:s[c]}),r.push({key:o.id,ref:s[o.id]})}return r}function Bd(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].key!==s[r].key||t[r].ref!==s[r].ref)return!1;return!0}function Kd(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Wd(t){const s=Kd(t);if(!s)return`empty:${t.messages.length}`;if(s.id)return`id:${String(s.id)}`;if(s._localId)return`local:${String(s._localId)}`;const r=String(s.role||""),n=ts(s.content).slice(0,240);return`${t.messages.length}:${r}:${n}`}function Od({ides:t,connectionStates:s,localUserMessages:r,clearedTabs:n,hiddenTabs:o}){const i=a.useRef([]),c=a.useRef([]),l=a.useRef([]),p=a.useRef([]),x=a.useMemo(()=>{const f=Ed(t);return Vs(i.current,f)?i.current:(i.current=f,f)},[t]),m=a.useMemo(()=>yo(t),[t]),h=a.useRef(new Map),g=a.useRef(new Map),S=a.useMemo(()=>{const f=new Map,j=[];for(const E of x){const{connectionState:W="new",machineName:T}=vo(E,{machineNames:m,connectionStates:s,defaultConnectionState:"new"}),V=$d(E,r),R=h.current.get(E.id);if(R&&R.ide===E&&R.connectionState===W&&R.machineName===T&&Bd(R.localRefs,V)){f.set(E.id,R),j.push(...R.conversations);continue}const w=yn(E,r,{machineNames:m,connectionStates:s,defaultConnectionState:"new"}),B={ide:E,connectionState:W,machineName:T,localRefs:V,conversations:w};f.set(E.id,B),j.push(...w)}h.current=f;const v=new Map,k=E=>{const W=Wd(E),T=g.current.get(E.tabKey);if(T&&T.signature===W)return v.set(E.tabKey,T),T.timestamp;const V={signature:W,timestamp:$o(E)||(T==null?void 0:T.timestamp)||0};return v.set(E.tabKey,V),V.timestamp},$=[...j].sort((E,W)=>Bo(E,W,k));return g.current=v,$},[x,r,s,m]),I=a.useMemo(()=>{const f=Dd(S,n);return Vs(c.current,f)?c.current:(c.current=f,f)},[S,n]),u=a.useMemo(()=>{const f=new Map,j=Array.from(new Set(I.map(v=>v.routeId)));for(const v of j){const k=Rt(I,v);k&&f.set(v,k)}return f},[I]),b=a.useMemo(()=>{const f=new Map;for(const j of I)if(j.sessionId&&f.set(j.sessionId,j),j.streamSource==="native"&&j.sessionId){const v=u.get(j.routeId);v&&f.set(j.sessionId,v)}return f},[I,u]),y=a.useMemo(()=>{const f=new Map;for(const j of I)j.sessionId&&f.set(j.sessionId,j),f.set(j.routeId,u.get(j.routeId)||j),f.set(j.tabKey,j);return f},[I,u]),d=a.useCallback(f=>{if(f)return b.get(f)},[b]),C=a.useCallback(f=>{if(f)return y.get(f)},[y]),M=a.useMemo(()=>{const f=I.filter(j=>!o.has(j.tabKey));return Vs(l.current,f)?l.current:(l.current=f,f)},[I,o]),N=a.useMemo(()=>{const f=M.map(j=>j.tabKey);return Vs(p.current,f)?p.current:(p.current=f,f)},[M]);return{chatIdes:x,conversations:I,visibleConversations:M,visibleTabKeys:N,resolveConversationBySessionId:d,resolveConversationByTarget:C}}function Hd({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:r,setSearchParams:n}){const o=a.useMemo(()=>{var l;return t||!s?null:((l=r(s))==null?void 0:l.tabKey)??null},[t,r,s]),i=a.useMemo(()=>{var l;return!t||!s?null:((l=r(s))==null?void 0:l.tabKey)??null},[t,r,s]),c=a.useCallback(()=>{s&&n(l=>{const p=new URLSearchParams(l);return p.delete("activeTab"),p},{replace:!0})},[n,s]);return{requestedDesktopTabKey:o,requestedMobileTabKey:i,consumeRequestedActiveTab:c}}function Ud({ides:t,sendDaemonCommand:s,setToasts:r,setLocalUserMessages:n,resolveConversationByTarget:o}){a.useEffect(()=>{gt.setIdes(t)},[t]),a.useEffect(()=>{gt.setResolveAction((i,c,l)=>{s(i,c,l).catch(()=>{})})},[s]),a.useEffect(()=>{const i=gt.onToast(p=>{r(m=>m.some(g=>g.message===p.message&&p.timestamp-g.timestamp<3e3)?m:[...m.slice(-4),{id:p.id,message:p.message,type:p.type,timestamp:p.timestamp,targetKey:p.targetKey,actions:p.actions}]);const x=p.duration||5e3;setTimeout(()=>r(m=>m.filter(h=>h.id!==p.id)),x)}),c=gt.onSystemMessage((p,x)=>{var S,I;const m=o(p),h=(S=x._localId)==null?void 0:S.startsWith("sys_approval_"),g=!!(m&&(m.status==="waiting_approval"||(I=m.modalButtons)!=null&&I.length||m.modalMessage));h&&g||n(u=>({...u,[p]:[...u[p]||[],x]}))}),l=gt.onClearSystemMessage((p,x)=>{n(m=>{var h;return(h=m[p])!=null&&h.length?{...m,[p]:m[p].filter(g=>{var S;return!(g.role==="system"&&((S=g._localId)!=null&&S.startsWith(x)))})}:m})});return()=>{i(),c(),l()}},[r,n]),a.useEffect(()=>{const i=mo.on("status_event",c=>{gt.handleRawEvent(c,"ws")});return()=>{i()}},[]),a.useEffect(()=>{var c;const i=l=>{var b;const p=l.data;if((p==null?void 0:p.type)!=="notification_action"||typeof p.action!="string"||!p.action.startsWith("approval_")||!(p.daemonId||p.targetSessionId||p.targetKey))return;const x=p.targetSessionId||p.targetKey||p.daemonId,m=o(x),h=(m==null?void 0:m.routeId)||p.daemonId;if(!h)return;const g=Number(p.buttonIndex),S=p.button||((b=m==null?void 0:m.modalButtons)==null?void 0:b[g])||"Approve",I=String(S).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),u=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(I);s(h,"resolve_action",{action:u?"approve":"reject",button:S,...Number.isFinite(g)&&{buttonIndex:g},...(m==null?void 0:m.sessionId)&&{targetSessionId:m.sessionId},...p.targetSessionId&&{targetSessionId:p.targetSessionId}}).catch(y=>console.error("[SW Action] approval failed:",y))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",i),()=>{var l;return(l=navigator.serviceWorker)==null?void 0:l.removeEventListener("message",i)}},[o,s])}const zd="adhdev_dashboardLayout_v1",Fd="adhdev_dashboardDockview_v1",Vd="adhdev_dashboardDockviewHiddenRestore_v1",ys={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function kn(t,s){try{const r=localStorage.getItem(t);return r?JSON.parse(r):s}catch{return s}}function Ko(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Wo(t){return`${zd}:${t}`}function qd(t){const s=Wo(t);return kn(s,null)}function Gd(t,s){try{const r=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,n=Wo(t);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Oo(t){return`${Fd}:${t}`}function Yd(t){const s=Oo(t);return kn(s,null)}function Xd(t,s){try{const r=Oo(t);if(!s){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Ho(t){return`${Vd}:${t}`}function Jd(t){const s=Ho(t);return kn(s,{})}function Zd(t,s){try{const r=Ho(t);if(Object.keys(s).length===0){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Qd(){return{groupAssignments:[...ys.groupAssignments],focusedGroup:ys.focusedGroup,groupActiveTabIds:{...ys.groupActiveTabIds},groupTabOrders:{...ys.groupTabOrders},groupSizes:[...ys.groupSizes]}}function eu(){const[t]=a.useState(()=>Ko(typeof window<"u"?window.innerWidth:1280)),[s,r]=a.useState(()=>new Map),[n,o]=a.useState(0),[i,c]=a.useState({}),[l,p]=a.useState({}),[x,m]=a.useState([]),[h,g]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[S,I]=a.useState(!1),u=a.useCallback(()=>{if(S)return;const b=qd(t)??Qd();r(new Map(b.groupAssignments)),o(b.focusedGroup),c(b.groupActiveTabIds),p(b.groupTabOrders),m(b.groupSizes),I(!0)},[S,t]);return a.useEffect(()=>{S&&Gd(t,{groupAssignments:[...s.entries()],focusedGroup:n,groupActiveTabIds:i,groupTabOrders:l,groupSizes:x})},[S,t,s,n,i,l,x]),a.useEffect(()=>{const b=window.matchMedia("(max-width: 767px)"),y=d=>g(d.matches);return b.addEventListener("change",y),()=>b.removeEventListener("change",y)},[]),{groupAssignments:s,setGroupAssignments:r,focusedGroup:n,setFocusedGroup:o,groupActiveTabIds:i,setGroupActiveTabIds:c,groupTabOrders:l,setGroupTabOrders:p,groupSizes:x,setGroupSizes:m,isMobile:h,hasHydratedStoredLayout:S,hydrateStoredLayout:u}}function tu(t,s){if(!Array.isArray(t)||t.length!==1||!s)return!1;const r=t[0],n=[s.providerSessionId,s.sessionId].filter(o=>typeof o=="string"&&o.length>0);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function su({urlActiveTab:t,conversations:s,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:o,hydrateStoredLayout:i,setGroupActiveTabIds:c,setFocusedGroup:l,setSearchParams:p,historyModalOpen:x,activeConv:m,isRefreshingHistory:h,ides:g,handleRefreshHistory:S}){const I=a.useRef(!1),u=a.useRef(!1),b=a.useRef(null),y=a.useRef(!1);a.useEffect(()=>{if(!t||I.current||s.length===0)return;if(!o){i();return}const d=r(t);if(!d)return;const C=n.get(d.tabKey)??0;c(M=>({...M,[C]:d.tabKey})),l(C),I.current=!0,u.current=!0,b.current!=null&&(window.clearTimeout(b.current),b.current=null),p(M=>{const N=new URLSearchParams(M);return N.delete("activeTab"),N},{replace:!0})},[t,s,r,n,o,i,c,l,p]),a.useEffect(()=>{if(!(u.current||o)&&s.length!==0){if(!t){i(),u.current=!0;return}if(I.current){u.current=!0;return}if(b.current==null)return b.current=window.setTimeout(()=>{b.current=null,!(u.current||o)&&(i(),u.current=!0)},1500),()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null)}}},[t,s.length,o,i]),a.useEffect(()=>{if(!x){y.current=!1;return}if(!m||y.current||h)return;const d=g.find(C=>C.id===m.routeId);d&&(!d.chats||d.chats.length===0||tu(d.chats,m))&&(y.current=!0,S())},[x,m,h,g,S]),a.useEffect(()=>{if(!m)return;let d=null,C=0,M=-1,N=0;const f=()=>{d=null;const j=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(k=>k.offsetParent!==null);if(j.length===0){C<18&&(C+=1,d=requestAnimationFrame(f));return}let v=0;for(const k of j)k.scrollTop=k.scrollHeight,v+=k.scrollHeight;v===M?N+=1:(N=0,M=v),C+=1,!(N>=2||C>=18)&&(d=requestAnimationFrame(f))};return d=requestAnimationFrame(f),()=>{d!=null&&cancelAnimationFrame(d)}},[m==null?void 0:m.tabKey])}function ru({isMobile:t,location:s,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:o,conversations:i,ides:c,resolveConversationByTarget:l}){const[p,x]=a.useState(null),[m,h]=a.useState(null),g=a.useMemo(()=>{if(t||!n)return null;const y=l(n);return y&&!Ge(y)&&!qe(y)?y:null},[t,n,l]),S=a.useMemo(()=>{const y=p==null?void 0:p.routeId;if(!y)return null;const d=p!=null&&p.tabKey?i.find(C=>C.tabKey===p.tabKey):o?i.find(C=>C.tabKey===o):null;return(d==null?void 0:d.routeId)===y?d:Rt(i,y)},[i,p,o]),I=a.useMemo(()=>{if(S)return c.find(y=>y.id===S.routeId)},[c,S]);a.useEffect(()=>{g&&(x({routeId:g.routeId,tabKey:Xn(g)}),h(g),r({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,r,g]);const u=a.useCallback(y=>{y&&(x({routeId:y.routeId,tabKey:Xn(y)}),h(y))},[]),b=a.useCallback(()=>{x(null),h(null)},[]);return{remoteDialogConv:S,remoteDialogIdeEntry:I,remoteDialogActiveConv:m,setRemoteDialogActiveConv:h,openRemoteDialog:u,closeRemoteDialog:b}}function ds(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return t.sessionId?s:Ge(t)||qe(t)?{agentType:jt(t)}:t.streamSource==="agent-stream"?{agentType:jt(t)}:s}function Rs(t){return t?cr(t):""}function vs(t,s){t(r=>[...r,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Er(t,s){if(!Array.isArray(t)||t.length!==1||!s)return!1;const r=t[0];if((r==null?void 0:r.active)===!0)return!0;const n=[s.providerSessionId,s.sessionId].filter(o=>typeof o=="string"&&o.length>0);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function ma({sendDaemonCommand:t,activeConv:s,chats:r,updateRouteChats:n,setToasts:o,setLocalUserMessages:i,setClearedTabs:c}){const[l,p]=a.useState(!1),[x,m]=a.useState(!1),h=a.useCallback(async u=>{try{await t("standalone","launch_ide",{ideType:u,enableCdp:!0})}catch(b){console.error("Launch failed",b)}},[t]),g=a.useCallback(async(u,b)=>{try{const y=u||(s==null?void 0:s.daemonId)||"",d=await t(y,"switch_chat",{id:b,sessionId:b,...ds(s)}),C=d==null?void 0:d.result;if((d==null?void 0:d.success)===!0||C==="switched"||C==="switched-by-title")return;C===!1||C==="not_found"?vs(o,"⚠️ Session tab not found — try refreshing history"):typeof C=="string"&&C.startsWith("error:")?vs(o,`⚠️ Switch error: ${C}`):vs(o,"⚠️ Session switch failed")}catch(y){console.error("Switch failed",y),vs(o,`❌ Switch failed: ${y.message||"connection error"}`)}},[s,t,o]),S=a.useCallback(async()=>{if(!(!s||l)){p(!0);try{const u=Rs(s);await t(u,"new_chat",{...ds(s)}),c(b=>({...b,[s.tabKey]:Date.now()})),i(b=>({...b,[s.tabKey]:[]}))}catch(u){console.error("New chat failed",u)}finally{p(!1)}}},[s,l,t,c,i]),I=a.useCallback(async()=>{var u,b;if(!(!s||x)){m(!0);try{const y=Rs(s),d=async()=>t(y,"list_chats",{forceExpand:!0,...ds(s)});let C=await d(),M=(C==null?void 0:C.chats)||((u=C==null?void 0:C.result)==null?void 0:u.chats);Er(M,s)&&(await new Promise(N=>setTimeout(N,450)),C=await d(),M=(C==null?void 0:C.chats)||((b=C==null?void 0:C.result)==null?void 0:b.chats)),C!=null&&C.success&&Array.isArray(M)&&(n(s.routeId,M),Er(M,s)&&!Er(r,s)&&vs(o,"⚠️ History dialog did not fully open — try once more"))}catch(y){console.error("Refresh history failed",y)}finally{m(!1)}}},[s,r,x,t,n,o]);return{isCreatingChat:l,isRefreshingHistory:x,handleLaunchIde:h,handleSwitchSession:g,handleNewChat:S,handleRefreshHistory:I}}function nu(t,s){if(t.size!==s.size)return!1;for(const[r,n]of t)if(s.get(r)!==n)return!1;return!0}function au(t,s){return t.length!==s.length?!1:t.every((r,n)=>r===s[n])}function fa(t,s){const r=Object.keys(t),n=Object.keys(s);return r.length!==n.length?!1:r.every(o=>s[Number(o)]===t[Number(o)])}function qs(t,s){const r=new Set(s),n=s.length>0?[0]:[];for(const[c,l]of t)!r.has(c)||l<=0||n.includes(l)||n.push(l);n.sort((c,l)=>c-l);const o={};n.forEach((c,l)=>{o[c]=l}),n.length===0&&(o[0]=0);const i=new Map;for(const[c,l]of t){if(!r.has(c)||l<=0)continue;const p=o[l];typeof p=="number"&&p>0&&i.set(c,p)}return{assignments:i,groupCount:Math.max(1,n.length),mapping:o,usedGroups:n}}function xa(t,s){const r={};for(const[n,o]of Object.entries(t)){const i=s[Number(n)];typeof i=="number"&&(r[i]=o)}return r}function ou(t,s,r){if(s.length===0)return 0;if(typeof r[t]=="number")return r[t];const n=[...s].reverse().find(o=>o<t)??s[0];return r[n]??0}function iu(t,s,r){if(s.length<=1)return[];const n=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),o=n.length===s.length?n:Array(r).fill(100/r),i=o.reduce((c,l)=>c+l,0);return i>0?o.map(c=>c/i*100):Array(r).fill(100/r)}function ha(t,s){const r={};for(const[n,o]of Object.entries(t)){const i=Number(n);r[i>=s?i+1:i]=o}return r}function ba(t){return Array(t).fill(100/t)}function cu({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:r,setGroupActiveTabIds:n,setGroupTabOrders:o,groupSizes:i,setGroupSizes:c,isMobile:l,visibleConversations:p,visibleTabKeys:x}){const m=a.useRef(null),h=a.useMemo(()=>qs(t,x),[t,x]),g=h.assignments,S=a.useMemo(()=>l?1:h.groupCount,[h.groupCount,l]),I=S>1,u=a.useCallback((N,f)=>{s(j=>{const v=new Map(qs(j,x).assignments);return f===0?v.delete(N):v.set(N,f),v}),n(j=>({...j,[f]:N})),r(f)},[s,x,n,r]),b=a.useCallback(N=>{s(f=>{const j=qs(f,x).assignments,v=new Map;for(const[k,$]of j)$!==N&&($>N?v.set(k,$-1):v.set(k,$));return v}),c(f=>{if(f.length<=1)return[];const j=[...f];j.splice(N,1);const v=j.reduce((k,$)=>k+$,0);return v>0?j.map(k=>k/v*100):[]}),r(0)},[s,x,c,r]),y=a.useCallback((N,f)=>{f.preventDefault();const j=m.current;if(!j)return;const v=f.clientX,k=j.offsetWidth,$=i.length===S?[...i]:ba(S),E=T=>{const R=(T.clientX-v)/k*100,w=[...$];w[N]=Math.max(15,$[N]+R),w[N+1]=Math.max(15,$[N+1]-R),c(w)},W=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",E),document.addEventListener("mouseup",W)},[i,S,c]),d=a.useCallback((N,f,j)=>{if(S>=4)return;const v=j==="left"?f:f+1;s(k=>{const $=qs(k,x).assignments,E=new Map;for(const W of p){const T=$.get(W.tabKey)??0,V=T>=v?T+1:T;V>0&&E.set(W.tabKey,V)}return v>0&&E.set(N,v),E}),c(k=>{const $=k.length===S?[...k]:ba(S),E=$[f]??100/S,W=Math.max(15,E/2),T=Math.max(15,E/2),V=[...$];V[f]=W,V.splice(v,0,T);const R=V.reduce((w,B)=>w+B,0);return V.map(w=>w/R*100)}),n(k=>{const $=ha(k,v);return $[v]=N,$}),o(k=>{const $=ha(k,v);return $[v]=[N],$}),r(v)},[S,s,x,p,c,n,o,r]);a.useEffect(()=>{nu(t,g)||s(g)},[t,g,s]),a.useEffect(()=>{const{mapping:N,usedGroups:f}=h;n(j=>{const v=xa(j,N);return fa(j,v)?j:v}),o(j=>{const v=xa(j,N);return fa(j,v)?j:v}),r(j=>{const v=l?0:ou(j,f,N);return j===v?j:v}),c(j=>{const v=l?[]:iu(j,f,h.groupCount);return au(j,v)?j:v})},[h,l,n,o,r,c]);const C=a.useMemo(()=>{const N=Array.from({length:S},()=>[]);for(const f of p){const j=g.get(f.tabKey)??0,v=Math.min(j,S-1);N[v].push(f)}return N},[p,g,S]),M=a.useCallback(()=>{s(new Map),r(0)},[s,r]);return{containerRef:m,normalizedGroupAssignments:g,numGroups:S,isSplitMode:I,groupedConvs:C,moveTabToGroup:u,closeGroup:b,handleResizeStart:y,splitTabRelative:d,clearAllSplits:M}}function lu({ides:t,sendDaemonCommand:s}){const r="0.8.45",n=a.useMemo(()=>t.filter(m=>m.type!=="adhdev-daemon"?!1:Mo(m,r)).sort((m,h)=>Number(Cs(h,r))-Number(Cs(m,r))),[r,t]),o=a.useMemo(()=>n.some(m=>Cs(m,r)),[r,n]),[i,c]=a.useState(!1),[l,p]=a.useState({}),x=a.useCallback(async m=>{var h,g;p(S=>({...S,[m]:"upgrading"}));try{const S=await s(m,"daemon_upgrade",{});(h=S==null?void 0:S.result)!=null&&h.upgraded||(g=S==null?void 0:S.result)!=null&&g.success?p(I=>({...I,[m]:"done"})):p(I=>({...I,[m]:"error"}))}catch{p(S=>({...S,[m]:"error"}))}},[s]);return{versionMismatchDaemons:n,hasRequiredVersionDaemons:o,appVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:c,upgradingDaemons:l,handleBannerUpgrade:x}}function ga(t){return!t||typeof t!="object"?t:t.result&&typeof t.result=="object"?t.result:t}function Nn(t){return t instanceof Error?t.message:String(t||"")}function ya(t){const s=Nn(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function va(t,s){const r=Nn(s);return r?r.toLowerCase().includes("button not found")?`⚠️ **${t}** failed — button not found`:`⚠️ **${t}** failed — ${r}`:`⚠️ **${t}** unavailable`}function yr({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:r,setActionLogs:n,isStandalone:o}){const[i,c]=a.useState(!1),[l,p]=a.useState(!1),x=a.useRef(!1),m=a.useRef(null),h=a.useCallback(async u=>{if(!s)return;const b=u.trim();if(!b||x.current)return;const y=s.tabKey,d=Date.now(),C=m.current;if(C&&C.tabKey===y&&C.message===b&&d-C.timestamp<2e3)return;x.current=!0,p(!0),m.current={tabKey:y,message:b,timestamp:d};const M=`${d}-${Math.random().toString(36).slice(2,8)}`,N={role:"user",content:b,timestamp:d,_localId:M},f=!(Ge(s)||qe(s));f&&r(j=>({...j,[y]:[...j[y]||[],N]}));try{const j=Rs(s);if(!j)return;const v=await t(j,"send_chat",{message:b,...ds(s)}),k=ga(v);if(f&&(k!=null&&k.deduplicated||(k==null?void 0:k.sent)===!1)){r($=>({...$,[y]:($[y]||[]).filter(E=>E._localId!==M)}));return}if((k==null?void 0:k.success)===!1)throw new Error((k==null?void 0:k.error)||"Send failed");setTimeout(()=>{const $=Date.now()-6e4;r(E=>{const W=E[y];if(!W)return E;const T=W.filter(V=>V.timestamp>$);return T.length===W.length?E:{...E,[y]:T}})},6e4)}catch(j){const v=Nn(j);v.toLowerCase().includes("provider sendmessage did not confirm send")?console.warn("Send not confirmed by provider script:",v):console.error("Send failed",j),f&&r(k=>({...k,[y]:(k[y]||[]).filter($=>$._localId!==M)}))}finally{x.current=!1,p(!1)}},[s,t,r]),g=a.useCallback(async()=>{if(s)try{if(!s.hostIdeType)return;await t(s.routeId,"launch_ide",{ideType:s.hostIdeType,enableCdp:!0})}catch(u){console.error("Relaunch failed",u)}},[s,t]),S=a.useCallback(async u=>{if(s)try{const y=(s.modalButtons||[]).indexOf(u),d=u.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),C=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(d),M=Rs(s);if(!M)return;const N=await t(M,"resolve_action",{button:u,action:C?"approve":"reject",...y>=0&&{buttonIndex:y},...ds(s)}),f=ga(N);f.success||n(j=>[...j,{routeId:s.tabKey,text:va(u,f==null?void 0:f.error),timestamp:Date.now()}])}catch(b){ya(b)||console.error("[ModalButton] Error:",b),n(y=>[...y,{routeId:s.tabKey,text:ya(b)?va(u,b):`❌ **${u}** error`,timestamp:Date.now()}])}},[s,t,n]),I=a.useCallback(async()=>{if(!(!s||i)){c(!0);try{await t(s.routeId,"focus_session",{...s.sessionId&&{targetSessionId:s.sessionId}})}catch(u){console.error("Focus agent failed",u)}finally{c(!1)}}},[s,i,t]);return{isSendingChat:l,isFocusingAgent:i,handleSendChat:h,handleRelaunch:g,handleModalButton:S,handleFocusAgent:I}}const Sn=a.memo(function({activeConv:s,clearToken:r,isCliTerminal:n,ideEntry:o,terminalRef:i,handleModalButton:c,handleRelaunch:l,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u=!0}){const b=Eo(s),y=b.status||b.modalMessage||b.modalButtons?{...s,...b.status?{status:b.status}:{},...b.modalMessage!==void 0?{modalMessage:b.modalMessage}:{},...b.modalButtons!==void 0?{modalButtons:b.modalButtons}:{}}:s;return e.jsxs(e.Fragment,{children:[e.jsx(so,{activeConv:y,onModalButton:c}),y.transport!=="pty"&&y.transport!=="acp"&&y.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(es,{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:l,children:"Relaunch with CDP"})]})}):null,y.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:n?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(yl,{activeConv:y,clearToken:r,terminalRef:i,handleSendChat:p,isSendingChat:x,isVisible:n})}),!n&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Jr,{activeConv:y,ideEntry:o,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u})})]}):e.jsx(Jr,{activeConv:y,ideEntry:o,handleSendChat:p,isSendingChat:x,handleFocusAgent:m,isFocusingAgent:h,actionLogs:g,userName:S,scrollToBottomRequestNonce:I,isInputActive:u})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce&&t.isInputActive===s.isInputActive);function du({selectedConversation:t,isAcp:s,isStandalone:r,selectedIdeEntry:n,actionLogs:o,userName:i,isSendingChat:c,isFocusingAgent:l,onBack:p,onOpenNativeConversation:x,onOpenMachine:m,onOpenHistory:h,onOpenRemote:g,onHideConversation:S,onStopCli:I,cliViewMode:u,onSetCliViewMode:b,handleSendChat:y,handleFocusAgent:d,handleModalButton:C,handleRelaunch:M}){const N=a.useRef(null),f=Ge(t)&&!s,j=f&&u==="terminal",v=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${v} 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:p,type:"button","aria-label":"Back",children:e.jsx(cn,{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:Qe(t)}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(io,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>x(t),onOpenMachine:()=>m(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[f&&u&&e.jsx(bn,{mode:u,onChange:b,compact:!0}),f&&I&&e.jsx("button",{onClick:()=>{I(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(wt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",children:e.jsx(dn,{size:14})}),!s&&!f&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>g(t),type:"button",children:e.jsx(Nt,{size:14})}),S&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>S(t),type:"button",title:"Close chat",children:e.jsx(wt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Sn,{activeConv:t,clearToken:0,isCliTerminal:j,ideEntry:n,terminalRef:N,handleModalButton:C,handleRelaunch:M,handleSendChat:y,isSendingChat:c,handleFocusAgent:d,isFocusingAgent:l,actionLogs:o,userName:i})})]})}const Dr={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 uu(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Uo(){const[t,s]=a.useState("unix"),[r,n]=a.useState("powershell"),[o,i]=a.useState(!1),c=t==="unix"?"unix":r;a.useEffect(()=>{s(uu())},[]);const l=a.useCallback(()=>{navigator.clipboard.writeText(Dr[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:l,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Dr[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Dr[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:o?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function zo({section:t,onSectionChange:s}){const r=[{key:"machines",label:"Machines",icon:Nt},{key:"chats",label:"Chats",icon:Bt}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:o,icon:i})=>{const c=t===n;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(n),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(i,{size:15})}),e.jsx("span",{children:o})]},n)})})})}function Gs({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 is({children:t,className:s=""}){return e.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function ws({icon:t,title:s,subtitle:r,children:n}){return e.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Ys({item:t,type:s,getAvatarText:r,onOpenConversation:n}){const o=s==="needs_attention"||s==="task_complete",i=s==="working",c=s==="earlier",l=s==="task_complete",{isReconnecting:p,isConnecting:x}=xs(t.conversation),m=Qe(t.conversation),h=rs(t.conversation),g=xo(t.conversation,{requiresAction:s==="needs_attention"}),S=o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":c?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",I=o?"bg-accent-primary shadow-glow":i?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":c?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",u=c?"text-text-secondary":"text-text-primary",b=c?"text-text-muted":"text-text-secondary",y=c?"text-text-secondary opacity-80":"text-text-muted",d=c?"text-text-muted opacity-80":"text-text-muted",C="text-[color:var(--status-warning)]";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] ${S}`,onClick:()=>n(t.conversation),type:"button",children:[o||i?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}`,style:o?{color:"var(--accent-on-primary)"}:void 0,children:r(m)}),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 truncate tracking-tight ${u}`,children:m}),!i&&e.jsx("span",{className:`text-[11px] font-medium shrink-0 ${d}`,children:to(t.timestamp)})]}),e.jsxs("div",{className:`text-[12px] font-medium truncate flex items-center ${b}`,children:[h,p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:`${C} animate-pulse`,children:"Reconnecting…"})]}):x?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-text-muted",children:"Connecting…"})]}):g==="Action needed"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:C,children:"Action needed"})]})]}),e.jsx("div",{className:`mt-0.5 truncate text-[13px] ${y}`,children:t.preview})]}),o&&!l&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),l&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Done"}),i&&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 wa({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 pu({section:t,attentionItems:s,unreadItems:r,workingItems:n,completedItems:o,hiddenConversations:i,machineCards:c,getAvatarText:l,onOpenConversation:p,onShowConversation:x,onShowAllHidden:m,onOpenNewSession:h,onOpenMachine:g,onOpenSettings:S,onSectionChange:I,wsStatus:u="connected",isStandalone:b=!1}){const y=u==="disconnected"||u==="reconnecting"||u==="offline"||u==="auth_failed",d=c.length>0,C=s.length>0||r.length>0||n.length>0||o.length>0,M=t==="machines"?"Machines":"Chats",N=b?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",f=b?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]";return e.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${N}`,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:M}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||r.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(hr,{size:13}),e.jsx("span",{children:s.length+r.length})]}),e.jsx("button",{onClick:S,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(fr,{size:18})})]})]})}),e.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${f}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:y?e.jsx(ws,{icon:e.jsx(wa,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:u==="offline"?"Your device appears to be offline. Waiting for network…":u==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(ws,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:b?"Waiting for your daemon":"Connect your first machine",subtitle:b?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!b&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Uo,{})})}):e.jsx(is,{children:c.map((j,v)=>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] ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>g(j.id),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:l(j.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:j.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[j.unread," new"]}):j.total>0?`${j.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:j.subtitle}),j.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[j.total," chat",j.total!==1?"s":"",j.unread>0?` · ${j.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},j.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Needs attention",className:"mb-0"}),e.jsx(is,{children:s.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"needs_attention",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(is,{children:r.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"task_complete",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Gs,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(is,{children:n.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"working",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[o.length>0&&e.jsx(Gs,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),o.length>0?e.jsx(is,{children:o.map((j,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Ys,{item:j,type:"earlier",getAvatarText:l,onOpenConversation:p})},j.conversation.tabKey))}):C?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):y?e.jsx(ws,{icon:e.jsx(wa,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):d?e.jsx(ws,{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(Bt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are available. Open a machine, wait for P2P to connect, then launch your first IDE, CLI, or ACP session."}):e.jsx(ws,{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"&&i.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:m,children:"Restore all"})]}),e.jsx(is,{className:"bg-bg-secondary/25",children:i.map((j,v)=>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 ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(j),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-border-subtle text-text-secondary",children:l(Qe(j))}),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:Qe(j)}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:rs(j)}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},j.tabKey))})]})]}),t==="chats"&&h&&e.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:h,"aria-label":"Start new session",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx(zo,{section:t,onSectionChange:I})]})}function mu(t){const s=t.trim();if(!s)return null;if(s.startsWith("~"))return s;if(/^[A-Za-z]:$/.test(s))return`${s[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(s))return`${s[0].toUpperCase()}:${s.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(s))return`${s[0].toUpperCase()}:\\${s.slice(2).replace(/[\\/]+/g,"\\")}`;const r=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),o=(r[2]||"").replace(/[\\/]+/g,"\\");return o?`${n}:\\${o}`:`${n}:\\`}return null}function vr(t,s=[]){if(t==="win32"){for(const r of s){if(typeof r!="string")continue;const n=mu(r);if(n)return n}return"C:\\"}for(const r of s){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function fu(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const r=s.includes("\\")?"\\":"/",n=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}async function wr(t,s,r){const n=await t(s,"file_list_browse",{path:r});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Could not browse folder");const o=typeof(n==null?void 0:n.path)=="string"?n.path:r,i=o.includes("\\")?"\\":"/",c=(p,x)=>/^[A-Za-z]:\\?$/.test(p)?`${p.replace(/\\?$/,"\\")}${x}`:p==="/"||p==="\\"?`${i}${x}`:`${p.replace(/[\\/]+$/,"")}${i}${x}`,l=Array.isArray(n==null?void 0:n.files)?n.files.filter(p=>(p==null?void 0:p.type)==="directory"&&typeof(p==null?void 0:p.name)=="string").map(p=>({name:p.name,path:c(o,p.name)})).sort((p,x)=>p.name.localeCompare(x.name)):[];return{path:o,directories:l}}function jr({title:t,description:s,currentPath:r,directories:n,busy:o=!1,error:i="",confirmLabel:c="Use this folder",onClose:l,onNavigate:p,onConfirm:x}){const[m,h]=a.useState(r);a.useEffect(()=>{h(r)},[r]);const g=fu(r),S=m.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:l,"aria-label":"Close folder browser",children:e.jsx(wt,{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:()=>{!g||o||p(g)},disabled:!g||o,children:[e.jsx(cn,{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:m,onChange:I=>h(I.target.value),onKeyDown:I=>{I.key!=="Enter"||!S||o||(I.preventDefault(),p(S))},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:()=>{!S||o||p(S)},disabled:!S||o,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:o?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):i?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:i}):n.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:n.map(I=>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:()=>p(I.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(us,{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:I.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:I.path})]})]},I.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:l,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>x(S||r),disabled:!S&&!r||o,children:c})]})]})})}function Cn({title:t,description:s,details:r,workspaceOptions:n,selectedWorkspaceKey:o,onWorkspaceChange:i,confirmLabel:c="Launch",busy:l=!1,showArgsInput:p,argsValue:x,onArgsChange:m,showModelInput:h,modelValue:g,onModelChange:S,historyProviderNode:I,onConfirm:u,onCancel:b}){const y=n==null?void 0:n.find(d=>d.key===o);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:b,"aria-label":"Close launch confirmation",children:e.jsx(wt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n&&n.length>0&&i&&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:o||"",onChange:d=>i(d.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:l,children:n.map(d=>e.jsx("option",{value:d.key,children:d.label},d.key))}),(y==null?void 0:y.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:y.description})]}),I,r.map(d=>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:d.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:d.value})]},`${d.label}:${d.value}`)),h&&S&&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:"Language Model (Optional)"}),e.jsx("input",{type:"text",value:g||"",onChange:d=>S(d.target.value),placeholder:"Auto-detect or default",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:l})]}),p&&m&&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:"CLI Arguments (Optional)"}),e.jsx("input",{type:"text",value:x||"",onChange:d=>m(d.target.value),placeholder:"e.g. --experimental",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:l})]})]}),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:b,disabled:l,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:u,disabled:l,children:[e.jsx(un,{size:14}),l?"Launching…":c]})]})]})})}function ja(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function Zt(t){const{machine:s,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:o=!0}=t,i=[];o&&i.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const p of s.workspaces||[])i.push({key:`saved:${p.id}`,label:`${p.id===s.defaultWorkspaceId?"⭐ ":""}${ja(p.path,p.label)}`,description:p.path,workspaceId:p.id,workspacePath:p.path});const c=(r==null?void 0:r.trim())||"",l=c?(s.workspaces||[]).find(p=>p.path===c):null;if(c&&!l&&i.push({key:`custom:${c}`,label:ja(c),description:c,workspaceId:null,workspacePath:c}),n){const p=`saved:${n}`;if(i.some(x=>x.key===p))return{options:i,selectedKey:p}}return l?{options:i,selectedKey:`saved:${l.id}`}:c?{options:i,selectedKey:`custom:${c}`}:{options:i,selectedKey:"__home__"}}function $r(t,s,r){return t?"ide":s>0?"cli":r>0?"acp":null}function xu({selectedMachineEntry:t,cliProviders:s,acpProviders:r,machineAction:n,onBrowseDirectory:o,onListSavedSessions:i}){var fe,F,xe,Ie;const c=Bs(),[l,p]=a.useState(!1),x=(((fe=t.detectedIdes)==null?void 0:fe.length)||0)>0,m=a.useMemo(()=>(t.workspaces||[]).map(ge=>({id:ge.id,path:ge.path,label:ge.label})),[t]),h=t.defaultWorkspaceId||null,[g,S]=a.useState(h||((F=m[0])==null?void 0:F.id)||""),[I,u]=a.useState(""),[b,y]=a.useState(""),[d,C]=a.useState([]),[M,N]=a.useState(!1),[f,j]=a.useState(""),[v,k]=a.useState(!1),[$,E]=a.useState($r(x,s.length,r.length)),W=a.useRef(null),[T,V]=a.useState(null),R=a.useRef("__home__"),[w,B]=a.useState("__home__"),[ee,L]=a.useState(""),[D,O]=a.useState(""),[z,Q]=a.useState(""),[re,je]=a.useState([]),[Y,ne]=a.useState(!1),[_,pe]=a.useState(!1),me=a.useRef(null);a.useEffect(()=>{(!t.workspaces||!t.availableProviders||!t.detectedIdes||!t.recentLaunches)&&c(t.id,{minFreshMs:3e4}).catch(()=>{})},[c,t]);const J=g==="__custom__"?I.trim():((xe=m.find(ge=>ge.id===g))==null?void 0:xe.path)||"",ie=g==="__custom__"&&!!J&&n.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(n.message),se=g!=="__custom__"&&((Ie=m.find(ge=>ge.id===g))==null?void 0:Ie.path)||"",he=a.useCallback(async ge=>{N(!0),j("");try{const Ee=await o(ge);y(Ee.path),u(Ee.path),C(Ee.directories)}catch(Ee){j(Ee instanceof Error?Ee.message:"Could not load folder")}finally{N(!1)}},[o]),ce=a.useCallback(()=>{var Ee,Ke;S("__custom__"),k(!0);const ge=vr(t.platform,[I.trim(),se,(Ee=m.find(He=>He.id===h))==null?void 0:Ee.path,(Ke=m[0])==null?void 0:Ke.path]);he(ge)},[I,h,he,se,t.platform,m]),be=a.useCallback(ge=>{if(ge!=null&&ge.workspaceId){S(ge.workspaceId),u("");return}if(ge!=null&&ge.workspacePath){S("__custom__"),u(ge.workspacePath);return}S(""),u("")},[]),Z=a.useCallback(ge=>{if(S(ge),ge==="__custom__"){ce();return}u("")},[ce]),oe=a.useCallback(ge=>{S("__custom__"),u(ge)},[]),ae=a.useCallback((ge,Ee)=>{W.current=Ee,R.current=ge.selectedWorkspaceKey||"__home__",B(ge.selectedWorkspaceKey||"__home__"),L(ge.initialArgs||""),O(ge.initialModel||""),Q(""),je([]),V(ge),ge.providerType&&i&&(ne(!0),i(ge.providerType).then(Ke=>je(Ke||[])).catch(Ke=>console.warn("Failed to load saved sessions",Ke)).finally(()=>ne(!1)))},[i]),ke=a.useCallback(()=>{W.current&&(pe(!0),W.current().finally(()=>{W.current=null,pe(!1),V(null)}))},[]),we=a.useCallback(()=>{W.current=null,V(null)},[]),P=a.useCallback(ge=>{R.current=ge,B(ge)},[]);return a.useEffect(()=>{var ge;me.current!==t.id&&(me.current=t.id,S(h||((ge=m[0])==null?void 0:ge.id)||"__custom__"),u(""),y(""),C([]),j(""),k(!1),E($r(x,s.length,r.length)))},[r.length,s.length,h,x,t.id,m]),a.useEffect(()=>{var ge;g!=="__custom__"&&(g&&m.some(Ee=>Ee.id===g)||S(h||((ge=m[0])==null?void 0:ge.id)||"__custom__"))},[h,g,m]),a.useEffect(()=>{$==="ide"&&x||$==="cli"&&s.length>0||$==="acp"&&r.length>0||E($r(x,s.length,r.length))},[$,r.length,s.length,x]),{showAllRecent:l,setShowAllRecent:p,hasIdeOptions:x,workspaceRows:m,defaultWorkspaceId:h,workspaceChoice:g,customWorkspacePath:I,browseCurrentPath:b,browseDirectories:d,browseBusy:M,browseError:f,browseDialogOpen:v,activeLauncherKind:$,launchConfirm:T,launchConfirmWorkspaceKeyRef:R,launchConfirmWorkspaceKey:w,launchConfirmArgs:ee,launchConfirmModel:D,launchConfirmResumeId:z,launchConfirmSavedSessions:re,launchConfirmSessionsLoading:Y,launchConfirmBusy:_,resolvedWorkspacePath:J,canCreateMissingWorkspace:ie,openBrowseDialog:ce,loadBrowsePath:he,handleWorkspaceChoiceChange:Z,chooseCustomWorkspacePath:oe,setCustomWorkspacePath:u,setBrowseDialogOpen:k,setActiveLauncherKind:E,openLaunchConfirm:ae,handleConfirmLaunch:ke,closeLaunchConfirm:we,setWorkspaceSelectionFromOption:be,setLaunchConfirmWorkspaceKeyAndSync:P,setLaunchConfirmArgs:L,setLaunchConfirmModel:O,setLaunchConfirmResumeId:Q}}function hu({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:o,selectedMachineNeedsUpgrade:i,appVersion:c,machineAction:l,isStandalone:p,section:x,showBottomNav:m,onBack:h,onSectionChange:g,onOpenConversation:S,onOpenRecent:I,onOpenMachineDetails:u,onMachineUpgrade:b,onLaunchDetectedIde:y,onAddWorkspace:d,onBrowseDirectory:C,onLaunchWorkspaceProvider:M,onListSavedSessions:N}){const f=w=>w==="ide"?"IDE":w==="cli"?"CLI":"ACP",j=r.slice(0,4),v=s.slice(0,3),k=xu({selectedMachineEntry:t,cliProviders:n,acpProviders:o,machineAction:l,onBrowseDirectory:C,onListSavedSessions:N}),$=a.useMemo(()=>j.map(w=>({key:`recent-launch:${w.id}`,primary:w.label,secondary:`${f(w.kind)}${w.subtitle?` · ${w.subtitle}`:""}`,onClick:()=>{const{options:B,selectedKey:ee}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspacePath:w.workspace});k.openLaunchConfirm({title:`Launch ${w.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:B,selectedWorkspaceKey:ee,details:[{label:"Mode",value:f(w.kind)},...w.providerType?[{label:"Provider",value:w.providerType}]:[]]},async()=>{const L=B.find(D=>D.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(L),await I({...w,workspace:(L==null?void 0:L.workspacePath)??null})})}})),[k,I,j]),E=a.useMemo(()=>v.map(w=>({key:`recent-chat:${w.conversation.tabKey}`,primary:Qe(w.conversation),secondary:xl(w.conversation,{timestampLabel:w.timestamp?to(w.timestamp):null}),unread:w.unread,onClick:()=>S(w.conversation)})),[S,v]),W=k.showAllRecent?$:$.slice(0,4),T=$.length>0,V=E.length>0,R=p?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`flex items-center justify-between gap-3 ${R} 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:h,type:"button","aria-label":"Back",children:e.jsx(cn,{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:kt(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:[V&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:E.map(w=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${w.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:w.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:w.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:w.secondary})]},w.key))})]}),T&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:W.map(w=>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:w.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:w.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:w.secondary})]},w.key))}),$.length>4&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>k.setShowAllRecent(w=>!w),children:k.showAllRecent?"Show fewer":`Show ${$.length-4} more`})})]}),(k.hasIdeOptions||n.length>0||o.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:k.workspaceChoice,onChange:w=>k.handleWorkspaceChoiceChange(w.target.value),className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:k.workspaceRows.length>0?e.jsxs(e.Fragment,{children:[k.workspaceRows.map(w=>e.jsxs("option",{value:w.id,children:[w.id===k.defaultWorkspaceId?"⭐ ":"",br(w.path,w.label)||w.path]},w.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),k.workspaceChoice==="__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(us,{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:k.resolvedWorkspacePath||k.browseCurrentPath||"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:k.openBrowseDialog,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:()=>{k.resolvedWorkspacePath&&d(k.resolvedWorkspacePath)},disabled:!k.resolvedWorkspacePath||k.browseBusy,children:"Save as workspace"})]})]}),k.resolvedWorkspacePath&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[k.hasIdeOptions&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("ide"),children:"IDE"}),n.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("cli"),children:"CLI"}),o.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${k.activeLauncherKind==="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:()=>k.setActiveLauncherKind("acp"),children:"ACP"})]}),k.activeLauncherKind&&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:k.activeLauncherKind==="ide"?"Choose an IDE":k.activeLauncherKind==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:k.activeLauncherKind==="ide"?(t.detectedIdes||[]).slice(0,6).map(w=>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:B,selectedKey:ee}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspaceId:k.workspaceChoice!=="__custom__"?k.workspaceChoice:null,currentWorkspacePath:k.resolvedWorkspacePath});k.openLaunchConfirm({title:`Launch ${w.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:B,selectedWorkspaceKey:ee,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:w.name}]},async()=>{const L=B.find(D=>D.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(L),y(w.type,{workspacePath:(L==null?void 0:L.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:w.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath||"Use selected workspace"})]},w.type)):(k.activeLauncherKind==="cli"?n:o).map(w=>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 B=k.activeLauncherKind==="cli"?"cli":"acp",{options:ee,selectedKey:L}=Zt({machine:{workspaces:k.workspaceRows,defaultWorkspaceId:k.defaultWorkspaceId},currentWorkspaceId:k.workspaceChoice!=="__custom__"?k.workspaceChoice:null,currentWorkspacePath:k.resolvedWorkspacePath});k.openLaunchConfirm({title:`Launch ${w.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${B.toUpperCase()}`,workspaceOptions:ee,selectedWorkspaceKey:L,details:[{label:"Mode",value:B.toUpperCase()},{label:"Provider",value:w.displayName}],showArgsInput:!0,showModelInput:B==="acp",initialArgs:"",initialModel:"",providerType:w.type},async()=>{const D=ee.find(O=>O.key===k.launchConfirmWorkspaceKeyRef.current);k.setWorkspaceSelectionFromOption(D),M(B,w.type,{workspaceId:(D==null?void 0:D.workspaceId)??null,workspacePath:(D==null?void 0:D.workspacePath)??null,args:k.launchConfirmArgs,model:k.launchConfirmModel,resumeSessionId:k.launchConfirmResumeId||null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[w.icon?`${w.icon} `:"",w.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:k.resolvedWorkspacePath||"Use selected workspace"})]},w.type))})]}),l.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${l.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[l.message,k.canCreateMissingWorkspace&&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:()=>d(k.resolvedWorkspacePath,{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:[i&&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:b,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:u,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"})]})]})]})]}),k.browseDialogOpen&&e.jsx(jr,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:k.browseCurrentPath,directories:k.browseDirectories,busy:k.browseBusy,error:k.browseError,confirmLabel:"Use this folder",onClose:()=>k.setBrowseDialogOpen(!1),onNavigate:w=>{k.loadBrowsePath(w)},onConfirm:w=>{k.chooseCustomWorkspacePath(w),k.setBrowseDialogOpen(!1)}}),k.launchConfirm&&e.jsx(Cn,{title:k.launchConfirm.title,description:k.launchConfirm.description,details:k.launchConfirm.details,workspaceOptions:k.launchConfirm.workspaceOptions,selectedWorkspaceKey:k.launchConfirmWorkspaceKey,onWorkspaceChange:k.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:k.launchConfirm.confirmLabel,busy:k.launchConfirmBusy,showArgsInput:k.launchConfirm.showArgsInput,argsValue:k.launchConfirmArgs,onArgsChange:k.setLaunchConfirmArgs,showModelInput:k.launchConfirm.showModelInput,modelValue:k.launchConfirmModel,onModelChange:k.setLaunchConfirmModel,historyProviderNode:k.launchConfirm.providerType&&(k.launchConfirmSessionsLoading||k.launchConfirmSavedSessions.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume from history"}),k.launchConfirmSessionsLoading&&e.jsx("div",{className:"text-[10px] text-text-secondary font-medium",children:"Loading..."})]}),e.jsxs("select",{value:k.launchConfirmResumeId,onChange:w=>k.setLaunchConfirmResumeId(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:k.launchConfirmBusy||k.launchConfirmSessionsLoading,children:[e.jsx("option",{value:"",children:"Start a new session"}),k.launchConfirmSavedSessions.map(w=>e.jsxs("option",{value:w.providerSessionId,disabled:!w.canResume,children:[w.title||w.providerSessionId," ",w.canResume?"":"(workspace missing)"]},w.providerSessionId))]})]}),onConfirm:k.handleConfirmLaunch,onCancel:k.closeLaunchConfirm}),m&&e.jsx(zo,{section:x,onSectionChange:g})]})}function Fo(t){var r;const s=((r=t.p2p)==null?void 0:r.state)||"";return s==="connected"?"Connected":s==="connecting"||s==="new"||s==="checking"?"Connecting":"Offline"}function bu(t,s){if(!t)return[];const r=t.recentLaunches||[];return r.length>0?r.map(n=>({id:n.id,label:n.title||n.providerName||n.providerType,kind:n.kind,providerType:n.providerType,providerSessionId:n.providerSessionId,subtitle:n.currentModel||n.workspace||void 0,workspace:n.workspace,currentModel:n.currentModel})):s.filter(n=>n.type!=="adhdev-daemon"&&n.daemonId===t.id).map(n=>{var i,c,l,p,x;const o=Ls(n)?"cli":ls(n)?"acp":"ide";return{id:`${o}:${n.type}:${n.workspace||""}`,label:((i=n.activeChat)==null?void 0:i.title)||(Ls(n)?n.cliName||n.type:ls(n)&&n.cliName||n.type),kind:o,providerType:n.type,providerSessionId:n.providerSessionId,subtitle:ls(n)?n.currentModel||n.workspace||void 0:n.workspace||void 0,workspace:n.workspace||void 0,currentModel:n.currentModel,timestamp:((x=(p=(l=(c=n.activeChat)==null?void 0:c.messages)==null?void 0:l.at)==null?void 0:p.call(l,-1))==null?void 0:x.timestamp)||0}}).sort((n,o)=>o.timestamp-n.timestamp).map(({timestamp:n,...o})=>o)}function gu(t,s){const r=new Map;for(const n of s){const o=Ut(n.conversation),i=r.get(o);i?i.push(n):r.set(o,[n])}return t.map(n=>{const o=r.get(n.id)||[],i=[...o].sort((h,g)=>g.timestamp-h.timestamp)[0]||null,c=(i==null?void 0:i.conversation)||null,l=Xr(n),p=o.filter(h=>h.unread||h.requiresAction).length,x=Fo(n),m=[n.platform||"machine",x].filter(Boolean);return{id:n.id,label:kt(n,{fallbackId:n.id}),subtitle:m.join(" · "),unread:p,total:o.length,latestConversation:c,latestTimestamp:(i==null?void 0:i.timestamp)||0,fallbackActivityAt:l,preview:c?hl(c):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((n,o)=>{const i=n.latestTimestamp||n.fallbackActivityAt||0,c=o.latestTimestamp||o.fallbackActivityAt||0;return c!==i?c-i:n.label.localeCompare(o.label)})}function Xs(t,s){var r;if(!(typeof window>"u"))try{if(!(!!((r=import.meta.env)!=null&&r.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function yu({conversations:t,machineEntries:s,items:r,selectedConversation:n,selectedTabKey:o,screen:i,liveSessionInboxState:c,sendDaemonCommand:l,requestedActiveTabKey:p,onRequestedActiveTabConsumed:x,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:g,onRequestedMobileSectionConsumed:S,setSelectedTabKey:I,setScreen:u,setSelectedMachineId:b,setSection:y,setMachineBackTarget:d,resetMachineAction:C}){const M=a.useRef(null),N=a.useCallback(f=>{if(!(f!=null&&f.sessionId))return;const j=_s(f,c),v=Math.max(Date.now(),Jt(f),j.lastUpdated||0);Xs("mark_read:start",{tabKey:f.tabKey,sessionId:f.sessionId,displayPrimary:Qe(f),inboxBucket:j.inboxBucket,unread:j.unread,lastSeenAt:j.lastSeenAt,lastUpdated:j.lastUpdated,activityAt:Jt(f),readAt:v}),l(Ut(f)||f.routeId,"mark_session_seen",{sessionId:f.sessionId,seenAt:v}).then(k=>{Xs("mark_read:result",{tabKey:f.tabKey,sessionId:f.sessionId,result:k})}).catch(k=>{Xs("mark_read:error",{tabKey:f.tabKey,sessionId:f.sessionId,error:k instanceof Error?k.message:String(k)})})},[c,l]);return a.useEffect(()=>{var j;if(!n){u("inbox"),I(((j=t[0])==null?void 0:j.tabKey)||null),M.current=null;return}if(i!=="chat"){M.current=null;return}const f=`${n.tabKey}:${n.sessionId||""}`;M.current!==f&&(M.current=f,N(n))},[t,N,i,n,u,I]),a.useEffect(()=>{if(!p)return;const f=t.find(j=>j.tabKey===p);f&&(I(f.tabKey),u("chat"),x==null||x())},[t,x,p,u,I]),a.useEffect(()=>{if(!m)return;const f=s.find(j=>j.id===m);f&&(b(f.id),C(),y("machines"),d("inbox"),u("machine"),h==null||h())},[s,h,m,C,d,u,y,b]),a.useEffect(()=>{g&&(y(g),u("inbox"),S==null||S())},[S,g,u,y]),a.useEffect(()=>{const f=r.filter(j=>j.inboxBucket==="task_complete"||j.unread);f.length!==0&&Xs("inbox_state",{screen:i,selectedTabKey:o,items:f.map(j=>{const v=_s(j.conversation,c);return{liveState:v,tabKey:j.conversation.tabKey,sessionId:j.conversation.sessionId,displayPrimary:Qe(j.conversation),serverBucket:v.inboxBucket,computedBucket:j.inboxBucket,serverUnread:v.unread,computedUnread:j.unread,lastSeenAt:v.lastSeenAt,lastUpdated:v.lastUpdated,activityAt:Jt(j.conversation)}})})},[r,c,i,o]),{markConversationRead:N}}function vu(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function ka(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function wu(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function ju({sendDaemonCommand:t,navigate:s,ides:r,conversations:n}){const[o,i]=a.useState("idle"),[c,l]=a.useState(""),[p,x]=a.useState(null),m=a.useCallback(()=>{i("idle"),l(""),x(null)},[]),h=a.useCallback(async(d,C,M)=>{var N;try{i("loading"),l(`Launching ${C}…`);const f={ideType:C,enableCdp:!0};(N=M==null?void 0:M.workspacePath)!=null&&N.trim()&&(f.workspace=M.workspacePath.trim()),await t(d,"launch_ide",f),i("done"),l(`${C} launch requested`)}catch(f){i("error"),l(f instanceof Error?f.message:"Launch IDE failed"),console.error("Launch IDE failed",f)}},[t]),g=a.useCallback(async(d,C,M)=>{if(C.trim())try{i("loading"),l(M!=null&&M.createIfMissing?"Creating folder…":"Saving workspace…");const N=await t(d,"workspace_add",{path:C.trim(),createIfMissing:(M==null?void 0:M.createIfMissing)===!0});if(N!=null&&N.success){i("done"),l(M!=null&&M.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),l((N==null?void 0:N.error)||"Could not save workspace")}catch(N){i("error"),l(N instanceof Error?N.message:"Could not save workspace")}},[t]),S=a.useCallback(async d=>{var C,M,N,f,j,v;try{i("loading"),l("Starting daemon upgrade…");const k=await t(d,"daemon_upgrade",{});if((C=k==null?void 0:k.result)!=null&&C.alreadyLatest){i("done"),l(`Already on v${((M=k==null?void 0:k.result)==null?void 0:M.version)||"latest"}.`);return}if((N=k==null?void 0:k.result)!=null&&N.upgraded||(f=k==null?void 0:k.result)!=null&&f.success){i("done"),l(`Upgrade to v${((j=k==null?void 0:k.result)==null?void 0:j.version)||"latest"} started. Daemon is restarting…`);return}i("error"),l(((v=k==null?void 0:k.result)==null?void 0:v.error)||"Upgrade failed")}catch(k){i("error"),l(k instanceof Error?k.message:"Upgrade failed")}},[t]),I=a.useCallback(async(d,C,M,N)=>{var v,k,$;const f=Date.now(),j={machineId:d,kind:C,providerType:M,workspaceId:(N==null?void 0:N.workspaceId)||null,workspacePath:(N==null?void 0:N.workspacePath)||null,resumeSessionId:(N==null?void 0:N.resumeSessionId)||null,startedAt:f};try{i("loading"),l(`Launching ${M}…`),x(j);const E={cliType:M};(v=N==null?void 0:N.workspacePath)!=null&&v.trim()?E.dir=N.workspacePath.trim():N!=null&&N.workspaceId&&(E.workspaceId=N.workspaceId),N!=null&&N.resumeSessionId&&(E.resumeSessionId=N.resumeSessionId),(k=N==null?void 0:N.args)!=null&&k.trim()&&(E.cliArgs=N.args.trim().split(/\s+/).filter(Boolean)),($=N==null?void 0:N.model)!=null&&$.trim()&&(E.initialModel=N.model.trim());const W=await t(d,"launch_cli",E),T=(W==null?void 0:W.result)||W,V=(T==null?void 0:T.sessionId)||(T==null?void 0:T.id);if(W!=null&&W.success&&V){x(null),i("done"),l(`${M} launched`),s(`/dashboard?activeTab=${encodeURIComponent(V)}`);return}if(W!=null&&W.success){i("loading"),l(`${M} launch requested — waiting for session…`);return}x(null),i("error"),l((W==null?void 0:W.error)||(T==null?void 0:T.error)||`Could not launch ${C.toUpperCase()} workspace`)}catch(E){if(wu(E)){i("loading"),l(`${M} launch requested — waiting for session…`);return}x(null),i("error"),l(E instanceof Error?E.message:`Could not launch ${C.toUpperCase()} workspace`)}},[s,t]),u=a.useCallback(async(d,C)=>{try{const M=await t(d,"list_saved_sessions",{providerType:C,kind:"cli",limit:30}),N=(M==null?void 0:M.result)??M;return Array.isArray(N==null?void 0:N.sessions)?N.sessions:[]}catch(M){return console.error("Failed to list saved sessions on mobile:",M),[]}},[t]),b=a.useCallback(async(d,C)=>wr(t,d,C),[t]);a.useEffect(()=>{var N;if(!p)return;const d=ka(p.workspacePath),C=r.find(f=>{var W,T,V,R;if(!f||f.type==="adhdev-daemon"||vu(f.daemonId||f.id)!==p.machineId||(f.transport==="acp"?"acp":f.transport==="pty"?"cli":null)!==p.kind||String(f.agentType||f.type||"")!==p.providerType)return!1;const $=String(f.providerSessionId||"");if(p.resumeSessionId&&$)return $===p.resumeSessionId;if(d){const w=ka(f.workspace||f.runtimeWorkspaceLabel);return w?w===d:!1}return Number(f.lastUpdated||f._lastUpdate||f.timestamp||((R=(V=(T=(W=f.activeChat)==null?void 0:W.messages)==null?void 0:T.at)==null?void 0:V.call(T,-1))==null?void 0:R.timestamp)||0)>=p.startedAt-5e3});if(!C)return;const M=typeof C.sessionId=="string"&&C.sessionId?C.sessionId:typeof C.instanceId=="string"&&C.instanceId?C.instanceId:(N=n.find(f=>f.routeId===C.id))==null?void 0:N.sessionId;M&&(x(null),i("done"),l(`${p.providerType} launched`),s(`/dashboard?activeTab=${encodeURIComponent(M)}`))},[n,r,s,p]),a.useEffect(()=>{if(!p)return;const d=window.setTimeout(()=>{x(C=>!C||C.startedAt!==p.startedAt?C:(i("error"),l("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(d)},[p]);const y=a.useCallback(async(d,C)=>{if(C.kind==="ide"&&C.providerType){await h(d,C.providerType,{workspacePath:C.workspace||null});return}(C.kind==="cli"||C.kind==="acp")&&C.providerType&&await I(d,C.kind,C.providerType,{workspacePath:C.workspace||null,resumeSessionId:C.providerSessionId||null})},[h,I]);return{machineAction:{state:o,message:c},resetMachineAction:m,handleLaunchDetectedIde:h,handleAddWorkspace:g,handleMachineUpgrade:S,handleLaunchWorkspaceProvider:I,handleListSavedSessions:u,handleBrowseDirectory:b,handleOpenRecent:y}}function ku({conversations:t,selectedConversation:s,machineBackTarget:r,markConversationRead:n,resetMachineAction:o,setSelectedTabKey:i,setScreen:c,setSelectedMachineId:l,setSection:p,setMachineBackTarget:x}){const m=a.useCallback(y=>{i(y.tabKey),c("chat"),n(y)},[n,c,i]),h=a.useCallback(y=>{const d=t.find(C=>C.routeId===y.routeId&&C.streamSource==="native");d&&(i(d.tabKey),c("chat"),n(d))},[t,n,c,i]),g=a.useCallback(()=>{n(s),c("inbox")},[n,s,c]),S=a.useCallback((y,d="inbox")=>{l(y),o(),p("machines"),x(d),c("machine")},[o,x,c,p,l]),I=a.useCallback(y=>{const d=Ut(y);d&&S(d,"chat")},[S]),u=a.useCallback(()=>{o(),c(r)},[r,o,c]),b=a.useCallback(y=>{p(y),c("inbox")},[c,p]);return{openConversation:m,openNativeConversation:h,backFromConversation:g,openMachine:S,openConversationMachine:I,backFromMachine:u,changeMachineSection:b}}function Nu(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Su(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function Cu({conversations:t,hiddenConversations:s,ides:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,userName:p,requestedActiveTabKey:x,onRequestedActiveTabConsumed:m,requestedMachineId:h,onRequestedMachineConsumed:g,requestedMobileSection:S,onRequestedMobileSectionConsumed:I,onOpenHistory:u,onOpenRemote:b,onStopCli:y,wsStatus:d,isConnected:C,onShowHiddenConversation:M,onShowAllHiddenConversations:N,onHideConversation:f,onOpenNewSession:j}){const[v,k]=a.useState(()=>{var F;return((F=t[0])==null?void 0:F.tabKey)||null}),[$,E]=a.useState(()=>t[0]?"chat":"inbox"),[W,T]=a.useState("chats"),[V,R]=a.useState(null),[w,B]=a.useState("inbox"),ee=ms(),L="0.8.45",D=a.useMemo(()=>t.find(F=>F.tabKey===v)||t[0]||null,[t,v]),O=a.useMemo(()=>D?r.find(F=>F.id===D.routeId):void 0,[r,D]),z=a.useMemo(()=>!D||qe(D)||!Ge(D)?null:ps(D),[D]),Q=a.useMemo(()=>r.filter(F=>F.type==="adhdev-daemon").sort(mn),[r]),re=a.useMemo(()=>Q.find(F=>F.id===V)||null,[Q,V]),je=a.useMemo(()=>Ds(r),[r]),Y=yr({sendDaemonCommand:o,activeConv:D||void 0,setLocalUserMessages:i,setActionLogs:c,isStandalone:l}),ne=ju({sendDaemonCommand:o,navigate:ee,ides:r,conversations:t}),_=a.useMemo(()=>t.map(F=>{const xe=$==="chat"&&(D==null?void 0:D.tabKey)===F.tabKey,Ie=Ps(F,je,{hideOpenTaskCompleteUnread:!0,isOpenConversation:xe}),ge=Jt(F),Ee=fo(F);return{conversation:F,timestamp:ge,preview:Ee,unread:Ie.unread,requiresAction:Ie.requiresAction,isWorking:Ie.isWorking,inboxBucket:Ie.inboxBucket}}),[t,je,$,D]),{markConversationRead:pe}=yu({conversations:t,machineEntries:Q,items:_,selectedConversation:D,selectedTabKey:v,screen:$,liveSessionInboxState:je,sendDaemonCommand:o,requestedActiveTabKey:x,onRequestedActiveTabConsumed:m,requestedMachineId:h,onRequestedMachineConsumed:g,requestedMobileSection:S,onRequestedMobileSectionConsumed:I,setSelectedTabKey:k,setScreen:E,setSelectedMachineId:R,setSection:T,setMachineBackTarget:B,resetMachineAction:ne.resetMachineAction}),me=ku({conversations:t,selectedConversation:D,machineBackTarget:w,markConversationRead:pe,resetMachineAction:ne.resetMachineAction,setSelectedTabKey:k,setScreen:E,setSelectedMachineId:R,setSection:T,setMachineBackTarget:B}),J=a.useMemo(()=>_.filter(F=>F.requiresAction),[_]),ie=a.useMemo(()=>_.filter(F=>F.unread&&!F.requiresAction),[_]),se=a.useMemo(()=>_.filter(F=>!F.unread&&!F.requiresAction&&F.isWorking),[_]),he=a.useMemo(()=>_.filter(F=>!F.unread&&!F.requiresAction&&!F.isWorking),[_]),ce=a.useMemo(()=>re?_.filter(F=>Ut(F.conversation)===re.id):[],[_,re]),be=a.useMemo(()=>bu(re,r),[r,re]),Z=(re==null?void 0:re.version)||null,oe=!!re&&!!Z&&!0&&Z!==L,ae=a.useMemo(()=>(re==null?void 0:re.availableProviders)||[],[re]),ke=a.useMemo(()=>ae.filter(F=>F.category==="cli"&&F.installed!==!1).map(F=>({type:F.type,displayName:F.displayName||F.type,icon:F.icon})),[ae]),we=a.useMemo(()=>ae.filter(F=>F.category==="acp"&&F.installed!==!1).map(F=>({type:F.type,displayName:F.displayName||F.type,icon:F.icon})),[ae]),P=a.useMemo(()=>gu(Q,_),[_,Q]),fe=a.useCallback(async F=>{re&&await ne.handleOpenRecent(re.id,F)},[ne,re]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:$==="chat"&&D?e.jsx(du,{selectedConversation:D,isAcp:qe(D),isStandalone:l,selectedIdeEntry:O,actionLogs:n,userName:p,isSendingChat:Y.isSendingChat,isFocusingAgent:Y.isFocusingAgent,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,onBack:me.backFromConversation,onOpenNativeConversation:me.openNativeConversation,onOpenMachine:me.openConversationMachine,onHideConversation:f,onOpenHistory:u,onOpenRemote:b,onStopCli:y,cliViewMode:z,onSetCliViewMode:async F=>{if(D&&z!==F)try{await o(Ut(D)||D.routeId,"set_cli_view_mode",{targetSessionId:D.sessionId,cliType:jt(D),mode:F})}catch(xe){Su(xe)?console.warn("Skipped CLI view mode switch:",xe instanceof Error?xe.message:String(xe)):console.error("Failed to switch CLI view mode:",xe)}},handleSendChat:Y.handleSendChat,handleFocusAgent:Y.handleFocusAgent}):$==="machine"&&re?e.jsx(hu,{selectedMachineEntry:re,selectedMachineConversations:ce,selectedMachineRecentLaunches:be,cliProviders:ke,acpProviders:we,selectedMachineNeedsUpgrade:oe,appVersion:L,machineAction:ne.machineAction,isStandalone:l,section:W,showBottomNav:w==="inbox",onBack:me.backFromMachine,onSectionChange:me.changeMachineSection,onOpenConversation:me.openConversation,onOpenRecent:fe,onOpenMachineDetails:()=>ee(`/machines/${re.id}`),onMachineUpgrade:()=>ne.handleMachineUpgrade(re.id),onLaunchDetectedIde:(F,xe)=>ne.handleLaunchDetectedIde(re.id,F,xe),onAddWorkspace:(F,xe)=>ne.handleAddWorkspace(re.id,F,xe),onBrowseDirectory:F=>ne.handleBrowseDirectory(re.id,F),onLaunchWorkspaceProvider:(F,xe,Ie)=>ne.handleLaunchWorkspaceProvider(re.id,F,xe,Ie),onListSavedSessions:F=>ne.handleListSavedSessions(re.id,F)}):e.jsx(pu,{section:W,attentionItems:J,unreadItems:ie,workingItems:se,completedItems:he,hiddenConversations:s,machineCards:P,getAvatarText:Nu,onOpenConversation:me.openConversation,onShowConversation:M,onShowAllHidden:N,onOpenNewSession:j,onOpenMachine:me.openMachine,onOpenSettings:()=>ee("/settings"),onSectionChange:T,wsStatus:d,isConnected:C,isStandalone:l})})}function Br(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Iu({conversations:t,numGroups:s,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:o,onClearPreviewOrder:i}){const c=a.useRef(0),[l,p]=a.useState(!1),[x,m]=a.useState(null),h=a.useCallback(()=>{c.current=0,p(!1),m(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const g=a.useCallback(b=>{b.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,p(!0))},[]),S=a.useCallback(b=>{if(!b.dataTransfer.types.includes("text/tab-key"))return;if(b.preventDefault(),!Br(s,r)){m("merge");return}const y=b.currentTarget.getBoundingClientRect(),d=b.clientX-y.left,C=y.width/3;d<C?m("split-left"):d>C*2?m("split-right"):m("merge")},[s,r]),I=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,p(!1),m(null))},[]),u=a.useCallback(b=>{c.current=0,p(!1);const y=b.dataTransfer.getData("text/tab-key"),d=y?t.some(M=>M.tabKey===y):!1,C=x;if(m(null),i(),!!y){if(b.preventDefault(),C==="split-left"&&Br(s,r)){r==null||r(y,"split-left");return}if(C==="split-right"&&Br(s,r)){r==null||r(y,"split-right");return}if(d){o(y);return}n==null||n(y)}},[t,x,s,r,n,o,i]);return{dragOver:l,dropAction:x,resetDragState:h,handleDragEnter:g,handleDragOver:S,handleDragLeave:I,handleDrop:u}}function Mu(t,s){const r=new Set(s.map(i=>i.tabKey)),n=t.filter(i=>r.has(i)),o=s.filter(i=>!t.includes(i.tabKey)).map(i=>i.tabKey);return[...n,...o]}function Au({conversations:t,initialActiveTabId:s,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:o}){const[i,c]=a.useState(s??null),[l,p]=a.useState(r??[]),[x,m]=a.useState(null),h=a.useRef(null),g=a.useRef(null),S=a.useRef(n),I=a.useRef(o);a.useEffect(()=>{S.current=n},[n]),a.useEffect(()=>{I.current=o},[o]),a.useEffect(()=>{s&&s!==i&&c(s)},[s,i]),a.useEffect(()=>{p(j=>{const v=Mu(j,t);return v.length===j.length&&v.every((k,$)=>k===j[$])?j:v})},[t]);const u=a.useMemo(()=>{const j=x??l;if(j.length===0)return t;const v=new Map(j.map((k,$)=>[k,$]));return[...t].sort((k,$)=>{const E=v.get(k.tabKey)??999,W=v.get($.tabKey)??999;return E-W})},[t,x,l]);a.useEffect(()=>{var v,k;if(u.length===0){i!==null&&(c(null),(v=S.current)==null||v.call(S,null));return}if(i&&u.some($=>$.tabKey===i))return;const j=u[0].tabKey;j!==i&&(c(j),(k=S.current)==null||k.call(S,j))},[u,i]);const b=a.useMemo(()=>u.find(j=>j.tabKey===i),[u,i]),y=a.useCallback(j=>{var v;c(j),(v=S.current)==null||v.call(S,j)},[]),d=a.useCallback((j,v,k)=>{p($=>{var V;const E=$.filter(R=>R!==j),W=E.indexOf(v);if(W<0)return $;const T=k==="left"?W:W+1;return E.splice(T,0,j),(V=I.current)==null||V.call(I,E),E}),m(null)},[]),C=a.useCallback((j,v,k)=>{const E=(l.length>0?l:t.map(V=>V.tabKey)).filter(V=>V!==j),W=E.indexOf(v);if(W<0)return;const T=k==="left"?W:W+1;E.splice(T,0,j),h.current=E,m(E)},[l,t]),M=a.useCallback(()=>{var v;const j=h.current;j&&(p(j),(v=I.current)==null||v.call(I,j))},[]),N=a.useCallback(()=>{h.current=null,m(null)},[]),f=a.useCallback(j=>{p(v=>{var $;const k=v.filter(E=>E!==j);return k.push(j),($=I.current)==null||$.call(I,k),k})},[]);return{activeTabId:i,activeConv:b,sortedConversations:u,previewOrderRef:h,draggingTabRef:g,selectTab:y,handleTabReorder:d,updatePreviewOrder:C,commitPreviewOrder:M,clearPreviewOrder:N,moveTabToEnd:f,setDraggingTabKey:j=>{g.current=j}}}function Tu({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 In({conversationsCount:t,isSplitMode:s,isStandalone:r,hasRegisteredMachines:n=!1,detectedIdes:o,handleLaunchIde:i}){const c=!r&&!n,l=r?"Waiting for your daemon":n?"No conversations yet":"Connect your first machine",p=r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":n?"Your machines are connected. Open a machine, choose a workspace, then launch an IDE, CLI, or ACP session.":"Install the ADHDev daemon and link your dashboard to start.";return t===0&&!s&&o&&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:l}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:p}),c&&e.jsx(Uo,{}),r&&o.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Detected IDEs"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:o.map(x=>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(x.type),children:[e.jsx(Xa,{size:14,className:"opacity-70"})," Open ",x.name]},x.type))})]}),c&&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 Vo="adhdev-tab-shortcuts";function qo(){try{return JSON.parse(localStorage.getItem(Vo)||"{}")}catch{return{}}}function Go({enabled:t=!0,sortedTabKeys:s,onFocus:r,onSelectTab:n}){const o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,c]=a.useState(()=>qo()),[l,p]=a.useState(null),x=a.useCallback(h=>{const g=[];return h.metaKey&&g.push(o?"⌘":"Meta"),h.ctrlKey&&g.push("Ctrl"),h.altKey&&g.push(o?"⌥":"Alt"),h.shiftKey&&g.push(o?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(h.key)?null:(g.push(h.key.length===1?h.key.toUpperCase():h.key),g.join("+"))},[o]),m=a.useCallback(h=>{c(h);try{localStorage.setItem(Vo,JSON.stringify(h))}catch{}},[]);return a.useEffect(()=>{if(!t||!l)return;const h=g=>{if(g.preventDefault(),g.stopPropagation(),g.key==="Escape"){p(null);return}const S=x(g);if(!S)return;const I={...i};for(const[u,b]of Object.entries(I))b===S&&delete I[u];I[l]=S,m(I),p(null)};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[t,l,i,m,x]),a.useEffect(()=>{if(!t)return;const h=g=>{if(!(!g.ctrlKey&&!g.metaKey&&!g.altKey)){for(const[S,I]of Object.entries(i))if(s.includes(S)&&x(g)===I){g.preventDefault(),r(),n(S);return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t,i,s,r,n,x]),{isMac:o,tabShortcuts:i,shortcutListening:l,setShortcutListening:p,saveShortcuts:m}}const _u=a.memo(function({conv:s,isActive:r,isDraggedTab:n,isTaskCompleteUnread:o,shortcut:i,conversationKeys:c,draggingTabRef:l,onFocus:p,onSelectTab:x,onConversationActivated:m,onPreviewReorder:h,onReorderTab:g,onCommitPreviewOrder:S,onClearPreviewOrder:I,onDragStateReset:u,onDragTabKeyChange:b,onReceiveTab:y,onOpenContextMenu:d,longPressTimer:C,isGroupActive:M}){const N=xs(s),f=N.isGenerating?"agent-tab-generating":N.isWaiting?"agent-tab-waiting":"",j=N.isReconnecting,v=a.useCallback(B=>{l.current=s.tabKey,b(s.tabKey),B.dataTransfer.setData("text/tab-key",s.tabKey),B.dataTransfer.effectAllowed="move"},[s.tabKey,l,b]),k=a.useCallback(()=>{l.current=null,b(null),S(),I(),u()},[l,b,S,I,u]),$=a.useCallback(B=>{const ee=l.current;if(!(!ee||ee===s.tabKey)&&B.dataTransfer.types.includes("text/tab-key")){B.preventDefault(),B.stopPropagation();const L=B.currentTarget.getBoundingClientRect(),D=B.clientX<L.left+L.width/2?"left":"right";h(ee,s.tabKey,D)}},[s.tabKey,l,h]),E=a.useCallback(B=>{B.preventDefault(),B.stopPropagation();const ee=B.dataTransfer.getData("text/tab-key");if(ee&&ee!==s.tabKey){const L=B.currentTarget.getBoundingClientRect(),D=B.clientX<L.left+L.width/2?"left":"right";c.includes(ee)?g(ee,s.tabKey,D):y&&y(ee)}I()},[s.tabKey,c,g,y,I]),W=a.useCallback(B=>{B.stopPropagation(),p(),x(s.tabKey),m(s)},[s,m,p,x]),T=a.useCallback(B=>{B.preventDefault(),d(B.clientX,B.clientY,s.tabKey)},[s.tabKey,d]),V=a.useCallback(B=>{const ee=B.touches[0];C.current=setTimeout(()=>{d(ee.clientX,ee.clientY,s.tabKey)},600)},[s.tabKey,C,d]),R=a.useCallback(()=>{C.current&&clearTimeout(C.current)},[C]),w=["adhdev-dockview-tab",f,r&&"is-active",M&&"is-group-active",j&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:w,draggable:!0,onDragStart:v,onDragEnd:k,onDragOver:$,onDrop:E,onClick:W,onContextMenu:T,onTouchStart:V,onTouchEnd:R,onTouchMove:R,style:{cursor:"pointer",opacity:n?.4:void 0},children:[o&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:N.isGenerating?e.jsx("div",{className:"tab-spinner"}):N.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):j?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):N.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:Qe(s),children:Qe(s)}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:j?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Gt(s)}):N.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",children:[Gt(s),e.jsx("span",{className:"connecting-dots"})]}):Gt(s)})]}),i&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${i}`,children:i})]})},(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 Pu({conversations:t,activeTabId:s,groupIndex:r,unreadTabKeys:n,draggingTabRef:o,onFocus:i,onSelectTab:c,onConversationActivated:l,onPreviewReorder:p,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:S,onReceiveTab:I,onHideTab:u,isGroupActive:b,allowTabShortcuts:y=!0}){const[d,C]=a.useState(null),M=a.useRef(null),N=a.useRef(null),f=a.useMemo(()=>t.map(T=>T.tabKey),[t]);Es("PaneGroupTabBar",{groupIndex:r,activeTabId:s,tabCount:t.length,ctxMenuTab:(d==null?void 0:d.tabKey)||null});const{isMac:j,tabShortcuts:v,shortcutListening:k,setShortcutListening:$,saveShortcuts:E}=Go({enabled:y,sortedTabKeys:t.map(T=>T.tabKey),onFocus:i,onSelectTab:c});a.useEffect(()=>{if(!d)return;const T=V=>{const R=document.querySelector("[data-pane-context-menu]");R&&R.contains(V.target)||C(null)};return window.addEventListener("mousedown",T,!0),()=>window.removeEventListener("mousedown",T,!0)},[d]),a.useEffect(()=>{const T=N.current;if(!T)return;const V=R=>{Math.abs(R.deltaY)>Math.abs(R.deltaX)&&(R.preventDefault(),T.scrollLeft+=R.deltaY)};return T.addEventListener("wheel",V,{passive:!1}),()=>T.removeEventListener("wheel",V)},[]);const W=a.useCallback((T,V,R)=>{C({x:T,y:V,tabKey:R})},[]);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:N,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(T=>e.jsx(_u,{conv:T,isActive:s===T.tabKey,isDraggedTab:o.current===T.tabKey,isTaskCompleteUnread:n.has(T.tabKey),shortcut:y?v[T.tabKey]:void 0,conversationKeys:f,draggingTabRef:o,onFocus:i,onSelectTab:c,onConversationActivated:l,onPreviewReorder:p,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:S,onReceiveTab:I,onOpenContextMenu:W,longPressTimer:M,isGroupActive:b},T.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),d&&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:d.x,top:d.y},children:[y&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:T=>{T.stopPropagation(),$(d.tabKey),C(null)},children:["⌨ ",v[d.tabKey]?`Change shortcut (${v[d.tabKey]})`:"Set shortcut"]}),v[d.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const T={...v};delete T[d.tabKey],E(T),C(null)},children:"✕ Remove shortcut"})]}),u&&e.jsxs(e.Fragment,{children:[y&&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:()=>{u(d.tabKey),C(null)},children:"🚫 Hide from Dashboard"})]})]}),y&&k&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>$(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:T=>T.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",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 Lu({conversations:t,ides:s,clearedTabs:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,hasRegisteredMachines:p,userName:x,groupIndex:m,onFocus:h,isSplitMode:g,numGroups:S,onMoveTab:I,onReceiveTab:u,style:b,detectedIdes:y,handleLaunchIde:d,onActiveTabChange:C,initialActiveTabId:M,initialTabOrder:N,onTabOrderChange:f,onHideTab:j,isFocused:v,allowTabShortcuts:k=!0}){const{sendCommand:$}=St(),E=a.useRef(null),{activeTabId:W,activeConv:T,sortedConversations:V,draggingTabRef:R,selectTab:w,handleTabReorder:B,updatePreviewOrder:ee,commitPreviewOrder:L,clearPreviewOrder:D,moveTabToEnd:O,setDraggingTabKey:z}=Au({conversations:t,initialActiveTabId:M,initialTabOrder:N,onActiveTabChange:C,onTabOrderChange:f}),Q=yr({sendDaemonCommand:o,activeConv:T,setLocalUserMessages:i,setActionLogs:c,isStandalone:l}),{dragOver:re,dropAction:je,resetDragState:Y,handleDragEnter:ne,handleDragOver:_,handleDragLeave:pe,handleDrop:me}=Iu({conversations:t,numGroups:S,onMoveTab:I,onReceiveTab:u,onOwnTabDrop:O,onClearPreviewOrder:D}),J=T&&!qe(T)&&ps(T)==="terminal",ie=a.useMemo(()=>T?s.find(Z=>Z.id===T.routeId):void 0,[s,T]),se=a.useMemo(()=>T?n.filter(Z=>Z.routeId===T.tabKey):[],[n,T]),he=a.useMemo(()=>Ds(s),[s]),ce=a.useMemo(()=>new Set(V.filter(Z=>Tc(Z,he,{isOpenConversation:Z.tabKey===W})).map(Z=>Z.tabKey)),[W,he,V]);Es("PaneGroup",{groupIndex:m,conversationCount:t.length,activeTabId:W,dragOver:re});const be=a.useCallback(Z=>{Z.streamSource==="agent-stream"&&Z.agentType&&$(Z.routeId,"focus_session",{agentType:Z.agentType,...Z.sessionId&&{targetSessionId:Z.sessionId}}).catch(()=>{})},[$]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:h,style:{...b,outline:re?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Pu,{conversations:V,activeTabId:W,groupIndex:m,numGroups:S,unreadTabKeys:ce,draggingTabRef:R,onFocus:h,onSelectTab:w,onConversationActivated:be,onPreviewReorder:ee,onReorderTab:B,onCommitPreviewOrder:L,onClearPreviewOrder:D,onDragStateReset:Y,onDragTabKeyChange:z,onMoveTab:I,onReceiveTab:u,onHideTab:j,isGroupActive:v??!1,allowTabShortcuts:k}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:ne,onDragOver:_,onDragLeave:pe,onDrop:me,children:[re&&e.jsx(Tu,{dropAction:je,canSplit:!!(S<4&&I)}),T?e.jsx(Sn,{activeConv:T,clearToken:r[T.tabKey]||0,isCliTerminal:!!J,ideEntry:ie,terminalRef:E,handleModalButton:Q.handleModalButton,handleRelaunch:Q.handleRelaunch,handleSendChat:Q.handleSendChat,isSendingChat:Q.isSendingChat,handleFocusAgent:Q.handleFocusAgent,isFocusingAgent:Q.isFocusingAgent,actionLogs:se,userName:x,isInputActive:!g||!!v}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(In,{conversationsCount:t.length,isSplitMode:g,isStandalone:l,hasRegisteredMachines:p,detectedIdes:y,handleLaunchIde:d})})]})]})}function Ru({containerRef:t,isSplitMode:s,numGroups:r,groupSizes:n,groupedConvs:o,clearedTabs:i,ides:c,actionLogs:l,sendDaemonCommand:p,setLocalUserMessages:x,setActionLogs:m,isStandalone:h,hasRegisteredMachines:g,userName:S,focusedGroup:I,setFocusedGroup:u,moveTabToGroup:b,splitTabRelative:y,closeGroup:d,handleResizeStart:C,detectedIdes:M,handleLaunchIde:N,groupActiveTabIds:f,setGroupActiveTabIds:j,groupTabOrders:v,setGroupTabOrders:k,toggleHiddenTab:$,allowTabShortcuts:E=!0}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:o.map((W,T)=>{const V=s&&n.length===r?`${n[T]}%`:void 0;return e.jsxs(nt.Fragment,{children:[s&&T>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:R=>C(T-1,R),onDoubleClick:()=>d(T),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(Lu,{style:s?{flexBasis:V??`${100/r}%`,flexGrow:V?0:1,flexShrink:V?0:1}:void 0,conversations:W,clearedTabs:i,ides:c,actionLogs:l,sendDaemonCommand:p,setLocalUserMessages:x,setActionLogs:m,isStandalone:h,hasRegisteredMachines:g,userName:S,groupIndex:T,isFocused:s&&I===T,onFocus:()=>u(T),isSplitMode:s,numGroups:r,onMoveTab:(R,w)=>{w==="left"&&T>0?b(R,T-1):w==="right"&&T<r-1?b(R,T+1):w==="split-left"&&r<4?y(R,T,"left"):w==="split-right"&&r<4&&y(R,T,"right")},onReceiveTab:R=>b(R,T),detectedIdes:T===0?M:void 0,handleLaunchIde:T===0?N:void 0,onActiveTabChange:R=>j(w=>(w[T]??null)===(R??null)?w:{...w,[T]:R}),initialActiveTabId:f[T],initialTabOrder:v[T],onTabOrderChange:R=>k(w=>{const B=w[T]||[];return B.length===R.length&&B.every((ee,L)=>ee===R[L])?w:{...w,[T]:R}}),onHideTab:$,allowTabShortcuts:E})]},T)})})}function Yo({doId:t,targetSessionId:s,connState:r,viewMode:n}){const[o,i]=a.useState(null),[c,l]=a.useState(null);a.useEffect(()=>t?at.onScreenshot("ide-page",(m,h)=>{if(m!==t)return;const g=new FileReader;g.onload=()=>i(g.result),g.readAsDataURL(h)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&i(null)},[r]),a.useEffect(()=>{var m;return t?((m=at.onStatus)==null?void 0:m.call(at,(h,g)=>{h===t&&g!=null&&g.screenshotUsage&&l(g.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{i(null)},[t,s]),a.useEffect(()=>{const x=t?at.get(t):null;if(!(!x||r!=="connected"))return n!=="chat"&&s?x.startScreenshots(s):x.stopScreenshots(s),()=>{x.stopScreenshots(s)}},[n,r,s,t]);const p=a.useCallback(async(x,m)=>{const h=t?at.get(t):null;return!h||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):h.sendInput(x,m,s)},[t,r,s]);return{connScreenshot:o,screenshotUsage:c,handleRemoteAction:p}}const Xo="adhdev-dashboard-action-shortcuts",Eu=1200,Du={toggleHiddenTabs:"G H",setActiveTabShortcut:"G S",selectPreviousGroupTab:"G K",selectNextGroupTab:"G J",splitActiveTabRight:"⌘+⌥+\\",focusLeftPane:"⌘+⌥+←",focusRightPane:"⌘+⌥+→",moveActiveTabToLeftPane:"⌘+⌥+⇧+←",moveActiveTabToRightPane:"⌘+⌥+⇧+→",triggerPrimaryApprovalAction:"⌥+A",triggerSecondaryApprovalAction:"⌥+D",toggleCliView:"T"};function $u(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function Xe(t,s){switch(t){case"openShortcutHelp":return"?";case"hideCurrentTab":return s?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return s?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return s?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return s?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return s?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return s?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return s?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return s?"⌘+⌥+=":"Ctrl+Alt+\\";case"splitActiveTabDown":return s?"⌘+⌥+-":"Ctrl+Alt+-";case"focusLeftPane":return s?"⌘+⌥+[":"Ctrl+Alt+←";case"focusRightPane":return s?"⌘+⌥+]":"Ctrl+Alt+→";case"focusUpPane":return s?"⌘+⌥+U":"Ctrl+Alt+↑";case"focusDownPane":return s?"⌘+⌥+J":"Ctrl+Alt+↓";case"moveActiveTabToLeftPane":return s?"⌘+⌥+,":"Ctrl+Alt+Shift+←";case"moveActiveTabToRightPane":return s?"⌘+⌥+.":"Ctrl+Alt+Shift+→";case"moveActiveTabToUpPane":return s?"⌘+⌥+I":"Ctrl+Alt+Shift+↑";case"moveActiveTabToDownPane":return s?"⌘+⌥+K":"Ctrl+Alt+Shift+↓";case"triggerPrimaryApprovalAction":return s?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return s?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return s?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return s?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return s?"⌥+[":"Ctrl+Alt+[";case"selectNextGroupTab":return s?"⌥+]":"Ctrl+Alt+]";case"toggleCliView":return s?"⌥+T":"Ctrl+Alt+T"}}function Jo(t){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:Xe("openShortcutHelp",t)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:Xe("hideCurrentTab",t)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:Xe("toggleHiddenTabs",t)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:Xe("openHistoryForActiveTab",t)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:Xe("openRemoteForActiveTab",t)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:Xe("floatActiveTab",t)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:Xe("popoutActiveTab",t)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:Xe("dockActiveTab",t)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:Xe("splitActiveTabRight",t)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:Xe("splitActiveTabDown",t)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:Xe("focusLeftPane",t)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:Xe("focusRightPane",t)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:Xe("focusUpPane",t)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:Xe("focusDownPane",t)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:Xe("moveActiveTabToLeftPane",t)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:Xe("moveActiveTabToRightPane",t)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:Xe("moveActiveTabToUpPane",t)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:Xe("moveActiveTabToDownPane",t)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:Xe("triggerPrimaryApprovalAction",t)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:Xe("triggerSecondaryApprovalAction",t)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:Xe("triggerTertiaryApprovalAction",t)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:Xe("setActiveTabShortcut",t)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:Xe("selectPreviousGroupTab",t)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:Xe("selectNextGroupTab",t)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:Xe("toggleCliView",t)}]}function nn(t){if(!(t instanceof HTMLElement))return!1;if(t.isContentEditable)return!0;const s=t.tagName;return s==="INPUT"||s==="TEXTAREA"||s==="SELECT"}function pr(t){const s=Object.fromEntries(Jo(t).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(Xo)||"{}"),n={...s,...r};for(const[o,i]of Object.entries(Du))n[o]===i&&(n[o]=s[o]);return n}catch{return s}}function Zo(t){return t===" "?"Space":t==="Escape"?"Esc":t==="ArrowLeft"?"←":t==="ArrowRight"?"→":t==="ArrowUp"?"↑":t==="ArrowDown"?"↓":t.length===1?t.toUpperCase():t}function Bu({enabled:t=!0,onTrigger:s}){const r=$u(),[n,o]=a.useState(()=>pr(r)),[i,c]=a.useState(null),[l,p]=a.useState([]),x=a.useRef({parts:[],timer:null}),m=a.useCallback(u=>{const b=[];return u.metaKey&&b.push(r?"⌘":"Meta"),u.ctrlKey&&b.push("Ctrl"),u.altKey&&b.push(r?"⌥":"Alt"),u.shiftKey&&u.key.length!==1&&b.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(b.push(Zo(u.key)),b.join("+"))},[r]),h=a.useCallback(u=>{o(u);try{localStorage.setItem(Xo,JSON.stringify(u))}catch{}},[]);a.useEffect(()=>{const u=pr(r),b=Object.entries(n),y=Object.entries(u);b.length===y.length&&b.every(([d,C])=>u[d]===C)||h(u)},[n,r,h]);const g=a.useCallback(()=>{typeof window<"u"&&x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current={parts:[],timer:null}},[]),S=a.useCallback(()=>{typeof window>"u"||(x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current.timer=window.setTimeout(()=>{x.current={parts:[],timer:null}},Eu))},[]);a.useEffect(()=>{if(!i)return;const u=b=>{if(b.preventDefault(),b.stopPropagation(),b.key==="Escape"){c(null),p([]);return}const y=m(b);if(!y)return;const C=!(b.metaKey||b.ctrlKey||b.altKey)&&/^[A-Z0-9]$/.test(y);if(l.length===0&&C){p([y]);return}const N=[...l,y].slice(0,2).join(" "),f={...n};for(const[j,v]of Object.entries(f))v===N&&delete f[j];f[i]=N,h(f),c(null),p([])};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[n,m,h,i,l]),a.useEffect(()=>{if(!t||i)return;const u=b=>{if(b.defaultPrevented)return;const y=m(b);if(!y)return;const d=b.metaKey||b.ctrlKey||b.altKey;if(nn(b.target)&&!d)return;const C=x.current.parts,M=d?[y]:[...C.slice(-1),y].slice(-2),N=M.join(" "),f=M[M.length-1],j=Object.entries(n).filter(([,W])=>!!W),v=j.find(([,W])=>W===N);if(v){b.preventDefault(),g(),s(v[0]);return}if(j.some(([,W])=>W.startsWith(`${N} `))){b.preventDefault(),x.current.parts=M,S();return}const $=j.find(([,W])=>W===f);if($){b.preventDefault(),g(),s($[0]);return}if(j.some(([,W])=>W.startsWith(`${f} `))){b.preventDefault(),x.current.parts=[f],S();return}g()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n,S,t,m,s,g,i]),a.useEffect(()=>()=>g(),[g]);const I=a.useMemo(()=>Jo(r),[r]);return{isMac:r,actionDefinitions:I,actionShortcuts:n,shortcutListening:i,shortcutListeningDraft:l,setShortcutListening:c,setShortcutListeningDraft:p,saveShortcuts:h}}const Qo=a.createContext(null);function kr(){const t=a.useContext(Qo);if(!t)throw new Error("DashboardDockviewContext missing");return t}function nr(t){return Qe(t)||t.tabKey}function Ku(t){return`remote:${t}`}function Wt(t){return t.startsWith("remote:")}function Na(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Sa(t){var r,n,o,i,c;const s=t==null?void 0:t.defaultView;if(s)try{s.focus(),(n=(r=t==null?void 0:t.body)==null?void 0:r.focus)==null||n.call(r),(i=(o=t==null?void 0:t.documentElement)==null?void 0:o.focus)==null||i.call(o),(c=s.requestAnimationFrame)==null||c.call(s,()=>{var l,p;try{s.focus(),(p=(l=t==null?void 0:t.body)==null?void 0:l.focus)==null||p.call(l)}catch{}})}catch{}}function Js(t,s){t.classList.remove(qr.className,Gr.className),t.classList.add(s==="light"?qr.className:Gr.className)}function Ca(t){return t?Array.from(new Set(t.groups.map(s=>{var r,n;return(n=(r=s.element)==null?void 0:r.ownerDocument)==null?void 0:n.defaultView}).filter(s=>!!s&&s!==window))):[]}function Wu(t){const[,s]=a.useState(0);a.useEffect(()=>{const r=()=>s(o=>o+1),n=[t.api.onDidActiveGroupChange(r),t.api.onDidTitleChange(r),t.api.onDidGroupChange(r),t.containerApi.onDidActivePanelChange(r)];return()=>{for(const o of n)o.dispose()}},[t.api,t.containerApi])}function Ou(t,s,r){var l;const n=[s];let o;for(const p of n){let x;for(const m of p){const h=t.addPanel({id:m.tabKey,component:"conversation",title:nr(m),params:{kind:"conversation",tabKey:m.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:o?{position:{referencePanel:o,direction:"right"},inactive:!0}:{}});x||(x=h.id)}o=x??o}const i=r??((l=s[0])==null?void 0:l.tabKey)??null;if(!i)return;const c=t.getPanel(i);c&&c.group.model.openPanel(c)}function Ia(t,s){const r=new Set(s.map(n=>n.tabKey));for(const n of[...t.panels])Wt(n.id)||r.has(n.id)||t.removePanel(n);for(const n of s){const o=t.getPanel(n.tabKey);if(o){o.update({params:{tabKey:n.tabKey}}),o.title!==nr(n)&&o.api.setTitle(nr(n));continue}t.addPanel({id:n.tabKey,component:"conversation",title:nr(n),params:{kind:"conversation",tabKey:n.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Ma(t,s,r){var p,x;const n=r?Ku(r):null;for(const m of[...t.panels])Wt(m.id)&&(!n||m.id!==n)&&t.removePanel(m);if(!r||!n)return;const o=Rt(s,r);if(!o&&t.totalPanels===0)return;const i=t.getPanel(n),c=bo(o);if(i){i.title!==c&&i.api.setTitle(c);return}const l=(o==null?void 0:o.tabKey)??((p=t.activePanel)==null?void 0:p.id)??((x=t.panels.find(m=>!Wt(m.id)))==null?void 0:x.id);t.addPanel({id:n,component:"remote",title:c,params:{kind:"remote",routeId:r},...l?{position:{referencePanel:l,direction:"right"},inactive:!0}:{}})}function Hu({params:t,api:s}){var h;const r=kr(),n=a.useRef(null),[o,i]=a.useState(s.isActive),c=r.conversationsByTabKey.get(t.tabKey),l=yr({sendDaemonCommand:r.sendDaemonCommand,activeConv:c,setLocalUserMessages:r.setLocalUserMessages,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});a.useEffect(()=>{i(s.isActive);const g=[s.onDidActiveChange(S=>i(S.isActive)),s.onDidActiveGroupChange(S=>{if(!s.isActive&&!S.isActive){i(!1);return}i(s.isActive)})];return()=>{for(const S of g)S.dispose()}},[s]);const p=a.useMemo(()=>c?r.ides.find(g=>g.id===c.routeId):void 0,[r.ides,c]),x=a.useMemo(()=>c?r.actionLogs.filter(g=>g.routeId===c.tabKey):[],[r.actionLogs,c]);if(!c)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(In,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,detectedIdes:r.detectedIdes,handleLaunchIde:r.handleLaunchIde})});const m=!qe(c)&&ps(c)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Sn,{activeConv:c,clearToken:r.clearedTabs[c.tabKey]||0,isCliTerminal:m,ideEntry:p,terminalRef:n,handleModalButton:l.handleModalButton,handleRelaunch:l.handleRelaunch,handleSendChat:l.handleSendChat,isSendingChat:l.isSendingChat,handleFocusAgent:l.handleFocusAgent,isFocusingAgent:l.isFocusingAgent,actionLogs:x,userName:r.userName,scrollToBottomRequestNonce:((h=r.scrollToBottomRequest)==null?void 0:h.tabKey)===c.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:o})})}function Uu({params:t}){var p;const s=kr(),r=a.useMemo(()=>Rt([...s.conversationsByTabKey.values()],t.routeId),[s.conversationsByTabKey,t.routeId]),n=a.useMemo(()=>s.ides.find(x=>x.id===t.routeId),[s.ides,t.routeId]),o=(r==null?void 0:r.daemonId)||((p=r==null?void 0:r.routeId)==null?void 0:p.split(":")[0])||t.routeId.split(":")[0]||t.routeId,{connScreenshot:i,screenshotUsage:c,handleRemoteAction:l}=Yo({doId:o,targetSessionId:r?hn(r):(n==null?void 0:n.sessionId)||(n==null?void 0:n.instanceId),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote"});return r?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(Qa,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:i,screenshotUsage:c,transportType:r.transport,onAction:l})}):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 zu(){const t=kr();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(In,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,hasRegisteredMachines:t.hasRegisteredMachines,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Fu(t){var S,I;Wu(t);const s=kr(),r=a.useCallback(u=>{"button"in u&&u.button!==0||t.api.setActive()},[t.api]);if(t.params.kind==="remote"){const u=Rt([...s.conversationsByTabKey.values()],t.params.routeId),b=((S=t.api.group.activePanel)==null?void 0:S.id)===t.api.id,y=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${y?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(u==null?void 0:u.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:u!=null&&u.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:u.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 o=((I=t.api.group.activePanel)==null?void 0:I.id)===t.api.id,i=t.api.isGroupActive,c=Ps(n,s.liveSessionInboxState,{isOpenConversation:o}),l=c.isReconnecting,p=c.isConnecting,x=c.isGenerating,m=c.isWaiting,h=c.unread,g=s.tabShortcuts[n.tabKey];return e.jsxs("div",{className:`adhdev-dockview-tab${o?" is-active":""}${i?" is-group-active":""}${l?" is-reconnecting":""}`,title:Qe(n),"data-tab-key":t.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:u=>{var b;u.preventDefault(),r(u),s.openTabContextMenu({x:u.clientX,y:u.clientY,tabKey:n.tabKey,sourceDocument:((b=u.target)==null?void 0:b.ownerDocument)??document})},children:[h&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?e.jsx("div",{className:"tab-spinner"}):m?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):p?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:Qe(n)}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:l?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Gt(n)}):p?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:Gt(n)}):e.jsx("span",{children:Gt(n)})})]}),g&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:g,children:g})]})}function Vu({visibleConversations:t,clearedTabs:s,ides:r,actionLogs:n,sendDaemonCommand:o,setLocalUserMessages:i,setActionLogs:c,isStandalone:l,hasRegisteredMachines:p,initialDataLoaded:x,userName:m,detectedIdes:h,handleLaunchIde:g,toggleHiddenTab:S,registerActionHandlers:I,onActiveTabChange:u,requestedActiveTabKey:b,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:d,scrollToBottomRequest:C}){var dt,Ct,yt;const{theme:M}=wn(),{sendCommand:N}=St(),f=a.useRef(null),j=a.useRef(null),v=a.useRef(!1),k=a.useRef(!1),$=a.useRef(!1),E=a.useRef(null),W=a.useRef([]),[T,V]=a.useState(null),[R,w]=a.useState(!1),[B,ee]=a.useState(!1),[L,D]=a.useState(0),O=a.useRef(null),z=a.useMemo(()=>Ko(typeof window<"u"?window.innerWidth:1280),[]),Q=a.useRef(typeof window>"u"?{}:Jd(z)),re=a.useMemo(()=>new Map(t.map(K=>[K.tabKey,K])),[t]),je=a.useMemo(()=>Ds(r),[r]),Y=a.useCallback(()=>{var K;(K=f.current)==null||K.focus()},[]),ne=a.useCallback(K=>{const H=document,G=K.document;for(const Pe of H.querySelectorAll('link[rel="stylesheet"]')){const te=G.createElement("link");te.rel="stylesheet",te.href=Pe.href,Pe.crossOrigin&&(te.crossOrigin=Pe.crossOrigin),G.head.appendChild(te)}for(const Pe of H.querySelectorAll("style")){const te=G.createElement("style");te.textContent=Pe.textContent,G.head.appendChild(te)}const X=[];for(const Pe of H.styleSheets)try{for(const te of Pe.cssRules)te instanceof CSSStyleRule&&(te.selectorText===":root"||te.selectorText==="html")&&X.push(te.cssText)}catch{}if(X.length>0){const Pe=G.createElement("style");Pe.textContent=X.join(`
|
|
41
41
|
`),G.head.appendChild(Pe)}const le=H.documentElement.getAttribute("data-theme");le&&G.documentElement.setAttribute("data-theme",le),G.documentElement.style.colorScheme=le==="light"?"light":"dark",G.body.className=H.body.className;const ue=H.documentElement.getAttribute("style");ue&&G.documentElement.setAttribute("style",ue);const Re=G.getElementById("dv-popout-window");Re instanceof HTMLElement&&(Re.classList.add("adhdev-dockview"),Js(Re,M))},[M]),_=a.useCallback(()=>{var H;const K=f.current;if(K)for(const G of K.groups)try{const X=(H=G.element)==null?void 0:H.ownerDocument;if(!X||X===document)continue;const le=X.getElementById("dv-popout-window");le instanceof HTMLElement&&(le.classList.add("adhdev-dockview"),Js(le,M));const ue=document.documentElement.getAttribute("data-theme");ue&&X.documentElement.setAttribute("data-theme",ue),X.documentElement.style.colorScheme=ue==="light"?"light":"dark",X.body.className=document.body.className;const Re=document.documentElement.getAttribute("style");Re?X.documentElement.setAttribute("style",Re):X.documentElement.removeAttribute("style")}catch{}},[M]),pe=a.useCallback(()=>{var H;const K=f.current;if(K)for(const G of K.groups)try{const X=(H=G.element)==null?void 0:H.ownerDocument;if(!X||X===document)continue;const le=X.getElementById("dv-popout-window");if(!(le instanceof HTMLElement))continue;le.classList.add("adhdev-dockview"),Js(le,M),le.classList.toggle("is-showing-dockview-overlay",B),le.classList.toggle("is-dragging-dockview",R)}catch{}},[R,B,M]),me=a.useCallback(K=>{const H=f.current;if(!H)return;const G=H.getPanel(K);G&&H.addPopoutGroup(G,{popoutUrl:"/popout.html",onDidOpen:({window:X})=>{ne(X),oe();const le=re.get(K);X.document.title=le?`${Qe(le)} — ADHDev`:"ADHDev — Popout"}})},[re,ne]),J=a.useCallback(K=>{const H=f.current,G=H==null?void 0:H.getPanel(K);if(!H||!G)return;const X=H.groups.filter(le=>{var ue;try{return((ue=le.element)==null?void 0:ue.ownerDocument)===document}catch{return!0}});X.length>0?G.api.moveTo({group:X[0],position:"center"}):G.api.moveTo({position:"center"}),G.api.setActive()},[]),ie=a.useCallback(K=>{var X;const H=f.current;if(!H)return!1;const G=H.getPanel(K);if(!G)return!1;try{return((X=G.group.element)==null?void 0:X.ownerDocument)!==document}catch{return!1}},[]),se=a.useCallback(K=>{ie(K)&&J(K),S(K)},[ie,J,S]),he=a.useCallback(K=>{const H=f.current,G=H==null?void 0:H.getPanel(K);!H||!G||H.addFloatingGroup(G,{width:600,height:500})},[]),ce=a.useCallback(K=>{var G;const H=(G=f.current)==null?void 0:G.getPanel(K);if(!H)return!1;try{return H.group.model.location.type==="floating"}catch{return!1}},[]),be=a.useCallback(()=>{var H,G;const K=(G=(H=f.current)==null?void 0:H.activePanel)==null?void 0:G.id;return!K||Wt(K)?null:re.has(K)?K:null},[re]),Z=a.useCallback(K=>{const H=f.current,G=H==null?void 0:H.getPanel(K);if(!H||!G)return;const X=H.groups.filter(le=>{try{return le.model.location.type==="grid"}catch{return!0}});X.length>0?G.api.moveTo({group:X[0],position:"center"}):G.api.moveTo({position:"center"}),G.api.setActive()},[]),oe=a.useCallback(()=>{var H,G;const K=f.current;if(K)for(const X of K.groups){const le=(H=X.element)==null?void 0:H.ownerDocument;if(!le||le===document)continue;const ue=le.getElementById("dv-popout-window");if(!(ue instanceof HTMLElement))continue;let Re=null,Pe=le.title||"ADHDev",te="Popout workspace";const Ne=X.activePanel;if(Ne)if(Re=Ne.id,Wt(Ne.id)){const A=((G=Ne.params)==null?void 0:G.routeId)||Ne.id.slice(7),U=Rt([...re.values()],A);Pe=bo(U),te=U!=null&&U.machineName?`Remote view · ${U.machineName}`:"Remote view"}else{const A=re.get(Ne.id);Pe=A?Qe(A):Ne.title||Ne.id,te=A?Gt(A):"Dockview panel"}le.title=`${Pe} — ADHDev`;let ze=le.getElementById("adhdev-popout-header");ze instanceof HTMLElement||(ze=le.createElement("div"),ze.id="adhdev-popout-header",le.body.appendChild(ze)),ze.setAttribute("style",["position:absolute","top:0","left:0","right:0","height:52px","display:flex","align-items:center","justify-content:space-between","gap:12px","padding:0 14px","box-sizing:border-box","background:var(--surface-secondary)","border-bottom:1px solid var(--border-subtle)","z-index:5","backdrop-filter:blur(14px)"].join(";")),ze.innerHTML=`
|
|
42
42
|
<div style="min-width:0;display:flex;flex-direction:column;gap:2px;">
|
|
43
43
|
<div style="font-size:10px;line-height:1;color:var(--text-muted);text-transform:uppercase;letter-spacing:0.08em;">ADHDev</div>
|
|
@@ -61,9 +61,9 @@ This will disconnect CDP and optionally kill the process.`))try{const D=await r(
|
|
|
61
61
|
✅ Auto-fix completed!`]),y.current&&clearInterval(y.current))}catch{}},3e3)},[t,s.type,r,o]),f=async()=>{if(p.length!==0){i("running"),S(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${p.join(", ")}`,m?`💬 Comment: ${m}`:"",""]),u("");try{const v=await r(t,"provider_auto_fix",{providerType:s.type,functions:p,agent:c,...m?{comment:m}:{}});v!=null&&v.success&&(v!=null&&v.started||v!=null&&v.running)?(S(k=>[...k,"✅ Agent started. Monitoring progress..."]),N()):(i("error"),u((v==null?void 0:v.error)||"Failed to start auto-fix"))}catch(v){i("error"),u((v==null?void 0:v.message)||"Connection failed")}}},j=async()=>{try{await r(t,"provider_auto_fix_cancel",{providerType:s.type}),S(v=>[...v,`
|
|
62
62
|
⚠️ Auto-fix cancelled.`]),i("done"),y.current&&clearInterval(y.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:v=>v.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:n,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[o==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:jp.map(v=>e.jsxs("button",{onClick:()=>l(v.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===v.value?v.color+"66":"var(--border-subtle)",background:c===v.value?v.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===v.value?v.color:"var(--text-primary)"},children:v.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:v.desc})]},v.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:C,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick:M,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Pa.map(v=>e.jsxs("button",{onClick:()=>d(v),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:p.includes(v)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:p.includes(v)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:p.includes(v)?"#a78bfa":"var(--text-secondary)"},children:[p.includes(v)?"☑ ":"☐ ",v]},v))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:m,onChange:v=>h(v.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(o==="running"||o==="done"||o==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[g.map((v,k)=>e.jsx("div",{className:v.startsWith("✅")?"text-green-400":"",style:v.startsWith("❌")||v.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:v},k)),o==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:b})]}),I&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:I})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[o==="config"&&p.length>0&&`${p.length} script(s) selected`,o==="running"&&"Agent is generating...",o==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[o==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:n,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:f,disabled:p.length===0,className:"machine-btn",style:{background:p.length>0?"color-mix(in srgb, var(--accent-primary) 15%, transparent)":void 0,borderColor:p.length>0?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":void 0,color:p.length>0?"#a78bfa":void 0,opacity:p.length===0?.4:1},children:"🚀 Start Fix"})]}),o==="running"&&e.jsx("button",{onClick:j,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(o==="done"||o==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{i("config"),S([]),u("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:n,className:"machine-btn",children:"Close"})]})]})]})]})})}function Np({machineId:t,providers:s,sendDaemonCommand:r,onClose:n,onCreated:o}){var N;const i=s.filter(f=>f.category==="ide"),[c,l]=a.useState(((N=i[0])==null?void 0:N.type)||""),[p,x]=a.useState(""),[m,h]=a.useState(""),[g,S]=a.useState(!1),[I,u]=a.useState(""),[b,y]=a.useState(!1),d=f=>{const j=f.toLowerCase().replace(/[^a-z0-9-]/g,"");x(j),(!m||m===C(p))&&h(C(j))},C=f=>f.split("-").map(j=>j.charAt(0).toUpperCase()+j.slice(1)).join(" "),M=async()=>{if(!(!p||!m||!c)){S(!0),u("");try{const f=await r(t,"provider_clone",{type:p,name:m,category:"ide",location:"user",cloneFrom:c});f!=null&&f.success||f!=null&&f.created?(y(!0),o==null||o(p)):u((f==null?void 0:f.error)||"Failed to create provider")}catch(f){u((f==null?void 0:f.message)||"Connection failed")}S(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[480px] rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:b?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:p})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",p,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",p]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:i.map(f=>e.jsxs("button",{onClick:()=>l(f.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===f.type?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:c===f.type?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:f.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===f.type?"#a78bfa":"var(--text-secondary)"},children:f.displayName})]},f.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:p,onChange:f=>d(f.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",p||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:m,onChange:f=>h(f.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),I&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:I})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:b?e.jsx("button",{onClick:n,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:n,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:M,disabled:!p||!m||g,className:"machine-btn",style:{background:p&&m?"rgba(34,197,94,0.12)":void 0,borderColor:p&&m?"rgba(34,197,94,0.3)":void 0,color:p&&m?"#86efac":void 0,opacity:!p||!m||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Sp({machineId:t,providers:s,sendDaemonCommand:r}){const[n,o]=a.useState([]),[i,c]=a.useState(!1),[l,p]=a.useState(null),[x,m]=a.useState("all"),[h,g]=a.useState(null),[S,I]=a.useState(!1),u=a.useCallback(async()=>{if(t){c(!0);try{const y=await r(t,"get_provider_settings",{}),d=vp(y);if(d){const C=wp(d,s);C.sort((M,N)=>M.category.localeCompare(N.category)||M.displayName.localeCompare(N.displayName)),o(C)}}catch{}c(!1)}},[t,s,r]);a.useEffect(()=>{n.length===0&&u()},[]);const b=async(y,d,C)=>{p(`${y}.${d}`),o(M=>M.map(N=>N.type===y?{...N,values:{...N.values,[d]:C}}:N));try{const M=await r(t,"set_provider_setting",{providerType:y,key:d,value:C});M!=null&&M.success||u()}catch{u()}p(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(y=>e.jsx("button",{onClick:()=>m(y),className:`machine-btn text-[10px] px-2 py-0.5 ${x===y?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:y.toUpperCase()},y))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>I(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:u,disabled:i,className:"machine-btn",children:i?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&n.filter(y=>y.category===x).length>1&&(()=>{const y=n.filter(N=>N.category===x),d=new Map;for(const N of y)for(const f of N.schema){if(f.type!=="boolean")continue;const j=d.get(f.key),v=!!(N.values[f.key]??f.default);j?(j.onCount+=v?1:0,j.total+=1):d.set(f.key,{label:f.label||f.key,onCount:v?1:0,total:1})}const C=[...d.entries()].filter(([,N])=>N.total===y.length);if(C.length===0)return null;const M=async(N,f)=>{for(const j of y)await b(j.type,N,f)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",x.toUpperCase()," providers (",y.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:C.map(([N,f])=>{const j=f.onCount===f.total,v=f.onCount===0;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"text-text-secondary font-medium",children:f.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",f.onCount,"/",f.total,")"]}),e.jsx("button",{onClick:()=>void M(N,!0),disabled:j,className:`machine-btn text-[9px] px-1.5 py-px ${j?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void M(N,!1),disabled:v,className:`machine-btn text-[9px] px-1.5 py-px ${v?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},N)})})]})})(),i&&n.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:n.filter(y=>x==="all"||y.category===x).map(y=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:y.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:y.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:y.category==="acp"?"rgba(139,92,246,0.08)":y.category==="cli"?"rgba(59,130,246,0.08)":y.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:y.category==="acp"?"#a78bfa":y.category==="cli"?"#60a5fa":y.category==="ide"?"#86efac":"var(--status-warning)"},children:y.category}),y.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(d=>d.type===y.type)||{type:y.type,name:y.displayName,displayName:y.displayName,icon:y.icon,category:y.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:y.schema.map(d=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[d.label||d.key,l===`${y.type}.${d.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),d.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:d.description})]}),e.jsx("div",{className:"shrink-0",children:d.type==="boolean"?e.jsx("button",{onClick:()=>b(y.type,d.key,!(y.values[d.key]??d.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:y.values[d.key]??d.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:y.values[d.key]??d.default?21:3}})}):d.type==="number"?e.jsx("input",{type:"number",value:Number(y.values[d.key]??d.default??0)||0,min:d.min,max:d.max,onChange:C=>{const M=parseInt(C.target.value)||0;d.min!==void 0&&M<d.min||d.max!==void 0&&M>d.max||b(y.type,d.key,M)},className:"machine-input w-20 text-center text-[11px]"}):d.type==="select"&&d.options?e.jsx("select",{value:String(y.values[d.key]??d.default??""),onChange:C=>b(y.type,d.key,C.target.value),className:"machine-input text-[11px]",children:d.options.map(C=>e.jsx("option",{value:C,children:C},C))}):e.jsx("input",{type:"text",value:String(y.values[d.key]??d.default??""),onBlur:C=>b(y.type,d.key,C.target.value),className:"machine-input w-[120px] text-[11px]"})})]},d.key))})]},y.type))}),h&&e.jsx(kp,{machineId:t,provider:h,sendDaemonCommand:r,onClose:()=>g(null)}),S&&e.jsx(Np,{machineId:t,providers:s,sendDaemonCommand:r,onClose:()=>I(!1),onCreated:()=>{I(!1),u()}})]})}function Cp({machineId:t,sendDaemonCommand:s}){const[r,n]=a.useState([]),[o,i]=a.useState(0),[c,l]=a.useState(!0),[p,x]=a.useState("debug"),m=a.useRef(null),h=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const g=async()=>{try{const I=await s(t,"get_logs",{count:200,minLevel:p,since:o}),u=(I==null?void 0:I.result)||I;if(I!=null&&I.success&&Array.isArray(u==null?void 0:u.logs)&&u.logs.length>0){n(y=>[...y,...u.logs.map(C=>({timestamp:C.ts,level:C.level,message:`[${C.category}] ${C.message}`}))].slice(-300));const b=Math.max(...u.logs.map(y=>y.ts));i(b)}}catch{}};g();const S=setInterval(g,3e3);return()=>clearInterval(S)},[t,c,o,p,s]),a.useEffect(()=>{if(c&&r.length>0){const g=h.current?"smooth":"instant";setTimeout(()=>{var S;(S=m.current)==null||S.scrollIntoView({behavior:g}),h.current=!0},50)}},[r.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(g=>e.jsx("button",{onClick:()=>{x(g),n([]),i(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${p===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[r.length," entries"]}),e.jsx("button",{onClick:()=>l(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{n([]),i(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[r.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),r.map((g,S)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"var(--status-warning)":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"var(--status-warning)":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},S)),e.jsx("div",{ref:m})]})]})}function Hr(t){return t!=null&&t.result&&typeof t.result=="object"&&"success"in t.result?t.result:t}function Ur(t){return t?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):"unknown"}function La(t){if(!t)return"unknown";const s=Date.now()-t,r=Math.max(0,Math.round(s/1e3));if(r<60)return`${r}s ago`;const n=Math.round(r/60);if(n<60)return`${n}m ago`;const o=Math.round(n/60);return o<48?`${o}h ago`:`${Math.round(o/24)}d ago`}function Ip(t){return t?t.ownerType==="user"?`user control · ${t.clientId}`:`agent control · ${t.clientId}`:"view only"}function Mp(t){const s=typeof(t==null?void 0:t.runtimeRecoveryState)=="string"?String(t.runtimeRecoveryState):"";return s?s==="auto_resumed"?"restored after restart":s==="resume_failed"?"restore failed":s==="host_restart_interrupted"?"host restart interrupted":s==="orphan_snapshot"?"snapshot recovered":s.replace(/_/g," "):null}function Ap(t){switch(t){case"running":return"bg-green-500/[0.08] text-green-500";case"starting":return"bg-sky-500/[0.08] text-sky-400";case"stopping":return"bg-orange-500/[0.08] text-orange-400";case"interrupted":return"bg-amber-500/[0.08] text-amber-400";case"failed":return"bg-red-500/[0.08] text-red-500";default:return"bg-[#ffffff0a] text-text-muted"}}function Tp(t){var r;const s=new Map;for(const n of t){if(!["starting","running","stopping","interrupted"].includes(n.lifecycle))continue;const o=typeof((r=n.meta)==null?void 0:r.providerSessionId)=="string"?String(n.meta.providerSessionId).trim():"";if(!o)continue;const i=`${n.providerType}::${n.workspace}::${o}`;s.set(i,(s.get(i)||0)+1)}return Array.from(s.values()).filter(n=>n>1).length}function _p({machineId:t,cliSessions:s,sendDaemonCommand:r}){const[n,o]=a.useState(""),[i,c]=a.useState(null),[l,p]=a.useState(!1),x=Ro(t,{enabled:!!t,includeSessions:!0,limit:12,intervalMs:8e3}),m=x.diagnostics,h=x.loading,g=x.applyDiagnostics,S=a.useMemo(()=>new Map(s.map(f=>[f.sessionId||f.id,f])),[s]),I=a.useCallback(async()=>{if(t){p(!0);try{const f=await r(t,"session_host_get_diagnostics",{includeSessions:!0,limit:12}),j=Hr(f);if(!(j!=null&&j.success))throw new Error((j==null?void 0:j.error)||"Could not load session host diagnostics");g(j.diagnostics||j.result||null),o("")}catch(f){const j=f instanceof Error?f.message:"Could not load session host diagnostics";o(j)}finally{p(!1)}}},[g,t,r]),u=a.useCallback(async(f,j)=>{const v=`${f}:${j.sessionId}`;if(!(f==="session_host_stop_session"&&!window.confirm(`Stop ${j.displayName}?
|
|
63
63
|
This will terminate the hosted runtime.`))){c(v);try{const k=await r(t,f,{sessionId:j.sessionId}),$=Hr(k);if(!($!=null&&$.success))throw new Error(($==null?void 0:$.error)||"Session host action failed");const E=f==="session_host_resume_session"?"resumed":f==="session_host_restart_session"?"restarted":"stopped";gt.showToast(`Session host ${E}: ${j.displayName}`,"success"),await I()}catch(k){const $=k instanceof Error?k.message:"Session host action failed";gt.showToast($,"warning"),o($)}finally{c(k=>k===v?null:k)}}},[t,I,r]),b=a.useCallback(async()=>{if(window.confirm(`Prune duplicate hosted runtimes?
|
|
64
|
-
The newest runtime for each provider session will be kept and older duplicates will be stopped and removed.`)){c("session_host_prune_duplicate_sessions");try{const j=await r(t,"session_host_prune_duplicate_sessions",{}),v=Hr(j);if(!(v!=null&&v.success))throw new Error((v==null?void 0:v.error)||"Duplicate prune failed");const k=v.result||{},$=Array.isArray(k.prunedSessionIds)?k.prunedSessionIds.length:0,E=typeof k.duplicateGroupCount=="number"?k.duplicateGroupCount:0;gt.showToast(`Pruned ${$} duplicate runtime(s) across ${E} group(s)`,"success"),await I()}catch(j){const v=j instanceof Error?j.message:"Duplicate prune failed";gt.showToast(v,"warning"),o(v)}finally{c(j=>j==="session_host_prune_duplicate_sessions"?null:j)}}},[t,I,r]),y=a.useMemo(()=>[...(m==null?void 0:m.sessions)||[]].sort((f,j)=>(j.lastActivityAt||0)-(f.lastActivityAt||0)),[m==null?void 0:m.sessions]),d=a.useMemo(()=>Tp(y),[y]),C=a.useMemo(()=>y.reduce((f,j)=>{var v;return f+(((v=j.attachedClients)==null?void 0:v.length)||0)},0),[y]),M=a.useMemo(()=>[...(m==null?void 0:m.recentTransitions)||[]].slice(-6).reverse(),[m==null?void 0:m.recentTransitions]),N=a.useMemo(()=>[...(m==null?void 0:m.recentLogs)||[]].reverse().find(f=>f.level==="warn"||f.level==="error")||null,[m==null?void 0:m.recentLogs]);return e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Session Host"]}),e.jsx("div",{className:"text-[12px] text-text-secondary mt-1",children:"Hosted CLI runtime diagnostics and recovery controls."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d>0&&e.jsx("button",{type:"button",className:"machine-btn",onClick:()=>{b()},disabled:i==="session_host_prune_duplicate_sessions",children:i==="session_host_prune_duplicate_sessions"?"Pruning…":`Prune duplicates (${d})`}),e.jsx("span",{className:`px-2 py-1 rounded-md text-[10px] font-semibold ${m?"bg-green-500/[0.08] text-green-500":"bg-amber-500/[0.08] text-amber-400"}`,children:m?"Managed":"Unavailable"}),e.jsxs("button",{type:"button",className:"machine-btn flex items-center gap-1",onClick:()=>{I()},disabled:h||l,children:[e.jsx(fs,{size:13}),h||l?"Refreshing…":"Refresh"]})]})]}),n&&!m&&e.jsx("div",{className:"rounded-xl border border-amber-500/[0.22] bg-amber-500/[0.08] px-3.5 py-3 text-[12px] text-amber-200 mb-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(es,{size:14,className:"mt-0.5 text-amber-300 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-amber-100",children:"Session host diagnostics unavailable"}),e.jsx("div",{className:"text-amber-200/90 mt-1",children:n})]})]})}),m&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Runtimes"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:m.runtimeCount})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Clients"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:C})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Requests"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:m.recentRequests.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Started"}),e.jsx("div",{className:"text-[12px] font-medium text-text-primary mt-1",children:La(m.hostStartedAt)}),e.jsx("div",{className:"text-[10px] text-text-secondary mt-0.5",children:Ur(m.hostStartedAt)})]})]}),N&&e.jsxs("div",{className:"rounded-xl border border-amber-500/[0.16] bg-amber-500/[0.07] px-3.5 py-3 text-[11px] text-text-secondary mb-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-amber-200 font-medium mb-1",children:[e.jsx(es,{size:13})," Latest host warning"]}),e.jsx("div",{className:"text-text-primary leading-relaxed",children:N.message}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-1",children:[Ur(N.timestamp),N.sessionId?` · ${N.sessionId}`:""]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-2.5",children:[e.jsx(xr,{size:14})," Hosted Runtimes"]}),y.length===0?e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-4 text-[12px] text-text-secondary",children:"No hosted runtimes on this machine yet."}):e.jsx("div",{className:"space-y-2",children:y.map(f=>{var T;const j=i===`session_host_resume_session:${f.sessionId}`,v=i===`session_host_restart_session:${f.sessionId}`,k=i===`session_host_stop_session:${f.sessionId}`,$=Mp(f.meta),E=S.get(f.sessionId),W=f.attachedClients.length===1?"1 client":`${f.attachedClients.length} clients`;return e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("div",{className:"font-medium text-[13px] text-text-primary",children:f.displayName||(E==null?void 0:E.cliName)||f.providerType}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Ap(f.lifecycle)}`,children:f.lifecycle}),$&&e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold bg-sky-500/[0.08] text-sky-300",children:$})]}),e.jsxs("div",{className:"text-[11px] text-text-secondary mt-1 flex flex-wrap gap-2",children:[e.jsx("span",{className:"text-text-primary/90",children:f.workspaceLabel||(E==null?void 0:E.runtimeWorkspaceLabel)||f.workspace||"No workspace"}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsx("span",{className:"font-mono text-text-primary",children:f.runtimeKey}),f.osPid?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"text-text-primary/90",children:["pid ",f.osPid]})]}):null]}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-1 flex flex-wrap gap-2",children:[e.jsx("span",{className:((T=f.writeOwner)==null?void 0:T.ownerType)==="user"?"text-amber-200":"text-text-primary/85",children:Ip(f.writeOwner)}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 text-text-primary/85",children:[e.jsx(ln,{size:11})," ",W]}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"text-text-primary/85",children:["active ",La(f.lastActivityAt)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[(f.lifecycle==="interrupted"||f.lifecycle==="failed"||f.lifecycle==="stopped")&&e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1",disabled:!!i,onClick:()=>{u("session_host_resume_session",f)},children:j?"Resuming…":"Resume"}),e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1",disabled:!!i,onClick:()=>{u("session_host_restart_session",f)},children:v?"Restarting…":"Restart"}),(f.lifecycle==="running"||f.lifecycle==="starting"||f.lifecycle==="interrupted")&&e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1 border-red-500/20 text-red-300 hover:text-red-200",disabled:!!i,onClick:()=>{u("session_host_stop_session",f)},children:k?"Stopping…":"Stop"})]})]})},f.sessionId)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider mb-2.5",children:"Recent Host Activity"}),M.length===0?e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3 text-[12px] text-text-secondary",children:"No recent runtime transitions yet."}):e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary divide-y divide-border-subtle",children:M.map(f=>{var v;const j=y.find(k=>k.sessionId===f.sessionId);return e.jsxs("div",{className:"px-3.5 py-2.5 text-[11px] flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-text-primary font-medium",children:(j==null?void 0:j.displayName)||((v=S.get(f.sessionId))==null?void 0:v.cliName)||f.sessionId}),e.jsxs("div",{className:"text-text-secondary mt-0.5 leading-relaxed",children:[f.action,f.lifecycle?` · ${f.lifecycle}`:"",f.detail?` · ${f.detail}`:"",f.error?` · ${f.error}`:""]})]}),e.jsx("div",{className:`shrink-0 text-[10px] ${f.success===!1?"text-red-300":"text-text-secondary"}`,children:Ur(f.timestamp)})]},`${f.sessionId}:${f.timestamp}:${f.action}`)})})]}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-3",children:["Endpoint: ",e.jsx("span",{className:"font-mono text-text-primary",children:m.endpoint||"unknown"}),n?e.jsxs("span",{className:"text-amber-200",children:[" · last error: ",n]}):null]})]})]})}function Pp({machine:t,launchPick:s,actions:r}){const{runLaunchCliCore:n,setLaunchPick:o}=r;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(i=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{o(null),n({cliType:s.cliType,workspaceId:i.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:i.label||i.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:i.path})]},i.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{o(null),n({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{o(null),n({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>o(null),children:"Cancel"})]})]})})}function zr({icon:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-text-muted tracking-[0.14em] uppercase",children:[t,e.jsx("span",{children:s})]})}function Fr({children:t,className:s=""}){return e.jsx("div",{className:`rounded-2xl border border-[#ffffff0a] bg-bg-surface/70 backdrop-blur-sm p-3 ${s}`,children:t})}function Lp({machineEntry:t,providers:s,recentLaunches:r,currentConversations:n,onUpgradeDaemon:o,onOpenRecent:i,onOpenConversation:c}){const l=n.slice(0,6),p=r.slice(0,4),m=Cs(t,"0.8.44"),h=g=>g==="ide"?"IDE":g==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-4 md:min-w-[300px] md:max-w-[360px] shrink-0 md:h-full overflow-y-auto",children:[l.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(Bt,{size:13}),children:"Current Chats"}),e.jsx(Fr,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:l.map(g=>{const S=sn(g);return e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>c(g),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate group-hover:text-accent-primary transition-colors",children:Qe(g)}),S>0&&e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:eo(S)})]}),e.jsx("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:rs(g)})]},g.tabKey)})})})]}),p.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(Ya,{size:13}),children:"Recent Launches"}),e.jsx(Fr,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:p.map(g=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>i(g),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:g.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[h(g.kind),g.subtitle?` · ${g.subtitle}`:""]})]},g.id))})})]}),t.versionMismatch&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(es,{size:13}),children:"Daemon Update"}),e.jsx(Fr,{className:"border-amber-500/20 bg-amber-500/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:m?"Daemon update required":"Version mismatch detected"}),e.jsx("div",{className:"text-xs text-text-secondary leading-relaxed",children:m?"This machine is on an incompatible daemon version. Update it before starting more sessions.":"This machine is running a different daemon version than the current app. Update it before starting more sessions."}),e.jsxs("button",{type:"button",className:"inline-flex items-center justify-center gap-2 px-3 py-2 rounded-xl bg-amber-500/12 border border-amber-500/20 text-amber-300 hover:bg-amber-500/18 transition-colors",onClick:o,children:[e.jsx(fs,{size:13}),e.jsx("span",{className:"text-sm font-medium",children:"Update daemon"})]})]})})]})]})}function Rp(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Ep={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function Qs(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Dp(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function Vr({category:t,machine:s,machineId:r,providers:n,managedEntries:o,getIcon:i,actions:c,sendDaemonCommand:l,initialWorkspaceId:p,initialWorkspacePath:x}){const m=ms(),{handleLaunchIde:h,handleStopCli:g,handleRestartIde:S,handleStopIde:I,handleDetectIdes:u,launchingIde:b,launchingAgentType:y,addLog:d}=c,[C,M]=a.useState(null),N=a.useCallback(A=>{A&&m({pathname:"/",search:`?activeTab=${encodeURIComponent(A)}`})},[m]),f=Ep[t],j=t==="ide",v=t==="acp",k=a.useMemo(()=>n.filter(A=>A.category===t&&(t==="ide"||A.installed!==!1)),[t,n]),$=a.useMemo(()=>new Map(k.map(A=>[A.type,A.displayName||A.type])),[k]),[E,W]=a.useState(""),[T,V]=a.useState(""),[R,w]=a.useState([]),[B,ee]=a.useState(""),[L,D]=a.useState(""),[O,z]=a.useState([]),[Q,re]=a.useState(!1),[je,Y]=a.useState(""),[ne,_]=a.useState(!1),[pe,me]=a.useState(null),[J,ie]=a.useState(x?"__custom__":p||s.defaultWorkspaceId||""),[se,he]=a.useState(x||""),[ce,be]=a.useState([]),[Z,oe]=a.useState(!1),[ae,ke]=a.useState(""),[we,P]=a.useState([]),[fe,F]=a.useState(!1),[xe,Ie]=a.useState(""),ge=a.useRef(null),[Ee,Ke]=a.useState(null),He=a.useRef("__home__"),[ct,Fe]=a.useState("__home__"),[rt,ft]=a.useState(!1),Je=a.useRef(0),et=ce.filter(A=>!o.some(U=>U.type===A&&bt(U.status)!=="stopped")),pt=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!J&&ie(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(x){ie("__custom__"),he(x);return}p&&(ie(p),he(""))},[p,x]),a.useEffect(()=>{j||E&&(k.some(A=>A.type===E)||(W(""),D("")))},[k,j,E]);const Ue=(()=>{if(J==="__custom__")return se.trim();if(!J)return"";const A=(s.workspaces||[]).find(U=>U.id===J);return(A==null?void 0:A.path)||""})(),tt=a.useCallback(A=>{const U=pt.current[A];U&&(clearTimeout(U),delete pt.current[A]),be(de=>de.includes(A)?de.filter(ye=>ye!==A):de)},[]),lt=a.useRef(new Set),mt=a.useCallback(async A=>{if(l){F(!0),Ie("");try{const U=await wr(l,r,A);ke(U.path),he(U.path),P(U.directories)}catch(U){Ie(U instanceof Error?U.message:"Could not load folder")}finally{F(!1)}}},[r,l]),q=a.useCallback(()=>{var U;if(!l)return;ie("__custom__"),oe(!0);const A=vr(s.platform,[se.trim(),Ue,s.defaultWorkspacePath,(U=s.workspaces[0])==null?void 0:U.path]);mt(A)},[se,mt,s.defaultWorkspacePath,s.platform,s.workspaces,Ue,l]),_e=a.useCallback(A=>{const U=String(A.workspace||"").trim();if(!U)return;const de=(s.workspaces||[]).find(ye=>Qs(ye.path)===Qs(U));if(de){ie(de.id),he("");return}ie("__custom__"),he(U)},[s.workspaces]),Le=a.useCallback(A=>{const U=String(A.workspace||"").trim();if(!U)return{workspaceId:null,workspacePath:"",useHome:!0};const de=(s.workspaces||[]).find(ye=>Qs(ye.path)===Qs(U));return de?{workspaceId:de.id,workspacePath:"",useHome:!1}:{workspaceId:null,workspacePath:U,useHome:!1}},[s.workspaces]),Oe=a.useCallback(async A=>{if(!l||!A||t!=="cli"){z([]),re(!1),Y("");return}const U=Je.current+1;Je.current=U,re(!0),Y("");try{const de=await l(r,"list_saved_sessions",{providerType:A,kind:"cli",limit:30});if(Je.current!==U)return;const ye=(de==null?void 0:de.result)??de;z(Array.isArray(ye==null?void 0:ye.sessions)?ye.sessions:[])}catch(de){if(Je.current!==U)return;z([]),Y(de instanceof Error?de.message:"Could not load saved sessions")}finally{Je.current===U&&re(!1)}},[t,r,l]),dt=a.useMemo(()=>{if(t!=="cli"||!E)return null;const A=$.get(E)||E;return{routeId:r,daemonId:r,providerSessionId:L||void 0,transport:"pty",mode:"chat",agentName:A,agentType:E,status:"idle",title:A,messages:[],ideType:E,workspaceName:Ue,displayPrimary:A,displaySecondary:"CLI",streamSource:"native",tabKey:`machine:${r}:resume-history:${E}`}},[t,r,$,Ue,L,E]),Ct=a.useCallback(A=>{if(t==="ide"||!A){w([]);return}w(ri(r,A))},[t,r]);a.useEffect(()=>{if(D(""),Ct(E),t!=="cli"||!E){z([]),Y(""),re(!1);return}Oe(E)},[t,Ct,Oe,E]),a.useEffect(()=>{if(!L)return;const A=O.find(U=>U.providerSessionId===L);A!=null&&A.canResume||D("")},[O,L]);const yt=a.useCallback((A,U)=>{ge.current=U,He.current=A.selectedWorkspaceKey||"__home__",Fe(A.selectedWorkspaceKey||"__home__"),Ke(A)},[]),K=a.useCallback(()=>{ge.current&&(ft(!0),ge.current().finally(()=>{ge.current=null,ft(!1),Ke(null)}))},[]),H=a.useCallback(A=>{if(!A)return;be(de=>de.includes(A)?de:[...de,A]);const U=pt.current[A];U&&clearTimeout(U),pt.current[A]=setTimeout(()=>{be(de=>de.includes(A)?de.filter(ye=>ye!==A):de),delete pt.current[A]},2e4)},[]);a.useEffect(()=>{for(const U of o)bt(U.status)!=="stopped"&&(ce.includes(U.type)&&!lt.current.has(U.type)&&(lt.current.add(U.type),d("info",`${$.get(U.type)||U.type} launched`,!0)),tt(U.type));const A=new Set(o.filter(U=>bt(U.status)!=="stopped").map(U=>U.type));lt.current.forEach(U=>{!ce.includes(U)&&!A.has(U)&<.current.delete(U)})},[d,tt,o,ce,$]),a.useEffect(()=>()=>{Object.values(pt.current).forEach(clearTimeout),pt.current={}},[]);const[G,X]=a.useState({}),[le,ue]=a.useState(null);a.useEffect(()=>{if(!j||!r||!l)return;(async()=>{try{const U=await l(r,"get_ide_extensions",{}),de=(U==null?void 0:U.result)||U;de!=null&&de.success&&(de!=null&&de.ideExtensions)&&X(de.ideExtensions)}catch{}})()},[j,r,l]);const Re=A=>j?Ze(A.type):t==="cli"?A.cliName:A.acpName,Pe=j?s.detectedIdes||[]:[],te=a.useCallback(async A=>{const U=(A==null?void 0:A.type)||E,de=(A==null?void 0:A.workspacePath)??Ue;if(j){await h(U,de?{workspace:de}:void 0)&&H(U);return}const ye=await c.runLaunchCliCore({cliType:U,dir:A!=null&&A.workspaceId?void 0:de||void 0,workspaceId:(A==null?void 0:A.workspaceId)||void 0,useHome:(A==null?void 0:A.useHome)||!(A!=null&&A.workspaceId)&&!de,argsStr:(A==null?void 0:A.argsStr)??(T||void 0),model:(A==null?void 0:A.model)??(v&&B||void 0),resumeSessionId:(A==null?void 0:A.resumeSessionId)||!v&&t==="cli"&&U===E&&L||void 0});if(ye.success||ye.pending){const Ae=(A==null?void 0:A.argsStr)??T;!j&&(Ae!=null&&Ae.trim())&&(ni(r,U,Ae),Ct(U)),H(U),ye.success&&ye.sessionId&&N(ye.sessionId)}},[c,h,v,j,T,B,Ct,H,r,N,Ue,L,E]),Ne=()=>{var ye;const A=j?Ze(E):$.get(E)||E,{options:U,selectedKey:de}=Zt({machine:s,currentWorkspaceId:J&&J!=="__custom__"?J:null,currentWorkspacePath:Ue});yt({title:`Launch ${A}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:U,selectedWorkspaceKey:de,details:[{label:"Mode",value:f.label},{label:"Provider",value:A},...!j&&t==="cli"&&L?[{label:"Resume",value:((ye=O.find(Ae=>Ae.providerSessionId===L))==null?void 0:ye.title)||L}]:[],...!j&&T.trim()?[{label:"Arguments",value:T.trim()}]:[],...v&&B.trim()?[{label:"Model",value:B.trim()}]:[]]},async()=>{const Ae=U.find(Te=>Te.key===He.current);Ae!=null&&Ae.workspaceId?(ie(Ae.workspaceId),he("")):Ae!=null&&Ae.workspacePath?(ie("__custom__"),he(Ae.workspacePath)):(ie(""),he("")),await te({workspaceId:(Ae==null?void 0:Ae.workspaceId)??null,workspacePath:(Ae==null?void 0:Ae.workspacePath)??"",useHome:!(Ae!=null&&Ae.workspaceId)&&!(Ae!=null&&Ae.workspacePath)})})},ze=A=>{j?I(A):g(A.type,A.workspace,A.id)},Ve=a.useCallback(async(A,U,de=!1)=>{if(A.mode===U){de&&A.sessionId&&N(A.sessionId);return}if(!l||!A.sessionId){de&&A.sessionId&&N(A.sessionId);return}try{await l(r,"set_cli_view_mode",{targetSessionId:A.sessionId,cliType:A.type,mode:U}),de&&N(A.sessionId)}catch(ye){Dp(ye)?console.warn("Skipped CLI view mode switch:",ye instanceof Error?ye.message:String(ye)):console.error("Failed to switch CLI view mode:",ye)}},[r,N,l]),Ye=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:J,onChange:A=>{const U=A.target.value;if(ie(U),U==="__custom__"&&l){q();return}U!=="__custom__"&&he("")},className:"px-3 py-1.5 rounded-md min-w-[200px] flex-1 text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(A=>e.jsxs("option",{value:A.id,children:[A.id===s.defaultWorkspaceId?"⭐ ":"",br(A.path,A.label)]},A.id)),e.jsx("option",{value:"__custom__",children:l?"📁 Select workspace…":"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:l?"📁 Select workspace…":"✏️ Custom path…"})]})}),J==="__custom__"&&(l?e.jsx("button",{type:"button",className:"px-3 py-1.5 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] hover:border-accent-primary text-text-secondary hover:text-text-primary transition-colors",onClick:q,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:se,onChange:A=>he(A.target.value),className:"px-3 py-1.5 rounded-md flex-1 min-w-[200px] text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",autoFocus:!0}))]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:J==="__custom__"?Ue?e.jsx("span",{className:"font-mono truncate block",title:Ue,children:Ue}):l?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":Ue?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:J===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:Ue,children:Ue})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-5 rounded-xl mb-6 bg-bg-secondary border ${f.accent} relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 left-0 w-full height-[1px] bg-gradient-to-r from-transparent via-[#ffffff20] to-transparent"}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-primary/60"}),"Select ",f.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:j?Pe.length>0?Pe.map(A=>{const U=o.find(We=>(We.type||"").toLowerCase()===(A.type||"").toLowerCase()&&bt(We.status)!=="stopped"),de=A.running||!!U,ye=!!U&&U.cdpConnected,Ae=ce.includes(A.type||A.id||""),Te=E===(A.type||"");return e.jsxs("button",{onClick:()=>{if(ye&&U){const We=U.sessionId;We?m(`/dashboard?activeTab=${encodeURIComponent(We)}`,{state:{openRemoteForTabKey:We}}):m("/dashboard",{state:{openRemoteForTabKey:U.id}});return}Ae||W(We=>We===(A.type||"")?"":A.type||"")},disabled:!!b||Ae,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${ye?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":Te?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,style:{opacity:b&&b!==A.type?.4:1},children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:i(A.type)}),de&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${ye?"bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]":"bg-orange-500 shadow-[0_0_6px_rgba(249,115,22,0.6)] animate-pulse"}`})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.name||Ze(A.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ye?"text-green-400":Ae?"text-orange-400":Te?"text-accent-primary":"text-text-muted"}`,children:ye?"Open Session":Ae?"Starting...":Te?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 flex flex-col items-center justify-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted italic gap-2",children:["No IDEs detected.",e.jsxs("button",{onClick:u,className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded-lg flex items-center gap-1.5",children:[e.jsx(Ji,{size:14})," Scan System"]})]}):k.length>0?k.map(A=>{const U=E===A.type,de=ce.includes(A.type),Ae=!!o.find(Te=>Te.type===A.type&&bt(Te.status)!=="stopped");return e.jsxs("button",{onClick:()=>W(Te=>Te===A.type?"":A.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${U?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:A.icon}),Ae&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${de?"text-orange-400":U?"text-accent-primary":"text-text-muted"}`,children:de?"Starting...":U?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 text-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted",children:["No usable ",t.toUpperCase()," providers available.",e.jsx("div",{className:"mt-1 text-[11px] text-text-muted",children:"Set a custom executable path in Providers if the binary is installed outside the default location."})]})}),E&&(j?Pe.find(A=>A.type===E):k.find(A=>A.type===E))&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-[#ffffff1a] flex flex-col gap-4 animate-in slide-in-from-top-2 fade-in duration-200",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center justify-between",children:[e.jsx("span",{children:"Launch Settings"}),e.jsx("span",{className:"text-accent-primary font-bold",children:j?Ze(E):$.get(E)||E})]}),Ye,!j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[!v&&t==="cli"&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Resume from History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void Oe(E),disabled:!E||Q,children:Q?"Loading…":"Refresh"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:()=>{E&&(_(!0),Oe(E))},disabled:!E,children:"Open History"})]})]}),L?(()=>{const A=O.find(U=>U.providerSessionId===L);return A?e.jsx("div",{className:"rounded-md border border-[#ffffff1a] bg-bg-primary px-3 py-2 text-[10px] text-text-muted leading-relaxed",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-text-primary text-[11px] font-semibold truncate",children:A.title||A.providerSessionId}),e.jsx("div",{className:"font-mono break-all",children:A.providerSessionId}),e.jsx("div",{children:A.workspace||"Workspace unknown"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm shrink-0",onClick:()=>D(""),children:"Clear"})]})}):null})():e.jsx("div",{className:"text-[10px] text-text-muted",children:"Start a new CLI session, or choose one from history."}),je&&e.jsx("div",{className:"text-[10px] text-red-400",children:je})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[v&&e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Target Model"}),e.jsx("input",{type:"text",placeholder:"Leave empty for default",value:B,onChange:A=>ee(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Startup Arguments"}),e.jsx("input",{type:"text",placeholder:"Optional flags...",value:T,onChange:A=>V(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"}),R.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:R.map(A=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>V(A),title:A,children:A},A))})]})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:Ne,disabled:!!y||!!b||ce.includes(E),className:"btn btn-primary h-9 px-6 font-bold transition-all flex items-center gap-2 hover:shadow-glow hover:-translate-y-px",children:y===E||b===E?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",o.length+ce.filter(A=>!o.some(U=>U.type===A&&bt(U.status)!=="stopped")).length,")"]}),o.length===0&&et.length===0?e.jsxs("div",{className:"py-7.5 px-5 text-center rounded-xl bg-bg-secondary border border-dashed border-border-subtle text-text-muted text-[13px] mb-5",children:["No ",f.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[et.map(A=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:i(A)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:j?Ze(A):$.get(A)||A}),e.jsx("div",{className:"text-[11px] text-text-muted",children:y===A?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${A}`)),o.map(A=>{const U=j?A:null,de=v?A:null,ye=!j&&!v?A:null,Ae=bt(A.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:i(A.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[Re(A),(U==null?void 0:U.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",U.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:A.workspace||"—"}),(de==null?void 0:de.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",de.currentModel]}),(de==null?void 0:de.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",de.currentPlan]}),(ye==null?void 0:ye.mode)&&e.jsx("span",{className:ye.mode==="chat"?"text-violet-400":"text-text-secondary",children:ye.mode==="chat"?"Chat view":"Terminal view"})]}),ye&&(ye.runtimeKey||ye.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ye.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",ye.runtimeKey]}),e.jsx("button",{type:"button",className:"flex items-center justify-center px-1.5 py-0.5 rounded text-[9px] bg-[#ffffff0a] hover:bg-[#ffffff14] border border-[#ffffff0a] text-text-muted hover:text-text-primary transition-colors cursor-pointer",onClick:()=>{var Te;(Te=navigator.clipboard)==null||Te.writeText(`adhdev attach ${ye.runtimeKey}`),M(ye.runtimeKey||null),window.setTimeout(()=>{M(We=>We===ye.runtimeKey?null:We)},1200)},children:C===ye.runtimeKey?"Copied":"Copy"})]}),ye.runtimeWriteOwner&&e.jsx("span",{style:{color:ye.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ye.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Rp(ye.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Ae==="stopped"?"bg-red-500/[0.08] text-red-500":Ae==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Ae}),j&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const Te=A.sessionId;if(Te){m(`/dashboard?activeTab=${encodeURIComponent(Te)}`,{state:{openRemoteForTabKey:Te}});return}m("/dashboard",{state:{openRemoteForTabKey:A.id}})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-primary transition-colors cursor-pointer",title:"Open remote control",children:e.jsx(Nt,{size:13})}),e.jsx("button",{onClick:()=>{const Te=A.workspace||"",{options:We,selectedKey:ot}=Zt({machine:s,currentWorkspacePath:Te});yt({title:`Restart ${Ze(A.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:We,selectedWorkspaceKey:ot,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Ze(A.type)}]},async()=>{const De=We.find(Kt=>Kt.key===He.current),st=(De==null?void 0:De.workspacePath)??"";if(st&&st!==Te){await te({type:A.type,workspacePath:st});return}await S(A)})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-orange-500/20 text-orange-400 transition-colors cursor-pointer",title:"Restart",children:e.jsx(fs,{size:14})})]}),v&&e.jsx("button",{onClick:()=>{const Te=A.sessionId;Te&&N(Te)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"View chat",disabled:!A.sessionId,children:e.jsx(Bt,{size:14})}),ye&&Ae!=="stopped"&&e.jsxs(e.Fragment,{children:[ye.mode&&e.jsx(bn,{mode:ye.mode,onChange:Te=>void Ve(ye,Te,!1),compact:!0}),e.jsx("button",{onClick:()=>{const Te=A.sessionId;Te&&N(Te)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"Open current view in dashboard",disabled:!A.sessionId,children:ye.mode==="chat"?e.jsx(Bt,{size:14}):e.jsx(Nt,{size:13})})]}),Ae==="stopped"?e.jsx("button",{onClick:()=>{const Te=A.workspace||"",We=j?Ze(A.type):Re(A),{options:ot,selectedKey:De}=Zt({machine:s,currentWorkspacePath:Te});yt({title:`Launch ${We}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:ot,selectedWorkspaceKey:De,details:[{label:"Mode",value:f.label},{label:"Provider",value:We}]},async()=>{const st=ot.find(Kt=>Kt.key===He.current);await te({type:A.type,workspaceId:(st==null?void 0:st.workspaceId)??null,workspacePath:(st==null?void 0:st.workspacePath)??"",useHome:!(st!=null&&st.workspaceId)&&!(st!=null&&st.workspacePath),model:de==null?void 0:de.currentModel})})},disabled:ce.includes(A.type),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-green-500/20 text-green-400 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Restart",children:ce.includes(A.type)?"⏳":e.jsx(un,{size:14})}):e.jsx("button",{onClick:()=>ze(A),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-red-500/20 text-red-400 transition-colors cursor-pointer",title:"Stop",children:e.jsx(wt,{size:14})})]})]}),U&&U.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:U.aiAgents.map(Te=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${ro(Te.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[Te.name," · ",bt(Te.status)]},Te.id))}),U&&(G[U.type]||[]).length>0&&l&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(G[U.type]||[]).map(Te=>e.jsxs("button",{disabled:le===`${U.type}.${Te.type}`,onClick:async()=>{const We=`${U.type}.${Te.type}`;ue(We);try{await l(r,"set_ide_extension",{ideType:U.type,extensionType:Te.type,enabled:!Te.enabled}),X(ot=>({...ot,[U.type]:(ot[U.type]||[]).map(De=>De.type===Te.type?{...De,enabled:!De.enabled}:De)}))}catch(ot){console.error("Extension toggle failed:",ot)}finally{ue(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${Te.enabled?"bg-accent-primary/10 border-accent-primary/20 text-accent-primary-light":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Te.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),Te.name,e.jsx("span",{className:"text-[9px] font-normal",children:Te.enabled?"ON":"OFF"})]},Te.type))})]})]},A.id)})]}),Z&&l&&e.jsx(jr,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:ae,directories:we,busy:fe,error:xe,confirmLabel:"Use this folder",onClose:()=>oe(!1),onNavigate:A=>{mt(A)},onConfirm:A=>{he(A),ie("__custom__"),oe(!1)}}),Ee&&e.jsx(Cn,{title:Ee.title,description:Ee.description,details:Ee.details,workspaceOptions:Ee.workspaceOptions,selectedWorkspaceKey:ct,onWorkspaceChange:A=>{He.current=A,Fe(A)},confirmLabel:Ee.confirmLabel,busy:rt,onConfirm:K,onCancel:()=>{ge.current=null,Ke(null)}}),ne&&dt&&e.jsx(gn,{activeConv:dt,ides:[],isCreatingChat:!1,isRefreshingHistory:Q,savedSessions:O,isSavedSessionsLoading:Q,isResumingSavedSessionId:pe,onClose:()=>_(!1),onNewChat:()=>{D(""),_(!1)},onSwitchSession:()=>{},onRefreshHistory:()=>{Oe(E)},onResumeSavedSession:A=>{if(!A.canResume||pe)return;const U=Le(A);D(A.providerSessionId),_e(A),me(A.providerSessionId),_(!1),te({type:A.providerType,workspaceId:U.workspaceId,workspacePath:U.workspacePath,useHome:U.useHome,resumeSessionId:A.providerSessionId}).finally(()=>{me(de=>de===A.providerSessionId?null:de)})}})]})}const Ra=[{id:"ide",label:"IDE",helper:"Open a graphical workspace and attach CDP"},{id:"cli",label:"CLI",helper:"Launch a terminal-first workspace on this machine"},{id:"acp",label:"ACP",helper:"Launch an ACP-backed workspace on this machine"}];function $p({machine:t,machineId:s,providers:r,ideSessions:n,cliSessions:o,acpSessions:i,actions:c,getIcon:l,initialCategory:p="ide",initialWorkspaceId:x,initialWorkspacePath:m,sendDaemonCommand:h}){var u;const[g,S]=a.useState(p);a.useEffect(()=>{S(p)},[p]);const I=a.useMemo(()=>({ide:n.length,cli:o.length,acp:i.length}),[n.length,o.length,i.length]);return e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 h-full",children:[e.jsxs("div",{className:"flex flex-col gap-1 pb-4 border-b border-[#ffffff0a] mb-4",children:[e.jsx("div",{className:"text-lg font-semibold text-text-primary",children:"Workspace Launcher"}),e.jsx("div",{className:"text-sm text-text-secondary",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-baseline gap-4 mb-4",children:[e.jsx("div",{className:"flex bg-bg-surface p-1 rounded-lg border border-[#ffffff0a] w-fit",children:Ra.map(b=>e.jsxs("button",{type:"button",className:`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${g===b.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>S(b.id),children:[e.jsx("span",{children:b.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${g===b.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:I[b.id]})]},b.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(u=Ra.find(b=>b.id===g))==null?void 0:u.helper})]}),g==="ide"&&e.jsx(Vr,{category:"ide",machine:t,machineId:s,providers:r,managedEntries:n,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m}),g==="cli"&&e.jsx(Vr,{category:"cli",machine:t,machineId:s,providers:r,managedEntries:o,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m}),g==="acp"&&e.jsx(Vr,{category:"acp",machine:t,machineId:s,providers:r,managedEntries:i,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m})]})}function Bp({onNicknameSynced:t}={}){var se,he,ce,be,Z,oe,ae,ke,we;const{id:s}=Ri(),r=ms(),n=on(),{sendCommand:o}=St(),i=Bs(),c=po(),l=c.ides||[],p=c.initialLoaded??!0,x=l.find(P=>P.id===s&&P.type==="adhdev-daemon"),m=l.some(P=>P.type==="adhdev-daemon"),[h,g]=a.useState("workspace"),[S,I]=a.useState("ide"),u=a.useRef(null),[b,y]=a.useState(null),d=a.useRef("__home__"),[C,M]=a.useState("__home__"),[N,f]=a.useState(!1),j=a.useRef(null);a.useEffect(()=>{!s||!x||!(!x.workspaces||!x.availableProviders||!x.detectedIdes||!x.recentLaunches)||i(s,{minFreshMs:3e4}).catch(()=>{})},[i,x,s]),Id(s&&h==="overview"?[s]:[],{enabled:h==="overview",intervalMs:15e3});const v=()=>{if(m){r("/dashboard",{state:{mobileSection:"machines"}});return}r("/machines")},k=gp({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:o,onNicknameSynced:t,logsEndRef:j});a.useEffect(()=>gt.onToast(fe=>{c.setToasts(xe=>{if(xe.some(Ee=>Ee.message===fe.message&&fe.timestamp-Ee.timestamp<3e3))return xe;const ge={id:fe.id,message:fe.message,type:fe.type,timestamp:fe.timestamp,targetKey:fe.targetKey,actions:fe.actions};return[...xe.slice(-4),ge]});const F=fe.duration||5e3;setTimeout(()=>c.setToasts(xe=>xe.filter(Ie=>Ie.id!==fe.id)),F)}),[c]);const $=(x==null?void 0:x.availableProviders)||[],E={};for(const P of $)E[P.type]=P.icon;const W=P=>E[P]||"",T=x?{id:x.id,hostname:no(x,{fallbackId:x.id}),platform:((se=x.machine)==null?void 0:se.platform)||"unknown",arch:((he=x.machine)==null?void 0:he.arch)||"",cpus:((ce=x.machine)==null?void 0:ce.cpus)||0,totalMem:((be=x.machine)==null?void 0:be.totalMem)||0,freeMem:(Z=x.machine)==null?void 0:Z.freeMem,availableMem:(oe=x.machine)==null?void 0:oe.availableMem,loadavg:(ae=x.machine)==null?void 0:ae.loadavg,uptime:(ke=x.machine)==null?void 0:ke.uptime,release:((we=x.machine)==null?void 0:we.release)||"",cdpConnected:!!x.cdpConnected,machineNickname:x.machineNickname||null,p2p:x.p2p?{screenshotActive:!1,...x.p2p}:{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:x.detectedIdes||[],workspaces:x.workspaces||[],defaultWorkspaceId:x.defaultWorkspaceId??x.activeWorkspaceId??null,defaultWorkspacePath:x.defaultWorkspacePath??x.activeWorkspacePath??null}:null,V=l.filter(P=>P.daemonId===s&&P.type!=="adhdev-daemon").filter(P=>!Ls(P)&&!ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,version:P.version||"",instanceId:P.instanceId||"",status:P.status,workspace:P.workspace||null,terminals:P.terminals||0,aiAgents:Uc(P.aiAgents||(P.agents||[]).map(fe=>({id:fe.name,name:fe.name,status:fe.status,version:fe.version}))),activeChat:P.activeChat||null,chats:P.chats||[],childSessions:P.childSessions||[],cdpConnected:P.cdpConnected||!1,daemonId:s})),R=l.filter(P=>P.daemonId===s&&Ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,cliName:P.cliName||P.type,status:P.status,workspace:P.workspace||"",activeChat:P.activeChat||null,providerSessionId:P.providerSessionId,mode:P.mode,runtimeKey:P.runtimeKey,runtimeDisplayName:P.runtimeDisplayName,runtimeWorkspaceLabel:P.runtimeWorkspaceLabel,runtimeWriteOwner:P.runtimeWriteOwner||null,runtimeAttachedClients:P.runtimeAttachedClients||[],daemonId:s})),w=l.filter(P=>P.daemonId===s&&ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,acpName:P.cliName||P.type,status:P.status,workspace:P.workspace||"",activeChat:P.activeChat||null,providerSessionId:P.providerSessionId,currentModel:P.currentModel,currentPlan:P.currentPlan,daemonId:s})),B=x?kt(x,{fallbackId:s}):"",ee="workspace",L=n.state,D=L==null?void 0:L.initialMachineTab,O=L==null?void 0:L.initialWorkspaceCategory,z=L==null?void 0:L.initialWorkspaceId,Q=L==null?void 0:L.initialWorkspacePath,re=D==="ides"||D==="clis"||D==="acps"?"workspace":D||ee,je=D==="ides"?"ide":D==="clis"?"cli":D==="acps"?"acp":O,Y=[...V.map(P=>{var fe,F,xe,Ie,ge;return{id:`ide:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.type,kind:"ide",providerType:P.type,subtitle:P.workspace||void 0,workspace:P.workspace||void 0,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}}),...R.map(P=>{var fe,F,xe,Ie,ge;return{id:`cli:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.cliName,kind:"cli",providerType:P.type,providerSessionId:P.providerSessionId,subtitle:P.workspace||void 0,workspace:P.workspace||void 0,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}}),...w.map(P=>{var fe,F,xe,Ie,ge;return{id:`acp:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.acpName,kind:"acp",providerType:P.type,providerSessionId:P.providerSessionId,subtitle:P.currentModel||P.workspace||void 0,workspace:P.workspace||void 0,currentModel:P.currentModel,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}})].sort((P,fe)=>fe.timestamp-P.timestamp).map(({timestamp:P,...fe})=>fe),ne=((x==null?void 0:x.recentLaunches)||[]).length>0?((x==null?void 0:x.recentLaunches)||[]).map(P=>({id:P.id,label:P.title||P.providerName||P.providerType,kind:P.kind,providerType:P.providerType,providerSessionId:P.providerSessionId,subtitle:P.currentModel||P.workspace||void 0,workspace:P.workspace,currentModel:P.currentModel})):Y,_=a.useMemo(()=>{var fe;const P=((fe=c.connectionStates)==null?void 0:fe[s||""])||void 0;return l.filter(F=>F.daemonId===s&&F.type!=="adhdev-daemon").flatMap(F=>yn(F,{},{connectionStates:s&&P?{[s]:P}:void 0,defaultConnectionState:P})).filter(F=>!(F.transport==="pty"&&F.mode==="terminal")).sort((F,xe)=>sn(xe)-sn(F))},[l,c.connectionStates,s]),pe=a.useCallback(P=>{const fe=P.sessionId||P.tabKey;fe&&r(`/dashboard?activeTab=${encodeURIComponent(fe)}`)},[r]),me=a.useCallback(()=>{u.current&&(f(!0),u.current().finally(()=>{u.current=null,f(!1),y(null)}))},[]),J=a.useCallback(P=>{if(!T)return;const{options:fe,selectedKey:F}=Zt({machine:T,currentWorkspacePath:P.workspace}),xe=async()=>{I(P.kind),g("workspace")};u.current=async()=>{const Ie=fe.find(Ke=>Ke.key===d.current),ge=(Ie==null?void 0:Ie.workspacePath)??null,Ee=(Ie==null?void 0:Ie.workspaceId)??null;if(P.kind==="ide"&&P.providerType){await k.handleLaunchIde(P.providerType,ge?{workspace:ge}:void 0);return}if((P.kind==="cli"||P.kind==="acp")&&P.providerType){await k.runLaunchCliCore({cliType:P.providerType,dir:Ee?void 0:ge||"",workspaceId:Ee||void 0,model:P.kind==="acp"?P.currentModel:void 0,resumeSessionId:P.providerSessionId});return}await xe()},d.current=F,M(F),y({title:`Launch ${P.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:fe,details:[{label:"Mode",value:P.kind.toUpperCase()},...P.providerType?[{label:"Provider",value:P.providerType}]:[]]})},[k,T]);if(a.useEffect(()=>{g(re)},[ee,re,s]),a.useEffect(()=>{je&&I(je)},[je,s]),!T)return p?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:v,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const ie=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:14})," Workspace"]}),count:V.length+R.length+w.length},{id:"session-host",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Session Host"]})},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fr,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Zi,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Yi,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:v,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[k.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:k.nicknameInput,onChange:P=>k.setNicknameInput(P.target.value),onKeyDown:P=>{P.key==="Enter"&&k.handleSaveNickname(),P.key==="Escape"&&k.setEditingNickname(!1)},placeholder:"Machine nickname...",className:"px-2.5 py-1 rounded-md border border-violet-500/30 bg-bg-secondary text-text-primary text-sm font-semibold w-[140px] md:w-[200px]"}),e.jsx("button",{onClick:k.handleSaveNickname,className:"flex items-center justify-center px-3 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 text-sm font-medium transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>k.setEditingNickname(!1),className:"flex items-center justify-center px-3 py-1 rounded bg-[#ffffff0a] text-text-muted hover:bg-[#ffffff14] hover:text-text-primary text-sm font-medium transition-colors",children:"Cancel"})]}):e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-text-primary cursor-pointer truncate hover:text-accent-primary transition-colors",onClick:()=>{k.setEditingNickname(!0),k.setNicknameInput(T.machineNickname||"")},title:"Click to set nickname",children:B}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)] shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 items-center mt-1.5 text-xs text-text-secondary opacity-80",children:[e.jsxs("span",{className:"font-mono bg-[#ffffff08] px-1.5 py-0.5 rounded",children:[T.platform," · ",T.arch]}),e.jsxs("span",{children:[T.cpus," cores"]}),(x==null?void 0:x.version)&&e.jsxs("span",{children:["v",x.version]}),T.p2p.available&&e.jsxs("span",{children:["P2P ",T.p2p.state==="connected"?"connected":T.p2p.state]}),T.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:T.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:ie.map(P=>e.jsxs("button",{onClick:()=>g(P.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${h===P.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[P.label,P.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${h===P.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:P.count})]},P.id))})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 md:px-8 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto h-full",children:e.jsxs("div",{className:"h-full",children:[h==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Lp,{machineEntry:x,providers:$,recentLaunches:ne,currentConversations:_,onUpgradeDaemon:async()=>{try{await o(s,"daemon_upgrade",{})}catch{}},onOpenRecent:J,onOpenConversation:pe}),e.jsx($p,{machine:T,machineId:s,providers:$,ideSessions:V,cliSessions:R,acpSessions:w,actions:k,getIcon:W,initialCategory:S,initialWorkspaceId:z,initialWorkspacePath:Q,sendDaemonCommand:o})]}),h==="providers"&&e.jsx(Sp,{machineId:s,providers:$,sendDaemonCommand:o}),h==="overview"&&e.jsx(yp,{machineId:s,machine:T,ideSessions:V,cliSessions:R,acpSessions:w,actions:k,sendDaemonCommand:o}),h==="session-host"&&e.jsx(_p,{machineId:s,cliSessions:R,sendDaemonCommand:o}),h==="logs"&&e.jsx(Cp,{machineId:s,sendDaemonCommand:o})]})})}),k.launchPick&&T&&e.jsx(Pp,{machine:T,launchPick:k.launchPick,actions:k}),b&&e.jsx(Cn,{title:b.title,description:b.description,details:b.details,workspaceOptions:b.workspaceOptions,selectedWorkspaceKey:C,onWorkspaceChange:P=>{d.current=P,M(P)},confirmLabel:b.confirmLabel,busy:N,onConfirm:me,onCancel:()=>{u.current=null,y(null)}}),e.jsx(go,{toasts:c.toasts||[],onDismiss:P=>c.setToasts(fe=>fe.filter(F=>F.id!==P)),onClickToast:P=>{P.targetKey&&r(`/dashboard?activeTab=${encodeURIComponent(P.targetKey)}`)}}),e.jsx("style",{children:`
|
|
64
|
+
The newest runtime for each provider session will be kept and older duplicates will be stopped and removed.`)){c("session_host_prune_duplicate_sessions");try{const j=await r(t,"session_host_prune_duplicate_sessions",{}),v=Hr(j);if(!(v!=null&&v.success))throw new Error((v==null?void 0:v.error)||"Duplicate prune failed");const k=v.result||{},$=Array.isArray(k.prunedSessionIds)?k.prunedSessionIds.length:0,E=typeof k.duplicateGroupCount=="number"?k.duplicateGroupCount:0;gt.showToast(`Pruned ${$} duplicate runtime(s) across ${E} group(s)`,"success"),await I()}catch(j){const v=j instanceof Error?j.message:"Duplicate prune failed";gt.showToast(v,"warning"),o(v)}finally{c(j=>j==="session_host_prune_duplicate_sessions"?null:j)}}},[t,I,r]),y=a.useMemo(()=>[...(m==null?void 0:m.sessions)||[]].sort((f,j)=>(j.lastActivityAt||0)-(f.lastActivityAt||0)),[m==null?void 0:m.sessions]),d=a.useMemo(()=>Tp(y),[y]),C=a.useMemo(()=>y.reduce((f,j)=>{var v;return f+(((v=j.attachedClients)==null?void 0:v.length)||0)},0),[y]),M=a.useMemo(()=>[...(m==null?void 0:m.recentTransitions)||[]].slice(-6).reverse(),[m==null?void 0:m.recentTransitions]),N=a.useMemo(()=>[...(m==null?void 0:m.recentLogs)||[]].reverse().find(f=>f.level==="warn"||f.level==="error")||null,[m==null?void 0:m.recentLogs]);return e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Session Host"]}),e.jsx("div",{className:"text-[12px] text-text-secondary mt-1",children:"Hosted CLI runtime diagnostics and recovery controls."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d>0&&e.jsx("button",{type:"button",className:"machine-btn",onClick:()=>{b()},disabled:i==="session_host_prune_duplicate_sessions",children:i==="session_host_prune_duplicate_sessions"?"Pruning…":`Prune duplicates (${d})`}),e.jsx("span",{className:`px-2 py-1 rounded-md text-[10px] font-semibold ${m?"bg-green-500/[0.08] text-green-500":"bg-amber-500/[0.08] text-amber-400"}`,children:m?"Managed":"Unavailable"}),e.jsxs("button",{type:"button",className:"machine-btn flex items-center gap-1",onClick:()=>{I()},disabled:h||l,children:[e.jsx(fs,{size:13}),h||l?"Refreshing…":"Refresh"]})]})]}),n&&!m&&e.jsx("div",{className:"rounded-xl border border-amber-500/[0.22] bg-amber-500/[0.08] px-3.5 py-3 text-[12px] text-amber-200 mb-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(es,{size:14,className:"mt-0.5 text-amber-300 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-amber-100",children:"Session host diagnostics unavailable"}),e.jsx("div",{className:"text-amber-200/90 mt-1",children:n})]})]})}),m&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Runtimes"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:m.runtimeCount})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Clients"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:C})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Requests"}),e.jsx("div",{className:"text-[18px] font-semibold text-text-primary mt-1",children:m.recentRequests.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-text-secondary",children:"Started"}),e.jsx("div",{className:"text-[12px] font-medium text-text-primary mt-1",children:La(m.hostStartedAt)}),e.jsx("div",{className:"text-[10px] text-text-secondary mt-0.5",children:Ur(m.hostStartedAt)})]})]}),N&&e.jsxs("div",{className:"rounded-xl border border-amber-500/[0.16] bg-amber-500/[0.07] px-3.5 py-3 text-[11px] text-text-secondary mb-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-amber-200 font-medium mb-1",children:[e.jsx(es,{size:13})," Latest host warning"]}),e.jsx("div",{className:"text-text-primary leading-relaxed",children:N.message}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-1",children:[Ur(N.timestamp),N.sessionId?` · ${N.sessionId}`:""]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-2.5",children:[e.jsx(xr,{size:14})," Hosted Runtimes"]}),y.length===0?e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-4 text-[12px] text-text-secondary",children:"No hosted runtimes on this machine yet."}):e.jsx("div",{className:"space-y-2",children:y.map(f=>{var T;const j=i===`session_host_resume_session:${f.sessionId}`,v=i===`session_host_restart_session:${f.sessionId}`,k=i===`session_host_stop_session:${f.sessionId}`,$=Mp(f.meta),E=S.get(f.sessionId),W=f.attachedClients.length===1?"1 client":`${f.attachedClients.length} clients`;return e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("div",{className:"font-medium text-[13px] text-text-primary",children:f.displayName||(E==null?void 0:E.cliName)||f.providerType}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Ap(f.lifecycle)}`,children:f.lifecycle}),$&&e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold bg-sky-500/[0.08] text-sky-300",children:$})]}),e.jsxs("div",{className:"text-[11px] text-text-secondary mt-1 flex flex-wrap gap-2",children:[e.jsx("span",{className:"text-text-primary/90",children:f.workspaceLabel||(E==null?void 0:E.runtimeWorkspaceLabel)||f.workspace||"No workspace"}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsx("span",{className:"font-mono text-text-primary",children:f.runtimeKey}),f.osPid?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"text-text-primary/90",children:["pid ",f.osPid]})]}):null]}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-1 flex flex-wrap gap-2",children:[e.jsx("span",{className:((T=f.writeOwner)==null?void 0:T.ownerType)==="user"?"text-amber-200":"text-text-primary/85",children:Ip(f.writeOwner)}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 text-text-primary/85",children:[e.jsx(ln,{size:11})," ",W]}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsxs("span",{className:"text-text-primary/85",children:["active ",La(f.lastActivityAt)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[(f.lifecycle==="interrupted"||f.lifecycle==="failed"||f.lifecycle==="stopped")&&e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1",disabled:!!i,onClick:()=>{u("session_host_resume_session",f)},children:j?"Resuming…":"Resume"}),e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1",disabled:!!i,onClick:()=>{u("session_host_restart_session",f)},children:v?"Restarting…":"Restart"}),(f.lifecycle==="running"||f.lifecycle==="starting"||f.lifecycle==="interrupted")&&e.jsx("button",{type:"button",className:"machine-btn text-[10px] px-2 py-1 border-red-500/20 text-red-300 hover:text-red-200",disabled:!!i,onClick:()=>{u("session_host_stop_session",f)},children:k?"Stopping…":"Stop"})]})]})},f.sessionId)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-text-secondary font-semibold uppercase tracking-wider mb-2.5",children:"Recent Host Activity"}),M.length===0?e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3 text-[12px] text-text-secondary",children:"No recent runtime transitions yet."}):e.jsx("div",{className:"rounded-xl border border-border-subtle bg-bg-primary divide-y divide-border-subtle",children:M.map(f=>{var v;const j=y.find(k=>k.sessionId===f.sessionId);return e.jsxs("div",{className:"px-3.5 py-2.5 text-[11px] flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-text-primary font-medium",children:(j==null?void 0:j.displayName)||((v=S.get(f.sessionId))==null?void 0:v.cliName)||f.sessionId}),e.jsxs("div",{className:"text-text-secondary mt-0.5 leading-relaxed",children:[f.action,f.lifecycle?` · ${f.lifecycle}`:"",f.detail?` · ${f.detail}`:"",f.error?` · ${f.error}`:""]})]}),e.jsx("div",{className:`shrink-0 text-[10px] ${f.success===!1?"text-red-300":"text-text-secondary"}`,children:Ur(f.timestamp)})]},`${f.sessionId}:${f.timestamp}:${f.action}`)})})]}),e.jsxs("div",{className:"text-[10px] text-text-secondary mt-3",children:["Endpoint: ",e.jsx("span",{className:"font-mono text-text-primary",children:m.endpoint||"unknown"}),n?e.jsxs("span",{className:"text-amber-200",children:[" · last error: ",n]}):null]})]})]})}function Pp({machine:t,launchPick:s,actions:r}){const{runLaunchCliCore:n,setLaunchPick:o}=r;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(i=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{o(null),n({cliType:s.cliType,workspaceId:i.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:i.label||i.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:i.path})]},i.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{o(null),n({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{o(null),n({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>o(null),children:"Cancel"})]})]})})}function zr({icon:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold text-text-muted tracking-[0.14em] uppercase",children:[t,e.jsx("span",{children:s})]})}function Fr({children:t,className:s=""}){return e.jsx("div",{className:`rounded-2xl border border-[#ffffff0a] bg-bg-surface/70 backdrop-blur-sm p-3 ${s}`,children:t})}function Lp({machineEntry:t,providers:s,recentLaunches:r,currentConversations:n,onUpgradeDaemon:o,onOpenRecent:i,onOpenConversation:c}){const l=n.slice(0,6),p=r.slice(0,4),m=Cs(t,"0.8.45"),h=g=>g==="ide"?"IDE":g==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-4 md:min-w-[300px] md:max-w-[360px] shrink-0 md:h-full overflow-y-auto",children:[l.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(Bt,{size:13}),children:"Current Chats"}),e.jsx(Fr,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:l.map(g=>{const S=sn(g);return e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>c(g),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate group-hover:text-accent-primary transition-colors",children:Qe(g)}),S>0&&e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:eo(S)})]}),e.jsx("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:rs(g)})]},g.tabKey)})})})]}),p.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(Ya,{size:13}),children:"Recent Launches"}),e.jsx(Fr,{children:e.jsx("div",{className:"flex flex-col gap-1.5",children:p.map(g=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-[#ffffff08] border border-transparent hover:border-[#ffffff12] hover:bg-[#ffffff0c] transition-colors cursor-pointer group",onClick:()=>i(g),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:g.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[h(g.kind),g.subtitle?` · ${g.subtitle}`:""]})]},g.id))})})]}),t.versionMismatch&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(zr,{icon:e.jsx(es,{size:13}),children:"Daemon Update"}),e.jsx(Fr,{className:"border-amber-500/20 bg-amber-500/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:m?"Daemon update required":"Version mismatch detected"}),e.jsx("div",{className:"text-xs text-text-secondary leading-relaxed",children:m?"This machine is on an incompatible daemon version. Update it before starting more sessions.":"This machine is running a different daemon version than the current app. Update it before starting more sessions."}),e.jsxs("button",{type:"button",className:"inline-flex items-center justify-center gap-2 px-3 py-2 rounded-xl bg-amber-500/12 border border-amber-500/20 text-amber-300 hover:bg-amber-500/18 transition-colors",onClick:o,children:[e.jsx(fs,{size:13}),e.jsx("span",{className:"text-sm font-medium",children:"Update daemon"})]})]})})]})]})}function Rp(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Ep={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function Qs(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Dp(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function Vr({category:t,machine:s,machineId:r,providers:n,managedEntries:o,getIcon:i,actions:c,sendDaemonCommand:l,initialWorkspaceId:p,initialWorkspacePath:x}){const m=ms(),{handleLaunchIde:h,handleStopCli:g,handleRestartIde:S,handleStopIde:I,handleDetectIdes:u,launchingIde:b,launchingAgentType:y,addLog:d}=c,[C,M]=a.useState(null),N=a.useCallback(A=>{A&&m({pathname:"/",search:`?activeTab=${encodeURIComponent(A)}`})},[m]),f=Ep[t],j=t==="ide",v=t==="acp",k=a.useMemo(()=>n.filter(A=>A.category===t&&(t==="ide"||A.installed!==!1)),[t,n]),$=a.useMemo(()=>new Map(k.map(A=>[A.type,A.displayName||A.type])),[k]),[E,W]=a.useState(""),[T,V]=a.useState(""),[R,w]=a.useState([]),[B,ee]=a.useState(""),[L,D]=a.useState(""),[O,z]=a.useState([]),[Q,re]=a.useState(!1),[je,Y]=a.useState(""),[ne,_]=a.useState(!1),[pe,me]=a.useState(null),[J,ie]=a.useState(x?"__custom__":p||s.defaultWorkspaceId||""),[se,he]=a.useState(x||""),[ce,be]=a.useState([]),[Z,oe]=a.useState(!1),[ae,ke]=a.useState(""),[we,P]=a.useState([]),[fe,F]=a.useState(!1),[xe,Ie]=a.useState(""),ge=a.useRef(null),[Ee,Ke]=a.useState(null),He=a.useRef("__home__"),[ct,Fe]=a.useState("__home__"),[rt,ft]=a.useState(!1),Je=a.useRef(0),et=ce.filter(A=>!o.some(U=>U.type===A&&bt(U.status)!=="stopped")),pt=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!J&&ie(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(x){ie("__custom__"),he(x);return}p&&(ie(p),he(""))},[p,x]),a.useEffect(()=>{j||E&&(k.some(A=>A.type===E)||(W(""),D("")))},[k,j,E]);const Ue=(()=>{if(J==="__custom__")return se.trim();if(!J)return"";const A=(s.workspaces||[]).find(U=>U.id===J);return(A==null?void 0:A.path)||""})(),tt=a.useCallback(A=>{const U=pt.current[A];U&&(clearTimeout(U),delete pt.current[A]),be(de=>de.includes(A)?de.filter(ye=>ye!==A):de)},[]),lt=a.useRef(new Set),mt=a.useCallback(async A=>{if(l){F(!0),Ie("");try{const U=await wr(l,r,A);ke(U.path),he(U.path),P(U.directories)}catch(U){Ie(U instanceof Error?U.message:"Could not load folder")}finally{F(!1)}}},[r,l]),q=a.useCallback(()=>{var U;if(!l)return;ie("__custom__"),oe(!0);const A=vr(s.platform,[se.trim(),Ue,s.defaultWorkspacePath,(U=s.workspaces[0])==null?void 0:U.path]);mt(A)},[se,mt,s.defaultWorkspacePath,s.platform,s.workspaces,Ue,l]),_e=a.useCallback(A=>{const U=String(A.workspace||"").trim();if(!U)return;const de=(s.workspaces||[]).find(ye=>Qs(ye.path)===Qs(U));if(de){ie(de.id),he("");return}ie("__custom__"),he(U)},[s.workspaces]),Le=a.useCallback(A=>{const U=String(A.workspace||"").trim();if(!U)return{workspaceId:null,workspacePath:"",useHome:!0};const de=(s.workspaces||[]).find(ye=>Qs(ye.path)===Qs(U));return de?{workspaceId:de.id,workspacePath:"",useHome:!1}:{workspaceId:null,workspacePath:U,useHome:!1}},[s.workspaces]),Oe=a.useCallback(async A=>{if(!l||!A||t!=="cli"){z([]),re(!1),Y("");return}const U=Je.current+1;Je.current=U,re(!0),Y("");try{const de=await l(r,"list_saved_sessions",{providerType:A,kind:"cli",limit:30});if(Je.current!==U)return;const ye=(de==null?void 0:de.result)??de;z(Array.isArray(ye==null?void 0:ye.sessions)?ye.sessions:[])}catch(de){if(Je.current!==U)return;z([]),Y(de instanceof Error?de.message:"Could not load saved sessions")}finally{Je.current===U&&re(!1)}},[t,r,l]),dt=a.useMemo(()=>{if(t!=="cli"||!E)return null;const A=$.get(E)||E;return{routeId:r,daemonId:r,providerSessionId:L||void 0,transport:"pty",mode:"chat",agentName:A,agentType:E,status:"idle",title:A,messages:[],ideType:E,workspaceName:Ue,displayPrimary:A,displaySecondary:"CLI",streamSource:"native",tabKey:`machine:${r}:resume-history:${E}`}},[t,r,$,Ue,L,E]),Ct=a.useCallback(A=>{if(t==="ide"||!A){w([]);return}w(ri(r,A))},[t,r]);a.useEffect(()=>{if(D(""),Ct(E),t!=="cli"||!E){z([]),Y(""),re(!1);return}Oe(E)},[t,Ct,Oe,E]),a.useEffect(()=>{if(!L)return;const A=O.find(U=>U.providerSessionId===L);A!=null&&A.canResume||D("")},[O,L]);const yt=a.useCallback((A,U)=>{ge.current=U,He.current=A.selectedWorkspaceKey||"__home__",Fe(A.selectedWorkspaceKey||"__home__"),Ke(A)},[]),K=a.useCallback(()=>{ge.current&&(ft(!0),ge.current().finally(()=>{ge.current=null,ft(!1),Ke(null)}))},[]),H=a.useCallback(A=>{if(!A)return;be(de=>de.includes(A)?de:[...de,A]);const U=pt.current[A];U&&clearTimeout(U),pt.current[A]=setTimeout(()=>{be(de=>de.includes(A)?de.filter(ye=>ye!==A):de),delete pt.current[A]},2e4)},[]);a.useEffect(()=>{for(const U of o)bt(U.status)!=="stopped"&&(ce.includes(U.type)&&!lt.current.has(U.type)&&(lt.current.add(U.type),d("info",`${$.get(U.type)||U.type} launched`,!0)),tt(U.type));const A=new Set(o.filter(U=>bt(U.status)!=="stopped").map(U=>U.type));lt.current.forEach(U=>{!ce.includes(U)&&!A.has(U)&<.current.delete(U)})},[d,tt,o,ce,$]),a.useEffect(()=>()=>{Object.values(pt.current).forEach(clearTimeout),pt.current={}},[]);const[G,X]=a.useState({}),[le,ue]=a.useState(null);a.useEffect(()=>{if(!j||!r||!l)return;(async()=>{try{const U=await l(r,"get_ide_extensions",{}),de=(U==null?void 0:U.result)||U;de!=null&&de.success&&(de!=null&&de.ideExtensions)&&X(de.ideExtensions)}catch{}})()},[j,r,l]);const Re=A=>j?Ze(A.type):t==="cli"?A.cliName:A.acpName,Pe=j?s.detectedIdes||[]:[],te=a.useCallback(async A=>{const U=(A==null?void 0:A.type)||E,de=(A==null?void 0:A.workspacePath)??Ue;if(j){await h(U,de?{workspace:de}:void 0)&&H(U);return}const ye=await c.runLaunchCliCore({cliType:U,dir:A!=null&&A.workspaceId?void 0:de||void 0,workspaceId:(A==null?void 0:A.workspaceId)||void 0,useHome:(A==null?void 0:A.useHome)||!(A!=null&&A.workspaceId)&&!de,argsStr:(A==null?void 0:A.argsStr)??(T||void 0),model:(A==null?void 0:A.model)??(v&&B||void 0),resumeSessionId:(A==null?void 0:A.resumeSessionId)||!v&&t==="cli"&&U===E&&L||void 0});if(ye.success||ye.pending){const Ae=(A==null?void 0:A.argsStr)??T;!j&&(Ae!=null&&Ae.trim())&&(ni(r,U,Ae),Ct(U)),H(U),ye.success&&ye.sessionId&&N(ye.sessionId)}},[c,h,v,j,T,B,Ct,H,r,N,Ue,L,E]),Ne=()=>{var ye;const A=j?Ze(E):$.get(E)||E,{options:U,selectedKey:de}=Zt({machine:s,currentWorkspaceId:J&&J!=="__custom__"?J:null,currentWorkspacePath:Ue});yt({title:`Launch ${A}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:U,selectedWorkspaceKey:de,details:[{label:"Mode",value:f.label},{label:"Provider",value:A},...!j&&t==="cli"&&L?[{label:"Resume",value:((ye=O.find(Ae=>Ae.providerSessionId===L))==null?void 0:ye.title)||L}]:[],...!j&&T.trim()?[{label:"Arguments",value:T.trim()}]:[],...v&&B.trim()?[{label:"Model",value:B.trim()}]:[]]},async()=>{const Ae=U.find(Te=>Te.key===He.current);Ae!=null&&Ae.workspaceId?(ie(Ae.workspaceId),he("")):Ae!=null&&Ae.workspacePath?(ie("__custom__"),he(Ae.workspacePath)):(ie(""),he("")),await te({workspaceId:(Ae==null?void 0:Ae.workspaceId)??null,workspacePath:(Ae==null?void 0:Ae.workspacePath)??"",useHome:!(Ae!=null&&Ae.workspaceId)&&!(Ae!=null&&Ae.workspacePath)})})},ze=A=>{j?I(A):g(A.type,A.workspace,A.id)},Ve=a.useCallback(async(A,U,de=!1)=>{if(A.mode===U){de&&A.sessionId&&N(A.sessionId);return}if(!l||!A.sessionId){de&&A.sessionId&&N(A.sessionId);return}try{await l(r,"set_cli_view_mode",{targetSessionId:A.sessionId,cliType:A.type,mode:U}),de&&N(A.sessionId)}catch(ye){Dp(ye)?console.warn("Skipped CLI view mode switch:",ye instanceof Error?ye.message:String(ye)):console.error("Failed to switch CLI view mode:",ye)}},[r,N,l]),Ye=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:J,onChange:A=>{const U=A.target.value;if(ie(U),U==="__custom__"&&l){q();return}U!=="__custom__"&&he("")},className:"px-3 py-1.5 rounded-md min-w-[200px] flex-1 text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(A=>e.jsxs("option",{value:A.id,children:[A.id===s.defaultWorkspaceId?"⭐ ":"",br(A.path,A.label)]},A.id)),e.jsx("option",{value:"__custom__",children:l?"📁 Select workspace…":"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:l?"📁 Select workspace…":"✏️ Custom path…"})]})}),J==="__custom__"&&(l?e.jsx("button",{type:"button",className:"px-3 py-1.5 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] hover:border-accent-primary text-text-secondary hover:text-text-primary transition-colors",onClick:q,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:se,onChange:A=>he(A.target.value),className:"px-3 py-1.5 rounded-md flex-1 min-w-[200px] text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",autoFocus:!0}))]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:J==="__custom__"?Ue?e.jsx("span",{className:"font-mono truncate block",title:Ue,children:Ue}):l?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":Ue?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:J===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:Ue,children:Ue})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-5 rounded-xl mb-6 bg-bg-secondary border ${f.accent} relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 left-0 w-full height-[1px] bg-gradient-to-r from-transparent via-[#ffffff20] to-transparent"}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-primary/60"}),"Select ",f.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:j?Pe.length>0?Pe.map(A=>{const U=o.find(We=>(We.type||"").toLowerCase()===(A.type||"").toLowerCase()&&bt(We.status)!=="stopped"),de=A.running||!!U,ye=!!U&&U.cdpConnected,Ae=ce.includes(A.type||A.id||""),Te=E===(A.type||"");return e.jsxs("button",{onClick:()=>{if(ye&&U){const We=U.sessionId;We?m(`/dashboard?activeTab=${encodeURIComponent(We)}`,{state:{openRemoteForTabKey:We}}):m("/dashboard",{state:{openRemoteForTabKey:U.id}});return}Ae||W(We=>We===(A.type||"")?"":A.type||"")},disabled:!!b||Ae,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${ye?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":Te?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,style:{opacity:b&&b!==A.type?.4:1},children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:i(A.type)}),de&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${ye?"bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]":"bg-orange-500 shadow-[0_0_6px_rgba(249,115,22,0.6)] animate-pulse"}`})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.name||Ze(A.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ye?"text-green-400":Ae?"text-orange-400":Te?"text-accent-primary":"text-text-muted"}`,children:ye?"Open Session":Ae?"Starting...":Te?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 flex flex-col items-center justify-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted italic gap-2",children:["No IDEs detected.",e.jsxs("button",{onClick:u,className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded-lg flex items-center gap-1.5",children:[e.jsx(Ji,{size:14})," Scan System"]})]}):k.length>0?k.map(A=>{const U=E===A.type,de=ce.includes(A.type),Ae=!!o.find(Te=>Te.type===A.type&&bt(Te.status)!=="stopped");return e.jsxs("button",{onClick:()=>W(Te=>Te===A.type?"":A.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${U?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:A.icon}),Ae&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${de?"text-orange-400":U?"text-accent-primary":"text-text-muted"}`,children:de?"Starting...":U?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 text-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted",children:["No usable ",t.toUpperCase()," providers available.",e.jsx("div",{className:"mt-1 text-[11px] text-text-muted",children:"Set a custom executable path in Providers if the binary is installed outside the default location."})]})}),E&&(j?Pe.find(A=>A.type===E):k.find(A=>A.type===E))&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-[#ffffff1a] flex flex-col gap-4 animate-in slide-in-from-top-2 fade-in duration-200",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center justify-between",children:[e.jsx("span",{children:"Launch Settings"}),e.jsx("span",{className:"text-accent-primary font-bold",children:j?Ze(E):$.get(E)||E})]}),Ye,!j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[!v&&t==="cli"&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Resume from History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void Oe(E),disabled:!E||Q,children:Q?"Loading…":"Refresh"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:()=>{E&&(_(!0),Oe(E))},disabled:!E,children:"Open History"})]})]}),L?(()=>{const A=O.find(U=>U.providerSessionId===L);return A?e.jsx("div",{className:"rounded-md border border-[#ffffff1a] bg-bg-primary px-3 py-2 text-[10px] text-text-muted leading-relaxed",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-text-primary text-[11px] font-semibold truncate",children:A.title||A.providerSessionId}),e.jsx("div",{className:"font-mono break-all",children:A.providerSessionId}),e.jsx("div",{children:A.workspace||"Workspace unknown"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm shrink-0",onClick:()=>D(""),children:"Clear"})]})}):null})():e.jsx("div",{className:"text-[10px] text-text-muted",children:"Start a new CLI session, or choose one from history."}),je&&e.jsx("div",{className:"text-[10px] text-red-400",children:je})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[v&&e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Target Model"}),e.jsx("input",{type:"text",placeholder:"Leave empty for default",value:B,onChange:A=>ee(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Startup Arguments"}),e.jsx("input",{type:"text",placeholder:"Optional flags...",value:T,onChange:A=>V(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"}),R.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:R.map(A=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>V(A),title:A,children:A},A))})]})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:Ne,disabled:!!y||!!b||ce.includes(E),className:"btn btn-primary h-9 px-6 font-bold transition-all flex items-center gap-2 hover:shadow-glow hover:-translate-y-px",children:y===E||b===E?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",o.length+ce.filter(A=>!o.some(U=>U.type===A&&bt(U.status)!=="stopped")).length,")"]}),o.length===0&&et.length===0?e.jsxs("div",{className:"py-7.5 px-5 text-center rounded-xl bg-bg-secondary border border-dashed border-border-subtle text-text-muted text-[13px] mb-5",children:["No ",f.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[et.map(A=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:i(A)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:j?Ze(A):$.get(A)||A}),e.jsx("div",{className:"text-[11px] text-text-muted",children:y===A?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${A}`)),o.map(A=>{const U=j?A:null,de=v?A:null,ye=!j&&!v?A:null,Ae=bt(A.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:i(A.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[Re(A),(U==null?void 0:U.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",U.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:A.workspace||"—"}),(de==null?void 0:de.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",de.currentModel]}),(de==null?void 0:de.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",de.currentPlan]}),(ye==null?void 0:ye.mode)&&e.jsx("span",{className:ye.mode==="chat"?"text-violet-400":"text-text-secondary",children:ye.mode==="chat"?"Chat view":"Terminal view"})]}),ye&&(ye.runtimeKey||ye.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ye.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",ye.runtimeKey]}),e.jsx("button",{type:"button",className:"flex items-center justify-center px-1.5 py-0.5 rounded text-[9px] bg-[#ffffff0a] hover:bg-[#ffffff14] border border-[#ffffff0a] text-text-muted hover:text-text-primary transition-colors cursor-pointer",onClick:()=>{var Te;(Te=navigator.clipboard)==null||Te.writeText(`adhdev attach ${ye.runtimeKey}`),M(ye.runtimeKey||null),window.setTimeout(()=>{M(We=>We===ye.runtimeKey?null:We)},1200)},children:C===ye.runtimeKey?"Copied":"Copy"})]}),ye.runtimeWriteOwner&&e.jsx("span",{style:{color:ye.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ye.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Rp(ye.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Ae==="stopped"?"bg-red-500/[0.08] text-red-500":Ae==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Ae}),j&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const Te=A.sessionId;if(Te){m(`/dashboard?activeTab=${encodeURIComponent(Te)}`,{state:{openRemoteForTabKey:Te}});return}m("/dashboard",{state:{openRemoteForTabKey:A.id}})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-primary transition-colors cursor-pointer",title:"Open remote control",children:e.jsx(Nt,{size:13})}),e.jsx("button",{onClick:()=>{const Te=A.workspace||"",{options:We,selectedKey:ot}=Zt({machine:s,currentWorkspacePath:Te});yt({title:`Restart ${Ze(A.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:We,selectedWorkspaceKey:ot,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Ze(A.type)}]},async()=>{const De=We.find(Kt=>Kt.key===He.current),st=(De==null?void 0:De.workspacePath)??"";if(st&&st!==Te){await te({type:A.type,workspacePath:st});return}await S(A)})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-orange-500/20 text-orange-400 transition-colors cursor-pointer",title:"Restart",children:e.jsx(fs,{size:14})})]}),v&&e.jsx("button",{onClick:()=>{const Te=A.sessionId;Te&&N(Te)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"View chat",disabled:!A.sessionId,children:e.jsx(Bt,{size:14})}),ye&&Ae!=="stopped"&&e.jsxs(e.Fragment,{children:[ye.mode&&e.jsx(bn,{mode:ye.mode,onChange:Te=>void Ve(ye,Te,!1),compact:!0}),e.jsx("button",{onClick:()=>{const Te=A.sessionId;Te&&N(Te)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"Open current view in dashboard",disabled:!A.sessionId,children:ye.mode==="chat"?e.jsx(Bt,{size:14}):e.jsx(Nt,{size:13})})]}),Ae==="stopped"?e.jsx("button",{onClick:()=>{const Te=A.workspace||"",We=j?Ze(A.type):Re(A),{options:ot,selectedKey:De}=Zt({machine:s,currentWorkspacePath:Te});yt({title:`Launch ${We}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:ot,selectedWorkspaceKey:De,details:[{label:"Mode",value:f.label},{label:"Provider",value:We}]},async()=>{const st=ot.find(Kt=>Kt.key===He.current);await te({type:A.type,workspaceId:(st==null?void 0:st.workspaceId)??null,workspacePath:(st==null?void 0:st.workspacePath)??"",useHome:!(st!=null&&st.workspaceId)&&!(st!=null&&st.workspacePath),model:de==null?void 0:de.currentModel})})},disabled:ce.includes(A.type),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-green-500/20 text-green-400 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Restart",children:ce.includes(A.type)?"⏳":e.jsx(un,{size:14})}):e.jsx("button",{onClick:()=>ze(A),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-red-500/20 text-red-400 transition-colors cursor-pointer",title:"Stop",children:e.jsx(wt,{size:14})})]})]}),U&&U.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:U.aiAgents.map(Te=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${ro(Te.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[Te.name," · ",bt(Te.status)]},Te.id))}),U&&(G[U.type]||[]).length>0&&l&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(G[U.type]||[]).map(Te=>e.jsxs("button",{disabled:le===`${U.type}.${Te.type}`,onClick:async()=>{const We=`${U.type}.${Te.type}`;ue(We);try{await l(r,"set_ide_extension",{ideType:U.type,extensionType:Te.type,enabled:!Te.enabled}),X(ot=>({...ot,[U.type]:(ot[U.type]||[]).map(De=>De.type===Te.type?{...De,enabled:!De.enabled}:De)}))}catch(ot){console.error("Extension toggle failed:",ot)}finally{ue(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${Te.enabled?"bg-accent-primary/10 border-accent-primary/20 text-accent-primary-light":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Te.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),Te.name,e.jsx("span",{className:"text-[9px] font-normal",children:Te.enabled?"ON":"OFF"})]},Te.type))})]})]},A.id)})]}),Z&&l&&e.jsx(jr,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:ae,directories:we,busy:fe,error:xe,confirmLabel:"Use this folder",onClose:()=>oe(!1),onNavigate:A=>{mt(A)},onConfirm:A=>{he(A),ie("__custom__"),oe(!1)}}),Ee&&e.jsx(Cn,{title:Ee.title,description:Ee.description,details:Ee.details,workspaceOptions:Ee.workspaceOptions,selectedWorkspaceKey:ct,onWorkspaceChange:A=>{He.current=A,Fe(A)},confirmLabel:Ee.confirmLabel,busy:rt,onConfirm:K,onCancel:()=>{ge.current=null,Ke(null)}}),ne&&dt&&e.jsx(gn,{activeConv:dt,ides:[],isCreatingChat:!1,isRefreshingHistory:Q,savedSessions:O,isSavedSessionsLoading:Q,isResumingSavedSessionId:pe,onClose:()=>_(!1),onNewChat:()=>{D(""),_(!1)},onSwitchSession:()=>{},onRefreshHistory:()=>{Oe(E)},onResumeSavedSession:A=>{if(!A.canResume||pe)return;const U=Le(A);D(A.providerSessionId),_e(A),me(A.providerSessionId),_(!1),te({type:A.providerType,workspaceId:U.workspaceId,workspacePath:U.workspacePath,useHome:U.useHome,resumeSessionId:A.providerSessionId}).finally(()=>{me(de=>de===A.providerSessionId?null:de)})}})]})}const Ra=[{id:"ide",label:"IDE",helper:"Open a graphical workspace and attach CDP"},{id:"cli",label:"CLI",helper:"Launch a terminal-first workspace on this machine"},{id:"acp",label:"ACP",helper:"Launch an ACP-backed workspace on this machine"}];function $p({machine:t,machineId:s,providers:r,ideSessions:n,cliSessions:o,acpSessions:i,actions:c,getIcon:l,initialCategory:p="ide",initialWorkspaceId:x,initialWorkspacePath:m,sendDaemonCommand:h}){var u;const[g,S]=a.useState(p);a.useEffect(()=>{S(p)},[p]);const I=a.useMemo(()=>({ide:n.length,cli:o.length,acp:i.length}),[n.length,o.length,i.length]);return e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 h-full",children:[e.jsxs("div",{className:"flex flex-col gap-1 pb-4 border-b border-[#ffffff0a] mb-4",children:[e.jsx("div",{className:"text-lg font-semibold text-text-primary",children:"Workspace Launcher"}),e.jsx("div",{className:"text-sm text-text-secondary",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-baseline gap-4 mb-4",children:[e.jsx("div",{className:"flex bg-bg-surface p-1 rounded-lg border border-[#ffffff0a] w-fit",children:Ra.map(b=>e.jsxs("button",{type:"button",className:`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${g===b.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>S(b.id),children:[e.jsx("span",{children:b.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${g===b.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:I[b.id]})]},b.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(u=Ra.find(b=>b.id===g))==null?void 0:u.helper})]}),g==="ide"&&e.jsx(Vr,{category:"ide",machine:t,machineId:s,providers:r,managedEntries:n,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m}),g==="cli"&&e.jsx(Vr,{category:"cli",machine:t,machineId:s,providers:r,managedEntries:o,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m}),g==="acp"&&e.jsx(Vr,{category:"acp",machine:t,machineId:s,providers:r,managedEntries:i,getIcon:l,actions:c,sendDaemonCommand:h,initialWorkspaceId:x,initialWorkspacePath:m})]})}function Bp({onNicknameSynced:t}={}){var se,he,ce,be,Z,oe,ae,ke,we;const{id:s}=Ri(),r=ms(),n=on(),{sendCommand:o}=St(),i=Bs(),c=po(),l=c.ides||[],p=c.initialLoaded??!0,x=l.find(P=>P.id===s&&P.type==="adhdev-daemon"),m=l.some(P=>P.type==="adhdev-daemon"),[h,g]=a.useState("workspace"),[S,I]=a.useState("ide"),u=a.useRef(null),[b,y]=a.useState(null),d=a.useRef("__home__"),[C,M]=a.useState("__home__"),[N,f]=a.useState(!1),j=a.useRef(null);a.useEffect(()=>{!s||!x||!(!x.workspaces||!x.availableProviders||!x.detectedIdes||!x.recentLaunches)||i(s,{minFreshMs:3e4}).catch(()=>{})},[i,x,s]),Id(s&&h==="overview"?[s]:[],{enabled:h==="overview",intervalMs:15e3});const v=()=>{if(m){r("/dashboard",{state:{mobileSection:"machines"}});return}r("/machines")},k=gp({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:o,onNicknameSynced:t,logsEndRef:j});a.useEffect(()=>gt.onToast(fe=>{c.setToasts(xe=>{if(xe.some(Ee=>Ee.message===fe.message&&fe.timestamp-Ee.timestamp<3e3))return xe;const ge={id:fe.id,message:fe.message,type:fe.type,timestamp:fe.timestamp,targetKey:fe.targetKey,actions:fe.actions};return[...xe.slice(-4),ge]});const F=fe.duration||5e3;setTimeout(()=>c.setToasts(xe=>xe.filter(Ie=>Ie.id!==fe.id)),F)}),[c]);const $=(x==null?void 0:x.availableProviders)||[],E={};for(const P of $)E[P.type]=P.icon;const W=P=>E[P]||"",T=x?{id:x.id,hostname:no(x,{fallbackId:x.id}),platform:((se=x.machine)==null?void 0:se.platform)||"unknown",arch:((he=x.machine)==null?void 0:he.arch)||"",cpus:((ce=x.machine)==null?void 0:ce.cpus)||0,totalMem:((be=x.machine)==null?void 0:be.totalMem)||0,freeMem:(Z=x.machine)==null?void 0:Z.freeMem,availableMem:(oe=x.machine)==null?void 0:oe.availableMem,loadavg:(ae=x.machine)==null?void 0:ae.loadavg,uptime:(ke=x.machine)==null?void 0:ke.uptime,release:((we=x.machine)==null?void 0:we.release)||"",cdpConnected:!!x.cdpConnected,machineNickname:x.machineNickname||null,p2p:x.p2p?{screenshotActive:!1,...x.p2p}:{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:x.detectedIdes||[],workspaces:x.workspaces||[],defaultWorkspaceId:x.defaultWorkspaceId??x.activeWorkspaceId??null,defaultWorkspacePath:x.defaultWorkspacePath??x.activeWorkspacePath??null}:null,V=l.filter(P=>P.daemonId===s&&P.type!=="adhdev-daemon").filter(P=>!Ls(P)&&!ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,version:P.version||"",instanceId:P.instanceId||"",status:P.status,workspace:P.workspace||null,terminals:P.terminals||0,aiAgents:Uc(P.aiAgents||(P.agents||[]).map(fe=>({id:fe.name,name:fe.name,status:fe.status,version:fe.version}))),activeChat:P.activeChat||null,chats:P.chats||[],childSessions:P.childSessions||[],cdpConnected:P.cdpConnected||!1,daemonId:s})),R=l.filter(P=>P.daemonId===s&&Ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,cliName:P.cliName||P.type,status:P.status,workspace:P.workspace||"",activeChat:P.activeChat||null,providerSessionId:P.providerSessionId,mode:P.mode,runtimeKey:P.runtimeKey,runtimeDisplayName:P.runtimeDisplayName,runtimeWorkspaceLabel:P.runtimeWorkspaceLabel,runtimeWriteOwner:P.runtimeWriteOwner||null,runtimeAttachedClients:P.runtimeAttachedClients||[],daemonId:s})),w=l.filter(P=>P.daemonId===s&&ls(P)).map(P=>({id:P.id,sessionId:P.sessionId,type:P.type,acpName:P.cliName||P.type,status:P.status,workspace:P.workspace||"",activeChat:P.activeChat||null,providerSessionId:P.providerSessionId,currentModel:P.currentModel,currentPlan:P.currentPlan,daemonId:s})),B=x?kt(x,{fallbackId:s}):"",ee="workspace",L=n.state,D=L==null?void 0:L.initialMachineTab,O=L==null?void 0:L.initialWorkspaceCategory,z=L==null?void 0:L.initialWorkspaceId,Q=L==null?void 0:L.initialWorkspacePath,re=D==="ides"||D==="clis"||D==="acps"?"workspace":D||ee,je=D==="ides"?"ide":D==="clis"?"cli":D==="acps"?"acp":O,Y=[...V.map(P=>{var fe,F,xe,Ie,ge;return{id:`ide:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.type,kind:"ide",providerType:P.type,subtitle:P.workspace||void 0,workspace:P.workspace||void 0,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}}),...R.map(P=>{var fe,F,xe,Ie,ge;return{id:`cli:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.cliName,kind:"cli",providerType:P.type,providerSessionId:P.providerSessionId,subtitle:P.workspace||void 0,workspace:P.workspace||void 0,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}}),...w.map(P=>{var fe,F,xe,Ie,ge;return{id:`acp:${P.type}:${P.workspace||""}`,label:((fe=P.activeChat)==null?void 0:fe.title)||P.acpName,kind:"acp",providerType:P.type,providerSessionId:P.providerSessionId,subtitle:P.currentModel||P.workspace||void 0,workspace:P.workspace||void 0,currentModel:P.currentModel,timestamp:((ge=(Ie=(xe=(F=P.activeChat)==null?void 0:F.messages)==null?void 0:xe.at)==null?void 0:Ie.call(xe,-1))==null?void 0:ge.timestamp)||0}})].sort((P,fe)=>fe.timestamp-P.timestamp).map(({timestamp:P,...fe})=>fe),ne=((x==null?void 0:x.recentLaunches)||[]).length>0?((x==null?void 0:x.recentLaunches)||[]).map(P=>({id:P.id,label:P.title||P.providerName||P.providerType,kind:P.kind,providerType:P.providerType,providerSessionId:P.providerSessionId,subtitle:P.currentModel||P.workspace||void 0,workspace:P.workspace,currentModel:P.currentModel})):Y,_=a.useMemo(()=>{var fe;const P=((fe=c.connectionStates)==null?void 0:fe[s||""])||void 0;return l.filter(F=>F.daemonId===s&&F.type!=="adhdev-daemon").flatMap(F=>yn(F,{},{connectionStates:s&&P?{[s]:P}:void 0,defaultConnectionState:P})).filter(F=>!(F.transport==="pty"&&F.mode==="terminal")).sort((F,xe)=>sn(xe)-sn(F))},[l,c.connectionStates,s]),pe=a.useCallback(P=>{const fe=P.sessionId||P.tabKey;fe&&r(`/dashboard?activeTab=${encodeURIComponent(fe)}`)},[r]),me=a.useCallback(()=>{u.current&&(f(!0),u.current().finally(()=>{u.current=null,f(!1),y(null)}))},[]),J=a.useCallback(P=>{if(!T)return;const{options:fe,selectedKey:F}=Zt({machine:T,currentWorkspacePath:P.workspace}),xe=async()=>{I(P.kind),g("workspace")};u.current=async()=>{const Ie=fe.find(Ke=>Ke.key===d.current),ge=(Ie==null?void 0:Ie.workspacePath)??null,Ee=(Ie==null?void 0:Ie.workspaceId)??null;if(P.kind==="ide"&&P.providerType){await k.handleLaunchIde(P.providerType,ge?{workspace:ge}:void 0);return}if((P.kind==="cli"||P.kind==="acp")&&P.providerType){await k.runLaunchCliCore({cliType:P.providerType,dir:Ee?void 0:ge||"",workspaceId:Ee||void 0,model:P.kind==="acp"?P.currentModel:void 0,resumeSessionId:P.providerSessionId});return}await xe()},d.current=F,M(F),y({title:`Launch ${P.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:fe,details:[{label:"Mode",value:P.kind.toUpperCase()},...P.providerType?[{label:"Provider",value:P.providerType}]:[]]})},[k,T]);if(a.useEffect(()=>{g(re)},[ee,re,s]),a.useEffect(()=>{je&&I(je)},[je,s]),!T)return p?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:v,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const ie=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:14})," Workspace"]}),count:V.length+R.length+w.length},{id:"session-host",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Session Host"]})},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fr,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Zi,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Yi,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:v,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[k.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:k.nicknameInput,onChange:P=>k.setNicknameInput(P.target.value),onKeyDown:P=>{P.key==="Enter"&&k.handleSaveNickname(),P.key==="Escape"&&k.setEditingNickname(!1)},placeholder:"Machine nickname...",className:"px-2.5 py-1 rounded-md border border-violet-500/30 bg-bg-secondary text-text-primary text-sm font-semibold w-[140px] md:w-[200px]"}),e.jsx("button",{onClick:k.handleSaveNickname,className:"flex items-center justify-center px-3 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 text-sm font-medium transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>k.setEditingNickname(!1),className:"flex items-center justify-center px-3 py-1 rounded bg-[#ffffff0a] text-text-muted hover:bg-[#ffffff14] hover:text-text-primary text-sm font-medium transition-colors",children:"Cancel"})]}):e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-text-primary cursor-pointer truncate hover:text-accent-primary transition-colors",onClick:()=>{k.setEditingNickname(!0),k.setNicknameInput(T.machineNickname||"")},title:"Click to set nickname",children:B}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)] shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 items-center mt-1.5 text-xs text-text-secondary opacity-80",children:[e.jsxs("span",{className:"font-mono bg-[#ffffff08] px-1.5 py-0.5 rounded",children:[T.platform," · ",T.arch]}),e.jsxs("span",{children:[T.cpus," cores"]}),(x==null?void 0:x.version)&&e.jsxs("span",{children:["v",x.version]}),T.p2p.available&&e.jsxs("span",{children:["P2P ",T.p2p.state==="connected"?"connected":T.p2p.state]}),T.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:T.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:ie.map(P=>e.jsxs("button",{onClick:()=>g(P.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${h===P.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[P.label,P.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${h===P.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:P.count})]},P.id))})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 md:px-8 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto h-full",children:e.jsxs("div",{className:"h-full",children:[h==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Lp,{machineEntry:x,providers:$,recentLaunches:ne,currentConversations:_,onUpgradeDaemon:async()=>{try{await o(s,"daemon_upgrade",{})}catch{}},onOpenRecent:J,onOpenConversation:pe}),e.jsx($p,{machine:T,machineId:s,providers:$,ideSessions:V,cliSessions:R,acpSessions:w,actions:k,getIcon:W,initialCategory:S,initialWorkspaceId:z,initialWorkspacePath:Q,sendDaemonCommand:o})]}),h==="providers"&&e.jsx(Sp,{machineId:s,providers:$,sendDaemonCommand:o}),h==="overview"&&e.jsx(yp,{machineId:s,machine:T,ideSessions:V,cliSessions:R,acpSessions:w,actions:k,sendDaemonCommand:o}),h==="session-host"&&e.jsx(_p,{machineId:s,cliSessions:R,sendDaemonCommand:o}),h==="logs"&&e.jsx(Cp,{machineId:s,sendDaemonCommand:o})]})})}),k.launchPick&&T&&e.jsx(Pp,{machine:T,launchPick:k.launchPick,actions:k}),b&&e.jsx(Cn,{title:b.title,description:b.description,details:b.details,workspaceOptions:b.workspaceOptions,selectedWorkspaceKey:C,onWorkspaceChange:P=>{d.current=P,M(P)},confirmLabel:b.confirmLabel,busy:N,onConfirm:me,onCancel:()=>{u.current=null,y(null)}}),e.jsx(go,{toasts:c.toasts||[],onDismiss:P=>c.setToasts(fe=>fe.filter(F=>F.id!==P)),onClickToast:P=>{P.targetKey&&r(`/dashboard?activeTab=${encodeURIComponent(P.targetKey)}`)}}),e.jsx("style",{children:`
|
|
65
65
|
@keyframes toast-in {
|
|
66
66
|
from { opacity: 0; transform: translateX(40px); }
|
|
67
67
|
to { opacity: 1; transform: translateX(0); }
|
|
68
68
|
}
|
|
69
|
-
`})]})}class Kp{constructor(){it(this,"adapters",new Map);it(this,"states",new Map);it(this,"runtimeListeners",new Map);it(this,"screenshotCallbacks",new Map);it(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const r of this.adapters.keys())if(r.startsWith("standalone"))return r}return null}register(s,r){this.adapters.set(s,r),this.states.set(s,r.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,r){this.states.set(s,r)}retryConnection(s){}get(s){const r=this.resolveDaemonId(s);return r?this.adapters.get(r):void 0}getState(s){const r=this.resolveDaemonId(s);return r&&this.states.get(r)||"disconnected"}sendData(s,r){return!1}sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,o){return!1}onScreenshot(s,r){return this.screenshotCallbacks.set(s,r),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,r){this.screenshotCallbacks.forEach(n=>n(s,r))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,r){this.statusCallbacks.forEach(n=>n(s,r))}emitRuntimeSnapshot(s,r,n=0,o=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:n,text:r,truncated:o})}emitSessionOutput(s,r,n){!s||typeof r!="string"||!r||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof n=="number"?{seq:n}:{},data:r})}onRuntimeEvent(s,r){const n=this.runtimeListeners.get(s)||new Set;return n.add(r),this.runtimeListeners.set(s,n),()=>{const o=this.runtimeListeners.get(s);o&&(o.delete(r),o.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,r){if(!r)return;const n=await fetch(`/api/v1/runtime/${encodeURIComponent(r)}/snapshot`);if(!n.ok)return;const o=await n.json();this.emitRuntimeEvent(r,{type:"runtime_snapshot",sessionId:r,seq:typeof o.seq=="number"?o.seq:0,text:typeof o.text=="string"?o.text:"",truncated:!!o.truncated,cols:typeof o.cols=="number"?o.cols:void 0,rows:typeof o.rows=="number"?o.rows:void 0})}emitRuntimeEvent(s,r){var n;(n=this.runtimeListeners.get(s))==null||n.forEach(o=>o(r))}}const Et=new Kp;function Wp(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,n=new URLSearchParams(window.location.search).get("token");return n?`${s}?token=${encodeURIComponent(n)}`:s}const er=Wp(),Ea=3e3,Op=3e4;let Lt=null,Hp=0;const mr=new Map;let Vt=null,Ms=null;function Da(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function js(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-ws] ${t}`,s)}catch{}}function Up(t){return t==="connected"?"connected":t}async function ar(t,s,r){const n=Al(t,r||{}),o=Lt;if(o&&o.readyState===WebSocket.OPEN){const i=`req_${++Hp}_${Date.now()}`;return new Promise((c,l)=>{const p=setTimeout(()=>{mr.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);mr.set(i,{resolve:x=>{clearTimeout(p),c(x)},reject:x=>{clearTimeout(p),l(x)}}),o.send(JSON.stringify({type:"command",requestId:i,data:{type:s,payload:n.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}function an(t,s){const r=Lt;if(!r||r.readyState!==WebSocket.OPEN)return!1;try{return r.send(JSON.stringify(s)),!0}catch{return!1}}class zp{constructor(s){it(this,"daemonId");it(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Lt==null?void 0:Lt.readyState)===WebSocket.OPEN}get connectionState(){return(Lt==null?void 0:Lt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,r){return ar(this.daemonId,s,r)}async sendInput(s,r){return ar(this.daemonId,"cdp_remote_action",{action:s,params:r,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Vt&&(clearInterval(Vt),Vt=null);const r=async()=>{if(this.hasCommandChannel)try{const n=await ar(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(n!=null&&n.success&&(n!=null&&n.base64)){const o=await fetch(`data:image/jpeg;base64,${n.base64}`).then(i=>i.blob());Et.emitScreenshot(this.daemonId,o)}}catch{}};r(),Vt=setInterval(r,2e3)}stopScreenshots(s){Vt&&(clearInterval(Vt),Vt=null)}}let At=null;function Fp(t){return(!At||At.daemonId!==t)&&(At=new zp(t)),At}function Vp({children:t}){const s=a.useRef(ir()),r=ir();s.current=r;const{setUserName:n}=Qt(),o=a.useRef(n);o.current=n;const i=a.useRef(null),c=a.useRef(null),[,l]=a.useState("disconnected"),p=a.useCallback((u,b)=>{l(u),Ms==null||Ms(u,b)},[]),x=a.useRef(null),m=a.useRef(),h=a.useRef(Ea),g=a.useRef(!0),S=a.useRef(!1),I=a.useRef("initial_connect");return a.useEffect(()=>{g.current=!0,S.current=!1;function u(){var d,C;if(!g.current||((d=x.current)==null?void 0:d.readyState)===WebSocket.OPEN||((C=x.current)==null?void 0:C.readyState)===WebSocket.CONNECTING)return;p("connecting"),console.log(`[Standalone WS] Connecting to ${er}...`),js("connect_attempt",{url:er,reason:I.current,delayMs:h.current});let y;try{y=new WebSocket(er)}catch(M){console.error("[Standalone WS] Failed to create WebSocket:",M),b();return}x.current=y,y.onopen=()=>{if(!g.current){y.close();return}p("connected"),h.current=Ea,js("open",{url:er,reason:I.current}),Ot.resubscribeAll({sendData:an}),console.log("[Standalone WS] Connected")},Lt=y,y.onmessage=M=>{var N,f;try{const j=JSON.parse(M.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const v=mr.get(j.requestId);v&&(mr.delete(j.requestId),j.type==="error"?v.reject(new Error(((N=j.data)==null?void 0:N.message)||"Command failed")):v.resolve(j.data));return}if(j.type==="session_output"){const v=j.sessionId||j.cliId||j.cliType;v&&Et.emitSessionOutput(v,typeof j.data=="string"?j.data:"",typeof j.seq=="number"?j.seq:void 0);return}if(j.type==="runtime_snapshot"){Et.emitRuntimeSnapshot(j.sessionId,typeof j.text=="string"?j.text:"",typeof j.seq=="number"?j.seq:0,!!j.truncated);return}if(j.type==="topic_update"){const v=j.update;v&&Ot.publish(v);return}if(j.type==="status"||j.type==="initial_state"){const v=j.data;if(!v)return;const{injectEntries:k,markLoaded:$,getIdes:E}=s.current,W=v.instanceId||"standalone",T=E().find(w=>w.id===W),V=Fp(W);Et.register(W,V),Et.setState(W,"connected"),p("connected",W),Et.emitStatus(W,v);const R=lr(v,{daemonId:W,existingDaemon:T,existingEntries:E()});Da("ws_status",{type:j.type,daemonId:W,sessions:(v.sessions||[]).map(w=>({id:w.id,parentId:w.parentId,providerType:w.providerType,kind:w.kind,transport:w.transport,unread:w.unread,inboxBucket:w.inboxBucket,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,title:w.title})),recentLaunches:(v.recentLaunches||[]).map(w=>({id:w.id,providerType:w.providerType,kind:w.kind,workspace:w.workspace,lastLaunchedAt:w.lastLaunchedAt}))}),Da("entries",{daemonId:W,entries:R.filter(w=>w.type!=="adhdev-daemon").map(w=>({id:w.id,type:w.type,unread:w.unread,inboxBucket:w.inboxBucket,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,sessionId:w.sessionId}))}),R.length>0&&k(R,{authoritativeDaemonIds:[W]}),$(),c.current!==W&&((f=i.current)==null||f.call(i),c.current=W,i.current=Ot.subscribe({sendData:an},W,{type:"subscribe",topic:"daemon.metadata",key:`daemon:metadata:${W}`,params:{includeSessions:!0}},w=>{if(w.topic!=="daemon.metadata")return;const B=s.current.getIdes(),ee=B.find(D=>D.id===W),L=lr(w.status,{daemonId:W,existingDaemon:ee,existingEntries:B,timestamp:w.timestamp});L.length>0&&s.current.injectEntries(L),w.userName&&o.current&&o.current(w.userName)}))}}catch(j){console.error("[Standalone WS] Parse error:",j)}},y.onclose=M=>{g.current&&(At==null||At.stopScreenshots(),At&&Et.setState(At.daemonId,"disconnected"),p("disconnected"),x.current=null,I.current=`close:${M.code}${M.wasClean?":clean":":unclean"}`,js("close",{code:M.code,reason:M.reason||"",wasClean:M.wasClean}),b())},y.onerror=M=>{S.current||!g.current||(I.current="error",js("error",{message:M instanceof Event?"event":String(M),readyState:y.readyState}),console.warn("[Standalone WS] Error, will reconnect:",M))}}function b(){if(!g.current)return;clearTimeout(m.current);const y=h.current;console.log(`[Standalone WS] Reconnecting in ${y}ms...`),js("schedule_reconnect",{reason:I.current,delayMs:y}),m.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,Op),u()},y)}return u(),()=>{var y;g.current=!1,S.current=!0,(y=i.current)==null||y.call(i),i.current=null,c.current=null,clearTimeout(m.current),x.current&&(x.current.onerror=null,x.current.onclose=null,x.current.close(),x.current=null,Lt=null),At&&(At.stopScreenshots(),Et.unregister(At.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function qp({children:t}){const[s,r]=a.useState("disconnected"),[n,o]=a.useState(null);a.useEffect(()=>(Ms=(c,l)=>{r(c),l&&o(l)},()=>{Ms=null}),[]);const i=a.useMemo(()=>{const c=s==="connected",l=Up(s),p={};return n&&(p[n]=l),p.standalone=l,{wsStatus:s,isConnected:c,connectionStates:p}},[s,n]);return e.jsx(Oi,{connectionOverrides:i,children:e.jsx(Vp,{children:t})})}const Gp=[{id:"dashboard",path:"/dashboard",icon:e.jsx(za,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ht,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(fr,{}),label:"Settings"}];function Yp({children:t}){const s=ms(),r=on(),[n,o]=a.useState(!1),[i,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),l=m=>{s(m),o(!1)},p=()=>{c(m=>{const h=!m;try{localStorage.setItem("sidebar-collapsed",h?"1":"0")}catch{}return h})},x=m=>`nav-item${r.pathname.startsWith(m)?" active":""} cursor-pointer ${i?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${n?" mobile-menu-open":""}${i?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>o(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),n&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>o(!1),onKeyDown:m=>m.key==="Escape"&&o(!1)}),e.jsxs("aside",{className:`sidebar ${n?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${i?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!i&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>o(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Gp.map(m=>e.jsxs("div",{className:x(m.path),id:`nav-${m.id}`,onClick:()=>l(m.path),title:i?m.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:m.icon}),!i&&m.label]},m.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:i?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Fa,{})}),!i&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${r.pathname==="/about"?" active":""} ${i?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:i?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Va,{})}),!i&&"About"]}),!i&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.44"]}),e.jsx(id,{collapsed:i}),e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":"mt-1"}`,onClick:p,title:i?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:i?"›":"‹"}),!i&&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 Xp=[{icon:e.jsx(Ht,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Bt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(qa,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Nt,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ts,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Fa,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Jp=[{icon:e.jsx(Xa,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(za,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(hr,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Gi,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(ln,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Xi,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Zp=[{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 Qp(){return e.jsxs(Co,{icon:e.jsx(Va,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, built-in 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.44"]}),children:[e.jsx(_t,{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(_t,{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:Xp.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(_t,{title:"Built-in inventory",description:"Bundled editors and agent surfaces exposed in the standalone dashboard. These lists describe inventory, not verified support.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:wo.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:ko.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:jo.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(_t,{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:Jp.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(_t,{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:Zp.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(Io,{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(dc,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function em(){const{ides:t}=Qt(),s=t.find(h=>h.type==="adhdev-daemon"),r=(s==null?void 0:s.detectedIdes)||[],{sendCommand:n}=St(),{userName:o}=Qt(),[i,c]=a.useState(o||"");a.useEffect(()=>{o!==void 0&&c(o)},[o]);const l=h=>{const g=h.target.value.trim();s!=null&&s.id&&g!==o&&n(s.id,"set_user_name",{userName:g}).catch(console.error)},[p,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),m=h=>{x(h);try{localStorage.setItem("adhdev_sound",h?"1":"0")}catch{}};return e.jsxs(Co,{icon:e.jsx(fr,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(td,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(_t,{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.44"]}),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(_t,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:r.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:r.map(h=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${h.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:h.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:h.type})]},h.type))})}),e.jsx(_t,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(ud,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(_t,{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(xd,{})]}),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(kd,{})]}),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(Sd,{})]})]})}),e.jsx(_t,{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(cd,{}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(lc,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:p,onChange:m})]})}),e.jsx(_t,{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(qi,{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:i,onChange:h=>c(h.target.value),onBlur:l,onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()}})]})})})]})}od();wd();const tm=Ha({baseUrl:""});function $a(){const{ides:t,initialLoaded:s}=Qt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const r=t.find(n=>n.daemonMode||n.type==="adhdev-daemon");return r?e.jsx(Yr,{to:`/machines/${r.id}`,replace:!0}):e.jsx(Yr,{to:"/dashboard",replace:!0})}function sm(){return e.jsx(Ei,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(zi,{client:tm,children:e.jsx(qp,{children:e.jsx(Vi,{value:{sendCommand:ar,sendData:an},children:e.jsx(Yp,{children:e.jsxs(Di,{children:[e.jsx(zt,{path:"/dashboard",element:e.jsx(bp,{})}),e.jsx(zt,{path:"/machine",element:e.jsx($a,{})}),e.jsx(zt,{path:"/machines/:id",element:e.jsx(Bp,{})}),e.jsx(zt,{path:"/machines",element:e.jsx($a,{})}),e.jsx(zt,{path:"/about",element:e.jsx(Qp,{})}),e.jsx(zt,{path:"/settings",element:e.jsx(em,{})}),e.jsx(zt,{path:"*",element:e.jsx(Yr,{to:"/dashboard",replace:!0})})]})})})})})})}fl({connectionManager:Et});$i(document.getElementById("root")).render(e.jsx(sm,{}));
|
|
69
|
+
`})]})}class Kp{constructor(){it(this,"adapters",new Map);it(this,"states",new Map);it(this,"runtimeListeners",new Map);it(this,"screenshotCallbacks",new Map);it(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const r of this.adapters.keys())if(r.startsWith("standalone"))return r}return null}register(s,r){this.adapters.set(s,r),this.states.set(s,r.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,r){this.states.set(s,r)}retryConnection(s){}get(s){const r=this.resolveDaemonId(s);return r?this.adapters.get(r):void 0}getState(s){const r=this.resolveDaemonId(s);return r&&this.states.get(r)||"disconnected"}sendData(s,r){return!1}sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,o){return!1}onScreenshot(s,r){return this.screenshotCallbacks.set(s,r),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,r){this.screenshotCallbacks.forEach(n=>n(s,r))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,r){this.statusCallbacks.forEach(n=>n(s,r))}emitRuntimeSnapshot(s,r,n=0,o=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:n,text:r,truncated:o})}emitSessionOutput(s,r,n){!s||typeof r!="string"||!r||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof n=="number"?{seq:n}:{},data:r})}onRuntimeEvent(s,r){const n=this.runtimeListeners.get(s)||new Set;return n.add(r),this.runtimeListeners.set(s,n),()=>{const o=this.runtimeListeners.get(s);o&&(o.delete(r),o.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,r){if(!r)return;const n=await fetch(`/api/v1/runtime/${encodeURIComponent(r)}/snapshot`);if(!n.ok)return;const o=await n.json();this.emitRuntimeEvent(r,{type:"runtime_snapshot",sessionId:r,seq:typeof o.seq=="number"?o.seq:0,text:typeof o.text=="string"?o.text:"",truncated:!!o.truncated,cols:typeof o.cols=="number"?o.cols:void 0,rows:typeof o.rows=="number"?o.rows:void 0})}emitRuntimeEvent(s,r){var n;(n=this.runtimeListeners.get(s))==null||n.forEach(o=>o(r))}}const Et=new Kp;function Wp(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,n=new URLSearchParams(window.location.search).get("token");return n?`${s}?token=${encodeURIComponent(n)}`:s}const er=Wp(),Ea=3e3,Op=3e4;let Lt=null,Hp=0;const mr=new Map;let Vt=null,Ms=null;function Da(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function js(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-ws] ${t}`,s)}catch{}}function Up(t){return t==="connected"?"connected":t}async function ar(t,s,r){const n=Al(t,r||{}),o=Lt;if(o&&o.readyState===WebSocket.OPEN){const i=`req_${++Hp}_${Date.now()}`;return new Promise((c,l)=>{const p=setTimeout(()=>{mr.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);mr.set(i,{resolve:x=>{clearTimeout(p),c(x)},reject:x=>{clearTimeout(p),l(x)}}),o.send(JSON.stringify({type:"command",requestId:i,data:{type:s,payload:n.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}function an(t,s){const r=Lt;if(!r||r.readyState!==WebSocket.OPEN)return!1;try{return r.send(JSON.stringify(s)),!0}catch{return!1}}class zp{constructor(s){it(this,"daemonId");it(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Lt==null?void 0:Lt.readyState)===WebSocket.OPEN}get connectionState(){return(Lt==null?void 0:Lt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,r){return ar(this.daemonId,s,r)}async sendInput(s,r){return ar(this.daemonId,"cdp_remote_action",{action:s,params:r,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Vt&&(clearInterval(Vt),Vt=null);const r=async()=>{if(this.hasCommandChannel)try{const n=await ar(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(n!=null&&n.success&&(n!=null&&n.base64)){const o=await fetch(`data:image/jpeg;base64,${n.base64}`).then(i=>i.blob());Et.emitScreenshot(this.daemonId,o)}}catch{}};r(),Vt=setInterval(r,2e3)}stopScreenshots(s){Vt&&(clearInterval(Vt),Vt=null)}}let At=null;function Fp(t){return(!At||At.daemonId!==t)&&(At=new zp(t)),At}function Vp({children:t}){const s=a.useRef(ir()),r=ir();s.current=r;const{setUserName:n}=Qt(),o=a.useRef(n);o.current=n;const i=a.useRef(null),c=a.useRef(null),[,l]=a.useState("disconnected"),p=a.useCallback((u,b)=>{l(u),Ms==null||Ms(u,b)},[]),x=a.useRef(null),m=a.useRef(),h=a.useRef(Ea),g=a.useRef(!0),S=a.useRef(!1),I=a.useRef("initial_connect");return a.useEffect(()=>{g.current=!0,S.current=!1;function u(){var d,C;if(!g.current||((d=x.current)==null?void 0:d.readyState)===WebSocket.OPEN||((C=x.current)==null?void 0:C.readyState)===WebSocket.CONNECTING)return;p("connecting"),console.log(`[Standalone WS] Connecting to ${er}...`),js("connect_attempt",{url:er,reason:I.current,delayMs:h.current});let y;try{y=new WebSocket(er)}catch(M){console.error("[Standalone WS] Failed to create WebSocket:",M),b();return}x.current=y,y.onopen=()=>{if(!g.current){y.close();return}p("connected"),h.current=Ea,js("open",{url:er,reason:I.current}),Ot.resubscribeAll({sendData:an}),console.log("[Standalone WS] Connected")},Lt=y,y.onmessage=M=>{var N,f;try{const j=JSON.parse(M.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const v=mr.get(j.requestId);v&&(mr.delete(j.requestId),j.type==="error"?v.reject(new Error(((N=j.data)==null?void 0:N.message)||"Command failed")):v.resolve(j.data));return}if(j.type==="session_output"){const v=j.sessionId||j.cliId||j.cliType;v&&Et.emitSessionOutput(v,typeof j.data=="string"?j.data:"",typeof j.seq=="number"?j.seq:void 0);return}if(j.type==="runtime_snapshot"){Et.emitRuntimeSnapshot(j.sessionId,typeof j.text=="string"?j.text:"",typeof j.seq=="number"?j.seq:0,!!j.truncated);return}if(j.type==="topic_update"){const v=j.update;v&&Ot.publish(v);return}if(j.type==="status"||j.type==="initial_state"){const v=j.data;if(!v)return;const{injectEntries:k,markLoaded:$,getIdes:E}=s.current,W=v.instanceId||"standalone",T=E().find(w=>w.id===W),V=Fp(W);Et.register(W,V),Et.setState(W,"connected"),p("connected",W),Et.emitStatus(W,v);const R=lr(v,{daemonId:W,existingDaemon:T,existingEntries:E()});Da("ws_status",{type:j.type,daemonId:W,sessions:(v.sessions||[]).map(w=>({id:w.id,parentId:w.parentId,providerType:w.providerType,kind:w.kind,transport:w.transport,unread:w.unread,inboxBucket:w.inboxBucket,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,title:w.title})),recentLaunches:(v.recentLaunches||[]).map(w=>({id:w.id,providerType:w.providerType,kind:w.kind,workspace:w.workspace,lastLaunchedAt:w.lastLaunchedAt}))}),Da("entries",{daemonId:W,entries:R.filter(w=>w.type!=="adhdev-daemon").map(w=>({id:w.id,type:w.type,unread:w.unread,inboxBucket:w.inboxBucket,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,sessionId:w.sessionId}))}),R.length>0&&k(R,{authoritativeDaemonIds:[W]}),$(),c.current!==W&&((f=i.current)==null||f.call(i),c.current=W,i.current=Ot.subscribe({sendData:an},W,{type:"subscribe",topic:"daemon.metadata",key:`daemon:metadata:${W}`,params:{includeSessions:!0}},w=>{if(w.topic!=="daemon.metadata")return;const B=s.current.getIdes(),ee=B.find(D=>D.id===W),L=lr(w.status,{daemonId:W,existingDaemon:ee,existingEntries:B,timestamp:w.timestamp});L.length>0&&s.current.injectEntries(L),w.userName&&o.current&&o.current(w.userName)}))}}catch(j){console.error("[Standalone WS] Parse error:",j)}},y.onclose=M=>{g.current&&(At==null||At.stopScreenshots(),At&&Et.setState(At.daemonId,"disconnected"),p("disconnected"),x.current=null,I.current=`close:${M.code}${M.wasClean?":clean":":unclean"}`,js("close",{code:M.code,reason:M.reason||"",wasClean:M.wasClean}),b())},y.onerror=M=>{S.current||!g.current||(I.current="error",js("error",{message:M instanceof Event?"event":String(M),readyState:y.readyState}),console.warn("[Standalone WS] Error, will reconnect:",M))}}function b(){if(!g.current)return;clearTimeout(m.current);const y=h.current;console.log(`[Standalone WS] Reconnecting in ${y}ms...`),js("schedule_reconnect",{reason:I.current,delayMs:y}),m.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,Op),u()},y)}return u(),()=>{var y;g.current=!1,S.current=!0,(y=i.current)==null||y.call(i),i.current=null,c.current=null,clearTimeout(m.current),x.current&&(x.current.onerror=null,x.current.onclose=null,x.current.close(),x.current=null,Lt=null),At&&(At.stopScreenshots(),Et.unregister(At.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function qp({children:t}){const[s,r]=a.useState("disconnected"),[n,o]=a.useState(null);a.useEffect(()=>(Ms=(c,l)=>{r(c),l&&o(l)},()=>{Ms=null}),[]);const i=a.useMemo(()=>{const c=s==="connected",l=Up(s),p={};return n&&(p[n]=l),p.standalone=l,{wsStatus:s,isConnected:c,connectionStates:p}},[s,n]);return e.jsx(Oi,{connectionOverrides:i,children:e.jsx(Vp,{children:t})})}const Gp=[{id:"dashboard",path:"/dashboard",icon:e.jsx(za,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ht,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(fr,{}),label:"Settings"}];function Yp({children:t}){const s=ms(),r=on(),[n,o]=a.useState(!1),[i,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),l=m=>{s(m),o(!1)},p=()=>{c(m=>{const h=!m;try{localStorage.setItem("sidebar-collapsed",h?"1":"0")}catch{}return h})},x=m=>`nav-item${r.pathname.startsWith(m)?" active":""} cursor-pointer ${i?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${n?" mobile-menu-open":""}${i?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>o(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),n&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>o(!1),onKeyDown:m=>m.key==="Escape"&&o(!1)}),e.jsxs("aside",{className:`sidebar ${n?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${i?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!i&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>o(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Gp.map(m=>e.jsxs("div",{className:x(m.path),id:`nav-${m.id}`,onClick:()=>l(m.path),title:i?m.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:m.icon}),!i&&m.label]},m.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:i?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Fa,{})}),!i&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${r.pathname==="/about"?" active":""} ${i?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:i?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Va,{})}),!i&&"About"]}),!i&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.45"]}),e.jsx(id,{collapsed:i}),e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":"mt-1"}`,onClick:p,title:i?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:i?"›":"‹"}),!i&&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 Xp=[{icon:e.jsx(Ht,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Bt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(qa,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Nt,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ts,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Fa,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Jp=[{icon:e.jsx(Xa,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(za,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(hr,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Gi,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(ln,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Xi,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Zp=[{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 Qp(){return e.jsxs(Co,{icon:e.jsx(Va,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, built-in 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.45"]}),children:[e.jsx(_t,{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(_t,{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:Xp.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(_t,{title:"Built-in inventory",description:"Bundled editors and agent surfaces exposed in the standalone dashboard. These lists describe inventory, not verified support.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:wo.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:ko.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:jo.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(_t,{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:Jp.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(_t,{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:Zp.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(Io,{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(dc,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function em(){const{ides:t}=Qt(),s=t.find(h=>h.type==="adhdev-daemon"),r=(s==null?void 0:s.detectedIdes)||[],{sendCommand:n}=St(),{userName:o}=Qt(),[i,c]=a.useState(o||"");a.useEffect(()=>{o!==void 0&&c(o)},[o]);const l=h=>{const g=h.target.value.trim();s!=null&&s.id&&g!==o&&n(s.id,"set_user_name",{userName:g}).catch(console.error)},[p,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),m=h=>{x(h);try{localStorage.setItem("adhdev_sound",h?"1":"0")}catch{}};return e.jsxs(Co,{icon:e.jsx(fr,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(td,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(_t,{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.45"]}),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(_t,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:r.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:r.map(h=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${h.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:h.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:h.type})]},h.type))})}),e.jsx(_t,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(ud,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(_t,{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(xd,{})]}),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(kd,{})]}),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(Sd,{})]})]})}),e.jsx(_t,{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(cd,{}),e.jsx(qt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(lc,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:p,onChange:m})]})}),e.jsx(_t,{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(qi,{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:i,onChange:h=>c(h.target.value),onBlur:l,onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()}})]})})})]})}od();wd();const tm=Ha({baseUrl:""});function $a(){const{ides:t,initialLoaded:s}=Qt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const r=t.find(n=>n.daemonMode||n.type==="adhdev-daemon");return r?e.jsx(Yr,{to:`/machines/${r.id}`,replace:!0}):e.jsx(Yr,{to:"/dashboard",replace:!0})}function sm(){return e.jsx(Ei,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(zi,{client:tm,children:e.jsx(qp,{children:e.jsx(Vi,{value:{sendCommand:ar,sendData:an},children:e.jsx(Yp,{children:e.jsxs(Di,{children:[e.jsx(zt,{path:"/dashboard",element:e.jsx(bp,{})}),e.jsx(zt,{path:"/machine",element:e.jsx($a,{})}),e.jsx(zt,{path:"/machines/:id",element:e.jsx(Bp,{})}),e.jsx(zt,{path:"/machines",element:e.jsx($a,{})}),e.jsx(zt,{path:"/about",element:e.jsx(Qp,{})}),e.jsx(zt,{path:"/settings",element:e.jsx(em,{})}),e.jsx(zt,{path:"*",element:e.jsx(Yr,{to:"/dashboard",replace:!0})})]})})})})})})}fl({connectionManager:Et});$i(document.getElementById("root")).render(e.jsx(sm,{}));
|