@adhdev/daemon-standalone 0.9.82-rc.212 → 0.9.82-rc.214

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.212",
3
+ "version": "0.9.82-rc.214",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -77,7 +77,7 @@ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Mach
77
77
  `),children:s.jsx("span",{className:"truncate",children:k})}),x.length>0&&s.jsx("div",{className:"mt-2 flex max-h-44 min-w-0 flex-col gap-1.5 overflow-y-auto pr-1",children:x.map(v=>{const I=dr(v);return s.jsxs("div",{className:`min-w-0 rounded-lg border px-2.5 py-1.5 ${r.isDark?"border-cyan-400/15 bg-cyan-500/[0.055]":"border-sky-200 bg-white/85"}`,title:[`Session ID: ${v.sessionId}`,v.providerType?`Provider: ${v.providerType}`:null,`Status: ${Ht(v)}`,`Role: ${I}`].filter(Boolean).join(`
78
78
  `),children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[s.jsx("span",{className:`min-w-0 truncate text-[10px] ${r.textMuted}`,children:v.providerType||"provider unknown"}),s.jsx("span",{className:`shrink-0 rounded-full border px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-[0.12em] ${Xa(v,r.isDark)}`,children:Ht(v)})]}),s.jsxs("div",{className:`mt-0.5 flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[9px] ${r.textMuted}`,children:[s.jsx("span",{className:"min-w-0 truncate font-mono",children:Ja(v.sessionId)}),s.jsx("span",{children:I})]})]},v.sessionId)})}),s.jsxs("div",{className:"mt-3",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap gap-1.5 text-[10px]",children:[s.jsx("span",{className:`rounded-full border px-2 py-0.5 capitalize ${At("health",r.isDark)}`,children:nw(o.health)}),c&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("submodule",r.isDark)}`,children:"submodule"}),!i&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At(lw(o),r.isDark)}`,children:cc(o.locality)}),u&&c&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("meta",r.isDark)}`,children:u}),o.dirty&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("dirty",r.isDark)}`,children:c?"local changes":`${o.dirtyFiles} dirty`}),o.outOfSync&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("conflict",r.isDark)}`,children:"out of sync"}),o.hasConflicts&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("conflict",r.isDark)}`,children:"conflicts"}),!c&&o.upstream&&o.upstreamStatus!=="fresh"&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("orphan",r.isDark)}`,children:"upstream unverified"}),o.isOrphan&&s.jsx("span",{className:`rounded-full border px-2 py-0.5 ${At("orphan",r.isDark)}`,children:"needs follow-up"})]}),s.jsx("div",{className:`mt-3 text-[11px] leading-5 ${r.textSecondary}`,style:tw,children:Pn(o)}),g.length>0&&s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:`mb-1.5 text-[9px] font-semibold uppercase tracking-[0.16em] ${r.textMuted}`,children:"Attached Chats"}),s.jsx("div",{className:"flex max-h-56 flex-col gap-1.5 overflow-y-auto pr-1",children:g.map(v=>{const I=v.startedAt||v.createdAt||null,w=dr(v);return s.jsxs("div",{className:`min-w-0 rounded-lg border px-2.5 py-1.5 ${r.isDark?"border-white/8 bg-white/[0.035]":"border-slate-200 bg-white/80"}`,title:[`Session ID: ${v.sessionId}`,v.providerType?`Provider: ${v.providerType}`:null,`Status: ${Ht(v)}`,`Role: ${w}`,I?`Started: ${I}`:"Started: not reported",v.statusNote?`Note: ${v.statusNote}`:null].filter(Boolean).join(`
79
79
  `),children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[s.jsx("span",{className:`min-w-0 truncate font-mono text-[10px] select-text ${r.textPrimary}`,children:Ja(v.sessionId)}),s.jsx("span",{className:`shrink-0 rounded-full border px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-[0.12em] ${Xa(v,r.isDark)}`,children:Ht(v)})]}),s.jsxs("div",{className:`mt-1 flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[9px] ${r.textMuted}`,children:[s.jsx("span",{className:"truncate",children:v.providerType||"provider unknown"}),s.jsx("span",{children:w}),s.jsx("span",{children:lc(I)})]}),v.statusNote&&s.jsx("div",{className:`mt-1 text-[9px] leading-4 ${r.textMuted}`,children:v.statusNote})]},v.sessionId)})})]}),d&&f&&s.jsx("div",{className:`mt-3 rounded-xl border px-3 py-2 text-[10px] leading-4 ${r.isDark?"border-cyan-400/15 bg-cyan-500/8 text-cyan-50/90":"border-sky-300 bg-sky-50 text-sky-700"}`,style:sw,children:f})]}),s.jsx(en,{type:"source",position:a==="TB"?es.Bottom:es.Right,isConnectable:!1,style:{opacity:0,pointerEvents:"none"}})]})}const dw={meshNode:cw},uw=8;function mw(e){if(e.length<2)return null;if(e.length===2){const[m,u]=e;return{d:`M ${m.x},${m.y} L ${u.x},${u.y}`,labelX:(m.x+u.x)/2,labelY:(m.y+u.y)/2}}const t=uw,r=[`M ${e[0].x},${e[0].y}`];for(let m=1;m<e.length-1;m+=1){const u=e[m-1],p=e[m],f=e[m+1],y=Math.sign(p.x-u.x),g=Math.sign(p.y-u.y),x=Math.sign(f.x-p.x),k=Math.sign(f.y-p.y),j=Math.hypot(p.x-u.x,p.y-u.y),h=Math.hypot(f.x-p.x,f.y-p.y),v=Math.min(t,j/2,h/2);if(v<1||y===x&&g===k){r.push(`L ${p.x},${p.y}`);continue}const I=p.x-y*v,w=p.y-g*v,b=p.x+x*v,C=p.y+k*v;r.push(`L ${I},${w}`),r.push(`Q ${p.x},${p.y} ${b},${C}`)}const n=e[e.length-1];r.push(`L ${n.x},${n.y}`);let a=0;const o=[0];for(let m=1;m<e.length;m+=1)a+=Math.hypot(e[m].x-e[m-1].x,e[m].y-e[m-1].y),o.push(a);const i=a/2;let c=e[0].x,d=e[0].y;for(let m=1;m<e.length;m+=1)if(o[m]>=i){const u=o[m]-o[m-1],p=u===0?0:(i-o[m-1])/u;c=e[m-1].x+(e[m].x-e[m-1].x)*p,d=e[m-1].y+(e[m].y-e[m-1].y)*p;break}return{d:r.join(" "),labelX:c,labelY:d}}function pw(e){const t=e.data.routePoints;if(t&&t.length>=2){const o=mw(t);if(o)return[o.d,o.labelX,o.labelY]}const r={sourceX:e.sourceX,sourceY:e.sourceY,sourcePosition:e.sourcePosition,targetX:e.targetX,targetY:e.targetY,targetPosition:e.targetPosition},n=e.data.graphEdge;let a;return n.type==="parentBranch"?a=Sp(r):n.type==="worktreeLink"||n.type==="submoduleLink"||n.type==="cloneLink"?a=jp(r):a=kp(r),[a[0],a[1],a[2]]}function hw(e,t){const r="nodrag nopan rounded-md border px-2 py-1 text-[10px] font-semibold shadow-sm backdrop-blur-sm";switch(e.type){case"orphanLink":return t?`${r} border-orange-400/35 bg-orange-500/14 text-orange-100`:`${r} border-orange-300 bg-orange-50 text-orange-700`;case"submoduleLink":return t?`${r} border-violet-400/30 bg-violet-500/14 text-violet-100`:`${r} border-violet-300 bg-violet-50 text-violet-700`;case"sessionLink":return t?`${r} border-emerald-400/30 bg-emerald-500/14 text-emerald-100`:`${r} border-emerald-300 bg-emerald-50 text-emerald-700`;case"cloneLink":return t?`${r} border-teal-400/30 bg-teal-500/14 text-teal-100`:`${r} border-teal-300 bg-teal-50 text-teal-700`;default:return t?`${r} border-sky-400/25 bg-slate-950/78 text-sky-100`:`${r} border-sky-300 bg-white/95 text-sky-700`}}function fw(e){const t=l.useContext(Ni),r=e.data.graphEdge,[n,a,o]=pw(e),i=typeof e.label=="string"?e.label:void 0;return s.jsxs(s.Fragment,{children:[s.jsx(gp,{id:e.id,path:n,markerEnd:e.markerEnd,style:e.style,interactionWidth:24}),e.label&&s.jsx(yp,{children:s.jsx("div",{className:hw(r,t.isDark),title:i,style:{position:"absolute",transform:`translate(-50%, -50%) translate(${a}px, ${o}px)`,pointerEvents:"none",maxWidth:Ev.maxWidth},children:s.jsx("span",{className:"block truncate",children:e.label})})})]})}const xw={meshEdge:fw};async function bw(e,t=Ys("dark"),r=!1,n="LR"){const a=await Xv(e,r,n),o=new Set(a.nodes.map(u=>u.id)),i=a.nodes.map(u=>({id:u.id,type:u.type,position:u.position,data:{graphNode:u.graphNode,compact:r},selected:u.selected,draggable:u.draggable,selectable:u.selectable})),c=e.edges.filter(u=>o.has(u.source)&&o.has(u.target)),d=vw(c),m=c.map(u=>{var p;return{id:u.id,source:u.source,target:u.target,label:d.has(u.id)?u.label:void 0,type:"meshEdge",data:{graphEdge:u,routePoints:(p=a.edgeRoutes.get(u.id))==null?void 0:p.points},animated:u.type==="orphanLink",markerEnd:u.direction==="directed"?{type:bp.ArrowClosed,width:u.type==="submoduleLink"?16:18,height:u.type==="submoduleLink"?16:18,color:uc(u)}:void 0,style:{stroke:uc(u),strokeWidth:u.type==="orphanLink"?2.25:u.type==="submoduleLink"?1.7:u.type==="worktreeLink"?1.8:u.type==="cloneLink"?1.6:2,strokeDasharray:u.type==="orphanLink"?"5 4":u.type==="submoduleLink"?"4 3":u.type==="cloneLink"?"6 3":void 0},labelStyle:{fill:t.edgeLabelTextColor,fontSize:10,fontWeight:600},labelBgStyle:{fill:t.edgeLabelBackgroundColor,fillOpacity:1,stroke:t.edgeLabelBorderColor},labelBgPadding:[6,4],labelBgBorderRadius:7}});return{nodes:i,edges:m}}const gw=3,yw=2;function dc(e){switch(e.type){case"orphanLink":return 5;case"parentBranch":return 4;case"submoduleLink":return 3;case"cloneLink":return 2;case"worktreeLink":return 1;case"sessionLink":return 0;default:return 0}}function vw(e){const t=new Set,r=new Map;for(const n of e){if(!n.label)continue;const a=r.get(n.source);a?a.push(n):r.set(n.source,[n])}for(const n of r.values()){if(n.length<gw){for(const o of n)t.add(o.id);continue}const a=[...n].sort((o,i)=>{const c=dc(i)-dc(o);return c!==0?c:o.id.localeCompare(i.id)});for(const o of a.slice(0,yw))t.add(o.id)}return t}function uc(e){switch(e.type){case"parentBranch":return"#38bdf8";case"worktreeLink":return"#a78bfa";case"sessionLink":return"#34d399";case"orphanLink":return"#f97316";case"submoduleLink":return"#c084fc";case"cloneLink":return"#2dd4bf";default:return"#64748b"}}function ww(e){const t=e.data.graphNode;if(t.locality==="local")return"#38bdf8";switch(t.health){case"online":return"#34d399";case"dirty":return"#fbbf24";case"degraded":case"offline":return"#fb7185";case"wrong_branch":return"#a78bfa";default:return"#94a3b8"}}function jw(e){const t=e.data.graphNode;return["mesh-minimap-node",`mesh-minimap-node--${t.type}`,`mesh-minimap-node--${t.health}`,t.isOrphan?"mesh-minimap-node--attention":null,t.dirty?"mesh-minimap-node--dirty":null,t.outOfSync?"mesh-minimap-node--out-of-sync":null].filter(Boolean).join(" ")}function kw({data:e,viewportKey:t}){const r=vp(),n=wp(),a=l.useRef(null),o=l.useMemo(()=>nm(e),[e]),i=l.useMemo(()=>_v(e),[e]);return l.useEffect(()=>{if(!r||e.nodes.length===0||a.current===t)return;let c=!1;const d=requestAnimationFrame(()=>{if(c)return;const m=i.length>0&&i.length<e.nodes.length;n.fitView({nodes:m?i.map(u=>({id:u})):void 0,padding:m?.24:.2,maxZoom:m?.98:.9,duration:260}),a.current=t});return()=>{c=!0,cancelAnimationFrame(d)}},[e.nodes.length,i,o,r,n,t]),null}function Sw(e){return e>=16?"min-h-[720px]":e>=10?"min-h-[580px]":"min-h-[460px]"}const Nw=12;function Cw({data:e,selectedNodeId:t=null,onNodeClick:r,onNodeHoverChange:n,onEdgeHoverChange:a}){const{theme:o}=qs(),i=l.useMemo(()=>Ys(o),[o]),c=l.useMemo(()=>Qv(e),[e]),d=l.useMemo(()=>Zv(e),[e]),m=e.nodes.length>=ew,[u,p]=l.useState("LR"),f=l.useMemo(()=>u==="auto"?Fv(e):u,[u,c,e]),y=e.nodes.length>=Nw,[g,x]=l.useState({nodes:[],edges:[]}),k=l.useRef(null),[j,h]=l.useState({width:0,height:0}),v=l.useMemo(()=>`${Lv(e,j.width,j.height)}::${f}`,[c,e,j.height,j.width,f]);l.useEffect(()=>{let C=!1;return bw(e,i,m,f).then(N=>{C||x(N)}),()=>{C=!0}},[e,d,i,m,f]);const I=l.useMemo(()=>g.nodes.map(C=>({...C,selected:C.id===t})),[g.nodes,t]);l.useEffect(()=>{const C=k.current;if(!C)return;const N=()=>{const T=Math.max(0,Math.round(C.clientWidth)),_=Math.max(0,Math.round(C.clientHeight));h(L=>L.width===T&&L.height===_?L:{width:T,height:_})};N();const S=typeof ResizeObserver=="function"?new ResizeObserver(()=>N()):null;return S==null||S.observe(C),window.addEventListener("resize",N),()=>{S==null||S.disconnect(),window.removeEventListener("resize",N)}},[]);const w=Sw(e.nodes.length),b=C=>C?i.isDark?"rounded-md border border-cyan-400/40 bg-cyan-500/15 px-2 py-0.5 text-cyan-100":"rounded-md border border-sky-400 bg-sky-100 px-2 py-0.5 text-sky-800":i.isDark?"rounded-md border border-white/10 bg-white/[0.03] px-2 py-0.5 text-slate-400 hover:text-slate-200":"rounded-md border border-slate-300 bg-white/80 px-2 py-0.5 text-slate-500 hover:text-slate-800";return s.jsx(Ni.Provider,{value:i,children:s.jsx(lm.Provider,{value:m,children:s.jsx(cm.Provider,{value:f,children:s.jsxs("div",{ref:k,className:i.graphShellClass,children:[s.jsxs("div",{className:`shrink-0 flex flex-wrap items-center justify-between gap-2 px-3 pt-3 pb-2 text-[11px] ${i.textSecondary}`,children:[s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs("span",{className:i.graphStatChipClass,children:[e.stats.totalNodes," node",e.stats.totalNodes===1?"":"s"]}),e.stats.totalActiveSessions>0&&s.jsxs("span",{className:i.isDark?"rounded-full border border-emerald-400/25 bg-emerald-500/12 px-3 py-1 text-emerald-100":"rounded-full border border-emerald-300 bg-emerald-50 px-3 py-1 text-emerald-700",children:[e.stats.totalActiveSessions," active session",e.stats.totalActiveSessions===1?"":"s"]}),e.stats.orphanNodes>0&&s.jsxs("span",{className:i.isDark?"rounded-full border border-orange-400/25 bg-orange-500/12 px-3 py-1 text-orange-100":"rounded-full border border-orange-300 bg-orange-50 px-3 py-1 text-orange-700",children:[e.stats.orphanNodes," need attention"]}),m&&s.jsx("span",{className:i.isDark?"rounded-full border border-white/8 bg-white/[0.03] px-3 py-1 text-slate-400":"rounded-full border border-slate-200 bg-slate-50/80 px-3 py-1 text-slate-500",children:"dense view · hover for details"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:i.isDark?"flex items-center gap-0.5 rounded-md border border-white/10 bg-slate-950/40 p-0.5 text-[10px]":"flex items-center gap-0.5 rounded-md border border-slate-300 bg-white/70 p-0.5 text-[10px]",role:"group","aria-label":"Graph layout direction",children:[s.jsx("button",{type:"button",onClick:()=>p("auto"),className:b(u==="auto"),title:`Auto (currently ${f==="TB"?"top-bottom":"left-right"})`,children:"Auto"}),s.jsx("button",{type:"button",onClick:()=>p("LR"),className:b(u==="LR"),title:"Left to right",children:"LR"}),s.jsx("button",{type:"button",onClick:()=>p("TB"),className:b(u==="TB"),title:"Top to bottom",children:"TB"})]}),s.jsx("div",{className:i.graphHintChipClass,children:"drag or scroll to pan"})]})]}),s.jsx("div",{className:`w-full min-w-0 flex-1 min-h-0 ${w}`,children:s.jsxs(mp,{nodes:I,edges:g.edges,nodeTypes:dw,edgeTypes:xw,minZoom:.18,maxZoom:1.35,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!0,panOnDrag:!0,panOnScroll:!0,zoomOnScroll:!1,zoomOnPinch:!0,zoomOnDoubleClick:!1,selectionOnDrag:!1,onNodeClick:(C,N)=>r==null?void 0:r(N.data.graphNode),onNodeMouseEnter:(C,N)=>n==null?void 0:n(N.data.graphNode),onNodeMouseLeave:()=>n==null?void 0:n(null),onEdgeMouseEnter:(C,N)=>{var S;return a==null?void 0:a(((S=N.data)==null?void 0:S.graphEdge)??null)},onEdgeMouseLeave:()=>a==null?void 0:a(null),className:"h-full w-full",colorMode:i.flowColorMode,proOptions:{hideAttribution:!0},children:[s.jsx(kw,{data:e,viewportKey:v}),s.jsx(pp,{className:i.graphControlsClass,position:"bottom-left",showZoom:!0,showFitView:!0,showInteractive:!1}),y&&s.jsx(hp,{position:"bottom-right",pannable:!0,zoomable:!0,nodeColor:ww,nodeClassName:jw,nodeStrokeWidth:3,className:i.isDark?"overflow-hidden rounded-xl border border-white/10 bg-slate-950/85":"overflow-hidden rounded-xl border border-slate-200 bg-white/95"}),s.jsx(fp,{variant:xp.Dots,gap:18,size:1.2,color:i.graphBackgroundDotColor})]})})]})})})})}function nt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Se(...e){for(const t of e){if(typeof t!="string")continue;const r=t.trim();if(r)return r}}function It(...e){for(const t of e)if(typeof t=="number"&&Number.isFinite(t))return t}function Ct(...e){for(const t of e)if(typeof t=="boolean")return t}function Qa(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function Ci(e){switch(e){case"fresh":return 30;case"no_upstream":return 4;case"unchecked":case void 0:return 0;case"stale":return-10;case"unavailable":return-15;default:return 0}}function Iw(e,t){const r=typeof e=="string"?e.trim().replace(/[\\/]+$/,""):"",n=typeof t=="string"?t.trim():"";if(n){if(/^(?:[A-Za-z]:[\\/]|\/)/.test(n))return n;if(r)return`${r}/${n.replace(/^[\\/]+/,"")}`}}function Mw(e,t){if(!Array.isArray(e))return;const r=e.map(n=>{const a=nt(n),o=Se(a.path),i=Se(a.commit),c=Se(a.repoPath,a.repo_root)??Iw(t,o);return!o||!i||!c?null:{path:o,commit:i,repoPath:c,dirty:Ct(a.dirty)??!1,outOfSync:Ct(a.outOfSync,a.out_of_sync)??!1,lastCheckedAt:It(a.lastCheckedAt,a.last_checked_at)??Date.now(),...Se(a.error)?{error:Se(a.error)}:{}}}).filter(n=>n!==null);return r.length>0?r:void 0}function Aw(e){return Ct(e.isGitRepo)!==void 0||!!Se(e.branch,e.upstream,e.upstreamStatus,e.upstream_status,e.headCommit)||It(e.ahead,e.behind,e.staged,e.modified,e.untracked,e.deleted,e.renamed,e.lastCheckedAt,e.last_checked_at)!==void 0||Array.isArray(e.submodules)&&e.submodules.length>0}function Rn(e,t,r){const n=Ct(e.isGitRepo);if(!Object.keys(e).length||!Aw(e))return;const a=n??!0,o=Array.isArray(e.conflictFiles)?e.conflictFiles.filter(v=>typeof v=="string"):[],i=It(e.conflicts)??o.length,c=Ct(e.hasConflicts)??i>0,d=Se(e.repoRoot,e.repo_root,t.repoRoot,t.repo_root,e.workspace,t.workspace)||void 0,m=Mw(e.submodules,d),u=Se(e.upstreamStatus,e.upstream_status),p=It(e.upstreamFetchedAt,e.upstream_fetched_at),f=Se(e.upstreamFetchError,e.upstream_fetch_error),y=Se(e.error),g=It(e.staged)??0,x=It(e.modified)??0,k=It(e.untracked)??0,j=It(e.deleted)??0,h=It(e.renamed)??0;return{workspace:Se(e.workspace,t.workspace)||"",repoRoot:d??null,isGitRepo:a,branch:Se(e.branch)??null,headCommit:Se(e.headCommit)??null,headMessage:Se(e.headMessage)??null,upstream:Se(e.upstream)??null,upstreamStatus:u??"unchecked",...p!==void 0?{upstreamFetchedAt:p}:{},...f?{upstreamFetchError:f}:{},ahead:It(e.ahead)??0,behind:It(e.behind)??0,staged:g,modified:x,untracked:k,deleted:j,renamed:h,dirty:Ct(e.dirty,e.isDirty,e.is_dirty)??(g+x+k+j+h>0||c),hasConflicts:c,conflictFiles:o,stashCount:It(e.stashCount,e.stash_count)??0,lastCheckedAt:(r==null?void 0:r.lastCheckedAt)??It(e.lastCheckedAt,e.last_checked_at)??Date.now(),...m?{submodules:m}:{},...y?{error:y}:{}}}function Tw(e){if(!e)return Number.NEGATIVE_INFINITY;let t=0;return e.isGitRepo===!0&&(t+=50),e.isGitRepo===!1&&(t-=10),e.branch&&(t+=20),e.headCommit&&(t+=20),e.upstream&&(t+=10),t+=Ci(e.upstreamStatus),typeof e.ahead=="number"&&(t+=2),typeof e.behind=="number"&&(t+=2),Array.isArray(e.submodules)&&e.submodules.length>0&&(t+=4+e.submodules.length),e.error&&(t-=20),t}function _w(e){const t=nt(e.lastGit??e.last_git),r=nt(t.result),n=nt(t.status),a=nt(r.status),o=nt(e.lastProbe??e.last_probe),i=nt(o.git),c=nt(i.result),d=nt(i.status),m=nt(c.status);let u=null;for(const p of[n,a,d,m]){const f=Rn(p,e,{lastCheckedAt:Date.now()});if(!f)continue;const y=Tw(f);(!u||y>u.score)&&(u={git:f,score:y})}return u==null?void 0:u.git}function Lw(e){const t=Array.isArray(e==null?void 0:e.submodules)?e.submodules:[];let r=!1,n=!1;for(const a of t)a!=null&&a.outOfSync&&(n=!0),a!=null&&a.dirty&&(r=!0);return{dirty:r,outOfSync:n}}function Pw(e){return e?(e.staged??0)>0||(e.modified??0)>0||(e.untracked??0)>0||(e.deleted??0)>0||(e.renamed??0)>0||e.hasConflicts===!0:!1}function ea(e){if(!e||e.isGitRepo===!1||!e.branch)return"degraded";const t=Lw(e);return t.outOfSync?"degraded":t.dirty||Pw(e)?"dirty":"online"}function Rw(e,t){const r=t?ea(t):void 0;return!e||e==="unknown"?r:e}function mm(e){const t=nt(e),r=Se(t.sessionId,t.session_id,t.id);return r?{sessionId:r,...Se(t.providerType,t.provider)?{providerType:Se(t.providerType,t.provider)}:{},...Se(t.state,t.status)?{state:Se(t.state,t.status)}:{},...Se(t.chatStatus,t.chat_status)?{chatStatus:Se(t.chatStatus,t.chat_status)}:{},...Se(t.lifecycle)?{lifecycle:Se(t.lifecycle)}:{},...Se(t.surfaceKind,t.surface_kind)?{surfaceKind:Se(t.surfaceKind,t.surface_kind)}:{},...Se(t.recoveryState,t.recovery_state)?{recoveryState:Se(t.recoveryState,t.recovery_state)}:{},...Se(t.workspace)?{workspace:Se(t.workspace)}:{},...Se(t.title)?{title:Se(t.title)}:{},...Se(t.role)?{role:Se(t.role)}:{},...Ct(t.isSelfCoordinator,t.is_self_coordinator)!==void 0?{isSelfCoordinator:Ct(t.isSelfCoordinator,t.is_self_coordinator)}:{},...Se(t.statusNote,t.status_note)?{statusNote:Se(t.statusNote,t.status_note)}:{},...Se(t.createdAt,t.created_at)?{createdAt:Se(t.createdAt,t.created_at)}:{},...Se(t.startedAt,t.started_at)?{startedAt:Se(t.startedAt,t.started_at)}:{},...Se(t.lastActivityAt,t.last_activity_at)?{lastActivityAt:Se(t.lastActivityAt,t.last_activity_at)}:{},...Ct(t.isCached,t.is_cached)!==void 0?{isCached:Ct(t.isCached,t.is_cached)}:{}}:null}function Dw(e){const t=Array.isArray(e.activeSessionDetails)?e.activeSessionDetails:Array.isArray(e.active_session_details)?e.active_session_details:Array.isArray(e.sessions)?e.sessions:null;if(t){const a=t.map(mm).filter(o=>o!==null);if(a.length>0)return a}const r=nt(e.activeSession??e.active_session),n=Se(r.id,r.sessionId,r.session_id,e.activeSessionId,e.active_session_id,e.sessionId,e.session_id);if(n)return[{sessionId:n,...Se(r.providerType,r.provider)?{providerType:Se(r.providerType,r.provider)}:{},...Se(r.state,r.status)?{state:Se(r.state,r.status)}:{},...Se(r.chatStatus,r.chat_status)?{chatStatus:Se(r.chatStatus,r.chat_status)}:{},...Se(r.statusNote,r.status_note)?{statusNote:Se(r.statusNote,r.status_note)}:{},...Se(r.createdAt,r.created_at)?{createdAt:Se(r.createdAt,r.created_at)}:{},...Se(r.startedAt,r.started_at)?{startedAt:Se(r.startedAt,r.started_at)}:{}}]}function $w(e){const t=nt(e.connection);return Object.keys(t).length>0?t:void 0}function Ew(e){const t=e==null?void 0:e.source,r=e==null?void 0:e.transport;return{...e,perspective:(e==null?void 0:e.perspective)??"selected_coordinator",source:t&&t!=="not_reported"?t:"mesh_peer_status",state:"connected",transport:r&&r!=="unknown"?r:"direct",reported:!0,reason:"Live peer git snapshot reported by the selected coordinator."}}function Ii(e){var r;const t=e.git;return!!(t&&(t.isGitRepo===!0||t.isGitRepo===!1||t.branch||t.upstream||t.headCommit||typeof t.lastCheckedAt=="number"||(((r=t.submodules)==null?void 0:r.length)??0)>0))}function mc(e){var n,a,o,i,c,d;let t=0;const r=e.git;return Ii(e)&&(t+=80,(r==null?void 0:r.isGitRepo)===!0&&(t+=20),(r==null?void 0:r.isGitRepo)===!1&&(t+=5),r!=null&&r.branch&&(t+=20),r!=null&&r.upstream&&(t+=12),r!=null&&r.headCommit&&(t+=12),t+=Ci(r==null?void 0:r.upstreamStatus),typeof(r==null?void 0:r.lastCheckedAt)=="number"&&(t+=6),t+=(((n=r==null?void 0:r.submodules)==null?void 0:n.length)??0)*6),(a=e.branchConvergence)!=null&&a.status&&(t+=12),(((o=e.connection)==null?void 0:o.state)==="connected"||((i=e.connection)==null?void 0:i.state)==="self")&&(t+=8),((c=e.connection)==null?void 0:c.transport)==="direct"&&(t+=4),((d=e.connection)==null?void 0:d.source)==="mesh_peer_status"&&(t+=4),e.health==="online"&&(t+=4),e.health==="dirty"&&(t+=3),e.health==="degraded"&&(t+=2),e.launchReady&&(t+=2),e.gitProbePending&&(t-=40),e.error&&(t-=10),t}function Bw(e,t){var g,x,k,j;const r=mc(e),a=mc(t)>r?t:e,o=a===t?e:t,i=a.git??o.git,c=(((g=a.providers)==null?void 0:g.length)??0)>0?a.providers:o.providers,d=(((x=a.activeSessions)==null?void 0:x.length)??0)>0?a.activeSessions:o.activeSessions,m=(((k=a.activeSessionDetails)==null?void 0:k.length)??0)>0?a.activeSessionDetails:o.activeSessionDetails,u=(((j=a.providerPriority)==null?void 0:j.length)??0)>0?a.providerPriority:o.providerPriority,p=a.connection??o.connection,f={...o,...a,machineLabel:a.machineLabel||o.machineLabel,workspace:a.workspace||o.workspace,...a.repoRoot||o.repoRoot?{repoRoot:a.repoRoot||o.repoRoot}:{},...a.daemonId||o.daemonId?{daemonId:a.daemonId||o.daemonId}:{},...a.machineId||o.machineId?{machineId:a.machineId||o.machineId}:{},...a.machineStatus||o.machineStatus?{machineStatus:a.machineStatus||o.machineStatus}:{},health:i&&(!a.health||a.health==="unknown")?ea(i):a.health,providers:c??[],activeSessions:d??[],...m&&m.length>0?{activeSessionDetails:m}:{},...u&&u.length>0?{providerPriority:u}:{},...p?{connection:p}:{},...i?{git:i}:{}},y=nt(a.branchConvergence);return Object.keys(y).length>0?Object.assign(f,{branchConvergence:y}):delete f.branchConvergence,i&&(delete f.gitProbePending,delete f.error),f}function pm(e){const t=nt(e),r=Se(t.nodeId,t.id);if(!r)return null;const n=nt(t.cachedStatus),a=_w(t),o=a?void 0:Rn(nt(t.git),t)??Rn(t,t),i=a??o,c=i?void 0:Rn(nt(n.git),t),d=i??c,m=Se(t.machineStatus,t.machine_status,n.machineStatus,n.machine_status),u=Se(t.health),p=a?ea(d):Rw(u,i)||(d?ea(d):void 0)||Se(n.health)||m||Se(t.status)||"unknown",y=(a?void 0:Se(t.error))??(i?void 0:Se(n.error)),g=Dw(t),x=Qa(t.activeSessions),k=(g==null?void 0:g.map(N=>N.sessionId))??[],j=Qa(t.providerPriority),h=Ct(t.gitProbePending,t.git_probe_pending),v=i?void 0:h,I=$w(t),w=nt(t.branchConvergence??t.branch_convergence),b=I==null?void 0:I.state,C=a&&(!(I!=null&&I.reported)||b==="unknown")?Ew(I):I;return{nodeId:r,machineLabel:Se(t.machineLabel,t.machine_label,t.hostname,t.daemonId,t.daemon_id,t.machineId,t.machine_id,r)||r,workspace:Se(t.workspace,d==null?void 0:d.workspace)||"",...Se(t.repoRoot,t.repo_root,d==null?void 0:d.repoRoot)?{repoRoot:Se(t.repoRoot,t.repo_root,d==null?void 0:d.repoRoot)}:{},...Se(t.daemonId,t.daemon_id)?{daemonId:Se(t.daemonId,t.daemon_id)}:{},...Se(t.machineId,t.machine_id)?{machineId:Se(t.machineId,t.machine_id)}:{},...m?{machineStatus:m}:{},...Ct(t.isLocalWorktree,t.is_local_worktree)!==void 0?{isLocalWorktree:Ct(t.isLocalWorktree,t.is_local_worktree)}:{},...Se(t.worktreeBranch,t.worktree_branch)?{worktreeBranch:Se(t.worktreeBranch,t.worktree_branch)}:{},...Se(t.clonedFromNodeId,t.cloned_from_node_id)?{clonedFromNodeId:Se(t.clonedFromNodeId,t.cloned_from_node_id)}:{},health:p,...d?{git:d}:{},...v!==void 0?{gitProbePending:v}:{},providers:Qa(t.providers),activeSessions:x.length>0?x:k,...g&&g.length>0?{activeSessionDetails:g}:{},...j.length>0?{providerPriority:j}:{},...Ct(t.launchReady)!==void 0?{launchReady:Ct(t.launchReady)}:a?{launchReady:!0}:{},...Se(t.lastSeenAt,t.last_seen_at,n.lastSeenAt,n.last_seen_at)?{lastSeenAt:Se(t.lastSeenAt,t.last_seen_at,n.lastSeenAt,n.last_seen_at)}:{},...Se(t.updatedAt,t.updated_at,n.updatedAt,n.updated_at)?{updatedAt:Se(t.updatedAt,t.updated_at,n.updatedAt,n.updated_at)}:{},...C?{connection:C}:{},...Object.keys(w).length>0?{branchConvergence:w}:{},...y?{error:y}:{}}}function pc(e){const t=new Map;for(const r of e){const n=t.get(r.sessionId);t.set(r.sessionId,n?{...n,...r}:r)}return[...t.values()]}function hm(e,t){const r=Array.isArray(e.coordinatorSessions)?e.coordinatorSessions:Array.isArray(e.coordinator_sessions)?e.coordinator_sessions:[],n=r.map(mm).filter(a=>a!==null);return n.length===0?t:t.map(a=>{const o=n.filter(c=>{const d=nt(r.find(f=>{const y=nt(f);return Se(y.sessionId,y.session_id,y.id)===c.sessionId})),m=Se(d.nodeId,d.node_id),u=Se(d.daemonId,d.daemon_id),p=Se(d.workspace);return m&&m===a.nodeId?!0:u&&a.daemonId&&u===a.daemonId?!p||!a.workspace||p===a.workspace:!!(p&&a.workspace&&p===a.workspace)});if(o.length===0)return a;const i=pc([...a.activeSessionDetails??[],...o]);return{...a,activeSessionDetails:i,activeSessions:pc([...a.activeSessionDetails??[],...o,...(a.activeSessions??[]).map(c=>({sessionId:c}))]).map(c=>c.sessionId)}})}function Ow(e){const t=nt(e);return Array.isArray(t.sessions)||Array.isArray(t.active_session_details)||Se(t.daemon_id,t.machine_id,t.repo_root,t.worktree_branch,t.cloned_from_node_id)!==void 0||Ct(t.is_local_worktree)!==void 0}function fm(e){const t=new Map,r=[];for(const n of e){const a=Ow(n)?pm(n)??n:n;if(!(a!=null&&a.nodeId))continue;const o=t.get(a.nodeId);if(!o){t.set(a.nodeId,a),r.push(a);continue}const i=Bw(o,a);t.set(a.nodeId,i);const c=r.findIndex(d=>d.nodeId===a.nodeId);c>=0&&(r[c]=i)}return r}function xm(e){const t=fm(e.nodes??[]);return{...e,nodes:hm(e,t)}}function Fw(e){var r;const t=e==null?void 0:e.git;return{nodeId:(e==null?void 0:e.nodeId)??null,chosenSource:t?"live_git":e!=null&&e.gitProbePending?"pending_git":"no_git",hasLiveGit:Ii(e??{git:void 0}),branch:(t==null?void 0:t.branch)??null,upstream:(t==null?void 0:t.upstream)??null,headCommit:(t==null?void 0:t.headCommit)??null,submoduleCount:((r=t==null?void 0:t.submodules)==null?void 0:r.length)??0,pendingGit:(e==null?void 0:e.gitProbePending)===!0,connection:e!=null&&e.connection?{state:e.connection.state,transport:e.connection.transport,source:e.connection.source}:null}}function Hw(e){const t=Se(e.meshId,e.mesh_id,e.id),r=e.nodes,n=Array.isArray(r)?r.map(d=>pm(d)).filter(d=>d!==null):null;if(!t||!n)return null;const a=hm(e,fm(n)),o=Se(e.meshName,e.mesh_name,e.name),i=Se(e.repoIdentity,e.repo_identity),c=Se(e.refreshedAt,e.refreshed_at,e.updatedAt,e.updated_at);return!o||!i||!c?null:{...e,meshId:t,meshName:o,repoIdentity:i,refreshedAt:c,nodes:a}}function Ww(e){var o;let t=0;const r=nt(e.sourceOfTruth),n=nt(r.directPeerTruth);Se(r.currentStatus)==="live_git_and_session_probes"&&(t+=100),r.coordinatorOwnsLiveTruth===!0&&(t+=25),n.satisfied===!0&&(t+=15);for(const i of e.nodes){const c=i.git;if(!c){i.gitProbePending&&(t-=8);continue}t+=10,c.isGitRepo===!0&&(t+=5),c.isGitRepo===!1&&(t+=1),c.branch&&(t+=4),c.upstream&&(t+=3),c.headCommit&&(t+=3),t+=Ci(c.upstreamStatus),typeof c.ahead=="number"&&(t+=1),typeof c.behind=="number"&&(t+=1),typeof c.lastCheckedAt=="number"&&(t+=2),t+=(((o=c.submodules)==null?void 0:o.length)??0)*2}return t}function hc(e){let t=null;for(const r of e){const n=Hw(nt(r));if(!n)continue;const a=Ww(n);(!t||a>t.score)&&(t={status:n,score:a})}return(t==null?void 0:t.status)??null}function bm(e){const r=!!(e&&typeof e=="object"&&"result"in e)?e==null?void 0:e.result:e,n=hc([r==null?void 0:r.status,r]);return n||hc([e==null?void 0:e.status,e])}const Kw=5*60*1e3;function gm(e){return typeof e.daemonId=="string"&&e.daemonId.trim()?e.daemonId.trim():null}function ym(e){return typeof e.machineId=="string"&&e.machineId.trim()?e.machineId.trim():null}function Uw(e){var t,r,n;return((t=e.connection)==null?void 0:t.state)==="self"||e.isLocalWorktree===!0?"local":((r=e.connection)==null?void 0:r.transport)==="direct"||((n=e.connection)==null?void 0:n.transport)==="relay"||gm(e)||ym(e)?"remote":"unknown"}function zw(e){return Ii(e)}function vm(e){var t;return zw(e)?!1:!!(e.gitProbePending||((t=e.connection)==null?void 0:t.state)==="connecting")}function Gw(e){if(!e)return null;const t=Date.parse(e);return Number.isNaN(t)?null:t}function Vw(e){return e.activeSessionDetails&&e.activeSessionDetails.length>0?e.activeSessionDetails:(e.activeSessions??[]).map(t=>({sessionId:t,workspace:e.workspace,isCached:!0}))}function wm(e){return e?e.staged+e.modified+e.untracked+e.deleted+e.renamed>0:!1}function jm(e){return((e==null?void 0:e.submodules)??[]).some(t=>t.dirty)}function Mi(e){return((e==null?void 0:e.submodules)??[]).some(t=>t.outOfSync||!!t.error)}function qw(e){return Mi(e)?"degraded":jm(e)?"dirty":"online"}function Yw(e){return e?e.staged+e.modified+e.untracked+e.deleted+e.renamed:0}function fc(e){switch(e){case"online":return 0;case"dirty":return 1;case"degraded":return 2;case"wrong_branch":return 3;case"offline":return 4;case"unknown":default:return 5}}function Za(e){return e.length===0?"unknown":e.reduce((t,r)=>fc(r)>fc(t)?r:t)}function Xw(e){var o,i,c,d,m;const t=new Map,r=new Map;for(const u of e){const p=(i=(o=u.git)==null?void 0:o.branch)==null?void 0:i.trim();p&&(r.set(p,(r.get(p)??0)+1),(c=u.git)!=null&&c.upstream&&t.set(p,(t.get(p)??0)+1))}const n=[...t.entries()].sort((u,p)=>{if(p[1]!==u[1])return p[1]-u[1];const f=["main","master","develop","dev"],y=f.indexOf(u[0]),g=f.indexOf(p[0]);return y!==-1||g!==-1?y===-1?1:g===-1?-1:y-g:u[0].localeCompare(p[0])});return(d=n[0])!=null&&d[0]?n[0][0]:((m=[...r.entries()].sort((u,p)=>p[1]-u[1])[0])==null?void 0:m[0])??null}function Jw(e,t){const r=[],n=e.git;return n?n.isGitRepo?(!n.branch&&n.headCommit&&r.push("Detached HEAD"),n.hasConflicts&&r.push("Merge conflicts need resolution"),n.branch&&t&&n.branch!==t&&!n.upstream&&r.push(`No upstream tracking for ${n.branch}`),n.upstream&&n.upstreamStatus&&n.upstreamStatus!=="fresh"&&r.push(`Upstream freshness unverified for ${n.branch??"workspace"}`),e.error&&r.push(e.error),r):(r.push("Not a git repository"),r):(r.push("No git status available"),r)}function xc(e){switch(e){case"merged_to_main":return 0;case"pushed_feature_branch_needs_merge":return 1;case"cleanup_candidate":return 2;case"blocked_review":return 3;case"not_mergeable":default:return 4}}function Qw(e){return e.reduce((t,r)=>xc(r.status)>xc(t.status)?r:t)}function Zw(e){const t=e.branchConvergenceSummary;if(Array.isArray(t==null?void 0:t.followUps))return t.followUps;const r=e.followUps;return Array.isArray(r)?r:(t==null?void 0:t.needsFollowUp)===!1||(t==null?void 0:t.unresolvedCount)===0?[]:null}function ej(e){var a,o,i;const t=e.sourceOfTruth,r=[],n=(a=t==null?void 0:t.fallback)==null?void 0:a.warning;return typeof n=="string"&&n.trim()&&r.push(n.trim()),(t==null?void 0:t.currentStatus)==="bootstrap_inventory_fallback"&&((o=t.directPeerTruth)==null?void 0:o.required)===!0&&((i=t.directPeerTruth)==null?void 0:i.satisfied)!==!0&&!r.some(c=>c.includes("direct mesh truth"))&&r.push("Direct mesh truth is not confirmed yet; this graph is drawn from setup inventory only."),r}function tj(e,t){return e.type!=="submoduleNode"&&e.branch===t&&e.ahead===0&&e.behind===0&&!e.dirty&&!e.hasConflicts&&(!e.upstreamStatus||e.upstreamStatus==="fresh")&&e.snapshotCompleteness==="complete"}function sj(e,t){var r,n;return{status:"merged_to_main",needsConvergence:!1,reason:"clean_default_branch_aggregate",nextStep:null,branch:e,defaultBranch:e,upstream:((r=t.find(a=>a.upstream))==null?void 0:r.upstream)??null,upstreamStatus:((n=t.find(a=>a.upstreamStatus))==null?void 0:n.upstreamStatus)??null,ahead:0,behind:0,dirty:!1,hasConflicts:!1}}function rj(e,t){if(vm(e))return null;const r=e.branchConvergence;if(!r||typeof r!="object")return null;const n=r.status;if(!n||!["merged_to_main","pushed_feature_branch_needs_merge","blocked_review","cleanup_candidate","not_mergeable"].includes(n))return null;const a=e.git,o=wm(a)||jm(a),i=!!(a!=null&&a.hasConflicts)||Mi(a),c=(a==null?void 0:a.ahead)??0,d=(a==null?void 0:a.behind)??0,m=(a==null?void 0:a.branch)??null,u=(a==null?void 0:a.upstream)??null,p=(a==null?void 0:a.upstreamStatus)??null,f=r.defaultBranch??t??null;return{status:n,needsConvergence:r.needsConvergence??n!=="merged_to_main",reason:r.reason??"provided_by_coordinator",nextStep:r.nextStep??null,branch:r.branch??m,defaultBranch:f,upstream:r.upstream??u,upstreamStatus:r.upstreamStatus??p,ahead:r.ahead??c,behind:r.behind??d,dirty:r.dirty??o,hasConflicts:r.hasConflicts??i}}function nj(e,t){const r=rj(e,t);return r?{...r,defaultBranch:r.defaultBranch??t}:null}function aj(e){return e.error||e.outOfSync?"degraded":e.dirty?"dirty":"online"}function oj(e){var d,m,u;const{nodeStatus:t,expectedSubmodulePaths:r,refreshedAtMs:n}=e,a=[],o=t.machineLabel||t.nodeId,i=t.git;if(!i){if(vm(t))return a.push(`${o} is still waiting for a live peer git snapshot from the selected coordinator.`),{snapshotCompleteness:"pending_git",snapshotWarnings:a};const p=t.health==="online"||t.machineStatus==="online"||((d=t.connection)==null?void 0:d.state)==="connected"||((m=t.connection)==null?void 0:m.state)==="self";return a.push(p?`${o} is online but no peer git snapshot is visible yet.`:`${o} has no peer git snapshot visible yet.`),{snapshotCompleteness:"missing_git",snapshotWarnings:a}}const c=new Set((i.submodules??[]).map(p=>p.path));if(r.size>0){const p=[...r].filter(f=>!c.has(f));p.length>0&&a.push(`${o} is missing submodule visibility for ${p.join(", ")} even though another peer reported it.`)}return((u=t.connection)==null?void 0:u.state)!=="self"&&n!==null&&typeof i.lastCheckedAt=="number"&&n-i.lastCheckedAt>Kw&&a.push(`${o} is relying on a peer git snapshot older than 5m; re-probe before trusting convergence.`),a.some(p=>p.includes("submodule visibility"))?{snapshotCompleteness:"missing_submodule_report",snapshotWarnings:a}:a.some(p=>p.includes("older than 5m"))?{snapshotCompleteness:"stale",snapshotWarnings:a}:{snapshotCompleteness:"complete",snapshotWarnings:a}}function ij(e){const t=xm(e),n=(typeof t.defaultBranch=="string"&&t.defaultBranch.trim().length>0?t.defaultBranch.trim():null)??Xw(t.nodes),a=Gw(t.refreshedAt),o=new Set(t.nodes.flatMap(M=>{var A;return(((A=M.git)==null?void 0:A.submodules)??[]).map(H=>H.path)})),i=[],c=[],d=ej(t),m=new Map;for(const M of t.nodes){const A=M.git,H=(A==null?void 0:A.branch)??null,P=qw(A),D=wm(A)||P==="dirty",O=Jw(M,n),R=nj(M,n),B=oj({nodeStatus:M,expectedSubmodulePaths:o,refreshedAtMs:a}),E=typeof M.clonedFromNodeId=="string"?M.clonedFromNodeId:null,F=Vw(M),Q={id:M.nodeId,type:O.length>0?"orphanNode":"worktreeNode",label:M.machineLabel||M.nodeId.slice(0,8),workspace:M.workspace,branch:H,upstream:(A==null?void 0:A.upstream)??null,upstreamStatus:(A==null?void 0:A.upstreamStatus)??null,daemonId:gm(M),machineId:ym(M),machineLabel:M.machineLabel||null,locality:Uw(M),health:Za([M.health,P]),ahead:(A==null?void 0:A.ahead)??0,behind:(A==null?void 0:A.behind)??0,dirty:D,dirtyFiles:Yw(A),hasConflicts:(A==null?void 0:A.hasConflicts)??!1,activeSessionCount:F.length,activeSessions:F.map(Z=>Z.sessionId),sessionDetails:F,providers:M.providers??[],isOrphan:O.length>0,orphanReasons:O,error:M.error,nextStepHint:B.snapshotWarnings[0]??O[0]??(R==null?void 0:R.nextStep)??void 0,parentNodeId:null,clonedFromNodeId:E,worktreeBranch:M.worktreeBranch??null,submodulePath:null,submoduleCommit:(A==null?void 0:A.headCommit)??null,outOfSync:Mi(A),snapshotCompleteness:B.snapshotCompleteness,snapshotWarnings:B.snapshotWarnings,branchConvergence:R,source:M};if(i.push(Q),H){const Z=m.get(H)??[];Z.push(Q.id),m.set(H,Z)}for(const Z of(A==null?void 0:A.submodules)??[]){const Y=`${Q.id}::submodule::${Z.path}`,te=Z.path.split("/").filter(Boolean).pop()||Z.path;i.push({id:Y,type:"submoduleNode",label:te,workspace:Z.repoPath,branch:null,upstream:null,upstreamStatus:null,daemonId:Q.daemonId,machineId:Q.machineId,machineLabel:Q.machineLabel,locality:Q.locality,health:aj(Z),ahead:0,behind:0,dirty:Z.dirty,dirtyFiles:Z.dirty?1:0,hasConflicts:!1,activeSessionCount:0,activeSessions:[],sessionDetails:[],providers:[],isOrphan:!1,orphanReasons:[],error:Z.error,nextStepHint:Z.error||(Z.outOfSync?`${Z.path} is out of sync with the parent checkout`:Z.dirty?`${Z.path} has local changes`:`${Z.path} is in sync with the parent checkout`),parentNodeId:Q.id,submodulePath:Z.path,submoduleCommit:Z.commit,outOfSync:Z.outOfSync,snapshotCompleteness:"complete",snapshotWarnings:[],branchConvergence:null,source:{kind:"synthetic-submodule",parentNodeId:Q.id,parentWorkspace:M.workspace,submodule:Z}}),c.push({id:`${Q.id}--${Y}`,source:Q.id,target:Y,type:"submoduleLink",label:Z.outOfSync?"submodule out of sync":"submodule",direction:"directed"})}}const u=n?`__branch_${n}`:null;if(u&&n){const A=(m.get(n)??[]).map(E=>i.find(F=>F.id===E)).filter(Boolean),H=A.map(E=>E.branchConvergence).filter(Boolean),P=Zw(t),D=A.length>0&&A.every(E=>tj(E,n)),O=(P==null?void 0:P.length)===0&&D?sj(n,A):H.length>0?Qw(H):null,R=(P==null?void 0:P.length)===0&&D?0:H.filter(E=>E.needsConvergence).length,B={id:u,type:"defaultBranchNode",label:n,workspace:t.repoIdentity,branch:n,upstream:null,upstreamStatus:null,daemonId:null,machineId:null,machineLabel:"default branch",locality:"unknown",health:Za(A.map(E=>E.health)),ahead:0,behind:0,dirty:A.some(E=>E.dirty),dirtyFiles:A.reduce((E,F)=>E+F.dirtyFiles,0),hasConflicts:A.some(E=>E.hasConflicts),activeSessionCount:A.reduce((E,F)=>E+F.activeSessionCount,0),activeSessions:A.flatMap(E=>E.activeSessions),sessionDetails:A.flatMap(E=>E.sessionDetails),providers:[...new Set(A.flatMap(E=>E.providers))],isOrphan:!1,orphanReasons:[],nextStepHint:R>0?`${R} workspace(s) on ${n} still need follow-up`:A.length>0?`${A.length} workspace(s) currently on ${n}`:"No workspaces currently checked out to the default branch",error:void 0,parentNodeId:null,submodulePath:null,submoduleCommit:null,outOfSync:!1,snapshotCompleteness:"complete",snapshotWarnings:[],branchConvergence:O,source:{nodeId:u,machineLabel:n,workspace:t.repoIdentity,health:Za(A.map(E=>E.health)),providers:[],activeSessions:[],activeSessionDetails:[]}};i.push(B);for(const E of i)if(!(E.id===u||E.type==="submoduleNode")){if(E.branch===n){c.push({id:`${u}--${E.id}`,source:u,target:E.id,type:"parentBranch",label:"checked out",direction:"undirected"});continue}if(E.branch){c.push({id:`${u}--${E.id}`,source:u,target:E.id,type:E.isOrphan?"orphanLink":"parentBranch",label:E.branch,direction:"undirected"});continue}E.isOrphan&&c.push({id:`${u}--${E.id}`,source:u,target:E.id,type:"orphanLink",label:"detached",direction:"undirected"})}}const p=new Set(i.map(M=>M.id)),f=new Set;for(const M of i){if(!M.clonedFromNodeId||M.type==="submoduleNode"||!p.has(M.clonedFromNodeId))continue;const A=`clone_${M.clonedFromNodeId}--${M.id}`;if(f.has(A))continue;f.add(A);const H=M.worktreeBranch??M.branch??void 0;c.push({id:A,source:M.clonedFromNodeId,target:M.id,type:"cloneLink",label:H?`cloned · ${H}`:"cloned",direction:"directed"})}const y=i.filter(M=>M.type!=="defaultBranchNode"),g=y.filter(M=>M.isOrphan).length,x=y.filter(M=>M.hasConflicts).length,k=y.filter(M=>M.health==="offline").length,j=y.filter(M=>M.type==="submoduleNode"&&M.outOfSync).length,h=y.filter(M=>{var A;return M.type!=="submoduleNode"&&((A=M.branchConvergence)==null?void 0:A.needsConvergence)}).length,v=y.filter(M=>{var A;return((A=M.branchConvergence)==null?void 0:A.status)==="blocked_review"}).length,I=y.filter(M=>{var A;return((A=M.branchConvergence)==null?void 0:A.status)==="pushed_feature_branch_needs_merge"}).length,w=y.filter(M=>{var A;return((A=M.branchConvergence)==null?void 0:A.status)==="cleanup_candidate"}).length,b=y.filter(M=>{var A;return((A=M.branchConvergence)==null?void 0:A.status)==="not_mergeable"}).length,C=y.filter(M=>M.snapshotWarnings.length>0).length,N=y.filter(M=>M.snapshotCompleteness==="pending_git").length,S=y.filter(M=>M.snapshotCompleteness==="missing_git").length,T=y.filter(M=>M.snapshotCompleteness==="missing_submodule_report").length,_=y.filter(M=>M.snapshotCompleteness==="stale").length,L=[N>0?`${N} node(s) are still waiting for a live peer git snapshot`:null,S>0?`${S} node(s) have no visible peer git snapshot`:null,T>0?`${T} node(s) are missing peer submodule visibility reported elsewhere in the mesh`:null,_>0?`${_} node(s) rely on peer git snapshots older than 5m`:null].filter(Boolean);return h>0&&d.push(`${h} workspace(s) still need follow-up before the mesh is converged`),g>0&&d.push(`${g} workspace(s) need attention before safe coordination`),v>0&&d.push(`${v} workspace(s) are blocked on branch convergence or upstream sync`),I>0&&d.push(`${I} clean feature branch workspace(s) still need merge follow-up`),w>0&&d.push(`${w} worktree workspace(s) are ready for refine / cleanup`),b>0&&d.push(`${b} workspace(s) have local changes or conflicts blocking convergence`),x>0&&d.push(`${x} workspace(s) report merge conflicts`),k>0&&d.push(`${k} node(s) are currently offline`),j>0&&d.push(`${j} submodule(s) are out of sync with their parent checkout`),d.push(...L),n||d.push("Could not infer a default branch from live mesh status"),{meshId:t.meshId,meshName:t.meshName,repoIdentity:t.repoIdentity,refreshedAt:t.refreshedAt,nodes:i,edges:c,stats:{totalNodes:y.length,onlineNodes:y.filter(M=>M.health==="online").length,dirtyNodes:y.filter(M=>M.dirty).length,orphanNodes:g,errorNodes:y.filter(M=>!!M.error||M.outOfSync).length,offlineNodes:k,followUpNodes:h,blockedReviewNodes:v,mergeReadyNodes:I,cleanupCandidateNodes:w,notMergeableNodes:b,incompleteSnapshotNodes:C,missingGitSnapshotNodes:S,missingSubmoduleSnapshotNodes:T,staleGitSnapshotNodes:_,totalActiveSessions:y.reduce((M,A)=>M+A.activeSessionCount,0)},warnings:d,snapshotWarnings:L}}const lj={recentFailures:0,taskCompleted:0,taskFailed:0,sessionLaunched:0},Ai=l.createContext(Ys("dark"));function Fe({label:e,tone:t="default"}){const r=l.useContext(Ai);return s.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] ${r.badge(t)}`,children:e})}function rt({label:e,value:t}){const r=l.useContext(Ai);return s.jsxs("div",{className:r.rowClass,children:[s.jsx("span",{className:r.rowLabelClass,children:e}),s.jsx("span",{className:r.rowValueClass,children:t})]})}function bc(e){switch(e){case"online":return"good";case"dirty":return"warn";case"degraded":case"offline":return"danger";case"wrong_branch":return"info";default:return"default"}}function eo(e){switch((e||"").toLowerCase()){case"idle":return"good";case"generating":case"running":return"info";case"waiting_approval":case"starting":case"pending":return"warn";case"failed":case"stopped":case"interrupted":return"danger";default:return"default"}}function yn(e){const t=(e.chatStatus||e.state||e.lifecycle||"").trim();if(!t)return"unknown";const r=t.toLowerCase().replace(/[\s-]+/g,"_");return r.includes("approval")?"awaiting approval":r.includes("generating")||r.includes("running")||r.includes("busy")?"generating":r.includes("idle")||r.includes("ready")||r.includes("waiting_input")?"idle":r.replace(/_/g," ")}function cj(e){return e.isSelfCoordinator?"coordinator":(typeof e.role=="string"?e.role.trim():"")||"worker"}function dj(e){return e.startedAt||e.createdAt||null}function uj(e){const t=dj(e);if(!t)return"runtime age not reported";const r=Date.parse(t);if(!Number.isFinite(r))return"runtime age not reported";const n=Math.max(0,Math.floor((Date.now()-r)/1e3));if(n<60)return`${n}s`;const a=Math.floor(n/60);if(a<60)return`${a}m`;const o=Math.floor(a/60);return o<48?`${o}h ${a%60}m`:`${Math.floor(o/24)}d ${o%24}h`}function mj(e){return e.length<=18?e:`${e.slice(0,10)}...${e.slice(-4)}`}function pj(e){if(!e)return"default";if(e.state==="self")return"info";if(e.transport==="direct"&&e.state==="connected")return"good";if(e.transport==="relay"&&e.state==="connected")return"info";switch(e.state){case"connected":return"good";case"connecting":return"warn";case"disconnected":case"failed":case"closed":return"danger";default:return"default"}}function hj(e){return e?e.state==="self"?"mesh self":e.transport==="direct"&&e.state==="connected"?"mesh direct":e.transport==="relay"&&e.state==="connected"?"mesh relay":!e.reported&&e.source==="not_reported"?"mesh unknown / not reported":`mesh ${e.state}`:"mesh unknown"}function fj(e){var r;const t=[];for(const n of e.nodes){const a=n.activeSessionDetails&&n.activeSessionDetails.length>0?n.activeSessionDetails:(n.activeSessions??[]).map(o=>({sessionId:o,workspace:n.workspace,isCached:!0}));for(const o of a)t.push({nodeId:n.nodeId,machineLabel:n.machineLabel,workspace:n.workspace,branch:((r=n.git)==null?void 0:r.branch)??null,nodeHealth:n.health,session:o})}return t}function xj(e){return e.assignedNodeId||e.targetNodeId||null}function gc(e){return e?e.slice(0,7):null}function bj(e,t){var o,i,c;const r=gc((o=e==null?void 0:e.git)==null?void 0:o.headCommit),n=((c=(i=e==null?void 0:e.git)==null?void 0:i.headMessage)==null?void 0:c.trim())||"";if(r||n)return[r,n].filter(Boolean).join(" · ");const a=t[0];return a?[gc(a.commit),a.message].filter(Boolean).join(" · "):null}function gj(e,t){const r=bj(e,t);return r||(e!=null&&e.gitProbePending?"Pending live git probe":null)}function yj(e){const t=(e==null?void 0:e.result)??e,r=(t==null?void 0:t.log)??(e==null?void 0:e.log)??t;return Array.isArray(r==null?void 0:r.entries)?r.entries:[]}function vj(e){var r,n,a,o,i,c;const t=((r=e.selectedSessionEntry)==null?void 0:r.session.workspace)||((n=e.selectedSessionEntry)==null?void 0:n.workspace)||((o=(a=e.selectedNodeStatus)==null?void 0:a.git)==null?void 0:o.workspace)||((i=e.selectedNodeStatus)==null?void 0:i.workspace)||null;if(t&&e.selectedSessionEntry){const d=((c=e.selectedNodeStatus)==null?void 0:c.daemonId)||e.coordinatorDaemonId;return d?{daemonId:d,workspace:t}:null}if(t&&e.selectedNodeStatus){const d=e.selectedNodeStatus.daemonId||e.coordinatorDaemonId;return d?{daemonId:d,workspace:t}:null}return null}function wj(e){return e.gitProbePending&&(!e.connection||e.connection.state==="unknown")?"mesh pending":hj(e.connection)}function yc(e){var r;const t=e.source;return t!=null&&t.kind?t.kind:((r=t==null?void 0:t.connection)==null?void 0:r.source)??"mesh_status"}function vc(e){switch(e.type){case"parentBranch":return"default branch link";case"worktreeLink":return"worktree relationship";case"sessionLink":return"session relationship";case"orphanLink":return"orphan relationship";case"submoduleLink":return"submodule relationship";case"cloneLink":return"clone relationship";default:return e.type}}function jj(e){return e.direction==="directed"?"directed":"undirected"}function wc(e,t){return t?e.nodes.find(r=>r.id===t)??null:null}function kj(e){var t,r,n,a;return[e.meshId,e.refreshedAt,e.nodes.length,((r=(t=e.queue)==null?void 0:t.summary)==null?void 0:r.active)??"",((a=(n=e.ledger)==null?void 0:n.summary)==null?void 0:a.recentFailures)??"",...e.nodes.map(o=>{var i,c,d,m,u,p,f,y,g,x,k,j,h,v,I,w,b,C,N,S,T,_;return[o.nodeId,o.daemonId??"",o.machineId??"",o.machineLabel,o.machineStatus??"",((i=o.connection)==null?void 0:i.state)??"",((c=o.connection)==null?void 0:c.transport)??"",((d=o.connection)==null?void 0:d.source)??"",o.health,o.gitProbePending?1:0,((m=o.git)==null?void 0:m.branch)??"",((u=o.git)==null?void 0:u.upstream)??"",((p=o.git)==null?void 0:p.upstreamStatus)??"",((f=o.git)==null?void 0:f.ahead)??"",((y=o.git)==null?void 0:y.behind)??"",((g=o.git)==null?void 0:g.headCommit)??"",((x=o.git)==null?void 0:x.staged)??"",((k=o.git)==null?void 0:k.modified)??"",((j=o.git)==null?void 0:j.untracked)??"",((h=o.git)==null?void 0:h.deleted)??"",((v=o.git)==null?void 0:v.renamed)??"",(I=o.git)!=null&&I.hasConflicts?1:0,((w=o.git)==null?void 0:w.lastCheckedAt)??"",((b=o.activeSessions)==null?void 0:b.join(","))??"",((C=o.activeSessionDetails)==null?void 0:C.length)??"",((N=o.activeSessionDetails)==null?void 0:N.map(L=>[L.sessionId,L.providerType??"",L.state??"",L.chatStatus??"",L.lifecycle??"",L.role??"",L.isSelfCoordinator?1:0,L.statusNote??"",L.startedAt??"",L.createdAt??""].join("/")).join(","))??"",((S=o.providers)==null?void 0:S.join(","))??"",((T=o.providerPriority)==null?void 0:T.join(","))??"",o.error??"",(((_=o.git)==null?void 0:_.submodules)??[]).map(L=>[L.path,L.commit,L.dirty?1:0,L.outOfSync?1:0,L.error??""].join("/")).join(",")].join("|")})].join("::")}function km({status:e,emptyMessage:t="No live mesh graph is available for this coordinator yet.",daemonId:r=null,sendDaemonCommand:n=null}){var de,Ie,ee,ve,ce;const{theme:a}=qs(),o=l.useMemo(()=>Ys(a),[a]),i=l.useMemo(()=>xm(e),[e]),c=l.useMemo(()=>kj(i),[i]),d=l.useMemo(()=>ij(i),[c]),[m,u]=l.useState(null),[p,f]=l.useState(null),[y,g]=l.useState(null),[x,k]=l.useState(null),[j,h]=l.useState({}),[v,I]=l.useState(null),[w,b]=l.useState(null),C=l.useMemo(()=>new Map(i.nodes.map(W=>[W.nodeId,W])),[i.nodes]),N=l.useMemo(()=>new Map(d.nodes.map(W=>[W.id,W])),[d.nodes]),S=((de=i.queue)==null?void 0:de.summary)??null,T=((Ie=i.ledger)==null?void 0:Ie.summary)??lj,_=l.useMemo(()=>fj(i),[i]),L=l.useMemo(()=>{const W=new Map;for(const ne of _){const ue=yn(ne.session);W.set(ue,(W.get(ue)??0)+1)}return[...W.entries()].sort((ne,ue)=>ue[1]-ne[1])},[_]);l.useEffect(()=>{m&&(N.has(m)||(u(null),k(W=>!W||"nodeId"in W&&W.nodeId===m?null:W)))},[N,m]);const M=m?C.get(m)??null:null,A=wc(d,m),H=wc(d,p),P=y?d.edges.find(W=>W.id===y)??null:null,D=P?d.nodes.find(W=>W.id===P.source)??null:null,O=P?d.nodes.find(W=>W.id===P.target)??null:null;l.useEffect(()=>{var W,ne,ue;if(m)try{console.info("[RepoMeshGraphDebug]",{event:"selected_canonical_node",meshId:i.meshId,selectedNodeId:m,canonicalNode:Fw(M),graphNode:A?{id:A.id,branch:A.branch,upstream:A.upstream,headCommit:A.submoduleCommit,submoduleCount:((ne=(W=M==null?void 0:M.git)==null?void 0:W.submodules)==null?void 0:ne.length)??0,snapshotCompleteness:A.snapshotCompleteness,snapshotWarnings:A.snapshotWarnings,branchConvergence:((ue=A.branchConvergence)==null?void 0:ue.status)??null}:null})}catch{}},[i.meshId,A,m,M]);const R=(x==null?void 0:x.kind)==="session"?_.find(W=>W.nodeId===x.nodeId&&W.session.sessionId===x.sessionId)??null:null,B=l.useMemo(()=>_.filter(W=>W.nodeId===m),[m,_]),E=vj({coordinatorDaemonId:r,selectedNodeStatus:M,selectedSessionEntry:R}),F=(E==null?void 0:E.workspace)??null,Q=F?j[F]??null:null,Z=gj(M,(Q==null?void 0:Q.entries)??[]),Y=(A==null?void 0:A.daemonId)??(M==null?void 0:M.daemonId)??r??null,te=!!(A&&n&&Y&&A.type!=="submoduleNode"&&A.behind>0&&A.ahead===0&&A.dirtyFiles===0&&!A.dirty&&!A.hasConflicts&&A.upstreamStatus==="fresh"),fe=l.useCallback(()=>{u(null),k(null),I(null)},[]);l.useEffect(()=>{I(null)},[m]);const Ne=l.useCallback(async()=>{if(!(!A||!Y||!n||!te)){b(A.id),I(null);try{const W=await n(Y,"fast_forward_mesh_node",{meshId:i.meshId,nodeId:A.id,dryRun:!0,execute:!1});if(I({phase:"dry_run",code:typeof(W==null?void 0:W.code)=="string"?W.code:void 0,error:typeof(W==null?void 0:W.operationError)=="string"?W.operationError:null,executed:(W==null?void 0:W.executed)===!0}),!(W!=null&&W.success)||W.code!=="fast_forward_available"||!window.confirm(`Apply fast-forward for ${A.label}?`))return;const ue=await n(Y,"fast_forward_mesh_node",{meshId:i.meshId,nodeId:A.id,dryRun:!1,execute:!0});I({phase:"execute",code:typeof(ue==null?void 0:ue.code)=="string"?ue.code:void 0,error:typeof(ue==null?void 0:ue.operationError)=="string"?ue.operationError:null,executed:(ue==null?void 0:ue.executed)===!0})}catch(W){I({phase:"dry_run",error:W instanceof Error?W.message:"fast-forward failed"})}finally{b(null)}}},[te,i.meshId,A,Y,n]);l.useEffect(()=>{if(!A)return;const W=ne=>{ne.key==="Escape"&&fe()};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[fe,A]),l.useEffect(()=>{if(!E||!n)return;const{daemonId:W,workspace:ne}=E,ue=j[ne];if(ue!=null&&ue.loading||ue&&(ue.entries.length>0||ue.error))return;let me=!1;return h(J=>{var q;return{...J,[ne]:{loading:!0,error:null,entries:((q=J[ne])==null?void 0:q.entries)??[]}}}),n(W,"git_log",{workspace:ne,limit:5}).then(J=>{me||h(q=>({...q,[ne]:{loading:!1,error:null,entries:yj(J)}}))}).catch(J=>{me||h(q=>({...q,[ne]:{loading:!1,error:J instanceof Error?J.message:"git_log failed",entries:[]}}))}),()=>{me=!0}},[j,E,n]);const X=[...d.warnings??[],...i.nodes.filter(W=>W.machineStatus&&W.machineStatus!=="online").map(W=>`${W.machineLabel}: ${W.machineStatus}`)],we=d.stats.incompleteSnapshotNodes>0,ge=d.stats.followUpNodes>0?`${d.stats.followUpNodes} need follow-up`:we?"mesh visibility incomplete":"mesh converged",be=d.stats.followUpNodes>0?"danger":we?"warn":"good";return s.jsx(Ai.Provider,{value:o,children:s.jsx("div",{className:"flex min-h-0 flex-1 flex-col gap-4",children:s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:s.jsxs("div",{className:`${o.cardClass} relative flex min-h-0 flex-1 flex-col rounded-[28px] p-3 sm:p-4`,style:{minHeight:420},children:[s.jsxs("div",{className:`absolute inset-x-4 top-4 z-30 flex max-h-[42dvh] flex-wrap items-start justify-between gap-3 overflow-y-auto rounded-2xl px-3.5 py-3 backdrop-blur-xl sm:static sm:mb-3 sm:max-h-none sm:overflow-visible sm:backdrop-blur-none ${o.isDark?"border border-white/10 bg-slate-950/85 sm:bg-slate-950/45":"border border-slate-200 bg-white/95 shadow-lg shadow-slate-900/10 sm:bg-white/95 sm:shadow-sm"}`,children:[s.jsxs("div",{className:`flex min-w-0 flex-1 flex-wrap gap-2 text-xs ${o.textSecondary}`,children:[s.jsx(Fe,{label:ge,tone:be}),d.stats.blockedReviewNodes>0&&s.jsx(Fe,{label:`${d.stats.blockedReviewNodes} blocked review`,tone:"danger"}),d.stats.notMergeableNodes>0&&s.jsx(Fe,{label:`${d.stats.notMergeableNodes} not mergeable`,tone:"danger"}),d.stats.mergeReadyNodes>0&&s.jsx(Fe,{label:`${d.stats.mergeReadyNodes} need merge`,tone:"warn"}),d.stats.cleanupCandidateNodes>0&&s.jsx(Fe,{label:`${d.stats.cleanupCandidateNodes} refine/cleanup`,tone:"info"}),d.stats.offlineNodes>0&&s.jsx(Fe,{label:`${d.stats.offlineNodes} offline`,tone:"danger"}),d.stats.incompleteSnapshotNodes>0&&s.jsx(Fe,{label:`${d.stats.incompleteSnapshotNodes} incomplete peer snapshot`,tone:"warn"}),d.stats.missingGitSnapshotNodes>0&&s.jsx(Fe,{label:`${d.stats.missingGitSnapshotNodes} no git snapshot`,tone:"warn"}),d.stats.missingSubmoduleSnapshotNodes>0&&s.jsx(Fe,{label:`${d.stats.missingSubmoduleSnapshotNodes} missing submodule visibility`,tone:"warn"}),d.stats.staleGitSnapshotNodes>0&&s.jsx(Fe,{label:`${d.stats.staleGitSnapshotNodes} stale peer snapshot`,tone:"warn"}),((S==null?void 0:S.active)??0)>0&&s.jsx(Fe,{label:`${(S==null?void 0:S.active)??0} active queue`,tone:"info"}),s.jsx(Fe,{label:`${d.stats.totalNodes} nodes`,tone:"default"}),d.stats.totalActiveSessions>0&&s.jsx(Fe,{label:`${d.stats.totalActiveSessions} attached chats`,tone:"info"})]}),s.jsxs("details",{className:`max-w-full rounded-xl px-3 py-2 text-xs ${o.isDark?"border border-white/10 bg-white/[0.03] text-slate-300":"border border-slate-200 bg-slate-50 text-slate-600"}`,children:[s.jsx("summary",{className:`cursor-pointer list-none font-medium ${o.textSecondary} [&::-webkit-details-marker]:hidden`,children:"Legend & secondary details"}),s.jsxs("div",{className:"mt-3 flex flex-col gap-3",children:[s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(Fe,{label:`${d.stats.dirtyNodes} dirty`,tone:d.stats.dirtyNodes>0?"warn":"good"}),s.jsx(Fe,{label:`${d.stats.orphanNodes} orphan`,tone:d.stats.orphanNodes>0?"warn":"good"}),s.jsx(Fe,{label:`${T.recentFailures} recent failures`,tone:T.recentFailures>0?"danger":"good"}),L.length===0?s.jsx(Fe,{label:"no session metadata"}):L.slice(0,2).map(([W,ne])=>s.jsx(Fe,{label:`${ne} ${W}`,tone:eo(W)},W))]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(Fe,{label:"Anchor = default branch",tone:"info"}),s.jsx(Fe,{label:"Peer link = same-branch worktree",tone:"default"}),s.jsx(Fe,{label:"Submodule link = child checkout",tone:"warn"})]}),X.length>0&&s.jsx("div",{className:"flex flex-wrap gap-2",children:X.map(W=>s.jsx("span",{className:o.isDark?"rounded-full border border-amber-400/20 bg-amber-500/10 px-3 py-1 text-xs text-amber-100":"rounded-full border border-amber-300 bg-amber-50 px-3 py-1 text-xs text-amber-700",children:W},W))}),s.jsx("div",{className:`text-xs ${o.textMuted}`,children:"Hover nodes or edges for a quick preview. Click a node when you want pinned drill-down details."})]})]})]}),d.nodes.length>0?s.jsx(Cw,{data:d,selectedNodeId:m,onNodeHoverChange:W=>{f((W==null?void 0:W.id)??null),W&&g(null)},onEdgeHoverChange:W=>{g((W==null?void 0:W.id)??null),W&&f(null)},onNodeClick:W=>{if((x==null?void 0:x.kind)==="node"&&m===W.id){u(null),k(null);return}u(W.id),k({kind:"node",nodeId:W.id})}}):s.jsx("div",{className:"flex h-full min-h-[320px] items-center justify-center px-6 text-center text-sm text-slate-400",children:t}),!A&&H&&s.jsx("div",{className:"pointer-events-none absolute inset-x-3 bottom-3 z-20 flex justify-center p-2 sm:inset-x-auto sm:right-5 sm:top-24 sm:bottom-auto sm:justify-end",children:s.jsxs("section",{"aria-label":"Hovered node preview",className:o.isDark?"w-full max-w-[min(24rem,calc(100vw-2.5rem))] rounded-2xl border border-white/12 bg-slate-950/94 p-4 shadow-2xl shadow-black/35 backdrop-blur-xl":"w-full max-w-[min(24rem,calc(100vw-2.5rem))] rounded-2xl border border-slate-200 bg-white/96 p-4 shadow-2xl shadow-slate-900/12 backdrop-blur-xl",children:[s.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:`truncate text-sm font-semibold ${o.textPrimary}`,children:H.label}),s.jsx("div",{className:`mt-1 font-mono text-[11px] ${o.textMuted}`,children:H.id.slice(0,16)})]}),s.jsx(Fe,{label:"hover preview",tone:"info"})]}),s.jsxs("div",{className:"mb-3 flex flex-wrap gap-2",children:[s.jsx(Fe,{label:H.health,tone:bc(H.health)}),H.branch&&s.jsx(Fe,{label:H.branch,tone:"default"}),H.ahead>0&&s.jsx(Fe,{label:`ahead ${H.ahead}`,tone:"warn"}),H.behind>0&&s.jsx(Fe,{label:`behind ${H.behind}`,tone:"warn"}),H.dirtyFiles>0&&s.jsx(Fe,{label:`${H.dirtyFiles} dirty`,tone:"warn"}),H.activeSessionCount>0&&s.jsx(Fe,{label:`${H.activeSessionCount} sessions`,tone:"info"})]}),s.jsxs("div",{className:"grid gap-2 text-xs sm:grid-cols-2",children:[s.jsx(rt,{label:"Machine",value:H.machineLabel??"not reported"}),s.jsx(rt,{label:"Locality",value:H.locality}),s.jsx(rt,{label:"Workspace",value:H.workspace}),s.jsx(rt,{label:"Upstream",value:H.upstream??"none"}),s.jsx(rt,{label:"Dirty/ahead/behind",value:`${H.dirtyFiles} dirty · ↑${H.ahead}/↓${H.behind}`}),s.jsx(rt,{label:"Source",value:yc(H)})]})]})}),!A&&!H&&P&&s.jsx("div",{className:"pointer-events-none absolute inset-x-3 bottom-3 z-20 flex justify-center p-2 sm:inset-x-auto sm:right-5 sm:top-24 sm:bottom-auto sm:justify-end",children:s.jsxs("section",{"aria-label":"Hovered edge preview",className:o.isDark?"w-full max-w-[min(22rem,calc(100vw-2.5rem))] rounded-2xl border border-white/12 bg-slate-950/94 p-4 shadow-2xl shadow-black/35 backdrop-blur-xl":"w-full max-w-[min(22rem,calc(100vw-2.5rem))] rounded-2xl border border-slate-200 bg-white/96 p-4 shadow-2xl shadow-slate-900/12 backdrop-blur-xl",children:[s.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:`truncate text-sm font-semibold ${o.textPrimary}`,children:P.label||vc(P)}),s.jsx("div",{className:`mt-1 text-[11px] ${o.textMuted}`,children:P.id})]}),s.jsx(Fe,{label:"hover preview",tone:"info"})]}),s.jsxs("div",{className:"mb-3 flex flex-wrap gap-2",children:[s.jsx(Fe,{label:vc(P),tone:"default"}),s.jsx(Fe,{label:jj(P),tone:"info"})]}),s.jsxs("div",{className:"grid gap-2 text-xs",children:[s.jsx(rt,{label:"From",value:(D==null?void 0:D.label)??P.source}),s.jsx(rt,{label:"To",value:(O==null?void 0:O.label)??P.target}),s.jsx(rt,{label:"Label",value:P.label??"none"})]})]})}),A&&(x==null?void 0:x.kind)==="node"&&s.jsx("div",{className:"absolute inset-x-3 bottom-3 top-20 z-20 flex items-end justify-center p-2 sm:inset-5 sm:top-24 sm:items-start sm:justify-end",onClick:fe,role:"presentation",children:s.jsxs("section",{role:"dialog","aria-modal":"false","aria-label":"Selected node",className:o.isDark?"max-h-[min(72vh,540px)] w-full max-w-[min(28rem,calc(100vw-2.5rem))] overflow-y-auto rounded-2xl border border-white/12 bg-slate-950/96 p-4 shadow-2xl shadow-black/40 backdrop-blur-xl":"max-h-[min(72vh,540px)] w-full max-w-[min(28rem,calc(100vw-2.5rem))] overflow-y-auto rounded-2xl border border-slate-200 bg-white/96 p-4 shadow-2xl shadow-slate-900/15 backdrop-blur-xl",onClick:W=>W.stopPropagation(),children:[s.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:`truncate text-sm font-semibold ${o.textPrimary}`,children:A.label}),s.jsx("div",{className:`mt-1 font-mono text-[11px] ${o.textMuted}`,children:A.id.slice(0,16)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[A.behind>0&&s.jsx("button",{type:"button",onClick:()=>{Ne()},disabled:!te||w===A.id,className:o.isDark?"rounded-full border border-emerald-400/25 bg-emerald-500/10 px-2.5 py-1 text-xs font-semibold text-emerald-100 transition hover:bg-emerald-500/18 disabled:cursor-not-allowed disabled:opacity-45":"rounded-full border border-emerald-300 bg-emerald-50 px-2.5 py-1 text-xs font-semibold text-emerald-700 transition hover:bg-emerald-100 disabled:cursor-not-allowed disabled:opacity-45",children:w===A.id?"Checking":"Heal"}),s.jsx("button",{type:"button",onClick:fe,className:o.isDark?"rounded-full border border-white/10 bg-white/[0.04] px-2.5 py-1 text-xs text-slate-200 transition hover:bg-white/[0.08]":"rounded-full border border-slate-200 bg-white px-2.5 py-1 text-xs text-slate-600 transition hover:bg-slate-50",children:"Close"})]})]}),s.jsxs("div",{className:"mb-3 flex flex-wrap gap-2",children:[s.jsx(Fe,{label:(M==null?void 0:M.health)??A.health,tone:bc((M==null?void 0:M.health)??A.health)}),A.branch&&s.jsx(Fe,{label:A.branch,tone:"default"}),A.ahead>0&&s.jsx(Fe,{label:`ahead ${A.ahead}`,tone:"warn"}),A.behind>0&&s.jsx(Fe,{label:`behind ${A.behind}`,tone:"warn"}),A.dirtyFiles>0&&s.jsx(Fe,{label:`${A.dirtyFiles} dirty`,tone:"warn"}),(M==null?void 0:M.connection)&&s.jsx(Fe,{label:wj(M),tone:pj(M.connection)}),B.length>0&&s.jsx(Fe,{label:`${B.length} sessions`,tone:"info"})]}),s.jsxs("div",{className:"grid gap-2 text-xs sm:grid-cols-2",children:[s.jsx(rt,{label:"Machine",value:A.machineLabel??"not reported"}),s.jsx(rt,{label:"Locality",value:A.locality}),s.jsx(rt,{label:"Machine id",value:A.machineId??(M==null?void 0:M.machineId)??"not reported"}),s.jsx(rt,{label:"Daemon id",value:A.daemonId??(M==null?void 0:M.daemonId)??"not reported"}),s.jsx(rt,{label:"Workspace",value:(M==null?void 0:M.workspace)??A.workspace}),s.jsx(rt,{label:"Branch",value:A.branch??"unknown"}),s.jsx(rt,{label:"HEAD",value:Z??(M!=null&&M.gitProbePending?"Pending live git probe":"not reported")}),s.jsx(rt,{label:"Upstream",value:A.upstream??"none"}),s.jsx(rt,{label:"Dirty/ahead/behind",value:`${A.dirtyFiles} dirty · ↑${A.ahead}/↓${A.behind}`}),s.jsx(rt,{label:"Source",value:String(((ee=M==null?void 0:M.connection)==null?void 0:ee.source)??yc(A))}),s.jsx(rt,{label:"Transport",value:((ve=M==null?void 0:M.connection)==null?void 0:ve.transport)??"unknown"}),s.jsx(rt,{label:"Sessions",value:B.length>0?B.map(W=>yn(W.session)).join(", "):"none active"})]}),B.length>0&&s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:`mb-1.5 text-[10px] uppercase tracking-wide ${o.textMuted}`,children:"Active Sessions"}),s.jsx("div",{className:"flex flex-col gap-1.5",children:B.map(W=>s.jsxs("div",{className:`rounded-lg border px-2.5 py-1.5 text-[11px] ${o.isDark?"border-white/8 bg-white/[0.03]":"border-slate-200 bg-slate-50/80"}`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:`min-w-0 truncate font-mono select-text ${o.textMuted}`,title:W.session.sessionId,children:mj(W.session.sessionId)}),s.jsx(Fe,{label:yn(W.session),tone:eo(yn(W.session))})]}),s.jsxs("div",{className:`mt-1 flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 ${o.textMuted}`,children:[s.jsx("span",{className:"truncate",children:W.session.providerType||"provider unknown"}),s.jsx("span",{children:cj(W.session)}),s.jsx("span",{children:uj(W.session)})]}),W.session.statusNote&&s.jsx("div",{className:`mt-1 text-[10px] leading-4 ${o.textMuted}`,children:W.session.statusNote}),s.jsxs("div",{className:`mt-0.5 truncate ${o.textMuted}`,title:W.session.workspace||W.workspace,children:[(W.session.workspace||W.workspace).slice(0,42),W.branch?` · ${W.branch}`:""]})]},W.session.sessionId))})]}),s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:`mb-1.5 text-[10px] uppercase tracking-wide ${o.textMuted}`,children:"Ledger (mesh-wide)"}),s.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[s.jsx(rt,{label:"Completed",value:String(T.taskCompleted)}),s.jsx(rt,{label:"Failed",value:s.jsx("span",{className:T.taskFailed>0?o.isDark?"text-rose-300":"text-rose-600":"",children:T.taskFailed})}),s.jsx(rt,{label:"Launched",value:String(T.sessionLaunched)}),s.jsx(rt,{label:"Recent failures",value:s.jsx("span",{className:T.recentFailures>0?o.isDark?"text-amber-300":"text-amber-600":"",children:T.recentFailures})})]})]}),(()=>{var ue,me;const W=((ue=i.queue)==null?void 0:ue.tasks)??((me=i.queue)==null?void 0:me.items)??null;if(!Array.isArray(W)||W.length===0)return null;const ne=W.filter(J=>xj(J)===m).slice(0,3);return ne.length===0?null:s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:`mb-1.5 text-[10px] uppercase tracking-wide ${o.textMuted}`,children:"Queue tasks"}),s.jsx("div",{className:"flex flex-col gap-1.5",children:ne.map(J=>s.jsxs("div",{className:`rounded-lg border px-2.5 py-1.5 text-[11px] ${o.isDark?"border-white/8 bg-white/[0.03]":"border-slate-200 bg-slate-50/80"}`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:`font-mono ${o.textMuted}`,children:J.id.slice(0,12)}),s.jsx(Fe,{label:J.status??"unknown",tone:eo(J.status)})]}),J.message&&s.jsx("div",{className:`mt-0.5 truncate ${o.textMuted}`,children:J.message.slice(0,48)})]},J.id))})]})})(),A.snapshotWarnings.length>0&&s.jsxs("div",{className:o.isDark?"mt-3 rounded-xl border border-amber-400/20 bg-amber-500/10 p-3 text-xs text-amber-100":"mt-3 rounded-xl border border-amber-300 bg-amber-50 p-3 text-xs text-amber-800",children:[s.jsx("div",{className:"font-medium",children:"Key warning"}),s.jsx("div",{className:"mt-1",children:A.snapshotWarnings[0]})]}),((ce=A.branchConvergence)==null?void 0:ce.nextStep)&&s.jsxs("div",{className:o.isDark?"mt-3 rounded-xl border border-sky-400/20 bg-sky-500/10 p-3 text-xs text-sky-100":"mt-3 rounded-xl border border-sky-300 bg-sky-50 p-3 text-xs text-sky-800",children:[s.jsx("div",{className:"font-medium",children:"Follow-up"}),s.jsx("div",{className:"mt-1",children:A.branchConvergence.nextStep})]}),v&&s.jsxs("div",{className:o.isDark?"mt-3 rounded-xl border border-emerald-400/20 bg-emerald-500/10 p-3 text-xs text-emerald-100":"mt-3 rounded-xl border border-emerald-300 bg-emerald-50 p-3 text-xs text-emerald-800",children:[s.jsx("div",{className:"font-medium",children:v.phase==="execute"?"Heal result":"Heal preview"}),s.jsx("div",{className:"mt-1",children:v.code??v.error??"No result code returned."})]})]})})]})})})})}function xt(e){return typeof e=="string"?e.trim():""}function Eo(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Ti(...e){const t=new Set;for(const r of e){const n=xt(r);n&&t.add(n)}return[...t]}function Sj(e,t){var p,f;const r=Eo(e==null?void 0:e.settings),n=xt((p=e==null?void 0:e.coordinator)==null?void 0:p.meshId)||xt(r.meshCoordinatorFor),a=xt(r.meshNodeFor),o=!!n||!!a,i=n===t||a===t;if(o&&!i)return null;const c=Eo(e==null?void 0:e.activeChat),d=Ti(e==null?void 0:e.id,e==null?void 0:e.sessionId,e==null?void 0:e.session_id,e==null?void 0:e.providerSessionId,e==null?void 0:e.provider_session_id,e==null?void 0:e.targetSessionId,e==null?void 0:e.target_session_id,c.sessionId,c.session_id,c.providerSessionId,c.provider_session_id),m=d[0]||"";if(!m)return null;const u=n===t?xt((f=e==null?void 0:e.coordinator)==null?void 0:f.role)||"coordinator":a===t?xt(r.meshNodeRole)||"worker":xt(e==null?void 0:e.role)||xt(r.meshNodeRole)||void 0;return{sessionId:m,aliases:d,meshId:t,nodeId:i&&xt(r.meshNodeId)||null,providerType:xt(e==null?void 0:e.providerType)||void 0,state:xt(e==null?void 0:e.status)||void 0,chatStatus:xt(c.status)||void 0,lifecycle:xt(e==null?void 0:e.runtimeLifecycle)||void 0,surfaceKind:xt(e==null?void 0:e.runtimeSurfaceKind)||void 0,recoveryState:xt(e==null?void 0:e.runtimeRecoveryState)||void 0,...u?{role:u}:{},...i?{isSelfCoordinator:n===t}:{},workspace:xt(e==null?void 0:e.workspace)||null}}function Sm(e,t){var n;return t?(Array.isArray((n=e.status)==null?void 0:n.sessions)?e.status.sessions:[]).map(a=>Sj(a,t)).filter(a=>a!==null):[]}function ta(e){return e.aliases&&e.aliases.length>0?e.aliases:[e.sessionId]}function Nj(e,t){const r=new Set(ta(t));return ta(e).some(n=>r.has(n))}function Cj(e,t){const r=t.filter(a=>!!a);return r.length===0?e:[...e.filter(a=>!r.some(o=>Nj(a,o))),...r]}function Ij(e,t){if(t.length===0)return e;const r=new Map;for(const o of t)for(const i of ta(o))r.set(i,o);let n=!1;const a=(e.nodes??[]).map(o=>{const i=Array.isArray(o.activeSessionDetails)?o.activeSessionDetails:Array.isArray(o.sessions)?o.sessions:[],c=new Map;for(const m of i){const u=Ti(m==null?void 0:m.sessionId,m==null?void 0:m.session_id,m==null?void 0:m.id,m==null?void 0:m.providerSessionId,m==null?void 0:m.provider_session_id),p=u[0]||"";if(!p)continue;const f=u.map(y=>r.get(y)).find(Boolean);f&&(n=!0),c.set(p,f?{...m,sessionId:p,providerType:f.providerType||m.providerType,state:f.state||m.state,chatStatus:f.chatStatus||m.chatStatus,lifecycle:f.lifecycle||m.lifecycle,surfaceKind:f.surfaceKind||m.surfaceKind,recoveryState:f.recoveryState||m.recoveryState,role:f.role||m.role,isSelfCoordinator:f.isSelfCoordinator??m.isSelfCoordinator,workspace:f.workspace||m.workspace}:{...m,sessionId:p})}for(const m of o.activeSessions??[])c.has(m)||c.set(m,{sessionId:m,workspace:o.workspace,isCached:!0});for(const m of t)ta(m).some(p=>c.has(p))||m.nodeId===o.nodeId&&(n=!0,c.set(m.sessionId,{sessionId:m.sessionId,providerType:m.providerType,state:m.state,chatStatus:m.chatStatus,lifecycle:m.lifecycle,surfaceKind:m.surfaceKind,recoveryState:m.recoveryState,role:m.role,isSelfCoordinator:m.isSelfCoordinator,workspace:m.workspace||o.workspace}));const d=[...c.values()];return d.length===0?o:{...o,activeSessionDetails:d,activeSessions:d.map(m=>m.sessionId)}});return n?{...e,nodes:a}:e}function Mj(e,t){const n=Sm(e,t).map(a=>{var d;const o=(Array.isArray((d=e.status)==null?void 0:d.sessions)?e.status.sessions:[]).find(m=>xt(m==null?void 0:m.id)===a.sessionId),i=Eo(o==null?void 0:o.activeInteractivePrompt),c=o!=null&&o.meshQueueStats&&typeof o.meshQueueStats=="object"?JSON.stringify(o.meshQueueStats):"";return[a.sessionId,a.providerType??"",a.state??"",a.chatStatus??"",a.lifecycle??"",a.surfaceKind??"",a.recoveryState??"",xt(i.status)||xt(i.kind)||xt(i.type),a.nodeId??"",a.isSelfCoordinator?"coordinator":"worker",c].join("|")}).filter(a=>!!a).sort();return n.length>0?n.join(`
80
- `):null}function Nm({status:e,daemonId:t,extraDaemonIds:r,meshId:n,sendData:a,extraLiveSessions:o=[]}){const[i,c]=l.useState(new Map),d=l.useRef(new Map),m=l.useMemo(()=>{const y=new Set;if(t&&y.add(t),r)for(const g of r)g&&y.add(g);return[...y].sort()},[t,r]),u=m.join(",");l.useEffect(()=>{d.current=new Map,c(new Map)},[t,n]),l.useEffect(()=>{if(!n||!a||m.length===0)return;const y=m.map(g=>Vt.subscribe({sendData:a},g,{type:"subscribe",topic:"daemon.metadata",key:`daemon:metadata:${g}`,params:{includeSessions:!0}},x=>{if(x.topic!=="daemon.metadata")return;const k=Mj(x,n);if(k===(d.current.get(g)??null))return;d.current.set(g,k);const j=Sm(x,n);c(h=>{const v=new Map(h);return v.set(g,j),v})}));return()=>{for(const g of y)g()}},[u,n,a]);const p=l.useMemo(()=>{const y=[];for(const g of i.values())y.push(...g);return y},[i]),f=l.useMemo(()=>Cj(p,o),[o,p]);return l.useMemo(()=>e?Ij(e,f):null,[f,e])}const vn=new Map;function Aj(e,t){return!e||!t?null:`${e}::${t}`}function Tj(e,t){var o,i,c,d;if(!t||!e.sessionId)return null;const r=((o=e.coordinator)==null?void 0:o.meshId)??(typeof((i=e.settings)==null?void 0:i.meshCoordinatorFor)=="string"?e.settings.meshCoordinatorFor:null),n=typeof((c=e.settings)==null?void 0:c.meshNodeFor)=="string"?e.settings.meshNodeFor:null;if(r!==t&&n!==t)return null;const a=typeof((d=e.settings)==null?void 0:d.meshNodeId)=="string"?e.settings.meshNodeId:null;return{sessionId:e.sessionId,aliases:Ti(e.sessionId,e.providerSessionId,e.historySessionId,e.nativeSessionId),meshId:t,nodeId:a,providerType:e.agentType,state:e.status,chatStatus:e.status,role:r===t?"coordinator":"worker",isSelfCoordinator:r===t,workspace:e.workspacePath??null}}function _j({activeConv:e,sendDaemonCommand:t,onClose:r}){var P,D,O,R,B,E;const n=((P=e.coordinator)==null?void 0:P.meshId)??(typeof((D=e.settings)==null?void 0:D.meshCoordinatorFor)=="string"?e.settings.meshCoordinatorFor:null),a=e.daemonId??null,o=Aj(a,n),i=o?vn.get(o)??null:null,c=_u(),{sendData:d}=it(),{theme:m}=qs(),u=l.useMemo(()=>Ys(m),[m]),p=l.useMemo(()=>Tj(e,n),[e.agentType,(O=e.coordinator)==null?void 0:O.meshId,e.sessionId,(R=e.settings)==null?void 0:R.meshCoordinatorFor,(B=e.settings)==null?void 0:B.meshNodeFor,(E=e.settings)==null?void 0:E.meshNodeId,e.status,e.workspacePath,n]),[f,y]=l.useState(i),[g,x]=l.useState(!1),[k,j]=l.useState(!1),[h,v]=l.useState(null),[I,w]=l.useState((i==null?void 0:i.refreshedAt)??null),b=l.useRef(i!==null),C=l.useRef(!1),N=l.useRef(!1),S=l.useRef(!0);l.useEffect(()=>{b.current=f!==null},[f]),l.useEffect(()=>{const F=o?vn.get(o)??null:null;y(F),w((F==null?void 0:F.refreshedAt)??null),b.current=F!==null,N.current=!1,j(!1),v(null)},[o]);const T=l.useCallback(async(F=!1)=>{if(!a||!n){v("This coordinator does not expose a live mesh id."),y(null);return}if(C.current){F&&(N.current=!0);return}if(!F&&o){const Z=vn.get(o);if(Z){y(Z),w(Z.refreshedAt||null),b.current=!0,x(!1),v(null);return}}C.current=!0;const Q=!b.current;x(Q),j(F&&b.current),v(null);try{const Z=c!=null&&c.loadMeshStatus?await c.loadMeshStatus(a,n,{refresh:F,retryProfile:F?"settled":"interactive"}):await t(a,"mesh_status",{meshId:n,refresh:F}),Y=bm(Z);if(!Y){v("mesh_status returned an unexpected payload.");return}o&&vn.set(o,Y),y(Y),b.current=!0,w(Y.refreshedAt||new Date().toISOString())}catch(Z){v(Z instanceof Error?Z.message:"Failed to load live mesh status")}finally{C.current=!1,x(!1),j(!1),N.current&&S.current&&(N.current=!1,window.setTimeout(()=>{S.current&&T(!0)},0))}},[o,a,n,c,t]);l.useEffect(()=>(S.current=!0,T(!1),()=>{S.current=!1}),[T]),l.useEffect(()=>{const F=Q=>{Q.key==="Escape"&&r()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[r]);const _=(f==null?void 0:f.meshName)||n||"Repo Mesh",L=l.useMemo(()=>p?[p]:[],[p]),M=Nm({status:f,daemonId:a,meshId:n,sendData:d,extraLiveSessions:L}),A=I?new Date(I).toLocaleTimeString():null,H=l.useMemo(()=>g?"Loading live mesh status…":"No live mesh graph is available for this coordinator yet.",[g]);return s.jsx("div",{className:u.dialogOverlayClass,onClick:r,children:s.jsxs("div",{role:"dialog","aria-modal":"true",className:u.dialogShellClass,onClick:F=>F.stopPropagation(),children:[s.jsxs("div",{className:u.dialogHeaderClass,children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl border border-sky-400/20 bg-sky-500/12 text-sky-200 shadow-[0_12px_30px_rgba(14,165,233,0.18)]",children:s.jsx(Jt,{size:18})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h2",{className:u.dialogTitleClass,children:_}),s.jsx("span",{className:u.dialogKickerClass,children:"Mesh observability"})]}),s.jsxs("p",{className:u.dialogSubtitleClass,children:[ot(e),e.workspaceName?` · ${e.workspaceName}`:"",f!=null&&f.repoIdentity?` · ${f.repoIdentity}`:""]})]})]})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:justify-end",children:[A&&s.jsx("span",{className:u.dialogRefreshedChipClass,children:k?"Refreshing mesh...":`Refreshed ${A}`}),!k&&f&&s.jsx("span",{className:u.dialogRefreshedChipClass,children:d&&!h?"Live daemon metadata":"Metadata subscription unavailable"}),s.jsx("button",{type:"button",onClick:()=>{T(!0)},disabled:g||k,className:"btn btn-secondary btn-sm rounded-xl px-3.5",title:"Refresh live mesh graph",children:g||k?"Refreshing...":"Refresh"}),s.jsx("button",{type:"button",onClick:r,className:u.dialogCloseButtonClass,"aria-label":"Close mesh graph",children:s.jsx(yt,{size:16})})]})]}),h&&s.jsx("div",{className:u.isDark?"shrink-0 border-b border-rose-400/20 bg-rose-500/12 px-4 py-2 text-sm text-rose-200 md:px-5":"shrink-0 border-b border-rose-300 bg-rose-50 px-4 py-2 text-sm text-rose-700 md:px-5",children:h}),s.jsx("div",{className:u.dialogBodyClass,children:M?s.jsx(km,{status:M,emptyMessage:H,daemonId:a,sendDaemonCommand:t}):s.jsx("div",{className:u.dialogEmptyClass,children:H})})]})})}function Lj(e,t){const{sendCommand:r}=it(),[n,a]=l.useState(null),[o,i]=l.useState(!1);l.useEffect(()=>{if(!e||!t){a(null);return}i(!0),r(e,"git_remote_url",{workspace:t}).then(d=>{const m=(d==null?void 0:d.result)??d;a(typeof(m==null?void 0:m.remoteUrl)=="string"?m.remoteUrl:null)}).catch(()=>{a(null)}).finally(()=>i(!1))},[e,t,r]);const c=Pj(n);return{remoteUrl:n,githubUrl:c,loading:o}}function Pj(e){if(!e)return null;const t=e.match(/git@github\.com[:/](.+?)(?:\.git)?$/);if(t)return`https://github.com/${t[1]}`;const r=e.match(/https?:\/\/github\.com\/(.+?)(?:\.git)?$/);return r?`https://github.com/${r[1]}`:null}const Cm=5e3;function Rj(e){return`git:${e}`}function Dj({workspace:e,includeDiffSummary:t=!1,intervalMs:r=Cm}){return{type:"subscribe",topic:"workspace.git",key:Rj(e),params:{workspace:e,includeDiffSummary:t,intervalMs:r}}}function _i(e){return e&&typeof e=="object"&&"result"in e&&e.result&&typeof e.result=="object"?e.result:e}function Ss(e,t){if(e instanceof Error)return e.message;if(e&&typeof e=="object"){const r=e;if(typeof r.error=="string"&&r.error.trim())return r.error;if(typeof r.message=="string"&&r.message.trim())return r.message}return t}function $j(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{status:null,error:Ss(t,"Git status request failed")}:t!=null&&t.status?{status:t.status,error:null}:{status:null,error:Ss(t,"Git status response did not include status")}}function Ej(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{diffSummary:null,error:Ss(t,"Git diff summary request failed")}:t!=null&&t.diffSummary?{diffSummary:t.diffSummary,error:null}:{diffSummary:null,error:Ss(t,"Git diff summary response did not include diffSummary")}}function to(e){return e===void 0||typeof e=="boolean"}function Bj(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.path=="string"&&typeof t.diff=="string"&&to(t.binary)&&to(t.truncated)&&to(t.staged)}function Oj(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{diff:null,error:Ss(t,"Git file diff request failed")}:Bj(t==null?void 0:t.diff)?{diff:t.diff,error:null}:{diff:null,error:Ss(t,"Git file diff response did not include a valid diff object")}}function Fj({daemonId:e,workspace:t,enabled:r=!0,includeDiffSummary:n=!1,intervalMs:a=Cm}){const{sendCommand:o,sendData:i}=it(),c=typeof t=="string"?t.trim():"",d=!!(r&&e&&c),[m,u]=l.useState(null),[p,f]=l.useState(null),[y,g]=l.useState(!1),[x,k]=l.useState(null),j=l.useCallback(async()=>{if(!(!d||!e||!c)){g(!0),k(null);try{const v=$j(await o(e,"git_status",{workspace:c}));if(v.error){u(null),f(null),k(v.error);return}if(u(v.status),!n){f(null);return}const I=Ej(await o(e,"git_diff_summary",{workspace:c}));if(I.error){f(null),k(I.error);return}f(I.diffSummary)}catch(v){k(Ss(v,"Git status request failed"))}finally{g(!1)}}},[d,e,n,o,c]),h=l.useMemo(()=>c?Dj({workspace:c,includeDiffSummary:n,intervalMs:a}):null,[n,a,c]);return l.useEffect(()=>{if(!d||!e||!c||!h){u(null),f(null),g(!1),k(null);return}const v=i?Vt.subscribe({sendData:i},e,h,I=>{var w,b;I.workspace===c&&(u(I.status),f(I.diffSummary??null),k(((w=I.status)==null?void 0:w.error)||((b=I.diffSummary)==null?void 0:b.error)||null),g(!1))},{retryIntervalMs:1e3}):null;return j(),()=>{v==null||v()}},[d,e,j,h,i,c]),{status:m,diffSummary:p,loading:y,error:x,refresh:j}}const Hj={added:"A",modified:"M",deleted:"D",renamed:"R",copied:"C",untracked:"?",conflict:"!"},Wj={added:"text-emerald-400",modified:"text-orange-400",deleted:"text-red-400",renamed:"text-sky-400",copied:"text-sky-400",untracked:"text-zinc-400",conflict:"text-red-400 font-bold"};function jc(e){return e.split("/").pop()??e}function Kj(e){const t=e.lastIndexOf("/");return t>0?e.slice(0,t):""}function Uj({files:e,truncated:t,onFileClick:r,selectedPath:n,className:a=""}){return e.length===0?s.jsx("p",{className:"px-3 py-2 text-xs text-text-secondary",children:"No changed files."}):s.jsxs("div",{className:`flex flex-col ${a}`,children:[s.jsx("ul",{className:"min-w-0 divide-y divide-border/30",children:e.map(o=>{const i=n===o.path,c=Hj[o.status]??"?",d=Wj[o.status]??"text-zinc-400",m=Kj(o.path),u=jc(o.path),p=o.staged?s.jsx("span",{className:"ml-1 inline-block h-1.5 w-1.5 rounded-full bg-emerald-500 align-middle",title:"Staged"}):null;return s.jsxs("li",{className:`flex cursor-pointer items-center gap-2 px-3 py-1.5 text-xs hover:bg-surface-elevated/60 ${i?"bg-surface-elevated":""}`,onClick:()=>r==null?void 0:r(o),children:[s.jsx("span",{className:`w-3 shrink-0 font-mono font-bold ${d}`,title:o.status,children:c}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[m&&s.jsxs("span",{className:"text-text-secondary",children:[m,"/"]}),s.jsx("span",{className:"text-text-primary",children:u}),o.oldPath&&s.jsxs("span",{className:"ml-1 text-text-secondary",children:["← ",jc(o.oldPath)]}),p]}),!o.binary&&(o.insertions>0||o.deletions>0)&&s.jsxs("span",{className:"shrink-0 font-mono text-[10px]",children:[o.insertions>0&&s.jsxs("span",{className:"text-emerald-500",children:["+",o.insertions]}),o.insertions>0&&o.deletions>0&&s.jsx("span",{className:"text-text-secondary",children:" "}),o.deletions>0&&s.jsxs("span",{className:"text-red-400",children:["-",o.deletions]})]}),o.binary&&s.jsx("span",{className:"shrink-0 text-[10px] text-text-secondary",children:"bin"})]},`${o.path}-${o.staged?"S":"U"}`)})}),t&&s.jsxs("p",{className:"px-3 py-1.5 text-[10px] text-text-secondary",children:["File list truncated — run ",s.jsx("code",{className:"font-mono",children:"git status"})," locally for full output."]})]})}function zj(e,t){let r="text-text-secondary";return e.startsWith("+")&&!e.startsWith("+++")?r="bg-emerald-500/10 text-emerald-300":e.startsWith("-")&&!e.startsWith("---")?r="bg-red-500/10 text-red-300":e.startsWith("@@")?r="text-sky-400":(e.startsWith("diff ")||e.startsWith("index ")||e.startsWith("--- ")||e.startsWith("+++ "))&&(r="text-text-secondary"),s.jsx("div",{className:`px-3 ${r}`,children:s.jsx("code",{className:"whitespace-pre font-mono text-[11px] leading-5",children:e})},t)}function Im({diff:e,binary:t,truncated:r,loading:n,error:a,className:o=""}){const i=l.useRef(null);if(l.useEffect(()=>{i.current&&(i.current.scrollTop=0)},[e]),n)return s.jsx("div",{className:`flex items-center justify-center py-8 text-xs text-text-secondary ${o}`,children:"Loading diff…"});if(a)return s.jsx("div",{className:`px-3 py-4 text-xs text-red-400 ${o}`,children:a});if(t)return s.jsx("div",{className:`px-3 py-4 text-xs text-text-secondary ${o}`,children:"Binary file — diff not available."});if(!e)return s.jsx("div",{className:`px-3 py-4 text-xs text-text-secondary ${o}`,children:"No diff available."});const c=e.split(`
80
+ `):null}function Nm({status:e,daemonId:t,extraDaemonIds:r,meshId:n,sendData:a,extraLiveSessions:o=[]}){const[i,c]=l.useState(new Map),d=l.useRef(new Map),m=l.useMemo(()=>{const y=new Set;if(t&&y.add(t),r)for(const g of r)g&&y.add(g);return[...y].sort()},[t,r]),u=m.join(",");l.useEffect(()=>{d.current=new Map,c(new Map)},[t,n]),l.useEffect(()=>{if(!n||!a||m.length===0)return;const y=m.map(g=>Vt.subscribe({sendData:a},g,{type:"subscribe",topic:"daemon.metadata",key:`daemon:metadata:${g}`,params:{includeSessions:!0}},x=>{if(x.topic!=="daemon.metadata")return;const k=Mj(x,n);if(k===(d.current.get(g)??null))return;d.current.set(g,k);const j=Sm(x,n);c(h=>{const v=new Map(h);return v.set(g,j),v})}));return()=>{for(const g of y)g()}},[u,n,a]);const p=l.useMemo(()=>{const y=[];for(const g of i.values())y.push(...g);return y},[i]),f=l.useMemo(()=>Cj(p,o),[o,p]);return l.useMemo(()=>e?Ij(e,f):null,[f,e])}const vn=new Map;function Aj(e,t){return!e||!t?null:`${e}::${t}`}function Tj(e,t){var o,i,c,d;if(!t||!e.sessionId)return null;const r=((o=e.coordinator)==null?void 0:o.meshId)??(typeof((i=e.settings)==null?void 0:i.meshCoordinatorFor)=="string"?e.settings.meshCoordinatorFor:null),n=typeof((c=e.settings)==null?void 0:c.meshNodeFor)=="string"?e.settings.meshNodeFor:null;if(r!==t&&n!==t)return null;const a=typeof((d=e.settings)==null?void 0:d.meshNodeId)=="string"?e.settings.meshNodeId:null;return{sessionId:e.sessionId,aliases:Ti(e.sessionId,e.providerSessionId,e.historySessionId,e.nativeSessionId),meshId:t,nodeId:a,providerType:e.agentType,state:e.status,chatStatus:e.status,role:r===t?"coordinator":"worker",isSelfCoordinator:r===t,workspace:e.workspacePath??null}}function _j({activeConv:e,sendDaemonCommand:t,onClose:r}){var P,D,O,R,B,E;const n=((P=e.coordinator)==null?void 0:P.meshId)??(typeof((D=e.settings)==null?void 0:D.meshCoordinatorFor)=="string"?e.settings.meshCoordinatorFor:null),a=e.daemonId??null,o=Aj(a,n),i=o?vn.get(o)??null:null,c=_u(),{sendData:d}=it(),{theme:m}=qs(),u=l.useMemo(()=>Ys(m),[m]),p=l.useMemo(()=>Tj(e,n),[e.agentType,(O=e.coordinator)==null?void 0:O.meshId,e.sessionId,(R=e.settings)==null?void 0:R.meshCoordinatorFor,(B=e.settings)==null?void 0:B.meshNodeFor,(E=e.settings)==null?void 0:E.meshNodeId,e.status,e.workspacePath,n]),[f,y]=l.useState(i),[g,x]=l.useState(!1),[k,j]=l.useState(!1),[h,v]=l.useState(null),[I,w]=l.useState((i==null?void 0:i.refreshedAt)??null),b=l.useRef(i!==null),C=l.useRef(!1),N=l.useRef(!1),S=l.useRef(!0);l.useEffect(()=>{b.current=f!==null},[f]),l.useEffect(()=>{const F=o?vn.get(o)??null:null;y(F),w((F==null?void 0:F.refreshedAt)??null),b.current=F!==null,N.current=!1,j(!1),v(null)},[o]);const T=l.useCallback(async(F=!1)=>{if(!a||!n){v("This coordinator does not expose a live mesh id."),y(null);return}if(C.current){F&&(N.current=!0);return}if(!F&&o){const Z=vn.get(o);if(Z){y(Z),w(Z.refreshedAt||null),b.current=!0,x(!1),v(null);return}}C.current=!0;const Q=!b.current;x(Q),j(F&&b.current),v(null);try{const Z=c!=null&&c.loadMeshStatus?await c.loadMeshStatus(a,n,{refresh:F,retryProfile:"settled"}):await t(a,"mesh_status",{meshId:n,refresh:F}),Y=bm(Z);if(!Y){v("mesh_status returned an unexpected payload.");return}o&&vn.set(o,Y),y(Y),b.current=!0,w(Y.refreshedAt||new Date().toISOString())}catch(Z){v(Z instanceof Error?Z.message:"Failed to load live mesh status")}finally{C.current=!1,x(!1),j(!1),N.current&&S.current&&(N.current=!1,window.setTimeout(()=>{S.current&&T(!0)},0))}},[o,a,n,c,t]);l.useEffect(()=>(S.current=!0,T(!1),()=>{S.current=!1}),[T]),l.useEffect(()=>{const F=Q=>{Q.key==="Escape"&&r()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[r]);const _=(f==null?void 0:f.meshName)||n||"Repo Mesh",L=l.useMemo(()=>p?[p]:[],[p]),M=Nm({status:f,daemonId:a,meshId:n,sendData:d,extraLiveSessions:L}),A=I?new Date(I).toLocaleTimeString():null,H=l.useMemo(()=>g?"Loading live mesh status…":"No live mesh graph is available for this coordinator yet.",[g]);return s.jsx("div",{className:u.dialogOverlayClass,onClick:r,children:s.jsxs("div",{role:"dialog","aria-modal":"true",className:u.dialogShellClass,onClick:F=>F.stopPropagation(),children:[s.jsxs("div",{className:u.dialogHeaderClass,children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl border border-sky-400/20 bg-sky-500/12 text-sky-200 shadow-[0_12px_30px_rgba(14,165,233,0.18)]",children:s.jsx(Jt,{size:18})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h2",{className:u.dialogTitleClass,children:_}),s.jsx("span",{className:u.dialogKickerClass,children:"Mesh observability"})]}),s.jsxs("p",{className:u.dialogSubtitleClass,children:[ot(e),e.workspaceName?` · ${e.workspaceName}`:"",f!=null&&f.repoIdentity?` · ${f.repoIdentity}`:""]})]})]})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:justify-end",children:[A&&s.jsx("span",{className:u.dialogRefreshedChipClass,children:k?"Refreshing mesh...":`Refreshed ${A}`}),!k&&f&&s.jsx("span",{className:u.dialogRefreshedChipClass,children:d&&!h?"Live daemon metadata":"Metadata subscription unavailable"}),s.jsx("button",{type:"button",onClick:()=>{T(!0)},disabled:g||k,className:"btn btn-secondary btn-sm rounded-xl px-3.5",title:"Refresh live mesh graph",children:g||k?"Refreshing...":"Refresh"}),s.jsx("button",{type:"button",onClick:r,className:u.dialogCloseButtonClass,"aria-label":"Close mesh graph",children:s.jsx(yt,{size:16})})]})]}),h&&s.jsx("div",{className:u.isDark?"shrink-0 border-b border-rose-400/20 bg-rose-500/12 px-4 py-2 text-sm text-rose-200 md:px-5":"shrink-0 border-b border-rose-300 bg-rose-50 px-4 py-2 text-sm text-rose-700 md:px-5",children:h}),s.jsx("div",{className:u.dialogBodyClass,children:M?s.jsx(km,{status:M,emptyMessage:H,daemonId:a,sendDaemonCommand:t}):s.jsx("div",{className:u.dialogEmptyClass,children:H})})]})})}function Lj(e,t){const{sendCommand:r}=it(),[n,a]=l.useState(null),[o,i]=l.useState(!1);l.useEffect(()=>{if(!e||!t){a(null);return}i(!0),r(e,"git_remote_url",{workspace:t}).then(d=>{const m=(d==null?void 0:d.result)??d;a(typeof(m==null?void 0:m.remoteUrl)=="string"?m.remoteUrl:null)}).catch(()=>{a(null)}).finally(()=>i(!1))},[e,t,r]);const c=Pj(n);return{remoteUrl:n,githubUrl:c,loading:o}}function Pj(e){if(!e)return null;const t=e.match(/git@github\.com[:/](.+?)(?:\.git)?$/);if(t)return`https://github.com/${t[1]}`;const r=e.match(/https?:\/\/github\.com\/(.+?)(?:\.git)?$/);return r?`https://github.com/${r[1]}`:null}const Cm=5e3;function Rj(e){return`git:${e}`}function Dj({workspace:e,includeDiffSummary:t=!1,intervalMs:r=Cm}){return{type:"subscribe",topic:"workspace.git",key:Rj(e),params:{workspace:e,includeDiffSummary:t,intervalMs:r}}}function _i(e){return e&&typeof e=="object"&&"result"in e&&e.result&&typeof e.result=="object"?e.result:e}function Ss(e,t){if(e instanceof Error)return e.message;if(e&&typeof e=="object"){const r=e;if(typeof r.error=="string"&&r.error.trim())return r.error;if(typeof r.message=="string"&&r.message.trim())return r.message}return t}function $j(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{status:null,error:Ss(t,"Git status request failed")}:t!=null&&t.status?{status:t.status,error:null}:{status:null,error:Ss(t,"Git status response did not include status")}}function Ej(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{diffSummary:null,error:Ss(t,"Git diff summary request failed")}:t!=null&&t.diffSummary?{diffSummary:t.diffSummary,error:null}:{diffSummary:null,error:Ss(t,"Git diff summary response did not include diffSummary")}}function to(e){return e===void 0||typeof e=="boolean"}function Bj(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.path=="string"&&typeof t.diff=="string"&&to(t.binary)&&to(t.truncated)&&to(t.staged)}function Oj(e){const t=_i(e);return(t==null?void 0:t.success)===!1?{diff:null,error:Ss(t,"Git file diff request failed")}:Bj(t==null?void 0:t.diff)?{diff:t.diff,error:null}:{diff:null,error:Ss(t,"Git file diff response did not include a valid diff object")}}function Fj({daemonId:e,workspace:t,enabled:r=!0,includeDiffSummary:n=!1,intervalMs:a=Cm}){const{sendCommand:o,sendData:i}=it(),c=typeof t=="string"?t.trim():"",d=!!(r&&e&&c),[m,u]=l.useState(null),[p,f]=l.useState(null),[y,g]=l.useState(!1),[x,k]=l.useState(null),j=l.useCallback(async()=>{if(!(!d||!e||!c)){g(!0),k(null);try{const v=$j(await o(e,"git_status",{workspace:c}));if(v.error){u(null),f(null),k(v.error);return}if(u(v.status),!n){f(null);return}const I=Ej(await o(e,"git_diff_summary",{workspace:c}));if(I.error){f(null),k(I.error);return}f(I.diffSummary)}catch(v){k(Ss(v,"Git status request failed"))}finally{g(!1)}}},[d,e,n,o,c]),h=l.useMemo(()=>c?Dj({workspace:c,includeDiffSummary:n,intervalMs:a}):null,[n,a,c]);return l.useEffect(()=>{if(!d||!e||!c||!h){u(null),f(null),g(!1),k(null);return}const v=i?Vt.subscribe({sendData:i},e,h,I=>{var w,b;I.workspace===c&&(u(I.status),f(I.diffSummary??null),k(((w=I.status)==null?void 0:w.error)||((b=I.diffSummary)==null?void 0:b.error)||null),g(!1))},{retryIntervalMs:1e3}):null;return j(),()=>{v==null||v()}},[d,e,j,h,i,c]),{status:m,diffSummary:p,loading:y,error:x,refresh:j}}const Hj={added:"A",modified:"M",deleted:"D",renamed:"R",copied:"C",untracked:"?",conflict:"!"},Wj={added:"text-emerald-400",modified:"text-orange-400",deleted:"text-red-400",renamed:"text-sky-400",copied:"text-sky-400",untracked:"text-zinc-400",conflict:"text-red-400 font-bold"};function jc(e){return e.split("/").pop()??e}function Kj(e){const t=e.lastIndexOf("/");return t>0?e.slice(0,t):""}function Uj({files:e,truncated:t,onFileClick:r,selectedPath:n,className:a=""}){return e.length===0?s.jsx("p",{className:"px-3 py-2 text-xs text-text-secondary",children:"No changed files."}):s.jsxs("div",{className:`flex flex-col ${a}`,children:[s.jsx("ul",{className:"min-w-0 divide-y divide-border/30",children:e.map(o=>{const i=n===o.path,c=Hj[o.status]??"?",d=Wj[o.status]??"text-zinc-400",m=Kj(o.path),u=jc(o.path),p=o.staged?s.jsx("span",{className:"ml-1 inline-block h-1.5 w-1.5 rounded-full bg-emerald-500 align-middle",title:"Staged"}):null;return s.jsxs("li",{className:`flex cursor-pointer items-center gap-2 px-3 py-1.5 text-xs hover:bg-surface-elevated/60 ${i?"bg-surface-elevated":""}`,onClick:()=>r==null?void 0:r(o),children:[s.jsx("span",{className:`w-3 shrink-0 font-mono font-bold ${d}`,title:o.status,children:c}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[m&&s.jsxs("span",{className:"text-text-secondary",children:[m,"/"]}),s.jsx("span",{className:"text-text-primary",children:u}),o.oldPath&&s.jsxs("span",{className:"ml-1 text-text-secondary",children:["← ",jc(o.oldPath)]}),p]}),!o.binary&&(o.insertions>0||o.deletions>0)&&s.jsxs("span",{className:"shrink-0 font-mono text-[10px]",children:[o.insertions>0&&s.jsxs("span",{className:"text-emerald-500",children:["+",o.insertions]}),o.insertions>0&&o.deletions>0&&s.jsx("span",{className:"text-text-secondary",children:" "}),o.deletions>0&&s.jsxs("span",{className:"text-red-400",children:["-",o.deletions]})]}),o.binary&&s.jsx("span",{className:"shrink-0 text-[10px] text-text-secondary",children:"bin"})]},`${o.path}-${o.staged?"S":"U"}`)})}),t&&s.jsxs("p",{className:"px-3 py-1.5 text-[10px] text-text-secondary",children:["File list truncated — run ",s.jsx("code",{className:"font-mono",children:"git status"})," locally for full output."]})]})}function zj(e,t){let r="text-text-secondary";return e.startsWith("+")&&!e.startsWith("+++")?r="bg-emerald-500/10 text-emerald-300":e.startsWith("-")&&!e.startsWith("---")?r="bg-red-500/10 text-red-300":e.startsWith("@@")?r="text-sky-400":(e.startsWith("diff ")||e.startsWith("index ")||e.startsWith("--- ")||e.startsWith("+++ "))&&(r="text-text-secondary"),s.jsx("div",{className:`px-3 ${r}`,children:s.jsx("code",{className:"whitespace-pre font-mono text-[11px] leading-5",children:e})},t)}function Im({diff:e,binary:t,truncated:r,loading:n,error:a,className:o=""}){const i=l.useRef(null);if(l.useEffect(()=>{i.current&&(i.current.scrollTop=0)},[e]),n)return s.jsx("div",{className:`flex items-center justify-center py-8 text-xs text-text-secondary ${o}`,children:"Loading diff…"});if(a)return s.jsx("div",{className:`px-3 py-4 text-xs text-red-400 ${o}`,children:a});if(t)return s.jsx("div",{className:`px-3 py-4 text-xs text-text-secondary ${o}`,children:"Binary file — diff not available."});if(!e)return s.jsx("div",{className:`px-3 py-4 text-xs text-text-secondary ${o}`,children:"No diff available."});const c=e.split(`
81
81
  `);return s.jsxs("div",{ref:i,className:`overflow-auto ${o}`,children:[s.jsx("div",{className:"py-1",children:c.map((d,m)=>zj(d,m))}),r&&s.jsxs("p",{className:"px-3 py-1.5 text-[10px] text-text-secondary border-t border-border/30",children:["Diff truncated — run ",s.jsx("code",{className:"font-mono",children:"git diff"})," locally for full output."]})]})}function Gj(e,t){const r=[`Branch: ${e||"unknown"}`];r.push(`Changed: ${t.files.length} file(s) +${t.totalInsertions}/-${t.totalDeletions}`);const n={};for(const a of t.files)n[a.status]||(n[a.status]=[]),n[a.status].push(a.path);for(const[a,o]of Object.entries(n))r.push(`${a}: ${o.slice(0,5).join(", ")}${o.length>5?` (+${o.length-5} more)`:""}`);return r.join(`
82
82
  `)}function Mm({daemonId:e,workspace:t,onClose:r}){const{sendCommand:n}=it(),{status:a,diffSummary:o,loading:i,error:c,refresh:d}=Fj({daemonId:e,workspace:t,includeDiffSummary:!0}),[m,u]=l.useState(null),[p,f]=l.useState(null),[y,g]=l.useState(""),[x,k]=l.useState(!1),[j,h]=l.useState(!1),[v,I]=l.useState(null),[w,b]=l.useState(null),{githubUrl:C}=Lj(e,t),N=l.useCallback(async A=>{if(!((m==null?void 0:m.path)===A.path&&!m.loading)){u({path:A.path,diff:"",binary:!1,truncated:!1,loading:!0,error:null});try{const H=await n(e,"git_diff_file",{workspace:t,path:A.path,staged:A.staged}),P=Oj(H);if(P.error||!P.diff){u({path:A.path,diff:"",binary:!1,truncated:!1,loading:!1,error:P.error??"Failed to load diff"});return}u({path:A.path,diff:P.diff.diff,binary:P.diff.binary??!1,truncated:P.diff.truncated??!1,loading:!1,error:null})}catch(H){const P=H instanceof Error?H.message:"Failed to load diff";u({path:A.path,diff:"",binary:!1,truncated:!1,loading:!1,error:P})}}},[e,n,m,t]),S=l.useCallback(A=>{g(""),k(!1),I(null),b(null),f(A)},[]),T=l.useCallback(()=>{f(null),I(null),h(!1)},[]),_=l.useCallback(async()=>{var A,H,P;if(p){h(!0),I(null);try{let D;p==="checkpoint"?D=await n(e,"git_checkpoint",{workspace:t,message:y,includeUntracked:x}):p==="stash"?D=await n(e,"git_stash_push",{workspace:t,message:y,includeUntracked:x}):p==="stash_pop"?D=await n(e,"git_stash_pop",{workspace:t}):p==="checkout_files"&&m&&(D=await n(e,"git_checkout_files",{workspace:t,paths:[m.path]}));const O=(D==null?void 0:D.result)??D;if((O==null?void 0:O.success)===!1||O!=null&&O.error){I((O==null?void 0:O.error)??"Action failed"),h(!1);return}p==="checkpoint"?b(`Checkpoint created: ${((H=(A=O==null?void 0:O.checkpoint)==null?void 0:A.commit)==null?void 0:H.slice(0,7))??"done"}`):p==="stash"?b(`Stashed as ${((P=O==null?void 0:O.stash)==null?void 0:P.stashRef)??"stash@{0}"}`):p==="stash_pop"?b("Stash restored"):(b("File reverted"),u(null)),f(null),await d()}catch(D){I(D instanceof Error?D.message:"Action failed")}finally{h(!1)}}},[p,n,e,t,y,x,m,d]),L=!!(a!=null&&a.hasConflicts),M=a?a.staged+a.modified+a.untracked+a.deleted+a.renamed:null;return s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:A=>{A.target===A.currentTarget&&r()},children:s.jsxs("div",{className:"relative flex h-[80vh] w-full max-w-3xl flex-col overflow-hidden rounded-xl border border-border bg-surface shadow-xl",children:[s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-3",children:[s.jsx("span",{"aria-hidden":"true",className:"text-sm",children:"⑂"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-sm font-semibold text-text-primary",children:(a==null?void 0:a.branch)??"Git Status"}),s.jsx("p",{className:"truncate text-xs text-text-secondary",children:t}),C&&s.jsx("a",{href:`${C}/tree/${(a==null?void 0:a.branch)||"main"}`,target:"_blank",rel:"noopener noreferrer",className:"truncate text-[10px] text-text-secondary hover:text-sky-400 underline",title:"Open on GitHub",children:"GitHub ↗"})]}),s.jsx("button",{onClick:d,disabled:i,className:"rounded px-2 py-1 text-xs text-text-secondary hover:text-text-primary disabled:opacity-40",title:"Refresh",children:"↺"}),s.jsx("button",{onClick:r,className:"rounded p-1 text-text-secondary hover:text-text-primary","aria-label":"Close",children:s.jsx(yt,{className:"h-4 w-4"})})]}),a&&s.jsxs("div",{className:"flex shrink-0 flex-wrap gap-x-4 gap-y-1 border-b border-border/50 px-4 py-2 text-xs text-text-secondary",children:[a.headCommit&&s.jsxs("span",{title:a.headMessage??void 0,children:[s.jsx("span",{className:"font-mono",children:a.headCommit.slice(0,7)}),a.headMessage&&s.jsx("span",{className:"ml-1 truncate",children:a.headMessage.slice(0,60)})]}),a.ahead>0&&s.jsxs("span",{className:"text-orange-400",children:["↑",a.ahead," ahead"]}),a.behind>0&&s.jsxs("span",{className:"text-orange-400",children:["↓",a.behind," behind"]}),a.staged>0&&s.jsxs("span",{className:"text-emerald-400",children:[a.staged," staged"]}),a.modified>0&&s.jsxs("span",{children:[a.modified," modified"]}),a.untracked>0&&s.jsxs("span",{children:[a.untracked," untracked"]}),a.deleted>0&&s.jsxs("span",{className:"text-red-400",children:[a.deleted," deleted"]}),a.stashCount>0&&s.jsxs("span",{children:[a.stashCount," stashed"]}),a.hasConflicts&&s.jsx("span",{className:"font-bold text-red-400",children:"conflicts"}),M===0&&!a.error&&s.jsx("span",{className:"text-emerald-500",children:"clean"}),o&&o.files.length>0&&s.jsxs("span",{className:"text-text-secondary",children:[o.files.length," file",o.files.length!==1?"s":"",o.totalInsertions>0&&s.jsxs("span",{className:"text-emerald-500",children:[" +",o.totalInsertions]}),o.totalDeletions>0&&s.jsxs("span",{className:"text-red-400",children:[" -",o.totalDeletions]})]})]}),c&&s.jsx("div",{className:"shrink-0 border-b border-border/50 bg-red-500/10 px-4 py-2 text-xs text-red-400",children:c}),s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsxs("div",{className:"flex w-56 shrink-0 flex-col overflow-y-auto border-r border-border/50",children:[i&&!o&&s.jsx("p",{className:"px-3 py-4 text-xs text-text-secondary",children:"Loading…"}),o&&s.jsx(Uj,{files:o.files,truncated:o.truncated,selectedPath:(m==null?void 0:m.path)??null,onFileClick:N}),!i&&!o&&!c&&s.jsx("p",{className:"px-3 py-4 text-xs text-text-secondary",children:"No diff data."})]}),s.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:m?s.jsx(Im,{diff:m.diff,binary:m.binary,truncated:m.truncated,loading:m.loading,error:m.error,className:"h-full"}):s.jsx("div",{className:"flex h-full items-center justify-center text-xs text-text-secondary",children:"Select a file to view diff"})})]}),w&&s.jsxs("div",{className:"shrink-0 border-t border-border/50 bg-emerald-500/10 px-4 py-2 text-xs text-emerald-400 flex items-center justify-between",children:[s.jsx("span",{children:w}),s.jsx("button",{onClick:()=>b(null),className:"ml-2 text-emerald-400 hover:text-text-primary",children:"×"})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-t border-border px-4 py-2",children:[s.jsx("button",{onClick:()=>S("checkpoint"),disabled:L,title:L?"Resolve conflicts before checkpointing":"Create a git commit checkpoint",className:"rounded px-2 py-1 text-xs text-text-secondary hover:text-text-primary disabled:opacity-40 disabled:cursor-not-allowed border border-border/50 hover:border-border",children:"Checkpoint"}),s.jsx("button",{onClick:()=>S("stash"),disabled:L,title:L?"Resolve conflicts before stashing":"Stash current changes",className:"rounded px-2 py-1 text-xs text-text-secondary hover:text-text-primary disabled:opacity-40 disabled:cursor-not-allowed border border-border/50 hover:border-border",children:"Stash"}),s.jsx("button",{onClick:()=>S("stash_pop"),disabled:L||!(a!=null&&a.stashCount),title:L?"Resolve conflicts before restoring a stash":a!=null&&a.stashCount?"Restore the latest stash":"No stashes to restore",className:"rounded px-2 py-1 text-xs text-text-secondary hover:text-text-primary disabled:opacity-40 disabled:cursor-not-allowed border border-border/50 hover:border-border",children:"Pop stash"}),s.jsx("button",{onClick:()=>S("checkout_files"),disabled:!m,title:m?`Revert changes to ${m.path}`:"Select a file to revert",className:"rounded px-2 py-1 text-xs text-text-secondary hover:text-text-primary disabled:opacity-40 disabled:cursor-not-allowed border border-border/50 hover:border-border",children:"Checkout selected"}),o&&o.files.length>0&&s.jsx("button",{onClick:()=>{const A=Gj((a==null?void 0:a.branch)??null,o);navigator.clipboard.writeText(A),b("Copied to clipboard"),setTimeout(()=>b(null),2e3)},className:"rounded border border-border px-2.5 py-1 text-xs text-text-secondary hover:text-text-primary",children:"Copy summary"})]}),p&&s.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/60",children:s.jsxs("div",{className:"flex w-80 flex-col gap-3 rounded-xl border border-border bg-surface p-4 shadow-xl",children:[s.jsxs("p",{className:"text-sm font-semibold text-text-primary",children:[p==="checkpoint"&&"Create checkpoint commit",p==="stash"&&"Stash changes",p==="stash_pop"&&"Restore latest stash?",p==="checkout_files"&&`Revert changes to ${(m==null?void 0:m.path)??"file"}?`]}),(p==="checkpoint"||p==="stash")&&s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"text",value:y,onChange:A=>g(A.target.value),maxLength:200,placeholder:"Message (required)",className:"rounded border border-border bg-surface-alt px-2 py-1 text-xs text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-1 focus:ring-border",autoFocus:!0}),s.jsxs("label",{className:"flex items-center gap-2 text-xs text-text-secondary cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:x,onChange:A=>k(A.target.checked)}),"Include untracked files"]})]}),v&&s.jsx("p",{className:"text-xs text-red-400",children:v}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx("button",{onClick:T,disabled:j,className:"rounded px-3 py-1 text-xs text-text-secondary hover:text-text-primary border border-border/50 disabled:opacity-40",children:"Cancel"}),s.jsx("button",{onClick:_,disabled:j||(p==="checkpoint"||p==="stash")&&!y.trim(),className:"rounded px-3 py-1 text-xs text-text-primary bg-border hover:bg-border/80 disabled:opacity-40",children:j?"Working…":"Confirm"})]})]})})]})})}function Vj({isMobile:e,showMobileChatMode:t,visibleConversationCount:r}){const[n,a]=l.useState(!1),[o,i]=l.useState(!1),[c,d]=l.useState(!1),[m,u]=l.useState(!1),[p,f]=l.useState(!1),[y,g]=l.useState("quickstart"),[x,k]=l.useState("workspace"),j=l.useMemo(()=>!t&&!e,[t,e]),h=l.useCallback(N=>{a(N),N&&i(!1)},[]),v=l.useCallback(N=>{i(N),N&&a(!1)},[]),I=l.useCallback(()=>{g(r===0?"quickstart":"shortcuts"),k("workspace"),d(!0),a(!1),i(!1)},[r]),w=l.useCallback(()=>{d(!1)},[]),b=l.useCallback(()=>{u(!0)},[]),C=l.useCallback(()=>{u(!1)},[]);return l.useEffect(()=>{if(!j){f(!1);return}f(!0);const N=window.setTimeout(()=>{f(!1)},1e4);return()=>window.clearTimeout(N)},[j]),{inboxOpen:n,hiddenOpen:o,shortcutHelpOpen:c,newSessionOpen:m,guideNudgeVisible:p,guideTab:y,shortcutSection:x,isDesktopDashboard:j,setGuideTab:g,setShortcutSection:k,handleInboxOpenChange:h,handleHiddenOpenChange:v,handleOpenShortcutHelp:I,closeShortcutHelp:w,openNewSession:b,closeNewSession:C}}function qj(e){switch(e.id){case"triggerPrimaryApprovalAction":case"triggerSecondaryApprovalAction":case"triggerTertiaryApprovalAction":return"approvals";case"splitActiveTabRight":case"splitActiveTabDown":case"focusLeftPane":case"focusRightPane":case"focusUpPane":case"focusDownPane":case"moveActiveTabToLeftPane":case"moveActiveTabToRightPane":case"moveActiveTabToUpPane":case"moveActiveTabToDownPane":return"panes";default:return"workspace"}}function Yj(e){return e instanceof Error?e.message:String(e||"")}function Xj(e){const t=Yj(e).toLowerCase();return t.includes("button not found")||t.includes("not in approval state")||t.includes("command failed")}function Jj({showMobileChatMode:e,isMobile:t,activeConv:r,wsStatus:n,isConnected:a,onOpenHistory:o,onOpenRemote:i,onStopCli:c,activeCliViewMode:d,onSetActiveCliViewMode:m,mobileChatConversations:u,hiddenConversations:p,ides:f,actionLogs:y,sendDaemonCommand:g,setActionLogs:x,setCliViewModeOverrides:k,isStandalone:j,initialDataLoaded:h,userName:v,requestedMobileTabKey:I,onRequestedMobileTabConsumed:w,requestedMachineId:b,onRequestedMachineConsumed:C,requestedMobileSection:N,onRequestedMobileSectionConsumed:S,containerRef:T,isSplitMode:_,numGroups:L,groupSizes:M,groupedConvs:A,clearedTabs:H,focusedGroup:P,focusGroup:D,moveTabToGroup:O,splitTabRelative:R,closeGroup:B,handleResizeStart:E,groupActiveTabIds:F,setGroupActiveTab:Q,groupTabOrders:Z,setGroupTabOrder:Y,toggleHiddenTab:te,visibleConversations:fe,requestedDesktopTabKey:Ne,onRequestedDesktopTabConsumed:X,onDesktopActiveTabChange:we,onRequestScrollToBottom:ge,onHideConversation:be,onShowHiddenConversation:de,onShowAllHiddenConversations:Ie,scrollToBottomRequest:ee,machineEntries:ve,layoutProfile:ce,onBrowseMachineDirectory:W,onSaveMachineWorkspace:ne,onLaunchMachineIde:ue,onLaunchMachineProvider:me,onListMachineMeshes:J,onLaunchMeshCoordinator:q,onListMachineSavedSessions:$,notifications:re,notificationUnreadCount:xe,liveSessionInboxState:je,onMarkNotificationRead:ae,onMarkNotificationUnread:Pe,onDeleteNotification:$e}){const Re=gt.useRef(null),{inboxOpen:Ge,hiddenOpen:Ye,shortcutHelpOpen:Xe,newSessionOpen:at,guideNudgeVisible:Je,guideTab:Ze,shortcutSection:dt,isDesktopDashboard:ft,setGuideTab:he,setShortcutSection:Oe,handleInboxOpenChange:et,handleHiddenOpenChange:ze,handleOpenShortcutHelp:ht,closeShortcutHelp:K,openNewSession:U,closeNewSession:V}=Vj({isMobile:t,showMobileChatMode:e,visibleConversationCount:fe.length}),[ie,pe]=gt.useState(null),[ke,z]=gt.useState(null),G=gt.useCallback((oe,ye)=>{pe({daemonId:oe,workspace:ye})},[]),le=gt.useCallback(oe=>{z(oe)},[]),Ce=gt.useCallback(oe=>{var ye;Cr.flushSync(()=>{de(oe)}),(ye=Re.current)==null||ye.restoreHiddenTabToSavedLocation(oe.tabKey)},[de]),Te=gt.useCallback(oe=>{var We;const ye=u.find(vt=>No(vt,oe))||p.find(vt=>No(vt,oe));ye&&(p.some(vt=>vt.tabKey===ye.tabKey)&&Ce(ye),we(ye.tabKey),(We=Re.current)==null||We.activateConversationTab(ye.tabKey),ge(ye.tabKey,"notification-open")),ae(oe.id),et(!1)},[Ce,p,u,we,ae,ge]),Me=gt.useCallback(()=>{var ye;window.confirm("Move every floating or popout panel back into the main dashboard grid?")&&((ye=Re.current)==null||ye.resetAllPanelsToMain(),ze(!1))},[ze]),_e=gt.useCallback(async oe=>{var is;if(!r)return;const ye=(is=r.modalButtons)==null?void 0:is[oe];if(!ye)return;const We=xs(r);if(!We)return;const vt=ye.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),Is=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(vt);try{await g(We,"resolve_action",{button:ye,action:Is?"approve":"reject",buttonIndex:oe,...fs(r)})}catch(ls){Xj(ls)||console.error("[Shortcut approval] Failed:",ls)}},[r,g]),{isMac:De,actionDefinitions:Ae,actionShortcuts:He,shortcutListening:Ve,shortcutListeningDraft:ut,setShortcutListening:bt,setShortcutListeningDraft:lt,saveShortcuts:mt}=ov({enabled:ft&&!Xe,onTrigger:oe=>{var ye,We,vt,Is,is,ls,zr,Gr,Vr,qr,Yr,Xr,Jr,Qr,cs,Zr;if(oe==="openShortcutHelp"){ht();return}if(oe==="openNewSession"){U();return}if(oe==="hideCurrentTab"){r&&be(r);return}if(oe==="toggleHiddenTabs"){ze(!Ye);return}if(oe==="openHistoryForActiveTab"){r&&!qe(r)&&o(r);return}if(oe==="openRemoteForActiveTab"){r&&!Qe(r)&&!qe(r)&&i(r);return}if(oe==="splitActiveTabRight"){(ye=Re.current)==null||ye.splitActiveTabRight();return}if(oe==="splitActiveTabDown"){(We=Re.current)==null||We.splitActiveTabDown();return}if(oe==="floatActiveTab"){(vt=Re.current)==null||vt.floatActiveTab();return}if(oe==="popoutActiveTab"){(Is=Re.current)==null||Is.popoutActiveTab();return}if(oe==="dockActiveTab"){(is=Re.current)==null||is.dockActiveTab();return}if(oe==="focusLeftPane"){(ls=Re.current)==null||ls.focusLeftPane();return}if(oe==="focusRightPane"){(zr=Re.current)==null||zr.focusRightPane();return}if(oe==="focusUpPane"){(Gr=Re.current)==null||Gr.focusUpPane();return}if(oe==="focusDownPane"){(Vr=Re.current)==null||Vr.focusDownPane();return}if(oe==="moveActiveTabToLeftPane"){(qr=Re.current)==null||qr.moveActiveTabToLeftPane();return}if(oe==="moveActiveTabToRightPane"){(Yr=Re.current)==null||Yr.moveActiveTabToRightPane();return}if(oe==="moveActiveTabToUpPane"){(Xr=Re.current)==null||Xr.moveActiveTabToUpPane();return}if(oe==="moveActiveTabToDownPane"){(Jr=Re.current)==null||Jr.moveActiveTabToDownPane();return}if(oe==="triggerPrimaryApprovalAction"){_e(0);return}if(oe==="triggerSecondaryApprovalAction"){_e(1);return}if(oe==="triggerTertiaryApprovalAction"){_e(2);return}if(oe==="setActiveTabShortcut"){(Qr=Re.current)==null||Qr.setShortcutForActiveTab();return}if(oe==="selectPreviousGroupTab"){(cs=Re.current)==null||cs.activatePreviousTabInGroup();return}if(oe==="selectNextGroupTab"){(Zr=Re.current)==null||Zr.activateNextTabInGroup();return}!r||!Qe(r)||qe(r)||oe==="toggleCliView"&&m(d==="chat"?"terminal":"chat")}}),Be=gt.useCallback(()=>{K(),bt(null),lt([])},[K,bt,lt]),Mt=gt.useMemo(()=>dt==="all"?Ae:Ae.filter(oe=>qj(oe)===dt),[Ae,dt]),se=gt.useCallback(()=>{const oe=Object.fromEntries(Ae.map(ye=>[ye.id,""]));mt(oe)},[Ae,mt]),Le=gt.useCallback(()=>{if(typeof window<"u"&&!window.confirm("Reset all dashboard shortcuts back to their default values?"))return;const oe=Object.fromEntries(Ae.map(ye=>[ye.id,ye.defaultShortcut]));mt(oe)},[Ae,mt]);return gt.useEffect(()=>{const oe=ye=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?ye.metaKey&&ye.key.toLowerCase()==="w":ye.ctrlKey&&ye.key.toLowerCase()==="w")&&(ye.preventDefault(),r&&be&&be(r))};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[r,be]),gt.useEffect(()=>{if(!Xe||Ve)return;const oe=ye=>{ye.key==="Escape"&&(ye.preventDefault(),Be())};return window.addEventListener("keydown",oe,!0),()=>window.removeEventListener("keydown",oe,!0)},[Be,Xe,Ve]),s.jsxs(s.Fragment,{children:[!e&&s.jsx(qb,{activeConv:r,wsStatus:n,isConnected:a,conversations:fe,hiddenConversations:p,onOpenHistory:o,onHideConversation:be,onShowConversation:Ce,onShowAllHidden:Ie,onResetPanelsToMain:Me,notifications:re,notificationUnreadCount:xe,onOpenNotification:Te,onMarkNotificationRead:ae,onMarkNotificationUnread:Pe,onDeleteNotification:$e,inboxOpen:Ge,onInboxOpenChange:et,hiddenOpen:Ye,onHiddenOpenChange:ze,onOpenNewSession:t?void 0:U,onOpenDashboardGuide:ht,guideNudgeVisible:Je,actionShortcuts:He,onOpenRemote:()=>{!r||Qe(r)||qe(r)||i(r)},onStopCli:c,activeCliViewMode:d,onSetCliViewMode:m,onOpenGitDialog:G,onOpenMeshGraph:le}),e?s.jsx(q0,{conversations:u,hiddenConversations:p,ides:f,actionLogs:y,sendDaemonCommand:g,setActionLogs:x,setCliViewModeOverrides:k,isStandalone:j,userName:v,requestedActiveTabKey:I,onRequestedActiveTabConsumed:w,requestedMachineId:b,onRequestedMachineConsumed:C,requestedMobileSection:N,onRequestedMobileSectionConsumed:S,onOpenHistory:o,onOpenRemote:i,onStopCli:c,wsStatus:n,isConnected:a,onShowAllHiddenConversations:Ie,onHideConversation:be,onOpenMeshGraph:le,onOpenNewSession:U,liveSessionInboxState:je}):t?s.jsx(sv,{containerRef:T,isSplitMode:_,numGroups:L,groupSizes:M,groupedConvs:A,clearedTabs:H,ides:f,actionLogs:y,sendDaemonCommand:g,setActionLogs:x,isStandalone:j,hasRegisteredMachines:ve.length>0,userName:v,focusedGroup:P,focusGroup:D,moveTabToGroup:O,splitTabRelative:R,closeGroup:B,handleResizeStart:E,groupActiveTabIds:F,setGroupActiveTab:Q,groupTabOrders:Z,setGroupTabOrder:Y,toggleHiddenTab:te,onOpenNewSession:U,allowTabShortcuts:!1,liveSessionInboxState:je}):s.jsx(vv,{visibleConversations:fe,clearedTabs:H,ides:f,actionLogs:y,sendDaemonCommand:g,setActionLogs:x,isStandalone:j,hasRegisteredMachines:ve.length>0,initialDataLoaded:h,userName:v,toggleHiddenTab:te,actionShortcuts:He,registerActionHandlers:oe=>{Re.current=oe},onActiveTabChange:we,requestedActiveTabKey:Ne,onRequestedActiveTabConsumed:X,onRequestScrollToBottom:ge,scrollToBottomRequest:ee,onOpenNewSession:U,liveSessionInboxState:je,layoutProfile:ce}),at&&s.jsx(Tv,{machines:ve,ides:f,onClose:V,onBrowseDirectory:W,onSaveWorkspace:ne,onLaunchIde:ue,onLaunchProvider:me,onListMeshes:J,onLaunchMeshCoordinator:q,onListSavedSessions:$}),ke&&s.jsx(_j,{activeConv:ke,sendDaemonCommand:g,onClose:()=>z(null)}),ie&&s.jsx(Mm,{daemonId:ie.daemonId,workspace:ie.workspace,onClose:()=>pe(null)}),Xe&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:Be,children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl w-[min(560px,calc(100vw-32px))] max-h-[min(80vh,720px)] overflow-y-auto px-6 py-5 shadow-xl",onClick:oe=>oe.stopPropagation(),children:[s.jsxs("div",{className:"flex items-start justify-between gap-4 mb-5",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Dashboard guide"}),s.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"A quick guide to the dashboard flow, floating and popout tabs, plus grouped shortcuts you can tune."})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex items-center justify-center w-8 px-0",onClick:Be,"aria-label":"Close dashboard guide",children:s.jsx(yt,{size:14})})]}),s.jsx("div",{className:"flex gap-2 mb-4 overflow-x-auto",children:[{id:"overview",label:"Overview"},{id:"quickstart",label:"Quick start"},{id:"shortcuts",label:"Shortcuts"}].map(oe=>s.jsx("button",{type:"button",className:`btn btn-sm ${Ze===oe.id?"btn-primary":"btn-secondary"}`,onClick:()=>he(oe.id),children:oe.label},oe.id))}),Ze==="overview"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3 mb-4",children:[s.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"What lives where"}),s.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Tabs:"})," active sessions across IDE, CLI, and ACP agents."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Hidden tabs:"})," stash sessions you do not want in the main strip but still want to keep around."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Activity inbox:"})," sessions waiting for approval or finished tasks you have not reviewed yet."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"CLI view toggle:"})," switch a PTY session between terminal and chat rendering without relaunching it."]})]})]}),s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[s.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Useful flows"}),s.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Review notifications:"})," open the inbox, jump to the session, then use the conversation or approval controls directly from the active pane."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Reduce clutter:"})," hide less important sessions instead of closing them, then restore from hidden tabs when needed."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Split work:"})," keep one pane active for input and let secondary panes stay read-only until you focus them."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Detached views:"})," float a tab for quick side-by-side work, or pop it into a new window when you want a separate monitor."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Docking:"})," use Dock to bring a floating tab back into the grid, or move a popped out tab back to the main dashboard."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Per-tab shortcuts:"})," right-click a Dockview tab to assign a direct shortcut for that specific session."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"Approval buttons:"})," use ",De?"⌥J / ⌥K / ⌥L":"Ctrl+Alt+J / K / L"," for the first three visible approval actions on the active session."]})]})]})]}),Ze==="quickstart"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[s.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Desktop quick start"}),s.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Start from the machine or workspace flow first. Pick or save a workspace before launching CLI or ACP sessions."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Keep the main strip focused on active work and push overflow into Hidden tabs."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Use the inbox for approval-required or completed sessions instead of scanning every tab."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"4."})," Split only when you need parallel reading; float or pop out a tab when you want to detach it without losing the main layout."]})]})]}),s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[s.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Mobile quick start"}),s.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Stay in chat mode for review and replies; use workspace mode mainly to launch or reopen sessions."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Start from the machine screen, choose a workspace, then launch IDE, CLI, or ACP from there."]}),s.jsxs("div",{children:[s.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Treat mobile as the simpler control surface: no split workflow, fewer tab mechanics, faster session switching."]})]})]})]}),Ze==="shortcuts"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[s.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"all",label:"All"},{id:"workspace",label:"Workspace"},{id:"panes",label:"Panes"},{id:"approvals",label:"Approvals"}].map(oe=>s.jsx("button",{type:"button",className:`btn btn-sm ${dt===oe.id?"btn-primary":"btn-secondary"}`,onClick:()=>Oe(oe.id),children:oe.label},oe.id))}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:se,children:"Disable all"}),s.jsx("button",{type:"button",className:"btn btn-sm",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, var(--border-subtle, transparent))",background:"color-mix(in srgb, var(--status-error, #ef4444) 8%, var(--bg-primary, transparent))"},onClick:Le,children:"Reset to defaults"})]})]}),s.jsx("div",{className:"space-y-2",children:Mt.map(oe=>s.jsx("div",{className:`rounded-xl border px-4 py-3 ${Ve===oe.id?"border-accent bg-bg-secondary/70":"border-border-subtle bg-bg-secondary/30"}`,children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-sm font-semibold text-text-primary",children:oe.label}),s.jsx("div",{className:"text-xs text-text-secondary mt-1",children:oe.description}),s.jsxs("div",{className:"text-[11px] text-text-muted mt-2",children:["Default: ",s.jsx("span",{className:"font-mono",children:oe.defaultShortcut})]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx("span",{className:"text-[11px] font-mono px-2 py-1 rounded bg-bg-tertiary border border-border-subtle min-w-[72px] text-center",children:Ve===oe.id?ut.length>0?`${ut.join(" ")} ...`:"Listening...":He[oe.id]||"Off"}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{bt(oe.id),lt([])},children:Ve===oe.id?"Listening":"Set"}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{const ye={...He};ye[oe.id]="",mt(ye)},children:"Disable"})]})]})},oe.id))}),s.jsxs("div",{className:"text-[11px] text-text-muted mt-4",children:["Use modifier shortcuts like ",De?"⌘⇧Enter, ⌘⇧→, ⌘Ctrl⇧↓":"Ctrl+Shift+Enter, Ctrl+Shift+→, Ctrl+Alt+Shift+↓",", or set your own combo. Dashboard action shortcuts are ignored while typing in text inputs."]})]})]})})]})}const so=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Qj({onClose:e}){const[t,r]=l.useState(0),n=so[t],a=t===so.length-1;return s.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.stopPropagation()},children:[s.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[s.jsx("button",{onClick:e,className:"absolute top-3 right-4 bg-transparent border-none text-text-muted hover:text-text-primary transition-colors cursor-pointer",children:s.jsx(yt,{size:20})}),s.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:so.map((o,i)=>s.jsx("div",{style:{width:i===t?24:8,height:8,borderRadius:4,background:i===t?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},i))}),s.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:n.visual||n.icon}),s.jsxs("div",{style:{textAlign:"center"},children:[s.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[s.jsx("span",{children:n.icon})," ",n.title]}),s.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:n.desc}),n.code&&s.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[s.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),n.code]}),a&&s.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),s.jsx("div",{className:"flex justify-end items-center mt-6",children:s.jsx("button",{onClick:()=>a?e():r(o=>o+1),className:"btn btn-primary",children:a?"Get Started →":"Next →"})})]}),s.jsx("style",{children:`
83
83
  @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
package/public/index.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <meta name="description" content="ADHDev self-hosted dashboard for controlling AI agents" />
8
8
  <link rel="icon" href="/otter-logo.png" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet" />
10
- <script type="module" crossorigin src="/assets/index-BW-Stll9.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-BbGgWdDc.js"></script>
11
11
  <link rel="modulepreload" crossorigin href="/assets/vendor-BwuWgaJI.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-DBlsL5MS.css">
13
13
  </head>