@adhdev/daemon-standalone 0.9.82-rc.181 → 0.9.82-rc.183
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
|
@@ -51,7 +51,7 @@ This will:
|
|
|
51
51
|
• Delete the machine registration
|
|
52
52
|
• Require restarting ADHDev on that machine
|
|
53
53
|
|
|
54
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:S,onCancel:()=>u(null)})]})}const Zb=["default","claude-cli","codex-cli","antigravity-cli","hermes-cli","gemini-cli"];function eg({daemonId:e,knownCliTypes:t=Zb}){const{sendCommand:r}=it(),[n,a]=l.useState({}),[o,i]=l.useState({}),[c,d]=l.useState(!0),[m,u]=l.useState(null),[h,f]=l.useState(null),[y,b]=l.useState(""),x=l.useCallback(async()=>{if(e){d(!0),f(null);try{const p=await r(e,"list_coordinator_prompts",{}),w=p!=null&&p.result&&typeof p.result=="object"?p.result:p;if(!(w!=null&&w.success)){f((w==null?void 0:w.error)||"Failed to load");return}const C=w.entries||{};b(w.dir||"");const v={};for(const g of t)v[g]=C[g]||{override:"",append:""};for(const g of Object.keys(C))v[g]||(v[g]=C[g]);a(v),i(JSON.parse(JSON.stringify(v)))}catch(p){f((p==null?void 0:p.message)||String(p))}finally{d(!1)}}},[r,e,t]);l.useEffect(()=>{x()},[x]);const k=l.useCallback(async(p,w)=>{var C;if(e){u(`${p}:${w}`),f(null);try{const v=((C=n[p])==null?void 0:C[w])||"",g=await r(e,"write_coordinator_prompt",{key:p,kind:w,content:v}),N=g!=null&&g.result&&typeof g.result=="object"?g.result:g;if(!(N!=null&&N.success)){f((N==null?void 0:N.error)||"Save failed");return}i(I=>({...I,[p]:{...I[p]||{override:"",append:""},[w]:v}}))}catch(v){f((v==null?void 0:v.message)||String(v))}finally{u(null)}}},[r,e,n]),j=l.useMemo(()=>(p,w)=>{var C,v;return(((C=n[p])==null?void 0:C[w])||"")!==(((v=o[p])==null?void 0:v[w])||"")},[n,o]);return e?s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs("div",{className:"text-[12px] text-text-muted",children:[s.jsxs("p",{children:["Customize the coordinator prompt this daemon's mesh coordinator sessions get. ",s.jsx("span",{className:"font-mono text-[11px]",children:y||"~/.adhdev/coordinator-prompts/"})]}),s.jsxs("p",{className:"mt-1",children:[s.jsx("strong",{children:"Override"})," replaces the daemon's built-in base prompt for that CLI."," ",s.jsx("strong",{children:"Append"})," stacks after whichever base wins. Leave a field empty + Save to remove it (reset to default). Supports placeholders: ","{{meshName}}",", ","{{repo}}",", ","{{nodes}}",", ","{{rules}}",", etc."]})]}),h&&s.jsx("div",{className:"text-[12px] text-red-400 bg-red-500/10 border border-red-500/20 rounded px-3 py-2",children:h}),c&&s.jsx("div",{className:"text-[12px] text-text-muted",children:"Loading…"}),s.jsx("div",{className:"flex flex-col gap-6",children:Object.entries(n).map(([p,w])=>s.jsxs("div",{className:"rounded-lg border border-border-subtle bg-bg-secondary/40 p-3",children:[s.jsx("div",{className:"text-[13px] font-semibold mb-2",children:p}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wide text-text-muted mb-1",children:"Override"}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-[12px] font-mono text-text-primary",rows:4,value:w.override,onChange:C=>a(v=>({...v,[p]:{...v[p],override:C.target.value}})),placeholder:"(empty — use daemon default base prompt)",disabled:m===`${p}:override`}),s.jsx("div",{className:"mt-1 mb-3 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void k(p,"override"),disabled:m===`${p}:override`||!j(p,"override"),children:m===`${p}:override`?"Saving…":j(p,"override")?"Save override":"Saved"})}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wide text-text-muted mb-1",children:"Append"}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-[12px] font-mono text-text-primary",rows:3,value:w.append,onChange:C=>a(v=>({...v,[p]:{...v[p],append:C.target.value}})),placeholder:"(empty — nothing appended at this layer)",disabled:m===`${p}:append`}),s.jsx("div",{className:"mt-1 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void k(p,"append"),disabled:m===`${p}:append`||!j(p,"append"),children:m===`${p}:append`?"Saving…":j(p,"append")?"Save append":"Saved"})})]},p))})]}):s.jsx("div",{className:"text-[12px] text-text-muted",children:"Connect a daemon to edit coordinator prompts."})}const tg=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function sg(){const{preference:e,setPreference:t}=zs();return s.jsx("div",{className:"flex gap-2",children:tg.map(r=>s.jsxs("button",{onClick:()=>t(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${e===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:e===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[s.jsx("span",{children:r.icon}),r.label]},r.id))})}function rg(e){const t=e.trim();return/^#[0-9a-fA-F]{6}$/.test(t)?t:/^#[0-9a-fA-F]{3}$/.test(t)?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:null}function ng(e){return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16)}}function Ca(e){const t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function wl(e){const{r:t,g:r,b:n}=ng(e);return .2126*Ca(t)+.7152*Ca(r)+.0722*Ca(n)}function jl(e,t){const r=wl(e),n=wl(t),a=Math.max(r,n),o=Math.min(r,n);return(a+.05)/(o+.05)}function Bd(e){const t=rg(e);if(!t)return"#111827";const r="#111827",n="#ffffff";return jl(t,r)>=jl(t,n)?r:n}const jo={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},ko={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},ag=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],Od="adhdev-chat-theme",Fd="adhdev-chat-theme-custom";function jn(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Od)||"ember"}catch{return"ember"}}function Et(e){try{const t=localStorage.getItem(Fd);if(t){const r=JSON.parse(t);return{...e==="dark"?jo:ko,...r[e]}}}catch{}return e==="dark"?jo:ko}function sn(e,t){try{localStorage.setItem(Fd,JSON.stringify({dark:e,light:t}))}catch{}}function It(e,t){const r=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16);return`rgba(${r}, ${n}, ${a}, ${t})`}function Vn(e,t){const r=Math.min(255,parseInt(e.slice(1,3),16)+t),n=Math.min(255,parseInt(e.slice(3,5),16)+t),a=Math.min(255,parseInt(e.slice(5,7),16)+t);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}const og={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function yr(e,t){var a;const r=(a=og[e])==null?void 0:a[t];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",Vn(r,24)),n.style.setProperty("--accent-on-primary",Bd(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${Vn(r,18)})`),n.style.setProperty("--border-accent",It(r,.35)),n.style.setProperty("--nav-active-bg",It(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${It(r,.06)}`)}function hs(e){const t=document.documentElement;t.style.setProperty("--bg-primary",e.bgPrimary),t.style.setProperty("--bg-secondary",e.bgSecondary),t.style.setProperty("--bg-card",It(e.surfacePrimary,.92)),t.style.setProperty("--surface-primary",e.surfacePrimary),t.style.setProperty("--surface-secondary",e.bgSecondary),t.style.setProperty("--bg-glass",It(e.borderSubtle,.15)),t.style.setProperty("--bg-glass-hover",It(e.borderSubtle,.25)),t.style.setProperty("--text-primary",e.textPrimary),t.style.setProperty("--text-secondary",e.textSecondary),t.style.setProperty("--text-muted",e.textMuted),t.style.setProperty("--border-subtle",It(e.borderSubtle,.5)),t.style.setProperty("--border-default",It(e.borderDefault,.5)),t.style.setProperty("--accent-primary",e.accentColor),t.style.setProperty("--accent-primary-light",Vn(e.accentColor,30)),t.style.setProperty("--accent-on-primary",Bd(e.accentColor)),t.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${e.accentColor}, ${Vn(e.accentColor,40)})`),t.style.setProperty("--border-accent",It(e.accentColor,.35)),t.style.setProperty("--nav-active-bg",It(e.accentColor,.1)),t.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${e.accentColor}, 0 0 12px ${It(e.accentColor,.06)}`),t.style.setProperty("--chat-user-bg",e.userBubble),t.style.setProperty("--chat-user-color",e.userText),t.style.setProperty("--chat-user-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px 4px ${e.bubbleRadius}px`),t.style.setProperty("--chat-assistant-bg",e.assistantBubble),t.style.setProperty("--chat-assistant-color",e.assistantText),t.style.setProperty("--chat-assistant-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px ${e.bubbleRadius}px 4px`),t.style.setProperty("--chat-assistant-border",`1px solid ${It(e.accentColor,.12)}`),t.style.setProperty("--chat-container-bg",e.containerBg),t.style.setProperty("--dashboard-pane-bg",e.containerBg),t.style.setProperty("--chat-thought-accent",e.accentColor),t.style.setProperty("--chat-tool-accent",e.accentColor),t.style.setProperty("--chat-action-color",e.accentColor),t.style.setProperty("--chat-send-bg",e.sendButton),t.style.setProperty("--chat-input-border",e.inputBorder)}function ei(){const e=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>e.style.removeProperty(r))}function ig(e){try{localStorage.setItem(Od,e)}catch{}if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=ps()?"dark":"light";hs(Et(t))}else ei(),yr(e,ps()?"dark":"light")}function lg(){try{localStorage.removeItem("adhdev-accent-color")}catch{}const e=jn();if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=ps()?"dark":"light";hs(Et(t))}else ei(),yr(e,ps()?"dark":"light")}function ps(){const e=document.documentElement.getAttribute("data-theme");return e?e==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function vt({label:e,value:t,onChange:r}){return s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:e}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[s.jsx("input",{type:"color",value:t,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),s.jsx("input",{type:"text",value:t,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function rr({title:e,children:t}){return s.jsxs("div",{style:{marginBottom:14},children:[s.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:e}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:t})]})}function cg({dark:e,onColorsChange:t}){const r=e?"dark":"light",[n,a]=l.useState(()=>Et(r));l.useEffect(()=>{a(Et(r))},[r]);const o=l.useCallback((i,c)=>{a(d=>{const m={...d,[i]:c},h=Et(r==="dark"?"light":"dark");return r==="dark"?sn(m,h):sn(h,m),hs(m),t(m),m})},[r,t]);return s.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[s.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",s.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[e?"🌙 Dark":"☀️ Light"," mode"]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsxs(rr,{title:"App Background",children:[s.jsx(vt,{label:"Background",value:n.bgPrimary,onChange:i=>o("bgPrimary",i)}),s.jsx(vt,{label:"Surface",value:n.bgSecondary,onChange:i=>o("bgSecondary",i)}),s.jsx(vt,{label:"Card",value:n.surfacePrimary,onChange:i=>o("surfacePrimary",i)})]}),s.jsxs(rr,{title:"App Text",children:[s.jsx(vt,{label:"Primary",value:n.textPrimary,onChange:i=>o("textPrimary",i)}),s.jsx(vt,{label:"Secondary",value:n.textSecondary,onChange:i=>o("textSecondary",i)}),s.jsx(vt,{label:"Muted",value:n.textMuted,onChange:i=>o("textMuted",i)})]}),s.jsxs(rr,{title:"Borders & Accent",children:[s.jsx(vt,{label:"Border subtle",value:n.borderSubtle,onChange:i=>o("borderSubtle",i)}),s.jsx(vt,{label:"Border default",value:n.borderDefault,onChange:i=>o("borderDefault",i)}),s.jsx(vt,{label:"Accent",value:n.accentColor,onChange:i=>o("accentColor",i)})]})]}),s.jsxs("div",{children:[s.jsxs(rr,{title:"Chat Bubbles",children:[s.jsx(vt,{label:"User bubble",value:n.userBubble,onChange:i=>o("userBubble",i)}),s.jsx(vt,{label:"User text",value:n.userText,onChange:i=>o("userText",i)}),s.jsx(vt,{label:"Agent bubble",value:n.assistantBubble,onChange:i=>o("assistantBubble",i)}),s.jsx(vt,{label:"Agent text",value:n.assistantText,onChange:i=>o("assistantText",i)})]}),s.jsxs(rr,{title:"Chat Layout",children:[s.jsx(vt,{label:"Chat BG",value:n.containerBg,onChange:i=>o("containerBg",i)}),s.jsx(vt,{label:"Send button",value:n.sendButton,onChange:i=>o("sendButton",i)}),s.jsx(vt,{label:"Input border",value:n.inputBorder,onChange:i=>o("inputBorder",i)}),s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[s.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:i=>o("bubbleRadius",Number(i.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),s.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),s.jsx("button",{onClick:()=>{const i=e?jo:ko,d=Et(e?"light":"dark");e?sn(i,d):sn(d,i),a(i),hs(i),t(i)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function dg(){const[e,t]=l.useState(jn),[r,n]=l.useState(!0),[a,o]=l.useState(()=>Et("dark"));l.useEffect(()=>{n(ps());const d=new MutationObserver(()=>{const h=ps();n(h);const f=jn();f==="custom"?hs(Et(h?"dark":"light")):yr(f,h?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const m=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const h=ps();n(h);const f=jn();f==="custom"?hs(Et(h?"dark":"light")):yr(f,h?"dark":"light")};return m.addEventListener("change",u),()=>{d.disconnect(),m.removeEventListener("change",u)}},[]),l.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",e),e==="custom"?hs(Et(r?"dark":"light")):(ei(),yr(e,r?"dark":"light"))},[e,r]),l.useEffect(()=>{o(Et(r?"dark":"light"))},[r]);const i=d=>{t(d),ig(d)},c=[...ag,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText},light:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText}}}];return s.jsxs("div",{children:[s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:c.map(d=>{const m=e===d.id,u=r?d.preview.dark:d.preview.light,h=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?a.userText:"#fff";return s.jsxs("button",{onClick:()=>i(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:m?"var(--bg-glass-hover)":"var(--bg-glass)",border:m?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:m?1:.75},children:[s.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),s.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:h},children:"Fix the bug please"}),s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[m&&s.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),s.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),e==="custom"&&s.jsx(cg,{dark:r,onColorsChange:d=>o(d)})]})}const ti="adhdev_mobileDashboardMode_v1",So="adhdev:mobile-dashboard-mode-change";function si(){try{return localStorage.getItem(ti)==="workspace"?"workspace":"chat"}catch{return"chat"}}function ug(e){if(typeof window>"u")return()=>{};const t=a=>{e(a??si())},r=a=>{const o=a.detail;t(o)},n=a=>{a.key&&a.key!==ti||t()};return window.addEventListener(So,r),window.addEventListener("storage",n),()=>{window.removeEventListener(So,r),window.removeEventListener("storage",n)}}function mg(e){try{localStorage.setItem(ti,e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent(So,{detail:e}))}function hg(){const[e,t]=l.useState(!0);return l.useEffect(()=>{t(si()==="chat")},[]),s.jsx(ls,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(ws,{size:15})," Mobile Inbox (Chat Mode)"]}),description:e?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:e,onChange:r=>{t(r),mg(r?"chat":"workspace")},extra:s.jsx("span",{className:"text-[11px] text-text-muted",children:e?"Chat mode":"Workspace"})})}const Ia=new Map,kl=new Map;function pg(e){if(!e||typeof e!="object")return null;const t=e,r=t.result&&typeof t.result=="object"?t.result:t,n=r.machine;return!n||typeof n!="object"?null:{machine:n,timestamp:typeof r.timestamp=="number"?r.timestamp:void 0}}function fg(e,t,r,n){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:n,platform:r.platform,machine:r}}function Hd(){const{sendCommand:e}=it(),{injectEntries:t,getIdes:r}=kr();return l.useCallback(async(n,a)=>{if(!n)return;const o=(a==null?void 0:a.minFreshMs)??Jf,i=kl.get(n)||0;if(!(a!=null&&a.force)&&i>0&&Date.now()-i<o)return;const c=Ia.get(n);if(c)return c;const d=(async()=>{const m=await e(n,"get_machine_runtime_stats"),u=pg(m);if(!u)return;const h=r().find(y=>y.id===n),f=fg(h,n,u.machine,u.timestamp||Date.now());t([f]),kl.set(n,Date.now())})().finally(()=>{Ia.delete(n)});return Ia.set(n,d),d},[r,t,e])}function xg(e,t,r){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:r.timestamp,platform:r.machine.platform,machine:{...(e==null?void 0:e.machine)||{},...r.machine}}}function bg(e,t){const{sendData:r}=it(),{injectEntries:n,getIdes:a}=kr(),o=Array.from(new Set(e.filter(Boolean))).join("|");l.useEffect(()=>{if(!(t!=null&&t.enabled)||!r)return;const i=o?o.split("|"):[];if(i.length===0)return;const c=i.map(d=>Gt.subscribe({sendData:r},d,{type:"subscribe",topic:"machine.runtime",key:`machine:${d}`,params:{intervalMs:t==null?void 0:t.intervalMs}},u=>{const h=a().find(y=>y.id===d),f=xg(h,d,u);n([f])}));return()=>{c.forEach(d=>d())}},[o,a,n,t==null?void 0:t.enabled,t==null?void 0:t.intervalMs,r])}function gg(e,t){const{sendData:r}=it(),[n,a]=l.useState(null),[o,i]=l.useState(!1);return l.useEffect(()=>{if(!e){a(null),i(!1);return}if(!(t!=null&&t.enabled)||!r){i(!1);return}a(null),i(!0);let c=null;const d=Gt.subscribe({sendData:r},e,{type:"subscribe",topic:"session_host.diagnostics",key:`session_host:${e}`,params:{includeSessions:(t==null?void 0:t.includeSessions)!==!1,...typeof(t==null?void 0:t.limit)=="number"?{limit:t.limit}:{},...typeof(t==null?void 0:t.intervalMs)=="number"?{intervalMs:t.intervalMs}:{}}},m=>{c&&(clearTimeout(c),c=null),a(m.diagnostics),i(!1)});return d.initialSendAccepted?c=setTimeout(()=>{i(!1)},tx):i(!1),()=>{c&&clearTimeout(c),d()}},[e,t==null?void 0:t.enabled,t==null?void 0:t.includeSessions,t==null?void 0:t.intervalMs,t==null?void 0:t.limit,r]),{diagnostics:n,loading:o,applyDiagnostics:a}}function yg(e){return e.daemonId||(e.routeId.includes(":")?e.routeId.split(":")[0]||null:e.routeId||null)}function Wd(e){const{sendData:t}=it(),[r,n]=l.useState({});return l.useEffect(()=>{const a=yg(e);if(!a||!e.sessionId||!t){n({});return}const o=Gt.subscribe({sendData:t},a,{type:"subscribe",topic:"session.modal",key:`daemon:${a}:session-modal:${e.sessionId}`,params:{targetSessionId:e.sessionId}},i=>{n({status:i.status,modalMessage:i.modalMessage,modalButtons:i.modalButtons}),Ds.record({interactionId:i.interactionId,kind:"dashboard.session_modal_applied",topic:"session.modal",payload:{sessionId:e.sessionId,status:i.status,modalButtonCount:Array.isArray(i.modalButtons)?i.modalButtons.length:0}})});return o.initialSendAccepted||n({}),()=>{o()}},[e.daemonId,e.routeId,e.sessionId,t]),r}const Kd="adhdev_hiddenTabs",Ud="adhdev_autoHiddenMeshTabs";function vg(){try{const e=localStorage.getItem(Kd);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function os(e){try{localStorage.setItem(Kd,JSON.stringify([...e]))}catch{}}function wg(){try{const e=localStorage.getItem(Ud);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function Sl(e){try{localStorage.setItem(Ud,JSON.stringify([...e]))}catch{}}function ur(e){return Nr(e)}function ia(e,t){return Vt(t).some(r=>e.has(r))}function zd(e){var t,r,n;return((t=e.settings)==null?void 0:t.launchedByCoordinator)===!0&&typeof((r=e.settings)==null?void 0:r.meshNodeFor)=="string"&&e.settings.meshNodeFor.trim().length>0&&((n=e.settings)==null?void 0:n.spawnedSessionVisibility)==="hidden"}function jg(e,t,r=new Set){return e.filter(n=>{if(!zd(n))return!1;const a=ur(n);return r.has(a)?!1:!ia(t,n)})}function kg(){const[e,t]=l.useState(vg),[r,n]=l.useState(wg),a=l.useCallback(f=>{const y=ur(f);t(b=>{const x=new Set(b);return x.has(y)?x.delete(y):x.add(y),os(x),x})},[]),o=l.useCallback(f=>{const y=ur(f);t(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),os(x),x})},[]),i=l.useCallback(f=>{const y=ur(f);t(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),os(x),x}),n(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),Sl(x),x})},[]),c=l.useCallback(f=>{const y=ur(f);t(b=>{if(!b.has(y))return b;const x=new Set(b);return x.delete(y),os(x),x}),n(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),Sl(x),x})},[]),d=l.useCallback(()=>{t(f=>{if(f.size===0)return f;const y=new Set;return os(y),y})},[]),m=l.useCallback((f,y)=>{t(b=>{const x=new Set(b);for(const k of y)x.add(k);return os(x),x})},[]),u=l.useCallback((f,y)=>{t(b=>{const x=new Set(b);for(const k of y)x.delete(k);return os(x),x})},[]),h=l.useCallback(f=>ia(e,f),[e]);return{hiddenTabs:e,autoHiddenTabs:r,toggleTarget:a,hideTarget:o,autoHideTarget:i,showTarget:c,showAllTabs:d,hideAllForDaemon:m,showAllForDaemon:u,isHidden:h}}const rn="adhdev_mutedConversations",Ma="adhdev_autoMutedMeshConversations";function Nl(e){try{const t=localStorage.getItem(e);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function nr(e,t){try{localStorage.setItem(e,JSON.stringify([...t]))}catch{}}function Sg(e,t){return Vt(t).some(r=>e.has(r))}function Ng(){const[e,t]=l.useState(()=>Nl(rn)),[r,n]=l.useState(()=>Nl(Ma)),a=l.useCallback(m=>{const u=Nr(m);t(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(rn,f),f})},[]),o=l.useCallback(m=>{const u=Vt(m);t(h=>{let f=!1;const y=new Set(h);for(const b of u)y.delete(b)&&(f=!0);return f?(nr(rn,y),y):h}),n(h=>{let f=!1;const y=new Set(h);for(const b of u)y.delete(b)&&(f=!0);return f?(nr(Ma,y),y):h})},[]),i=l.useCallback(m=>{Vt(m).some(f=>e.has(f))?o(m):a(m)},[e,a,o]),c=l.useCallback(m=>{if(!zd(m))return;const u=Nr(m);r.has(u)||(n(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(Ma,f),f}),t(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(rn,f),f}))},[r]),d=l.useCallback(m=>Sg(e,m),[e]);return{mutedTargets:e,autoMutedTargets:r,muteTarget:a,unmuteTarget:o,toggleTarget:i,autoMuteIfCoordinator:c,isMuted:d}}function Cg(e){if(!e||typeof e!="object")return!1;const t=e.result??e;return!!t&&typeof t=="object"&&t.success!==!1}function Ig(e){const t=(e==null?void 0:e.result)??e;return typeof(t==null?void 0:t.error)=="string"?t.error:"Interactive prompt response failed"}async function Mg(e,t,r){const n=await r(`/api/v1/sessions/${encodeURIComponent(e)}/interactive-prompt/resolve`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let a=`HTTP ${n.status}`;try{const o=await n.json();typeof(o==null?void 0:o.error)=="string"&&(a=o.error)}catch{}throw new Error(a)}}async function Tg({promptSession:e,response:t,useP2PCommand:r,sendCommand:n,fetchImpl:a=fetch}){if(r){const o=await n(e.routeId,"interactive_prompt_response",{targetSessionId:e.sessionId,sessionId:e.sessionId,response:t});if(!Cg(o))throw new Error(Ig(o));return}await Mg(e.sessionId,t,a)}function Ag(e){const{ides:t,isP2PActive:r,p2pStates:n}=qt(),{sendCommand:a}=it(),[o,i]=l.useState(null),[c,d]=l.useState(!1),[m,u]=l.useState(null),h=l.useMemo(()=>{const b=kp(t);return b?b.prompt.promptId===o?null:b:null},[o,t,e]),f=l.useCallback(async b=>{if(!h)return;const x=Wc(h.prompt,b);d(!0),u(null);try{const k=(n==null?void 0:n[h.daemonId])==="connected"||r===!0;await Tg({promptSession:h,response:x,useP2PCommand:k,sendCommand:a}),i(h.prompt.promptId)}catch(k){throw u(k instanceof Error?k.message:String(k)),k}finally{d(!1)}},[r,n,h,a]),y=l.useCallback(()=>{h&&i(h.prompt.promptId)},[h]);return{promptSession:h,responseError:m,isSubmitting:c,submit:f,cancel:y}}function Gd(e){return e instanceof Error?e.message:String(e||"")}function _g(e){const t=Gd(e);return t.includes("P2P command timeout")||t.includes("P2P not connected")||t.includes("P2P channel not open")||t.includes("P2P not available")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}function Lg(e){const t=Gd(e);return t.includes("P2P command timeout")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}async function Vd({conversation:e,mode:t,ides:r,sendDaemonCommand:n,setCliViewModeOverrides:a}){if(!e||!Ye(e)||Ve(e))return;const o=Us(e);if(o===t)return;const i=e.sessionId;i&&a(c=>({...c,[i]:t}));try{await n(js(e)||e.routeId,"set_cli_view_mode",{targetSessionId:e.sessionId,cliType:Kt(e),mode:t})}catch(c){const d=Lg(c);i&&!d&&a(m=>{const u={...m};return o===qd(r,i)?delete u[i]:u[i]=o,u}),_g(c)?console.warn(d?"CLI view mode result was lost after send; keeping optimistic mode override:":"Skipped CLI view mode switch:",c instanceof Error?c.message:String(c)):console.error("Failed to switch CLI view mode:",c)}}function Cl(e,t){const r=typeof e.sessionId=="string"&&e.sessionId?e.sessionId:typeof e.id=="string"?e.id:"";if(!r||e.transport!=="pty")return e;const n=t[r];return!n||e.mode===n?e:{...e,mode:n}}function Pg(e,t){if(!Array.isArray(e)||e.length===0||!t||Object.keys(t).length===0)return e;let r=!1;const n=e.map(a=>{const o=Cl(a,t),i=Array.isArray(a.childSessions)?a.childSessions.map(d=>Cl(d,t)):a.childSessions,c=i!==a.childSessions;return o!==a||c?(r=!0,{...o,...c?{childSessions:i}:{}}):a});return r?n:e}function qd(e,t){if(!t)return null;for(const r of e){if(r.sessionId===t&&r.transport==="pty")return r.mode==="chat"?"chat":"terminal";for(const n of r.childSessions||[])if(n.id===t&&n.transport==="pty")return n.mode==="chat"?"chat":"terminal"}return null}function Rg(e,t){if(!e||Object.keys(e).length===0)return e;let r=!1;const n={...e};for(const[a,o]of Object.entries(e))qd(t,a)===o&&(delete n[a],r=!0);return r?n:e}function Dg({visibleConversations:e,clearedTabs:t,setClearedTabs:r,setActionLogs:n}){l.useEffect(()=>{Xc()},[]);const a=l.useMemo(()=>e.map(o=>({id:o.tabKey,name:wd(o),status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[e]);return tf(a),l.useEffect(()=>{if(Object.keys(t).length===0)return;const i=setTimeout(()=>{r(c=>{const d=Date.now(),m={};for(const[u,h]of Object.entries(c))d-h<5e3&&(m[u]=h);return Object.keys(m).length===Object.keys(c).length?c:m})},5500);return()=>clearTimeout(i)},[t,r]),l.useEffect(()=>{const o=setInterval(()=>{const i=Date.now()-3e5;n(c=>{const d=c.filter(m=>m.timestamp>i).slice(-100);return d.length===c.length?c:d})},6e4);return()=>clearInterval(o)},[n]),null}function Il(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function fs(e){const t=[...e.messages].reverse().find(a=>!(a!=null&&a._localId))||e.messages[e.messages.length-1],r=typeof e.lastMessageAt=="number"&&Number.isFinite(e.lastMessageAt)?e.lastMessageAt:0,n=Il(t==null?void 0:t.receivedAt)||Il(t==null?void 0:t.timestamp)||0;return Math.max(r,n)}function No(e,t=0){return fs(e)||e.lastUpdated||t||0}function Yd(e){return fs(e)||e.lastUpdated||0}function Xd(e,t,r=Yd){const n=r(t)-r(e);if(n!==0)return n;const a=(e.machineName||"").localeCompare(t.machineName||"");if(a!==0)return a;const o=e.displayPrimary.localeCompare(t.displayPrimary);if(o!==0)return o;const i=e.displaySecondary.localeCompare(t.displaySecondary);return i!==0?i:e.tabKey.localeCompare(t.tabKey)}function Co(e){var r;const t=Tt(e.status,{activeModal:(r=e.modalButtons)!=null&&r.length?{buttons:e.modalButtons}:null});return t==="generating"||t==="waiting_approval"}function Eg(e){var t;return e.messages.length===0&&!((t=e.modalButtons)!=null&&t.length)&&!Co(e)&&!e.title.trim()}function $g(e){return e.length===0?null:[...e].sort((t,r)=>{const n=Number(Co(r))-Number(Co(t));if(n!==0)return n;const a=r.messages.length-t.messages.length;return a!==0?a:Xd(t,r)})[0]||null}function $t(e,t){const r=e.filter(i=>i.routeId===t);if(r.length===0)return null;const n=r.find(i=>i.streamSource==="native")||null,a=r.filter(i=>i.streamSource==="agent-stream"),o=$g(a);return n?o&&Eg(n)?o:n:o||r[0]||null}function Bg(e){const t=String(e.daemonId||"").trim(),r=String(e.id||"").trim();return!t||r.startsWith(`${t}:`)?r:`${t}:${r}`}function Og(e){const t=e.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of t){const a=Bg(n),o=r.get(a);if(!o){r.set(a,n);continue}const i=(o.workspace?1:0)+(o.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>i||(n.timestamp||0)>(o.timestamp||0))&&r.set(a,n)}return Array.from(r.values())}function Ta(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(e[r]!==t[r])return!1;return!0}function Fg(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function Ml(e){if(!e)return"";const t=Array.isArray(e.messages)?e.messages:[],r=t[t.length-1],n=r?Fg(Es(r.content)):"";return[e.id||"",e.title||"",e.status||"",t.length,String((r==null?void 0:r.id)||""),String((r==null?void 0:r.index)??""),String((r==null?void 0:r.receivedAt)??(r==null?void 0:r.timestamp)??""),n].join(":")}function Hg(e){const t=Array.isArray(e.childSessions)?e.childSessions:[];return[e.id,e.sessionId||"",e.providerSessionId||"",e.transport||"",e.mode||"",e.status||"",e.workspace||"",e.lastMessageHash||"",String(e.lastMessageAt||""),e.lastMessagePreview||"",e.lastMessageRole||"",String(e.lastUpdated||""),Ml(e.activeChat),...t.map(r=>[r.id||"",r.providerSessionId||"",r.transport||"",r.mode||"",r.status||"",r.title||"",r.lastMessageHash||"",String(r.lastMessageAt||""),r.lastMessagePreview||"",r.lastMessageRole||"",String(r.lastUpdated||""),Ml(r.activeChat)].join(":"))].join("|")}function Wg(e,t){const r=Date.now();return e.map(n=>{const a=t[n.tabKey];return a&&r-a<5e3?{...n,messages:[],title:""}:n})}function Kg(e,t){const r=new Map;for(const n of e){const a=t.get(n.routeId)||n;for(const o of Vt({routeId:n.routeId}))r.set(o,a);for(const o of Vt({providerSessionId:n.providerSessionId,sessionId:n.sessionId}))r.set(o,n.streamSource==="native"?a:n);for(const o of Vt({tabKey:n.tabKey}))r.set(o,n)}return r}function Ug(e){return[...e.messages].reverse().find(t=>!(t!=null&&t._localId))||e.messages[e.messages.length-1]}function zg(e){const t=Ug(e);if(!t)return`empty:${e.messages.length}`;if(t.id)return`id:${String(t.id)}`;if(t._localId)return`local:${String(t._localId)}`;const r=String(t.role||""),n=Es(t.content).slice(0,240);return`${e.messages.length}:${r}:${n}`}function Gg({ides:e,connectionStates:t,clearedTabs:r,hiddenTabs:n}){const a=l.useMemo(()=>Og(e),[e]),o=l.useMemo(()=>Ad(e),[e]),i=l.useRef([]),c=l.useRef([]),d=l.useRef([]),m=l.useRef(new Map),u=l.useRef(new Map),h=l.useMemo(()=>{const C=new Map,v=[];for(const S of a){const{connectionState:T="new",machineName:P}=_d(S,{machineNames:o,connectionStates:t,defaultConnectionState:"new"}),A=Hg(S),D=m.current.get(S.id);if(D&&D.ide===S&&D.sourceSignature===A&&D.connectionState===T&&D.machineName===P){C.set(S.id,D),v.push(...D.conversations);continue}const L=Qo(S,{machineNames:o,connectionStates:t,defaultConnectionState:"new"}),O={ide:S,sourceSignature:A,connectionState:T,machineName:P,conversations:L};C.set(S.id,O),v.push(...L)}m.current=C;const g=new Map,N=S=>{const T=zg(S),P=u.current.get(S.tabKey);if(P&&P.signature===T)return g.set(S.tabKey,P),P.timestamp;const A={signature:T,timestamp:Yd(S)||(P==null?void 0:P.timestamp)||0};return g.set(S.tabKey,A),A.timestamp},I=[...v].sort((S,T)=>Xd(S,T,N));return u.current=g,I},[a,t,o]),f=l.useMemo(()=>{const C=Wg(h,r);return Ta(i.current,C)?i.current:(i.current=C,C)},[h,r]),y=l.useMemo(()=>{const C=new Map,v=Array.from(new Set(f.map(g=>g.routeId)));for(const g of v){const N=$t(f,g);N&&C.set(g,N)}return C},[f]),b=l.useMemo(()=>{const C=new Map;for(const v of f){const g=y.get(v.routeId),N=v.streamSource==="native"&&g?g:v;for(const I of Vt({providerSessionId:v.providerSessionId,sessionId:v.sessionId,tabKey:v.tabKey}))C.set(I,N)}return C},[f,y]),x=l.useMemo(()=>Kg(f,y),[f,y]),k=l.useCallback(C=>{if(C)return b.get(C)},[b]),j=l.useCallback(C=>{if(C)return x.get(C)},[x]),p=l.useMemo(()=>{const C=f.filter(v=>!ia(n,v));return Ta(c.current,C)?c.current:(c.current=C,C)},[f,n]),w=l.useMemo(()=>{const C=p.map(v=>v.tabKey);return Ta(d.current,C)?d.current:(d.current=C,C)},[p]);return{chatIdes:a,conversations:f,visibleConversations:p,visibleTabKeys:w,resolveConversationBySessionId:k,resolveConversationByTarget:j}}function Vg({isMobile:e,urlActiveTab:t,resolveConversationBySessionId:r,setSearchParams:n}){const a=l.useMemo(()=>{var c;return e||!t?null:((c=r(t))==null?void 0:c.tabKey)??null},[e,r,t]),o=l.useMemo(()=>{var c;return!e||!t?null:((c=r(t))==null?void 0:c.tabKey)??null},[e,r,t]),i=l.useCallback(()=>{t&&n(c=>{const d=new URLSearchParams(c);return d.delete("activeTab"),d},{replace:!0})},[n,t]);return{requestedDesktopTabKey:a,requestedMobileTabKey:o,consumeRequestedActiveTab:i}}function qg({ides:e,sendDaemonCommand:t,setToasts:r,resolveConversationByTarget:n}){l.useEffect(()=>{Je.setIdes(e)},[e]),l.useEffect(()=>{Je.setResolveAction((a,o,i)=>{t(a,o,i).catch(()=>{})})},[t]),l.useEffect(()=>{const a=Je.onToast(o=>{r(c=>c.some(m=>m.message===o.message&&o.timestamp-m.timestamp<3e3)?c:[...c.slice(-4),{id:o.id,message:o.message,type:o.type,timestamp:o.timestamp,targetKey:o.targetKey,actions:o.actions}]);const i=o.duration||5e3;setTimeout(()=>r(c=>c.filter(d=>d.id!==o.id)),i)});return()=>{a()}},[r]),l.useEffect(()=>{const a=gd.on("status_event",o=>{Je.handleRawEvent(o,"ws")});return()=>{a()}},[]),l.useEffect(()=>{var o;const a=i=>{var x;const c=i.data;if((c==null?void 0:c.type)!=="notification_action"||typeof c.action!="string"||!c.action.startsWith("approval_")||!(c.daemonId||c.targetSessionId||c.targetKey))return;const d=c.targetSessionId||c.targetKey||c.daemonId,m=n(d),u=(m==null?void 0:m.routeId)||c.daemonId;if(!u)return;const h=Number(c.buttonIndex),f=c.button||((x=m==null?void 0:m.modalButtons)==null?void 0:x[h])||"Approve",y=String(f).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y);t(u,"resolve_action",{action:b?"approve":"reject",button:f,...Number.isFinite(h)&&{buttonIndex:h},...(m==null?void 0:m.sessionId)&&{targetSessionId:m.sessionId},...c.targetSessionId&&{targetSessionId:c.targetSessionId}}).catch(k=>console.error("[SW Action] approval failed:",k))};return(o=navigator.serviceWorker)==null||o.addEventListener("message",a),()=>{var i;return(i=navigator.serviceWorker)==null?void 0:i.removeEventListener("message",a)}},[n,t])}const Yg="adhdev_dashboardLayout_v1",Xg="adhdev_dashboardDockview_v1",Jg="adhdev_dashboardDockviewHiddenRestore_v1",ar={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function ri(e,t){try{const r=localStorage.getItem(e);return r?JSON.parse(r):t}catch{return t}}function Qg(e){return e<768?"mobile":e<1280?"desktop-narrow":"desktop-wide"}function Jd(e){return`${Yg}:${e}`}function Zg(e){const t=Jd(e);return ri(t,null)}function ey(e,t){try{const r=t.groupAssignments.length===0&&t.focusedGroup===0&&Object.keys(t.groupActiveTabIds).length===0&&Object.keys(t.groupTabOrders).length===0&&t.groupSizes.length===0,n=Jd(e);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(t))}catch{}}function Qd(e){return`${Xg}:${e}`}function ty(e){const t=Qd(e);return ri(t,null)}function sy(e,t){try{const r=Qd(e);if(!t){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(t))}catch{}}function Zd(e){return`${Jg}:${e}`}function ry(e){const t=Zd(e);return ri(t,{})}function ny(e,t){try{const r=Zd(e);if(Object.keys(t).length===0){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(t))}catch{}}function ay(){return{groupAssignments:[...ar.groupAssignments],focusedGroup:ar.focusedGroup,groupActiveTabIds:{...ar.groupActiveTabIds},groupTabOrders:{...ar.groupTabOrders},groupSizes:[...ar.groupSizes]}}function oy(e,t){return e?e.length===t.length&&e.every((r,n)=>r===t[n]):t.length===0}function iy(){const[e]=l.useState(()=>Qg(typeof window<"u"?window.innerWidth:1280)),[t,r]=l.useState(()=>new Map),[n,a]=l.useState(0),[o,i]=l.useState({}),[c,d]=l.useState({}),[m,u]=l.useState([]),[h,f]=l.useState(()=>typeof window<"u"&&window.innerWidth<768),[y,b]=l.useState(!1),x=l.useCallback(()=>{if(y)return;const S=Zg(e)??ay();r(new Map(S.groupAssignments)),a(S.focusedGroup),i(S.groupActiveTabIds),d(S.groupTabOrders),u(S.groupSizes),b(!0)},[y,e]);l.useEffect(()=>{y&&ey(e,{groupAssignments:[...t.entries()],focusedGroup:n,groupActiveTabIds:o,groupTabOrders:c,groupSizes:m})},[y,e,t,n,o,c,m]),l.useEffect(()=>{const S=window.matchMedia("(max-width: 767px)"),T=P=>f(P.matches);return S.addEventListener("change",T),()=>S.removeEventListener("change",T)},[]);const k=l.useCallback(S=>{r(S)},[]),j=l.useCallback(S=>{a(S)},[]),p=l.useCallback(S=>{i(S)},[]),w=l.useCallback(S=>{d(S)},[]),C=l.useCallback(S=>{u(S)},[]),v=l.useCallback(S=>{j(S)},[j]),g=l.useCallback((S,T)=>{i(P=>(P[S]??null)===(T??null)?P:{...P,[S]:T})},[]),N=l.useCallback((S,T)=>{d(P=>{const A=P[S];return oy(A,T)?P:{...P,[S]:T}})},[]),I=l.useCallback((S,T)=>{const P=T.get(S)??0;return g(P,S),v(P),P},[v,g]);return{layoutProfile:e,groupAssignments:t,updateGroupAssignments:k,focusedGroup:n,updateFocusedGroup:j,focusGroup:v,groupActiveTabIds:o,updateGroupActiveTabIds:p,setGroupActiveTab:g,groupTabOrders:c,updateGroupTabOrders:w,setGroupTabOrder:N,groupSizes:m,updateGroupSizes:C,isMobile:h,hasHydratedStoredLayout:y,hydrateStoredLayout:x,focusConversationTab:I}}function ly(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const r=e[0],n=oa(t);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function cy({urlActiveTab:e,conversations:t,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:a,hydrateStoredLayout:o,focusConversationTab:i,setSearchParams:c,historyModalOpen:d,activeConv:m,isRefreshingHistory:u,ides:h,handleRefreshHistory:f}){const y=l.useRef(!1),b=l.useRef(!1),x=l.useRef(null),k=l.useRef(!1);l.useEffect(()=>{if(!e||y.current||t.length===0)return;if(!a){o();return}const j=r(e);j&&(i(j.tabKey,n),y.current=!0,b.current=!0,x.current!=null&&(window.clearTimeout(x.current),x.current=null),c(p=>{const w=new URLSearchParams(p);return w.delete("activeTab"),w},{replace:!0}))},[e,t,r,n,a,o,i,c]),l.useEffect(()=>{if(!(b.current||a)&&t.length!==0){if(!e){o(),b.current=!0;return}if(y.current){b.current=!0;return}if(x.current==null)return x.current=window.setTimeout(()=>{x.current=null,!(b.current||a)&&(o(),b.current=!0)},1500),()=>{x.current!=null&&(window.clearTimeout(x.current),x.current=null)}}},[e,t.length,a,o]),l.useEffect(()=>{if(!d){k.current=!1;return}if(!m||k.current||u)return;const j=h.find(p=>p.id===m.routeId);j&&(!j.chats||j.chats.length===0||ly(j.chats,m))&&(k.current=!0,f())},[d,m,u,h,f])}function Aa(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const r=e[0];if((r==null?void 0:r.active)===!0)return!0;const n=oa(t);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function eu({sendDaemonCommand:e,activeConv:t,chats:r,updateRouteChats:n,setToasts:a,setClearedTabs:o}){const[i,c]=l.useState(!1),[d,m]=l.useState(!1),u=l.useCallback(async b=>{try{await e("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(x){console.error("Launch failed",x)}},[e]),h=l.useCallback(async(b,x)=>{try{const k=b||(t==null?void 0:t.daemonId)||"",j=await e(k,"switch_chat",{id:x,sessionId:x,...ds(t)}),p=j==null?void 0:j.result;if((j==null?void 0:j.success)===!0||p==="switched"||p==="switched-by-title")return;p===!1||p==="not_found"?er(a,"⚠️ Session tab not found — try refreshing history"):typeof p=="string"&&p.startsWith("error:")?er(a,`⚠️ Switch error: ${p}`):er(a,"⚠️ Session switch failed")}catch(k){console.error("Switch failed",k),er(a,`❌ Switch failed: ${k.message||"connection error"}`)}},[t,e,a]),f=l.useCallback(async()=>{if(!(!t||i)){c(!0);try{const b=us(t);await e(b,"new_chat",{...ds(t)}),vx(b,t.sessionId,oa(t)[0]),o(x=>({...x,[t.tabKey]:Date.now()}))}catch(b){console.error("New chat failed",b)}finally{c(!1)}}},[t,i,e,o]),y=l.useCallback(async()=>{var b,x;if(!(!t||d)){m(!0);try{const k=us(t),j=async()=>e(k,"list_chats",{forceExpand:!0,...ds(t)});let p=await j(),w=(p==null?void 0:p.chats)||((b=p==null?void 0:p.result)==null?void 0:b.chats);Aa(w,t)&&(await new Promise(C=>setTimeout(C,450)),p=await j(),w=(p==null?void 0:p.chats)||((x=p==null?void 0:p.result)==null?void 0:x.chats)),p!=null&&p.success&&Array.isArray(w)&&(n(t.routeId,w),Aa(w,t)&&!Aa(r,t)&&er(a,"⚠️ History dialog did not fully open — try once more"))}catch(k){console.error("Refresh history failed",k)}finally{m(!1)}}},[t,r,d,e,n,a]);return{isCreatingChat:i,isRefreshingHistory:d,handleLaunchIde:u,handleSwitchSession:h,handleNewChat:f,handleRefreshHistory:y}}function dy(e,t){if(e.size!==t.size)return!1;for(const[r,n]of e)if(t.get(r)!==n)return!1;return!0}function uy(e,t){return e.length!==t.length?!1:e.every((r,n)=>r===t[n])}function Tl(e,t){const r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(a=>t[Number(a)]===e[Number(a)])}function nn(e,t){const r=new Set(t),n=t.length>0?[0]:[];for(const[i,c]of e)!r.has(i)||c<=0||n.includes(c)||n.push(c);n.sort((i,c)=>i-c);const a={};n.forEach((i,c)=>{a[i]=c}),n.length===0&&(a[0]=0);const o=new Map;for(const[i,c]of e){if(!r.has(i)||c<=0)continue;const d=a[c];typeof d=="number"&&d>0&&o.set(i,d)}return{assignments:o,groupCount:Math.max(1,n.length),mapping:a,usedGroups:n}}function Al(e,t){const r={};for(const[n,a]of Object.entries(e)){const o=t[Number(n)];typeof o=="number"&&(r[o]=a)}return r}function my(e,t,r){if(t.length===0)return 0;if(typeof r[e]=="number")return r[e];const n=[...t].reverse().find(a=>a<e)??t[0];return r[n]??0}function hy(e,t,r){if(t.length<=1)return[];const n=t.map(i=>e[i]).filter(i=>Number.isFinite(i)),a=n.length===t.length?n:Array(r).fill(100/r),o=a.reduce((i,c)=>i+c,0);return o>0?a.map(i=>i/o*100):Array(r).fill(100/r)}function _l(e,t){const r={};for(const[n,a]of Object.entries(e)){const o=Number(n);r[o>=t?o+1:o]=a}return r}function Ll(e){return Array(e).fill(100/e)}function py({groupAssignments:e,updateGroupAssignments:t,updateFocusedGroup:r,updateGroupActiveTabIds:n,updateGroupTabOrders:a,groupSizes:o,updateGroupSizes:i,isMobile:c,visibleConversations:d,visibleTabKeys:m}){const u=l.useRef(null),h=l.useMemo(()=>nn(e,m),[e,m]),f=h.assignments,y=l.useMemo(()=>c?1:h.groupCount,[h.groupCount,c]),b=y>1,x=l.useCallback((v,g)=>{t(N=>{const I=new Map(nn(N,m).assignments);return g===0?I.delete(v):I.set(v,g),I}),n(N=>({...N,[g]:v})),r(g)},[t,m,n,r]),k=l.useCallback(v=>{t(g=>{const N=nn(g,m).assignments,I=new Map;for(const[S,T]of N)T!==v&&(T>v?I.set(S,T-1):I.set(S,T));return I}),i(g=>{if(g.length<=1)return[];const N=[...g];N.splice(v,1);const I=N.reduce((S,T)=>S+T,0);return I>0?N.map(S=>S/I*100):[]}),r(0)},[t,m,i,r]),j=l.useCallback((v,g)=>{g.preventDefault();const N=u.current;if(!N)return;const I=g.clientX,S=N.offsetWidth,T=o.length===y?[...o]:Ll(y),P=D=>{const O=(D.clientX-I)/S*100,_=[...T];_[v]=Math.max(15,T[v]+O),_[v+1]=Math.max(15,T[v+1]-O),i(_)},A=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",A),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",P),document.addEventListener("mouseup",A)},[o,y,i]),p=l.useCallback((v,g,N)=>{if(y>=4)return;const I=N==="left"?g:g+1;t(S=>{const T=nn(S,m).assignments,P=new Map;for(const A of d){const D=T.get(A.tabKey)??0,L=D>=I?D+1:D;L>0&&P.set(A.tabKey,L)}return I>0&&P.set(v,I),P}),i(S=>{const T=S.length===y?[...S]:Ll(y),P=T[g]??100/y,A=Math.max(15,P/2),D=Math.max(15,P/2),L=[...T];L[g]=A,L.splice(I,0,D);const O=L.reduce((_,M)=>_+M,0);return L.map(_=>_/O*100)}),n(S=>{const T=_l(S,I);return T[I]=v,T}),a(S=>{const T=_l(S,I);return T[I]=[v],T}),r(I)},[y,t,m,d,i,n,a,r]);l.useEffect(()=>{dy(e,f)||t(f)},[e,f,t]),l.useEffect(()=>{const{mapping:v,usedGroups:g}=h;n(N=>{const I=Al(N,v);return Tl(N,I)?N:I}),a(N=>{const I=Al(N,v);return Tl(N,I)?N:I}),r(N=>{const I=c?0:my(N,g,v);return N===I?N:I}),i(N=>{const I=c?[]:hy(N,g,h.groupCount);return uy(N,I)?N:I})},[h,c,n,a,r,i]);const w=l.useMemo(()=>{const v=Array.from({length:y},()=>[]);for(const g of d){const N=f.get(g.tabKey)??0,I=Math.min(N,y-1);v[I].push(g)}return v},[d,f,y]),C=l.useCallback(()=>{t(new Map),r(0)},[t,r]);return{containerRef:u,normalizedGroupAssignments:f,numGroups:y,isSplitMode:b,groupedConvs:w,moveTabToGroup:x,closeGroup:k,handleResizeStart:j,splitTabRelative:p,clearAllSplits:C}}function _a(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="stable"||t==="latest"?"stable":t==="preview"||t==="next"?"preview":null}function fy(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="latest"||t==="stable"?"latest":t==="next"||t==="preview"?"next":null}function an(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function ni(e){const t=e.updatePolicy&&typeof e.updatePolicy=="object"?e.updatePolicy:{},r=_a(t.channel)||_a(e.updateChannel)||_a(e.releaseChannel)||void 0,n=fy(t.npmTag)||(r==="preview"?"next":r==="stable"?"latest":void 0),a=an(t.targetVersion)||an(e.serverVersion)||void 0,o=an(t.minVersion)||void 0,i=an(t.updateCommand)||(r?`adhdev update --channel ${r}`:void 0);return{...r?{channel:r}:{},...n?{npmTag:n}:{},...a?{targetVersion:a}:{},...o?{minVersion:o}:{},...i?{updateCommand:i}:{}}}function Ts(e,t=null){return ni(e).targetVersion||t}function tu(e){return ni(e).channel||null}function su(e){const t=ni(e);return{...t.channel?{channel:t.channel}:{},...t.npmTag?{npmTag:t.npmTag}:{},...t.targetVersion?{targetVersion:t.targetVersion}:{},...Object.keys(t).length>0?{updatePolicy:t}:{}}}function xy({ides:e,sendDaemonCommand:t}){const r="0.9.82",n=l.useMemo(()=>e.filter(h=>h.type!=="adhdev-daemon"?!1:Zo(h,Ts(h,r))).sort((h,f)=>Number(gr(f,Ts(f,r)))-Number(gr(h,Ts(h,r)))),[r,e]),a=l.useMemo(()=>n.some(h=>gr(h,Ts(h,r))),[r,n]),o=l.useMemo(()=>n.map(h=>Ts(h,r)).find(h=>typeof h=="string"&&h.trim().length>0)||r,[r,n]),[i,c]=l.useState(!1),[d,m]=l.useState({}),u=l.useCallback(async h=>{var y,b;const f=e.find(x=>x.id===h);if(f){m(x=>({...x,[h]:"upgrading"}));try{const x=await t(h,"daemon_upgrade",su(f));(y=x==null?void 0:x.result)!=null&&y.upgraded||(b=x==null?void 0:x.result)!=null&&b.success?m(k=>({...k,[h]:"done"})):m(k=>({...k,[h]:"error"}))}catch{m(x=>({...x,[h]:"error"}))}}},[e,t]);return{versionMismatchDaemons:n,hasRequiredVersionDaemons:a,targetVersion:o,versionBannerDismissed:i,setVersionBannerDismissed:c,upgradingDaemons:d,handleBannerUpgrade:u}}const ru=80;function kn(e,t=Date.now()){return typeof e=="number"&&Number.isFinite(e)?e:t}function by(e){return{...e,createdAt:kn(e.createdAt),updatedAt:kn(e.updatedAt,e.createdAt),lastEventAt:kn(e.lastEventAt,e.updatedAt||e.createdAt)}}function gy(e){const t=Nr(e);return t==="unknown:"?e.id:t}function yy(e){return[e.type,md(e)||"",e.lastMessageHash||"",String(e.lastMessageAt||e.lastUpdated||0)].join("|")}function vy(e,t=ru){const r=new Map;for(const n of e){if(n.deletedAt)continue;const a=gy(n),o=r.get(a);if(!o){r.set(a,n);continue}(n.updatedAt>o.updatedAt||n.updatedAt===o.updatedAt&&n.createdAt>o.createdAt)&&r.set(a,n)}return Array.from(r.values()).sort((n,a)=>{const o=a.updatedAt-n.updatedAt;return o!==0?o:a.createdAt-n.createdAt}).slice(0,Math.max(0,t))}function wy(e,t){const r=Date.now(),n=[];for(const a of e){const o=a.sessionId?t.get(a.sessionId):void 0;if(o!=null&&o.surfaceHidden)continue;const i=ra(a,t),c=i.inboxBucket==="needs_attention"?"needs_attention":i.inboxBucket==="task_complete"&&i.unread?"task_complete":null;if(!c)continue;const d=kn(a.lastMessageAt||(o==null?void 0:o.lastUpdated)||a.lastUpdated,r),m=yy({type:c,sessionId:a.sessionId,providerSessionId:a.providerSessionId,tabKey:a.tabKey,lastMessageHash:a.lastMessageHash,lastMessageAt:a.lastMessageAt,lastUpdated:(o==null?void 0:o.lastUpdated)||a.lastUpdated});n.push(by({id:m,dedupKey:m,type:c,routeId:a.routeId,machineId:a.daemonId||a.routeId,sessionId:a.sessionId,providerSessionId:a.providerSessionId,tabKey:a.tabKey,title:sd(a),preview:Lf(a),createdAt:d,updatedAt:d,lastEventAt:d}))}return vy(n)}function jy(e){return e.filter(t=>!t.readAt&&!t.deletedAt).length}function ky(e){const{conversations:t,liveSessionInboxState:r,maxItems:n=ru}=e,a=l.useMemo(()=>wy(t,r).slice(0,Math.max(0,n)),[t,r,n]),o=l.useMemo(()=>jy(a),[a]);return{notifications:a,unreadCount:o}}function Sy({notifications:e,sendDaemonCommand:t}){const r=l.useCallback(o=>{const i=e.find(d=>d.id===o),c=Math.max(Date.now(),(i==null?void 0:i.updatedAt)||0);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_session_seen",{sessionId:i.sessionId,seenAt:c}).catch(()=>{})},[e,t]),n=l.useCallback(o=>{const i=e.find(c=>c.id===o);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_notification_unread",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]),a=l.useCallback(o=>{const i=e.find(c=>c.id===o);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"delete_notification",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]);return{handleMarkDashboardNotificationRead:r,handleMarkDashboardNotificationUnread:n,handleDeleteDashboardNotification:a}}const Ny=l.createContext(null);function nu(){return l.useContext(Ny)}function ai(...e){const t=new Set,r=[],n=a=>{const o=typeof a=="string"?a.trim():"";if(!o)return;const i=o.toLowerCase();t.has(i)||(t.add(i),r.push(o))};for(const a of e){if(Array.isArray(a)){for(const o of a)n(o);continue}n(a)}return r}function Cy(e){const t=e.trim();if(!t)return null;if(t.startsWith("~"))return t;if(/^[A-Za-z]:$/.test(t))return`${t[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(t))return`${t[0].toUpperCase()}:${t.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(t))return`${t[0].toUpperCase()}:\\${t.slice(2).replace(/[\\/]+/g,"\\")}`;const r=t.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),a=(r[2]||"").replace(/[\\/]+/g,"\\");return a?`${n}:\\${a}`:`${n}:\\`}return null}function oi(e,t=[]){if(e==="win32"){for(const r of t){if(typeof r!="string")continue;const n=Cy(r);if(n)return n}return"C:\\"}for(const r of t){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function Iy(e){const t=e.replace(/[\\/]+$/,"");if(!t||t==="/"||/^[A-Za-z]:$/.test(t))return null;const r=t.includes("\\")?"\\":"/",n=t.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}function My(e){return e!=null&&e.result&&typeof e.result=="object"&&"success"in e.result?e.result:e}async function ii(e,t,r){const n=await e(t,"file_list_browse",{path:r}),a=My(n);if(!(a!=null&&a.success))throw new Error((a==null?void 0:a.error)||(n==null?void 0:n.error)||"Could not browse folder");const o=typeof(a==null?void 0:a.path)=="string"?a.path:r,i=o.includes("\\")?"\\":"/",c=(m,u)=>/^[A-Za-z]:\\?$/.test(m)?`${m.replace(/\\?$/,"\\")}${u}`:m==="/"||m==="\\"?`${i}${u}`:`${m.replace(/[\\/]+$/,"")}${i}${u}`,d=Array.isArray(a==null?void 0:a.files)?a.files.filter(m=>(m==null?void 0:m.type)==="directory"&&typeof(m==null?void 0:m.name)=="string").map(m=>({name:m.name,path:typeof(m==null?void 0:m.path)=="string"&&m.path.trim()?m.path:c(o,m.name)})).sort((m,u)=>m.name.localeCompare(u.name)):[];return{path:o,directories:d}}function Ty(e,t){const r={meshId:t.meshId||"",workspace:t.workspace||"",serverName:t.serverName||"adhdev-mesh",adhdevMcpCommand:t.adhdevMcpCommand||"adhdev-mcp"};return e.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g,(n,a)=>r[a]||"")}function au(e,t={}){const r=e==null?void 0:e.mcpConfig;return(r==null?void 0:r.mode)!=="manual"?null:{serverName:r.serverName||"adhdev-mesh",configFormat:r.format,configPathCommand:r.configPathCommand,requiresRestart:r.requiresRestart===!0,instructions:r.instructions||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:Ty(r.template||"",{...t,serverName:r.serverName||"adhdev-mesh"})}}function Ay(e){if(!e||typeof e!="object")return null;const t=e,r=typeof t.instructions=="string"?t.instructions:"",n=typeof t.template=="string"?t.template:"";return!r&&!n?null:{serverName:typeof t.serverName=="string"?t.serverName:void 0,configFormat:typeof t.configFormat=="string"?t.configFormat:void 0,configPathCommand:typeof t.configPathCommand=="string"?t.configPathCommand:void 0,requiresRestart:t.requiresRestart===!0,instructions:r||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:n}}function Cr(e){return`/dashboard?activeTab=${encodeURIComponent(e)}`}function ou(e){return Rr(e)||e.tabKey||e.routeId||null}function iu(e){const t=typeof e.entrySessionId=="string"?e.entrySessionId.trim():"",r=typeof e.entryInstanceId=="string"?e.entryInstanceId.trim():"",n=typeof e.entryRouteId=="string"?e.entryRouteId.trim():"",a=e.conversations.find(o=>{if(n&&o.routeId!==n)return!1;const i=[o.providerSessionId,o.sessionId,o.nativeSessionId,o.tabKey].map(c=>typeof c=="string"?c.trim():"").filter(Boolean);return!!(t&&i.includes(t)||r&&i.includes(r)||n&&o.routeId===n)});if(a!=null&&a.tabKey)return a.tabKey;if(n){const o=$t(e.conversations,n)||e.conversations.find(i=>i.routeId===n);if(o!=null&&o.tabKey)return o.tabKey}return t||r||n||null}function Qt(e){return String(e||"").trim()}function lu(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function qn(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function _y(e,t){return!e||!t?!1:e===t||e.endsWith(`/${t}`)||t.endsWith(`/${e}`)}function Ly(e,t){const r=Qt(e.providerSessionId),n=Qt(e.targetSessionId),a=t.find(o=>{const i=[o.providerSessionId,o.sessionId,o.nativeSessionId,o.tabKey,o.routeId].map(Qt).filter(Boolean);return!!(r&&i.includes(r)||n&&i.includes(n))});return a?a.tabKey:n||r||null}function Py(e,t,r){if(t.event!=="agent:generating_completed")return null;const n=lu(t.daemonId);if(n&&n!==e.machineId)return null;const a=Qt(t.providerType);if(e.providerType&&a!==e.providerType)return null;const o=Qt(e.resumeSessionId),i=Qt(e.launchedSessionId),c=Qt(t.providerSessionId),d=Qt(t.targetSessionId);if(o&&o!==c&&o!==d||i&&i!==c&&i!==d)return null;const m=qn(e.workspacePath);if(m){const u=qn(t.workspaceName);if(u&&!_y(u,m))return null}return Ly(t,r)}function Pl(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function Ry({ides:e,conversations:t,onOpenSession:r}){const[n,a]=l.useState(null),o=l.useRef(null),i=l.useCallback(()=>{o.current=null,a(null)},[]),c=l.useCallback(d=>{o.current=d,a(d)},[]);return l.useEffect(()=>{if(!n)return;const d=qn(n.workspacePath),m=e.find(h=>{var k,j,p,w;if(!h||h.type==="adhdev-daemon"||lu(h.daemonId||h.id)!==n.machineId||(Sr(h)?"cli":Ls(h)?"acp":"ide")!==n.kind)return!1;const b=String(h.agentType||h.type||"");if(n.providerType&&b!==n.providerType)return!1;if(n.resumeSessionId)return String(h.providerSessionId||"")===n.resumeSessionId;if(n.launchedSessionId){const C=String(n.launchedSessionId||"");return[h.providerSessionId,h.sessionId,h.instanceId,h.id].map(g=>String(g||"")).filter(Boolean).includes(C)}if(d){const C=qn(h.workspace||h.runtimeWorkspaceLabel);return C?C===d:!1}return Number(h.lastUpdated||h._lastUpdate||h.timestamp||((w=(p=(j=(k=h.activeChat)==null?void 0:k.messages)==null?void 0:j.at)==null?void 0:p.call(j,-1))==null?void 0:w.timestamp)||0)>=n.startedAt-5e3});if(!m)return;const u=iu({entrySessionId:m.sessionId,entryInstanceId:m.instanceId,entryRouteId:m.id,conversations:t});u&&(i(),r(u))},[i,t,e,r,n]),l.useEffect(()=>Je.onStatusEvent(d=>{const m=o.current;if(!m)return;const u=Py(m,d,t);u&&(i(),r(u))}),[i,t,r]),l.useEffect(()=>{if(!n)return;const d=window.setTimeout(()=>{a(m=>!m||m.startedAt!==n.startedAt?m:(o.current=null,null))},45e3);return()=>window.clearTimeout(d)},[n]),{trackPendingLaunch:c}}function Dy({sendDaemonCommand:e,trackPendingLaunch:t,onOpenSession:r,activeConv:n,ides:a,setCliViewModeOverrides:o}){const i=nu(),{launchCli:c}=Zn(),d=l.useCallback(async(k,j)=>ii(e,k,j),[e]),m=l.useCallback(async(k,j)=>{if(!j.trim())return{ok:!1,error:"Choose a workspace path first."};try{const p=await e(k,"workspace_add",{path:j.trim()});return p!=null&&p.success?{ok:!0}:{ok:!1,error:(p==null?void 0:p.error)||"Could not save workspace"}}catch(p){return{ok:!1,error:p instanceof Error?p.message:"Could not save workspace"}}},[e]),u=l.useCallback(async(k,j,p)=>{var w;try{const C={ideType:j,enableCdp:!0};(w=p==null?void 0:p.workspacePath)!=null&&w.trim()&&(C.workspace=p.workspacePath.trim());const v=await e(k,"launch_ide",C);return!(v!=null&&v.success)&&(v==null?void 0:v.success)!==void 0?{ok:!1,error:(v==null?void 0:v.error)||"Could not launch IDE"}:(t({machineId:k,kind:"ide",providerType:j,workspacePath:(p==null?void 0:p.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(C){return{ok:!1,error:C instanceof Error?C.message:"Could not launch IDE"}}},[e,t]),h=l.useCallback(async(k,j,p,w)=>{var v,g,N;const C=Date.now();try{const I={cliType:p};(v=w==null?void 0:w.workspacePath)!=null&&v.trim()?I.dir=w.workspacePath.trim():w!=null&&w.workspaceId&&(I.workspaceId=w.workspaceId),(g=w==null?void 0:w.resumeSessionId)!=null&&g.trim()&&(I.resumeSessionId=w.resumeSessionId.trim()),Array.isArray(w==null?void 0:w.cliArgs)&&w.cliArgs.length>0&&(I.cliArgs=w.cliArgs),(N=w==null?void 0:w.initialModel)!=null&&N.trim()&&(I.initialModel=w.initialModel.trim());const S=await c(k,I),T=(S==null?void 0:S.result)||S,P=(T==null?void 0:T.sessionId)||(T==null?void 0:T.id);return S!=null&&S.success&&P?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,launchedSessionId:P,startedAt:C}),{ok:!0}):S!=null&&S.success?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,startedAt:C}),{ok:!0}):{ok:!1,error:(S==null?void 0:S.error)||(T==null?void 0:T.error)||`Could not launch ${j.toUpperCase()} session`}}catch(I){return Pl(I)?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,startedAt:C}),{ok:!0}):{ok:!1,error:I instanceof Error?I.message:`Could not launch ${j.toUpperCase()} session`}}},[c,e,t]),f=l.useCallback(async k=>{var j;if(i!=null&&i.listMeshes)return i.listMeshes(k);if(!k)return[];try{const p=await e(k,"list_meshes",{}),w=(p==null?void 0:p.result)??p;if((w==null?void 0:w.success)===!1)throw new Error((w==null?void 0:w.error)||"Could not load meshes");return(Array.isArray(w==null?void 0:w.meshes)?w.meshes:Array.isArray((j=w==null?void 0:w.result)==null?void 0:j.meshes)?w.result.meshes:[]).map(v=>{var g;return{id:String((v==null?void 0:v.id)||""),name:String((v==null?void 0:v.name)||(v==null?void 0:v.id)||"Untitled mesh"),repoIdentity:(v==null?void 0:v.repoIdentity)||(v==null?void 0:v.repo_identity)||null,workspace:Array.isArray(v==null?void 0:v.nodes)&&v.nodes.length>0?String(((g=v.nodes[0])==null?void 0:g.workspace)||""):null,nodesCount:Array.isArray(v==null?void 0:v.nodes)?v.nodes.length:void 0,status:(v==null?void 0:v.status)||null}}).filter(v=>v.id)}catch(p){throw console.error("List meshes failed",p),p}},[i,e]),y=l.useCallback(async(k,j,p)=>{if(!j.trim())return{ok:!1,error:"Choose a mesh first."};if(i!=null&&i.launchMeshCoordinator)return i.launchMeshCoordinator(k,j,p);const w=Date.now();try{const C={meshId:j.trim()};p.trim()&&(C.cliType=p.trim());const v=await e(k,"launch_mesh_coordinator",C),g=(v==null?void 0:v.result)??v;if((g==null?void 0:g.success)===!1||(v==null?void 0:v.success)===!1){const I=String((g==null?void 0:g.code)||(v==null?void 0:v.code)||""),S=Ay((g==null?void 0:g.meshCoordinatorSetup)||(g==null?void 0:g.manualSetup)||(v==null?void 0:v.meshCoordinatorSetup)||(v==null?void 0:v.manualSetup));return{ok:!1,error:(g==null?void 0:g.error)||(v==null?void 0:v.error)||"Could not launch mesh coordinator",code:I||void 0,manualSetup:S}}const N=(g==null?void 0:g.sessionId)||(g==null?void 0:g.id);return N?r(N):t({machineId:k,kind:"cli",providerType:(g==null?void 0:g.cliType)||p.trim()||void 0,workspacePath:(g==null?void 0:g.workspace)||null,startedAt:w}),{ok:!0}}catch(C){return Pl(C)?(t({machineId:k,kind:"cli",providerType:p.trim()||void 0,startedAt:w}),{ok:!0}):{ok:!1,error:C instanceof Error?C.message:"Could not launch mesh coordinator"}}},[i,r,e,t]),b=l.useCallback(async(k,j)=>{if(!k||!j)return[];try{const p=await e(k,"list_saved_sessions",{providerType:j,kind:"cli",limit:30}),w=(p==null?void 0:p.result)??p;return Array.isArray(w==null?void 0:w.sessions)?w.sessions:[]}catch(p){return console.error("List saved sessions failed",p),[]}},[e]),x=l.useCallback(async k=>{await Vd({conversation:n,mode:k,ides:a,sendDaemonCommand:e,setCliViewModeOverrides:o})},[n,a,e,o]);return{handleBrowseMachineDirectory:d,handleSaveMachineWorkspace:m,handleLaunchMachineIde:u,handleLaunchMachineProvider:h,handleListMachineMeshes:f,handleLaunchMeshCoordinator:y,handleListMachineSavedSessions:b,setActiveCliViewMode:x}}function Ey(e){switch(e){case"notification-open":case"toast-open":case"conversation-open":case"requested-tab":return!0;case"dockview-shortcut":case"dockview-focus":case"dockview-move":case"dockview-split":case"stored-layout-restore":case"passive-tab-sync":return!1;default:return!1}}function $y(e,t,r=Date.now()){return!e||!Ey(t)?null:{tabKey:e,nonce:r}}function By({isMobile:e,conversations:t,visibleConversations:r,groupActiveTabIds:n,focusedGroup:a,groupedConvs:o,setSearchParams:i}){const[c,d]=l.useState(null),[m,u]=l.useState(null),h=l.useMemo(()=>{var k,j;if(!e){if(c){const p=t.find(w=>w.tabKey===c);if(p)return p}return r[0]}const x=n[a];if(x){const p=t.find(w=>w.tabKey===x);if(p)return p}return((k=o[a])==null?void 0:k[0])||((j=o[0])==null?void 0:j[0])},[t,c,a,n,o,e,r]),f=l.useCallback(x=>{d(x)},[]),y=l.useCallback(x=>{d(x.tabKey),i(k=>{const j=new URLSearchParams(k),p=Rf(x);return p?j.set("activeTab",p):j.delete("activeTab"),j},{replace:!0})},[i]),b=l.useCallback((x,k)=>{const j=$y(x,k);j&&u(j)},[]);return{activeConv:h,openDesktopConversation:y,requestScrollToBottom:b,scrollToBottomRequest:m,setDesktopActiveTab:f}}function Oy(e){const t=e.completedKey||null,r=e.pendingKey||null;return e.shouldMarkSeen?t===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:r!==null&&r!==e.autoReadKey,nextPendingKey:r===e.autoReadKey?r:null}:r===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:!1,nextPendingKey:r}:{shouldSchedule:!0,shouldCancelPending:r!==null&&r!==e.autoReadKey,nextPendingKey:e.autoReadKey}:{shouldSchedule:!1,shouldCancelPending:!!r,nextPendingKey:null}}function Fy(e){const t=String(e.liveState.completionMarker||""),r=String(e.liveState.seenCompletionMarker||""),n=String(e.liveState.inboxBucket||"idle"),a=!!e.liveState.unread,o=[e.tabKey,e.historySessionId||"",t,r,n,a?"1":"0"].join(":");return{shouldMarkSeen:!!(n==="task_complete"&&a&&(!t||t!==r)),autoReadKey:o,completionMarker:t,readAt:Math.max(Date.now(),e.timestamp||0,e.liveState.lastUpdated||0)}}function Hy({activeConv:e,isMobile:t,liveSessionInboxState:r,sendDaemonCommand:n}){const a=l.useRef(null),o=l.useRef(null),i=l.useRef(null),c=l.useRef(null),d=l.useRef(null);l.useEffect(()=>{const m=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(clearTimeout(c.current),c.current=null),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null),o.current=null};if(t){m(),a.current=null;return}if(!(e!=null&&e.sessionId)){m(),a.current=null;return}const u=Rn(e,r),h=Fy({tabKey:e.tabKey,historySessionId:Rr(e)||"",lastMessageHash:e.lastMessageHash||"",lastMessageAt:Number(e.lastMessageAt||0),timestamp:fs(e),liveState:u}),f=h.autoReadKey,y=Oy({autoReadKey:f,shouldMarkSeen:h.shouldMarkSeen,completedKey:a.current,pendingKey:o.current});if(!h.shouldMarkSeen){y.shouldCancelPending&&m(),a.current=f;return}if(!y.shouldSchedule)return;y.shouldCancelPending&&m();const b=()=>{if(document.visibilityState!=="visible"||a.current===f)return;a.current=f,o.current=null,i.current=null,c.current=null,d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null);const k=h.readAt;n(e.daemonId||e.routeId,"mark_session_seen",{sessionId:e.sessionId,providerSessionId:e.providerSessionId,seenAt:k,completionMarker:h.completionMarker}).catch(()=>{})};if(o.current=y.nextPendingKey,document.visibilityState==="visible"){i.current=setTimeout(b,1500);const k=()=>{document.visibilityState!=="visible"&&i.current&&(clearTimeout(i.current),i.current=null)};d.current=k,document.addEventListener("visibilitychange",k);return}const x=()=>{document.visibilityState==="visible"&&(c.current&&clearTimeout(c.current),c.current=setTimeout(b,800),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null))};d.current=x,document.addEventListener("visibilitychange",x)},[e,t,r,n]),l.useEffect(()=>()=>{i.current&&clearTimeout(i.current),c.current&&clearTimeout(c.current),d.current&&document.removeEventListener("visibilitychange",d.current)},[])}function La(e){if(!e)return"";const t=String(e.workspacePath||"").trim();if(t)return t;const r=String(e.workspaceName||"").trim();return/^(?:~\/|\/|[A-Za-z]:[\\/])/.test(r)?r:""}function Wy({activeConv:e,remoteDialogConv:t,remoteDialogActiveConv:r,ides:n,sendDaemonCommand:a,updateRouteChats:o,setToasts:i,setClearedTabs:c,setSearchParams:d}){var $;const{launchCli:m}=Zn(),[u,h]=l.useState(!1),[f,y]=l.useState([]),[b,x]=l.useState(()=>jt()),[k,j]=l.useState(!1),[p,w]=l.useState(null),C=l.useRef(null),v=l.useMemo(()=>r||t||e,[e,r,t]),g=!!v&&Ye(v)&&!Ve(v),N=l.useMemo(()=>{if(!v||!g)return null;const W=v.daemonId||v.routeId||"",B=Kt(v),F=La(v);return`${W}:${B}:${v.providerSessionId||""}:${F}`},[v,g]),I=l.useMemo(()=>!v||!g?"":La(v),[v,g]),{isCreatingChat:S,isRefreshingHistory:T,handleSwitchSession:P,handleNewChat:A,handleRefreshHistory:D}=eu({sendDaemonCommand:a,activeConv:v,chats:($=n.find(W=>W.id===(v==null?void 0:v.routeId)))==null?void 0:$.chats,updateRouteChats:o,setToasts:i,setClearedTabs:c}),L=l.useCallback(()=>{h(!0)},[]),O=l.useCallback(()=>{h(!1)},[]),_=l.useCallback(async()=>{if(!(!v||!g||k)){j(!0);try{const W=v.daemonId||v.routeId,B=Kt(v),F=La(v),K=await a(W,"list_saved_sessions",{agentType:B,providerType:B,kind:"cli",limit:50,...v.providerSessionId?{providerSessionId:v.providerSessionId}:{},...F?{workspace:F}:{}}),Y=(K==null?void 0:K.result)??K;y(Array.isArray(Y==null?void 0:Y.sessions)?Y.sessions:[])}catch(W){console.error("Refresh saved sessions failed",W),y([])}finally{j(!1)}}},[v,k,g,a]);l.useEffect(()=>{if(!u){C.current=null;return}if(!g){C.current=null,y([]),j(!1);return}!N||k||C.current!==N&&(C.current=N,_())},[_,u,k,g,N]);const M=l.useCallback(async W=>{if(!v||!g||!W.providerSessionId||!W.workspace)return;const B=v.daemonId||v.routeId,F=Kt(v);try{w(W.providerSessionId);const K=await m(B,{cliType:F,dir:W.workspace,resumeSessionId:W.providerSessionId,initialModel:qc(W.summaryMetadata,"model",{preferShortValue:!0})||void 0}),Y=(K==null?void 0:K.result)??K,re=typeof(Y==null?void 0:Y.sessionId)=="string"?Y.sessionId:typeof(Y==null?void 0:Y.id)=="string"?Y.id:"";re&&d(ae=>{const he=new URLSearchParams(ae);return he.set("activeTab",re),he},{replace:!0}),O()}catch(K){console.error("Resume saved session failed",K)}finally{w(null)}},[O,v,g,a,d]);return{historyModalOpen:u,openHistoryModal:L,closeHistoryModal:O,historyTargetConv:v,isSavedSessionHistoryTarget:g,isHistoryCreatingChat:S,isHistoryRefreshingHistory:T,handleHistorySwitchSession:P,handleHistoryNewChat:A,handleHistoryRefresh:D,savedHistorySessions:f,savedHistoryFilters:b,setSavedHistoryFilters:x,missingWorkspaceResumePath:I,isSavedHistoryLoading:k,resumingSavedHistorySessionId:p,handleRefreshSavedHistory:_,handleResumeSavedHistorySession:M}}function Ky({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c}){const[d,m]=l.useState(null),[u,h]=l.useState(null),f=l.useMemo(()=>{if(e||!n)return null;const j=c(n);return j&&!Ye(j)&&!Ve(j)?j:null},[e,n,c]),y=l.useMemo(()=>{const j=d==null?void 0:d.routeId;if(!j)return null;const p=d!=null&&d.tabKey?o.find(w=>w.tabKey===d.tabKey):a?o.find(w=>w.tabKey===a):null;return(p==null?void 0:p.routeId)===j?p:$t(o,j)},[o,d,a]),b=l.useMemo(()=>{if(y)return i.find(j=>j.id===y.routeId)},[i,y]);l.useEffect(()=>{f&&(m({routeId:f.routeId,tabKey:el(f)}),h(f),r({pathname:t.pathname,search:t.search},{replace:!0,state:null}))},[t.pathname,t.search,r,f]);const x=l.useCallback(j=>{j&&(m({routeId:j.routeId,tabKey:el(j)}),h(j))},[]),k=l.useCallback(()=>{m(null),h(null)},[]);return{remoteDialogConv:y,remoteDialogIdeEntry:b,remoteDialogActiveConv:u,setRemoteDialogActiveConv:h,openRemoteDialog:x,closeRemoteDialog:k}}function Uy({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c,activeConv:d,sendDaemonCommand:m}){const{remoteDialogConv:u,remoteDialogIdeEntry:h,remoteDialogActiveConv:f,setRemoteDialogActiveConv:y,openRemoteDialog:b,closeRemoteDialog:x}=Ky({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c}),[k,j]=l.useState(!1),[p,w]=l.useState(null),C=l.useCallback(async N=>{const I=N||d;!I||!Ye(I)&&!Ve(I)||(w(I),j(!0))},[d]),v=l.useCallback(()=>{j(!1),w(null)},[]),g=l.useCallback(async N=>{const I=p||d;if(!I||!Ye(I)&&!Ve(I)){v();return}j(!1);try{const S=Kt(I),T=I.routeId||I.daemonId||"";await m(T,"stop_cli",{cliType:S,targetSessionId:I.sessionId,mode:N})}catch(S){console.error("Stop CLI failed:",S)}finally{w(null)}},[d,v,p,m]);return{remoteDialogConv:u,remoteDialogIdeEntry:h,remoteDialogActiveConv:f,setRemoteDialogActiveConv:y,openRemoteDialog:b,closeRemoteDialog:x,cliStopDialogOpen:k,cliStopTargetConv:p,requestCliStop:C,cancelCliStop:v,confirmCliStop:g}}function cu({conversation:e,className:t="",onOpenNativeConversation:r,onOpenMachine:n,interactive:a=!0,meshOnly:o=!1}){var w,C,v;const i=Tr(),c=js(e),d=o?null:td(e),m=!o&&(e.transport==="cdp-page"||e.transport==="cdp-webview"),u=!o&&e.streamSource==="agent-stream"&&!!e.agentName,h=!o&&!u&&(e.transport==="pty"||e.transport==="acp"),f=Fs(e),y=Pf(e),b=(w=e.settings)==null?void 0:w.meshNodeFor,x=e.meshQueueStats,k=((C=e.coordinator)==null?void 0:C.meshId)||((v=e.settings)==null?void 0:v.meshCoordinatorFor);if(!m&&!u&&!h&&!d&&!b&&!x)return null;const j=l.useCallback(()=>{if(n){n();return}c&&i("/dashboard",{state:{openMachineId:c}})},[c,i,n]),p=l.useCallback(()=>{if(r){r();return}const g=ou(e);g&&i(Cr(g))},[e,i,r]);return s.jsxs("div",{className:`conversation-meta-chips ${t}`.trim(),children:[m&&(a?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:y,children:[s.jsx(Bt,{size:12}),s.jsx("span",{children:y})]}):s.jsxs("span",{className:"conversation-meta-chip",title:y,children:[s.jsx(Bt,{size:12}),s.jsx("span",{children:y})]})),u&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(Os,{size:12}),s.jsx("span",{children:f})]}),h&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(Os,{size:12}),s.jsx("span",{children:f})]}),d&&(a?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:j,title:d,children:[s.jsx(ts,{size:12}),s.jsx("span",{children:d})]}):s.jsxs("span",{className:"conversation-meta-chip",title:d,children:[s.jsx(ts,{size:12}),s.jsx("span",{children:d})]})),b&&s.jsxs("span",{className:"conversation-meta-chip",title:"Mesh node",children:[s.jsx(ts,{size:12}),s.jsx("span",{children:"Mesh Node"})]}),k&&x&&s.jsxs("span",{className:`conversation-meta-chip ${x.pending>0?"is-active":""}`,style:x.failed>0?{color:"var(--color-red-400)",borderColor:"var(--color-red-400)"}:void 0,title:`Queue: ${x.pending} pending, ${x.assigned} assigned, ${x.completed} completed, ${x.failed} failed`,children:[s.jsx(Ch,{size:12}),s.jsxs("span",{children:[x.pending," Pending"]})]})]})}function Pa(e,t=!0){return(e??!0)&&t}const li=l.memo(function({activeConv:t,clearToken:r,isCliTerminal:n,ideEntry:a,terminalRef:o,handleModalButton:i,handleRelaunch:c,handleSendChat:d,handleForceSendChat:m,isSendingChat:u,sendFeedbackMessage:h=null,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j=!0,isVisible:p=!0}){const w=n,C=!n,v=Pa(p,w),g=Pa(p,C),N=Pa(p),I=Wd(t),S=I.status||I.modalMessage||I.modalButtons?{...t,...I.status?{status:I.status}:{},...I.modalMessage!==void 0?{modalMessage:I.modalMessage}:{},...I.modalButtons!==void 0?{modalButtons:I.modalButtons}:{}}:t;return s.jsxs(s.Fragment,{children:[s.jsx(Uc,{activeConv:S,onModalButton:i}),s.jsx(cu,{conversation:S,className:"chat-pane-meta-row mx-3 mt-1",meshOnly:!0}),S.transport!=="pty"&&S.transport!=="acp"&&S.cdpConnected===!1?s.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[s.jsx("span",{className:"text-sm",children:s.jsx(Bs,{size:14})}),s.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),s.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:c,children:"Relaunch with CDP"})]})}):null,S.transport==="pty"?s.jsxs("div",{style:{position:"relative",minHeight:0,flex:"1 1 0%",width:"100%",overflow:"hidden"},children:[s.jsx("div",{"aria-hidden":!n,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:w?"visible":"hidden",pointerEvents:w?"auto":"none"},children:s.jsx(eb,{activeConv:S,clearToken:r,terminalRef:o,handleSendChat:d,isSendingChat:u,sendFeedbackMessage:h,isVisible:v,isInputActive:j&&v})}),s.jsx("div",{"aria-hidden":n,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:C?"visible":"hidden",pointerEvents:C?"auto":"none"},children:s.jsx(yo,{activeConv:S,ideEntry:a,handleSendChat:d,isSendingChat:u,sendFeedbackMessage:h,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j&&g,isVisible:g})})]}):s.jsx(yo,{activeConv:S,ideEntry:a,handleSendChat:d,handleForceSendChat:m,isSendingChat:u,sendFeedbackMessage:h,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j&&N,isVisible:N})]})},(e,t)=>e.activeConv===t.activeConv&&e.isCliTerminal===t.isCliTerminal&&e.ideEntry===t.ideEntry&&e.terminalRef===t.terminalRef&&e.handleModalButton===t.handleModalButton&&e.handleRelaunch===t.handleRelaunch&&e.handleSendChat===t.handleSendChat&&e.handleForceSendChat===t.handleForceSendChat&&e.isSendingChat===t.isSendingChat&&e.sendFeedbackMessage===t.sendFeedbackMessage&&e.handleFocusAgent===t.handleFocusAgent&&e.isFocusingAgent===t.isFocusingAgent&&e.actionLogs===t.actionLogs&&e.userName===t.userName&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isInputActive===t.isInputActive&&e.isVisible===t.isVisible);function zy({selectedConversation:e,isAcp:t,isStandalone:r,selectedIdeEntry:n,actionLogs:a,userName:o,isSendingChat:i,sendFeedbackMessage:c=null,isFocusingAgent:d,onBack:m,onOpenNativeConversation:u,onOpenMachine:h,onOpenHistory:f,onOpenRemote:y,onOpenMeshGraph:b,onStopCli:x,cliViewMode:k,onSetCliViewMode:j,handleSendChat:p,handleForceSendChat:w,handleFocusAgent:C,handleModalButton:v,handleRelaunch:g}){var A,D;const N=l.useRef(null),I=Ye(e)&&!t,S=I&&k==="terminal",T=!!e.daemonId&&!!((A=e.coordinator)!=null&&A.meshId||(D=e.settings)!=null&&D.meshCoordinatorFor),P=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center justify-between gap-3 ${P} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:m,type:"button","aria-label":"Back",children:s.jsx(Ro,{size:18})}),s.jsxs("div",{className:"min-w-0 flex-1 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:nt(e)}),s.jsx("div",{className:"min-w-0 max-w-full text-xs text-text-secondary",children:s.jsx(cu,{conversation:e,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>u(e),onOpenMachine:()=>h(e)})})]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[I&&k&&s.jsx(kd,{mode:k,onChange:j,compact:!0}),I&&x&&s.jsx("button",{onClick:()=>{x(e)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(xt,{size:14})}),T&&b&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>b(e),type:"button",title:"Open live repo mesh graph","aria-label":"Open live repo mesh graph",children:s.jsx(Zt,{size:14})}),s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(e),type:"button",children:s.jsx(Do,{size:14})}),!t&&!I&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>y(e),type:"button",children:s.jsx(Bt,{size:14})})]})]}),s.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:s.jsx(li,{activeConv:e,clearToken:0,isCliTerminal:S,ideEntry:n,terminalRef:N,handleModalButton:v,handleRelaunch:g,handleSendChat:p,handleForceSendChat:w,isSendingChat:i,sendFeedbackMessage:c,handleFocusAgent:C,isFocusingAgent:d,actionLogs:a,userName:o})})]})}const Ra={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function Gy(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function du(){const[e,t]=l.useState("unix"),[r,n]=l.useState("powershell"),[a,o]=l.useState(!1),i=e==="unix"?"unix":r;l.useEffect(()=>{t(Gy())},[]);const c=l.useCallback(()=>{navigator.clipboard.writeText(Ra[i].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[i]);return s.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${e==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>t("unix"),children:"🍎🐧 macOS / Linux"}),s.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${e==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>t("windows"),children:"🪟 Windows"})]}),e==="windows"&&s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),s.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),s.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:c,title:"Click to copy",children:[s.jsx("span",{className:"text-text-muted select-none",children:Ra[i].prompt}),s.jsx("span",{className:"flex-1 break-all",children:Ra[i].cmd}),s.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:a?"✓":"📋"})]}),s.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",s.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function uu({section:e,onSectionChange:t}){const r=[{key:"machines",label:"Machines",icon:Bt},{key:"chats",label:"Chats",icon:ws}];return s.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:s.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:a,icon:o})=>{const i=e===n;return s.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${i?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:i?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>t(n),type:"button","aria-pressed":i,children:[s.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${i?"text-accent-primary":"bg-transparent text-current"}`,style:i?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:s.jsx(o,{size:15})}),s.jsx("span",{children:a})]},n)})})})}function on({title:e,className:t=""}){return s.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${t}`,children:s.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:e})})}function Ns({children:e,className:t=""}){return s.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${t}`,children:e})}function or({icon:e,title:t,subtitle:r,children:n}){return s.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[s.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:e}),s.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:t}),s.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Vy({conversation:e,onCancel:t,onConfirm:r}){const n=nt(e),a=ys(e);return s.jsxs("div",{className:"fixed inset-0 z-[1400] flex items-end justify-center overflow-y-auto px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",children:[s.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:t}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"mobile-hide-confirm-title",className:"fade-in relative w-full sm:w-[min(92vw,420px)] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] flex flex-col overflow-hidden rounded-[24px] sm:rounded-[18px] border border-border-subtle bg-bg-primary shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border-subtle bg-[var(--surface-primary)] px-4 py-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h3",{id:"mobile-hide-confirm-title",className:"m-0 text-base font-extrabold text-text-primary",children:"Hide this chat from the inbox?"}),s.jsx("div",{className:"mt-1 text-[13px] leading-relaxed text-text-muted",children:"This only collapses the chat locally. You can restore it from Hidden tabs."})]}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary text-text-secondary transition-colors hover:bg-surface-primary hover:text-text-primary",onClick:t,"aria-label":"Cancel hide chat",children:s.jsx(xt,{size:16})})]}),s.jsx("div",{className:"px-4 py-4",children:s.jsxs("div",{className:"rounded-2xl border border-border-subtle bg-bg-secondary/60 px-3.5 py-3",children:[s.jsx("div",{className:"truncate text-sm font-bold text-text-primary",children:n}),s.jsx("div",{className:"mt-1 truncate text-xs text-text-muted",children:a})]})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border-subtle bg-bg-secondary px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))]",children:[s.jsx("button",{type:"button",className:"btn btn-secondary min-h-[40px] px-4 text-sm",onClick:t,children:"Cancel"}),s.jsx("button",{type:"button",className:"btn btn-primary min-h-[40px] px-4 text-sm",onClick:r,children:"Hide tab"})]})]})]})}function ln({item:e,type:t,getAvatarText:r,onOpenConversation:n,onRequestHideConversation:a,onOpenMeshGraph:o,onCollectChatDebugBundle:i,isMuted:c,onToggleMute:d}){var A,D;const m=t==="needs_attention"||t==="task_complete",u=t==="working",h=t==="earlier",f=t==="task_complete",{isReconnecting:y,isConnecting:b}=Ks(e.conversation),x=nt(e.conversation),k=ys(e.conversation),j=vd(e.conversation,{requiresAction:t==="needs_attention"}),p=m?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":u?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":h?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",w=m?"bg-accent-primary shadow-glow":u?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":h?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",C=h?"text-text-secondary":"text-text-primary",v=h?"text-text-muted":"text-text-secondary",g=h?"text-text-secondary opacity-80":"text-text-muted",N=h?"text-text-muted opacity-80":"text-text-muted",I=!u&&!f,S=!!e.conversation.daemonId&&!!((A=e.conversation.coordinator)!=null&&A.meshId||(D=e.conversation.settings)!=null&&D.meshCoordinatorFor),T="text-[color:var(--status-warning)]",P=L=>{if(!i)return;L.preventDefault(),L.stopPropagation();const O=i==null?void 0:i(e.conversation);Promise.resolve(O).catch(_=>{console.warn("[chat-debug-bundle] failed to collect mobile inbox debug bundle",_)})};return s.jsx("div",{className:`group relative overflow-hidden transition-colors active:scale-[0.995] ${p}`,children:s.jsxs("div",{className:"relative flex w-full items-start gap-3.5 px-4 py-3.5 text-left",children:[m||u?s.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,s.jsxs("div",{className:"mobile-inbox-leading-rail flex w-11 shrink-0 flex-col items-center gap-1.5",children:[s.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${w}`,style:m?{color:"var(--accent-on-primary)"}:void 0,children:r(x)}),a&&s.jsxs("button",{type:"button",className:"mobile-inbox-hide-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border border-border-subtle bg-bg-primary/70 px-2 text-[10px] font-semibold text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:L=>{L.preventDefault(),L.stopPropagation(),a()},"aria-label":`Hide ${x}`,title:"Hide conversation",children:[s.jsx(Eo,{size:11}),s.jsx("span",{children:"Hide"})]}),d&&s.jsxs("button",{type:"button",className:`mobile-inbox-mute-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border px-2 text-[10px] font-semibold transition-colors ${c?"border-amber-500/40 bg-amber-500/10 text-amber-300 hover:bg-amber-500/20":"border-border-subtle bg-bg-primary/70 text-text-muted hover:border-border-default hover:text-text-primary"}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),d()},"aria-label":c?`Unmute ${x}`:`Mute ${x}`,title:c?"Unmute (resume notifications)":"Mute notifications",children:[s.jsx(Ar,{size:11}),s.jsx("span",{children:c?"Muted":"Mute"})]}),S&&o&&s.jsxs("button",{type:"button",className:"mobile-inbox-mesh-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border border-border-subtle bg-bg-primary/70 px-2 text-[10px] font-semibold text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:L=>{L.preventDefault(),L.stopPropagation(),o(e.conversation)},"aria-label":`Open mesh graph for ${x}`,title:"Open live repo mesh graph",children:[s.jsx(Zt,{size:11}),s.jsx("span",{children:"Graph"})]})]}),s.jsxs("button",{className:"relative flex min-w-0 flex-1 flex-col gap-0.5 text-left",onClick:()=>n(e.conversation),onContextMenu:P,type:"button",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:`text-[15px] font-bold truncate tracking-tight ${C}`,children:x}),I&&s.jsx("span",{className:`text-[11px] font-medium shrink-0 ${N}`,children:Kc(e.timestamp)})]}),s.jsxs("div",{className:`text-[12px] font-medium truncate flex items-center ${v}`,children:[s.jsx("span",{className:"truncate",children:k}),s.jsx(On,{git:e.conversation.git,compact:!0,className:"ml-1 max-w-[6.5rem] shrink-0"}),y?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:`${T} animate-pulse`,children:"Reconnecting…"})]}):b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-text-muted",children:"Connecting…"})]}):j==="Action needed"&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:T,children:"Action needed"})]})]}),s.jsx("div",{className:`mt-0.5 truncate text-[13px] ${g}`,children:e.preview})]}),m&&!f&&s.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),f&&s.jsx("span",{className:"absolute top-4 right-4 rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Done"}),u&&s.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]})},e.conversation.tabKey)}function Rl({size:e=32}){return s.jsx("div",{className:"flex flex-col items-center gap-2.5",children:s.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:e,height:e}})})}function qy({section:e,attentionItems:t,unreadItems:r,workingItems:n,completedItems:a,hiddenConversations:o,machineCards:i,getAvatarText:c,actionLogs:d,sendDaemonCommand:m,onOpenConversation:u,onShowAllHidden:h,onHideConversation:f,onOpenMeshGraph:y,onOpenNewSession:b,onOpenMachine:x,onOpenSettings:k,onSectionChange:j,wsStatus:p="connected",isStandalone:w=!1,onCollectChatDebugBundle:C,isConversationMuted:v,onToggleMuteConversation:g}){const[N,I]=l.useState(null),S=p==="disconnected"||p==="reconnecting"||p==="offline"||p==="auth_failed",T=i.length>0,P=t.length>0||r.length>0||n.length>0||a.length>0,A=e==="machines"?"Machines":"Chats",D=w?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",L=w?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]",O=l.useCallback(async $=>{const W=us($);if(!W)return;const B=Array.isArray($.messages)?$.messages:[],F=id({activeConv:$,visibleMessages:B,actionLogs:d,visibleBarControlCount:0,chatTailState:{hasMoreHistory:!1,historyError:null,historyMessages:[]},ui:{controlsVisible:!1,visibleLiveCount:B.length,hiddenLiveCount:0,isInputActive:!1,isVisible:!0}}),K=await m(W,"get_chat_debug_bundle",{...ds($),delivery:"daemon_file",frontendSnapshot:F}),Y=fr(K),re=dd(Y),ae=await cd(re);ae==="failed"&&console.warn("[chat-debug-bundle] failed to copy or present mobile inbox debug bundle locator"),Je.showToast(ld(Y,{locatorCopyStatus:ae}),ae==="failed"?"warning":"success")},[d,m]),_=C||O,M=l.useCallback(()=>{N&&(f==null||f(N),I(null))},[N,f]);return s.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[s.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${D}`,children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:A}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e==="chats"&&(t.length>0||r.length>0)&&s.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[s.jsx(Ar,{size:13}),s.jsx("span",{children:t.length+r.length})]}),s.jsx("button",{onClick:k,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:s.jsx(ea,{size:18})})]})]})}),s.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${L}`,children:[e==="machines"&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:S?s.jsx(or,{icon:s.jsx(Rl,{}),title:p==="offline"?"Network offline":p==="auth_failed"?"Session expired":"Reconnecting",subtitle:p==="offline"?"Waiting for network…":p==="auth_failed"?"Please log in again.":"Restoring the server connection…"}):i.length===0?s.jsx(or,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:w?"Waiting for your daemon":"Connect your machines",subtitle:w?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can launch sessions with any installed provider.":"Install ADHDev on a machine, sign in, and it will show up here.",children:!w&&s.jsx("div",{className:"w-full max-w-[360px] mt-4",children:s.jsx(du,{})})}):s.jsx(Ns,{children:i.map(($,W)=>s.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${W>0?"border-t border-border-subtle/70":""}`,onClick:()=>x($.id),type:"button",children:[s.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:c($.label)}),s.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:$.label}),s.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:$.unread>0?s.jsxs("span",{className:"text-accent-primary",children:[$.unread," new"]}):$.total>0?`${$.total} chats`:"Idle"})]}),s.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:$.subtitle}),$.total>0?s.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[$.total," chat",$.total!==1?"s":"",$.unread>0?` · ${$.unread} unread`:""]}):s.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},$.id))})}),e==="chats"&&t.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Needs attention",className:"mb-0"}),s.jsx(Ns,{children:t.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"needs_attention",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&r.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Task complete",className:"mb-0 mt-2"}),s.jsx(Ns,{children:r.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"task_complete",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&n.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Working now",className:"mb-0 mt-2"}),s.jsx(Ns,{children:n.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"working",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[a.length>0&&s.jsx(on,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),a.length>0?s.jsx(Ns,{children:a.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"earlier",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))}):P?s.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):S?s.jsx(or,{icon:s.jsx(Rl,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):T?s.jsx(or,{icon:s.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:s.jsx(ws,{size:20})}),title:"No conversations yet",subtitle:Sd,children:b&&s.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex items-center gap-2 mt-4",onClick:b,"aria-label":Ht,title:Ht,children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),s.jsx("span",{children:Ht})]})}):s.jsx(or,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),e==="chats"&&o.length>0&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:s.jsx(Ns,{className:"mt-4 border-dashed bg-bg-secondary/20",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 text-left",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:"Hidden tabs"}),s.jsxs("div",{className:"mt-0.5 text-[13px] text-text-muted",children:[o.length," collapsed ",o.length===1?"conversation":"conversations"]})]}),s.jsx("button",{type:"button",className:"shrink-0 rounded-full border border-border-subtle bg-bg-primary/70 px-3 py-1.5 text-[12px] font-semibold text-accent-primary hover:border-border-default",onClick:h,children:"Restore all"})]})})})]}),e==="chats"&&b&&P&&s.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:b,"aria-label":Ht,title:Ht,children:s.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),N&&s.jsx(Vy,{conversation:N,onCancel:()=>I(null),onConfirm:M}),s.jsx(uu,{section:e,onSectionChange:j})]})}function Yy(e){if(!e)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(e))}catch{return new Date(e).toLocaleString()}}function mu(e){const t=[e.workspace||"Workspace unknown"],r=gs(e.summaryMetadata);r&&t.push(r),(e.messageCount||0)>0&&t.push(`${e.messageCount} msgs`);const n=Yy(e.lastMessageAt);return{title:e.title||e.providerSessionId,providerSessionId:e.providerSessionId,metaLine:t.join(" · "),updatedLabel:n?`Updated ${n}`:"",preview:(e.preview||"").trim()}}function ci({title:e,description:t,currentPath:r,directories:n,busy:a=!1,error:o="",confirmLabel:i="Use this folder",onClose:c,onNavigate:d,onConfirm:m}){const[u,h]=l.useState(r);l.useEffect(()=>{h(r)},[r]);const f=Iy(r),y=u.trim();return s.jsx("div",{className:"fixed inset-0 z-[110] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:s.jsxs("div",{className:"w-full max-w-2xl max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(86vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:c,"aria-label":"Close folder browser",children:s.jsx(xt,{size:16})})]}),s.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!f||a||d(f)},disabled:!f||a,children:[s.jsx(Ro,{size:15}),"Parent"]}),s.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"text",value:u,onChange:b=>h(b.target.value),onKeyDown:b=>{b.key!=="Enter"||!y||a||(b.preventDefault(),d(y))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!y||a||d(y)},disabled:!y||a,children:"Go"})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:a?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?s.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):n.length===0?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):s.jsx("div",{className:"p-3",children:n.map(b=>s.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(b.path),children:[s.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:s.jsx($s,{size:17})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:b.name}),s.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:b.path})]})]},b.path))})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:c,children:"Cancel"}),s.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>m(y||r),disabled:!y&&!r||a,children:i})]})]})})}function hu({title:e,description:t,details:r,workspaceOptions:n,selectedWorkspaceKey:a,onWorkspaceChange:o,confirmLabel:i="Launch",busyLabel:c="Launching…",busy:d=!1,showArgsInput:m,argsValue:u,onArgsChange:h,showModelInput:f,modelValue:y,onModelChange:b,historyProviderNode:x,onConfirm:k,onCancel:j}){const p=n==null?void 0:n.find(w=>w.key===a);return s.jsx("div",{className:"fixed inset-0 z-[110] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:s.jsxs("div",{className:"w-full max-w-lg max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(88vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:j,"aria-label":"Close launch confirmation",children:s.jsx(xt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-5 sm:py-4 flex flex-col gap-3",children:[n&&n.length>0&&o&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),s.jsx("select",{value:a||"",onChange:w=>o(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:n.map(w=>s.jsx("option",{value:w.key,children:w.label},w.key))}),(p==null?void 0:p.description)&&s.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:p.description})]}),x,r.map(w=>s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:w.label}),s.jsx("div",{className:"text-sm text-text-primary break-all",children:w.value})]},`${w.label}:${w.value}`)),f&&b&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Language Model (Optional)"}),s.jsx("input",{type:"text",value:y||"",onChange:w=>b(w.target.value),placeholder:"Auto-detect or default",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]}),m&&h&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"CLI Arguments (Optional)"}),s.jsx("input",{type:"text",value:u||"",onChange:w=>h(w.target.value),placeholder:"e.g. --experimental",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:j,disabled:d,children:"Cancel"}),s.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:k,disabled:d,children:[s.jsx(Ac,{size:14}),d?c:i]})]})]})})}function Dl(e,t){return t||e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||e}function pu(e){const{machine:t,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:a=!0}=e,o=[];a&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const d of t.workspaces||[])o.push({key:`saved:${d.id}`,label:`${d.id===t.defaultWorkspaceId?"⭐ ":""}${Dl(d.path,d.label)}`,description:d.path,workspaceId:d.id,workspacePath:d.path});const i=(r==null?void 0:r.trim())||"",c=i?(t.workspaces||[]).find(d=>d.path===i):null;if(i&&!c&&o.push({key:`custom:${i}`,label:Dl(i),description:i,workspaceId:null,workspacePath:i}),n){const d=`saved:${n}`;if(o.some(m=>m.key===d))return{options:o,selectedKey:d}}return c?{options:o,selectedKey:`saved:${c.id}`}:i?{options:o,selectedKey:`custom:${i}`}:{options:o,selectedKey:"__home__"}}function Xy(e){return e==="ide"?"IDE":e==="cli"?"CLI":"ACP"}function Jy(e){return[Xy(e.kind),e.subtitle||"",e.providerSessionId?"Saved history":""].filter(Boolean).join(" · ")}function Qy(e){return e.lastLaunchedAt?sa(e.lastLaunchedAt):""}function fu(e){return{metaText:Jy(e),updatedLabel:Qy(e)}}function Da(e,t,r){return e?"ide":t>0?"cli":r>0?"acp":null}function Zy({selectedMachineEntry:e,cliProviders:t,acpProviders:r,machineAction:n,onBrowseDirectory:a,onListSavedSessions:o}){var et,ct,Xe,pt;const i=Pr(),[c,d]=l.useState(!1),m=(((et=e.detectedIdes)==null?void 0:et.length)||0)>0,u=l.useMemo(()=>(e.workspaces||[]).map(Ae=>({id:Ae.id,path:Ae.path,label:Ae.label})),[e]),h=e.defaultWorkspaceId||null,[f,y]=l.useState(h||((ct=u[0])==null?void 0:ct.id)||""),[b,x]=l.useState(""),[k,j]=l.useState(""),[p,w]=l.useState([]),[C,v]=l.useState(!1),[g,N]=l.useState(""),[I,S]=l.useState(!1),[T,P]=l.useState(Da(m,t.length,r.length)),A=l.useRef(null),[D,L]=l.useState(null),O=l.useRef("__home__"),[_,M]=l.useState("__home__"),[$,W]=l.useState(""),[B,F]=l.useState(""),[K,Y]=l.useState(""),[re,ae]=l.useState([]),[he,we]=l.useState(()=>jt().textQuery),[Ce,V]=l.useState(()=>jt().workspaceQuery),[q,ue]=l.useState(()=>jt().modelQuery),[me,le]=l.useState(()=>jt().resumableOnly),[je,X]=l.useState(()=>jt().sortMode),[ye,de]=l.useState(!1),[ve,fe]=l.useState(!1),ge=l.useRef(null),ce=l.useRef(null);l.useEffect(()=>{(!e.workspaces||!e.availableProviders||!e.detectedIdes||!e.recentLaunches)&&i(e.id,{minFreshMs:3e4}).catch(()=>{})},[i,e]);const be=f==="__custom__"?b.trim():((Xe=u.find(Ae=>Ae.id===f))==null?void 0:Xe.path)||"",oe=f==="__custom__"&&!!be&&n.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(n.message),R=f!=="__custom__"&&((pt=u.find(Ae=>Ae.id===f))==null?void 0:pt.path)||"",pe=l.useMemo(()=>(e.recentLaunches||[]).map(Ae=>Ae.workspace),[e]),Se=l.useCallback(async Ae=>{v(!0),N("");try{const Fe=await a(Ae);j(Fe.path),x(Fe.path),w(Fe.directories)}catch(Fe){N(Fe instanceof Error?Fe.message:"Could not load folder")}finally{v(!1)}},[a]),Me=l.useCallback(()=>{var Fe;y("__custom__"),S(!0);const Ae=oi(e.platform,ai(b.trim(),R,pe,e.defaultWorkspacePath,(Fe=u.find(st=>st.id===h))==null?void 0:Fe.path,u.map(st=>st.path)));Se(Ae)},[b,h,Se,pe,R,e.platform,u]),ee=l.useCallback(Ae=>{if(Ae!=null&&Ae.workspaceId){y(Ae.workspaceId),x("");return}if(Ae!=null&&Ae.workspacePath){y("__custom__"),x(Ae.workspacePath);return}y(""),x("")},[]),Ne=l.useCallback(Ae=>{if(y(Ae),Ae==="__custom__"){Me();return}x("")},[Me]),De=l.useCallback(Ae=>{y("__custom__"),x(Ae)},[]),Ee=l.useCallback((Ae,Fe)=>{A.current=Fe,O.current=Ae.selectedWorkspaceKey||"__home__",M(Ae.selectedWorkspaceKey||"__home__"),W(Ae.initialArgs||""),F(Ae.initialModel||""),Y(""),ae([]);const st=Ae.providerType?`${e.id}:${Ae.providerType}`:null;if(ub(ce.current,st)){const qe=jt();we(qe.textQuery),V(qe.workspaceQuery),ue(qe.modelQuery),le(qe.resumableOnly),X(qe.sortMode)}ce.current=st,L(Ae),Ae.providerType&&o&&(de(!0),o(Ae.providerType).then(qe=>ae(qe||[])).catch(qe=>console.warn("Failed to load saved sessions",qe)).finally(()=>de(!1)))},[o,e.id]),ze=l.useMemo(()=>Nd(re,{textQuery:he,workspaceQuery:Ce,modelQuery:q,resumableOnly:me,sortMode:je}),[q,me,re,je,he,Ce]);l.useEffect(()=>{K&&(ze.some(Ae=>Ae.providerSessionId===K)||Y(""))},[ze,K]);const Qe=l.useCallback(()=>{A.current&&(fe(!0),A.current().finally(()=>{A.current=null,fe(!1),L(null)}))},[]),Ze=l.useCallback(()=>{A.current=null,L(null)},[]),rt=l.useCallback(Ae=>{O.current=Ae,M(Ae)},[]);return l.useEffect(()=>{var Ae;ge.current!==e.id&&(ge.current=e.id,y(h||((Ae=u[0])==null?void 0:Ae.id)||"__custom__"),x(""),j(""),w([]),N(""),S(!1),we(jt().textQuery),V(jt().workspaceQuery),ue(jt().modelQuery),le(jt().resumableOnly),X(jt().sortMode),ce.current=null,P(Da(m,t.length,r.length)))},[r.length,t.length,h,m,e.id,u]),l.useEffect(()=>{var Ae;f!=="__custom__"&&(f&&u.some(Fe=>Fe.id===f)||y(h||((Ae=u[0])==null?void 0:Ae.id)||"__custom__"))},[h,f,u]),l.useEffect(()=>{T==="ide"&&m||T==="cli"&&t.length>0||T==="acp"&&r.length>0||P(Da(m,t.length,r.length))},[T,r.length,t.length,m]),{showAllRecent:c,setShowAllRecent:d,hasIdeOptions:m,workspaceRows:u,defaultWorkspaceId:h,workspaceChoice:f,customWorkspacePath:b,browseCurrentPath:k,browseDirectories:p,browseBusy:C,browseError:g,browseDialogOpen:I,activeLauncherKind:T,launchConfirm:D,launchConfirmWorkspaceKeyRef:O,launchConfirmWorkspaceKey:_,launchConfirmArgs:$,launchConfirmModel:B,launchConfirmResumeId:K,launchConfirmSavedSessions:re,launchConfirmTextFilter:he,launchConfirmWorkspaceFilter:Ce,launchConfirmModelFilter:q,launchConfirmResumableOnly:me,launchConfirmSortMode:je,filteredLaunchConfirmSavedSessions:ze,launchConfirmSessionsLoading:ye,launchConfirmBusy:ve,resolvedWorkspacePath:be,canCreateMissingWorkspace:oe,openBrowseDialog:Me,loadBrowsePath:Se,handleWorkspaceChoiceChange:Ne,chooseCustomWorkspacePath:De,setCustomWorkspacePath:x,setBrowseDialogOpen:S,setActiveLauncherKind:P,openLaunchConfirm:Ee,handleConfirmLaunch:Qe,closeLaunchConfirm:Ze,setWorkspaceSelectionFromOption:ee,setLaunchConfirmWorkspaceKeyAndSync:rt,setLaunchConfirmArgs:W,setLaunchConfirmModel:F,setLaunchConfirmResumeId:Y,setLaunchConfirmTextFilter:we,setLaunchConfirmWorkspaceFilter:V,setLaunchConfirmModelFilter:ue,setLaunchConfirmResumableOnly:le,setLaunchConfirmSortMode:X}}function e0({selectedMachineEntry:e,selectedMachineConversations:t,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:a,selectedMachineNeedsUpgrade:o,appVersion:i,machineAction:c,isStandalone:d,section:m,showBottomNav:u,onBack:h,onSectionChange:f,onOpenConversation:y,onOpenRecent:b,onOpenMachineDetails:x,onMachineUpgrade:k,onLaunchDetectedIde:j,onAddWorkspace:p,onBrowseDirectory:w,onLaunchWorkspaceProvider:C,onListSavedSessions:v}){const g=_=>_==="ide"?"Workspace":_==="cli"?"CLI":"ACP",N=r.slice(0,4),I=t.slice(0,3),S=Zy({selectedMachineEntry:e,cliProviders:n,acpProviders:a,machineAction:c,onBrowseDirectory:w,onListSavedSessions:v}),T=l.useMemo(()=>N.map(_=>{const{metaText:M,updatedLabel:$}=fu(_);return{key:`recent-launch:${_.id}`,primary:_.label,secondary:M,updatedLabel:$,onClick:()=>{const{options:W,selectedKey:B}=pu({machine:{workspaces:S.workspaceRows,defaultWorkspaceId:S.defaultWorkspaceId},currentWorkspacePath:_.workspace});S.openLaunchConfirm({title:_.kind==="ide"?Hn("restart-ide",_.label):_.providerSessionId?Cd(_.label):Hn("start-fresh",_.label),description:_.kind==="ide"?Wn("restart-ide"):_.providerSessionId?Id():Wn("start-fresh"),confirmLabel:_.kind==="ide"?Kn("restart-ide"):_.providerSessionId?Fn(!0):Kn("start-fresh"),busyLabel:_.kind==="ide"?Un("restart-ide"):_.providerSessionId?Xo(!0):Un("start-fresh"),workspaceOptions:W,selectedWorkspaceKey:B,details:[{label:"Mode",value:g(_.kind)},..._.providerType?[{label:"Provider",value:_.providerType}]:[]]},async()=>{const F=W.find(K=>K.key===S.launchConfirmWorkspaceKeyRef.current);S.setWorkspaceSelectionFromOption(F),await b({..._,workspace:(F==null?void 0:F.workspacePath)??null})})}}}),[S,b,N]),P=l.useMemo(()=>I.map(_=>({key:`recent-chat:${_.conversation.tabKey}`,primary:nt(_.conversation),secondary:Xx(_.conversation,{timestampLabel:_.timestamp?Kc(_.timestamp):null}),unread:_.unread,onClick:()=>y(_.conversation)})),[y,I]),A=S.showAllRecent?T:T.slice(0,4),D=T.length>0,L=P.length>0,O=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`flex items-center justify-between gap-3 ${O} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:h,type:"button","aria-label":"Back",children:s.jsx(Ro,{size:18})}),s.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:Ct(e,{fallbackId:e.id})}),s.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[e.platform||"machine",e.version?` · v${e.version}`:""]})]})]})}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[L&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:P.map(_=>s.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${_.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:_.onClick,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:_.primary}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:_.secondary})]},_.key))})]}),D&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:A.map(_=>s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:_.onClick,children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsx("span",{className:"text-sm font-bold text-text-primary truncate",children:_.primary}),_.updatedLabel&&s.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:_.updatedLabel})]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:_.secondary})]},_.key))}),T.length>4&&s.jsx("div",{className:"flex justify-center px-4 pt-2",children:s.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>S.setShowAllRecent(_=>!_),children:S.showAllRecent?"Show fewer":`Show ${T.length-4} more`})})]}),!1,s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),s.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:k,children:[s.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",i]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:x,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),S.browseDialogOpen&&s.jsx(ci,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:S.browseCurrentPath,directories:S.browseDirectories,busy:S.browseBusy,error:S.browseError,confirmLabel:"Use this folder",onClose:()=>S.setBrowseDialogOpen(!1),onNavigate:_=>{S.loadBrowsePath(_)},onConfirm:_=>{S.chooseCustomWorkspacePath(_),S.setBrowseDialogOpen(!1)}}),S.launchConfirm&&s.jsx(hu,{title:S.launchConfirm.title,description:S.launchConfirm.description,details:S.launchConfirm.details,workspaceOptions:S.launchConfirm.workspaceOptions,selectedWorkspaceKey:S.launchConfirmWorkspaceKey,onWorkspaceChange:S.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:S.launchConfirm.providerType?Fn(!!S.launchConfirmResumeId):S.launchConfirm.confirmLabel,busyLabel:S.launchConfirm.providerType?void 0:S.launchConfirm.busyLabel,busy:S.launchConfirmBusy,showArgsInput:S.launchConfirm.showArgsInput,argsValue:S.launchConfirmArgs,onArgsChange:S.setLaunchConfirmArgs,showModelInput:S.launchConfirm.showModelInput,modelValue:S.launchConfirmModel,onModelChange:S.setLaunchConfirmModel,historyProviderNode:S.launchConfirm.providerType&&(S.launchConfirmSessionsLoading||S.launchConfirmSavedSessions.length>0)&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume saved history"}),S.launchConfirmSessionsLoading&&s.jsx("div",{className:"text-[10px] text-text-secondary font-medium",children:"Loading..."})]}),s.jsx("div",{className:"text-[11px] text-text-secondary mb-2",children:Jo()}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:S.launchConfirmTextFilter,onChange:_=>S.setLaunchConfirmTextFilter(_.target.value),placeholder:"Search title or preview",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:S.launchConfirmWorkspaceFilter,onChange:_=>S.setLaunchConfirmWorkspaceFilter(_.target.value),placeholder:"Filter by workspace",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:S.launchConfirmModelFilter,onChange:_=>S.setLaunchConfirmModelFilter(_.target.value),placeholder:"Filter by model",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsxs("select",{value:S.launchConfirmSortMode,onChange:_=>S.setLaunchConfirmSortMode(_.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"recent",children:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mb-2 flex items-center gap-2 text-[11px] text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:S.launchConfirmResumableOnly,onChange:_=>S.setLaunchConfirmResumableOnly(_.target.checked),disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),"Resume-ready only"]}),s.jsxs("select",{value:S.launchConfirmResumeId,onChange:_=>S.setLaunchConfirmResumeId(_.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"",children:pb()}),S.filteredLaunchConfirmSavedSessions.map(_=>s.jsxs("option",{value:_.providerSessionId,disabled:!_.canResume,children:[_.title||_.providerSessionId," ",_.canResume?"":"(workspace missing)"]},_.providerSessionId))]}),!S.launchConfirmSessionsLoading&&S.launchConfirmSavedSessions.length>0&&S.filteredLaunchConfirmSavedSessions.length===0&&s.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"No saved history matches these filters."}),S.launchConfirmResumeId&&(()=>{const _=S.filteredLaunchConfirmSavedSessions.find($=>$.providerSessionId===S.launchConfirmResumeId);if(!_)return null;const M=mu(_);return s.jsxs("div",{className:"mt-2 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2.5 text-[11px] text-text-muted leading-relaxed",children:[s.jsx("div",{className:"font-semibold text-text-primary truncate",children:M.title}),s.jsx("div",{className:"font-mono break-all mt-0.5",children:M.providerSessionId}),s.jsx("div",{className:"mt-1",children:M.metaLine}),M.updatedLabel&&s.jsx("div",{className:"mt-1 text-text-secondary",children:M.updatedLabel}),M.preview&&s.jsx("div",{className:"mt-2 line-clamp-2 text-text-secondary",children:M.preview})]})})()]}),onConfirm:S.handleConfirmLaunch,onCancel:S.closeLaunchConfirm}),u&&s.jsx(uu,{section:m,onSectionChange:f})]})}function Sn(e){return[...e].sort((t,r)=>{const n=r.timestamp-t.timestamp;return n!==0?n:t.conversation.tabKey.localeCompare(r.conversation.tabKey)})}function t0(e,t=[]){const r=new Map(e.map(a=>[a.conversation.tabKey,a])),n=t.map(a=>r.get(a)).filter(a=>!!a);return n.length===e.length?n:Sn(e)}function s0(e){var r;const t=((r=e.p2p)==null?void 0:r.state)||"";return t==="connected"?"Connected":t==="connecting"||t==="new"||t==="checking"?"Connecting":"Offline"}function r0(e,t){if(!e)return[];const r=e.recentLaunches||[];return r.length>0?r.map(n=>({id:n.id,label:n.title||n.providerName||n.providerType,kind:n.kind,providerType:n.providerType,providerSessionId:n.providerSessionId,subtitle:gs(n.summaryMetadata)||n.workspace||void 0,workspace:n.workspace,summaryMetadata:n.summaryMetadata})):t.filter(n=>n.type!=="adhdev-daemon"&&n.daemonId===e.id).map(n=>{var i;const a=Sr(n)?"cli":Ls(n)?"acp":"ide",o=gs(n.summaryMetadata);return{id:`${a}:${n.type}:${n.workspace||""}`,label:((i=n.activeChat)==null?void 0:i.title)||(Sr(n)?n.cliName||n.type:Ls(n)&&n.cliName||n.type),kind:a,providerType:n.type,providerSessionId:n.providerSessionId,subtitle:Ls(n)?o||n.workspace||void 0:n.workspace||void 0,workspace:n.workspace||void 0,timestamp:n.lastMessageAt||0}}).sort((n,a)=>a.timestamp-n.timestamp).map(({timestamp:n,...a})=>a)}function n0(e,t){const r=new Map;for(const n of t){const a=js(n.conversation),o=r.get(a);o?o.push(n):r.set(a,[n])}return e.map(n=>{const a=r.get(n.id)||[],o=[...a].sort((h,f)=>f.timestamp-h.timestamp)[0]||null,i=(o==null?void 0:o.conversation)||null,c=mo(n),d=a.filter(h=>h.unread||h.requiresAction).length,m=s0(n),u=[n.platform||"machine",m].filter(Boolean);return{id:n.id,label:Ct(n,{fallbackId:n.id}),subtitle:u.join(" · "),unread:d,total:a.length,latestConversation:i,latestTimestamp:(o==null?void 0:o.timestamp)||0,fallbackActivityAt:c,preview:i?Jx(i):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((n,a)=>{const o=n.latestTimestamp||n.fallbackActivityAt||0,i=a.latestTimestamp||a.fallbackActivityAt||0;return i!==o?i-o:n.label.localeCompare(a.label)})}function a0(e){return e==="chat"}function cn(e,t){var r;if(!(typeof window>"u"))try{if(!(!!((r=import.meta.env)!=null&&r.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${e}`,t)}catch{}}function o0({conversations:e,machineEntries:t,items:r,selectedConversation:n,selectedTabKey:a,screen:o,liveSessionInboxState:i,sendDaemonCommand:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,setSelectedTabKey:b,setScreen:x,setSelectedMachineId:k,setSection:j,setMachineBackTarget:p,resetMachineAction:w}){const C=l.useRef(null),v=l.useCallback(g=>{if(!(g!=null&&g.sessionId))return;const N=Rn(g,i),I=Math.max(Date.now(),fs(g),N.lastUpdated||0);cn("mark_read:start",{tabKey:g.tabKey,sessionId:g.sessionId,displayPrimary:nt(g),inboxBucket:N.inboxBucket,unread:N.unread,lastSeenAt:N.lastSeenAt,lastUpdated:N.lastUpdated,activityAt:fs(g),readAt:I}),c(js(g)||g.routeId,"mark_session_seen",{sessionId:g.sessionId,providerSessionId:g.providerSessionId,seenAt:I,completionMarker:N.completionMarker}).then(S=>{cn("mark_read:result",{tabKey:g.tabKey,sessionId:g.sessionId,result:S})}).catch(S=>{cn("mark_read:error",{tabKey:g.tabKey,sessionId:g.sessionId,error:S instanceof Error?S.message:String(S)})})},[i,c]);return l.useEffect(()=>{var N;if(!n){a0(o)&&x("inbox"),b(((N=e[0])==null?void 0:N.tabKey)||null),C.current=null;return}if(o!=="chat"){C.current=null;return}const g=`${n.tabKey}:${n.sessionId||""}`;C.current!==g&&(C.current=g,v(n))},[e,v,o,n,x,b]),l.useEffect(()=>{if(!d)return;const g=e.find(N=>N.tabKey===d);g&&(b(g.tabKey),x("chat"),m==null||m())},[e,m,d,x,b]),l.useEffect(()=>{if(!u)return;const g=t.find(N=>N.id===u);g&&(k(g.id),w(),j("machines"),p("inbox"),x("machine"),h==null||h())},[t,h,u,w,p,x,j,k]),l.useEffect(()=>{f&&(j(f),x("inbox"),y==null||y())},[y,f,x,j]),l.useEffect(()=>{const g=r.filter(N=>N.inboxBucket==="task_complete"||N.unread);g.length!==0&&cn("inbox_state",{screen:o,selectedTabKey:a,items:g.map(N=>{const I=Rn(N.conversation,i);return{liveState:I,tabKey:N.conversation.tabKey,sessionId:N.conversation.sessionId,displayPrimary:nt(N.conversation),serverBucket:I.inboxBucket,computedBucket:N.inboxBucket,serverUnread:I.unread,computedUnread:N.unread,lastSeenAt:I.lastSeenAt,lastUpdated:I.lastUpdated,activityAt:fs(N.conversation)}})})},[r,i,o,a]),{markConversationRead:v}}function i0(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function El(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function l0(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function c0({sendDaemonCommand:e,navigate:t,ides:r,conversations:n}){const{launchCli:a}=Zn(),[o,i]=l.useState("idle"),[c,d]=l.useState(""),[m,u]=l.useState(null),h=l.useCallback(()=>{i("idle"),d(""),u(null)},[]),f=l.useCallback(async(w,C,v)=>{var g;try{i("loading"),d(`Launching ${C}…`);const N={ideType:C,enableCdp:!0};(g=v==null?void 0:v.workspacePath)!=null&&g.trim()&&(N.workspace=v.workspacePath.trim()),await e(w,"launch_ide",N),i("done"),d(`${C} launch requested`)}catch(N){i("error"),d(N instanceof Error?N.message:"Launch IDE failed"),console.error("Launch IDE failed",N)}},[e]),y=l.useCallback(async(w,C,v)=>{if(C.trim())try{i("loading"),d(v!=null&&v.createIfMissing?"Creating folder…":"Saving workspace…");const g=await e(w,"workspace_add",{path:C.trim(),createIfMissing:(v==null?void 0:v.createIfMissing)===!0});if(g!=null&&g.success){i("done"),d(v!=null&&v.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),d((g==null?void 0:g.error)||"Could not save workspace")}catch(g){i("error"),d(g instanceof Error?g.message:"Could not save workspace")}},[e]),b=l.useCallback(async w=>{var C,v,g,N,I,S;try{i("loading"),d("Starting daemon upgrade…");const T=await e(w,"daemon_upgrade",{});if((C=T==null?void 0:T.result)!=null&&C.alreadyLatest){i("done"),d(`Already on v${((v=T==null?void 0:T.result)==null?void 0:v.version)||"latest"}.`);return}if((g=T==null?void 0:T.result)!=null&&g.upgraded||(N=T==null?void 0:T.result)!=null&&N.success){i("done"),d(`Upgrade to v${((I=T==null?void 0:T.result)==null?void 0:I.version)||"latest"} started. Daemon is restarting…`);return}i("error"),d(((S=T==null?void 0:T.result)==null?void 0:S.error)||"Upgrade failed")}catch(T){i("error"),d(T instanceof Error?T.message:"Upgrade failed")}},[e]),x=l.useCallback(async(w,C,v,g)=>{var S,T,P;const N=Date.now(),I={machineId:w,kind:C,providerType:v,workspaceId:(g==null?void 0:g.workspaceId)||null,workspacePath:(g==null?void 0:g.workspacePath)||null,resumeSessionId:(g==null?void 0:g.resumeSessionId)||null,startedAt:N};try{i("loading"),d(`Launching ${v}…`),u(I);const A={cliType:v};(S=g==null?void 0:g.workspacePath)!=null&&S.trim()?A.dir=g.workspacePath.trim():g!=null&&g.workspaceId&&(A.workspaceId=g.workspaceId),g!=null&&g.resumeSessionId&&(A.resumeSessionId=g.resumeSessionId),(T=g==null?void 0:g.args)!=null&&T.trim()&&(A.cliArgs=g.args.trim().split(/\s+/).filter(Boolean)),(P=g==null?void 0:g.model)!=null&&P.trim()&&(A.initialModel=g.model.trim());const D=await a(w,A),L=(D==null?void 0:D.result)||D,O=(L==null?void 0:L.sessionId)||(L==null?void 0:L.id);if(D!=null&&D.success&&O){u(null),i("done"),d(`${v} launched`),t(Cr(O));return}if(D!=null&&D.success){i("loading"),d(`${v} launch requested — waiting for session…`);return}u(null),i("error"),d((D==null?void 0:D.error)||(L==null?void 0:L.error)||`Could not launch ${C.toUpperCase()} workspace`)}catch(A){if(l0(A)){i("loading"),d(`${v} launch requested — waiting for session…`);return}u(null),i("error"),d(A instanceof Error?A.message:`Could not launch ${C.toUpperCase()} workspace`)}},[t,e]),k=l.useCallback(async(w,C)=>{try{const v=await e(w,"list_saved_sessions",{providerType:C,kind:"cli",limit:30}),g=(v==null?void 0:v.result)??v;return Array.isArray(g==null?void 0:g.sessions)?g.sessions:[]}catch(v){return console.error("Failed to list saved sessions on mobile:",v),[]}},[e]),j=l.useCallback(async(w,C)=>ii(e,w,C),[e]);l.useEffect(()=>{if(!m)return;const w=El(m.workspacePath),C=r.find(g=>{var A,D,L,O;if(!g||g.type==="adhdev-daemon"||i0(g.daemonId||g.id)!==m.machineId||(g.transport==="acp"?"acp":g.transport==="pty"?"cli":null)!==m.kind||String(g.agentType||g.type||"")!==m.providerType)return!1;const T=String(g.providerSessionId||"");if(m.resumeSessionId&&T)return T===m.resumeSessionId;if(w){const _=El(g.workspace||g.runtimeWorkspaceLabel);return _?_===w:!1}return Number(g.lastUpdated||g._lastUpdate||g.timestamp||((O=(L=(D=(A=g.activeChat)==null?void 0:A.messages)==null?void 0:D.at)==null?void 0:L.call(D,-1))==null?void 0:O.timestamp)||0)>=m.startedAt-5e3});if(!C)return;const v=iu({entrySessionId:C.sessionId,entryInstanceId:C.instanceId,entryRouteId:C.id,conversations:n});v&&(u(null),i("done"),d(`${m.providerType} launched`),t(Cr(v)))},[n,r,t,m]),l.useEffect(()=>{if(!m)return;const w=window.setTimeout(()=>{u(C=>!C||C.startedAt!==m.startedAt?C:(i("error"),d("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(w)},[m]);const p=l.useCallback(async(w,C)=>{if(C.kind==="ide"&&C.providerType){await f(w,C.providerType,{workspacePath:C.workspace||null});return}(C.kind==="cli"||C.kind==="acp")&&C.providerType&&await x(w,C.kind,C.providerType,{workspacePath:C.workspace||null,resumeSessionId:C.providerSessionId||null})},[f,x]);return{machineAction:{state:o,message:c},resetMachineAction:h,handleLaunchDetectedIde:f,handleAddWorkspace:y,handleMachineUpgrade:b,handleLaunchWorkspaceProvider:x,handleListSavedSessions:k,handleBrowseDirectory:j,handleOpenRecent:p}}function d0({conversations:e,selectedConversation:t,machineBackTarget:r,markConversationRead:n,resetMachineAction:a,setSelectedTabKey:o,setScreen:i,setSelectedMachineId:c,setSection:d,setMachineBackTarget:m}){const u=l.useCallback(j=>{o(j.tabKey),i("chat"),n(j)},[n,i,o]),h=l.useCallback(j=>{const p=e.find(w=>w.routeId===j.routeId&&w.streamSource==="native");p&&(o(p.tabKey),i("chat"),n(p))},[e,n,i,o]),f=l.useCallback(()=>{n(t),i("inbox")},[n,t,i]),y=l.useCallback((j,p="inbox")=>{c(j),a(),d("machines"),m(p),i("machine")},[a,m,i,d,c]),b=l.useCallback(j=>{const p=js(j);p&&y(p,"chat")},[y]),x=l.useCallback(()=>{a(),i(r)},[r,a,i]),k=l.useCallback(j=>{d(j),i("inbox")},[i,d]);return{openConversation:u,openNativeConversation:h,backFromConversation:f,openMachine:y,openConversationMachine:b,backFromMachine:x,changeMachineSection:k}}function Hs(e,t){return e.category!==t?!1:t==="ide"?!0:e.enabled===!0}function u0(e){const t=e.trim();return t?t[0].toUpperCase():"?"}function m0({conversations:e,hiddenConversations:t,ides:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,userName:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,onOpenHistory:b,onOpenRemote:x,onStopCli:k,wsStatus:j,isConnected:p,onShowAllHiddenConversations:w,onHideConversation:C,onOpenMeshGraph:v,onOpenNewSession:g,liveSessionInboxState:N,setCliViewModeOverrides:I}){const[S,T]=l.useState(()=>{var ee;return((ee=e[0])==null?void 0:ee.tabKey)||null}),[P,A]=l.useState(()=>e[0]?"chat":"inbox"),[D,L]=l.useState("chats"),[O,_]=l.useState(null),[M,$]=l.useState("inbox"),W=l.useRef([]),B=Tr(),F="0.9.82",K=l.useMemo(()=>e.find(ee=>ee.tabKey===S)||e[0]||null,[e,S]),Y=l.useMemo(()=>K?r.find(ee=>ee.id===K.routeId):void 0,[r,K]),re=l.useMemo(()=>!K||Ve(K)||!Ye(K)?null:Us(K),[K]),ae=l.useMemo(()=>r.filter(ee=>ee.type==="adhdev-daemon").sort(Wo),[r]),he=l.useMemo(()=>ae.find(ee=>ee.id===O)||null,[ae,O]),we=aa({sendDaemonCommand:a,activeConv:K||void 0,setActionLogs:o,isStandalone:i}),Ce=c0({sendDaemonCommand:a,navigate:B,ides:r,conversations:e}),V=l.useMemo(()=>e.map(ee=>{const Ne=P==="chat"&&(K==null?void 0:K.tabKey)===ee.tabKey,De=ra(ee,N,{hideOpenTaskCompleteUnread:!0,isOpenConversation:Ne}),Ee=fs(ee),ze=yd(ee);return{conversation:ee,timestamp:Ee,preview:ze,unread:De.unread,requiresAction:De.requiresAction,isWorking:De.isWorking,inboxBucket:De.inboxBucket}}),[e,N,P,K]),{markConversationRead:q}=o0({conversations:e,machineEntries:ae,items:V,selectedConversation:K,selectedTabKey:S,screen:P,liveSessionInboxState:N,sendDaemonCommand:a,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,setSelectedTabKey:T,setScreen:A,setSelectedMachineId:_,setSection:L,setMachineBackTarget:$,resetMachineAction:Ce.resetMachineAction}),ue=d0({conversations:e,selectedConversation:K,machineBackTarget:M,markConversationRead:q,resetMachineAction:Ce.resetMachineAction,setSelectedTabKey:T,setScreen:A,setSelectedMachineId:_,setSection:L,setMachineBackTarget:$}),{isMuted:me,autoMuteIfCoordinator:le,toggleTarget:je}=Ng();l.useEffect(()=>{if(i)for(const ee of V)le(ee.conversation)},[V,i,le]);const X=l.useMemo(()=>Sn(V.filter(ee=>ee.requiresAction&&!me(ee.conversation))),[V,me]),ye=l.useMemo(()=>Sn(V.filter(ee=>ee.unread&&!ee.requiresAction&&!me(ee.conversation))),[V,me]),de=l.useMemo(()=>t0(V.filter(ee=>!ee.unread&&!ee.requiresAction&&ee.isWorking),W.current),[V]);l.useEffect(()=>{W.current=de.map(ee=>ee.conversation.tabKey)},[de]);const ve=l.useMemo(()=>Sn(V.filter(ee=>!ee.unread&&!ee.requiresAction&&!ee.isWorking)),[V]),fe=l.useMemo(()=>he?V.filter(ee=>js(ee.conversation)===he.id):[],[V,he]),ge=l.useMemo(()=>r0(he,r),[r,he]),ce=(he==null?void 0:he.version)||null,be=!!he&&!!ce&&!0&&ce!==F,oe=l.useMemo(()=>(he==null?void 0:he.availableProviders)||[],[he]),R=l.useMemo(()=>oe.filter(ee=>Hs(ee,"cli")).map(ee=>({type:ee.type,displayName:ee.displayName||ee.type,icon:ee.icon})),[oe]),pe=l.useMemo(()=>oe.filter(ee=>Hs(ee,"acp")).map(ee=>({type:ee.type,displayName:ee.displayName||ee.type,icon:ee.icon})),[oe]),Se=l.useMemo(()=>n0(ae,V),[V,ae]),Me=l.useCallback(async ee=>{he&&await Ce.handleOpenRecent(he.id,ee)},[Ce,he]);return s.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:P==="chat"&&K?s.jsx(zy,{selectedConversation:K,isAcp:Ve(K),isStandalone:i,selectedIdeEntry:Y,actionLogs:n,userName:c,isSendingChat:we.isSendingChat,sendFeedbackMessage:we.sendFeedbackMessage,isFocusingAgent:we.isFocusingAgent,handleModalButton:we.handleModalButton,handleRelaunch:we.handleRelaunch,onBack:ue.backFromConversation,onOpenNativeConversation:ue.openNativeConversation,onOpenMachine:ue.openConversationMachine,onOpenHistory:b,onOpenRemote:x,onOpenMeshGraph:v,onStopCli:k,cliViewMode:re,onSetCliViewMode:async ee=>{await Vd({conversation:K,mode:ee,ides:r,sendDaemonCommand:a,setCliViewModeOverrides:I})},handleSendChat:we.handleSendChat,handleForceSendChat:we.handleForceSendChat,handleFocusAgent:we.handleFocusAgent}):P==="machine"&&he?s.jsx(e0,{selectedMachineEntry:he,selectedMachineConversations:fe,selectedMachineRecentLaunches:ge,cliProviders:R,acpProviders:pe,selectedMachineNeedsUpgrade:be,appVersion:F,machineAction:Ce.machineAction,isStandalone:i,section:D,showBottomNav:M==="inbox",onBack:ue.backFromMachine,onSectionChange:ue.changeMachineSection,onOpenConversation:ue.openConversation,onOpenRecent:Me,onOpenMachineDetails:()=>B(`/machines/${he.id}`),onMachineUpgrade:()=>Ce.handleMachineUpgrade(he.id),onLaunchDetectedIde:(ee,Ne)=>Ce.handleLaunchDetectedIde(he.id,ee,Ne),onAddWorkspace:(ee,Ne)=>Ce.handleAddWorkspace(he.id,ee,Ne),onBrowseDirectory:ee=>Ce.handleBrowseDirectory(he.id,ee),onLaunchWorkspaceProvider:(ee,Ne,De)=>Ce.handleLaunchWorkspaceProvider(he.id,ee,Ne,De),onListSavedSessions:ee=>Ce.handleListSavedSessions(he.id,ee)}):s.jsx(qy,{section:D,attentionItems:X,unreadItems:ye,workingItems:de,completedItems:ve,hiddenConversations:t,machineCards:Se,getAvatarText:u0,actionLogs:n,sendDaemonCommand:a,onOpenConversation:ue.openConversation,onShowAllHidden:w,onHideConversation:C,onOpenMeshGraph:v,onOpenNewSession:g,onOpenMachine:ue.openMachine,onOpenSettings:()=>B("/settings"),onSectionChange:L,wsStatus:j,isConnected:p,isStandalone:i,isConversationMuted:i?me:void 0,onToggleMuteConversation:i?je:void 0})})}function Ea(e,t){return!!(e<4&&t&&window.innerWidth>=768)}function h0({conversations:e,numGroups:t,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:a,onClearPreviewOrder:o}){const i=l.useRef(0),[c,d]=l.useState(!1),[m,u]=l.useState(null),h=l.useCallback(()=>{i.current=0,d(!1),u(null)},[]);l.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const f=l.useCallback(k=>{k.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,d(!0))},[]),y=l.useCallback(k=>{if(!k.dataTransfer.types.includes("text/tab-key"))return;if(k.preventDefault(),!Ea(t,r)){u("merge");return}const j=k.currentTarget.getBoundingClientRect(),p=k.clientX-j.left,w=j.width/3;p<w?u("split-left"):p>w*2?u("split-right"):u("merge")},[t,r]),b=l.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,d(!1),u(null))},[]),x=l.useCallback(k=>{i.current=0,d(!1);const j=k.dataTransfer.getData("text/tab-key"),p=j?e.some(C=>C.tabKey===j):!1,w=m;if(u(null),o(),!!j){if(k.preventDefault(),w==="split-left"&&Ea(t,r)){r==null||r(j,"split-left");return}if(w==="split-right"&&Ea(t,r)){r==null||r(j,"split-right");return}if(p){a(j);return}n==null||n(j)}},[e,m,t,r,n,a,o]);return{dragOver:c,dropAction:m,resetDragState:h,handleDragEnter:f,handleDragOver:y,handleDragLeave:b,handleDrop:x}}function p0(e,t){const r=new Set(t.map(o=>o.tabKey)),n=e.filter(o=>r.has(o)),a=t.filter(o=>!e.includes(o.tabKey)).map(o=>o.tabKey);return[...n,...a]}function f0({conversations:e,initialActiveTabId:t,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:a}){const[o,i]=l.useState(t??null),[c,d]=l.useState(r??[]),[m,u]=l.useState(null),h=l.useRef(null),f=l.useRef(null),y=l.useRef(n),b=l.useRef(a);l.useEffect(()=>{y.current=n},[n]),l.useEffect(()=>{b.current=a},[a]),l.useEffect(()=>{t&&t!==o&&i(t)},[t,o]),l.useEffect(()=>{d(N=>{const I=p0(N,e);return I.length===N.length&&I.every((S,T)=>S===N[T])?N:I})},[e]);const x=l.useMemo(()=>{const N=m??c;if(N.length===0)return e;const I=new Map(N.map((S,T)=>[S,T]));return[...e].sort((S,T)=>{const P=I.get(S.tabKey)??999,A=I.get(T.tabKey)??999;return P-A})},[e,m,c]);l.useEffect(()=>{var I,S;if(x.length===0){o!==null&&(i(null),(I=y.current)==null||I.call(y,null));return}if(o&&x.some(T=>T.tabKey===o))return;const N=x[0].tabKey;N!==o&&(i(N),(S=y.current)==null||S.call(y,N))},[x,o]);const k=l.useMemo(()=>x.find(N=>N.tabKey===o),[x,o]),j=l.useCallback(N=>{var I;i(N),(I=y.current)==null||I.call(y,N)},[]),p=l.useCallback((N,I,S)=>{d(T=>{var L;const P=T.filter(O=>O!==N),A=P.indexOf(I);if(A<0)return T;const D=S==="left"?A:A+1;return P.splice(D,0,N),(L=b.current)==null||L.call(b,P),P}),u(null)},[]),w=l.useCallback((N,I,S)=>{const P=(c.length>0?c:e.map(L=>L.tabKey)).filter(L=>L!==N),A=P.indexOf(I);if(A<0)return;const D=S==="left"?A:A+1;P.splice(D,0,N),h.current=P,u(P)},[c,e]),C=l.useCallback(()=>{var I;const N=h.current;N&&(d(N),(I=b.current)==null||I.call(b,N))},[]),v=l.useCallback(()=>{h.current=null,u(null)},[]),g=l.useCallback(N=>{d(I=>{var T;const S=I.filter(P=>P!==N);return S.push(N),(T=b.current)==null||T.call(b,S),S})},[]);return{activeTabId:o,activeConv:k,sortedConversations:x,previewOrderRef:h,draggingTabRef:f,selectTab:j,handleTabReorder:p,updatePreviewOrder:w,commitPreviewOrder:C,clearPreviewOrder:v,moveTabToEnd:g,setDraggingTabKey:N=>{f.current=N}}}function x0({dropAction:e,canSplit:t}){return s.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),s.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function di({conversationsCount:e,isSplitMode:t,isStandalone:r,hasRegisteredMachines:n=!1,suppressGuide:a=!1,onOpenNewSession:o}){if(a)return s.jsx("div",{className:"text-sm text-text-muted opacity-0 select-none","aria-hidden":"true",children:"No active agent"});const i=!r&&!n,c=n&&!!o,d=n?"No conversations yet":r?"Waiting for your daemon":"Connect your machines",m=n?Sd:r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can launch sessions with any installed provider.":"Install ADHDev on a machine, sign in, and it will show up here.";return e===0&&!t?s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[s.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),s.jsxs("div",{className:"text-center max-w-lg",children:[s.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:d}),s.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:m}),c&&s.jsx("div",{className:"flex items-center justify-center mb-4",children:s.jsxs("button",{type:"button",onClick:o,className:"btn btn-secondary btn-sm inline-flex items-center gap-2",title:Ht,"aria-label":Ht,children:[s.jsx(_c,{size:14}),s.jsx("span",{children:Ht})]})}),i&&s.jsx(du,{}),i&&s.jsx("div",{className:"mt-8",children:s.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):s.jsx("div",{className:"text-sm text-text-muted opacity-50",children:t?"Move a tab here to view":"No active agent"})}const xu="adhdev-tab-shortcuts";function bu(){try{return JSON.parse(localStorage.getItem(xu)||"{}")}catch{return{}}}function gu({enabled:e=!0,sortedTabKeys:t,onFocus:r,onSelectTab:n}){const a=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,i]=l.useState(()=>bu()),[c,d]=l.useState(null),m=l.useCallback(h=>{const f=[];return h.metaKey&&f.push(a?"⌘":"Meta"),h.ctrlKey&&f.push("Ctrl"),h.altKey&&f.push(a?"⌥":"Alt"),h.shiftKey&&f.push(a?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(h.key)?null:(f.push(h.key.length===1?h.key.toUpperCase():h.key),f.join("+"))},[a]),u=l.useCallback(h=>{i(h);try{localStorage.setItem(xu,JSON.stringify(h))}catch{}},[]);return l.useEffect(()=>{if(!e||!c)return;const h=f=>{if(f.preventDefault(),f.stopPropagation(),f.key==="Escape"){d(null);return}const y=m(f);if(!y)return;const b={...o};for(const[x,k]of Object.entries(b))k===y&&delete b[x];b[c]=y,u(b),d(null)};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[e,c,o,u,m]),l.useEffect(()=>{if(!e)return;const h=f=>{if(!(!f.ctrlKey&&!f.metaKey&&!f.altKey)){for(const[y,b]of Object.entries(o))if(t.includes(y)&&m(f)===b){f.preventDefault(),r(),n(y);return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[e,o,t,r,n,m]),{isMac:a,tabShortcuts:o,shortcutListening:c,setShortcutListening:d,saveShortcuts:u}}const $a=e=>{e.preventDefault()},b0=l.memo(function({conv:t,isActive:r,isDraggedTab:n,isTaskCompleteUnread:a,shortcut:o,conversationKeys:i,draggingTabRef:c,onFocus:d,onSelectTab:m,onConversationActivated:u,onPreviewReorder:h,onReorderTab:f,onCommitPreviewOrder:y,onClearPreviewOrder:b,onDragStateReset:x,onDragTabKeyChange:k,onReceiveTab:j,onOpenContextMenu:p,longPressTimer:w,isGroupActive:C}){const v=Ks(t),g=v.isGenerating?"agent-tab-generating":v.isWaiting?"agent-tab-waiting":"",N=v.isReconnecting,I=l.useCallback(M=>{c.current=t.tabKey,k(t.tabKey),M.dataTransfer.setData("text/tab-key",t.tabKey),M.dataTransfer.effectAllowed="move"},[t.tabKey,c,k]),S=l.useCallback(()=>{c.current=null,k(null),y(),b(),x()},[c,k,y,b,x]),T=l.useCallback(M=>{const $=c.current;if(!(!$||$===t.tabKey)&&M.dataTransfer.types.includes("text/tab-key")){M.preventDefault(),M.stopPropagation();const W=M.currentTarget.getBoundingClientRect(),B=M.clientX<W.left+W.width/2?"left":"right";h($,t.tabKey,B)}},[t.tabKey,c,h]),P=l.useCallback(M=>{M.preventDefault(),M.stopPropagation();const $=M.dataTransfer.getData("text/tab-key");if($&&$!==t.tabKey){const W=M.currentTarget.getBoundingClientRect(),B=M.clientX<W.left+W.width/2?"left":"right";i.includes($)?f($,t.tabKey,B):j&&j($)}b()},[t.tabKey,i,f,j,b]),A=l.useCallback(M=>{M.stopPropagation(),d(),m(t.tabKey),u(t)},[t,u,d,m]),D=l.useCallback(M=>{M.preventDefault(),p(M.clientX,M.clientY,t.tabKey)},[t.tabKey,p]),L=l.useCallback(M=>{const $=M.touches[0];w.current=setTimeout(()=>{p($.clientX,$.clientY,t.tabKey)},600)},[t.tabKey,w,p]),O=l.useCallback(()=>{w.current&&clearTimeout(w.current)},[w]),_=["adhdev-dockview-tab",g,r&&"is-active",C&&"is-group-active",N&&"is-reconnecting"].filter(Boolean).join(" ");return s.jsxs("div",{"data-tabkey":t.tabKey,className:_,draggable:!0,onDragStart:I,onDragEnd:S,onDragOver:T,onDrop:P,onClick:A,onContextMenu:D,onTouchStart:L,onTouchEnd:O,onTouchMove:O,style:{cursor:"pointer",opacity:n?.4:void 0},children:[a&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status",children:v.isGenerating?s.jsx("div",{className:"tab-spinner"}):v.isWaiting?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):N?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):v.isConnecting?s.jsx("div",{className:"tab-connecting-spinner"}):t.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("span",{className:"adhdev-dockview-tab-primary",title:nt(t),children:nt(t)}),s.jsxs("span",{className:"adhdev-dockview-tab-meta inline-flex min-w-0 items-center gap-1",children:[N?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting truncate",children:ms(t)}):v.isConnecting?s.jsxs("span",{className:"adhdev-dockview-tab-connecting truncate",children:[ms(t),s.jsx("span",{className:"connecting-dots"})]}):s.jsx("span",{className:"truncate",children:ms(t)}),s.jsx(On,{git:t.git,compact:!0,className:"max-w-[6.5rem] shrink-0"})]})]}),o&&s.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(e,t)=>e.conv===t.conv&&e.isActive===t.isActive&&e.isDraggedTab===t.isDraggedTab&&e.isTaskCompleteUnread===t.isTaskCompleteUnread&&e.shortcut===t.shortcut&&e.conversationKeys===t.conversationKeys&&e.isGroupActive===t.isGroupActive);function g0({conversations:e,activeTabId:t,groupIndex:r,unreadTabKeys:n,draggingTabRef:a,onFocus:o,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:m,onCommitPreviewOrder:u,onClearPreviewOrder:h,onDragStateReset:f,onDragTabKeyChange:y,onReceiveTab:b,onHideTab:x,isGroupActive:k,allowTabShortcuts:j=!0}){const[p,w]=l.useState(null),C=l.useRef(null),v=l.useRef(null),g=l.useMemo(()=>e.map(D=>D.tabKey),[e]);_r("PaneGroupTabBar",{groupIndex:r,activeTabId:t,tabCount:e.length,ctxMenuTab:(p==null?void 0:p.tabKey)||null});const{isMac:N,tabShortcuts:I,shortcutListening:S,setShortcutListening:T,saveShortcuts:P}=gu({enabled:j,sortedTabKeys:e.map(D=>D.tabKey),onFocus:o,onSelectTab:i});l.useEffect(()=>{if(!p)return;const D=L=>{const O=document.querySelector("[data-pane-context-menu]");O&&O.contains(L.target)||w(null)};return window.addEventListener("mousedown",D,!0),()=>window.removeEventListener("mousedown",D,!0)},[p]),l.useEffect(()=>{const D=v.current;if(!D)return;const L=O=>{Math.abs(O.deltaY)<=Math.abs(O.deltaX)||(O.preventDefault(),D.scrollLeft+=O.deltaY)};return D.addEventListener("wheel",L,{passive:!1}),()=>D.removeEventListener("wheel",L)},[]);const A=l.useCallback((D,L,O)=>{w({x:D,y:L,tabKey:O})},[]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:s.jsxs("div",{ref:v,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none",overscrollBehaviorX:"contain"},children:[e.map(D=>s.jsx(b0,{conv:D,isActive:t===D.tabKey,isDraggedTab:a.current===D.tabKey,isTaskCompleteUnread:n.has(D.tabKey),shortcut:j?I[D.tabKey]:void 0,conversationKeys:g,draggingTabRef:a,onFocus:o,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:m,onCommitPreviewOrder:u,onClearPreviewOrder:h,onDragStateReset:f,onDragTabKeyChange:y,onReceiveTab:b,onOpenContextMenu:A,longPressTimer:C,isGroupActive:k},D.tabKey)),e.length===0&&s.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),p&&s.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:p.x,top:p.y},children:[j&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onMouseDown:$a,onClick:D=>{D.stopPropagation(),T(p.tabKey),w(null)},children:["⌨ ",I[p.tabKey]?`Change shortcut (${I[p.tabKey]})`:"Set shortcut"]}),I[p.tabKey]&&s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onMouseDown:$a,onClick:()=>{const D={...I};delete D[p.tabKey],P(D),w(null)},children:"✕ Remove shortcut"})]}),x&&s.jsxs(s.Fragment,{children:[j&&s.jsx("div",{className:"border-t border-border-subtle my-1"}),s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onMouseDown:$a,onClick:()=>{x(p.tabKey),w(null)},children:"🚫 Hide from Dashboard"})]})]}),j&&S&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>T(null),children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:D=>D.stopPropagation(),children:[s.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),s.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),s.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),s.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function y0({conversations:e,ides:t,clearedTabs:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,hasRegisteredMachines:c,userName:d,groupIndex:m,onFocus:u,isSplitMode:h,numGroups:f,onMoveTab:y,onReceiveTab:b,style:x,onActiveTabChange:k,initialActiveTabId:j,initialTabOrder:p,onTabOrderChange:w,onHideTab:C,isFocused:v,allowTabShortcuts:g=!0,onOpenNewSession:N,liveSessionInboxState:I}){const{sendCommand:S}=it(),T=l.useRef(null),{activeTabId:P,activeConv:A,sortedConversations:D,draggingTabRef:L,selectTab:O,handleTabReorder:_,updatePreviewOrder:M,commitPreviewOrder:$,clearPreviewOrder:W,moveTabToEnd:B,setDraggingTabKey:F}=f0({conversations:e,initialActiveTabId:j,initialTabOrder:p,onActiveTabChange:k,onTabOrderChange:w}),K=aa({sendDaemonCommand:a,activeConv:A,setActionLogs:o,isStandalone:i}),{dragOver:Y,dropAction:re,resetDragState:ae,handleDragEnter:he,handleDragOver:we,handleDragLeave:Ce,handleDrop:V}=h0({conversations:e,numGroups:f,onMoveTab:y,onReceiveTab:b,onOwnTabDrop:B,onClearPreviewOrder:W}),q=A&&!Ve(A)&&Us(A)==="terminal",ue=l.useMemo(()=>A?t.find(X=>X.id===A.routeId):void 0,[t,A]),me=l.useMemo(()=>A?n.filter(X=>X.routeId===A.tabKey):[],[n,A]),le=l.useMemo(()=>new Set(D.filter(X=>Tp(X,I,{isOpenConversation:X.tabKey===P})).map(X=>X.tabKey)),[P,I,D]);_r("PaneGroup",{groupIndex:m,conversationCount:e.length,activeTabId:P,dragOver:Y});const je=l.useCallback(X=>{X.streamSource==="agent-stream"&&X.agentType&&S(X.routeId,od(),{agentType:X.agentType,...X.sessionId&&{targetSessionId:X.sessionId}}).catch(()=>{})},[S]);return s.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...x,outline:Y?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[s.jsx(g0,{conversations:D,activeTabId:P,groupIndex:m,numGroups:f,unreadTabKeys:le,draggingTabRef:L,onFocus:u,onSelectTab:O,onConversationActivated:je,onPreviewReorder:M,onReorderTab:_,onCommitPreviewOrder:$,onClearPreviewOrder:W,onDragStateReset:ae,onDragTabKeyChange:F,onMoveTab:y,onReceiveTab:b,onHideTab:C,isGroupActive:v??!1,allowTabShortcuts:g}),s.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:he,onDragOver:we,onDragLeave:Ce,onDrop:V,children:[Y&&s.jsx(x0,{dropAction:re,canSplit:!!(f<4&&y)}),A?s.jsx(li,{activeConv:A,clearToken:r[A.tabKey]||0,isCliTerminal:!!q,ideEntry:ue,terminalRef:T,handleModalButton:K.handleModalButton,handleRelaunch:K.handleRelaunch,handleSendChat:K.handleSendChat,handleForceSendChat:K.handleForceSendChat,isSendingChat:K.isSendingChat,sendFeedbackMessage:K.sendFeedbackMessage,handleFocusAgent:K.handleFocusAgent,isFocusingAgent:K.isFocusingAgent,actionLogs:me,userName:d,isInputActive:!h||!!v}):s.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:s.jsx(di,{conversationsCount:e.length,isSplitMode:h,isStandalone:i,hasRegisteredMachines:c,onOpenNewSession:N})})]})]})}function v0({containerRef:e,isSplitMode:t,numGroups:r,groupSizes:n,groupedConvs:a,clearedTabs:o,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:m,isStandalone:u,hasRegisteredMachines:h,userName:f,focusedGroup:y,focusGroup:b,moveTabToGroup:x,splitTabRelative:k,closeGroup:j,handleResizeStart:p,groupActiveTabIds:w,setGroupActiveTab:C,groupTabOrders:v,setGroupTabOrder:g,toggleHiddenTab:N,onOpenNewSession:I,allowTabShortcuts:S=!0,liveSessionInboxState:T}){return s.jsx("div",{ref:e,className:`flex-1 min-h-0 flex ${t?"flex-row":"flex-col"} overflow-hidden`,children:a.map((P,A)=>{const D=t&&n.length===r?`${n[A]}%`:void 0;return s.jsxs(ft.Fragment,{children:[t&&A>0&&s.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:L=>p(A-1,L),onDoubleClick:()=>j(A),title:"Drag to resize · Double-click to merge",children:s.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),s.jsx(y0,{style:t?{flexBasis:D??`${100/r}%`,flexGrow:D?0:1,flexShrink:D?0:1}:void 0,conversations:P,clearedTabs:o,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:m,isStandalone:u,hasRegisteredMachines:h,userName:f,groupIndex:A,isFocused:t&&y===A,onFocus:()=>b(A),isSplitMode:t,numGroups:r,onMoveTab:(L,O)=>{O==="left"&&A>0?x(L,A-1):O==="right"&&A<r-1?x(L,A+1):O==="split-left"&&r<4?k(L,A,"left"):O==="split-right"&&r<4&&k(L,A,"right")},onReceiveTab:L=>x(L,A),onActiveTabChange:L=>C(A,L),initialActiveTabId:w[A],initialTabOrder:v[A],onTabOrderChange:L=>g(A,L),onHideTab:N,onOpenNewSession:I,allowTabShortcuts:S,liveSessionInboxState:T})]},A)})})}function yu({doId:e,targetSessionId:t,connState:r,viewMode:n}){const[a,o]=l.useState(null),[i,c]=l.useState(null);l.useEffect(()=>e?at.onScreenshot("ide-page",(u,h)=>{if(u!==e)return;const f=new FileReader;f.onload=()=>o(f.result),f.readAsDataURL(h)}):void 0,[e]),l.useEffect(()=>{r!=="connected"&&o(null)},[r]),l.useEffect(()=>{var u;return e?((u=at.onStatus)==null?void 0:u.call(at,(h,f)=>{h===e&&f!=null&&f.screenshotUsage&&c(f.screenshotUsage)}))||(()=>{}):void 0},[e]),l.useEffect(()=>{o(null)},[e,t]),l.useEffect(()=>{const m=e?at.get(e):null;if(!(!m||r!=="connected"))return n!=="chat"&&t?m.startScreenshots(t):m.stopScreenshots(t),()=>{m.stopScreenshots(t)}},[n,r,t,e]);const d=l.useCallback(async(m,u)=>{const h=e?at.get(e):null;return!h||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):h.sendInput(m,u,t)},[e,r,t]);return{connScreenshot:a,screenshotUsage:i,handleRemoteAction:d}}const vu="adhdev-dashboard-action-shortcuts",w0=1200,j0=[["toggleHiddenTabs","G H"],["openNewSession","N"],["setActiveTabShortcut","G S"],["selectPreviousGroupTab","G K"],["selectPreviousGroupTab","T ←"],["selectPreviousGroupTab","⌥+["],["selectPreviousGroupTab","Ctrl+Alt+["],["selectNextGroupTab","G J"],["selectNextGroupTab","T →"],["selectNextGroupTab","⌥+]"],["selectNextGroupTab","Ctrl+Alt+]"],["splitActiveTabDown","S ↓"],["splitActiveTabDown","⌘+⌥+-"],["splitActiveTabDown","Ctrl+Alt+-"],["splitActiveTabRight","S →"],["splitActiveTabRight","⌘+⌥+\\"],["splitActiveTabRight","⌘+⌥+="],["splitActiveTabRight","Ctrl+Alt+\\"],["focusLeftPane","F ←"],["focusLeftPane","⌘+⌥+←"],["focusLeftPane","⌘+⌥+["],["focusLeftPane","Ctrl+Alt+←"],["focusRightPane","F →"],["focusRightPane","⌘+⌥+→"],["focusRightPane","⌘+⌥+]"],["focusRightPane","Ctrl+Alt+→"],["focusUpPane","F ↑"],["focusUpPane","⌘+⌥+U"],["focusUpPane","Ctrl+Alt+↑"],["focusDownPane","F ↓"],["focusDownPane","⌘+⌥+J"],["focusDownPane","Ctrl+Alt+↓"],["moveActiveTabToLeftPane","M ←"],["moveActiveTabToLeftPane","⌘+⌥+⇧+←"],["moveActiveTabToLeftPane","⌘+⌥+,"],["moveActiveTabToLeftPane","Ctrl+Alt+Shift+←"],["moveActiveTabToRightPane","M →"],["moveActiveTabToRightPane","⌘+⌥+⇧+→"],["moveActiveTabToRightPane","⌘+⌥+."],["moveActiveTabToRightPane","Ctrl+Alt+Shift+→"],["moveActiveTabToUpPane","M ↑"],["moveActiveTabToUpPane","⌘+⌥+I"],["moveActiveTabToUpPane","Ctrl+Alt+Shift+↑"],["moveActiveTabToDownPane","M ↓"],["moveActiveTabToDownPane","⌘+⌥+K"],["moveActiveTabToDownPane","Ctrl+Alt+Shift+↓"],["triggerPrimaryApprovalAction","⌥+A"],["triggerSecondaryApprovalAction","⌥+D"],["toggleCliView","T"]];function k0(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function tt(e,t){switch(e){case"openShortcutHelp":return"?";case"openNewSession":return t?"⌘+⇧+Enter":"Ctrl+Shift+Enter";case"hideCurrentTab":return t?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return t?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return t?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return t?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return t?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return t?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return t?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return t?"⌘+Ctrl+⇧+→":"Ctrl+Alt+Shift+→";case"splitActiveTabDown":return t?"⌘+Ctrl+⇧+↓":"Ctrl+Alt+Shift+↓";case"focusLeftPane":return"";case"focusRightPane":return"";case"focusUpPane":return"";case"focusDownPane":return"";case"moveActiveTabToLeftPane":return"";case"moveActiveTabToRightPane":return"";case"moveActiveTabToUpPane":return"";case"moveActiveTabToDownPane":return"";case"triggerPrimaryApprovalAction":return t?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return t?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return t?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return t?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return t?"⌘+⇧+←":"Ctrl+Shift+←";case"selectNextGroupTab":return t?"⌘+⇧+→":"Ctrl+Shift+→";case"toggleCliView":return t?"⌥+T":"Ctrl+Alt+T"}}function wu(e){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:tt("openShortcutHelp",e)},{id:"openNewSession",label:"New session",description:"Open the new session launcher.",defaultShortcut:tt("openNewSession",e)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:tt("hideCurrentTab",e)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:tt("toggleHiddenTabs",e)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:tt("openHistoryForActiveTab",e)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:tt("openRemoteForActiveTab",e)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:tt("floatActiveTab",e)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:tt("popoutActiveTab",e)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:tt("dockActiveTab",e)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:tt("splitActiveTabRight",e)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:tt("splitActiveTabDown",e)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:tt("focusLeftPane",e)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:tt("focusRightPane",e)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:tt("focusUpPane",e)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:tt("focusDownPane",e)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:tt("moveActiveTabToLeftPane",e)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:tt("moveActiveTabToRightPane",e)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:tt("moveActiveTabToUpPane",e)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:tt("moveActiveTabToDownPane",e)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:tt("triggerPrimaryApprovalAction",e)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:tt("triggerSecondaryApprovalAction",e)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:tt("triggerTertiaryApprovalAction",e)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:tt("setActiveTabShortcut",e)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:tt("selectPreviousGroupTab",e)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:tt("selectNextGroupTab",e)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:tt("toggleCliView",e)}]}function Io(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"}function Yn(e){const t=Object.fromEntries(wu(e).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(vu)||"{}"),n={...t,...r};for(const[a,o]of j0)n[a]===o&&(n[a]=t[a]);return n}catch{return t}}function ju(e){return e===" "?"Space":e==="Escape"?"Esc":e==="ArrowLeft"?"←":e==="ArrowRight"?"→":e==="ArrowUp"?"↑":e==="ArrowDown"?"↓":e.length===1?e.toUpperCase():e}function S0({enabled:e=!0,onTrigger:t}){const r=k0(),[n,a]=l.useState(()=>Yn(r)),[o,i]=l.useState(null),[c,d]=l.useState([]),m=l.useRef({parts:[],timer:null}),u=l.useCallback(x=>{const k=[];return x.metaKey&&k.push(r?"⌘":"Meta"),x.ctrlKey&&k.push("Ctrl"),x.altKey&&k.push(r?"⌥":"Alt"),x.shiftKey&&x.key.length!==1&&k.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(x.key)?null:(k.push(ju(x.key)),k.join("+"))},[r]),h=l.useCallback(x=>{a(x);try{localStorage.setItem(vu,JSON.stringify(x))}catch{}},[]);l.useEffect(()=>{const x=Yn(r),k=Object.entries(n),j=Object.entries(x);k.length===j.length&&k.every(([p,w])=>x[p]===w)||h(x)},[n,r,h]);const f=l.useCallback(()=>{typeof window<"u"&&m.current.timer!=null&&window.clearTimeout(m.current.timer),m.current={parts:[],timer:null}},[]),y=l.useCallback(()=>{typeof window>"u"||(m.current.timer!=null&&window.clearTimeout(m.current.timer),m.current.timer=window.setTimeout(()=>{m.current={parts:[],timer:null}},w0))},[]);l.useEffect(()=>{if(!o)return;const x=k=>{if(k.preventDefault(),k.stopPropagation(),k.key==="Escape"){i(null),d([]);return}const j=u(k);if(!j)return;const w=!(k.metaKey||k.ctrlKey||k.altKey)&&/^[A-Z0-9]$/.test(j);if(c.length===0&&w){d([j]);return}const v=[...c,j].slice(0,2).join(" "),g={...n};for(const[N,I]of Object.entries(g))I===v&&delete g[N];g[o]=v,h(g),i(null),d([])};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[n,u,h,o,c]),l.useEffect(()=>{if(!e||o)return;const x=k=>{if(k.defaultPrevented)return;const j=u(k);if(!j)return;const p=k.metaKey||k.ctrlKey||k.altKey;if(Io(k.target))return;const w=m.current.parts,C=p?[j]:[...w.slice(-1),j].slice(-2),v=C.join(" "),g=C[C.length-1],N=Object.entries(n).filter(([,A])=>!!A),I=N.find(([,A])=>A===v);if(I){k.preventDefault(),f(),t(I[0]);return}if(N.some(([,A])=>A.startsWith(`${v} `))){k.preventDefault(),m.current.parts=C,y();return}const T=N.find(([,A])=>A===g);if(T){k.preventDefault(),f(),t(T[0]);return}if(N.some(([,A])=>A.startsWith(`${g} `))){k.preventDefault(),m.current.parts=[g],y();return}f()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[n,y,e,u,t,f,o]),l.useEffect(()=>()=>f(),[f]);const b=l.useMemo(()=>wu(r),[r]);return{isMac:r,actionDefinitions:b,actionShortcuts:n,shortcutListening:o,shortcutListeningDraft:c,setShortcutListening:i,setShortcutListeningDraft:d,saveShortcuts:h}}function N0({isTabInPopout:e,isTabFloating:t,tabShortcut:r,actionShortcuts:n}){const a=[];return e?(t&&a.push({type:"action",id:"dockInWindow",label:"Dock in window",shortcut:n.dockActiveTab}),a.push({type:"action",id:"moveBackToMain",label:"Move back to main window",shortcut:n.dockActiveTab})):t?a.push({type:"action",id:"dockBackToGrid",label:"Dock back to grid",shortcut:n.dockActiveTab}):a.push({type:"action",id:"floatAsPanel",label:"Float as panel",shortcut:n.floatActiveTab},{type:"action",id:"openInNewWindow",label:"Open in new window",shortcut:n.popoutActiveTab}),a.push({type:"separator",id:"before-shortcut-actions"},{type:"action",id:"setShortcut",label:r?`Change shortcut (${r})`:"Set shortcut",shortcut:n.setActiveTabShortcut}),r&&a.push({type:"action",id:"removeShortcut",label:"Remove shortcut",tone:"muted"}),a.push({type:"separator",id:"before-hide-tab"},{type:"action",id:"hideTab",label:"Hide tab",shortcut:n.hideCurrentTab,tone:"muted"}),a}function ku(e){return e.some(t=>t.type!=="adhdev-daemon")||e.some(t=>t.type==="adhdev-daemon"&&!!t.machine)}function $l({hasStoredLayout:e,initialDataLoaded:t,visibleConversationCount:r,ides:n}){return!e||r>0?!1:t?!ku(n):!0}function C0({previousVisibleConversationCount:e,visibleConversationCount:t,ides:r}){return t>0||e<=0?!1:ku(r)}const Su=1e3,I0=4;function Bl(e,t){return t?e.clientX>=t.left&&e.clientX<=t.right&&e.clientY>=t.top&&e.clientY<=t.bottom:!1}function Ol(e,t,r){return Math.abs(t.clientX-e.clientX)>r||Math.abs(t.clientY-e.clientY)>r}function M0({detachDelayMs:e=Su,stillnessThresholdPx:t=I0,onDetach:r,setTimeoutFn:n=globalThis.setTimeout.bind(globalThis),clearTimeoutFn:a=globalThis.clearTimeout.bind(globalThis)}){let o=null,i=null,c=null,d=null,m=null,u=!1;const h=()=>{m!=null&&(a(m),m=null)},f=()=>{h(),c=null},y=()=>{h(),o=null,i=null,c=null,d=null,u=!1},b=()=>{!o||!c||!d||u||m!=null||(m=n(()=>{m=null,!(!o||!c||!d||u)&&Bl(d,i)&&(Ol(c,d,t)||(u=!0,r({panelId:o,clientX:d.clientX,clientY:d.clientY})))},e))},x=j=>{if(!(!o||u)){if(!Bl(j,i)){d={clientX:j.clientX,clientY:j.clientY},f();return}(!c||Ol(c,j,t))&&(h(),c={clientX:j.clientX,clientY:j.clientY}),d={clientX:j.clientX,clientY:j.clientY},b()}},k=j=>{!o||u||(j&&(d={clientX:j.clientX,clientY:j.clientY}),f())};return{startDrag:j=>{h(),o=j.panelId,i=j.selfPanelBounds??null,c=null,d={clientX:j.clientX,clientY:j.clientY},u=!1},markSelfPanel:x,markNonSelfPanel:k,markNoDropTarget:k,markDockTarget:k,endDrag:y,isDragging:()=>o!=null,hasDetached:()=>u,dispose:y}}function T0(e=typeof window>"u"?null:window.localStorage){return(e==null?void 0:e.getItem("adhdev:dockviewIdleDragFloat"))!=="off"}function dn(e){return e.isActive}function Fl(e){return e.isVisible}const Nu=l.createContext(null);function la(){const e=l.useContext(Nu);if(!e)throw new Error("DashboardDockviewContext missing");return e}function Nn(e){return nt(e)||e.tabKey}function A0(e){return`remote:${e}`}function Rt(e){return e.startsWith("remote:")}function Hl(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _0(e){e.preventDefault()}function Ba(e){var n;const t=e==null?void 0:e.defaultView;if(!t)return;const r=a=>{if(a)try{a.focus({preventScroll:!0})}catch{try{a.focus()}catch{}}};try{t.focus(),r(e==null?void 0:e.body),r(e==null?void 0:e.documentElement),(n=t.requestAnimationFrame)==null||n.call(t,()=>{try{t.focus(),r(e==null?void 0:e.body)}catch{}})}catch{}}function Oa(e,t){e.classList.remove(ro.className,no.className),e.classList.add(t==="light"?ro.className:no.className)}function Wl(e){return e?Array.from(new Set(e.groups.map(t=>{var r,n;return(n=(r=t.element)==null?void 0:r.ownerDocument)==null?void 0:n.defaultView}).filter(t=>!!t&&t!==window))):[]}function L0(e){const[,t]=l.useState(0);l.useEffect(()=>{const r=()=>t(a=>a+1),n=[e.api.onDidActiveGroupChange(r),e.api.onDidTitleChange(r),e.api.onDidGroupChange(r),e.containerApi.onDidActivePanelChange(r)];return()=>{for(const a of n)a.dispose()}},[e.api,e.containerApi])}function P0(e,t,r){var i;const n=[t];let a;for(const c of n){let d;for(const m of c){const u=e.addPanel({id:m.tabKey,component:"conversation",title:Nn(m),params:{kind:"conversation",tabKey:m.tabKey},...d?{position:{referencePanel:d,direction:"within"},inactive:!0}:a?{position:{referencePanel:a,direction:"right"},inactive:!0}:{}});d||(d=u.id)}a=d??a}return r??((i=t[0])==null?void 0:i.tabKey)??null}function Kl(e,t){const r=new Set(t.map(a=>a.tabKey)),n=new Map;for(const a of t)n.set(a.tabKey,(n.get(a.tabKey)||0)+1);for(const a of[...e.panels])Rt(a.id)||r.has(a.id)||e.removePanel(a);for(const a of t){const o=e.getPanel(a.tabKey);if(o){(n.get(a.tabKey)||0)>1&&console.warn("[dashboard-conversations] Dockview panel already exists for duplicate tabKey",{tabKey:a.tabKey,daemonId:a.daemonId,sessionId:a.sessionId,providerSessionId:a.providerSessionId,panelId:o.id}),o.update({params:{tabKey:a.tabKey}}),o.title!==Nn(a)&&o.api.setTitle(Nn(a));continue}e.addPanel({id:a.tabKey,component:"conversation",title:Nn(a),params:{kind:"conversation",tabKey:a.tabKey},...e.activePanel?{position:{referencePanel:e.activePanel.id,direction:"within"},inactive:!0}:e.panels[0]?{position:{referencePanel:e.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Ul(e,t,r){var d,m;const n=r?A0(r):null;for(const u of[...e.panels])Rt(u.id)&&(!n||u.id!==n)&&e.removePanel(u);if(!r||!n)return;const a=$t(t,r);if(!a&&e.totalPanels===0)return;const o=e.getPanel(n),i=jd(a);if(o){o.title!==i&&o.api.setTitle(i);return}const c=(a==null?void 0:a.tabKey)??((d=e.activePanel)==null?void 0:d.id)??((m=e.panels.find(u=>!Rt(u.id)))==null?void 0:m.id);e.addPanel({id:n,component:"remote",title:i,params:{kind:"remote",routeId:r},...c?{position:{referencePanel:c,direction:"right"},inactive:!0}:{}})}function R0({params:e,api:t}){var y;const r=la(),n=l.useRef(null),[a,o]=l.useState(()=>dn(t)),[i,c]=l.useState(()=>Fl(t)),d=r.conversationsByTabKey.get(e.tabKey),m=aa({sendDaemonCommand:r.sendDaemonCommand,activeConv:d,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});l.useEffect(()=>{o(dn(t)),c(Fl(t));const b=[t.onDidActiveChange(x=>o(x.isActive)),t.onDidActiveGroupChange(x=>{if(!dn(t)&&!x.isActive){o(!1);return}o(dn(t))}),t.onDidVisibilityChange(x=>c(x.isVisible))];return()=>{for(const x of b)x.dispose()}},[t]);const u=l.useMemo(()=>d?r.ides.find(b=>b.id===d.routeId):void 0,[r.ides,d]),h=l.useMemo(()=>d?r.actionLogs.filter(b=>b.routeId===d.tabKey):[],[r.actionLogs,d]);if(!d)return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:s.jsx(di,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,onOpenNewSession:r.onOpenNewSession,suppressGuide:r.hasDetachedConversationPanels})});const f=!Ve(d)&&Us(d)==="terminal";return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:s.jsx(li,{activeConv:d,clearToken:r.clearedTabs[d.tabKey]||0,isCliTerminal:f,ideEntry:u,terminalRef:n,handleModalButton:m.handleModalButton,handleRelaunch:m.handleRelaunch,handleSendChat:m.handleSendChat,handleForceSendChat:m.handleForceSendChat,isSendingChat:m.isSendingChat,handleFocusAgent:m.handleFocusAgent,isFocusingAgent:m.isFocusingAgent,actionLogs:h,userName:r.userName,scrollToBottomRequestNonce:((y=r.scrollToBottomRequest)==null?void 0:y.tabKey)===d.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:a,isVisible:i})})}function D0({params:e}){var d;const t=la(),r=l.useMemo(()=>$t([...t.conversationsByTabKey.values()],e.routeId),[t.conversationsByTabKey,e.routeId]),n=l.useMemo(()=>t.ides.find(m=>m.id===e.routeId),[t.ides,e.routeId]),a=(r==null?void 0:r.daemonId)||((d=r==null?void 0:r.routeId)==null?void 0:d.split(":")[0])||e.routeId.split(":")[0]||e.routeId,{connScreenshot:o,screenshotUsage:i,handleRemoteAction:c}=yu({doId:a,targetSessionId:r?ad(r):(n==null?void 0:n.sessionId)||(n==null?void 0:n.instanceId),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote"});return r?s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:s.jsx(Hc,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:o,screenshotUsage:i,transportType:r.transport,onAction:c})}):s.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function E0(){const e=la();return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:s.jsx(di,{conversationsCount:0,isSplitMode:!1,isStandalone:e.isStandalone,hasRegisteredMachines:e.hasRegisteredMachines,onOpenNewSession:e.onOpenNewSession,suppressGuide:e.hasDetachedConversationPanels})})}function $0(e){var p,w;L0(e);const t=la(),r=l.useCallback(C=>{"button"in C&&C.button!==0||e.api.setActive()},[e.api]),n=e.params.kind==="remote"?void 0:t.conversationsByTabKey.get(e.params.tabKey),a=n==null?void 0:n.sessionId,o=l.useCallback(C=>Rx(C),[]),i=l.useCallback(()=>Px(a),[a]),c=l.useSyncExternalStore(o,i,i);if(e.params.kind==="remote"){const C=$t([...t.conversationsByTabKey.values()],e.params.routeId),v=((p=e.api.group.activePanel)==null?void 0:p.id)===e.api.id,g=e.api.isGroupActive;return s.jsxs("div",{className:`adhdev-dockview-tab${v?" is-active":""}${g?" is-group-active":""}`,title:e.api.title||"Remote","data-tab-key":(C==null?void 0:C.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||"Remote"}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:C!=null&&C.machineName?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"Live remote view"}),s.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),s.jsx("span",{className:"adhdev-dockview-tab-machine",children:C.machineName})]}):s.jsx("span",{children:"Live remote view"})})]})]})}const d=t.conversationsByTabKey.get(e.params.tabKey);if(!d)return s.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":e.params.tabKey||"",children:s.jsx("div",{className:"adhdev-dockview-tab-copy",children:s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||e.params.tabKey})})});const m=((w=e.api.group.activePanel)==null?void 0:w.id)===e.api.id,u=e.api.isGroupActive,h=ra(d,t.liveSessionInboxState,{isOpenConversation:m}),f=h.isReconnecting,y=h.isConnecting,b=h.isGenerating||c,x=h.isWaiting,k=h.unread,j=t.tabShortcuts[d.tabKey];return s.jsxs("div",{className:`adhdev-dockview-tab${m?" is-active":""}${u?" is-group-active":""}${f?" is-reconnecting":""}`,title:nt(d),"data-tab-key":e.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:C=>{var v;C.preventDefault(),r(C),t.openTabContextMenu({x:C.clientX,y:C.clientY,tabKey:d.tabKey,sourceDocument:((v=C.target)==null?void 0:v.ownerDocument)??document})},children:[k&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:b?s.jsx("div",{className:"tab-spinner"}):x?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):f?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):y?s.jsx("div",{className:"tab-connecting-spinner"}):d.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:nt(d)}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:f?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:ms(d)}):y?s.jsx("span",{className:"adhdev-dockview-tab-connecting",children:ms(d)}):s.jsx("span",{children:ms(d)})})]}),j&&s.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:j,children:j})]})}function B0({visibleConversations:e,clearedTabs:t,ides:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d,userName:m,toggleHiddenTab:u,actionShortcuts:h,registerActionHandlers:f,onActiveTabChange:y,onOpenNewSession:b,onRequestScrollToBottom:x,requestedActiveTabKey:k,requestedRemoteIdeId:j,onRequestedActiveTabConsumed:p,scrollToBottomRequest:w,liveSessionInboxState:C,layoutProfile:v}){var st,qe,Ke;const{theme:g}=zs(),{sendCommand:N}=it(),I=l.useRef(null),S=l.useRef(null),T=l.useRef(null),P=l.useRef(!1),A=l.useRef(!1),D=l.useRef(!1),L=l.useRef(null),O=l.useRef([]),[_,M]=l.useState(null),[$,W]=l.useState(0),B=l.useRef(typeof window>"u"?{}:ry(v)),F=l.useMemo(()=>new Map(e.map(U=>[U.tabKey,U])),[e]),K=l.useMemo(()=>{const U=I.current;return U?U.groups.some(z=>{try{const J=z.model.location.type;return J!=="floating"&&J!=="popout"?!1:z.panels.some(te=>F.has(te.id))}catch{return!1}}):!1},[F,$,e]),Y=l.useCallback(()=>{var U;(U=I.current)==null||U.focus()},[]),re=l.useCallback((U,z)=>{x==null||x(U,z)},[x]),ae=l.useCallback(U=>{const z=document,J=U.document;for(const ne of z.querySelectorAll('link[rel="stylesheet"]')){const E=J.createElement("link");E.rel="stylesheet",E.href=ne.href,ne.crossOrigin&&(E.crossOrigin=ne.crossOrigin),J.head.appendChild(E)}for(const ne of z.querySelectorAll("style")){const E=J.createElement("style");E.textContent=ne.textContent,J.head.appendChild(E)}const te=[];for(const ne of z.styleSheets)try{for(const E of ne.cssRules)E instanceof CSSStyleRule&&(E.selectorText===":root"||E.selectorText==="html")&&te.push(E.cssText)}catch{}if(te.length>0){const ne=J.createElement("style");ne.textContent=te.join(`
|
|
54
|
+
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:S,onCancel:()=>u(null)})]})}const Zb=["default","claude-cli","codex-cli","antigravity-cli","hermes-cli","gemini-cli"];function eg({daemonId:e,knownCliTypes:t=Zb}){const{sendCommand:r}=it(),[n,a]=l.useState({}),[o,i]=l.useState({}),[c,d]=l.useState(!0),[m,u]=l.useState(null),[h,f]=l.useState(null),[y,b]=l.useState(""),x=l.useCallback(async()=>{if(e){d(!0),f(null);try{const p=await r(e,"list_coordinator_prompts",{}),w=p!=null&&p.result&&typeof p.result=="object"?p.result:p;if(!(w!=null&&w.success)){f((w==null?void 0:w.error)||"Failed to load");return}const C=w.entries||{};b(w.dir||"");const v={};for(const g of t)v[g]=C[g]||{override:"",append:""};for(const g of Object.keys(C))v[g]||(v[g]=C[g]);a(v),i(JSON.parse(JSON.stringify(v)))}catch(p){f((p==null?void 0:p.message)||String(p))}finally{d(!1)}}},[r,e,t]);l.useEffect(()=>{x()},[x]);const k=l.useCallback(async(p,w)=>{var C;if(e){u(`${p}:${w}`),f(null);try{const v=((C=n[p])==null?void 0:C[w])||"",g=await r(e,"write_coordinator_prompt",{key:p,kind:w,content:v}),N=g!=null&&g.result&&typeof g.result=="object"?g.result:g;if(!(N!=null&&N.success)){f((N==null?void 0:N.error)||"Save failed");return}i(I=>({...I,[p]:{...I[p]||{override:"",append:""},[w]:v}}))}catch(v){f((v==null?void 0:v.message)||String(v))}finally{u(null)}}},[r,e,n]),j=l.useMemo(()=>(p,w)=>{var C,v;return(((C=n[p])==null?void 0:C[w])||"")!==(((v=o[p])==null?void 0:v[w])||"")},[n,o]);return e?s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs("div",{className:"text-[12px] text-text-muted",children:[s.jsxs("p",{children:["Customize the coordinator prompt this daemon's mesh coordinator sessions get. ",s.jsx("span",{className:"font-mono text-[11px]",children:y||"~/.adhdev/coordinator-prompts/"})]}),s.jsxs("p",{className:"mt-1",children:[s.jsx("strong",{children:"Override"})," replaces the daemon's built-in base prompt for that CLI."," ",s.jsx("strong",{children:"Append"})," stacks after whichever base wins. Leave a field empty + Save to remove it (reset to default). Supports placeholders: ","{{meshName}}",", ","{{repo}}",", ","{{nodes}}",", ","{{rules}}",", etc."]})]}),h&&s.jsx("div",{className:"text-[12px] text-red-400 bg-red-500/10 border border-red-500/20 rounded px-3 py-2",children:h}),c&&s.jsx("div",{className:"text-[12px] text-text-muted",children:"Loading…"}),s.jsx("div",{className:"flex flex-col gap-6",children:Object.entries(n).map(([p,w])=>s.jsxs("div",{className:"rounded-lg border border-border-subtle bg-bg-secondary/40 p-3",children:[s.jsx("div",{className:"text-[13px] font-semibold mb-2",children:p}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wide text-text-muted mb-1",children:"Override"}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-[12px] font-mono text-text-primary",rows:4,value:w.override,onChange:C=>a(v=>({...v,[p]:{...v[p],override:C.target.value}})),placeholder:"(empty — use daemon default base prompt)",disabled:m===`${p}:override`}),s.jsx("div",{className:"mt-1 mb-3 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void k(p,"override"),disabled:m===`${p}:override`||!j(p,"override"),children:m===`${p}:override`?"Saving…":j(p,"override")?"Save override":"Saved"})}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wide text-text-muted mb-1",children:"Append"}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-[12px] font-mono text-text-primary",rows:3,value:w.append,onChange:C=>a(v=>({...v,[p]:{...v[p],append:C.target.value}})),placeholder:"(empty — nothing appended at this layer)",disabled:m===`${p}:append`}),s.jsx("div",{className:"mt-1 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void k(p,"append"),disabled:m===`${p}:append`||!j(p,"append"),children:m===`${p}:append`?"Saving…":j(p,"append")?"Save append":"Saved"})})]},p))})]}):s.jsx("div",{className:"text-[12px] text-text-muted",children:"Connect a daemon to edit coordinator prompts."})}const tg=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function sg(){const{preference:e,setPreference:t}=zs();return s.jsx("div",{className:"flex gap-2",children:tg.map(r=>s.jsxs("button",{onClick:()=>t(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${e===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:e===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[s.jsx("span",{children:r.icon}),r.label]},r.id))})}function rg(e){const t=e.trim();return/^#[0-9a-fA-F]{6}$/.test(t)?t:/^#[0-9a-fA-F]{3}$/.test(t)?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:null}function ng(e){return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16)}}function Ca(e){const t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function wl(e){const{r:t,g:r,b:n}=ng(e);return .2126*Ca(t)+.7152*Ca(r)+.0722*Ca(n)}function jl(e,t){const r=wl(e),n=wl(t),a=Math.max(r,n),o=Math.min(r,n);return(a+.05)/(o+.05)}function Bd(e){const t=rg(e);if(!t)return"#111827";const r="#111827",n="#ffffff";return jl(t,r)>=jl(t,n)?r:n}const jo={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},ko={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},ag=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],Od="adhdev-chat-theme",Fd="adhdev-chat-theme-custom";function jn(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Od)||"ember"}catch{return"ember"}}function Et(e){try{const t=localStorage.getItem(Fd);if(t){const r=JSON.parse(t);return{...e==="dark"?jo:ko,...r[e]}}}catch{}return e==="dark"?jo:ko}function sn(e,t){try{localStorage.setItem(Fd,JSON.stringify({dark:e,light:t}))}catch{}}function It(e,t){const r=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16);return`rgba(${r}, ${n}, ${a}, ${t})`}function Vn(e,t){const r=Math.min(255,parseInt(e.slice(1,3),16)+t),n=Math.min(255,parseInt(e.slice(3,5),16)+t),a=Math.min(255,parseInt(e.slice(5,7),16)+t);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}const og={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function yr(e,t){var a;const r=(a=og[e])==null?void 0:a[t];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",Vn(r,24)),n.style.setProperty("--accent-on-primary",Bd(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${Vn(r,18)})`),n.style.setProperty("--border-accent",It(r,.35)),n.style.setProperty("--nav-active-bg",It(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${It(r,.06)}`)}function hs(e){const t=document.documentElement;t.style.setProperty("--bg-primary",e.bgPrimary),t.style.setProperty("--bg-secondary",e.bgSecondary),t.style.setProperty("--bg-card",It(e.surfacePrimary,.92)),t.style.setProperty("--surface-primary",e.surfacePrimary),t.style.setProperty("--surface-secondary",e.bgSecondary),t.style.setProperty("--bg-glass",It(e.borderSubtle,.15)),t.style.setProperty("--bg-glass-hover",It(e.borderSubtle,.25)),t.style.setProperty("--text-primary",e.textPrimary),t.style.setProperty("--text-secondary",e.textSecondary),t.style.setProperty("--text-muted",e.textMuted),t.style.setProperty("--border-subtle",It(e.borderSubtle,.5)),t.style.setProperty("--border-default",It(e.borderDefault,.5)),t.style.setProperty("--accent-primary",e.accentColor),t.style.setProperty("--accent-primary-light",Vn(e.accentColor,30)),t.style.setProperty("--accent-on-primary",Bd(e.accentColor)),t.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${e.accentColor}, ${Vn(e.accentColor,40)})`),t.style.setProperty("--border-accent",It(e.accentColor,.35)),t.style.setProperty("--nav-active-bg",It(e.accentColor,.1)),t.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${e.accentColor}, 0 0 12px ${It(e.accentColor,.06)}`),t.style.setProperty("--chat-user-bg",e.userBubble),t.style.setProperty("--chat-user-color",e.userText),t.style.setProperty("--chat-user-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px 4px ${e.bubbleRadius}px`),t.style.setProperty("--chat-assistant-bg",e.assistantBubble),t.style.setProperty("--chat-assistant-color",e.assistantText),t.style.setProperty("--chat-assistant-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px ${e.bubbleRadius}px 4px`),t.style.setProperty("--chat-assistant-border",`1px solid ${It(e.accentColor,.12)}`),t.style.setProperty("--chat-container-bg",e.containerBg),t.style.setProperty("--dashboard-pane-bg",e.containerBg),t.style.setProperty("--chat-thought-accent",e.accentColor),t.style.setProperty("--chat-tool-accent",e.accentColor),t.style.setProperty("--chat-action-color",e.accentColor),t.style.setProperty("--chat-send-bg",e.sendButton),t.style.setProperty("--chat-input-border",e.inputBorder)}function ei(){const e=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>e.style.removeProperty(r))}function ig(e){try{localStorage.setItem(Od,e)}catch{}if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=ps()?"dark":"light";hs(Et(t))}else ei(),yr(e,ps()?"dark":"light")}function lg(){try{localStorage.removeItem("adhdev-accent-color")}catch{}const e=jn();if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=ps()?"dark":"light";hs(Et(t))}else ei(),yr(e,ps()?"dark":"light")}function ps(){const e=document.documentElement.getAttribute("data-theme");return e?e==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function vt({label:e,value:t,onChange:r}){return s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:e}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[s.jsx("input",{type:"color",value:t,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),s.jsx("input",{type:"text",value:t,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function rr({title:e,children:t}){return s.jsxs("div",{style:{marginBottom:14},children:[s.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:e}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:t})]})}function cg({dark:e,onColorsChange:t}){const r=e?"dark":"light",[n,a]=l.useState(()=>Et(r));l.useEffect(()=>{a(Et(r))},[r]);const o=l.useCallback((i,c)=>{a(d=>{const m={...d,[i]:c},h=Et(r==="dark"?"light":"dark");return r==="dark"?sn(m,h):sn(h,m),hs(m),t(m),m})},[r,t]);return s.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[s.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",s.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[e?"🌙 Dark":"☀️ Light"," mode"]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsxs(rr,{title:"App Background",children:[s.jsx(vt,{label:"Background",value:n.bgPrimary,onChange:i=>o("bgPrimary",i)}),s.jsx(vt,{label:"Surface",value:n.bgSecondary,onChange:i=>o("bgSecondary",i)}),s.jsx(vt,{label:"Card",value:n.surfacePrimary,onChange:i=>o("surfacePrimary",i)})]}),s.jsxs(rr,{title:"App Text",children:[s.jsx(vt,{label:"Primary",value:n.textPrimary,onChange:i=>o("textPrimary",i)}),s.jsx(vt,{label:"Secondary",value:n.textSecondary,onChange:i=>o("textSecondary",i)}),s.jsx(vt,{label:"Muted",value:n.textMuted,onChange:i=>o("textMuted",i)})]}),s.jsxs(rr,{title:"Borders & Accent",children:[s.jsx(vt,{label:"Border subtle",value:n.borderSubtle,onChange:i=>o("borderSubtle",i)}),s.jsx(vt,{label:"Border default",value:n.borderDefault,onChange:i=>o("borderDefault",i)}),s.jsx(vt,{label:"Accent",value:n.accentColor,onChange:i=>o("accentColor",i)})]})]}),s.jsxs("div",{children:[s.jsxs(rr,{title:"Chat Bubbles",children:[s.jsx(vt,{label:"User bubble",value:n.userBubble,onChange:i=>o("userBubble",i)}),s.jsx(vt,{label:"User text",value:n.userText,onChange:i=>o("userText",i)}),s.jsx(vt,{label:"Agent bubble",value:n.assistantBubble,onChange:i=>o("assistantBubble",i)}),s.jsx(vt,{label:"Agent text",value:n.assistantText,onChange:i=>o("assistantText",i)})]}),s.jsxs(rr,{title:"Chat Layout",children:[s.jsx(vt,{label:"Chat BG",value:n.containerBg,onChange:i=>o("containerBg",i)}),s.jsx(vt,{label:"Send button",value:n.sendButton,onChange:i=>o("sendButton",i)}),s.jsx(vt,{label:"Input border",value:n.inputBorder,onChange:i=>o("inputBorder",i)}),s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[s.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:i=>o("bubbleRadius",Number(i.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),s.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),s.jsx("button",{onClick:()=>{const i=e?jo:ko,d=Et(e?"light":"dark");e?sn(i,d):sn(d,i),a(i),hs(i),t(i)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function dg(){const[e,t]=l.useState(jn),[r,n]=l.useState(!0),[a,o]=l.useState(()=>Et("dark"));l.useEffect(()=>{n(ps());const d=new MutationObserver(()=>{const h=ps();n(h);const f=jn();f==="custom"?hs(Et(h?"dark":"light")):yr(f,h?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const m=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const h=ps();n(h);const f=jn();f==="custom"?hs(Et(h?"dark":"light")):yr(f,h?"dark":"light")};return m.addEventListener("change",u),()=>{d.disconnect(),m.removeEventListener("change",u)}},[]),l.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",e),e==="custom"?hs(Et(r?"dark":"light")):(ei(),yr(e,r?"dark":"light"))},[e,r]),l.useEffect(()=>{o(Et(r?"dark":"light"))},[r]);const i=d=>{t(d),ig(d)},c=[...ag,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText},light:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText}}}];return s.jsxs("div",{children:[s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:c.map(d=>{const m=e===d.id,u=r?d.preview.dark:d.preview.light,h=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?a.userText:"#fff";return s.jsxs("button",{onClick:()=>i(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:m?"var(--bg-glass-hover)":"var(--bg-glass)",border:m?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:m?1:.75},children:[s.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),s.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:h},children:"Fix the bug please"}),s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[m&&s.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),s.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),e==="custom"&&s.jsx(cg,{dark:r,onColorsChange:d=>o(d)})]})}const ti="adhdev_mobileDashboardMode_v1",So="adhdev:mobile-dashboard-mode-change";function si(){try{return localStorage.getItem(ti)==="workspace"?"workspace":"chat"}catch{return"chat"}}function ug(e){if(typeof window>"u")return()=>{};const t=a=>{e(a??si())},r=a=>{const o=a.detail;t(o)},n=a=>{a.key&&a.key!==ti||t()};return window.addEventListener(So,r),window.addEventListener("storage",n),()=>{window.removeEventListener(So,r),window.removeEventListener("storage",n)}}function mg(e){try{localStorage.setItem(ti,e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent(So,{detail:e}))}function hg(){const[e,t]=l.useState(!0);return l.useEffect(()=>{t(si()==="chat")},[]),s.jsx(ls,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(ws,{size:15})," Mobile Inbox (Chat Mode)"]}),description:e?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:e,onChange:r=>{t(r),mg(r?"chat":"workspace")},extra:s.jsx("span",{className:"text-[11px] text-text-muted",children:e?"Chat mode":"Workspace"})})}const Ia=new Map,kl=new Map;function pg(e){if(!e||typeof e!="object")return null;const t=e,r=t.result&&typeof t.result=="object"?t.result:t,n=r.machine;return!n||typeof n!="object"?null:{machine:n,timestamp:typeof r.timestamp=="number"?r.timestamp:void 0}}function fg(e,t,r,n){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:n,platform:r.platform,machine:r}}function Hd(){const{sendCommand:e}=it(),{injectEntries:t,getIdes:r}=kr();return l.useCallback(async(n,a)=>{if(!n)return;const o=(a==null?void 0:a.minFreshMs)??Jf,i=kl.get(n)||0;if(!(a!=null&&a.force)&&i>0&&Date.now()-i<o)return;const c=Ia.get(n);if(c)return c;const d=(async()=>{const m=await e(n,"get_machine_runtime_stats"),u=pg(m);if(!u)return;const h=r().find(y=>y.id===n),f=fg(h,n,u.machine,u.timestamp||Date.now());t([f]),kl.set(n,Date.now())})().finally(()=>{Ia.delete(n)});return Ia.set(n,d),d},[r,t,e])}function xg(e,t,r){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:r.timestamp,platform:r.machine.platform,machine:{...(e==null?void 0:e.machine)||{},...r.machine}}}function bg(e,t){const{sendData:r}=it(),{injectEntries:n,getIdes:a}=kr(),o=Array.from(new Set(e.filter(Boolean))).join("|");l.useEffect(()=>{if(!(t!=null&&t.enabled)||!r)return;const i=o?o.split("|"):[];if(i.length===0)return;const c=i.map(d=>Gt.subscribe({sendData:r},d,{type:"subscribe",topic:"machine.runtime",key:`machine:${d}`,params:{intervalMs:t==null?void 0:t.intervalMs}},u=>{const h=a().find(y=>y.id===d),f=xg(h,d,u);n([f])}));return()=>{c.forEach(d=>d())}},[o,a,n,t==null?void 0:t.enabled,t==null?void 0:t.intervalMs,r])}function gg(e,t){const{sendData:r}=it(),[n,a]=l.useState(null),[o,i]=l.useState(!1);return l.useEffect(()=>{if(!e){a(null),i(!1);return}if(!(t!=null&&t.enabled)||!r){i(!1);return}a(null),i(!0);let c=null;const d=Gt.subscribe({sendData:r},e,{type:"subscribe",topic:"session_host.diagnostics",key:`session_host:${e}`,params:{includeSessions:(t==null?void 0:t.includeSessions)!==!1,...typeof(t==null?void 0:t.limit)=="number"?{limit:t.limit}:{},...typeof(t==null?void 0:t.intervalMs)=="number"?{intervalMs:t.intervalMs}:{}}},m=>{c&&(clearTimeout(c),c=null),a(m.diagnostics),i(!1)});return d.initialSendAccepted?c=setTimeout(()=>{i(!1)},tx):i(!1),()=>{c&&clearTimeout(c),d()}},[e,t==null?void 0:t.enabled,t==null?void 0:t.includeSessions,t==null?void 0:t.intervalMs,t==null?void 0:t.limit,r]),{diagnostics:n,loading:o,applyDiagnostics:a}}function yg(e){return e.daemonId||(e.routeId.includes(":")?e.routeId.split(":")[0]||null:e.routeId||null)}function Wd(e){const{sendData:t}=it(),[r,n]=l.useState({});return l.useEffect(()=>{const a=yg(e);if(!a||!e.sessionId||!t){n({});return}const o=Gt.subscribe({sendData:t},a,{type:"subscribe",topic:"session.modal",key:`daemon:${a}:session-modal:${e.sessionId}`,params:{targetSessionId:e.sessionId}},i=>{n({status:i.status,modalMessage:i.modalMessage,modalButtons:i.modalButtons}),Ds.record({interactionId:i.interactionId,kind:"dashboard.session_modal_applied",topic:"session.modal",payload:{sessionId:e.sessionId,status:i.status,modalButtonCount:Array.isArray(i.modalButtons)?i.modalButtons.length:0}})});return o.initialSendAccepted||n({}),()=>{o()}},[e.daemonId,e.routeId,e.sessionId,t]),r}const Kd="adhdev_hiddenTabs",Ud="adhdev_autoHiddenMeshTabs";function vg(){try{const e=localStorage.getItem(Kd);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function os(e){try{localStorage.setItem(Kd,JSON.stringify([...e]))}catch{}}function wg(){try{const e=localStorage.getItem(Ud);if(e)return new Set(JSON.parse(e))}catch{}return new Set}function Sl(e){try{localStorage.setItem(Ud,JSON.stringify([...e]))}catch{}}function ur(e){return Nr(e)}function ia(e,t){return Vt(t).some(r=>e.has(r))}function zd(e){var t,r,n;return((t=e.settings)==null?void 0:t.launchedByCoordinator)===!0&&typeof((r=e.settings)==null?void 0:r.meshNodeFor)=="string"&&e.settings.meshNodeFor.trim().length>0&&((n=e.settings)==null?void 0:n.spawnedSessionVisibility)==="hidden"}function jg(e,t,r=new Set){return e.filter(n=>{if(!zd(n))return!1;const a=ur(n);return r.has(a)?!1:!ia(t,n)})}function kg(){const[e,t]=l.useState(vg),[r,n]=l.useState(wg),a=l.useCallback(f=>{const y=ur(f);t(b=>{const x=new Set(b);return x.has(y)?x.delete(y):x.add(y),os(x),x})},[]),o=l.useCallback(f=>{const y=ur(f);t(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),os(x),x})},[]),i=l.useCallback(f=>{const y=ur(f);t(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),os(x),x}),n(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),Sl(x),x})},[]),c=l.useCallback(f=>{const y=ur(f);t(b=>{if(!b.has(y))return b;const x=new Set(b);return x.delete(y),os(x),x}),n(b=>{if(b.has(y))return b;const x=new Set(b);return x.add(y),Sl(x),x})},[]),d=l.useCallback(()=>{t(f=>{if(f.size===0)return f;const y=new Set;return os(y),y})},[]),m=l.useCallback((f,y)=>{t(b=>{const x=new Set(b);for(const k of y)x.add(k);return os(x),x})},[]),u=l.useCallback((f,y)=>{t(b=>{const x=new Set(b);for(const k of y)x.delete(k);return os(x),x})},[]),h=l.useCallback(f=>ia(e,f),[e]);return{hiddenTabs:e,autoHiddenTabs:r,toggleTarget:a,hideTarget:o,autoHideTarget:i,showTarget:c,showAllTabs:d,hideAllForDaemon:m,showAllForDaemon:u,isHidden:h}}const rn="adhdev_mutedConversations",Ma="adhdev_autoMutedMeshConversations";function Nl(e){try{const t=localStorage.getItem(e);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function nr(e,t){try{localStorage.setItem(e,JSON.stringify([...t]))}catch{}}function Sg(e,t){return Vt(t).some(r=>e.has(r))}function Ng(){const[e,t]=l.useState(()=>Nl(rn)),[r,n]=l.useState(()=>Nl(Ma)),a=l.useCallback(m=>{const u=Nr(m);t(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(rn,f),f})},[]),o=l.useCallback(m=>{const u=Vt(m);t(h=>{let f=!1;const y=new Set(h);for(const b of u)y.delete(b)&&(f=!0);return f?(nr(rn,y),y):h}),n(h=>{let f=!1;const y=new Set(h);for(const b of u)y.delete(b)&&(f=!0);return f?(nr(Ma,y),y):h})},[]),i=l.useCallback(m=>{Vt(m).some(f=>e.has(f))?o(m):a(m)},[e,a,o]),c=l.useCallback(m=>{if(!zd(m))return;const u=Nr(m);r.has(u)||(n(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(Ma,f),f}),t(h=>{if(h.has(u))return h;const f=new Set(h);return f.add(u),nr(rn,f),f}))},[r]),d=l.useCallback(m=>Sg(e,m),[e]);return{mutedTargets:e,autoMutedTargets:r,muteTarget:a,unmuteTarget:o,toggleTarget:i,autoMuteIfCoordinator:c,isMuted:d}}function Cg(e){if(!e||typeof e!="object")return!1;const t=e.result??e;return!!t&&typeof t=="object"&&t.success!==!1}function Ig(e){const t=(e==null?void 0:e.result)??e;return typeof(t==null?void 0:t.error)=="string"?t.error:"Interactive prompt response failed"}async function Mg(e,t,r){const n=await r(`/api/v1/sessions/${encodeURIComponent(e)}/interactive-prompt/resolve`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let a=`HTTP ${n.status}`;try{const o=await n.json();typeof(o==null?void 0:o.error)=="string"&&(a=o.error)}catch{}throw new Error(a)}}async function Tg({promptSession:e,response:t,useP2PCommand:r,sendCommand:n,fetchImpl:a=fetch}){if(r){const o=await n(e.routeId,"interactive_prompt_response",{targetSessionId:e.sessionId,sessionId:e.sessionId,response:t});if(!Cg(o))throw new Error(Ig(o));return}await Mg(e.sessionId,t,a)}function Ag(e){const{ides:t,isP2PActive:r,p2pStates:n}=qt(),{sendCommand:a}=it(),[o,i]=l.useState(null),[c,d]=l.useState(!1),[m,u]=l.useState(null),h=l.useMemo(()=>{const b=kp(t);return b?b.prompt.promptId===o?null:b:null},[o,t,e]),f=l.useCallback(async b=>{if(!h)return;const x=Wc(h.prompt,b);d(!0),u(null);try{const k=(n==null?void 0:n[h.daemonId])==="connected"||r===!0;await Tg({promptSession:h,response:x,useP2PCommand:k,sendCommand:a}),i(h.prompt.promptId)}catch(k){throw u(k instanceof Error?k.message:String(k)),k}finally{d(!1)}},[r,n,h,a]),y=l.useCallback(()=>{h&&i(h.prompt.promptId)},[h]);return{promptSession:h,responseError:m,isSubmitting:c,submit:f,cancel:y}}function Gd(e){return e instanceof Error?e.message:String(e||"")}function _g(e){const t=Gd(e);return t.includes("P2P command timeout")||t.includes("P2P not connected")||t.includes("P2P channel not open")||t.includes("P2P not available")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}function Lg(e){const t=Gd(e);return t.includes("P2P command timeout")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}async function Vd({conversation:e,mode:t,ides:r,sendDaemonCommand:n,setCliViewModeOverrides:a}){if(!e||!Ye(e)||Ve(e))return;const o=Us(e);if(o===t)return;const i=e.sessionId;i&&a(c=>({...c,[i]:t}));try{await n(js(e)||e.routeId,"set_cli_view_mode",{targetSessionId:e.sessionId,cliType:Kt(e),mode:t})}catch(c){const d=Lg(c);i&&!d&&a(m=>{const u={...m};return o===qd(r,i)?delete u[i]:u[i]=o,u}),_g(c)?console.warn(d?"CLI view mode result was lost after send; keeping optimistic mode override:":"Skipped CLI view mode switch:",c instanceof Error?c.message:String(c)):console.error("Failed to switch CLI view mode:",c)}}function Cl(e,t){const r=typeof e.sessionId=="string"&&e.sessionId?e.sessionId:typeof e.id=="string"?e.id:"";if(!r||e.transport!=="pty")return e;const n=t[r];return!n||e.mode===n?e:{...e,mode:n}}function Pg(e,t){if(!Array.isArray(e)||e.length===0||!t||Object.keys(t).length===0)return e;let r=!1;const n=e.map(a=>{const o=Cl(a,t),i=Array.isArray(a.childSessions)?a.childSessions.map(d=>Cl(d,t)):a.childSessions,c=i!==a.childSessions;return o!==a||c?(r=!0,{...o,...c?{childSessions:i}:{}}):a});return r?n:e}function qd(e,t){if(!t)return null;for(const r of e){if(r.sessionId===t&&r.transport==="pty")return r.mode==="chat"?"chat":"terminal";for(const n of r.childSessions||[])if(n.id===t&&n.transport==="pty")return n.mode==="chat"?"chat":"terminal"}return null}function Rg(e,t){if(!e||Object.keys(e).length===0)return e;let r=!1;const n={...e};for(const[a,o]of Object.entries(e))qd(t,a)===o&&(delete n[a],r=!0);return r?n:e}function Dg({visibleConversations:e,clearedTabs:t,setClearedTabs:r,setActionLogs:n}){l.useEffect(()=>{Xc()},[]);const a=l.useMemo(()=>e.map(o=>({id:o.tabKey,name:wd(o),status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[e]);return tf(a),l.useEffect(()=>{if(Object.keys(t).length===0)return;const i=setTimeout(()=>{r(c=>{const d=Date.now(),m={};for(const[u,h]of Object.entries(c))d-h<5e3&&(m[u]=h);return Object.keys(m).length===Object.keys(c).length?c:m})},5500);return()=>clearTimeout(i)},[t,r]),l.useEffect(()=>{const o=setInterval(()=>{const i=Date.now()-3e5;n(c=>{const d=c.filter(m=>m.timestamp>i).slice(-100);return d.length===c.length?c:d})},6e4);return()=>clearInterval(o)},[n]),null}function Il(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function fs(e){const t=[...e.messages].reverse().find(a=>!(a!=null&&a._localId))||e.messages[e.messages.length-1],r=typeof e.lastMessageAt=="number"&&Number.isFinite(e.lastMessageAt)?e.lastMessageAt:0,n=Il(t==null?void 0:t.receivedAt)||Il(t==null?void 0:t.timestamp)||0;return Math.max(r,n)}function No(e,t=0){return fs(e)||e.lastUpdated||t||0}function Yd(e){return fs(e)||e.lastUpdated||0}function Xd(e,t,r=Yd){const n=r(t)-r(e);if(n!==0)return n;const a=(e.machineName||"").localeCompare(t.machineName||"");if(a!==0)return a;const o=e.displayPrimary.localeCompare(t.displayPrimary);if(o!==0)return o;const i=e.displaySecondary.localeCompare(t.displaySecondary);return i!==0?i:e.tabKey.localeCompare(t.tabKey)}function Co(e){var r;const t=Tt(e.status,{activeModal:(r=e.modalButtons)!=null&&r.length?{buttons:e.modalButtons}:null});return t==="generating"||t==="waiting_approval"}function Eg(e){var t;return e.messages.length===0&&!((t=e.modalButtons)!=null&&t.length)&&!Co(e)&&!e.title.trim()}function $g(e){return e.length===0?null:[...e].sort((t,r)=>{const n=Number(Co(r))-Number(Co(t));if(n!==0)return n;const a=r.messages.length-t.messages.length;return a!==0?a:Xd(t,r)})[0]||null}function $t(e,t){const r=e.filter(i=>i.routeId===t);if(r.length===0)return null;const n=r.find(i=>i.streamSource==="native")||null,a=r.filter(i=>i.streamSource==="agent-stream"),o=$g(a);return n?o&&Eg(n)?o:n:o||r[0]||null}function Bg(e){const t=String(e.daemonId||"").trim(),r=String(e.id||"").trim();return!t||r.startsWith(`${t}:`)?r:`${t}:${r}`}function Og(e){const t=e.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of t){const a=Bg(n),o=r.get(a);if(!o){r.set(a,n);continue}const i=(o.workspace?1:0)+(o.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>i||(n.timestamp||0)>(o.timestamp||0))&&r.set(a,n)}return Array.from(r.values())}function Ta(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(e[r]!==t[r])return!1;return!0}function Fg(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function Ml(e){if(!e)return"";const t=Array.isArray(e.messages)?e.messages:[],r=t[t.length-1],n=r?Fg(Es(r.content)):"";return[e.id||"",e.title||"",e.status||"",t.length,String((r==null?void 0:r.id)||""),String((r==null?void 0:r.index)??""),String((r==null?void 0:r.receivedAt)??(r==null?void 0:r.timestamp)??""),n].join(":")}function Hg(e){const t=Array.isArray(e.childSessions)?e.childSessions:[];return[e.id,e.sessionId||"",e.providerSessionId||"",e.transport||"",e.mode||"",e.status||"",e.workspace||"",e.lastMessageHash||"",String(e.lastMessageAt||""),e.lastMessagePreview||"",e.lastMessageRole||"",String(e.lastUpdated||""),Ml(e.activeChat),...t.map(r=>[r.id||"",r.providerSessionId||"",r.transport||"",r.mode||"",r.status||"",r.title||"",r.lastMessageHash||"",String(r.lastMessageAt||""),r.lastMessagePreview||"",r.lastMessageRole||"",String(r.lastUpdated||""),Ml(r.activeChat)].join(":"))].join("|")}function Wg(e,t){const r=Date.now();return e.map(n=>{const a=t[n.tabKey];return a&&r-a<5e3?{...n,messages:[],title:""}:n})}function Kg(e,t){const r=new Map;for(const n of e){const a=t.get(n.routeId)||n;for(const o of Vt({routeId:n.routeId}))r.set(o,a);for(const o of Vt({providerSessionId:n.providerSessionId,sessionId:n.sessionId}))r.set(o,n.streamSource==="native"?a:n);for(const o of Vt({tabKey:n.tabKey}))r.set(o,n)}return r}function Ug(e){return[...e.messages].reverse().find(t=>!(t!=null&&t._localId))||e.messages[e.messages.length-1]}function zg(e){const t=Ug(e);if(!t)return`empty:${e.messages.length}`;if(t.id)return`id:${String(t.id)}`;if(t._localId)return`local:${String(t._localId)}`;const r=String(t.role||""),n=Es(t.content).slice(0,240);return`${e.messages.length}:${r}:${n}`}function Gg({ides:e,connectionStates:t,clearedTabs:r,hiddenTabs:n}){const a=l.useMemo(()=>Og(e),[e]),o=l.useMemo(()=>Ad(e),[e]),i=l.useRef([]),c=l.useRef([]),d=l.useRef([]),m=l.useRef(new Map),u=l.useRef(new Map),h=l.useMemo(()=>{const C=new Map,v=[];for(const S of a){const{connectionState:T="new",machineName:P}=_d(S,{machineNames:o,connectionStates:t,defaultConnectionState:"new"}),A=Hg(S),D=m.current.get(S.id);if(D&&D.ide===S&&D.sourceSignature===A&&D.connectionState===T&&D.machineName===P){C.set(S.id,D),v.push(...D.conversations);continue}const L=Qo(S,{machineNames:o,connectionStates:t,defaultConnectionState:"new"}),O={ide:S,sourceSignature:A,connectionState:T,machineName:P,conversations:L};C.set(S.id,O),v.push(...L)}m.current=C;const g=new Map,N=S=>{const T=zg(S),P=u.current.get(S.tabKey);if(P&&P.signature===T)return g.set(S.tabKey,P),P.timestamp;const A={signature:T,timestamp:Yd(S)||(P==null?void 0:P.timestamp)||0};return g.set(S.tabKey,A),A.timestamp},I=[...v].sort((S,T)=>Xd(S,T,N));return u.current=g,I},[a,t,o]),f=l.useMemo(()=>{const C=Wg(h,r);return Ta(i.current,C)?i.current:(i.current=C,C)},[h,r]),y=l.useMemo(()=>{const C=new Map,v=Array.from(new Set(f.map(g=>g.routeId)));for(const g of v){const N=$t(f,g);N&&C.set(g,N)}return C},[f]),b=l.useMemo(()=>{const C=new Map;for(const v of f){const g=y.get(v.routeId),N=v.streamSource==="native"&&g?g:v;for(const I of Vt({providerSessionId:v.providerSessionId,sessionId:v.sessionId,tabKey:v.tabKey}))C.set(I,N)}return C},[f,y]),x=l.useMemo(()=>Kg(f,y),[f,y]),k=l.useCallback(C=>{if(C)return b.get(C)},[b]),j=l.useCallback(C=>{if(C)return x.get(C)},[x]),p=l.useMemo(()=>{const C=f.filter(v=>!ia(n,v));return Ta(c.current,C)?c.current:(c.current=C,C)},[f,n]),w=l.useMemo(()=>{const C=p.map(v=>v.tabKey);return Ta(d.current,C)?d.current:(d.current=C,C)},[p]);return{chatIdes:a,conversations:f,visibleConversations:p,visibleTabKeys:w,resolveConversationBySessionId:k,resolveConversationByTarget:j}}function Vg({isMobile:e,urlActiveTab:t,resolveConversationBySessionId:r,setSearchParams:n}){const a=l.useMemo(()=>{var c;return e||!t?null:((c=r(t))==null?void 0:c.tabKey)??null},[e,r,t]),o=l.useMemo(()=>{var c;return!e||!t?null:((c=r(t))==null?void 0:c.tabKey)??null},[e,r,t]),i=l.useCallback(()=>{t&&n(c=>{const d=new URLSearchParams(c);return d.delete("activeTab"),d},{replace:!0})},[n,t]);return{requestedDesktopTabKey:a,requestedMobileTabKey:o,consumeRequestedActiveTab:i}}function qg({ides:e,sendDaemonCommand:t,setToasts:r,resolveConversationByTarget:n}){l.useEffect(()=>{Je.setIdes(e)},[e]),l.useEffect(()=>{Je.setResolveAction((a,o,i)=>{t(a,o,i).catch(()=>{})})},[t]),l.useEffect(()=>{const a=Je.onToast(o=>{r(c=>c.some(m=>m.message===o.message&&o.timestamp-m.timestamp<3e3)?c:[...c.slice(-4),{id:o.id,message:o.message,type:o.type,timestamp:o.timestamp,targetKey:o.targetKey,actions:o.actions}]);const i=o.duration||5e3;setTimeout(()=>r(c=>c.filter(d=>d.id!==o.id)),i)});return()=>{a()}},[r]),l.useEffect(()=>{const a=gd.on("status_event",o=>{Je.handleRawEvent(o,"ws")});return()=>{a()}},[]),l.useEffect(()=>{var o;const a=i=>{var x;const c=i.data;if((c==null?void 0:c.type)!=="notification_action"||typeof c.action!="string"||!c.action.startsWith("approval_")||!(c.daemonId||c.targetSessionId||c.targetKey))return;const d=c.targetSessionId||c.targetKey||c.daemonId,m=n(d),u=(m==null?void 0:m.routeId)||c.daemonId;if(!u)return;const h=Number(c.buttonIndex),f=c.button||((x=m==null?void 0:m.modalButtons)==null?void 0:x[h])||"Approve",y=String(f).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y);t(u,"resolve_action",{action:b?"approve":"reject",button:f,...Number.isFinite(h)&&{buttonIndex:h},...(m==null?void 0:m.sessionId)&&{targetSessionId:m.sessionId},...c.targetSessionId&&{targetSessionId:c.targetSessionId}}).catch(k=>console.error("[SW Action] approval failed:",k))};return(o=navigator.serviceWorker)==null||o.addEventListener("message",a),()=>{var i;return(i=navigator.serviceWorker)==null?void 0:i.removeEventListener("message",a)}},[n,t])}const Yg="adhdev_dashboardLayout_v1",Xg="adhdev_dashboardDockview_v1",Jg="adhdev_dashboardDockviewHiddenRestore_v1",ar={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function ri(e,t){try{const r=localStorage.getItem(e);return r?JSON.parse(r):t}catch{return t}}function Qg(e){return e<768?"mobile":e<1280?"desktop-narrow":"desktop-wide"}function Jd(e){return`${Yg}:${e}`}function Zg(e){const t=Jd(e);return ri(t,null)}function ey(e,t){try{const r=t.groupAssignments.length===0&&t.focusedGroup===0&&Object.keys(t.groupActiveTabIds).length===0&&Object.keys(t.groupTabOrders).length===0&&t.groupSizes.length===0,n=Jd(e);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(t))}catch{}}function Qd(e){return`${Xg}:${e}`}function ty(e){const t=Qd(e);return ri(t,null)}function sy(e,t){try{const r=Qd(e);if(!t){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(t))}catch{}}function Zd(e){return`${Jg}:${e}`}function ry(e){const t=Zd(e);return ri(t,{})}function ny(e,t){try{const r=Zd(e);if(Object.keys(t).length===0){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(t))}catch{}}function ay(){return{groupAssignments:[...ar.groupAssignments],focusedGroup:ar.focusedGroup,groupActiveTabIds:{...ar.groupActiveTabIds},groupTabOrders:{...ar.groupTabOrders},groupSizes:[...ar.groupSizes]}}function oy(e,t){return e?e.length===t.length&&e.every((r,n)=>r===t[n]):t.length===0}function iy(){const[e]=l.useState(()=>Qg(typeof window<"u"?window.innerWidth:1280)),[t,r]=l.useState(()=>new Map),[n,a]=l.useState(0),[o,i]=l.useState({}),[c,d]=l.useState({}),[m,u]=l.useState([]),[h,f]=l.useState(()=>typeof window<"u"&&window.innerWidth<768),[y,b]=l.useState(!1),x=l.useCallback(()=>{if(y)return;const S=Zg(e)??ay();r(new Map(S.groupAssignments)),a(S.focusedGroup),i(S.groupActiveTabIds),d(S.groupTabOrders),u(S.groupSizes),b(!0)},[y,e]);l.useEffect(()=>{y&&ey(e,{groupAssignments:[...t.entries()],focusedGroup:n,groupActiveTabIds:o,groupTabOrders:c,groupSizes:m})},[y,e,t,n,o,c,m]),l.useEffect(()=>{const S=window.matchMedia("(max-width: 767px)"),T=P=>f(P.matches);return S.addEventListener("change",T),()=>S.removeEventListener("change",T)},[]);const k=l.useCallback(S=>{r(S)},[]),j=l.useCallback(S=>{a(S)},[]),p=l.useCallback(S=>{i(S)},[]),w=l.useCallback(S=>{d(S)},[]),C=l.useCallback(S=>{u(S)},[]),v=l.useCallback(S=>{j(S)},[j]),g=l.useCallback((S,T)=>{i(P=>(P[S]??null)===(T??null)?P:{...P,[S]:T})},[]),N=l.useCallback((S,T)=>{d(P=>{const A=P[S];return oy(A,T)?P:{...P,[S]:T}})},[]),I=l.useCallback((S,T)=>{const P=T.get(S)??0;return g(P,S),v(P),P},[v,g]);return{layoutProfile:e,groupAssignments:t,updateGroupAssignments:k,focusedGroup:n,updateFocusedGroup:j,focusGroup:v,groupActiveTabIds:o,updateGroupActiveTabIds:p,setGroupActiveTab:g,groupTabOrders:c,updateGroupTabOrders:w,setGroupTabOrder:N,groupSizes:m,updateGroupSizes:C,isMobile:h,hasHydratedStoredLayout:y,hydrateStoredLayout:x,focusConversationTab:I}}function ly(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const r=e[0],n=oa(t);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function cy({urlActiveTab:e,conversations:t,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:a,hydrateStoredLayout:o,focusConversationTab:i,setSearchParams:c,historyModalOpen:d,activeConv:m,isRefreshingHistory:u,ides:h,handleRefreshHistory:f}){const y=l.useRef(!1),b=l.useRef(!1),x=l.useRef(null),k=l.useRef(!1);l.useEffect(()=>{if(!e||y.current||t.length===0)return;if(!a){o();return}const j=r(e);j&&(i(j.tabKey,n),y.current=!0,b.current=!0,x.current!=null&&(window.clearTimeout(x.current),x.current=null),c(p=>{const w=new URLSearchParams(p);return w.delete("activeTab"),w},{replace:!0}))},[e,t,r,n,a,o,i,c]),l.useEffect(()=>{if(!(b.current||a)&&t.length!==0){if(!e){o(),b.current=!0;return}if(y.current){b.current=!0;return}if(x.current==null)return x.current=window.setTimeout(()=>{x.current=null,!(b.current||a)&&(o(),b.current=!0)},1500),()=>{x.current!=null&&(window.clearTimeout(x.current),x.current=null)}}},[e,t.length,a,o]),l.useEffect(()=>{if(!d){k.current=!1;return}if(!m||k.current||u)return;const j=h.find(p=>p.id===m.routeId);j&&(!j.chats||j.chats.length===0||ly(j.chats,m))&&(k.current=!0,f())},[d,m,u,h,f])}function Aa(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const r=e[0];if((r==null?void 0:r.active)===!0)return!0;const n=oa(t);return typeof(r==null?void 0:r.id)=="string"&&n.includes(r.id)}function eu({sendDaemonCommand:e,activeConv:t,chats:r,updateRouteChats:n,setToasts:a,setClearedTabs:o}){const[i,c]=l.useState(!1),[d,m]=l.useState(!1),u=l.useCallback(async b=>{try{await e("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(x){console.error("Launch failed",x)}},[e]),h=l.useCallback(async(b,x)=>{try{const k=b||(t==null?void 0:t.daemonId)||"",j=await e(k,"switch_chat",{id:x,sessionId:x,...ds(t)}),p=j==null?void 0:j.result;if((j==null?void 0:j.success)===!0||p==="switched"||p==="switched-by-title")return;p===!1||p==="not_found"?er(a,"⚠️ Session tab not found — try refreshing history"):typeof p=="string"&&p.startsWith("error:")?er(a,`⚠️ Switch error: ${p}`):er(a,"⚠️ Session switch failed")}catch(k){console.error("Switch failed",k),er(a,`❌ Switch failed: ${k.message||"connection error"}`)}},[t,e,a]),f=l.useCallback(async()=>{if(!(!t||i)){c(!0);try{const b=us(t);await e(b,"new_chat",{...ds(t)}),vx(b,t.sessionId,oa(t)[0]),o(x=>({...x,[t.tabKey]:Date.now()}))}catch(b){console.error("New chat failed",b)}finally{c(!1)}}},[t,i,e,o]),y=l.useCallback(async()=>{var b,x;if(!(!t||d)){m(!0);try{const k=us(t),j=async()=>e(k,"list_chats",{forceExpand:!0,...ds(t)});let p=await j(),w=(p==null?void 0:p.chats)||((b=p==null?void 0:p.result)==null?void 0:b.chats);Aa(w,t)&&(await new Promise(C=>setTimeout(C,450)),p=await j(),w=(p==null?void 0:p.chats)||((x=p==null?void 0:p.result)==null?void 0:x.chats)),p!=null&&p.success&&Array.isArray(w)&&(n(t.routeId,w),Aa(w,t)&&!Aa(r,t)&&er(a,"⚠️ History dialog did not fully open — try once more"))}catch(k){console.error("Refresh history failed",k)}finally{m(!1)}}},[t,r,d,e,n,a]);return{isCreatingChat:i,isRefreshingHistory:d,handleLaunchIde:u,handleSwitchSession:h,handleNewChat:f,handleRefreshHistory:y}}function dy(e,t){if(e.size!==t.size)return!1;for(const[r,n]of e)if(t.get(r)!==n)return!1;return!0}function uy(e,t){return e.length!==t.length?!1:e.every((r,n)=>r===t[n])}function Tl(e,t){const r=Object.keys(e),n=Object.keys(t);return r.length!==n.length?!1:r.every(a=>t[Number(a)]===e[Number(a)])}function nn(e,t){const r=new Set(t),n=t.length>0?[0]:[];for(const[i,c]of e)!r.has(i)||c<=0||n.includes(c)||n.push(c);n.sort((i,c)=>i-c);const a={};n.forEach((i,c)=>{a[i]=c}),n.length===0&&(a[0]=0);const o=new Map;for(const[i,c]of e){if(!r.has(i)||c<=0)continue;const d=a[c];typeof d=="number"&&d>0&&o.set(i,d)}return{assignments:o,groupCount:Math.max(1,n.length),mapping:a,usedGroups:n}}function Al(e,t){const r={};for(const[n,a]of Object.entries(e)){const o=t[Number(n)];typeof o=="number"&&(r[o]=a)}return r}function my(e,t,r){if(t.length===0)return 0;if(typeof r[e]=="number")return r[e];const n=[...t].reverse().find(a=>a<e)??t[0];return r[n]??0}function hy(e,t,r){if(t.length<=1)return[];const n=t.map(i=>e[i]).filter(i=>Number.isFinite(i)),a=n.length===t.length?n:Array(r).fill(100/r),o=a.reduce((i,c)=>i+c,0);return o>0?a.map(i=>i/o*100):Array(r).fill(100/r)}function _l(e,t){const r={};for(const[n,a]of Object.entries(e)){const o=Number(n);r[o>=t?o+1:o]=a}return r}function Ll(e){return Array(e).fill(100/e)}function py({groupAssignments:e,updateGroupAssignments:t,updateFocusedGroup:r,updateGroupActiveTabIds:n,updateGroupTabOrders:a,groupSizes:o,updateGroupSizes:i,isMobile:c,visibleConversations:d,visibleTabKeys:m}){const u=l.useRef(null),h=l.useMemo(()=>nn(e,m),[e,m]),f=h.assignments,y=l.useMemo(()=>c?1:h.groupCount,[h.groupCount,c]),b=y>1,x=l.useCallback((v,g)=>{t(N=>{const I=new Map(nn(N,m).assignments);return g===0?I.delete(v):I.set(v,g),I}),n(N=>({...N,[g]:v})),r(g)},[t,m,n,r]),k=l.useCallback(v=>{t(g=>{const N=nn(g,m).assignments,I=new Map;for(const[S,T]of N)T!==v&&(T>v?I.set(S,T-1):I.set(S,T));return I}),i(g=>{if(g.length<=1)return[];const N=[...g];N.splice(v,1);const I=N.reduce((S,T)=>S+T,0);return I>0?N.map(S=>S/I*100):[]}),r(0)},[t,m,i,r]),j=l.useCallback((v,g)=>{g.preventDefault();const N=u.current;if(!N)return;const I=g.clientX,S=N.offsetWidth,T=o.length===y?[...o]:Ll(y),P=D=>{const O=(D.clientX-I)/S*100,_=[...T];_[v]=Math.max(15,T[v]+O),_[v+1]=Math.max(15,T[v+1]-O),i(_)},A=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",A),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",P),document.addEventListener("mouseup",A)},[o,y,i]),p=l.useCallback((v,g,N)=>{if(y>=4)return;const I=N==="left"?g:g+1;t(S=>{const T=nn(S,m).assignments,P=new Map;for(const A of d){const D=T.get(A.tabKey)??0,L=D>=I?D+1:D;L>0&&P.set(A.tabKey,L)}return I>0&&P.set(v,I),P}),i(S=>{const T=S.length===y?[...S]:Ll(y),P=T[g]??100/y,A=Math.max(15,P/2),D=Math.max(15,P/2),L=[...T];L[g]=A,L.splice(I,0,D);const O=L.reduce((_,M)=>_+M,0);return L.map(_=>_/O*100)}),n(S=>{const T=_l(S,I);return T[I]=v,T}),a(S=>{const T=_l(S,I);return T[I]=[v],T}),r(I)},[y,t,m,d,i,n,a,r]);l.useEffect(()=>{dy(e,f)||t(f)},[e,f,t]),l.useEffect(()=>{const{mapping:v,usedGroups:g}=h;n(N=>{const I=Al(N,v);return Tl(N,I)?N:I}),a(N=>{const I=Al(N,v);return Tl(N,I)?N:I}),r(N=>{const I=c?0:my(N,g,v);return N===I?N:I}),i(N=>{const I=c?[]:hy(N,g,h.groupCount);return uy(N,I)?N:I})},[h,c,n,a,r,i]);const w=l.useMemo(()=>{const v=Array.from({length:y},()=>[]);for(const g of d){const N=f.get(g.tabKey)??0,I=Math.min(N,y-1);v[I].push(g)}return v},[d,f,y]),C=l.useCallback(()=>{t(new Map),r(0)},[t,r]);return{containerRef:u,normalizedGroupAssignments:f,numGroups:y,isSplitMode:b,groupedConvs:w,moveTabToGroup:x,closeGroup:k,handleResizeStart:j,splitTabRelative:p,clearAllSplits:C}}function _a(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="stable"||t==="latest"?"stable":t==="preview"||t==="next"?"preview":null}function fy(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="latest"||t==="stable"?"latest":t==="next"||t==="preview"?"next":null}function an(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function ni(e){const t=e.updatePolicy&&typeof e.updatePolicy=="object"?e.updatePolicy:{},r=_a(t.channel)||_a(e.updateChannel)||_a(e.releaseChannel)||void 0,n=fy(t.npmTag)||(r==="preview"?"next":r==="stable"?"latest":void 0),a=an(t.targetVersion)||an(e.serverVersion)||void 0,o=an(t.minVersion)||void 0,i=an(t.updateCommand)||(r?`adhdev update --channel ${r}`:void 0);return{...r?{channel:r}:{},...n?{npmTag:n}:{},...a?{targetVersion:a}:{},...o?{minVersion:o}:{},...i?{updateCommand:i}:{}}}function Ts(e,t=null){return ni(e).targetVersion||t}function tu(e){return ni(e).channel||null}function su(e){const t=ni(e);return{...t.channel?{channel:t.channel}:{},...t.npmTag?{npmTag:t.npmTag}:{},...t.targetVersion?{targetVersion:t.targetVersion}:{},...Object.keys(t).length>0?{updatePolicy:t}:{}}}function xy({ides:e,sendDaemonCommand:t}){const r="0.9.82",n=l.useMemo(()=>e.filter(h=>h.type!=="adhdev-daemon"?!1:Zo(h,Ts(h,r))).sort((h,f)=>Number(gr(f,Ts(f,r)))-Number(gr(h,Ts(h,r)))),[r,e]),a=l.useMemo(()=>n.some(h=>gr(h,Ts(h,r))),[r,n]),o=l.useMemo(()=>n.map(h=>Ts(h,r)).find(h=>typeof h=="string"&&h.trim().length>0)||r,[r,n]),[i,c]=l.useState(!1),[d,m]=l.useState({}),u=l.useCallback(async h=>{var y,b;const f=e.find(x=>x.id===h);if(f){m(x=>({...x,[h]:"upgrading"}));try{const x=await t(h,"daemon_upgrade",su(f));(y=x==null?void 0:x.result)!=null&&y.upgraded||(b=x==null?void 0:x.result)!=null&&b.success?m(k=>({...k,[h]:"done"})):m(k=>({...k,[h]:"error"}))}catch{m(x=>({...x,[h]:"error"}))}}},[e,t]);return{versionMismatchDaemons:n,hasRequiredVersionDaemons:a,targetVersion:o,versionBannerDismissed:i,setVersionBannerDismissed:c,upgradingDaemons:d,handleBannerUpgrade:u}}const ru=80;function kn(e,t=Date.now()){return typeof e=="number"&&Number.isFinite(e)?e:t}function by(e){return{...e,createdAt:kn(e.createdAt),updatedAt:kn(e.updatedAt,e.createdAt),lastEventAt:kn(e.lastEventAt,e.updatedAt||e.createdAt)}}function gy(e){const t=Nr(e);return t==="unknown:"?e.id:t}function yy(e){return[e.type,md(e)||"",e.lastMessageHash||"",String(e.lastMessageAt||e.lastUpdated||0)].join("|")}function vy(e,t=ru){const r=new Map;for(const n of e){if(n.deletedAt)continue;const a=gy(n),o=r.get(a);if(!o){r.set(a,n);continue}(n.updatedAt>o.updatedAt||n.updatedAt===o.updatedAt&&n.createdAt>o.createdAt)&&r.set(a,n)}return Array.from(r.values()).sort((n,a)=>{const o=a.updatedAt-n.updatedAt;return o!==0?o:a.createdAt-n.createdAt}).slice(0,Math.max(0,t))}function wy(e,t){const r=Date.now(),n=[];for(const a of e){const o=a.sessionId?t.get(a.sessionId):void 0;if(o!=null&&o.surfaceHidden)continue;const i=ra(a,t),c=i.inboxBucket==="needs_attention"?"needs_attention":i.inboxBucket==="task_complete"&&i.unread?"task_complete":null;if(!c)continue;const d=kn(a.lastMessageAt||(o==null?void 0:o.lastUpdated)||a.lastUpdated,r),m=yy({type:c,sessionId:a.sessionId,providerSessionId:a.providerSessionId,tabKey:a.tabKey,lastMessageHash:a.lastMessageHash,lastMessageAt:a.lastMessageAt,lastUpdated:(o==null?void 0:o.lastUpdated)||a.lastUpdated});n.push(by({id:m,dedupKey:m,type:c,routeId:a.routeId,machineId:a.daemonId||a.routeId,sessionId:a.sessionId,providerSessionId:a.providerSessionId,tabKey:a.tabKey,title:sd(a),preview:Lf(a),createdAt:d,updatedAt:d,lastEventAt:d}))}return vy(n)}function jy(e){return e.filter(t=>!t.readAt&&!t.deletedAt).length}function ky(e){const{conversations:t,liveSessionInboxState:r,maxItems:n=ru}=e,a=l.useMemo(()=>wy(t,r).slice(0,Math.max(0,n)),[t,r,n]),o=l.useMemo(()=>jy(a),[a]);return{notifications:a,unreadCount:o}}function Sy({notifications:e,sendDaemonCommand:t}){const r=l.useCallback(o=>{const i=e.find(d=>d.id===o),c=Math.max(Date.now(),(i==null?void 0:i.updatedAt)||0);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_session_seen",{sessionId:i.sessionId,seenAt:c}).catch(()=>{})},[e,t]),n=l.useCallback(o=>{const i=e.find(c=>c.id===o);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_notification_unread",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]),a=l.useCallback(o=>{const i=e.find(c=>c.id===o);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"delete_notification",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]);return{handleMarkDashboardNotificationRead:r,handleMarkDashboardNotificationUnread:n,handleDeleteDashboardNotification:a}}const Ny=l.createContext(null);function nu(){return l.useContext(Ny)}function ai(...e){const t=new Set,r=[],n=a=>{const o=typeof a=="string"?a.trim():"";if(!o)return;const i=o.toLowerCase();t.has(i)||(t.add(i),r.push(o))};for(const a of e){if(Array.isArray(a)){for(const o of a)n(o);continue}n(a)}return r}function Cy(e){const t=e.trim();if(!t)return null;if(t.startsWith("~"))return t;if(/^[A-Za-z]:$/.test(t))return`${t[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(t))return`${t[0].toUpperCase()}:${t.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(t))return`${t[0].toUpperCase()}:\\${t.slice(2).replace(/[\\/]+/g,"\\")}`;const r=t.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),a=(r[2]||"").replace(/[\\/]+/g,"\\");return a?`${n}:\\${a}`:`${n}:\\`}return null}function oi(e,t=[]){if(e==="win32"){for(const r of t){if(typeof r!="string")continue;const n=Cy(r);if(n)return n}return"C:\\"}for(const r of t){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function Iy(e){const t=e.replace(/[\\/]+$/,"");if(!t||t==="/"||/^[A-Za-z]:$/.test(t))return null;const r=t.includes("\\")?"\\":"/",n=t.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}function My(e){return e!=null&&e.result&&typeof e.result=="object"&&"success"in e.result?e.result:e}async function ii(e,t,r){const n=await e(t,"file_list_browse",{path:r}),a=My(n);if(!(a!=null&&a.success))throw new Error((a==null?void 0:a.error)||(n==null?void 0:n.error)||"Could not browse folder");const o=typeof(a==null?void 0:a.path)=="string"?a.path:r,i=o.includes("\\")?"\\":"/",c=(m,u)=>/^[A-Za-z]:\\?$/.test(m)?`${m.replace(/\\?$/,"\\")}${u}`:m==="/"||m==="\\"?`${i}${u}`:`${m.replace(/[\\/]+$/,"")}${i}${u}`,d=Array.isArray(a==null?void 0:a.files)?a.files.filter(m=>(m==null?void 0:m.type)==="directory"&&typeof(m==null?void 0:m.name)=="string").map(m=>({name:m.name,path:typeof(m==null?void 0:m.path)=="string"&&m.path.trim()?m.path:c(o,m.name)})).sort((m,u)=>m.name.localeCompare(u.name)):[];return{path:o,directories:d}}function Ty(e,t){const r={meshId:t.meshId||"",workspace:t.workspace||"",serverName:t.serverName||"adhdev-mesh",adhdevMcpCommand:t.adhdevMcpCommand||"adhdev-mcp"};return e.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g,(n,a)=>r[a]||"")}function au(e,t={}){const r=e==null?void 0:e.mcpConfig;return(r==null?void 0:r.mode)!=="manual"?null:{serverName:r.serverName||"adhdev-mesh",configFormat:r.format,configPathCommand:r.configPathCommand,requiresRestart:r.requiresRestart===!0,instructions:r.instructions||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:Ty(r.template||"",{...t,serverName:r.serverName||"adhdev-mesh"})}}function Ay(e){if(!e||typeof e!="object")return null;const t=e,r=typeof t.instructions=="string"?t.instructions:"",n=typeof t.template=="string"?t.template:"";return!r&&!n?null:{serverName:typeof t.serverName=="string"?t.serverName:void 0,configFormat:typeof t.configFormat=="string"?t.configFormat:void 0,configPathCommand:typeof t.configPathCommand=="string"?t.configPathCommand:void 0,requiresRestart:t.requiresRestart===!0,instructions:r||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:n}}function Cr(e){return`/dashboard?activeTab=${encodeURIComponent(e)}`}function ou(e){return Rr(e)||e.tabKey||e.routeId||null}function iu(e){const t=typeof e.entrySessionId=="string"?e.entrySessionId.trim():"",r=typeof e.entryInstanceId=="string"?e.entryInstanceId.trim():"",n=typeof e.entryRouteId=="string"?e.entryRouteId.trim():"",a=e.conversations.find(o=>{if(n&&o.routeId!==n)return!1;const i=[o.providerSessionId,o.sessionId,o.nativeSessionId,o.tabKey].map(c=>typeof c=="string"?c.trim():"").filter(Boolean);return!!(t&&i.includes(t)||r&&i.includes(r)||n&&o.routeId===n)});if(a!=null&&a.tabKey)return a.tabKey;if(n){const o=$t(e.conversations,n)||e.conversations.find(i=>i.routeId===n);if(o!=null&&o.tabKey)return o.tabKey}return t||r||n||null}function Qt(e){return String(e||"").trim()}function lu(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function qn(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function _y(e,t){return!e||!t?!1:e===t||e.endsWith(`/${t}`)||t.endsWith(`/${e}`)}function Ly(e,t){const r=Qt(e.providerSessionId),n=Qt(e.targetSessionId),a=t.find(o=>{const i=[o.providerSessionId,o.sessionId,o.nativeSessionId,o.tabKey,o.routeId].map(Qt).filter(Boolean);return!!(r&&i.includes(r)||n&&i.includes(n))});return a?a.tabKey:n||r||null}function Py(e,t,r){if(t.event!=="agent:generating_completed")return null;const n=lu(t.daemonId);if(n&&n!==e.machineId)return null;const a=Qt(t.providerType);if(e.providerType&&a!==e.providerType)return null;const o=Qt(e.resumeSessionId),i=Qt(e.launchedSessionId),c=Qt(t.providerSessionId),d=Qt(t.targetSessionId);if(o&&o!==c&&o!==d||i&&i!==c&&i!==d)return null;const m=qn(e.workspacePath);if(m){const u=qn(t.workspaceName);if(u&&!_y(u,m))return null}return Ly(t,r)}function Pl(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function Ry({ides:e,conversations:t,onOpenSession:r}){const[n,a]=l.useState(null),o=l.useRef(null),i=l.useCallback(()=>{o.current=null,a(null)},[]),c=l.useCallback(d=>{o.current=d,a(d)},[]);return l.useEffect(()=>{if(!n)return;const d=qn(n.workspacePath),m=e.find(h=>{var k,j,p,w;if(!h||h.type==="adhdev-daemon"||lu(h.daemonId||h.id)!==n.machineId||(Sr(h)?"cli":Ls(h)?"acp":"ide")!==n.kind)return!1;const b=String(h.agentType||h.type||"");if(n.providerType&&b!==n.providerType)return!1;if(n.resumeSessionId)return String(h.providerSessionId||"")===n.resumeSessionId;if(n.launchedSessionId){const C=String(n.launchedSessionId||"");return[h.providerSessionId,h.sessionId,h.instanceId,h.id].map(g=>String(g||"")).filter(Boolean).includes(C)}if(d){const C=qn(h.workspace||h.runtimeWorkspaceLabel);return C?C===d:!1}return Number(h.lastUpdated||h._lastUpdate||h.timestamp||((w=(p=(j=(k=h.activeChat)==null?void 0:k.messages)==null?void 0:j.at)==null?void 0:p.call(j,-1))==null?void 0:w.timestamp)||0)>=n.startedAt-5e3});if(!m)return;const u=iu({entrySessionId:m.sessionId,entryInstanceId:m.instanceId,entryRouteId:m.id,conversations:t});u&&(i(),r(u))},[i,t,e,r,n]),l.useEffect(()=>Je.onStatusEvent(d=>{const m=o.current;if(!m)return;const u=Py(m,d,t);u&&(i(),r(u))}),[i,t,r]),l.useEffect(()=>{if(!n)return;const d=window.setTimeout(()=>{a(m=>!m||m.startedAt!==n.startedAt?m:(o.current=null,null))},45e3);return()=>window.clearTimeout(d)},[n]),{trackPendingLaunch:c}}function Dy({sendDaemonCommand:e,trackPendingLaunch:t,onOpenSession:r,activeConv:n,ides:a,setCliViewModeOverrides:o}){const i=nu(),{launchCli:c}=Zn(),d=l.useCallback(async(k,j)=>ii(e,k,j),[e]),m=l.useCallback(async(k,j)=>{if(!j.trim())return{ok:!1,error:"Choose a workspace path first."};try{const p=await e(k,"workspace_add",{path:j.trim()});return p!=null&&p.success?{ok:!0}:{ok:!1,error:(p==null?void 0:p.error)||"Could not save workspace"}}catch(p){return{ok:!1,error:p instanceof Error?p.message:"Could not save workspace"}}},[e]),u=l.useCallback(async(k,j,p)=>{var w;try{const C={ideType:j,enableCdp:!0};(w=p==null?void 0:p.workspacePath)!=null&&w.trim()&&(C.workspace=p.workspacePath.trim());const v=await e(k,"launch_ide",C);return!(v!=null&&v.success)&&(v==null?void 0:v.success)!==void 0?{ok:!1,error:(v==null?void 0:v.error)||"Could not launch IDE"}:(t({machineId:k,kind:"ide",providerType:j,workspacePath:(p==null?void 0:p.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(C){return{ok:!1,error:C instanceof Error?C.message:"Could not launch IDE"}}},[e,t]),h=l.useCallback(async(k,j,p,w)=>{var v,g,N;const C=Date.now();try{const I={cliType:p};(v=w==null?void 0:w.workspacePath)!=null&&v.trim()?I.dir=w.workspacePath.trim():w!=null&&w.workspaceId&&(I.workspaceId=w.workspaceId),(g=w==null?void 0:w.resumeSessionId)!=null&&g.trim()&&(I.resumeSessionId=w.resumeSessionId.trim()),Array.isArray(w==null?void 0:w.cliArgs)&&w.cliArgs.length>0&&(I.cliArgs=w.cliArgs),(N=w==null?void 0:w.initialModel)!=null&&N.trim()&&(I.initialModel=w.initialModel.trim());const S=await c(k,I),T=(S==null?void 0:S.result)||S,P=(T==null?void 0:T.sessionId)||(T==null?void 0:T.id);return S!=null&&S.success&&P?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,launchedSessionId:P,startedAt:C}),{ok:!0}):S!=null&&S.success?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,startedAt:C}),{ok:!0}):{ok:!1,error:(S==null?void 0:S.error)||(T==null?void 0:T.error)||`Could not launch ${j.toUpperCase()} session`}}catch(I){return Pl(I)?(t({machineId:k,kind:j,providerType:p,workspacePath:(w==null?void 0:w.workspacePath)||null,resumeSessionId:(w==null?void 0:w.resumeSessionId)||null,startedAt:C}),{ok:!0}):{ok:!1,error:I instanceof Error?I.message:`Could not launch ${j.toUpperCase()} session`}}},[c,e,t]),f=l.useCallback(async k=>{var j;if(i!=null&&i.listMeshes)return i.listMeshes(k);if(!k)return[];try{const p=await e(k,"list_meshes",{}),w=(p==null?void 0:p.result)??p;if((w==null?void 0:w.success)===!1)throw new Error((w==null?void 0:w.error)||"Could not load meshes");return(Array.isArray(w==null?void 0:w.meshes)?w.meshes:Array.isArray((j=w==null?void 0:w.result)==null?void 0:j.meshes)?w.result.meshes:[]).map(v=>{var g;return{id:String((v==null?void 0:v.id)||""),name:String((v==null?void 0:v.name)||(v==null?void 0:v.id)||"Untitled mesh"),repoIdentity:(v==null?void 0:v.repoIdentity)||(v==null?void 0:v.repo_identity)||null,workspace:Array.isArray(v==null?void 0:v.nodes)&&v.nodes.length>0?String(((g=v.nodes[0])==null?void 0:g.workspace)||""):null,nodesCount:Array.isArray(v==null?void 0:v.nodes)?v.nodes.length:void 0,status:(v==null?void 0:v.status)||null}}).filter(v=>v.id)}catch(p){throw console.error("List meshes failed",p),p}},[i,e]),y=l.useCallback(async(k,j,p)=>{if(!j.trim())return{ok:!1,error:"Choose a mesh first."};if(i!=null&&i.launchMeshCoordinator)return i.launchMeshCoordinator(k,j,p);const w=Date.now();try{const C={meshId:j.trim()};p.trim()&&(C.cliType=p.trim());const v=await e(k,"launch_mesh_coordinator",C),g=(v==null?void 0:v.result)??v;if((g==null?void 0:g.success)===!1||(v==null?void 0:v.success)===!1){const I=String((g==null?void 0:g.code)||(v==null?void 0:v.code)||""),S=Ay((g==null?void 0:g.meshCoordinatorSetup)||(g==null?void 0:g.manualSetup)||(v==null?void 0:v.meshCoordinatorSetup)||(v==null?void 0:v.manualSetup));return{ok:!1,error:(g==null?void 0:g.error)||(v==null?void 0:v.error)||"Could not launch mesh coordinator",code:I||void 0,manualSetup:S}}const N=(g==null?void 0:g.sessionId)||(g==null?void 0:g.id);return N?r(N):t({machineId:k,kind:"cli",providerType:(g==null?void 0:g.cliType)||p.trim()||void 0,workspacePath:(g==null?void 0:g.workspace)||null,startedAt:w}),{ok:!0}}catch(C){return Pl(C)?(t({machineId:k,kind:"cli",providerType:p.trim()||void 0,startedAt:w}),{ok:!0}):{ok:!1,error:C instanceof Error?C.message:"Could not launch mesh coordinator"}}},[i,r,e,t]),b=l.useCallback(async(k,j)=>{if(!k||!j)return[];try{const p=await e(k,"list_saved_sessions",{providerType:j,kind:"cli",limit:30}),w=(p==null?void 0:p.result)??p;return Array.isArray(w==null?void 0:w.sessions)?w.sessions:[]}catch(p){return console.error("List saved sessions failed",p),[]}},[e]),x=l.useCallback(async k=>{await Vd({conversation:n,mode:k,ides:a,sendDaemonCommand:e,setCliViewModeOverrides:o})},[n,a,e,o]);return{handleBrowseMachineDirectory:d,handleSaveMachineWorkspace:m,handleLaunchMachineIde:u,handleLaunchMachineProvider:h,handleListMachineMeshes:f,handleLaunchMeshCoordinator:y,handleListMachineSavedSessions:b,setActiveCliViewMode:x}}function Ey(e){switch(e){case"notification-open":case"toast-open":case"conversation-open":case"requested-tab":return!0;case"dockview-shortcut":case"dockview-focus":case"dockview-move":case"dockview-split":case"stored-layout-restore":case"passive-tab-sync":return!1;default:return!1}}function $y(e,t,r=Date.now()){return!e||!Ey(t)?null:{tabKey:e,nonce:r}}function By({isMobile:e,conversations:t,visibleConversations:r,groupActiveTabIds:n,focusedGroup:a,groupedConvs:o,setSearchParams:i}){const[c,d]=l.useState(null),[m,u]=l.useState(null),h=l.useMemo(()=>{var k,j;if(!e){if(c){const p=t.find(w=>w.tabKey===c);if(p)return p}return r[0]}const x=n[a];if(x){const p=t.find(w=>w.tabKey===x);if(p)return p}return((k=o[a])==null?void 0:k[0])||((j=o[0])==null?void 0:j[0])},[t,c,a,n,o,e,r]),f=l.useCallback(x=>{d(x)},[]),y=l.useCallback(x=>{d(x.tabKey),i(k=>{const j=new URLSearchParams(k),p=Rf(x);return p?j.set("activeTab",p):j.delete("activeTab"),j},{replace:!0})},[i]),b=l.useCallback((x,k)=>{const j=$y(x,k);j&&u(j)},[]);return{activeConv:h,openDesktopConversation:y,requestScrollToBottom:b,scrollToBottomRequest:m,setDesktopActiveTab:f}}function Oy(e){const t=e.completedKey||null,r=e.pendingKey||null;return e.shouldMarkSeen?t===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:r!==null&&r!==e.autoReadKey,nextPendingKey:r===e.autoReadKey?r:null}:r===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:!1,nextPendingKey:r}:{shouldSchedule:!0,shouldCancelPending:r!==null&&r!==e.autoReadKey,nextPendingKey:e.autoReadKey}:{shouldSchedule:!1,shouldCancelPending:!!r,nextPendingKey:null}}function Fy(e){const t=String(e.liveState.completionMarker||""),r=String(e.liveState.seenCompletionMarker||""),n=String(e.liveState.inboxBucket||"idle"),a=!!e.liveState.unread,o=[e.tabKey,e.historySessionId||"",t,r,n,a?"1":"0"].join(":");return{shouldMarkSeen:!!(n==="task_complete"&&a&&(!t||t!==r)),autoReadKey:o,completionMarker:t,readAt:Math.max(Date.now(),e.timestamp||0,e.liveState.lastUpdated||0)}}function Hy({activeConv:e,isMobile:t,liveSessionInboxState:r,sendDaemonCommand:n}){const a=l.useRef(null),o=l.useRef(null),i=l.useRef(null),c=l.useRef(null),d=l.useRef(null);l.useEffect(()=>{const m=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(clearTimeout(c.current),c.current=null),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null),o.current=null};if(t){m(),a.current=null;return}if(!(e!=null&&e.sessionId)){m(),a.current=null;return}const u=Rn(e,r),h=Fy({tabKey:e.tabKey,historySessionId:Rr(e)||"",lastMessageHash:e.lastMessageHash||"",lastMessageAt:Number(e.lastMessageAt||0),timestamp:fs(e),liveState:u}),f=h.autoReadKey,y=Oy({autoReadKey:f,shouldMarkSeen:h.shouldMarkSeen,completedKey:a.current,pendingKey:o.current});if(!h.shouldMarkSeen){y.shouldCancelPending&&m(),a.current=f;return}if(!y.shouldSchedule)return;y.shouldCancelPending&&m();const b=()=>{if(document.visibilityState!=="visible"||a.current===f)return;a.current=f,o.current=null,i.current=null,c.current=null,d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null);const k=h.readAt;n(e.daemonId||e.routeId,"mark_session_seen",{sessionId:e.sessionId,providerSessionId:e.providerSessionId,seenAt:k,completionMarker:h.completionMarker}).catch(()=>{})};if(o.current=y.nextPendingKey,document.visibilityState==="visible"){i.current=setTimeout(b,1500);const k=()=>{document.visibilityState!=="visible"&&i.current&&(clearTimeout(i.current),i.current=null)};d.current=k,document.addEventListener("visibilitychange",k);return}const x=()=>{document.visibilityState==="visible"&&(c.current&&clearTimeout(c.current),c.current=setTimeout(b,800),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null))};d.current=x,document.addEventListener("visibilitychange",x)},[e,t,r,n]),l.useEffect(()=>()=>{i.current&&clearTimeout(i.current),c.current&&clearTimeout(c.current),d.current&&document.removeEventListener("visibilitychange",d.current)},[])}function La(e){if(!e)return"";const t=String(e.workspacePath||"").trim();if(t)return t;const r=String(e.workspaceName||"").trim();return/^(?:~\/|\/|[A-Za-z]:[\\/])/.test(r)?r:""}function Wy({activeConv:e,remoteDialogConv:t,remoteDialogActiveConv:r,ides:n,sendDaemonCommand:a,updateRouteChats:o,setToasts:i,setClearedTabs:c,setSearchParams:d}){var $;const{launchCli:m}=Zn(),[u,h]=l.useState(!1),[f,y]=l.useState([]),[b,x]=l.useState(()=>jt()),[k,j]=l.useState(!1),[p,w]=l.useState(null),C=l.useRef(null),v=l.useMemo(()=>r||t||e,[e,r,t]),g=!!v&&Ye(v)&&!Ve(v),N=l.useMemo(()=>{if(!v||!g)return null;const W=v.daemonId||v.routeId||"",B=Kt(v),F=La(v);return`${W}:${B}:${v.providerSessionId||""}:${F}`},[v,g]),I=l.useMemo(()=>!v||!g?"":La(v),[v,g]),{isCreatingChat:S,isRefreshingHistory:T,handleSwitchSession:P,handleNewChat:A,handleRefreshHistory:D}=eu({sendDaemonCommand:a,activeConv:v,chats:($=n.find(W=>W.id===(v==null?void 0:v.routeId)))==null?void 0:$.chats,updateRouteChats:o,setToasts:i,setClearedTabs:c}),L=l.useCallback(()=>{h(!0)},[]),O=l.useCallback(()=>{h(!1)},[]),_=l.useCallback(async()=>{if(!(!v||!g||k)){j(!0);try{const W=v.daemonId||v.routeId,B=Kt(v),F=La(v),K=await a(W,"list_saved_sessions",{agentType:B,providerType:B,kind:"cli",limit:50,...v.providerSessionId?{providerSessionId:v.providerSessionId}:{},...F?{workspace:F}:{}}),Y=(K==null?void 0:K.result)??K;y(Array.isArray(Y==null?void 0:Y.sessions)?Y.sessions:[])}catch(W){console.error("Refresh saved sessions failed",W),y([])}finally{j(!1)}}},[v,k,g,a]);l.useEffect(()=>{if(!u){C.current=null;return}if(!g){C.current=null,y([]),j(!1);return}!N||k||C.current!==N&&(C.current=N,_())},[_,u,k,g,N]);const M=l.useCallback(async W=>{if(!v||!g||!W.providerSessionId||!W.workspace)return;const B=v.daemonId||v.routeId,F=Kt(v);try{w(W.providerSessionId);const K=await m(B,{cliType:F,dir:W.workspace,resumeSessionId:W.providerSessionId,initialModel:qc(W.summaryMetadata,"model",{preferShortValue:!0})||void 0}),Y=(K==null?void 0:K.result)??K,re=typeof(Y==null?void 0:Y.sessionId)=="string"?Y.sessionId:typeof(Y==null?void 0:Y.id)=="string"?Y.id:"";re&&d(ae=>{const he=new URLSearchParams(ae);return he.set("activeTab",re),he},{replace:!0}),O()}catch(K){console.error("Resume saved session failed",K)}finally{w(null)}},[O,v,g,a,d]);return{historyModalOpen:u,openHistoryModal:L,closeHistoryModal:O,historyTargetConv:v,isSavedSessionHistoryTarget:g,isHistoryCreatingChat:S,isHistoryRefreshingHistory:T,handleHistorySwitchSession:P,handleHistoryNewChat:A,handleHistoryRefresh:D,savedHistorySessions:f,savedHistoryFilters:b,setSavedHistoryFilters:x,missingWorkspaceResumePath:I,isSavedHistoryLoading:k,resumingSavedHistorySessionId:p,handleRefreshSavedHistory:_,handleResumeSavedHistorySession:M}}function Ky({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c}){const[d,m]=l.useState(null),[u,h]=l.useState(null),f=l.useMemo(()=>{if(e||!n)return null;const j=c(n);return j&&!Ye(j)&&!Ve(j)?j:null},[e,n,c]),y=l.useMemo(()=>{const j=d==null?void 0:d.routeId;if(!j)return null;const p=d!=null&&d.tabKey?o.find(w=>w.tabKey===d.tabKey):a?o.find(w=>w.tabKey===a):null;return(p==null?void 0:p.routeId)===j?p:$t(o,j)},[o,d,a]),b=l.useMemo(()=>{if(y)return i.find(j=>j.id===y.routeId)},[i,y]);l.useEffect(()=>{f&&(m({routeId:f.routeId,tabKey:el(f)}),h(f),r({pathname:t.pathname,search:t.search},{replace:!0,state:null}))},[t.pathname,t.search,r,f]);const x=l.useCallback(j=>{j&&(m({routeId:j.routeId,tabKey:el(j)}),h(j))},[]),k=l.useCallback(()=>{m(null),h(null)},[]);return{remoteDialogConv:y,remoteDialogIdeEntry:b,remoteDialogActiveConv:u,setRemoteDialogActiveConv:h,openRemoteDialog:x,closeRemoteDialog:k}}function Uy({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c,activeConv:d,sendDaemonCommand:m}){const{remoteDialogConv:u,remoteDialogIdeEntry:h,remoteDialogActiveConv:f,setRemoteDialogActiveConv:y,openRemoteDialog:b,closeRemoteDialog:x}=Ky({isMobile:e,location:t,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:a,conversations:o,ides:i,resolveConversationByTarget:c}),[k,j]=l.useState(!1),[p,w]=l.useState(null),C=l.useCallback(async N=>{const I=N||d;!I||!Ye(I)&&!Ve(I)||(w(I),j(!0))},[d]),v=l.useCallback(()=>{j(!1),w(null)},[]),g=l.useCallback(async N=>{const I=p||d;if(!I||!Ye(I)&&!Ve(I)){v();return}j(!1);try{const S=Kt(I),T=I.routeId||I.daemonId||"";await m(T,"stop_cli",{cliType:S,targetSessionId:I.sessionId,mode:N})}catch(S){console.error("Stop CLI failed:",S)}finally{w(null)}},[d,v,p,m]);return{remoteDialogConv:u,remoteDialogIdeEntry:h,remoteDialogActiveConv:f,setRemoteDialogActiveConv:y,openRemoteDialog:b,closeRemoteDialog:x,cliStopDialogOpen:k,cliStopTargetConv:p,requestCliStop:C,cancelCliStop:v,confirmCliStop:g}}function cu({conversation:e,className:t="",onOpenNativeConversation:r,onOpenMachine:n,interactive:a=!0,meshOnly:o=!1}){var w,C,v;const i=Tr(),c=js(e),d=o?null:td(e),m=!o&&(e.transport==="cdp-page"||e.transport==="cdp-webview"),u=!o&&e.streamSource==="agent-stream"&&!!e.agentName,h=!o&&!u&&(e.transport==="pty"||e.transport==="acp"),f=Fs(e),y=Pf(e),b=(w=e.settings)==null?void 0:w.meshNodeFor,x=e.meshQueueStats,k=((C=e.coordinator)==null?void 0:C.meshId)||((v=e.settings)==null?void 0:v.meshCoordinatorFor),j=l.useCallback(()=>{if(n){n();return}c&&i("/dashboard",{state:{openMachineId:c}})},[c,i,n]),p=l.useCallback(()=>{if(r){r();return}const g=ou(e);g&&i(Cr(g))},[e,i,r]);return!m&&!u&&!h&&!d&&!b&&!x?null:s.jsxs("div",{className:`conversation-meta-chips ${t}`.trim(),children:[m&&(a?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:y,children:[s.jsx(Bt,{size:12}),s.jsx("span",{children:y})]}):s.jsxs("span",{className:"conversation-meta-chip",title:y,children:[s.jsx(Bt,{size:12}),s.jsx("span",{children:y})]})),u&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(Os,{size:12}),s.jsx("span",{children:f})]}),h&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(Os,{size:12}),s.jsx("span",{children:f})]}),d&&(a?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:j,title:d,children:[s.jsx(ts,{size:12}),s.jsx("span",{children:d})]}):s.jsxs("span",{className:"conversation-meta-chip",title:d,children:[s.jsx(ts,{size:12}),s.jsx("span",{children:d})]})),b&&s.jsxs("span",{className:"conversation-meta-chip",title:"Mesh node",children:[s.jsx(ts,{size:12}),s.jsx("span",{children:"Mesh Node"})]}),k&&x&&s.jsxs("span",{className:`conversation-meta-chip ${x.pending>0?"is-active":""}`,style:x.failed>0?{color:"var(--color-red-400)",borderColor:"var(--color-red-400)"}:void 0,title:`Queue: ${x.pending} pending, ${x.assigned} assigned, ${x.completed} completed, ${x.failed} failed`,children:[s.jsx(Ch,{size:12}),s.jsxs("span",{children:[x.pending," Pending"]})]})]})}function Pa(e,t=!0){return(e??!0)&&t}const li=l.memo(function({activeConv:t,clearToken:r,isCliTerminal:n,ideEntry:a,terminalRef:o,handleModalButton:i,handleRelaunch:c,handleSendChat:d,handleForceSendChat:m,isSendingChat:u,sendFeedbackMessage:h=null,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j=!0,isVisible:p=!0}){const w=n,C=!n,v=Pa(p,w),g=Pa(p,C),N=Pa(p),I=Wd(t),S=I.status||I.modalMessage||I.modalButtons?{...t,...I.status?{status:I.status}:{},...I.modalMessage!==void 0?{modalMessage:I.modalMessage}:{},...I.modalButtons!==void 0?{modalButtons:I.modalButtons}:{}}:t;return s.jsxs(s.Fragment,{children:[s.jsx(Uc,{activeConv:S,onModalButton:i}),s.jsx(cu,{conversation:S,className:"chat-pane-meta-row mx-3 mt-1",meshOnly:!0}),S.transport!=="pty"&&S.transport!=="acp"&&S.cdpConnected===!1?s.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[s.jsx("span",{className:"text-sm",children:s.jsx(Bs,{size:14})}),s.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),s.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:c,children:"Relaunch with CDP"})]})}):null,S.transport==="pty"?s.jsxs("div",{style:{position:"relative",minHeight:0,flex:"1 1 0%",width:"100%",overflow:"hidden"},children:[s.jsx("div",{"aria-hidden":!n,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:w?"visible":"hidden",pointerEvents:w?"auto":"none"},children:s.jsx(eb,{activeConv:S,clearToken:r,terminalRef:o,handleSendChat:d,isSendingChat:u,sendFeedbackMessage:h,isVisible:v,isInputActive:j&&v})}),s.jsx("div",{"aria-hidden":n,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:C?"visible":"hidden",pointerEvents:C?"auto":"none"},children:s.jsx(yo,{activeConv:S,ideEntry:a,handleSendChat:d,isSendingChat:u,sendFeedbackMessage:h,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j&&g,isVisible:g})})]}):s.jsx(yo,{activeConv:S,ideEntry:a,handleSendChat:d,handleForceSendChat:m,isSendingChat:u,sendFeedbackMessage:h,handleFocusAgent:f,isFocusingAgent:y,actionLogs:b,userName:x,scrollToBottomRequestNonce:k,isInputActive:j&&N,isVisible:N})]})},(e,t)=>e.activeConv===t.activeConv&&e.isCliTerminal===t.isCliTerminal&&e.ideEntry===t.ideEntry&&e.terminalRef===t.terminalRef&&e.handleModalButton===t.handleModalButton&&e.handleRelaunch===t.handleRelaunch&&e.handleSendChat===t.handleSendChat&&e.handleForceSendChat===t.handleForceSendChat&&e.isSendingChat===t.isSendingChat&&e.sendFeedbackMessage===t.sendFeedbackMessage&&e.handleFocusAgent===t.handleFocusAgent&&e.isFocusingAgent===t.isFocusingAgent&&e.actionLogs===t.actionLogs&&e.userName===t.userName&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isInputActive===t.isInputActive&&e.isVisible===t.isVisible);function zy({selectedConversation:e,isAcp:t,isStandalone:r,selectedIdeEntry:n,actionLogs:a,userName:o,isSendingChat:i,sendFeedbackMessage:c=null,isFocusingAgent:d,onBack:m,onOpenNativeConversation:u,onOpenMachine:h,onOpenHistory:f,onOpenRemote:y,onOpenMeshGraph:b,onStopCli:x,cliViewMode:k,onSetCliViewMode:j,handleSendChat:p,handleForceSendChat:w,handleFocusAgent:C,handleModalButton:v,handleRelaunch:g}){var A,D;const N=l.useRef(null),I=Ye(e)&&!t,S=I&&k==="terminal",T=!!e.daemonId&&!!((A=e.coordinator)!=null&&A.meshId||(D=e.settings)!=null&&D.meshCoordinatorFor),P=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center justify-between gap-3 ${P} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:m,type:"button","aria-label":"Back",children:s.jsx(Ro,{size:18})}),s.jsxs("div",{className:"min-w-0 flex-1 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:nt(e)}),s.jsx("div",{className:"min-w-0 max-w-full text-xs text-text-secondary",children:s.jsx(cu,{conversation:e,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>u(e),onOpenMachine:()=>h(e)})})]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[I&&k&&s.jsx(kd,{mode:k,onChange:j,compact:!0}),I&&x&&s.jsx("button",{onClick:()=>{x(e)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(xt,{size:14})}),T&&b&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>b(e),type:"button",title:"Open live repo mesh graph","aria-label":"Open live repo mesh graph",children:s.jsx(Zt,{size:14})}),s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(e),type:"button",children:s.jsx(Do,{size:14})}),!t&&!I&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>y(e),type:"button",children:s.jsx(Bt,{size:14})})]})]}),s.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:s.jsx(li,{activeConv:e,clearToken:0,isCliTerminal:S,ideEntry:n,terminalRef:N,handleModalButton:v,handleRelaunch:g,handleSendChat:p,handleForceSendChat:w,isSendingChat:i,sendFeedbackMessage:c,handleFocusAgent:C,isFocusingAgent:d,actionLogs:a,userName:o})})]})}const Ra={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function Gy(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function du(){const[e,t]=l.useState("unix"),[r,n]=l.useState("powershell"),[a,o]=l.useState(!1),i=e==="unix"?"unix":r;l.useEffect(()=>{t(Gy())},[]);const c=l.useCallback(()=>{navigator.clipboard.writeText(Ra[i].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[i]);return s.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${e==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>t("unix"),children:"🍎🐧 macOS / Linux"}),s.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${e==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>t("windows"),children:"🪟 Windows"})]}),e==="windows"&&s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),s.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),s.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:c,title:"Click to copy",children:[s.jsx("span",{className:"text-text-muted select-none",children:Ra[i].prompt}),s.jsx("span",{className:"flex-1 break-all",children:Ra[i].cmd}),s.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:a?"✓":"📋"})]}),s.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",s.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function uu({section:e,onSectionChange:t}){const r=[{key:"machines",label:"Machines",icon:Bt},{key:"chats",label:"Chats",icon:ws}];return s.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:s.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:a,icon:o})=>{const i=e===n;return s.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${i?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:i?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>t(n),type:"button","aria-pressed":i,children:[s.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${i?"text-accent-primary":"bg-transparent text-current"}`,style:i?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:s.jsx(o,{size:15})}),s.jsx("span",{children:a})]},n)})})})}function on({title:e,className:t=""}){return s.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${t}`,children:s.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:e})})}function Ns({children:e,className:t=""}){return s.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${t}`,children:e})}function or({icon:e,title:t,subtitle:r,children:n}){return s.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[s.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:e}),s.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:t}),s.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Vy({conversation:e,onCancel:t,onConfirm:r}){const n=nt(e),a=ys(e);return s.jsxs("div",{className:"fixed inset-0 z-[1400] flex items-end justify-center overflow-y-auto px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",children:[s.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:t}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"mobile-hide-confirm-title",className:"fade-in relative w-full sm:w-[min(92vw,420px)] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] flex flex-col overflow-hidden rounded-[24px] sm:rounded-[18px] border border-border-subtle bg-bg-primary shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border-subtle bg-[var(--surface-primary)] px-4 py-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h3",{id:"mobile-hide-confirm-title",className:"m-0 text-base font-extrabold text-text-primary",children:"Hide this chat from the inbox?"}),s.jsx("div",{className:"mt-1 text-[13px] leading-relaxed text-text-muted",children:"This only collapses the chat locally. You can restore it from Hidden tabs."})]}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary text-text-secondary transition-colors hover:bg-surface-primary hover:text-text-primary",onClick:t,"aria-label":"Cancel hide chat",children:s.jsx(xt,{size:16})})]}),s.jsx("div",{className:"px-4 py-4",children:s.jsxs("div",{className:"rounded-2xl border border-border-subtle bg-bg-secondary/60 px-3.5 py-3",children:[s.jsx("div",{className:"truncate text-sm font-bold text-text-primary",children:n}),s.jsx("div",{className:"mt-1 truncate text-xs text-text-muted",children:a})]})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border-subtle bg-bg-secondary px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))]",children:[s.jsx("button",{type:"button",className:"btn btn-secondary min-h-[40px] px-4 text-sm",onClick:t,children:"Cancel"}),s.jsx("button",{type:"button",className:"btn btn-primary min-h-[40px] px-4 text-sm",onClick:r,children:"Hide tab"})]})]})]})}function ln({item:e,type:t,getAvatarText:r,onOpenConversation:n,onRequestHideConversation:a,onOpenMeshGraph:o,onCollectChatDebugBundle:i,isMuted:c,onToggleMute:d}){var A,D;const m=t==="needs_attention"||t==="task_complete",u=t==="working",h=t==="earlier",f=t==="task_complete",{isReconnecting:y,isConnecting:b}=Ks(e.conversation),x=nt(e.conversation),k=ys(e.conversation),j=vd(e.conversation,{requiresAction:t==="needs_attention"}),p=m?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":u?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":h?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",w=m?"bg-accent-primary shadow-glow":u?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":h?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",C=h?"text-text-secondary":"text-text-primary",v=h?"text-text-muted":"text-text-secondary",g=h?"text-text-secondary opacity-80":"text-text-muted",N=h?"text-text-muted opacity-80":"text-text-muted",I=!u&&!f,S=!!e.conversation.daemonId&&!!((A=e.conversation.coordinator)!=null&&A.meshId||(D=e.conversation.settings)!=null&&D.meshCoordinatorFor),T="text-[color:var(--status-warning)]",P=L=>{if(!i)return;L.preventDefault(),L.stopPropagation();const O=i==null?void 0:i(e.conversation);Promise.resolve(O).catch(_=>{console.warn("[chat-debug-bundle] failed to collect mobile inbox debug bundle",_)})};return s.jsx("div",{className:`group relative overflow-hidden transition-colors active:scale-[0.995] ${p}`,children:s.jsxs("div",{className:"relative flex w-full items-start gap-3.5 px-4 py-3.5 text-left",children:[m||u?s.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,s.jsxs("div",{className:"mobile-inbox-leading-rail flex w-11 shrink-0 flex-col items-center gap-1.5",children:[s.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${w}`,style:m?{color:"var(--accent-on-primary)"}:void 0,children:r(x)}),a&&s.jsxs("button",{type:"button",className:"mobile-inbox-hide-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border border-border-subtle bg-bg-primary/70 px-2 text-[10px] font-semibold text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:L=>{L.preventDefault(),L.stopPropagation(),a()},"aria-label":`Hide ${x}`,title:"Hide conversation",children:[s.jsx(Eo,{size:11}),s.jsx("span",{children:"Hide"})]}),d&&s.jsxs("button",{type:"button",className:`mobile-inbox-mute-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border px-2 text-[10px] font-semibold transition-colors ${c?"border-amber-500/40 bg-amber-500/10 text-amber-300 hover:bg-amber-500/20":"border-border-subtle bg-bg-primary/70 text-text-muted hover:border-border-default hover:text-text-primary"}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),d()},"aria-label":c?`Unmute ${x}`:`Mute ${x}`,title:c?"Unmute (resume notifications)":"Mute notifications",children:[s.jsx(Ar,{size:11}),s.jsx("span",{children:c?"Muted":"Mute"})]}),S&&o&&s.jsxs("button",{type:"button",className:"mobile-inbox-mesh-button inline-flex min-h-7 items-center justify-center gap-1 rounded-full border border-border-subtle bg-bg-primary/70 px-2 text-[10px] font-semibold text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:L=>{L.preventDefault(),L.stopPropagation(),o(e.conversation)},"aria-label":`Open mesh graph for ${x}`,title:"Open live repo mesh graph",children:[s.jsx(Zt,{size:11}),s.jsx("span",{children:"Graph"})]})]}),s.jsxs("button",{className:"relative flex min-w-0 flex-1 flex-col gap-0.5 text-left",onClick:()=>n(e.conversation),onContextMenu:P,type:"button",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:`text-[15px] font-bold truncate tracking-tight ${C}`,children:x}),I&&s.jsx("span",{className:`text-[11px] font-medium shrink-0 ${N}`,children:Kc(e.timestamp)})]}),s.jsxs("div",{className:`text-[12px] font-medium truncate flex items-center ${v}`,children:[s.jsx("span",{className:"truncate",children:k}),s.jsx(On,{git:e.conversation.git,compact:!0,className:"ml-1 max-w-[6.5rem] shrink-0"}),y?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:`${T} animate-pulse`,children:"Reconnecting…"})]}):b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-text-muted",children:"Connecting…"})]}):j==="Action needed"&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:T,children:"Action needed"})]})]}),s.jsx("div",{className:`mt-0.5 truncate text-[13px] ${g}`,children:e.preview})]}),m&&!f&&s.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),f&&s.jsx("span",{className:"absolute top-4 right-4 rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Done"}),u&&s.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]})},e.conversation.tabKey)}function Rl({size:e=32}){return s.jsx("div",{className:"flex flex-col items-center gap-2.5",children:s.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:e,height:e}})})}function qy({section:e,attentionItems:t,unreadItems:r,workingItems:n,completedItems:a,hiddenConversations:o,machineCards:i,getAvatarText:c,actionLogs:d,sendDaemonCommand:m,onOpenConversation:u,onShowAllHidden:h,onHideConversation:f,onOpenMeshGraph:y,onOpenNewSession:b,onOpenMachine:x,onOpenSettings:k,onSectionChange:j,wsStatus:p="connected",isStandalone:w=!1,onCollectChatDebugBundle:C,isConversationMuted:v,onToggleMuteConversation:g}){const[N,I]=l.useState(null),S=p==="disconnected"||p==="reconnecting"||p==="offline"||p==="auth_failed",T=i.length>0,P=t.length>0||r.length>0||n.length>0||a.length>0,A=e==="machines"?"Machines":"Chats",D=w?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",L=w?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]",O=l.useCallback(async $=>{const W=us($);if(!W)return;const B=Array.isArray($.messages)?$.messages:[],F=id({activeConv:$,visibleMessages:B,actionLogs:d,visibleBarControlCount:0,chatTailState:{hasMoreHistory:!1,historyError:null,historyMessages:[]},ui:{controlsVisible:!1,visibleLiveCount:B.length,hiddenLiveCount:0,isInputActive:!1,isVisible:!0}}),K=await m(W,"get_chat_debug_bundle",{...ds($),delivery:"daemon_file",frontendSnapshot:F}),Y=fr(K),re=dd(Y),ae=await cd(re);ae==="failed"&&console.warn("[chat-debug-bundle] failed to copy or present mobile inbox debug bundle locator"),Je.showToast(ld(Y,{locatorCopyStatus:ae}),ae==="failed"?"warning":"success")},[d,m]),_=C||O,M=l.useCallback(()=>{N&&(f==null||f(N),I(null))},[N,f]);return s.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[s.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${D}`,children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:A}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e==="chats"&&(t.length>0||r.length>0)&&s.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[s.jsx(Ar,{size:13}),s.jsx("span",{children:t.length+r.length})]}),s.jsx("button",{onClick:k,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:s.jsx(ea,{size:18})})]})]})}),s.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${L}`,children:[e==="machines"&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:S?s.jsx(or,{icon:s.jsx(Rl,{}),title:p==="offline"?"Network offline":p==="auth_failed"?"Session expired":"Reconnecting",subtitle:p==="offline"?"Waiting for network…":p==="auth_failed"?"Please log in again.":"Restoring the server connection…"}):i.length===0?s.jsx(or,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:w?"Waiting for your daemon":"Connect your machines",subtitle:w?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can launch sessions with any installed provider.":"Install ADHDev on a machine, sign in, and it will show up here.",children:!w&&s.jsx("div",{className:"w-full max-w-[360px] mt-4",children:s.jsx(du,{})})}):s.jsx(Ns,{children:i.map(($,W)=>s.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${W>0?"border-t border-border-subtle/70":""}`,onClick:()=>x($.id),type:"button",children:[s.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:c($.label)}),s.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:$.label}),s.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:$.unread>0?s.jsxs("span",{className:"text-accent-primary",children:[$.unread," new"]}):$.total>0?`${$.total} chats`:"Idle"})]}),s.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:$.subtitle}),$.total>0?s.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[$.total," chat",$.total!==1?"s":"",$.unread>0?` · ${$.unread} unread`:""]}):s.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},$.id))})}),e==="chats"&&t.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Needs attention",className:"mb-0"}),s.jsx(Ns,{children:t.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"needs_attention",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&r.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Task complete",className:"mb-0 mt-2"}),s.jsx(Ns,{children:r.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"task_complete",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&n.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(on,{title:"Working now",className:"mb-0 mt-2"}),s.jsx(Ns,{children:n.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"working",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))})]}),e==="chats"&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[a.length>0&&s.jsx(on,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),a.length>0?s.jsx(Ns,{children:a.map(($,W)=>s.jsx("div",{className:W>0?"border-t border-border-subtle/70":"",children:s.jsx(ln,{item:$,type:"earlier",getAvatarText:c,onOpenConversation:u,onRequestHideConversation:f?()=>I($.conversation):void 0,onOpenMeshGraph:y,onCollectChatDebugBundle:_,isMuted:v==null?void 0:v($.conversation),onToggleMute:g?()=>g($.conversation):void 0})},$.conversation.tabKey))}):P?s.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):S?s.jsx(or,{icon:s.jsx(Rl,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):T?s.jsx(or,{icon:s.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:s.jsx(ws,{size:20})}),title:"No conversations yet",subtitle:Sd,children:b&&s.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex items-center gap-2 mt-4",onClick:b,"aria-label":Ht,title:Ht,children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),s.jsx("span",{children:Ht})]})}):s.jsx(or,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),e==="chats"&&o.length>0&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:s.jsx(Ns,{className:"mt-4 border-dashed bg-bg-secondary/20",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 text-left",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:"Hidden tabs"}),s.jsxs("div",{className:"mt-0.5 text-[13px] text-text-muted",children:[o.length," collapsed ",o.length===1?"conversation":"conversations"]})]}),s.jsx("button",{type:"button",className:"shrink-0 rounded-full border border-border-subtle bg-bg-primary/70 px-3 py-1.5 text-[12px] font-semibold text-accent-primary hover:border-border-default",onClick:h,children:"Restore all"})]})})})]}),e==="chats"&&b&&P&&s.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:b,"aria-label":Ht,title:Ht,children:s.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),N&&s.jsx(Vy,{conversation:N,onCancel:()=>I(null),onConfirm:M}),s.jsx(uu,{section:e,onSectionChange:j})]})}function Yy(e){if(!e)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(e))}catch{return new Date(e).toLocaleString()}}function mu(e){const t=[e.workspace||"Workspace unknown"],r=gs(e.summaryMetadata);r&&t.push(r),(e.messageCount||0)>0&&t.push(`${e.messageCount} msgs`);const n=Yy(e.lastMessageAt);return{title:e.title||e.providerSessionId,providerSessionId:e.providerSessionId,metaLine:t.join(" · "),updatedLabel:n?`Updated ${n}`:"",preview:(e.preview||"").trim()}}function ci({title:e,description:t,currentPath:r,directories:n,busy:a=!1,error:o="",confirmLabel:i="Use this folder",onClose:c,onNavigate:d,onConfirm:m}){const[u,h]=l.useState(r);l.useEffect(()=>{h(r)},[r]);const f=Iy(r),y=u.trim();return s.jsx("div",{className:"fixed inset-0 z-[110] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:s.jsxs("div",{className:"w-full max-w-2xl max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(86vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:c,"aria-label":"Close folder browser",children:s.jsx(xt,{size:16})})]}),s.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!f||a||d(f)},disabled:!f||a,children:[s.jsx(Ro,{size:15}),"Parent"]}),s.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"text",value:u,onChange:b=>h(b.target.value),onKeyDown:b=>{b.key!=="Enter"||!y||a||(b.preventDefault(),d(y))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!y||a||d(y)},disabled:!y||a,children:"Go"})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:a?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?s.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):n.length===0?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):s.jsx("div",{className:"p-3",children:n.map(b=>s.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(b.path),children:[s.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:s.jsx($s,{size:17})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:b.name}),s.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:b.path})]})]},b.path))})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:c,children:"Cancel"}),s.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>m(y||r),disabled:!y&&!r||a,children:i})]})]})})}function hu({title:e,description:t,details:r,workspaceOptions:n,selectedWorkspaceKey:a,onWorkspaceChange:o,confirmLabel:i="Launch",busyLabel:c="Launching…",busy:d=!1,showArgsInput:m,argsValue:u,onArgsChange:h,showModelInput:f,modelValue:y,onModelChange:b,historyProviderNode:x,onConfirm:k,onCancel:j}){const p=n==null?void 0:n.find(w=>w.key===a);return s.jsx("div",{className:"fixed inset-0 z-[110] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:s.jsxs("div",{className:"w-full max-w-lg max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(88vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:j,"aria-label":"Close launch confirmation",children:s.jsx(xt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-5 sm:py-4 flex flex-col gap-3",children:[n&&n.length>0&&o&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),s.jsx("select",{value:a||"",onChange:w=>o(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:n.map(w=>s.jsx("option",{value:w.key,children:w.label},w.key))}),(p==null?void 0:p.description)&&s.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:p.description})]}),x,r.map(w=>s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:w.label}),s.jsx("div",{className:"text-sm text-text-primary break-all",children:w.value})]},`${w.label}:${w.value}`)),f&&b&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Language Model (Optional)"}),s.jsx("input",{type:"text",value:y||"",onChange:w=>b(w.target.value),placeholder:"Auto-detect or default",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]}),m&&h&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"CLI Arguments (Optional)"}),s.jsx("input",{type:"text",value:u||"",onChange:w=>h(w.target.value),placeholder:"e.g. --experimental",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:j,disabled:d,children:"Cancel"}),s.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:k,disabled:d,children:[s.jsx(Ac,{size:14}),d?c:i]})]})]})})}function Dl(e,t){return t||e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||e}function pu(e){const{machine:t,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:a=!0}=e,o=[];a&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const d of t.workspaces||[])o.push({key:`saved:${d.id}`,label:`${d.id===t.defaultWorkspaceId?"⭐ ":""}${Dl(d.path,d.label)}`,description:d.path,workspaceId:d.id,workspacePath:d.path});const i=(r==null?void 0:r.trim())||"",c=i?(t.workspaces||[]).find(d=>d.path===i):null;if(i&&!c&&o.push({key:`custom:${i}`,label:Dl(i),description:i,workspaceId:null,workspacePath:i}),n){const d=`saved:${n}`;if(o.some(m=>m.key===d))return{options:o,selectedKey:d}}return c?{options:o,selectedKey:`saved:${c.id}`}:i?{options:o,selectedKey:`custom:${i}`}:{options:o,selectedKey:"__home__"}}function Xy(e){return e==="ide"?"IDE":e==="cli"?"CLI":"ACP"}function Jy(e){return[Xy(e.kind),e.subtitle||"",e.providerSessionId?"Saved history":""].filter(Boolean).join(" · ")}function Qy(e){return e.lastLaunchedAt?sa(e.lastLaunchedAt):""}function fu(e){return{metaText:Jy(e),updatedLabel:Qy(e)}}function Da(e,t,r){return e?"ide":t>0?"cli":r>0?"acp":null}function Zy({selectedMachineEntry:e,cliProviders:t,acpProviders:r,machineAction:n,onBrowseDirectory:a,onListSavedSessions:o}){var et,ct,Xe,pt;const i=Pr(),[c,d]=l.useState(!1),m=(((et=e.detectedIdes)==null?void 0:et.length)||0)>0,u=l.useMemo(()=>(e.workspaces||[]).map(Ae=>({id:Ae.id,path:Ae.path,label:Ae.label})),[e]),h=e.defaultWorkspaceId||null,[f,y]=l.useState(h||((ct=u[0])==null?void 0:ct.id)||""),[b,x]=l.useState(""),[k,j]=l.useState(""),[p,w]=l.useState([]),[C,v]=l.useState(!1),[g,N]=l.useState(""),[I,S]=l.useState(!1),[T,P]=l.useState(Da(m,t.length,r.length)),A=l.useRef(null),[D,L]=l.useState(null),O=l.useRef("__home__"),[_,M]=l.useState("__home__"),[$,W]=l.useState(""),[B,F]=l.useState(""),[K,Y]=l.useState(""),[re,ae]=l.useState([]),[he,we]=l.useState(()=>jt().textQuery),[Ce,V]=l.useState(()=>jt().workspaceQuery),[q,ue]=l.useState(()=>jt().modelQuery),[me,le]=l.useState(()=>jt().resumableOnly),[je,X]=l.useState(()=>jt().sortMode),[ye,de]=l.useState(!1),[ve,fe]=l.useState(!1),ge=l.useRef(null),ce=l.useRef(null);l.useEffect(()=>{(!e.workspaces||!e.availableProviders||!e.detectedIdes||!e.recentLaunches)&&i(e.id,{minFreshMs:3e4}).catch(()=>{})},[i,e]);const be=f==="__custom__"?b.trim():((Xe=u.find(Ae=>Ae.id===f))==null?void 0:Xe.path)||"",oe=f==="__custom__"&&!!be&&n.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(n.message),R=f!=="__custom__"&&((pt=u.find(Ae=>Ae.id===f))==null?void 0:pt.path)||"",pe=l.useMemo(()=>(e.recentLaunches||[]).map(Ae=>Ae.workspace),[e]),Se=l.useCallback(async Ae=>{v(!0),N("");try{const Fe=await a(Ae);j(Fe.path),x(Fe.path),w(Fe.directories)}catch(Fe){N(Fe instanceof Error?Fe.message:"Could not load folder")}finally{v(!1)}},[a]),Me=l.useCallback(()=>{var Fe;y("__custom__"),S(!0);const Ae=oi(e.platform,ai(b.trim(),R,pe,e.defaultWorkspacePath,(Fe=u.find(st=>st.id===h))==null?void 0:Fe.path,u.map(st=>st.path)));Se(Ae)},[b,h,Se,pe,R,e.platform,u]),ee=l.useCallback(Ae=>{if(Ae!=null&&Ae.workspaceId){y(Ae.workspaceId),x("");return}if(Ae!=null&&Ae.workspacePath){y("__custom__"),x(Ae.workspacePath);return}y(""),x("")},[]),Ne=l.useCallback(Ae=>{if(y(Ae),Ae==="__custom__"){Me();return}x("")},[Me]),De=l.useCallback(Ae=>{y("__custom__"),x(Ae)},[]),Ee=l.useCallback((Ae,Fe)=>{A.current=Fe,O.current=Ae.selectedWorkspaceKey||"__home__",M(Ae.selectedWorkspaceKey||"__home__"),W(Ae.initialArgs||""),F(Ae.initialModel||""),Y(""),ae([]);const st=Ae.providerType?`${e.id}:${Ae.providerType}`:null;if(ub(ce.current,st)){const qe=jt();we(qe.textQuery),V(qe.workspaceQuery),ue(qe.modelQuery),le(qe.resumableOnly),X(qe.sortMode)}ce.current=st,L(Ae),Ae.providerType&&o&&(de(!0),o(Ae.providerType).then(qe=>ae(qe||[])).catch(qe=>console.warn("Failed to load saved sessions",qe)).finally(()=>de(!1)))},[o,e.id]),ze=l.useMemo(()=>Nd(re,{textQuery:he,workspaceQuery:Ce,modelQuery:q,resumableOnly:me,sortMode:je}),[q,me,re,je,he,Ce]);l.useEffect(()=>{K&&(ze.some(Ae=>Ae.providerSessionId===K)||Y(""))},[ze,K]);const Qe=l.useCallback(()=>{A.current&&(fe(!0),A.current().finally(()=>{A.current=null,fe(!1),L(null)}))},[]),Ze=l.useCallback(()=>{A.current=null,L(null)},[]),rt=l.useCallback(Ae=>{O.current=Ae,M(Ae)},[]);return l.useEffect(()=>{var Ae;ge.current!==e.id&&(ge.current=e.id,y(h||((Ae=u[0])==null?void 0:Ae.id)||"__custom__"),x(""),j(""),w([]),N(""),S(!1),we(jt().textQuery),V(jt().workspaceQuery),ue(jt().modelQuery),le(jt().resumableOnly),X(jt().sortMode),ce.current=null,P(Da(m,t.length,r.length)))},[r.length,t.length,h,m,e.id,u]),l.useEffect(()=>{var Ae;f!=="__custom__"&&(f&&u.some(Fe=>Fe.id===f)||y(h||((Ae=u[0])==null?void 0:Ae.id)||"__custom__"))},[h,f,u]),l.useEffect(()=>{T==="ide"&&m||T==="cli"&&t.length>0||T==="acp"&&r.length>0||P(Da(m,t.length,r.length))},[T,r.length,t.length,m]),{showAllRecent:c,setShowAllRecent:d,hasIdeOptions:m,workspaceRows:u,defaultWorkspaceId:h,workspaceChoice:f,customWorkspacePath:b,browseCurrentPath:k,browseDirectories:p,browseBusy:C,browseError:g,browseDialogOpen:I,activeLauncherKind:T,launchConfirm:D,launchConfirmWorkspaceKeyRef:O,launchConfirmWorkspaceKey:_,launchConfirmArgs:$,launchConfirmModel:B,launchConfirmResumeId:K,launchConfirmSavedSessions:re,launchConfirmTextFilter:he,launchConfirmWorkspaceFilter:Ce,launchConfirmModelFilter:q,launchConfirmResumableOnly:me,launchConfirmSortMode:je,filteredLaunchConfirmSavedSessions:ze,launchConfirmSessionsLoading:ye,launchConfirmBusy:ve,resolvedWorkspacePath:be,canCreateMissingWorkspace:oe,openBrowseDialog:Me,loadBrowsePath:Se,handleWorkspaceChoiceChange:Ne,chooseCustomWorkspacePath:De,setCustomWorkspacePath:x,setBrowseDialogOpen:S,setActiveLauncherKind:P,openLaunchConfirm:Ee,handleConfirmLaunch:Qe,closeLaunchConfirm:Ze,setWorkspaceSelectionFromOption:ee,setLaunchConfirmWorkspaceKeyAndSync:rt,setLaunchConfirmArgs:W,setLaunchConfirmModel:F,setLaunchConfirmResumeId:Y,setLaunchConfirmTextFilter:we,setLaunchConfirmWorkspaceFilter:V,setLaunchConfirmModelFilter:ue,setLaunchConfirmResumableOnly:le,setLaunchConfirmSortMode:X}}function e0({selectedMachineEntry:e,selectedMachineConversations:t,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:a,selectedMachineNeedsUpgrade:o,appVersion:i,machineAction:c,isStandalone:d,section:m,showBottomNav:u,onBack:h,onSectionChange:f,onOpenConversation:y,onOpenRecent:b,onOpenMachineDetails:x,onMachineUpgrade:k,onLaunchDetectedIde:j,onAddWorkspace:p,onBrowseDirectory:w,onLaunchWorkspaceProvider:C,onListSavedSessions:v}){const g=_=>_==="ide"?"Workspace":_==="cli"?"CLI":"ACP",N=r.slice(0,4),I=t.slice(0,3),S=Zy({selectedMachineEntry:e,cliProviders:n,acpProviders:a,machineAction:c,onBrowseDirectory:w,onListSavedSessions:v}),T=l.useMemo(()=>N.map(_=>{const{metaText:M,updatedLabel:$}=fu(_);return{key:`recent-launch:${_.id}`,primary:_.label,secondary:M,updatedLabel:$,onClick:()=>{const{options:W,selectedKey:B}=pu({machine:{workspaces:S.workspaceRows,defaultWorkspaceId:S.defaultWorkspaceId},currentWorkspacePath:_.workspace});S.openLaunchConfirm({title:_.kind==="ide"?Hn("restart-ide",_.label):_.providerSessionId?Cd(_.label):Hn("start-fresh",_.label),description:_.kind==="ide"?Wn("restart-ide"):_.providerSessionId?Id():Wn("start-fresh"),confirmLabel:_.kind==="ide"?Kn("restart-ide"):_.providerSessionId?Fn(!0):Kn("start-fresh"),busyLabel:_.kind==="ide"?Un("restart-ide"):_.providerSessionId?Xo(!0):Un("start-fresh"),workspaceOptions:W,selectedWorkspaceKey:B,details:[{label:"Mode",value:g(_.kind)},..._.providerType?[{label:"Provider",value:_.providerType}]:[]]},async()=>{const F=W.find(K=>K.key===S.launchConfirmWorkspaceKeyRef.current);S.setWorkspaceSelectionFromOption(F),await b({..._,workspace:(F==null?void 0:F.workspacePath)??null})})}}}),[S,b,N]),P=l.useMemo(()=>I.map(_=>({key:`recent-chat:${_.conversation.tabKey}`,primary:nt(_.conversation),secondary:Xx(_.conversation,{timestampLabel:_.timestamp?Kc(_.timestamp):null}),unread:_.unread,onClick:()=>y(_.conversation)})),[y,I]),A=S.showAllRecent?T:T.slice(0,4),D=T.length>0,L=P.length>0,O=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`flex items-center justify-between gap-3 ${O} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:h,type:"button","aria-label":"Back",children:s.jsx(Ro,{size:18})}),s.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:Ct(e,{fallbackId:e.id})}),s.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[e.platform||"machine",e.version?` · v${e.version}`:""]})]})]})}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[L&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:P.map(_=>s.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${_.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:_.onClick,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:_.primary}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:_.secondary})]},_.key))})]}),D&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:A.map(_=>s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:_.onClick,children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsx("span",{className:"text-sm font-bold text-text-primary truncate",children:_.primary}),_.updatedLabel&&s.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:_.updatedLabel})]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:_.secondary})]},_.key))}),T.length>4&&s.jsx("div",{className:"flex justify-center px-4 pt-2",children:s.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>S.setShowAllRecent(_=>!_),children:S.showAllRecent?"Show fewer":`Show ${T.length-4} more`})})]}),!1,s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),s.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:k,children:[s.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",i]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:x,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),S.browseDialogOpen&&s.jsx(ci,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:S.browseCurrentPath,directories:S.browseDirectories,busy:S.browseBusy,error:S.browseError,confirmLabel:"Use this folder",onClose:()=>S.setBrowseDialogOpen(!1),onNavigate:_=>{S.loadBrowsePath(_)},onConfirm:_=>{S.chooseCustomWorkspacePath(_),S.setBrowseDialogOpen(!1)}}),S.launchConfirm&&s.jsx(hu,{title:S.launchConfirm.title,description:S.launchConfirm.description,details:S.launchConfirm.details,workspaceOptions:S.launchConfirm.workspaceOptions,selectedWorkspaceKey:S.launchConfirmWorkspaceKey,onWorkspaceChange:S.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:S.launchConfirm.providerType?Fn(!!S.launchConfirmResumeId):S.launchConfirm.confirmLabel,busyLabel:S.launchConfirm.providerType?void 0:S.launchConfirm.busyLabel,busy:S.launchConfirmBusy,showArgsInput:S.launchConfirm.showArgsInput,argsValue:S.launchConfirmArgs,onArgsChange:S.setLaunchConfirmArgs,showModelInput:S.launchConfirm.showModelInput,modelValue:S.launchConfirmModel,onModelChange:S.setLaunchConfirmModel,historyProviderNode:S.launchConfirm.providerType&&(S.launchConfirmSessionsLoading||S.launchConfirmSavedSessions.length>0)&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume saved history"}),S.launchConfirmSessionsLoading&&s.jsx("div",{className:"text-[10px] text-text-secondary font-medium",children:"Loading..."})]}),s.jsx("div",{className:"text-[11px] text-text-secondary mb-2",children:Jo()}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:S.launchConfirmTextFilter,onChange:_=>S.setLaunchConfirmTextFilter(_.target.value),placeholder:"Search title or preview",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:S.launchConfirmWorkspaceFilter,onChange:_=>S.setLaunchConfirmWorkspaceFilter(_.target.value),placeholder:"Filter by workspace",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:S.launchConfirmModelFilter,onChange:_=>S.setLaunchConfirmModelFilter(_.target.value),placeholder:"Filter by model",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),s.jsxs("select",{value:S.launchConfirmSortMode,onChange:_=>S.setLaunchConfirmSortMode(_.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"recent",children:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mb-2 flex items-center gap-2 text-[11px] text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:S.launchConfirmResumableOnly,onChange:_=>S.setLaunchConfirmResumableOnly(_.target.checked),disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading}),"Resume-ready only"]}),s.jsxs("select",{value:S.launchConfirmResumeId,onChange:_=>S.setLaunchConfirmResumeId(_.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:S.launchConfirmBusy||S.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"",children:pb()}),S.filteredLaunchConfirmSavedSessions.map(_=>s.jsxs("option",{value:_.providerSessionId,disabled:!_.canResume,children:[_.title||_.providerSessionId," ",_.canResume?"":"(workspace missing)"]},_.providerSessionId))]}),!S.launchConfirmSessionsLoading&&S.launchConfirmSavedSessions.length>0&&S.filteredLaunchConfirmSavedSessions.length===0&&s.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"No saved history matches these filters."}),S.launchConfirmResumeId&&(()=>{const _=S.filteredLaunchConfirmSavedSessions.find($=>$.providerSessionId===S.launchConfirmResumeId);if(!_)return null;const M=mu(_);return s.jsxs("div",{className:"mt-2 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2.5 text-[11px] text-text-muted leading-relaxed",children:[s.jsx("div",{className:"font-semibold text-text-primary truncate",children:M.title}),s.jsx("div",{className:"font-mono break-all mt-0.5",children:M.providerSessionId}),s.jsx("div",{className:"mt-1",children:M.metaLine}),M.updatedLabel&&s.jsx("div",{className:"mt-1 text-text-secondary",children:M.updatedLabel}),M.preview&&s.jsx("div",{className:"mt-2 line-clamp-2 text-text-secondary",children:M.preview})]})})()]}),onConfirm:S.handleConfirmLaunch,onCancel:S.closeLaunchConfirm}),u&&s.jsx(uu,{section:m,onSectionChange:f})]})}function Sn(e){return[...e].sort((t,r)=>{const n=r.timestamp-t.timestamp;return n!==0?n:t.conversation.tabKey.localeCompare(r.conversation.tabKey)})}function t0(e,t=[]){const r=new Map(e.map(a=>[a.conversation.tabKey,a])),n=t.map(a=>r.get(a)).filter(a=>!!a);return n.length===e.length?n:Sn(e)}function s0(e){var r;const t=((r=e.p2p)==null?void 0:r.state)||"";return t==="connected"?"Connected":t==="connecting"||t==="new"||t==="checking"?"Connecting":"Offline"}function r0(e,t){if(!e)return[];const r=e.recentLaunches||[];return r.length>0?r.map(n=>({id:n.id,label:n.title||n.providerName||n.providerType,kind:n.kind,providerType:n.providerType,providerSessionId:n.providerSessionId,subtitle:gs(n.summaryMetadata)||n.workspace||void 0,workspace:n.workspace,summaryMetadata:n.summaryMetadata})):t.filter(n=>n.type!=="adhdev-daemon"&&n.daemonId===e.id).map(n=>{var i;const a=Sr(n)?"cli":Ls(n)?"acp":"ide",o=gs(n.summaryMetadata);return{id:`${a}:${n.type}:${n.workspace||""}`,label:((i=n.activeChat)==null?void 0:i.title)||(Sr(n)?n.cliName||n.type:Ls(n)&&n.cliName||n.type),kind:a,providerType:n.type,providerSessionId:n.providerSessionId,subtitle:Ls(n)?o||n.workspace||void 0:n.workspace||void 0,workspace:n.workspace||void 0,timestamp:n.lastMessageAt||0}}).sort((n,a)=>a.timestamp-n.timestamp).map(({timestamp:n,...a})=>a)}function n0(e,t){const r=new Map;for(const n of t){const a=js(n.conversation),o=r.get(a);o?o.push(n):r.set(a,[n])}return e.map(n=>{const a=r.get(n.id)||[],o=[...a].sort((h,f)=>f.timestamp-h.timestamp)[0]||null,i=(o==null?void 0:o.conversation)||null,c=mo(n),d=a.filter(h=>h.unread||h.requiresAction).length,m=s0(n),u=[n.platform||"machine",m].filter(Boolean);return{id:n.id,label:Ct(n,{fallbackId:n.id}),subtitle:u.join(" · "),unread:d,total:a.length,latestConversation:i,latestTimestamp:(o==null?void 0:o.timestamp)||0,fallbackActivityAt:c,preview:i?Jx(i):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((n,a)=>{const o=n.latestTimestamp||n.fallbackActivityAt||0,i=a.latestTimestamp||a.fallbackActivityAt||0;return i!==o?i-o:n.label.localeCompare(a.label)})}function a0(e){return e==="chat"}function cn(e,t){var r;if(!(typeof window>"u"))try{if(!(!!((r=import.meta.env)!=null&&r.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${e}`,t)}catch{}}function o0({conversations:e,machineEntries:t,items:r,selectedConversation:n,selectedTabKey:a,screen:o,liveSessionInboxState:i,sendDaemonCommand:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,setSelectedTabKey:b,setScreen:x,setSelectedMachineId:k,setSection:j,setMachineBackTarget:p,resetMachineAction:w}){const C=l.useRef(null),v=l.useCallback(g=>{if(!(g!=null&&g.sessionId))return;const N=Rn(g,i),I=Math.max(Date.now(),fs(g),N.lastUpdated||0);cn("mark_read:start",{tabKey:g.tabKey,sessionId:g.sessionId,displayPrimary:nt(g),inboxBucket:N.inboxBucket,unread:N.unread,lastSeenAt:N.lastSeenAt,lastUpdated:N.lastUpdated,activityAt:fs(g),readAt:I}),c(js(g)||g.routeId,"mark_session_seen",{sessionId:g.sessionId,providerSessionId:g.providerSessionId,seenAt:I,completionMarker:N.completionMarker}).then(S=>{cn("mark_read:result",{tabKey:g.tabKey,sessionId:g.sessionId,result:S})}).catch(S=>{cn("mark_read:error",{tabKey:g.tabKey,sessionId:g.sessionId,error:S instanceof Error?S.message:String(S)})})},[i,c]);return l.useEffect(()=>{var N;if(!n){a0(o)&&x("inbox"),b(((N=e[0])==null?void 0:N.tabKey)||null),C.current=null;return}if(o!=="chat"){C.current=null;return}const g=`${n.tabKey}:${n.sessionId||""}`;C.current!==g&&(C.current=g,v(n))},[e,v,o,n,x,b]),l.useEffect(()=>{if(!d)return;const g=e.find(N=>N.tabKey===d);g&&(b(g.tabKey),x("chat"),m==null||m())},[e,m,d,x,b]),l.useEffect(()=>{if(!u)return;const g=t.find(N=>N.id===u);g&&(k(g.id),w(),j("machines"),p("inbox"),x("machine"),h==null||h())},[t,h,u,w,p,x,j,k]),l.useEffect(()=>{f&&(j(f),x("inbox"),y==null||y())},[y,f,x,j]),l.useEffect(()=>{const g=r.filter(N=>N.inboxBucket==="task_complete"||N.unread);g.length!==0&&cn("inbox_state",{screen:o,selectedTabKey:a,items:g.map(N=>{const I=Rn(N.conversation,i);return{liveState:I,tabKey:N.conversation.tabKey,sessionId:N.conversation.sessionId,displayPrimary:nt(N.conversation),serverBucket:I.inboxBucket,computedBucket:N.inboxBucket,serverUnread:I.unread,computedUnread:N.unread,lastSeenAt:I.lastSeenAt,lastUpdated:I.lastUpdated,activityAt:fs(N.conversation)}})})},[r,i,o,a]),{markConversationRead:v}}function i0(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function El(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function l0(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function c0({sendDaemonCommand:e,navigate:t,ides:r,conversations:n}){const{launchCli:a}=Zn(),[o,i]=l.useState("idle"),[c,d]=l.useState(""),[m,u]=l.useState(null),h=l.useCallback(()=>{i("idle"),d(""),u(null)},[]),f=l.useCallback(async(w,C,v)=>{var g;try{i("loading"),d(`Launching ${C}…`);const N={ideType:C,enableCdp:!0};(g=v==null?void 0:v.workspacePath)!=null&&g.trim()&&(N.workspace=v.workspacePath.trim()),await e(w,"launch_ide",N),i("done"),d(`${C} launch requested`)}catch(N){i("error"),d(N instanceof Error?N.message:"Launch IDE failed"),console.error("Launch IDE failed",N)}},[e]),y=l.useCallback(async(w,C,v)=>{if(C.trim())try{i("loading"),d(v!=null&&v.createIfMissing?"Creating folder…":"Saving workspace…");const g=await e(w,"workspace_add",{path:C.trim(),createIfMissing:(v==null?void 0:v.createIfMissing)===!0});if(g!=null&&g.success){i("done"),d(v!=null&&v.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),d((g==null?void 0:g.error)||"Could not save workspace")}catch(g){i("error"),d(g instanceof Error?g.message:"Could not save workspace")}},[e]),b=l.useCallback(async w=>{var C,v,g,N,I,S;try{i("loading"),d("Starting daemon upgrade…");const T=await e(w,"daemon_upgrade",{});if((C=T==null?void 0:T.result)!=null&&C.alreadyLatest){i("done"),d(`Already on v${((v=T==null?void 0:T.result)==null?void 0:v.version)||"latest"}.`);return}if((g=T==null?void 0:T.result)!=null&&g.upgraded||(N=T==null?void 0:T.result)!=null&&N.success){i("done"),d(`Upgrade to v${((I=T==null?void 0:T.result)==null?void 0:I.version)||"latest"} started. Daemon is restarting…`);return}i("error"),d(((S=T==null?void 0:T.result)==null?void 0:S.error)||"Upgrade failed")}catch(T){i("error"),d(T instanceof Error?T.message:"Upgrade failed")}},[e]),x=l.useCallback(async(w,C,v,g)=>{var S,T,P;const N=Date.now(),I={machineId:w,kind:C,providerType:v,workspaceId:(g==null?void 0:g.workspaceId)||null,workspacePath:(g==null?void 0:g.workspacePath)||null,resumeSessionId:(g==null?void 0:g.resumeSessionId)||null,startedAt:N};try{i("loading"),d(`Launching ${v}…`),u(I);const A={cliType:v};(S=g==null?void 0:g.workspacePath)!=null&&S.trim()?A.dir=g.workspacePath.trim():g!=null&&g.workspaceId&&(A.workspaceId=g.workspaceId),g!=null&&g.resumeSessionId&&(A.resumeSessionId=g.resumeSessionId),(T=g==null?void 0:g.args)!=null&&T.trim()&&(A.cliArgs=g.args.trim().split(/\s+/).filter(Boolean)),(P=g==null?void 0:g.model)!=null&&P.trim()&&(A.initialModel=g.model.trim());const D=await a(w,A),L=(D==null?void 0:D.result)||D,O=(L==null?void 0:L.sessionId)||(L==null?void 0:L.id);if(D!=null&&D.success&&O){u(null),i("done"),d(`${v} launched`),t(Cr(O));return}if(D!=null&&D.success){i("loading"),d(`${v} launch requested — waiting for session…`);return}u(null),i("error"),d((D==null?void 0:D.error)||(L==null?void 0:L.error)||`Could not launch ${C.toUpperCase()} workspace`)}catch(A){if(l0(A)){i("loading"),d(`${v} launch requested — waiting for session…`);return}u(null),i("error"),d(A instanceof Error?A.message:`Could not launch ${C.toUpperCase()} workspace`)}},[t,e]),k=l.useCallback(async(w,C)=>{try{const v=await e(w,"list_saved_sessions",{providerType:C,kind:"cli",limit:30}),g=(v==null?void 0:v.result)??v;return Array.isArray(g==null?void 0:g.sessions)?g.sessions:[]}catch(v){return console.error("Failed to list saved sessions on mobile:",v),[]}},[e]),j=l.useCallback(async(w,C)=>ii(e,w,C),[e]);l.useEffect(()=>{if(!m)return;const w=El(m.workspacePath),C=r.find(g=>{var A,D,L,O;if(!g||g.type==="adhdev-daemon"||i0(g.daemonId||g.id)!==m.machineId||(g.transport==="acp"?"acp":g.transport==="pty"?"cli":null)!==m.kind||String(g.agentType||g.type||"")!==m.providerType)return!1;const T=String(g.providerSessionId||"");if(m.resumeSessionId&&T)return T===m.resumeSessionId;if(w){const _=El(g.workspace||g.runtimeWorkspaceLabel);return _?_===w:!1}return Number(g.lastUpdated||g._lastUpdate||g.timestamp||((O=(L=(D=(A=g.activeChat)==null?void 0:A.messages)==null?void 0:D.at)==null?void 0:L.call(D,-1))==null?void 0:O.timestamp)||0)>=m.startedAt-5e3});if(!C)return;const v=iu({entrySessionId:C.sessionId,entryInstanceId:C.instanceId,entryRouteId:C.id,conversations:n});v&&(u(null),i("done"),d(`${m.providerType} launched`),t(Cr(v)))},[n,r,t,m]),l.useEffect(()=>{if(!m)return;const w=window.setTimeout(()=>{u(C=>!C||C.startedAt!==m.startedAt?C:(i("error"),d("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(w)},[m]);const p=l.useCallback(async(w,C)=>{if(C.kind==="ide"&&C.providerType){await f(w,C.providerType,{workspacePath:C.workspace||null});return}(C.kind==="cli"||C.kind==="acp")&&C.providerType&&await x(w,C.kind,C.providerType,{workspacePath:C.workspace||null,resumeSessionId:C.providerSessionId||null})},[f,x]);return{machineAction:{state:o,message:c},resetMachineAction:h,handleLaunchDetectedIde:f,handleAddWorkspace:y,handleMachineUpgrade:b,handleLaunchWorkspaceProvider:x,handleListSavedSessions:k,handleBrowseDirectory:j,handleOpenRecent:p}}function d0({conversations:e,selectedConversation:t,machineBackTarget:r,markConversationRead:n,resetMachineAction:a,setSelectedTabKey:o,setScreen:i,setSelectedMachineId:c,setSection:d,setMachineBackTarget:m}){const u=l.useCallback(j=>{o(j.tabKey),i("chat"),n(j)},[n,i,o]),h=l.useCallback(j=>{const p=e.find(w=>w.routeId===j.routeId&&w.streamSource==="native");p&&(o(p.tabKey),i("chat"),n(p))},[e,n,i,o]),f=l.useCallback(()=>{n(t),i("inbox")},[n,t,i]),y=l.useCallback((j,p="inbox")=>{c(j),a(),d("machines"),m(p),i("machine")},[a,m,i,d,c]),b=l.useCallback(j=>{const p=js(j);p&&y(p,"chat")},[y]),x=l.useCallback(()=>{a(),i(r)},[r,a,i]),k=l.useCallback(j=>{d(j),i("inbox")},[i,d]);return{openConversation:u,openNativeConversation:h,backFromConversation:f,openMachine:y,openConversationMachine:b,backFromMachine:x,changeMachineSection:k}}function Hs(e,t){return e.category!==t?!1:t==="ide"?!0:e.enabled===!0}function u0(e){const t=e.trim();return t?t[0].toUpperCase():"?"}function m0({conversations:e,hiddenConversations:t,ides:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,userName:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,onOpenHistory:b,onOpenRemote:x,onStopCli:k,wsStatus:j,isConnected:p,onShowAllHiddenConversations:w,onHideConversation:C,onOpenMeshGraph:v,onOpenNewSession:g,liveSessionInboxState:N,setCliViewModeOverrides:I}){const[S,T]=l.useState(()=>{var ee;return((ee=e[0])==null?void 0:ee.tabKey)||null}),[P,A]=l.useState(()=>e[0]?"chat":"inbox"),[D,L]=l.useState("chats"),[O,_]=l.useState(null),[M,$]=l.useState("inbox"),W=l.useRef([]),B=Tr(),F="0.9.82",K=l.useMemo(()=>e.find(ee=>ee.tabKey===S)||e[0]||null,[e,S]),Y=l.useMemo(()=>K?r.find(ee=>ee.id===K.routeId):void 0,[r,K]),re=l.useMemo(()=>!K||Ve(K)||!Ye(K)?null:Us(K),[K]),ae=l.useMemo(()=>r.filter(ee=>ee.type==="adhdev-daemon").sort(Wo),[r]),he=l.useMemo(()=>ae.find(ee=>ee.id===O)||null,[ae,O]),we=aa({sendDaemonCommand:a,activeConv:K||void 0,setActionLogs:o,isStandalone:i}),Ce=c0({sendDaemonCommand:a,navigate:B,ides:r,conversations:e}),V=l.useMemo(()=>e.map(ee=>{const Ne=P==="chat"&&(K==null?void 0:K.tabKey)===ee.tabKey,De=ra(ee,N,{hideOpenTaskCompleteUnread:!0,isOpenConversation:Ne}),Ee=fs(ee),ze=yd(ee);return{conversation:ee,timestamp:Ee,preview:ze,unread:De.unread,requiresAction:De.requiresAction,isWorking:De.isWorking,inboxBucket:De.inboxBucket}}),[e,N,P,K]),{markConversationRead:q}=o0({conversations:e,machineEntries:ae,items:V,selectedConversation:K,selectedTabKey:S,screen:P,liveSessionInboxState:N,sendDaemonCommand:a,requestedActiveTabKey:d,onRequestedActiveTabConsumed:m,requestedMachineId:u,onRequestedMachineConsumed:h,requestedMobileSection:f,onRequestedMobileSectionConsumed:y,setSelectedTabKey:T,setScreen:A,setSelectedMachineId:_,setSection:L,setMachineBackTarget:$,resetMachineAction:Ce.resetMachineAction}),ue=d0({conversations:e,selectedConversation:K,machineBackTarget:M,markConversationRead:q,resetMachineAction:Ce.resetMachineAction,setSelectedTabKey:T,setScreen:A,setSelectedMachineId:_,setSection:L,setMachineBackTarget:$}),{isMuted:me,autoMuteIfCoordinator:le,toggleTarget:je}=Ng();l.useEffect(()=>{if(i)for(const ee of V)le(ee.conversation)},[V,i,le]);const X=l.useMemo(()=>Sn(V.filter(ee=>ee.requiresAction&&!me(ee.conversation))),[V,me]),ye=l.useMemo(()=>Sn(V.filter(ee=>ee.unread&&!ee.requiresAction&&!me(ee.conversation))),[V,me]),de=l.useMemo(()=>t0(V.filter(ee=>!ee.unread&&!ee.requiresAction&&ee.isWorking),W.current),[V]);l.useEffect(()=>{W.current=de.map(ee=>ee.conversation.tabKey)},[de]);const ve=l.useMemo(()=>Sn(V.filter(ee=>!ee.unread&&!ee.requiresAction&&!ee.isWorking)),[V]),fe=l.useMemo(()=>he?V.filter(ee=>js(ee.conversation)===he.id):[],[V,he]),ge=l.useMemo(()=>r0(he,r),[r,he]),ce=(he==null?void 0:he.version)||null,be=!!he&&!!ce&&!0&&ce!==F,oe=l.useMemo(()=>(he==null?void 0:he.availableProviders)||[],[he]),R=l.useMemo(()=>oe.filter(ee=>Hs(ee,"cli")).map(ee=>({type:ee.type,displayName:ee.displayName||ee.type,icon:ee.icon})),[oe]),pe=l.useMemo(()=>oe.filter(ee=>Hs(ee,"acp")).map(ee=>({type:ee.type,displayName:ee.displayName||ee.type,icon:ee.icon})),[oe]),Se=l.useMemo(()=>n0(ae,V),[V,ae]),Me=l.useCallback(async ee=>{he&&await Ce.handleOpenRecent(he.id,ee)},[Ce,he]);return s.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:P==="chat"&&K?s.jsx(zy,{selectedConversation:K,isAcp:Ve(K),isStandalone:i,selectedIdeEntry:Y,actionLogs:n,userName:c,isSendingChat:we.isSendingChat,sendFeedbackMessage:we.sendFeedbackMessage,isFocusingAgent:we.isFocusingAgent,handleModalButton:we.handleModalButton,handleRelaunch:we.handleRelaunch,onBack:ue.backFromConversation,onOpenNativeConversation:ue.openNativeConversation,onOpenMachine:ue.openConversationMachine,onOpenHistory:b,onOpenRemote:x,onOpenMeshGraph:v,onStopCli:k,cliViewMode:re,onSetCliViewMode:async ee=>{await Vd({conversation:K,mode:ee,ides:r,sendDaemonCommand:a,setCliViewModeOverrides:I})},handleSendChat:we.handleSendChat,handleForceSendChat:we.handleForceSendChat,handleFocusAgent:we.handleFocusAgent}):P==="machine"&&he?s.jsx(e0,{selectedMachineEntry:he,selectedMachineConversations:fe,selectedMachineRecentLaunches:ge,cliProviders:R,acpProviders:pe,selectedMachineNeedsUpgrade:be,appVersion:F,machineAction:Ce.machineAction,isStandalone:i,section:D,showBottomNav:M==="inbox",onBack:ue.backFromMachine,onSectionChange:ue.changeMachineSection,onOpenConversation:ue.openConversation,onOpenRecent:Me,onOpenMachineDetails:()=>B(`/machines/${he.id}`),onMachineUpgrade:()=>Ce.handleMachineUpgrade(he.id),onLaunchDetectedIde:(ee,Ne)=>Ce.handleLaunchDetectedIde(he.id,ee,Ne),onAddWorkspace:(ee,Ne)=>Ce.handleAddWorkspace(he.id,ee,Ne),onBrowseDirectory:ee=>Ce.handleBrowseDirectory(he.id,ee),onLaunchWorkspaceProvider:(ee,Ne,De)=>Ce.handleLaunchWorkspaceProvider(he.id,ee,Ne,De),onListSavedSessions:ee=>Ce.handleListSavedSessions(he.id,ee)}):s.jsx(qy,{section:D,attentionItems:X,unreadItems:ye,workingItems:de,completedItems:ve,hiddenConversations:t,machineCards:Se,getAvatarText:u0,actionLogs:n,sendDaemonCommand:a,onOpenConversation:ue.openConversation,onShowAllHidden:w,onHideConversation:C,onOpenMeshGraph:v,onOpenNewSession:g,onOpenMachine:ue.openMachine,onOpenSettings:()=>B("/settings"),onSectionChange:L,wsStatus:j,isConnected:p,isStandalone:i,isConversationMuted:i?me:void 0,onToggleMuteConversation:i?je:void 0})})}function Ea(e,t){return!!(e<4&&t&&window.innerWidth>=768)}function h0({conversations:e,numGroups:t,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:a,onClearPreviewOrder:o}){const i=l.useRef(0),[c,d]=l.useState(!1),[m,u]=l.useState(null),h=l.useCallback(()=>{i.current=0,d(!1),u(null)},[]);l.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const f=l.useCallback(k=>{k.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,d(!0))},[]),y=l.useCallback(k=>{if(!k.dataTransfer.types.includes("text/tab-key"))return;if(k.preventDefault(),!Ea(t,r)){u("merge");return}const j=k.currentTarget.getBoundingClientRect(),p=k.clientX-j.left,w=j.width/3;p<w?u("split-left"):p>w*2?u("split-right"):u("merge")},[t,r]),b=l.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,d(!1),u(null))},[]),x=l.useCallback(k=>{i.current=0,d(!1);const j=k.dataTransfer.getData("text/tab-key"),p=j?e.some(C=>C.tabKey===j):!1,w=m;if(u(null),o(),!!j){if(k.preventDefault(),w==="split-left"&&Ea(t,r)){r==null||r(j,"split-left");return}if(w==="split-right"&&Ea(t,r)){r==null||r(j,"split-right");return}if(p){a(j);return}n==null||n(j)}},[e,m,t,r,n,a,o]);return{dragOver:c,dropAction:m,resetDragState:h,handleDragEnter:f,handleDragOver:y,handleDragLeave:b,handleDrop:x}}function p0(e,t){const r=new Set(t.map(o=>o.tabKey)),n=e.filter(o=>r.has(o)),a=t.filter(o=>!e.includes(o.tabKey)).map(o=>o.tabKey);return[...n,...a]}function f0({conversations:e,initialActiveTabId:t,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:a}){const[o,i]=l.useState(t??null),[c,d]=l.useState(r??[]),[m,u]=l.useState(null),h=l.useRef(null),f=l.useRef(null),y=l.useRef(n),b=l.useRef(a);l.useEffect(()=>{y.current=n},[n]),l.useEffect(()=>{b.current=a},[a]),l.useEffect(()=>{t&&t!==o&&i(t)},[t,o]),l.useEffect(()=>{d(N=>{const I=p0(N,e);return I.length===N.length&&I.every((S,T)=>S===N[T])?N:I})},[e]);const x=l.useMemo(()=>{const N=m??c;if(N.length===0)return e;const I=new Map(N.map((S,T)=>[S,T]));return[...e].sort((S,T)=>{const P=I.get(S.tabKey)??999,A=I.get(T.tabKey)??999;return P-A})},[e,m,c]);l.useEffect(()=>{var I,S;if(x.length===0){o!==null&&(i(null),(I=y.current)==null||I.call(y,null));return}if(o&&x.some(T=>T.tabKey===o))return;const N=x[0].tabKey;N!==o&&(i(N),(S=y.current)==null||S.call(y,N))},[x,o]);const k=l.useMemo(()=>x.find(N=>N.tabKey===o),[x,o]),j=l.useCallback(N=>{var I;i(N),(I=y.current)==null||I.call(y,N)},[]),p=l.useCallback((N,I,S)=>{d(T=>{var L;const P=T.filter(O=>O!==N),A=P.indexOf(I);if(A<0)return T;const D=S==="left"?A:A+1;return P.splice(D,0,N),(L=b.current)==null||L.call(b,P),P}),u(null)},[]),w=l.useCallback((N,I,S)=>{const P=(c.length>0?c:e.map(L=>L.tabKey)).filter(L=>L!==N),A=P.indexOf(I);if(A<0)return;const D=S==="left"?A:A+1;P.splice(D,0,N),h.current=P,u(P)},[c,e]),C=l.useCallback(()=>{var I;const N=h.current;N&&(d(N),(I=b.current)==null||I.call(b,N))},[]),v=l.useCallback(()=>{h.current=null,u(null)},[]),g=l.useCallback(N=>{d(I=>{var T;const S=I.filter(P=>P!==N);return S.push(N),(T=b.current)==null||T.call(b,S),S})},[]);return{activeTabId:o,activeConv:k,sortedConversations:x,previewOrderRef:h,draggingTabRef:f,selectTab:j,handleTabReorder:p,updatePreviewOrder:w,commitPreviewOrder:C,clearPreviewOrder:v,moveTabToEnd:g,setDraggingTabKey:N=>{f.current=N}}}function x0({dropAction:e,canSplit:t}){return s.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),s.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function di({conversationsCount:e,isSplitMode:t,isStandalone:r,hasRegisteredMachines:n=!1,suppressGuide:a=!1,onOpenNewSession:o}){if(a)return s.jsx("div",{className:"text-sm text-text-muted opacity-0 select-none","aria-hidden":"true",children:"No active agent"});const i=!r&&!n,c=n&&!!o,d=n?"No conversations yet":r?"Waiting for your daemon":"Connect your machines",m=n?Sd:r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can launch sessions with any installed provider.":"Install ADHDev on a machine, sign in, and it will show up here.";return e===0&&!t?s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[s.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),s.jsxs("div",{className:"text-center max-w-lg",children:[s.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:d}),s.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:m}),c&&s.jsx("div",{className:"flex items-center justify-center mb-4",children:s.jsxs("button",{type:"button",onClick:o,className:"btn btn-secondary btn-sm inline-flex items-center gap-2",title:Ht,"aria-label":Ht,children:[s.jsx(_c,{size:14}),s.jsx("span",{children:Ht})]})}),i&&s.jsx(du,{}),i&&s.jsx("div",{className:"mt-8",children:s.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):s.jsx("div",{className:"text-sm text-text-muted opacity-50",children:t?"Move a tab here to view":"No active agent"})}const xu="adhdev-tab-shortcuts";function bu(){try{return JSON.parse(localStorage.getItem(xu)||"{}")}catch{return{}}}function gu({enabled:e=!0,sortedTabKeys:t,onFocus:r,onSelectTab:n}){const a=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,i]=l.useState(()=>bu()),[c,d]=l.useState(null),m=l.useCallback(h=>{const f=[];return h.metaKey&&f.push(a?"⌘":"Meta"),h.ctrlKey&&f.push("Ctrl"),h.altKey&&f.push(a?"⌥":"Alt"),h.shiftKey&&f.push(a?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(h.key)?null:(f.push(h.key.length===1?h.key.toUpperCase():h.key),f.join("+"))},[a]),u=l.useCallback(h=>{i(h);try{localStorage.setItem(xu,JSON.stringify(h))}catch{}},[]);return l.useEffect(()=>{if(!e||!c)return;const h=f=>{if(f.preventDefault(),f.stopPropagation(),f.key==="Escape"){d(null);return}const y=m(f);if(!y)return;const b={...o};for(const[x,k]of Object.entries(b))k===y&&delete b[x];b[c]=y,u(b),d(null)};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[e,c,o,u,m]),l.useEffect(()=>{if(!e)return;const h=f=>{if(!(!f.ctrlKey&&!f.metaKey&&!f.altKey)){for(const[y,b]of Object.entries(o))if(t.includes(y)&&m(f)===b){f.preventDefault(),r(),n(y);return}}};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[e,o,t,r,n,m]),{isMac:a,tabShortcuts:o,shortcutListening:c,setShortcutListening:d,saveShortcuts:u}}const $a=e=>{e.preventDefault()},b0=l.memo(function({conv:t,isActive:r,isDraggedTab:n,isTaskCompleteUnread:a,shortcut:o,conversationKeys:i,draggingTabRef:c,onFocus:d,onSelectTab:m,onConversationActivated:u,onPreviewReorder:h,onReorderTab:f,onCommitPreviewOrder:y,onClearPreviewOrder:b,onDragStateReset:x,onDragTabKeyChange:k,onReceiveTab:j,onOpenContextMenu:p,longPressTimer:w,isGroupActive:C}){const v=Ks(t),g=v.isGenerating?"agent-tab-generating":v.isWaiting?"agent-tab-waiting":"",N=v.isReconnecting,I=l.useCallback(M=>{c.current=t.tabKey,k(t.tabKey),M.dataTransfer.setData("text/tab-key",t.tabKey),M.dataTransfer.effectAllowed="move"},[t.tabKey,c,k]),S=l.useCallback(()=>{c.current=null,k(null),y(),b(),x()},[c,k,y,b,x]),T=l.useCallback(M=>{const $=c.current;if(!(!$||$===t.tabKey)&&M.dataTransfer.types.includes("text/tab-key")){M.preventDefault(),M.stopPropagation();const W=M.currentTarget.getBoundingClientRect(),B=M.clientX<W.left+W.width/2?"left":"right";h($,t.tabKey,B)}},[t.tabKey,c,h]),P=l.useCallback(M=>{M.preventDefault(),M.stopPropagation();const $=M.dataTransfer.getData("text/tab-key");if($&&$!==t.tabKey){const W=M.currentTarget.getBoundingClientRect(),B=M.clientX<W.left+W.width/2?"left":"right";i.includes($)?f($,t.tabKey,B):j&&j($)}b()},[t.tabKey,i,f,j,b]),A=l.useCallback(M=>{M.stopPropagation(),d(),m(t.tabKey),u(t)},[t,u,d,m]),D=l.useCallback(M=>{M.preventDefault(),p(M.clientX,M.clientY,t.tabKey)},[t.tabKey,p]),L=l.useCallback(M=>{const $=M.touches[0];w.current=setTimeout(()=>{p($.clientX,$.clientY,t.tabKey)},600)},[t.tabKey,w,p]),O=l.useCallback(()=>{w.current&&clearTimeout(w.current)},[w]),_=["adhdev-dockview-tab",g,r&&"is-active",C&&"is-group-active",N&&"is-reconnecting"].filter(Boolean).join(" ");return s.jsxs("div",{"data-tabkey":t.tabKey,className:_,draggable:!0,onDragStart:I,onDragEnd:S,onDragOver:T,onDrop:P,onClick:A,onContextMenu:D,onTouchStart:L,onTouchEnd:O,onTouchMove:O,style:{cursor:"pointer",opacity:n?.4:void 0},children:[a&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status",children:v.isGenerating?s.jsx("div",{className:"tab-spinner"}):v.isWaiting?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):N?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):v.isConnecting?s.jsx("div",{className:"tab-connecting-spinner"}):t.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("span",{className:"adhdev-dockview-tab-primary",title:nt(t),children:nt(t)}),s.jsxs("span",{className:"adhdev-dockview-tab-meta inline-flex min-w-0 items-center gap-1",children:[N?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting truncate",children:ms(t)}):v.isConnecting?s.jsxs("span",{className:"adhdev-dockview-tab-connecting truncate",children:[ms(t),s.jsx("span",{className:"connecting-dots"})]}):s.jsx("span",{className:"truncate",children:ms(t)}),s.jsx(On,{git:t.git,compact:!0,className:"max-w-[6.5rem] shrink-0"})]})]}),o&&s.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(e,t)=>e.conv===t.conv&&e.isActive===t.isActive&&e.isDraggedTab===t.isDraggedTab&&e.isTaskCompleteUnread===t.isTaskCompleteUnread&&e.shortcut===t.shortcut&&e.conversationKeys===t.conversationKeys&&e.isGroupActive===t.isGroupActive);function g0({conversations:e,activeTabId:t,groupIndex:r,unreadTabKeys:n,draggingTabRef:a,onFocus:o,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:m,onCommitPreviewOrder:u,onClearPreviewOrder:h,onDragStateReset:f,onDragTabKeyChange:y,onReceiveTab:b,onHideTab:x,isGroupActive:k,allowTabShortcuts:j=!0}){const[p,w]=l.useState(null),C=l.useRef(null),v=l.useRef(null),g=l.useMemo(()=>e.map(D=>D.tabKey),[e]);_r("PaneGroupTabBar",{groupIndex:r,activeTabId:t,tabCount:e.length,ctxMenuTab:(p==null?void 0:p.tabKey)||null});const{isMac:N,tabShortcuts:I,shortcutListening:S,setShortcutListening:T,saveShortcuts:P}=gu({enabled:j,sortedTabKeys:e.map(D=>D.tabKey),onFocus:o,onSelectTab:i});l.useEffect(()=>{if(!p)return;const D=L=>{const O=document.querySelector("[data-pane-context-menu]");O&&O.contains(L.target)||w(null)};return window.addEventListener("mousedown",D,!0),()=>window.removeEventListener("mousedown",D,!0)},[p]),l.useEffect(()=>{const D=v.current;if(!D)return;const L=O=>{Math.abs(O.deltaY)<=Math.abs(O.deltaX)||(O.preventDefault(),D.scrollLeft+=O.deltaY)};return D.addEventListener("wheel",L,{passive:!1}),()=>D.removeEventListener("wheel",L)},[]);const A=l.useCallback((D,L,O)=>{w({x:D,y:L,tabKey:O})},[]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:s.jsxs("div",{ref:v,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none",overscrollBehaviorX:"contain"},children:[e.map(D=>s.jsx(b0,{conv:D,isActive:t===D.tabKey,isDraggedTab:a.current===D.tabKey,isTaskCompleteUnread:n.has(D.tabKey),shortcut:j?I[D.tabKey]:void 0,conversationKeys:g,draggingTabRef:a,onFocus:o,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:m,onCommitPreviewOrder:u,onClearPreviewOrder:h,onDragStateReset:f,onDragTabKeyChange:y,onReceiveTab:b,onOpenContextMenu:A,longPressTimer:C,isGroupActive:k},D.tabKey)),e.length===0&&s.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),p&&s.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:p.x,top:p.y},children:[j&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onMouseDown:$a,onClick:D=>{D.stopPropagation(),T(p.tabKey),w(null)},children:["⌨ ",I[p.tabKey]?`Change shortcut (${I[p.tabKey]})`:"Set shortcut"]}),I[p.tabKey]&&s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onMouseDown:$a,onClick:()=>{const D={...I};delete D[p.tabKey],P(D),w(null)},children:"✕ Remove shortcut"})]}),x&&s.jsxs(s.Fragment,{children:[j&&s.jsx("div",{className:"border-t border-border-subtle my-1"}),s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onMouseDown:$a,onClick:()=>{x(p.tabKey),w(null)},children:"🚫 Hide from Dashboard"})]})]}),j&&S&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>T(null),children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:D=>D.stopPropagation(),children:[s.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),s.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),s.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),s.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function y0({conversations:e,ides:t,clearedTabs:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,hasRegisteredMachines:c,userName:d,groupIndex:m,onFocus:u,isSplitMode:h,numGroups:f,onMoveTab:y,onReceiveTab:b,style:x,onActiveTabChange:k,initialActiveTabId:j,initialTabOrder:p,onTabOrderChange:w,onHideTab:C,isFocused:v,allowTabShortcuts:g=!0,onOpenNewSession:N,liveSessionInboxState:I}){const{sendCommand:S}=it(),T=l.useRef(null),{activeTabId:P,activeConv:A,sortedConversations:D,draggingTabRef:L,selectTab:O,handleTabReorder:_,updatePreviewOrder:M,commitPreviewOrder:$,clearPreviewOrder:W,moveTabToEnd:B,setDraggingTabKey:F}=f0({conversations:e,initialActiveTabId:j,initialTabOrder:p,onActiveTabChange:k,onTabOrderChange:w}),K=aa({sendDaemonCommand:a,activeConv:A,setActionLogs:o,isStandalone:i}),{dragOver:Y,dropAction:re,resetDragState:ae,handleDragEnter:he,handleDragOver:we,handleDragLeave:Ce,handleDrop:V}=h0({conversations:e,numGroups:f,onMoveTab:y,onReceiveTab:b,onOwnTabDrop:B,onClearPreviewOrder:W}),q=A&&!Ve(A)&&Us(A)==="terminal",ue=l.useMemo(()=>A?t.find(X=>X.id===A.routeId):void 0,[t,A]),me=l.useMemo(()=>A?n.filter(X=>X.routeId===A.tabKey):[],[n,A]),le=l.useMemo(()=>new Set(D.filter(X=>Tp(X,I,{isOpenConversation:X.tabKey===P})).map(X=>X.tabKey)),[P,I,D]);_r("PaneGroup",{groupIndex:m,conversationCount:e.length,activeTabId:P,dragOver:Y});const je=l.useCallback(X=>{X.streamSource==="agent-stream"&&X.agentType&&S(X.routeId,od(),{agentType:X.agentType,...X.sessionId&&{targetSessionId:X.sessionId}}).catch(()=>{})},[S]);return s.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...x,outline:Y?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[s.jsx(g0,{conversations:D,activeTabId:P,groupIndex:m,numGroups:f,unreadTabKeys:le,draggingTabRef:L,onFocus:u,onSelectTab:O,onConversationActivated:je,onPreviewReorder:M,onReorderTab:_,onCommitPreviewOrder:$,onClearPreviewOrder:W,onDragStateReset:ae,onDragTabKeyChange:F,onMoveTab:y,onReceiveTab:b,onHideTab:C,isGroupActive:v??!1,allowTabShortcuts:g}),s.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:he,onDragOver:we,onDragLeave:Ce,onDrop:V,children:[Y&&s.jsx(x0,{dropAction:re,canSplit:!!(f<4&&y)}),A?s.jsx(li,{activeConv:A,clearToken:r[A.tabKey]||0,isCliTerminal:!!q,ideEntry:ue,terminalRef:T,handleModalButton:K.handleModalButton,handleRelaunch:K.handleRelaunch,handleSendChat:K.handleSendChat,handleForceSendChat:K.handleForceSendChat,isSendingChat:K.isSendingChat,sendFeedbackMessage:K.sendFeedbackMessage,handleFocusAgent:K.handleFocusAgent,isFocusingAgent:K.isFocusingAgent,actionLogs:me,userName:d,isInputActive:!h||!!v}):s.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:s.jsx(di,{conversationsCount:e.length,isSplitMode:h,isStandalone:i,hasRegisteredMachines:c,onOpenNewSession:N})})]})]})}function v0({containerRef:e,isSplitMode:t,numGroups:r,groupSizes:n,groupedConvs:a,clearedTabs:o,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:m,isStandalone:u,hasRegisteredMachines:h,userName:f,focusedGroup:y,focusGroup:b,moveTabToGroup:x,splitTabRelative:k,closeGroup:j,handleResizeStart:p,groupActiveTabIds:w,setGroupActiveTab:C,groupTabOrders:v,setGroupTabOrder:g,toggleHiddenTab:N,onOpenNewSession:I,allowTabShortcuts:S=!0,liveSessionInboxState:T}){return s.jsx("div",{ref:e,className:`flex-1 min-h-0 flex ${t?"flex-row":"flex-col"} overflow-hidden`,children:a.map((P,A)=>{const D=t&&n.length===r?`${n[A]}%`:void 0;return s.jsxs(ft.Fragment,{children:[t&&A>0&&s.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:L=>p(A-1,L),onDoubleClick:()=>j(A),title:"Drag to resize · Double-click to merge",children:s.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),s.jsx(y0,{style:t?{flexBasis:D??`${100/r}%`,flexGrow:D?0:1,flexShrink:D?0:1}:void 0,conversations:P,clearedTabs:o,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:m,isStandalone:u,hasRegisteredMachines:h,userName:f,groupIndex:A,isFocused:t&&y===A,onFocus:()=>b(A),isSplitMode:t,numGroups:r,onMoveTab:(L,O)=>{O==="left"&&A>0?x(L,A-1):O==="right"&&A<r-1?x(L,A+1):O==="split-left"&&r<4?k(L,A,"left"):O==="split-right"&&r<4&&k(L,A,"right")},onReceiveTab:L=>x(L,A),onActiveTabChange:L=>C(A,L),initialActiveTabId:w[A],initialTabOrder:v[A],onTabOrderChange:L=>g(A,L),onHideTab:N,onOpenNewSession:I,allowTabShortcuts:S,liveSessionInboxState:T})]},A)})})}function yu({doId:e,targetSessionId:t,connState:r,viewMode:n}){const[a,o]=l.useState(null),[i,c]=l.useState(null);l.useEffect(()=>e?at.onScreenshot("ide-page",(u,h)=>{if(u!==e)return;const f=new FileReader;f.onload=()=>o(f.result),f.readAsDataURL(h)}):void 0,[e]),l.useEffect(()=>{r!=="connected"&&o(null)},[r]),l.useEffect(()=>{var u;return e?((u=at.onStatus)==null?void 0:u.call(at,(h,f)=>{h===e&&f!=null&&f.screenshotUsage&&c(f.screenshotUsage)}))||(()=>{}):void 0},[e]),l.useEffect(()=>{o(null)},[e,t]),l.useEffect(()=>{const m=e?at.get(e):null;if(!(!m||r!=="connected"))return n!=="chat"&&t?m.startScreenshots(t):m.stopScreenshots(t),()=>{m.stopScreenshots(t)}},[n,r,t,e]);const d=l.useCallback(async(m,u)=>{const h=e?at.get(e):null;return!h||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):h.sendInput(m,u,t)},[e,r,t]);return{connScreenshot:a,screenshotUsage:i,handleRemoteAction:d}}const vu="adhdev-dashboard-action-shortcuts",w0=1200,j0=[["toggleHiddenTabs","G H"],["openNewSession","N"],["setActiveTabShortcut","G S"],["selectPreviousGroupTab","G K"],["selectPreviousGroupTab","T ←"],["selectPreviousGroupTab","⌥+["],["selectPreviousGroupTab","Ctrl+Alt+["],["selectNextGroupTab","G J"],["selectNextGroupTab","T →"],["selectNextGroupTab","⌥+]"],["selectNextGroupTab","Ctrl+Alt+]"],["splitActiveTabDown","S ↓"],["splitActiveTabDown","⌘+⌥+-"],["splitActiveTabDown","Ctrl+Alt+-"],["splitActiveTabRight","S →"],["splitActiveTabRight","⌘+⌥+\\"],["splitActiveTabRight","⌘+⌥+="],["splitActiveTabRight","Ctrl+Alt+\\"],["focusLeftPane","F ←"],["focusLeftPane","⌘+⌥+←"],["focusLeftPane","⌘+⌥+["],["focusLeftPane","Ctrl+Alt+←"],["focusRightPane","F →"],["focusRightPane","⌘+⌥+→"],["focusRightPane","⌘+⌥+]"],["focusRightPane","Ctrl+Alt+→"],["focusUpPane","F ↑"],["focusUpPane","⌘+⌥+U"],["focusUpPane","Ctrl+Alt+↑"],["focusDownPane","F ↓"],["focusDownPane","⌘+⌥+J"],["focusDownPane","Ctrl+Alt+↓"],["moveActiveTabToLeftPane","M ←"],["moveActiveTabToLeftPane","⌘+⌥+⇧+←"],["moveActiveTabToLeftPane","⌘+⌥+,"],["moveActiveTabToLeftPane","Ctrl+Alt+Shift+←"],["moveActiveTabToRightPane","M →"],["moveActiveTabToRightPane","⌘+⌥+⇧+→"],["moveActiveTabToRightPane","⌘+⌥+."],["moveActiveTabToRightPane","Ctrl+Alt+Shift+→"],["moveActiveTabToUpPane","M ↑"],["moveActiveTabToUpPane","⌘+⌥+I"],["moveActiveTabToUpPane","Ctrl+Alt+Shift+↑"],["moveActiveTabToDownPane","M ↓"],["moveActiveTabToDownPane","⌘+⌥+K"],["moveActiveTabToDownPane","Ctrl+Alt+Shift+↓"],["triggerPrimaryApprovalAction","⌥+A"],["triggerSecondaryApprovalAction","⌥+D"],["toggleCliView","T"]];function k0(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function tt(e,t){switch(e){case"openShortcutHelp":return"?";case"openNewSession":return t?"⌘+⇧+Enter":"Ctrl+Shift+Enter";case"hideCurrentTab":return t?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return t?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return t?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return t?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return t?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return t?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return t?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return t?"⌘+Ctrl+⇧+→":"Ctrl+Alt+Shift+→";case"splitActiveTabDown":return t?"⌘+Ctrl+⇧+↓":"Ctrl+Alt+Shift+↓";case"focusLeftPane":return"";case"focusRightPane":return"";case"focusUpPane":return"";case"focusDownPane":return"";case"moveActiveTabToLeftPane":return"";case"moveActiveTabToRightPane":return"";case"moveActiveTabToUpPane":return"";case"moveActiveTabToDownPane":return"";case"triggerPrimaryApprovalAction":return t?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return t?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return t?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return t?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return t?"⌘+⇧+←":"Ctrl+Shift+←";case"selectNextGroupTab":return t?"⌘+⇧+→":"Ctrl+Shift+→";case"toggleCliView":return t?"⌥+T":"Ctrl+Alt+T"}}function wu(e){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:tt("openShortcutHelp",e)},{id:"openNewSession",label:"New session",description:"Open the new session launcher.",defaultShortcut:tt("openNewSession",e)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:tt("hideCurrentTab",e)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:tt("toggleHiddenTabs",e)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:tt("openHistoryForActiveTab",e)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:tt("openRemoteForActiveTab",e)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:tt("floatActiveTab",e)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:tt("popoutActiveTab",e)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:tt("dockActiveTab",e)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:tt("splitActiveTabRight",e)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:tt("splitActiveTabDown",e)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:tt("focusLeftPane",e)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:tt("focusRightPane",e)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:tt("focusUpPane",e)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:tt("focusDownPane",e)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:tt("moveActiveTabToLeftPane",e)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:tt("moveActiveTabToRightPane",e)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:tt("moveActiveTabToUpPane",e)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:tt("moveActiveTabToDownPane",e)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:tt("triggerPrimaryApprovalAction",e)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:tt("triggerSecondaryApprovalAction",e)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:tt("triggerTertiaryApprovalAction",e)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:tt("setActiveTabShortcut",e)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:tt("selectPreviousGroupTab",e)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:tt("selectNextGroupTab",e)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:tt("toggleCliView",e)}]}function Io(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"}function Yn(e){const t=Object.fromEntries(wu(e).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(vu)||"{}"),n={...t,...r};for(const[a,o]of j0)n[a]===o&&(n[a]=t[a]);return n}catch{return t}}function ju(e){return e===" "?"Space":e==="Escape"?"Esc":e==="ArrowLeft"?"←":e==="ArrowRight"?"→":e==="ArrowUp"?"↑":e==="ArrowDown"?"↓":e.length===1?e.toUpperCase():e}function S0({enabled:e=!0,onTrigger:t}){const r=k0(),[n,a]=l.useState(()=>Yn(r)),[o,i]=l.useState(null),[c,d]=l.useState([]),m=l.useRef({parts:[],timer:null}),u=l.useCallback(x=>{const k=[];return x.metaKey&&k.push(r?"⌘":"Meta"),x.ctrlKey&&k.push("Ctrl"),x.altKey&&k.push(r?"⌥":"Alt"),x.shiftKey&&x.key.length!==1&&k.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(x.key)?null:(k.push(ju(x.key)),k.join("+"))},[r]),h=l.useCallback(x=>{a(x);try{localStorage.setItem(vu,JSON.stringify(x))}catch{}},[]);l.useEffect(()=>{const x=Yn(r),k=Object.entries(n),j=Object.entries(x);k.length===j.length&&k.every(([p,w])=>x[p]===w)||h(x)},[n,r,h]);const f=l.useCallback(()=>{typeof window<"u"&&m.current.timer!=null&&window.clearTimeout(m.current.timer),m.current={parts:[],timer:null}},[]),y=l.useCallback(()=>{typeof window>"u"||(m.current.timer!=null&&window.clearTimeout(m.current.timer),m.current.timer=window.setTimeout(()=>{m.current={parts:[],timer:null}},w0))},[]);l.useEffect(()=>{if(!o)return;const x=k=>{if(k.preventDefault(),k.stopPropagation(),k.key==="Escape"){i(null),d([]);return}const j=u(k);if(!j)return;const w=!(k.metaKey||k.ctrlKey||k.altKey)&&/^[A-Z0-9]$/.test(j);if(c.length===0&&w){d([j]);return}const v=[...c,j].slice(0,2).join(" "),g={...n};for(const[N,I]of Object.entries(g))I===v&&delete g[N];g[o]=v,h(g),i(null),d([])};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[n,u,h,o,c]),l.useEffect(()=>{if(!e||o)return;const x=k=>{if(k.defaultPrevented)return;const j=u(k);if(!j)return;const p=k.metaKey||k.ctrlKey||k.altKey;if(Io(k.target))return;const w=m.current.parts,C=p?[j]:[...w.slice(-1),j].slice(-2),v=C.join(" "),g=C[C.length-1],N=Object.entries(n).filter(([,A])=>!!A),I=N.find(([,A])=>A===v);if(I){k.preventDefault(),f(),t(I[0]);return}if(N.some(([,A])=>A.startsWith(`${v} `))){k.preventDefault(),m.current.parts=C,y();return}const T=N.find(([,A])=>A===g);if(T){k.preventDefault(),f(),t(T[0]);return}if(N.some(([,A])=>A.startsWith(`${g} `))){k.preventDefault(),m.current.parts=[g],y();return}f()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[n,y,e,u,t,f,o]),l.useEffect(()=>()=>f(),[f]);const b=l.useMemo(()=>wu(r),[r]);return{isMac:r,actionDefinitions:b,actionShortcuts:n,shortcutListening:o,shortcutListeningDraft:c,setShortcutListening:i,setShortcutListeningDraft:d,saveShortcuts:h}}function N0({isTabInPopout:e,isTabFloating:t,tabShortcut:r,actionShortcuts:n}){const a=[];return e?(t&&a.push({type:"action",id:"dockInWindow",label:"Dock in window",shortcut:n.dockActiveTab}),a.push({type:"action",id:"moveBackToMain",label:"Move back to main window",shortcut:n.dockActiveTab})):t?a.push({type:"action",id:"dockBackToGrid",label:"Dock back to grid",shortcut:n.dockActiveTab}):a.push({type:"action",id:"floatAsPanel",label:"Float as panel",shortcut:n.floatActiveTab},{type:"action",id:"openInNewWindow",label:"Open in new window",shortcut:n.popoutActiveTab}),a.push({type:"separator",id:"before-shortcut-actions"},{type:"action",id:"setShortcut",label:r?`Change shortcut (${r})`:"Set shortcut",shortcut:n.setActiveTabShortcut}),r&&a.push({type:"action",id:"removeShortcut",label:"Remove shortcut",tone:"muted"}),a.push({type:"separator",id:"before-hide-tab"},{type:"action",id:"hideTab",label:"Hide tab",shortcut:n.hideCurrentTab,tone:"muted"}),a}function ku(e){return e.some(t=>t.type!=="adhdev-daemon")||e.some(t=>t.type==="adhdev-daemon"&&!!t.machine)}function $l({hasStoredLayout:e,initialDataLoaded:t,visibleConversationCount:r,ides:n}){return!e||r>0?!1:t?!ku(n):!0}function C0({previousVisibleConversationCount:e,visibleConversationCount:t,ides:r}){return t>0||e<=0?!1:ku(r)}const Su=1e3,I0=4;function Bl(e,t){return t?e.clientX>=t.left&&e.clientX<=t.right&&e.clientY>=t.top&&e.clientY<=t.bottom:!1}function Ol(e,t,r){return Math.abs(t.clientX-e.clientX)>r||Math.abs(t.clientY-e.clientY)>r}function M0({detachDelayMs:e=Su,stillnessThresholdPx:t=I0,onDetach:r,setTimeoutFn:n=globalThis.setTimeout.bind(globalThis),clearTimeoutFn:a=globalThis.clearTimeout.bind(globalThis)}){let o=null,i=null,c=null,d=null,m=null,u=!1;const h=()=>{m!=null&&(a(m),m=null)},f=()=>{h(),c=null},y=()=>{h(),o=null,i=null,c=null,d=null,u=!1},b=()=>{!o||!c||!d||u||m!=null||(m=n(()=>{m=null,!(!o||!c||!d||u)&&Bl(d,i)&&(Ol(c,d,t)||(u=!0,r({panelId:o,clientX:d.clientX,clientY:d.clientY})))},e))},x=j=>{if(!(!o||u)){if(!Bl(j,i)){d={clientX:j.clientX,clientY:j.clientY},f();return}(!c||Ol(c,j,t))&&(h(),c={clientX:j.clientX,clientY:j.clientY}),d={clientX:j.clientX,clientY:j.clientY},b()}},k=j=>{!o||u||(j&&(d={clientX:j.clientX,clientY:j.clientY}),f())};return{startDrag:j=>{h(),o=j.panelId,i=j.selfPanelBounds??null,c=null,d={clientX:j.clientX,clientY:j.clientY},u=!1},markSelfPanel:x,markNonSelfPanel:k,markNoDropTarget:k,markDockTarget:k,endDrag:y,isDragging:()=>o!=null,hasDetached:()=>u,dispose:y}}function T0(e=typeof window>"u"?null:window.localStorage){return(e==null?void 0:e.getItem("adhdev:dockviewIdleDragFloat"))!=="off"}function dn(e){return e.isActive}function Fl(e){return e.isVisible}const Nu=l.createContext(null);function la(){const e=l.useContext(Nu);if(!e)throw new Error("DashboardDockviewContext missing");return e}function Nn(e){return nt(e)||e.tabKey}function A0(e){return`remote:${e}`}function Rt(e){return e.startsWith("remote:")}function Hl(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _0(e){e.preventDefault()}function Ba(e){var n;const t=e==null?void 0:e.defaultView;if(!t)return;const r=a=>{if(a)try{a.focus({preventScroll:!0})}catch{try{a.focus()}catch{}}};try{t.focus(),r(e==null?void 0:e.body),r(e==null?void 0:e.documentElement),(n=t.requestAnimationFrame)==null||n.call(t,()=>{try{t.focus(),r(e==null?void 0:e.body)}catch{}})}catch{}}function Oa(e,t){e.classList.remove(ro.className,no.className),e.classList.add(t==="light"?ro.className:no.className)}function Wl(e){return e?Array.from(new Set(e.groups.map(t=>{var r,n;return(n=(r=t.element)==null?void 0:r.ownerDocument)==null?void 0:n.defaultView}).filter(t=>!!t&&t!==window))):[]}function L0(e){const[,t]=l.useState(0);l.useEffect(()=>{const r=()=>t(a=>a+1),n=[e.api.onDidActiveGroupChange(r),e.api.onDidTitleChange(r),e.api.onDidGroupChange(r),e.containerApi.onDidActivePanelChange(r)];return()=>{for(const a of n)a.dispose()}},[e.api,e.containerApi])}function P0(e,t,r){var i;const n=[t];let a;for(const c of n){let d;for(const m of c){const u=e.addPanel({id:m.tabKey,component:"conversation",title:Nn(m),params:{kind:"conversation",tabKey:m.tabKey},...d?{position:{referencePanel:d,direction:"within"},inactive:!0}:a?{position:{referencePanel:a,direction:"right"},inactive:!0}:{}});d||(d=u.id)}a=d??a}return r??((i=t[0])==null?void 0:i.tabKey)??null}function Kl(e,t){const r=new Set(t.map(a=>a.tabKey)),n=new Map;for(const a of t)n.set(a.tabKey,(n.get(a.tabKey)||0)+1);for(const a of[...e.panels])Rt(a.id)||r.has(a.id)||e.removePanel(a);for(const a of t){const o=e.getPanel(a.tabKey);if(o){(n.get(a.tabKey)||0)>1&&console.warn("[dashboard-conversations] Dockview panel already exists for duplicate tabKey",{tabKey:a.tabKey,daemonId:a.daemonId,sessionId:a.sessionId,providerSessionId:a.providerSessionId,panelId:o.id}),o.update({params:{tabKey:a.tabKey}}),o.title!==Nn(a)&&o.api.setTitle(Nn(a));continue}e.addPanel({id:a.tabKey,component:"conversation",title:Nn(a),params:{kind:"conversation",tabKey:a.tabKey},...e.activePanel?{position:{referencePanel:e.activePanel.id,direction:"within"},inactive:!0}:e.panels[0]?{position:{referencePanel:e.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Ul(e,t,r){var d,m;const n=r?A0(r):null;for(const u of[...e.panels])Rt(u.id)&&(!n||u.id!==n)&&e.removePanel(u);if(!r||!n)return;const a=$t(t,r);if(!a&&e.totalPanels===0)return;const o=e.getPanel(n),i=jd(a);if(o){o.title!==i&&o.api.setTitle(i);return}const c=(a==null?void 0:a.tabKey)??((d=e.activePanel)==null?void 0:d.id)??((m=e.panels.find(u=>!Rt(u.id)))==null?void 0:m.id);e.addPanel({id:n,component:"remote",title:i,params:{kind:"remote",routeId:r},...c?{position:{referencePanel:c,direction:"right"},inactive:!0}:{}})}function R0({params:e,api:t}){var y;const r=la(),n=l.useRef(null),[a,o]=l.useState(()=>dn(t)),[i,c]=l.useState(()=>Fl(t)),d=r.conversationsByTabKey.get(e.tabKey),m=aa({sendDaemonCommand:r.sendDaemonCommand,activeConv:d,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});l.useEffect(()=>{o(dn(t)),c(Fl(t));const b=[t.onDidActiveChange(x=>o(x.isActive)),t.onDidActiveGroupChange(x=>{if(!dn(t)&&!x.isActive){o(!1);return}o(dn(t))}),t.onDidVisibilityChange(x=>c(x.isVisible))];return()=>{for(const x of b)x.dispose()}},[t]);const u=l.useMemo(()=>d?r.ides.find(b=>b.id===d.routeId):void 0,[r.ides,d]),h=l.useMemo(()=>d?r.actionLogs.filter(b=>b.routeId===d.tabKey):[],[r.actionLogs,d]);if(!d)return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:s.jsx(di,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,onOpenNewSession:r.onOpenNewSession,suppressGuide:r.hasDetachedConversationPanels})});const f=!Ve(d)&&Us(d)==="terminal";return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:s.jsx(li,{activeConv:d,clearToken:r.clearedTabs[d.tabKey]||0,isCliTerminal:f,ideEntry:u,terminalRef:n,handleModalButton:m.handleModalButton,handleRelaunch:m.handleRelaunch,handleSendChat:m.handleSendChat,handleForceSendChat:m.handleForceSendChat,isSendingChat:m.isSendingChat,handleFocusAgent:m.handleFocusAgent,isFocusingAgent:m.isFocusingAgent,actionLogs:h,userName:r.userName,scrollToBottomRequestNonce:((y=r.scrollToBottomRequest)==null?void 0:y.tabKey)===d.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:a,isVisible:i})})}function D0({params:e}){var d;const t=la(),r=l.useMemo(()=>$t([...t.conversationsByTabKey.values()],e.routeId),[t.conversationsByTabKey,e.routeId]),n=l.useMemo(()=>t.ides.find(m=>m.id===e.routeId),[t.ides,e.routeId]),a=(r==null?void 0:r.daemonId)||((d=r==null?void 0:r.routeId)==null?void 0:d.split(":")[0])||e.routeId.split(":")[0]||e.routeId,{connScreenshot:o,screenshotUsage:i,handleRemoteAction:c}=yu({doId:a,targetSessionId:r?ad(r):(n==null?void 0:n.sessionId)||(n==null?void 0:n.instanceId),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote"});return r?s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:s.jsx(Hc,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:o,screenshotUsage:i,transportType:r.transport,onAction:c})}):s.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function E0(){const e=la();return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:s.jsx(di,{conversationsCount:0,isSplitMode:!1,isStandalone:e.isStandalone,hasRegisteredMachines:e.hasRegisteredMachines,onOpenNewSession:e.onOpenNewSession,suppressGuide:e.hasDetachedConversationPanels})})}function $0(e){var p,w;L0(e);const t=la(),r=l.useCallback(C=>{"button"in C&&C.button!==0||e.api.setActive()},[e.api]),n=e.params.kind==="remote"?void 0:t.conversationsByTabKey.get(e.params.tabKey),a=n==null?void 0:n.sessionId,o=l.useCallback(C=>Rx(C),[]),i=l.useCallback(()=>Px(a),[a]),c=l.useSyncExternalStore(o,i,i);if(e.params.kind==="remote"){const C=$t([...t.conversationsByTabKey.values()],e.params.routeId),v=((p=e.api.group.activePanel)==null?void 0:p.id)===e.api.id,g=e.api.isGroupActive;return s.jsxs("div",{className:`adhdev-dockview-tab${v?" is-active":""}${g?" is-group-active":""}`,title:e.api.title||"Remote","data-tab-key":(C==null?void 0:C.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||"Remote"}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:C!=null&&C.machineName?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"Live remote view"}),s.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),s.jsx("span",{className:"adhdev-dockview-tab-machine",children:C.machineName})]}):s.jsx("span",{children:"Live remote view"})})]})]})}const d=t.conversationsByTabKey.get(e.params.tabKey);if(!d)return s.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":e.params.tabKey||"",children:s.jsx("div",{className:"adhdev-dockview-tab-copy",children:s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||e.params.tabKey})})});const m=((w=e.api.group.activePanel)==null?void 0:w.id)===e.api.id,u=e.api.isGroupActive,h=ra(d,t.liveSessionInboxState,{isOpenConversation:m}),f=h.isReconnecting,y=h.isConnecting,b=h.isGenerating||c,x=h.isWaiting,k=h.unread,j=t.tabShortcuts[d.tabKey];return s.jsxs("div",{className:`adhdev-dockview-tab${m?" is-active":""}${u?" is-group-active":""}${f?" is-reconnecting":""}`,title:nt(d),"data-tab-key":e.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:C=>{var v;C.preventDefault(),r(C),t.openTabContextMenu({x:C.clientX,y:C.clientY,tabKey:d.tabKey,sourceDocument:((v=C.target)==null?void 0:v.ownerDocument)??document})},children:[k&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:b?s.jsx("div",{className:"tab-spinner"}):x?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):f?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):y?s.jsx("div",{className:"tab-connecting-spinner"}):d.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:nt(d)}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:f?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:ms(d)}):y?s.jsx("span",{className:"adhdev-dockview-tab-connecting",children:ms(d)}):s.jsx("span",{children:ms(d)})})]}),j&&s.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:j,children:j})]})}function B0({visibleConversations:e,clearedTabs:t,ides:r,actionLogs:n,sendDaemonCommand:a,setActionLogs:o,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d,userName:m,toggleHiddenTab:u,actionShortcuts:h,registerActionHandlers:f,onActiveTabChange:y,onOpenNewSession:b,onRequestScrollToBottom:x,requestedActiveTabKey:k,requestedRemoteIdeId:j,onRequestedActiveTabConsumed:p,scrollToBottomRequest:w,liveSessionInboxState:C,layoutProfile:v}){var st,qe,Ke;const{theme:g}=zs(),{sendCommand:N}=it(),I=l.useRef(null),S=l.useRef(null),T=l.useRef(null),P=l.useRef(!1),A=l.useRef(!1),D=l.useRef(!1),L=l.useRef(null),O=l.useRef([]),[_,M]=l.useState(null),[$,W]=l.useState(0),B=l.useRef(typeof window>"u"?{}:ry(v)),F=l.useMemo(()=>new Map(e.map(U=>[U.tabKey,U])),[e]),K=l.useMemo(()=>{const U=I.current;return U?U.groups.some(z=>{try{const J=z.model.location.type;return J!=="floating"&&J!=="popout"?!1:z.panels.some(te=>F.has(te.id))}catch{return!1}}):!1},[F,$,e]),Y=l.useCallback(()=>{var U;(U=I.current)==null||U.focus()},[]),re=l.useCallback((U,z)=>{x==null||x(U,z)},[x]),ae=l.useCallback(U=>{const z=document,J=U.document;for(const ne of z.querySelectorAll('link[rel="stylesheet"]')){const E=J.createElement("link");E.rel="stylesheet",E.href=ne.href,ne.crossOrigin&&(E.crossOrigin=ne.crossOrigin),J.head.appendChild(E)}for(const ne of z.querySelectorAll("style")){const E=J.createElement("style");E.textContent=ne.textContent,J.head.appendChild(E)}const te=[];for(const ne of z.styleSheets)try{for(const E of ne.cssRules)E instanceof CSSStyleRule&&(E.selectorText===":root"||E.selectorText==="html")&&te.push(E.cssText)}catch{}if(te.length>0){const ne=J.createElement("style");ne.textContent=te.join(`
|
|
55
55
|
`),J.head.appendChild(ne)}const H=z.documentElement.getAttribute("data-theme");H&&J.documentElement.setAttribute("data-theme",H),J.documentElement.style.colorScheme=H==="light"?"light":"dark",J.body.className=z.body.className;const G=z.documentElement.getAttribute("style");G&&J.documentElement.setAttribute("style",G);const Z=J.getElementById("dv-popout-window");Z instanceof HTMLElement&&(Z.classList.add("adhdev-dockview"),Oa(Z,g))},[g]),he=l.useCallback(()=>{var z;const U=I.current;if(U)for(const J of U.groups)try{const te=(z=J.element)==null?void 0:z.ownerDocument;if(!te||te===document)continue;const H=te.getElementById("dv-popout-window");H instanceof HTMLElement&&(H.classList.add("adhdev-dockview"),Oa(H,g));const G=document.documentElement.getAttribute("data-theme");G&&te.documentElement.setAttribute("data-theme",G),te.documentElement.style.colorScheme=G==="light"?"light":"dark",te.body.className=document.body.className;const Z=document.documentElement.getAttribute("style");Z?te.documentElement.setAttribute("style",Z):te.documentElement.removeAttribute("style")}catch{}},[g]),we=l.useCallback(U=>{const z=I.current;if(!z)return;const J=z.getPanel(U);J&&z.addPopoutGroup(J,{popoutUrl:"/popout.html",onDidOpen:({window:te})=>{ae(te),ye();const H=F.get(U);te.document.title=H?`${nt(H)} — ADHDev`:"ADHDev — Popout"}})},[F,ae]),Ce=l.useCallback(U=>{const z=I.current,J=z==null?void 0:z.getPanel(U);if(!z||!J)return;const te=z.groups.filter(H=>{var G;try{return((G=H.element)==null?void 0:G.ownerDocument)===document}catch{return!0}});te.length>0?J.api.moveTo({group:te[0],position:"center"}):J.api.moveTo({position:"center"}),J.api.setActive()},[]),V=l.useCallback(U=>{var te;const z=I.current;if(!z)return!1;const J=z.getPanel(U);if(!J)return!1;try{return((te=J.group.element)==null?void 0:te.ownerDocument)!==document}catch{return!1}},[]),q=l.useCallback(U=>{V(U)&&Ce(U),u(U)},[V,Ce,u]),ue=l.useCallback(U=>{const z=I.current,J=z==null?void 0:z.getPanel(U);!z||!J||z.addFloatingGroup(J,{width:600,height:500})},[]),me=l.useCallback(U=>{var J;const z=(J=I.current)==null?void 0:J.getPanel(U);if(!z)return!1;try{return z.group.model.location.type==="floating"}catch{return!1}},[]),le=l.useCallback(()=>{var z,J;const U=(J=(z=I.current)==null?void 0:z.activePanel)==null?void 0:J.id;return!U||Rt(U)?null:F.has(U)?U:null},[F]),je=l.useCallback(U=>{const z=I.current,J=z==null?void 0:z.getPanel(U);if(!z||!J)return;const te=z.groups.filter(H=>{try{return H.model.location.type==="grid"}catch{return!0}});te.length>0?J.api.moveTo({group:te[0],position:"center"}):J.api.moveTo({position:"center"}),J.api.setActive()},[]),X=l.useCallback(()=>{var G;const U=I.current;if(!U)return;const J=U.groups.filter(Z=>{var ne;try{return((ne=Z.element)==null?void 0:ne.ownerDocument)===document&&Z.model.location.type==="grid"}catch{return!1}})[0]||null,te=[...U.panels];for(const Z of te){const ne=(G=Z.group.element)==null?void 0:G.ownerDocument,E=Z.group.model.location.type;ne===document&&E==="grid"||(J&&J.id!==Z.group.id?Z.api.moveTo({group:J,position:"center"}):Z.api.moveTo({position:"center"}))}const H=U.activePanel;H&&(H.group.model.openPanel(H),H.api.setActive()),Ba(document)},[]),ye=l.useCallback(()=>{var z,J;const U=I.current;if(U)for(const te of U.groups){const H=(z=te.element)==null?void 0:z.ownerDocument;if(!H||H===document)continue;const G=H.getElementById("dv-popout-window");if(!(G instanceof HTMLElement))continue;let Z=null,ne=H.title||"ADHDev",E="Popout workspace";const ie=te.activePanel;if(ie)if(Z=ie.id,Rt(ie.id)){const Te=((J=ie.params)==null?void 0:J.routeId)||ie.id.slice(7),Le=$t([...F.values()],Te);ne=jd(Le),E=Le!=null&&Le.machineName?`Remote view · ${Le.machineName}`:"Remote view"}else{const Te=F.get(ie.id);ne=Te?nt(Te):ie.title||ie.id,E=Te?ms(Te):"Dockview panel"}H.title=`${ne} — ADHDev`;const xe=Array.from(H.querySelectorAll("#adhdev-popout-header"));for(const Te of xe)Te.remove();const ke=H.createElement("div");ke.id="adhdev-popout-header",H.body.appendChild(ke),ke.setAttribute("style",["position:absolute","top:0","left:0","right:0","height:52px","display:flex","align-items:center","justify-content:space-between","gap:12px","padding:0 14px","box-sizing:border-box","background:var(--surface-secondary)","border-bottom:1px solid var(--border-subtle)","z-index:5","backdrop-filter:blur(14px)"].join(";")),ke.innerHTML=`
|
|
56
56
|
<div style="min-width:0;display:flex;flex-direction:column;gap:2px;">
|
|
57
57
|
<div style="font-size:10px;line-height:1;color:var(--text-muted);text-transform:uppercase;letter-spacing:0.08em;">ADHDev</div>
|
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-B9KHrSa-.js"></script>
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/vendor-DNk1FT1R.js">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-BSeeeP5M.css">
|
|
13
13
|
</head>
|