@harness-engineering/dashboard 0.5.0 → 0.5.1
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.
|
@@ -386,7 +386,7 @@ ${t.result}`:d}}function b6(e,t){const n=[],r=new Set;for(const a of t){if(r.has
|
|
|
386
386
|
`);d=h.pop()??"";for(const b of h){if(!b.startsWith("data: "))continue;const y=b.slice(6).trim();if(y==="[DONE]"){r.onDone();return}try{const v=JSON.parse(y);if(typeof v!="object"||v===null||!("type"in v))continue;const k=v;if(k.type==="session")r.onSession(k.sessionId);else if(k.type==="error"){r.onError(k.error);return}else r.onChunk(k)}catch{}}}r.onDone()}catch(s){s.name!=="AbortError"&&r.onError(s.message??"Stream failed")}}function XC(e,t){if(t.type==="session"||t.type==="error")return;const n=e[e.length-1];switch(t.type){case"text":o8(e,n,t.text);break;case"thinking":l8(e,n,t.text);break;case"tool_use":e.push({kind:"tool_use",tool:t.tool,...t.args!=null?{args:t.args}:{}});break;case"tool_args_delta":u8(e,t.text);break;case"tool_result":c8(e,t.content,t.isError);break;case"status":d8(e,n,t.text);break}}function o8(e,t,n){(t==null?void 0:t.kind)==="text"?e[e.length-1]={kind:"text",text:t.text+n}:((t==null?void 0:t.kind)==="status"&&e.pop(),e.push({kind:"text",text:n}))}function l8(e,t,n){(t==null?void 0:t.kind)==="thinking"?e[e.length-1]={kind:"thinking",text:t.text+n}:e.push({kind:"thinking",text:n})}function u8(e,t){for(let n=e.length-1;n>=0;n--){const r=e[n];if(r.kind==="tool_use"&&r.result===void 0){e[n]={...r,args:(r.args??"")+t};break}}}function c8(e,t,n){for(let r=e.length-1;r>=0;r--){const a=e[r];if(a.kind==="tool_use"&&a.result===void 0){e[r]={...a,result:t,...n!=null?{isError:n}:{}};break}}}function d8(e,t,n){(t==null?void 0:t.kind)==="status"?e[e.length-1]={kind:"status",text:n}:e.push({kind:"status",text:n})}async function p8(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch context from ${e}: ${t.statusText}`);const n=await t.json();return{source:e,data:n}}function f8(e){const t={};for(const{source:n,data:r}of e)t[n]=r;return t}function m8(e){return e instanceof Error?e.message:"Unknown error fetching chat context"}function h8(e){return e?e.split("|"):[]}function g8(e,t,n){e({}),t(!1),n(null)}function b8(e){const[t,n]=N.useState({}),[r,a]=N.useState(!1),[s,o]=N.useState(null),c=N.useMemo(()=>(e??[]).join("|"),[e]);return N.useEffect(()=>{const d=h8(c);if(d.length===0){g8(n,a,o);return}let p=!0;return a(!0),o(null),Promise.all(d.map(p8)).then(m=>{p&&n(f8(m))}).catch(m=>{p&&o(m8(m))}).finally(()=>{p&&a(!1)}),()=>{p=!1}},[c]),{data:t,isLoading:r,error:s}}const y8=[];function x8(e){fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(t=>console.error("Failed to persist session:",t))}function v8({thread:e}){const t=e.meta,n=Pe(R=>R.messages.get(e.id)??y8),r=Pe;N.useEffect(()=>{const R=[];for(const B of n)B.role==="assistant"&&R.push(...B.blocks);const P=Y6(R);P.length>0&&Pe.getState().updatePanelState(e.id,{todos:P})},[n,e.id]);const[a,s]=N.useState(""),[o,c]=N.useState(!1),[d,p]=N.useState(null),[m,h]=N.useState(),[b,y]=N.useState(null),[v,k]=N.useState(!1),w=N.useRef(new Set),E=N.useRef(null);N.useEffect(()=>{const R=r.getState().messages.get(e.id);R&&R.length>0||fetch(`/api/sessions/${t.sessionId}`).then(P=>P.ok?P.json():null).then(P=>{P&&Array.isArray(P.messages)&&(r.getState().setMessages(e.id,P.messages),P.orchestratorSessionId&&h(P.orchestratorSessionId))}).catch(()=>{})},[t.sessionId,e.id,r]),N.useEffect(()=>{if(t.command&&!b){const R=ii.find(P=>P.id===t.command||P.slashCommand===t.command);R&&(y(R),k(!0))}},[t.command,b]);const T=N.useMemo(()=>b||(t.command?ii.find(R=>R.id===t.command)??null:null),[b,t.command]),A=b8(T==null?void 0:T.contextSources),_=N.useCallback(async(R,P)=>{const B=(R??a).trim();if(!B||o)return;const O=n.length===0,$={role:"user",content:B},H={role:"assistant",blocks:[]};r.getState().appendMessage(e.id,$),r.getState().appendMessage(e.id,H),s(""),c(!0),p(null);const Z={sessionId:t.sessionId,...m?{orchestratorSessionId:m}:{},command:t.command,interactionId:null,label:e.title,createdAt:new Date(e.createdAt).toISOString(),lastActiveAt:new Date().toISOString(),artifacts:[],status:"active",messages:[...n,$,H],input:""};x8(Z);const q=O?void 0:m,Y=new AbortController;await KC(B,P,q,{onSession:ae=>{h(ae)},onChunk:ae=>{r.getState().updateLastMessage(e.id,ee=>{if(ee.role!=="assistant")return ee;const W=[...ee.blocks];return XC(W,ae),{...ee,blocks:W}})},onDone:()=>{if(c(!1),e.title==="New Chat"&&B.length>0){const ae=B.length>50?B.slice(0,47)+"...":B;r.getState().updateThread(e.id,{title:ae})}},onError:ae=>{p(ae),r.getState().updateLastMessage(e.id,ee=>ee.role!=="assistant"?ee:{...ee,blocks:[...ee.blocks,{kind:"text",text:`**Error:** ${ae}`}]}),c(!1)}},Y.signal)},[a,o,n,t,m,e]);N.useEffect(()=>{const R=P=>{const B=P.detail;typeof B=="string"&&B.length>0&&!o&&_(B)};return window.addEventListener("chat-action-send",R),()=>window.removeEventListener("chat-action-send",R)},[_,o]);const j=N.useCallback(()=>{if(!b)return;const R=J6(b,A.data),P=E.current,B=P?`${b.slashCommand} ${P}`:b.slashCommand;E.current=null,k(!1),_(B,R),y(null)},[b,A.data,_]);N.useEffect(()=>{b&&!v&&n.length===0&&!o&&!A.isLoading&&!w.current.has(t.sessionId)&&(w.current.add(t.sessionId),j())},[b,v,n.length,o,A.isLoading,j,t.sessionId]);const D=N.useCallback(R=>{y(R),k(!0),n.length===0&&r.getState().updateThread(e.id,{title:R.id.split(":").pop()||"New Chat"})},[n.length,e.id]);return n.length===0&&!b&&!t.command?u.jsxs("div",{className:"flex flex-1 flex-col",children:[u.jsxs("div",{className:"flex items-center gap-3 border-b border-white/[0.06] px-6 py-4",children:[u.jsx(ur,{size:36,growthDuration:5}),u.jsxs("div",{children:[u.jsx("h2",{className:"text-sm font-bold text-white",children:e.title}),u.jsx("p",{className:"text-[10px] text-neutral-muted",children:"Start a conversation or select a skill"})]})]}),u.jsxs("div",{className:"flex-1 flex flex-col overflow-y-auto",children:[u.jsx("div",{className:"px-4 pt-4",children:u.jsx(Pm,{value:a,onChange:s,onSend:()=>void _(),disabled:o,placeholder:"Type a message or select a skill below..."})}),u.jsx("div",{className:"flex-1 px-4 py-4",children:u.jsx(UI,{onSelect:D})})]})]}):v&&b&&n.length===0?u.jsxs("div",{className:"flex flex-1 flex-col",children:[u.jsxs("div",{className:"flex items-center gap-3 border-b border-white/[0.06] px-6 py-4",children:[u.jsx(ur,{size:36,growthDuration:5}),u.jsxs("div",{children:[u.jsx("h2",{className:"text-sm font-bold text-white",children:b.name}),u.jsx("p",{className:"text-[10px] text-neutral-muted",children:b.description})]})]}),u.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:u.jsx(s8,{skill:b,context:A,onExecute:j,onCancel:()=>{y(null),k(!1)}})})]}):u.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[u.jsxs("div",{className:"flex items-center gap-3 border-b border-white/[0.06] px-6 py-3 flex-shrink-0",children:[u.jsx(ur,{size:28,growthDuration:5}),u.jsx("h2",{className:"text-sm font-bold text-white truncate",children:e.title}),o&&u.jsx(J.div,{animate:{opacity:[.4,1,.4]},transition:{duration:1.5,repeat:1/0},className:"text-[9px] font-bold uppercase tracking-widest text-primary-500",children:"Streaming"}),d&&u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest text-semantic-error",children:"Error"})]}),u.jsx("div",{className:"flex-1 min-h-0 p-4",children:u.jsx(av,{messages:n,streaming:o})}),u.jsx("div",{className:"flex-shrink-0 border-t border-white/[0.06] px-4 py-3",children:u.jsx(Pm,{value:a,onChange:s,onSend:()=>void _(),disabled:o,placeholder:"Type a message..."})})]})}const oT={low:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",medium:"bg-yellow-500/10 text-yellow-400 border-yellow-500/20",high:"bg-orange-500/10 text-orange-400 border-orange-500/20",critical:"bg-red-500/10 text-red-400 border-red-500/20"};function S8({spec:e}){return u.jsxs("div",{className:"space-y-3 rounded-lg border border-primary-500/20 bg-primary-500/5 p-3",children:[u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-primary-500",children:"Enriched Spec (SEL)"}),u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-neutral-muted",children:"Intent"}),u.jsx("p",{className:"mt-0.5 text-xs text-white",children:e.intent})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-neutral-muted",children:"Summary"}),u.jsx("p",{className:"mt-0.5 text-xs text-neutral-text/80 leading-relaxed",children:e.summary})]}),e.affectedSystems.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-neutral-muted",children:"Affected Systems"}),u.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.affectedSystems.map(t=>u.jsxs("span",{className:"rounded-md border border-blue-500/20 bg-blue-500/10 px-1.5 py-0.5 text-[9px] font-medium text-blue-400",title:`Confidence: ${Math.round(t.confidence*100)}% | Tests: ${t.testCoverage} | Deps: ${t.transitiveDeps.length}`,children:[t.name,t.graphNodeId&&u.jsxs("span",{className:"ml-1 text-blue-500/50",children:[Math.round(t.confidence*100),"%"]})]},t.name))})]}),u.jsxs("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-3",children:[e.unknowns.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-amber-400",children:["Unknowns (",e.unknowns.length,")"]}),u.jsx("ul",{className:"mt-0.5 space-y-0.5",children:e.unknowns.map((t,n)=>u.jsx("li",{className:"text-[11px] text-neutral-text/70",children:t},n))})]}),e.ambiguities.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-orange-400",children:["Ambiguities (",e.ambiguities.length,")"]}),u.jsx("ul",{className:"mt-0.5 space-y-0.5",children:e.ambiguities.map((t,n)=>u.jsx("li",{className:"text-[11px] text-neutral-text/70",children:t},n))})]}),e.riskSignals.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-red-400",children:["Risk Signals (",e.riskSignals.length,")"]}),u.jsx("ul",{className:"mt-0.5 space-y-0.5",children:e.riskSignals.map((t,n)=>u.jsx("li",{className:"text-[11px] text-neutral-text/70",children:t},n))})]})]})]})}const E8={local:"text-emerald-400",human:"text-amber-400","simulation-required":"text-purple-400"};function io({value:e,label:t,color:n}){const r=Math.round(e*100);return u.jsxs("div",{className:"space-y-0.5",children:[u.jsxs("div",{className:"flex justify-between text-[10px]",children:[u.jsx("span",{className:"text-neutral-muted",children:t}),u.jsxs("span",{className:n,children:[r,"%"]})]}),u.jsx("div",{className:"h-1 w-full rounded-full bg-white/[0.06]",children:u.jsx("div",{className:`h-full rounded-full ${n.replace("text-","bg-")}`,style:{width:`${r}%`}})})]})}function w8({score:e}){return u.jsxs("div",{className:"space-y-3 rounded-lg border border-secondary-400/20 bg-secondary-400/5 p-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-secondary-400",children:"Complexity (CML)"}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-block rounded-md border px-1.5 py-0.5 text-[9px] font-bold uppercase ${oT[e.riskLevel]??oT.medium}`,children:e.riskLevel}),u.jsx("span",{className:`text-[10px] font-mono font-bold ${E8[e.recommendedRoute]??"text-neutral-muted"}`,children:e.recommendedRoute})]})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(io,{value:e.overall,label:"Overall",color:"text-primary-500"}),u.jsx(io,{value:e.dimensions.structural,label:"Structural",color:"text-blue-400"}),u.jsx(io,{value:e.dimensions.semantic,label:"Semantic",color:"text-purple-400"}),u.jsx(io,{value:e.dimensions.historical,label:"Historical",color:"text-yellow-400"}),u.jsx(io,{value:e.confidence,label:"Confidence",color:"text-emerald-400"})]}),u.jsxs("div",{className:"grid grid-cols-2 gap-2 border-t border-white/[0.06] pt-2 md:grid-cols-4",children:[u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-sm font-bold text-white",children:e.blastRadius.services}),u.jsx("span",{className:"text-[9px] uppercase tracking-widest text-neutral-muted",children:"Services"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-sm font-bold text-white",children:e.blastRadius.modules}),u.jsx("span",{className:"text-[9px] uppercase tracking-widest text-neutral-muted",children:"Modules"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-sm font-bold text-white",children:e.blastRadius.filesEstimated}),u.jsx("span",{className:"text-[9px] uppercase tracking-widest text-neutral-muted",children:"Files"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-sm font-bold text-white",children:e.blastRadius.testFilesAffected}),u.jsx("span",{className:"text-[9px] uppercase tracking-widest text-neutral-muted",children:"Test Files"})]})]}),e.reasoning.length>0&&u.jsxs("div",{className:"border-t border-white/[0.06] pt-2",children:[u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.15em] text-neutral-muted",children:"Reasoning"}),u.jsx("ul",{className:"mt-0.5 space-y-0.5",children:e.reasoning.map((t,n)=>u.jsx("li",{className:"text-[11px] text-neutral-text/70",children:t},n))})]})]})}function k8({interaction:e,collapsed:t,onClaim:n,onDismiss:r}){const[a,s]=N.useState(!t),{context:o,reasons:c}=e;return u.jsxs("div",{className:"border-b border-white/[0.06] bg-neutral-surface/20 backdrop-blur-sm",children:[u.jsxs("button",{onClick:()=>s(!a),className:"flex w-full items-center gap-3 px-6 py-3 text-left hover:bg-white/[0.02] transition-colors",children:[u.jsx(PI,{size:16,className:"text-semantic-warning flex-shrink-0"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("h3",{className:"text-sm font-bold text-white truncate",children:o.issueTitle}),t&&u.jsx("p",{className:"text-[10px] text-neutral-muted truncate",children:c[0]||"Needs attention"})]}),!t&&u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u.jsxs("button",{onClick:d=>{d.stopPropagation(),n()},className:"flex items-center gap-1 rounded-lg bg-primary-500/10 border border-primary-500/20 px-3 py-1 text-[9px] font-bold uppercase tracking-widest text-primary-500 hover:bg-primary-500/20 transition-colors",children:[u.jsx(Nh,{size:10}),"Claim"]}),u.jsxs("button",{onClick:d=>{d.stopPropagation(),r()},className:"flex items-center gap-1 rounded-lg bg-white/[0.04] border border-white/[0.08] px-3 py-1 text-[9px] font-bold uppercase tracking-widest text-neutral-muted hover:text-white hover:bg-white/[0.08] transition-colors",children:[u.jsx(Ch,{size:10}),"Dismiss"]})]}),u.jsx(J.div,{animate:{rotate:a?0:-90},transition:{duration:.2},children:u.jsx(Rc,{size:14,className:"text-neutral-muted"})})]}),u.jsx(dn,{initial:!1,children:a&&u.jsx(J.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:"easeInOut"},className:"overflow-hidden",children:u.jsxs("div",{className:"px-6 pb-4 space-y-3",children:[o.issueDescription&&u.jsx("div",{className:"text-xs text-neutral-text/80 leading-relaxed prose prose-invert prose-xs max-w-none",children:u.jsx(ka,{remarkPlugins:[Na],children:o.issueDescription})}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-neutral-muted",children:"Escalation Reasons"}),c.map((d,p)=>u.jsx("div",{className:"text-xs text-neutral-text/80 leading-relaxed prose prose-invert prose-xs max-w-none",children:u.jsx(ka,{remarkPlugins:[Na],children:d})},p))]}),o.enrichedSpec&&u.jsx(S8,{spec:o.enrichedSpec}),o.complexityScore&&u.jsx(w8,{score:o.complexityScore}),o.relatedFiles.length>0&&u.jsxs("div",{children:[u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-neutral-muted mb-1",children:"Related Files"}),u.jsx("div",{className:"flex flex-wrap gap-1",children:o.relatedFiles.map(d=>u.jsx("span",{className:"rounded bg-white/[0.04] px-1.5 py-0.5 text-[10px] font-mono text-neutral-muted",children:d.split("/").pop()},d))})]})]})})})]})}const N8=[];function lT(e){const{context:t,reasons:n}=e,r=["You are helping a human engineer reason through a complex issue that was escalated from the orchestrator.","",`## Issue: ${t.issueTitle}`];return t.issueDescription&&r.push("","## Description",t.issueDescription),n.length>0&&r.push("","## Escalation Reasons",...n.map(a=>`- ${a}`)),t.specPath&&r.push("","## Spec",`Available at: ${t.specPath}`),t.relatedFiles.length>0&&r.push("","## Related Files",...t.relatedFiles.map(a=>`- ${a}`)),r.push("","## Instructions",'Help the human brainstorm and produce a plan. When the human is satisfied with the plan, they will save it using the "Save Plan" button.'),r.join(`
|
|
387
387
|
`)}function T8({thread:e}){const t=e.meta,n=Pe,r=n(T=>T.messages.get(e.id)??N8),[a,s]=N.useState(""),[o,c]=N.useState(!1),[d,p]=N.useState(),[m,h]=N.useState(null),[b,y]=N.useState(e.status==="active"),v=N.useRef(!1);N.useEffect(()=>{fetch("/api/interactions").then(T=>T.json()).then(T=>{const A=T.find(_=>_.id===t.interactionId);A&&(h(A),A.context.issueTitle&&e.title.startsWith("Attention:")&&n.getState().updateThread(e.id,{title:A.context.issueTitle}))}).catch(()=>{})},[t.interactionId,e.id,e.title]);const k=N.useCallback(()=>{n.getState().claimThread(e.id),y(!0),t.interactionId&&fetch(`/api/interactions/${t.interactionId}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:"claimed"})}).catch(()=>{})},[e.id,t.interactionId]),w=N.useCallback(()=>{n.getState().dismissThread(e.id),t.interactionId&&fetch(`/api/interactions/${t.interactionId}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:"resolved"})}).catch(()=>{})},[e.id,t.interactionId]),E=N.useCallback(async(T,A)=>{const _=(T??a).trim();if(!_||o)return;b||k();const j=r.length===0,D={role:"user",content:_},R={role:"assistant",blocks:[]};n.getState().appendMessage(e.id,D),n.getState().appendMessage(e.id,R),s(""),c(!0);let P=A;j&&!P&&m&&(P=lT(m));const B=j?void 0:d,O=new AbortController;await KC(_,P,B,{onSession:$=>p($),onChunk:$=>{n.getState().updateLastMessage(e.id,H=>{if(H.role!=="assistant")return H;const Z=[...H.blocks];return XC(Z,$),{...H,blocks:Z}})},onDone:()=>c(!1),onError:$=>{n.getState().updateLastMessage(e.id,H=>H.role!=="assistant"?H:{...H,blocks:[...H.blocks,{kind:"text",text:`**Error:** ${$}`}]}),c(!1)}},O.signal)},[a,o,b,r.length,m,d,k,e.id]);return N.useEffect(()=>{b&&m&&r.length===0&&!o&&!v.current&&(v.current=!0,E("Analyze this escalated issue and help me brainstorm an implementation approach.",lT(m)))},[b,m,r.length,o,E]),m?u.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[u.jsx(k8,{interaction:m,collapsed:b,onClaim:k,onDismiss:w}),r.length>0&&u.jsx("div",{className:"flex-1 min-h-0 p-4",children:u.jsx(av,{messages:r,streaming:o})}),b&&u.jsx("div",{className:"flex-shrink-0 border-t border-white/[0.06] px-4 py-3",children:u.jsx(Pm,{value:a,onChange:s,onSend:()=>void E(),disabled:o,placeholder:"Discuss the escalation..."})})]}):u.jsx("div",{className:"flex flex-1 items-center justify-center",children:u.jsx(J.div,{animate:{opacity:[.3,1,.3]},transition:{duration:1.5,repeat:1/0},className:"text-xs text-neutral-muted",children:"Loading interaction..."})})}function A8(e){const t=[],n=e.trim().split(`
|
|
388
388
|
`).filter(Boolean);for(const r of n)try{const a=JSON.parse(r);if(a.type==="session_start"||a.type==="session_end")continue;const s=I8(a);NI(t,s)}catch{}return t}function I8(e){const t={type:typeof e.type=="string"?e.type:"",timestamp:typeof e.timestamp=="string"?e.timestamp:""};return typeof e.content=="string"?t.content=e.content:e.content!=null&&(t.content=JSON.stringify(e.content)),typeof e.subtype=="string"&&(t.subtype=e.subtype),typeof e.sessionId=="string"&&(t.sessionId=e.sessionId),t}function C8(e,t){const[n,r]=N.useState(null),[a,s]=N.useState([]),[o,c]=N.useState(!1),[d,p]=N.useState(null),m=N.useRef(null);return N.useEffect(()=>{if(!e){r(null),s([]),p(null),m.current=null;return}const h=`${e}:latest`;if(m.current===h)return;let b=!1;async function y(){c(!0),p(null);try{const v=await R8(e);if(b)return;if(!v){r(null),s([]),c(!1);return}r(v);const k=await _8(e,t);if(b)return;s(k),m.current=h}catch(v){b||p(v instanceof Error?v.message:"Failed to load stream")}finally{b||c(!1)}}return y(),()=>{b=!0}},[e,t]),{manifest:n,recordedBlocks:a,loading:o,error:d}}async function R8(e){const t=await fetch(`/api/streams/${e}/manifest`);if(t.status===404)return null;if(!t.ok)throw new Error(`Manifest fetch failed: ${t.status}`);return await t.json()}async function _8(e,t){const n=`/api/streams/${e}`,r=await fetch(n);if(!r.ok)throw new Error(`Stream fetch failed: ${r.status}`);const a=await r.text();return A8(a)}function O8({thread:e}){const t=e.meta,r=N.useContext(BI)[t.issueId]??[],{recordedBlocks:a,manifest:s,loading:o}=C8(t.issueId),{snapshot:c}=Yo(),d=N.useMemo(()=>{if(!c)return null;const v=c.running.find(([k])=>k===t.issueId);return v?v[1]:null},[c,t.issueId]),p=(d==null?void 0:d.session)??null,m=(s==null?void 0:s.attempts.at(-1))??null,h=N.useMemo(()=>a.length>0&&r.length>0?[...a,...r]:a.length>0?a:r,[a,r]),b=N.useMemo(()=>h.length===0?[]:[{role:"assistant",blocks:h}],[h]),y=e.status==="active";return N.useEffect(()=>{var w,E,T,A;const v=((w=m==null?void 0:m.stats)==null?void 0:w.durationMs)??null,k={identifier:t.identifier,phase:t.phase,backendName:(p==null?void 0:p.backendName)??t.backendName,description:t.issueDescription??null,turnCount:(p==null?void 0:p.turnCount)??((E=m==null?void 0:m.stats)==null?void 0:E.turnCount)??0,inputTokens:(p==null?void 0:p.inputTokens)??((T=m==null?void 0:m.stats)==null?void 0:T.inputTokens)??0,outputTokens:(p==null?void 0:p.outputTokens)??((A=m==null?void 0:m.stats)==null?void 0:A.outputTokens)??0,totalTokens:(p==null?void 0:p.totalTokens)??(m!=null&&m.stats?m.stats.inputTokens+m.stats.outputTokens:0),startedAt:t.startedAt?new Date(t.startedAt).getTime():null,durationMs:v,isRunning:y,pr:s!=null&&s.pr?{number:s.pr.number,status:s.pr.status}:null};Pe.getState().updatePanelState(e.id,{phase:t.phase,skill:t.backendName,startedAt:t.startedAt?new Date(t.startedAt).getTime():null,agentStats:k})},[t,p,m,s,e.id,y]),u.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[u.jsxs("div",{className:"flex items-center gap-3 border-b border-white/[0.06] px-6 py-3 flex-shrink-0",children:[u.jsx(ur,{size:32,growthDuration:5}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("h2",{className:"text-sm font-bold text-white truncate",children:e.title}),u.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-neutral-muted",children:[u.jsx("span",{className:"font-mono truncate",children:t.identifier}),u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(kh,{size:10}),t.phase]})]})]}),y?u.jsxs(J.div,{animate:{opacity:[.4,1,.4]},transition:{duration:1.5,repeat:1/0},className:"flex items-center gap-1 text-[9px] font-bold uppercase tracking-widest text-semantic-success",children:[u.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-semantic-success"}),"Running"]}):u.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest text-neutral-muted",children:"Completed"})]}),t.issueDescription&&u.jsx("div",{className:"border-b border-white/[0.06] px-6 py-3 flex-shrink-0",children:u.jsx("p",{className:"text-xs text-neutral-muted leading-relaxed line-clamp-3",children:t.issueDescription})}),u.jsx("div",{className:"flex-1 min-h-0 p-4",children:o?u.jsx("div",{className:"flex flex-1 items-center justify-center h-full",children:u.jsx(J.div,{animate:{opacity:[.3,1,.3]},transition:{duration:1.5,repeat:1/0},className:"text-xs text-neutral-muted",children:"Loading stream history..."})}):b.length>0?u.jsx(av,{messages:b,streaming:y}):u.jsx("div",{className:"flex flex-1 items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(ur,{size:60,growthDuration:10}),u.jsx("p",{className:"mt-4 text-xs text-neutral-muted",children:y?"Agent is working...":"No activity recorded for this session."})]})})})]})}function L8({initialTitle:e,initialDescription:t,initialLabels:n,collapsed:r,onSubmit:a}){const[s,o]=N.useState(!r),[c,d]=N.useState(e),[p,m]=N.useState(t),[h,b]=N.useState(n.join(", ")),y=()=>{if(!c.trim())return;const v=h.split(",").map(k=>k.trim()).filter(Boolean);a({title:c.trim(),description:p.trim(),labels:v})};return u.jsxs("div",{className:"border-b border-white/[0.06] bg-neutral-surface/20 backdrop-blur-sm",children:[u.jsxs("button",{onClick:()=>o(!s),className:"flex w-full items-center gap-3 px-6 py-3 text-left hover:bg-white/[0.02] transition-colors",children:[u.jsx(Th,{size:16,className:"text-accent-500 flex-shrink-0"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("h3",{className:"text-sm font-bold text-white truncate",children:c||"New Analysis"}),r&&u.jsx("p",{className:"text-[10px] text-neutral-muted truncate",children:"Analysis complete — expand to see inputs"})]}),u.jsx(J.div,{animate:{rotate:s?0:-90},transition:{duration:.2},children:u.jsx(Rc,{size:14,className:"text-neutral-muted"})})]}),u.jsx(dn,{initial:!1,children:s&&u.jsx(J.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:"easeInOut"},className:"overflow-hidden",children:u.jsxs("div",{className:"px-6 pb-4 space-y-3",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-neutral-muted block mb-1",children:"Title *"}),u.jsx("input",{type:"text",value:c,onChange:v=>d(v.target.value),disabled:r,placeholder:"Feature or issue title...",className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.04] px-3 py-2 text-sm text-white placeholder:text-neutral-muted/40 focus:border-primary-500/40 focus:outline-none focus:ring-2 focus:ring-primary-500/10 disabled:opacity-50"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-neutral-muted block mb-1",children:"Description"}),u.jsx("textarea",{value:p,onChange:v=>m(v.target.value),disabled:r,rows:3,placeholder:"Optional context...",className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.04] px-3 py-2 text-sm text-white placeholder:text-neutral-muted/40 focus:border-primary-500/40 focus:outline-none focus:ring-2 focus:ring-primary-500/10 resize-none disabled:opacity-50"})]}),u.jsxs("div",{children:[u.jsx("label",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-neutral-muted block mb-1",children:"Labels"}),u.jsx("input",{type:"text",value:h,onChange:v=>b(v.target.value),disabled:r,placeholder:"Comma-separated labels...",className:"w-full rounded-lg border border-white/[0.08] bg-white/[0.04] px-3 py-2 text-sm text-white placeholder:text-neutral-muted/40 focus:border-primary-500/40 focus:outline-none focus:ring-2 focus:ring-primary-500/10 disabled:opacity-50"})]}),!r&&u.jsxs("button",{onClick:y,disabled:!c.trim(),className:"flex items-center gap-2 rounded-lg bg-accent-500/10 border border-accent-500/20 px-4 py-2 text-xs font-bold text-accent-500 hover:bg-accent-500/20 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:[u.jsx(Ih,{size:12}),"Run Analysis"]})]})})})]})}const D8={low:"text-semantic-success border-semantic-success/20 bg-semantic-success/10",medium:"text-semantic-warning border-semantic-warning/20 bg-semantic-warning/10",high:"text-orange-400 border-orange-500/20 bg-orange-500/10",critical:"text-semantic-error border-semantic-error/20 bg-semantic-error/10"};function j8({thread:e}){const t=e.meta,[n,r]=N.useState(!1),[a,s]=N.useState(!1),[o,c]=N.useState(null),[d,p]=N.useState(null),[m,h]=N.useState(null),[b,y]=N.useState(null),[v,k]=N.useState(null),w=N.useRef(null),E=N.useCallback(async T=>{r(!0),s(!0),c("Starting analysis..."),k(null),p(null),h(null),y(null),Pe.getState().updateThread(e.id,{title:T.title}),w.current=new AbortController;try{const A=await fetch("/api/analyze",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T),signal:w.current.signal});if(!A.ok||!A.body){k(`HTTP ${A.status}`),s(!1);return}const _=A.body.getReader(),j=new TextDecoder;let D="";for(;;){const{done:R,value:P}=await _.read();if(R)break;D+=j.decode(P,{stream:!0});const B=D.split(`
|
|
389
|
-
`);D=B.pop()??"";for(const O of B){if(!O.startsWith("data: "))continue;const $=O.slice(6).trim();if($==="[DONE]"){s(!1),c(null);return}try{const H=JSON.parse($);switch(H.type){case"status":c(H.text);break;case"sel_result":p(H.data);break;case"cml_result":h(H.data);break;case"pesl_result":y(H.data);break;case"error":k(H.error),s(!1);return}}catch{}}}s(!1),c(null)}catch(A){A.name!=="AbortError"&&k(A.message),s(!1)}},[e.id]);return u.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[u.jsx(L8,{initialTitle:t.analysisTitle,initialDescription:t.description,initialLabels:t.labels,collapsed:n,onSubmit:T=>void E(T)}),u.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[a&&o&&u.jsxs(J.div,{animate:{opacity:[.5,1,.5]},transition:{duration:1.5,repeat:1/0},className:"flex items-center gap-2 text-xs text-primary-500",children:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary-500 animate-pulse"}),o]}),d&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-primary-500/20 bg-primary-500/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(lc,{size:14,className:"text-primary-500"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-primary-500",children:"Spec Enrichment (SEL)"})]}),u.jsx("p",{className:"text-sm text-white font-medium",children:d.intent}),u.jsx("p",{className:"text-xs text-neutral-text/80 leading-relaxed",children:d.summary}),d.affectedSystems.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.affectedSystems.map(T=>u.jsxs("span",{className:"rounded-md border border-blue-500/20 bg-blue-500/10 px-2 py-0.5 text-[10px] text-blue-400",children:[T.name," (",Math.round(T.confidence*100),"%)"]},T.name))})]}),m&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-secondary-400/20 bg-secondary-400/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(li,{size:14,className:"text-secondary-400"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-secondary-400",children:"Complexity Model (CML)"})]}),u.jsx("span",{className:`rounded-md border px-2 py-0.5 text-[9px] font-bold uppercase ${D8[m.riskLevel]??""}`,children:m.riskLevel})]}),u.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[u.jsxs("div",{className:"text-center",children:[u.jsxs("span",{className:"block text-lg font-bold text-white",children:[Math.round(m.overall*100),"%"]}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Overall"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.blastRadius.filesEstimated}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Files"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.blastRadius.modules}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Modules"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.recommendedRoute}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Route"})]})]})]}),b&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-accent-500/20 bg-accent-500/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(MI,{size:14,className:"text-accent-500"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-accent-500",children:"Simulation (PESL)"}),u.jsxs("span",{className:"text-xs text-neutral-muted ml-auto",children:["Confidence: ",Math.round(b.executionConfidence*100),"%"]})]}),b.predictedFailures.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase text-red-400",children:"Predicted Failures"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:b.predictedFailures.map((T,A)=>u.jsxs("li",{className:"text-xs text-neutral-text/80",children:["- ",T]},A))})]}),b.recommendedChanges.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase text-accent-400",children:"Recommended Changes"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:b.recommendedChanges.map((T,A)=>u.jsxs("li",{className:"text-xs text-neutral-text/80",children:["- ",T]},A))})]})]}),v&&u.jsx("div",{className:"rounded-xl border border-semantic-error/20 bg-semantic-error/5 p-4",children:u.jsxs("p",{className:"text-xs text-semantic-error",children:["Error: ",v]})}),n&&!a&&(d||m||b)&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex items-center gap-2 pt-2",children:[u.jsxs("button",{className:"flex items-center gap-1.5 rounded-lg bg-primary-500/10 border border-primary-500/20 px-3 py-1.5 text-[10px] font-bold text-primary-500 hover:bg-primary-500/20 transition-colors",children:[u.jsx(Ah,{size:10}),"Add to Roadmap"]}),u.jsxs("button",{className:"flex items-center gap-1.5 rounded-lg bg-white/[0.04] border border-white/[0.08] px-3 py-1.5 text-[10px] font-bold text-neutral-muted hover:text-white hover:bg-white/[0.08] transition-colors",children:[u.jsx(LI,{size:10}),"Export Spec"]}),u.jsxs("button",{onClick:()=>{r(!1),p(null),h(null),y(null),k(null)},className:"flex items-center gap-1.5 rounded-lg bg-white/[0.04] border border-white/[0.08] px-3 py-1.5 text-[10px] font-bold text-neutral-muted hover:text-white hover:bg-white/[0.08] transition-colors",children:[u.jsx(MB,{size:10}),"Refine"]})]})]})]})}const M8=3e3;function gc(e,t){const[n,r]=N.useState({data:null,lastUpdated:null,stale:!1,error:null}),a=N.useRef(null);return N.useEffect(()=>{let s=null,o=!0;function c(){s=new EventSource(e),s.addEventListener(t,d=>{if(!o)return;const p=d;try{const m=JSON.parse(p.data);r({data:m.data,lastUpdated:m.timestamp,stale:!1,error:null})}catch{}}),s.onerror=()=>{o&&(s==null||s.close(),r(d=>({...d,stale:!0,error:"Connection lost. Reconnecting…"})),a.current=setTimeout(c,M8))}}return c(),()=>{o=!1,s==null||s.close(),a.current&&clearTimeout(a.current)}},[e,t]),n}const F8={default:"text-white",green:"text-emerald-400",yellow:"text-yellow-400",red:"text-red-400"};function Ze({label:e,value:t,sub:n,accent:r="default"}){return u.jsxs("div",{className:"rounded-lg border border-neutral-border bg-neutral-surface p-5",children:[u.jsx("p",{className:"text-xs font-medium uppercase tracking-widest text-neutral-muted",children:e}),u.jsx("p",{className:["mt-2 text-3xl font-bold tabular-nums",F8[r]].join(" "),children:t}),n&&u.jsx("p",{className:"mt-1 text-xs text-neutral-muted",children:n})]})}function iv({lastUpdated:e,stale:t,error:n}){const r=e?new Date(e).toLocaleTimeString():null;return t||n?u.jsxs("div",{className:"flex items-center gap-2 text-xs text-secondary-400",children:[u.jsx("span",{className:"inline-block h-2 w-2 animate-pulse rounded-full bg-secondary-400"}),u.jsx("span",{children:n??"Stale data"}),r&&u.jsxs("span",{className:"text-neutral-muted",children:["· last updated ",r]})]}):u.jsxs("div",{className:"flex items-center gap-2 text-xs text-neutral-muted",children:[u.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-secondary-400"}),u.jsxs("span",{children:["Live",r?` · updated ${r}`:""]})]})}function ZC(e){const[t,n]=N.useState("idle"),[r,a]=N.useState(null),[s,o]=N.useState(null),c=N.useCallback(async d=>{n("loading"),o(null);try{const p=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},...d!==void 0?{body:JSON.stringify(d)}:{}}),m=await p.json();!p.ok||m&&typeof m=="object"&&"error"in m&&m.error?(n("error"),o(m.error??`HTTP ${p.status}`)):(n("success"),a(m))}catch(p){n("error"),o(p instanceof Error?p.message:"Network error")}},[e]);return{state:t,data:r,error:s,run:c}}function P8({url:e,label:t,body:n,loadingLabel:r,onSuccess:a,className:s=""}){const{state:o,error:c,run:d}=ZC(e),p=N.useRef(null),m=sc(0),h=sc(0),b={damping:15,stiffness:150},y=oc(m,b),v=oc(h,b);N.useEffect(()=>{o==="success"&&(a==null||a())},[o,a]);const k=_=>{if(!p.current)return;const{left:j,top:D,width:R,height:P}=p.current.getBoundingClientRect(),B=_.clientX-(j+R/2),O=_.clientY-(D+P/2);m.set(B*.3),h.set(O*.3)},w=()=>{m.set(0),h.set(0)},E=o==="loading",T=o==="success",A=o==="error";return u.jsxs("div",{className:`inline-flex flex-col items-center gap-2 ${s}`,children:[u.jsxs(J.button,{ref:p,style:{x:y,y:v},onMouseMove:k,onMouseLeave:w,whileTap:{scale:.95},onClick:()=>void d(n),disabled:E,className:["group relative flex items-center gap-2 overflow-hidden rounded-xl border px-5 py-2.5 text-xs font-bold uppercase tracking-wider transition-all duration-300 shadow-lg",E?"cursor-not-allowed border-neutral-border bg-neutral-surface/50 text-neutral-muted":"",T?"border-emerald-500/50 bg-emerald-500/10 text-emerald-400 shadow-emerald-500/20":"",A?"border-red-500/50 bg-red-500/10 text-red-400 shadow-red-500/20":"",!E&&!T&&!A?"border-primary-500/50 bg-primary-500/10 text-primary-500 hover:bg-primary-500 hover:text-white shadow-primary-500/20":""].filter(Boolean).join(" "),children:[!E&&!T&&u.jsx(J.div,{initial:{left:"-100%"},animate:{left:"100%"},transition:{duration:3,repeat:1/0,ease:"linear"},className:"absolute top-0 bottom-0 w-1/2 bg-gradient-to-r from-transparent via-white/5 to-transparent pointer-events-none"}),u.jsxs(dn,{mode:"wait",children:[E&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(_c,{className:"h-3.5 w-3.5 animate-spin"})},"loading"),T&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(Nh,{className:"h-3.5 w-3.5"})},"success"),A&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(CI,{className:"h-3.5 w-3.5"})},"error")]}),u.jsx("span",{className:"relative z-10",children:E?r??"Syncing...":T?"Verified":t}),u.jsx("div",{className:"absolute inset-0 z-0 bg-gradient-to-r from-transparent via-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"})]}),A&&c&&u.jsx(J.p,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-[10px] font-mono font-bold text-red-400 uppercase tracking-tighter",children:c})]})}const bc="/api/sse";function B8(e){return typeof e=="object"&&e!==null&&"totalFeatures"in e}function U8(e){return typeof e=="object"&&e!==null&&"totalIssues"in e}function $8(e){return typeof e=="object"&&e!==null&&"available"in e&&e.available===!0}function z8(e){return typeof e=="object"&&e!==null&&"findings"in e&&"stats"in e}function G8(e){return typeof e=="object"&&e!==null&&"violations"in e&&"stats"in e}function H8(e){return typeof e=="object"&&e!==null&&"passed"in e&&"totalViolations"in e}function V8(e){return typeof e=="object"&&e!==null&&"sourceNodeId"in e&&"layers"in e}const sv=N.memo(function({title:t,count:n,children:r}){const[a,s]=N.useState(!1);return u.jsxs("div",{className:"space-y-2",children:[u.jsxs("button",{onClick:()=>s(!a),className:"flex items-center gap-2 text-left transition-opacity hover:opacity-80","aria-expanded":a,children:[u.jsx("span",{className:"text-[10px] text-gray-600",children:a?"▼":"▶"}),u.jsxs("p",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-gray-500",children:[t," (",n,")"]})]}),a&&r]})});function QC({command:e}){const t=Ln();return u.jsx("button",{onClick:()=>{const n=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:e});t(`/t/${n.id}`)},className:"rounded bg-primary-500/10 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-primary-400 border border-primary-500/20 hover:bg-primary-500 hover:text-white transition-all",children:"Fix It"})}const W8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Errors",value:t.stats.errorCount,accent:t.stats.errorCount>0?"red":"green"}),u.jsx(Ze,{label:"Warnings",value:t.stats.warningCount,accent:t.stats.warningCount>0?"yellow":"default"}),u.jsx(Ze,{label:"Info",value:t.stats.infoCount}),u.jsx(Ze,{label:"Files Scanned",value:t.stats.filesScanned})]}),t.findings.length>0&&u.jsx(sv,{title:"Top Findings",count:t.findings.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.findings.slice(0,10).map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":n.severity==="warning"?"text-yellow-400":"text-gray-400",children:["[",n.severity,"]"]}),u.jsxs("span",{className:"text-gray-300",children:[n.file,":",n.line]}),u.jsx("span",{className:"text-gray-500",children:n.message})]},r))})})]})}),q8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Violations",value:t.stats.violationCount,accent:t.stats.violationCount>0?"red":"green"}),u.jsx(Ze,{label:"Files Analyzed",value:t.stats.filesAnalyzed}),u.jsx(Ze,{label:"Status",value:t.valid?"OK":"Failing",accent:t.valid?"green":"red"})]}),t.violations.length>0&&u.jsx(sv,{title:"Violations",count:t.violations.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.violations.map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":"text-yellow-400",children:["[",n.severity,"]"]}),u.jsx("span",{className:"text-gray-300",children:n.file}),u.jsxs("span",{className:"text-gray-500",children:[n.metric,": ",n.value," (threshold: ",n.threshold,")"]})]},r))})})]})}),Y8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Status",value:t.passed?"Passed":"Failed",accent:t.passed?"green":"red"}),u.jsx(Ze,{label:"Violations",value:t.totalViolations,accent:t.totalViolations>0?"red":"default"}),u.jsx(Ze,{label:"Regressions",value:t.regressions.length,accent:t.regressions.length>0?"yellow":"default"})]}),t.newViolations.length>0&&u.jsx(sv,{title:"New Violations",count:t.newViolations.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.newViolations.map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":"text-yellow-400",children:["[",n.severity,"]"]}),u.jsx("span",{className:"text-gray-300",children:n.file}),u.jsx("span",{className:"text-gray-500",children:n.detail})]},r))})})]})});function K8({healthData:e}){return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Entropy Analysis"}),e.totalIssues>0&&u.jsx(QC,{command:"harness:validate"})]}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Total Issues",value:e.totalIssues,accent:e.totalIssues>0?"yellow":"green"}),u.jsx(Ze,{label:"Errors",value:e.errors,accent:e.errors>0?"red":"default"}),u.jsx(Ze,{label:"Warnings",value:e.warnings,accent:e.warnings>0?"yellow":"default"}),u.jsx(Ze,{label:"Auto-fixable",value:e.fixableCount,accent:"default"})]})]})}function X8({healthData:e}){return u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Scan Details"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Suggestions",value:e.suggestionCount}),u.jsx(Ze,{label:"Scan Duration",value:`${e.durationMs} ms`}),u.jsx(Ze,{label:"Analysis Errors",value:e.analysisErrors.length,accent:e.analysisErrors.length>0?"red":"default"})]})]})}function Z8({healthData:e}){return e.analysisErrors.length===0?null:u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Analysis Errors"}),u.jsx("div",{className:"space-y-2 rounded-lg border border-red-900 bg-gray-900 p-4",children:e.analysisErrors.map((t,n)=>u.jsx("p",{className:"text-xs text-red-400",children:t},n))})]})}function Bf({title:e,raw:t,guard:n,Section:r,fixCommand:a}){const s=t,o=typeof s=="object"&&s!==null&&"stats"in s?s.stats:void 0,d=n(t)&&(o!=null&&(o.errorCount??0)+(o.warningCount??0)>0||s!=null&&"totalViolations"in s&&s.totalViolations>0||o!=null&&(o.violationCount??0)>0)&&a?u.jsx(QC,{command:a}):void 0;return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex w-full items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:e}),d]}),t==null?u.jsx("p",{className:"text-sm text-gray-500",children:"Awaiting first scan..."}):n(t)?u.jsx(r,{data:t}):u.jsx("p",{className:"text-sm text-red-400",children:"error"in t?String(t.error):"Unavailable"})]})}function Q8({health:e}){const t="error"in e?String(e.error):"Unavailable";return u.jsx("p",{className:"text-sm text-red-400",children:t})}function J8({healthData:e,security:t,perf:n,arch:r}){return u.jsxs("div",{className:"space-y-8",children:[u.jsx(K8,{healthData:e}),u.jsx(X8,{healthData:e}),u.jsx(Z8,{healthData:e}),u.jsx(Bf,{title:"Security",raw:t,guard:z8,Section:W8,fixCommand:"harness:security-scan"}),u.jsx(Bf,{title:"Performance",raw:n,guard:G8,Section:q8,fixCommand:"harness:perf"}),u.jsx(Bf,{title:"Architecture",raw:r,guard:H8,Section:Y8,fixCommand:"harness:enforce-architecture"})]})}function eW(e){const t=e?e.health:null,n=t&&U8(t)?t:null;return{health:t,healthData:n}}function tW(e){return{security:(e==null?void 0:e.security)??null,perf:(e==null?void 0:e.perf)??null,arch:(e==null?void 0:e.arch)??null}}const nW=["validate","check-deps","check-arch","check-perf","check-security","check-docs","phase-gate"];function rW(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}const aW=N.memo(function({name:t,result:n,expanded:r,onToggle:a}){if(!n)return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-4",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"inline-block h-3 w-3 rounded-full bg-gray-600"}),u.jsx("span",{className:"text-sm font-medium text-gray-400",children:t})]}),u.jsx("p",{className:"mt-1 text-xs text-gray-600",children:"Not yet run"})]});const s=n.passed?"border-emerald-800":"border-red-800",o=n.passed?"bg-emerald-400":"bg-red-400",c=n.passed?"text-emerald-400":"text-red-400";return u.jsxs("div",{className:`rounded-lg border ${s} bg-gray-900`,children:[u.jsxs("button",{onClick:a,className:"w-full p-4 text-left","aria-expanded":r,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-block h-3 w-3 rounded-full ${o}`}),u.jsx("span",{className:"text-sm font-medium text-gray-200",children:t})]}),u.jsx("span",{className:`text-xs font-medium ${c}`,children:n.passed?"PASS":"FAIL"})]}),!r&&(n.errorCount>0||n.warningCount>0)&&u.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[n.errorCount>0&&`${n.errorCount} errors`,n.errorCount>0&&n.warningCount>0&&", ",n.warningCount>0&&`${n.warningCount} warnings`]})]}),r&&u.jsx("div",{className:"border-t border-gray-800 px-4 py-3",children:u.jsxs("div",{className:"space-y-1 text-xs",children:[u.jsxs("p",{className:"text-gray-400",children:["Errors:"," ",u.jsx("span",{className:n.errorCount>0?"text-red-400":"text-gray-300",children:n.errorCount})," | ","Warnings:"," ",u.jsx("span",{className:n.warningCount>0?"text-yellow-400":"text-gray-300",children:n.warningCount})]}),n.details&&u.jsx("p",{className:"text-gray-500",children:n.details})]})})]})});function iW(e){const t=new Map;if(!e)return t;for(const n of e.checks)t.set(n.name,n);return t}async function sW(e,t,n){try{const r=await fetch("/api/ci");if(!r.ok){t(`HTTP ${r.status}`);return}const a=await r.json();e(a.data),t(null)}catch(r){t(r instanceof Error?r.message:"Network error")}finally{n(!1)}}function oW(){const[e,t]=N.useState(null),[n,r]=N.useState(!0),[a,s]=N.useState(null),[o,c]=N.useState(new Set),d=N.useCallback(()=>{sW(t,s,r)},[]);N.useEffect(()=>{d()},[d]);const p=h=>{c(b=>{const y=new Set(b);return y.has(h)?y.delete(h):y.add(h),y})},m=N.useMemo(()=>iW(e),[e]);return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"CI Checks"}),u.jsxs("div",{className:"flex items-center gap-4",children:[u.jsx(P8,{url:"/api/actions/refresh-checks",label:"Run All Checks",loadingLabel:"Running checks...",onSuccess:d}),(e==null?void 0:e.lastRun)&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Last checked ",rW(e.lastRun)]})]})]}),n&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading check results..."}),a&&u.jsx("p",{className:"text-sm text-red-400",children:a}),u.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:nW.map(h=>u.jsx(aW,{name:h,result:m.get(h),expanded:o.has(h),onToggle:()=>p(h)},h))})]})}function lW(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),{data:a}=gc(bc,"checks"),{health:s,healthData:o}=eW(e),{security:c,perf:d,arch:p}=tW(a);return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Health"}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]}),u.jsxs("div",{className:"space-y-8",children:[u.jsx(oW,{}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream..."}),s&&!o&&u.jsx(Q8,{health:s}),o&&u.jsx(J8,{healthData:o,security:c,perf:d,arch:p})]})]})}function uW({reason:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsx("p",{className:"text-base font-medium text-gray-300",children:"Graph not connected"}),e&&u.jsx("p",{className:"mt-2 text-sm text-gray-500",children:e}),u.jsxs("div",{className:"mt-4 rounded border border-gray-700 bg-gray-950 p-4",children:[u.jsx("p",{className:"text-xs font-semibold text-gray-400",children:"To connect the graph:"}),u.jsxs("ol",{className:"mt-2 list-decimal list-inside space-y-1 text-xs text-gray-500",children:[u.jsxs("li",{children:["Run ",u.jsx("code",{className:"text-gray-300",children:"harness ingest"})," to build the knowledge graph"]}),u.jsx("li",{children:"Ensure the graph database is available in your project"}),u.jsx("li",{children:"Restart the dashboard to reconnect"})]})]})]})}const cW=N.memo(function({type:t,count:n,pct:r}){return u.jsxs("tr",{className:"hover:bg-gray-900",children:[u.jsx("td",{className:"px-4 py-2.5 text-gray-300",children:t}),u.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-gray-400",children:n}),u.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums text-gray-500",children:[r,"%"]})]})}),dW=N.memo(function({nodesByType:t,nodeCount:n}){const r=N.useMemo(()=>[...t].sort((a,s)=>s.count-a.count),[t]);return t.length===0?null:u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Node Type Breakdown"}),u.jsx("div",{className:"overflow-hidden rounded-lg border border-gray-800",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"bg-gray-900 text-xs uppercase tracking-wider text-gray-500",children:u.jsxs("tr",{children:[u.jsx("th",{className:"px-4 py-3 text-left",children:"Type"}),u.jsx("th",{className:"px-4 py-3 text-right",children:"Count"}),u.jsx("th",{className:"px-4 py-3 text-right",children:"%"})]})}),u.jsx("tbody",{className:"divide-y divide-gray-800 bg-gray-950",children:r.map(a=>{const s=n>0?(a.count/n*100).toFixed(1):"0";return u.jsx(cW,{type:a.type,count:a.count,pct:s},a.type)})})]})})]})}),pW=N.memo(function({graphData:t}){return u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Graph Metrics"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Nodes",value:t.nodeCount}),u.jsx(Ze,{label:"Edges",value:t.edgeCount}),u.jsx(Ze,{label:"Node Types",value:t.nodesByType.length})]})]}),u.jsx(dW,{nodesByType:t.nodesByType,nodeCount:t.nodeCount})]})});function fW(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),a=e?e.graph:null,s=a&&$8(a)?a:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Knowledge Graph"}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream…"}),a&&!s&&u.jsx(uW,{reason:a.available?void 0:a.reason}),s&&u.jsx(pW,{graphData:s})]})}const ba=130,Ya=30,JC=180,mW=44,Ja={top:40,right:24,bottom:24,left:24},yc=Ja.left,Ku={high:"#ef4444",medium:"#f59e0b",low:"#71717a"};function hW(e){return e>.7?"high":e>=.3?"medium":"low"}function uT(e){return Math.max(.15,Math.min(1,e))}function gW(e){if(e.layers.length===0)return null;const t=[],n=[],r={nodeId:e.sourceNodeId,name:e.sourceName,type:"source",probability:1,parentId:"",risk:"high",x:yc,y:Ja.top};t.push(r);for(const o of e.layers){const c=yc+o.depth*JC;o.nodes.forEach((d,p)=>{const m={nodeId:d.nodeId,name:d.name,type:d.type,probability:d.probability,parentId:d.parentId,risk:hW(d.probability),x:c,y:Ja.top+p*mW};t.push(m),n.push({fromId:d.parentId,toId:d.nodeId})})}const a=Math.max(...t.map(o=>o.x+ba))+Ja.right,s=Math.max(...t.map(o=>o.y+Ya))+Ja.bottom;return{nodes:t,sourceNode:r,edges:n,width:a,height:s}}function bW({data:e}){const{summary:t}=e,n=[{label:"Total Affected",count:t.totalAffected,color:"#fafafa"},{label:"High Risk",count:t.highRisk,color:Ku.high},{label:"Medium Risk",count:t.mediumRisk,color:Ku.medium},{label:"Low Risk",count:t.lowRisk,color:Ku.low}];return u.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-4",children:[n.map(r=>u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{background:r.color}}),u.jsx("span",{className:"text-sm tabular-nums text-neutral-text",children:r.count}),u.jsx("span",{className:"text-xs text-neutral-muted",children:r.label})]},r.label)),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"text-xs text-neutral-muted",children:"Max Depth:"}),u.jsx("span",{className:"text-sm tabular-nums text-neutral-text",children:t.maxDepth})]})]})}function yW({data:e}){const t=gW(e),[n,r]=N.useState(null);if(!t)return u.jsx(J.div,{initial:{opacity:0},animate:{opacity:1},className:"flex h-32 items-center justify-center rounded-2xl border border-neutral-border bg-neutral-bg/50 backdrop-blur-sm",children:u.jsx("p",{className:"text-sm text-neutral-muted",children:"No affected nodes detected"})});const a=new Map(t.nodes.map(o=>[o.nodeId,o])),s=e.layers.map(o=>o.depth);return u.jsxs("div",{className:"relative group",children:[u.jsx(bW,{data:e}),u.jsx("div",{className:"overflow-x-auto rounded-2xl border border-neutral-border bg-neutral-bg/30 p-6 backdrop-blur-md",children:u.jsxs("svg",{width:t.width,height:t.height,className:"overflow-visible",children:[u.jsxs("defs",{children:[u.jsxs("filter",{id:"neon-glow",x:"-20%",y:"-20%",width:"140%",height:"140%",children:[u.jsx("feGaussianBlur",{stdDeviation:"2",result:"blur"}),u.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]}),u.jsx("marker",{id:"blast-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:u.jsx("path",{d:"M0,0 L0,6 L8,3 z",fill:"#4f46e5"})})]}),u.jsx(J.text,{initial:{opacity:0},animate:{opacity:1},x:yc+ba/2,y:Ja.top-14,textAnchor:"middle",className:"text-[10px] font-bold uppercase tracking-widest fill-neutral-muted",children:"Origin"}),s.map(o=>{const c=yc+o*JC;return u.jsxs(J.text,{initial:{opacity:0},animate:{opacity:1},transition:{delay:o*.1},x:c+ba/2,y:Ja.top-14,textAnchor:"middle",className:"text-[10px] font-bold uppercase tracking-widest fill-neutral-muted",children:["Layer ",o]},o)}),t.edges.map((o,c)=>{const d=a.get(o.fromId),p=a.get(o.toId);if(!d||!p)return null;const m=d.x+ba,h=d.y+Ya/2,b=p.x,y=p.y+Ya/2,v=n===o.fromId||n===o.toId;return u.jsx(J.line,{initial:{pathLength:0,opacity:0},animate:{pathLength:1,opacity:v?1:uT(p.probability),stroke:v?"var(--color-primary-500)":"rgba(79, 70, 229, 0.2)",strokeWidth:v?2:1.5},transition:{duration:.4},x1:m,y1:h,x2:b-4,y2:y,markerEnd:"url(#blast-arrow)"},`${o.fromId}-${o.toId}`)}),t.nodes.map((o,c)=>u.jsxs(J.g,{initial:{opacity:0,scale:.9,x:o.x-10},animate:{opacity:n&&n!==o.nodeId?.3:uT(o.probability),scale:n===o.nodeId?1.05:1,x:o.x},onMouseEnter:()=>r(o.nodeId),onMouseLeave:()=>r(null),transition:{duration:.2},className:"cursor-pointer",children:[u.jsx("rect",{x:0,y:o.y,width:ba,height:Ya,rx:8,className:"fill-neutral-surface/80 stroke-neutral-border",strokeWidth:1}),u.jsx(J.rect,{x:0,y:o.y,width:ba,height:Ya,rx:8,className:"fill-none",stroke:Ku[o.risk],strokeWidth:1.5,initial:{pathLength:0},animate:{pathLength:1},transition:{duration:1,delay:c*.05}}),u.jsx("text",{x:ba/2,y:o.y+Ya/2,dominantBaseline:"middle",textAnchor:"middle",className:"text-[10px] font-bold tracking-tight fill-neutral-text pointer-events-none",children:o.name.length>16?o.name.slice(0,15)+"…":o.name}),u.jsx("text",{x:ba-6,y:o.y+Ya-6,textAnchor:"end",className:"text-[8px] font-mono fill-neutral-muted pointer-events-none",children:o.type==="source"?"SRC":`${(o.probability*100).toFixed(0)}%`})]},o.nodeId))]})})]})}const xW=[1,2,3,4,5],vW=3,SW=N.memo(function({loading:t,fetchError:n,anomalies:r,sortedAPs:a,sortedOutliers:s,selectedNodeId:o,onAnomalyClick:c}){return u.jsxs("div",{className:"lg:col-span-1",children:[t&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading anomalies..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),r&&a.length===0&&s.length===0&&u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsx("p",{className:"text-base font-medium text-gray-300",children:"No anomalies detected"}),u.jsx("p",{className:"mt-2 text-sm text-gray-500",children:'Run "harness scan" to build the knowledge graph, then restart the dashboard.'})]}),a.length>0&&u.jsxs("section",{className:"mb-6",children:[u.jsx("h2",{className:"mb-2 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Articulation Points"}),u.jsx("div",{className:"space-y-1",children:a.map(d=>u.jsxs("button",{onClick:()=>c(d.nodeId),className:["w-full rounded border px-3 py-2 text-left text-sm transition-colors",o===d.nodeId?"border-blue-700 bg-blue-950":"border-gray-800 bg-gray-900 hover:bg-gray-800"].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"truncate font-medium text-gray-200",children:d.name}),u.jsxs("span",{className:"ml-2 text-xs tabular-nums text-gray-500",children:[d.dependentCount," deps"]})]}),u.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:[d.componentsIfRemoved," components if removed"]})]},d.nodeId))})]}),s.length>0&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-2 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Statistical Outliers"}),u.jsx("div",{className:"space-y-1",children:s.map(d=>u.jsxs("button",{onClick:()=>c(d.nodeId),className:["w-full rounded border px-3 py-2 text-left text-sm transition-colors",o===d.nodeId?"border-blue-700 bg-blue-950":"border-gray-800 bg-gray-900 hover:bg-gray-800"].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"truncate font-medium text-gray-200",children:d.name}),u.jsxs("span",{className:"ml-2 text-xs tabular-nums text-gray-500",children:["z=",d.zScore.toFixed(1)]})]}),u.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:[d.metric,": ",d.value," (",d.type,")"]})]},d.nodeId))})]})]})}),EW=N.memo(function({selectedNodeId:t,blastRadiusState:n,blastRadiusError:r,brData:a,brIsData:s}){const o=s?a:null;return u.jsxs("div",{className:"lg:col-span-2",children:[!t&&n==="idle"&&u.jsx("div",{className:"flex h-64 items-center justify-center rounded-lg border border-gray-800 bg-gray-900",children:u.jsx("p",{className:"text-sm text-gray-500",children:"Select a node or search to view blast radius"})}),n==="loading"&&u.jsx("div",{className:"flex h-64 items-center justify-center rounded-lg border border-gray-800 bg-gray-900",children:u.jsx("p",{className:"text-sm text-gray-500",children:"Computing blast radius..."})}),n==="error"&&r&&u.jsx("div",{className:"rounded-lg border border-red-800 bg-gray-900 p-6",children:u.jsx("p",{className:"text-sm text-red-400",children:r})}),n==="success"&&a&&!s&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:u.jsx("p",{className:"text-sm text-gray-400",children:"error"in a?a.error:"No blast radius data"})}),n==="success"&&o&&u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsxs("h3",{className:"mb-3 text-sm font-semibold text-gray-200",children:["Blast Radius: ",o.sourceName]}),u.jsx(yW,{data:o})]})]})}),wW=N.memo(function({searchText:t,depth:n,onSearchTextChange:r,onDepthChange:a,onSubmit:s}){return u.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[u.jsxs("form",{onSubmit:s,className:"flex flex-1 gap-2",children:[u.jsx("input",{type:"text",value:t,onChange:o=>r(o.target.value),placeholder:"Search node by name or path...",className:"flex-1 rounded border border-gray-700 bg-gray-900 px-3 py-1.5 text-sm text-gray-200 placeholder-gray-500 focus:border-gray-500 focus:outline-none"}),u.jsx("button",{type:"submit",className:"rounded bg-gray-800 px-3 py-1.5 text-xs font-medium text-gray-200 hover:bg-gray-700",children:"Search"})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-400",children:["Depth",u.jsx("select",{value:n,onChange:o=>a(Number(o.target.value)),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1.5 text-sm text-gray-200",children:xW.map(o=>u.jsx("option",{value:o,children:o},o))})]})]})});function kW(){const[e,t]=N.useState(null),[n,r]=N.useState(!0),[a,s]=N.useState(null),o=N.useCallback(async()=>{try{const c=await fetch("/api/impact/anomalies");if(!c.ok){s(`HTTP ${c.status}`);return}const d=await c.json();t(d.data),s(null)}catch(c){s(c instanceof Error?c.message:"Network error")}finally{r(!1)}},[]);return N.useEffect(()=>{o()},[o]),{anomalies:e,loading:n,fetchError:a}}function NW(e){const t=e?[...e.articulationPoints].sort((r,a)=>a.dependentCount-r.dependentCount):[],n=e?[...e.outliers].sort((r,a)=>a.zScore-r.zScore):[];return{sortedAPs:t,sortedOutliers:n}}function TW(){var E;const{anomalies:e,loading:t,fetchError:n}=kW(),[r,a]=N.useState(null),[s,o]=N.useState(""),[c,d]=N.useState(vW),p=ZC("/api/impact/blast-radius"),m=N.useCallback(T=>{a(T),p.run({nodeId:T,maxDepth:c})},[p,c]),h=N.useCallback(T=>{T.preventDefault();const A=s.trim();A&&m(A)},[s,m]),b=N.useCallback(T=>{o(""),m(T)},[m]),{sortedAPs:y,sortedOutliers:v}=N.useMemo(()=>NW(e),[e]),k=(E=p.data)==null?void 0:E.data,w=!!k&&V8(k);return{anomalies:e,loading:t,fetchError:n,selectedNodeId:r,searchText:s,depth:c,setSearchText:o,setDepth:d,handleSearch:h,handleAnomalyClick:b,sortedAPs:y,sortedOutliers:v,blastRadius:p,brData:k,brIsData:w}}function AW(){const{anomalies:e,loading:t,fetchError:n,selectedNodeId:r,searchText:a,depth:s,setSearchText:o,setDepth:c,handleSearch:d,handleAnomalyClick:p,sortedAPs:m,sortedOutliers:h,blastRadius:b,brData:y,brIsData:v}=TW();return u.jsxs("div",{children:[u.jsx("h1",{className:"mb-6 text-2xl font-bold",children:"Impact Explorer"}),u.jsx(wW,{searchText:a,depth:s,onSearchTextChange:o,onDepthChange:c,onSubmit:d}),u.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[u.jsx(SW,{loading:t,fetchError:n,anomalies:e,sortedAPs:m,sortedOutliers:h,selectedNodeId:r,onAnomalyClick:p}),u.jsx(EW,{selectedNodeId:r,blastRadiusState:b.state,blastRadiusError:b.error,brData:y,brIsData:v})]})]})}function eR(e){return e==="improving"?"Improving":e==="declining"?"Degrading":"Stable"}function Uf(e){return e==="improving"?"green":e==="declining"?"red":"yellow"}function IW(e){return e==="improving"?"text-emerald-400":e==="declining"?"text-red-400":"text-yellow-400"}function CW(e){return e==="improving"?"↓":e==="declining"?"↑":"→"}function tR(e){return e===0?"0":`${e>0?"+":""}${e.toFixed(1)}`}function RW(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const _W=N.memo(function({name:t,trend:n}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:RW(t)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200",children:n.current.toFixed(1)}),u.jsxs("td",{className:`py-2 px-3 text-right tabular-nums ${IW(n.direction)}`,children:[CW(n.direction)," ",eR(n.direction)]}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:tR(n.delta)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-500",children:n.previous.toFixed(1)})]})});function OW({categories:e}){const t=N.useMemo(()=>Object.entries(e).sort((n,r)=>Math.abs(r[1].delta)-Math.abs(n[1].delta)),[e]);return t.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No category data yet. Capture architecture snapshots to see trends."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Category"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Current"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Trend"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Delta"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Previous"})]})}),u.jsx("tbody",{children:t.map(([n,r])=>u.jsx(_W,{name:n,trend:r},n))})]})})}async function LW(){const e=await fetch("/api/decay-trends");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function DW(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),o=N.useCallback(async()=>{try{const d=await LW();t(d),r(null)}catch(d){r(d instanceof Error?d.message:"Network error")}finally{s(!1)}},[]);N.useEffect(()=>{o()},[o]);const c=e&&e.snapshotCount===0;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Decay Trends"}),e&&e.to&&u.jsxs("span",{className:"text-xs text-gray-500",children:[e.snapshotCount," snapshot",e.snapshotCount!==1?"s":""," analyzed",e.from&&` from ${e.from.slice(0,10)} to ${e.to.slice(0,10)}`]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading decay trends..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),c&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsxs("p",{className:"text-sm text-gray-500",children:["No architecture snapshots found. Run"," ",u.jsx("code",{className:"text-gray-400",children:"harness snapshot capture"})," to create the first snapshot."]})}),e&&!c&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Overview"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Stability Score",value:e.stability.current,sub:"0-100 (higher is healthier)",accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Trend Direction",value:eR(e.stability.direction),accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Score Delta",value:tR(e.stability.delta),sub:`Previous: ${e.stability.previous}`,accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Snapshots",value:e.snapshotCount})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Category Breakdown"}),u.jsx(OW,{categories:e.categories})]})]})]})}function jW(e){switch(e){case"full":return"Covered";case"code-only":return"Partial (code)";case"test-only":return"Partial (test)";case"none":return"Uncovered"}}function MW(e){switch(e){case"full":return"text-emerald-400";case"code-only":case"test-only":return"text-yellow-400";case"none":return"text-red-400"}}function FW(e){switch(e){case"full":return"bg-emerald-400";case"code-only":case"test-only":return"bg-yellow-400";case"none":return"bg-red-400"}}function _u(e){return e>=80?"green":e>=50?"yellow":"red"}const PW=N.memo(function({req:t}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsxs("td",{className:"py-2 px-3",children:[u.jsx("div",{className:"font-mono text-xs text-gray-200",children:t.requirementName||t.requirementId}),t.featureName&&u.jsx("div",{className:"text-[10px] text-gray-500 mt-0.5",children:t.featureName})]}),u.jsx("td",{className:"py-2 px-3",children:u.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[u.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${FW(t.status)}`}),u.jsx("span",{className:`text-xs font-medium ${MW(t.status)}`,children:jW(t.status)})]})}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200 text-sm",children:t.codeFileCount}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200 text-sm",children:t.testFileCount})]})});function BW({requirements:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsxs("p",{className:"text-sm text-gray-500",children:["No requirements found in graph. Run"," ",u.jsx("code",{className:"rounded bg-gray-800 px-1 py-0.5 text-xs font-mono text-gray-300",children:"harness scan"})," ","to ingest spec requirements."]})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Requirement"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Implementations"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Tests"})]})}),u.jsx("tbody",{children:e.map(t=>u.jsx(PW,{req:t},t.requirementId))})]})})}async function UW(){const e=await fetch("/api/traceability");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function $W(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),[o,c]=N.useState(!1),d=N.useCallback(async()=>{try{const b=await UW();b===null?c(!0):t(b),r(null)}catch(b){r(b instanceof Error?b.message:"Network error")}finally{s(!1)}},[]);N.useEffect(()=>{d()},[d]);const p=e?e.totals.fullyTraced:0,m=e?e.totals.withCode+e.totals.withTests-2*e.totals.fullyTraced:0,h=e?e.totals.untraceable:0;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Traceability"}),e&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Generated ",new Date(e.generatedAt).toLocaleString()]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading traceability data..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),o&&!a&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-8 text-center",children:u.jsxs("p",{className:"text-sm text-gray-400",children:["No traceability data available. Run"," ",u.jsx("code",{className:"rounded bg-gray-800 px-1.5 py-0.5 text-xs font-mono text-gray-300",children:"harness scan"})," ","to build the knowledge graph with requirement nodes from spec files."]})}),e&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Coverage Summary"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Total Requirements",value:e.totals.total}),u.jsx(Ze,{label:"Covered",value:p,accent:"green",sub:`${e.overallCoverage}% coverage`}),u.jsx(Ze,{label:"Partial",value:m>0?m:e.totals.total-p-h,accent:"yellow"}),u.jsx(Ze,{label:"Uncovered",value:h,accent:h>0?"red":"green"})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Overall Coverage"}),u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsx("span",{className:"text-sm text-gray-400",children:"Fully traced"}),u.jsxs("span",{className:`text-sm font-bold ${_u(e.overallCoverage)==="green"?"text-emerald-400":_u(e.overallCoverage)==="yellow"?"text-yellow-400":"text-red-400"}`,children:[e.overallCoverage,"%"]})]}),u.jsx("div",{className:"h-2 rounded-full bg-gray-800 overflow-hidden",children:u.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${_u(e.overallCoverage)==="green"?"bg-emerald-500":_u(e.overallCoverage)==="yellow"?"bg-yellow-500":"bg-red-500"}`,style:{width:`${e.overallCoverage}%`}})})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Requirements"}),u.jsx(BW,{requirements:e.requirements})]})]})]})}function zW(){const[e,t]=N.useState([]),[n,r]=N.useState(!0),[a,s]=N.useState(null);return N.useEffect(()=>{let o=!1;async function c(){try{const p=await fetch("/api/streams");if(!p.ok)throw new Error(`Failed to fetch sessions: ${p.status}`);const m=await p.json();o||(t(m),s(null))}catch(p){o||s(p instanceof Error?p.message:"Failed to load sessions")}finally{o||r(!1)}}c();const d=setInterval(()=>void c(),3e4);return()=>{o=!0,clearInterval(d)}},[]),{sessions:e,loading:n,error:a}}function GW(e){if(!e)return"never";const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function cT({status:e}){const t=e.detected.length>0?e.detected.join(", "):"none detected";return u.jsx("div",{role:"alert",className:"mb-6 rounded-lg border border-red-900/60 bg-red-950/40 px-4 py-3 text-sm",children:u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("span",{className:"mt-0.5 inline-block h-2.5 w-2.5 flex-shrink-0 rounded-full bg-red-500"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("p",{className:"font-semibold text-red-300",children:"Local model unavailable"}),u.jsxs("p",{className:"mt-1 font-mono text-xs text-red-300/80",children:[e.backendName," — ",e.endpoint]}),u.jsx("p",{className:"mt-1 text-red-200",children:"No configured candidate is currently loaded on the local server. The intelligence pipeline and local agent dispatch are disabled until a candidate is loaded."}),u.jsxs("dl",{className:"mt-2 grid grid-cols-1 gap-x-6 gap-y-1 text-xs text-red-200 sm:grid-cols-2",children:[u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Configured:"}),u.jsx("dd",{className:"font-mono",children:e.configured.join(", ")||"(none)"})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Detected:"}),u.jsx("dd",{className:"font-mono",children:t})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Last probe:"}),u.jsx("dd",{className:"font-mono",children:GW(e.lastProbeAt)})]}),e.lastError&&u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Last error:"}),u.jsx("dd",{className:"font-mono",children:e.lastError})]})]})]})]})})}function Gr({title:e}){return u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:e})}function or(e){return e.toLocaleString()}function HW(e){const t=nR(),n=Math.max(0,Math.floor((t-new Date(e).getTime())/1e3));if(n<60)return`${n}s`;const r=Math.floor(n/60),a=n%60;return r<60?`${r}m ${a}s`:`${Math.floor(r/60)}h ${r%60}m`}function nR(){const[e,t]=N.useState(Date.now());return N.useEffect(()=>{const n=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(n)},[]),e}function VW({phase:e}){const n={PreparingWorkspace:"bg-yellow-900/50 text-yellow-400",BuildingPrompt:"bg-yellow-900/50 text-yellow-400",LaunchingAgent:"bg-blue-900/50 text-blue-400",InitializingSession:"bg-blue-900/50 text-blue-400",StreamingTurn:"bg-emerald-900/50 text-emerald-400",Finishing:"bg-purple-900/50 text-purple-400",Succeeded:"bg-emerald-900/50 text-emerald-300",Failed:"bg-red-900/50 text-red-400",TimedOut:"bg-red-900/50 text-red-400",Stalled:"bg-orange-900/50 text-orange-400",CanceledByReconciliation:"bg-gray-800 text-gray-400"}[e]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${n}`,children:e})}function WW({startedAt:e}){const t=HW(e);return u.jsx("span",{className:"tabular-nums text-gray-400",children:t})}function qW({snapshot:e}){const t=e.globalCooldownUntilMs!==null&&Date.now()<e.globalCooldownUntilMs,n=Date.now(),r=e.recentRequestTimestamps.filter(o=>n-o<6e4).length,a=e.recentInputTokens.filter(o=>n-o.timestamp<6e4).reduce((o,c)=>o+c.tokens,0),s=e.recentOutputTokens.filter(o=>n-o.timestamp<6e4).reduce((o,c)=>o+c.tokens,0);return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Rate Limits"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Status"}),u.jsx("span",{className:t?"font-semibold text-red-400":"text-emerald-400",children:t?"COOLDOWN":"OK"})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Req/Min"}),u.jsxs("span",{className:"text-blue-400",children:[r," / ",e.maxRequestsPerMinute]})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Req/Sec"}),u.jsxs("span",{className:"text-blue-400",children:[e.maxRequestsPerSecond," max"]})]}),e.maxInputTokensPerMinute>0&&u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"ITPM"}),u.jsxs("span",{className:"text-yellow-400",children:[or(a)," / ",or(e.maxInputTokensPerMinute)]})]}),e.maxOutputTokensPerMinute>0&&u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"OTPM"}),u.jsxs("span",{className:"text-yellow-400",children:[or(s)," / ",or(e.maxOutputTokensPerMinute)]})]})]})]})}function YW({snapshot:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Concurrency"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Active"}),u.jsxs("span",{className:e.running.length>0?"text-emerald-400":"text-gray-500",children:[e.running.length," / ",e.maxConcurrentAgents]})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Claimed"}),u.jsx("span",{className:"text-cyan-400",children:e.claimed.length})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Retry Queue"}),u.jsx("span",{className:"text-gray-300",children:e.retryAttempts.length})]})]})]})}function KW({snapshot:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Token Usage"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Input"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.inputTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Output"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.outputTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Total"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.totalTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Time Running"}),u.jsxs("span",{className:"text-blue-400",children:[Math.round(e.tokenTotals.secondsRunning),"s"]})]})]})]})}function XW({activity:e}){if(e.phase==="idle")return null;const t={fetching:"Fetching",analyzing:"Analyzing",dispatching:"Dispatching"},n={fetching:"text-blue-400",analyzing:"text-violet-400",dispatching:"text-emerald-400"};return u.jsxs("div",{className:"mb-6 rounded-lg border border-violet-800/50 bg-violet-950/20 px-4 py-3",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[u.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-violet-400 opacity-75"}),u.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-violet-500"})]}),u.jsx("span",{className:`text-sm font-medium ${n[e.phase]??"text-gray-400"}`,children:t[e.phase]??e.phase}),e.detail&&u.jsx("span",{className:"truncate text-sm text-gray-400",children:e.detail}),e.progress&&u.jsxs("span",{className:"ml-auto text-xs tabular-nums text-gray-500",children:[e.progress.current,"/",e.progress.total]})]}),e.progress&&u.jsx("div",{className:"mt-2 h-1 overflow-hidden rounded-full bg-gray-800",children:u.jsx("div",{className:"h-full rounded-full bg-violet-500 transition-all duration-300",style:{width:`${e.progress.current/e.progress.total*100}%`}})})]})}function ZW({agent:e,blocks:t,onViewStream:n}){var o,c,d,p,m,h,b,y,v;const[r,a]=N.useState(!1),s=t.slice(-5);return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900/60",children:[u.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-gray-800/40",children:[u.jsx("div",{className:"mt-1 flex-shrink-0",children:e.phase==="StreamingTurn"?u.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[u.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-75"}),u.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-emerald-500"})]}):u.jsx("span",{className:"inline-flex h-2.5 w-2.5 rounded-full bg-yellow-500"})}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"truncate font-medium text-white",children:((o=e.issue)==null?void 0:o.title)??e.identifier}),u.jsx(VW,{phase:e.phase})]}),u.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-gray-500",children:[u.jsx("span",{className:"font-mono",children:e.identifier}),u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx("span",{className:"text-blue-400",children:((c=e.session)==null?void 0:c.backendName)??"pending"}),u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx(WW,{startedAt:e.startedAt}),e.session&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:["T",e.session.turnCount," · ",or(e.session.totalTokens)," tok"]})]})]}),((d=e.session)==null?void 0:d.lastMessage)&&u.jsx("p",{className:"mt-1.5 truncate text-xs text-gray-400",children:e.session.lastMessage})]}),u.jsx("span",{className:"mt-1 flex-shrink-0 text-gray-600",children:r?"▲":"▼"})]}),r&&u.jsxs("div",{className:"border-t border-gray-800 px-4 py-3 text-sm",children:[(p=e.issue)!=null&&p.description?u.jsxs("div",{className:"mb-3",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Description"}),u.jsx("p",{className:"mt-1 whitespace-pre-wrap text-gray-300",children:e.issue.description})]}):u.jsx("p",{className:"mb-3 text-xs italic text-gray-600",children:"No description available."}),u.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1 text-xs",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Input Tokens"}),u.jsx("span",{className:"text-yellow-400",children:or(((m=e.session)==null?void 0:m.inputTokens)??0)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Output Tokens"}),u.jsx("span",{className:"text-yellow-400",children:or(((h=e.session)==null?void 0:h.outputTokens)??0)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Backend"}),u.jsx("span",{className:"text-blue-400",children:((b=e.session)==null?void 0:b.backendName)??"-"})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Turns"}),u.jsx("span",{className:"text-gray-300",children:((y=e.session)==null?void 0:y.turnCount)??0})]})]}),s.length>0&&u.jsxs("div",{className:"mt-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Live Activity"}),u.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),n()},className:"text-xs font-medium text-blue-400 transition-colors hover:text-blue-300",children:"View Full Stream"})]}),u.jsx("div",{className:"mt-2 max-h-48 overflow-hidden rounded-lg border border-gray-800 bg-gray-950/60 px-3 py-2 text-xs",children:u.jsx(YC,{blocks:s,isStreaming:e.phase==="StreamingTurn"})})]}),s.length===0&&((v=e.session)==null?void 0:v.lastMessage)&&u.jsxs("div",{className:"mt-3",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Latest Activity"}),u.jsx("p",{className:"mt-1 whitespace-pre-wrap text-gray-300",children:e.session.lastMessage})]})]})]})}function QW({agents:e,agentEvents:t,onViewStream:n}){return e.length===0?u.jsx("p",{className:"text-sm italic text-gray-500",children:"No active agents."}):u.jsx("div",{className:"space-y-2",children:e.map(r=>u.jsx(ZW,{agent:r,blocks:t[r.issueId]??[],onViewStream:()=>n(r)},r.issueId))})}function JW({snapshot:e}){const t=nR();if(e.retryAttempts.length===0)return null;const n=[...e.retryAttempts].sort((r,a)=>r[1].dueAtMs-a[1].dueAtMs);return u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Retry Queue"}),u.jsx("div",{className:"space-y-1",children:n.map(([,r])=>{const a=Math.max(0,Math.ceil((r.dueAtMs-t)/1e3));return u.jsxs("div",{className:"flex items-center justify-between rounded border border-gray-800 bg-gray-900/40 px-3 py-2 text-sm",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-flex h-2 w-2 rounded-full ${a>0?"bg-orange-500":"bg-orange-400 animate-pulse"}`}),u.jsx("span",{className:"font-mono text-gray-300",children:r.identifier}),u.jsxs("span",{className:"text-gray-500",children:["attempt ",r.attempt]})]}),u.jsx("span",{className:`text-xs ${a>0?"text-gray-500":"text-orange-400 font-medium"}`,children:a>0?`retries in ${a}s`:"due now"})]},r.issueId)})})]})}function e9(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function t9(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function n9({outcome:e}){if(!e)return u.jsx("span",{className:"text-xs text-gray-600",children:"in progress"});const n={normal:"bg-emerald-900/50 text-emerald-400",error:"bg-red-900/50 text-red-400"}[e]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${n}`,children:e})}function r9({session:e,onViewStream:t}){const n=e.attempts.at(-1),r=n==null?void 0:n.startedAt,a=(n==null?void 0:n.outcome)??null,s=n==null?void 0:n.stats;return u.jsxs("button",{type:"button",onClick:()=>t(e.issueId),className:"flex w-full items-center gap-3 rounded-lg border border-gray-800 bg-gray-900/60 px-4 py-3 text-left transition-colors hover:bg-gray-800/40",children:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"truncate font-medium text-white",children:e.title??e.identifier}),u.jsx(n9,{outcome:a}),e.pr&&u.jsxs("span",{className:"text-xs text-blue-400",children:["PR #",e.pr.number]})]}),u.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-gray-500",children:[r&&u.jsx("span",{children:t9(r)}),s&&s.durationMs>0&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx("span",{children:e9(s.durationMs)})]}),s&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:["T",s.turnCount," · ",or(s.inputTokens+s.outputTokens)," ","tok"]})]}),e.attempts.length>1&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:[e.attempts.length," attempts"]})]})]})]}),u.jsx("span",{className:"flex-shrink-0 text-gray-600",children:"›"})]})}function dT({onViewStream:e}){const{sessions:t,loading:n,error:r}=zW();return n?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Loading sessions..."})]}):r?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm text-red-400",children:r})]}):t.length===0?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm italic text-gray-500",children:"No recorded sessions yet."})]}):u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("div",{className:"space-y-2",children:t.map(a=>u.jsx(r9,{session:a,onViewStream:e},a.issueId))})]})}function a9(){const{snapshot:e,agentEvents:t,connected:n,localModelStatuses:r}=Yo(),a=Ln(),s=N.useCallback(d=>{var h,b,y;const p=Pe.getState();for(const v of p.threads.values())if(v.type==="agent"&&v.meta.issueId===d.issueId){p.setActiveThread(v.id),a(`/t/${v.id}`);return}const m=p.createThread("agent",{issueId:d.issueId,identifier:d.identifier,phase:d.phase,issueTitle:((h=d.issue)==null?void 0:h.title)??d.identifier,issueDescription:((b=d.issue)==null?void 0:b.description)??null,startedAt:d.startedAt,backendName:((y=d.session)==null?void 0:y.backendName)??null});p.setActiveThread(m.id),a(`/t/${m.id}`)},[a]),o=N.useCallback(d=>{const p=Pe.getState();for(const h of p.threads.values())if(h.type==="agent"&&h.meta.issueId===d){p.setActiveThread(h.id),a(`/t/${h.id}`);return}const m=p.createThread("agent",{issueId:d,identifier:d,phase:"completed",issueTitle:d,issueDescription:null,startedAt:new Date().toISOString(),backendName:null});p.updateThread(m.id,{status:"completed"}),p.setActiveThread(m.id),a(`/t/${m.id}`)},[a]);if(!e)return u.jsxs("div",{children:[r.filter(d=>!d.available).map(d=>u.jsx(cT,{status:d},d.backendName)),u.jsx("h1",{className:"mb-6 text-2xl font-bold",children:"Agent Monitor"}),u.jsx("p",{className:"text-sm text-gray-500",children:n?"Waiting for first state update...":"Connecting to orchestrator..."}),u.jsx(dT,{onViewStream:o})]});const c=e.running.map(([,d])=>d);return u.jsxs("div",{children:[r.filter(d=>!d.available).map(d=>u.jsx(cT,{status:d},d.backendName)),u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Agent Monitor"}),u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("span",{className:["inline-block h-2 w-2 rounded-full",n?"bg-emerald-500":"bg-yellow-400"].join(" ")}),u.jsx("span",{className:n?"text-gray-500":"text-yellow-400",children:n?"Live":"Reconnecting..."})]})]}),u.jsxs("div",{className:"mb-8 grid grid-cols-1 gap-4 md:grid-cols-3",children:[u.jsx(qW,{snapshot:e}),u.jsx(YW,{snapshot:e}),u.jsx(KW,{snapshot:e})]}),e.tickActivity&&u.jsx(XW,{activity:e.tickActivity}),u.jsxs("section",{children:[u.jsx(Gr,{title:"Active Agents"}),u.jsx(QW,{agents:c,agentEvents:t,onViewStream:s})]}),u.jsx(JW,{snapshot:e}),u.jsx(dT,{onViewStream:o})]})}function i9(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function s9(e){return e==="success"?"text-emerald-400":e==="failed"?"text-red-400":"text-yellow-400"}function Bm(e){return e?new Date(e).toLocaleString():"—"}const o9=N.memo(function({entry:t}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:t.task}),u.jsx("td",{className:`py-2 px-3 text-xs font-semibold uppercase ${s9(t.status)}`,children:t.status}),u.jsx("td",{className:"py-2 px-3 text-xs text-gray-400",children:Bm(t.startedAt)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:i9(t.durationMs)})]})});function l9({entries:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No maintenance history yet. Runs will appear here after the first execution."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Task"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Started At"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Duration"})]})}),u.jsx("tbody",{children:e.map((t,n)=>u.jsx(o9,{entry:t},`${t.task}-${t.startedAt}-${n}`))})]})})}async function u9(){const e=await fetch("/api/maintenance/status");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}async function c9(){const e=await fetch("/api/maintenance/history");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}async function d9(e){const t=await fetch("/api/maintenance/trigger",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:e})});if(!t.ok)throw new Error(`HTTP ${t.status}`)}function p9(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(null),[o,c]=N.useState(!0),[d,p]=N.useState(!1),{maintenanceEvent:m,connected:h}=Yo(),b=N.useCallback(async()=>{try{const[k,w]=await Promise.all([u9(),c9()]);t(k),r(w),s(null)}catch(k){const w=k instanceof Error?k.message:"Network error";w.includes("404")||w.includes("502")?s("Orchestrator not running. Start with: harness orchestrator run"):s(w)}finally{c(!1)}},[]);N.useEffect(()=>{b()},[b]),N.useEffect(()=>{m&&b()},[m,b]);const y=()=>{const k="project-health";p(!0),d9(k).then(()=>b()).catch(w=>{s(w instanceof Error?w.message:"Failed to trigger maintenance run")}).finally(()=>p(!1))},v=(m==null?void 0:m.type)==="maintenance:started"?m.data.taskId:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Maintenance"}),u.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${h?"bg-emerald-400":"bg-gray-600"}`,title:h?"WebSocket connected":"WebSocket disconnected"})]}),u.jsx("button",{onClick:y,disabled:d,className:"rounded-lg border border-white/10 bg-white/5 px-4 py-1.5 text-xs font-semibold uppercase tracking-wider text-gray-200 transition-all hover:bg-white/10 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:d?"Running...":"Trigger Run"})]}),v&&u.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/10 px-4 py-2",children:[u.jsx("span",{className:"inline-block h-2 w-2 animate-pulse rounded-full bg-blue-400"}),u.jsxs("span",{className:"text-sm text-blue-300",children:["Running task: ",u.jsx("span",{className:"font-mono font-semibold",children:v})]})]}),(m==null?void 0:m.type)==="maintenance:error"&&u.jsx("div",{className:"mb-4 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2",children:u.jsxs("span",{className:"text-sm text-red-300",children:["Task ",u.jsx("span",{className:"font-mono font-semibold",children:m.data.taskId})," ","failed",m.data.error?`: ${m.data.error}`:""]})}),o&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading maintenance status..."}),a&&u.jsx("p",{className:"text-sm text-red-400",children:a}),e&&n&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Scheduler Status"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Scheduled Tasks",value:e.scheduledTasks}),u.jsx(Ze,{label:"Last Run",value:Bm(e.lastRunAt)}),u.jsx(Ze,{label:"Next Run",value:Bm(e.nextRunAt)})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Run History"}),u.jsx(l9,{entries:n})]})]})]})}function f9(e){if(e<1e3)return`${Math.round(e)}ms`;const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function m9(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function h9(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function g9(e){return new Date(e).toLocaleString()}async function b9(){const e=await fetch("/api/streams");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}const y9=N.memo(function({outcome:t}){if(!t)return u.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded px-2 py-0.5 text-xs font-medium bg-blue-900/50 text-blue-400",children:[u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-blue-400 animate-pulse"}),"running"]});const r={normal:"bg-emerald-900/50 text-emerald-400",error:"bg-red-900/50 text-red-400",timeout:"bg-orange-900/50 text-orange-400"}[t]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${r}`,children:t})});function x9({title:e}){return u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:e})}const v9=N.memo(function({session:t,onSelect:n}){const r=t.attempts.at(-1),a=r==null?void 0:r.startedAt,s=(r==null?void 0:r.outcome)??null,o=r==null?void 0:r.stats,c=o?o.turnCount:0,d=o?o.inputTokens+o.outputTokens:0;return u.jsxs("tr",{onClick:n,className:"border-b border-gray-800 cursor-pointer transition-colors hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-3 px-3 text-sm text-white truncate max-w-[260px]",children:t.title??t.identifier}),u.jsx("td",{className:"py-3 px-3 font-mono text-xs text-gray-400 max-w-[180px] truncate",children:t.identifier}),u.jsx("td",{className:"py-3 px-3",children:u.jsx(y9,{outcome:s})}),u.jsx("td",{className:"py-3 px-3 text-xs text-gray-400",children:a?g9(a):"-"}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-gray-400 text-xs",children:a?h9(a):"-"}),u.jsxs("td",{className:"py-3 px-3 text-right tabular-nums text-gray-300 text-xs",children:[c," turns"]}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-yellow-400 text-xs",children:m9(d)}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-gray-400 text-xs",children:o&&o.durationMs>0?f9(o.durationMs):"-"}),u.jsxs("td",{className:"py-3 px-3 text-right text-gray-500 text-xs",children:[t.attempts.length>1?`${t.attempts.length} attempts`:"",t.pr?u.jsxs("span",{className:"ml-2 text-blue-400",children:["PR #",t.pr.number]}):null]})]})});function S9(e){const t=Pe.getState();for(const s of t.threads.values())if(s.type==="agent"&&s.meta.issueId===e.issueId)return s.id;const n=e.attempts.at(-1),r=n!=null&&!n.endedAt,a=t.createThread("agent",{issueId:e.issueId,identifier:e.identifier,phase:r?"running":"completed",issueTitle:e.title??e.identifier,issueDescription:null,startedAt:(n==null?void 0:n.startedAt)??new Date().toISOString(),backendName:null});return r||t.updateThread(a.id,{status:"completed"}),a.id}function E9(){const e=Ln(),[t,n]=N.useState([]),[r,a]=N.useState(null),[s,o]=N.useState(!0),c=N.useCallback(async()=>{try{const p=await b9();n(p),a(null)}catch(p){const m=p instanceof Error?p.message:"Network error";m.includes("404")||m.includes("502")?a("Orchestrator not running. Start with: harness orchestrator run"):a(m)}finally{o(!1)}},[]);N.useEffect(()=>{c();const p=setInterval(()=>void c(),3e4);return()=>clearInterval(p)},[c]);const d=N.useCallback(p=>{const m=S9(p);Pe.getState().setActiveThread(m),e(`/t/${m}`)},[e]);return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Streams"}),u.jsxs("div",{className:"flex items-center gap-4",children:[t.length>0&&u.jsxs("span",{className:"text-xs text-gray-500",children:[t.length," recorded session",t.length!==1?"s":""]}),u.jsx("button",{type:"button",onClick:()=>{o(!0),c()},className:"rounded-lg border border-gray-700 bg-gray-800/60 px-3 py-1.5 text-xs font-medium text-gray-300 transition-colors hover:bg-gray-700 hover:text-white",children:"Refresh"})]})]}),s&&t.length===0&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading streams..."}),r&&u.jsx("p",{className:"text-sm text-red-400",children:r}),!s&&!r&&t.length===0&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No recorded streams yet. Sessions will appear here after agents run."})}),t.length>0&&u.jsxs("section",{children:[u.jsx(x9,{title:"Recorded Sessions"}),u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Title"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Identifier"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Started At"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Age"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Turns"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Tokens"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Duration"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Info"})]})}),u.jsx("tbody",{children:t.map(p=>u.jsx(v9,{session:p,onSelect:()=>d(p)},p.issueId))})]})})]})]})}const xa={done:"#10b981","in-progress":"#3b82f6",planned:"#6b7280",blocked:"#ef4444",backlog:"#374151","needs-human":"#f59e0b"},Bi=20,$f=8,Ou=140,Ui={top:12,right:24,bottom:12,left:8};function w9({milestones:e}){const t=e.filter(d=>!d.isBacklog);if(t.length===0)return null;const n=Math.max(...t.map(d=>d.total),1),r=480,a=r-Ou,s=Ui.top+t.length*(Bi+$f)-$f+Ui.bottom;function o(d){return Ou+d/n*a}function c(d,p){const m=[{value:d.done,color:xa.done},{value:d.inProgress,color:xa["in-progress"]},{value:d.blocked,color:xa.blocked},{value:d.needsHuman,color:xa["needs-human"]},{value:d.planned+d.backlog,color:xa.planned}];let h=0;return m.map(({value:b,color:y},v)=>{if(b===0)return null;const k=o(h),w=b/n*a;return h+=b,u.jsx("rect",{x:k,y:p,width:w,height:Bi,fill:y},v)})}return u.jsxs("div",{children:[u.jsx("p",{className:"mb-2 text-xs text-neutral-muted",children:"Per-milestone progress (done / in-progress / blocked / remaining)"}),u.jsx("svg",{width:r+Ui.left+Ui.right,height:s,className:"overflow-visible",children:u.jsx("g",{transform:`translate(${Ui.left},${Ui.top})`,children:t.map((d,p)=>{const m=p*(Bi+$f);return u.jsxs("g",{children:[u.jsx("text",{x:Ou-8,y:m+Bi/2,dominantBaseline:"middle",textAnchor:"end",fontSize:11,fill:"#71717a",children:d.name.length>18?d.name.slice(0,17)+"…":d.name}),u.jsx("rect",{x:Ou,y:m,width:a,height:Bi,fill:"#18181b",rx:3}),c(d,m),u.jsxs("text",{x:o(d.total)+4,y:m+Bi/2,dominantBaseline:"middle",fontSize:10,fill:"#71717a",children:[d.done,"/",d.total]})]},d.name)})})}),u.jsx("div",{className:"mt-2 flex flex-wrap gap-4",children:Object.entries(xa).map(([d,p])=>u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-sm",style:{background:p}}),u.jsx("span",{className:"text-xs capitalize text-neutral-muted",children:d.replace("-"," ")})]},d))})]})}const so=140,$i=32,k9=180,N9=56,xc=24;function T9(e){const t=[],n=new Set(e.map(b=>b.name)),r=new Map;for(const b of e)r.set(b.name,[]);for(const b of e)for(const y of b.blockedBy)n.has(y)&&(t.push([y,b.name]),r.get(y).push(b.name));const a=new Map;for(const b of e)a.set(b.name,0);for(const[,b]of t)a.set(b,(a.get(b)??0)+1);const s=new Map,o=[];for(const b of e)(a.get(b.name)??0)===0&&(o.push(b.name),s.set(b.name,0));let c=0;for(;c<o.length;){const b=o[c++],y=s.get(b)??0;for(const v of r.get(b)){const k=(a.get(v)??1)-1;a.set(v,k),s.set(v,Math.max(s.get(v)??0,y+1)),k===0&&o.push(v)}}const d=new Set(o),p=e.filter(b=>!d.has(b.name)).map(b=>b.name);if(p.length>0){const b=Math.max(0,...Array.from(s.values()));for(const y of p)s.set(y,b+1)}const m=new Map;return{nodes:e.map(b=>{const y=s.get(b.name)??0,v=m.get(y)??0;return m.set(y,v+1),{id:b.name,x:xc+y*k9,y:xc+v*N9,status:b.status}}),edges:t,cycleNodes:p}}function A9({features:e}){const t=new Set,n=new Set;for(const m of e)for(const h of m.blockedBy)t.add(h),n.add(m.name);const r=e.filter(m=>t.has(m.name)||n.has(m.name));if(r.length===0)return null;const{nodes:a,edges:s,cycleNodes:o}=T9(r),c=new Map(a.map(m=>[m.id,m])),d=Math.max(...a.map(m=>m.x+so))+xc,p=Math.max(...a.map(m=>m.y+$i))+xc;return u.jsxs("div",{className:"relative group",children:[u.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[u.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-neutral-muted",children:"Relationship Topology"}),o.length>0&&u.jsxs("span",{className:"rounded bg-red-500/10 px-2 py-0.5 text-[10px] font-bold text-red-400 border border-red-500/20 animate-pulse",children:["Cycles Detected: ",o.length]})]}),u.jsx("div",{className:"overflow-x-auto rounded-2xl border border-neutral-border bg-neutral-bg/30 p-6 backdrop-blur-md",children:u.jsxs("svg",{width:d,height:p,className:"overflow-visible",children:[u.jsxs("defs",{children:[u.jsxs("filter",{id:"neon-glow-small",x:"-20%",y:"-20%",width:"140%",height:"140%",children:[u.jsx("feGaussianBlur",{stdDeviation:"1.5",result:"blur"}),u.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]}),u.jsx("marker",{id:"arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:u.jsx("path",{d:"M0,0 L0,6 L8,3 z",fill:"#4f46e5"})})]}),s.map(([m,h],b)=>{const y=c.get(m),v=c.get(h);if(!y||!v)return null;const k=y.x+so,w=y.y+$i/2,E=v.x,T=v.y+$i/2;return u.jsx(J.line,{initial:{pathLength:0,opacity:0},animate:{pathLength:1,opacity:1},transition:{duration:1,delay:b*.05},x1:k,y1:w,x2:E-4,y2:T,className:"stroke-primary-500/20",strokeWidth:1.5,markerEnd:"url(#arrow)"},`${m}-${h}`)}),a.map((m,h)=>u.jsxs(J.g,{initial:{opacity:0,scale:.9,y:m.y+10},animate:{opacity:1,scale:1,y:m.y},transition:{duration:.4,delay:h*.03},whileHover:{scale:1.05,filter:"url(#neon-glow-small)"},className:"cursor-pointer",children:[u.jsx("rect",{x:m.x,y:0,width:so,height:$i,rx:8,className:"fill-neutral-surface/80 stroke-neutral-border",strokeWidth:1}),u.jsx(J.rect,{x:m.x,y:0,width:so,height:$i,rx:8,className:"fill-none",stroke:xa[m.status]??"#27272a",strokeWidth:1.5,initial:{pathLength:0},animate:{pathLength:1},transition:{duration:1,delay:h*.05}}),u.jsx("text",{x:m.x+so/2,y:$i/2,dominantBaseline:"middle",textAnchor:"middle",className:"text-[10px] font-bold tracking-tight fill-neutral-text pointer-events-none",children:m.id.length>18?m.id.slice(0,17)+"…":m.id})]},m.id))]})})]})}const I9=[{key:"totalFeatures",label:"Total",color:"text-white"},{key:"totalDone",label:"Done",color:"text-emerald-400"},{key:"totalInProgress",label:"In Progress",color:"text-blue-400"},{key:"totalPlanned",label:"Planned",color:"text-gray-400"},{key:"totalBlocked",label:"Blocked",color:"text-red-400"},{key:"totalNeedsHuman",label:"Needs Human",color:"text-amber-400"},{key:"totalBacklog",label:"Backlog",color:"text-gray-500"}];function C9({data:e}){return u.jsx("div",{className:"flex flex-wrap gap-6 rounded-lg border border-gray-800 bg-gray-900/50 px-5 py-3",children:I9.map(({key:t,label:n,color:r})=>u.jsxs("div",{className:"flex items-baseline gap-1.5",children:[u.jsx("span",{className:`text-lg font-bold tabular-nums ${r}`,children:e[t]}),u.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-gray-500",children:n})]},t))})}const ei="—";function rR(e){return(e.status==="planned"||e.status==="backlog")&&(!e.assignee||e.assignee===ei)}function R9(e){return!e.spec||e.spec==="none"||e.spec===ei?"brainstorming":!e.plans||e.plans.length===0||e.plans.length===1&&e.plans[0]===ei?"planning":"execution"}function _9(e){const t=e.match(/^github:(.+?)#(\d+)$/);return t?`https://github.com/${t[1]}/issues/${t[2]}`:null}function O9({status:e}){const t=xa[e]??"#71717a";return u.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider",style:{backgroundColor:`${t}20`,color:t},children:e.replace("-"," ")})}function L9({priority:e}){const t={P0:"text-red-400 bg-red-400/10",P1:"text-orange-400 bg-orange-400/10",P2:"text-yellow-400 bg-yellow-400/10",P3:"text-gray-400 bg-gray-400/10"};return u.jsx("span",{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-bold ${t[e]??"text-gray-400 bg-gray-400/10"}`,children:e})}function D9({feature:e,identity:t,onClaim:n}){const[r,a]=N.useState(!1),s=rR(e);return u.jsxs("div",{className:"border-t border-gray-800 first:border-t-0",children:[u.jsxs("div",{className:"group flex cursor-pointer items-center gap-3 px-4 py-2.5 hover:bg-gray-800/40 transition-colors",onClick:()=>a(!r),children:[u.jsx("span",{className:"text-[10px] text-gray-600 transition-transform",style:{transform:r?"rotate(90deg)":void 0},children:"▶"}),u.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-gray-200",title:e.name,children:e.name}),u.jsx(O9,{status:e.status}),e.priority&&u.jsx(L9,{priority:e.priority}),e.assignee&&e.assignee!==ei&&u.jsx("span",{className:"text-xs text-gray-500",title:e.assignee,children:e.assignee}),u.jsx("span",{className:"hidden max-w-[200px] truncate text-xs text-gray-600 lg:inline",title:e.summary,children:e.summary}),s&&u.jsx("button",{onClick:o=>{o.stopPropagation(),t&&n(e)},disabled:!t,title:t?void 0:"Could not resolve your identity",className:`ml-auto rounded px-2 py-1 text-[10px] font-bold uppercase tracking-widest border transition-all whitespace-nowrap ${t?"bg-primary-500/10 text-primary-400 border-primary-500/20 hover:bg-primary-500 hover:text-white":"bg-gray-800 text-gray-600 border-gray-700 cursor-not-allowed"}`,children:"Start Working"})]}),r&&u.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1.5 bg-gray-900/30 px-10 py-3 text-xs",children:[u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Summary: "}),u.jsx("span",{className:"text-gray-300",children:e.summary})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Spec: "}),u.jsx("span",{className:"text-gray-400",children:e.spec??ei})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Plans: "}),u.jsx("span",{className:"text-gray-400",children:e.plans.length>0?e.plans.join(", "):ei})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"External ID: "}),e.externalId?(()=>{const o=_9(e.externalId);return o?u.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"text-primary-400 hover:underline",onClick:c=>c.stopPropagation(),children:e.externalId}):u.jsx("span",{className:"text-gray-400",children:e.externalId})})():u.jsx("span",{className:"text-gray-400",children:ei})]}),e.blockedBy.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Blocked by: "}),u.jsx("span",{className:"text-red-400",children:e.blockedBy.join(", ")})]}),e.updatedAt&&u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Updated: "}),u.jsx("span",{className:"text-gray-400",children:new Date(e.updatedAt).toLocaleDateString()})]})]})]})}function j9({name:e,features:t,progress:n,identity:r,onClaim:a}){const[s,o]=N.useState(!1),c=(n==null?void 0:n.done)??0,d=(n==null?void 0:n.total)??t.length;return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 overflow-hidden",children:[u.jsxs("button",{className:"flex w-full items-center gap-3 px-4 py-3 text-left hover:bg-gray-800/40 transition-colors",onClick:()=>o(!s),children:[u.jsx("span",{className:"text-xs text-gray-500 transition-transform",style:{transform:s?void 0:"rotate(90deg)"},children:"▶"}),u.jsx("span",{className:"text-sm font-semibold text-gray-200",children:e}),u.jsxs("span",{className:"text-xs text-gray-500",children:[c,"/",d]}),u.jsx("div",{className:"ml-auto h-1.5 w-24 overflow-hidden rounded-full bg-gray-800",children:u.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all",style:{width:d>0?`${c/d*100}%`:"0%"}})})]}),!s&&u.jsx("div",{children:t.map(p=>u.jsx(D9,{feature:p,identity:r,onClaim:a},p.name))})]})}function M9({features:e,milestones:t,filterMilestone:n,filterStatus:r,workableOnly:a,identity:s,onClaim:o}){const c=e.filter(m=>{if(n&&m.milestone!==n)return!1;if(r){if(m.status!==r)return!1}else if(m.status==="done")return!1;return!(a&&!rR(m))});if(c.length===0)return u.jsx("p",{className:"text-sm text-neutral-muted",children:"No features match the current filters."});const d=new Map;for(const m of c){const h=d.get(m.milestone)??[];h.push(m),d.set(m.milestone,h)}const p=new Map(t.map(m=>[m.name,m]));return u.jsx("div",{className:"space-y-3",children:Array.from(d).map(([m,h])=>u.jsx(j9,{name:m,features:h,progress:p.get(m),identity:s,onClaim:o},m))})}const F9={brainstorming:{label:"Brainstorming",description:"No spec found. You’ll start by exploring the problem space."},planning:{label:"Planning",description:"Spec exists but no plan. You’ll create an implementation plan."},execution:{label:"Execution",description:"Spec and plan exist. You’ll start implementing."}};function P9({feature:e,identity:t,onConfirm:n,onCancel:r}){const[a,s]=N.useState(!1),[o,c]=N.useState(null),d=R9(e),p=F9[d];async function m(){s(!0),c(null);try{const h=await fetch("/api/actions/roadmap/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feature:e.name,assignee:t})}),b=await h.json();if(!h.ok){c(b.error??"Claim failed"),s(!1);return}n(b)}catch{c("Network error"),s(!1)}}return u.jsxs("div",{className:"absolute right-0 top-full z-50 mt-2 w-80 rounded-lg border border-gray-700 bg-gray-900 p-4 shadow-xl",children:[u.jsx("h3",{className:"mb-1 text-sm font-semibold text-gray-200",children:"Claim Feature"}),u.jsx("p",{className:"mb-3 text-xs text-gray-400 truncate",title:e.name,children:e.name}),u.jsxs("div",{className:"mb-3 rounded border border-gray-800 bg-gray-800/50 px-3 py-2",children:[u.jsx("div",{className:"flex items-center gap-2",children:u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-primary-400",children:p.label})}),u.jsx("p",{className:"mt-1 text-xs text-gray-400",children:p.description})]}),u.jsxs("p",{className:"mb-3 text-xs text-gray-500",children:["Claiming as ",u.jsx("span",{className:"font-medium text-gray-300",children:t})]}),o&&u.jsx("p",{className:"mb-2 text-xs text-red-400",children:o}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx("button",{onClick:r,disabled:a,className:"rounded px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest text-gray-500 hover:text-gray-300 transition-colors",children:"Cancel"}),u.jsx("button",{onClick:()=>void m(),disabled:a,className:"rounded bg-primary-500 px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest text-white disabled:opacity-40 hover:bg-primary-400 transition-colors",children:a?"Claiming…":"Confirm"})]})]})}const B9={assigned:"text-blue-400",completed:"text-emerald-400",unassigned:"text-gray-400"};function U9({records:e}){return e.length===0?null:u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-left text-xs",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 text-[10px] font-semibold uppercase tracking-widest text-gray-500",children:[u.jsx("th",{className:"px-4 py-2.5",children:"Feature"}),u.jsx("th",{className:"px-4 py-2.5",children:"Assignee"}),u.jsx("th",{className:"px-4 py-2.5",children:"Action"}),u.jsx("th",{className:"px-4 py-2.5",children:"Date"})]})}),u.jsx("tbody",{children:e.map((t,n)=>u.jsxs("tr",{className:"border-t border-gray-800/50 hover:bg-gray-800/30 transition-colors",children:[u.jsx("td",{className:"px-4 py-2 text-gray-300",children:t.feature}),u.jsx("td",{className:"px-4 py-2 text-gray-400",children:t.assignee}),u.jsx("td",{className:`px-4 py-2 capitalize ${B9[t.action]??"text-gray-400"}`,children:t.action}),u.jsx("td",{className:"px-4 py-2 text-gray-500",children:t.date})]},n))})]})})}function $9({milestoneOptions:e,filterMilestone:t,setFilterMilestone:n,filterStatus:r,setFilterStatus:a,workableOnly:s,setWorkableOnly:o}){return u.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[u.jsxs("select",{value:t,onChange:c=>n(c.target.value),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1 text-xs text-gray-300 focus:outline-none",children:[u.jsx("option",{value:"",children:"All Milestones"}),e.map(c=>u.jsx("option",{value:c,children:c},c))]}),u.jsxs("select",{value:r,onChange:c=>a(c.target.value),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1 text-xs text-gray-300 focus:outline-none",children:[u.jsx("option",{value:"",children:"Non-done"}),u.jsx("option",{value:"in-progress",children:"In Progress"}),u.jsx("option",{value:"planned",children:"Planned"}),u.jsx("option",{value:"blocked",children:"Blocked"}),u.jsx("option",{value:"done",children:"Done"}),u.jsx("option",{value:"backlog",children:"Backlog"}),u.jsx("option",{value:"needs-human",children:"Needs Human"})]}),u.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer select-none",children:[u.jsx("input",{type:"checkbox",checked:s,onChange:c=>o(c.target.checked),className:"rounded border-gray-600 bg-gray-800 text-primary-500 focus:ring-primary-500/30"}),"Workable only"]})]})}const aR="rounded bg-primary-500/10 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-primary-400 border border-primary-500/20 hover:bg-primary-500 hover:text-white transition-all";function pT({command:e,label:t}){const n=Ln();return u.jsx("button",{onClick:()=>{const r=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:e});n(`/t/${r.id}`)},className:aR,children:t})}function z9(){const e=Ln(),[t,n]=N.useState(!1),[r,a]=N.useState(""),s=N.useRef(null);N.useEffect(()=>{var c;t&&((c=s.current)==null||c.focus())},[t]);const o=()=>{if(!r.trim())return;const d=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:"harness:roadmap-add"});e(`/t/${d.id}`),n(!1),a("")};return u.jsxs("div",{className:"relative",children:[u.jsx("button",{onClick:()=>n(!t),className:aR,children:"Add"}),t&&u.jsxs("div",{className:"absolute right-0 top-full z-50 mt-2 w-72 rounded-lg border border-gray-700 bg-gray-900 p-3 shadow-xl",children:[u.jsx("label",{className:"mb-1.5 block text-[10px] font-semibold uppercase tracking-widest text-gray-400",children:"What should be added?"}),u.jsx("input",{ref:s,value:r,onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&o(),c.key==="Escape"&&(n(!1),a(""))},placeholder:"e.g. Dark mode support",className:"mb-2 w-full rounded border border-gray-700 bg-gray-800 px-2 py-1.5 text-xs text-gray-200 placeholder-gray-600 focus:border-primary-500 focus:outline-none"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx("button",{onClick:()=>{n(!1),a("")},className:"rounded px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-gray-500 hover:text-gray-300 transition-colors",children:"Cancel"}),u.jsx("button",{onClick:o,disabled:!r.trim(),className:"rounded bg-primary-500 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-white disabled:opacity-40 hover:bg-primary-400 transition-colors",children:"Go"})]})]})]})}const G9={brainstorming:"harness:brainstorming",planning:"harness:planning",execution:"harness:execution"};function H9({milestones:e,features:t,data:n}){const r=Ln(),[a,s]=N.useState(""),[o,c]=N.useState(""),[d,p]=N.useState(!1),[m,h]=N.useState(null),[b,y]=N.useState(null),[v,k]=N.useState(!0),w=e.map(_=>_.name),E=t.some(_=>_.blockedBy.length>0);N.useEffect(()=>{fetch("/api/identity").then(_=>_.ok?_.json():null).then(_=>{_!=null&&_.username&&y(_.username)}).catch(()=>{}).finally(()=>k(!1))},[]);const T=N.useCallback(_=>{h(_)},[]),A=N.useCallback(_=>{h(null);const j=G9[_.workflow]??"harness:execution",D=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:j});r(`/t/${D.id}`)},[r]);return u.jsxs("div",{className:"space-y-8",children:[u.jsx(C9,{data:n}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Progress by Milestone"}),u.jsx(w9,{milestones:e})]}),u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Features"}),u.jsx($9,{milestoneOptions:w,filterMilestone:a,setFilterMilestone:s,filterStatus:o,setFilterStatus:c,workableOnly:d,setWorkableOnly:p})]}),u.jsxs("div",{className:"relative",children:[u.jsx(M9,{features:t,milestones:e,filterMilestone:a,filterStatus:o,workableOnly:d,identity:v?null:b,onClaim:T}),m&&b&&u.jsx(P9,{feature:m,identity:b,onConfirm:A,onCancel:()=>h(null)})]})]}),E&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Blocker Dependencies"}),u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900 p-4",children:u.jsx(A9,{features:t})})]}),n.assignmentHistory.length>0&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Assignment History"}),u.jsx(U9,{records:n.assignmentHistory})]})]})}function V9(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),a=e?e.roadmap:null,s=a&&B8(a)?a:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Roadmap"}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(pT,{command:"harness:roadmap-pilot",label:"Pilot"}),u.jsx(pT,{command:"harness:roadmap-sync",label:"Sync"}),u.jsx(z9,{}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]})]}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream…"}),a&&!s&&u.jsx("p",{className:"text-sm text-red-400",children:"error"in a?a.error:"Unavailable"}),s&&u.jsx(H9,{milestones:s.milestones,features:s.features,data:s})]})}function W9(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function q9(e){return`${Math.round(e*100)}%`}function Y9(e){return e>=.8?"text-emerald-400":e>=.5?"text-yellow-400":"text-red-400"}const K9=N.memo(function({skill:t}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:t.skill}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200",children:t.invocations}),u.jsx("td",{className:`py-2 px-3 text-right tabular-nums ${Y9(t.successRate)}`,children:q9(t.successRate)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:W9(t.avgDuration)}),u.jsx("td",{className:"py-2 px-3 text-right text-xs text-gray-500",children:t.lastUsed.slice(0,10)})]})});function X9({skills:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No adoption data yet. Skills will appear here after your next session."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Skill"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Invocations"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Success"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Avg Duration"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Last Used"})]})}),u.jsx("tbody",{children:e.map(t=>u.jsx(K9,{skill:t},t.skill))})]})})}async function Z9(){const e=await fetch("/api/adoption");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function Q9(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),o=N.useCallback(async()=>{try{const c=await Z9();t(c),r(null)}catch(c){r(c instanceof Error?c.message:"Network error")}finally{s(!1)}},[]);return N.useEffect(()=>{o()},[o]),u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Adoption"}),e&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Generated ",new Date(e.generatedAt).toLocaleString()]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading adoption telemetry..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),e&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Summary"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Total Invocations",value:e.totalInvocations}),u.jsx(Ze,{label:"Unique Skills",value:e.uniqueSkills}),u.jsx(Ze,{label:"Period",value:e.period})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Top Skills"}),u.jsx(X9,{skills:e.topSkills})]})]})]})}function J9(e){const t=N.useRef(new Set),n=N.useRef(!1);N.useEffect(()=>{typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]),N.useEffect(()=>{if(!n.current){for(const r of e)t.current.add(r.id);n.current=!0;return}if(!(typeof Notification>"u"||Notification.permission!=="granted")&&document.hidden)for(const r of e)t.current.has(r.id)||(t.current.add(r.id),new Notification("Needs Attention",{body:`${r.context.issueTitle}
|
|
389
|
+
`);D=B.pop()??"";for(const O of B){if(!O.startsWith("data: "))continue;const $=O.slice(6).trim();if($==="[DONE]"){s(!1),c(null);return}try{const H=JSON.parse($);switch(H.type){case"status":c(H.text);break;case"sel_result":p(H.data);break;case"cml_result":h(H.data);break;case"pesl_result":y(H.data);break;case"error":k(H.error),s(!1);return}}catch{}}}s(!1),c(null)}catch(A){A.name!=="AbortError"&&k(A.message),s(!1)}},[e.id]);return u.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[u.jsx(L8,{initialTitle:t.analysisTitle,initialDescription:t.description,initialLabels:t.labels,collapsed:n,onSubmit:T=>void E(T)}),u.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[a&&o&&u.jsxs(J.div,{animate:{opacity:[.5,1,.5]},transition:{duration:1.5,repeat:1/0},className:"flex items-center gap-2 text-xs text-primary-500",children:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary-500 animate-pulse"}),o]}),d&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-primary-500/20 bg-primary-500/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(lc,{size:14,className:"text-primary-500"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-primary-500",children:"Spec Enrichment (SEL)"})]}),u.jsx("p",{className:"text-sm text-white font-medium",children:d.intent}),u.jsx("p",{className:"text-xs text-neutral-text/80 leading-relaxed",children:d.summary}),d.affectedSystems.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.affectedSystems.map(T=>u.jsxs("span",{className:"rounded-md border border-blue-500/20 bg-blue-500/10 px-2 py-0.5 text-[10px] text-blue-400",children:[T.name," (",Math.round(T.confidence*100),"%)"]},T.name))})]}),m&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-secondary-400/20 bg-secondary-400/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(li,{size:14,className:"text-secondary-400"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-secondary-400",children:"Complexity Model (CML)"})]}),u.jsx("span",{className:`rounded-md border px-2 py-0.5 text-[9px] font-bold uppercase ${D8[m.riskLevel]??""}`,children:m.riskLevel})]}),u.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[u.jsxs("div",{className:"text-center",children:[u.jsxs("span",{className:"block text-lg font-bold text-white",children:[Math.round(m.overall*100),"%"]}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Overall"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.blastRadius.filesEstimated}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Files"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.blastRadius.modules}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Modules"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:m.recommendedRoute}),u.jsx("span",{className:"text-[9px] text-neutral-muted uppercase",children:"Route"})]})]})]}),b&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-xl border border-accent-500/20 bg-accent-500/5 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(MI,{size:14,className:"text-accent-500"}),u.jsx("h4",{className:"text-[9px] font-black uppercase tracking-[0.2em] text-accent-500",children:"Simulation (PESL)"}),u.jsxs("span",{className:"text-xs text-neutral-muted ml-auto",children:["Confidence: ",Math.round(b.executionConfidence*100),"%"]})]}),b.predictedFailures.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase text-red-400",children:"Predicted Failures"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:b.predictedFailures.map((T,A)=>u.jsxs("li",{className:"text-xs text-neutral-text/80",children:["- ",T]},A))})]}),b.recommendedChanges.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[9px] font-bold uppercase text-accent-400",children:"Recommended Changes"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:b.recommendedChanges.map((T,A)=>u.jsxs("li",{className:"text-xs text-neutral-text/80",children:["- ",T]},A))})]})]}),v&&u.jsx("div",{className:"rounded-xl border border-semantic-error/20 bg-semantic-error/5 p-4",children:u.jsxs("p",{className:"text-xs text-semantic-error",children:["Error: ",v]})}),n&&!a&&(d||m||b)&&u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex items-center gap-2 pt-2",children:[u.jsxs("button",{className:"flex items-center gap-1.5 rounded-lg bg-primary-500/10 border border-primary-500/20 px-3 py-1.5 text-[10px] font-bold text-primary-500 hover:bg-primary-500/20 transition-colors",children:[u.jsx(Ah,{size:10}),"Add to Roadmap"]}),u.jsxs("button",{className:"flex items-center gap-1.5 rounded-lg bg-white/[0.04] border border-white/[0.08] px-3 py-1.5 text-[10px] font-bold text-neutral-muted hover:text-white hover:bg-white/[0.08] transition-colors",children:[u.jsx(LI,{size:10}),"Export Spec"]}),u.jsxs("button",{onClick:()=>{r(!1),p(null),h(null),y(null),k(null)},className:"flex items-center gap-1.5 rounded-lg bg-white/[0.04] border border-white/[0.08] px-3 py-1.5 text-[10px] font-bold text-neutral-muted hover:text-white hover:bg-white/[0.08] transition-colors",children:[u.jsx(MB,{size:10}),"Refine"]})]})]})]})}const M8=3e3;function gc(e,t){const[n,r]=N.useState({data:null,lastUpdated:null,stale:!1,error:null}),a=N.useRef(null);return N.useEffect(()=>{let s=null,o=!0;function c(){s=new EventSource(e),s.addEventListener(t,d=>{if(!o)return;const p=d;try{const m=JSON.parse(p.data);r({data:m.data,lastUpdated:m.timestamp,stale:!1,error:null})}catch{}}),s.onerror=()=>{o&&(s==null||s.close(),r(d=>({...d,stale:!0,error:"Connection lost. Reconnecting…"})),a.current=setTimeout(c,M8))}}return c(),()=>{o=!1,s==null||s.close(),a.current&&clearTimeout(a.current)}},[e,t]),n}const F8={default:"text-white",green:"text-emerald-400",yellow:"text-yellow-400",red:"text-red-400"};function Ze({label:e,value:t,sub:n,accent:r="default"}){return u.jsxs("div",{className:"rounded-lg border border-neutral-border bg-neutral-surface p-5",children:[u.jsx("p",{className:"text-xs font-medium uppercase tracking-widest text-neutral-muted",children:e}),u.jsx("p",{className:["mt-2 text-3xl font-bold tabular-nums",F8[r]].join(" "),children:t}),n&&u.jsx("p",{className:"mt-1 text-xs text-neutral-muted",children:n})]})}function iv({lastUpdated:e,stale:t,error:n}){const r=e?new Date(e).toLocaleTimeString():null;return t||n?u.jsxs("div",{className:"flex items-center gap-2 text-xs text-secondary-400",children:[u.jsx("span",{className:"inline-block h-2 w-2 animate-pulse rounded-full bg-secondary-400"}),u.jsx("span",{children:n??"Stale data"}),r&&u.jsxs("span",{className:"text-neutral-muted",children:["· last updated ",r]})]}):u.jsxs("div",{className:"flex items-center gap-2 text-xs text-neutral-muted",children:[u.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-secondary-400"}),u.jsxs("span",{children:["Live",r?` · updated ${r}`:""]})]})}function ZC(e){const[t,n]=N.useState("idle"),[r,a]=N.useState(null),[s,o]=N.useState(null),c=N.useCallback(async d=>{n("loading"),o(null);try{const p=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},...d!==void 0?{body:JSON.stringify(d)}:{}}),m=await p.json();!p.ok||m&&typeof m=="object"&&"error"in m&&m.error?(n("error"),o(m.error??`HTTP ${p.status}`)):(n("success"),a(m))}catch(p){n("error"),o(p instanceof Error?p.message:"Network error")}},[e]);return{state:t,data:r,error:s,run:c}}function P8({url:e,label:t,body:n,loadingLabel:r,onSuccess:a,className:s=""}){const{state:o,error:c,run:d}=ZC(e),p=N.useRef(null),m=sc(0),h=sc(0),b={damping:15,stiffness:150},y=oc(m,b),v=oc(h,b);N.useEffect(()=>{o==="success"&&(a==null||a())},[o,a]);const k=_=>{if(!p.current)return;const{left:j,top:D,width:R,height:P}=p.current.getBoundingClientRect(),B=_.clientX-(j+R/2),O=_.clientY-(D+P/2);m.set(B*.3),h.set(O*.3)},w=()=>{m.set(0),h.set(0)},E=o==="loading",T=o==="success",A=o==="error";return u.jsxs("div",{className:`inline-flex flex-col items-center gap-2 ${s}`,children:[u.jsxs(J.button,{ref:p,style:{x:y,y:v},onMouseMove:k,onMouseLeave:w,whileTap:{scale:.95},onClick:()=>void d(n),disabled:E,className:["group relative flex items-center gap-2 overflow-hidden rounded-xl border px-5 py-2.5 text-xs font-bold uppercase tracking-wider transition-all duration-300 shadow-lg",E?"cursor-not-allowed border-neutral-border bg-neutral-surface/50 text-neutral-muted":"",T?"border-emerald-500/50 bg-emerald-500/10 text-emerald-400 shadow-emerald-500/20":"",A?"border-red-500/50 bg-red-500/10 text-red-400 shadow-red-500/20":"",!E&&!T&&!A?"border-primary-500/50 bg-primary-500/10 text-primary-500 hover:bg-primary-500 hover:text-white shadow-primary-500/20":""].filter(Boolean).join(" "),children:[!E&&!T&&u.jsx(J.div,{initial:{left:"-100%"},animate:{left:"100%"},transition:{duration:3,repeat:1/0,ease:"linear"},className:"absolute top-0 bottom-0 w-1/2 bg-gradient-to-r from-transparent via-white/5 to-transparent pointer-events-none"}),u.jsxs(dn,{mode:"wait",children:[E&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(_c,{className:"h-3.5 w-3.5 animate-spin"})},"loading"),T&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(Nh,{className:"h-3.5 w-3.5"})},"success"),A&&u.jsx(J.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},children:u.jsx(CI,{className:"h-3.5 w-3.5"})},"error")]}),u.jsx("span",{className:"relative z-10",children:E?r??"Syncing...":T?"Verified":t}),u.jsx("div",{className:"absolute inset-0 z-0 bg-gradient-to-r from-transparent via-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"})]}),A&&c&&u.jsx(J.p,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-[10px] font-mono font-bold text-red-400 uppercase tracking-tighter",children:c})]})}const bc="/api/sse";function B8(e){return typeof e=="object"&&e!==null&&"totalFeatures"in e}function U8(e){return typeof e=="object"&&e!==null&&"totalIssues"in e}function $8(e){return typeof e=="object"&&e!==null&&"available"in e&&e.available===!0}function z8(e){return typeof e=="object"&&e!==null&&"findings"in e&&"stats"in e}function G8(e){return typeof e=="object"&&e!==null&&"violations"in e&&"stats"in e}function H8(e){return typeof e=="object"&&e!==null&&"passed"in e&&"totalViolations"in e}function V8(e){return typeof e=="object"&&e!==null&&"sourceNodeId"in e&&"layers"in e}const sv=N.memo(function({title:t,count:n,children:r}){const[a,s]=N.useState(!1);return u.jsxs("div",{className:"space-y-2",children:[u.jsxs("button",{onClick:()=>s(!a),className:"flex items-center gap-2 text-left transition-opacity hover:opacity-80","aria-expanded":a,children:[u.jsx("span",{className:"text-[10px] text-gray-600",children:a?"▼":"▶"}),u.jsxs("p",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-gray-500",children:[t," (",n,")"]})]}),a&&r]})});function QC({command:e}){const t=Ln();return u.jsx("button",{onClick:()=>{const n=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:e});t(`/t/${n.id}`)},className:"rounded bg-primary-500/10 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-primary-400 border border-primary-500/20 hover:bg-primary-500 hover:text-white transition-all",children:"Fix It"})}const W8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Errors",value:t.stats.errorCount,accent:t.stats.errorCount>0?"red":"green"}),u.jsx(Ze,{label:"Warnings",value:t.stats.warningCount,accent:t.stats.warningCount>0?"yellow":"default"}),u.jsx(Ze,{label:"Info",value:t.stats.infoCount}),u.jsx(Ze,{label:"Files Scanned",value:t.stats.filesScanned})]}),t.findings.length>0&&u.jsx(sv,{title:"Top Findings",count:t.findings.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.findings.slice(0,10).map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":n.severity==="warning"?"text-yellow-400":"text-gray-400",children:["[",n.severity,"]"]}),u.jsxs("span",{className:"text-gray-300",children:[n.file,":",n.line]}),u.jsx("span",{className:"text-gray-500",children:n.message})]},r))})})]})}),q8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Violations",value:t.stats.violationCount,accent:t.stats.violationCount>0?"red":"green"}),u.jsx(Ze,{label:"Files Analyzed",value:t.stats.filesAnalyzed}),u.jsx(Ze,{label:"Status",value:t.valid?"OK":"Failing",accent:t.valid?"green":"red"})]}),t.violations.length>0&&u.jsx(sv,{title:"Violations",count:t.violations.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.violations.map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":"text-yellow-400",children:["[",n.severity,"]"]}),u.jsx("span",{className:"text-gray-300",children:n.file}),u.jsxs("span",{className:"text-gray-500",children:[n.metric,": ",n.value," (threshold: ",n.threshold,")"]})]},r))})})]})}),Y8=N.memo(function({data:t}){return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Status",value:t.passed?"Passed":"Failed",accent:t.passed?"green":"red"}),u.jsx(Ze,{label:"Violations",value:t.totalViolations,accent:t.totalViolations>0?"red":"default"}),u.jsx(Ze,{label:"Regressions",value:t.regressions.length,accent:t.regressions.length>0?"yellow":"default"})]}),t.newViolations.length>0&&u.jsx(sv,{title:"New Violations",count:t.newViolations.length,children:u.jsx("div",{className:"space-y-2 rounded-lg border border-gray-800 bg-gray-900 p-4",children:t.newViolations.map((n,r)=>u.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[u.jsxs("span",{className:n.severity==="error"?"text-red-400":"text-yellow-400",children:["[",n.severity,"]"]}),u.jsx("span",{className:"text-gray-300",children:n.file}),u.jsx("span",{className:"text-gray-500",children:n.detail})]},r))})})]})});function K8({healthData:e}){return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Entropy Analysis"}),e.totalIssues>0&&u.jsx(QC,{command:"harness:validate"})]}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Total Issues",value:e.totalIssues,accent:e.totalIssues>0?"yellow":"green"}),u.jsx(Ze,{label:"Errors",value:e.errors,accent:e.errors>0?"red":"default"}),u.jsx(Ze,{label:"Warnings",value:e.warnings,accent:e.warnings>0?"yellow":"default"}),u.jsx(Ze,{label:"Auto-fixable",value:e.fixableCount,accent:"default"})]})]})}function X8({healthData:e}){return u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Scan Details"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Suggestions",value:e.suggestionCount}),u.jsx(Ze,{label:"Scan Duration",value:`${e.durationMs} ms`}),u.jsx(Ze,{label:"Analysis Errors",value:e.analysisErrors.length,accent:e.analysisErrors.length>0?"red":"default"})]})]})}function Z8({healthData:e}){return e.analysisErrors.length===0?null:u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Analysis Errors"}),u.jsx("div",{className:"space-y-2 rounded-lg border border-red-900 bg-gray-900 p-4",children:e.analysisErrors.map((t,n)=>u.jsx("p",{className:"text-xs text-red-400",children:t},n))})]})}function Bf({title:e,raw:t,guard:n,Section:r,fixCommand:a}){const s=t,o=typeof s=="object"&&s!==null&&"stats"in s?s.stats:void 0,d=n(t)&&(o!=null&&(o.errorCount??0)+(o.warningCount??0)>0||s!=null&&"totalViolations"in s&&s.totalViolations>0||o!=null&&(o.violationCount??0)>0)&&a?u.jsx(QC,{command:a}):void 0;return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex w-full items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:e}),d]}),t==null?u.jsx("p",{className:"text-sm text-gray-500",children:"Awaiting first scan..."}):n(t)?u.jsx(r,{data:t}):u.jsx("p",{className:"text-sm text-red-400",children:"error"in t?String(t.error):"Unavailable"})]})}function Q8({health:e}){const t="error"in e?String(e.error):"Unavailable";return u.jsx("p",{className:"text-sm text-red-400",children:t})}function J8({healthData:e,security:t,perf:n,arch:r}){return u.jsxs("div",{className:"space-y-8",children:[u.jsx(K8,{healthData:e}),u.jsx(X8,{healthData:e}),u.jsx(Z8,{healthData:e}),u.jsx(Bf,{title:"Security",raw:t,guard:z8,Section:W8,fixCommand:"harness:security-scan"}),u.jsx(Bf,{title:"Performance",raw:n,guard:G8,Section:q8,fixCommand:"harness:perf"}),u.jsx(Bf,{title:"Architecture",raw:r,guard:H8,Section:Y8,fixCommand:"harness:enforce-architecture"})]})}function eW(e){const t=e?e.health:null,n=t&&U8(t)?t:null;return{health:t,healthData:n}}function tW(e){return{security:(e==null?void 0:e.security)??null,perf:(e==null?void 0:e.perf)??null,arch:(e==null?void 0:e.arch)??null}}const nW=["validate","check-deps","check-arch","check-perf","check-security","check-docs","phase-gate"];function rW(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}const aW=N.memo(function({name:t,result:n,expanded:r,onToggle:a}){if(!n)return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-4",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"inline-block h-3 w-3 rounded-full bg-gray-600"}),u.jsx("span",{className:"text-sm font-medium text-gray-400",children:t})]}),u.jsx("p",{className:"mt-1 text-xs text-gray-600",children:"Not yet run"})]});const s=n.passed?"border-emerald-800":"border-red-800",o=n.passed?"bg-emerald-400":"bg-red-400",c=n.passed?"text-emerald-400":"text-red-400";return u.jsxs("div",{className:`rounded-lg border ${s} bg-gray-900`,children:[u.jsxs("button",{onClick:a,className:"w-full p-4 text-left","aria-expanded":r,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-block h-3 w-3 rounded-full ${o}`}),u.jsx("span",{className:"text-sm font-medium text-gray-200",children:t})]}),u.jsx("span",{className:`text-xs font-medium ${c}`,children:n.passed?"PASS":"FAIL"})]}),!r&&(n.errorCount>0||n.warningCount>0)&&u.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[n.errorCount>0&&`${n.errorCount} errors`,n.errorCount>0&&n.warningCount>0&&", ",n.warningCount>0&&`${n.warningCount} warnings`]})]}),r&&u.jsx("div",{className:"border-t border-gray-800 px-4 py-3",children:u.jsxs("div",{className:"space-y-1 text-xs",children:[u.jsxs("p",{className:"text-gray-400",children:["Errors:"," ",u.jsx("span",{className:n.errorCount>0?"text-red-400":"text-gray-300",children:n.errorCount})," | ","Warnings:"," ",u.jsx("span",{className:n.warningCount>0?"text-yellow-400":"text-gray-300",children:n.warningCount})]}),n.details&&u.jsx("p",{className:"text-gray-500",children:n.details})]})})]})});function iW(e){const t=new Map;if(!e)return t;for(const n of e.checks)t.set(n.name,n);return t}async function sW(e,t,n){try{const r=await fetch("/api/ci");if(!r.ok){t(`HTTP ${r.status}`);return}const a=await r.json();e(a.data),t(null)}catch(r){t(r instanceof Error?r.message:"Network error")}finally{n(!1)}}function oW(){const[e,t]=N.useState(null),[n,r]=N.useState(!0),[a,s]=N.useState(null),[o,c]=N.useState(new Set),d=N.useCallback(()=>{sW(t,s,r)},[]);N.useEffect(()=>{d()},[d]);const p=h=>{c(b=>{const y=new Set(b);return y.has(h)?y.delete(h):y.add(h),y})},m=N.useMemo(()=>iW(e),[e]);return u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"CI Checks"}),u.jsxs("div",{className:"flex items-center gap-4",children:[u.jsx(P8,{url:"/api/actions/refresh-checks",label:"Run All Checks",loadingLabel:"Running checks...",onSuccess:d}),(e==null?void 0:e.lastRun)&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Last checked ",rW(e.lastRun)]})]})]}),n&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading check results..."}),a&&u.jsx("p",{className:"text-sm text-red-400",children:a}),u.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:nW.map(h=>u.jsx(aW,{name:h,result:m.get(h),expanded:o.has(h),onToggle:()=>p(h)},h))})]})}function lW(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),{data:a}=gc(bc,"checks"),{health:s,healthData:o}=eW(e),{security:c,perf:d,arch:p}=tW(a);return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Health"}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]}),u.jsxs("div",{className:"space-y-8",children:[u.jsx(oW,{}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream..."}),s&&!o&&u.jsx(Q8,{health:s}),o&&u.jsx(J8,{healthData:o,security:c,perf:d,arch:p})]})]})}function uW({reason:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsx("p",{className:"text-base font-medium text-gray-300",children:"Graph not connected"}),e&&u.jsx("p",{className:"mt-2 text-sm text-gray-500",children:e}),u.jsxs("div",{className:"mt-4 rounded border border-gray-700 bg-gray-950 p-4",children:[u.jsx("p",{className:"text-xs font-semibold text-gray-400",children:"To connect the graph:"}),u.jsxs("ol",{className:"mt-2 list-decimal list-inside space-y-1 text-xs text-gray-500",children:[u.jsxs("li",{children:["Run ",u.jsx("code",{className:"text-gray-300",children:"harness ingest"})," to build the knowledge graph"]}),u.jsx("li",{children:"Ensure the graph database is available in your project"}),u.jsx("li",{children:"Restart the dashboard to reconnect"})]})]})]})}const cW=N.memo(function({type:t,count:n,pct:r}){return u.jsxs("tr",{className:"hover:bg-gray-900",children:[u.jsx("td",{className:"px-4 py-2.5 text-gray-300",children:t}),u.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-gray-400",children:n}),u.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums text-gray-500",children:[r,"%"]})]})}),dW=N.memo(function({nodesByType:t,nodeCount:n}){const r=N.useMemo(()=>[...t].sort((a,s)=>s.count-a.count),[t]);return t.length===0?null:u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Node Type Breakdown"}),u.jsx("div",{className:"overflow-hidden rounded-lg border border-gray-800",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"bg-gray-900 text-xs uppercase tracking-wider text-gray-500",children:u.jsxs("tr",{children:[u.jsx("th",{className:"px-4 py-3 text-left",children:"Type"}),u.jsx("th",{className:"px-4 py-3 text-right",children:"Count"}),u.jsx("th",{className:"px-4 py-3 text-right",children:"%"})]})}),u.jsx("tbody",{className:"divide-y divide-gray-800 bg-gray-950",children:r.map(a=>{const s=n>0?(a.count/n*100).toFixed(1):"0";return u.jsx(cW,{type:a.type,count:a.count,pct:s},a.type)})})]})})]})}),pW=N.memo(function({graphData:t}){return u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Graph Metrics"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Nodes",value:t.nodeCount}),u.jsx(Ze,{label:"Edges",value:t.edgeCount}),u.jsx(Ze,{label:"Node Types",value:t.nodesByType.length})]})]}),u.jsx(dW,{nodesByType:t.nodesByType,nodeCount:t.nodeCount})]})});function fW(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),a=e?e.graph:null,s=a&&$8(a)?a:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Knowledge Graph"}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream…"}),a&&!s&&u.jsx(uW,{reason:a.available?void 0:a.reason}),s&&u.jsx(pW,{graphData:s})]})}const ba=130,Ya=30,JC=180,mW=44,Ja={top:40,right:24,bottom:24,left:24},yc=Ja.left,Ku={high:"#ef4444",medium:"#f59e0b",low:"#71717a"};function hW(e){return e>.7?"high":e>=.3?"medium":"low"}function uT(e){return Math.max(.15,Math.min(1,e))}function gW(e){if(e.layers.length===0)return null;const t=[],n=[],r={nodeId:e.sourceNodeId,name:e.sourceName,type:"source",probability:1,parentId:"",risk:"high",x:yc,y:Ja.top};t.push(r);for(const o of e.layers){const c=yc+o.depth*JC;o.nodes.forEach((d,p)=>{const m={nodeId:d.nodeId,name:d.name,type:d.type,probability:d.probability,parentId:d.parentId,risk:hW(d.probability),x:c,y:Ja.top+p*mW};t.push(m),n.push({fromId:d.parentId,toId:d.nodeId})})}const a=Math.max(...t.map(o=>o.x+ba))+Ja.right,s=Math.max(...t.map(o=>o.y+Ya))+Ja.bottom;return{nodes:t,sourceNode:r,edges:n,width:a,height:s}}function bW({data:e}){const{summary:t}=e,n=[{label:"Total Affected",count:t.totalAffected,color:"#fafafa"},{label:"High Risk",count:t.highRisk,color:Ku.high},{label:"Medium Risk",count:t.mediumRisk,color:Ku.medium},{label:"Low Risk",count:t.lowRisk,color:Ku.low}];return u.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-4",children:[n.map(r=>u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{background:r.color}}),u.jsx("span",{className:"text-sm tabular-nums text-neutral-text",children:r.count}),u.jsx("span",{className:"text-xs text-neutral-muted",children:r.label})]},r.label)),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"text-xs text-neutral-muted",children:"Max Depth:"}),u.jsx("span",{className:"text-sm tabular-nums text-neutral-text",children:t.maxDepth})]})]})}function yW({data:e}){const t=gW(e),[n,r]=N.useState(null);if(!t)return u.jsx(J.div,{initial:{opacity:0},animate:{opacity:1},className:"flex h-32 items-center justify-center rounded-2xl border border-neutral-border bg-neutral-bg/50 backdrop-blur-sm",children:u.jsx("p",{className:"text-sm text-neutral-muted",children:"No affected nodes detected"})});const a=new Map(t.nodes.map(o=>[o.nodeId,o])),s=e.layers.map(o=>o.depth);return u.jsxs("div",{className:"relative group",children:[u.jsx(bW,{data:e}),u.jsx("div",{className:"overflow-x-auto rounded-2xl border border-neutral-border bg-neutral-bg/30 p-6 backdrop-blur-md",children:u.jsxs("svg",{width:t.width,height:t.height,className:"overflow-visible",children:[u.jsxs("defs",{children:[u.jsxs("filter",{id:"neon-glow",x:"-20%",y:"-20%",width:"140%",height:"140%",children:[u.jsx("feGaussianBlur",{stdDeviation:"2",result:"blur"}),u.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]}),u.jsx("marker",{id:"blast-arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:u.jsx("path",{d:"M0,0 L0,6 L8,3 z",fill:"#4f46e5"})})]}),u.jsx(J.text,{initial:{opacity:0},animate:{opacity:1},x:yc+ba/2,y:Ja.top-14,textAnchor:"middle",className:"text-[10px] font-bold uppercase tracking-widest fill-neutral-muted",children:"Origin"}),s.map(o=>{const c=yc+o*JC;return u.jsxs(J.text,{initial:{opacity:0},animate:{opacity:1},transition:{delay:o*.1},x:c+ba/2,y:Ja.top-14,textAnchor:"middle",className:"text-[10px] font-bold uppercase tracking-widest fill-neutral-muted",children:["Layer ",o]},o)}),t.edges.map((o,c)=>{const d=a.get(o.fromId),p=a.get(o.toId);if(!d||!p)return null;const m=d.x+ba,h=d.y+Ya/2,b=p.x,y=p.y+Ya/2,v=n===o.fromId||n===o.toId;return u.jsx(J.line,{initial:{pathLength:0,opacity:0},animate:{pathLength:1,opacity:v?1:uT(p.probability),stroke:v?"var(--color-primary-500)":"rgba(79, 70, 229, 0.2)",strokeWidth:v?2:1.5},transition:{duration:.4},x1:m,y1:h,x2:b-4,y2:y,markerEnd:"url(#blast-arrow)"},`${o.fromId}-${o.toId}`)}),t.nodes.map((o,c)=>u.jsxs(J.g,{initial:{opacity:0,scale:.9,x:o.x-10},animate:{opacity:n&&n!==o.nodeId?.3:uT(o.probability),scale:n===o.nodeId?1.05:1,x:o.x},onMouseEnter:()=>r(o.nodeId),onMouseLeave:()=>r(null),transition:{duration:.2},className:"cursor-pointer",children:[u.jsx("rect",{x:0,y:o.y,width:ba,height:Ya,rx:8,className:"fill-neutral-surface/80 stroke-neutral-border",strokeWidth:1}),u.jsx(J.rect,{x:0,y:o.y,width:ba,height:Ya,rx:8,className:"fill-none",stroke:Ku[o.risk],strokeWidth:1.5,initial:{pathLength:0},animate:{pathLength:1},transition:{duration:1,delay:c*.05}}),u.jsx("text",{x:ba/2,y:o.y+Ya/2,dominantBaseline:"middle",textAnchor:"middle",className:"text-[10px] font-bold tracking-tight fill-neutral-text pointer-events-none",children:o.name.length>16?o.name.slice(0,15)+"…":o.name}),u.jsx("text",{x:ba-6,y:o.y+Ya-6,textAnchor:"end",className:"text-[8px] font-mono fill-neutral-muted pointer-events-none",children:o.type==="source"?"SRC":`${(o.probability*100).toFixed(0)}%`})]},o.nodeId))]})})]})}const xW=[1,2,3,4,5],vW=3,SW=N.memo(function({loading:t,fetchError:n,anomalies:r,sortedAPs:a,sortedOutliers:s,selectedNodeId:o,onAnomalyClick:c}){return u.jsxs("div",{className:"lg:col-span-1",children:[t&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading anomalies..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),r&&a.length===0&&s.length===0&&u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsx("p",{className:"text-base font-medium text-gray-300",children:"No anomalies detected"}),u.jsx("p",{className:"mt-2 text-sm text-gray-500",children:'Run "harness scan" to build the knowledge graph, then restart the dashboard.'})]}),a.length>0&&u.jsxs("section",{className:"mb-6",children:[u.jsx("h2",{className:"mb-2 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Articulation Points"}),u.jsx("div",{className:"space-y-1",children:a.map(d=>u.jsxs("button",{onClick:()=>c(d.nodeId),className:["w-full rounded border px-3 py-2 text-left text-sm transition-colors",o===d.nodeId?"border-blue-700 bg-blue-950":"border-gray-800 bg-gray-900 hover:bg-gray-800"].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"truncate font-medium text-gray-200",children:d.name}),u.jsxs("span",{className:"ml-2 text-xs tabular-nums text-gray-500",children:[d.dependentCount," deps"]})]}),u.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:[d.componentsIfRemoved," components if removed"]})]},d.nodeId))})]}),s.length>0&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-2 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Statistical Outliers"}),u.jsx("div",{className:"space-y-1",children:s.map(d=>u.jsxs("button",{onClick:()=>c(d.nodeId),className:["w-full rounded border px-3 py-2 text-left text-sm transition-colors",o===d.nodeId?"border-blue-700 bg-blue-950":"border-gray-800 bg-gray-900 hover:bg-gray-800"].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"truncate font-medium text-gray-200",children:d.name}),u.jsxs("span",{className:"ml-2 text-xs tabular-nums text-gray-500",children:["z=",d.zScore.toFixed(1)]})]}),u.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:[d.metric,": ",d.value," (",d.type,")"]})]},d.nodeId))})]})]})}),EW=N.memo(function({selectedNodeId:t,blastRadiusState:n,blastRadiusError:r,brData:a,brIsData:s}){const o=s?a:null;return u.jsxs("div",{className:"lg:col-span-2",children:[!t&&n==="idle"&&u.jsx("div",{className:"flex h-64 items-center justify-center rounded-lg border border-gray-800 bg-gray-900",children:u.jsx("p",{className:"text-sm text-gray-500",children:"Select a node or search to view blast radius"})}),n==="loading"&&u.jsx("div",{className:"flex h-64 items-center justify-center rounded-lg border border-gray-800 bg-gray-900",children:u.jsx("p",{className:"text-sm text-gray-500",children:"Computing blast radius..."})}),n==="error"&&r&&u.jsx("div",{className:"rounded-lg border border-red-800 bg-gray-900 p-6",children:u.jsx("p",{className:"text-sm text-red-400",children:r})}),n==="success"&&a&&!s&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:u.jsx("p",{className:"text-sm text-gray-400",children:"error"in a?a.error:"No blast radius data"})}),n==="success"&&o&&u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6",children:[u.jsxs("h3",{className:"mb-3 text-sm font-semibold text-gray-200",children:["Blast Radius: ",o.sourceName]}),u.jsx(yW,{data:o})]})]})}),wW=N.memo(function({searchText:t,depth:n,onSearchTextChange:r,onDepthChange:a,onSubmit:s}){return u.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[u.jsxs("form",{onSubmit:s,className:"flex flex-1 gap-2",children:[u.jsx("input",{type:"text",value:t,onChange:o=>r(o.target.value),placeholder:"Search node by name or path...",className:"flex-1 rounded border border-gray-700 bg-gray-900 px-3 py-1.5 text-sm text-gray-200 placeholder-gray-500 focus:border-gray-500 focus:outline-none"}),u.jsx("button",{type:"submit",className:"rounded bg-gray-800 px-3 py-1.5 text-xs font-medium text-gray-200 hover:bg-gray-700",children:"Search"})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-400",children:["Depth",u.jsx("select",{value:n,onChange:o=>a(Number(o.target.value)),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1.5 text-sm text-gray-200",children:xW.map(o=>u.jsx("option",{value:o,children:o},o))})]})]})});function kW(){const[e,t]=N.useState(null),[n,r]=N.useState(!0),[a,s]=N.useState(null),o=N.useCallback(async()=>{try{const c=await fetch("/api/impact/anomalies");if(!c.ok){s(`HTTP ${c.status}`);return}const d=await c.json();t(d.data),s(null)}catch(c){s(c instanceof Error?c.message:"Network error")}finally{r(!1)}},[]);return N.useEffect(()=>{o()},[o]),{anomalies:e,loading:n,fetchError:a}}function NW(e){const t=e?[...e.articulationPoints].sort((r,a)=>a.dependentCount-r.dependentCount):[],n=e?[...e.outliers].sort((r,a)=>a.zScore-r.zScore):[];return{sortedAPs:t,sortedOutliers:n}}function TW(){var E;const{anomalies:e,loading:t,fetchError:n}=kW(),[r,a]=N.useState(null),[s,o]=N.useState(""),[c,d]=N.useState(vW),p=ZC("/api/impact/blast-radius"),m=N.useCallback(T=>{a(T),p.run({nodeId:T,maxDepth:c})},[p,c]),h=N.useCallback(T=>{T.preventDefault();const A=s.trim();A&&m(A)},[s,m]),b=N.useCallback(T=>{o(""),m(T)},[m]),{sortedAPs:y,sortedOutliers:v}=N.useMemo(()=>NW(e),[e]),k=(E=p.data)==null?void 0:E.data,w=!!k&&V8(k);return{anomalies:e,loading:t,fetchError:n,selectedNodeId:r,searchText:s,depth:c,setSearchText:o,setDepth:d,handleSearch:h,handleAnomalyClick:b,sortedAPs:y,sortedOutliers:v,blastRadius:p,brData:k,brIsData:w}}function AW(){const{anomalies:e,loading:t,fetchError:n,selectedNodeId:r,searchText:a,depth:s,setSearchText:o,setDepth:c,handleSearch:d,handleAnomalyClick:p,sortedAPs:m,sortedOutliers:h,blastRadius:b,brData:y,brIsData:v}=TW();return u.jsxs("div",{children:[u.jsx("h1",{className:"mb-6 text-2xl font-bold",children:"Impact Explorer"}),u.jsx(wW,{searchText:a,depth:s,onSearchTextChange:o,onDepthChange:c,onSubmit:d}),u.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[u.jsx(SW,{loading:t,fetchError:n,anomalies:e,sortedAPs:m,sortedOutliers:h,selectedNodeId:r,onAnomalyClick:p}),u.jsx(EW,{selectedNodeId:r,blastRadiusState:b.state,blastRadiusError:b.error,brData:y,brIsData:v})]})]})}function eR(e){return e==="improving"?"Improving":e==="declining"?"Degrading":"Stable"}function Uf(e){return e==="improving"?"green":e==="declining"?"red":"yellow"}function IW(e){return e==="improving"?"text-emerald-400":e==="declining"?"text-red-400":"text-yellow-400"}function CW(e){return e==="improving"?"↓":e==="declining"?"↑":"→"}function tR(e){return e===0?"0":`${e>0?"+":""}${e.toFixed(1)}`}function RW(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const _W=N.memo(function({name:t,trend:n}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:RW(t)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200",children:n.current.toFixed(1)}),u.jsxs("td",{className:`py-2 px-3 text-right tabular-nums ${IW(n.direction)}`,children:[CW(n.direction)," ",eR(n.direction)]}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:tR(n.delta)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-500",children:n.previous.toFixed(1)})]})});function OW({categories:e}){const t=N.useMemo(()=>Object.entries(e).sort((n,r)=>Math.abs(r[1].delta)-Math.abs(n[1].delta)),[e]);return t.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No category data yet. Capture architecture snapshots to see trends."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Category"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Current"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Trend"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Delta"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Previous"})]})}),u.jsx("tbody",{children:t.map(([n,r])=>u.jsx(_W,{name:n,trend:r},n))})]})})}async function LW(){const e=await fetch("/api/decay-trends");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function DW(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),o=N.useCallback(async()=>{try{const d=await LW();t(d),r(null)}catch(d){r(d instanceof Error?d.message:"Network error")}finally{s(!1)}},[]);N.useEffect(()=>{o()},[o]);const c=e&&e.snapshotCount===0;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Decay Trends"}),e&&e.to&&u.jsxs("span",{className:"text-xs text-gray-500",children:[e.snapshotCount," snapshot",e.snapshotCount!==1?"s":""," analyzed",e.from&&` from ${e.from.slice(0,10)} to ${e.to.slice(0,10)}`]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading decay trends..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),c&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsxs("p",{className:"text-sm text-gray-500",children:["No architecture snapshots found. Run"," ",u.jsx("code",{className:"text-gray-400",children:"harness snapshot capture"})," to create the first snapshot."]})}),e&&!c&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Overview"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Stability Score",value:e.stability.current,sub:"0-100 (higher is healthier)",accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Trend Direction",value:eR(e.stability.direction),accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Score Delta",value:tR(e.stability.delta),sub:`Previous: ${e.stability.previous}`,accent:Uf(e.stability.direction)}),u.jsx(Ze,{label:"Snapshots",value:e.snapshotCount})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Category Breakdown"}),u.jsx(OW,{categories:e.categories})]})]})]})}function jW(e){switch(e){case"full":return"Covered";case"code-only":return"Partial (code)";case"test-only":return"Partial (test)";case"none":return"Uncovered"}}function MW(e){switch(e){case"full":return"text-emerald-400";case"code-only":case"test-only":return"text-yellow-400";case"none":return"text-red-400"}}function FW(e){switch(e){case"full":return"bg-emerald-400";case"code-only":case"test-only":return"bg-yellow-400";case"none":return"bg-red-400"}}function _u(e){return e>=80?"green":e>=50?"yellow":"red"}const PW=N.memo(function({req:t}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsxs("td",{className:"py-2 px-3",children:[u.jsx("div",{className:"font-mono text-xs text-gray-200",children:t.requirementName||t.requirementId}),t.featureName&&u.jsx("div",{className:"text-[10px] text-gray-500 mt-0.5",children:t.featureName})]}),u.jsx("td",{className:"py-2 px-3",children:u.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[u.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${FW(t.status)}`}),u.jsx("span",{className:`text-xs font-medium ${MW(t.status)}`,children:jW(t.status)})]})}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200 text-sm",children:t.codeFileCount}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200 text-sm",children:t.testFileCount})]})});function BW({requirements:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsxs("p",{className:"text-sm text-gray-500",children:["No requirements found in graph. Run"," ",u.jsx("code",{className:"rounded bg-gray-800 px-1 py-0.5 text-xs font-mono text-gray-300",children:"harness scan"})," ","to ingest spec requirements."]})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Requirement"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Implementations"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Tests"})]})}),u.jsx("tbody",{children:e.map(t=>u.jsx(PW,{req:t},t.requirementId))})]})})}async function UW(){const e=await fetch("/api/traceability");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function $W(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),[o,c]=N.useState(!1),d=N.useCallback(async()=>{try{const b=await UW();b===null?c(!0):t(b),r(null)}catch(b){r(b instanceof Error?b.message:"Network error")}finally{s(!1)}},[]);N.useEffect(()=>{d()},[d]);const p=e?e.totals.fullyTraced:0,m=e?e.totals.withCode+e.totals.withTests-2*e.totals.fullyTraced:0,h=e?e.totals.untraceable:0;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Traceability"}),e&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Generated ",new Date(e.generatedAt).toLocaleString()]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading traceability data..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),o&&!a&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-8 text-center",children:u.jsxs("p",{className:"text-sm text-gray-400",children:["No traceability data available. Run"," ",u.jsx("code",{className:"rounded bg-gray-800 px-1.5 py-0.5 text-xs font-mono text-gray-300",children:"harness scan"})," ","to build the knowledge graph with requirement nodes from spec files."]})}),e&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Coverage Summary"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[u.jsx(Ze,{label:"Total Requirements",value:e.totals.total}),u.jsx(Ze,{label:"Covered",value:p,accent:"green",sub:`${e.overallCoverage}% coverage`}),u.jsx(Ze,{label:"Partial",value:m>0?m:e.totals.total-p-h,accent:"yellow"}),u.jsx(Ze,{label:"Uncovered",value:h,accent:h>0?"red":"green"})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Overall Coverage"}),u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsx("span",{className:"text-sm text-gray-400",children:"Fully traced"}),u.jsxs("span",{className:`text-sm font-bold ${_u(e.overallCoverage)==="green"?"text-emerald-400":_u(e.overallCoverage)==="yellow"?"text-yellow-400":"text-red-400"}`,children:[e.overallCoverage,"%"]})]}),u.jsx("div",{className:"h-2 rounded-full bg-gray-800 overflow-hidden",children:u.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${_u(e.overallCoverage)==="green"?"bg-emerald-500":_u(e.overallCoverage)==="yellow"?"bg-yellow-500":"bg-red-500"}`,style:{width:`${e.overallCoverage}%`}})})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Requirements"}),u.jsx(BW,{requirements:e.requirements})]})]})]})}function zW(){const[e,t]=N.useState([]),[n,r]=N.useState(!0),[a,s]=N.useState(null);return N.useEffect(()=>{let o=!1;async function c(){try{const p=await fetch("/api/streams");if(!p.ok)throw new Error(`Failed to fetch sessions: ${p.status}`);const m=await p.json();o||(t(m),s(null))}catch(p){o||s(p instanceof Error?p.message:"Failed to load sessions")}finally{o||r(!1)}}c();const d=setInterval(()=>void c(),3e4);return()=>{o=!0,clearInterval(d)}},[]),{sessions:e,loading:n,error:a}}function GW(e){if(!e)return"never";const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function cT({status:e}){const t=e.detected.length>0?e.detected.join(", "):"none detected";return u.jsx("div",{role:"alert",className:"mb-6 rounded-lg border border-red-900/60 bg-red-950/40 px-4 py-3 text-sm",children:u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("span",{className:"mt-0.5 inline-block h-2.5 w-2.5 flex-shrink-0 rounded-full bg-red-500"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("p",{className:"font-semibold text-red-300",children:"Local model unavailable"}),u.jsxs("p",{className:"mt-1 font-mono text-xs text-red-300/80",children:[e.backendName," — ",e.endpoint]}),u.jsx("p",{className:"mt-1 text-red-200",children:"No configured candidate is currently loaded on the local server. The intelligence pipeline and local agent dispatch are disabled until a candidate is loaded."}),u.jsxs("dl",{className:"mt-2 grid grid-cols-1 gap-x-6 gap-y-1 text-xs text-red-200 sm:grid-cols-2",children:[u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Configured:"}),u.jsx("dd",{className:"font-mono",children:e.configured.join(", ")||"(none)"})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Detected:"}),u.jsx("dd",{className:"font-mono",children:t})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Last probe:"}),u.jsx("dd",{className:"font-mono",children:GW(e.lastProbeAt)})]}),e.lastError&&u.jsxs("div",{className:"flex gap-2",children:[u.jsx("dt",{className:"text-red-400",children:"Last error:"}),u.jsx("dd",{className:"font-mono",children:e.lastError})]})]})]})]})})}function Gr({title:e}){return u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:e})}function or(e){return e.toLocaleString()}function HW(e){const t=nR(),n=Math.max(0,Math.floor((t-new Date(e).getTime())/1e3));if(n<60)return`${n}s`;const r=Math.floor(n/60),a=n%60;return r<60?`${r}m ${a}s`:`${Math.floor(r/60)}h ${r%60}m`}function nR(){const[e,t]=N.useState(Date.now());return N.useEffect(()=>{const n=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(n)},[]),e}function VW({phase:e}){const n={PreparingWorkspace:"bg-yellow-900/50 text-yellow-400",BuildingPrompt:"bg-yellow-900/50 text-yellow-400",LaunchingAgent:"bg-blue-900/50 text-blue-400",InitializingSession:"bg-blue-900/50 text-blue-400",StreamingTurn:"bg-emerald-900/50 text-emerald-400",Finishing:"bg-purple-900/50 text-purple-400",Succeeded:"bg-emerald-900/50 text-emerald-300",Failed:"bg-red-900/50 text-red-400",TimedOut:"bg-red-900/50 text-red-400",Stalled:"bg-orange-900/50 text-orange-400",CanceledByReconciliation:"bg-gray-800 text-gray-400"}[e]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${n}`,children:e})}function WW({startedAt:e}){const t=HW(e);return u.jsx("span",{className:"tabular-nums text-gray-400",children:t})}function qW({snapshot:e}){const t=e.globalCooldownUntilMs!==null&&Date.now()<e.globalCooldownUntilMs,n=Date.now(),r=e.recentRequestTimestamps.filter(o=>n-o<6e4).length,a=e.recentInputTokens.filter(o=>n-o.timestamp<6e4).reduce((o,c)=>o+c.tokens,0),s=e.recentOutputTokens.filter(o=>n-o.timestamp<6e4).reduce((o,c)=>o+c.tokens,0);return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Rate Limits"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Status"}),u.jsx("span",{className:t?"font-semibold text-red-400":"text-emerald-400",children:t?"COOLDOWN":"OK"})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Req/Min"}),u.jsxs("span",{className:"text-blue-400",children:[r," / ",e.maxRequestsPerMinute]})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Req/Sec"}),u.jsxs("span",{className:"text-blue-400",children:[e.maxRequestsPerSecond," max"]})]}),e.maxInputTokensPerMinute>0&&u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"ITPM"}),u.jsxs("span",{className:"text-yellow-400",children:[or(a)," / ",or(e.maxInputTokensPerMinute)]})]}),e.maxOutputTokensPerMinute>0&&u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"OTPM"}),u.jsxs("span",{className:"text-yellow-400",children:[or(s)," / ",or(e.maxOutputTokensPerMinute)]})]})]})]})}function YW({snapshot:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Concurrency"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Active"}),u.jsxs("span",{className:e.running.length>0?"text-emerald-400":"text-gray-500",children:[e.running.length," / ",e.maxConcurrentAgents]})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Claimed"}),u.jsx("span",{className:"text-cyan-400",children:e.claimed.length})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Retry Queue"}),u.jsx("span",{className:"text-gray-300",children:e.retryAttempts.length})]})]})]})}function KW({snapshot:e}){return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsx(Gr,{title:"Token Usage"}),u.jsxs("div",{className:"space-y-2 text-sm",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Input"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.inputTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Output"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.outputTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Total"}),u.jsx("span",{className:"text-yellow-400",children:or(e.tokenTotals.totalTokens)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-400",children:"Time Running"}),u.jsxs("span",{className:"text-blue-400",children:[Math.round(e.tokenTotals.secondsRunning),"s"]})]})]})]})}function XW({activity:e}){if(e.phase==="idle")return null;const t={fetching:"Fetching",analyzing:"Analyzing",dispatching:"Dispatching"},n={fetching:"text-blue-400",analyzing:"text-violet-400",dispatching:"text-emerald-400"};return u.jsxs("div",{className:"mb-6 rounded-lg border border-violet-800/50 bg-violet-950/20 px-4 py-3",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[u.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-violet-400 opacity-75"}),u.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-violet-500"})]}),u.jsx("span",{className:`text-sm font-medium ${n[e.phase]??"text-gray-400"}`,children:t[e.phase]??e.phase}),e.detail&&u.jsx("span",{className:"truncate text-sm text-gray-400",children:e.detail}),e.progress&&u.jsxs("span",{className:"ml-auto text-xs tabular-nums text-gray-500",children:[e.progress.current,"/",e.progress.total]})]}),e.progress&&u.jsx("div",{className:"mt-2 h-1 overflow-hidden rounded-full bg-gray-800",children:u.jsx("div",{className:"h-full rounded-full bg-violet-500 transition-all duration-300",style:{width:`${e.progress.current/e.progress.total*100}%`}})})]})}function ZW({agent:e,blocks:t,onViewStream:n}){var o,c,d,p,m,h,b,y,v;const[r,a]=N.useState(!1),s=t.slice(-5);return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900/60",children:[u.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-gray-800/40",children:[u.jsx("div",{className:"mt-1 flex-shrink-0",children:e.phase==="StreamingTurn"?u.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[u.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-75"}),u.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-emerald-500"})]}):u.jsx("span",{className:"inline-flex h-2.5 w-2.5 rounded-full bg-yellow-500"})}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"truncate font-medium text-white",children:((o=e.issue)==null?void 0:o.title)??e.identifier}),u.jsx(VW,{phase:e.phase})]}),u.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-gray-500",children:[u.jsx("span",{className:"font-mono",children:e.identifier}),u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx("span",{className:"text-blue-400",children:((c=e.session)==null?void 0:c.backendName)??"pending"}),u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx(WW,{startedAt:e.startedAt}),e.session&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:["T",e.session.turnCount," · ",or(e.session.totalTokens)," tok"]})]})]}),((d=e.session)==null?void 0:d.lastMessage)&&u.jsx("p",{className:"mt-1.5 truncate text-xs text-gray-400",children:e.session.lastMessage})]}),u.jsx("span",{className:"mt-1 flex-shrink-0 text-gray-600",children:r?"▲":"▼"})]}),r&&u.jsxs("div",{className:"border-t border-gray-800 px-4 py-3 text-sm",children:[(p=e.issue)!=null&&p.description?u.jsxs("div",{className:"mb-3",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Description"}),u.jsx("p",{className:"mt-1 whitespace-pre-wrap text-gray-300",children:e.issue.description})]}):u.jsx("p",{className:"mb-3 text-xs italic text-gray-600",children:"No description available."}),u.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1 text-xs",children:[u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Input Tokens"}),u.jsx("span",{className:"text-yellow-400",children:or(((m=e.session)==null?void 0:m.inputTokens)??0)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Output Tokens"}),u.jsx("span",{className:"text-yellow-400",children:or(((h=e.session)==null?void 0:h.outputTokens)??0)})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Backend"}),u.jsx("span",{className:"text-blue-400",children:((b=e.session)==null?void 0:b.backendName)??"-"})]}),u.jsxs("div",{className:"flex justify-between",children:[u.jsx("span",{className:"text-gray-500",children:"Turns"}),u.jsx("span",{className:"text-gray-300",children:((y=e.session)==null?void 0:y.turnCount)??0})]})]}),s.length>0&&u.jsxs("div",{className:"mt-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Live Activity"}),u.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),n()},className:"text-xs font-medium text-blue-400 transition-colors hover:text-blue-300",children:"View Full Stream"})]}),u.jsx("div",{className:"mt-2 max-h-48 overflow-hidden rounded-lg border border-gray-800 bg-gray-950/60 px-3 py-2 text-xs",children:u.jsx(YC,{blocks:s,isStreaming:e.phase==="StreamingTurn"})})]}),s.length===0&&((v=e.session)==null?void 0:v.lastMessage)&&u.jsxs("div",{className:"mt-3",children:[u.jsx("span",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Latest Activity"}),u.jsx("p",{className:"mt-1 whitespace-pre-wrap text-gray-300",children:e.session.lastMessage})]})]})]})}function QW({agents:e,agentEvents:t,onViewStream:n}){return e.length===0?u.jsx("p",{className:"text-sm italic text-gray-500",children:"No active agents."}):u.jsx("div",{className:"space-y-2",children:e.map(r=>u.jsx(ZW,{agent:r,blocks:t[r.issueId]??[],onViewStream:()=>n(r)},r.issueId))})}function JW({snapshot:e}){const t=nR();if(e.retryAttempts.length===0)return null;const n=[...e.retryAttempts].sort((r,a)=>r[1].dueAtMs-a[1].dueAtMs);return u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Retry Queue"}),u.jsx("div",{className:"space-y-1",children:n.map(([,r])=>{const a=Math.max(0,Math.ceil((r.dueAtMs-t)/1e3));return u.jsxs("div",{className:"flex items-center justify-between rounded border border-gray-800 bg-gray-900/40 px-3 py-2 text-sm",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-flex h-2 w-2 rounded-full ${a>0?"bg-orange-500":"bg-orange-400 animate-pulse"}`}),u.jsx("span",{className:"font-mono text-gray-300",children:r.identifier}),u.jsxs("span",{className:"text-gray-500",children:["attempt ",r.attempt]})]}),u.jsx("span",{className:`text-xs ${a>0?"text-gray-500":"text-orange-400 font-medium"}`,children:a>0?`retries in ${a}s`:"due now"})]},r.issueId)})})]})}function e9(e){const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function t9(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function n9({outcome:e}){if(!e)return u.jsx("span",{className:"text-xs text-gray-600",children:"in progress"});const n={normal:"bg-emerald-900/50 text-emerald-400",error:"bg-red-900/50 text-red-400"}[e]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${n}`,children:e})}function r9({session:e,onViewStream:t}){const n=e.attempts.at(-1),r=n==null?void 0:n.startedAt,a=(n==null?void 0:n.outcome)??null,s=n==null?void 0:n.stats;return u.jsxs("button",{type:"button",onClick:()=>t(e.issueId),className:"flex w-full items-center gap-3 rounded-lg border border-gray-800 bg-gray-900/60 px-4 py-3 text-left transition-colors hover:bg-gray-800/40",children:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"truncate font-medium text-white",children:e.title??e.identifier}),u.jsx(n9,{outcome:a}),e.pr&&u.jsxs("span",{className:"text-xs text-blue-400",children:["PR #",e.pr.number]})]}),u.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-gray-500",children:[r&&u.jsx("span",{children:t9(r)}),s&&s.durationMs>0&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsx("span",{children:e9(s.durationMs)})]}),s&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:["T",s.turnCount," · ",or(s.inputTokens+s.outputTokens)," ","tok"]})]}),e.attempts.length>1&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-gray-600",children:"|"}),u.jsxs("span",{children:[e.attempts.length," attempts"]})]})]})]}),u.jsx("span",{className:"flex-shrink-0 text-gray-600",children:"›"})]})}function dT({onViewStream:e}){const{sessions:t,loading:n,error:r}=zW();return n?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Loading sessions..."})]}):r?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm text-red-400",children:r})]}):t.length===0?u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("p",{className:"text-sm italic text-gray-500",children:"No recorded sessions yet."})]}):u.jsxs("section",{className:"mt-6",children:[u.jsx(Gr,{title:"Recent Sessions"}),u.jsx("div",{className:"space-y-2",children:t.map(a=>u.jsx(r9,{session:a,onViewStream:e},a.issueId))})]})}function a9(){const{snapshot:e,agentEvents:t,connected:n,localModelStatuses:r}=Yo(),a=Ln(),s=N.useCallback(d=>{var h,b,y;const p=Pe.getState();for(const v of p.threads.values())if(v.type==="agent"&&v.meta.issueId===d.issueId){p.setActiveThread(v.id),a(`/t/${v.id}`);return}const m=p.createThread("agent",{issueId:d.issueId,identifier:d.identifier,phase:d.phase,issueTitle:((h=d.issue)==null?void 0:h.title)??d.identifier,issueDescription:((b=d.issue)==null?void 0:b.description)??null,startedAt:d.startedAt,backendName:((y=d.session)==null?void 0:y.backendName)??null});p.setActiveThread(m.id),a(`/t/${m.id}`)},[a]),o=N.useCallback(d=>{const p=Pe.getState();for(const h of p.threads.values())if(h.type==="agent"&&h.meta.issueId===d){p.setActiveThread(h.id),a(`/t/${h.id}`);return}const m=p.createThread("agent",{issueId:d,identifier:d,phase:"completed",issueTitle:d,issueDescription:null,startedAt:new Date().toISOString(),backendName:null});p.updateThread(m.id,{status:"completed"}),p.setActiveThread(m.id),a(`/t/${m.id}`)},[a]);if(!e)return u.jsxs("div",{children:[r.filter(d=>!d.available).map(d=>u.jsx(cT,{status:d},d.backendName)),u.jsx("h1",{className:"mb-6 text-2xl font-bold",children:"Agent Monitor"}),u.jsx("p",{className:"text-sm text-gray-500",children:n?"Waiting for first state update...":"Connecting to orchestrator..."}),u.jsx(dT,{onViewStream:o})]});const c=e.running.map(([,d])=>d);return u.jsxs("div",{children:[r.filter(d=>!d.available).map(d=>u.jsx(cT,{status:d},d.backendName)),u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Agent Monitor"}),u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("span",{className:["inline-block h-2 w-2 rounded-full",n?"bg-emerald-500":"bg-yellow-400"].join(" ")}),u.jsx("span",{className:n?"text-gray-500":"text-yellow-400",children:n?"Live":"Reconnecting..."})]})]}),u.jsxs("div",{className:"mb-8 grid grid-cols-1 gap-4 md:grid-cols-3",children:[u.jsx(qW,{snapshot:e}),u.jsx(YW,{snapshot:e}),u.jsx(KW,{snapshot:e})]}),e.tickActivity&&u.jsx(XW,{activity:e.tickActivity}),u.jsxs("section",{children:[u.jsx(Gr,{title:"Active Agents"}),u.jsx(QW,{agents:c,agentEvents:t,onViewStream:s})]}),u.jsx(JW,{snapshot:e}),u.jsx(dT,{onViewStream:o})]})}function i9(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function s9(e){return e==="success"||e==="no-issues"?"text-emerald-400":e==="failed"?"text-red-400":"text-yellow-400"}function Bm(e){return e?new Date(e).toLocaleString():"—"}const o9=N.memo(function({entry:t}){const n=t.task==="compound-candidates"&&(t.findings??0)>0;return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsxs("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:[t.task,n&&u.jsxs("span",{className:"ml-2 inline-block rounded bg-amber-500/20 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-300",title:"Undocumented learnings detected this run",children:[t.findings," candidates"]})]}),u.jsx("td",{className:`py-2 px-3 text-xs font-semibold uppercase ${s9(t.status)}`,children:t.status}),u.jsx("td",{className:"py-2 px-3 text-xs text-gray-400",children:Bm(t.startedAt)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:i9(t.durationMs)})]})});function l9({entries:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No maintenance history yet. Runs will appear here after the first execution."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Task"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Started At"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Duration"})]})}),u.jsx("tbody",{children:e.map((t,n)=>u.jsx(o9,{entry:t},`${t.task}-${t.startedAt}-${n}`))})]})})}async function u9(){const e=await fetch("/api/maintenance/status");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}async function c9(){const e=await fetch("/api/maintenance/history");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}async function d9(e){const t=await fetch("/api/maintenance/trigger",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:e})});if(!t.ok)throw new Error(`HTTP ${t.status}`)}function p9(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(null),[o,c]=N.useState(!0),[d,p]=N.useState(!1),{maintenanceEvent:m,connected:h}=Yo(),b=N.useCallback(async()=>{try{const[k,w]=await Promise.all([u9(),c9()]);t(k),r(w),s(null)}catch(k){const w=k instanceof Error?k.message:"Network error";w.includes("404")||w.includes("502")?s("Orchestrator not running. Start with: harness orchestrator run"):s(w)}finally{c(!1)}},[]);N.useEffect(()=>{b()},[b]),N.useEffect(()=>{m&&b()},[m,b]);const y=()=>{const k="project-health";p(!0),d9(k).then(()=>b()).catch(w=>{s(w instanceof Error?w.message:"Failed to trigger maintenance run")}).finally(()=>p(!1))},v=(m==null?void 0:m.type)==="maintenance:started"?m.data.taskId:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Maintenance"}),u.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${h?"bg-emerald-400":"bg-gray-600"}`,title:h?"WebSocket connected":"WebSocket disconnected"})]}),u.jsx("button",{onClick:y,disabled:d,className:"rounded-lg border border-white/10 bg-white/5 px-4 py-1.5 text-xs font-semibold uppercase tracking-wider text-gray-200 transition-all hover:bg-white/10 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:d?"Running...":"Trigger Run"})]}),v&&u.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/10 px-4 py-2",children:[u.jsx("span",{className:"inline-block h-2 w-2 animate-pulse rounded-full bg-blue-400"}),u.jsxs("span",{className:"text-sm text-blue-300",children:["Running task: ",u.jsx("span",{className:"font-mono font-semibold",children:v})]})]}),(m==null?void 0:m.type)==="maintenance:error"&&u.jsx("div",{className:"mb-4 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2",children:u.jsxs("span",{className:"text-sm text-red-300",children:["Task ",u.jsx("span",{className:"font-mono font-semibold",children:m.data.taskId})," ","failed",m.data.error?`: ${m.data.error}`:""]})}),o&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading maintenance status..."}),a&&u.jsx("p",{className:"text-sm text-red-400",children:a}),e&&n&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Scheduler Status"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Scheduled Tasks",value:e.scheduledTasks}),u.jsx(Ze,{label:"Last Run",value:Bm(e.lastRunAt)}),u.jsx(Ze,{label:"Next Run",value:Bm(e.nextRunAt)})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Run History"}),u.jsx(l9,{entries:n})]})]})]})}function f9(e){if(e<1e3)return`${Math.round(e)}ms`;const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function m9(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function h9(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function g9(e){return new Date(e).toLocaleString()}async function b9(){const e=await fetch("/api/streams");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}const y9=N.memo(function({outcome:t}){if(!t)return u.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded px-2 py-0.5 text-xs font-medium bg-blue-900/50 text-blue-400",children:[u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-blue-400 animate-pulse"}),"running"]});const r={normal:"bg-emerald-900/50 text-emerald-400",error:"bg-red-900/50 text-red-400",timeout:"bg-orange-900/50 text-orange-400"}[t]??"bg-gray-800 text-gray-400";return u.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-medium ${r}`,children:t})});function x9({title:e}){return u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:e})}const v9=N.memo(function({session:t,onSelect:n}){const r=t.attempts.at(-1),a=r==null?void 0:r.startedAt,s=(r==null?void 0:r.outcome)??null,o=r==null?void 0:r.stats,c=o?o.turnCount:0,d=o?o.inputTokens+o.outputTokens:0;return u.jsxs("tr",{onClick:n,className:"border-b border-gray-800 cursor-pointer transition-colors hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-3 px-3 text-sm text-white truncate max-w-[260px]",children:t.title??t.identifier}),u.jsx("td",{className:"py-3 px-3 font-mono text-xs text-gray-400 max-w-[180px] truncate",children:t.identifier}),u.jsx("td",{className:"py-3 px-3",children:u.jsx(y9,{outcome:s})}),u.jsx("td",{className:"py-3 px-3 text-xs text-gray-400",children:a?g9(a):"-"}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-gray-400 text-xs",children:a?h9(a):"-"}),u.jsxs("td",{className:"py-3 px-3 text-right tabular-nums text-gray-300 text-xs",children:[c," turns"]}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-yellow-400 text-xs",children:m9(d)}),u.jsx("td",{className:"py-3 px-3 text-right tabular-nums text-gray-400 text-xs",children:o&&o.durationMs>0?f9(o.durationMs):"-"}),u.jsxs("td",{className:"py-3 px-3 text-right text-gray-500 text-xs",children:[t.attempts.length>1?`${t.attempts.length} attempts`:"",t.pr?u.jsxs("span",{className:"ml-2 text-blue-400",children:["PR #",t.pr.number]}):null]})]})});function S9(e){const t=Pe.getState();for(const s of t.threads.values())if(s.type==="agent"&&s.meta.issueId===e.issueId)return s.id;const n=e.attempts.at(-1),r=n!=null&&!n.endedAt,a=t.createThread("agent",{issueId:e.issueId,identifier:e.identifier,phase:r?"running":"completed",issueTitle:e.title??e.identifier,issueDescription:null,startedAt:(n==null?void 0:n.startedAt)??new Date().toISOString(),backendName:null});return r||t.updateThread(a.id,{status:"completed"}),a.id}function E9(){const e=Ln(),[t,n]=N.useState([]),[r,a]=N.useState(null),[s,o]=N.useState(!0),c=N.useCallback(async()=>{try{const p=await b9();n(p),a(null)}catch(p){const m=p instanceof Error?p.message:"Network error";m.includes("404")||m.includes("502")?a("Orchestrator not running. Start with: harness orchestrator run"):a(m)}finally{o(!1)}},[]);N.useEffect(()=>{c();const p=setInterval(()=>void c(),3e4);return()=>clearInterval(p)},[c]);const d=N.useCallback(p=>{const m=S9(p);Pe.getState().setActiveThread(m),e(`/t/${m}`)},[e]);return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Streams"}),u.jsxs("div",{className:"flex items-center gap-4",children:[t.length>0&&u.jsxs("span",{className:"text-xs text-gray-500",children:[t.length," recorded session",t.length!==1?"s":""]}),u.jsx("button",{type:"button",onClick:()=>{o(!0),c()},className:"rounded-lg border border-gray-700 bg-gray-800/60 px-3 py-1.5 text-xs font-medium text-gray-300 transition-colors hover:bg-gray-700 hover:text-white",children:"Refresh"})]})]}),s&&t.length===0&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading streams..."}),r&&u.jsx("p",{className:"text-sm text-red-400",children:r}),!s&&!r&&t.length===0&&u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No recorded streams yet. Sessions will appear here after agents run."})}),t.length>0&&u.jsxs("section",{children:[u.jsx(x9,{title:"Recorded Sessions"}),u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Title"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Identifier"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Status"}),u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Started At"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Age"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Turns"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Tokens"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Duration"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Info"})]})}),u.jsx("tbody",{children:t.map(p=>u.jsx(v9,{session:p,onSelect:()=>d(p)},p.issueId))})]})})]})]})}const xa={done:"#10b981","in-progress":"#3b82f6",planned:"#6b7280",blocked:"#ef4444",backlog:"#374151","needs-human":"#f59e0b"},Bi=20,$f=8,Ou=140,Ui={top:12,right:24,bottom:12,left:8};function w9({milestones:e}){const t=e.filter(d=>!d.isBacklog);if(t.length===0)return null;const n=Math.max(...t.map(d=>d.total),1),r=480,a=r-Ou,s=Ui.top+t.length*(Bi+$f)-$f+Ui.bottom;function o(d){return Ou+d/n*a}function c(d,p){const m=[{value:d.done,color:xa.done},{value:d.inProgress,color:xa["in-progress"]},{value:d.blocked,color:xa.blocked},{value:d.needsHuman,color:xa["needs-human"]},{value:d.planned+d.backlog,color:xa.planned}];let h=0;return m.map(({value:b,color:y},v)=>{if(b===0)return null;const k=o(h),w=b/n*a;return h+=b,u.jsx("rect",{x:k,y:p,width:w,height:Bi,fill:y},v)})}return u.jsxs("div",{children:[u.jsx("p",{className:"mb-2 text-xs text-neutral-muted",children:"Per-milestone progress (done / in-progress / blocked / remaining)"}),u.jsx("svg",{width:r+Ui.left+Ui.right,height:s,className:"overflow-visible",children:u.jsx("g",{transform:`translate(${Ui.left},${Ui.top})`,children:t.map((d,p)=>{const m=p*(Bi+$f);return u.jsxs("g",{children:[u.jsx("text",{x:Ou-8,y:m+Bi/2,dominantBaseline:"middle",textAnchor:"end",fontSize:11,fill:"#71717a",children:d.name.length>18?d.name.slice(0,17)+"…":d.name}),u.jsx("rect",{x:Ou,y:m,width:a,height:Bi,fill:"#18181b",rx:3}),c(d,m),u.jsxs("text",{x:o(d.total)+4,y:m+Bi/2,dominantBaseline:"middle",fontSize:10,fill:"#71717a",children:[d.done,"/",d.total]})]},d.name)})})}),u.jsx("div",{className:"mt-2 flex flex-wrap gap-4",children:Object.entries(xa).map(([d,p])=>u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-sm",style:{background:p}}),u.jsx("span",{className:"text-xs capitalize text-neutral-muted",children:d.replace("-"," ")})]},d))})]})}const so=140,$i=32,k9=180,N9=56,xc=24;function T9(e){const t=[],n=new Set(e.map(b=>b.name)),r=new Map;for(const b of e)r.set(b.name,[]);for(const b of e)for(const y of b.blockedBy)n.has(y)&&(t.push([y,b.name]),r.get(y).push(b.name));const a=new Map;for(const b of e)a.set(b.name,0);for(const[,b]of t)a.set(b,(a.get(b)??0)+1);const s=new Map,o=[];for(const b of e)(a.get(b.name)??0)===0&&(o.push(b.name),s.set(b.name,0));let c=0;for(;c<o.length;){const b=o[c++],y=s.get(b)??0;for(const v of r.get(b)){const k=(a.get(v)??1)-1;a.set(v,k),s.set(v,Math.max(s.get(v)??0,y+1)),k===0&&o.push(v)}}const d=new Set(o),p=e.filter(b=>!d.has(b.name)).map(b=>b.name);if(p.length>0){const b=Math.max(0,...Array.from(s.values()));for(const y of p)s.set(y,b+1)}const m=new Map;return{nodes:e.map(b=>{const y=s.get(b.name)??0,v=m.get(y)??0;return m.set(y,v+1),{id:b.name,x:xc+y*k9,y:xc+v*N9,status:b.status}}),edges:t,cycleNodes:p}}function A9({features:e}){const t=new Set,n=new Set;for(const m of e)for(const h of m.blockedBy)t.add(h),n.add(m.name);const r=e.filter(m=>t.has(m.name)||n.has(m.name));if(r.length===0)return null;const{nodes:a,edges:s,cycleNodes:o}=T9(r),c=new Map(a.map(m=>[m.id,m])),d=Math.max(...a.map(m=>m.x+so))+xc,p=Math.max(...a.map(m=>m.y+$i))+xc;return u.jsxs("div",{className:"relative group",children:[u.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[u.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-neutral-muted",children:"Relationship Topology"}),o.length>0&&u.jsxs("span",{className:"rounded bg-red-500/10 px-2 py-0.5 text-[10px] font-bold text-red-400 border border-red-500/20 animate-pulse",children:["Cycles Detected: ",o.length]})]}),u.jsx("div",{className:"overflow-x-auto rounded-2xl border border-neutral-border bg-neutral-bg/30 p-6 backdrop-blur-md",children:u.jsxs("svg",{width:d,height:p,className:"overflow-visible",children:[u.jsxs("defs",{children:[u.jsxs("filter",{id:"neon-glow-small",x:"-20%",y:"-20%",width:"140%",height:"140%",children:[u.jsx("feGaussianBlur",{stdDeviation:"1.5",result:"blur"}),u.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]}),u.jsx("marker",{id:"arrow",markerWidth:"8",markerHeight:"8",refX:"6",refY:"3",orient:"auto",children:u.jsx("path",{d:"M0,0 L0,6 L8,3 z",fill:"#4f46e5"})})]}),s.map(([m,h],b)=>{const y=c.get(m),v=c.get(h);if(!y||!v)return null;const k=y.x+so,w=y.y+$i/2,E=v.x,T=v.y+$i/2;return u.jsx(J.line,{initial:{pathLength:0,opacity:0},animate:{pathLength:1,opacity:1},transition:{duration:1,delay:b*.05},x1:k,y1:w,x2:E-4,y2:T,className:"stroke-primary-500/20",strokeWidth:1.5,markerEnd:"url(#arrow)"},`${m}-${h}`)}),a.map((m,h)=>u.jsxs(J.g,{initial:{opacity:0,scale:.9,y:m.y+10},animate:{opacity:1,scale:1,y:m.y},transition:{duration:.4,delay:h*.03},whileHover:{scale:1.05,filter:"url(#neon-glow-small)"},className:"cursor-pointer",children:[u.jsx("rect",{x:m.x,y:0,width:so,height:$i,rx:8,className:"fill-neutral-surface/80 stroke-neutral-border",strokeWidth:1}),u.jsx(J.rect,{x:m.x,y:0,width:so,height:$i,rx:8,className:"fill-none",stroke:xa[m.status]??"#27272a",strokeWidth:1.5,initial:{pathLength:0},animate:{pathLength:1},transition:{duration:1,delay:h*.05}}),u.jsx("text",{x:m.x+so/2,y:$i/2,dominantBaseline:"middle",textAnchor:"middle",className:"text-[10px] font-bold tracking-tight fill-neutral-text pointer-events-none",children:m.id.length>18?m.id.slice(0,17)+"…":m.id})]},m.id))]})})]})}const I9=[{key:"totalFeatures",label:"Total",color:"text-white"},{key:"totalDone",label:"Done",color:"text-emerald-400"},{key:"totalInProgress",label:"In Progress",color:"text-blue-400"},{key:"totalPlanned",label:"Planned",color:"text-gray-400"},{key:"totalBlocked",label:"Blocked",color:"text-red-400"},{key:"totalNeedsHuman",label:"Needs Human",color:"text-amber-400"},{key:"totalBacklog",label:"Backlog",color:"text-gray-500"}];function C9({data:e}){return u.jsx("div",{className:"flex flex-wrap gap-6 rounded-lg border border-gray-800 bg-gray-900/50 px-5 py-3",children:I9.map(({key:t,label:n,color:r})=>u.jsxs("div",{className:"flex items-baseline gap-1.5",children:[u.jsx("span",{className:`text-lg font-bold tabular-nums ${r}`,children:e[t]}),u.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-gray-500",children:n})]},t))})}const ei="—";function rR(e){return(e.status==="planned"||e.status==="backlog")&&(!e.assignee||e.assignee===ei)}function R9(e){return!e.spec||e.spec==="none"||e.spec===ei?"brainstorming":!e.plans||e.plans.length===0||e.plans.length===1&&e.plans[0]===ei?"planning":"execution"}function _9(e){const t=e.match(/^github:(.+?)#(\d+)$/);return t?`https://github.com/${t[1]}/issues/${t[2]}`:null}function O9({status:e}){const t=xa[e]??"#71717a";return u.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider",style:{backgroundColor:`${t}20`,color:t},children:e.replace("-"," ")})}function L9({priority:e}){const t={P0:"text-red-400 bg-red-400/10",P1:"text-orange-400 bg-orange-400/10",P2:"text-yellow-400 bg-yellow-400/10",P3:"text-gray-400 bg-gray-400/10"};return u.jsx("span",{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-bold ${t[e]??"text-gray-400 bg-gray-400/10"}`,children:e})}function D9({feature:e,identity:t,onClaim:n}){const[r,a]=N.useState(!1),s=rR(e);return u.jsxs("div",{className:"border-t border-gray-800 first:border-t-0",children:[u.jsxs("div",{className:"group flex cursor-pointer items-center gap-3 px-4 py-2.5 hover:bg-gray-800/40 transition-colors",onClick:()=>a(!r),children:[u.jsx("span",{className:"text-[10px] text-gray-600 transition-transform",style:{transform:r?"rotate(90deg)":void 0},children:"▶"}),u.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-gray-200",title:e.name,children:e.name}),u.jsx(O9,{status:e.status}),e.priority&&u.jsx(L9,{priority:e.priority}),e.assignee&&e.assignee!==ei&&u.jsx("span",{className:"text-xs text-gray-500",title:e.assignee,children:e.assignee}),u.jsx("span",{className:"hidden max-w-[200px] truncate text-xs text-gray-600 lg:inline",title:e.summary,children:e.summary}),s&&u.jsx("button",{onClick:o=>{o.stopPropagation(),t&&n(e)},disabled:!t,title:t?void 0:"Could not resolve your identity",className:`ml-auto rounded px-2 py-1 text-[10px] font-bold uppercase tracking-widest border transition-all whitespace-nowrap ${t?"bg-primary-500/10 text-primary-400 border-primary-500/20 hover:bg-primary-500 hover:text-white":"bg-gray-800 text-gray-600 border-gray-700 cursor-not-allowed"}`,children:"Start Working"})]}),r&&u.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1.5 bg-gray-900/30 px-10 py-3 text-xs",children:[u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Summary: "}),u.jsx("span",{className:"text-gray-300",children:e.summary})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Spec: "}),u.jsx("span",{className:"text-gray-400",children:e.spec??ei})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Plans: "}),u.jsx("span",{className:"text-gray-400",children:e.plans.length>0?e.plans.join(", "):ei})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"External ID: "}),e.externalId?(()=>{const o=_9(e.externalId);return o?u.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"text-primary-400 hover:underline",onClick:c=>c.stopPropagation(),children:e.externalId}):u.jsx("span",{className:"text-gray-400",children:e.externalId})})():u.jsx("span",{className:"text-gray-400",children:ei})]}),e.blockedBy.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Blocked by: "}),u.jsx("span",{className:"text-red-400",children:e.blockedBy.join(", ")})]}),e.updatedAt&&u.jsxs("div",{children:[u.jsx("span",{className:"text-gray-500",children:"Updated: "}),u.jsx("span",{className:"text-gray-400",children:new Date(e.updatedAt).toLocaleDateString()})]})]})]})}function j9({name:e,features:t,progress:n,identity:r,onClaim:a}){const[s,o]=N.useState(!1),c=(n==null?void 0:n.done)??0,d=(n==null?void 0:n.total)??t.length;return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 overflow-hidden",children:[u.jsxs("button",{className:"flex w-full items-center gap-3 px-4 py-3 text-left hover:bg-gray-800/40 transition-colors",onClick:()=>o(!s),children:[u.jsx("span",{className:"text-xs text-gray-500 transition-transform",style:{transform:s?void 0:"rotate(90deg)"},children:"▶"}),u.jsx("span",{className:"text-sm font-semibold text-gray-200",children:e}),u.jsxs("span",{className:"text-xs text-gray-500",children:[c,"/",d]}),u.jsx("div",{className:"ml-auto h-1.5 w-24 overflow-hidden rounded-full bg-gray-800",children:u.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all",style:{width:d>0?`${c/d*100}%`:"0%"}})})]}),!s&&u.jsx("div",{children:t.map(p=>u.jsx(D9,{feature:p,identity:r,onClaim:a},p.name))})]})}function M9({features:e,milestones:t,filterMilestone:n,filterStatus:r,workableOnly:a,identity:s,onClaim:o}){const c=e.filter(m=>{if(n&&m.milestone!==n)return!1;if(r){if(m.status!==r)return!1}else if(m.status==="done")return!1;return!(a&&!rR(m))});if(c.length===0)return u.jsx("p",{className:"text-sm text-neutral-muted",children:"No features match the current filters."});const d=new Map;for(const m of c){const h=d.get(m.milestone)??[];h.push(m),d.set(m.milestone,h)}const p=new Map(t.map(m=>[m.name,m]));return u.jsx("div",{className:"space-y-3",children:Array.from(d).map(([m,h])=>u.jsx(j9,{name:m,features:h,progress:p.get(m),identity:s,onClaim:o},m))})}const F9={brainstorming:{label:"Brainstorming",description:"No spec found. You’ll start by exploring the problem space."},planning:{label:"Planning",description:"Spec exists but no plan. You’ll create an implementation plan."},execution:{label:"Execution",description:"Spec and plan exist. You’ll start implementing."}};function P9({feature:e,identity:t,onConfirm:n,onCancel:r}){const[a,s]=N.useState(!1),[o,c]=N.useState(null),d=R9(e),p=F9[d];async function m(){s(!0),c(null);try{const h=await fetch("/api/actions/roadmap/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feature:e.name,assignee:t})}),b=await h.json();if(!h.ok){c(b.error??"Claim failed"),s(!1);return}n(b)}catch{c("Network error"),s(!1)}}return u.jsxs("div",{className:"absolute right-0 top-full z-50 mt-2 w-80 rounded-lg border border-gray-700 bg-gray-900 p-4 shadow-xl",children:[u.jsx("h3",{className:"mb-1 text-sm font-semibold text-gray-200",children:"Claim Feature"}),u.jsx("p",{className:"mb-3 text-xs text-gray-400 truncate",title:e.name,children:e.name}),u.jsxs("div",{className:"mb-3 rounded border border-gray-800 bg-gray-800/50 px-3 py-2",children:[u.jsx("div",{className:"flex items-center gap-2",children:u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-primary-400",children:p.label})}),u.jsx("p",{className:"mt-1 text-xs text-gray-400",children:p.description})]}),u.jsxs("p",{className:"mb-3 text-xs text-gray-500",children:["Claiming as ",u.jsx("span",{className:"font-medium text-gray-300",children:t})]}),o&&u.jsx("p",{className:"mb-2 text-xs text-red-400",children:o}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx("button",{onClick:r,disabled:a,className:"rounded px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest text-gray-500 hover:text-gray-300 transition-colors",children:"Cancel"}),u.jsx("button",{onClick:()=>void m(),disabled:a,className:"rounded bg-primary-500 px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest text-white disabled:opacity-40 hover:bg-primary-400 transition-colors",children:a?"Claiming…":"Confirm"})]})]})}const B9={assigned:"text-blue-400",completed:"text-emerald-400",unassigned:"text-gray-400"};function U9({records:e}){return e.length===0?null:u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-left text-xs",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 text-[10px] font-semibold uppercase tracking-widest text-gray-500",children:[u.jsx("th",{className:"px-4 py-2.5",children:"Feature"}),u.jsx("th",{className:"px-4 py-2.5",children:"Assignee"}),u.jsx("th",{className:"px-4 py-2.5",children:"Action"}),u.jsx("th",{className:"px-4 py-2.5",children:"Date"})]})}),u.jsx("tbody",{children:e.map((t,n)=>u.jsxs("tr",{className:"border-t border-gray-800/50 hover:bg-gray-800/30 transition-colors",children:[u.jsx("td",{className:"px-4 py-2 text-gray-300",children:t.feature}),u.jsx("td",{className:"px-4 py-2 text-gray-400",children:t.assignee}),u.jsx("td",{className:`px-4 py-2 capitalize ${B9[t.action]??"text-gray-400"}`,children:t.action}),u.jsx("td",{className:"px-4 py-2 text-gray-500",children:t.date})]},n))})]})})}function $9({milestoneOptions:e,filterMilestone:t,setFilterMilestone:n,filterStatus:r,setFilterStatus:a,workableOnly:s,setWorkableOnly:o}){return u.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[u.jsxs("select",{value:t,onChange:c=>n(c.target.value),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1 text-xs text-gray-300 focus:outline-none",children:[u.jsx("option",{value:"",children:"All Milestones"}),e.map(c=>u.jsx("option",{value:c,children:c},c))]}),u.jsxs("select",{value:r,onChange:c=>a(c.target.value),className:"rounded border border-gray-700 bg-gray-900 px-2 py-1 text-xs text-gray-300 focus:outline-none",children:[u.jsx("option",{value:"",children:"Non-done"}),u.jsx("option",{value:"in-progress",children:"In Progress"}),u.jsx("option",{value:"planned",children:"Planned"}),u.jsx("option",{value:"blocked",children:"Blocked"}),u.jsx("option",{value:"done",children:"Done"}),u.jsx("option",{value:"backlog",children:"Backlog"}),u.jsx("option",{value:"needs-human",children:"Needs Human"})]}),u.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer select-none",children:[u.jsx("input",{type:"checkbox",checked:s,onChange:c=>o(c.target.checked),className:"rounded border-gray-600 bg-gray-800 text-primary-500 focus:ring-primary-500/30"}),"Workable only"]})]})}const aR="rounded bg-primary-500/10 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-primary-400 border border-primary-500/20 hover:bg-primary-500 hover:text-white transition-all";function pT({command:e,label:t}){const n=Ln();return u.jsx("button",{onClick:()=>{const r=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:e});n(`/t/${r.id}`)},className:aR,children:t})}function z9(){const e=Ln(),[t,n]=N.useState(!1),[r,a]=N.useState(""),s=N.useRef(null);N.useEffect(()=>{var c;t&&((c=s.current)==null||c.focus())},[t]);const o=()=>{if(!r.trim())return;const d=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:"harness:roadmap-add"});e(`/t/${d.id}`),n(!1),a("")};return u.jsxs("div",{className:"relative",children:[u.jsx("button",{onClick:()=>n(!t),className:aR,children:"Add"}),t&&u.jsxs("div",{className:"absolute right-0 top-full z-50 mt-2 w-72 rounded-lg border border-gray-700 bg-gray-900 p-3 shadow-xl",children:[u.jsx("label",{className:"mb-1.5 block text-[10px] font-semibold uppercase tracking-widest text-gray-400",children:"What should be added?"}),u.jsx("input",{ref:s,value:r,onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&o(),c.key==="Escape"&&(n(!1),a(""))},placeholder:"e.g. Dark mode support",className:"mb-2 w-full rounded border border-gray-700 bg-gray-800 px-2 py-1.5 text-xs text-gray-200 placeholder-gray-600 focus:border-primary-500 focus:outline-none"}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx("button",{onClick:()=>{n(!1),a("")},className:"rounded px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-gray-500 hover:text-gray-300 transition-colors",children:"Cancel"}),u.jsx("button",{onClick:o,disabled:!r.trim(),className:"rounded bg-primary-500 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-white disabled:opacity-40 hover:bg-primary-400 transition-colors",children:"Go"})]})]})]})}const G9={brainstorming:"harness:brainstorming",planning:"harness:planning",execution:"harness:execution"};function H9({milestones:e,features:t,data:n}){const r=Ln(),[a,s]=N.useState(""),[o,c]=N.useState(""),[d,p]=N.useState(!1),[m,h]=N.useState(null),[b,y]=N.useState(null),[v,k]=N.useState(!0),w=e.map(_=>_.name),E=t.some(_=>_.blockedBy.length>0);N.useEffect(()=>{fetch("/api/identity").then(_=>_.ok?_.json():null).then(_=>{_!=null&&_.username&&y(_.username)}).catch(()=>{}).finally(()=>k(!1))},[]);const T=N.useCallback(_=>{h(_)},[]),A=N.useCallback(_=>{h(null);const j=G9[_.workflow]??"harness:execution",D=Pe.getState().createThread("chat",{sessionId:crypto.randomUUID(),command:j});r(`/t/${D.id}`)},[r]);return u.jsxs("div",{className:"space-y-8",children:[u.jsx(C9,{data:n}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Progress by Milestone"}),u.jsx(w9,{milestones:e})]}),u.jsxs("section",{children:[u.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[u.jsx("h2",{className:"text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Features"}),u.jsx($9,{milestoneOptions:w,filterMilestone:a,setFilterMilestone:s,filterStatus:o,setFilterStatus:c,workableOnly:d,setWorkableOnly:p})]}),u.jsxs("div",{className:"relative",children:[u.jsx(M9,{features:t,milestones:e,filterMilestone:a,filterStatus:o,workableOnly:d,identity:v?null:b,onClaim:T}),m&&b&&u.jsx(P9,{feature:m,identity:b,onConfirm:A,onCancel:()=>h(null)})]})]}),E&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Blocker Dependencies"}),u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900 p-4",children:u.jsx(A9,{features:t})})]}),n.assignmentHistory.length>0&&u.jsxs("section",{children:[u.jsx("h2",{className:"mb-4 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Assignment History"}),u.jsx(U9,{records:n.assignmentHistory})]})]})}function V9(){const{data:e,lastUpdated:t,stale:n,error:r}=gc(bc,"overview"),a=e?e.roadmap:null,s=a&&B8(a)?a:null;return u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Roadmap"}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(pT,{command:"harness:roadmap-pilot",label:"Pilot"}),u.jsx(pT,{command:"harness:roadmap-sync",label:"Sync"}),u.jsx(z9,{}),u.jsx(iv,{lastUpdated:t,stale:n,error:r})]})]}),!e&&!r&&u.jsx("p",{className:"text-sm text-gray-500",children:"Connecting to data stream…"}),a&&!s&&u.jsx("p",{className:"text-sm text-red-400",children:"error"in a?a.error:"Unavailable"}),s&&u.jsx(H9,{milestones:s.milestones,features:s.features,data:s})]})}function W9(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function q9(e){return`${Math.round(e*100)}%`}function Y9(e){return e>=.8?"text-emerald-400":e>=.5?"text-yellow-400":"text-red-400"}const K9=N.memo(function({skill:t}){return u.jsxs("tr",{className:"border-b border-gray-800 hover:bg-gray-800/40",children:[u.jsx("td",{className:"py-2 px-3 font-mono text-xs text-gray-200",children:t.skill}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-200",children:t.invocations}),u.jsx("td",{className:`py-2 px-3 text-right tabular-nums ${Y9(t.successRate)}`,children:q9(t.successRate)}),u.jsx("td",{className:"py-2 px-3 text-right tabular-nums text-gray-400",children:W9(t.avgDuration)}),u.jsx("td",{className:"py-2 px-3 text-right text-xs text-gray-500",children:t.lastUsed.slice(0,10)})]})});function X9({skills:e}){return e.length===0?u.jsx("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-6 text-center",children:u.jsx("p",{className:"text-sm text-gray-500",children:"No adoption data yet. Skills will appear here after your next session."})}):u.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-800 bg-gray-900",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-gray-800 bg-gray-900/60",children:[u.jsx("th",{className:"py-2 px-3 text-left text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Skill"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Invocations"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Success"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Avg Duration"}),u.jsx("th",{className:"py-2 px-3 text-right text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Last Used"})]})}),u.jsx("tbody",{children:e.map(t=>u.jsx(K9,{skill:t},t.skill))})]})})}async function Z9(){const e=await fetch("/api/adoption");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).data}function Q9(){const[e,t]=N.useState(null),[n,r]=N.useState(null),[a,s]=N.useState(!0),o=N.useCallback(async()=>{try{const c=await Z9();t(c),r(null)}catch(c){r(c instanceof Error?c.message:"Network error")}finally{s(!1)}},[]);return N.useEffect(()=>{o()},[o]),u.jsxs("div",{children:[u.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Adoption"}),e&&u.jsxs("span",{className:"text-xs text-gray-500",children:["Generated ",new Date(e.generatedAt).toLocaleString()]})]}),a&&!e&&u.jsx("p",{className:"text-sm text-gray-500",children:"Loading adoption telemetry..."}),n&&u.jsx("p",{className:"text-sm text-red-400",children:n}),e&&u.jsxs("div",{className:"space-y-8",children:[u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Summary"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[u.jsx(Ze,{label:"Total Invocations",value:e.totalInvocations}),u.jsx(Ze,{label:"Unique Skills",value:e.uniqueSkills}),u.jsx(Ze,{label:"Period",value:e.period})]})]}),u.jsxs("section",{children:[u.jsx("h2",{className:"mb-3 text-xs font-semibold uppercase tracking-widest text-gray-500",children:"Top Skills"}),u.jsx(X9,{skills:e.topSkills})]})]})]})}function J9(e){const t=N.useRef(new Set),n=N.useRef(!1);N.useEffect(()=>{typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]),N.useEffect(()=>{if(!n.current){for(const r of e)t.current.add(r.id);n.current=!0;return}if(!(typeof Notification>"u"||Notification.permission!=="granted")&&document.hidden)for(const r of e)t.current.has(r.id)||(t.current.add(r.id),new Notification("Needs Attention",{body:`${r.context.issueTitle}
|
|
390
390
|
${r.reasons.join(", ")}`,tag:r.id}))},[e])}function eq({spec:e}){return u.jsxs("div",{className:"space-y-3 rounded-md border border-primary-500/20 bg-primary-500/5 p-4",children:[u.jsx("h4",{className:"text-xs font-semibold uppercase tracking-widest text-primary-500",children:"Enriched Spec (SEL)"}),u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Intent"}),u.jsx("p",{className:"mt-1 text-sm text-white",children:e.intent})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Summary"}),u.jsx("p",{className:"mt-1 text-sm leading-relaxed text-gray-300",children:e.summary})]}),e.affectedSystems.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Affected Systems"}),u.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:e.affectedSystems.map(t=>u.jsxs("span",{className:"rounded-md border border-blue-500/20 bg-blue-500/10 px-2 py-0.5 text-[10px] font-medium text-blue-400",title:`Confidence: ${Math.round(t.confidence*100)}% | Tests: ${t.testCoverage} | Deps: ${t.transitiveDeps.length}`,children:[t.name,t.graphNodeId&&u.jsxs("span",{className:"ml-1 text-blue-500/50",children:[Math.round(t.confidence*100),"%"]})]},t.name))})]}),u.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-3",children:[e.unknowns.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-amber-500",children:["Unknowns (",e.unknowns.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.unknowns.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.ambiguities.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-orange-500",children:["Ambiguities (",e.ambiguities.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.ambiguities.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.riskSignals.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-red-500",children:["Risk Signals (",e.riskSignals.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.riskSignals.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]})]})}const vc={low:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",medium:"bg-yellow-500/10 text-yellow-400 border-yellow-500/20",high:"bg-orange-500/10 text-orange-400 border-orange-500/20",critical:"bg-red-500/10 text-red-400 border-red-500/20"},tq={local:"text-emerald-400",human:"text-amber-400","simulation-required":"text-purple-400"};function oo({value:e,label:t,color:n}){const r=Math.round(e*100);return u.jsxs("div",{className:"space-y-1",children:[u.jsxs("div",{className:"flex justify-between text-xs",children:[u.jsx("span",{className:"text-gray-400",children:t}),u.jsxs("span",{className:n,children:[r,"%"]})]}),u.jsx("div",{className:"h-1.5 w-full rounded-full bg-gray-800",children:u.jsx("div",{className:`h-full rounded-full ${n.replace("text-","bg-")}`,style:{width:`${r}%`}})})]})}function nq({score:e}){return u.jsxs("div",{className:"space-y-3 rounded-md border border-secondary-400/20 bg-secondary-400/5 p-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h4",{className:"text-xs font-semibold uppercase tracking-widest text-secondary-400",children:"Complexity Model (CML)"}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`inline-block rounded-md border px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest ${vc[e.riskLevel]??vc.medium}`,children:e.riskLevel}),u.jsx("span",{className:`text-xs font-mono font-bold ${tq[e.recommendedRoute]??"text-gray-400"}`,children:e.recommendedRoute})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(oo,{value:e.overall,label:"Overall",color:"text-primary-500"}),u.jsx(oo,{value:e.dimensions.structural,label:"Structural",color:"text-blue-400"}),u.jsx(oo,{value:e.dimensions.semantic,label:"Semantic",color:"text-purple-400"}),u.jsx(oo,{value:e.dimensions.historical,label:"Historical",color:"text-yellow-400"}),u.jsx(oo,{value:e.confidence,label:"Confidence",color:"text-emerald-400"})]}),u.jsxs("div",{className:"grid grid-cols-2 gap-3 border-t border-gray-800 pt-2 md:grid-cols-4",children:[u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.services}),u.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-500",children:"Services"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.modules}),u.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-500",children:"Modules"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.filesEstimated}),u.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-500",children:"Files"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.testFilesAffected}),u.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-500",children:"Test Files"})]})]}),e.reasoning.length>0&&u.jsxs("div",{className:"border-t border-gray-800 pt-2",children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Reasoning"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.reasoning.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]})}function rq({interaction:e,onDismiss:t,onClaim:n}){const{context:r,reasons:a,status:s,createdAt:o}=e,c=s==="pending",d=s==="claimed",p=!!r.enrichedSpec,m=!!r.complexityScore,h=p||m,[b,y]=N.useState(!1);return u.jsxs("div",{className:"rounded-lg border border-gray-800 bg-gray-900 p-5",children:[u.jsxs("div",{className:"mb-3 flex items-start justify-between",children:[u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("h3",{className:"text-base font-semibold text-white",children:r.issueTitle}),h&&u.jsx("span",{className:"rounded-md border border-primary-500/20 bg-primary-500/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-widest text-primary-500",children:"Analyzed"})]}),u.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[new Date(o).toLocaleString()," · ",e.issueId]})]}),u.jsx("span",{className:["rounded px-2 py-0.5 text-xs font-medium",c?"bg-yellow-900 text-yellow-300":"",d?"bg-blue-900 text-blue-300":"",s==="resolved"?"bg-gray-700 text-gray-400":""].filter(Boolean).join(" "),children:s})]}),r.issueDescription&&u.jsx("p",{className:"mb-3 text-sm text-gray-300",children:r.issueDescription}),u.jsxs("div",{className:"mb-3",children:[u.jsx("p",{className:"mb-1 text-xs font-medium uppercase tracking-widest text-gray-500",children:"Escalation Reasons"}),u.jsx("div",{className:"space-y-1",children:a.map((v,k)=>u.jsx("div",{className:"text-sm text-yellow-400 [&_p]:m-0 [&_strong]:font-bold [&_strong]:text-yellow-200",children:u.jsx(ka,{remarkPlugins:[Na],children:v})},k))})]}),h&&u.jsxs("div",{className:"mb-3",children:[u.jsxs("button",{onClick:()=>y(v=>!v),className:["flex w-full items-center justify-between rounded-md border px-3 py-2 text-left text-xs transition-colors",b?"border-primary-500/30 bg-primary-500/10":"border-gray-700 bg-gray-800/50 hover:border-gray-600 hover:bg-gray-800"].join(" "),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"inline-block text-[10px] text-gray-500 transition-transform",style:{transform:b?"rotate(90deg)":"rotate(0deg)"},children:"▶"}),u.jsxs("span",{className:"font-medium text-gray-300",children:[b?"Hide":"View"," Analysis"]}),p&&u.jsxs("span",{className:"text-gray-500",children:[r.enrichedSpec.affectedSystems.length," system",r.enrichedSpec.affectedSystems.length!==1?"s":""]})]}),m&&u.jsxs("span",{className:`rounded-md border px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest ${vc[r.complexityScore.riskLevel]??vc.medium}`,children:[r.complexityScore.riskLevel," risk"]})]}),b&&u.jsxs("div",{className:"mt-2 space-y-3",children:[p&&u.jsx(eq,{spec:r.enrichedSpec}),m&&u.jsx(nq,{score:r.complexityScore})]})]}),r.relatedFiles.length>0&&u.jsxs("div",{className:"mb-3",children:[u.jsx("p",{className:"mb-1 text-xs font-medium uppercase tracking-widest text-gray-500",children:"Related Files"}),u.jsx("ul",{className:"space-y-0.5",children:r.relatedFiles.map(v=>u.jsx("li",{className:"font-mono text-xs text-gray-400",children:v},v))})]}),r.specPath&&u.jsxs("p",{className:"mb-3 text-xs text-gray-500",children:["Spec: ",u.jsx("span",{className:"font-mono text-gray-400",children:r.specPath})]}),(c||d)&&u.jsxs("div",{className:"flex gap-2",children:[u.jsx("button",{onClick:()=>n(e.id),className:"rounded bg-blue-700 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-600",children:"Claim"}),u.jsx("button",{onClick:()=>t(e.id),className:"rounded bg-gray-700 px-3 py-1.5 text-xs font-medium text-gray-300 hover:bg-gray-600",children:"Dismiss"})]})]})}function aq(){const{interactions:e,removeInteraction:t,setInteractions:n}=Yo(),[r,a]=N.useState(!1),[s,o]=N.useState([]),[c,d]=N.useState(""),p=Ln();J9(s),N.useEffect(()=>{const v=new AbortController;return(async()=>{try{const k=await fetch("/api/interactions",{signal:v.signal});if(k.ok){const w=await k.json();n(w),o(w)}}catch(k){if(k.name==="AbortError")return}finally{a(!0)}})(),()=>v.abort()},[n]),N.useEffect(()=>{e.length>0&&o(v=>{const k=new Set(v.map(E=>E.id)),w=e.filter(E=>!k.has(E.id));return w.length>0?[...v,...w]:v})},[e]);const m=N.useCallback(async v=>{(await fetch(`/api/interactions/${v}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:"resolved"})})).ok&&(t(v),o(w=>w.filter(E=>E.id!==v)))},[t]),h=N.useCallback(v=>{const k=Pe.getState();let w;for(const E of k.threads.values())if(E.type==="attention"&&"interactionId"in E.meta&&E.meta.interactionId===v){w=E.id;break}w&&p(`/t/${w}`)},[p]),y=s.filter(v=>{var _,j;if(v.status==="resolved")return!1;if(!c.trim())return!0;const k=c.toLowerCase(),w=(_=v.context.issueTitle)==null?void 0:_.toLowerCase().includes(k),E=(j=v.context.issueDescription)==null?void 0:j.toLowerCase().includes(k),T=v.reasons.some(D=>D.toLowerCase().includes(k)),A=v.id.toLowerCase().includes(k)||v.issueId.toLowerCase().includes(k);return w||E||T||A}).sort((v,k)=>new Date(k.createdAt).getTime()-new Date(v.createdAt).getTime());return u.jsxs("div",{className:"flex h-full flex-col",children:[u.jsxs("div",{className:"mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[u.jsx("h1",{className:"text-2xl font-bold",children:"Needs Attention"}),u.jsxs("div",{className:"relative w-full max-w-sm",children:[u.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3",children:u.jsx(mm,{className:"h-4 w-4 text-gray-500"})}),u.jsx("input",{type:"text",className:"block w-full rounded-lg border border-gray-800 bg-gray-900 py-2 pl-10 pr-10 text-sm text-white placeholder-gray-500 transition-all focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500",placeholder:"Search escalations...",value:c,onChange:v=>d(v.target.value)}),c&&u.jsx("button",{className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500 hover:text-gray-300",onClick:()=>d(""),children:u.jsx(Ch,{className:"h-4 w-4"})})]})]}),!r&&u.jsx("div",{className:"flex flex-1 items-center justify-center",children:u.jsxs("div",{className:"flex flex-col items-center gap-2 text-gray-500",children:[u.jsx(_c,{className:"h-8 w-8 animate-spin"}),u.jsx("p",{className:"text-sm",children:"Loading interactions..."})]})}),r&&y.length===0&&u.jsx("div",{className:"flex flex-1 items-center justify-center rounded-xl border border-dashed border-gray-800 bg-gray-900/20 p-12 text-center",children:u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-gray-500",children:c?"No interactions match your search.":"No interactions require attention."}),c&&u.jsx("button",{onClick:()=>d(""),className:"mt-2 text-xs font-semibold text-primary-500 hover:text-primary-400",children:"Clear search"})]})}),r&&y.length>0&&u.jsx("div",{className:"flex-1 overflow-hidden",children:u.jsx(x1,{style:{height:"100%"},data:y,itemContent:(v,k)=>u.jsx("div",{className:"pb-4 pr-4",children:u.jsx(rq,{interaction:k,onDismiss:w=>void m(w),onClaim:h})})})})]})}async function iq(e,t,n){var r;try{const a=await fetch("/api/analyze",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:n});if(!a.ok){if((r=a.headers.get("content-type"))!=null&&r.includes("application/json")){const d=await a.json();t.onError(d.error??`HTTP ${a.status}`)}else t.onError(`HTTP ${a.status}`);return}if(!a.body){t.onError("No response stream");return}const s=a.body.getReader(),o=new TextDecoder;let c="";for(;;){const{done:d,value:p}=await s.read();if(d)break;c+=o.decode(p,{stream:!0});const m=c.split(`
|
|
391
391
|
`);c=m.pop()??"";for(const h of m){if(!h.startsWith("data: "))continue;const b=h.slice(6).trim();if(b==="[DONE]"){t.onDone();return}try{const y=JSON.parse(b);if(typeof y!="object"||y===null||!("type"in y))continue;const v=y;switch(v.type){case"status":t.onStatus(v.text);break;case"sel_result":t.onSEL(v.data);break;case"cml_result":t.onCML(v.data);break;case"pesl_result":t.onPESL(v.data);break;case"signals":t.onSignals(v.data);break;case"error":t.onError(v.error);return}}catch{}}}t.onDone()}catch(a){a.name!=="AbortError"&&t.onError(a.message??"Stream failed")}}function lo({value:e,label:t,color:n}){const r=Math.round(e*100),s={"text-primary-500":"bg-primary-500","text-secondary-400":"bg-secondary-400","text-accent-500":"bg-accent-500","text-blue-400":"bg-blue-400","text-purple-400":"bg-purple-400","text-yellow-400":"bg-yellow-400","text-emerald-400":"bg-emerald-400"}[n]||"bg-gray-600";return u.jsxs("div",{className:"space-y-1",children:[u.jsxs("div",{className:"flex justify-between text-xs",children:[u.jsx("span",{className:"text-gray-400",children:t}),u.jsxs("span",{className:n,children:[r,"%"]})]}),u.jsx("div",{className:"h-1.5 w-full rounded-full bg-gray-800",children:u.jsx(J.div,{initial:{width:0},animate:{width:`${r}%`},transition:{duration:.6,ease:"easeOut"},className:`h-full rounded-full ${s}`})})]})}const fT={low:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",medium:"bg-yellow-500/10 text-yellow-400 border-yellow-500/20",high:"bg-orange-500/10 text-orange-400 border-orange-500/20",critical:"bg-red-500/10 text-red-400 border-red-500/20"};function sq({level:e}){return u.jsx("span",{className:`inline-block rounded-md border px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest ${fT[e]??fT.medium}`,children:e})}const oq={local:"text-emerald-400",human:"text-amber-400","simulation-required":"text-purple-400"};function lq({data:e}){return u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-lg border border-gray-800 bg-gray-900 p-5 space-y-4",children:[u.jsx("h3",{className:"text-xs font-semibold uppercase tracking-widest text-primary-500",children:"Spec Enrichment (SEL)"}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Intent"}),u.jsx("p",{className:"mt-1 text-sm text-white",children:e.intent})]}),u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Summary"}),u.jsx("p",{className:"mt-1 text-sm text-gray-300 leading-relaxed",children:e.summary})]}),e.affectedSystems.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Affected Systems"}),u.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:e.affectedSystems.map(t=>u.jsxs("span",{className:"rounded-md bg-blue-500/10 border border-blue-500/20 px-2 py-0.5 text-[10px] font-medium text-blue-400",title:`Confidence: ${Math.round(t.confidence*100)}% | Tests: ${t.testCoverage} | Deps: ${t.transitiveDeps.length}`,children:[t.name,t.graphNodeId&&u.jsxs("span",{className:"ml-1 text-blue-500/50",children:[Math.round(t.confidence*100),"%"]})]},t.name))})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.unknowns.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-amber-500",children:["Unknowns (",e.unknowns.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.unknowns.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.ambiguities.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-orange-500",children:["Ambiguities (",e.ambiguities.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.ambiguities.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.riskSignals.length>0&&u.jsxs("div",{children:[u.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-red-500",children:["Risk Signals (",e.riskSignals.length,")"]}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.riskSignals.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]})]})]})}function uq({data:e}){return u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-lg border border-gray-800 bg-gray-900 p-5 space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"text-xs font-semibold uppercase tracking-widest text-secondary-400",children:"Complexity Model (CML)"}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(sq,{level:e.riskLevel}),u.jsx("span",{className:`text-xs font-mono font-bold ${oq[e.recommendedRoute]??"text-gray-400"}`,children:e.recommendedRoute})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(lo,{value:e.overall,label:"Overall",color:"text-primary-500"}),u.jsx(lo,{value:e.dimensions.structural,label:"Structural",color:"text-secondary-400"}),u.jsx(lo,{value:e.dimensions.semantic,label:"Semantic",color:"text-accent-500"}),u.jsx(lo,{value:e.dimensions.historical,label:"Historical",color:"text-yellow-400"}),u.jsx(lo,{value:e.confidence,label:"Confidence",color:"text-emerald-400"})]}),u.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 pt-2 border-t border-gray-800",children:[u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.services}),u.jsx("span",{className:"text-[10px] text-gray-500 uppercase tracking-widest",children:"Services"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.modules}),u.jsx("span",{className:"text-[10px] text-gray-500 uppercase tracking-widest",children:"Modules"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.filesEstimated}),u.jsx("span",{className:"text-[10px] text-gray-500 uppercase tracking-widest",children:"Files"})]}),u.jsxs("div",{className:"text-center",children:[u.jsx("span",{className:"block text-lg font-bold text-white",children:e.blastRadius.testFilesAffected}),u.jsx("span",{className:"text-[10px] text-gray-500 uppercase tracking-widest",children:"Test Files"})]})]}),e.reasoning.length>0&&u.jsxs("div",{className:"pt-2 border-t border-gray-800",children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Reasoning"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.reasoning.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]})}function cq({data:e}){return u.jsxs(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"rounded-lg border border-gray-800 bg-gray-900 p-5 space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"text-xs font-semibold uppercase tracking-widest text-amber-400",children:"Simulation (PESL)"}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"font-mono text-[10px] text-gray-500 uppercase",children:e.tier}),e.abort&&u.jsx("span",{className:"rounded-md bg-red-500/10 border border-red-500/20 px-2 py-0.5 text-[10px] font-bold uppercase text-red-400",children:"Abort Recommended"}),u.jsxs("span",{className:`text-sm font-bold ${e.executionConfidence>=.7?"text-emerald-400":e.executionConfidence>=.4?"text-yellow-400":"text-red-400"}`,children:[Math.round(e.executionConfidence*100),"% confidence"]})]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.simulatedPlan.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Simulated Plan"}),u.jsx("ol",{className:"mt-1 space-y-0.5 list-decimal list-inside",children:e.simulatedPlan.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-300",children:t},n))})]}),e.predictedFailures.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-red-500",children:"Predicted Failures"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.predictedFailures.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.riskHotspots.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-orange-500",children:"Risk Hotspots"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.riskHotspots.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]}),e.testGaps.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-amber-500",children:"Test Gaps"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.testGaps.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]}),e.recommendedChanges.length>0&&u.jsxs("div",{className:"pt-2 border-t border-gray-800",children:[u.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-gray-500",children:"Recommended Changes"}),u.jsx("ul",{className:"mt-1 space-y-0.5",children:e.recommendedChanges.map((t,n)=>u.jsx("li",{className:"text-xs text-gray-400",children:t},n))})]})]})}function dq({signals:e}){return u.jsx(J.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex flex-wrap gap-2",children:e.map((t,n)=>u.jsx("span",{className:"rounded-md bg-red-500/10 border border-red-500/20 px-3 py-1 text-xs font-medium text-red-400",title:t.reason,children:t.name},n))})}function pq(e,t,n,r){const a=[`# Spec: ${e}`,""];if(a.push(`**Generated:** ${new Date().toISOString()}`),n&&(a.push(`**Route Recommendation:** ${n.recommendedRoute}`),a.push(`**Risk Level:** ${n.riskLevel}`)),a.push(""),t&&(a.push("## Intent","",t.intent,""),a.push("## Summary","",t.summary,""),t.affectedSystems.length>0)){a.push("## Affected Systems","");for(const s of t.affectedSystems)a.push(`- ${s.name}`);a.push("")}if(n&&(a.push("## Complexity Score",""),a.push(`- **Overall:** ${Math.round(n.overall*100)}%`),a.push(`- **Structural:** ${Math.round(n.dimensions.structural*100)}%`),a.push(`- **Semantic:** ${Math.round(n.dimensions.semantic*100)}%`),a.push(`- **Historical:** ${Math.round(n.dimensions.historical*100)}%`),a.push(`- **Blast Radius:** ${n.blastRadius.services} services, ${n.blastRadius.modules} modules, ~${n.blastRadius.filesEstimated} files`),a.push("")),t){if(t.unknowns.length>0){a.push("## Unknowns","");for(const s of t.unknowns)a.push(`- ${s}`);a.push("")}if(t.ambiguities.length>0){a.push("## Ambiguities","");for(const s of t.ambiguities)a.push(`- ${s}`);a.push("")}if(t.riskSignals.length>0){a.push("## Risk Signals","");for(const s of t.riskSignals)a.push(`- ${s}`);a.push("")}}if(r){if(a.push("## Simulation (PESL)",""),a.push(`**Execution Confidence:** ${Math.round(r.executionConfidence*100)}%`),a.push(""),r.simulatedPlan.length>0&&(a.push("### Simulated Plan",""),r.simulatedPlan.forEach((s,o)=>a.push(`${o+1}. ${s}`)),a.push("")),r.predictedFailures.length>0){a.push("### Predicted Failures","");for(const s of r.predictedFailures)a.push(`- ${s}`);a.push("")}if(r.recommendedChanges.length>0){a.push("### Recommended Changes","");for(const s of r.recommendedChanges)a.push(`- ${s}`);a.push("")}}return a.join(`
|
|
392
392
|
`)}function Lu({icon:e,label:t,doneLabel:n,onClick:r,disabled:a,pending:s,done:o,title:c,color:d="border-gray-700 text-gray-400 hover:border-primary-500/50 hover:text-primary-400"}){return u.jsxs(J.button,{...a?{}:{whileHover:{scale:1.02},whileTap:{scale:.98}},onClick:r,disabled:a||s||o,...c!=null?{title:c}:{},className:`flex items-center gap-2 rounded-lg border px-4 py-2.5 text-xs font-bold uppercase tracking-wider transition-all disabled:cursor-not-allowed disabled:opacity-30 ${o?"border-emerald-500/30 text-emerald-400":d}`,children:[s?u.jsx("div",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):o?u.jsx(Nh,{size:14}):e,o?n:t]})}function fq(){const[e,t]=N.useState(""),[n,r]=N.useState(""),[a,s]=N.useState(""),[o,c]=N.useState(!1),[d,p]=N.useState(null),[m,h]=N.useState(null),[b,y]=N.useState(null),[v,k]=N.useState(null),[w,E]=N.useState(null),[T,A]=N.useState(null),[_,j]=N.useState("idle"),[D,R]=N.useState(null),P=N.useRef(null),B=b||v||w||T,O=!o&&B;N.useEffect(()=>{if(_==="roadmap-done"||_==="dispatch-done"){const ee=setTimeout(()=>j("idle"),3e3);return()=>clearTimeout(ee)}},[_]);const $=N.useCallback(async()=>{if(!e.trim()||o)return;h(null),y(null),k(null),E(null),A(null),p(null),c(!0);const ee=new AbortController;P.current=ee;const W=a.split(",").map(C=>C.trim()).filter(Boolean),re={title:e.trim()};n.trim()&&(re.description=n.trim()),W.length>0&&(re.labels=W),await iq(re,{onStatus:p,onSEL:C=>{y(C),p(null)},onCML:C=>{k(C),p(null)},onPESL:C=>{E(C),p(null)},onSignals:C=>{A(C),p(null)},onError:C=>{h(C),c(!1),p(null)},onDone:()=>{c(!1),p(null)}},ee.signal)},[e,n,a,o]),H=N.useCallback(()=>{var ee;(ee=P.current)==null||ee.abort(),c(!1),p(null)},[]),Z=N.useCallback(async()=>{j("roadmap-pending"),R(null);try{const ee=await fetch("/api/roadmap/append",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.trim(),summary:b==null?void 0:b.summary,enrichedSpec:b?{intent:b.intent,unknowns:b.unknowns,ambiguities:b.ambiguities,riskSignals:b.riskSignals,affectedSystems:b.affectedSystems.map(W=>({name:W.name}))}:void 0,cmlRecommendedRoute:v==null?void 0:v.recommendedRoute})});if(!ee.ok){const W=await ee.json();throw new Error(W.error??`HTTP ${ee.status}`)}j("roadmap-done")}catch(ee){R(ee.message),j("idle")}},[e,b,v]),q=N.useCallback(async()=>{j("dispatch-pending"),R(null);try{const ee=a.split(",").map(re=>re.trim()).filter(Boolean),W=await fetch("/api/dispatch/adhoc",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.trim(),description:n.trim()||void 0,labels:ee.length>0?ee:void 0})});if(!W.ok){const re=await W.json();throw new Error(re.error??`HTTP ${W.status}`)}j("dispatch-done")}catch(ee){R(ee.message),j("idle")}},[e,n,a]),Y=N.useCallback(()=>{var re;if(!b)return;const ee=[];n.trim()&&ee.push(n.trim());const W=[];for(const C of b.unknowns)W.push(`- Unknown: ${C}`);for(const C of b.ambiguities)W.push(`- Ambiguity: ${C}`);W.length>0&&ee.push("","---","Suggested clarifications from analysis:",...W),r(ee.join(`
|