@adhdev/daemon-standalone 0.9.82-rc.553 → 0.9.82-rc.554
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhdev/daemon-standalone",
|
|
3
|
-
"version": "0.9.82-rc.
|
|
3
|
+
"version": "0.9.82-rc.554",
|
|
4
4
|
"description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"license": "AGPL-3.0-or-later",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@adhdev/ghostty-vt-node": "*",
|
|
40
|
-
"@adhdev/session-host-core": "0.9.82-rc.
|
|
40
|
+
"@adhdev/session-host-core": "0.9.82-rc.554",
|
|
41
41
|
"@xterm/addon-serialize": "^0.14.0",
|
|
42
42
|
"@xterm/xterm": "^6.0.0",
|
|
43
43
|
"chalk": "^5.3.0",
|
|
@@ -48,7 +48,7 @@ ${JSON.stringify(t,null,2)}
|
|
|
48
48
|
`):"");try{await navigator.clipboard.writeText(J.join(`
|
|
49
49
|
`)),b("Copied!"),setTimeout(()=>b("Snapshot"),1500)}catch(oe){console.error("[SpecDebugPanel] clipboard write failed",oe)}},fe=K=>{h($=>{const J=new Set($);return J.has(K)?J.delete(K):J.add(K),J})};return s.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Spec debug",className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center bg-black/60 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] px-0 sm:items-center sm:p-4",onClick:t,style:{pointerEvents:"auto"},children:s.jsxs("div",{className:"bg-bg-secondary text-text-primary border border-border-default rounded-t-xl sm:rounded-lg shadow-2xl max-w-2xl w-full max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[88vh] flex flex-col",onClick:K=>K.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border-default px-4 py-2.5 shrink-0 gap-2 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 overflow-hidden",children:[s.jsx("span",{className:"text-sm font-semibold text-text-primary shrink-0",children:"Spec Debug"}),q&&s.jsx("span",{className:"text-[11px] text-text-secondary font-mono bg-surface-secondary px-1.5 py-0.5 rounded truncate",children:q.spec_id})]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[(q==null?void 0:q.specPath)&&s.jsx("button",{type:"button",className:`text-[11px] transition-colors px-2 py-1 rounded border ${f?"text-accent-primary bg-accent-primary/20 border-accent":"text-text-secondary hover:text-text-primary hover:bg-bg-glass-hover border-transparent hover:border-border-default"}`,onClick:()=>{f?k(!1):te()},disabled:n,children:f?"Close Editor":"Edit Spec"}),s.jsx("button",{type:"button",className:"text-[11px] text-text-secondary hover:text-text-primary transition-colors px-2 py-1 rounded hover:bg-bg-glass-hover border border-transparent hover:border-border-default",onClick:()=>{pe()},disabled:n,children:g}),s.jsx("button",{type:"button",className:"text-[11px] text-text-secondary hover:text-text-primary transition-colors px-2 py-1 rounded hover:bg-bg-glass-hover border border-transparent hover:border-border-default",onClick:()=>{G()},disabled:n,children:n?"Loading…":"Refresh"}),s.jsx("button",{type:"button",className:"text-text-secondary hover:text-text-primary transition-colors text-xl leading-none w-7 h-7 flex items-center justify-center rounded hover:bg-bg-glass-hover",onClick:t,"aria-label":"Close",children:"×"})]})]}),f&&s.jsxs("div",{className:"flex-1 flex flex-col min-h-0 px-4 py-3 gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"inline-flex rounded border border-border-default overflow-hidden text-[10px]",children:[s.jsx("button",{type:"button",className:`px-2 py-0.5 ${v?"text-text-secondary hover:bg-bg-glass-hover":"bg-accent-primary/20 text-accent-primary"}`,onClick:()=>{if(v)try{const K=JSON.parse(w);x(K),U(K)}catch{return}I(!1)},disabled:!j&&v,children:"Form"}),s.jsx("button",{type:"button",className:`px-2 py-0.5 ${v?"bg-accent-primary/20 text-accent-primary":"text-text-secondary hover:bg-bg-glass-hover"}`,onClick:()=>{j&&y(JSON.stringify(j,null,2)),I(!0)},children:"JSON"})]}),s.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate flex-1",title:q==null?void 0:q.specPath,children:((q==null?void 0:q.specPath)??"").split("/").slice(-3).join("/")}),S&&s.jsx("span",{className:"text-status-warning text-[10px]",children:"unsaved"}),!v&&D.length>0&&s.jsxs("span",{className:"text-status-error text-[10px]",children:[D.length," error",D.length>1?"s":""]}),s.jsx("button",{type:"button",className:`text-[11px] px-2.5 py-1 rounded border transition-colors ${C==="saving"||!v&&D.length>0?"text-text-muted border-border-default cursor-not-allowed":"text-status-online bg-status-online/20 border-status-online/40 hover:bg-status-online/20"}`,onClick:()=>{O()},disabled:C==="saving"||!v&&D.length>0,children:C==="saving"?"Saving…":C==="saved"?"Saved ✓ (reloading)":"Save & Apply"})]}),L&&s.jsx("pre",{className:"text-status-error bg-status-error/20 border border-status-error/40 rounded p-2 text-[10px] whitespace-pre-wrap shrink-0 max-h-28 overflow-y-auto",children:L}),!v&&D.length>0&&s.jsx("div",{className:"text-status-error bg-status-error/20 border border-status-error/40 rounded p-1.5 text-[10px] shrink-0 max-h-24 overflow-y-auto space-y-0.5",children:D.map((K,$)=>s.jsx("div",{className:"font-mono",children:K},$))}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:v||!j?s.jsx("textarea",{value:w,onChange:K=>{y(K.target.value),N(!0),R("idle")},spellCheck:!1,className:"w-full h-full min-h-[300px] font-mono text-[11px] leading-relaxed bg-bg-secondary text-text-primary border border-border-default rounded p-3 resize-none outline-none focus:border-accent"}):s.jsx(By,{model:j,onChange:Z,onPreview:se,preview:z,onTestSections:V,sectionPreview:H})}),s.jsx("div",{className:"text-[10px] text-text-muted shrink-0",children:v?"Raw JSON — validated on save.":'Build the FSM; from/to are constrained to existing states. "test" evaluates a condition against the live screen. Save hot-reloads the session.'})]}),!f&&s.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))] space-y-3 text-[12px]",children:[c&&s.jsx("div",{className:"text-status-error bg-status-error/20 border border-status-error/40 rounded p-2",children:c}),n&&!o&&s.jsx("div",{className:"text-text-muted text-center py-6",children:"Loading…"}),o&&!o.isSpecProvider&&s.jsxs("div",{className:"text-text-muted text-center py-6",children:["Not a spec-driven provider (",o.providerType||"unknown",")."]}),q&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-[11px] bg-surface-secondary rounded-md px-3 py-2 border border-border-default",children:[q.name&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-text-muted",children:"Provider"}),s.jsxs("span",{className:"font-mono text-text-primary",children:[q.name," ",s.jsxs("span",{className:"text-text-muted",children:["(",q.cliType,")"]})]})]}),q.workingDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-text-muted",children:"Dir"}),s.jsx("span",{className:"font-mono text-text-secondary truncate",title:q.workingDir,children:q.workingDir})]}),q.spawnedAtMs?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-text-muted",children:"Spawned"}),s.jsx("span",{className:"text-text-secondary",children:Pr(q.spawnedAtMs)})]}):null,q.providerSessionId&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-text-muted",children:"Session"}),s.jsx("span",{className:"font-mono text-text-muted text-[10px] truncate",title:q.providerSessionId,children:q.providerSessionId})]})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-wrap bg-surface-secondary rounded-md px-3 py-2 border border-border-default",children:[s.jsx("span",{className:`font-semibold font-mono text-[12px] px-2 py-0.5 rounded ${q.current_state?eo(q.current_state.id):"text-text-muted"}`,children:q.current_state?q.current_state.id:"none"}),((ye=q.current_state)==null?void 0:ye.label)&&q.current_state.label!==q.current_state.id&&s.jsx("span",{className:"text-text-secondary text-[11px]",children:q.current_state.label}),q.status&&q.status!==((we=q.current_state)==null?void 0:we.id)&&s.jsxs("span",{className:"text-text-muted text-[11px]",children:["engine: ",s.jsx("span",{className:`font-mono ${eo(q.status)} px-1 py-0.5 rounded text-[10px]`,children:q.status})]}),q.idleHoldPending&&s.jsx("span",{className:"text-yellow-200 text-[10px] bg-yellow-600/25 border border-yellow-500/35 px-1.5 py-0.5 rounded font-mono",children:"idle hold pending"}),q.exited&&s.jsx("span",{className:"text-status-error text-[10px] bg-status-error/20 border border-status-error/40 px-1.5 py-0.5 rounded font-mono",children:"exited"}),q.cursorPosition!=null&&s.jsxs("span",{className:"text-text-muted text-[11px] font-mono",children:["cursor: ",s.jsxs("span",{className:"text-text-secondary",children:[q.cursorPosition.row,",",q.cursorPosition.col]})]}),q.lastBusyAt>0&&s.jsxs("span",{className:"text-text-muted text-[11px] ml-auto",children:["last busy: ",s.jsx("span",{className:"text-text-secondary",children:Pr(q.lastBusyAt)})]})]}),((he=q.completionIdleDebounce)==null?void 0:he.active)&&s.jsxs("div",{className:"flex items-center gap-2 text-[11px] bg-accent-primary/20 border border-accent rounded-md px-3 py-1.5 font-mono",children:[s.jsx("span",{className:"text-accent-primary",children:"completion_idle_after"}),s.jsxs("span",{className:"text-text-secondary",children:["age: ",s.jsxs("span",{className:"text-accent-primary",children:[q.completionIdleDebounce.ageMs,"ms"]})]}),s.jsx("span",{className:"text-text-muted",children:"/"}),s.jsxs("span",{className:"text-text-secondary",children:["hold: ",s.jsxs("span",{className:"text-text-secondary",children:[q.completionIdleDebounce.holdMs,"ms"]})]}),s.jsxs("span",{className:"text-text-secondary",children:["force: ",s.jsxs("span",{className:"text-text-secondary",children:[q.completionIdleDebounce.forceAfterMs,"ms"]})]}),s.jsx("span",{className:"text-text-muted ml-auto",children:q.completionIdleDebounce.ageMs<q.completionIdleDebounce.holdMs?s.jsxs("span",{className:"text-status-warning",children:["hold remaining: ",q.completionIdleDebounce.holdMs-q.completionIdleDebounce.ageMs,"ms"]}):q.completionIdleDebounce.ageMs<q.completionIdleDebounce.forceAfterMs?s.jsxs("span",{className:"text-orange-300",children:["force in: ",q.completionIdleDebounce.forceAfterMs-q.completionIdleDebounce.ageMs,"ms"]}):s.jsx("span",{className:"text-status-error",children:"overdue"})})]}),q.current_modal&&s.jsxs("div",{className:"bg-orange-900/30 border border-orange-600/40 rounded-md p-2.5",children:[s.jsx("span",{className:"text-orange-200 font-semibold",children:"Modal: "}),s.jsx("span",{className:"text-text-secondary",children:q.current_modal.title||""}),q.current_modal.buttons.length>0&&s.jsxs("span",{className:"text-text-secondary ml-2",children:["[",q.current_modal.buttons.map(K=>K.label).join(" / "),"]"]})]}),q.fsm&&s.jsxs(s.Fragment,{children:[s.jsx(Nn,{}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[s.jsxs(kn,{children:["FSM — outgoing from ",s.jsx("span",{className:"text-accent-primary font-mono normal-case",children:q.fsm.currentState})," (held ",dc(q.fsm.stateAgeMs),")"]}),s.jsxs("label",{className:"ml-auto flex items-center gap-1 text-[10px] text-text-muted cursor-pointer select-none mb-1.5",children:[s.jsx("input",{type:"checkbox",checked:A,onChange:K=>E(K.target.checked),className:"accent-[var(--accent-primary)]"}),"live"]})]}),s.jsxs("div",{className:"space-y-1",children:[q.fsm.transitions.length===0&&s.jsx("div",{className:"text-text-muted text-[11px] italic px-1",children:"no outgoing transitions (terminal state)"}),q.fsm.transitions.map((K,$)=>s.jsx(Wy,{t:K},$))]})]})]}),s.jsx(Nn,{}),q.sections&&Object.keys(q.sections).length>0&&s.jsxs("div",{children:[s.jsx(kn,{children:"Sections"}),s.jsx("div",{className:"space-y-1",children:Object.entries(q.sections).map(([K,$])=>{var ue;const J=m.has(K),re=$.split(`
|
|
50
50
|
`),be=((ue=re[0])==null?void 0:ue.slice(0,80))||"(empty)";return s.jsxs("div",{className:"border border-border-default rounded overflow-hidden bg-surface-secondary",children:[s.jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-2.5 py-1.5 hover:bg-bg-glass-hover transition-colors text-left",onClick:()=>fe(K),children:[s.jsx("span",{className:"text-[10px] text-text-muted w-3",children:J?"▾":"▸"}),s.jsx("span",{className:"font-mono text-accent-primary w-20 shrink-0 text-[11px]",children:K}),!J&&s.jsx("span",{className:"text-text-secondary truncate font-mono text-[11px]",children:be}),s.jsxs("span",{className:"ml-auto text-text-muted text-[10px] shrink-0",children:[re.length,"L"]})]}),J&&s.jsx("pre",{className:"px-3 pb-2.5 pt-1 font-mono text-[11px] text-text-secondary whitespace-pre-wrap break-all bg-bg-secondary max-h-40 overflow-y-auto border-t border-border-default",children:$||"(empty)"})]},K)})})]}),s.jsx(Nn,{}),q.stateHistory&&q.stateHistory.length>0&&s.jsxs("div",{children:[s.jsxs(kn,{children:["State History (",q.stateHistory.length,")"]}),s.jsx("div",{className:"space-y-px",children:[...q.stateHistory].reverse().slice(0,20).map((K,$)=>s.jsxs("div",{className:"rounded px-2 py-1 hover:bg-bg-glass-hover transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:`font-mono text-[11px] font-semibold px-1.5 py-0.5 rounded shrink-0 ${eo(K.stateId)}`,children:K.stateId}),s.jsx("span",{className:"text-text-secondary text-[11px] shrink-0 tabular-nums",children:Pr(K.at)}),K.durationMs>0&&s.jsxs("span",{className:"text-text-muted text-[11px]",children:["held ",s.jsx("span",{className:"text-text-secondary",children:dc(K.durationMs)})]}),K.reason&&s.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-mono shrink-0 ${Oy[String(K.reason)]??"text-text-secondary bg-bg-glass border border-border-default"}`,children:String(K.reason)}),K.debounceKind&&String(K.debounceKind)!=="none"&&s.jsxs("span",{className:"text-text-muted text-[10px] font-mono",children:["debounce:",String(K.debounceKind)]}),K.matchedStateId&&String(K.matchedStateId)!==K.stateId&&s.jsxs("span",{className:"text-text-muted text-[10px] font-mono",children:["eval→",s.jsx("span",{className:"text-text-secondary",children:String(K.matchedStateId)})]})]}),K.matchedRules&&K.matchedRules.length>0&&s.jsxs("div",{className:"flex items-start gap-1 flex-wrap mt-0.5 ml-1 pl-1 border-l border-border-default",children:[K.matchedRules.slice(0,3).map((J,re)=>s.jsx("span",{className:"font-mono text-[10px] text-accent-primary bg-accent-primary/20 border border-accent px-1.5 py-0.5 rounded break-all",children:typeof J=="string"?J:JSON.stringify(J)},re)),K.matchedRules.length>3&&s.jsxs("span",{className:"text-[10px] text-text-muted",children:["+",K.matchedRules.length-3," more"]})]})]},$))})]}),s.jsx(Nn,{}),(()=>{const K=q.messages??q.committedMessages??[];if(K.length===0)return null;const $=K.filter(be=>be.role==="user").length,J=K.filter(be=>be.role==="assistant").length,re=[...K].reverse().find(be=>be.role==="assistant");return s.jsxs("div",{children:[s.jsxs(kn,{children:["Transcript (",K.length," — ",$,"u / ",J,"a)"]}),re&&s.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-md p-2.5 text-[11px]",children:[s.jsxs("div",{className:"text-text-muted mb-1 text-[10px]",children:["Last assistant ",re.receivedAt?Pr(re.receivedAt):""]}),s.jsxs("div",{className:"text-text-secondary font-mono whitespace-pre-wrap line-clamp-4 break-all",children:[re.content.slice(0,400),re.content.length>400?"…":""]})]})]})})(),q.specPath&&s.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate border-t border-border-default pt-2 mt-1",title:q.specPath,children:q.specPath}),s.jsxs("div",{children:[s.jsxs("button",{type:"button",className:"text-[11px] text-text-secondary hover:text-text-primary transition-colors flex items-center gap-1.5",onClick:()=>u(K=>!K),children:[s.jsx("span",{className:"text-text-muted",children:p?"▾":"▸"}),s.jsxs("span",{children:["Raw screen (",q.screen?q.screen.split(`
|
|
51
|
-
`).length:0," lines)"]})]}),p&&s.jsx("pre",{className:"mt-1.5 px-3 py-2 font-mono text-[11px] text-text-secondary whitespace-pre bg-bg-secondary rounded-md border border-border-default max-h-64 overflow-auto",children:q.screen||"(empty)"})]})]})]})]})})}function Uy({activeConv:e,clearToken:t=0,terminalRef:r,handleSendChat:n,isSendingChat:a=!1,sendFeedbackMessage:o=null,isVisible:i=!0,isInputActive:c=!0}){var Ue;hs();const{sendPtyInput:d}=xt(),[p,u]=l.useState(!1),m=l.useRef(!1);m.current=p;const[h,g]=l.useState("Runtime terminal unavailable"),[b,f]=l.useState(!1),[k,j]=l.useState(null),[x,v]=l.useState(!1),[I,w]=l.useState(!1),[y,S]=l.useState(1),[N,C]=l.useState(!1),[R,L]=l.useState(!1),[_,D]=l.useState(!1),[B,z]=l.useState(!1),[M,H]=l.useState(!1),[Y,A]=l.useState({width:0,height:0}),[E,T]=l.useState({width:0,height:0}),[F,G]=l.useState({scrollTop:0,scrollHeight:0,clientHeight:0,atTop:!1,canScroll:!1}),[U,te]=l.useState(null),Z=l.useRef(null),se=l.useRef(null),V=l.useRef(!1),O=l.useRef(!1),q=l.useRef(i),pe=l.useRef(0),fe=l.useRef(!1),de=l.useRef(""),ke=l.useRef(null),ye=l.useRef(!1),we=l.useRef(!1),he=l.useRef(null),K=l.useRef(null),$=l.useRef(null),J=32*1024,re=()=>{var ae,ce,ge,$e;return((ce=(ae=Z.current)==null?void 0:ae.ownerDocument)==null?void 0:ce.defaultView)||(($e=(ge=se.current)==null?void 0:ge.ownerDocument)==null?void 0:$e.defaultView)||window},be=ae=>{const ce=re();return{ownerWindow:ce,frameId:ce.requestAnimationFrame(ae)}},ue=()=>{const ae=he.current;if(ae){try{ae.ownerWindow.cancelAnimationFrame(ae.frameId)}catch{}he.current=null}},P=()=>{const ae=K.current;if(ae){try{ae.ownerWindow.clearTimeout(ae.timeoutId)}catch{}K.current=null}},me=()=>{const ae=$.current;if(ae){try{ae.ownerWindow.clearTimeout(ae.timeoutId)}catch{}$.current=null}},Se=()=>{i&&he.current===null&&(he.current=be(()=>{Lt()}))},oe=e.tabKey,Q=e.sessionId||"",ve=e.daemonId||((Ue=e.routeId)==null?void 0:Ue.split(":")[0])||e.routeId||"",Ne=Pi(e),Le=p?o||Ne:h,We=Ny,le=Sy,Ee=.05,Be=()=>{const ae=E.width,ce=E.height;if(!Number.isFinite(Y.width)||Y.width<=0||!Number.isFinite(Y.height)||Y.height<=0||!Number.isFinite(ae)||ae<=0||!Number.isFinite(ce)||ce<=0)return 1;const ge=Y.width/ae,$e=Y.height/ce;return Number(Math.min(le,Math.max(We,Math.min(ge,$e))).toFixed(2))},Je=Be(),qe=V.current&&y>Je,je=Number.isFinite(E.width)&&E.width>0?Math.max(Y.width,Math.round(E.width*y)):Y.width,at=Number.isFinite(E.height)&&E.height>0?Math.max(Y.height,Math.round(E.height*y)):Y.height,Ie=()=>{be(()=>{const ae=se.current;ae&&(ae.scrollLeft=0,ae.scrollTop=ae.scrollHeight-ae.clientHeight)})},ot=()=>{var ae,ce;pe.current=0,fe.current=!1,de.current="",ke.current=null,ye.current=!1,we.current=!1,V.current||(O.current=!1,S(1)),he.current!==null&&ue(),u(!1),g("Runtime terminal unavailable"),me(),P(),j(null),te(null),C(!1),f(!1),v(!1),w(!1),(ce=(ae=r.current)==null?void 0:ae.reset)==null||ce.call(ae)},nt=()=>{var ae,ce;pe.current=0,fe.current=!1,de.current="",ke.current=null,ye.current=!1,we.current=!1,he.current!==null&&ue(),u(!0),g(""),me(),P(),j(null),te(null),C(!1),f(!1),v(!1),w(!1),(ce=(ae=r.current)==null?void 0:ae.reset)==null||ce.call(ae)},Qe=()=>{we.current&&(we.current=!1,be(()=>{var ae,ce;(ce=(ae=r.current)==null?void 0:ae.scrollToTop)==null||ce.call(ae)}))},Lt=()=>{if(he.current=null,!i)return;const ae=de.current;if(!ae)return;const ce=ae.slice(0,J);de.current=ae.slice(ce.length);const ge=r.current;if(!ge){de.current=ce+de.current,Se();return}ge.write(ce,()=>{if(de.current.length>0){Se();return}Qe()})},X=ae=>{ae&&(de.current+=ae,Se())},ee=(ae,ce=0,ge,$e,Fe={})=>{var Ze,rt,Ge,Nt;const Ye=!!Fe.force;!Ye&&ce>0&&pe.current>=ce||!Ye&&ce===0&&fe.current||(pe.current=ce,ce>0&&v(!0),u(!0),g(""),typeof ge=="number"&&typeof $e=="number"&&ge>0&&$e>0&&((rt=(Ze=r.current)==null?void 0:Ze.resize)==null||rt.call(Ze,ge,$e)),de.current="",(Nt=(Ge=r.current)==null?void 0:Ge.reset)==null||Nt.call(Ge),ae?X(ae):Qe())};l.useEffect(()=>{ot()},[Q]),l.useEffect(()=>{var ce;if(!Q)return;const ae=((ce=bt.onRuntimeEvent)==null?void 0:ce.call(bt,Q,ge=>{if(!(!ge||ge.sessionId!==Q)){if(ge.type==="runtime_snapshot"){if(!i){ke.current={text:ge.text||"",seq:ge.seq||0,cols:ge.cols,rows:ge.rows,force:!!ge.force};return}ee(ge.text||"",ge.seq||0,ge.cols,ge.rows,{force:!!ge.force});return}if(ge.type==="session_output"){fe.current=!0,typeof ge.seq=="number"&&(pe.current=Math.max(pe.current,ge.seq),ge.seq>0&&v(!0)),m.current||u(!0),m.current||g(""),typeof ge.data=="string"&&X(ge.data);return}if(ge.type==="session_cleared"){if(!i){ye.current=!0,de.current="",ke.current=null;return}nt();return}if(ge.type==="session_io_error"){const $e=typeof ge.error=="string"&&ge.error?ge.error:typeof ge.reason=="string"&&ge.reason?ge.reason:"unknown error";u(!1),g(`Runtime input failed: ${$e}`);return}}},ve))||(()=>{});return()=>{ae()}},[ve,Q,r,i]);const ne=async(ae={})=>{var ce;if(!ve||!Q)return{success:!1,error:"daemonId and sessionId are required"};ae.preserveStatus||g(ae.loadingMessage||"Loading runtime terminal...");try{const ge=await((ce=bt.requestRuntimeSnapshot)==null?void 0:ce.call(bt,ve,Q,{sinceSeq:ae.sinceSeq,force:ae.force}));return ge&&ge.success===!1?(ae.preserveStatus||(u(!1),g(`Runtime terminal unavailable: ${ge.error}`)),ge):ge||{success:!0}}catch(ge){const $e=(ge==null?void 0:ge.message)||String(ge);return ae.preserveStatus||(u(!1),g(`Runtime terminal unavailable: ${$e}`)),{success:!1,error:$e}}},ie=async ae=>{var Ye,Ze;const ce=((Ye=Z.current)==null?void 0:Ye.ownerDocument)||document,ge=ce.defaultView||window,$e=(Ze=ge.navigator)==null?void 0:Ze.clipboard;if($e!=null&&$e.writeText&&ge.isSecureContext)try{return await $e.writeText(ae),!0}catch{}let Fe=null;try{return Fe=ce.createElement("textarea"),Fe.value=ae,Fe.setAttribute("readonly","true"),Fe.style.position="fixed",Fe.style.left="-9999px",Fe.style.top="0",ce.body.appendChild(Fe),Fe.focus(),Fe.select(),ce.execCommand("copy")}catch{return!1}finally{Fe==null||Fe.remove()}},xe=ae=>{P(),te(ae);const ce=re();K.current={ownerWindow:ce,timeoutId:ce.setTimeout(()=>{K.current=null,te(ge=>ge===ae?null:ge)},2200)}},Ae=ae=>{me(),j(ae);const ce=re();$.current={ownerWindow:ce,timeoutId:ce.setTimeout(()=>{$.current=null,j(ge=>ge===ae?null:ge)},2200)}},De=async()=>{var Fe,Ye,Ze,rt;const ae=((Ye=(Fe=r.current)==null?void 0:Fe.getSelection)==null?void 0:Ye.call(Fe))||"",ce=((rt=(Ze=r.current)==null?void 0:Ze.getVisibleText)==null?void 0:rt.call(Ze))||"",ge=ae.trimEnd()||ce.trimEnd();if(!ge){xe("Nothing to copy");return}if(!await ie(ge)){xe("Copy failed");return}xe(ae.trimEnd()?"Copied selection":"Copied visible terminal")},Ce=ae=>{if(!p||!i)return;((d==null?void 0:d(ve,Q,ae))??!1)||xe("Terminal input failed")},Re=ae=>{Ce(Iy({ctrl:R,alt:_,shift:B},ae)),L(!1),D(!1),z(!1)},He=async()=>{if(b)return;f(!0),j("Loading older terminal output..."),we.current=!0;const ae=await ne({sinceSeq:0,force:!0,loadingMessage:"Loading older terminal output...",preserveStatus:p});if(f(!1),(ae==null?void 0:ae.success)===!1){we.current=!1,j(`Older terminal output unavailable: ${ae.error}`);return}w(!0),Ae("Older terminal output loaded"),be(()=>{var ce;(ce=r.current)==null||ce.bumpResize()})};l.useEffect(()=>{var ce,ge;if(!Q)return;ve&&((ce=bt.getState)==null?void 0:ce.call(bt,ve))==="connected"&&ne();const ae=(ge=bt.onStateChange)==null?void 0:ge.call(bt,($e,Fe)=>{$e!==ve||Fe!=="connected"||ne()});return()=>{ae==null||ae()}},[ve,Q,r]),l.useEffect(()=>{t&&ot()},[t,oe,r]),l.useEffect(()=>{var $e,Fe;const ae=Z.current,ce=(Fe=($e=ae==null?void 0:ae.ownerDocument)==null?void 0:$e.defaultView)==null?void 0:Fe.ResizeObserver;if(!ae||!ce)return;const ge=new ce(Ye=>{const Ze=Ye[0];if(!Ze)return;const{width:rt,height:Ge}=Ze.contentRect;A(Nt=>{const Jt=Math.round(rt),Ht=Math.round(Ge);return Nt.width===Jt&&Nt.height===Ht?Nt:{width:Jt,height:Ht}})});return ge.observe(ae),()=>ge.disconnect()},[]),l.useEffect(()=>{if(V.current)return;const ae=Be();!Number.isFinite(ae)||ae<=0||S(ce=>O.current?ae<ce-Ee?ae:ce:(O.current=!0,ae))},[E.height,E.width,Y.height,Y.width]),l.useEffect(()=>{qe&&Ie()},[qe,at,je]),l.useEffect(()=>{var ge;const ae=q.current;if(q.current=i,!i)return;ae||w(!1),ye.current&&(ye.current=!1,nt());const ce=ke.current;ce&&(ke.current=null,ee(ce.text,ce.seq,ce.cols,ce.rows,{force:!!ce.force})),ve&&Q&&((ge=bt.getState)==null?void 0:ge.call(bt,ve))==="connected"&&ne(),de.current&&he.current===null&&Se(),be(()=>{var $e;($e=r.current)==null||$e.bumpResize()})},[ve,i,Q]),l.useEffect(()=>()=>{he.current!==null&&ue(),P(),me()},[]),l.useEffect(()=>{const ae=$e=>{var Ye;const Fe=$e.detail;Fe!=null&&Fe.sessionId&&Fe.sessionId!==Q||p&&((Ye=r.current)==null||Ye.bumpResize())},ce=re(),ge=ce===window?[window]:[window,ce];for(const $e of ge)$e.addEventListener("adhdev:fit-cli-terminal",ae);return()=>{for(const $e of ge)$e.removeEventListener("adhdev:fit-cli-terminal",ae)}},[p,Q,r]);const Oe=p&&x&&!I&&(F.atTop||!F.canScroll)||b||!!k;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{ref:Z,className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[Oe&&s.jsxs("div",{className:"absolute left-3 top-3 z-10 flex items-center gap-2",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-medium text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{He()},disabled:!Q||b,title:"Replay raw session scrollback so the terminal viewport can scroll farther up",children:b?"Loading older...":"Load older terminal output"}),k&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:k})]}),s.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[U&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:U}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>H(ae=>!ae),title:"Spec debug — inspect current state, sections, and transition history",children:"Debug"}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{De()},disabled:!p,title:"Copy selected terminal text, or the visible terminal viewport if nothing is selected",children:"Copy"}),s.jsxs("div",{className:"relative",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>C(ae=>!ae),disabled:!p,"aria-label":"Open terminal control keys","aria-expanded":N,"aria-controls":"terminal-control-keys-popover",title:"Open mobile-friendly terminal control keys",children:"Keys"}),N&&s.jsxs("div",{id:"terminal-control-keys-popover",role:"dialog","aria-label":"Terminal control keys",className:"absolute right-0 top-10 w-72 rounded-2xl border border-white/10 bg-[#0b0d12]/95 p-3 text-white/85 shadow-2xl shadow-black/40 backdrop-blur-md",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-white/45",children:"Terminal keys"}),s.jsx("button",{type:"button",className:"rounded-full px-2 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/10 hover:text-white/85",onClick:()=>C(!1),"aria-label":"Close terminal control keys",children:"×"})]}),s.jsx("div",{className:"mb-2 grid grid-cols-3 gap-1.5",children:[["Ctrl",R,L],["Alt",_,D],["Shift",B,z]].map(([ae,ce,ge])=>s.jsx("button",{type:"button","aria-pressed":ce,className:`h-9 rounded-lg border text-[12px] font-semibold transition-colors ${ce?"border-sky-400/50 bg-sky-400/25 text-white":"border-white/10 bg-white/[0.06] hover:bg-white/[0.12]"}`,onClick:()=>ge($e=>!$e),children:ae},ae))}),s.jsx("div",{className:"grid grid-cols-6 gap-1",children:"abcdefghijklmnopqrstuvwxyz0123456789".split("").map(ae=>s.jsx("button",{type:"button",className:"h-8 rounded-md border border-white/10 bg-white/[0.06] text-[12px] font-semibold uppercase hover:bg-white/[0.12]",onClick:()=>Re(ae),children:ae},ae))}),s.jsx("div",{className:"my-2 h-px bg-white/10"}),s.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Escape"),children:"Esc"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Tab"),children:"Tab"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Enter"),children:"Enter"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowUp"),"aria-label":"Arrow up",children:"↑"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowLeft"),"aria-label":"Arrow left",children:"←"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowDown"),"aria-label":"Arrow down",children:"↓"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowRight"),"aria-label":"Arrow right",children:"→"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ce(""),title:"Send SIGINT (Ctrl-C)",children:"Ctrl-C"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Space"),children:"Space"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Backspace"),children:"Bksp"})]})]})]}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{V.current=!0,S(ae=>{const ce=Math.max(Je,Number((ae-.1).toFixed(2)));return ce>Je&&Ie(),ce})},title:"Shrink terminal viewport",children:"-"}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{V.current=!0,S(ae=>{const ce=Math.min(le,Number((ae+.1).toFixed(2)));return ce>Je&&Ie(),ce})},title:"Increase terminal viewport",children:"+"})]}),s.jsx("div",{ref:se,className:qe?"w-full h-full overflow-auto rounded-lg overscroll-contain":"w-full h-full overflow-hidden rounded-lg overscroll-contain",children:s.jsx("div",{style:{width:je>0?`${je}px`:"100%",height:at>0?`${at}px`:"100%",minWidth:"100%",minHeight:"100%",position:"relative"},children:s.jsx("div",{style:{width:E.width>0?`${E.width}px`:"100%",height:E.height>0?`${E.height}px`:"100%",position:"absolute",left:0,bottom:0,zoom:y},children:s.jsx(Xd,{ref:r,readOnly:!p||!i,sizingMode:"measured",onViewportMetrics:T,onScrollMetrics:G,onInput:ae=>{!p||(d==null||d(ve,Q,ae))}})})})}),!p&&s.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:h})]}),s.jsx(fu,{contextKey:e.tabKey,panelLabel:ft(e),isSending:a,isBusy:!!Ne,statusMessage:Le,inlineStatusMessage:Le,onSend:async ae=>Ne?!1:n(ae),isActive:c&&i,showControlsToggle:!1,animateVisibility:!1}),M&&s.jsx(Ky,{activeConv:e,onClose:()=>H(!1)})]})}const zy=5e3,Gy=12e3;function Vy(e){return e==="disconnected"||e==="reconnecting"}function qy({wsStatus:e,showReconnected:t,loginUrl:r,onReconnect:n,reconnectDelayMs:a=zy,reconnectActionDelayMs:o=Gy}){const i=Vy(e),[c,d]=l.useState(()=>!i||a<=0),[p,u]=l.useState(()=>!i||o<=0),m=l.useRef(!1);l.useEffect(()=>{if(!i){d(!1);return}if(m.current=!1,a<=0){m.current=!0,d(!0);return}d(!1);const w=setTimeout(()=>{m.current=!0,d(!0)},a);return()=>clearTimeout(w)},[a,i]),l.useEffect(()=>{if(!i){u(!1);return}if(o<=0){u(!0);return}u(!1);const w=setTimeout(()=>{u(!0)},o);return()=>clearTimeout(w)},[o,i]);const h=i?c:e==="offline"||e==="auth_failed",g=!!(n&&e!=="auth_failed"&&(!i||p)),b=l.useMemo(()=>!t||e!=="connected"?!1:a<=0||m.current,[a,t,e]),f=e==="auth_failed"?"red":e==="offline"?"orange":"accent",k={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},j={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},x={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"},v="fixed left-1/2 top-4 z-[var(--z-toast)] flex items-center justify-center pointer-events-none",I={top:"calc(env(safe-area-inset-top, 0px) + 16px)",transform:"translateX(-50%)"};return s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{className:v,style:I,children:s.jsxs("div",{className:"pointer-events-auto max-w-[min(720px,calc(100vw-24px))] rounded-2xl border px-3 py-2.5 sm:px-4 sm:py-3 text-[13px] font-semibold flex flex-wrap items-center gap-x-2.5 gap-y-2 justify-center shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:k[f],border:j[f],color:x[f]},children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5 shrink-0",style:{opacity:e==="auth_failed"?.6:1,animation:e==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:e==="auth_failed"?"grayscale(1)":void 0}}),s.jsxs("span",{className:"min-w-0 text-center whitespace-nowrap",children:[e==="offline"&&"Network offline",e==="disconnected"&&"Reconnecting",e==="reconnecting"&&"Reconnecting",e==="auth_failed"&&(r?s.jsxs(s.Fragment,{children:["Session expired."," ",s.jsx("a",{href:r,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — refresh the page or try again shortly.")]}),g&&s.jsx("button",{type:"button",className:"basis-full sm:basis-auto mx-auto sm:mx-0 sm:ml-1 shrink-0 px-2.5 py-1 rounded-md border border-current/30 text-[12px] font-semibold hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed",onClick:()=>n==null?void 0:n(),disabled:e==="offline",children:"Reconnect now"})]})}),b&&s.jsx("div",{className:v,style:I,children:s.jsxs("div",{className:"pointer-events-none rounded-2xl border px-4 py-2 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-green-500/15 shadow-[0_18px_40px_rgba(2,6,23,0.2)] backdrop-blur-xl animate-[fadeIn_0.3s_ease]",children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})})]})}function Zu({mode:e,onChange:t,compact:r=!1}){const n=r?14:15;return s.jsx("button",{type:"button",onClick:()=>t(e==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:e==="chat"?"Switch to Terminal view":"Switch to Chat view",children:e==="chat"?s.jsx(wi,{size:n}):s.jsx(Xs,{size:n})})}const us="New session",ep="A connected machine is ready. Start a new session with any installed provider — CLI, ACP, or IDE.";function Yy(e){if(!e||e.isGitRepo===!1||e.reason==="not_git_repo")return null;if(e.hasConflicts)return`${e.branch||"Git"} · conflicts${e.changedFiles>0?` ${e.changedFiles}`:""}`;const t=[e.branch||"Git"];return e.changedFiles>0&&t.push(`±${e.changedFiles}`),e.ahead>0&&t.push(`↑${e.ahead}`),e.behind>0&&t.push(`↓${e.behind}`),t.length===1&&e.dirty&&t.push("dirty"),t.join(" ")}function Jy(e){return!e||e.isGitRepo===!1||e.reason==="not_git_repo"?null:e.hasConflicts?"conflict":e.error?"error":e.dirty||e.changedFiles>0||e.ahead>0||e.behind>0?"dirty":"quiet"}function Xy(e){switch(e){case"conflict":return"border-status-error/40 bg-status-error/10 text-status-error";case"error":return"border-yellow-500/25 bg-yellow-500/[0.08] text-yellow-500";case"dirty":return"border-orange-500/25 bg-orange-500/[0.08] text-orange-400";case"quiet":default:return"border-status-online/40 bg-status-online/10 text-status-online"}}function aa({git:e,className:t="",compact:r=!1}){const n=Yy(e),a=Jy(e);if(!n||!a)return null;const o=[e!=null&&e.branch?`Branch: ${e.branch}`:null,e!=null&&e.changedFiles?`Changed files: ${e.changedFiles}`:null,e!=null&&e.ahead?`Ahead: ${e.ahead}`:null,e!=null&&e.behind?`Behind: ${e.behind}`:null,e!=null&&e.hasConflicts?"Conflicts detected":null,e!=null&&e.error?`Git error: ${e.error}`:null].filter(Boolean);return s.jsxs("span",{className:`inline-flex min-w-0 max-w-[12rem] items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none ${Xy(a)} ${t}`.trim(),title:o.join(" · ")||n,"data-git-tone":a,children:[s.jsx("span",{"aria-hidden":"true",children:"⑂"}),s.jsx("span",{className:"truncate",children:n})]})}function Qy({wsStatus:e,isConnected:t,daemonCount:r,p2pStates:n={}}){if(e!=="connected")return{tone:"disconnected",title:"Disconnected",subtitle:null};const a=Object.values(n),o=a.filter(c=>c==="connected").length,i=a.filter(c=>c==="connecting"||c==="new"||c==="checking").length;return r>0&&i>0&&o===0?{tone:"limited",title:"Connected to dashboard",subtitle:"Connecting to machine..."}:t?{tone:"connected",title:"Connected",subtitle:null}:{tone:"limited",title:"Connected to dashboard",subtitle:null}}function uc({value:e}){return e?s.jsx("span",{className:"dashboard-header-shortcut-pill",children:e}):null}function pc({notification:e,shortcutIndex:t,onOpen:r,onMarkRead:n,onMarkUnread:a,onDelete:o}){const i=wa(e.updatedAt),c=!e.readAt;return s.jsxs("div",{className:`dashboard-header-inbox-item ${c?"is-attention":""}`.trim(),children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:r,children:[s.jsx("span",{className:"dashboard-header-inbox-item-title",children:e.title}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[t?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",t]}):null,[e.type==="needs_attention"?"Action needed":"Task complete",i].filter(Boolean).join(" · ")]}),e.preview?s.jsx("span",{className:"dashboard-header-inbox-item-meta dashboard-header-inbox-item-preview",children:e.preview}):null]}),s.jsxs("div",{className:"ml-3 flex shrink-0 items-center gap-1.5",children:[c?s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),n()},children:"Mark read"}):s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),a()},children:"Mark unread"}),s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),o()},children:"Delete"})]})]})}function Zy({activeConv:e,wsStatus:t,isConnected:r,conversations:n,onOpenHistory:a,onOpenRemote:o,onStopCli:i,activeCliViewMode:c,onSetCliViewMode:d,onHideConversation:p,hiddenConversations:u=[],onShowConversation:m,onShowAllHidden:h,onResetPanelsToMain:g,inboxOpen:b,onInboxOpenChange:f,hiddenOpen:k,onHiddenOpenChange:j,onOpenNewSession:x,onOpenDashboardGuide:v,guideNudgeVisible:I=!1,actionShortcuts:w,notifications:y,notificationUnreadCount:S,onOpenNotification:N,onMarkNotificationRead:C,onMarkNotificationUnread:R,onDeleteNotification:L,onOpenGitDialog:_,onOpenMeshGraph:D}){var K;const{ides:B,p2pStates:z={}}=hs(),M=!!e&<(e)&&!it(e),H=!!e&&it(e),Y=!!(e!=null&&e.daemonId)&&!!((K=e==null?void 0:e.coordinator)!=null&&K.meshId),A=c||(e?ku(e)?"terminal":"chat":null),[E,T]=l.useState(!1),[F,G]=l.useState(!1),U=l.useRef(null),te=l.useRef(null),Z=l.useRef(null),se=B.filter($=>$.type==="adhdev-daemon"),V=Qy({wsStatus:t,isConnected:r,daemonCount:se.length,p2pStates:z}),O=V.subtitle,q=V.tone==="connected"?"#22c55e":V.tone==="limited"?"#eab308":"#ef4444",pe=V.tone==="connected"?"0 0 4px #22c55e80":V.tone==="limited"?"0 0 4px #eab30880":"0 0 4px #ef444480",fe=l.useMemo(()=>y.filter($=>!$.readAt),[y]),de=l.useMemo(()=>y.filter($=>!!$.readAt),[y]),ke=l.useMemo(()=>fe.slice(0,9),[fe]),ye=S;l.useEffect(()=>{if(!b)return;const $=J=>{var re;(re=te.current)!=null&&re.contains(J.target)||f(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[b,f]),l.useEffect(()=>{if(!k)return;const $=J=>{var re;(re=Z.current)!=null&&re.contains(J.target)||j(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[k,j]),l.useEffect(()=>{if(!k&&!b)return;const $=J=>{if(!J.altKey)return;const re=J.code.match(/^Digit([1-9])$/);if(!re)return;const be=Number(re[1])-1,ue=k?u[be]:void 0,P=b?ke[be]:void 0;if(!(!ue&&!P)){if(J.preventDefault(),J.stopPropagation(),ue){m==null||m(ue),j(!1);return}P&&(N(P),f(!1))}};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[u,k,b,ke,j,f,N,m]),l.useEffect(()=>{const $=u.length;if(U.current===null){U.current=$;return}$>U.current&&G(!0),U.current=$},[u.length]);const we=()=>G(!1),he=$=>{if(!$)return;const J=n.find(re=>re.tabKey===$);J&&(p==null||p(J))};return s.jsxs("div",{className:"dashboard-header",children:[s.jsx("div",{className:"flex items-center gap-3",children:s.jsx("div",{className:"header-title-block",children:s.jsxs("div",{className:"header-title-row",children:[s.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[s.jsx(Xs,{size:18}),s.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),s.jsx("span",{className:"header-title-mobile",children:e?ft(e):"Dashboard"}),s.jsx("span",{title:V.title,"aria-label":V.title,className:"header-title-status-dot",style:{background:q,boxShadow:pe}}),s.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:s.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:q,boxShadow:pe}})})]}),s.jsxs("div",{className:"header-subtitle flex items-center",children:[O&&s.jsxs("span",{className:"header-subtitle-status mr-2",children:["· ",O]}),x&&s.jsx("button",{type:"button",onClick:x,className:"btn btn-secondary btn-sm ml-2",title:`${us}${w!=null&&w.openNewSession?` (${w.openNewSession})`:""}`,"aria-label":us,children:s.jsx(ji,{size:14})})]})]})})}),s.jsxs("div",{className:"flex gap-2 items-center",children:[v&&s.jsxs("button",{type:"button",onClick:v,className:"btn btn-secondary btn-sm hidden md:inline-flex items-center gap-1.5 dashboard-header-guide-button",title:"Dashboard guide","aria-label":"Open dashboard guide",children:[s.jsx("span",{className:"font-semibold leading-none",children:"?"}),I&&s.jsx("span",{children:"Guide"})]}),e&&(M||H||!it(e))&&s.jsxs("div",{className:"dashboard-header-actions-group",children:[s.jsx("span",{className:"dashboard-header-action-target",title:xr(e)||ft(e),children:ft(e)}),_&&e.git&&e.daemonId&&e.workspacePath?s.jsx("button",{type:"button",className:"appearance-none bg-transparent border-0 p-0 cursor-pointer",title:"Open git status",onClick:()=>_(e.daemonId,e.workspacePath),children:s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"})}):s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"}),Y&&D&&s.jsxs("button",{type:"button",onClick:()=>D(e),className:"btn btn-secondary btn-sm dashboard-header-mesh-button",title:"Open live repo mesh graph",children:[s.jsx(ss,{size:14}),s.jsx("span",{className:"hidden lg:inline",children:"Mesh graph"})]}),(M||H)&&i&&s.jsxs(s.Fragment,{children:[M&&d&&A&&s.jsx(Zu,{mode:A,onChange:d,compact:!0}),s.jsx("button",{onClick:()=>i(e),className:"btn btn-secondary btn-sm",title:H?"Stop ACP session":"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(wt,{size:14})})]}),!it(e)&&s.jsx("button",{onClick:()=>a(e),className:"btn btn-secondary btn-sm",title:"Chat History",children:s.jsx(yi,{size:14})}),!M&&!it(e)&&s.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Remote Control",children:s.jsx(os,{size:14})})]}),s.jsxs("div",{className:"dashboard-header-inbox",ref:te,children:[s.jsxs("div",{className:`dashboard-header-hidden${E?" is-drop-target":""}${F?" hidden-spawn-flash":""}`,onAnimationEnd:we,ref:Z,onDragEnter:$=>{$.dataTransfer.types.includes("text/tab-key")&&($.preventDefault(),T(!0))},onDragOver:$=>{$.dataTransfer.types.includes("text/tab-key")&&($.preventDefault(),$.dataTransfer.dropEffect="move",T(!0))},onDragLeave:$=>{$.currentTarget.contains($.relatedTarget)||T(!1)},onDrop:$=>{const J=$.dataTransfer.getData("text/tab-key");$.preventDefault(),T(!1),he(J)},children:[s.jsxs("button",{type:"button",onClick:()=>j(!k),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:`Hidden tabs${w!=null&&w.toggleHiddenTabs?` (${w.toggleHiddenTabs})`:""}. Drag a tab here to hide it.`,children:[s.jsx(vi,{size:16}),u.length>0&&s.jsx("span",{className:`dashboard-header-hidden-badge${F?" hidden-badge-pop":""}`,children:u.length})]}),k&&s.jsxs("div",{className:"dashboard-header-hidden-popover",children:[s.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),s.jsx(uc,{value:w==null?void 0:w.toggleHiddenTabs})]}),s.jsxs("div",{className:"dashboard-header-hidden-actions",children:[g&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:g,children:"Reset panels"}),u.length>0&&h&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{h(),j(!1)},children:"Restore all"})]})]}),e&&p&&s.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>p(e),children:[s.jsxs("span",{className:"dashboard-header-hidden-current-leading",children:[s.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),s.jsx(uc,{value:w==null?void 0:w.hideCurrentTab})]}),s.jsx("span",{className:"dashboard-header-hidden-current-title",children:ft(e)})]}),u.length>0?s.jsx("div",{className:"dashboard-header-hidden-list",children:u.map($=>s.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{m==null||m($),j(!1)},children:[s.jsx("span",{className:"dashboard-header-inbox-item-title",children:ft($)}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[u.indexOf($)<9?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",u.indexOf($)+1]}):null,xr($)]})]},$.tabKey))}):s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),s.jsxs("button",{type:"button",onClick:()=>f(!b),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[s.jsx(jr,{size:16}),ye>0&&s.jsx("span",{className:"dashboard-header-inbox-badge",children:ye})]}),b&&s.jsxs("div",{className:"dashboard-header-inbox-popover",children:[fe.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Unread"}),fe.map($=>s.jsx(pc,{notification:$,shortcutIndex:ke.indexOf($)>=0?ke.indexOf($)+1:void 0,onOpen:()=>N($),onMarkRead:()=>C($.id),onMarkUnread:()=>R($.id),onDelete:()=>L($.id)},$.id))]}),de.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Read"}),de.map($=>s.jsx(pc,{notification:$,onOpen:()=>N($),onMarkRead:()=>C($.id),onMarkUnread:()=>R($.id),onDelete:()=>L($.id)},$.id))]}),y.length===0&&s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Dt(e={}){return{textQuery:e.textQuery||"",workspaceQuery:e.workspaceQuery||"",modelQuery:e.modelQuery||"",resumableOnly:!!e.resumableOnly,sortMode:e.sortMode||"recent"}}function e0(e,t){return String(e||"")!==String(t||"")}function t0(e,t={}){const r=String(t.textQuery||"").trim().toLowerCase(),n=String(t.workspaceQuery||"").trim().toLowerCase(),a=String(t.modelQuery||"").trim().toLowerCase(),o=!!t.resumableOnly;return!r&&!n&&!a&&!o?e:e.filter(i=>!(o&&!i.canResume||r&&![i.title,i.preview].map(d=>String(d||"").toLowerCase()).join(`
|
|
51
|
+
`).length:0," lines)"]})]}),p&&s.jsx("pre",{className:"mt-1.5 px-3 py-2 font-mono text-[11px] text-text-secondary whitespace-pre bg-bg-secondary rounded-md border border-border-default max-h-64 overflow-auto",children:q.screen||"(empty)"})]})]})]})]})})}function Uy({activeConv:e,clearToken:t=0,terminalRef:r,handleSendChat:n,isSendingChat:a=!1,sendFeedbackMessage:o=null,isVisible:i=!0,isInputActive:c=!0}){var Ue;hs();const{sendPtyInput:d}=xt(),[p,u]=l.useState(!1),m=l.useRef(!1);m.current=p;const[h,g]=l.useState("Runtime terminal unavailable"),[b,f]=l.useState(!1),[k,j]=l.useState(null),[x,v]=l.useState(!1),[I,w]=l.useState(!1),[y,S]=l.useState(1),[N,C]=l.useState(!1),[R,L]=l.useState(!1),[_,D]=l.useState(!1),[B,z]=l.useState(!1),[M,H]=l.useState(!1),[Y,A]=l.useState({width:0,height:0}),[E,T]=l.useState({width:0,height:0}),[F,G]=l.useState({scrollTop:0,scrollHeight:0,clientHeight:0,atTop:!1,canScroll:!1}),[U,te]=l.useState(null),Z=l.useRef(null),se=l.useRef(null),V=l.useRef(!1),O=l.useRef(!1),q=l.useRef(i),pe=l.useRef(0),fe=l.useRef(!1),de=l.useRef(""),ke=l.useRef(null),ye=l.useRef(!1),we=l.useRef(!1),he=l.useRef(null),K=l.useRef(null),$=l.useRef(null),J=32*1024,re=()=>{var ae,ce,ge,$e;return((ce=(ae=Z.current)==null?void 0:ae.ownerDocument)==null?void 0:ce.defaultView)||(($e=(ge=se.current)==null?void 0:ge.ownerDocument)==null?void 0:$e.defaultView)||window},be=ae=>{const ce=re();return{ownerWindow:ce,frameId:ce.requestAnimationFrame(ae)}},ue=()=>{const ae=he.current;if(ae){try{ae.ownerWindow.cancelAnimationFrame(ae.frameId)}catch{}he.current=null}},P=()=>{const ae=K.current;if(ae){try{ae.ownerWindow.clearTimeout(ae.timeoutId)}catch{}K.current=null}},me=()=>{const ae=$.current;if(ae){try{ae.ownerWindow.clearTimeout(ae.timeoutId)}catch{}$.current=null}},Se=()=>{i&&he.current===null&&(he.current=be(()=>{Lt()}))},oe=e.tabKey,Q=e.sessionId||"",ve=e.daemonId||((Ue=e.routeId)==null?void 0:Ue.split(":")[0])||e.routeId||"",Ne=Pi(e),Le=p?o||Ne:h,We=Ny,le=Sy,Ee=.05,Be=()=>{const ae=E.width,ce=E.height;if(!Number.isFinite(Y.width)||Y.width<=0||!Number.isFinite(Y.height)||Y.height<=0||!Number.isFinite(ae)||ae<=0||!Number.isFinite(ce)||ce<=0)return 1;const ge=Y.width/ae,$e=Y.height/ce;return Number(Math.min(le,Math.max(We,Math.min(ge,$e))).toFixed(2))},Je=Be(),qe=V.current&&y>Je,je=Number.isFinite(E.width)&&E.width>0?Math.max(Y.width,Math.round(E.width*y)):Y.width,at=Number.isFinite(E.height)&&E.height>0?Math.max(Y.height,Math.round(E.height*y)):Y.height,Ie=()=>{be(()=>{const ae=se.current;ae&&(ae.scrollLeft=0,ae.scrollTop=ae.scrollHeight-ae.clientHeight)})},ot=()=>{var ae,ce;pe.current=0,fe.current=!1,de.current="",ke.current=null,ye.current=!1,we.current=!1,V.current||(O.current=!1,S(1)),he.current!==null&&ue(),u(!1),g("Runtime terminal unavailable"),me(),P(),j(null),te(null),C(!1),f(!1),v(!1),w(!1),(ce=(ae=r.current)==null?void 0:ae.reset)==null||ce.call(ae)},nt=()=>{var ae,ce;pe.current=0,fe.current=!1,de.current="",ke.current=null,ye.current=!1,we.current=!1,he.current!==null&&ue(),u(!0),g(""),me(),P(),j(null),te(null),C(!1),f(!1),v(!1),w(!1),(ce=(ae=r.current)==null?void 0:ae.reset)==null||ce.call(ae)},Qe=()=>{we.current&&(we.current=!1,be(()=>{var ae,ce;(ce=(ae=r.current)==null?void 0:ae.scrollToTop)==null||ce.call(ae)}))},Lt=()=>{if(he.current=null,!i)return;const ae=de.current;if(!ae)return;const ce=ae.slice(0,J);de.current=ae.slice(ce.length);const ge=r.current;if(!ge){de.current=ce+de.current,Se();return}ge.write(ce,()=>{if(de.current.length>0){Se();return}Qe()})},X=ae=>{ae&&(de.current+=ae,Se())},ee=(ae,ce=0,ge,$e,Fe={})=>{var Ze,rt,Ge,Nt;const Ye=!!Fe.force;!Ye&&ce>0&&pe.current>=ce||!Ye&&ce===0&&fe.current||(pe.current=ce,ce>0&&v(!0),u(!0),g(""),typeof ge=="number"&&typeof $e=="number"&&ge>0&&$e>0&&((rt=(Ze=r.current)==null?void 0:Ze.resize)==null||rt.call(Ze,ge,$e)),de.current="",(Nt=(Ge=r.current)==null?void 0:Ge.reset)==null||Nt.call(Ge),ae?X(ae):Qe())};l.useEffect(()=>{ot()},[Q]),l.useEffect(()=>{var ce;if(!Q)return;const ae=((ce=bt.onRuntimeEvent)==null?void 0:ce.call(bt,Q,ge=>{if(!(!ge||ge.sessionId!==Q)){if(ge.type==="runtime_snapshot"){if(!i){ke.current={text:ge.text||"",seq:ge.seq||0,cols:ge.cols,rows:ge.rows,force:!!ge.force};return}ee(ge.text||"",ge.seq||0,ge.cols,ge.rows,{force:!!ge.force});return}if(ge.type==="session_output"){fe.current=!0,typeof ge.seq=="number"&&(pe.current=Math.max(pe.current,ge.seq),ge.seq>0&&v(!0)),m.current||u(!0),m.current||g(""),typeof ge.data=="string"&&X(ge.data);return}if(ge.type==="session_cleared"){if(!i){ye.current=!0,de.current="",ke.current=null;return}nt();return}if(ge.type==="session_io_error"){const $e=typeof ge.error=="string"&&ge.error?ge.error:typeof ge.reason=="string"&&ge.reason?ge.reason:"unknown error";u(!1),g(`Runtime input failed: ${$e}`);return}}},ve))||(()=>{});return()=>{ae()}},[ve,Q,r,i]);const ne=async(ae={})=>{var ce;if(!ve||!Q)return{success:!1,error:"daemonId and sessionId are required"};ae.preserveStatus||g(ae.loadingMessage||"Loading runtime terminal...");try{const ge=await((ce=bt.requestRuntimeSnapshot)==null?void 0:ce.call(bt,ve,Q,{sinceSeq:ae.sinceSeq,force:ae.force}));return ge&&ge.success===!1?(ae.preserveStatus||(u(!1),g(`Runtime terminal unavailable: ${ge.error}`)),ge):ge||{success:!0}}catch(ge){const $e=(ge==null?void 0:ge.message)||String(ge);return ae.preserveStatus||(u(!1),g(`Runtime terminal unavailable: ${$e}`)),{success:!1,error:$e}}},ie=async ae=>{var Ye,Ze;const ce=((Ye=Z.current)==null?void 0:Ye.ownerDocument)||document,ge=ce.defaultView||window,$e=(Ze=ge.navigator)==null?void 0:Ze.clipboard;if($e!=null&&$e.writeText&&ge.isSecureContext)try{return await $e.writeText(ae),!0}catch{}let Fe=null;try{return Fe=ce.createElement("textarea"),Fe.value=ae,Fe.setAttribute("readonly","true"),Fe.style.position="fixed",Fe.style.left="-9999px",Fe.style.top="0",ce.body.appendChild(Fe),Fe.focus(),Fe.select(),ce.execCommand("copy")}catch{return!1}finally{Fe==null||Fe.remove()}},xe=ae=>{P(),te(ae);const ce=re();K.current={ownerWindow:ce,timeoutId:ce.setTimeout(()=>{K.current=null,te(ge=>ge===ae?null:ge)},2200)}},Ae=ae=>{me(),j(ae);const ce=re();$.current={ownerWindow:ce,timeoutId:ce.setTimeout(()=>{$.current=null,j(ge=>ge===ae?null:ge)},2200)}},De=async()=>{var Fe,Ye,Ze,rt;const ae=((Ye=(Fe=r.current)==null?void 0:Fe.getSelection)==null?void 0:Ye.call(Fe))||"",ce=((rt=(Ze=r.current)==null?void 0:Ze.getVisibleText)==null?void 0:rt.call(Ze))||"",ge=ae.trimEnd()||ce.trimEnd();if(!ge){xe("Nothing to copy");return}if(!await ie(ge)){xe("Copy failed");return}xe(ae.trimEnd()?"Copied selection":"Copied visible terminal")},Ce=ae=>{if(!p||!i)return;((d==null?void 0:d(ve,Q,ae))??!1)||xe("Terminal input failed")},Re=ae=>{Ce(Iy({ctrl:R,alt:_,shift:B},ae)),L(!1),D(!1),z(!1)},He=async()=>{if(b)return;f(!0),j("Loading older terminal output..."),we.current=!0;const ae=await ne({sinceSeq:0,force:!0,loadingMessage:"Loading older terminal output...",preserveStatus:p});if(f(!1),(ae==null?void 0:ae.success)===!1){we.current=!1,j(`Older terminal output unavailable: ${ae.error}`);return}w(!0),Ae("Older terminal output loaded"),be(()=>{var ce;(ce=r.current)==null||ce.bumpResize()})};l.useEffect(()=>{var ce,ge;if(!Q)return;ve&&((ce=bt.getState)==null?void 0:ce.call(bt,ve))==="connected"&&ne();const ae=(ge=bt.onStateChange)==null?void 0:ge.call(bt,($e,Fe)=>{$e!==ve||Fe!=="connected"||ne()});return()=>{ae==null||ae()}},[ve,Q,r]),l.useEffect(()=>{t&&ot()},[t,oe,r]),l.useEffect(()=>{var $e,Fe;const ae=Z.current,ce=(Fe=($e=ae==null?void 0:ae.ownerDocument)==null?void 0:$e.defaultView)==null?void 0:Fe.ResizeObserver;if(!ae||!ce)return;const ge=new ce(Ye=>{const Ze=Ye[0];if(!Ze)return;const{width:rt,height:Ge}=Ze.contentRect;A(Nt=>{const Jt=Math.round(rt),Ht=Math.round(Ge);return Nt.width===Jt&&Nt.height===Ht?Nt:{width:Jt,height:Ht}})});return ge.observe(ae),()=>ge.disconnect()},[]),l.useEffect(()=>{if(V.current)return;const ae=Be();!Number.isFinite(ae)||ae<=0||S(ce=>O.current?ae<ce-Ee?ae:ce:(O.current=!0,ae))},[E.height,E.width,Y.height,Y.width]),l.useEffect(()=>{qe&&Ie()},[qe,at,je]),l.useEffect(()=>{var ge;const ae=q.current;if(q.current=i,!i)return;ae||w(!1),ye.current&&(ye.current=!1,nt());const ce=ke.current;ce&&(ke.current=null,ee(ce.text,ce.seq,ce.cols,ce.rows,{force:!!ce.force})),ve&&Q&&((ge=bt.getState)==null?void 0:ge.call(bt,ve))==="connected"&&ne(),de.current&&he.current===null&&Se(),be(()=>{var $e;($e=r.current)==null||$e.bumpResize()})},[ve,i,Q]),l.useEffect(()=>()=>{he.current!==null&&ue(),P(),me()},[]),l.useEffect(()=>{const ae=$e=>{var Ye;const Fe=$e.detail;Fe!=null&&Fe.sessionId&&Fe.sessionId!==Q||p&&((Ye=r.current)==null||Ye.bumpResize())},ce=re(),ge=ce===window?[window]:[window,ce];for(const $e of ge)$e.addEventListener("adhdev:fit-cli-terminal",ae);return()=>{for(const $e of ge)$e.removeEventListener("adhdev:fit-cli-terminal",ae)}},[p,Q,r]);const Oe=p&&x&&!I&&(F.atTop||!F.canScroll)||b||!!k;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{ref:Z,className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[Oe&&s.jsxs("div",{className:"absolute left-3 top-3 z-10 flex items-center gap-2",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-medium text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{He()},disabled:!Q||b,title:"Replay raw session scrollback so the terminal viewport can scroll farther up",children:b?"Loading older...":"Load older terminal output"}),k&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:k})]}),s.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[U&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:U}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>H(ae=>!ae),title:"Spec debug — inspect current state, sections, and transition history",children:"Debug"}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{De()},disabled:!p,title:"Copy selected terminal text, or the visible terminal viewport if nothing is selected",children:"Copy"}),s.jsxs("div",{className:"relative",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>C(ae=>!ae),disabled:!p,"aria-label":"Open terminal control keys","aria-expanded":N,"aria-controls":"terminal-control-keys-popover",title:"Open mobile-friendly terminal control keys",children:"Keys"}),N&&s.jsxs("div",{id:"terminal-control-keys-popover",role:"dialog","aria-label":"Terminal control keys",className:"absolute right-0 top-10 w-72 rounded-2xl border border-white/10 bg-[#0b0d12]/95 p-3 text-white/85 shadow-2xl shadow-black/40 backdrop-blur-md",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-white/45",children:"Terminal keys"}),s.jsx("button",{type:"button",className:"rounded-full px-2 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/10 hover:text-white/85",onClick:()=>C(!1),"aria-label":"Close terminal control keys",children:"×"})]}),s.jsx("div",{className:"mb-2 grid grid-cols-3 gap-1.5",children:[["Ctrl",R,L],["Alt",_,D],["Shift",B,z]].map(([ae,ce,ge])=>s.jsx("button",{type:"button","aria-pressed":ce,className:`h-9 rounded-lg border text-[12px] font-semibold transition-colors ${ce?"border-sky-400/50 bg-sky-400/25 text-white":"border-white/10 bg-white/[0.06] hover:bg-white/[0.12]"}`,onClick:()=>ge($e=>!$e),children:ae},ae))}),s.jsx("div",{className:"grid grid-cols-6 gap-1",children:"abcdefghijklmnopqrstuvwxyz0123456789".split("").map(ae=>s.jsx("button",{type:"button",className:"h-8 rounded-md border border-white/10 bg-white/[0.06] text-[12px] font-semibold uppercase hover:bg-white/[0.12]",onClick:()=>Re(ae),children:ae},ae))}),s.jsx("div",{className:"my-2 h-px bg-white/10"}),s.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Escape"),children:"Esc"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Tab"),children:"Tab"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Enter"),children:"Enter"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowUp"),"aria-label":"Arrow up",children:"↑"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowLeft"),"aria-label":"Arrow left",children:"←"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowDown"),"aria-label":"Arrow down",children:"↓"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("ArrowRight"),"aria-label":"Arrow right",children:"→"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ce(""),title:"Send SIGINT (Ctrl-C)",children:"Ctrl-C"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Space"),children:"Space"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Backspace"),children:"Bksp"})]})]})]}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{V.current=!0,S(ae=>{const ce=Math.max(Je,Number((ae-.1).toFixed(2)));return ce>Je&&Ie(),ce})},title:"Shrink terminal viewport",children:"-"}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{V.current=!0,S(ae=>{const ce=Math.min(le,Number((ae+.1).toFixed(2)));return ce>Je&&Ie(),ce})},title:"Increase terminal viewport",children:"+"})]}),s.jsx("div",{ref:se,className:qe?"w-full h-full overflow-auto rounded-lg overscroll-contain":"w-full h-full overflow-hidden rounded-lg overscroll-contain",children:s.jsx("div",{style:{width:je>0?`${je}px`:"100%",height:at>0?`${at}px`:"100%",minWidth:"100%",minHeight:"100%",position:"relative"},children:s.jsx("div",{style:{width:E.width>0?`${E.width}px`:"100%",height:E.height>0?`${E.height}px`:"100%",position:"absolute",left:0,bottom:0,zoom:y},children:s.jsx(Xd,{ref:r,readOnly:!p||!i,sizingMode:"measured",onViewportMetrics:T,onScrollMetrics:G,onInput:ae=>{!p||(d==null||d(ve,Q,ae))}})})})}),!p&&s.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:h})]}),s.jsx(fu,{contextKey:e.tabKey,panelLabel:ft(e),isSending:a,isBusy:!!Ne,statusMessage:Le,inlineStatusMessage:Le,onSend:async ae=>Ne?!1:n(ae),isActive:c&&i,showControlsToggle:!1,animateVisibility:!1}),M&&s.jsx(Ky,{activeConv:e,onClose:()=>H(!1)})]})}const zy=5e3,Gy=12e3;function Vy(e){return e==="disconnected"||e==="reconnecting"}function qy({wsStatus:e,showReconnected:t,loginUrl:r,onReconnect:n,reconnectDelayMs:a=zy,reconnectActionDelayMs:o=Gy}){const i=Vy(e),[c,d]=l.useState(()=>!i||a<=0),[p,u]=l.useState(()=>!i||o<=0),m=l.useRef(!1);l.useEffect(()=>{if(!i){d(!1);return}if(m.current=!1,a<=0){m.current=!0,d(!0);return}d(!1);const w=setTimeout(()=>{m.current=!0,d(!0)},a);return()=>clearTimeout(w)},[a,i]),l.useEffect(()=>{if(!i){u(!1);return}if(o<=0){u(!0);return}u(!1);const w=setTimeout(()=>{u(!0)},o);return()=>clearTimeout(w)},[o,i]);const h=i?c:e==="offline"||e==="auth_failed",g=!!(n&&e!=="auth_failed"&&(!i||p)),b=l.useMemo(()=>!t||e!=="connected"?!1:a<=0||m.current,[a,t,e]),f=e==="auth_failed"?"red":e==="offline"?"orange":"accent",k={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},j={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},x={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"},v="fixed left-1/2 top-4 z-[var(--z-toast)] flex items-center justify-center pointer-events-none",I={top:"calc(env(safe-area-inset-top, 0px) + 16px)",transform:"translateX(-50%)"};return s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{className:v,style:I,children:s.jsxs("div",{className:"pointer-events-auto max-w-[min(720px,calc(100vw-24px))] rounded-2xl border px-3 py-2.5 sm:px-4 sm:py-3 text-[13px] font-semibold flex flex-wrap items-center gap-x-2.5 gap-y-2 justify-center shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:k[f],border:j[f],color:x[f]},children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5 shrink-0",style:{opacity:e==="auth_failed"?.6:1,animation:e==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:e==="auth_failed"?"grayscale(1)":void 0}}),s.jsxs("span",{className:"min-w-0 text-center whitespace-nowrap",children:[e==="offline"&&"Network offline",e==="disconnected"&&"Reconnecting",e==="reconnecting"&&"Reconnecting",e==="auth_failed"&&(r?s.jsxs(s.Fragment,{children:["Session expired."," ",s.jsx("a",{href:r,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — refresh the page or try again shortly.")]}),g&&s.jsx("button",{type:"button",className:"basis-full sm:basis-auto mx-auto sm:mx-0 sm:ml-1 shrink-0 px-2.5 py-1 rounded-md border border-current/30 text-[12px] font-semibold hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed",onClick:()=>n==null?void 0:n(),disabled:e==="offline",children:"Reconnect now"})]})}),b&&s.jsx("div",{className:v,style:I,children:s.jsxs("div",{className:"pointer-events-none rounded-2xl border px-4 py-2 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-green-500/15 shadow-[0_18px_40px_rgba(2,6,23,0.2)] backdrop-blur-xl animate-[fadeIn_0.3s_ease]",children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})})]})}function Zu({mode:e,onChange:t,compact:r=!1}){const n=r?14:15;return s.jsx("button",{type:"button",onClick:()=>t(e==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:e==="chat"?"Switch to Terminal view":"Switch to Chat view",children:e==="chat"?s.jsx(wi,{size:n}):s.jsx(Xs,{size:n})})}const us="New session",ep="A connected machine is ready. Start a new session with any installed provider — CLI, ACP, or IDE.";function Yy(e){if(!e||e.isGitRepo===!1||e.reason==="not_git_repo")return null;if(e.hasConflicts)return`${e.branch||"Git"} · conflicts${e.changedFiles>0?` ${e.changedFiles}`:""}`;const t=[e.branch||"Git"];return e.changedFiles>0&&t.push(`±${e.changedFiles}`),e.ahead>0&&t.push(`↑${e.ahead}`),e.behind>0&&t.push(`↓${e.behind}`),t.length===1&&e.dirty&&t.push("dirty"),t.join(" ")}function Jy(e){return!e||e.isGitRepo===!1||e.reason==="not_git_repo"?null:e.hasConflicts?"conflict":e.error?"error":e.dirty||e.changedFiles>0||e.ahead>0||e.behind>0?"dirty":"quiet"}function Xy(e){switch(e){case"conflict":return"border-status-error/40 bg-status-error/10 text-status-error";case"error":return"border-yellow-500/25 bg-yellow-500/[0.08] text-yellow-500";case"dirty":return"border-orange-500/25 bg-orange-500/[0.08] text-orange-400";case"quiet":default:return"border-status-online/40 bg-status-online/10 text-status-online"}}function aa({git:e,className:t="",compact:r=!1}){const n=Yy(e),a=Jy(e);if(!n||!a)return null;const o=[e!=null&&e.branch?`Branch: ${e.branch}`:null,e!=null&&e.changedFiles?`Changed files: ${e.changedFiles}`:null,e!=null&&e.ahead?`Ahead: ${e.ahead}`:null,e!=null&&e.behind?`Behind: ${e.behind}`:null,e!=null&&e.hasConflicts?"Conflicts detected":null,e!=null&&e.error?`Git error: ${e.error}`:null].filter(Boolean);return s.jsxs("span",{className:`inline-flex min-w-0 max-w-[12rem] items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none ${Xy(a)} ${t}`.trim(),title:o.join(" · ")||n,"data-git-tone":a,children:[s.jsx("span",{"aria-hidden":"true",children:"⑂"}),s.jsx("span",{className:"truncate",children:n})]})}function Qy({wsStatus:e,isConnected:t,daemonCount:r,p2pStates:n={}}){if(e!=="connected")return{tone:"disconnected",title:"Disconnected",subtitle:null};const a=Object.values(n),o=a.filter(c=>c==="connected").length,i=a.filter(c=>c==="connecting"||c==="new"||c==="checking").length;return r>0&&i>0&&o===0?{tone:"limited",title:"Connected to dashboard",subtitle:"Connecting to machine..."}:t?{tone:"connected",title:"Connected",subtitle:null}:{tone:"limited",title:"Connected to dashboard",subtitle:null}}function uc({value:e}){return e?s.jsx("span",{className:"dashboard-header-shortcut-pill",children:e}):null}function pc({notification:e,shortcutIndex:t,onOpen:r,onMarkRead:n,onMarkUnread:a,onDelete:o}){const i=wa(e.updatedAt),c=!e.readAt;return s.jsxs("div",{className:`dashboard-header-inbox-item ${c?"is-attention":""}`.trim(),children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:r,children:[s.jsx("span",{className:"dashboard-header-inbox-item-title",children:e.title}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[t?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",t]}):null,[e.type==="needs_attention"?"Action needed":"Task complete",i].filter(Boolean).join(" · ")]}),e.preview?s.jsx("span",{className:"dashboard-header-inbox-item-meta dashboard-header-inbox-item-preview",children:e.preview}):null]}),s.jsxs("div",{className:"ml-3 flex shrink-0 items-center gap-1.5",children:[c?s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),n()},children:"Mark read"}):s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),a()},children:"Mark unread"}),s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),o()},children:"Delete"})]})]})}function Zy({activeConv:e,wsStatus:t,isConnected:r,conversations:n,onOpenHistory:a,onOpenRemote:o,onStopCli:i,activeCliViewMode:c,onSetCliViewMode:d,onHideConversation:p,hiddenConversations:u=[],onShowConversation:m,onShowAllHidden:h,onResetPanelsToMain:g,inboxOpen:b,onInboxOpenChange:f,hiddenOpen:k,onHiddenOpenChange:j,onOpenNewSession:x,onOpenDashboardGuide:v,guideNudgeVisible:I=!1,actionShortcuts:w,notifications:y,notificationUnreadCount:S,onOpenNotification:N,onMarkNotificationRead:C,onMarkNotificationUnread:R,onDeleteNotification:L,onOpenGitDialog:_,onOpenMeshGraph:D}){var K;const{ides:B,p2pStates:z={}}=hs(),M=!!e&<(e)&&!it(e),H=!!e&&it(e),Y=!!(e!=null&&e.daemonId)&&!!((K=e==null?void 0:e.coordinator)!=null&&K.meshId),A=c||(e?ku(e)?"terminal":"chat":null),[E,T]=l.useState(!1),[F,G]=l.useState(!1),U=l.useRef(null),te=l.useRef(null),Z=l.useRef(null),se=B.filter($=>$.type==="adhdev-daemon"),V=Qy({wsStatus:t,isConnected:r,daemonCount:se.length,p2pStates:z}),O=V.subtitle,q=V.tone==="connected"?"#22c55e":V.tone==="limited"?"#eab308":"#ef4444",pe=V.tone==="connected"?"0 0 4px #22c55e80":V.tone==="limited"?"0 0 4px #eab30880":"0 0 4px #ef444480",fe=l.useMemo(()=>y.filter($=>!$.readAt),[y]),de=l.useMemo(()=>y.filter($=>!!$.readAt),[y]),ke=l.useMemo(()=>fe.slice(0,9),[fe]),ye=S;l.useEffect(()=>{if(!b)return;const $=J=>{var re;(re=te.current)!=null&&re.contains(J.target)||f(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[b,f]),l.useEffect(()=>{if(!k)return;const $=J=>{var re;(re=Z.current)!=null&&re.contains(J.target)||j(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[k,j]),l.useEffect(()=>{if(!k&&!b)return;const $=J=>{if(!J.altKey)return;const re=J.code.match(/^Digit([1-9])$/);if(!re)return;const be=Number(re[1])-1,ue=k?u[be]:void 0,P=b?ke[be]:void 0;if(!(!ue&&!P)){if(J.preventDefault(),J.stopPropagation(),ue){m==null||m(ue),j(!1);return}P&&(N(P),f(!1))}};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[u,k,b,ke,j,f,N,m]),l.useEffect(()=>{const $=u.length;if(U.current===null){U.current=$;return}$>U.current&&G(!0),U.current=$},[u.length]);const we=()=>G(!1),he=$=>{if(!$)return;const J=n.find(re=>re.tabKey===$);J&&(p==null||p(J))};return s.jsxs("div",{className:"dashboard-header",children:[s.jsx("div",{className:"flex items-center gap-3",children:s.jsx("div",{className:"header-title-block",children:s.jsxs("div",{className:"header-title-row",children:[s.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[s.jsx(Xs,{size:18}),s.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),s.jsx("span",{className:"header-title-mobile",children:e?ft(e):"Dashboard"}),s.jsx("span",{title:V.title,"aria-label":V.title,className:"header-title-status-dot",style:{background:q,boxShadow:pe}}),s.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:s.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:q,boxShadow:pe}})})]}),s.jsxs("div",{className:"header-subtitle flex items-center",children:[O&&s.jsxs("span",{className:"header-subtitle-status mr-2",children:["· ",O]}),x&&s.jsx("button",{type:"button",onClick:x,className:"btn btn-secondary btn-sm ml-2",title:`${us}${w!=null&&w.openNewSession?` (${w.openNewSession})`:""}`,"aria-label":us,children:s.jsx(ji,{size:14})})]})]})})}),s.jsxs("div",{className:"flex gap-2 items-center",children:[v&&s.jsxs("button",{type:"button",onClick:v,className:"btn btn-secondary btn-sm hidden md:inline-flex items-center gap-1.5 dashboard-header-guide-button",title:"Dashboard guide","aria-label":"Open dashboard guide",children:[s.jsx("span",{className:"font-semibold leading-none",children:"?"}),I&&s.jsx("span",{children:"Guide"})]}),e&&(M||H||!it(e))&&s.jsxs("div",{className:"dashboard-header-actions-group",children:[s.jsx("span",{className:"dashboard-header-action-target",title:xr(e)||ft(e),children:ft(e)}),_&&e.git&&e.daemonId&&e.workspacePath?s.jsx("button",{type:"button",className:"appearance-none bg-transparent border-0 p-0 cursor-pointer",title:"Open git status",onClick:()=>_(e.daemonId,e.workspacePath),children:s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"})}):s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"}),Y&&D&&s.jsxs("button",{type:"button",onClick:()=>D(e),className:"btn btn-secondary btn-sm dashboard-header-mesh-button",title:"Open live repo mesh graph",children:[s.jsx(ss,{size:14}),s.jsx("span",{className:"hidden lg:inline",children:"Mesh graph"})]}),(M||H)&&i&&s.jsxs(s.Fragment,{children:[M&&d&&A&&s.jsx(Zu,{mode:A,onChange:d,compact:!0}),s.jsx("button",{onClick:()=>i(e),className:"btn btn-secondary btn-sm",title:H?"Stop ACP session":"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(wt,{size:14})})]}),!it(e)&&s.jsx("button",{onClick:()=>a(e),className:"btn btn-secondary btn-sm",title:"Chat History",children:s.jsx(yi,{size:14})}),!M&&!it(e)&&s.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Remote Control",children:s.jsx(os,{size:14})})]}),s.jsxs("div",{className:"dashboard-header-inbox",ref:te,children:[s.jsxs("div",{className:`dashboard-header-hidden${E?" is-drop-target":""}${F?" hidden-spawn-flash":""}`,onAnimationEnd:we,ref:Z,onDragEnter:$=>{$.dataTransfer.types.includes("text/tab-key")&&($.preventDefault(),T(!0))},onDragOver:$=>{$.dataTransfer.types.includes("text/tab-key")&&($.preventDefault(),$.dataTransfer.dropEffect="move",T(!0))},onDragLeave:$=>{$.currentTarget.contains($.relatedTarget)||T(!1)},onDrop:$=>{const J=$.dataTransfer.getData("text/tab-key");$.preventDefault(),T(!1),he(J)},children:[s.jsxs("button",{type:"button",onClick:()=>j(!k),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:`Hidden tabs${w!=null&&w.toggleHiddenTabs?` (${w.toggleHiddenTabs})`:""}. Drag a tab here to hide it.`,children:[s.jsx(vi,{size:16}),u.length>0&&s.jsx("span",{className:`dashboard-header-hidden-badge${F?" hidden-badge-pop":""}`,children:u.length})]}),k&&s.jsxs("div",{className:"dashboard-header-hidden-popover",children:[s.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),s.jsx(uc,{value:w==null?void 0:w.toggleHiddenTabs})]}),s.jsxs("div",{className:"dashboard-header-hidden-actions",children:[g&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:g,children:"Reset panels"}),u.length>0&&h&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{h(),j(!1)},children:"Restore all"})]})]}),e&&p&&s.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>p(e),children:[s.jsxs("span",{className:"dashboard-header-hidden-current-leading",children:[s.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),s.jsx(uc,{value:w==null?void 0:w.hideCurrentTab})]}),s.jsx("span",{className:"dashboard-header-hidden-current-title",children:ft(e)})]}),u.length>0?s.jsx("div",{className:"dashboard-header-hidden-list",children:u.map($=>s.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{m==null||m($),j(!1)},children:[s.jsxs("span",{className:"dashboard-header-inbox-item-title",children:[$.status==="generating"&&s.jsx("span",{className:"tab-spinner dashboard-header-inbox-item-spinner","aria-label":"generating"}),ft($)]}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[u.indexOf($)<9?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",u.indexOf($)+1]}):null,xr($)]})]},$.tabKey))}):s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),s.jsxs("button",{type:"button",onClick:()=>f(!b),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[s.jsx(jr,{size:16}),ye>0&&s.jsx("span",{className:"dashboard-header-inbox-badge",children:ye})]}),b&&s.jsxs("div",{className:"dashboard-header-inbox-popover",children:[fe.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Unread"}),fe.map($=>s.jsx(pc,{notification:$,shortcutIndex:ke.indexOf($)>=0?ke.indexOf($)+1:void 0,onOpen:()=>N($),onMarkRead:()=>C($.id),onMarkUnread:()=>R($.id),onDelete:()=>L($.id)},$.id))]}),de.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Read"}),de.map($=>s.jsx(pc,{notification:$,onOpen:()=>N($),onMarkRead:()=>C($.id),onMarkUnread:()=>R($.id),onDelete:()=>L($.id)},$.id))]}),y.length===0&&s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Dt(e={}){return{textQuery:e.textQuery||"",workspaceQuery:e.workspaceQuery||"",modelQuery:e.modelQuery||"",resumableOnly:!!e.resumableOnly,sortMode:e.sortMode||"recent"}}function e0(e,t){return String(e||"")!==String(t||"")}function t0(e,t={}){const r=String(t.textQuery||"").trim().toLowerCase(),n=String(t.workspaceQuery||"").trim().toLowerCase(),a=String(t.modelQuery||"").trim().toLowerCase(),o=!!t.resumableOnly;return!r&&!n&&!a&&!o?e:e.filter(i=>!(o&&!i.canResume||r&&![i.title,i.preview].map(d=>String(d||"").toLowerCase()).join(`
|
|
52
52
|
`).includes(r)||n&&!String(i.workspace||"").toLowerCase().includes(n)||a&&!cu(i.summaryMetadata).map(d=>d.toLowerCase()).join(`
|
|
53
53
|
`).includes(a)))}function s0(e,t="recent"){const r=e.slice();return r.sort((n,a)=>{if(t==="oldest")return(Number(n.lastMessageAt)||0)-(Number(a.lastMessageAt)||0);if(t==="messages"){const o=(Number(a.messageCount)||0)-(Number(n.messageCount)||0);if(o!==0)return o}return(Number(a.lastMessageAt)||0)-(Number(n.lastMessageAt)||0)}),r}function tp(e,t={}){return s0(t0(e,t),t.sortMode||"recent")}function oa(e){return e?"Resume saved history":"Start fresh"}function Bi(e){return e?"Resuming saved history…":"Starting fresh…"}function r0(){return"Start fresh"}function n0(e,t=!1){return e==="cli"?oa(t):e==="ide"?"Start IDE":"Start ACP session"}function a0(e,t=!1){return e==="cli"?Bi(t):e==="ide"?"Starting IDE…":"Starting ACP session…"}function o0(){return"Fallback recovery for hosted runtimes after interruptions. For normal continuity, open saved history instead."}function i0(){return"Open saved history"}function l0(){return"Saved History"}function Fi(){return"Use saved history when you want continuity in the same provider conversation."}function c0(){return"No saved history found yet."}function d0(){return"Refresh saved history"}function u0(){return"Refreshing saved history…"}function ia(e,t){return e==="start-fresh"?`Start fresh with ${t}?`:`Restart ${t}?`}function la(e){return e==="start-fresh"?"Review the provider and target folder before starting fresh.":e==="restart-ide"?"Review or change the target workspace before restarting this IDE.":"Review or change the target workspace before restarting this stopped session."}function ca(e){return e==="start-fresh"?"Start fresh":"Restart"}function da(e){return e==="start-fresh"?"Starting fresh…":"Restarting…"}function sp(e){return`Resume saved history with ${e}?`}function rp(){return"Review or change the target workspace before resuming saved history."}function p0(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 np({activeConv:e,ides:t,isCreatingChat:r,isRefreshingHistory:n,savedSessions:a=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:i=null,savedHistoryFilters:c,missingWorkspaceResumePath:d,onSavedHistoryFiltersChange:p,onClose:u,onNewChat:m,onSwitchSession:h,onRefreshHistory:g,onResumeSavedSession:b}){var L;const f=t.find(_=>_.id===e.routeId),k=(f==null?void 0:f.chats)||[],j=(L=f==null?void 0:f.activeChat)==null?void 0:L.id,x=lt(e)&&!it(e),[v,I]=l.useState(()=>Dt()),w=c||v,y=String(d||"").trim(),S=_=>{if(p){p(_);return}I(_)},N=l.useMemo(()=>a.map(_=>{const D=String(_.workspace||"").trim();return _.canResume||D||!y?_:{..._,workspace:y,canResume:!0,workspaceFallbackSource:"selected-workspace"}}),[y,a]),C=l.useMemo(()=>tp(N,{textQuery:w.textQuery,workspaceQuery:w.workspaceQuery,modelQuery:w.modelQuery,resumableOnly:w.resumableOnly,sortMode:w.sortMode}),[N,w.modelQuery,w.resumableOnly,w.sortMode,w.textQuery,w.workspaceQuery]),R=s.jsxs("div",{className:"fixed inset-0 z-[var(--z-modal)] 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",{onClick:u,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),s.jsxs("div",{className:"card fade-in relative w-full sm:w-[90%] max-w-[500px] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[24px] sm:rounded-[20px]",children:[s.jsxs("div",{className:"px-4 py-4 sm:px-6 sm:py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)] shrink-0",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"m-0 text-lg font-extrabold",children:x?l0():"Chat History"}),s.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:Ly(e)}),x&&s.jsx("div",{className:"text-[11px] text-text-muted mt-1",children:Fi()})]}),s.jsx("button",{onClick:u,className:"btn btn-secondary btn-sm rounded-md px-1.5 py-1.5 border-transparent bg-transparent hover:bg-bg-secondary",children:s.jsx(wt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-3 bg-bg-primary",children:[!x&&s.jsx("button",{onClick:m,disabled:r,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:r?"⌛ Creating...":"+ Start New Chat Session"}),x?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-[var(--surface-secondary)] p-3 mb-3",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-2",children:[s.jsx("input",{type:"text",value:w.textQuery,onChange:_=>S({...w,textQuery:_.target.value}),placeholder:"Search title or preview",className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("input",{type:"text",value:w.workspaceQuery,onChange:_=>S({...w,workspaceQuery:_.target.value}),placeholder:"Filter by workspace",className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("input",{type:"text",value:w.modelQuery,onChange:_=>S({...w,modelQuery:_.target.value}),placeholder:"Filter by model",className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsxs("select",{value:w.sortMode,onChange:_=>S({...w,sortMode:_.target.value}),className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary",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:"mt-2 flex items-center gap-2 text-[11px] text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:w.resumableOnly,onChange:_=>S({...w,resumableOnly:_.target.checked})}),"Resume-ready only"]})]}),C.map(_=>{const D=e.providerSessionId===_.providerSessionId,B=D||!_.canResume||!!i,z=_.workspaceFallbackSource==="selected-workspace";return s.jsxs("button",{type:"button",onClick:()=>{B||!b||b(_)},disabled:B,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${D?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${B?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:`font-bold text-sm mb-1 truncate ${D?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:_.providerSessionId})]}),s.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:p0(_.lastMessageAt)})]}),s.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:_.preview||"No saved preview yet"}),s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[s.jsxs("div",{className:"truncate",children:[_.workspace||"Workspace unknown",z?" · selected workspace":"",qs(_.summaryMetadata)?` · ${qs(_.summaryMetadata)}`:"",_.messageCount>0?` · ${_.messageCount} msgs`:""]}),s.jsx("div",{className:"shrink-0",children:D?"ACTIVE":_.canResume?z?"RESUME IN SELECTED WORKSPACE":i===_.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},_.id)})]}):k.map(_=>s.jsxs("div",{onClick:()=>{h(e.routeId,_.id),u()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${j===_.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[s.jsx("div",{className:`font-bold text-sm mb-1 ${j===_.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[_.id.substring(0,12),"..."]}),j===_.id&&s.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},_.id)),(x&&!o&&C.length===0||!x&&k.length===0)&&s.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[s.jsx("div",{className:"text-3xl mb-3 opacity-60",children:s.jsx(If,{size:32})}),s.jsx("div",{className:"text-[13px]",children:x?a.length>0?"No saved history matches these filters.":c0():"No recent chat sessions found."})]}),x&&o&&s.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:s.jsx("div",{className:"text-[13px]",children:u0()})})]}),s.jsx("div",{className:"px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right shrink-0",children:s.jsx("button",{onClick:g,disabled:n||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||o?"⌛ Refreshing...":s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(va,{size:13})," ",x?d0():"Refresh History"]})})})]})]});return typeof document>"u"?R:ur.createPortal(R,document.body)}const mc={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Done"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Attention"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Update"}};function ap({toasts:e,onDismiss:t,onClickToast:r}){return s.jsx("div",{className:"fixed right-4 z-[var(--z-toast)] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:e.map(n=>{const a=mc[n.type]||mc.info;return s.jsxs("div",{className:"fade-in pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[380px] relative group overflow-hidden rounded-[16px] border shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:"color-mix(in srgb, var(--surface-primary) 94%, var(--bg-secondary) 6%)",borderColor:"color-mix(in srgb, var(--border-default) 88%, transparent)",color:"var(--text-primary)"},onClick:()=>{var o;(o=n.actions)!=null&&o.length||r&&r(n)},children:[s.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${a.accent}, color-mix(in srgb, ${a.accent} 55%, transparent))`}}),s.jsx("button",{className:"absolute top-2 right-2 w-7 h-7 rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-glass transition-colors leading-none cursor-pointer",onClick:o=>{o.stopPropagation(),t(n.id)},"aria-label":"Dismiss",children:s.jsx(wt,{size:14})}),s.jsxs("div",{className:"px-4 py-3.5 pl-5",children:[s.jsx("div",{className:"flex items-center gap-2 pr-8",children:s.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-[0.08em]",style:{background:a.chipBg,color:a.chipText,border:`1px solid color-mix(in srgb, ${a.accent} 22%, transparent)`},children:a.label})}),s.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:n.message}),n.actions&&n.actions.length>0&&s.jsx("div",{className:"flex gap-2 mt-3",children:n.actions.map((o,i)=>s.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${o.variant==="primary"||o.variant==="danger",""}`,style:o.variant==="primary"?{background:"color-mix(in srgb, var(--accent-primary) 12%, var(--surface-primary))",color:"var(--text-primary)",borderColor:"color-mix(in srgb, var(--accent-primary) 26%, transparent)"}:o.variant==="danger"?{background:"color-mix(in srgb, var(--status-error) 10%, var(--surface-primary))",color:"var(--status-error)",borderColor:"color-mix(in srgb, var(--status-error) 22%, transparent)"}:{background:"var(--surface-secondary)",color:"var(--text-secondary)",borderColor:"var(--border-subtle)"},onClick:c=>{c.stopPropagation(),o.onClick(),t(n.id)},children:o.label},i))})]})]},n.id)})})}const m0=e=>e.transport==="pty"||e.transport==="acp"||e.transport==="cdp-page"?!0:e.daemonId!==e.id;function h0(e){const t=e.workspace||"";if(!t)return"";const r=t.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:t}function f0(e,t){return op(e)||t}function op(e){var a,o,i;const t=(o=(a=e.summaryMetadata)==null?void 0:a.items)==null?void 0:o.find(c=>(c==null?void 0:c.id)==="model"),r=((t==null?void 0:t.value)||(t==null?void 0:t.shortValue)||"").trim();if(r)return r;const n=(i=e.controlValues)==null?void 0:i.model;return typeof n=="string"&&n.trim()?n.trim():""}function x0(e){return op(e)||void 0}function b0(e){return e.sessionId||e.instanceId||e.agentType}function ip(e=[]){const t={};for(const r of e)r.type==="adhdev-daemon"&&(t[r.id]=Yt(r,{fallbackId:r.id}));return t}function lp(e,t={}){var n;const r=e.daemonId||((n=e.id)==null?void 0:n.split(":")[0])||e.id;return{machineName:Dx(e,t.machineNames),connectionState:t.connectionStates?t.connectionStates[r]||t.defaultConnectionState||"new":t.defaultConnectionState}}function Oi(e,t={}){return g0(e,lp(e,t))}function g0(e,t={}){var h,g,b,f,k,j,x,v,I;const r=[],n=t.machineName,a=t.connectionState,o=h0(e),i=e.workspace||"",c=Hx(e.type,{agentName:e.cliName}),d=lt(e)||it(e)?c:Tt(e.type),p=f0(e,d),u=Array.isArray(e.childSessions)?e.childSessions.map(w=>{var y,S,N;return{sessionId:w.id,instanceId:w.id,providerSessionId:w.providerSessionId,activeChatId:(y=w.activeChat)==null?void 0:y.id,transport:w.transport,sessionCapabilities:w.capabilities,agentType:w.providerType,agentName:w.providerName||Tt(w.providerType),model:x0(w),status:w.status,title:w.title,lastMessagePreview:w.lastMessagePreview,lastMessageRole:w.lastMessageRole,lastMessageAt:w.lastMessageAt,lastMessageHash:w.lastMessageHash,messages:((S=w.activeChat)==null?void 0:S.messages)||[],activeModal:((N=w.activeChat)==null?void 0:N.activeModal)||void 0,unread:w.unread,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,inboxBucket:w.inboxBucket,completionMarker:w.completionMarker,surfaceHidden:w.surfaceHidden,muted:w.muted,git:w.git,settings:w.settings,coordinator:w.coordinator,messageInput:w.messageInput}}):[],m=m0(e);if(m){const w=e.sessionId||e.instanceId,y=(h=e.settings)==null?void 0:h.meshCoordinatorFor,S=((g=e.settings)==null?void 0:g.meshNodeFor)||!((b=e.settings)!=null&&b.meshCoordinatorFor)&&((f=e.settings)==null?void 0:f.launchedByCoordinator),N=y?" (Coordinator)":S?" (Mesh Node)":"",C=c+N,R=(k=e.activeChat)==null?void 0:k.activeModal,L=R&&Array.isArray(R.buttons)&&R.buttons.length>0,_=Wx(e.activeChat,[{status:e.status,activeModal:(j=e.activeChat)==null?void 0:j.activeModal}],e.agents||[]),D=e.activeChat||{title:"",messages:[]};let B=D.title&&String(D.title).trim()?String(D.title).trim():"";const z=(x=e.activeChat)==null?void 0:x.id,M=e.chats;if(z&&Array.isArray(M)&&M.length>0){const U=M.find(te=>te.id===z||te.id&&String(te.id)===String(z));U!=null&&U.title&&String(U.title).trim()&&(B=String(U.title).trim())}const H=(lt(e)||it(e),e.type),Y=(lt(e)||it(e))&&El(B,C,H)?"":B,A=D.messages||[],E=typeof z=="string"?z.trim():"",T=(lt(e)||it(e))&&E===String(e.type||"").trim(),F=E&&!T?E:e.providerSessionId,G=e.coordinator||(typeof((v=e.settings)==null?void 0:v.meshCoordinatorFor)=="string"&&e.settings.meshCoordinatorFor?{meshId:e.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.push({routeId:e.id,sessionId:w,providerSessionId:e.providerSessionId,historySessionId:F,nativeSessionId:w,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:lt(e)&&e.mode||"chat",agentName:C,agentType:H,status:_,title:Y,messages:A,resume:e.resume,hostIdeType:!lt(e)&&!it(e)?e.type:void 0,workspaceName:o,workspacePath:i,git:e.git,displayPrimary:o||Y||(lt(e)?e.mode==="chat"?C:`Terminal${N}`:C),displaySecondary:p,cdpConnected:e.cdpConnected,lastMessagePreview:e.lastMessagePreview,lastMessageRole:e.lastMessageRole,lastMessageAt:e.lastMessageAt,lastMessageHash:e.lastMessageHash,lastUpdated:e.lastUpdated,inboxBucket:e.inboxBucket,completionMarker:e.completionMarker,modalButtons:L?R.buttons:void 0,modalMessage:L?R.message:void 0,streamSource:"native",tabKey:Ga(w,e.id),machineName:n,connectionState:a,settings:e.settings,coordinator:G,messageInput:e.messageInput})}if(m&&(lt(e)||it(e)))return r;for(const w of u){const y=w.activeModal&&Array.isArray(w.activeModal.buttons)&&w.activeModal.buttons.length>0,S=Kx(w),N=b0(w),C=`${e.id}:${N}`,R=w.title&&String(w.title).trim()||"",L=El(R,w.agentName,w.agentType)?"":R,_=w.messages||[];if(!(w.transport==="cdp-webview"||!!w.sessionId||!!w.providerSessionId||_.length>0||y||!!L||!["idle","panel_hidden","disconnected","not_monitored"].includes(S)))continue;const B=w.coordinator||(typeof((I=w.settings)==null?void 0:I.meshCoordinatorFor)=="string"&&w.settings.meshCoordinatorFor?{meshId:w.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.push({routeId:e.id,sessionId:w.sessionId||w.instanceId,providerSessionId:w.providerSessionId,historySessionId:w.activeChatId||w.providerSessionId,nativeSessionId:e.sessionId||e.instanceId,transport:w.transport||"cdp-webview",daemonId:e.daemonId||void 0,sessionCapabilities:w.sessionCapabilities,mode:"chat",agentName:w.agentName,agentType:w.agentType,status:S,title:L,messages:_,hostIdeType:e.type,workspaceName:o,workspacePath:i,git:w.git||e.git,displayPrimary:o||L||w.agentName||d,displaySecondary:w.model&&w.model.trim()?w.model.trim():`${d} · ${w.agentName}`,cdpConnected:e.cdpConnected,lastMessagePreview:w.lastMessagePreview,lastMessageRole:w.lastMessageRole,lastMessageAt:w.lastMessageAt,lastMessageHash:w.lastMessageHash,lastUpdated:w.lastUpdated||e.lastUpdated,inboxBucket:w.inboxBucket,completionMarker:w.completionMarker,modalButtons:y?w.activeModal.buttons:void 0,modalMessage:y?w.activeModal.message:void 0,streamSource:"agent-stream",tabKey:Ga(w.sessionId||w.instanceId,C),machineName:n,connectionState:a,settings:w.settings,coordinator:B,messageInput:w.messageInput})}return r.length===0&&r.push({routeId:e.id,sessionId:e.sessionId||e.instanceId,providerSessionId:e.providerSessionId,nativeSessionId:e.sessionId||e.instanceId,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:"chat",agentName:c,agentType:"ide-native",status:"idle",title:"",messages:[],hostIdeType:e.type,workspaceName:o,workspacePath:i,git:e.git,displayPrimary:o||d,displaySecondary:p,cdpConnected:e.cdpConnected,lastUpdated:e.lastUpdated,streamSource:"native",tabKey:Ga(e.sessionId||e.instanceId,e.id),connectionState:a,settings:e.settings,messageInput:e.messageInput}),r}function cp(e){return String(e.type||e.id||"").trim()}function ua(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!!t.trim()).map(t=>t.trim()):[]}function y0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.modelOptions)}function v0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.thinkingLevelOptions)}function dp(e){const t=new Map;for(const r of e||[])r!=null&&r.type&&t.set(r.type,{models:ua(r.modelOptions),thinking:ua(r.thinkingLevelOptions)});return t}function w0(e){var t;return e.category!=="cli"||!cp(e)||e.enabled===!1?!1:e.machineStatus?e.machineStatus==="detected":((t=e.lastDetection)==null?void 0:t.ok)===!0||e.installed===!0||!!e.detectedPath}function br(e){var n;const t=new Set,r=[];for(const a of e||[]){if(!w0(a))continue;const o=cp(a);if(!o||t.has(o))continue;t.add(o);const i=String(a.displayName||a.name||o),c=a.detectedPath||((n=a.lastDetection)==null?void 0:n.path)||null;r.push({type:o,label:i,icon:a.icon,statusLabel:c?`Detected at ${c}`:"Detected on this machine",detectedPath:c,...Array.isArray(a.modelOptions)&&a.modelOptions.length?{modelOptions:a.modelOptions}:{},...Array.isArray(a.thinkingLevelOptions)&&a.thinkingLevelOptions.length?{thinkingLevelOptions:a.thinkingLevelOptions}:{}})}return r}function gr(e){const t=Array.isArray(e)?e:typeof e=="string"?e.split(/[\s,]+/):[],r=new Set,n=[];for(const a of t){const o=typeof a=="string"?a.trim():"";!o||r.has(o)||(r.add(o),n.push(o))}return n}function nn(e){return e.map(t=>t.type)}function j0(e,t){const r=gr(e),n=t.trim();return!n||r.includes(n)?r:[...r,n]}function k0(e,t){return gr(e).filter(r=>r!==t)}function hc(e,t,r){const n=gr(e),a=n.indexOf(t);if(a<0)return n;const o=n.filter(c=>c!==t);if(r==="top")return[t,...o];if(r==="bottom")return[...o,t];const i=r==="up"?Math.max(0,a-1):Math.min(o.length,a+1);return o.splice(i,0,t),o}function fc({direction:e}){return s.jsx("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e==="up"?s.jsx("polyline",{points:"18 15 12 9 6 15"}):s.jsx("polyline",{points:"6 9 12 15 18 9"})})}function N0({value:e,availableProviders:t,onChange:r,disabled:n=!1,saveButton:a}){const[o,i]=l.useState(""),c=l.useMemo(()=>new Map(t.map(h=>[h.type,h])),[t]),d=l.useMemo(()=>gr(e),[e]),p=d.filter(h=>!c.has(h)).length,u=t.filter(h=>!d.includes(h.type)),m=()=>{o&&(r(j0(d,o)),i(""))};return s.jsxs("div",{className:"rounded-lg border border-border-subtle bg-bg-secondary/60 p-3",children:[s.jsx("div",{className:"flex flex-col gap-2",children:d.length===0?s.jsx("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-300",children:"No provider priority configured. Launches without an explicit CLI provider will fail closed."}):d.map((h,g)=>{const b=c.get(h),f=!!b;return s.jsxs("div",{className:`flex flex-col gap-2 rounded-md border border-border-subtle px-3 py-2 sm:flex-row sm:items-center sm:justify-between ${f?"bg-bg-primary":"bg-bg-primary/40"}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("span",{className:"text-[10px] font-semibold text-text-muted",children:["#",g+1]}),(b==null?void 0:b.icon)&&s.jsx("span",{"aria-hidden":"true",children:b.icon}),s.jsx("span",{className:`font-mono text-[12px] ${f?"text-text-primary":"text-text-muted"}`,children:h}),f?s.jsx("span",{className:"rounded border border-green-500/20 bg-green-500/10 px-1.5 py-px text-[9px] font-semibold text-green-400",children:"available"}):s.jsx("span",{className:"rounded border border-amber-500/25 bg-amber-500/10 px-1.5 py-px text-[9px] font-semibold text-amber-400",children:"not on this machine"})]}),s.jsx("div",{className:"mt-1 text-[10px] text-text-muted",children:b?`${b.label} · ${b.statusLabel}`:"Kept in order; skipped at launch until detected here."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex h-8 w-8 items-center justify-center p-0","aria-label":"Move up",disabled:n||g===0,title:"Move up",onClick:()=>r(hc(d,h,"up")),children:s.jsx(fc,{direction:"up"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex h-8 w-8 items-center justify-center p-0","aria-label":"Move down",disabled:n||g===d.length-1,title:"Move down",onClick:()=>r(hc(d,h,"down")),children:s.jsx(fc,{direction:"down"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm text-red-400",disabled:n,onClick:()=>r(k0(d,h)),children:"Remove"})]})]},h)})}),s.jsxs("div",{className:"mt-3 flex flex-col gap-2 sm:flex-row sm:items-end",children:[s.jsxs("label",{className:"flex-1 text-[11px] text-text-secondary",children:[s.jsx("span",{className:"mb-1 block font-medium text-text-primary",children:"Add available CLI provider"}),s.jsxs("select",{className:"w-full rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2 text-sm text-text-primary",value:o,onChange:h=>i(h.target.value),disabled:n||u.length===0,children:[s.jsx("option",{value:"",children:u.length?"Select provider…":"No additional detected CLI providers"}),u.map(h=>s.jsxs("option",{value:h.type,children:[h.label," (",h.type,")"]},h.type))]})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:n||!o,onClick:m,children:"Add provider"}),a]}),s.jsxs("div",{className:"mt-2 text-[11px] text-text-muted",children:["Launches use this order, top to bottom.",p>0?` ${p} provider${p===1?"":"s"} not detected here — kept in order, skipped until available.`:""]})]})}function S0(e){const t=e.split(":");return t.length>=3&&(t[1]==="ide"||t[1]==="cli"||t[1]==="acp")?{daemonId:t[0],targetSessionId:t.slice(2).join(":")||void 0}:{daemonId:e}}function up(e,t){const r=S0(e);return{daemonId:r.daemonId,payload:{...t,...r.targetSessionId&&!t.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const pp=[{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"trae",name:"Trae",icon:"🔮"},{id:"vscode",name:"VS Code",icon:"💙"},{id:"vscodium",name:"VSCodium",icon:"💚"},{id:"windsurf",name:"Windsurf",icon:"🏄"}],mp=[{id:"antigravity-cli",name:"Antigravity CLI",icon:"🪐"},{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"hermes-cli",name:"Hermes",icon:"⚕️"},{id:"kimi",name:"Kimi",icon:"🌙"},{id:"opencode",name:"OpenCode CLI",icon:"◆"}],hp=[{id:"cline",name:"Cline",icon:"🧠"},{id:"codex",name:"Codex",icon:"📦"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"claude-code-vscode",name:"Claude Code (VS Code)",icon:"🟠"}],C0=pp,I0=mp,A0=hp;function M0({icon:e,title:t,subtitle:r,badge:n,actions:a,className:o}){return s.jsxs("div",{className:$t("dashboard-header",o),children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"header-title flex items-center gap-2",children:[s.jsx("span",{className:"flex items-center text-lg",children:e})," ",t,n&&s.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&s.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),a&&s.jsx("div",{className:"flex gap-2",children:a})]})}function mn({icon:e,title:t,subtitle:r,badge:n,actions:a,widthClassName:o="max-w-6xl",contentClassName:i,children:c}){return s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(M0,{icon:e,title:t,subtitle:r,badge:n,actions:a}),s.jsx("div",{className:"page-content",children:s.jsx("div",{className:$t("mx-auto flex w-full flex-col gap-4",o,i),children:c})})]})}const Zo="adhdev:themechange";function _0(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function ar(){try{const e=localStorage.getItem("theme");if(e==="dark"||e==="light"||e==="system")return e}catch{}return"system"}function or(e){return e==="system"?_0():e}function fp(e){typeof document>"u"||(document.documentElement.setAttribute("data-theme",e),document.documentElement.style.colorScheme=e)}function Wn(e,t){typeof window>"u"||window.dispatchEvent(new CustomEvent(Zo,{detail:{preference:e,theme:t}}))}function T0(){const e=ar(),t=or(e);fp(t),Wn(e,t)}function Ts(){const[e,t]=l.useState(ar),[r,n]=l.useState(()=>or(ar()));l.useEffect(()=>{fp(r)},[r]),l.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),c=d=>{if(e==="system"){const p=d.matches?"light":"dark";n(p),Wn("system",p)}};return i.addEventListener("change",c),()=>i.removeEventListener("change",c)},[e]),l.useEffect(()=>{const i=d=>{const p=d.detail||{},u=p.preference,m=p.theme;t(u==="dark"||u==="light"||u==="system"?u:ar()),n(m==="dark"||m==="light"?m:or(ar()))},c=d=>{if(d.key!=="theme")return;const p=ar(),u=or(p);t(p),n(u)};return window.addEventListener(Zo,i),window.addEventListener("storage",c),()=>{window.removeEventListener(Zo,i),window.removeEventListener("storage",c)}},[]);const a=l.useCallback(i=>{const c=or(i);t(i),n(c);try{localStorage.setItem("theme",i)}catch{}Wn(i,c)},[]),o=l.useCallback(()=>{t(i=>{const c=i==="dark"?"light":i==="light"?"system":"dark",d=or(c);n(d);try{localStorage.setItem("theme",c)}catch{}return Wn(c,d),c})},[]);return{theme:r,preference:e,setPreference:a,cycleTheme:o,isDark:r==="dark"}}const xc={dark:"Dark",light:"Light",system:"System"};function L0({collapsed:e}){const{preference:t,cycleTheme:r}=Ts(),n=t==="dark"?s.jsx(Mf,{size:16}):t==="light"?s.jsx(Af,{size:16}):s.jsx(_f,{size:16});return s.jsxs("div",{className:`nav-item cursor-pointer ${e?"justify-center py-2.5 px-0":""}`,onClick:r,title:`Theme: ${xc[t]} (click to cycle)`,children:[s.jsx("span",{className:"nav-icon",children:n}),!e&&s.jsx("span",{className:"text-xs",children:xc[t]})]})}function to(e,t){return e?typeof e=="function"?e(t):e:null}function R0({children:e,brand:t,navItems:r,sidebarSections:n=[],footerItems:a=[],footerInfo:o,footerActions:i,preMainContent:c,collapsedStorageKey:d="sidebar-collapsed"}){const[p,u]=l.useState(!1),[m,h]=l.useState(()=>{try{return localStorage.getItem(d)==="1"}catch{return!1}}),g=()=>u(!0),b=()=>u(!1),f=()=>{h(v=>{const I=!v;try{localStorage.setItem(d,I?"1":"0")}catch{}return I})},k=l.useMemo(()=>({collapsed:m,mobileMenuOpen:p,openMobileMenu:g,closeMobileMenu:b,toggleCollapsed:f}),[m,p]),j=v=>`nav-item${v.active?" active":""} cursor-pointer ${m?"justify-center py-2.5 px-0":""}${v.className?` ${v.className}`:""}`,x=v=>s.jsxs("div",{className:j(v),id:`nav-${v.id}`,onClick:()=>{v.onSelect(),b()},title:m?v.title??(typeof v.label=="string"?v.label:void 0):v.title,children:[s.jsx("span",{className:"nav-icon",children:v.icon}),!m&&v.label]},v.id);return s.jsxs("div",{className:`app-layout${p?" mobile-menu-open":""}${m?" sidebar-collapsed":""}`,children:[s.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:g,children:[s.jsx("span",{className:"mobile-menu-icon"}),s.jsx("span",{className:"mobile-menu-icon"}),s.jsx("span",{className:"mobile-menu-icon"})]}),p&&s.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:b,onKeyDown:v=>v.key==="Escape"&&b()}),s.jsxs("aside",{className:`sidebar ${p?"sidebar-open":""}`,children:[s.jsxs("div",{className:"sidebar-header",children:[s.jsx("div",{className:`sidebar-logo ${m?"justify-center gap-0":""}`,children:to(t,k)}),s.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:b,children:s.jsx(wt,{size:16})})]}),s.jsx("nav",{className:"sidebar-nav",children:r.map(x)}),n.map(v=>s.jsxs("div",{className:v.className??"border-t border-border-subtle pt-2 mt-2",children:[!m&&v.title?s.jsx("div",{className:"px-3 py-1 text-[10px] text-text-muted uppercase tracking-widest",children:v.title}):null,v.items.map(x)]},v.key)),s.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[a.map(x),to(o,k),s.jsx(L0,{collapsed:m}),to(i,k)]})]}),s.jsx("main",{className:"main-content relative",children:s.jsxs("div",{className:"main-content-inner",children:[c,e]})})]})}function mt({title:e,icon:t,description:r,accentColor:n,className:a,collapsible:o,defaultOpen:i=!0,badge:c,children:d}){const[p,u]=l.useState(i),m=o?p:!0,h=(e||r)&&s.jsxs("div",{className:$t("flex items-start justify-between gap-3",m&&"mb-4"),children:[s.jsxs("div",{className:"min-w-0",children:[e&&s.jsxs("h3",{className:"text-base font-semibold text-text-primary flex items-center gap-1.5",children:[t&&s.jsx("span",{children:t}),s.jsx("span",{children:e}),c]}),r&&s.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o&&s.jsx("span",{className:$t("mt-0.5 shrink-0 text-text-muted transition-transform select-none",m?"rotate-90":"rotate-0"),"aria-hidden":!0,children:"▸"})]});return s.jsxs("div",{className:$t("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",a),style:n?{borderLeftColor:n}:void 0,children:[o&&h?s.jsx("button",{type:"button",className:"w-full bg-transparent border-none p-0 text-left cursor-pointer",onClick:()=>u(g=>!g),"aria-expanded":m,children:h}):h,m&&d]})}function _a({icon:e,title:t,description:r,action:n,className:a}){return s.jsxs("div",{className:$t("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),children:[s.jsx("div",{className:"text-5xl mb-4 opacity-50",children:e}),s.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:t}),s.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:r}),n]})}const P0={error:"bg-red-500/10 border-red-500/30 text-red-400",warning:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400",success:"bg-green-500/10 border-green-500/30 text-green-400",info:"bg-indigo-500/10 border-indigo-500/30 text-indigo-400"},D0={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Ft({variant:e,children:t,onDismiss:r,className:n}){return s.jsxs("div",{className:$t("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",P0[e],n),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{children:D0[e]}),s.jsx("span",{children:t})]}),r&&s.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}function yt({label:e,hint:t,children:r,className:n}){return s.jsxs("div",{className:$t("mb-5",n),children:[s.jsx("label",{className:"block text-xs font-semibold text-text-muted uppercase tracking-wider mb-2",children:e}),r,t&&s.jsx("p",{className:"text-xs text-text-muted mt-1.5",children:t})]})}function ts(e){const{className:t,...r}=e;return s.jsx("input",{...r,className:$t("w-full px-4 py-3 rounded-xl border border-border-subtle bg-bg-secondary","text-text-primary text-sm outline-none","focus:border-accent transition-colors",t)})}const $0={primary:"btn-primary",secondary:"btn-secondary",warning:"btn-warning",danger:"btn-danger",ghost:"btn-ghost"},gs=l.forwardRef(function({variant:t="secondary",size:r="md",type:n,className:a,...o},i){return s.jsx("button",{ref:i,type:n??"button",className:$t("btn",$0[t],r==="sm"&&"btn-sm",a),...o})}),E0=l.forwardRef(function({options:t,children:r,className:n,...a},o){return s.jsx("select",{ref:o,className:$t("w-full px-4 py-3 rounded-xl border border-border-subtle bg-bg-secondary","text-text-primary text-sm outline-none cursor-pointer","focus:border-accent transition-colors",n),...a,children:r??(t==null?void 0:t.map(i=>s.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value)))})}),B0={online:"bg-green-500/10 text-green-400 border-green-500/30",idle:"bg-yellow-500/10 text-yellow-400 border-yellow-500/30",busy:"bg-orange-500/10 text-orange-400 border-orange-500/30",error:"bg-red-500/10 text-red-400 border-red-500/30",offline:"bg-gray-500/10 text-text-secondary border-gray-500/30"},F0={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function O0({status:e,label:t,className:r}){const n=t||e;return s.jsxs("span",{className:$t("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",B0[e],r),children:[s.jsx("span",{className:$t("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",F0[e])}),n]})}function Es({label:e,description:t,checked:r,disabled:n,onChange:a,extra:o}){return s.jsxs("div",{className:`flex justify-between items-center ${n?"opacity-60":""}`,children:[s.jsxs("div",{className:"pr-4",children:[s.jsx("div",{className:"font-medium text-sm",children:e}),s.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:t})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,s.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>a(!r),className:`relative inline-flex items-center ${n?"cursor-not-allowed":"cursor-pointer"}`,children:[s.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:r?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),s.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function H0({onPrefChange:e}){const[t,r]=Zx(),[n,a]=l.useState(()=>typeof window>"u"||!("Notification"in window)?"unsupported":Notification.permission);l.useEffect(()=>{const i=()=>{if(typeof window>"u"||!("Notification"in window)){a("unsupported");return}a(Notification.permission)};return i(),window.addEventListener("focus",i),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",i),document.removeEventListener("visibilitychange",i)}},[]);const o=(i,c)=>{r({[i]:c}),e==null||e(i,c)};return s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(jr,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:t.globalEnabled,onChange:i=>o("globalEnabled",i)}),t.globalEnabled&&s.jsx("div",{className:"border-t border-border-subtle my-0.5"}),t.globalEnabled&&s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(os,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:t.browserNotifications,onChange:i=>o("browserNotifications",i)}),t.globalEnabled&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx("div",{className:"text-[11px] text-text-muted",children:"Browser alerts only fire while this dashboard tab stays open in the background. If you close it, standalone cannot deliver hosted push notifications for you."}),n==="default"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-status-warning",children:[s.jsx("span",{children:"This browser has not granted notification permission yet. Allow it to receive local browser alerts."}),s.jsx("button",{onClick:()=>{pu().then(a)},className:"px-2 py-0.5 rounded border border-border-default bg-bg-glass text-text-secondary hover:text-text-primary transition-colors",children:"Allow notifications"})]}),n==="denied"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"Browser notifications are blocked in site or browser settings. Re-enable them there to receive standalone desktop alerts."}),n==="unsupported"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"This browser cannot show desktop notifications here. Keep the dashboard visible, or use another supported browser on this device."})]}),t.globalEnabled&&t.browserNotifications&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Ud,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:t.completionAlert,onChange:i=>o("completionAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Tf,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:t.approvalAlert,onChange:i=>o("approvalAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(tn,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:t.disconnectAlert,onChange:i=>o("disconnectAlert",i)})]}),!t.globalEnabled&&s.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function ei(e){const t=e.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/);if(!t)return null;const r=t[4]??null;let n=null;if(r){const a=r.match(/(?:^|\.)(\d+)$/);n=a?Number(a[1]):null}return{base:[Number(t[1]),Number(t[2]),Number(t[3])],prereleaseNumber:n,isPrerelease:r!==null}}function pa(e){var t;return((t=ei(e))==null?void 0:t.base)??null}function W0(e,t){const r=pa(e),n=pa(t);if(!r||!n)return e.localeCompare(t);for(let a=0;a<3;a+=1){if(r[a]<n[a])return-1;if(r[a]>n[a])return 1}return 0}function K0(e,t){const r=ei(e),n=ei(t);if(!r||!n)return e!==t;for(let a=0;a<3;a+=1){if(r.base[a]<n.base[a])return!0;if(r.base[a]>n.base[a])return!1}return r.isPrerelease&&n.isPrerelease?r.prereleaseNumber===null||n.prereleaseNumber===null?!1:r.prereleaseNumber<n.prereleaseNumber:!1}function Hi(e,t){const r=e.version||null;return e.versionMismatch===!0?!0:!r||!t?!1:K0(r,t)}function Jr(e,t){if(e.versionUpdateRequired===!0)return!0;const r=e.version||null;if(!r||!t||r===t||W0(r,t)>=0)return!1;const n=pa(r),a=pa(t);return!n||!a?!1:n[0]!==a[0]||n[1]!==a[1]}function U0(e){return!e||typeof e!="object"?{}:"result"in e&&e.result&&typeof e.result=="object"?e.result:e}function so(e,t){return e instanceof Error?e.message:t}function z0({ides:e,emptyMessage:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){const o=e.filter(i=>i.type==="adhdev-daemon");return o.length===0?s.jsx(_a,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:t||"Install ADHDev on a machine and sign in to connect it here."}):s.jsx("div",{className:"flex flex-col gap-2",children:o.map(i=>s.jsx(V0,{ide:i,allIdes:e,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a},i.id))})}function bc({title:e,message:t,confirmLabel:r,confirmColor:n,onConfirm:a,onCancel:o}){const i=n==="red"?"bg-status-error/20 text-status-error border-status-error/40 hover:bg-status-error/30":"";return ur.createPortal(s.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:"var(--z-modal)"},onClick:o,children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:c=>c.stopPropagation(),children:[s.jsx("div",{className:"font-semibold text-sm mb-3",children:e}),s.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:t}),s.jsxs("div",{className:"flex gap-2 justify-end",children:[s.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),s.jsx("button",{onClick:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,style:n==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:r})]})]})}),document.body)}function G0(e){const t=e.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...C0,...I0,...A0].find(a=>a.id===t||t.includes(a.id)||a.id.includes(t));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:e}}function V0({ide:e,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){var B,z;const[o,i]=l.useState("idle"),[c,d]=l.useState(""),[p,u]=l.useState(null),[m,h]=l.useState("idle"),[g,b]=l.useState(""),f=e.version||null,k=((B=e.machine)==null?void 0:B.platform)||((z=e.system)==null?void 0:z.platform)||"",j=Yt(e,{fallbackId:e.id}),x=k==="win32"?"🪟":k==="darwin"?"🍎":"🐧",v=t.filter(M=>M.daemonId===e.id&&M.transport==="cdp-page"),I=t.filter(M=>M.daemonId===e.id&&M.transport==="pty"),w=t.filter(M=>M.daemonId===e.id&&M.transport==="acp"),y=e.p2p,S=async()=>{if(r){i("upgrading"),d("Starting upgrade...");try{const M=U0(await r(e.id,"daemon_upgrade",{}));M.alreadyLatest?(i("done"),d(`Already on v${M.version||"latest"}.`)):M.upgraded||M.success?(i("done"),d(`Upgrade to v${M.version||"latest"} started. Daemon is restarting...`)):(i("error"),d(M.error||"Upgrade failed"))}catch(M){i("error"),d(so(M,"Connection lost during upgrade"))}}},N=async()=>{if(u(null),!!n){h("loading");try{await n(e.id),h("done"),b("Machine disconnected.")}catch(M){h("error"),b(so(M,"Failed to disconnect"))}}},C=async()=>{if(u(null),!!a){h("loading");try{await a(e.id),h("done"),b("Token revoked. Restart ADHDev on that machine to reconnect.")}catch(M){h("error"),b(so(M,"Failed to revoke token"))}}},R="0.9.82",L=Hi(e,R),_=Jr(e,R),D=v.length+I.length+w.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"text-xl",children:x}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium text-sm",children:j}),s.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[s.jsxs("span",{children:[e.id.substring(0,12),"…"]}),f&&s.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${L?"":"bg-bg-secondary"}`,style:L?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",f,!L&&" ✓"]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[r&&L&&s.jsx("button",{onClick:S,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${R}`,children:o==="upgrading"?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`${_?"↑ Update now":`↑ Update${` to v${R}`}`}`}),n&&s.jsx("button",{onClick:()=>u("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&s.jsx("button",{onClick:()=>u("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),s.jsx(O0,{status:e.status==="online"?"online":"error"})]})]}),s.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[y&&s.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${y.state==="connected"?"bg-status-online":"bg-text-muted/30"} ${y.state==="connecting"||y.state==="new"?"animate-pulse":""}`,style:y.state==="connecting"||y.state==="new"?{background:"var(--status-warning)"}:void 0}),s.jsxs("span",{className:"text-text-muted",children:["P2P ",y.state==="connected"?"connected":y.state==="connecting"||y.state==="new"?"connecting...":y.state||"off"]}),y.peers!==void 0&&y.peers>0&&s.jsxs("span",{className:"text-text-muted/60",children:["(",y.peers," peer",y.peers!==1?"s":"",")"]})]}),y&&D>0&&s.jsx("span",{className:"text-border-subtle",children:"·"}),D>0?s.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[v.map(M=>{const H=G0(M.type),Y=M.cdpConnected;return s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:H.icon}),s.jsx("span",{children:H.name}),Y!==void 0&&s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Y?"bg-status-online":"animate-pulse"}`,style:Y?void 0:{background:"var(--status-warning)"},title:Y?"CDP connected":"CDP connecting..."})]},M.id)}),I.map(M=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"⌨️"}),s.jsx("span",{children:M.cliName||"CLI"})]},M.id)),w.map(M=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"🔗"}),s.jsx("span",{children:M.cliName||"ACP"})]},M.id))]}):s.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(c||g)&&s.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-status-error":o==="done"||m==="done"?"text-status-online":"text-text-muted"}`,children:g||c})]}),p==="disconnect"&&s.jsx(bc,{title:"🔌 Disconnect Machine",message:`Disconnect "${j}" from ADHDev?
|
|
54
54
|
|