@adhdev/daemon-standalone 0.6.18 → 0.6.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ var _s=Object.defineProperty;var As=(t,s,a)=>s in t?_s(t,s,{enumerable:!0,config
|
|
|
26
26
|
}
|
|
27
27
|
`})]})}function fn({screenshotUrl:t,mode:s="preview",zoom:a=100,interactive:r=!1,connectionState:i,onDismiss:c,onClickAt:o,onKeyDown:x,badge:m,emptyMessage:p,aspectRatio:u,className:l,style:N}){const h=n.useRef(null),d=n.useCallback(S=>{if(!r||!o||!h.current)return;const T=h.current,I=T.getBoundingClientRect(),$=(S.clientX-I.left)/I.width*T.naturalWidth,K=(S.clientY-I.top)/I.height*T.naturalHeight;o($,K,T.naturalWidth,T.naturalHeight)},[r,o]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${l||""}`,style:{aspectRatio:u||"16/9",...N},children:[e.jsx("img",{ref:h,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),c&&e.jsx("button",{onClick:c,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${r?"screenshot-interactive":""} ${l||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?x:void 0,style:N,children:[e.jsx("img",{ref:h,src:t,alt:"IDE Screenshot",onClick:r?d:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...a!==100?{transform:`scale(${a/100})`,transformOrigin:"center center"}:{}}}),m&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:m})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${l||""}`,style:N,children:[e.jsx("p",{className:"text-base",children:p||"🖥 Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]})]})}function ys({activeConv:t,onModalButton:s}){const[a,r]=n.useState(null);if(n.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=o=>{a||(r(o),s(o))},c=o=>o.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(xs,{size:14})," ",a?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((o,x)=>{const m=c(o).toLowerCase(),p=/^(run|approve|accept|yes|allow|always)/.test(m),u=/^(reject|deny|delete|remove|abort)/.test(m),l=a===o,N=a!==null;return e.jsx("button",{onClick:()=>i(o),disabled:N,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${p?"bg-white text-amber-700 font-extrabold":u?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${N&&!l?"opacity-40":"opacity-100"} ${N?"cursor-not-allowed":"cursor-pointer"}`,children:l?"⏳ ...":c(o)},x)})})]})]})}const We=new Map;function gn({ideId:t,ideType:s,agentType:a,agentName:r,serverModel:i,serverMode:c,acpConfigOptions:o,acpModes:x}){var P;const{sendCommand:m}=Je(),p=!!(o||x),u=`${t}:${a}`,l=We.get(u),[N,h]=n.useState(!1),[d,S]=n.useState(!1),[T,I]=n.useState((l==null?void 0:l.models)||[]),[$,K]=n.useState((l==null?void 0:l.modes)||[]),z=b=>b?typeof b=="string"?b:typeof b=="object"?b.name||b.id||JSON.stringify(b):String(b):"",[q,ie]=n.useState(z(i)),[H,Q]=n.useState(z(c)),[w,R]=n.useState(!1),[D,F]=n.useState(!1),V=n.useRef(0),y=b=>b.map(_=>typeof _=="string"?_:(_==null?void 0:_.name)||(_==null?void 0:_.id)||String(_));n.useEffect(()=>{if(o){const b=o.find(_=>_.category==="model");if(b){const _=y(b.options.map(W=>W.value));I(_),b.currentValue&&ie(z(b.currentValue));const g=We.get(u)||{models:[],modes:[]};We.set(u,{...g,models:_})}}if(x&&x.length>0){const b=y(x.map(g=>g.id));K(b);const _=We.get(u)||{models:[],modes:[]};We.set(u,{..._,modes:b})}else if(o){const b=o.find(_=>_.category!=="model");if(b){const _=y(b.options.map(W=>W.value));K(_),b.currentValue&&Q(z(b.currentValue));const g=We.get(u)||{models:[],modes:[]};We.set(u,{...g,modes:_})}}},[o,x,u]),n.useEffect(()=>{h(!1),S(!1),ie(z(i)),Q(z(c));const b=We.get(u);b?(I(b.models),K(b.modes)):(I([]),K([]))},[t,a]),n.useEffect(()=>{i&&Date.now()>V.current&&ie(z(i))},[i]),n.useEffect(()=>{c&&Date.now()>V.current&&Q(z(c))},[c]);const U=n.useCallback(async(b,_={})=>{const g={..._},W=t.split(":");return W.length>=3&&(W[1]==="ide"||W[1]==="cli"||W[1]==="acp")&&(g._targetInstance=W.slice(2).join(":"),g._targetType=W[1]),await m(t,b,g)},[t]),ee=async()=>{var b,_;if(T.length>0){h(!N);return}if(p){h(!0);return}R(!0);try{const g=await U("list_extension_models",{agentType:a,ideType:s}),W=(g==null?void 0:g.models)||((b=g==null?void 0:g.result)==null?void 0:b.models)||[],G=y(W);I(G),g!=null&&g.current&&ie(z(g.current)),(_=g==null?void 0:g.result)!=null&&_.current&&ie(z(g.result.current));const pe=We.get(u)||{models:[],modes:[]};We.set(u,{...pe,models:G}),h(!0)}catch{}finally{R(!1)}},Y=async()=>{var b,_;if($.length>0){S(!d);return}if(p){S(!0);return}F(!0);try{const g=await U("list_extension_modes",{agentType:a,ideType:s}),W=(g==null?void 0:g.modes)||((b=g==null?void 0:g.result)==null?void 0:b.modes)||[],G=y(W);K(G),g!=null&&g.current&&Q(z(g.current)),(_=g==null?void 0:g.result)!=null&&_.current&&Q(z(g.result.current));const pe=We.get(u)||{models:[],modes:[]};We.set(u,{...pe,modes:G}),S(!0)}catch{}finally{F(!1)}},Z=async b=>{h(!1),ie(b),V.current=Date.now()+5e3;try{p?await U("change_model",{agentType:a,ideType:s,model:b}):await U("set_extension_model",{agentType:a,ideType:s,model:b})}catch{}},B=p&&!(x&&x.length>0)&&(o==null?void 0:o.some(b=>b.category!=="model")),oe=B?(P=o==null?void 0:o.find(b=>b.category!=="model"))==null?void 0:P.configId:void 0,te=async b=>{S(!1),Q(b),V.current=Date.now()+5e3;try{p&&B&&oe?await U("set_thought_level",{agentType:a,ideType:s,configId:oe,value:b}):p?await U("set_mode",{agentType:a,ideType:s,mode:b}):await U("set_extension_mode",{agentType:a,ideType:s,mode:b})}catch{}},ne={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[a]||"#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 uppercase opacity-70",style:{color:ne},children:r}),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:N?`${ne}55`:"transparent",border:"1px solid",color:q?"var(--text-primary)":"var(--text-muted)"},onClick:ee,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),w?"...":q||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),N&&T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>h(!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"}),T.map(b=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:b===q?`${ne}18`:"transparent",color:b===q?ne:"var(--text-secondary)",fontWeight:b===q?600:400,borderLeft:b===q?`2px solid ${ne}`:"2px solid transparent"},onMouseEnter:_=>{_.currentTarget.style.background=`${ne}12`},onMouseLeave:_=>{_.currentTarget.style.background=b===q?`${ne}18`:"transparent"},onClick:()=>Z(b),children:b},b))]})]})]}),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:d?`${ne}55`:"transparent",border:"1px solid",color:H?"var(--text-primary)":"var(--text-muted)"},onClick:Y,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:B?"🧠":"⚡"}),D?"...":H||(B?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),d&&$.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(!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:B?"SELECT THINKING LEVEL":"SELECT MODE"}),$.map(b=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:b===H?`${ne}18`:"transparent",color:b===H?ne:"var(--text-secondary)",fontWeight:b===H?600:400,borderLeft:b===H?`2px solid ${ne}`:"2px solid transparent"},onMouseEnter:_=>{_.currentTarget.style.background=`${ne}12`},onMouseLeave:_=>{_.currentTarget.style.background=b===H?`${ne}18`:"transparent"},onClick:()=>te(b),children:b},b))]})]})]})]})}const qe=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Fe=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function vs({activeConv:t,ides:s,agentInput:a,setAgentInput:r,handleSendChat:i,handleFocusAgent:c,isFocusingAgent:o,messageReceivedAt:x,actionLogs:m,userName:p}){const u=n.useRef(null),{sendCommand:l}=Je(),N=n.useRef(new Map),h=n.useCallback(w=>(N.current.has(w)||N.current.set(w,{messages:[],offset:0,hasMore:!0,error:null}),N.current.get(w)),[]),d=n.useCallback((w,R)=>{const D=h(w);N.current.set(w,{...D,...R}),S(F=>F+1)},[h]),[,S]=n.useState(0),T=t.tabKey,I=h(T),$=I.messages,K=I.hasMore,z=I.error,[q,ie]=n.useState(!1),H=n.useCallback(async()=>{var D,F;if(q)return;const w=t.tabKey,R=h(w);ie(!0),d(w,{error:null});try{const V=s.find(oe=>oe.id===t.ideId),y=(V==null?void 0:V.daemonId)||((D=t.ideId)==null?void 0:D.split(":")[0])||"";if(!y){d(w,{hasMore:!1});return}const U=t.ideType||t.agentType||"",ee=(t.ideId||"").split(":"),Y=ee.length>=3?ee.slice(2).join(":"):void 0,Z=await l(y,"chat_history",{agentType:U,offset:R.offset,limit:30,instanceId:Y}),B=(Z==null?void 0:Z.result)??Z;if(((F=B.messages)==null?void 0:F.length)>0){const oe=h(w);d(w,{messages:[...B.messages,...oe.messages],offset:oe.offset+B.messages.length,hasMore:!!B.hasMore})}else d(w,{hasMore:!!B.hasMore})}catch(V){const y=(V==null?void 0:V.message)||"";y.includes("P2P not available")||y.includes("channel not open")||y.includes("P2P not connected")||y.includes("timeout")?d(w,{error:"Connection not ready — tap to retry"}):d(w,{hasMore:!1,error:"Failed to load history"})}finally{ie(!1)}},[q,s,t,l,h,d]),Q=(()=>{const w=t.messages.map((F,V)=>{const y=`${t.ideId}-${F.id??`i-${V}`}`;return{...F,receivedAt:F.receivedAt||x[y]||0}});if($.length===0)return w;const R=new Set(w.map(F=>`${F.role}:${(F.content||"").slice(0,100)}`));return[...$.filter(F=>!R.has(`${F.role}:${(F.content||"").slice(0,100)}`)),...w]})();return e.jsxs(e.Fragment,{children:[e.jsx(xn,{messages:Q,actionLogs:m.filter(w=>w.ideId===t.tabKey).sort((w,R)=>w.timestamp-R.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:p,isCliMode:qe(t)||Fe(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:H,isLoadingMore:q,hasMoreHistory:K,loadError:z??void 0,emptyState:t.messages.length===0?t.connectionState==="connecting"||t.connectionState==="new"?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"})]})]}):t.status==="not_monitored"?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(hs,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]}):t.status==="panel_hidden"?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(on,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Panel is not visible in IDE"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent sidebar in your IDE to start viewing messages"})]}):t.status==="idle"&&!q?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..."})]}):void 0:void 0}),!qe(t)&&(()=>{var R,D,F,V;const w=s.find(y=>y.id===t.ideId);return e.jsx(gn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((D=(R=w==null?void 0:w.agents)==null?void 0:R[0])==null?void 0:D.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((V=(F=w==null?void 0:w.agents)==null?void 0:F[0])==null?void 0:V.name)||t.agentName,serverModel:(w==null?void 0:w.currentModel)||void 0,serverMode:(w==null?void 0:w.currentPlan)||void 0,acpConfigOptions:Fe(t)?w==null?void 0:w.acpConfigOptions:void 0,acpModes:Fe(t)?w==null?void 0:w.acpModes:void 0})})(),e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:u,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:w=>r(w.target.value),onPaste:w=>{const R=w.clipboardData.getData("text");R&&r(D=>D+R),w.preventDefault()},onKeyDown:w=>{if(w.key==="Enter"){if(w.nativeEvent.isComposing){w.preventDefault();return}w.preventDefault(),i()}},onBlur:w=>{if(window.innerWidth<768){const R=w.relatedTarget;if((R==null?void 0:R.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:i,disabled:!a.trim(),className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${a.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:a.trim()?{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:a.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const It=new Set,js={emit(t,s){for(const a of It)a(t,s)},on(t){return It.add(t),()=>{It.delete(t)}}};function bn({activeConv:t,ptyBuffers:s,terminalRef:a,agentInput:r,setAgentInput:i,handleSendChat:c,handleModalButton:o}){var h;const x=n.useRef(null),{sendCommand:m,sendData:p}=Je(),u=(h=t.ideId)!=null&&h.includes(":cli:")?t.ideId.split(":cli:")[1]:"",l=t.tabKey,N=t.ideType||t.agentType||"";return n.useEffect(()=>{const d=s.current.get(l);if(d&&d.length>0){const S=setTimeout(()=>{var T;for(const I of d)(T=a.current)==null||T.write(I);requestAnimationFrame(()=>{var I;(I=a.current)==null||I.bumpResize()})},100);return()=>clearTimeout(S)}},[l]),n.useEffect(()=>{const d=js.on((S,T)=>{var $;if(!T)return;(S===u||S===N)&&(($=a.current)==null||$.write(T))});return()=>{d()}},[u,N]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[var(--surface-primary)] border-b border-border-subtle shrink-0",children:[e.jsx("div",{className:"flex gap-1",children:e.jsx("div",{className:"px-3 py-1 rounded-md text-[11px] font-semibold bg-accent text-white",children:"⬛ Terminal"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[t.agentName," — Terminal"]}),e.jsx("button",{onClick:()=>{if(!a.current||!t)return;const d=s.current.get(t.tabKey);if(d&&d.length>0)for(const S of d)a.current.write(S);requestAnimationFrame(()=>{requestAnimationFrame(()=>{var S;(S=a.current)==null||S.bumpResize()})})},title:"Refresh terminal (replay buffer + TUI redraw)",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-bg-secondary text-text-secondary border border-border-subtle cursor-pointer leading-none",children:"↺"}),e.jsx("button",{onClick:async()=>{var T;const d=(T=t.ideId)!=null&&T.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";if(!window.confirm(`Stop ${d}?
|
|
28
28
|
This will terminate the CLI process.`))return;const S=t.ideId||t.daemonId||"";try{await m(S,"stop_cli",{cliType:d})}catch(I){console.error("Stop CLI failed:",I)}},title:"Stop CLI process",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-red-500/[0.08] text-red-400 border border-red-500/30 cursor-pointer leading-none font-semibold",children:"■ Stop"})]})]}),e.jsx(ys,{activeConv:t,onModalButton:o}),e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(bs,{ref:a,onInput:d=>{var I;const S=t.ideId||t.daemonId||"",T=(I=t.ideId)!=null&&I.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";p!=null&&p(S,{type:"pty_input",cliType:T,data:d})||m(S,"pty_input",{cliType:T,data:d}).catch(console.error)},onResize:(d,S)=>{var $;const T=t.ideId||t.daemonId||"",I=($=t.ideId)!=null&&$.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";p!=null&&p(T,{type:"pty_resize",cliType:I,cols:d,rows:S})||m(T,"pty_resize",{cliType:I,cols:d,rows:S,force:!0}).catch(()=>{})}},t.tabKey)}),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:x,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:r,onChange:d=>i(d.target.value),onPaste:d=>{const S=d.clipboardData.getData("text");S&&i(T=>T+S),d.preventDefault()},onKeyDown:d=>{if(d.key==="Enter"){if(d.nativeEvent.isComposing){d.preventDefault();return}d.preventDefault(),c()}},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:c,disabled:!r.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${r.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:r.trim()?{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:r.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function yn({wsStatus:t,showReconnected:s,loginUrl:a}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",c={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},o={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},x={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:c[i],borderBottom:o[i],color:x[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(a?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:a,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"]})]})}let vn=dt;function St(){return vn()}class jn{constructor(){$e(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,a){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(a),()=>{var r;(r=this.listeners.get(s))==null||r.delete(a)}}emit(s,...a){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...a))}}let wn=new jn;class Nn{constructor(){$e(this,"ptyCallbacks",new Set)}sendPtyInput(s,a,r){return!1}sendPtyResize(s,a,r,i){return!1}async requestChatHistory(s,a,r,i,c){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,a){return!1}get(s){}onScreenshot(s,a){return()=>{}}onStatusEvent(s){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,a){this.ptyCallbacks.forEach(r=>r(s,a))}}let Ae=new Nn,Gt=Ae;const Mt=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Tt=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function kn({activeConv:t,agentCount:s,wsStatus:a,isConnected:r,onOpenHistory:i}){const c=mt(),o=St(),x=o.p2pStates||{},m=o.ides||[],p=r?"#22c55e":a==="connected"?"#eab308":"#ef4444",u=r?"0 0 4px #22c55e80":a==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",l=m.filter(I=>I.type==="adhdev-daemon"),N=Object.values(x),h=N.filter(I=>I==="connected").length,d=N.filter(I=>I==="connecting"||I==="new"||I==="checking").length,T=a!=="connected"||l.length===0?null:d>0&&h===0?"P2P connecting...":h>0&&s===0?"Waiting for IDE...":null;return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"leading-tight",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(Nt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:p,boxShadow:u}})})]}),e.jsxs("div",{className:"header-subtitle text-[11px] items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":a==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:p,boxShadow:u}}),T&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",T]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&!Mt(t)&&!Tt(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(fs,{size:14})," IDE"]}),t&&!Mt(t)&&!Tt(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(nn,{size:16})}),t&&!Mt(t)&&!Tt(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(xt,{size:16})})]})]})}function Oe(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Sn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const a=Math.floor(s/60),r=s%60;if(a<24)return r>0?`${a}h ${r}m`:`${a}h`;const i=Math.floor(a/24),c=a%24;return`${i}d ${c}h`}function Vt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function qt(t){return(t.id||"").includes(":cli:")}function Jt(t){return(t.id||"").includes(":acp:")}function Lt(t,s){return Oe(t)}function Cn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,a=["generating","streaming","active","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(i);if(!c){s.set(i,r);continue}const o=a.indexOf(c.status||"idle"),x=a.indexOf(r.status||"idle");x>=0&&(o<0||x<o)&&s.set(i,r)}return Array.from(s.values())}function In({activeConv:t,ides:s,isCreatingChat:a,isRefreshingHistory:r,onClose:i,onNewChat:c,onSwitchSession:o,onRefreshHistory:x}){var l;const m=s.find(N=>N.id===t.ideId),p=(m==null?void 0:m.chats)||[],u=(l=m==null?void 0:m.activeChat)==null?void 0:l.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Oe(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:c,disabled:a,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:a?"⌛ Creating...":"+ Start New Chat Session"}),p.map(N=>e.jsxs("div",{onClick:()=>{o(t.ideId,N.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${u===N.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 ${u===N.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:N.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:[N.id.substring(0,12),"..."]}),u===N.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},N.id)),p.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(pn,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:x,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(an,{size:13})," Refresh History"]})})})]})]})}const Zt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Mn({toasts:t,onDismiss:s,onClickToast:a}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(r=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px]",style:{background:Zt[r.type]||Zt.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(a&&a(r),s(r.id))},children:[e.jsx("div",{children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:o=>{o.stopPropagation(),i.onClick(),s(r.id)},children:i.label},c))})]},r.id))})}const Tn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function En(t){return t.workspace||""}function $n(t,s,a,r){var c;const i={};if(a)for(const o of a){const x=o;if(x.type==="adhdev-daemon"||x.daemonMode){const m=x.machine||{},p=x.machineNickname,u=m.hostname||((c=x.system)==null?void 0:c.hostname)||"",l=p||(u&&u!=="Unknown"?u.replace(/\.local$/,""):null)||`Machine ${(x.id||"").substring(0,6)}`;i[x.id]=l}}return t.flatMap(o=>{var $,K,z,q,ie;const x=[],m=o.daemonId&&i[o.daemonId]||void 0,p=o.daemonId||(($=o.id)==null?void 0:$.split(":")[0])||o.id,u=r?r[p]||"new":void 0,l=En(o),N=Oe(o.type),h=o.agentStreams,d=Array.isArray(h)?h.map(H=>({...H,activeModal:H.activeModal??void 0})):[],S=Tn(o),T=o.activeChat||{title:""},I=T.title&&String(T.title).trim()?String(T.title).trim():"";if(S){const H=Lt(o.type),Q=(K=o.agents)==null?void 0:K[0],w=(z=o.activeChat)==null?void 0:z.activeModal,R=w&&Array.isArray(w.buttons)&&w.buttons.length>0,D=(q=o.activeChat)==null?void 0:q.status,F=D==="generating"||D==="loading"||D&&D.toLowerCase()==="thinking",y=R||D==="waiting_approval"?"waiting_approval":F?"working":(Q==null?void 0:Q.status)||"idle",U=o.activeChat||{title:"",messages:[]};let ee=U.title&&String(U.title).trim()?String(U.title).trim():"";const Y=(ie=o.activeChat)==null?void 0:ie.id,Z=o.chats;if(Y&&Array.isArray(Z)&&Z.length>0){const ne=Z.find(P=>P.id===Y||P.id&&String(P.id)===String(Y));ne!=null&&ne.title&&String(ne.title).trim()&&(ee=String(ne.title).trim())}const B=U.messages||[],oe=s[o.id]||[],te=new Map;B.filter(ne=>ne.role==="user").forEach(ne=>{te.set(ne.content,(te.get(ne.content)||0)+1)});const se=oe.filter(ne=>{const P=te.get(ne.content)||0;return P>0?(te.set(ne.content,P-1),!1):!0});x.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:H,agentType:qe(o)||Fe(o)?o.type:(Q==null?void 0:Q.type)||"ide-native",status:y,title:ee,messages:[...B,...se],ideType:o.type,workspaceName:l,displayPrimary:ee||l||H,displaySecondary:N,cdpConnected:o.cdpConnected,modalButtons:R?w.buttons:void 0,modalMessage:R?w.message:void 0,streamSource:"native",tabKey:o.id,machineName:m,connectionState:u})}if(S&&(qe(o)||Fe(o)))return x;for(const H of d){const Q=H.activeModal&&Array.isArray(H.activeModal.buttons)&&H.activeModal.buttons.length>0,w=Q?"waiting_approval":H.status==="streaming"?"working":H.status,R=`${o.id}:${H.agentType}`,D=H.messages||[],F=s[R]||[],V=new Map;D.filter(U=>U.role==="user").forEach(U=>{V.set(U.content,(V.get(U.content)||0)+1)});const y=F.filter(U=>{const ee=V.get(U.content)||0;return ee>0?(V.set(U.content,ee-1),!1):!0});x.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:H.agentName,agentType:H.agentType,status:w,title:"",messages:[...D,...y],ideType:H.agentType,workspaceName:l,displayPrimary:I||l||H.agentName,displaySecondary:`${N}·${H.agentName}`,cdpConnected:o.cdpConnected,modalButtons:Q?H.activeModal.buttons:void 0,modalMessage:Q?H.activeModal.message:void 0,streamSource:"agent-stream",tabKey:R,machineName:m,connectionState:u})}return x.length===0&&x.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:Lt(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:l,displayPrimary:l||N,displaySecondary:N,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:u}),x})}function _n(t,s){var x,m,p,u;const a=[],{daemonId:r,existingDaemon:i,timestamp:c}=s,o=c||t.timestamp||Date.now();a.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:o,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},..."system"in t&&{system:t.system},..."hostname"in t&&{hostname:t.hostname},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:t.managedIdes.some(l=>l.cdpConnected),managedIdeIds:t.managedIdes.map(l=>`${r}:ide:${l.instanceId}`),managedCliIds:t.managedClis.map(l=>l.id?`${r}:cli:${l.id}`:`${r}:cli:${l.cliType}`),managedAcpIds:t.managedAcps.map(l=>l.id?`${r}:acp:${l.id}`:`${r}:acp:${l.acpType}`)});for(const l of t.managedIdes)a.push({id:`${r}:ide:${l.instanceId}`,type:l.ideType,ideType:l.ideType,version:l.ideVersion,status:l.cdpConnected?"online":"detected",daemonId:r,instanceId:l.instanceId,workspace:l.workspace,terminals:l.terminals,agents:l.aiAgents,activeChat:l.activeChat,chats:l.chats,agentStreams:l.agentStreams,cdpConnected:l.cdpConnected,currentModel:l.currentModel,currentPlan:l.currentPlan,currentAutoApprove:l.currentAutoApprove,timestamp:o});for(const l of t.managedClis){const N=l.id?`${r}:cli:${l.id}`:`${r}:cli:${l.cliType}`;a.push({id:N,type:l.cliType,ideType:l.cliType,agentType:l.cliType,status:l.status||"running",daemonId:r,instanceId:l.id,cliName:l.cliName,mode:l.mode||"terminal",workspace:l.workspace,activeChat:l.activeChat,agentStreams:[{agentType:l.cliType,agentName:l.cliName,extensionId:"cli-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((x=l.activeChat)==null?void 0:x.messages)||[],inputContent:"",activeModal:(m=l.activeChat)==null?void 0:m.activeModal}],timestamp:o,_isCli:!0})}for(const l of t.managedAcps){const N=l.id?`${r}:acp:${l.id}`:`${r}:acp:${l.acpType}`;a.push({id:N,type:l.acpType,ideType:l.acpType,agentType:l.acpType,status:l.status||"running",daemonId:r,instanceId:l.id,cliName:l.acpName,mode:"chat",workspace:l.workspace,activeChat:l.activeChat,currentModel:l.currentModel,currentPlan:l.currentPlan,acpConfigOptions:l.acpConfigOptions,acpModes:l.acpModes,agentStreams:[{agentType:l.acpType,agentName:l.acpName,extensionId:"acp-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((p=l.activeChat)==null?void 0:p.messages)||[],inputContent:"",activeModal:(u=l.activeChat)==null?void 0:u.activeModal}],timestamp:o,_isAcp:!0})}return a}const ws="adhdev_notification_prefs",Qt={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function An(){try{const t=localStorage.getItem(ws);if(t){const s=JSON.parse(t);return{...Qt,...s}}}catch{}return{...Qt}}function Rn(t){try{localStorage.setItem(ws,JSON.stringify(t))}catch{}}let Xe=An(),yt=[];function Pn(){yt.forEach(t=>t())}function Ln(t){Xe={...Xe,...t},Rn(Xe),Pn()}function Dn(){const[,t]=n.useState(0);n.useEffect(()=>{const a=()=>t(r=>r+1);return yt.push(a),()=>{yt=yt.filter(r=>r!==a)}},[]);const s=n.useCallback(a=>{Ln(a)},[]);return[{...Xe},s]}function it(t){if(!Xe.globalEnabled)return!1;switch(t){case"disconnect":return Xe.disconnectAlert;case"completion":return Xe.completionAlert;case"approval":return Xe.approvalAlert;case"browser":return Xe.browserNotifications;default:return!0}}const Bn={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Wn(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Ns(){return"Notification"in window&&Notification.permission==="granted"}let Ze=null;async function On(){if(Ze!==null)return Ze;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Ze=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Ze=!!await t.pushManager.getSubscription(),Ze):(Ze=!1,!1)}catch{return Ze=!1,!1}}function Dt(t,s,a){if(Ns())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:a||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function Kn(t,s={}){const a={...Bn,...s},r=n.useRef(new Map),i=n.useRef(0),c=n.useRef(null);n.useEffect(()=>{On().then(x=>{c.current=x})},[]);const o=n.useCallback((x,m,p)=>{const u=Date.now();u-i.current<a.throttleMs||(i.current=u,Dt(x,m,p))},[a.throttleMs]);n.useEffect(()=>{var x;if(!(!a.enabled||!Ns())&&it("browser")&&c.current!==!0){if(document.hasFocus()){for(const m of t)r.current.set(m.id,m.status||"idle");return}for(const m of t){const p=r.current.get(m.id),u=m.status||"idle",l=m.name||m.id;if(a.onApproval&&it("approval")&&u==="waiting_approval"&&p!=="waiting_approval"){const N=((x=m.activeModal)==null?void 0:x.message)||"Action requires your approval";o(`🔔 ${l} — Approval needed`,N.slice(0,120),`approval-${m.id}`)}a.onComplete&&it("completion")&&p==="generating"&&u==="idle"&&o(`✅ ${l} — Task complete`,"Agent has finished working",`complete-${m.id}`),a.onError&&u==="error"&&p!=="error"&&o(`⚠️ ${l} — Error`,"Agent encountered an error",`error-${m.id}`),r.current.set(m.id,u)}}},[t,a.enabled,a.onApproval,a.onComplete,a.onError,o])}class Fn{constructor(){$e(this,"dedupMap",new Map);$e(this,"DEDUP_WINDOW_MS",5e3);$e(this,"DEDUP_MAX_SIZE",50);$e(this,"DEDUP_CLEANUP_AGE_MS",1e4);$e(this,"toastCallbacks",[]);$e(this,"systemMessageCallbacks",[]);$e(this,"clearSystemMessageCallbacks",[]);$e(this,"resolveActionFn",null);$e(this,"viewRequestRespondFn",null);$e(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(a=>a!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(a=>a!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(a=>a!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const a of this.toastCallbacks)a(s)}emitSystemMessage(s,a){for(const r of this.systemMessageCallbacks)r(s,a)}emitClearSystemMessage(s,a){for(const r of this.clearSystemMessageCallbacks)r(s,a)}isDuplicate(s){const a=Date.now(),r=this.dedupMap.get(s)||0;if(a-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,a),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,c]of this.dedupMap)a-c>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveRouteId(s,a){for(const r of this.ides)if(r.id.startsWith(s)&&(!a||a===r.type))return r.id;return s}handleRawEvent(s,a){var x,m;const r=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(r))return;if(!s.ideId&&s.instanceId){for(const p of this.ides)if(p.id.endsWith(`:ide:${s.instanceId}`)||p.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=p.id;break}}const i=Oe(s.ideType||"");let c="",o="info";if(s.event==="agent:generating_completed"){const p=s.duration?` (${s.duration}s)`:"";c=`✅ ${i} agent task completed${p}`,o="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${p}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(c=`⚡ ${i} approval needed`,o="warning",s.ideId){const p=s.modalMessage||"Approval requested",u=(x=s.modalButtons)!=null&&x.length?s.modalButtons.map(l=>`[${l}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${p}
|
|
29
|
-
${u}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((m=s.modalButtons)!=null&&m.length)&&this.resolveActionFn){const p=s.ideId,u=s.agentType||s.ideType||"",l=s.ideType||"",N=s.modalButtons,h=$=>$.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),d=this.resolveActionFn,S=N.map(($,K)=>{const z=h($).toLowerCase(),q=/^(run|approve|accept|yes|allow|always)/.test(z),ie=/^(reject|deny|delete|remove|abort|cancel|no)/.test(z);return{label:h($),variant:q?"primary":ie?"danger":"default",onClick:()=>{const H=this.resolveRouteId(p,u),Q=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(z);d(H,"resolve_action",{action:Q?"approve":"reject",button:$,buttonIndex:K,agentType:u,ideType:l})}}}),T=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,I=Date.now();this.emitToast({id:I,message:T,type:o,timestamp:I,ideId:p,actions:S,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const p=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${p}`,o="warning",it("browser")&&!document.hasFocus()&&Dt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${p.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const p=s.requesterName||"A team member",u=s.requestId,l=s.orgId;if(c=`👁️ ${p} wants to view your session`,o="warning",u&&l&&this.viewRequestRespondFn){const N=this.viewRequestRespondFn,h=Date.now(),d=[{label:"Approve",variant:"primary",onClick:()=>{N(l,u,"approve").catch(S=>console.error("[EventManager] approve view request failed:",S))}},{label:"Decline",variant:"danger",onClick:()=>{N(l,u,"reject").catch(S=>console.error("[EventManager] reject view request failed:",S))}}];this.emitToast({id:h,message:c,type:o,timestamp:h,actions:d,duration:3e4}),c=""}it("browser")&&!document.hasFocus()&&Dt("👁️ View Request",`${p} wants to view your session`,`view-request-${u}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",o="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,o="warning");if(c){const p=Date.now();this.emitToast({id:p,message:c,type:o,timestamp:p,ideId:s.ideId,duration:5e3})}}}const Qe=new Fn;function ut(...t){return Ls(Ds(t))}function Hn({icon:t,title:s,subtitle:a,badge:r,actions:i,className:c}){return e.jsxs("div",{className:ut("flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-surface-primary animate-[fadeIn_0.3s_ease-out_forwards]",c),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg font-bold text-text-primary flex items-center gap-2.5 tracking-tight",children:[e.jsx("span",{children:t})," ",s,r&&e.jsxs("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),a&&e.jsx("p",{className:"hidden sm:block text-[13px] text-text-muted mt-1",children:a})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function nt({title:t,icon:s,description:a,accentColor:r,className:i,children:c}){return e.jsxs("div",{className:ut("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||a)&&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]}),a&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:a})]}),c]})}function zn({icon:t,title:s,description:a,action:r,className:i}){return e.jsxs("div",{className:ut("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:a}),r]})}const Un={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"},Yn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Xn({status:t,label:s,className:a}){const r=s||t;return e.jsxs("span",{className:ut("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Un[t],a),children:[e.jsx("span",{className:ut("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Yn[t])}),r]})}function Gn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function es(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Et(t){return t==="system"?Gn():t}function Vn(){const[t,s]=n.useState(es),[a,r]=n.useState(()=>Et(es()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",a)},[a]),n.useEffect(()=>{const o=window.matchMedia("(prefers-color-scheme: light)"),x=m=>{t==="system"&&r(m.matches?"light":"dark")};return o.addEventListener("change",x),()=>o.removeEventListener("change",x)},[t]);const i=n.useCallback(o=>{s(o),r(Et(o));try{localStorage.setItem("theme",o)}catch{}},[]),c=n.useCallback(()=>{s(o=>{const x=o==="dark"?"light":o==="light"?"system":"dark";r(Et(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:a,preference:t,setPreference:i,cycleTheme:c,isDark:a==="dark"}}function rt({label:t,description:s,checked:a,disabled:r,onChange:i,extra:c}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c,e.jsx("input",{type:"checkbox",checked:a,disabled:r,onChange:o=>i(o.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function qn({onPrefChange:t}){const[s,a]=Dn(),r=(i,c)=>{a({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(rt,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(rt,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(rt,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(rt,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(rt,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Jn({ides:t,emptyMessage:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){const c=t.filter(o=>o.type==="adhdev-daemon");return c.length===0?e.jsx(zn,{icon:"🔌",title:"No machines connected",description:s||"Run 'adhdev daemon' on your machine to connect."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(o=>e.jsx(er,{ide:o,allIdes:t,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i},o.id))})}function ts({title:t,message:s,confirmLabel:a,confirmColor:r,onConfirm:i,onCancel:c}){const o=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return Bs.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:x=>x.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:c,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${o}`,children:a})]})]})}),document.body)}const Zn={vscode:{icon:"💠",name:"VS Code"},cursor:{icon:"⚡",name:"Cursor"},windsurf:{icon:"🏄",name:"Windsurf"},codex:{icon:"🤖",name:"Codex"},"claude-code":{icon:"🟠",name:"Claude Code"},aider:{icon:"🔧",name:"Aider"}};function Qn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase();return Zn[s]||{icon:"📝",name:t}}function er({ide:t,allIdes:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){var U,ee,Y,Z;const[c,o]=n.useState("idle"),[x,m]=n.useState(""),[p,u]=n.useState(null),[l,N]=n.useState("idle"),[h,d]=n.useState(""),S=t,T=S.version||S.daemonVersion||null,I=((U=S.machine)==null?void 0:U.hostname)||((ee=S.system)==null?void 0:ee.hostname)||"",$=((Y=S.machine)==null?void 0:Y.platform)||((Z=S.system)==null?void 0:Z.platform)||"",K=S.machineNickname||(I==null?void 0:I.replace(/\.local$/,""))||"Machine",z=$==="win32"?"🪟":$==="darwin"?"🍎":"🐧",q=s.filter(B=>B.daemonId===t.id&&B.id.includes(":ide:")),ie=s.filter(B=>B.daemonId===t.id&&B.id.includes(":cli:")),H=s.filter(B=>B.daemonId===t.id&&B.id.includes(":acp:")),Q=S.p2p,w=async()=>{var B,oe,te;if(a){o("upgrading"),m("Installing latest version...");try{const se=await a(t.id,"daemon_upgrade",{});(B=se==null?void 0:se.result)!=null&&B.upgraded||(oe=se==null?void 0:se.result)!=null&&oe.success?(o("done"),m(`Upgraded to v${se.result.version||"latest"}. Daemon is restarting...`)):(o("error"),m(((te=se==null?void 0:se.result)==null?void 0:te.error)||"Upgrade failed"))}catch(se){o("error"),m((se==null?void 0:se.message)||"Connection lost during upgrade")}}},R=async()=>{if(u(null),!!r){N("loading");try{await r(t.id),N("done"),d("Machine disconnected.")}catch(B){N("error"),d((B==null?void 0:B.message)||"Failed to disconnect")}}},D=async()=>{if(u(null),!!i){N("loading");try{await i(t.id),N("done"),d('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(B){N("error"),d((B==null?void 0:B.message)||"Failed to revoke token")}}},F="0.6.18",V=!T||T!==F,y=q.length+ie.length+H.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:z}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:K}),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),"…"]}),T&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${V?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",T,!V&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&V&&e.jsx("button",{onClick:w,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${F}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${F}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:l==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:l==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Revoke token (requires re-setup)",children:"Revoke"}),e.jsx(Xn,{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:[Q&&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 ${Q.state==="connected"?"bg-green-400":Q.state==="connecting"||Q.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",Q.state==="connected"?"connected":Q.state==="connecting"||Q.state==="new"?"connecting...":Q.state||"off"]}),Q.peers!==void 0&&Q.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",Q.peers," peer",Q.peers!==1?"s":"",")"]})]}),Q&&y>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),y>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[q.map(B=>{const oe=Qn(B.type),te=B.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:oe.icon}),e.jsx("span",{children:oe.name}),te!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${te?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:te?"CDP connected":"CDP connecting..."})]},B.id)}),ie.map(B=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:B.cliName||"CLI"})]},B.id)),H.map(B=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:B.cliName||"ACP"})]},B.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||h)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||l==="error"?"text-red-400":c==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:h||x})]}),p==="disconnect"&&e.jsx(ts,{title:"🔌 Disconnect Machine",message:`Disconnect "${K}" from ADHDev?
|
|
29
|
+
${u}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((m=s.modalButtons)!=null&&m.length)&&this.resolveActionFn){const p=s.ideId,u=s.agentType||s.ideType||"",l=s.ideType||"",N=s.modalButtons,h=$=>$.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),d=this.resolveActionFn,S=N.map(($,K)=>{const z=h($).toLowerCase(),q=/^(run|approve|accept|yes|allow|always)/.test(z),ie=/^(reject|deny|delete|remove|abort|cancel|no)/.test(z);return{label:h($),variant:q?"primary":ie?"danger":"default",onClick:()=>{const H=this.resolveRouteId(p,u),Q=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(z);d(H,"resolve_action",{action:Q?"approve":"reject",button:$,buttonIndex:K,agentType:u,ideType:l})}}}),T=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,I=Date.now();this.emitToast({id:I,message:T,type:o,timestamp:I,ideId:p,actions:S,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const p=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${p}`,o="warning",it("browser")&&!document.hasFocus()&&Dt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${p.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const p=s.requesterName||"A team member",u=s.requestId,l=s.orgId;if(c=`👁️ ${p} wants to view your session`,o="warning",u&&l&&this.viewRequestRespondFn){const N=this.viewRequestRespondFn,h=Date.now(),d=[{label:"Approve",variant:"primary",onClick:()=>{N(l,u,"approve").catch(S=>console.error("[EventManager] approve view request failed:",S))}},{label:"Decline",variant:"danger",onClick:()=>{N(l,u,"reject").catch(S=>console.error("[EventManager] reject view request failed:",S))}}];this.emitToast({id:h,message:c,type:o,timestamp:h,actions:d,duration:3e4}),c=""}it("browser")&&!document.hasFocus()&&Dt("👁️ View Request",`${p} wants to view your session`,`view-request-${u}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",o="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,o="warning");if(c){const p=Date.now();this.emitToast({id:p,message:c,type:o,timestamp:p,ideId:s.ideId,duration:5e3})}}}const Qe=new Fn;function ut(...t){return Ls(Ds(t))}function Hn({icon:t,title:s,subtitle:a,badge:r,actions:i,className:c}){return e.jsxs("div",{className:ut("flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-surface-primary animate-[fadeIn_0.3s_ease-out_forwards]",c),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg font-bold text-text-primary flex items-center gap-2.5 tracking-tight",children:[e.jsx("span",{children:t})," ",s,r&&e.jsxs("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),a&&e.jsx("p",{className:"hidden sm:block text-[13px] text-text-muted mt-1",children:a})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function nt({title:t,icon:s,description:a,accentColor:r,className:i,children:c}){return e.jsxs("div",{className:ut("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||a)&&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]}),a&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:a})]}),c]})}function zn({icon:t,title:s,description:a,action:r,className:i}){return e.jsxs("div",{className:ut("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:a}),r]})}const Un={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"},Yn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Xn({status:t,label:s,className:a}){const r=s||t;return e.jsxs("span",{className:ut("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Un[t],a),children:[e.jsx("span",{className:ut("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Yn[t])}),r]})}function Gn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function es(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Et(t){return t==="system"?Gn():t}function Vn(){const[t,s]=n.useState(es),[a,r]=n.useState(()=>Et(es()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",a)},[a]),n.useEffect(()=>{const o=window.matchMedia("(prefers-color-scheme: light)"),x=m=>{t==="system"&&r(m.matches?"light":"dark")};return o.addEventListener("change",x),()=>o.removeEventListener("change",x)},[t]);const i=n.useCallback(o=>{s(o),r(Et(o));try{localStorage.setItem("theme",o)}catch{}},[]),c=n.useCallback(()=>{s(o=>{const x=o==="dark"?"light":o==="light"?"system":"dark";r(Et(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:a,preference:t,setPreference:i,cycleTheme:c,isDark:a==="dark"}}function rt({label:t,description:s,checked:a,disabled:r,onChange:i,extra:c}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c,e.jsx("input",{type:"checkbox",checked:a,disabled:r,onChange:o=>i(o.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function qn({onPrefChange:t}){const[s,a]=Dn(),r=(i,c)=>{a({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(rt,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(rt,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(rt,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(rt,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(rt,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Jn({ides:t,emptyMessage:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){const c=t.filter(o=>o.type==="adhdev-daemon");return c.length===0?e.jsx(zn,{icon:"🔌",title:"No machines connected",description:s||"Run 'adhdev daemon' on your machine to connect."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(o=>e.jsx(er,{ide:o,allIdes:t,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i},o.id))})}function ts({title:t,message:s,confirmLabel:a,confirmColor:r,onConfirm:i,onCancel:c}){const o=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return Bs.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:x=>x.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:c,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${o}`,children:a})]})]})}),document.body)}const Zn={vscode:{icon:"💠",name:"VS Code"},cursor:{icon:"⚡",name:"Cursor"},windsurf:{icon:"🏄",name:"Windsurf"},codex:{icon:"🤖",name:"Codex"},"claude-code":{icon:"🟠",name:"Claude Code"},aider:{icon:"🔧",name:"Aider"}};function Qn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase();return Zn[s]||{icon:"📝",name:t}}function er({ide:t,allIdes:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){var U,ee,Y,Z;const[c,o]=n.useState("idle"),[x,m]=n.useState(""),[p,u]=n.useState(null),[l,N]=n.useState("idle"),[h,d]=n.useState(""),S=t,T=S.version||S.daemonVersion||null,I=((U=S.machine)==null?void 0:U.hostname)||((ee=S.system)==null?void 0:ee.hostname)||"",$=((Y=S.machine)==null?void 0:Y.platform)||((Z=S.system)==null?void 0:Z.platform)||"",K=S.machineNickname||(I==null?void 0:I.replace(/\.local$/,""))||"Machine",z=$==="win32"?"🪟":$==="darwin"?"🍎":"🐧",q=s.filter(B=>B.daemonId===t.id&&B.id.includes(":ide:")),ie=s.filter(B=>B.daemonId===t.id&&B.id.includes(":cli:")),H=s.filter(B=>B.daemonId===t.id&&B.id.includes(":acp:")),Q=S.p2p,w=async()=>{var B,oe,te;if(a){o("upgrading"),m("Installing latest version...");try{const se=await a(t.id,"daemon_upgrade",{});(B=se==null?void 0:se.result)!=null&&B.upgraded||(oe=se==null?void 0:se.result)!=null&&oe.success?(o("done"),m(`Upgraded to v${se.result.version||"latest"}. Daemon is restarting...`)):(o("error"),m(((te=se==null?void 0:se.result)==null?void 0:te.error)||"Upgrade failed"))}catch(se){o("error"),m((se==null?void 0:se.message)||"Connection lost during upgrade")}}},R=async()=>{if(u(null),!!r){N("loading");try{await r(t.id),N("done"),d("Machine disconnected.")}catch(B){N("error"),d((B==null?void 0:B.message)||"Failed to disconnect")}}},D=async()=>{if(u(null),!!i){N("loading");try{await i(t.id),N("done"),d('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(B){N("error"),d((B==null?void 0:B.message)||"Failed to revoke token")}}},F="0.6.19",V=!T||T!==F,y=q.length+ie.length+H.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:z}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:K}),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),"…"]}),T&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${V?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",T,!V&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&V&&e.jsx("button",{onClick:w,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${F}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${F}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:l==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:l==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Revoke token (requires re-setup)",children:"Revoke"}),e.jsx(Xn,{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:[Q&&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 ${Q.state==="connected"?"bg-green-400":Q.state==="connecting"||Q.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",Q.state==="connected"?"connected":Q.state==="connecting"||Q.state==="new"?"connecting...":Q.state||"off"]}),Q.peers!==void 0&&Q.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",Q.peers," peer",Q.peers!==1?"s":"",")"]})]}),Q&&y>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),y>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[q.map(B=>{const oe=Qn(B.type),te=B.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:oe.icon}),e.jsx("span",{children:oe.name}),te!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${te?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:te?"CDP connected":"CDP connecting..."})]},B.id)}),ie.map(B=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:B.cliName||"CLI"})]},B.id)),H.map(B=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:B.cliName||"ACP"})]},B.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||h)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||l==="error"?"text-red-400":c==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:h||x})]}),p==="disconnect"&&e.jsx(ts,{title:"🔌 Disconnect Machine",message:`Disconnect "${K}" 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
|
|
|
@@ -55,4 +55,4 @@ Use this if you accidentally set up on a shared/public computer and want to ensu
|
|
|
55
55
|
}
|
|
56
56
|
`}),p&&e.jsx(br,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}u(!1)}})]})}function vr(t){return t.split(":")[0]||""}function jr({renderHeaderActions:t}={}){var ge,Se,he;const{id:s}=ls(),a=mt(),r=St(),i=r.ides||[],c=r.connectionStates||{},{sendCommand:o}=Je(),x=n.useMemo(()=>vr(s||""),[s]),m=n.useMemo(()=>i.find(M=>M.id===s),[i,s]),p=(m==null?void 0:m.type)||void 0,u=p?p.charAt(0).toUpperCase()+p.slice(1):"IDE",l=(m==null?void 0:m.activeChat)||null,N=(m==null?void 0:m.agentStreams)||[],h=r.isConnected??!0,d=c[x]||(h?"connected":"new"),S=n.useMemo(()=>i.find(M=>M.id===x||M.daemonId===x),[i,x]),T=(S==null?void 0:S.machineNickname)||((ge=S==null?void 0:S.machine)==null?void 0:ge.hostname)||"",I=(m==null?void 0:m.workspace)||"",[$]=cs(),K=typeof window<"u"&&window.innerWidth<=768,z=$.get("view")||(K?"chat":"split"),[q,ie]=n.useState(z),[H,Q]=n.useState("native"),[w,R]=n.useState(""),[D,F]=n.useState(!1),[V,y]=n.useState(null),[U,ee]=n.useState(null),[Y,Z]=n.useState([]),B=l==null?void 0:l.status,oe=(((he=(Se=l==null?void 0:l.activeModal)==null?void 0:Se.buttons)==null?void 0:he.length)??0)>0,te=B==="generating"||B==="loading"||B&&B.toLowerCase()==="thinking",ne=oe||B==="waiting_approval"?"waiting_approval":te?"working":B||"idle",P=n.useMemo(()=>{var M,J;return{ideId:s||"",daemonId:x,agentName:Lt(p||""),agentType:p||"",status:ne,title:(l==null?void 0:l.title)||"",messages:(l==null?void 0:l.messages)||[],ideType:p||"",workspaceName:(m==null?void 0:m.workspaceName)||"",displayPrimary:u,displaySecondary:(m==null?void 0:m.workspaceName)||"",cdpConnected:!0,modalButtons:(M=l==null?void 0:l.activeModal)==null?void 0:M.buttons,modalMessage:(J=l==null?void 0:l.activeModal)==null?void 0:J.message,streamSource:"native",tabKey:`ide-${s}`}},[s,x,p,l,m,u,ne]),b=n.useMemo(()=>N.map(M=>{var ue,xe;const J=M.activeModal?"waiting_approval":M.status==="streaming"?"working":M.status||"idle";return{ideId:s||"",daemonId:x,agentName:M.agentName,agentType:M.agentType,status:J,title:"",messages:M.messages.map((le,Ne)=>({role:le.role,content:le.content,kind:le.kind,id:`${M.agentType}-${Ne}`,receivedAt:le.timestamp})),ideType:M.agentType,workspaceName:"",displayPrimary:M.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(ue=M.activeModal)==null?void 0:ue.buttons,modalMessage:(xe=M.activeModal)==null?void 0:xe.message,streamSource:"agent-stream",tabKey:`agent-stream-${M.agentType}`}}),[N,s,x]),_=n.useMemo(()=>H==="native"?P:b.find(M=>M.agentType===H)||P,[H,P,b]);n.useEffect(()=>x?Ae.onScreenshot("ide-page",(J,ue)=>{if(J!==x)return;const xe=new FileReader;xe.onload=()=>y(xe.result),xe.readAsDataURL(ue)}):void 0,[x]),n.useEffect(()=>x?Ae.onStatusEvent((J,ue)=>{if(J!==x)return;let xe="",le="info";if(ue.event==="agent:generating_completed"?(xe=`✅ Task completed${ue.duration?` (${ue.duration}s)`:""}`,le="success"):ue.event==="agent:waiting_approval"&&(xe="⚡ Approval needed",le="warning"),xe){const Ne=Date.now();Z(ke=>[...ke.slice(-4),{id:Ne,message:xe,type:le}]),setTimeout(()=>Z(ke=>ke.filter(Pe=>Pe.id!==Ne)),le==="warning"?1e4:5e3)}}):void 0,[x]);const g=n.useMemo(()=>{if(!s)return p;const M=s.split(":");return M.length>=3&&M[1]==="ide"?M.slice(2).join(":"):p},[s,p]);n.useEffect(()=>{const M=x?Ae.get(x):null;!M||!(d==="connected")||(q!=="chat"&&g?M.startScreenshots(g):M.stopScreenshots(g))},[q,d,g,x]);const W=n.useCallback(async(M,J={})=>{if(!s)throw new Error("No IDE ID");const ue={...J};if(!ue._targetInstance&&s){const le=s.split(":");le.length>=3&&(le[1]==="ide"||le[1]==="cli")&&(ue._targetInstance=le.slice(2).join(":"),ue._targetType=le[1])}const xe=x?Ae.get(x):null;return xe!=null&&xe.hasCommandChannel?await xe.sendCommand(M,ue):xe&&xe.connectionState!=="failed"&&xe.connectionState!=="closed"&&await new Promise(Ne=>{const Re=Date.now(),ke=()=>{if(xe.hasCommandChannel)return Ne(!0);if(Date.now()-Re>3e3)return Ne(!1);setTimeout(ke,200)};ke()})&&xe.hasCommandChannel?await xe.sendCommand(M,ue):await o(s,M,ue)},[s,x]),G=async()=>{const M=w.trim();if(!(!M||!s||D)){R(""),F(!0);try{await W("send_chat",{message:M,text:M,waitForResponse:!0,...H!=="native"&&{agentType:H}})}catch(J){console.error("[IDE] Send failed:",J)}finally{F(!1)}}},pe=async M=>{if(s)try{const J=await o(s,"screenshot",{width:M?Math.min(M,1280):1280});J!=null&&J.success&&(J!=null&&J.base64)&&ee(`data:image/jpeg;base64,${J.base64}`)}catch(J){console.error("[IDE] Screenshot failed:",J)}},be=N.length>0;return s?e.jsxs("div",{className:"ide-page",children:[e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(Nt,{size:16}),e.jsx("span",{className:"ide-name",children:u}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),I&&e.jsx("span",{className:"ide-workspace",children:I}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${d==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:d==="connected"?"Connected":d==="connecting"?"Connecting":"WS"})]}),T&&e.jsx("span",{className:"ide-machine-label",children:T})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(M=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:q===M?"1px solid var(--accent-primary)":"none",background:q===M?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:q===M?"var(--accent-primary)":void 0},onClick:()=>ie(M),children:M==="chat"?e.jsx(Nt,{size:14}):M==="split"?"⊞":e.jsx(xt,{size:14})},M)),t&&t({daemonId:x,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>a(-1),children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${q==="chat"?"full":""} ${q==="remote"?"hidden":""}`,children:[be&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${H==="native"?"active":""}`,onClick:()=>Q("native"),children:u}),N.map(M=>{const J=H===M.agentType,ue=M.status==="waiting_approval"||!!M.activeModal,xe=M.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${J?"active":""}`,onClick:()=>Q(M.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ue?"#f59e0b":xe?"var(--accent-primary)":"#64748b",boxShadow:xe?"0 0 6px var(--accent-primary)":"none"}}),M.agentName,ue&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},M.agentType)})]}),e.jsx(vs,{activeConv:_,ides:i,agentInput:w,setAgentInput:R,handleSendChat:G,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${q==="remote"?"full":""} ${q==="chat"?"hidden":""}`,children:e.jsx(hn,{screenshot:U,isCapturing:!1,onRefresh:pe,addLog:()=>{},connState:d,connScreenshot:V,onAction:async(M,J)=>{const ue=x?Ae.get(x):null;if(!ue||d!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const xe=(m==null?void 0:m.instanceId)||g;return await ue.sendInput(M,J,xe)}})})]}),Y.length>0&&e.jsx("div",{className:"ide-toasts",children:Y.map(M=>e.jsx("div",{className:`ide-toast ${M.type}`,onClick:()=>Z(J=>J.filter(ue=>ue.id!==M.id)),children:M.message},M.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function wr({machineId:t,sendDaemonCommand:s,logsEndRef:a}){const[r,i]=n.useState([]),[c,o]=n.useState(null),[x,m]=n.useState(!1),[p,u]=n.useState(!1),[l,N]=n.useState(!1),[h,d]=n.useState([]),[S,T]=n.useState([]),[I,$]=n.useState(null),[K,z]=n.useState(!1),[q,ie]=n.useState(""),H=n.useRef(null),Q=n.useCallback(P=>{H.current=P},[]),w=n.useCallback((P,b)=>{i(_=>[..._.slice(-100),{timestamp:Date.now(),level:P,message:b}]),setTimeout(()=>{var _;return(_=a.current)==null?void 0:_.scrollIntoView({behavior:"smooth"})},100)},[a]),R=n.useCallback(async(P,b)=>{var _;if(!(!t||c)){o(P),w("info",`Launching ${Oe(P)}${b!=null&&b.workspace?` in ${b.workspace}`:""}...`);try{const g={ideType:P,enableCdp:!0};(_=b==null?void 0:b.workspace)!=null&&_.trim()?g.workspace=b.workspace.trim():b!=null&&b.useDefaultWorkspace&&(g.useDefaultWorkspace=!0);const W=await s(t,"launch_ide",g);w(W!=null&&W.success?"info":"error",W!=null&&W.success?`${Oe(P)} launched`:`Failed: ${W==null?void 0:W.error}`)}catch(g){w("error",`Launch error: ${g.message}`)}finally{o(null)}}},[t,c,w,s]),D=n.useCallback(async P=>{if(!t)return;const{cliType:b,dir:_,workspaceId:g,useDefaultWorkspace:W,useHome:G,argsStr:pe,model:be}=P;if(!b){w("warn","Select a CLI or ACP provider first");return}const ge=pe?pe.split(/\s+/).filter(Boolean):void 0,Se=(_==null?void 0:_.trim())||(g?"(saved id)":W?"(default workspace)":G?"(home)":"");w("info",`Launching ${b}${Se?` in ${Se}`:""}${be?` (model: ${be})`:""}...`);try{const he={cliType:b,cliArgs:ge,initialModel:be||void 0};_!=null&&_.trim()?he.dir=_.trim():g?he.workspaceId=g:W?he.useDefaultWorkspace=!0:G&&(he.useHome=!0);const M=await s(t,"launch_cli",he),J=(M==null?void 0:M.result)||M;M!=null&&M.success?(w("info",`${b} launched`),(J==null?void 0:J.launchSource)==="home"?w("info","📂 Running in home directory (explicit choice)"):(J==null?void 0:J.launchSource)==="defaultWorkspace"&&w("info","📂 Using default workspace (explicit choice)")):(w("error",`Failed: ${(M==null?void 0:M.error)||(J==null?void 0:J.error)}`),(M==null?void 0:M.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&$({cliType:b,argsStr:pe,model:be}))}catch(he){w("error",`Launch error: ${he.message}`)}},[t,w,s]),F=n.useCallback((P,b,_,g)=>{if(t){if(!P){w("warn","Select a provider");return}if(!b.trim()){$({cliType:P,argsStr:_,model:g});return}D({cliType:P,dir:b,argsStr:_,model:g})}},[t,w,D]),V=n.useCallback(async(P,b,_)=>{if(t&&window.confirm(`Stop ${P}?
|
|
57
57
|
This will terminate the process.`))try{const g=await s(t,"stop_cli",{cliType:P,dir:b,_targetInstance:_});g!=null&&g.success?w("info",`${P} stopped`):w("error",`Stop failed: ${(g==null?void 0:g.error)||"Unknown error"}`)}catch(g){w("error",`Stop failed: ${g.message}`)}},[t,w,s]),y=n.useCallback(async P=>{try{await s(P.daemonId,"restart_ide",{ideType:P.type}),w("info",`${Oe(P.type)} restart initiated`)}catch(b){w("error",`Restart failed: ${b.message}`)}},[w,s]),U=n.useCallback(async P=>{if(window.confirm(`Stop ${Oe(P.type)}?
|
|
58
|
-
This will disconnect CDP and optionally kill the process.`))try{const b=await s(P.daemonId,"stop_ide",{ideType:P.type,killProcess:!0});b!=null&&b.success?w("info",`${Oe(P.type)} stopped`):w("error",`Stop failed: ${(b==null?void 0:b.error)||"Unknown error"}`)}catch(b){w("error",`Stop failed: ${b.message}`)}},[w,s]),ee=n.useCallback(async()=>{if(t)try{const P=await s(t,"detect_ides",{});w("info",`Found ${((P==null?void 0:P.result)||[]).length} IDE(s)`)}catch(P){w("error",`Detection failed: ${P.message}`)}},[t,w,s]),Y=n.useCallback(async()=>{if(t){m(!0);try{const P=await s(t,"get_recent_workspaces",{});P!=null&&P.success&&Array.isArray(P==null?void 0:P.result)&&T(P.result)}catch(P){w("error",`Failed: ${P.message}`)}finally{m(!1)}}},[t,w,s]),Z=n.useCallback(async P=>{if(!(!t||!P.trim())){u(!0);try{const b=await s(t,"workspace_add",{path:P.trim()});b!=null&&b.success?w("info",`Workspace added: ${P.trim()}`):w("error",(b==null?void 0:b.error)||"workspace_add failed")}catch(b){w("error",b.message)}finally{u(!1)}return!0}},[t,w,s]),B=n.useCallback(async P=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){u(!0);try{const b=await s(t,"workspace_remove",{id:P});b!=null&&b.success?w("info","Workspace removed"):w("error",(b==null?void 0:b.error)||"workspace_remove failed")}catch(b){w("error",b.message)}finally{u(!1)}}},[t,w,s]),oe=n.useCallback(async P=>{var b;if(t){u(!0);try{const _=await s(t,"workspace_set_default",P===null?{clear:!0}:{id:P});if(_!=null&&_.success){w("info",P?"Default workspace updated":"Default workspace cleared");const g=typeof _.defaultWorkspacePath=="string"?_.defaultWorkspacePath:"";g&&((b=H.current)==null||b.call(H,g))}else w("error",(_==null?void 0:_.error)||"workspace_set_default failed")}catch(_){w("error",_.message)}finally{u(!1)}}},[t,w,s]),te=n.useCallback(async P=>{var _;if(!t||!P.trim())return;const b=P.trim();u(!0);try{const g=await s(t,"workspace_set_default",{path:b});g!=null&&g.success?(w("info","Default workspace set from history"),(_=H.current)==null||_.call(H,b)):w("error",(g==null?void 0:g.error)||"Could not set default (path missing on disk?)")}catch(g){w("error",g.message)}finally{u(!1)}},[t,w,s]),se=n.useCallback(async()=>{var P;if(t){N(!0);try{const b=await s(t,"get_cli_history",{}),_=(b==null?void 0:b.history)??((P=b==null?void 0:b.result)==null?void 0:P.history);b!=null&&b.success&&Array.isArray(_)&&d(_)}catch{}N(!1)}},[t,s]),ne=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:q}),w("info",`Nickname set to "${q||"(cleared)"}"`),z(!1)}catch(P){w("error",`Failed: ${P.message}`)}},[t,q,w,s]);return{logs:r,launchingIde:c,loadingWorkspaces:x,workspaceBusy:p,loadingHistory:l,cliHistory:h,recentWorkspaces:S,launchPick:I,setLaunchPick:$,editingNickname:K,setEditingNickname:z,nicknameInput:q,setNicknameInput:ie,addLog:w,handleLaunchIde:R,runLaunchCliCore:D,handleLaunchCli:F,handleStopCli:V,handleRestartIde:y,handleStopIde:U,handleDetectIdes:ee,handleLoadRecentWorkspaces:Y,handleWorkspaceAdd:Z,handleWorkspaceRemove:B,handleWorkspaceSetDefault:oe,handleWorkspaceResumePath:te,loadCliHistory:se,handleSaveNickname:ne,setOnDefaultWorkspaceChanged:Q}}function Nr({machine:t,managedIdes:s,managedClis:a,managedAcps:r,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:o,handleWorkspaceRemove:x,handleWorkspaceSetDefault:m}=i,[p,u]=n.useState(""),l=t.availableMem??t.freeMem,N=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,h=t.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(ft,{icon:e.jsx(cn,{size:16}),label:"Uptime",value:Sn(t.uptime)}),e.jsx(ft,{icon:e.jsx(xt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ft,{icon:e.jsx(fs,{size:16}),label:"CLIs",value:`${a.length}`}),e.jsx(ft,{icon:e.jsx(gs,{size:16}),label:"ACPs",value:`${r.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(Xt,{value:Math.min(Math.round(h/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${h.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Xt,{value:N,max:100,label:"Memory",color:"#3b82f6",detail:`${Vt(t.totalMem-l)} / ${Vt(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Pt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:c,value:t.defaultWorkspaceId||"",onChange:d=>void m(d.target.value===""?null:d.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(d=>e.jsx("option",{value:d.id,children:d.label||d.path},d.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:p,disabled:c,onChange:d=>u(d.target.value),onKeyDown:d=>d.key==="Enter"&&void(async()=>{await o(p)&&u("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await o(p)&&u("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(d=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[d.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:d.path,children:d.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:c,onClick:()=>void x(d.id),children:"Remove"})]},d.id))})]})]})}const kr={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 At({category:t,machine:s,machineId:a,providers:r,managedEntries:i,getIcon:c,actions:o,sendDaemonCommand:x}){const m=mt(),{handleLaunchIde:p,handleLaunchCli:u,handleStopCli:l,handleRestartIde:N,handleStopIde:h,handleDetectIdes:d,cliHistory:S,loadingHistory:T,loadCliHistory:I,launchingIde:$}=o,K=kr[t],z=t==="ide",q=t==="acp",ie=r.filter(g=>g.category===t),[H,Q]=n.useState(""),[w,R]=n.useState(""),[D,F]=n.useState(""),[V,y]=n.useState(s.defaultWorkspaceId||""),[U,ee]=n.useState("");n.useEffect(()=>{!H&&ie.length>0&&Q(ie[0].type)},[H,ie.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!V&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const Y=(()=>{if(V==="__custom__")return U.trim();if(!V)return"";const g=(s.workspaces||[]).find(W=>W.id===V);return(g==null?void 0:g.path)||""})(),[Z,B]=n.useState({}),[oe,te]=n.useState(null);n.useEffect(()=>{if(!z||!a||!x)return;(async()=>{try{const W=await x(a,"get_ide_extensions",{}),G=(W==null?void 0:W.result)||W;G!=null&&G.success&&(G!=null&&G.ides)&&B(G.ides)}catch{}})()},[z,a,x]);const se=g=>z?Oe(g.type):t==="cli"?g.cliName:g.acpName,ne=z?s.detectedIdes||[]:[],P=()=>{z?p(H,Y?{workspace:Y}:void 0):u(H,Y,w||void 0,q&&D||void 0)},b=g=>{z?h(g):l(g.type,g.workspace,g.id)},_=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:V,onChange:g=>{y(g.target.value),g.target.value!=="__custom__"&&ee("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(g=>e.jsxs("option",{value:g.id,children:[g.id===s.defaultWorkspaceId?"⭐ ":"",g.label||g.path.split("/").filter(Boolean).pop()||g.path," — ",g.path]},g.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),V==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:U,onChange:g=>ee(g.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${K.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",K.label]}),_,z?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ne.map(g=>{const W=g.running||i.some(G=>(G.type||"").toLowerCase()===(g.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>p(g.type||g.id||"",Y?{workspace:Y}:void 0),disabled:!!$,className:`machine-btn-primary flex items-center gap-1.5 ${W?"!border-green-500/30":""}`,style:{opacity:$&&$!==g.type?.4:1},children:[e.jsx("span",{children:c(g.type)}),W&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),$===g.type?"⏳ Launching...":`▶ ${g.name||Oe(g.type)}`,W&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},g.type)}),ne.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:d,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(rn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:H,onChange:g=>Q(g.target.value),className:"machine-input",children:ie.length>0?ie.map(g=>e.jsxs("option",{value:g.type,children:[g.icon," ",g.displayName]},g.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),q&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:D,onChange:g=>F(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:w,onChange:g=>R(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:P,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.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 ",K.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(g=>{const W=z?g:null,G=q?g:null;return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:c(g.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[se(g),(W==null?void 0:W.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",W.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:g.workspace||"—"}),(G==null?void 0:G.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",G.currentModel]}),(G==null?void 0:G.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",G.currentPlan]})]})]})]}),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 ${g.status==="stopped"?"bg-red-500/[0.08] text-red-500":g.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:g.status}),z&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>m(`/ide/${g.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(xt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>N(g),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),q&&e.jsx("button",{onClick:()=>m(`/ide/${g.id}`),className:"machine-btn",title:"View chat",children:e.jsx(Nt,{size:14})}),g.status==="stopped"?e.jsx("button",{onClick:()=>z?p(g.type,g.workspace?{workspace:g.workspace}:void 0):u(g.type,g.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>b(g),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),W&&W.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:W.aiAgents.map(pe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${pe.status==="generating"||pe.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[pe.name," · ",pe.status]},pe.id))}),W&&(Z[W.type]||[]).length>0&&x&&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:(Z[W.type]||[]).map(pe=>e.jsxs("button",{disabled:oe===`${W.type}.${pe.type}`,onClick:async()=>{const be=`${W.type}.${pe.type}`;te(be);try{await x(a,"set_ide_extension",{ideType:W.type,extensionType:pe.type,enabled:!pe.enabled}),B(ge=>({...ge,[W.type]:(ge[W.type]||[]).map(Se=>Se.type===pe.type?{...Se,enabled:!Se.enabled}:Se)}))}catch(ge){console.error("Extension toggle failed:",ge)}finally{te(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 ${pe.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${pe.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),pe.name,e.jsx("span",{className:"text-[9px] font-normal",children:pe.enabled?"ON":"OFF"})]},pe.type))})]})]},g.id)})}),!z&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:I,disabled:T,className:"machine-btn",children:T?"⏳":"↻ Load"})]}),(()=>{const g=new Set(ie.map(G=>G.type)),W=S.filter(G=>g.has(G.cliType));return W.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:W.map((G,pe)=>{var be,ge;return e.jsxs("div",{onClick:()=>{Q(G.cliType),y("__custom__"),ee(G.dir),R((G.cliArgs||[]).join(" "))},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:c(G.cliType)}),e.jsx("span",{children:((be=G.dir)==null?void 0:be.split("/").filter(Boolean).pop())||"root"}),((ge=G.cliArgs)==null?void 0:ge.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:G.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:G.timestamp?new Date(G.timestamp).toLocaleDateString():""})]},pe)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",K.label," launch history yet."]})})()]})]})}function Sr({machineId:t,providers:s,sendDaemonCommand:a}){const[r,i]=n.useState([]),[c,o]=n.useState(!1),[x,m]=n.useState(null),[p,u]=n.useState("all"),l=n.useCallback(async()=>{var h;if(t){o(!0);try{const d=await a(t,"get_provider_settings",{}),S=(d==null?void 0:d.result)||d;if(d!=null&&d.success&&(S!=null&&S.settings)){const T=[];for(const[I,$]of Object.entries(S.settings)){const K=s.find(z=>z.type===I);T.push({type:I,displayName:(K==null?void 0:K.displayName)||I,icon:(K==null?void 0:K.icon)||"",category:(K==null?void 0:K.category)||"unknown",schema:$,values:((h=S.values)==null?void 0:h[I])||{}})}T.sort((I,$)=>I.category.localeCompare($.category)||I.displayName.localeCompare($.displayName)),i(T)}}catch{}o(!1)}},[t,s,a]);n.useEffect(()=>{r.length===0&&l()},[]);const N=async(h,d,S)=>{m(`${h}.${d}`),i(T=>T.map(I=>I.type===h?{...I,values:{...I.values,[d]:S}}:I));try{const T=await a(t,"set_provider_setting",{providerType:h,key:d,value:S});T!=null&&T.success||l()}catch{l()}m(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(h=>e.jsx("button",{onClick:()=>u(h),className:`machine-btn text-[10px] px-2 py-0.5 ${p===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsx("button",{onClick:l,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]}),p!=="all"&&r.filter(h=>h.category===p).length>1&&(()=>{const h=r.filter(I=>I.category===p),d=new Map;for(const I of h)for(const $ of I.schema){if($.type!=="boolean")continue;const K=d.get($.key),z=!!(I.values[$.key]??$.default);K?(K.onCount+=z?1:0,K.total+=1):d.set($.key,{label:$.label||$.key,onCount:z?1:0,total:1})}const S=[...d.entries()].filter(([,I])=>I.total===h.length);if(S.length===0)return null;const T=async(I,$)=>{for(const K of h)await N(K.type,I,$)};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 ",p.toUpperCase()," providers (",h.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(([I,$])=>{const K=$.onCount===$.total,z=$.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:$.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",$.onCount,"/",$.total,")"]}),e.jsx("button",{onClick:()=>void T(I,!0),disabled:K,className:`machine-btn text-[9px] px-1.5 py-px ${K?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(I,!1),disabled:z,className:`machine-btn text-[9px] px-1.5 py-px ${z?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},I)})})]})})(),c&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(h=>p==="all"||h.category===p).map(h=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:h.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:h.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:h.category==="acp"?"rgba(139,92,246,0.08)":h.category==="cli"?"rgba(59,130,246,0.08)":h.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:h.category==="acp"?"#a78bfa":h.category==="cli"?"#60a5fa":h.category==="ide"?"#86efac":"#fbbf24"},children:h.category})]}),e.jsx("div",{className:"flex flex-col gap-2",children:h.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,x===`${h.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:()=>N(h.type,d.key,!(h.values[d.key]??d.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:h.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:h.values[d.key]??d.default?21:3}})}):d.type==="number"?e.jsx("input",{type:"number",value:h.values[d.key]??d.default??0,min:d.min,max:d.max,onChange:S=>{const T=parseInt(S.target.value)||0;d.min!==void 0&&T<d.min||d.max!==void 0&&T>d.max||N(h.type,d.key,T)},className:"machine-input w-20 text-center text-[11px]"}):d.type==="select"&&d.options?e.jsx("select",{value:h.values[d.key]??d.default??"",onChange:S=>N(h.type,d.key,S.target.value),className:"machine-input text-[11px]",children:d.options.map(S=>e.jsx("option",{value:S,children:S},S))}):e.jsx("input",{type:"text",value:h.values[d.key]??d.default??"",onBlur:S=>N(h.type,d.key,S.target.value),className:"machine-input w-[120px] text-[11px]"})})]},d.key))})]},h.type))})]})}function Cr({machineId:t,sendDaemonCommand:s}){const[a,r]=n.useState([]),[i,c]=n.useState(0),[o,x]=n.useState(!0),[m,p]=n.useState("debug"),u=n.useRef(null),l=n.useRef(!1);return n.useEffect(()=>{if(!t||!o)return;const N=async()=>{try{const d=await s(t,"get_logs",{count:200,minLevel:m,since:i}),S=(d==null?void 0:d.result)||d;if(d!=null&&d.success&&Array.isArray(S==null?void 0:S.logs)&&S.logs.length>0){r(I=>[...I,...S.logs.map(K=>({timestamp:K.ts,level:K.level,message:`[${K.category}] ${K.message}`}))].slice(-300));const T=Math.max(...S.logs.map(I=>I.ts));c(T)}}catch{}};N();const h=setInterval(N,3e3);return()=>clearInterval(h)},[t,o,i,m,s]),n.useEffect(()=>{if(o&&a.length>0){const N=l.current?"smooth":"instant";setTimeout(()=>{var h;(h=u.current)==null||h.scrollIntoView({behavior:N}),l.current=!0},50)}},[a.length,o]),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(N=>e.jsx("button",{onClick:()=>{p(N),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${m===N?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:N.toUpperCase()},N))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.length," entries"]}),e.jsx("button",{onClick:()=>x(!o),className:`machine-btn ${o?"text-green-500 border-green-500/30":""}`,children:o?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),c(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[a.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),a.map((N,h)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:N.level==="error"?"#ef4444":N.level==="warn"?"#f59e0b":N.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(N.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:N.level==="error"?"#ef4444":N.level==="warn"?"#f59e0b":N.level==="debug"?"#475569":"#8b5cf6"},children:N.level==="error"?"ERR":N.level==="warn"?"WRN":N.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:N.message})]},h)),e.jsx("div",{ref:u})]})]})}function Ir({machine:t,launchPick:s,actions:a}){const{runLaunchCliCore:r,setLaunchPick:i}=a;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(c=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function Mr(){var z,q,ie,H,Q,w,R,D,F,V;const{id:t}=ls(),s=mt(),{sendCommand:a}=Je(),r=St(),i=r.ides||[],c=r.initialLoaded??!0,[o,x]=n.useState("overview"),m=n.useRef(null),p=wr({machineId:t,sendDaemonCommand:a,logsEndRef:m}),u=i.find(y=>y.id===t&&y.daemonMode),l=((u==null?void 0:u.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),N={};for(const y of l)N[y.type]=y.icon;const h=y=>N[y]||"",d=u?{id:u.id,hostname:((z=u.machine)==null?void 0:z.hostname)||u.id,platform:((q=u.machine)==null?void 0:q.platform)||"unknown",arch:((ie=u.machine)==null?void 0:ie.arch)||"",cpus:((H=u.machine)==null?void 0:H.cpus)||0,totalMem:((Q=u.machine)==null?void 0:Q.totalMem)||0,freeMem:((w=u.machine)==null?void 0:w.freeMem)||0,availableMem:(R=u.machine)==null?void 0:R.availableMem,loadavg:((D=u.machine)==null?void 0:D.loadavg)||[],uptime:((F=u.machine)==null?void 0:F.uptime)||0,release:((V=u.machine)==null?void 0:V.release)||"",cdpConnected:!!(u.ides||[]).some(y=>y.cdpConnected),machineNickname:u.machineNickname||null,p2p:u.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:u.detectedIdes||[],managedIdeIds:u.managedIdeIds||[],managedCliIds:u.managedCliIds||[],workspaces:u.workspaces||[],defaultWorkspaceId:u.defaultWorkspaceId??u.activeWorkspaceId??null,defaultWorkspacePath:u.defaultWorkspacePath??u.activeWorkspacePath??null,workspaceActivity:u.workspaceActivity||[]}:null,S=i.filter(y=>y.daemonId===t&&!y.daemonMode).filter(y=>!qt(y)&&!Jt(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:Cn(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:t})),T=i.filter(y=>y.daemonId===t&&qt(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:t})),I=i.filter(y=>y.daemonId===t&&Jt(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:t}));if(!d)return c?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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const $=d.machineNickname||d.hostname,K=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ln,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{size:14})," IDEs"]}),count:S.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{size:14})," CLIs"]}),count:T.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(gs,{size:14})," ACP Agents"]}),count:I.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ms,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tn,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>s("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:p.nicknameInput,onChange:y=>p.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&p.handleSaveNickname(),y.key==="Escape"&&p.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:p.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>p.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{p.setEditingNickname(!0),p.setNicknameInput(d.machineNickname||"")},title:"Click to set nickname",children:$}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[d.platform," · ",d.arch," · ",d.cpus," cores"]}),(u==null?void 0:u.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",u.version]}),(u==null?void 0:u.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await a(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",u.serverVersion]}),d.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:d.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:d.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",d.p2p.state==="connected"?`● ${d.p2p.peers}`:"○"]}),d.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),d.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",d.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:K.map(y=>e.jsxs("button",{onClick:()=>x(y.id),className:`machine-tab shrink-0${o===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[o==="overview"&&e.jsx(Nr,{machine:d,managedIdes:S,managedClis:T,managedAcps:I,actions:p}),o==="ides"&&e.jsx(At,{category:"ide",machine:d,machineId:t,providers:l,managedEntries:S,getIcon:h,actions:p,sendDaemonCommand:a}),o==="clis"&&e.jsx(At,{category:"cli",machine:d,machineId:t,providers:l,managedEntries:T,getIcon:h,actions:p}),o==="acps"&&e.jsx(At,{category:"acp",machine:d,machineId:t,providers:l,managedEntries:I,getIcon:h,actions:p}),o==="providers"&&e.jsx(Sr,{machineId:t,providers:l,sendDaemonCommand:a}),o==="logs"&&e.jsx(Cr,{machineId:t,sendDaemonCommand:a})]}),p.launchPick&&d&&e.jsx(Ir,{machine:d,launchPick:p.launchPick,actions:p})]})}function Tr(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const as=Tr(),os=3e3,Er=3e4;let Ye=null,$r=0;const kt=new Map,Kt=new Set;let et=null,_r=null,lt=null;async function wt(t,s,a){const r=Ye;if(r&&r.readyState===WebSocket.OPEN){const c=`req_${++$r}_${Date.now()}`;return new Promise((o,x)=>{const m=setTimeout(()=>{kt.delete(c),x(new Error(`WS command timeout: ${s}`))},3e4);kt.set(c,{resolve:p=>{clearTimeout(m),o(p)},reject:p=>{clearTimeout(m),x(p)}}),r.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:a||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:a||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class Ar{constructor(s){$e(this,"daemonId");$e(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ye==null?void 0:Ye.readyState)===WebSocket.OPEN}get connectionState(){return(Ye==null?void 0:Ye.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,a){return wt(this.daemonId,s,a)}async sendInput(s,a){const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return wt(r,"cdp_remote_action",{action:s,params:a})}startScreenshots(s){this.screenshotIdeType=s||null,et&&(clearInterval(et),et=null);const a=async()=>{if(this.hasCommandChannel)try{const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await wt(r,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(o=>o.blob());Kt.forEach(o=>o(this.daemonId,c))}}catch{}};a(),et=setInterval(a,2e3)}stopScreenshots(s){et&&(clearInterval(et),et=null)}}let tt=null;function Rr(t){(!tt||tt.daemonId!==t)&&(tt=new Ar(t));const s=Ae._originalGet||Ae.get.bind(Ae);Ae._originalGet=s,Ae.get=a=>a===t||a.startsWith("standalone")?tt:s(a),Ae.getState=a=>(a===t||a.startsWith("standalone"))&&(tt==null?void 0:tt.connectionState)||"disconnected",Ae.onScreenshot=(a,r)=>(Kt.add(r),()=>{Kt.delete(r)})}function Pr({children:t}){const s=n.useRef(Ut()),a=Ut();s.current=a;const{setUserName:r}=dt(),i=n.useRef(r);i.current=r;const[,c]=n.useState("disconnected"),o=n.useCallback((l,N)=>{c(l),lt==null||lt(l,N)},[]),x=n.useRef(null),m=n.useRef(),p=n.useRef(os),u=n.useRef(!0);return n.useEffect(()=>{u.current=!0;function l(){var d,S;if(!u.current||((d=x.current)==null?void 0:d.readyState)===WebSocket.OPEN||((S=x.current)==null?void 0:S.readyState)===WebSocket.CONNECTING)return;o("connecting"),console.log(`[Standalone WS] Connecting to ${as}...`);let h;try{h=new WebSocket(as)}catch(T){console.error("[Standalone WS] Failed to create WebSocket:",T),N();return}x.current=h,h.onopen=()=>{if(!u.current){h.close();return}o("connected"),p.current=os,console.log("[Standalone WS] Connected")},Ye=h,h.onmessage=T=>{var I;try{const $=JSON.parse(T.data);if(($.type==="command_result"||$.type==="error")&&$.requestId){const K=kt.get($.requestId);K&&(kt.delete($.requestId),$.type==="error"?K.reject(new Error(((I=$.data)==null?void 0:I.message)||"Command failed")):K.resolve($.data));return}if($.type==="status"||$.type==="initial_state"){const K=$.data;if(!K)return;const{injectEntries:z,markLoaded:q}=s.current,ie=K.id||"standalone";_r=ie,Rr(ie),o("connected",ie);const H=_n(K,{daemonId:ie});H.length>0&&z(H),q(),K.userName&&i.current&&i.current(K.userName)}}catch($){console.error("[Standalone WS] Parse error:",$)}},h.onclose=()=>{u.current&&(o("disconnected"),x.current=null,N())},h.onerror=T=>{console.warn("[Standalone WS] Error, will reconnect:",T)}}function N(){if(!u.current)return;clearTimeout(m.current);const h=p.current;console.log(`[Standalone WS] Reconnecting in ${h}ms...`),m.current=setTimeout(()=>{p.current=Math.min(p.current*1.5,Er),l()},h)}return l(),()=>{u.current=!1,clearTimeout(m.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,Ye=null)}},[]),e.jsx(e.Fragment,{children:t})}function Lr({children:t}){const[s,a]=n.useState("disconnected"),[r,i]=n.useState(null);n.useEffect(()=>(lt=(o,x)=>{a(o),x&&i(x)},()=>{lt=null}),[]);const c=n.useMemo(()=>{const o=s==="connected",x={};return r&&(x[r]=o?"connected":"connecting"),x.standalone=o?"connected":"connecting",{wsStatus:s,isConnected:o,connectionStates:x}},[s,r]);return e.jsx(Gs,{connectionOverrides:c,children:e.jsx(Pr,{children:t})})}const Dr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Qs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(en,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(ms,{}),label:"Settings"}];function Br({children:t}){const s=mt(),a=Os(),[r,i]=n.useState(!1),[c,o]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=u=>{s(u),i(!1)},m=()=>{o(u=>{const l=!u;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},p=u=>`nav-item${a.pathname.startsWith(u)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Dr.map(u=>e.jsxs("div",{className:p(u.path),id:`nav-${u.id}`,onClick:()=>x(u.path),title:c?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!c&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${a.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(sn,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.18"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:m,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Wr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Or=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Kr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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}],Rt={ides:["VS Code","Cursor","Antigravity","Windsurf","Trae","PearAI","Kiro","VSCodium","VS Code Insiders"],agents:["GitHub Copilot","Cline","Roo Code"],cli:["Gemini CLI","Claude Code","Codex CLI"]};function Fr(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.18"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Wr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:Rt.ides},{label:"Extension agents",items:Rt.agents},{label:"CLI agents",items:Rt.cli}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Kr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Or.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Hr(){const{ides:t}=dt(),s=t.find(l=>l.type==="adhdev-daemon"),a=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Je(),{userName:i}=dt(),[c,o]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&o(i)},[i]);const x=l=>{const N=l.target.value.trim();s!=null&&s.id&&N!==i&&r(s.id,"set_user_name",{userName:N}).catch(console.error)},[m,p]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=l=>{p(l);try{localStorage.setItem("adhdev_sound",l?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Hn,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(nt,{title:"Daemon",className:"mb-4",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.6.18"]}),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(nt,{title:"Detected IDEs",className:"mb-4",children:a.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:a.map(l=>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 ${l.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:l.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:l.type})]},l.type))})}),e.jsx(nt,{title:"Machine",className:"mb-4",children:e.jsx(Jn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(nt,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(sr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(cr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(xr,{})]})]})}),e.jsx(nt,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(qn,{}),e.jsx(rt,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:m,onChange:u})]})}),e.jsx(nt,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 Display Name"}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:c,onChange:l=>o(l.target.value),onBlur:x,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})]})}or();function is(){const{ides:t}=dt(),s=t.find(a=>{var r;return a.daemonMode||((r=a.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(bt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(bt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(bt,{to:"/dashboard",replace:!0})}function zr(){return e.jsx(Ks,{children:e.jsx(Lr,{children:e.jsx(Zs,{value:{sendCommand:wt,sendData:()=>!1},children:e.jsx(Br,{children:e.jsxs(Fs,{children:[e.jsx(Ve,{path:"/dashboard",element:e.jsx(yr,{})}),e.jsx(Ve,{path:"/ide/:id",element:e.jsx(jr,{})}),e.jsx(Ve,{path:"/machine",element:e.jsx(is,{})}),e.jsx(Ve,{path:"/machines/:id",element:e.jsx(Mr,{})}),e.jsx(Ve,{path:"/machines",element:e.jsx(is,{})}),e.jsx(Ve,{path:"/about",element:e.jsx(Fr,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(Hr,{})}),e.jsx(Ve,{path:"*",element:e.jsx(bt,{to:"/dashboard",replace:!0})})]})})})})})}Hs(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(zr,{})}));
|
|
58
|
+
This will disconnect CDP and optionally kill the process.`))try{const b=await s(P.daemonId,"stop_ide",{ideType:P.type,killProcess:!0});b!=null&&b.success?w("info",`${Oe(P.type)} stopped`):w("error",`Stop failed: ${(b==null?void 0:b.error)||"Unknown error"}`)}catch(b){w("error",`Stop failed: ${b.message}`)}},[w,s]),ee=n.useCallback(async()=>{if(t)try{const P=await s(t,"detect_ides",{});w("info",`Found ${((P==null?void 0:P.result)||[]).length} IDE(s)`)}catch(P){w("error",`Detection failed: ${P.message}`)}},[t,w,s]),Y=n.useCallback(async()=>{if(t){m(!0);try{const P=await s(t,"get_recent_workspaces",{});P!=null&&P.success&&Array.isArray(P==null?void 0:P.result)&&T(P.result)}catch(P){w("error",`Failed: ${P.message}`)}finally{m(!1)}}},[t,w,s]),Z=n.useCallback(async P=>{if(!(!t||!P.trim())){u(!0);try{const b=await s(t,"workspace_add",{path:P.trim()});b!=null&&b.success?w("info",`Workspace added: ${P.trim()}`):w("error",(b==null?void 0:b.error)||"workspace_add failed")}catch(b){w("error",b.message)}finally{u(!1)}return!0}},[t,w,s]),B=n.useCallback(async P=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){u(!0);try{const b=await s(t,"workspace_remove",{id:P});b!=null&&b.success?w("info","Workspace removed"):w("error",(b==null?void 0:b.error)||"workspace_remove failed")}catch(b){w("error",b.message)}finally{u(!1)}}},[t,w,s]),oe=n.useCallback(async P=>{var b;if(t){u(!0);try{const _=await s(t,"workspace_set_default",P===null?{clear:!0}:{id:P});if(_!=null&&_.success){w("info",P?"Default workspace updated":"Default workspace cleared");const g=typeof _.defaultWorkspacePath=="string"?_.defaultWorkspacePath:"";g&&((b=H.current)==null||b.call(H,g))}else w("error",(_==null?void 0:_.error)||"workspace_set_default failed")}catch(_){w("error",_.message)}finally{u(!1)}}},[t,w,s]),te=n.useCallback(async P=>{var _;if(!t||!P.trim())return;const b=P.trim();u(!0);try{const g=await s(t,"workspace_set_default",{path:b});g!=null&&g.success?(w("info","Default workspace set from history"),(_=H.current)==null||_.call(H,b)):w("error",(g==null?void 0:g.error)||"Could not set default (path missing on disk?)")}catch(g){w("error",g.message)}finally{u(!1)}},[t,w,s]),se=n.useCallback(async()=>{var P;if(t){N(!0);try{const b=await s(t,"get_cli_history",{}),_=(b==null?void 0:b.history)??((P=b==null?void 0:b.result)==null?void 0:P.history);b!=null&&b.success&&Array.isArray(_)&&d(_)}catch{}N(!1)}},[t,s]),ne=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:q}),w("info",`Nickname set to "${q||"(cleared)"}"`),z(!1)}catch(P){w("error",`Failed: ${P.message}`)}},[t,q,w,s]);return{logs:r,launchingIde:c,loadingWorkspaces:x,workspaceBusy:p,loadingHistory:l,cliHistory:h,recentWorkspaces:S,launchPick:I,setLaunchPick:$,editingNickname:K,setEditingNickname:z,nicknameInput:q,setNicknameInput:ie,addLog:w,handleLaunchIde:R,runLaunchCliCore:D,handleLaunchCli:F,handleStopCli:V,handleRestartIde:y,handleStopIde:U,handleDetectIdes:ee,handleLoadRecentWorkspaces:Y,handleWorkspaceAdd:Z,handleWorkspaceRemove:B,handleWorkspaceSetDefault:oe,handleWorkspaceResumePath:te,loadCliHistory:se,handleSaveNickname:ne,setOnDefaultWorkspaceChanged:Q}}function Nr({machine:t,managedIdes:s,managedClis:a,managedAcps:r,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:o,handleWorkspaceRemove:x,handleWorkspaceSetDefault:m}=i,[p,u]=n.useState(""),l=t.availableMem??t.freeMem,N=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,h=t.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(ft,{icon:e.jsx(cn,{size:16}),label:"Uptime",value:Sn(t.uptime)}),e.jsx(ft,{icon:e.jsx(xt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ft,{icon:e.jsx(fs,{size:16}),label:"CLIs",value:`${a.length}`}),e.jsx(ft,{icon:e.jsx(gs,{size:16}),label:"ACPs",value:`${r.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(Xt,{value:Math.min(Math.round(h/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${h.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Xt,{value:N,max:100,label:"Memory",color:"#3b82f6",detail:`${Vt(t.totalMem-l)} / ${Vt(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Pt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:c,value:t.defaultWorkspaceId||"",onChange:d=>void m(d.target.value===""?null:d.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(d=>e.jsx("option",{value:d.id,children:d.label||d.path},d.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:p,disabled:c,onChange:d=>u(d.target.value),onKeyDown:d=>d.key==="Enter"&&void(async()=>{await o(p)&&u("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await o(p)&&u("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(d=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[d.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:d.path,children:d.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:c,onClick:()=>void x(d.id),children:"Remove"})]},d.id))})]})]})}const kr={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 At({category:t,machine:s,machineId:a,providers:r,managedEntries:i,getIcon:c,actions:o,sendDaemonCommand:x}){const m=mt(),{handleLaunchIde:p,handleLaunchCli:u,handleStopCli:l,handleRestartIde:N,handleStopIde:h,handleDetectIdes:d,cliHistory:S,loadingHistory:T,loadCliHistory:I,launchingIde:$}=o,K=kr[t],z=t==="ide",q=t==="acp",ie=r.filter(g=>g.category===t),[H,Q]=n.useState(""),[w,R]=n.useState(""),[D,F]=n.useState(""),[V,y]=n.useState(s.defaultWorkspaceId||""),[U,ee]=n.useState("");n.useEffect(()=>{!H&&ie.length>0&&Q(ie[0].type)},[H,ie.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!V&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const Y=(()=>{if(V==="__custom__")return U.trim();if(!V)return"";const g=(s.workspaces||[]).find(W=>W.id===V);return(g==null?void 0:g.path)||""})(),[Z,B]=n.useState({}),[oe,te]=n.useState(null);n.useEffect(()=>{if(!z||!a||!x)return;(async()=>{try{const W=await x(a,"get_ide_extensions",{}),G=(W==null?void 0:W.result)||W;G!=null&&G.success&&(G!=null&&G.ides)&&B(G.ides)}catch{}})()},[z,a,x]);const se=g=>z?Oe(g.type):t==="cli"?g.cliName:g.acpName,ne=z?s.detectedIdes||[]:[],P=()=>{z?p(H,Y?{workspace:Y}:void 0):u(H,Y,w||void 0,q&&D||void 0)},b=g=>{z?h(g):l(g.type,g.workspace,g.id)},_=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:V,onChange:g=>{y(g.target.value),g.target.value!=="__custom__"&&ee("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(g=>e.jsxs("option",{value:g.id,children:[g.id===s.defaultWorkspaceId?"⭐ ":"",g.label||g.path.split("/").filter(Boolean).pop()||g.path," — ",g.path]},g.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),V==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:U,onChange:g=>ee(g.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${K.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",K.label]}),_,z?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ne.map(g=>{const W=g.running||i.some(G=>(G.type||"").toLowerCase()===(g.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>p(g.type||g.id||"",Y?{workspace:Y}:void 0),disabled:!!$,className:`machine-btn-primary flex items-center gap-1.5 ${W?"!border-green-500/30":""}`,style:{opacity:$&&$!==g.type?.4:1},children:[e.jsx("span",{children:c(g.type)}),W&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),$===g.type?"⏳ Launching...":`▶ ${g.name||Oe(g.type)}`,W&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},g.type)}),ne.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:d,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(rn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:H,onChange:g=>Q(g.target.value),className:"machine-input",children:ie.length>0?ie.map(g=>e.jsxs("option",{value:g.type,children:[g.icon," ",g.displayName]},g.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),q&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:D,onChange:g=>F(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:w,onChange:g=>R(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:P,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.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 ",K.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(g=>{const W=z?g:null,G=q?g:null;return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:c(g.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[se(g),(W==null?void 0:W.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",W.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:g.workspace||"—"}),(G==null?void 0:G.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",G.currentModel]}),(G==null?void 0:G.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",G.currentPlan]})]})]})]}),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 ${g.status==="stopped"?"bg-red-500/[0.08] text-red-500":g.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:g.status}),z&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>m(`/ide/${g.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(xt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>N(g),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),q&&e.jsx("button",{onClick:()=>m(`/ide/${g.id}`),className:"machine-btn",title:"View chat",children:e.jsx(Nt,{size:14})}),g.status==="stopped"?e.jsx("button",{onClick:()=>z?p(g.type,g.workspace?{workspace:g.workspace}:void 0):u(g.type,g.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>b(g),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),W&&W.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:W.aiAgents.map(pe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${pe.status==="generating"||pe.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[pe.name," · ",pe.status]},pe.id))}),W&&(Z[W.type]||[]).length>0&&x&&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:(Z[W.type]||[]).map(pe=>e.jsxs("button",{disabled:oe===`${W.type}.${pe.type}`,onClick:async()=>{const be=`${W.type}.${pe.type}`;te(be);try{await x(a,"set_ide_extension",{ideType:W.type,extensionType:pe.type,enabled:!pe.enabled}),B(ge=>({...ge,[W.type]:(ge[W.type]||[]).map(Se=>Se.type===pe.type?{...Se,enabled:!Se.enabled}:Se)}))}catch(ge){console.error("Extension toggle failed:",ge)}finally{te(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 ${pe.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${pe.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),pe.name,e.jsx("span",{className:"text-[9px] font-normal",children:pe.enabled?"ON":"OFF"})]},pe.type))})]})]},g.id)})}),!z&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:I,disabled:T,className:"machine-btn",children:T?"⏳":"↻ Load"})]}),(()=>{const g=new Set(ie.map(G=>G.type)),W=S.filter(G=>g.has(G.cliType));return W.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:W.map((G,pe)=>{var be,ge;return e.jsxs("div",{onClick:()=>{Q(G.cliType),y("__custom__"),ee(G.dir),R((G.cliArgs||[]).join(" "))},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:c(G.cliType)}),e.jsx("span",{children:((be=G.dir)==null?void 0:be.split("/").filter(Boolean).pop())||"root"}),((ge=G.cliArgs)==null?void 0:ge.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:G.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:G.timestamp?new Date(G.timestamp).toLocaleDateString():""})]},pe)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",K.label," launch history yet."]})})()]})]})}function Sr({machineId:t,providers:s,sendDaemonCommand:a}){const[r,i]=n.useState([]),[c,o]=n.useState(!1),[x,m]=n.useState(null),[p,u]=n.useState("all"),l=n.useCallback(async()=>{var h;if(t){o(!0);try{const d=await a(t,"get_provider_settings",{}),S=(d==null?void 0:d.result)||d;if(d!=null&&d.success&&(S!=null&&S.settings)){const T=[];for(const[I,$]of Object.entries(S.settings)){const K=s.find(z=>z.type===I);T.push({type:I,displayName:(K==null?void 0:K.displayName)||I,icon:(K==null?void 0:K.icon)||"",category:(K==null?void 0:K.category)||"unknown",schema:$,values:((h=S.values)==null?void 0:h[I])||{}})}T.sort((I,$)=>I.category.localeCompare($.category)||I.displayName.localeCompare($.displayName)),i(T)}}catch{}o(!1)}},[t,s,a]);n.useEffect(()=>{r.length===0&&l()},[]);const N=async(h,d,S)=>{m(`${h}.${d}`),i(T=>T.map(I=>I.type===h?{...I,values:{...I.values,[d]:S}}:I));try{const T=await a(t,"set_provider_setting",{providerType:h,key:d,value:S});T!=null&&T.success||l()}catch{l()}m(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(h=>e.jsx("button",{onClick:()=>u(h),className:`machine-btn text-[10px] px-2 py-0.5 ${p===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsx("button",{onClick:l,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]}),p!=="all"&&r.filter(h=>h.category===p).length>1&&(()=>{const h=r.filter(I=>I.category===p),d=new Map;for(const I of h)for(const $ of I.schema){if($.type!=="boolean")continue;const K=d.get($.key),z=!!(I.values[$.key]??$.default);K?(K.onCount+=z?1:0,K.total+=1):d.set($.key,{label:$.label||$.key,onCount:z?1:0,total:1})}const S=[...d.entries()].filter(([,I])=>I.total===h.length);if(S.length===0)return null;const T=async(I,$)=>{for(const K of h)await N(K.type,I,$)};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 ",p.toUpperCase()," providers (",h.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(([I,$])=>{const K=$.onCount===$.total,z=$.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:$.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",$.onCount,"/",$.total,")"]}),e.jsx("button",{onClick:()=>void T(I,!0),disabled:K,className:`machine-btn text-[9px] px-1.5 py-px ${K?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(I,!1),disabled:z,className:`machine-btn text-[9px] px-1.5 py-px ${z?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},I)})})]})})(),c&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(h=>p==="all"||h.category===p).map(h=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:h.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:h.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:h.category==="acp"?"rgba(139,92,246,0.08)":h.category==="cli"?"rgba(59,130,246,0.08)":h.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:h.category==="acp"?"#a78bfa":h.category==="cli"?"#60a5fa":h.category==="ide"?"#86efac":"#fbbf24"},children:h.category})]}),e.jsx("div",{className:"flex flex-col gap-2",children:h.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,x===`${h.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:()=>N(h.type,d.key,!(h.values[d.key]??d.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:h.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:h.values[d.key]??d.default?21:3}})}):d.type==="number"?e.jsx("input",{type:"number",value:h.values[d.key]??d.default??0,min:d.min,max:d.max,onChange:S=>{const T=parseInt(S.target.value)||0;d.min!==void 0&&T<d.min||d.max!==void 0&&T>d.max||N(h.type,d.key,T)},className:"machine-input w-20 text-center text-[11px]"}):d.type==="select"&&d.options?e.jsx("select",{value:h.values[d.key]??d.default??"",onChange:S=>N(h.type,d.key,S.target.value),className:"machine-input text-[11px]",children:d.options.map(S=>e.jsx("option",{value:S,children:S},S))}):e.jsx("input",{type:"text",value:h.values[d.key]??d.default??"",onBlur:S=>N(h.type,d.key,S.target.value),className:"machine-input w-[120px] text-[11px]"})})]},d.key))})]},h.type))})]})}function Cr({machineId:t,sendDaemonCommand:s}){const[a,r]=n.useState([]),[i,c]=n.useState(0),[o,x]=n.useState(!0),[m,p]=n.useState("debug"),u=n.useRef(null),l=n.useRef(!1);return n.useEffect(()=>{if(!t||!o)return;const N=async()=>{try{const d=await s(t,"get_logs",{count:200,minLevel:m,since:i}),S=(d==null?void 0:d.result)||d;if(d!=null&&d.success&&Array.isArray(S==null?void 0:S.logs)&&S.logs.length>0){r(I=>[...I,...S.logs.map(K=>({timestamp:K.ts,level:K.level,message:`[${K.category}] ${K.message}`}))].slice(-300));const T=Math.max(...S.logs.map(I=>I.ts));c(T)}}catch{}};N();const h=setInterval(N,3e3);return()=>clearInterval(h)},[t,o,i,m,s]),n.useEffect(()=>{if(o&&a.length>0){const N=l.current?"smooth":"instant";setTimeout(()=>{var h;(h=u.current)==null||h.scrollIntoView({behavior:N}),l.current=!0},50)}},[a.length,o]),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(N=>e.jsx("button",{onClick:()=>{p(N),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${m===N?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:N.toUpperCase()},N))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.length," entries"]}),e.jsx("button",{onClick:()=>x(!o),className:`machine-btn ${o?"text-green-500 border-green-500/30":""}`,children:o?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),c(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[a.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),a.map((N,h)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:N.level==="error"?"#ef4444":N.level==="warn"?"#f59e0b":N.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(N.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:N.level==="error"?"#ef4444":N.level==="warn"?"#f59e0b":N.level==="debug"?"#475569":"#8b5cf6"},children:N.level==="error"?"ERR":N.level==="warn"?"WRN":N.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:N.message})]},h)),e.jsx("div",{ref:u})]})]})}function Ir({machine:t,launchPick:s,actions:a}){const{runLaunchCliCore:r,setLaunchPick:i}=a;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(c=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function Mr(){var z,q,ie,H,Q,w,R,D,F,V;const{id:t}=ls(),s=mt(),{sendCommand:a}=Je(),r=St(),i=r.ides||[],c=r.initialLoaded??!0,[o,x]=n.useState("overview"),m=n.useRef(null),p=wr({machineId:t,sendDaemonCommand:a,logsEndRef:m}),u=i.find(y=>y.id===t&&y.daemonMode),l=((u==null?void 0:u.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),N={};for(const y of l)N[y.type]=y.icon;const h=y=>N[y]||"",d=u?{id:u.id,hostname:((z=u.machine)==null?void 0:z.hostname)||u.id,platform:((q=u.machine)==null?void 0:q.platform)||"unknown",arch:((ie=u.machine)==null?void 0:ie.arch)||"",cpus:((H=u.machine)==null?void 0:H.cpus)||0,totalMem:((Q=u.machine)==null?void 0:Q.totalMem)||0,freeMem:((w=u.machine)==null?void 0:w.freeMem)||0,availableMem:(R=u.machine)==null?void 0:R.availableMem,loadavg:((D=u.machine)==null?void 0:D.loadavg)||[],uptime:((F=u.machine)==null?void 0:F.uptime)||0,release:((V=u.machine)==null?void 0:V.release)||"",cdpConnected:!!(u.ides||[]).some(y=>y.cdpConnected),machineNickname:u.machineNickname||null,p2p:u.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:u.detectedIdes||[],managedIdeIds:u.managedIdeIds||[],managedCliIds:u.managedCliIds||[],workspaces:u.workspaces||[],defaultWorkspaceId:u.defaultWorkspaceId??u.activeWorkspaceId??null,defaultWorkspacePath:u.defaultWorkspacePath??u.activeWorkspacePath??null,workspaceActivity:u.workspaceActivity||[]}:null,S=i.filter(y=>y.daemonId===t&&!y.daemonMode).filter(y=>!qt(y)&&!Jt(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:Cn(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:t})),T=i.filter(y=>y.daemonId===t&&qt(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:t})),I=i.filter(y=>y.daemonId===t&&Jt(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:t}));if(!d)return c?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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const $=d.machineNickname||d.hostname,K=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ln,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{size:14})," IDEs"]}),count:S.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{size:14})," CLIs"]}),count:T.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(gs,{size:14})," ACP Agents"]}),count:I.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ms,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tn,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>s("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:p.nicknameInput,onChange:y=>p.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&p.handleSaveNickname(),y.key==="Escape"&&p.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:p.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>p.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{p.setEditingNickname(!0),p.setNicknameInput(d.machineNickname||"")},title:"Click to set nickname",children:$}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[d.platform," · ",d.arch," · ",d.cpus," cores"]}),(u==null?void 0:u.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",u.version]}),(u==null?void 0:u.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await a(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",u.serverVersion]}),d.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:d.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:d.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",d.p2p.state==="connected"?`● ${d.p2p.peers}`:"○"]}),d.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),d.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",d.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:K.map(y=>e.jsxs("button",{onClick:()=>x(y.id),className:`machine-tab shrink-0${o===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[o==="overview"&&e.jsx(Nr,{machine:d,managedIdes:S,managedClis:T,managedAcps:I,actions:p}),o==="ides"&&e.jsx(At,{category:"ide",machine:d,machineId:t,providers:l,managedEntries:S,getIcon:h,actions:p,sendDaemonCommand:a}),o==="clis"&&e.jsx(At,{category:"cli",machine:d,machineId:t,providers:l,managedEntries:T,getIcon:h,actions:p}),o==="acps"&&e.jsx(At,{category:"acp",machine:d,machineId:t,providers:l,managedEntries:I,getIcon:h,actions:p}),o==="providers"&&e.jsx(Sr,{machineId:t,providers:l,sendDaemonCommand:a}),o==="logs"&&e.jsx(Cr,{machineId:t,sendDaemonCommand:a})]}),p.launchPick&&d&&e.jsx(Ir,{machine:d,launchPick:p.launchPick,actions:p})]})}function Tr(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const as=Tr(),os=3e3,Er=3e4;let Ye=null,$r=0;const kt=new Map,Kt=new Set;let et=null,_r=null,lt=null;async function wt(t,s,a){const r=Ye;if(r&&r.readyState===WebSocket.OPEN){const c=`req_${++$r}_${Date.now()}`;return new Promise((o,x)=>{const m=setTimeout(()=>{kt.delete(c),x(new Error(`WS command timeout: ${s}`))},3e4);kt.set(c,{resolve:p=>{clearTimeout(m),o(p)},reject:p=>{clearTimeout(m),x(p)}}),r.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:a||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:a||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class Ar{constructor(s){$e(this,"daemonId");$e(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ye==null?void 0:Ye.readyState)===WebSocket.OPEN}get connectionState(){return(Ye==null?void 0:Ye.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,a){return wt(this.daemonId,s,a)}async sendInput(s,a){const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return wt(r,"cdp_remote_action",{action:s,params:a})}startScreenshots(s){this.screenshotIdeType=s||null,et&&(clearInterval(et),et=null);const a=async()=>{if(this.hasCommandChannel)try{const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await wt(r,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(o=>o.blob());Kt.forEach(o=>o(this.daemonId,c))}}catch{}};a(),et=setInterval(a,2e3)}stopScreenshots(s){et&&(clearInterval(et),et=null)}}let tt=null;function Rr(t){(!tt||tt.daemonId!==t)&&(tt=new Ar(t));const s=Ae._originalGet||Ae.get.bind(Ae);Ae._originalGet=s,Ae.get=a=>a===t||a.startsWith("standalone")?tt:s(a),Ae.getState=a=>(a===t||a.startsWith("standalone"))&&(tt==null?void 0:tt.connectionState)||"disconnected",Ae.onScreenshot=(a,r)=>(Kt.add(r),()=>{Kt.delete(r)})}function Pr({children:t}){const s=n.useRef(Ut()),a=Ut();s.current=a;const{setUserName:r}=dt(),i=n.useRef(r);i.current=r;const[,c]=n.useState("disconnected"),o=n.useCallback((l,N)=>{c(l),lt==null||lt(l,N)},[]),x=n.useRef(null),m=n.useRef(),p=n.useRef(os),u=n.useRef(!0);return n.useEffect(()=>{u.current=!0;function l(){var d,S;if(!u.current||((d=x.current)==null?void 0:d.readyState)===WebSocket.OPEN||((S=x.current)==null?void 0:S.readyState)===WebSocket.CONNECTING)return;o("connecting"),console.log(`[Standalone WS] Connecting to ${as}...`);let h;try{h=new WebSocket(as)}catch(T){console.error("[Standalone WS] Failed to create WebSocket:",T),N();return}x.current=h,h.onopen=()=>{if(!u.current){h.close();return}o("connected"),p.current=os,console.log("[Standalone WS] Connected")},Ye=h,h.onmessage=T=>{var I;try{const $=JSON.parse(T.data);if(($.type==="command_result"||$.type==="error")&&$.requestId){const K=kt.get($.requestId);K&&(kt.delete($.requestId),$.type==="error"?K.reject(new Error(((I=$.data)==null?void 0:I.message)||"Command failed")):K.resolve($.data));return}if($.type==="status"||$.type==="initial_state"){const K=$.data;if(!K)return;const{injectEntries:z,markLoaded:q}=s.current,ie=K.id||"standalone";_r=ie,Rr(ie),o("connected",ie);const H=_n(K,{daemonId:ie});H.length>0&&z(H),q(),K.userName&&i.current&&i.current(K.userName)}}catch($){console.error("[Standalone WS] Parse error:",$)}},h.onclose=()=>{u.current&&(o("disconnected"),x.current=null,N())},h.onerror=T=>{console.warn("[Standalone WS] Error, will reconnect:",T)}}function N(){if(!u.current)return;clearTimeout(m.current);const h=p.current;console.log(`[Standalone WS] Reconnecting in ${h}ms...`),m.current=setTimeout(()=>{p.current=Math.min(p.current*1.5,Er),l()},h)}return l(),()=>{u.current=!1,clearTimeout(m.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,Ye=null)}},[]),e.jsx(e.Fragment,{children:t})}function Lr({children:t}){const[s,a]=n.useState("disconnected"),[r,i]=n.useState(null);n.useEffect(()=>(lt=(o,x)=>{a(o),x&&i(x)},()=>{lt=null}),[]);const c=n.useMemo(()=>{const o=s==="connected",x={};return r&&(x[r]=o?"connected":"connecting"),x.standalone=o?"connected":"connecting",{wsStatus:s,isConnected:o,connectionStates:x}},[s,r]);return e.jsx(Gs,{connectionOverrides:c,children:e.jsx(Pr,{children:t})})}const Dr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Qs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(en,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(ms,{}),label:"Settings"}];function Br({children:t}){const s=mt(),a=Os(),[r,i]=n.useState(!1),[c,o]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=u=>{s(u),i(!1)},m=()=>{o(u=>{const l=!u;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},p=u=>`nav-item${a.pathname.startsWith(u)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Dr.map(u=>e.jsxs("div",{className:p(u.path),id:`nav-${u.id}`,onClick:()=>x(u.path),title:c?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!c&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${a.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(sn,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.19"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:m,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Wr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Or=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Kr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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}],Rt={ides:["VS Code","Cursor","Antigravity","Windsurf","Trae","PearAI","Kiro","VSCodium","VS Code Insiders"],agents:["GitHub Copilot","Cline","Roo Code"],cli:["Gemini CLI","Claude Code","Codex CLI"]};function Fr(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.19"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Wr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:Rt.ides},{label:"Extension agents",items:Rt.agents},{label:"CLI agents",items:Rt.cli}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Kr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Or.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Hr(){const{ides:t}=dt(),s=t.find(l=>l.type==="adhdev-daemon"),a=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Je(),{userName:i}=dt(),[c,o]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&o(i)},[i]);const x=l=>{const N=l.target.value.trim();s!=null&&s.id&&N!==i&&r(s.id,"set_user_name",{userName:N}).catch(console.error)},[m,p]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=l=>{p(l);try{localStorage.setItem("adhdev_sound",l?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Hn,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(nt,{title:"Daemon",className:"mb-4",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.6.19"]}),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(nt,{title:"Detected IDEs",className:"mb-4",children:a.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:a.map(l=>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 ${l.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:l.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:l.type})]},l.type))})}),e.jsx(nt,{title:"Machine",className:"mb-4",children:e.jsx(Jn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(nt,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(sr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(cr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(xr,{})]})]})}),e.jsx(nt,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(qn,{}),e.jsx(rt,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:m,onChange:u})]})}),e.jsx(nt,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 Display Name"}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:c,onChange:l=>o(l.target.value),onBlur:x,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})]})}or();function is(){const{ides:t}=dt(),s=t.find(a=>{var r;return a.daemonMode||((r=a.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(bt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(bt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(bt,{to:"/dashboard",replace:!0})}function zr(){return e.jsx(Ks,{children:e.jsx(Lr,{children:e.jsx(Zs,{value:{sendCommand:wt,sendData:()=>!1},children:e.jsx(Br,{children:e.jsxs(Fs,{children:[e.jsx(Ve,{path:"/dashboard",element:e.jsx(yr,{})}),e.jsx(Ve,{path:"/ide/:id",element:e.jsx(jr,{})}),e.jsx(Ve,{path:"/machine",element:e.jsx(is,{})}),e.jsx(Ve,{path:"/machines/:id",element:e.jsx(Mr,{})}),e.jsx(Ve,{path:"/machines",element:e.jsx(is,{})}),e.jsx(Ve,{path:"/about",element:e.jsx(Fr,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(Hr,{})}),e.jsx(Ve,{path:"*",element:e.jsx(bt,{to:"/dashboard",replace:!0})})]})})})})})}Hs(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(zr,{})}));
|
package/public/index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="description" content="ADHDev self-hosted dashboard for controlling AI agents" />
|
|
8
8
|
<link rel="icon" href="/otter-logo.png" />
|
|
9
9
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet" />
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-q3YUB5UA.js"></script>
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/vendor-Df99lqBA.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/terminal-Dm9LBRva.js">
|
|
13
13
|
<link rel="stylesheet" crossorigin href="/assets/terminal-6GBZ9nXN.css">
|