@open-mercato/cezar 0.15.2-pr1447.3107 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/skills-update.d.ts +0 -3
- package/dist/skills-update.js +2 -10
- package/dist/skills-update.js.map +1 -1
- package/dist/telemetry-service.json +1 -0
- package/package.json +3 -3
- package/web/dist/assets/{agent-task-pickers-D_OQwnko.js → agent-task-pickers-C-rOsLnA.js} +1 -1
- package/web/dist/assets/automations-route-UzAUdv-r.js +1 -0
- package/web/dist/assets/{commit-list-DTBP41tD.js → commit-list-aFd0UsXK.js} +1 -1
- package/web/dist/assets/compare-variants-DR0CiQWw.js +1 -0
- package/web/dist/assets/{composer-f4AXANQy.js → composer-G626Ezh_.js} +2 -2
- package/web/dist/assets/{dashboard-C1mwFC4C.js → dashboard-DAjv056O.js} +2 -2
- package/web/dist/assets/{diff-Db7J9-1q.js → diff-DItiiWPs.js} +2 -2
- package/web/dist/assets/{diff-view-DnGSA7so.js → diff-view-CZg35276.js} +1 -1
- package/web/dist/assets/{file-preview-FrUzT5oU.js → file-preview-g_OAxH_c.js} +1 -1
- package/web/dist/assets/github-BxPp6Ok6.js +1 -0
- package/web/dist/assets/index-DUhrduZ3.js +21 -0
- package/web/dist/assets/{project-router-Bbjch1Od.js → project-router-Bp0y3Wss.js} +1 -1
- package/web/dist/assets/{reference-chip-Bj-3A7KY.js → reference-chip-BY5hNSAj.js} +1 -1
- package/web/dist/assets/{reference-overflow-akntoVya.js → reference-overflow-qtIEQOUG.js} +1 -1
- package/web/dist/assets/repo-git-D6HYGT9U.js +1 -0
- package/web/dist/assets/{run-diff-CPrDJf4d.js → run-diff-Cerx-k73.js} +2 -2
- package/web/dist/assets/run-header-BXD65PK7.js +1 -0
- package/web/dist/assets/skills-CNMsR9rN.js +1 -0
- package/web/dist/assets/{tab-link-BZ9c9R8j.js → tab-link-I7VPbxny.js} +1 -1
- package/web/dist/assets/{task-changes-CdaU1MMG.js → task-changes-CBAIhtoq.js} +1 -1
- package/web/dist/assets/{task-commits-CDsqvtev.js → task-commits-B-qT0GSg.js} +1 -1
- package/web/dist/assets/task-composer-40NbgA4F.js +12 -0
- package/web/dist/assets/{task-files-DrpoiNnU.js → task-files-CFnfuW1J.js} +1 -1
- package/web/dist/assets/{task-graph-4DuqoXmM.js → task-graph-Cj0V7t7y.js} +1 -1
- package/web/dist/assets/{task-notes-Nt0GCLMA.js → task-notes-BCf-8JWr.js} +1 -1
- package/web/dist/assets/{task-thread-kGNKArqC.js → task-thread-AaQ3ayCT.js} +4 -4
- package/web/dist/assets/tracker-D6J0H891.js +4 -0
- package/web/dist/assets/use-automations-gfSKvY5Q.js +5 -0
- package/web/dist/assets/{use-now-B8VxwDYO.js → use-now-Dso5ls9n.js} +1 -1
- package/web/dist/assets/{workflow-graph-CFqe6uQR.js → workflow-graph-C_5mKuH_.js} +3 -3
- package/web/dist/index.html +7 -7
- package/web/dist/assets/automations-route-hHvqPIth.js +0 -1
- package/web/dist/assets/compare-variants-kEeeTxE7.js +0 -1
- package/web/dist/assets/github-DYJu_wkB.js +0 -1
- package/web/dist/assets/index-CqWWWJTj.js +0 -21
- package/web/dist/assets/repo-git-COMD-gnL.js +0 -1
- package/web/dist/assets/run-header-BPDeWJbZ.js +0 -1
- package/web/dist/assets/skills-CoZiiNzR.js +0 -1
- package/web/dist/assets/task-composer-CWZkMjD0.js +0 -12
- package/web/dist/assets/tracker-BFLM_t1d.js +0 -4
- package/web/dist/assets/use-automations-B7o3Xbrw.js +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{$n as r,Bn as i,Cn as a,Ei as o,H as s,Kn as c,Lr as l,Rn as u,an as d,ca as f,ea as p,ni as m,nt as h,oa as g,qi as _,ra as v,rn as y}from"./project-router-Bbjch1Od.js";import{$ as b,F as x,Q as S,X as C,Y as w,Z as T,et as ee,gt as E,nt as D,t as O}from"./button-Cz2i1VWG.js";import{A as te,C as ne,E as re,M as k,N as A,O as j,P as M,T as ie,_ as ae,b as oe,c as se,d as ce,f as le,g as ue,h as de,i as fe,j as pe,m as me,p as he,v as ge,w as _e,x as ve,y as ye}from"./use-automations-B7o3Xbrw.js";import{a as be,i as xe,o as Se,r as Ce,t as we}from"./sheet-D3Gui9Gi.js";import{S as Te,a as Ee,o as De,r as Oe,t as ke}from"./reference-chip-Bj-3A7KY.js";import{a as Ae,f as N,p as je,r as Me}from"./automation-format-x-IsIfyB.js";import{i as Ne,n as Pe,p as Fe,r as Ie,t as Le}from"./tooltip-CxsyqHYQ.js";import{t as Re}from"./chevron-right-qEQMQjVX.js";import{t as ze}from"./download-CNAZsQUZ.js";import{i as P,r as F,t as Be}from"./token-metrics-CCt2gB1-.js";import{t as Ve}from"./use-now-B8VxwDYO.js";import{t as He}from"./index-CqWWWJTj.js";var Ue=x(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),We=x(`arrow-down-left`,[[`path`,{d:`M17 7 7 17`,key:`15tmo1`}],[`path`,{d:`M17 17H7V7`,key:`1org7z`}]]),Ge=x(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Ke=x(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),qe=x(`grip-horizontal`,[[`circle`,{cx:`12`,cy:`9`,r:`1`,key:`124mty`}],[`circle`,{cx:`19`,cy:`9`,r:`1`,key:`1ruzo2`}],[`circle`,{cx:`5`,cy:`9`,r:`1`,key:`1a8b28`}],[`circle`,{cx:`12`,cy:`15`,r:`1`,key:`1e56xg`}],[`circle`,{cx:`19`,cy:`15`,r:`1`,key:`1a92ep`}],[`circle`,{cx:`5`,cy:`15`,r:`1`,key:`5r1jwy`}]]),Je=x(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]),I=e(t(),1);function Ye(e){let t=Date.parse(e.nextRunAt??``),n=Date.parse(e.state?.backoffUntil??``);return Number.isFinite(t)?Math.max(t,Number.isFinite(n)?n:t):null}function Xe(e){return e.flatMap(e=>(e.data?.automations??[]).filter(e=>e.enabled).map(t=>({project:e,automation:t,at:Ye(t)}))).sort((e,t)=>(e.at??1/0)-(t.at??1/0)||e.project.id.localeCompare(t.project.id)||e.automation.id.localeCompare(t.automation.id))}function Ze(e){let t=h(),n=f(),i=t.data?.projects??[],a=t.data?.bootProject,s=a&&!i.some(e=>e.id===a)?[...i,{id:a,name:a,status:`ok`}]:i,c=g({queryKey:[...d.dashboard,`automations`,s.map(e=>[e.id,e.name,e.status])],enabled:e&&!!t.data,queryFn:async({signal:e})=>{let t=0,n=[];return await Promise.all([0,1].map(async()=>{for(;t<s.length&&!e.aborted;){let i=s[t++];if(i.status===`missing`){n.push({...i,error:`Project folder unavailable`});continue}try{let t=D.parse(await o(await r.api.v1.workspace.dashboard.automations.$get({query:{projectId:i.id}},{init:{signal:e}}),`/workspace/dashboard/automations`));n.push({id:i.id,name:i.name,data:t})}catch{n.push({id:i.id,name:i.name,error:`Could not load automations`})}}})),n}});return(0,I.useEffect)(()=>{if(e)return j(e=>{e===`automation-change`&&n.invalidateQueries({queryKey:[...d.dashboard,`automations`]})})},[n,e]),{...c,registry:t,retry:()=>{t.refetch(),c.refetch()}}}var L=n();function R({rows:e}){return(0,L.jsx)(`span`,{hidden:!0,"data-dashboard-export":JSON.stringify(e)})}var z=`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,B=`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,Qe=`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden`;function V(){return(0,L.jsx)(Re,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-soft-foreground transition-transform duration-150 motion-reduce:transition-none [details[open]>summary>&]:rotate-90`})}var $e=`flex items-center gap-2 text-xs text-muted-foreground`;function et({className:e=``,...t}){return(0,L.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,L.jsx)(`select`,{...t,className:`h-9 cursor-pointer appearance-none rounded-md border bg-card-2 pr-8 pl-3 font-mono text-xs text-foreground outline-none transition-colors hover:border-foreground/20 hover:bg-muted focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 no-hover:min-h-11 ${e}`}),(0,L.jsx)(Fe,{"aria-hidden":`true`,className:`pointer-events-none absolute top-1/2 right-2.5 size-3.5 -translate-y-1/2 text-soft-foreground`})]})}var tt=`relative min-w-0 overflow-hidden rounded-lg border bg-card-2 p-4 transition-colors before:absolute before:inset-x-0 before:top-0 before:h-px before:opacity-80 hover:border-foreground/20 hover:bg-muted/40 sm:p-5`,H={violet:`before:bg-violet`,info:`before:bg-info`,success:`before:bg-success`,danger:`before:bg-danger`,primary:`before:bg-primary`,neutral:`before:bg-border`};function nt({label:e,value:t,icon:n,children:r}){return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`flex w-full items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] font-medium uppercase tracking-[0.12em] text-muted-foreground`,children:e}),(0,L.jsx)(`span`,{className:`text-soft-foreground`,"aria-hidden":`true`,children:n})]}),(0,L.jsx)(`span`,{className:`mt-4 block text-4xl font-semibold leading-none tracking-tight tabular-nums`,children:t}),(0,L.jsx)(`span`,{className:`mt-3 block text-xs text-soft-foreground`,children:r})]})}function rt({at:e}){return(0,L.jsxs)(`time`,{dateTime:e,title:new Date(e).toLocaleString(),children:[`Updated `,F(e),` ago`]})}function it(){let e=fe(),t=Ze(e.known&&!e.off),n=Ve(3e4),[r,i]=(0,I.useState)(!1),a=Xe(t.data??[]),o=r?a:a.slice(0,3),s=t.data?.filter(e=>e.error)??[],c=!e.known||!t.registry.isError&&(t.registry.isPending||t.isPending),l=t.isError||t.registry.isError||s.length>0;return(0,L.jsxs)(N,{"data-export-context":`Enabled automations · showing ${o.length} of ${a.length} loaded · ${l?`partial coverage`:`available projects`}`,className:`min-w-0 gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsxs)(`h2`,{className:`flex items-center ${z}`,children:[`Automations`,(0,L.jsx)(je,{className:`ml-2 size-3.5 text-soft-foreground`,"aria-hidden":`true`})]}),!e.off&&t.data&&(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:[a.length,` enabled`,l?` · partial`:``]})]}),!e.off&&t.data&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R,{rows:[{section:`automations`,metric:`enabled`,value:a.length,unit:`automations`,note:l?`Partial project coverage`:`Loaded projects`}]}),t.dataUpdatedAt>0&&(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:new Date(t.dataUpdatedAt).toISOString()})})]}),e.off?(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Automations are disabled in this workspace.`}):(0,L.jsxs)(L.Fragment,{children:[c&&(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading automations…`}),l&&(0,L.jsxs)(`div`,{role:`alert`,className:`p-4 text-sm`,children:[(0,L.jsx)(`p`,{children:`Some automation data could not be refreshed. Available results are shown.`}),s.map(e=>(0,L.jsxs)(`p`,{children:[e.name,`: `,e.error]},e.id)),(0,L.jsx)(O,{variant:`ghost`,onClick:t.retry,children:`Retry automations`})]}),!c&&!l&&a.length===0&&(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No enabled automations. Enable one in a project's Automations page.`}),o.map(({project:e,automation:t,at:r})=>{let i=(t.state?.consecutiveFailures??0)>0?`Recent checks failed`:void 0,a=r===null?`Next time not available`:r<=n?`Due — awaiting scheduler`:Ae(r,n),o=t.kind===`schedule`?`Next run`:`Next check`;return(0,L.jsxs)(`div`,{"data-export-row":!0,className:`border-b px-4 py-3 transition-colors last:border-0 hover:bg-muted/30`,children:[(0,L.jsx)(_,{className:`block min-h-11 text-sm font-medium hover:underline`,to:`/p/${encodeURIComponent(e.id)}/automations/${encodeURIComponent(t.id)}`,children:t.name}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.name,` · `,o,`: `,a]}),r!==null&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:(0,L.jsxs)(`time`,{dateTime:new Date(r).toISOString(),children:[Me(r,e.data.timeZone),` · `,e.data.timeZone]})}),t.kind!==`schedule`&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Checks for matching events; a task may not be started.`}),i&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-warning`,children:i}),(0,L.jsx)(R,{rows:[{section:`automation`,entity:`${e.id}:${t.id}`,metric:`name`,value:t.name},{section:`automation`,entity:`${e.id}:${t.id}`,metric:t.kind===`schedule`?`nextRunAt`:`nextCheckAt`,value:r===null?null:new Date(r).toISOString(),note:[a,i].filter(Boolean).join(` · `)}]})]},`${e.id}:${t.id}`)}),a.length>3&&(0,L.jsx)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>i(!r),children:r?`Show fewer`:`Show all ${a.length} enabled`}),!c&&(0,L.jsxs)(`details`,{className:`border-t px-4 py-2 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden min-h-11`,"data-export-heading":`Project automations`,children:[(0,L.jsx)(V,{}),`Manage automations by project`]}),t.data?.map(e=>(0,L.jsx)(_,{className:`block min-h-11 py-3 hover:underline`,to:`/p/${encodeURIComponent(e.id)}/automations`,children:e.name},e.id))]})]})]})}function at(e,t,n){let r=new Set,i=new Map(e.map((e,t)=>[n(e),{r:e,i:t}]));return t.forEach((e,t)=>{let a=i.get(n(e));(!a||a.i!==t||JSON.stringify(a.r)!==JSON.stringify(e))&&r.add(n(e)),i.delete(n(e))}),i.forEach((e,t)=>r.add(t)),r}function ot(e,t,n){let r=new Map(t.map(e=>[n(e),e]));return e.map(e=>({row:r.get(n(e))??e,removed:!r.has(n(e))}))}var st=(0,I.createContext)(``),ct=(0,I.createContext)(!0),U=new Map;function lt(e,t,n=``,r=0,i){let a=(0,I.useContext)(st),o=`${a}:${n}`,[s,c]=(0,I.useState)(()=>U.get(o)),[l,u]=(0,I.useState)(o),d=(0,I.useRef)(r),f=(0,I.useRef)(!1);l!==o&&(u(o),c(U.get(o)),d.current=r,f.current=!1),d.current!==r&&(d.current=r,f.current=!0),(0,I.useEffect)(()=>{e&&(!s||f.current)&&(c(e),f.current=!1)},[s,e]);let p=(0,I.useMemo)(()=>({current:s}),[o]);p.current=s,(0,I.useEffect)(()=>()=>{!a||!p.current||(U.delete(o),U.set(o,p.current),U.size>60&&U.delete(U.keys().next().value))},[a,o,p]);let m=s??e??[],h=new Set((e??m).map(t)),g=i?m.filter(e=>h.has(t(e))||i(e)):m;return{rows:ot(g,e??m,t),updates:e?at(g,e,t).size:0,show:()=>c(e)}}var ut=new Map;function dt(e){return ut.get(e)}function ft(e,t){ut.delete(e),ut.set(e,t),ut.size>20&&ut.delete(ut.keys().next().value)}var W=new Map;function pt(e,t){return W.get(e)?.[t]}function mt(e,t,n){let r=W.get(e)??{};r[t]=n,W.delete(e),W.set(e,r),W.size>20&&W.delete(W.keys().next().value)}var G=e=>`${e.projectId}:${e.id}`;function ht({row:e,removed:t=!1,queue:n=!1,checking:r=!1,checkFailed:o=!1,kicker:s}){let c=(0,I.useContext)(ct)&&!r&&!o,l=M(e);t=t||l===null||n&&l?.archived===!0,l&&(e={...e,status:l.status,awaitingAnswerSince:l.awaitingAnswerSince});let d=u(e),f=n&&!i(e),p=t||f||!c;return(0,L.jsxs)(`div`,{"data-dashboard-row":G(e),className:`min-w-0 border-b px-4 py-3 transition-colors last:border-0 hover:bg-muted/30`,children:[(0,L.jsx)(R,{rows:[{section:`task`,entity:G(e),metric:`title`,value:e.titleSummary||e.title},{section:`task`,entity:G(e),metric:`status`,value:p?`Not currently actionable`:e.status},{section:`task`,entity:G(e),metric:`createdAt`,value:e.createdAt}]}),s&&(0,L.jsx)(`p`,{className:`mb-1 pl-[15px] font-mono text-[10.5px] uppercase tracking-[0.1em] text-soft-foreground`,children:s}),(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(P,{tone:d.tone,className:`mt-[7px]`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(_,{tabIndex:p?-1:void 0,"aria-disabled":p||void 0,onClick:e=>{p&&e.preventDefault()},to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,className:`block break-words text-sm font-medium leading-relaxed hover:underline no-hover:min-h-11`,children:e.titleSummary||e.title}),(0,L.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:e.projectId}),(0,L.jsx)(`span`,{children:o?`Could not check current state`:c?t?n&&l!==null?`No longer needs you`:`Task removed`:f?`No longer needs you`:d.label:`Checking current state…`}),(0,L.jsx)(`span`,{children:F(e.createdAt)}),e.dispatch&&(0,L.jsx)(`span`,{children:`Subtask`}),!p&&a(e).map(t=>(0,L.jsx)(ke,{reference:t,taskTitle:e.title,projectId:e.projectId,className:`no-hover:min-h-11`},`${t.kind}:${t.number}`))]})]})]})]})}function K({coverage:e,count:t,retry:n}){let r=e.projects.filter(e=>e.state!==`complete`);return r.length?(0,L.jsxs)(`div`,{className:`rounded-lg border border-pending/40 bg-card-2 p-3 text-sm`,role:`status`,children:[(0,L.jsxs)(`p`,{children:[t===void 0?``:`${t} tasks need you in the available data. Complete coverage: ${e.projects.length-r.length} of ${e.projects.length} projects. `,r.length===1?r[0].state===`unavailable`?`One project is unavailable.`:`One project has incomplete coverage.`:`${r.length} projects have incomplete coverage.`]}),(0,L.jsxs)(`details`,{className:`mt-2`,children:[(0,L.jsxs)(`summary`,{className:`${Qe} min-h-11`,children:[(0,L.jsx)(V,{}),`View unavailable `,r.length===1?`project`:`projects`]}),r.map(e=>(0,L.jsxs)(`p`,{children:[e.projectId,`: `,e.reason??e.state,e.omittedRuns>0?` · ${e.omittedRuns} omitted tasks`:``]},e.projectId))]}),(0,L.jsx)(O,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Retry`})]}):null}function gt(e,t=!1){return e==null?`Unavailable`:t?`$${e.toFixed(e===0||e>=1?2:Math.min(20,Math.max(4,Math.ceil(-Math.log10(e))+1)))}`:e.toLocaleString(`en-US`)}function q(e){return e===null?`Unavailable`:e<1?`${Math.round(e*60)}m`:e<48?`${e.toFixed(1)}h`:`${(e/24).toFixed(1)}d`}function _t(e,t,n){let r=p(),i=r.state?.dashboardEntry??r.key,[a,o]=v(),s=a.get(e);return[s!==null&&t.includes(s)?s:n,t=>o(n=>{let r=new URLSearchParams(n);return r.set(e,t),r},{replace:!0,state:{...r.state,dashboardEntry:i}})]}var vt=e=>`Last ${e===`7d`?7:30} calendar days`,yt=`font-mono text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground`,bt=`min-w-0 rounded-lg border bg-card-2 p-4`,J=`whitespace-nowrap px-3 py-2 font-mono text-[11px] font-medium uppercase tracking-[0.1em] text-soft-foreground`;function xt(){let e=h().data?.projects;return t=>e?.find(e=>e.id===t)?.name??t}var St=(e,t)=>`/p/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}`;function Ct({label:e,value:t,onChange:n}){return(0,L.jsxs)(`label`,{className:$e,children:[e,(0,L.jsxs)(et,{value:t,onChange:e=>n(e.target.value===`30d`?`30d`:`7d`),children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})}function wt({query:e}){return e.isPending?(0,L.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading insights…`}):e.isError?(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[e.data?`Showing previous results. `:``,`Could not refresh insights.`,` `,(0,L.jsx)(O,{variant:`outline`,onClick:()=>void e.refetch(),children:`Retry insights`})]}):null}function Tt({period:e,active:t}){let n=He(e,t),r=n.data;return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsx)(wt,{query:n}),r&&(0,L.jsx)(K,{coverage:r.coverage,retry:()=>void n.refetch()}),r&&(0,L.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[(0,L.jsx)(Et,{data:r}),(0,L.jsx)(Dt,{data:r})]})]})}function Et({data:e}){let t=e.delivered,n=[{label:`PRs opened`,value:t.prsOpened,note:`${t.prsTouched} touched`},{label:`Lines`,value:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`text-success`,children:[`+`,t.additions.toLocaleString(`en-US`)]}),` `,(0,L.jsxs)(`span`,{className:`text-danger`,children:[`−`,t.deletions.toLocaleString(`en-US`)]})]})},{label:`Files`,value:t.files.toLocaleString(`en-US`)},{label:`Issues`,value:t.issues}];return(0,L.jsxs)(`section`,{className:bt,"aria-label":`Delivered`,children:[(0,L.jsx)(R,{rows:Object.entries(t).map(([t,n])=>({section:`delivered`,metric:t,value:n,unit:[`additions`,`deletions`].includes(t)?`lines`:t===`files`?`files`:`count`,asOf:e.asOf,note:`Completed since ${e.windowStart}`}))}),(0,L.jsx)(`h3`,{className:yt,children:`Delivered`}),(0,L.jsx)(`dl`,{className:`mt-3 grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-4`,children:n.map(e=>(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`dt`,{className:`text-xs text-soft-foreground`,children:e.label}),(0,L.jsx)(`dd`,{className:`mt-1 truncate text-xl font-semibold tracking-tight tabular-nums`,children:e.value}),e.note&&(0,L.jsx)(`dd`,{className:`text-xs text-soft-foreground`,children:e.note})]},e.label))}),(0,L.jsxs)(`span`,{className:`mt-3 block text-xs text-soft-foreground`,children:[`From `,t.completedTasks,` completed `,t.completedTasks===1?`task`:`tasks`,` ·`,` `,t.measuredTasks,` with a stored diff`]})]})}function Dt({data:e}){let t=xt(),{total:n,reasons:r}=e.failures;return(0,L.jsxs)(`section`,{className:bt,"aria-label":`Why tasks failed`,children:[(0,L.jsx)(R,{rows:r.map(t=>({section:`failures`,entity:t.label,metric:t.category,value:t.count,unit:`tasks`,asOf:e.asOf,note:t.latest.message}))}),(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,L.jsx)(`h3`,{className:yt,children:`Why tasks failed`}),n>0&&(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:[n,` failed`]})]}),n===0?(0,L.jsxs)(`span`,{className:`mt-4 flex items-center gap-2.5 text-sm text-muted-foreground`,children:[(0,L.jsx)(P,{tone:`success`}),`No failed outcomes in this period`]}):(0,L.jsx)(`ul`,{className:`mt-3 space-y-3`,children:r.map(e=>(0,L.jsx)(Ot,{reason:e,total:n,projectName:t},`${e.category}:${e.label}`))})]})}function Ot({reason:e,total:t,projectName:n}){let{latest:r}=e;return(0,L.jsxs)(`li`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-sm`,children:[(0,L.jsx)(`span`,{className:`min-w-0 truncate font-medium`,title:e.label,children:e.label}),(0,L.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:e.count})]}),(0,L.jsx)(`div`,{className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full bg-danger/70`,style:{width:`${e.count/t*100}%`}})}),(0,L.jsxs)(`span`,{className:`mt-1.5 block truncate text-xs text-soft-foreground`,title:r.message,children:[`Latest:`,` `,(0,L.jsx)(_,{className:`text-muted-foreground hover:text-foreground hover:underline`,to:St(r.projectId,r.id),children:r.title}),` `,`· `,n(r.projectId),r.step?` · ${r.step}`:``,` · `,F(r.at),` ago`]})]})}var kt={claude:`Claude Code`,codex:`Codex`,opencode:`OpenCode`,cursor:`Cursor`,pi:`Pi`,unknown:`Unknown backend`,mixed:`Mixed backends`},At=e=>kt[e]??e,jt=(e,t)=>t?Math.round(e/t*100):0;function Mt(){let[e,t]=_t(`backends`,[`7d`,`30d`],`7d`),n=He(e),r=n.data,i=r?.visibility.cost;return(0,L.jsx)(`section`,{"data-dashboard-module":`backends`,className:`min-w-0`,children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Backends: ${vt(e)}; finished tasks`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Backends & models`}),(0,L.jsx)(Ct,{label:`Finished`,value:e,onChange:t})]}),(0,L.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,L.jsx)(wt,{query:n}),r&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Tasks that finished done or failed in the period, by the backend and model their steps ran on. Includes subtasks. Cost is reported USD only.`}),(0,L.jsx)(K,{coverage:r.coverage,retry:()=>void n.refetch()}),r.backends.length?(0,L.jsx)(`div`,{className:`overflow-x-auto`,role:`region`,"aria-label":`Backend comparison`,tabIndex:0,children:(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:J,children:`Backend`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Finished`}),(0,L.jsx)(`th`,{className:J,children:`Success`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Median cycle`}),i&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Reported USD`}),i&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Per completed`})]})}),(0,L.jsx)(`tbody`,{children:r.backends.map(e=>(0,L.jsx)(Nt,{stat:e,cost:!!i},`${e.backend}:${e.model??``}`))})]})}):(0,L.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No finished tasks in this period.`}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:(0,L.jsx)(rt,{at:r.asOf})}),(0,L.jsx)(R,{rows:r.backends.flatMap(e=>[`finished`,`done`,`failed`,`medianCycleHours`].map(t=>({section:`backends`,entity:`${e.backend}${e.model?`:${e.model}`:``}`,metric:t,value:e[t],unit:t===`medianCycleHours`?`hours`:`tasks`,asOf:r.asOf})))})]})]})]})})}function Nt({stat:e,cost:t}){let n=jt(e.done,e.finished),r=e.costUsd?.value;return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2.5`,children:[(0,L.jsx)(`span`,{className:`block font-medium`,children:At(e.backend)}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:e.backend===`mixed`?`steps ran on different backends`:e.model??`default model`})]}),(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:e.finished}),(0,L.jsxs)(`td`,{className:`min-w-40 px-3 py-2.5`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`h-1.5 flex-1 overflow-hidden rounded-full bg-danger/40`,"aria-hidden":`true`,children:(0,L.jsx)(`span`,{className:`block h-full rounded-full bg-success`,style:{width:`${n}%`}})}),(0,L.jsxs)(`span`,{className:`w-10 text-right font-mono text-xs tabular-nums`,children:[n,`%`]})]}),(0,L.jsxs)(`span`,{className:`block text-xs text-soft-foreground`,children:[e.done,` done · `,e.failed,` failed`]})]}),(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:e.timedTasks?q(e.medianCycleHours):`—`}),t&&(0,L.jsxs)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:[r==null?`—`:gt(r,!0),(0,L.jsxs)(`span`,{className:`block text-xs text-soft-foreground`,children:[e.costUsd?.reportedTasks??0,`/`,e.finished,` reported`]})]}),t&&(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:r==null||!e.done?`—`:gt(r/e.done,!0)})]})}function Pt(){let[e,t]=_t(`automations`,[`7d`,`30d`],`7d`),n=fe(),r=He(e),i=Ze(n.known&&!n.off),a=xt(),o=r.data,s=o?.visibility.cost,c=new Map;for(let e of i.data??[])for(let t of e.data?.automations??[])c.set(`${e.id}\u0000${t.id}`,{projectId:e.id,automationId:t.id,name:t.name,enabled:t.enabled,definition:`known`});let l=new Set((i.data??[]).flatMap(e=>e.data&&!e.error?[e.id]:[])),u=i.isError||i.registry.isError||(i.data??[]).some(e=>e.error);for(let e of o?.automations??[]){let t=`${e.projectId}\u0000${e.automationId}`,n=c.get(t);c.set(t,n?{...n,stat:e}:{...e,name:e.automationId,definition:l.has(e.projectId)?`removed`:`unknown`,stat:e})}let d=[...c.values()].sort((e,t)=>(t.stat?.tasks??0)-(e.stat?.tasks??0)||Number(t.enabled??!1)-Number(e.enabled??!1)||e.name.localeCompare(t.name));return(0,L.jsx)(`section`,{"data-dashboard-module":`automation-outcomes`,className:`min-w-0`,children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Automation outcomes: tasks created in ${vt(e)}`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Automation outcomes`}),(0,L.jsx)(Ct,{label:`Launched`,value:e,onChange:t})]}),(0,L.jsx)(`div`,{className:`space-y-3 p-4`,children:n.off?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Automations are disabled in this workspace.`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(wt,{query:r}),o&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Tasks each automation created in the period and how they ended. Active means still running, queued, waiting on you, or waiting to resume after a usage limit.`}),(0,L.jsx)(K,{coverage:o.coverage,retry:()=>void r.refetch()}),u&&(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[`Some automation details could not be loaded. Their outcomes are shown by id.`,` `,(0,L.jsx)(O,{variant:`ghost`,onClick:i.retry,children:`Retry automations`})]}),d.length?(0,L.jsx)(`div`,{className:`overflow-x-auto`,role:`region`,"aria-label":`Automation outcomes`,tabIndex:0,children:(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:J,children:`Automation`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Tasks`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Done`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Failed`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Active`}),(0,L.jsx)(`th`,{className:J,children:`Last run`}),s&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Reported USD`})]})}),(0,L.jsx)(`tbody`,{children:d.map(e=>(0,L.jsx)(Ft,{row:e,cost:!!s,projectName:a},`${e.projectId}:${e.automationId}`))})]})}):(0,L.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No automations yet. Create one in a project's Automations page.`}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:(0,L.jsx)(rt,{at:o.asOf})}),(0,L.jsx)(R,{rows:d.flatMap(e=>[`tasks`,`done`,`failed`,`active`].map(t=>({section:`automation-outcomes`,entity:`${e.projectId}:${e.automationId}`,metric:t,value:e.stat?.[t]??0,unit:`tasks`,asOf:o.asOf,note:e.name})))})]})]})})]})})}function Ft({row:e,cost:t,projectName:n}){let r=e.stat,i=`px-3 py-2.5 text-right tabular-nums`,a=e=>e||(0,L.jsx)(`span`,{className:`text-soft-foreground`,children:`0`});return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2.5`,children:[e.definition===`removed`?(0,L.jsx)(`span`,{className:`block font-medium`,children:e.name}):(0,L.jsx)(_,{className:`block font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/automations/${encodeURIComponent(e.automationId)}`,children:e.name}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-soft-foreground`,children:[(0,L.jsx)(P,{tone:e.enabled?`success`:`neutral`}),n(e.projectId),` ·`,` `,e.definition===`removed`?`Removed`:e.definition===`unknown`?`Details unavailable`:e.enabled?`Enabled`:`Disabled`]})]}),(0,L.jsx)(`td`,{className:i,children:a(r?.tasks)}),(0,L.jsx)(`td`,{className:i,children:a(r?.done)}),(0,L.jsx)(`td`,{className:`${i} ${r?.failed?`text-danger`:``}`,children:a(r?.failed)}),(0,L.jsx)(`td`,{className:i,children:a(r?.active)}),(0,L.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2.5 text-xs text-muted-foreground`,children:r?.lastRunAt?(0,L.jsxs)(`time`,{dateTime:r.lastRunAt,title:new Date(r.lastRunAt).toLocaleString(),children:[F(r.lastRunAt),` ago · `,r.lastStatus]}):`—`}),t&&(0,L.jsx)(`td`,{className:i,children:r?.costUsd?.value==null?`—`:gt(r.costUsd.value,!0)})]})}var It=0,Lt=()=>++It,Y=new Map;function X(e,t){let n=(0,I.useContext)(st),r=()=>{let r=n?Y.get(n):void 0;return r?.has(e)?r.get(e):typeof t==`function`?t():t},[i,a]=(0,I.useState)(r),o=`${n}:${e}`,[s,c]=(0,I.useState)(o);o!==s&&(c(o),a(()=>r()));let l=(0,I.useMemo)(()=>({value:i}),[n,e]);return l.value=i,(0,I.useEffect)(()=>()=>{if(!n)return;let t=Y.get(n)??new Map;t.set(e,l.value),t.size>80&&t.delete(t.keys().next().value),Y.delete(n),Y.set(n,t),Y.size>20&&Y.delete(Y.keys().next().value)},[n,e,l]),[i,a]}var Rt=`a[href], button, select, input, [tabindex]`;function zt(e){let[t]=X(`${e}:position`,()=>({scroll:0})),n=(0,I.useCallback)(e=>{let n=[...e.querySelectorAll(Rt)],r=t.href?n.find(e=>e.getAttribute(`href`)===t.href):t.index===void 0?void 0:n[t.index];return r&&r.getAttribute(`aria-disabled`)!==`true`&&r.focus({preventScroll:!0}),e.scrollTop=t.scroll,!!r&&r.getAttribute(`aria-disabled`)!==`true`},[t]),r=(0,I.useMemo)(()=>({restore:()=>!1}),[t]);return{ref:(0,I.useCallback)(e=>{if(!e)return;let i=t.href!==void 0||t.index!==void 0,a=()=>{if(!i)return!1;let r=n(e);return r?(i=!1,o.disconnect()):e.querySelector(`[data-sheet-loading="false"]`)&&(i=!1,o.disconnect(),e.querySelector(`button:not([disabled]), select, [tabindex="0"]`)?.focus({preventScroll:!0}),e.scrollTop=t.scroll),r};r.restore=a;let o=new MutationObserver(a);i&&o.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-sheet-loading`]});let s=()=>{i=!1,o.disconnect()},c=()=>{i||(t.scroll=e.scrollTop)},l=n=>{i||!(n.target instanceof HTMLElement)||(t.href=n.target.getAttribute(`href`)??void 0,t.index=[...e.querySelectorAll(Rt)].indexOf(n.target))};return e.addEventListener(`pointerdown`,s),e.addEventListener(`keydown`,s),e.addEventListener(`wheel`,s,{passive:!0}),e.addEventListener(`scroll`,c),e.addEventListener(`focusin`,l),()=>{o.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`keydown`,s),e.removeEventListener(`wheel`,s),e.removeEventListener(`scroll`,c),e.removeEventListener(`focusin`,l)}},[t,n,r]),onOpenAutoFocus:e=>{(t.href!==void 0||t.index!==void 0)&&(e.preventDefault(),r.restore())}}}function Bt(e,t){let n=(0,I.useRef)(null),[r,i]=X(`${e}:trigger`,null);return{capture:()=>{let e=document.activeElement;n.current=e instanceof HTMLElement&&e!==document.body?e:null,i(n.current?{label:n.current.getAttribute(`aria-label`),text:n.current.textContent}:null)},restore:()=>{((n.current?.isConnected?n.current:r?[...document.querySelectorAll(`button`)].find(e=>!e.closest(`[role="dialog"]`)&&!e.hasAttribute(`disabled`)&&(r.label?e.getAttribute(`aria-label`)===r.label:e.textContent===r.text)):void 0)??document.querySelector(t))?.focus({preventScroll:!0})}}}function Vt(e,t=!0){return g({queryKey:[...d.dashboard,`overview`,e],enabled:t,staleTime:5e3,refetchInterval:t&&!e.snapshotId?15e3:!1,refetchIntervalInBackground:!1,retry:!1,queryFn:async({signal:t})=>w.parse(await o(await r.api.v1.workspace.dashboard.overview.$get({query:{period:e.period??`7d`,group:e.group??`completed`,tzOffsetMinutes:String(e.tzOffsetMinutes??new Date().getTimezoneOffset()),...e.snapshotId?{snapshotId:e.snapshotId}:{},...e.projectId?{projectId:e.projectId}:{},offset:String(e.offset??0),limit:`20`}},{init:{signal:t}}),`/workspace/dashboard/overview`))})}var Ht={running:`Running now`,"needs-you":`Needs you`,completed:`Completed`,failed:`Failed outcomes`},Ut={"needs-you":H.violet,running:H.info,completed:H.success,failed:H.danger},Wt={"needs-you":Ke,running:Ue,completed:re,failed:Ge};function Gt({active:e,children:t,onCurrent:n}){let[r,i]=_t(`period`,[`7d`,`30d`],`7d`),a=Bt(`outcome`,`[data-outcome-trigger]`),o=h().data?.projects,s=e=>o?.find(t=>t.id===e)?.name??e,c=Vt({period:r},e),[l,u]=X(`outcome:selection`,null),d=zt(`outcome:${l?.identity??`closed`}`),f=pe();if((0,I.useEffect)(()=>{e||u(null)},[e]),!e)return t({});let p=c.data,m=(e,t)=>{a.capture(),p&&u({identity:Lt(),snapshot:p,group:e,projectId:t})},g=p?.coverage.projects.every(e=>e.state===`complete`);return(0,L.jsxs)(L.Fragment,{children:[t({overview:(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Workspace overview`}),(0,L.jsxs)(`label`,{className:$e,children:[`Outcomes period`,(0,L.jsxs)(et,{value:r,onChange:e=>{i(e.target.value===`30d`?`30d`:`7d`),u(null)},children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-4 p-4`,children:[c.isPending&&(0,L.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading overview…`}),c.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[p?`Showing previous results. `:``,`Could not refresh overview.`,` `,(0,L.jsx)(O,{variant:`outline`,onClick:()=>void c.refetch(),children:`Retry overview`})]}),p&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[p.metrics.needsYou?`${p.metrics.needsYou} tasks require your input or review.`:g&&f.connected&&!c.isError?`No tasks currently require your input or review.`:`No waiting tasks found in the available data.`,` `,p.metrics.failed,` failed `,p.metrics.failed===1?`outcome`:`outcomes`,` `,`in this period. Includes subtasks; completed does not mean accepted or deployed.`]}),(0,L.jsx)(K,{coverage:p.coverage,retry:()=>void c.refetch()}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[`needs-you`,`running`,`completed`,`failed`].map(e=>{let t=p.metrics[e===`needs-you`?`needsYou`:e],i=Wt[e];return(0,L.jsxs)(O,{"data-outcome-trigger":!0,"data-export-keep":!0,variant:`outline`,className:`relative min-w-0 overflow-hidden rounded-lg border bg-card-2 p-4 transition-colors before:absolute before:inset-x-0 before:top-0 before:h-px before:opacity-80 hover:border-foreground/20 hover:bg-muted/40 sm:p-5 group/metric h-auto min-h-24 flex-col items-start gap-0 whitespace-normal text-left font-normal ${t===0?H.neutral:Ut[e]}`,onClick:t=>{n&&(e===`running`||e===`needs-you`)?n(e,t.currentTarget):m(e)},"aria-label":`${Ht[e]}: ${t}`,children:[(0,L.jsx)(nt,{label:Ht[e],value:t,icon:(0,L.jsx)(i,{className:`size-4`}),children:e===`running`||e===`needs-you`?`Current state`:`Last ${r===`7d`?7:30} calendar days`}),(0,L.jsxs)(`span`,{"data-export-exclude":!0,className:`mt-4 flex items-center gap-1 text-xs font-medium text-muted-foreground transition-colors group-hover/metric:text-foreground`,children:[`View tasks`,` `,(0,L.jsx)(Re,{className:`size-3 transition-transform group-hover/metric:translate-x-0.5 motion-reduce:transition-none`,"aria-hidden":`true`})]})]},e)})}),(0,L.jsx)(Tt,{period:r,active:e}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-1 border-t pt-3`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Median cycle time`,` `,(0,L.jsx)(`strong`,{className:`font-mono font-semibold text-foreground`,children:q(p.metrics.medianCycleHours)}),` `,`· `,p.metrics.timedTasks,`/`,p.metrics.completed,` completed tasks have valid timings.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`h-auto px-1.5 py-1 text-sm text-foreground underline-offset-4 hover:underline`,onClick:()=>m(`completed`),children:`Inspect completed tasks`})]}),(0,L.jsx)(`p`,{className:`font-mono text-[11px] text-soft-foreground`,children:(0,L.jsxs)(`time`,{dateTime:p.asOf,title:new Date(p.asOf).toLocaleString(),children:[`Updated `,F(p.asOf),` ago`]})})]}),(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-1`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsx)(`p`,{className:`mt-1 max-w-prose pl-5 leading-relaxed`,children:`Outcomes use finish dates, including archived tasks. Scheduled retries are excluded from failed outcomes. Period includes today at your current fixed UTC offset.`})]}),(0,L.jsx)(R,{rows:Object.entries(p.metrics).map(([e,t])=>({section:`overview`,metric:e,value:t,unit:e===`medianCycleHours`?`hours`:`tasks`,asOf:p.asOf,note:e===`running`||e===`needsYou`?`Current non-archived state`:`Finished since ${p.windowStart}`}))})]})]})]}),portfolio:p&&(0,L.jsx)(`div`,{children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Outcomes: Last ${r===`7d`?7:30} calendar days; workload: current state`,children:[(0,L.jsx)(`div`,{className:`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,children:(0,L.jsx)(`h2`,{className:`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Projects`})}),(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:`Current workload and outcomes for the selected period. Sorted by tasks needing you, then running tasks. Counts include subtasks.`}),(0,L.jsxs)(`div`,{className:`overflow-x-auto px-1 pb-2`,role:`region`,"aria-label":`Project outcomes`,tabIndex:0,children:[(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsx)(`tr`,{children:[`Project`,`Needs you`,`Running`,`Completed`,`Failed`,`Median cycle`].map(e=>(0,L.jsx)(`th`,{className:`whitespace-nowrap px-3 py-2 font-mono text-[11px] font-medium uppercase tracking-[0.1em] text-soft-foreground ${e===`Project`?``:`text-right`}`,children:e},e))})}),(0,L.jsx)(`tbody`,{children:p.projects.map(e=>{let t=p.coverage.projects.find(t=>t.projectId===e.projectId);return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,L.jsx)(_,{className:`font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/tasks`,children:s(e.projectId)}),t?.state!==`complete`&&(0,L.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Incomplete data`})]}),[`needs-you`,`running`,`completed`,`failed`].map(n=>(0,L.jsx)(`td`,{className:`px-3 py-1 text-right`,children:(0,L.jsx)(O,{"data-export-keep":!0,variant:`ghost`,className:`min-h-11 tabular-nums`,"aria-label":`${s(e.projectId)}: ${Ht[n]}: ${t?.state===`unavailable`?`Unavailable`:e[n===`needs-you`?`needsYou`:n]}`,disabled:t?.state===`unavailable`,onClick:()=>m(n,e.projectId),children:t?.state===`unavailable`?`Unavailable`:e[n===`needs-you`?`needsYou`:n]})},n)),(0,L.jsxs)(`td`,{className:`px-3 py-2 text-right tabular-nums`,children:[q(e.medianCycleHours),(0,L.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.timedTasks,`/`,e.completed,` timed`]})]})]},e.projectId)})})]}),!p.projects.length&&(0,L.jsx)(`p`,{className:`py-4`,children:`No projects to compare yet.`})]}),(0,L.jsx)(R,{rows:p.projects.flatMap(({projectId:e,...t})=>Object.entries(t).map(([t,n])=>({section:`portfolio`,entity:e,metric:t,value:p.coverage.projects.find(t=>t.projectId===e)?.state===`unavailable`?null:n,unit:t===`medianCycleHours`?`hours`:`tasks`,asOf:p.asOf,note:`Outcomes since ${p.windowStart}; running and needsYou are current state`})))})]})})}),(0,L.jsx)(we,{open:!!l,onOpenChange:e=>{e||u(null)},children:(0,L.jsxs)(Ce,{...d,className:`w-full overflow-y-auto sm:max-w-xl`,onCloseAutoFocus:e=>{e.preventDefault(),a.restore()},children:[(0,L.jsxs)(be,{children:[(0,L.jsxs)(Se,{children:[l?Ht[l.group]:`Tasks`,l?.projectId?` · ${l.projectId}`:``]}),(0,L.jsx)(xe,{children:`Tasks behind the selected metric. Includes subtasks. Snapshot keeps counts and rows consistent.`})]}),l&&(0,L.jsx)(Kt,{selection:l,projectName:s,refresh:()=>{u(null),c.refetch()}},l.identity)]})})]})}function Kt({selection:e,refresh:t,projectName:n}){let[r,i]=X(`outcome:${e.identity}:offset`,0),a=Vt({period:e.snapshot.period,snapshotId:e.snapshot.snapshotId,group:e.group,projectId:e.projectId,offset:r}),o=(0,I.useRef)(null),s=(0,I.useRef)(null);(0,I.useEffect)(()=>{a.data&&s.current===r&&(o.current?.focus(),s.current=null)},[a.data,r]);let c=e=>{s.current=e,i(e)};return(0,L.jsxs)(`div`,{className:`space-y-3 p-4`,"data-sheet-loading":a.isFetching,children:[a.isPending&&(0,L.jsx)(`p`,{children:`Loading tasks…`}),a.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[`This snapshot may have expired or become unavailable.`,` `,(0,L.jsx)(O,{onClick:t,children:`Refresh overview`})]}),a.data&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{ref:o,tabIndex:-1,className:`text-xs text-muted-foreground`,children:[a.data.page.total,` tasks · Snapshot from`,` `,(0,L.jsxs)(`time`,{dateTime:a.data.asOf,title:new Date(a.data.asOf).toLocaleString(),children:[F(a.data.asOf),` ago`]})]}),a.data.page.rows.map(t=>(0,L.jsx)(qt,{row:t,group:e.group,projectName:n},`${t.projectId}:${t.id}`)),!a.data.page.rows.length&&(0,L.jsx)(`p`,{children:`No tasks in this group.`})]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(O,{variant:`outline`,disabled:!r||a.isFetching,onClick:()=>c(Math.max(0,r-20)),children:`Previous`}),(0,L.jsx)(O,{variant:`outline`,disabled:!a.data||a.data.page.nextOffset===null||a.isFetching,onClick:()=>c(a.data.page.nextOffset),children:`Next`})]})]})}function qt({row:e,group:t,projectName:n}){let r=M(e),a=t===`running`||t===`needs-you`;a&&r&&(e={...e,...r});let o=r===null,s=a&&(e.archived||(t===`running`?e.status!==`running`:!i(e))),c=o||s,l=u(e),d=a&&o?`Task removed`:s?t===`running`?`No longer running`:`No longer needs you`:l.label;return(0,L.jsxs)(`div`,{className:`border-b py-3`,children:[(0,L.jsx)(_,{"aria-disabled":c||void 0,tabIndex:c?-1:void 0,onClick:e=>{c&&e.preventDefault()},className:`block min-h-11 font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,children:e.titleSummary||e.title}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsx)(P,{tone:l.tone}),` `,n(e.projectId),` ·`,` `,d,` · `,e.archived?`Archived · `:``,(0,L.jsxs)(`time`,{dateTime:e.finishedAt??e.createdAt,title:new Date(e.finishedAt??e.createdAt).toLocaleString(),children:[e.finishedAt?`Finished`:`Created`,` `,F(e.finishedAt??e.createdAt),` ago`]})]})]})}var Jt={snapshot:[...d.dashboard,`snapshot`],feed:e=>[...d.dashboard,`feed`,e],telemetry:[...d.dashboard,`telemetry`]},Yt=new Map;async function Xt(e){let t=k(),n=S.parse(await o(await r.api.v1.workspace.dashboard.$get({},{init:{signal:e}}),`/workspace/dashboard`));return Yt.has(n.snapshotId)||Yt.set(n.snapshotId,t),Yt.size>60&&Yt.delete(Yt.keys().next().value),A(t,[...n.questions.rows,...n.reviews.rows]),n}async function Zt(e,t,n=0,i=20,a){let s=b.parse(await o(await r.api.v1.workspace.dashboard.tasks.$get({query:{snapshotId:e,group:t,offset:String(n),limit:String(i)}},{init:{signal:a}}),`/workspace/dashboard/tasks`)),c=Yt.get(e);return c!==void 0&&A(c,s.page.rows),s}function Qt(e){return g({queryKey:Jt.snapshot,queryFn:({signal:e})=>Xt(e),enabled:e,staleTime:5e3,refetchOnMount:`always`,refetchInterval:e?15e3:!1,refetchIntervalInBackground:!1,retry:!1})}function $t(e){return g({queryKey:Jt.telemetry,enabled:e,staleTime:0,queryFn:async({signal:e})=>{let t=ee.parse(await o(await r.api.v1.workspace.dashboard.telemetry.$get({},{init:{signal:e}}),`/workspace/dashboard/telemetry`));return te.seed(t.samples,t.asOf),t}})}function en(e,t){let n=g({queryKey:Jt.feed(e),queryFn:async({signal:t})=>{let n=k(),i=T.parse(await o(await r.api.v1.workspace.dashboard.feed.$get({query:{filter:e}},{init:{signal:t}}),`/workspace/dashboard/feed`));return A(n,i.rows.flatMap(e=>e.kind===`task-result`?[e.run]:[])),i},enabled:t,staleTime:15e3,refetchInterval:t&&e!==`github`?15e3:!1,retry:!1}),i=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{i.current=!1},[e,t]),(0,I.useEffect)(()=>{if(!t||i.current||!n.data?.sources.some(e=>e.reason===`Still loading GitHub`))return;let e=setTimeout(()=>{document.visibilityState!==`hidden`&&(i.current=!0,n.refetch())},5e3);return()=>clearTimeout(e)},[t,n.data,n.refetch]),n}function tn(e,t){let n=en(`tasks`,t&&e!==`github`),r=en(`github`,t&&e!==`tasks`),i=(0,I.useMemo)(()=>{if(e===`tasks`)return n.data;if(e===`github`)return r.data;let t=n.data,i=r.data;if(!t&&!i)return;let a=t??i,o=new Date(Math.max(Date.parse(t?.asOf??a.asOf),Date.parse(i?.asOf??a.asOf))).toISOString(),s=new Date(Date.parse(o)-10080*60*1e3).toISOString(),c=[...t?.rows??[],...i?.rows??[]].filter(e=>Date.parse(e.at)>=Date.parse(s)&&Date.parse(e.at)<=Date.parse(o)).sort((e,t)=>nn(e,t)),l=new Set(c.slice(60).map(e=>e.kind===`task-result`?`tasks:${e.run.projectId}`:e.key.slice(0,e.key.lastIndexOf(`:`)))),u=[...t?.sources??[],...i?.sources??[]].map(e=>l.has(e.key)?{...e,truncated:!0}:e);return{...a,asOf:o,windowStart:s,filter:`all`,rows:c.slice(0,60),sources:u,coverage:t?.coverage??a.coverage,truncated:c.length>60||!!t?.truncated||!!i?.truncated}},[e,n.data,r.data]),a=e===`github`?r:n;return{...a,data:i,githubError:r.isError,githubFetching:r.isFetching,retryTasks:()=>n.refetch(),retryFailed:()=>e===`github`?r.refetch():e===`tasks`?n.refetch():Promise.all([...n.isError?[n.refetch()]:[],...r.isError?[r.refetch()]:[]]),isPending:!i&&a.isPending,isError:a.isError||e===`all`&&r.isError,isFetching:a.isFetching||e===`all`&&r.isFetching,refetch:()=>e===`tasks`?n.refetch():r.refetch()}}function nn(e,t){return Date.parse(t.at)-Date.parse(e.at)||e.key.localeCompare(t.key)}var rn=[...d.dashboard,`costs`];function an(){let e=0,t=0,n,r=new Set;return{subscribe:e=>(r.add(e),()=>{r.delete(e)}),getSnapshot:()=>n,async read(i,a){let o=++e,s=await un(i,a);return!a?.aborted&&o>t&&(t=o,(n?.cost!==s.visibility.cost||n?.tokens!==s.visibility.tokens)&&(n=s.visibility,r.forEach(e=>e()))),s}}}var on=new WeakMap;function sn(e){let t=on.get(e);return t||(t=an(),on.set(e,t)),t}function cn(){let e=sn(f());return(0,I.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot)}var ln=new Map;async function un(e,t){let n=k(),i=C.parse(await o(await r.api.v1.workspace.dashboard.costs.$get({query:{...e,offset:String(e.offset??0),limit:`20`}},{init:{signal:t}}),`/workspace/dashboard/costs`));!e.snapshotId&&!ln.has(i.snapshotId)&&ln.set(i.snapshotId,n),ln.size>60&&ln.delete(ln.keys().next().value);let a=ln.get(i.snapshotId);return a!==void 0&&A(a,i.tasks.rows),i}function dn(e,t,n){let r=sn(f());return g({queryKey:[...rn,e,t,n],queryFn:({signal:n})=>r.read({period:e,sort:t,tzOffsetMinutes:new Date().getTimezoneOffset()},n),staleTime:5e3,refetchOnMount:`always`,refetchInterval:15e3,refetchIntervalInBackground:!1,retry:!1})}function fn(e,t,n,r){let i=sn(f());return g({queryKey:[...rn,`tasks`,e.snapshotId,t,n,r,e.visibility],retry:!1,queryFn:async({signal:a})=>{let o=e.tzOffsetMinutes??new Date().getTimezoneOffset(),s=async s=>{let c=await i.read({period:e.period,sort:n,snapshotId:s,projectId:t,tzOffsetMinutes:o},a),l=[...c.tasks.rows];for(;c.tasks.nextOffset!==null&&l.length<r;)c=await i.read({period:e.period,sort:n,snapshotId:c.snapshotId,projectId:t,offset:c.tasks.nextOffset},a),l.push(...c.tasks.rows);return{...c,tasks:{...c.tasks,rows:l}}};try{return await s(e.snapshotId)}catch(e){if(e instanceof c&&e.status===409)return s();throw e}}})}var pn={cost:{text:`text-primary`,fill:`bg-primary`,tint:H.primary,icon:ie},input:{text:`text-violet`,fill:`bg-violet`,tint:H.violet,icon:We},output:{text:`text-info`,fill:`bg-info`,tint:H.info,icon:Te}};function mn({metric:e,label:t,value:n,reported:r,total:i}){let a=pn[e],o=a.icon,s=i?Math.min(100,r/i*100):0;return(0,L.jsxs)(`div`,{className:`${tt} ${a.tint}`,children:[(0,L.jsxs)(nt,{label:t,value:n,icon:(0,L.jsx)(o,{className:`size-4 ${a.text}`}),children:[r,` of `,i,` tasks report this metric`]}),(0,L.jsx)(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full ${a.fill} transition-[width] duration-300 motion-reduce:transition-none`,style:{width:`${s}%`}})})]})}function hn({projects:e,currentProjects:t,metric:n,field:r,label:i,format:a,onSelect:o}){let s=e.reduce((e,t)=>Math.max(e,t[r]?.value??0),0),c=pn[n];return(0,L.jsxs)(Ie,{delayDuration:150,children:[(0,L.jsxs)(`div`,{className:`space-y-1 rounded-xl border p-2`,"aria-label":`Projects ranked by ${i}`,children:[e.length===0&&(0,L.jsx)(`p`,{className:`px-3 py-4 text-muted-foreground`,children:`No projects to compare in this cohort.`}),e.slice(0,5).map((e,n)=>{let l=e[r],u=l?.value,d=u==null||s===0?0:u/s*100,f=u!=null;return(0,L.jsxs)(Le,{children:[(0,L.jsx)(Ne,{asChild:!0,children:(0,L.jsxs)(`button`,{"data-export-row":!0,"data-export-keep":!0,className:`group w-full rounded-lg px-3 py-3 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 motion-reduce:transition-none`,disabled:!t.some(t=>t.projectId===e.projectId),onClick:()=>o(e.projectId),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`span`,{className:`w-4 shrink-0 text-xs tabular-nums text-muted-foreground`,"aria-hidden":`true`,children:n+1}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-medium`,children:e.projectId}),(0,L.jsx)(`span`,{className:`shrink-0 font-semibold tabular-nums`,children:a(u)}),(0,L.jsx)(Re,{"data-export-exclude":!0,className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]}),(0,L.jsx)(`div`,{className:`mt-2 ml-7 h-2 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{"data-project-bar":e.projectId,className:`h-full rounded-full ${c.fill} transition-[width] duration-300 motion-reduce:transition-none`,style:{width:`${d}%`}})}),(0,L.jsxs)(`p`,{className:`mt-1.5 ml-7 text-xs text-muted-foreground`,children:[l?.reportedTasks??0,` of `,e.tasks,` tasks report this metric`,f?``:` · No measured value`]})]})}),(0,L.jsxs)(Pe,{className:`max-w-64`,children:[(0,L.jsxs)(`p`,{className:`font-medium`,children:[e.projectId,` · `,i,`: `,a(u)]}),(0,L.jsxs)(`p`,{children:[l?.reportedTasks??0,` of `,e.tasks,` tasks report this metric.`]}),(0,L.jsx)(`p`,{children:`Open project tasks`})]})]},e.projectId)})]}),e.length>0&&(0,L.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[e.length>5?`Top 5 of ${e.length} projects. `:``,`Bar lengths compare reported values; the largest is the reference.`]})]})}var Z={cost:`costUsd`,input:`inputTokens`,output:`outputTokens`},gn={cost:`Reported USD`,input:`Input tokens`,output:`Output tokens`};function _n(e,t){return JSON.stringify([e.totals,e.projects,e.tasks,e.visibility,e.coverage,e.invalidDateTasks])!==JSON.stringify([t.totals,t.projects,t.tasks,t.visibility,t.coverage,t.invalidDateTasks])}var vn=(e,t)=>gt(e,t===`cost`);function Q(e){return[...e.cost?[`cost`]:[],...e.tokens?[`input`,`output`]:[]]}function yn({value:e,onChange:t,visibility:n}){return(0,L.jsxs)(`label`,{className:$e,children:[`Sort by`,(0,L.jsx)(et,{value:e,onChange:e=>t(e.target.value),children:Q(n).map(e=>(0,L.jsx)(`option`,{value:e,children:gn[e]},e))})]})}function bn(){return(0,L.jsx)(xn,{visibility:Be(s().data)})}function xn({visibility:e}){return(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsx)(`div`,{className:B,children:(0,L.jsx)(`h2`,{className:z,children:`Usage & cost`})}),!e.cost&&!e.tokens?(0,L.jsx)(`p`,{className:`p-4 text-sm`,children:`Usage metrics are hidden by workspace settings`}):(0,L.jsx)(Sn,{visibility:e},`${e.cost}:${e.tokens}`)]})}function Sn({visibility:e}){let[t,n]=_t(`usagePeriod`,[`all`,`7d`,`30d`],`all`),[r,i]=_t(`usageSort`,Q(e),e.cost?`cost`:`input`);return(0,L.jsx)(Cn,{period:t,setPeriod:n,sort:r,setSort:i,visibility:e})}function Cn({period:e,setPeriod:t,sort:n,setSort:r,visibility:i}){let a=dn(e,n,`${i.cost}:${i.tokens}`),[o,s]=X(`usage:accepted`,void 0),c=o??a.data,l=a.data??c,[u,d]=X(`usage:panel`,null),[f,p]=(0,I.useState)(e);f!==e&&(p(e),s(void 0),d(null));let m=zt(`usage:${u?.identity??`closed`}`),h=Bt(`usage`,`[data-usage-trigger]`),g=e=>{h.capture(),c&&d({identity:Lt(),projectId:e,snapshot:c,latestId:l?.snapshotId??c.snapshotId})},_=cn()??i,v={cost:i.cost&&_.cost,tokens:i.tokens&&_.tokens},y=Q(v).includes(n)?n:Q(v)[0]??`cost`,b=[...c?.projects??[]].sort((e,t)=>{let n=e[Z[y]]?.value,r=t[Z[y]]?.value;return(n==null?r==null?0:1:r==null?-1:r-n)||e.projectId.localeCompare(t.projectId)});!o&&a.data&&s(a.data);let x=c&&l&&_n(c,l),S=c?.coverage.projects.some(e=>e.state!==`complete`),C=l?.coverage.projects.some(e=>e.state!==`complete`),w=JSON.stringify(c?.coverage)!==JSON.stringify(l?.coverage),T=c?.totals.tasks===0&&!S&&!C;return(0,L.jsxs)(`div`,{className:`space-y-4 p-4 text-sm`,children:[c&&(0,L.jsx)(R,{rows:T?[]:[...Q(v).map(e=>({section:`totals`,metric:Z[e],value:c.totals[Z[e]]?.value??null,unit:e===`cost`?`USD`:`tokens`,reportedTasks:c.totals[Z[e]]?.reportedTasks??0,totalTasks:c.totals.tasks,asOf:c.asOf})),...(v.cost||v.tokens?b.slice(0,5):[]).map(e=>({section:`project`,entity:e.projectId,metric:Z[y],value:e[Z[y]]?.value??null,unit:y===`cost`?`USD`:`tokens`,reportedTasks:e[Z[y]]?.reportedTasks??0,totalTasks:e.tasks,asOf:c.asOf}))]}),c&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:c.asOf})}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-medium`,children:`Lifetime totals of retained tasks`}),(0,L.jsxs)(`details`,{className:`mt-1 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`${Qe} min-h-11`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsxs)(`p`,{children:[`Includes archived tasks and subtasks.`,` `,v.cost&&`Reported USD is not an invoice. `,`Missing reports are excluded, not treated as zero. Calendar days use your current UTC offset, including today.`]})]})]}),(0,L.jsxs)(`label`,{className:$e,children:[`Tasks created`,(0,L.jsxs)(et,{value:e,onChange:e=>t(e.target.value),children:[(0,L.jsx)(`option`,{value:`all`,children:`All time`}),(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),e!==`all`&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Lifetime usage of tasks created in this period — not spending during the period.`}),a.isPending&&(0,L.jsx)(`p`,{children:`Loading usage…`}),a.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[c?`Showing stale usage. Could not refresh.`:`Could not load usage.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void a.refetch(),children:`Retry`})]}),x&&(0,L.jsx)(`p`,{role:`status`,children:`Newer usage data is available; displayed values use the previous snapshot.`}),x&&(0,L.jsx)(O,{className:`min-h-11`,variant:`outline`,onClick:()=>s(l),children:`Updates available — Show`}),c&&S&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Coverage of displayed usage:`}),(0,L.jsx)(K,{coverage:c.coverage,retry:()=>void a.refetch()})]}),l&&C&&w&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Current source availability:`}),(0,L.jsx)(K,{coverage:l.coverage,retry:()=>void a.refetch()})]}),c&&(0,L.jsxs)(L.Fragment,{children:[!T&&(0,L.jsx)(`div`,{className:`report-cost-metrics grid gap-3 sm:grid-cols-[repeat(auto-fit,minmax(220px,1fr))]`,children:Q(v).map(e=>(0,L.jsx)(mn,{metric:e,label:gn[e],value:vn(c.totals[Z[e]]?.value,e),reported:c.totals[Z[e]]?.reportedTasks??0,total:c.totals.tasks},e))}),!v.cost&&!v.tokens&&(0,L.jsx)(`p`,{children:`Usage metrics are hidden by workspace settings`}),c.totals.tasks===0?(0,L.jsx)(`p`,{children:S||C?`No retained tasks could be read from available sources.`:`No retained tasks in this cohort.`}):Q(v).every(e=>!c.totals[Z[e]]?.reportedTasks)&&(0,L.jsx)(`p`,{children:`No reports for the visible metrics in this cohort.`}),T&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Usage appears when tasks report cost or tokens.`}),(0,L.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Deleted tasks are excluded from retained history.`,c.invalidDateTasks?` ${c.invalidDateTasks} tasks have missing or invalid creation dates${e===`all`?`; included in All time`:`; excluded from this period`}.`:``]}),!T&&(v.cost||v.tokens)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-medium`,children:`Top projects`}),(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Ranking uses reported metrics only.`})]}),(0,L.jsx)(yn,{value:y,onChange:r,visibility:v})]}),(0,L.jsx)(hn,{projects:b,metric:y,label:gn[y],field:Z[y],format:e=>vn(e,y),currentProjects:l?.projects??[],onSelect:g}),(0,L.jsx)(O,{"data-usage-trigger":!0,className:`min-h-11`,variant:`outline`,onClick:()=>g(``),children:`View tasks`})]})]}),(0,L.jsx)(we,{open:u!==null&&(v.cost||v.tokens),onOpenChange:e=>{e||d(null)},children:(0,L.jsxs)(Ce,{...m,className:`w-full overflow-y-auto sm:max-w-xl`,onCloseAutoFocus:e=>{e.preventDefault(),h.restore()},children:[(0,L.jsxs)(be,{children:[(0,L.jsx)(Se,{children:u?.projectId?`${u.projectId} tasks`:`All tasks`}),(0,L.jsx)(xe,{children:`Lifetime usage of retained tasks. Missing reports are unavailable.`})]}),u!==null&&(0,L.jsx)(wn,{identity:`usage:${u.identity}`,snapshot:l&&l.snapshotId!==u.latestId?l:u.snapshot,projectId:u.projectId||void 0,visibility:v},u.identity)]})})]})}function wn({identity:e,snapshot:t,projectId:n,visibility:r}){let[i,a]=X(`${e}:sort`,t.sort);return(0,L.jsx)(Tn,{identity:e,snapshot:t,projectId:n,visibility:r,sort:Q(r).includes(i)?i:Q(r)[0]??`cost`,setSort:a})}function Tn({identity:e,snapshot:t,projectId:n,visibility:r,sort:i,setSort:a}){let[o,s]=X(`${e}:count`,20),[c,l]=X(`${e}:paging`,void 0),[u,d]=(0,I.useState)(t.snapshotId);u!==t.snapshotId&&(d(t.snapshotId),l(void 0));let f=fn(c??t,n,i,o),p=cn()??r,m={cost:r.cost&&p.cost,tokens:r.tokens&&p.tokens},h=Q(m).includes(i)?i:Q(m)[0]??`cost`,[g,_]=X(`${e}:accepted`,void 0),[v,y]=X(`${e}:acceptedCount`,o),[b,x]=X(`${e}:acceptedSort`,i),[S,C]=(0,I.useState)(i);S!==i&&(C(i),s(20),l(g??c??t)),f.data&&(!g||(v!==o||b!==i)&&g.snapshotId===f.data.snapshotId)&&(_(f.data),y(o),x(i));let w=g??f.data,T=f.data&&w&&_n(f.data,w),ee=w?.coverage.projects.some(e=>e.state!==`complete`),E=f.data?.coverage.projects.some(e=>e.state!==`complete`),D=JSON.stringify(w?.coverage)!==JSON.stringify(f.data?.coverage),te=!n||t.projects.some(e=>e.projectId===n);return(0,L.jsxs)(`div`,{className:`space-y-3 p-4 text-sm`,"data-sheet-loading":f.isFetching,children:[(0,L.jsx)(yn,{value:h,onChange:a,visibility:m}),f.isPending&&(0,L.jsx)(`p`,{children:`Loading tasks…`}),f.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[`Could not refresh tasks. `,w?`Showing stale usage.`:``,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void f.refetch(),children:`Retry`})]}),T&&(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{_(f.data),y(o),x(i)},children:`Updates available — Show`}),w&&ee&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Coverage of displayed tasks:`}),(0,L.jsx)(K,{coverage:w.coverage,retry:()=>void f.refetch()})]}),f.data&&E&&D&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Current source availability:`}),(0,L.jsx)(K,{coverage:f.data.coverage,retry:()=>void f.refetch()})]}),w&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{className:`border-b pb-2 font-mono text-[11px] text-soft-foreground`,children:[w.tasks.rows.length,` of `,w.tasks.total,` retained tasks`]}),w.tasks.total===0&&(0,L.jsx)(`p`,{children:w.coverage.projects.some(e=>e.state!==`complete`)?`No tasks could be read from available sources.`:`No retained tasks in this cohort.`}),w.tasks.rows.map(e=>(0,L.jsx)(En,{row:e,sort:h,visibility:m,disabled:!te||!f.data||!!(T&&!f.data?.tasks.rows.some(t=>t.id===e.id&&t.projectId===e.projectId))},`${e.projectId}:${e.id}`)),w.tasks.nextOffset!==null&&(0,L.jsx)(O,{className:`min-h-11`,disabled:f.isFetching,onClick:()=>{l(w),s(e=>e+20)},children:`Show 20 more tasks`})]})]})}function En({row:e,sort:t,visibility:n,disabled:r}){let i=M(e);r||=i===null;let a=u(i?{status:i.status,awaitingAnswerSince:i.awaitingAnswerSince}:e),o=Q(n).filter(e=>e!==t),s=t=>{let n=e[Z[t]];return n==null?`—`:vn(n,t)},c=t=>`${gn[t]}: ${vn(e[Z[t]],t)}`;return(0,L.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-4 border-b py-3 last:border-0`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(P,{tone:a.tone,pulse:a.pulse,className:`mt-[7px]`}),(0,L.jsx)(_,{className:`line-clamp-2 break-words font-medium leading-snug hover:underline no-hover:min-h-11`,title:e.title,to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,"aria-disabled":r||void 0,tabIndex:r?-1:void 0,onClick:e=>{r&&e.preventDefault()},children:e.title})]}),(0,L.jsxs)(`p`,{className:`mt-1 pl-[15px] font-mono text-[11px] text-soft-foreground`,children:[e.projectId,` · `,r?`Checking current state…`:i?.status??e.status,e.archived?` · Archived`:``,e.subtask?` · Subtask`:``]})]}),(0,L.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,L.jsx)(`span`,{"aria-label":c(t),className:`block font-semibold ${e[Z[t]]==null?`text-soft-foreground`:``}`,children:s(t)}),o.length>0&&(0,L.jsx)(`span`,{className:`mt-1 flex justify-end gap-3 font-mono text-[11px] text-soft-foreground`,children:o.map(e=>(0,L.jsxs)(`span`,{"aria-label":c(e),children:[s(e),` `,e===`cost`?``:e===`input`?`in`:`out`]},e))})]})]})}var Dn={cost:`costUsd`,input:`inputTokens`,output:`outputTokens`},On={cost:`Reported USD`,input:`Input tokens`,output:`Output tokens`};function kn(e){return[...e.cost?[`cost`]:[],...e.tokens?[`input`,`output`]:[]]}var An=(e,t)=>gt(e,t===`cost`);function jn(e){return new Date(`${e}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Mn({series:e,height:t,accent:n,renderTooltip:r,describe:i}){let a=Math.max(1,...e.map(t));return(0,L.jsxs)(Ie,{delayDuration:150,children:[(0,L.jsx)(`div`,{className:`flex h-20 items-end gap-0.5`,role:`group`,"aria-label":`Daily trend`,children:e.map(e=>{let o=t(e),s=Math.max(o>0?4:0,o/a*100);return(0,L.jsxs)(Le,{children:[(0,L.jsx)(Ne,{asChild:!0,children:(0,L.jsx)(`button`,{"data-export-keep":!0,"aria-label":i(e),type:`button`,className:`min-w-0 flex-1 rounded-t-sm transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,style:{height:`100%`,display:`flex`,alignItems:`end`},children:(0,L.jsx)(`span`,{style:{height:`${s}%`},className:`block w-full rounded-t-sm ${n}`})})}),(0,L.jsx)(Pe,{children:r(e)})]},e.date)})}),(0,L.jsxs)(`div`,{className:`mt-1 flex justify-between text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{children:jn(e[0].date)}),(0,L.jsx)(`span`,{children:jn(e.at(-1).date)})]})]})}function Nn({metrics:e,series:t}){return(0,L.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b`,children:[(0,L.jsx)(`th`,{className:`py-1 pr-2 font-medium`,children:`Date`}),e.map(e=>(0,L.jsx)(`th`,{className:`py-1 pr-2 text-right font-medium`,children:On[e]},e)),(0,L.jsx)(`th`,{className:`py-1 pr-2 text-right font-medium`,children:`Completed`}),(0,L.jsx)(`th`,{className:`py-1 text-right font-medium`,children:`Avg cycle`})]})}),(0,L.jsx)(`tbody`,{children:t.map(t=>(0,L.jsxs)(`tr`,{className:`border-b last:border-0`,children:[(0,L.jsx)(`td`,{className:`py-1 pr-2`,children:jn(t.date)}),e.map(e=>(0,L.jsx)(`td`,{className:`py-1 pr-2 text-right tabular-nums`,children:An(t[Dn[e]]?.value,e)},e)),(0,L.jsx)(`td`,{className:`py-1 pr-2 text-right tabular-nums`,children:t.completed}),(0,L.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:t.avgCycleHours===null?`—`:q(t.avgCycleHours)})]},t.date))})]})}function Pn({metric:e,series:t}){let n=pn[e],r=Dn[e],i=t.reduce((e,t)=>e+(t[r]?.reportedTasks??0),0);return(0,L.jsxs)(`div`,{className:`rounded-xl border p-3`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium ${n.text}`,children:On[e]}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(Mn,{series:t,describe:t=>`${t.date}, ${On[e]}: ${An(t[r]?.value,e)}, ${t[r]?.reportedTasks??0} of ${t.tasks} tasks reported`,height:e=>e[r]?.value??0,accent:n.fill,renderTooltip:t=>(0,L.jsxs)(`p`,{children:[jn(t.date),` · `,An(t[r]?.value,e),` ·`,` `,t[r]?.reportedTasks??0,`/`,t.tasks,` tasks reported`]})})}),i===0&&(0,L.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No reports in this period.`})]})}function Fn({series:e}){let t=e.reduce((e,t)=>e+t.completed,0),n=e.reduce((e,t)=>e+(t.avgCycleHours??0)*(t.cycleReportedTasks??t.completed),0),r=e.reduce((e,t)=>e+(t.cycleReportedTasks??t.completed),0),i=r?n/r:null;return(0,L.jsxs)(`div`,{className:`rounded-xl border p-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium text-success`,children:`Completed tasks`}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t,` done · avg cycle`,` `,i===null?`unavailable`:q(i)]})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[r,`/`,t,` completed tasks have valid cycle times.`]}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(Mn,{series:e,describe:e=>`${e.date}: ${e.completed} completed tasks, average cycle ${e.avgCycleHours==null?`Unavailable`:q(e.avgCycleHours)}`,height:e=>e.completed,accent:`bg-success`,renderTooltip:e=>(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`p`,{children:[jn(e.date),` · `,e.completed,` completed`]}),(0,L.jsxs)(`p`,{children:[`Avg cycle`,` `,e.avgCycleHours===null?`unavailable`:q(e.avgCycleHours),` · Median`,` `,e.medianCycleHours===null?`unavailable`:q(e.medianCycleHours)]})]})})}),t===0&&(0,L.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No tasks finished in this period.`})]})}function In(){return(0,L.jsx)(Ln,{visibility:Be(s().data)})}function Ln({visibility:e}){let[t,n]=_t(`trendPeriod`,[`7d`,`30d`],`7d`),r=dn(t,e.cost?`cost`:`input`,`${e.cost}:${e.tokens}`),i=r.data,a=i&&i.totals.tasks===0&&i.coverage.projects.every(e=>e.state===`complete`)&&i.series.every(e=>e.tasks===0&&e.completed===0),o=kn({cost:e.cost&&i?.visibility.cost!==!1,tokens:e.tokens&&i?.visibility.tokens!==!1});return(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Trends`}),(0,L.jsxs)(`label`,{className:$e,children:[`Period`,(0,L.jsxs)(et,{value:t,onChange:e=>n(e.target.value),children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-4 p-4 text-sm`,children:[i&&(0,L.jsx)(R,{rows:a?[]:i.series.flatMap(e=>[...o.map(t=>({section:`daily-creation-cohort`,entity:e.date,metric:Dn[t],value:e[Dn[t]]?.value??null,unit:t===`cost`?`USD`:`tokens`,reportedTasks:e[Dn[t]]?.reportedTasks??0,totalTasks:e.tasks,asOf:i.asOf,note:`Lifetime usage grouped by task creation date; not daily spend`})),{section:`daily-completions`,entity:e.date,metric:`completed`,value:e.completed,unit:`tasks`,asOf:i.asOf},{section:`daily-completions`,entity:e.date,metric:`avgCycleHours`,value:e.avgCycleHours,reportedTasks:e.cycleReportedTasks??e.completed,totalTasks:e.completed,unit:`hours`,asOf:i.asOf},{section:`daily-completions`,entity:e.date,metric:`medianCycleHours`,value:e.medianCycleHours,unit:`hours`,asOf:i.asOf}])}),(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`${Qe} py-2`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsx)(`p`,{children:`Usage is grouped by creation date, not spending date. Completed tasks are grouped by finish date. Calendar days use your current UTC offset (fixed across the period), including today.`})]}),r.isPending&&(0,L.jsx)(`p`,{children:`Loading trends…`}),r.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[i?`Showing stale trends. Could not refresh.`:`Could not load trends.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void r.refetch(),children:`Retry`})]}),i&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:i.asOf})}),i&&(0,L.jsx)(K,{coverage:i.coverage,retry:()=>void r.refetch()}),i&&a&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`No retained tasks in this period yet.`}),i&&!a&&i.series.length>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`space-y-4`,children:[o.length>0&&(0,L.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-[repeat(auto-fit,minmax(200px,1fr))]`,children:o.map(e=>(0,L.jsx)(Pn,{metric:e,series:i.series},e))}),(0,L.jsx)(Fn,{series:i.series})]}),(0,L.jsxs)(`details`,{className:`group rounded-lg border bg-muted/20 print:block`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Daily data`,className:`flex min-h-11 cursor-pointer list-none items-center gap-2 px-3 text-xs font-medium text-muted-foreground hover:text-foreground [&::-webkit-details-marker]:hidden`,children:[(0,L.jsx)(Je,{className:`size-4`,"aria-hidden":`true`}),` View data table`,(0,L.jsx)(Fe,{className:`ml-auto size-4 transition-transform group-open:rotate-180`,"aria-hidden":`true`})]}),(0,L.jsx)(`div`,{className:`max-h-80 overflow-auto border-t p-3 print:max-h-none print:overflow-visible`,role:`region`,"aria-label":`Daily trend values`,tabIndex:0,children:(0,L.jsx)(Nn,{metrics:o,series:i.series})})]})]})]})]})}function Rn(e,t,n,r=!0){let i=f();return g({queryKey:[...Jt.snapshot,e?.snapshotId,t,n],enabled:r&&!!e,retry:!1,queryFn:async({signal:r})=>{if(!e)throw Error(`Dashboard not loaded`);let a=[];try{for(let i=0;i<n;){let o=await Zt(e.snapshotId,t,i,Math.min(20,n-i),r);if(a.push(...o.page.rows),o.page.nextOffset===null)break;i=o.page.nextOffset}return a}catch(e){if(e instanceof c&&e.status===409){let e=await Xt(r);i.setQueryData(Jt.snapshot,e)}throw e}}})}function zn(e,t,n,r){let i=f(),a=t===`questions`||t===`reviews`?`needs-you`:t,o=a===`needs-you`?0:n,s=r.map(e=>`${e.projectId}:${e.id}`).sort();return g({queryKey:[...Jt.snapshot,e.snapshotId,t,`displaced`,...s],enabled:s.length>0,retry:!1,queryFn:async({signal:t})=>{let n=new Set(s),r=new Map;try{for(let i=o;i!==null&&n.size;){let o=await Zt(e.snapshotId,a,i,20,t);for(let e of o.page.rows){let t=`${e.projectId}:${e.id}`;n.delete(t)&&r.set(t,e)}i=o.page.nextOffset}return r}catch(e){throw e instanceof c&&e.status===409&&i.setQueryData(Jt.snapshot,await Xt(t)),e}}})}function Bn({snapshot:e,questions:t,reviews:n,more:r,healthy:i=!0}){let a=pe();return(0,L.jsxs)(N,{className:`min-w-0 gap-0 overflow-hidden py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsxs)(`h2`,{id:`dashboard-needs-you`,tabIndex:-1,className:z,children:[`Needs you · `,e.counts.questions+e.counts.reviews]}),(0,L.jsxs)(`p`,{className:`font-mono text-[11px] text-soft-foreground`,children:[e.counts.questions,` questions · `,e.counts.reviews,` reviews`]})]}),i&&a.connected&&e.counts.questions+e.counts.reviews===0&&e.coverage.projects.every(e=>e.state===`complete`)?(0,L.jsxs)(`p`,{className:`flex items-center gap-2.5 px-4 py-8 text-sm text-muted-foreground`,children:[(0,L.jsx)(P,{tone:`success`}),`All caught up — no tasks need your input`]}):null,(0,L.jsx)(Vn,{snapshot:e,group:`questions`,count:t,more:r}),(0,L.jsx)(Vn,{snapshot:e,group:`reviews`,count:n,more:r})]})}function Vn({snapshot:e,group:t,count:n,more:r}){let i=e[t],a=Math.max(n,i.rows.length),o=Rn(e,t,a,a>i.rows.length),s=a>i.rows.length?o.data:i.rows,c=lt(s,G,t,n),l=zn(e,t,a,c.rows.filter(e=>e.removed).map(e=>e.row)),u=(0,I.useRef)(null);return!i.total&&!c.rows.length?null:(0,L.jsxs)(`section`,{children:[(0,L.jsxs)(`h3`,{ref:u,tabIndex:-1,className:`border-b bg-card-2 px-4 py-2 font-mono text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground`,children:[t===`questions`?`Questions`:`Reviews`,` · `,i.total]}),c.updates>0&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>{c.show(),u.current?.focus()},children:[c.updates,` updates — Show`]}),c.rows.map(({row:e,removed:t})=>(0,L.jsx)(ht,{row:l.data?.get(G(e))??e,removed:t&&!!l.data&&!l.data.has(G(e)),checking:s===void 0||t&&!l.data,checkFailed:s===void 0&&o.isError||t&&!l.data&&l.isError,queue:!0},G(e))),(o.isError||l.isError)&&(0,L.jsxs)(`p`,{role:`alert`,className:`p-4 text-sm`,children:[`Could not check current task state.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11`,onClick:()=>{o.refetch(),l.refetch()},children:`Retry`})]}),a<i.total&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,disabled:o.isFetching,onClick:()=>r(t,a+Math.min(20,i.total-a)),children:[`Show `,Math.min(20,i.total-a),` more `,t]})]})}function Hn(e){if(!e.startsWith(`github:`))return e===`tasks`?`Task results`:e;let t=e.slice(7).split(`:`),n=t.pop()===`pr`?`Pull requests`:`Issues`;return`${t.join(`:`).replace(/^project:/,`Project `).replace(/^github.com\//,``)} · ${n}`}var Un=e=>e.key;function Wn({filter:e,setFilter:t,count:n,more:r}){let i=tn(e,!0),a=lt(i.data?.rows,Un,`feed:${e}`,0,e=>e.kind===`task-result`),o=a.rows,s=a.updates,c=(0,I.useContext)(st),l=(0,I.useRef)(null),u=`feed:${e}`,d=(0,I.useMemo)(()=>({scroll:pt(c,u)?.scroll??0,done:!1}),[c,u]);(0,I.useLayoutEffect)(()=>{!l.current||d.done||(l.current.scrollTop=d.scroll,d.done=Math.abs(l.current.scrollTop-d.scroll)<1||!!i.data&&!i.isPending&&!i.isFetching)},[d,o.length,n,i.data,i.isPending,i.isFetching]);let f=(0,I.useRef)(null),p=i.data?.sources.filter(e=>e.key.startsWith(`github:`))??[],m=p.flatMap(e=>e.fetchedAt?[e.fetchedAt]:[]).sort()[0],h=i.githubError,g=p.filter(e=>e.reason===`No GitHub remote`),_=p.some(e=>e.reason===`Still loading GitHub`),v=p.length>0&&g.length===p.length&&!h,y=p.filter(e=>e.state!==`ready`&&e.reason!==`No GitHub remote`&&e.reason!==`Still loading GitHub`),b=v&&e===`all`;return(0,L.jsxs)(N,{"data-export-context":`Results source: ${e}; Last 7 days; loaded ${Math.min(n,o.length)} rows`,className:`min-w-0 gap-0 overflow-hidden py-0`,children:[(0,L.jsxs)(`div`,{className:`space-y-2 border-b px-4 pt-2.5 pb-2`,children:[(0,L.jsxs)(`div`,{className:`flex min-h-9 flex-wrap items-center justify-between gap-2`,children:[(0,L.jsx)(`h2`,{ref:f,tabIndex:-1,className:z,children:b?`Recent results`:`Recent results & GitHub`}),(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:`Last 7 days`})]}),!b&&(0,L.jsx)(se,{slot:`dashboard-feed`,label:`Results source`,value:e,options:[{value:`all`,label:`All`},{value:`tasks`,label:`Tasks`},{value:`github`,label:`GitHub`}],onChange:t}),b&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Task results · No GitHub repositories configured`}),e!==`tasks`&&!b&&(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,open:y.length||h?!0:void 0,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-1.5`,children:[(0,L.jsx)(V,{}),y.length||h?`GitHub needs attention`:_?`Checking GitHub…`:v?`GitHub not configured`:m?`GitHub checked ${F(m)} ago`:`GitHub source`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3`,children:[(0,L.jsx)(`p`,{children:y.length||h?m?`Could not refresh GitHub. Showing results from ${new Date(m).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}.`:`Could not load one or more GitHub sources.`:_?`Checking repository sources. Available results remain visible.`:v?`No GitHub repositories configured. Select Tasks to see task results.`:m?`GitHub checked ${F(m)} ago`:`GitHub snapshot`}),!v&&(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11 px-0`,disabled:i.githubFetching,onClick:()=>{i.refetch()},children:i.githubFetching?`Refreshing…`:y.length||h?`Retry GitHub`:`Refresh GitHub`})]})]})]}),(0,L.jsxs)(`div`,{role:`region`,"aria-label":`Recent results list`,ref:l,onWheel:()=>{d.done=!0},onTouchStart:()=>{d.done=!0},onKeyDown:()=>{d.done=!0},onScroll:e=>{c&&d.done&&mt(c,u,{count:n,scroll:e.currentTarget.scrollTop})},tabIndex:0,className:`max-h-80 overflow-y-auto overscroll-contain focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,children:[i.isError&&(0,L.jsxs)(`p`,{role:`alert`,className:`p-4 text-sm`,children:[`Could not load results.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{i.retryFailed()},children:`Retry`})]}),i.isPending&&(0,L.jsx)(`p`,{className:`p-4 text-sm`,children:`Loading results…`}),s>0&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>{a.show(),f.current?.focus()},children:[s,` updates — Show`]}),o.slice(0,n).map(({row:e,removed:t})=>e.kind===`task-result`?(0,L.jsx)(ht,{row:e.run,kicker:t?`Outside current results`:`Latest result: ${e.run.status===`failed`?`Failed`:`Completed`}`},e.key):(0,L.jsxs)(`div`,{className:`border-b px-4 py-3 transition-colors hover:bg-muted/30`,children:[(0,L.jsx)(R,{rows:[{section:`github`,entity:`${e.repo}#${e.number}`,metric:e.itemKind,value:e.title,asOf:e.at,note:e.url}]}),(0,L.jsx)(`a`,{className:`block break-words text-sm font-medium hover:underline no-hover:min-h-11`,href:e.url,target:`_blank`,rel:`noreferrer`,children:e.title}),(0,L.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.repo,` · `,e.itemKind===`pr`?`PR`:`Issue`,` #`,e.number,` created ·`,` `,F(e.at)]})]},e.key)),i.data&&!i.data.rows.length&&!o.length&&!i.isFetching&&!i.isError&&!y.length&&!_&&i.data.coverage.projects.every(e=>e.state===`complete`)&&(0,L.jsx)(`p`,{className:`px-4 py-8 text-sm text-muted-foreground`,children:`No results in the last 7 days`}),n<o.length&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:r,children:[`Show `,Math.min(20,o.length-n),` more results`]}),i.data?.truncated&&(0,L.jsx)(`p`,{className:`p-4 text-xs`,children:`Showing the latest 60 results`}),i.data&&(0,L.jsx)(K,{coverage:i.data.coverage,retry:()=>{i.retryTasks()}}),!b&&i.data?.sources.some(e=>e.state!==`ready`||e.truncated)&&(0,L.jsxs)(`details`,{className:`p-4 text-xs`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden min-h-11`,children:[(0,L.jsx)(V,{}),`Source details`]}),i.data.sources.map(e=>(0,L.jsxs)(`p`,{className:`break-words py-1`,children:[Hn(e.key),`:`,` `,e.reason===`No GitHub remote`?`Not configured`:e.reason===`Still loading GitHub`?`Checking…`:e.reason??(e.state===`ready`?`Up to date`:e.state),e.truncated?` · capped`:``,e.fetchedAt?` · checked ${F(e.fetchedAt)}`:``]},e.key))]})]})]})}var $=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]),Gn=`Visible modules and loaded rows only. Filters and report availability apply. Retained task usage is not an invoice or a complete history.`,Kn=`Confidential — internal distribution only`,qn={costUsd:{label:`Reported cost`,usd:!0},inputTokens:{label:`Input tokens`},outputTokens:{label:`Output tokens`},needsYou:{label:`Needs you`},running:{label:`Running now`},completed:{label:`Completed in period`},failed:{label:`Failed outcomes in period`},medianCycleHours:{label:`Median cycle (hours)`}};function Jn(e,t){return e==null?`Unavailable`:typeof e==`string`?e:gt(e,t)}function Yn(e){let t=new Set,n=[];for(let r of e.modules)for(let e of r.rows){if(e.section!==`totals`&&e.section!==`fleet`&&e.section!==`overview`)continue;let i=qn[e.metric];!i||t.has(e.metric)||(t.add(e.metric),n.push({label:i.label,value:Jn(e.value,i.usd),note:[e.metric===`needsYou`||e.metric===`running`?e.note||`Current non-archived state`:r.filters,e.asOf?`Data as of ${e.asOf}`:``,e.reportedTasks==null?``:`${e.reportedTasks} of ${e.totalTasks} tasks reported`].filter(Boolean).join(` · `)}))}return n}function Xn(e){let t=e.cloneNode(!0);t.querySelectorAll(`script,style,link,img,iframe,object,embed,input,[hidden],[data-dashboard-export],[data-export-exclude]`).forEach(e=>e.remove()),t.querySelectorAll(`select`).forEach((t,n)=>{let r=e.querySelectorAll(`select`)[n];t.replaceWith(document.createTextNode(`: `+(r?.selectedOptions[0]?.textContent??``)))}),t.querySelectorAll(`[data-export-row],[data-dashboard-row]`).forEach(e=>e.classList.add(`report-row`)),t.querySelectorAll(`summary`).forEach(e=>{let t=document.createElement(`h3`);t.textContent=e.getAttribute(`data-export-heading`)||e.textContent,e.replaceWith(t)}),t.querySelectorAll(`button`).forEach(e=>{if(e.hasAttribute(`data-export-keep`)){let t=document.createElement(`div`);for(let n of[...e.attributes])[`class`,`style`,`title`].includes(n.name)&&t.setAttribute(n.name,n.value);t.append(...e.childNodes),e.replaceWith(t)}else e.remove()}),t.querySelectorAll(`details`).forEach(e=>{let t=document.createElement(`div`);t.className=e.className,t.append(...e.childNodes),e.replaceWith(t)});for(let e of[t,...t.querySelectorAll(`*`)])for(let t of[...e.attributes])(t.name.startsWith(`on`)||[`href`,`src`,`srcset`,`action`,`formaction`,`tabindex`].includes(t.name)||t.name.startsWith(`data-`))&&e.removeAttribute(t.name);return t.removeAttribute(`style`),t.innerHTML}function Zn(e,t,n,r){return{generatedAt:t,source:n,title:r||void 0,notices:[...e.querySelectorAll(`[role=alert],[role=status]`)].filter(e=>!e.closest(`[data-dashboard-module]`)).map(e=>e.textContent?.trim()??``).filter(Boolean),modules:[...e.querySelectorAll(`[data-dashboard-module]`)].map(e=>{let t=[...e.querySelectorAll(`select`)].map(e=>`${e.closest(`label`)?.childNodes[0]?.textContent?.trim()??`Filter`}: ${e.selectedOptions[0]?.textContent}`).concat([...e.querySelectorAll(`[data-export-context]`)].map(e=>e.dataset.exportContext)).join(`; `),n=[...new Set([...e.querySelectorAll(`p,[role="alert"],[role="status"]`)].filter(e=>!e.closest(`table,[data-export-exclude]`)&&!e.querySelector(`p,[role="alert"],[role="status"]`)).map(e=>{let t=e.cloneNode(!0);return t.querySelectorAll(`table,button,select,summary,[data-export-exclude]`).forEach(e=>e.remove()),t.textContent?.trim()}).filter(Boolean))].join(` | `);return{id:e.dataset.dashboardModule,title:e.querySelector(`h2`)?.textContent??e.dataset.dashboardModule,filters:t,notes:n,html:Xn(e),rows:[...e.querySelectorAll(`[data-dashboard-export]`)].flatMap(e=>JSON.parse(e.dataset.dashboardExport))}})}}function Qn(e){let t=e==null?``:String(e);return typeof e==`string`&&/^[\s\uFEFF]*[=+@\-]/.test(t)&&(t=`'${t}`),`"${t.replaceAll(`"`,`""`)}"`}function $n(e){let t=[[`generated_at`,`source`,`module`,`filters`,`section`,`entity`,`metric`,`value`,`unit`,`availability`,`reported_tasks`,`total_tasks`,`as_of`,`notes`]];for(let n of e.modules){t.push([e.generatedAt,e.source,n.title,n.filters,`context`,``,`scope`,Gn,``,``,``,``,``,[...e.title?[`Report title: ${e.title}`]:[],...e.notices,n.notes].join(` | `)]);for(let r of n.rows)t.push([e.generatedAt,e.source,n.title,n.filters,r.section,r.entity,r.metric,r.value,r.unit,r.value===null?`unavailable`:typeof r.value==`number`?`measured`:`reported`,r.reportedTasks,r.totalTasks,r.asOf,r.note])}return``+t.map(e=>e.map(Qn).join(`,`)).join(`\r
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{$i as r,$n as i,Bn as a,Cn as o,H as s,Ir as c,Ki as l,Kn as u,Rn as d,Ti as f,aa as p,an as m,na as h,nt as g,rn as _,sa as v,ti as y}from"./project-router-Bp0y3Wss.js";import{$ as b,F as x,Q as S,X as C,Y as w,Z as T,et as ee,gt as E,nt as D,t as O}from"./button-Cz2i1VWG.js";import{A as te,C as ne,E as re,M as k,N as A,O as j,P as M,T as ie,_ as ae,b as oe,c as se,d as ce,f as le,g as ue,h as de,i as fe,j as pe,m as me,p as he,v as ge,w as _e,x as ve,y as ye}from"./use-automations-gfSKvY5Q.js";import{a as be,i as xe,o as Se,r as Ce,t as we}from"./sheet-D3Gui9Gi.js";import{S as Te,a as Ee,o as De,r as Oe,t as ke}from"./reference-chip-BY5hNSAj.js";import{a as Ae,f as N,p as je,r as Me}from"./automation-format-x-IsIfyB.js";import{i as Ne,n as Pe,p as Fe,r as Ie,t as Le}from"./tooltip-CxsyqHYQ.js";import{t as Re}from"./chevron-right-qEQMQjVX.js";import{t as ze}from"./download-CNAZsQUZ.js";import{i as P,r as F,t as Be}from"./token-metrics-CCt2gB1-.js";import{t as Ve}from"./use-now-Dso5ls9n.js";import{t as He}from"./index-DUhrduZ3.js";var Ue=x(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),We=x(`arrow-down-left`,[[`path`,{d:`M17 7 7 17`,key:`15tmo1`}],[`path`,{d:`M17 17H7V7`,key:`1org7z`}]]),Ge=x(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Ke=x(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),qe=x(`grip-horizontal`,[[`circle`,{cx:`12`,cy:`9`,r:`1`,key:`124mty`}],[`circle`,{cx:`19`,cy:`9`,r:`1`,key:`1ruzo2`}],[`circle`,{cx:`5`,cy:`9`,r:`1`,key:`1a8b28`}],[`circle`,{cx:`12`,cy:`15`,r:`1`,key:`1e56xg`}],[`circle`,{cx:`19`,cy:`15`,r:`1`,key:`1a92ep`}],[`circle`,{cx:`5`,cy:`15`,r:`1`,key:`5r1jwy`}]]),Je=x(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]),I=e(t(),1);function Ye(e){let t=Date.parse(e.nextRunAt??``),n=Date.parse(e.state?.backoffUntil??``);return Number.isFinite(t)?Math.max(t,Number.isFinite(n)?n:t):null}function Xe(e){return e.flatMap(e=>(e.data?.automations??[]).filter(e=>e.enabled).map(t=>({project:e,automation:t,at:Ye(t)}))).sort((e,t)=>(e.at??1/0)-(t.at??1/0)||e.project.id.localeCompare(t.project.id)||e.automation.id.localeCompare(t.automation.id))}function Ze(e){let t=g(),n=v(),r=t.data?.projects??[],a=t.data?.bootProject,o=a&&!r.some(e=>e.id===a)?[...r,{id:a,name:a,status:`ok`}]:r,s=p({queryKey:[...m.dashboard,`automations`,o.map(e=>[e.id,e.name,e.status])],enabled:e&&!!t.data,queryFn:async({signal:e})=>{let t=0,n=[];return await Promise.all([0,1].map(async()=>{for(;t<o.length&&!e.aborted;){let r=o[t++];if(r.status===`missing`){n.push({...r,error:`Project folder unavailable`});continue}try{let t=D.parse(await f(await i.api.v1.workspace.dashboard.automations.$get({query:{projectId:r.id}},{init:{signal:e}}),`/workspace/dashboard/automations`));n.push({id:r.id,name:r.name,data:t})}catch{n.push({id:r.id,name:r.name,error:`Could not load automations`})}}})),n}});return(0,I.useEffect)(()=>{if(e)return j(e=>{e===`automation-change`&&n.invalidateQueries({queryKey:[...m.dashboard,`automations`]})})},[n,e]),{...s,registry:t,retry:()=>{t.refetch(),s.refetch()}}}var L=n();function R({rows:e}){return(0,L.jsx)(`span`,{hidden:!0,"data-dashboard-export":JSON.stringify(e)})}var z=`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,B=`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,Qe=`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden`;function V(){return(0,L.jsx)(Re,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-soft-foreground transition-transform duration-150 motion-reduce:transition-none [details[open]>summary>&]:rotate-90`})}var $e=`flex items-center gap-2 text-xs text-muted-foreground`;function et({className:e=``,...t}){return(0,L.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,L.jsx)(`select`,{...t,className:`h-9 cursor-pointer appearance-none rounded-md border bg-card-2 pr-8 pl-3 font-mono text-xs text-foreground outline-none transition-colors hover:border-foreground/20 hover:bg-muted focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 no-hover:min-h-11 ${e}`}),(0,L.jsx)(Fe,{"aria-hidden":`true`,className:`pointer-events-none absolute top-1/2 right-2.5 size-3.5 -translate-y-1/2 text-soft-foreground`})]})}var tt=`relative min-w-0 overflow-hidden rounded-lg border bg-card-2 p-4 transition-colors before:absolute before:inset-x-0 before:top-0 before:h-px before:opacity-80 hover:border-foreground/20 hover:bg-muted/40 sm:p-5`,H={violet:`before:bg-violet`,info:`before:bg-info`,success:`before:bg-success`,danger:`before:bg-danger`,primary:`before:bg-primary`,neutral:`before:bg-border`};function nt({label:e,value:t,icon:n,children:r}){return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`flex w-full items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] font-medium uppercase tracking-[0.12em] text-muted-foreground`,children:e}),(0,L.jsx)(`span`,{className:`text-soft-foreground`,"aria-hidden":`true`,children:n})]}),(0,L.jsx)(`span`,{className:`mt-4 block text-4xl font-semibold leading-none tracking-tight tabular-nums`,children:t}),(0,L.jsx)(`span`,{className:`mt-3 block text-xs text-soft-foreground`,children:r})]})}function rt({at:e}){return(0,L.jsxs)(`time`,{dateTime:e,title:new Date(e).toLocaleString(),children:[`Updated `,F(e),` ago`]})}function it(){let e=fe(),t=Ze(e.known&&!e.off),n=Ve(3e4),[r,i]=(0,I.useState)(!1),a=Xe(t.data??[]),o=r?a:a.slice(0,3),s=t.data?.filter(e=>e.error)??[],c=!e.known||!t.registry.isError&&(t.registry.isPending||t.isPending),u=t.isError||t.registry.isError||s.length>0;return(0,L.jsxs)(N,{"data-export-context":`Enabled automations · showing ${o.length} of ${a.length} loaded · ${u?`partial coverage`:`available projects`}`,className:`min-w-0 gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsxs)(`h2`,{className:`flex items-center ${z}`,children:[`Automations`,(0,L.jsx)(je,{className:`ml-2 size-3.5 text-soft-foreground`,"aria-hidden":`true`})]}),!e.off&&t.data&&(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:[a.length,` enabled`,u?` · partial`:``]})]}),!e.off&&t.data&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R,{rows:[{section:`automations`,metric:`enabled`,value:a.length,unit:`automations`,note:u?`Partial project coverage`:`Loaded projects`}]}),t.dataUpdatedAt>0&&(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:new Date(t.dataUpdatedAt).toISOString()})})]}),e.off?(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Automations are disabled in this workspace.`}):(0,L.jsxs)(L.Fragment,{children:[c&&(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading automations…`}),u&&(0,L.jsxs)(`div`,{role:`alert`,className:`p-4 text-sm`,children:[(0,L.jsx)(`p`,{children:`Some automation data could not be refreshed. Available results are shown.`}),s.map(e=>(0,L.jsxs)(`p`,{children:[e.name,`: `,e.error]},e.id)),(0,L.jsx)(O,{variant:`ghost`,onClick:t.retry,children:`Retry automations`})]}),!c&&!u&&a.length===0&&(0,L.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No enabled automations. Enable one in a project's Automations page.`}),o.map(({project:e,automation:t,at:r})=>{let i=(t.state?.consecutiveFailures??0)>0?`Recent checks failed`:void 0,a=r===null?`Next time not available`:r<=n?`Due — awaiting scheduler`:Ae(r,n),o=t.kind===`schedule`?`Next run`:`Next check`;return(0,L.jsxs)(`div`,{"data-export-row":!0,className:`border-b px-4 py-3 transition-colors last:border-0 hover:bg-muted/30`,children:[(0,L.jsx)(l,{className:`block min-h-11 text-sm font-medium hover:underline`,to:`/p/${encodeURIComponent(e.id)}/automations/${encodeURIComponent(t.id)}`,children:t.name}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.name,` · `,o,`: `,a]}),r!==null&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:(0,L.jsxs)(`time`,{dateTime:new Date(r).toISOString(),children:[Me(r,e.data.timeZone),` · `,e.data.timeZone]})}),t.kind!==`schedule`&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Checks for matching events; a task may not be started.`}),i&&(0,L.jsx)(`p`,{className:`mt-1 text-xs text-warning`,children:i}),(0,L.jsx)(R,{rows:[{section:`automation`,entity:`${e.id}:${t.id}`,metric:`name`,value:t.name},{section:`automation`,entity:`${e.id}:${t.id}`,metric:t.kind===`schedule`?`nextRunAt`:`nextCheckAt`,value:r===null?null:new Date(r).toISOString(),note:[a,i].filter(Boolean).join(` · `)}]})]},`${e.id}:${t.id}`)}),a.length>3&&(0,L.jsx)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>i(!r),children:r?`Show fewer`:`Show all ${a.length} enabled`}),!c&&(0,L.jsxs)(`details`,{className:`border-t px-4 py-2 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden min-h-11`,"data-export-heading":`Project automations`,children:[(0,L.jsx)(V,{}),`Manage automations by project`]}),t.data?.map(e=>(0,L.jsx)(l,{className:`block min-h-11 py-3 hover:underline`,to:`/p/${encodeURIComponent(e.id)}/automations`,children:e.name},e.id))]})]})]})}function at(e,t,n){let r=new Set,i=new Map(e.map((e,t)=>[n(e),{r:e,i:t}]));return t.forEach((e,t)=>{let a=i.get(n(e));(!a||a.i!==t||JSON.stringify(a.r)!==JSON.stringify(e))&&r.add(n(e)),i.delete(n(e))}),i.forEach((e,t)=>r.add(t)),r}function ot(e,t,n){let r=new Map(t.map(e=>[n(e),e]));return e.map(e=>({row:r.get(n(e))??e,removed:!r.has(n(e))}))}var st=(0,I.createContext)(``),ct=(0,I.createContext)(!0),U=new Map;function lt(e,t,n=``,r=0,i){let a=(0,I.useContext)(st),o=`${a}:${n}`,[s,c]=(0,I.useState)(()=>U.get(o)),[l,u]=(0,I.useState)(o),d=(0,I.useRef)(r),f=(0,I.useRef)(!1);l!==o&&(u(o),c(U.get(o)),d.current=r,f.current=!1),d.current!==r&&(d.current=r,f.current=!0),(0,I.useEffect)(()=>{e&&(!s||f.current)&&(c(e),f.current=!1)},[s,e]);let p=(0,I.useMemo)(()=>({current:s}),[o]);p.current=s,(0,I.useEffect)(()=>()=>{!a||!p.current||(U.delete(o),U.set(o,p.current),U.size>60&&U.delete(U.keys().next().value))},[a,o,p]);let m=s??e??[],h=new Set((e??m).map(t)),g=i?m.filter(e=>h.has(t(e))||i(e)):m;return{rows:ot(g,e??m,t),updates:e?at(g,e,t).size:0,show:()=>c(e)}}var ut=new Map;function dt(e){return ut.get(e)}function ft(e,t){ut.delete(e),ut.set(e,t),ut.size>20&&ut.delete(ut.keys().next().value)}var W=new Map;function pt(e,t){return W.get(e)?.[t]}function mt(e,t,n){let r=W.get(e)??{};r[t]=n,W.delete(e),W.set(e,r),W.size>20&&W.delete(W.keys().next().value)}var G=e=>`${e.projectId}:${e.id}`;function ht({row:e,removed:t=!1,queue:n=!1,checking:r=!1,checkFailed:i=!1,kicker:s}){let c=(0,I.useContext)(ct)&&!r&&!i,u=M(e);t=t||u===null||n&&u?.archived===!0,u&&(e={...e,status:u.status,awaitingAnswerSince:u.awaitingAnswerSince});let f=d(e),p=n&&!a(e),m=t||p||!c;return(0,L.jsxs)(`div`,{"data-dashboard-row":G(e),className:`min-w-0 border-b px-4 py-3 transition-colors last:border-0 hover:bg-muted/30`,children:[(0,L.jsx)(R,{rows:[{section:`task`,entity:G(e),metric:`title`,value:e.titleSummary||e.title},{section:`task`,entity:G(e),metric:`status`,value:m?`Not currently actionable`:e.status},{section:`task`,entity:G(e),metric:`createdAt`,value:e.createdAt}]}),s&&(0,L.jsx)(`p`,{className:`mb-1 pl-[15px] font-mono text-[10.5px] uppercase tracking-[0.1em] text-soft-foreground`,children:s}),(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(P,{tone:f.tone,className:`mt-[7px]`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(l,{tabIndex:m?-1:void 0,"aria-disabled":m||void 0,onClick:e=>{m&&e.preventDefault()},to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,className:`block break-words text-sm font-medium leading-relaxed hover:underline no-hover:min-h-11`,children:e.titleSummary||e.title}),(0,L.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:e.projectId}),(0,L.jsx)(`span`,{children:i?`Could not check current state`:c?t?n&&u!==null?`No longer needs you`:`Task removed`:p?`No longer needs you`:f.label:`Checking current state…`}),(0,L.jsx)(`span`,{children:F(e.createdAt)}),e.dispatch&&(0,L.jsx)(`span`,{children:`Subtask`}),!m&&o(e).map(t=>(0,L.jsx)(ke,{reference:t,taskTitle:e.title,projectId:e.projectId,className:`no-hover:min-h-11`},`${t.kind}:${t.number}`))]})]})]})]})}function K({coverage:e,count:t,retry:n}){let r=e.projects.filter(e=>e.state!==`complete`);return r.length?(0,L.jsxs)(`div`,{className:`rounded-lg border border-pending/40 bg-card-2 p-3 text-sm`,role:`status`,children:[(0,L.jsxs)(`p`,{children:[t===void 0?``:`${t} tasks need you in the available data. Complete coverage: ${e.projects.length-r.length} of ${e.projects.length} projects. `,r.length===1?r[0].state===`unavailable`?`One project is unavailable.`:`One project has incomplete coverage.`:`${r.length} projects have incomplete coverage.`]}),(0,L.jsxs)(`details`,{className:`mt-2`,children:[(0,L.jsxs)(`summary`,{className:`${Qe} min-h-11`,children:[(0,L.jsx)(V,{}),`View unavailable `,r.length===1?`project`:`projects`]}),r.map(e=>(0,L.jsxs)(`p`,{children:[e.projectId,`: `,e.reason??e.state,e.omittedRuns>0?` · ${e.omittedRuns} omitted tasks`:``]},e.projectId))]}),(0,L.jsx)(O,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Retry`})]}):null}function gt(e,t=!1){return e==null?`Unavailable`:t?`$${e.toFixed(e===0||e>=1?2:Math.min(20,Math.max(4,Math.ceil(-Math.log10(e))+1)))}`:e.toLocaleString(`en-US`)}function q(e){return e===null?`Unavailable`:e<1?`${Math.round(e*60)}m`:e<48?`${e.toFixed(1)}h`:`${(e/24).toFixed(1)}d`}function _t(e,t,n){let i=r(),a=i.state?.dashboardEntry??i.key,[o,s]=h(),c=o.get(e);return[c!==null&&t.includes(c)?c:n,t=>s(n=>{let r=new URLSearchParams(n);return r.set(e,t),r},{replace:!0,state:{...i.state,dashboardEntry:a}})]}var vt=e=>`Last ${e===`7d`?7:30} calendar days`,yt=`font-mono text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground`,bt=`min-w-0 rounded-lg border bg-card-2 p-4`,J=`whitespace-nowrap px-3 py-2 font-mono text-[11px] font-medium uppercase tracking-[0.1em] text-soft-foreground`;function xt(){let e=g().data?.projects;return t=>e?.find(e=>e.id===t)?.name??t}var St=(e,t)=>`/p/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}`;function Ct({label:e,value:t,onChange:n}){return(0,L.jsxs)(`label`,{className:$e,children:[e,(0,L.jsxs)(et,{value:t,onChange:e=>n(e.target.value===`30d`?`30d`:`7d`),children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})}function wt({query:e}){return e.isPending?(0,L.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading insights…`}):e.isError?(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[e.data?`Showing previous results. `:``,`Could not refresh insights.`,` `,(0,L.jsx)(O,{variant:`outline`,onClick:()=>void e.refetch(),children:`Retry insights`})]}):null}function Tt({period:e,active:t}){let n=He(e,t),r=n.data;return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsx)(wt,{query:n}),r&&(0,L.jsx)(K,{coverage:r.coverage,retry:()=>void n.refetch()}),r&&(0,L.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[(0,L.jsx)(Et,{data:r}),(0,L.jsx)(Dt,{data:r})]})]})}function Et({data:e}){let t=e.delivered,n=[{label:`PRs opened`,value:t.prsOpened,note:`${t.prsTouched} touched`},{label:`Lines`,value:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`text-success`,children:[`+`,t.additions.toLocaleString(`en-US`)]}),` `,(0,L.jsxs)(`span`,{className:`text-danger`,children:[`−`,t.deletions.toLocaleString(`en-US`)]})]})},{label:`Files`,value:t.files.toLocaleString(`en-US`)},{label:`Issues`,value:t.issues}];return(0,L.jsxs)(`section`,{className:bt,"aria-label":`Delivered`,children:[(0,L.jsx)(R,{rows:Object.entries(t).map(([t,n])=>({section:`delivered`,metric:t,value:n,unit:[`additions`,`deletions`].includes(t)?`lines`:t===`files`?`files`:`count`,asOf:e.asOf,note:`Completed since ${e.windowStart}`}))}),(0,L.jsx)(`h3`,{className:yt,children:`Delivered`}),(0,L.jsx)(`dl`,{className:`mt-3 grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-4`,children:n.map(e=>(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`dt`,{className:`text-xs text-soft-foreground`,children:e.label}),(0,L.jsx)(`dd`,{className:`mt-1 truncate text-xl font-semibold tracking-tight tabular-nums`,children:e.value}),e.note&&(0,L.jsx)(`dd`,{className:`text-xs text-soft-foreground`,children:e.note})]},e.label))}),(0,L.jsxs)(`span`,{className:`mt-3 block text-xs text-soft-foreground`,children:[`From `,t.completedTasks,` completed `,t.completedTasks===1?`task`:`tasks`,` ·`,` `,t.measuredTasks,` with a stored diff`]})]})}function Dt({data:e}){let t=xt(),{total:n,reasons:r}=e.failures;return(0,L.jsxs)(`section`,{className:bt,"aria-label":`Why tasks failed`,children:[(0,L.jsx)(R,{rows:r.map(t=>({section:`failures`,entity:t.label,metric:t.category,value:t.count,unit:`tasks`,asOf:e.asOf,note:t.latest.message}))}),(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,L.jsx)(`h3`,{className:yt,children:`Why tasks failed`}),n>0&&(0,L.jsxs)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:[n,` failed`]})]}),n===0?(0,L.jsxs)(`span`,{className:`mt-4 flex items-center gap-2.5 text-sm text-muted-foreground`,children:[(0,L.jsx)(P,{tone:`success`}),`No failed outcomes in this period`]}):(0,L.jsx)(`ul`,{className:`mt-3 space-y-3`,children:r.map(e=>(0,L.jsx)(Ot,{reason:e,total:n,projectName:t},`${e.category}:${e.label}`))})]})}function Ot({reason:e,total:t,projectName:n}){let{latest:r}=e;return(0,L.jsxs)(`li`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-sm`,children:[(0,L.jsx)(`span`,{className:`min-w-0 truncate font-medium`,title:e.label,children:e.label}),(0,L.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:e.count})]}),(0,L.jsx)(`div`,{className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full bg-danger/70`,style:{width:`${e.count/t*100}%`}})}),(0,L.jsxs)(`span`,{className:`mt-1.5 block truncate text-xs text-soft-foreground`,title:r.message,children:[`Latest:`,` `,(0,L.jsx)(l,{className:`text-muted-foreground hover:text-foreground hover:underline`,to:St(r.projectId,r.id),children:r.title}),` `,`· `,n(r.projectId),r.step?` · ${r.step}`:``,` · `,F(r.at),` ago`]})]})}var kt={claude:`Claude Code`,codex:`Codex`,opencode:`OpenCode`,cursor:`Cursor`,pi:`Pi`,unknown:`Unknown backend`,mixed:`Mixed backends`},At=e=>kt[e]??e,jt=(e,t)=>t?Math.round(e/t*100):0;function Mt(){let[e,t]=_t(`backends`,[`7d`,`30d`],`7d`),n=He(e),r=n.data,i=r?.visibility.cost;return(0,L.jsx)(`section`,{"data-dashboard-module":`backends`,className:`min-w-0`,children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Backends: ${vt(e)}; finished tasks`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Backends & models`}),(0,L.jsx)(Ct,{label:`Finished`,value:e,onChange:t})]}),(0,L.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,L.jsx)(wt,{query:n}),r&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Tasks that finished done or failed in the period, by the backend and model their steps ran on. Includes subtasks. Cost is reported USD only.`}),(0,L.jsx)(K,{coverage:r.coverage,retry:()=>void n.refetch()}),r.backends.length?(0,L.jsx)(`div`,{className:`overflow-x-auto`,role:`region`,"aria-label":`Backend comparison`,tabIndex:0,children:(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:J,children:`Backend`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Finished`}),(0,L.jsx)(`th`,{className:J,children:`Success`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Median cycle`}),i&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Reported USD`}),i&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Per completed`})]})}),(0,L.jsx)(`tbody`,{children:r.backends.map(e=>(0,L.jsx)(Nt,{stat:e,cost:!!i},`${e.backend}:${e.model??``}`))})]})}):(0,L.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No finished tasks in this period.`}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:(0,L.jsx)(rt,{at:r.asOf})}),(0,L.jsx)(R,{rows:r.backends.flatMap(e=>[`finished`,`done`,`failed`,`medianCycleHours`].map(t=>({section:`backends`,entity:`${e.backend}${e.model?`:${e.model}`:``}`,metric:t,value:e[t],unit:t===`medianCycleHours`?`hours`:`tasks`,asOf:r.asOf})))})]})]})]})})}function Nt({stat:e,cost:t}){let n=jt(e.done,e.finished),r=e.costUsd?.value;return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2.5`,children:[(0,L.jsx)(`span`,{className:`block font-medium`,children:At(e.backend)}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:e.backend===`mixed`?`steps ran on different backends`:e.model??`default model`})]}),(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:e.finished}),(0,L.jsxs)(`td`,{className:`min-w-40 px-3 py-2.5`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`h-1.5 flex-1 overflow-hidden rounded-full bg-danger/40`,"aria-hidden":`true`,children:(0,L.jsx)(`span`,{className:`block h-full rounded-full bg-success`,style:{width:`${n}%`}})}),(0,L.jsxs)(`span`,{className:`w-10 text-right font-mono text-xs tabular-nums`,children:[n,`%`]})]}),(0,L.jsxs)(`span`,{className:`block text-xs text-soft-foreground`,children:[e.done,` done · `,e.failed,` failed`]})]}),(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:e.timedTasks?q(e.medianCycleHours):`—`}),t&&(0,L.jsxs)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:[r==null?`—`:gt(r,!0),(0,L.jsxs)(`span`,{className:`block text-xs text-soft-foreground`,children:[e.costUsd?.reportedTasks??0,`/`,e.finished,` reported`]})]}),t&&(0,L.jsx)(`td`,{className:`px-3 py-2.5 text-right tabular-nums`,children:r==null||!e.done?`—`:gt(r/e.done,!0)})]})}function Pt(){let[e,t]=_t(`automations`,[`7d`,`30d`],`7d`),n=fe(),r=He(e),i=Ze(n.known&&!n.off),a=xt(),o=r.data,s=o?.visibility.cost,c=new Map;for(let e of i.data??[])for(let t of e.data?.automations??[])c.set(`${e.id}\u0000${t.id}`,{projectId:e.id,automationId:t.id,name:t.name,enabled:t.enabled,definition:`known`});let l=new Set((i.data??[]).flatMap(e=>e.data&&!e.error?[e.id]:[])),u=i.isError||i.registry.isError||(i.data??[]).some(e=>e.error);for(let e of o?.automations??[]){let t=`${e.projectId}\u0000${e.automationId}`,n=c.get(t);c.set(t,n?{...n,stat:e}:{...e,name:e.automationId,definition:l.has(e.projectId)?`removed`:`unknown`,stat:e})}let d=[...c.values()].sort((e,t)=>(t.stat?.tasks??0)-(e.stat?.tasks??0)||Number(t.enabled??!1)-Number(e.enabled??!1)||e.name.localeCompare(t.name));return(0,L.jsx)(`section`,{"data-dashboard-module":`automation-outcomes`,className:`min-w-0`,children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Automation outcomes: tasks created in ${vt(e)}`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Automation outcomes`}),(0,L.jsx)(Ct,{label:`Launched`,value:e,onChange:t})]}),(0,L.jsx)(`div`,{className:`space-y-3 p-4`,children:n.off?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Automations are disabled in this workspace.`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(wt,{query:r}),o&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Tasks each automation created in the period and how they ended. Active means still running, queued, waiting on you, or waiting to resume after a usage limit.`}),(0,L.jsx)(K,{coverage:o.coverage,retry:()=>void r.refetch()}),u&&(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[`Some automation details could not be loaded. Their outcomes are shown by id.`,` `,(0,L.jsx)(O,{variant:`ghost`,onClick:i.retry,children:`Retry automations`})]}),d.length?(0,L.jsx)(`div`,{className:`overflow-x-auto`,role:`region`,"aria-label":`Automation outcomes`,tabIndex:0,children:(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{className:J,children:`Automation`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Tasks`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Done`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Failed`}),(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Active`}),(0,L.jsx)(`th`,{className:J,children:`Last run`}),s&&(0,L.jsx)(`th`,{className:`${J} text-right`,children:`Reported USD`})]})}),(0,L.jsx)(`tbody`,{children:d.map(e=>(0,L.jsx)(Ft,{row:e,cost:!!s,projectName:a},`${e.projectId}:${e.automationId}`))})]})}):(0,L.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No automations yet. Create one in a project's Automations page.`}),(0,L.jsx)(`span`,{className:`block font-mono text-[11px] text-soft-foreground`,children:(0,L.jsx)(rt,{at:o.asOf})}),(0,L.jsx)(R,{rows:d.flatMap(e=>[`tasks`,`done`,`failed`,`active`].map(t=>({section:`automation-outcomes`,entity:`${e.projectId}:${e.automationId}`,metric:t,value:e.stat?.[t]??0,unit:`tasks`,asOf:o.asOf,note:e.name})))})]})]})})]})})}function Ft({row:e,cost:t,projectName:n}){let r=e.stat,i=`px-3 py-2.5 text-right tabular-nums`,a=e=>e||(0,L.jsx)(`span`,{className:`text-soft-foreground`,children:`0`});return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2.5`,children:[e.definition===`removed`?(0,L.jsx)(`span`,{className:`block font-medium`,children:e.name}):(0,L.jsx)(l,{className:`block font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/automations/${encodeURIComponent(e.automationId)}`,children:e.name}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-soft-foreground`,children:[(0,L.jsx)(P,{tone:e.enabled?`success`:`neutral`}),n(e.projectId),` ·`,` `,e.definition===`removed`?`Removed`:e.definition===`unknown`?`Details unavailable`:e.enabled?`Enabled`:`Disabled`]})]}),(0,L.jsx)(`td`,{className:i,children:a(r?.tasks)}),(0,L.jsx)(`td`,{className:i,children:a(r?.done)}),(0,L.jsx)(`td`,{className:`${i} ${r?.failed?`text-danger`:``}`,children:a(r?.failed)}),(0,L.jsx)(`td`,{className:i,children:a(r?.active)}),(0,L.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2.5 text-xs text-muted-foreground`,children:r?.lastRunAt?(0,L.jsxs)(`time`,{dateTime:r.lastRunAt,title:new Date(r.lastRunAt).toLocaleString(),children:[F(r.lastRunAt),` ago · `,r.lastStatus]}):`—`}),t&&(0,L.jsx)(`td`,{className:i,children:r?.costUsd?.value==null?`—`:gt(r.costUsd.value,!0)})]})}var It=0,Lt=()=>++It,Y=new Map;function X(e,t){let n=(0,I.useContext)(st),r=()=>{let r=n?Y.get(n):void 0;return r?.has(e)?r.get(e):typeof t==`function`?t():t},[i,a]=(0,I.useState)(r),o=`${n}:${e}`,[s,c]=(0,I.useState)(o);o!==s&&(c(o),a(()=>r()));let l=(0,I.useMemo)(()=>({value:i}),[n,e]);return l.value=i,(0,I.useEffect)(()=>()=>{if(!n)return;let t=Y.get(n)??new Map;t.set(e,l.value),t.size>80&&t.delete(t.keys().next().value),Y.delete(n),Y.set(n,t),Y.size>20&&Y.delete(Y.keys().next().value)},[n,e,l]),[i,a]}var Rt=`a[href], button, select, input, [tabindex]`;function zt(e){let[t]=X(`${e}:position`,()=>({scroll:0})),n=(0,I.useCallback)(e=>{let n=[...e.querySelectorAll(Rt)],r=t.href?n.find(e=>e.getAttribute(`href`)===t.href):t.index===void 0?void 0:n[t.index];return r&&r.getAttribute(`aria-disabled`)!==`true`&&r.focus({preventScroll:!0}),e.scrollTop=t.scroll,!!r&&r.getAttribute(`aria-disabled`)!==`true`},[t]),r=(0,I.useMemo)(()=>({restore:()=>!1}),[t]);return{ref:(0,I.useCallback)(e=>{if(!e)return;let i=t.href!==void 0||t.index!==void 0,a=()=>{if(!i)return!1;let r=n(e);return r?(i=!1,o.disconnect()):e.querySelector(`[data-sheet-loading="false"]`)&&(i=!1,o.disconnect(),e.querySelector(`button:not([disabled]), select, [tabindex="0"]`)?.focus({preventScroll:!0}),e.scrollTop=t.scroll),r};r.restore=a;let o=new MutationObserver(a);i&&o.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-sheet-loading`]});let s=()=>{i=!1,o.disconnect()},c=()=>{i||(t.scroll=e.scrollTop)},l=n=>{i||!(n.target instanceof HTMLElement)||(t.href=n.target.getAttribute(`href`)??void 0,t.index=[...e.querySelectorAll(Rt)].indexOf(n.target))};return e.addEventListener(`pointerdown`,s),e.addEventListener(`keydown`,s),e.addEventListener(`wheel`,s,{passive:!0}),e.addEventListener(`scroll`,c),e.addEventListener(`focusin`,l),()=>{o.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`keydown`,s),e.removeEventListener(`wheel`,s),e.removeEventListener(`scroll`,c),e.removeEventListener(`focusin`,l)}},[t,n,r]),onOpenAutoFocus:e=>{(t.href!==void 0||t.index!==void 0)&&(e.preventDefault(),r.restore())}}}function Bt(e,t){let n=(0,I.useRef)(null),[r,i]=X(`${e}:trigger`,null);return{capture:()=>{let e=document.activeElement;n.current=e instanceof HTMLElement&&e!==document.body?e:null,i(n.current?{label:n.current.getAttribute(`aria-label`),text:n.current.textContent}:null)},restore:()=>{((n.current?.isConnected?n.current:r?[...document.querySelectorAll(`button`)].find(e=>!e.closest(`[role="dialog"]`)&&!e.hasAttribute(`disabled`)&&(r.label?e.getAttribute(`aria-label`)===r.label:e.textContent===r.text)):void 0)??document.querySelector(t))?.focus({preventScroll:!0})}}}function Vt(e,t=!0){return p({queryKey:[...m.dashboard,`overview`,e],enabled:t,staleTime:5e3,refetchInterval:t&&!e.snapshotId?15e3:!1,refetchIntervalInBackground:!1,retry:!1,queryFn:async({signal:t})=>w.parse(await f(await i.api.v1.workspace.dashboard.overview.$get({query:{period:e.period??`7d`,group:e.group??`completed`,tzOffsetMinutes:String(e.tzOffsetMinutes??new Date().getTimezoneOffset()),...e.snapshotId?{snapshotId:e.snapshotId}:{},...e.projectId?{projectId:e.projectId}:{},offset:String(e.offset??0),limit:`20`}},{init:{signal:t}}),`/workspace/dashboard/overview`))})}var Ht={running:`Running now`,"needs-you":`Needs you`,completed:`Completed`,failed:`Failed outcomes`},Ut={"needs-you":H.violet,running:H.info,completed:H.success,failed:H.danger},Wt={"needs-you":Ke,running:Ue,completed:re,failed:Ge};function Gt({active:e,children:t,onCurrent:n}){let[r,i]=_t(`period`,[`7d`,`30d`],`7d`),a=Bt(`outcome`,`[data-outcome-trigger]`),o=g().data?.projects,s=e=>o?.find(t=>t.id===e)?.name??e,c=Vt({period:r},e),[u,d]=X(`outcome:selection`,null),f=zt(`outcome:${u?.identity??`closed`}`),p=pe();if((0,I.useEffect)(()=>{e||d(null)},[e]),!e)return t({});let m=c.data,h=(e,t)=>{a.capture(),m&&d({identity:Lt(),snapshot:m,group:e,projectId:t})},_=m?.coverage.projects.every(e=>e.state===`complete`);return(0,L.jsxs)(L.Fragment,{children:[t({overview:(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Workspace overview`}),(0,L.jsxs)(`label`,{className:$e,children:[`Outcomes period`,(0,L.jsxs)(et,{value:r,onChange:e=>{i(e.target.value===`30d`?`30d`:`7d`),d(null)},children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-4 p-4`,children:[c.isPending&&(0,L.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading overview…`}),c.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[m?`Showing previous results. `:``,`Could not refresh overview.`,` `,(0,L.jsx)(O,{variant:`outline`,onClick:()=>void c.refetch(),children:`Retry overview`})]}),m&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[m.metrics.needsYou?`${m.metrics.needsYou} tasks require your input or review.`:_&&p.connected&&!c.isError?`No tasks currently require your input or review.`:`No waiting tasks found in the available data.`,` `,m.metrics.failed,` failed `,m.metrics.failed===1?`outcome`:`outcomes`,` `,`in this period. Includes subtasks; completed does not mean accepted or deployed.`]}),(0,L.jsx)(K,{coverage:m.coverage,retry:()=>void c.refetch()}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[`needs-you`,`running`,`completed`,`failed`].map(e=>{let t=m.metrics[e===`needs-you`?`needsYou`:e],i=Wt[e];return(0,L.jsxs)(O,{"data-outcome-trigger":!0,"data-export-keep":!0,variant:`outline`,className:`relative min-w-0 overflow-hidden rounded-lg border bg-card-2 p-4 transition-colors before:absolute before:inset-x-0 before:top-0 before:h-px before:opacity-80 hover:border-foreground/20 hover:bg-muted/40 sm:p-5 group/metric h-auto min-h-24 flex-col items-start gap-0 whitespace-normal text-left font-normal ${t===0?H.neutral:Ut[e]}`,onClick:t=>{n&&(e===`running`||e===`needs-you`)?n(e,t.currentTarget):h(e)},"aria-label":`${Ht[e]}: ${t}`,children:[(0,L.jsx)(nt,{label:Ht[e],value:t,icon:(0,L.jsx)(i,{className:`size-4`}),children:e===`running`||e===`needs-you`?`Current state`:`Last ${r===`7d`?7:30} calendar days`}),(0,L.jsxs)(`span`,{"data-export-exclude":!0,className:`mt-4 flex items-center gap-1 text-xs font-medium text-muted-foreground transition-colors group-hover/metric:text-foreground`,children:[`View tasks`,` `,(0,L.jsx)(Re,{className:`size-3 transition-transform group-hover/metric:translate-x-0.5 motion-reduce:transition-none`,"aria-hidden":`true`})]})]},e)})}),(0,L.jsx)(Tt,{period:r,active:e}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-1 border-t pt-3`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Median cycle time`,` `,(0,L.jsx)(`strong`,{className:`font-mono font-semibold text-foreground`,children:q(m.metrics.medianCycleHours)}),` `,`· `,m.metrics.timedTasks,`/`,m.metrics.completed,` completed tasks have valid timings.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`h-auto px-1.5 py-1 text-sm text-foreground underline-offset-4 hover:underline`,onClick:()=>h(`completed`),children:`Inspect completed tasks`})]}),(0,L.jsx)(`p`,{className:`font-mono text-[11px] text-soft-foreground`,children:(0,L.jsxs)(`time`,{dateTime:m.asOf,title:new Date(m.asOf).toLocaleString(),children:[`Updated `,F(m.asOf),` ago`]})})]}),(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-1`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsx)(`p`,{className:`mt-1 max-w-prose pl-5 leading-relaxed`,children:`Outcomes use finish dates, including archived tasks. Scheduled retries are excluded from failed outcomes. Period includes today at your current fixed UTC offset.`})]}),(0,L.jsx)(R,{rows:Object.entries(m.metrics).map(([e,t])=>({section:`overview`,metric:e,value:t,unit:e===`medianCycleHours`?`hours`:`tasks`,asOf:m.asOf,note:e===`running`||e===`needsYou`?`Current non-archived state`:`Finished since ${m.windowStart}`}))})]})]})]}),portfolio:m&&(0,L.jsx)(`div`,{children:(0,L.jsxs)(N,{className:`gap-0 py-0`,"data-export-context":`Outcomes: Last ${r===`7d`?7:30} calendar days; workload: current state`,children:[(0,L.jsx)(`div`,{className:`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,children:(0,L.jsx)(`h2`,{className:`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Projects`})}),(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:`Current workload and outcomes for the selected period. Sorted by tasks needing you, then running tasks. Counts include subtasks.`}),(0,L.jsxs)(`div`,{className:`overflow-x-auto px-1 pb-2`,role:`region`,"aria-label":`Project outcomes`,tabIndex:0,children:[(0,L.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsx)(`tr`,{children:[`Project`,`Needs you`,`Running`,`Completed`,`Failed`,`Median cycle`].map(e=>(0,L.jsx)(`th`,{className:`whitespace-nowrap px-3 py-2 font-mono text-[11px] font-medium uppercase tracking-[0.1em] text-soft-foreground ${e===`Project`?``:`text-right`}`,children:e},e))})}),(0,L.jsx)(`tbody`,{children:m.projects.map(e=>{let t=m.coverage.projects.find(t=>t.projectId===e.projectId);return(0,L.jsxs)(`tr`,{className:`border-t transition-colors hover:bg-muted/30`,children:[(0,L.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,L.jsx)(l,{className:`font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/tasks`,children:s(e.projectId)}),t?.state!==`complete`&&(0,L.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Incomplete data`})]}),[`needs-you`,`running`,`completed`,`failed`].map(n=>(0,L.jsx)(`td`,{className:`px-3 py-1 text-right`,children:(0,L.jsx)(O,{"data-export-keep":!0,variant:`ghost`,className:`min-h-11 tabular-nums`,"aria-label":`${s(e.projectId)}: ${Ht[n]}: ${t?.state===`unavailable`?`Unavailable`:e[n===`needs-you`?`needsYou`:n]}`,disabled:t?.state===`unavailable`,onClick:()=>h(n,e.projectId),children:t?.state===`unavailable`?`Unavailable`:e[n===`needs-you`?`needsYou`:n]})},n)),(0,L.jsxs)(`td`,{className:`px-3 py-2 text-right tabular-nums`,children:[q(e.medianCycleHours),(0,L.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.timedTasks,`/`,e.completed,` timed`]})]})]},e.projectId)})})]}),!m.projects.length&&(0,L.jsx)(`p`,{className:`py-4`,children:`No projects to compare yet.`})]}),(0,L.jsx)(R,{rows:m.projects.flatMap(({projectId:e,...t})=>Object.entries(t).map(([t,n])=>({section:`portfolio`,entity:e,metric:t,value:m.coverage.projects.find(t=>t.projectId===e)?.state===`unavailable`?null:n,unit:t===`medianCycleHours`?`hours`:`tasks`,asOf:m.asOf,note:`Outcomes since ${m.windowStart}; running and needsYou are current state`})))})]})})}),(0,L.jsx)(we,{open:!!u,onOpenChange:e=>{e||d(null)},children:(0,L.jsxs)(Ce,{...f,className:`w-full overflow-y-auto sm:max-w-xl`,onCloseAutoFocus:e=>{e.preventDefault(),a.restore()},children:[(0,L.jsxs)(be,{children:[(0,L.jsxs)(Se,{children:[u?Ht[u.group]:`Tasks`,u?.projectId?` · ${u.projectId}`:``]}),(0,L.jsx)(xe,{children:`Tasks behind the selected metric. Includes subtasks. Snapshot keeps counts and rows consistent.`})]}),u&&(0,L.jsx)(Kt,{selection:u,projectName:s,refresh:()=>{d(null),c.refetch()}},u.identity)]})})]})}function Kt({selection:e,refresh:t,projectName:n}){let[r,i]=X(`outcome:${e.identity}:offset`,0),a=Vt({period:e.snapshot.period,snapshotId:e.snapshot.snapshotId,group:e.group,projectId:e.projectId,offset:r}),o=(0,I.useRef)(null),s=(0,I.useRef)(null);(0,I.useEffect)(()=>{a.data&&s.current===r&&(o.current?.focus(),s.current=null)},[a.data,r]);let c=e=>{s.current=e,i(e)};return(0,L.jsxs)(`div`,{className:`space-y-3 p-4`,"data-sheet-loading":a.isFetching,children:[a.isPending&&(0,L.jsx)(`p`,{children:`Loading tasks…`}),a.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[`This snapshot may have expired or become unavailable.`,` `,(0,L.jsx)(O,{onClick:t,children:`Refresh overview`})]}),a.data&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{ref:o,tabIndex:-1,className:`text-xs text-muted-foreground`,children:[a.data.page.total,` tasks · Snapshot from`,` `,(0,L.jsxs)(`time`,{dateTime:a.data.asOf,title:new Date(a.data.asOf).toLocaleString(),children:[F(a.data.asOf),` ago`]})]}),a.data.page.rows.map(t=>(0,L.jsx)(qt,{row:t,group:e.group,projectName:n},`${t.projectId}:${t.id}`)),!a.data.page.rows.length&&(0,L.jsx)(`p`,{children:`No tasks in this group.`})]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(O,{variant:`outline`,disabled:!r||a.isFetching,onClick:()=>c(Math.max(0,r-20)),children:`Previous`}),(0,L.jsx)(O,{variant:`outline`,disabled:!a.data||a.data.page.nextOffset===null||a.isFetching,onClick:()=>c(a.data.page.nextOffset),children:`Next`})]})]})}function qt({row:e,group:t,projectName:n}){let r=M(e),i=t===`running`||t===`needs-you`;i&&r&&(e={...e,...r});let o=r===null,s=i&&(e.archived||(t===`running`?e.status!==`running`:!a(e))),c=o||s,u=d(e),f=i&&o?`Task removed`:s?t===`running`?`No longer running`:`No longer needs you`:u.label;return(0,L.jsxs)(`div`,{className:`border-b py-3`,children:[(0,L.jsx)(l,{"aria-disabled":c||void 0,tabIndex:c?-1:void 0,onClick:e=>{c&&e.preventDefault()},className:`block min-h-11 font-medium hover:underline`,to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,children:e.titleSummary||e.title}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsx)(P,{tone:u.tone}),` `,n(e.projectId),` ·`,` `,f,` · `,e.archived?`Archived · `:``,(0,L.jsxs)(`time`,{dateTime:e.finishedAt??e.createdAt,title:new Date(e.finishedAt??e.createdAt).toLocaleString(),children:[e.finishedAt?`Finished`:`Created`,` `,F(e.finishedAt??e.createdAt),` ago`]})]})]})}var Jt={snapshot:[...m.dashboard,`snapshot`],feed:e=>[...m.dashboard,`feed`,e],telemetry:[...m.dashboard,`telemetry`]},Yt=new Map;async function Xt(e){let t=k(),n=S.parse(await f(await i.api.v1.workspace.dashboard.$get({},{init:{signal:e}}),`/workspace/dashboard`));return Yt.has(n.snapshotId)||Yt.set(n.snapshotId,t),Yt.size>60&&Yt.delete(Yt.keys().next().value),A(t,[...n.questions.rows,...n.reviews.rows]),n}async function Zt(e,t,n=0,r=20,a){let o=b.parse(await f(await i.api.v1.workspace.dashboard.tasks.$get({query:{snapshotId:e,group:t,offset:String(n),limit:String(r)}},{init:{signal:a}}),`/workspace/dashboard/tasks`)),s=Yt.get(e);return s!==void 0&&A(s,o.page.rows),o}function Qt(e){return p({queryKey:Jt.snapshot,queryFn:({signal:e})=>Xt(e),enabled:e,staleTime:5e3,refetchOnMount:`always`,refetchInterval:e?15e3:!1,refetchIntervalInBackground:!1,retry:!1})}function $t(e){return p({queryKey:Jt.telemetry,enabled:e,staleTime:0,queryFn:async({signal:e})=>{let t=ee.parse(await f(await i.api.v1.workspace.dashboard.telemetry.$get({},{init:{signal:e}}),`/workspace/dashboard/telemetry`));return te.seed(t.samples,t.asOf),t}})}function en(e,t){let n=p({queryKey:Jt.feed(e),queryFn:async({signal:t})=>{let n=k(),r=T.parse(await f(await i.api.v1.workspace.dashboard.feed.$get({query:{filter:e}},{init:{signal:t}}),`/workspace/dashboard/feed`));return A(n,r.rows.flatMap(e=>e.kind===`task-result`?[e.run]:[])),r},enabled:t,staleTime:15e3,refetchInterval:t&&e!==`github`?15e3:!1,retry:!1}),r=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{r.current=!1},[e,t]),(0,I.useEffect)(()=>{if(!t||r.current||!n.data?.sources.some(e=>e.reason===`Still loading GitHub`))return;let e=setTimeout(()=>{document.visibilityState!==`hidden`&&(r.current=!0,n.refetch())},5e3);return()=>clearTimeout(e)},[t,n.data,n.refetch]),n}function tn(e,t){let n=en(`tasks`,t&&e!==`github`),r=en(`github`,t&&e!==`tasks`),i=(0,I.useMemo)(()=>{if(e===`tasks`)return n.data;if(e===`github`)return r.data;let t=n.data,i=r.data;if(!t&&!i)return;let a=t??i,o=new Date(Math.max(Date.parse(t?.asOf??a.asOf),Date.parse(i?.asOf??a.asOf))).toISOString(),s=new Date(Date.parse(o)-10080*60*1e3).toISOString(),c=[...t?.rows??[],...i?.rows??[]].filter(e=>Date.parse(e.at)>=Date.parse(s)&&Date.parse(e.at)<=Date.parse(o)).sort((e,t)=>nn(e,t)),l=new Set(c.slice(60).map(e=>e.kind===`task-result`?`tasks:${e.run.projectId}`:e.key.slice(0,e.key.lastIndexOf(`:`)))),u=[...t?.sources??[],...i?.sources??[]].map(e=>l.has(e.key)?{...e,truncated:!0}:e);return{...a,asOf:o,windowStart:s,filter:`all`,rows:c.slice(0,60),sources:u,coverage:t?.coverage??a.coverage,truncated:c.length>60||!!t?.truncated||!!i?.truncated}},[e,n.data,r.data]),a=e===`github`?r:n;return{...a,data:i,githubError:r.isError,githubFetching:r.isFetching,retryTasks:()=>n.refetch(),retryFailed:()=>e===`github`?r.refetch():e===`tasks`?n.refetch():Promise.all([...n.isError?[n.refetch()]:[],...r.isError?[r.refetch()]:[]]),isPending:!i&&a.isPending,isError:a.isError||e===`all`&&r.isError,isFetching:a.isFetching||e===`all`&&r.isFetching,refetch:()=>e===`tasks`?n.refetch():r.refetch()}}function nn(e,t){return Date.parse(t.at)-Date.parse(e.at)||e.key.localeCompare(t.key)}var rn=[...m.dashboard,`costs`];function an(){let e=0,t=0,n,r=new Set;return{subscribe:e=>(r.add(e),()=>{r.delete(e)}),getSnapshot:()=>n,async read(i,a){let o=++e,s=await un(i,a);return!a?.aborted&&o>t&&(t=o,(n?.cost!==s.visibility.cost||n?.tokens!==s.visibility.tokens)&&(n=s.visibility,r.forEach(e=>e()))),s}}}var on=new WeakMap;function sn(e){let t=on.get(e);return t||(t=an(),on.set(e,t)),t}function cn(){let e=sn(v());return(0,I.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot)}var ln=new Map;async function un(e,t){let n=k(),r=C.parse(await f(await i.api.v1.workspace.dashboard.costs.$get({query:{...e,offset:String(e.offset??0),limit:`20`}},{init:{signal:t}}),`/workspace/dashboard/costs`));!e.snapshotId&&!ln.has(r.snapshotId)&&ln.set(r.snapshotId,n),ln.size>60&&ln.delete(ln.keys().next().value);let a=ln.get(r.snapshotId);return a!==void 0&&A(a,r.tasks.rows),r}function dn(e,t,n){let r=sn(v());return p({queryKey:[...rn,e,t,n],queryFn:({signal:n})=>r.read({period:e,sort:t,tzOffsetMinutes:new Date().getTimezoneOffset()},n),staleTime:5e3,refetchOnMount:`always`,refetchInterval:15e3,refetchIntervalInBackground:!1,retry:!1})}function fn(e,t,n,r){let i=sn(v());return p({queryKey:[...rn,`tasks`,e.snapshotId,t,n,r,e.visibility],retry:!1,queryFn:async({signal:a})=>{let o=e.tzOffsetMinutes??new Date().getTimezoneOffset(),s=async s=>{let c=await i.read({period:e.period,sort:n,snapshotId:s,projectId:t,tzOffsetMinutes:o},a),l=[...c.tasks.rows];for(;c.tasks.nextOffset!==null&&l.length<r;)c=await i.read({period:e.period,sort:n,snapshotId:c.snapshotId,projectId:t,offset:c.tasks.nextOffset},a),l.push(...c.tasks.rows);return{...c,tasks:{...c.tasks,rows:l}}};try{return await s(e.snapshotId)}catch(e){if(e instanceof u&&e.status===409)return s();throw e}}})}var pn={cost:{text:`text-primary`,fill:`bg-primary`,tint:H.primary,icon:ie},input:{text:`text-violet`,fill:`bg-violet`,tint:H.violet,icon:We},output:{text:`text-info`,fill:`bg-info`,tint:H.info,icon:Te}};function mn({metric:e,label:t,value:n,reported:r,total:i}){let a=pn[e],o=a.icon,s=i?Math.min(100,r/i*100):0;return(0,L.jsxs)(`div`,{className:`${tt} ${a.tint}`,children:[(0,L.jsxs)(nt,{label:t,value:n,icon:(0,L.jsx)(o,{className:`size-4 ${a.text}`}),children:[r,` of `,i,` tasks report this metric`]}),(0,L.jsx)(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full ${a.fill} transition-[width] duration-300 motion-reduce:transition-none`,style:{width:`${s}%`}})})]})}function hn({projects:e,currentProjects:t,metric:n,field:r,label:i,format:a,onSelect:o}){let s=e.reduce((e,t)=>Math.max(e,t[r]?.value??0),0),c=pn[n];return(0,L.jsxs)(Ie,{delayDuration:150,children:[(0,L.jsxs)(`div`,{className:`space-y-1 rounded-xl border p-2`,"aria-label":`Projects ranked by ${i}`,children:[e.length===0&&(0,L.jsx)(`p`,{className:`px-3 py-4 text-muted-foreground`,children:`No projects to compare in this cohort.`}),e.slice(0,5).map((e,n)=>{let l=e[r],u=l?.value,d=u==null||s===0?0:u/s*100,f=u!=null;return(0,L.jsxs)(Le,{children:[(0,L.jsx)(Ne,{asChild:!0,children:(0,L.jsxs)(`button`,{"data-export-row":!0,"data-export-keep":!0,className:`group w-full rounded-lg px-3 py-3 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 motion-reduce:transition-none`,disabled:!t.some(t=>t.projectId===e.projectId),onClick:()=>o(e.projectId),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`span`,{className:`w-4 shrink-0 text-xs tabular-nums text-muted-foreground`,"aria-hidden":`true`,children:n+1}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-medium`,children:e.projectId}),(0,L.jsx)(`span`,{className:`shrink-0 font-semibold tabular-nums`,children:a(u)}),(0,L.jsx)(Re,{"data-export-exclude":!0,className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]}),(0,L.jsx)(`div`,{className:`mt-2 ml-7 h-2 overflow-hidden rounded-full bg-muted`,"aria-hidden":`true`,children:(0,L.jsx)(`div`,{"data-project-bar":e.projectId,className:`h-full rounded-full ${c.fill} transition-[width] duration-300 motion-reduce:transition-none`,style:{width:`${d}%`}})}),(0,L.jsxs)(`p`,{className:`mt-1.5 ml-7 text-xs text-muted-foreground`,children:[l?.reportedTasks??0,` of `,e.tasks,` tasks report this metric`,f?``:` · No measured value`]})]})}),(0,L.jsxs)(Pe,{className:`max-w-64`,children:[(0,L.jsxs)(`p`,{className:`font-medium`,children:[e.projectId,` · `,i,`: `,a(u)]}),(0,L.jsxs)(`p`,{children:[l?.reportedTasks??0,` of `,e.tasks,` tasks report this metric.`]}),(0,L.jsx)(`p`,{children:`Open project tasks`})]})]},e.projectId)})]}),e.length>0&&(0,L.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[e.length>5?`Top 5 of ${e.length} projects. `:``,`Bar lengths compare reported values; the largest is the reference.`]})]})}var Z={cost:`costUsd`,input:`inputTokens`,output:`outputTokens`},gn={cost:`Reported USD`,input:`Input tokens`,output:`Output tokens`};function _n(e,t){return JSON.stringify([e.totals,e.projects,e.tasks,e.visibility,e.coverage,e.invalidDateTasks])!==JSON.stringify([t.totals,t.projects,t.tasks,t.visibility,t.coverage,t.invalidDateTasks])}var vn=(e,t)=>gt(e,t===`cost`);function Q(e){return[...e.cost?[`cost`]:[],...e.tokens?[`input`,`output`]:[]]}function yn({value:e,onChange:t,visibility:n}){return(0,L.jsxs)(`label`,{className:$e,children:[`Sort by`,(0,L.jsx)(et,{value:e,onChange:e=>t(e.target.value),children:Q(n).map(e=>(0,L.jsx)(`option`,{value:e,children:gn[e]},e))})]})}function bn(){return(0,L.jsx)(xn,{visibility:Be(s().data)})}function xn({visibility:e}){return(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsx)(`div`,{className:B,children:(0,L.jsx)(`h2`,{className:z,children:`Usage & cost`})}),!e.cost&&!e.tokens?(0,L.jsx)(`p`,{className:`p-4 text-sm`,children:`Usage metrics are hidden by workspace settings`}):(0,L.jsx)(Sn,{visibility:e},`${e.cost}:${e.tokens}`)]})}function Sn({visibility:e}){let[t,n]=_t(`usagePeriod`,[`all`,`7d`,`30d`],`all`),[r,i]=_t(`usageSort`,Q(e),e.cost?`cost`:`input`);return(0,L.jsx)(Cn,{period:t,setPeriod:n,sort:r,setSort:i,visibility:e})}function Cn({period:e,setPeriod:t,sort:n,setSort:r,visibility:i}){let a=dn(e,n,`${i.cost}:${i.tokens}`),[o,s]=X(`usage:accepted`,void 0),c=o??a.data,l=a.data??c,[u,d]=X(`usage:panel`,null),[f,p]=(0,I.useState)(e);f!==e&&(p(e),s(void 0),d(null));let m=zt(`usage:${u?.identity??`closed`}`),h=Bt(`usage`,`[data-usage-trigger]`),g=e=>{h.capture(),c&&d({identity:Lt(),projectId:e,snapshot:c,latestId:l?.snapshotId??c.snapshotId})},_=cn()??i,v={cost:i.cost&&_.cost,tokens:i.tokens&&_.tokens},y=Q(v).includes(n)?n:Q(v)[0]??`cost`,b=[...c?.projects??[]].sort((e,t)=>{let n=e[Z[y]]?.value,r=t[Z[y]]?.value;return(n==null?r==null?0:1:r==null?-1:r-n)||e.projectId.localeCompare(t.projectId)});!o&&a.data&&s(a.data);let x=c&&l&&_n(c,l),S=c?.coverage.projects.some(e=>e.state!==`complete`),C=l?.coverage.projects.some(e=>e.state!==`complete`),w=JSON.stringify(c?.coverage)!==JSON.stringify(l?.coverage),T=c?.totals.tasks===0&&!S&&!C;return(0,L.jsxs)(`div`,{className:`space-y-4 p-4 text-sm`,children:[c&&(0,L.jsx)(R,{rows:T?[]:[...Q(v).map(e=>({section:`totals`,metric:Z[e],value:c.totals[Z[e]]?.value??null,unit:e===`cost`?`USD`:`tokens`,reportedTasks:c.totals[Z[e]]?.reportedTasks??0,totalTasks:c.totals.tasks,asOf:c.asOf})),...(v.cost||v.tokens?b.slice(0,5):[]).map(e=>({section:`project`,entity:e.projectId,metric:Z[y],value:e[Z[y]]?.value??null,unit:y===`cost`?`USD`:`tokens`,reportedTasks:e[Z[y]]?.reportedTasks??0,totalTasks:e.tasks,asOf:c.asOf}))]}),c&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:c.asOf})}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-medium`,children:`Lifetime totals of retained tasks`}),(0,L.jsxs)(`details`,{className:`mt-1 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`${Qe} min-h-11`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsxs)(`p`,{children:[`Includes archived tasks and subtasks.`,` `,v.cost&&`Reported USD is not an invoice. `,`Missing reports are excluded, not treated as zero. Calendar days use your current UTC offset, including today.`]})]})]}),(0,L.jsxs)(`label`,{className:$e,children:[`Tasks created`,(0,L.jsxs)(et,{value:e,onChange:e=>t(e.target.value),children:[(0,L.jsx)(`option`,{value:`all`,children:`All time`}),(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),e!==`all`&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Lifetime usage of tasks created in this period — not spending during the period.`}),a.isPending&&(0,L.jsx)(`p`,{children:`Loading usage…`}),a.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[c?`Showing stale usage. Could not refresh.`:`Could not load usage.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void a.refetch(),children:`Retry`})]}),x&&(0,L.jsx)(`p`,{role:`status`,children:`Newer usage data is available; displayed values use the previous snapshot.`}),x&&(0,L.jsx)(O,{className:`min-h-11`,variant:`outline`,onClick:()=>s(l),children:`Updates available — Show`}),c&&S&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Coverage of displayed usage:`}),(0,L.jsx)(K,{coverage:c.coverage,retry:()=>void a.refetch()})]}),l&&C&&w&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Current source availability:`}),(0,L.jsx)(K,{coverage:l.coverage,retry:()=>void a.refetch()})]}),c&&(0,L.jsxs)(L.Fragment,{children:[!T&&(0,L.jsx)(`div`,{className:`report-cost-metrics grid gap-3 sm:grid-cols-[repeat(auto-fit,minmax(220px,1fr))]`,children:Q(v).map(e=>(0,L.jsx)(mn,{metric:e,label:gn[e],value:vn(c.totals[Z[e]]?.value,e),reported:c.totals[Z[e]]?.reportedTasks??0,total:c.totals.tasks},e))}),!v.cost&&!v.tokens&&(0,L.jsx)(`p`,{children:`Usage metrics are hidden by workspace settings`}),c.totals.tasks===0?(0,L.jsx)(`p`,{children:S||C?`No retained tasks could be read from available sources.`:`No retained tasks in this cohort.`}):Q(v).every(e=>!c.totals[Z[e]]?.reportedTasks)&&(0,L.jsx)(`p`,{children:`No reports for the visible metrics in this cohort.`}),T&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Usage appears when tasks report cost or tokens.`}),(0,L.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Deleted tasks are excluded from retained history.`,c.invalidDateTasks?` ${c.invalidDateTasks} tasks have missing or invalid creation dates${e===`all`?`; included in All time`:`; excluded from this period`}.`:``]}),!T&&(v.cost||v.tokens)&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-medium`,children:`Top projects`}),(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Ranking uses reported metrics only.`})]}),(0,L.jsx)(yn,{value:y,onChange:r,visibility:v})]}),(0,L.jsx)(hn,{projects:b,metric:y,label:gn[y],field:Z[y],format:e=>vn(e,y),currentProjects:l?.projects??[],onSelect:g}),(0,L.jsx)(O,{"data-usage-trigger":!0,className:`min-h-11`,variant:`outline`,onClick:()=>g(``),children:`View tasks`})]})]}),(0,L.jsx)(we,{open:u!==null&&(v.cost||v.tokens),onOpenChange:e=>{e||d(null)},children:(0,L.jsxs)(Ce,{...m,className:`w-full overflow-y-auto sm:max-w-xl`,onCloseAutoFocus:e=>{e.preventDefault(),h.restore()},children:[(0,L.jsxs)(be,{children:[(0,L.jsx)(Se,{children:u?.projectId?`${u.projectId} tasks`:`All tasks`}),(0,L.jsx)(xe,{children:`Lifetime usage of retained tasks. Missing reports are unavailable.`})]}),u!==null&&(0,L.jsx)(wn,{identity:`usage:${u.identity}`,snapshot:l&&l.snapshotId!==u.latestId?l:u.snapshot,projectId:u.projectId||void 0,visibility:v},u.identity)]})})]})}function wn({identity:e,snapshot:t,projectId:n,visibility:r}){let[i,a]=X(`${e}:sort`,t.sort);return(0,L.jsx)(Tn,{identity:e,snapshot:t,projectId:n,visibility:r,sort:Q(r).includes(i)?i:Q(r)[0]??`cost`,setSort:a})}function Tn({identity:e,snapshot:t,projectId:n,visibility:r,sort:i,setSort:a}){let[o,s]=X(`${e}:count`,20),[c,l]=X(`${e}:paging`,void 0),[u,d]=(0,I.useState)(t.snapshotId);u!==t.snapshotId&&(d(t.snapshotId),l(void 0));let f=fn(c??t,n,i,o),p=cn()??r,m={cost:r.cost&&p.cost,tokens:r.tokens&&p.tokens},h=Q(m).includes(i)?i:Q(m)[0]??`cost`,[g,_]=X(`${e}:accepted`,void 0),[v,y]=X(`${e}:acceptedCount`,o),[b,x]=X(`${e}:acceptedSort`,i),[S,C]=(0,I.useState)(i);S!==i&&(C(i),s(20),l(g??c??t)),f.data&&(!g||(v!==o||b!==i)&&g.snapshotId===f.data.snapshotId)&&(_(f.data),y(o),x(i));let w=g??f.data,T=f.data&&w&&_n(f.data,w),ee=w?.coverage.projects.some(e=>e.state!==`complete`),E=f.data?.coverage.projects.some(e=>e.state!==`complete`),D=JSON.stringify(w?.coverage)!==JSON.stringify(f.data?.coverage),te=!n||t.projects.some(e=>e.projectId===n);return(0,L.jsxs)(`div`,{className:`space-y-3 p-4 text-sm`,"data-sheet-loading":f.isFetching,children:[(0,L.jsx)(yn,{value:h,onChange:a,visibility:m}),f.isPending&&(0,L.jsx)(`p`,{children:`Loading tasks…`}),f.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[`Could not refresh tasks. `,w?`Showing stale usage.`:``,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void f.refetch(),children:`Retry`})]}),T&&(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{_(f.data),y(o),x(i)},children:`Updates available — Show`}),w&&ee&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Coverage of displayed tasks:`}),(0,L.jsx)(K,{coverage:w.coverage,retry:()=>void f.refetch()})]}),f.data&&E&&D&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`Current source availability:`}),(0,L.jsx)(K,{coverage:f.data.coverage,retry:()=>void f.refetch()})]}),w&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{className:`border-b pb-2 font-mono text-[11px] text-soft-foreground`,children:[w.tasks.rows.length,` of `,w.tasks.total,` retained tasks`]}),w.tasks.total===0&&(0,L.jsx)(`p`,{children:w.coverage.projects.some(e=>e.state!==`complete`)?`No tasks could be read from available sources.`:`No retained tasks in this cohort.`}),w.tasks.rows.map(e=>(0,L.jsx)(En,{row:e,sort:h,visibility:m,disabled:!te||!f.data||!!(T&&!f.data?.tasks.rows.some(t=>t.id===e.id&&t.projectId===e.projectId))},`${e.projectId}:${e.id}`)),w.tasks.nextOffset!==null&&(0,L.jsx)(O,{className:`min-h-11`,disabled:f.isFetching,onClick:()=>{l(w),s(e=>e+20)},children:`Show 20 more tasks`})]})]})}function En({row:e,sort:t,visibility:n,disabled:r}){let i=M(e);r||=i===null;let a=d(i?{status:i.status,awaitingAnswerSince:i.awaitingAnswerSince}:e),o=Q(n).filter(e=>e!==t),s=t=>{let n=e[Z[t]];return n==null?`—`:vn(n,t)},c=t=>`${gn[t]}: ${vn(e[Z[t]],t)}`;return(0,L.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-4 border-b py-3 last:border-0`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(P,{tone:a.tone,pulse:a.pulse,className:`mt-[7px]`}),(0,L.jsx)(l,{className:`line-clamp-2 break-words font-medium leading-snug hover:underline no-hover:min-h-11`,title:e.title,to:`/p/${encodeURIComponent(e.projectId)}/tasks/${encodeURIComponent(e.id)}`,"aria-disabled":r||void 0,tabIndex:r?-1:void 0,onClick:e=>{r&&e.preventDefault()},children:e.title})]}),(0,L.jsxs)(`p`,{className:`mt-1 pl-[15px] font-mono text-[11px] text-soft-foreground`,children:[e.projectId,` · `,r?`Checking current state…`:i?.status??e.status,e.archived?` · Archived`:``,e.subtask?` · Subtask`:``]})]}),(0,L.jsxs)(`div`,{className:`text-right tabular-nums`,children:[(0,L.jsx)(`span`,{"aria-label":c(t),className:`block font-semibold ${e[Z[t]]==null?`text-soft-foreground`:``}`,children:s(t)}),o.length>0&&(0,L.jsx)(`span`,{className:`mt-1 flex justify-end gap-3 font-mono text-[11px] text-soft-foreground`,children:o.map(e=>(0,L.jsxs)(`span`,{"aria-label":c(e),children:[s(e),` `,e===`cost`?``:e===`input`?`in`:`out`]},e))})]})]})}var Dn={cost:`costUsd`,input:`inputTokens`,output:`outputTokens`},On={cost:`Reported USD`,input:`Input tokens`,output:`Output tokens`};function kn(e){return[...e.cost?[`cost`]:[],...e.tokens?[`input`,`output`]:[]]}var An=(e,t)=>gt(e,t===`cost`);function jn(e){return new Date(`${e}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Mn({series:e,height:t,accent:n,renderTooltip:r,describe:i}){let a=Math.max(1,...e.map(t));return(0,L.jsxs)(Ie,{delayDuration:150,children:[(0,L.jsx)(`div`,{className:`flex h-20 items-end gap-0.5`,role:`group`,"aria-label":`Daily trend`,children:e.map(e=>{let o=t(e),s=Math.max(o>0?4:0,o/a*100);return(0,L.jsxs)(Le,{children:[(0,L.jsx)(Ne,{asChild:!0,children:(0,L.jsx)(`button`,{"data-export-keep":!0,"aria-label":i(e),type:`button`,className:`min-w-0 flex-1 rounded-t-sm transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,style:{height:`100%`,display:`flex`,alignItems:`end`},children:(0,L.jsx)(`span`,{style:{height:`${s}%`},className:`block w-full rounded-t-sm ${n}`})})}),(0,L.jsx)(Pe,{children:r(e)})]},e.date)})}),(0,L.jsxs)(`div`,{className:`mt-1 flex justify-between text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{children:jn(e[0].date)}),(0,L.jsx)(`span`,{children:jn(e.at(-1).date)})]})]})}function Nn({metrics:e,series:t}){return(0,L.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b`,children:[(0,L.jsx)(`th`,{className:`py-1 pr-2 font-medium`,children:`Date`}),e.map(e=>(0,L.jsx)(`th`,{className:`py-1 pr-2 text-right font-medium`,children:On[e]},e)),(0,L.jsx)(`th`,{className:`py-1 pr-2 text-right font-medium`,children:`Completed`}),(0,L.jsx)(`th`,{className:`py-1 text-right font-medium`,children:`Avg cycle`})]})}),(0,L.jsx)(`tbody`,{children:t.map(t=>(0,L.jsxs)(`tr`,{className:`border-b last:border-0`,children:[(0,L.jsx)(`td`,{className:`py-1 pr-2`,children:jn(t.date)}),e.map(e=>(0,L.jsx)(`td`,{className:`py-1 pr-2 text-right tabular-nums`,children:An(t[Dn[e]]?.value,e)},e)),(0,L.jsx)(`td`,{className:`py-1 pr-2 text-right tabular-nums`,children:t.completed}),(0,L.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:t.avgCycleHours===null?`—`:q(t.avgCycleHours)})]},t.date))})]})}function Pn({metric:e,series:t}){let n=pn[e],r=Dn[e],i=t.reduce((e,t)=>e+(t[r]?.reportedTasks??0),0);return(0,L.jsxs)(`div`,{className:`rounded-xl border p-3`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium ${n.text}`,children:On[e]}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(Mn,{series:t,describe:t=>`${t.date}, ${On[e]}: ${An(t[r]?.value,e)}, ${t[r]?.reportedTasks??0} of ${t.tasks} tasks reported`,height:e=>e[r]?.value??0,accent:n.fill,renderTooltip:t=>(0,L.jsxs)(`p`,{children:[jn(t.date),` · `,An(t[r]?.value,e),` ·`,` `,t[r]?.reportedTasks??0,`/`,t.tasks,` tasks reported`]})})}),i===0&&(0,L.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No reports in this period.`})]})}function Fn({series:e}){let t=e.reduce((e,t)=>e+t.completed,0),n=e.reduce((e,t)=>e+(t.avgCycleHours??0)*(t.cycleReportedTasks??t.completed),0),r=e.reduce((e,t)=>e+(t.cycleReportedTasks??t.completed),0),i=r?n/r:null;return(0,L.jsxs)(`div`,{className:`rounded-xl border p-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium text-success`,children:`Completed tasks`}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t,` done · avg cycle`,` `,i===null?`unavailable`:q(i)]})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[r,`/`,t,` completed tasks have valid cycle times.`]}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(Mn,{series:e,describe:e=>`${e.date}: ${e.completed} completed tasks, average cycle ${e.avgCycleHours==null?`Unavailable`:q(e.avgCycleHours)}`,height:e=>e.completed,accent:`bg-success`,renderTooltip:e=>(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`p`,{children:[jn(e.date),` · `,e.completed,` completed`]}),(0,L.jsxs)(`p`,{children:[`Avg cycle`,` `,e.avgCycleHours===null?`unavailable`:q(e.avgCycleHours),` · Median`,` `,e.medianCycleHours===null?`unavailable`:q(e.medianCycleHours)]})]})})}),t===0&&(0,L.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No tasks finished in this period.`})]})}function In(){return(0,L.jsx)(Ln,{visibility:Be(s().data)})}function Ln({visibility:e}){let[t,n]=_t(`trendPeriod`,[`7d`,`30d`],`7d`),r=dn(t,e.cost?`cost`:`input`,`${e.cost}:${e.tokens}`),i=r.data,a=i&&i.totals.tasks===0&&i.coverage.projects.every(e=>e.state===`complete`)&&i.series.every(e=>e.tasks===0&&e.completed===0),o=kn({cost:e.cost&&i?.visibility.cost!==!1,tokens:e.tokens&&i?.visibility.tokens!==!1});return(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsx)(`h2`,{className:z,children:`Trends`}),(0,L.jsxs)(`label`,{className:$e,children:[`Period`,(0,L.jsxs)(et,{value:t,onChange:e=>n(e.target.value),children:[(0,L.jsx)(`option`,{value:`7d`,children:`Last 7 days`}),(0,L.jsx)(`option`,{value:`30d`,children:`Last 30 days`})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-4 p-4 text-sm`,children:[i&&(0,L.jsx)(R,{rows:a?[]:i.series.flatMap(e=>[...o.map(t=>({section:`daily-creation-cohort`,entity:e.date,metric:Dn[t],value:e[Dn[t]]?.value??null,unit:t===`cost`?`USD`:`tokens`,reportedTasks:e[Dn[t]]?.reportedTasks??0,totalTasks:e.tasks,asOf:i.asOf,note:`Lifetime usage grouped by task creation date; not daily spend`})),{section:`daily-completions`,entity:e.date,metric:`completed`,value:e.completed,unit:`tasks`,asOf:i.asOf},{section:`daily-completions`,entity:e.date,metric:`avgCycleHours`,value:e.avgCycleHours,reportedTasks:e.cycleReportedTasks??e.completed,totalTasks:e.completed,unit:`hours`,asOf:i.asOf},{section:`daily-completions`,entity:e.date,metric:`medianCycleHours`,value:e.medianCycleHours,unit:`hours`,asOf:i.asOf}])}),(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Metric definitions`,className:`${Qe} py-2`,children:[(0,L.jsx)(V,{}),`How these metrics work`]}),(0,L.jsx)(`p`,{children:`Usage is grouped by creation date, not spending date. Completed tasks are grouped by finish date. Calendar days use your current UTC offset (fixed across the period), including today.`})]}),r.isPending&&(0,L.jsx)(`p`,{children:`Loading trends…`}),r.isError&&(0,L.jsxs)(`p`,{role:`alert`,children:[i?`Showing stale trends. Could not refresh.`:`Could not load trends.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>void r.refetch(),children:`Retry`})]}),i&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,L.jsx)(rt,{at:i.asOf})}),i&&(0,L.jsx)(K,{coverage:i.coverage,retry:()=>void r.refetch()}),i&&a&&(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`No retained tasks in this period yet.`}),i&&!a&&i.series.length>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`space-y-4`,children:[o.length>0&&(0,L.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-[repeat(auto-fit,minmax(200px,1fr))]`,children:o.map(e=>(0,L.jsx)(Pn,{metric:e,series:i.series},e))}),(0,L.jsx)(Fn,{series:i.series})]}),(0,L.jsxs)(`details`,{className:`group rounded-lg border bg-muted/20 print:block`,children:[(0,L.jsxs)(`summary`,{"data-export-heading":`Daily data`,className:`flex min-h-11 cursor-pointer list-none items-center gap-2 px-3 text-xs font-medium text-muted-foreground hover:text-foreground [&::-webkit-details-marker]:hidden`,children:[(0,L.jsx)(Je,{className:`size-4`,"aria-hidden":`true`}),` View data table`,(0,L.jsx)(Fe,{className:`ml-auto size-4 transition-transform group-open:rotate-180`,"aria-hidden":`true`})]}),(0,L.jsx)(`div`,{className:`max-h-80 overflow-auto border-t p-3 print:max-h-none print:overflow-visible`,role:`region`,"aria-label":`Daily trend values`,tabIndex:0,children:(0,L.jsx)(Nn,{metrics:o,series:i.series})})]})]})]})]})}function Rn(e,t,n,r=!0){let i=v();return p({queryKey:[...Jt.snapshot,e?.snapshotId,t,n],enabled:r&&!!e,retry:!1,queryFn:async({signal:r})=>{if(!e)throw Error(`Dashboard not loaded`);let a=[];try{for(let i=0;i<n;){let o=await Zt(e.snapshotId,t,i,Math.min(20,n-i),r);if(a.push(...o.page.rows),o.page.nextOffset===null)break;i=o.page.nextOffset}return a}catch(e){if(e instanceof u&&e.status===409){let e=await Xt(r);i.setQueryData(Jt.snapshot,e)}throw e}}})}function zn(e,t,n,r){let i=v(),a=t===`questions`||t===`reviews`?`needs-you`:t,o=a===`needs-you`?0:n,s=r.map(e=>`${e.projectId}:${e.id}`).sort();return p({queryKey:[...Jt.snapshot,e.snapshotId,t,`displaced`,...s],enabled:s.length>0,retry:!1,queryFn:async({signal:t})=>{let n=new Set(s),r=new Map;try{for(let i=o;i!==null&&n.size;){let o=await Zt(e.snapshotId,a,i,20,t);for(let e of o.page.rows){let t=`${e.projectId}:${e.id}`;n.delete(t)&&r.set(t,e)}i=o.page.nextOffset}return r}catch(e){throw e instanceof u&&e.status===409&&i.setQueryData(Jt.snapshot,await Xt(t)),e}}})}function Bn({snapshot:e,questions:t,reviews:n,more:r,healthy:i=!0}){let a=pe();return(0,L.jsxs)(N,{className:`min-w-0 gap-0 overflow-hidden py-0`,children:[(0,L.jsxs)(`div`,{className:B,children:[(0,L.jsxs)(`h2`,{id:`dashboard-needs-you`,tabIndex:-1,className:z,children:[`Needs you · `,e.counts.questions+e.counts.reviews]}),(0,L.jsxs)(`p`,{className:`font-mono text-[11px] text-soft-foreground`,children:[e.counts.questions,` questions · `,e.counts.reviews,` reviews`]})]}),i&&a.connected&&e.counts.questions+e.counts.reviews===0&&e.coverage.projects.every(e=>e.state===`complete`)?(0,L.jsxs)(`p`,{className:`flex items-center gap-2.5 px-4 py-8 text-sm text-muted-foreground`,children:[(0,L.jsx)(P,{tone:`success`}),`All caught up — no tasks need your input`]}):null,(0,L.jsx)(Vn,{snapshot:e,group:`questions`,count:t,more:r}),(0,L.jsx)(Vn,{snapshot:e,group:`reviews`,count:n,more:r})]})}function Vn({snapshot:e,group:t,count:n,more:r}){let i=e[t],a=Math.max(n,i.rows.length),o=Rn(e,t,a,a>i.rows.length),s=a>i.rows.length?o.data:i.rows,c=lt(s,G,t,n),l=zn(e,t,a,c.rows.filter(e=>e.removed).map(e=>e.row)),u=(0,I.useRef)(null);return!i.total&&!c.rows.length?null:(0,L.jsxs)(`section`,{children:[(0,L.jsxs)(`h3`,{ref:u,tabIndex:-1,className:`border-b bg-card-2 px-4 py-2 font-mono text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground`,children:[t===`questions`?`Questions`:`Reviews`,` · `,i.total]}),c.updates>0&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>{c.show(),u.current?.focus()},children:[c.updates,` updates — Show`]}),c.rows.map(({row:e,removed:t})=>(0,L.jsx)(ht,{row:l.data?.get(G(e))??e,removed:t&&!!l.data&&!l.data.has(G(e)),checking:s===void 0||t&&!l.data,checkFailed:s===void 0&&o.isError||t&&!l.data&&l.isError,queue:!0},G(e))),(o.isError||l.isError)&&(0,L.jsxs)(`p`,{role:`alert`,className:`p-4 text-sm`,children:[`Could not check current task state.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11`,onClick:()=>{o.refetch(),l.refetch()},children:`Retry`})]}),a<i.total&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,disabled:o.isFetching,onClick:()=>r(t,a+Math.min(20,i.total-a)),children:[`Show `,Math.min(20,i.total-a),` more `,t]})]})}function Hn(e){if(!e.startsWith(`github:`))return e===`tasks`?`Task results`:e;let t=e.slice(7).split(`:`),n=t.pop()===`pr`?`Pull requests`:`Issues`;return`${t.join(`:`).replace(/^project:/,`Project `).replace(/^github.com\//,``)} · ${n}`}var Un=e=>e.key;function Wn({filter:e,setFilter:t,count:n,more:r}){let i=tn(e,!0),a=lt(i.data?.rows,Un,`feed:${e}`,0,e=>e.kind===`task-result`),o=a.rows,s=a.updates,c=(0,I.useContext)(st),l=(0,I.useRef)(null),u=`feed:${e}`,d=(0,I.useMemo)(()=>({scroll:pt(c,u)?.scroll??0,done:!1}),[c,u]);(0,I.useLayoutEffect)(()=>{!l.current||d.done||(l.current.scrollTop=d.scroll,d.done=Math.abs(l.current.scrollTop-d.scroll)<1||!!i.data&&!i.isPending&&!i.isFetching)},[d,o.length,n,i.data,i.isPending,i.isFetching]);let f=(0,I.useRef)(null),p=i.data?.sources.filter(e=>e.key.startsWith(`github:`))??[],m=p.flatMap(e=>e.fetchedAt?[e.fetchedAt]:[]).sort()[0],h=i.githubError,g=p.filter(e=>e.reason===`No GitHub remote`),_=p.some(e=>e.reason===`Still loading GitHub`),v=p.length>0&&g.length===p.length&&!h,y=p.filter(e=>e.state!==`ready`&&e.reason!==`No GitHub remote`&&e.reason!==`Still loading GitHub`),b=v&&e===`all`;return(0,L.jsxs)(N,{"data-export-context":`Results source: ${e}; Last 7 days; loaded ${Math.min(n,o.length)} rows`,className:`min-w-0 gap-0 overflow-hidden py-0`,children:[(0,L.jsxs)(`div`,{className:`space-y-2 border-b px-4 pt-2.5 pb-2`,children:[(0,L.jsxs)(`div`,{className:`flex min-h-9 flex-wrap items-center justify-between gap-2`,children:[(0,L.jsx)(`h2`,{ref:f,tabIndex:-1,className:z,children:b?`Recent results`:`Recent results & GitHub`}),(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-soft-foreground`,children:`Last 7 days`})]}),!b&&(0,L.jsx)(se,{slot:`dashboard-feed`,label:`Results source`,value:e,options:[{value:`all`,label:`All`},{value:`tasks`,label:`Tasks`},{value:`github`,label:`GitHub`}],onChange:t}),b&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Task results · No GitHub repositories configured`}),e!==`tasks`&&!b&&(0,L.jsxs)(`details`,{className:`text-xs text-muted-foreground`,open:y.length||h?!0:void 0,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-1.5`,children:[(0,L.jsx)(V,{}),y.length||h?`GitHub needs attention`:_?`Checking GitHub…`:v?`GitHub not configured`:m?`GitHub checked ${F(m)} ago`:`GitHub source`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3`,children:[(0,L.jsx)(`p`,{children:y.length||h?m?`Could not refresh GitHub. Showing results from ${new Date(m).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}.`:`Could not load one or more GitHub sources.`:_?`Checking repository sources. Available results remain visible.`:v?`No GitHub repositories configured. Select Tasks to see task results.`:m?`GitHub checked ${F(m)} ago`:`GitHub snapshot`}),!v&&(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11 px-0`,disabled:i.githubFetching,onClick:()=>{i.refetch()},children:i.githubFetching?`Refreshing…`:y.length||h?`Retry GitHub`:`Refresh GitHub`})]})]})]}),(0,L.jsxs)(`div`,{role:`region`,"aria-label":`Recent results list`,ref:l,onWheel:()=>{d.done=!0},onTouchStart:()=>{d.done=!0},onKeyDown:()=>{d.done=!0},onScroll:e=>{c&&d.done&&mt(c,u,{count:n,scroll:e.currentTarget.scrollTop})},tabIndex:0,className:`max-h-80 overflow-y-auto overscroll-contain focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,children:[i.isError&&(0,L.jsxs)(`p`,{role:`alert`,className:`p-4 text-sm`,children:[`Could not load results.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{i.retryFailed()},children:`Retry`})]}),i.isPending&&(0,L.jsx)(`p`,{className:`p-4 text-sm`,children:`Loading results…`}),s>0&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:()=>{a.show(),f.current?.focus()},children:[s,` updates — Show`]}),o.slice(0,n).map(({row:e,removed:t})=>e.kind===`task-result`?(0,L.jsx)(ht,{row:e.run,kicker:t?`Outside current results`:`Latest result: ${e.run.status===`failed`?`Failed`:`Completed`}`},e.key):(0,L.jsxs)(`div`,{className:`border-b px-4 py-3 transition-colors hover:bg-muted/30`,children:[(0,L.jsx)(R,{rows:[{section:`github`,entity:`${e.repo}#${e.number}`,metric:e.itemKind,value:e.title,asOf:e.at,note:e.url}]}),(0,L.jsx)(`a`,{className:`block break-words text-sm font-medium hover:underline no-hover:min-h-11`,href:e.url,target:`_blank`,rel:`noreferrer`,children:e.title}),(0,L.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.repo,` · `,e.itemKind===`pr`?`PR`:`Issue`,` #`,e.number,` created ·`,` `,F(e.at)]})]},e.key)),i.data&&!i.data.rows.length&&!o.length&&!i.isFetching&&!i.isError&&!y.length&&!_&&i.data.coverage.projects.every(e=>e.state===`complete`)&&(0,L.jsx)(`p`,{className:`px-4 py-8 text-sm text-muted-foreground`,children:`No results in the last 7 days`}),n<o.length&&(0,L.jsxs)(O,{variant:`ghost`,className:`m-2 min-h-11`,onClick:r,children:[`Show `,Math.min(20,o.length-n),` more results`]}),i.data?.truncated&&(0,L.jsx)(`p`,{className:`p-4 text-xs`,children:`Showing the latest 60 results`}),i.data&&(0,L.jsx)(K,{coverage:i.data.coverage,retry:()=>{i.retryTasks()}}),!b&&i.data?.sources.some(e=>e.state!==`ready`||e.truncated)&&(0,L.jsxs)(`details`,{className:`p-4 text-xs`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden min-h-11`,children:[(0,L.jsx)(V,{}),`Source details`]}),i.data.sources.map(e=>(0,L.jsxs)(`p`,{className:`break-words py-1`,children:[Hn(e.key),`:`,` `,e.reason===`No GitHub remote`?`Not configured`:e.reason===`Still loading GitHub`?`Checking…`:e.reason??(e.state===`ready`?`Up to date`:e.state),e.truncated?` · capped`:``,e.fetchedAt?` · checked ${F(e.fetchedAt)}`:``]},e.key))]})]})]})}var $=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]),Gn=`Visible modules and loaded rows only. Filters and report availability apply. Retained task usage is not an invoice or a complete history.`,Kn=`Confidential — internal distribution only`,qn={costUsd:{label:`Reported cost`,usd:!0},inputTokens:{label:`Input tokens`},outputTokens:{label:`Output tokens`},needsYou:{label:`Needs you`},running:{label:`Running now`},completed:{label:`Completed in period`},failed:{label:`Failed outcomes in period`},medianCycleHours:{label:`Median cycle (hours)`}};function Jn(e,t){return e==null?`Unavailable`:typeof e==`string`?e:gt(e,t)}function Yn(e){let t=new Set,n=[];for(let r of e.modules)for(let e of r.rows){if(e.section!==`totals`&&e.section!==`fleet`&&e.section!==`overview`)continue;let i=qn[e.metric];!i||t.has(e.metric)||(t.add(e.metric),n.push({label:i.label,value:Jn(e.value,i.usd),note:[e.metric===`needsYou`||e.metric===`running`?e.note||`Current non-archived state`:r.filters,e.asOf?`Data as of ${e.asOf}`:``,e.reportedTasks==null?``:`${e.reportedTasks} of ${e.totalTasks} tasks reported`].filter(Boolean).join(` · `)}))}return n}function Xn(e){let t=e.cloneNode(!0);t.querySelectorAll(`script,style,link,img,iframe,object,embed,input,[hidden],[data-dashboard-export],[data-export-exclude]`).forEach(e=>e.remove()),t.querySelectorAll(`select`).forEach((t,n)=>{let r=e.querySelectorAll(`select`)[n];t.replaceWith(document.createTextNode(`: `+(r?.selectedOptions[0]?.textContent??``)))}),t.querySelectorAll(`[data-export-row],[data-dashboard-row]`).forEach(e=>e.classList.add(`report-row`)),t.querySelectorAll(`summary`).forEach(e=>{let t=document.createElement(`h3`);t.textContent=e.getAttribute(`data-export-heading`)||e.textContent,e.replaceWith(t)}),t.querySelectorAll(`button`).forEach(e=>{if(e.hasAttribute(`data-export-keep`)){let t=document.createElement(`div`);for(let n of[...e.attributes])[`class`,`style`,`title`].includes(n.name)&&t.setAttribute(n.name,n.value);t.append(...e.childNodes),e.replaceWith(t)}else e.remove()}),t.querySelectorAll(`details`).forEach(e=>{let t=document.createElement(`div`);t.className=e.className,t.append(...e.childNodes),e.replaceWith(t)});for(let e of[t,...t.querySelectorAll(`*`)])for(let t of[...e.attributes])(t.name.startsWith(`on`)||[`href`,`src`,`srcset`,`action`,`formaction`,`tabindex`].includes(t.name)||t.name.startsWith(`data-`))&&e.removeAttribute(t.name);return t.removeAttribute(`style`),t.innerHTML}function Zn(e,t,n,r){return{generatedAt:t,source:n,title:r||void 0,notices:[...e.querySelectorAll(`[role=alert],[role=status]`)].filter(e=>!e.closest(`[data-dashboard-module]`)).map(e=>e.textContent?.trim()??``).filter(Boolean),modules:[...e.querySelectorAll(`[data-dashboard-module]`)].map(e=>{let t=[...e.querySelectorAll(`select`)].map(e=>`${e.closest(`label`)?.childNodes[0]?.textContent?.trim()??`Filter`}: ${e.selectedOptions[0]?.textContent}`).concat([...e.querySelectorAll(`[data-export-context]`)].map(e=>e.dataset.exportContext)).join(`; `),n=[...new Set([...e.querySelectorAll(`p,[role="alert"],[role="status"]`)].filter(e=>!e.closest(`table,[data-export-exclude]`)&&!e.querySelector(`p,[role="alert"],[role="status"]`)).map(e=>{let t=e.cloneNode(!0);return t.querySelectorAll(`table,button,select,summary,[data-export-exclude]`).forEach(e=>e.remove()),t.textContent?.trim()}).filter(Boolean))].join(` | `);return{id:e.dataset.dashboardModule,title:e.querySelector(`h2`)?.textContent??e.dataset.dashboardModule,filters:t,notes:n,html:Xn(e),rows:[...e.querySelectorAll(`[data-dashboard-export]`)].flatMap(e=>JSON.parse(e.dataset.dashboardExport))}})}}function Qn(e){let t=e==null?``:String(e);return typeof e==`string`&&/^[\s\uFEFF]*[=+@\-]/.test(t)&&(t=`'${t}`),`"${t.replaceAll(`"`,`""`)}"`}function $n(e){let t=[[`generated_at`,`source`,`module`,`filters`,`section`,`entity`,`metric`,`value`,`unit`,`availability`,`reported_tasks`,`total_tasks`,`as_of`,`notes`]];for(let n of e.modules){t.push([e.generatedAt,e.source,n.title,n.filters,`context`,``,`scope`,Gn,``,``,``,``,``,[...e.title?[`Report title: ${e.title}`]:[],...e.notices,n.notes].join(` | `)]);for(let r of n.rows)t.push([e.generatedAt,e.source,n.title,n.filters,r.section,r.entity,r.metric,r.value,r.unit,r.value===null?`unavailable`:typeof r.value==`number`?`measured`:`reported`,r.reportedTasks,r.totalTasks,r.asOf,r.note])}return``+t.map(e=>e.map(Qn).join(`,`)).join(`\r
|
|
2
2
|
`)+`\r
|
|
3
3
|
`}function er(e,t){let n=Yn(e);return`<!doctype html><html class="light"><head><meta charset="utf-8"><title>${$(e.title||`Dashboard`)} ${$(e.generatedAt.slice(0,10))}</title>${t.join(``)}<style>
|
|
4
4
|
@page {
|
|
@@ -41,4 +41,4 @@ body { margin:0; font:12px/1.5 system-ui,sans-serif; }
|
|
|
41
41
|
.report-module [role=region] > div, .report-module [role=region] > p { break-inside:avoid; }
|
|
42
42
|
.report-module .sr-only { display:none!important; }
|
|
43
43
|
.report-context { font-size:11px; color:var(--muted-foreground); margin:0 0 8px; }
|
|
44
|
-
</style></head><body><header class="report-heading"><h1>${$(e.title||`Dashboard report`)}</h1><p>${$(e.generatedAt)} · ${$(e.source)}</p><span class="report-confidential">${Kn}</span><p>${$(Gn)}</p>${e.notices.map(e=>`<p>${$(e)}</p>`).join(``)}</header>${n.length?`<section class="report-summary"><h2>Executive summary</h2><div class="summary-grid">${n.map(e=>`<div class="summary-tile"><span class="summary-value">${$(e.value)}</span><span class="summary-label">${$(e.label)}</span>${e.note?`<span class="summary-note">${$(e.note)}</span>`:``}</div>`).join(``)}</div></section>`:``}${e.modules.map(e=>`<section class="report-module${e.id===`usage`?` report-module-usage`:e.id===`fleet`?` report-module-fleet`:``}"><p class="report-context">${$(e.filters)}</p>${e.html}</section>`).join(``)}</body></html>`}function tr({dashboard:e}){let[t,n]=(0,I.useState)(!1),[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(``),l=t=>{i(``);try{if(!e.current)return;let r=Zn(e.current,new Date().toISOString(),location.origin,s.trim());if(!r.modules.length){i(`Show at least one dashboard module before exporting.`);return}if(t===`csv`){let e=URL.createObjectURL(new Blob([$n(r)],{type:`text/csv;charset=utf-8`})),t=document.createElement(`a`);t.href=e,t.download=`dashboard-${r.generatedAt.replaceAll(`:`,`-`)}.csv`,document.body.append(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),1e3),n(!1)}else{o(!0);let e=[...document.querySelectorAll(`link[rel="stylesheet"],style`)].flatMap(e=>{if(e.tagName===`STYLE`)return[e.outerHTML];let t=e.href;if(new URL(t).origin!==location.origin)return[];let n=document.createElement(`link`);return n.rel=`stylesheet`,n.href=t,[n.outerHTML]}),t=document.createElement(`iframe`);t.title=`Dashboard PDF report`,t.style.cssText=`position:fixed;width:1000px;height:1px;bottom:0;left:0;border:0;opacity:0;pointer-events:none`;let a,s=()=>{clearTimeout(a),t.remove(),o(!1)};t.onload=async()=>{try{let e=t.contentWindow;await e.document.fonts.ready,e.addEventListener(`afterprint`,s,{once:!0}),e.focus(),e.print(),n(!1),o(!1)}catch{s(),i(`Could not open the print dialog. Please try again.`)}},a=setTimeout(s,12e4),t.srcdoc=er(r,e),document.body.append(t)}}catch{o(!1),i(`Could not prepare the export. Please try again.`)}};return(0,L.jsxs)(Oe,{open:t,onOpenChange:n,children:[(0,L.jsx)(De,{asChild:!0,children:(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,disabled:a,children:[(0,L.jsx)(ze,{className:`size-4`}),a?`Preparing report…`:`Export`]})}),(0,L.jsxs)(Ee,{align:`end`,className:`max-w-[calc(100vw-2rem)] space-y-3`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Export current dashboard`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Visible modules, current filters and loaded rows. Hidden metrics are excluded.`}),(0,L.jsxs)(`label`,{className:`block space-y-1 text-xs text-muted-foreground`,children:[`Report title (optional)`,(0,L.jsx)(`input`,{className:`min-h-11 w-full rounded-md border bg-background px-3 text-sm text-foreground`,placeholder:`e.g. Fleet review for leadership`,value:s,onChange:e=>c(e.target.value)})]}),(0,L.jsx)(O,{className:`min-h-11 w-full`,onClick:()=>l(`pdf`),children:`PDF report…`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Choose Save as PDF in the print dialog.`}),(0,L.jsx)(O,{variant:`outline`,className:`min-h-11 w-full`,onClick:()=>l(`csv`),children:`Download CSV`}),r&&(0,L.jsx)(`p`,{role:`alert`,className:`text-sm`,children:r})]})]})}var nr={overview:`Workspace overview`,portfolio:`Projects`,automations:`Automations`,fleet:`Queue & scheduling`,needsYou:`Needs you`,recent:`Recent results & GitHub`,usage:`Usage & cost`,trends:`Trends`};function rr({id:e,children:t,wide:n}){let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,isDragging:c}=de({id:e});return(0,L.jsxs)(`section`,{ref:a,"data-dashboard-module":e,className:`group/module relative min-w-0 ${n?`lg:col-span-2`:``} ${c?`z-20 opacity-80`:``}`,style:{transform:s?`translate3d(${s.x}px, ${s.y}px, 0)`:void 0},children:[(0,L.jsx)(O,{ref:o,variant:`ghost`,className:`absolute -top-[22px] left-1/2 z-10 min-h-11 min-w-11 -translate-x-1/2 cursor-grab touch-none p-0 opacity-0 transition-opacity hover:bg-transparent focus-visible:opacity-100 active:cursor-grabbing group-hover/module:opacity-100 no-hover:opacity-100`,...r,...i,"aria-label":`Move ${nr[e]}`,children:(0,L.jsx)(`span`,{className:`flex h-4 w-8 items-center justify-center rounded-full border bg-card text-muted-foreground shadow-xs`,children:(0,L.jsx)(qe,{className:`size-3.5`,"aria-hidden":`true`})})}),t]})}function ir({order:e,modules:t,onOrder:n}){let r=ve(oe(ge,{activationConstraint:{distance:8}}),oe(ae,{coordinateGetter:me})),i=e.filter(e=>t[e]),a=new Set([`overview`,`portfolio`,`usage`,`trends`]),o;for(let e of i)a.has(e)?(o&&a.add(o),o=void 0):o=o?void 0:e;o&&a.add(o);let s=e=>`${nr[e]}, position ${i.indexOf(e)+1} of ${i.length}`;return(0,L.jsx)(ue,{sensors:r,collisionDetection:ye,accessibility:{announcements:{onDragStart:({active:e})=>`Picked up ${s(e.id)}.`,onDragOver:({active:e,over:t})=>t?`${nr[e.id]} moved to position ${i.indexOf(t.id)+1} of ${i.length}.`:void 0,onDragEnd:({active:e,over:t})=>t?`${nr[e.id]} dropped at position ${i.indexOf(t.id)+1} of ${i.length}.`:`Order unchanged. ${s(e.id)}.`,onDragCancel:({active:e})=>`Reordering cancelled. ${s(e.id)}.`},screenReaderInstructions:{draggable:`Press Space to pick up a module, use arrow keys to move, Space to drop, or Escape to cancel.`}},onDragEnd:({active:t,over:r})=>{!r||t.id===r.id||n(le(e,e.indexOf(t.id),e.indexOf(r.id)))},children:(0,L.jsx)(ce,{items:i,strategy:he,children:(0,L.jsx)(`div`,{className:`grid items-start gap-5 lg:grid-cols-2`,children:i.map(e=>(0,L.jsx)(rr,{id:e,wide:a.has(e),children:t[e]},e))})})})}var ar=[`overview`,`needsYou`,`recent`,`fleet`,`automations`,`portfolio`,`usage`,`trends`],or=e=>ar.includes(e);function sr(e=[]){let t=e.filter(or);return(e=>t.length===e.length&&t.every((t,n)=>t===e[n]))(ar.filter(e=>e!==`automations`))?[...ar]:[...new Set([...t.includes(`overview`)?[]:[`overview`],...t,...ar])]}function cr(e=[],t){let n=0;return[...e.map(e=>or(e)?t[n++]:e),...t.slice(n)]}function lr(){let e=y(),t=f(),[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)(!1),o=(0,I.useRef)(void 0),s=(0,I.useRef)(!1),c=E.parse(e.data?.dashboard??{}),u=(0,I.useRef)(c);u.current=c;let p=n?.tiles??{automations:c.tiles?.automations??!0,fleet:c.tiles?.fleet??!0,needsYou:c.tiles?.needsYou??!0,recent:c.tiles?.recent??!0,usage:c.tiles?.usage??!0,trends:c.tiles?.trends??!0},h=sr(n?.order??c.order),g=(0,I.useRef)({tiles:p,order:h});g.current=n??{tiles:p,order:h};let _=e=>{let t={...g.current,...e};g.current=t,r(t),o.current=t},v=async()=>{if(!(s.current||!o.current)){for(s.current=!0;o.current;){let n=o.current;o.current=void 0;try{e.data||(u.current=E.parse((await l()).dashboard??{}));let i=await m({dashboard:{...u.current,order:cr(u.current.order,n.order),tiles:{...u.current?.tiles,...n.tiles}}});t.setQueryData(d.uiState,i),u.current=E.parse(i.dashboard??{}),a(!1),r(e=>e===n?void 0:e)}catch{a(!0),o.current||=n;break}}s.current=!1}},b=(0,I.useRef)(v);return b.current=v,(0,I.useEffect)(()=>()=>{b.current()},[]),(0,I.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>{v()},250);return()=>clearTimeout(e)},[n]),{tiles:p,order:h,setOrder:e=>_({order:sr(e)}),failed:i,ready:e.data!==void 0||e.isError,setTiles(e){_({tiles:e})},retry:()=>{v()}}}function ur(e,t){let n=ar.filter(e=>t.includes(e)),r=0;return e.map(e=>t.includes(e)?n[r++]:e)}var dr=[[`overview`,`Overview`],[`costs`,`Usage & cost`],[`automations`,`Automations`]];function fr(){let e=p(),t=e.state?.dashboardEntry??e.key;return(0,L.jsx)(pr,{entryKey:t},t)}function pr({entryKey:e}){let t=p(),[n,r]=v(),i=(0,I.useRef)(dt(e)).current,[a,o]=(0,I.useState)(i?.questions??0),[s,c]=(0,I.useState)(i?.reviews??0),[l,u]=(0,I.useState)(i?.feed??6),d=(0,I.useRef)(null),f=(0,I.useRef)(null),[m,h]=(0,I.useState)(!1),g=lr(),[y,b]=(0,I.useState)(!1),x=n.get(`view`)===`costs`?`costs`:n.get(`view`)===`automations`?`automations`:`overview`,S=dr.find(([e])=>e===x)[1],C=x===`costs`?[`usage`,`trends`]:x===`automations`?[`automations`]:[`fleet`,`needsYou`,`recent`],w=x===`overview`?[`overview`,`portfolio`,...C]:[...C],T=ur(g.order,w),ee=()=>g.setTiles({...g.tiles,...Object.fromEntries(C.map(e=>[e,!0]))}),E=g.tiles,D={...E,automations:x===`automations`&&E.automations,fleet:x===`overview`&&E.fleet,needsYou:x===`overview`&&E.needsYou,recent:x===`overview`&&E.recent,usage:x===`costs`&&E.usage,trends:x===`costs`&&E.trends},te=n.get(`feed`)===`tasks`?`tasks`:n.get(`feed`)===`github`?`github`:`all`,re=n.get(`panel`),k=re&&[`running`,`queued`,`scheduled`,`needs-you`].includes(re)?re:null,A=D.fleet||D.needsYou||D.recent&&te!==`github`||!!k,j=Qt(g.ready&&A),M=pe();$t(g.ready&&D.fleet&&y);let ie=(0,I.useRef)({questions:a,reviews:s,feed:l,scroll:i?.scroll??0,focus:i?.focus});ie.current={...ie.current,questions:a,reviews:s,feed:l},(0,I.useEffect)(()=>{let t=d.current?.closest(`main`)??d.current,n=()=>{ie.current.scroll=t?.scrollTop??0},r=()=>{ie.current.focus=document.activeElement?.closest(`[data-dashboard-row]`)?.getAttribute(`data-dashboard-row`)??void 0};return t?.addEventListener(`scroll`,n),document.addEventListener(`focusin`,r),()=>{ft(e,ie.current),t?.removeEventListener(`scroll`,n),document.removeEventListener(`focusin`,r)}},[e]);let ae=(0,I.useRef)(!1),oe=g.ready&&(!A||!!j.data&&!j.isFetching);(0,I.useEffect)(()=>{if(!i||ae.current||!oe)return;let e=!1,t=()=>{if(e)return!0;let t=d.current?.closest(`main`)??d.current;t&&(t.scrollTop=i.scroll);let n=!!t&&Math.abs(t.scrollTop-i.scroll)<1;if(!i.focus)return n;let r=document.querySelector(`[data-dashboard-row="${CSS.escape(i.focus)}"] a`);return r?(r.focus({preventScroll:!0}),n):(document.getElementById(`dashboard-needs-you`)?.focus({preventScroll:!0}),!1)},n=()=>{t()&&o()},r=new MutationObserver(n),a=typeof ResizeObserver>`u`?null:new ResizeObserver(n),o=()=>{e=!0,ae.current=!0,r.disconnect(),a?.disconnect()},s=requestAnimationFrame(()=>{n(),e||(r.observe(document.body,{childList:!0,subtree:!0}),d.current&&a?.observe(d.current))}),c=setTimeout(o,5e3),l=[`pointerdown`,`keydown`,`wheel`,`touchstart`];for(let e of l)document.addEventListener(e,o,{once:!0});return()=>{cancelAnimationFrame(s),clearTimeout(c),e=!0,r.disconnect(),a?.disconnect();for(let e of l)document.removeEventListener(e,o)}},[i,oe]);let se=i=>{let a=new URLSearchParams(n);i?a.set(`panel`,i):a.delete(`panel`),r(a,{replace:!0,state:{...t.state,dashboardEntry:e}})},ce=(e,t)=>{f.current=t,se(e)},le=j.data?j.data.counts.questions+j.data.counts.reviews:0;return(0,L.jsx)(st.Provider,{value:e,children:(0,L.jsx)(ct.Provider,{value:!i||!j.isFetching&&!j.isError,children:(0,L.jsxs)(`div`,{ref:d,"data-route":`dashboard`,className:`mx-auto w-full max-w-[1440px] space-y-6 p-4 md:px-8 md:py-7`,children:[(0,L.jsxs)(`header`,{className:`flex flex-wrap items-end justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Dashboard`}),(0,L.jsxs)(`p`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[`Across your workspace · Includes subtasks`,(0,L.jsxs)(`span`,{"data-export-exclude":!0,className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 font-mono text-[10.5px] uppercase tracking-[0.1em]`,children:[(0,L.jsx)(P,{tone:M.connected?`success`:`neutral`,pulse:M.connected}),M.connected?`Live`:`Offline`]})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(tr,{dashboard:d}),(0,L.jsxs)(Oe,{open:m,onOpenChange:h,children:[(0,L.jsx)(De,{asChild:!0,children:(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,children:[(0,L.jsx)(ne,{className:`size-4`}),`Customize`]})}),(0,L.jsxs)(Ee,{align:`end`,className:`max-h-[min(32rem,80dvh)] max-w-[calc(100vw-2rem)] overflow-y-auto`,children:[(0,L.jsx)(`p`,{className:`mb-3 text-sm font-medium`,children:`Optional modules in this view`}),C.map(e=>(0,L.jsxs)(`label`,{className:`flex min-h-11 items-center gap-3 text-sm`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:E[e],disabled:!g.ready,onChange:t=>g.setTiles({...E,[e]:t.target.checked})}),{automations:`Automations`,fleet:`Queue & scheduling`,needsYou:`Needs you`,recent:`Recent results & GitHub`,usage:`Usage & cost`,trends:`Trends`}[e]]},e)),(0,L.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Drag a module by its handle. With keyboard: Space, arrow keys, Space. Escape cancels.`}),g.order.some((e,t)=>e!==T[t])&&(0,L.jsxs)(O,{variant:`ghost`,className:`min-h-11`,onClick:()=>g.setOrder(T),children:[`Reset `,S,` order`]}),(0,L.jsx)(`p`,{className:`my-3 text-xs text-muted-foreground`,children:`Shared across browsers using this workspace`}),C.some(e=>!E[e])&&(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,disabled:!g.ready,onClick:()=>{ee(),h(!1)},children:[`Show all in `,S]})]})]})]})]}),(0,L.jsx)(`nav`,{"aria-label":`Dashboard views`,className:`-mt-2 flex flex-wrap gap-5 border-b`,children:dr.map(([r,i])=>{let a=new URLSearchParams(n);return a.set(`view`,r),a.delete(`panel`),(0,L.jsx)(O,{asChild:!0,variant:`ghost`,className:`-mb-px min-h-11 rounded-none border-b-2 px-0.5 hover:bg-transparent ${x===r?`border-primary text-foreground`:`border-transparent`}`,children:(0,L.jsx)(_,{"aria-current":x===r?`page`:void 0,to:`?${a}`,replace:x===r,state:{...t.state,dashboardEntry:x===r?e:void 0},children:i})},r)})}),g.failed&&(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[`Layout changed for this session, but could not be saved.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11`,onClick:g.retry,children:`Retry saving`})]}),A&&!M.connected&&j.data&&(0,L.jsxs)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:[`Tasks disconnected · Last updated `,F(j.data.asOf),` ago`]}),A&&j.isError&&(0,L.jsxs)(`p`,{role:`alert`,className:`rounded-md border p-4 text-sm`,children:[`Could not refresh dashboard.`,` `,j.data?`Showing the last available task state.`:``,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{j.refetch()},children:`Retry`})]}),x===`costs`&&!Object.values(D).some(Boolean)?(0,L.jsxs)(`p`,{role:`status`,className:`flex flex-wrap items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(_e,{className:`size-4`,"aria-hidden":`true`}),`Optional modules in this view are hidden.`,(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,onClick:()=>ee(),children:[`Show all in `,S]})]}):null,j.isPending&&(D.fleet||D.needsYou)&&(0,L.jsx)(`p`,{className:`text-sm`,children:`Loading dashboard…`}),A&&j.data&&(0,L.jsx)(K,{coverage:j.data.coverage,count:le,retry:()=>void j.refetch()}),x===`automations`&&(0,L.jsx)(Pt,{}),(0,L.jsx)(Gt,{active:x===`overview`,onCurrent:ce,children:i=>g.ready&&(0,L.jsx)(ir,{order:g.order,onOrder:g.setOrder,modules:{...i,automations:D.automations?(0,L.jsx)(it,{}):null,fleet:D.fleet&&j.data?(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsx)(R,{rows:Object.entries({queued:j.data.counts.queued,scheduled:j.data.counts.scheduled,monitoring:j.data.counts.monitoring}).map(([e,t])=>({section:`fleet`,metric:e,value:t,unit:`tasks`,asOf:j.data.asOf}))}),(0,L.jsxs)(`div`,{className:`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,children:[(0,L.jsx)(`h2`,{className:`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Queue & scheduling`}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(P,{tone:M.connected?`success`:`neutral`}),M.connected?`Tasks connected`:`Tasks disconnected`]})]}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 divide-x`,children:[[`queued`,`Queued`,j.data.counts.queued],[`scheduled`,`Scheduled`,j.data.counts.scheduled]].map(([e,t,n])=>(0,L.jsxs)(`button`,{"data-export-keep":!0,"aria-label":`${t}: ${n}`,className:`min-h-24 p-4 text-left transition-colors hover:bg-muted/40 focus-visible:outline-ring`,onClick:t=>ce(e,t.currentTarget),children:[(0,L.jsx)(`span`,{className:`block font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground`,children:t}),(0,L.jsx)(`span`,{className:`mt-3 block text-3xl font-semibold leading-none tracking-tight tabular-nums`,children:n})]},e))}),(0,L.jsxs)(`details`,{open:y,onToggle:e=>b(e.currentTarget.open),className:`border-t px-4 py-3 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-2`,children:[(0,L.jsx)(V,{}),`Technical details`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:[(0,L.jsxs)(`span`,{children:[j.data.counts.monitoring,` monitoring (included in Running)`]}),(0,L.jsx)(`span`,{children:`Agent processes`}),y&&(0,L.jsx)(mr,{running:j.data.counts.running})]})]})]}):null,needsYou:D.needsYou&&j.data?(0,L.jsx)(Bn,{healthy:!j.isError,snapshot:j.data,questions:a,reviews:s,more:(e,t)=>e===`questions`?o(t):c(t)}):null,recent:D.recent?(0,L.jsx)(Wn,{filter:te,setFilter:i=>{let a=new URLSearchParams(n);a.set(`feed`,i||`all`),r(a,{replace:!0,state:{...t.state,dashboardEntry:e}}),u(6)},count:l,more:()=>u(e=>Math.min(60,e+20))}):null,usage:D.usage?(0,L.jsx)(bn,{}):null,trends:D.trends?(0,L.jsx)(In,{}):null}})}),x===`costs`&&(0,L.jsx)(Mt,{}),(0,L.jsx)(we,{open:!!k,onOpenChange:e=>{e||se(null)},children:(0,L.jsxs)(Ce,{className:`w-full overflow-y-auto sm:max-w-lg`,onCloseAutoFocus:e=>{e.preventDefault(),f.current?.focus()},children:[(0,L.jsxs)(be,{children:[(0,L.jsxs)(Se,{children:[k===`needs-you`?`Needs you`:k?k[0].toUpperCase()+k.slice(1):`Tasks`,j.data&&k?` · ${k===`needs-you`?le:j.data.counts[k]}`:``]}),(0,L.jsx)(xe,{children:`Includes subtasks. Open a task to continue in its project.`})]}),!j.data&&j.isPending&&(0,L.jsx)(`p`,{className:`p-4`,role:`status`,children:`Loading tasks…`}),!j.data&&j.isError&&(0,L.jsxs)(`p`,{className:`p-4`,role:`alert`,children:[`Could not load tasks.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{j.refetch()},children:`Retry`})]}),k&&j.data&&(0,L.jsx)(hr,{snapshot:j.data,group:k},k)]})})]})})})}function mr({running:e}){let{connected:t,samples:n}=pe(),r=t?n:[],i=r.filter(e=>e.cpuPct!==null);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R,{rows:[{section:`telemetry`,metric:`cpuPct`,value:i.length?i.reduce((e,t)=>e+(t.cpuPct??0),0):null,unit:`%`,reportedTasks:i.length,totalTasks:e,note:`Sum of sampled processes; may exceed 100%`},{section:`telemetry`,metric:`rssBytes`,value:r.length?r.reduce((e,t)=>e+t.rssBytes,0):null,unit:`bytes`,reportedTasks:r.length,totalTasks:e}]}),(0,L.jsxs)(`span`,{children:[`CPU`,` `,i.length?`${Math.round(i.reduce((e,t)=>e+(t.cpuPct??0),0))}%`:`unavailable`,` `,`· `,i.length,`/`,e,` measured`]}),(0,L.jsxs)(`span`,{children:[`RSS`,` `,r.length?`${(r.reduce((e,t)=>e+t.rssBytes,0)/1024**3).toFixed(1)} GiB`:`unavailable`,` `,`· `,r.length,`/`,e,` measured`]}),(0,L.jsx)(`span`,{children:`RSS sums process resident memory; CPU may exceed 100%.`})]})}function hr({snapshot:e,group:t}){let n=(0,I.useContext)(st),r=(0,I.useRef)(pt(n,t)).current,[i,a]=(0,I.useState)(r?.count??20),o=(0,I.useRef)(null),s=(0,I.useRef)({count:i,scroll:r?.scroll??0});s.current.count=i,(0,I.useEffect)(()=>{let e=o.current?.closest(`[data-slot="sheet-content"]`),r=()=>{s.current.scroll=e?.scrollTop??0};return e?.addEventListener(`scroll`,r),()=>{mt(n,t,s.current),e?.removeEventListener(`scroll`,r)}},[n,t]);let c=Rn(e,t,i),l=lt(c.data,G,`panel:${t}`,i),u=zn(e,t,i,l.rows.filter(e=>e.removed).map(e=>e.row)),d=(0,I.useRef)(null),f=(0,I.useRef)(!1);(0,I.useEffect)(()=>{if(!c.data||!r||f.current)return;f.current=!0;let e=o.current?.closest(`[data-slot="sheet-content"]`);e&&(e.scrollTop=r.scroll)},[c.data,r]);let p=t===`needs-you`?e.counts.questions+e.counts.reviews:e.counts[t];return(0,L.jsxs)(`div`,{ref:o,children:[(0,L.jsx)(`h3`,{ref:d,tabIndex:-1,className:`sr-only`,children:`Tasks`}),c.isPending&&(0,L.jsx)(`p`,{className:`p-4`,children:`Loading tasks…`}),(c.isError||u.isError)&&(0,L.jsxs)(`p`,{className:`p-4`,role:`alert`,children:[`Could not check current task state.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{c.refetch(),u.refetch()},children:`Retry`})]}),l.updates>0&&(0,L.jsxs)(O,{className:`m-4 min-h-11`,onClick:()=>{l.show(),d.current?.focus()},children:[l.updates,` updates — Show`]}),l.rows.map(({row:e,removed:n})=>(0,L.jsx)(ht,{row:u.data?.get(G(e))??e,removed:n&&!!u.data&&!u.data.has(G(e)),checking:!c.data||n&&!u.data,checkFailed:!c.data&&c.isError||n&&!u.data&&u.isError,queue:t===`needs-you`},G(e))),i<p&&(0,L.jsxs)(O,{className:`m-4 min-h-11`,disabled:c.isFetching,onClick:()=>a(e=>e+20),children:[`Show `,Math.min(20,p-i),` more tasks`]})]})}export{fr as DashboardRoute};
|
|
44
|
+
</style></head><body><header class="report-heading"><h1>${$(e.title||`Dashboard report`)}</h1><p>${$(e.generatedAt)} · ${$(e.source)}</p><span class="report-confidential">${Kn}</span><p>${$(Gn)}</p>${e.notices.map(e=>`<p>${$(e)}</p>`).join(``)}</header>${n.length?`<section class="report-summary"><h2>Executive summary</h2><div class="summary-grid">${n.map(e=>`<div class="summary-tile"><span class="summary-value">${$(e.value)}</span><span class="summary-label">${$(e.label)}</span>${e.note?`<span class="summary-note">${$(e.note)}</span>`:``}</div>`).join(``)}</div></section>`:``}${e.modules.map(e=>`<section class="report-module${e.id===`usage`?` report-module-usage`:e.id===`fleet`?` report-module-fleet`:``}"><p class="report-context">${$(e.filters)}</p>${e.html}</section>`).join(``)}</body></html>`}function tr({dashboard:e}){let[t,n]=(0,I.useState)(!1),[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(``),l=t=>{i(``);try{if(!e.current)return;let r=Zn(e.current,new Date().toISOString(),location.origin,s.trim());if(!r.modules.length){i(`Show at least one dashboard module before exporting.`);return}if(t===`csv`){let e=URL.createObjectURL(new Blob([$n(r)],{type:`text/csv;charset=utf-8`})),t=document.createElement(`a`);t.href=e,t.download=`dashboard-${r.generatedAt.replaceAll(`:`,`-`)}.csv`,document.body.append(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),1e3),n(!1)}else{o(!0);let e=[...document.querySelectorAll(`link[rel="stylesheet"],style`)].flatMap(e=>{if(e.tagName===`STYLE`)return[e.outerHTML];let t=e.href;if(new URL(t).origin!==location.origin)return[];let n=document.createElement(`link`);return n.rel=`stylesheet`,n.href=t,[n.outerHTML]}),t=document.createElement(`iframe`);t.title=`Dashboard PDF report`,t.style.cssText=`position:fixed;width:1000px;height:1px;bottom:0;left:0;border:0;opacity:0;pointer-events:none`;let a,s=()=>{clearTimeout(a),t.remove(),o(!1)};t.onload=async()=>{try{let e=t.contentWindow;await e.document.fonts.ready,e.addEventListener(`afterprint`,s,{once:!0}),e.focus(),e.print(),n(!1),o(!1)}catch{s(),i(`Could not open the print dialog. Please try again.`)}},a=setTimeout(s,12e4),t.srcdoc=er(r,e),document.body.append(t)}}catch{o(!1),i(`Could not prepare the export. Please try again.`)}};return(0,L.jsxs)(Oe,{open:t,onOpenChange:n,children:[(0,L.jsx)(De,{asChild:!0,children:(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,disabled:a,children:[(0,L.jsx)(ze,{className:`size-4`}),a?`Preparing report…`:`Export`]})}),(0,L.jsxs)(Ee,{align:`end`,className:`max-w-[calc(100vw-2rem)] space-y-3`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Export current dashboard`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Visible modules, current filters and loaded rows. Hidden metrics are excluded.`}),(0,L.jsxs)(`label`,{className:`block space-y-1 text-xs text-muted-foreground`,children:[`Report title (optional)`,(0,L.jsx)(`input`,{className:`min-h-11 w-full rounded-md border bg-background px-3 text-sm text-foreground`,placeholder:`e.g. Fleet review for leadership`,value:s,onChange:e=>c(e.target.value)})]}),(0,L.jsx)(O,{className:`min-h-11 w-full`,onClick:()=>l(`pdf`),children:`PDF report…`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Choose Save as PDF in the print dialog.`}),(0,L.jsx)(O,{variant:`outline`,className:`min-h-11 w-full`,onClick:()=>l(`csv`),children:`Download CSV`}),r&&(0,L.jsx)(`p`,{role:`alert`,className:`text-sm`,children:r})]})]})}var nr={overview:`Workspace overview`,portfolio:`Projects`,automations:`Automations`,fleet:`Queue & scheduling`,needsYou:`Needs you`,recent:`Recent results & GitHub`,usage:`Usage & cost`,trends:`Trends`};function rr({id:e,children:t,wide:n}){let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,isDragging:c}=de({id:e});return(0,L.jsxs)(`section`,{ref:a,"data-dashboard-module":e,className:`group/module relative min-w-0 ${n?`lg:col-span-2`:``} ${c?`z-20 opacity-80`:``}`,style:{transform:s?`translate3d(${s.x}px, ${s.y}px, 0)`:void 0},children:[(0,L.jsx)(O,{ref:o,variant:`ghost`,className:`absolute -top-[22px] left-1/2 z-10 min-h-11 min-w-11 -translate-x-1/2 cursor-grab touch-none p-0 opacity-0 transition-opacity hover:bg-transparent focus-visible:opacity-100 active:cursor-grabbing group-hover/module:opacity-100 no-hover:opacity-100`,...r,...i,"aria-label":`Move ${nr[e]}`,children:(0,L.jsx)(`span`,{className:`flex h-4 w-8 items-center justify-center rounded-full border bg-card text-muted-foreground shadow-xs`,children:(0,L.jsx)(qe,{className:`size-3.5`,"aria-hidden":`true`})})}),t]})}function ir({order:e,modules:t,onOrder:n}){let r=ve(oe(ge,{activationConstraint:{distance:8}}),oe(ae,{coordinateGetter:me})),i=e.filter(e=>t[e]),a=new Set([`overview`,`portfolio`,`usage`,`trends`]),o;for(let e of i)a.has(e)?(o&&a.add(o),o=void 0):o=o?void 0:e;o&&a.add(o);let s=e=>`${nr[e]}, position ${i.indexOf(e)+1} of ${i.length}`;return(0,L.jsx)(ue,{sensors:r,collisionDetection:ye,accessibility:{announcements:{onDragStart:({active:e})=>`Picked up ${s(e.id)}.`,onDragOver:({active:e,over:t})=>t?`${nr[e.id]} moved to position ${i.indexOf(t.id)+1} of ${i.length}.`:void 0,onDragEnd:({active:e,over:t})=>t?`${nr[e.id]} dropped at position ${i.indexOf(t.id)+1} of ${i.length}.`:`Order unchanged. ${s(e.id)}.`,onDragCancel:({active:e})=>`Reordering cancelled. ${s(e.id)}.`},screenReaderInstructions:{draggable:`Press Space to pick up a module, use arrow keys to move, Space to drop, or Escape to cancel.`}},onDragEnd:({active:t,over:r})=>{!r||t.id===r.id||n(le(e,e.indexOf(t.id),e.indexOf(r.id)))},children:(0,L.jsx)(ce,{items:i,strategy:he,children:(0,L.jsx)(`div`,{className:`grid items-start gap-5 lg:grid-cols-2`,children:i.map(e=>(0,L.jsx)(rr,{id:e,wide:a.has(e),children:t[e]},e))})})})}var ar=[`overview`,`needsYou`,`recent`,`fleet`,`automations`,`portfolio`,`usage`,`trends`],or=e=>ar.includes(e);function sr(e=[]){let t=e.filter(or);return(e=>t.length===e.length&&t.every((t,n)=>t===e[n]))(ar.filter(e=>e!==`automations`))?[...ar]:[...new Set([...t.includes(`overview`)?[]:[`overview`],...t,...ar])]}function cr(e=[],t){let n=0;return[...e.map(e=>or(e)?t[n++]:e),...t.slice(n)]}function lr(){let e=_(),t=v(),[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)(!1),o=(0,I.useRef)(void 0),s=(0,I.useRef)(!1),l=E.parse(e.data?.dashboard??{}),u=(0,I.useRef)(l);u.current=l;let d=n?.tiles??{automations:l.tiles?.automations??!0,fleet:l.tiles?.fleet??!0,needsYou:l.tiles?.needsYou??!0,recent:l.tiles?.recent??!0,usage:l.tiles?.usage??!0,trends:l.tiles?.trends??!0},f=sr(n?.order??l.order),p=(0,I.useRef)({tiles:d,order:f});p.current=n??{tiles:d,order:f};let h=e=>{let t={...p.current,...e};p.current=t,r(t),o.current=t},g=async()=>{if(!(s.current||!o.current)){for(s.current=!0;o.current;){let n=o.current;o.current=void 0;try{e.data||(u.current=E.parse((await c()).dashboard??{}));let i=await y({dashboard:{...u.current,order:cr(u.current.order,n.order),tiles:{...u.current?.tiles,...n.tiles}}});t.setQueryData(m.uiState,i),u.current=E.parse(i.dashboard??{}),a(!1),r(e=>e===n?void 0:e)}catch{a(!0),o.current||=n;break}}s.current=!1}},b=(0,I.useRef)(g);return b.current=g,(0,I.useEffect)(()=>()=>{b.current()},[]),(0,I.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>{g()},250);return()=>clearTimeout(e)},[n]),{tiles:d,order:f,setOrder:e=>h({order:sr(e)}),failed:i,ready:e.data!==void 0||e.isError,setTiles(e){h({tiles:e})},retry:()=>{g()}}}function ur(e,t){let n=ar.filter(e=>t.includes(e)),r=0;return e.map(e=>t.includes(e)?n[r++]:e)}var dr=[[`overview`,`Overview`],[`costs`,`Usage & cost`],[`automations`,`Automations`]];function fr(){let e=r(),t=e.state?.dashboardEntry??e.key;return(0,L.jsx)(pr,{entryKey:t},t)}function pr({entryKey:e}){let t=r(),[n,i]=h(),a=(0,I.useRef)(dt(e)).current,[o,s]=(0,I.useState)(a?.questions??0),[c,u]=(0,I.useState)(a?.reviews??0),[d,f]=(0,I.useState)(a?.feed??6),p=(0,I.useRef)(null),m=(0,I.useRef)(null),[g,_]=(0,I.useState)(!1),v=lr(),[y,b]=(0,I.useState)(!1),x=n.get(`view`)===`costs`?`costs`:n.get(`view`)===`automations`?`automations`:`overview`,S=dr.find(([e])=>e===x)[1],C=x===`costs`?[`usage`,`trends`]:x===`automations`?[`automations`]:[`fleet`,`needsYou`,`recent`],w=x===`overview`?[`overview`,`portfolio`,...C]:[...C],T=ur(v.order,w),ee=()=>v.setTiles({...v.tiles,...Object.fromEntries(C.map(e=>[e,!0]))}),E=v.tiles,D={...E,automations:x===`automations`&&E.automations,fleet:x===`overview`&&E.fleet,needsYou:x===`overview`&&E.needsYou,recent:x===`overview`&&E.recent,usage:x===`costs`&&E.usage,trends:x===`costs`&&E.trends},te=n.get(`feed`)===`tasks`?`tasks`:n.get(`feed`)===`github`?`github`:`all`,re=n.get(`panel`),k=re&&[`running`,`queued`,`scheduled`,`needs-you`].includes(re)?re:null,A=D.fleet||D.needsYou||D.recent&&te!==`github`||!!k,j=Qt(v.ready&&A),M=pe();$t(v.ready&&D.fleet&&y);let ie=(0,I.useRef)({questions:o,reviews:c,feed:d,scroll:a?.scroll??0,focus:a?.focus});ie.current={...ie.current,questions:o,reviews:c,feed:d},(0,I.useEffect)(()=>{let t=p.current?.closest(`main`)??p.current,n=()=>{ie.current.scroll=t?.scrollTop??0},r=()=>{ie.current.focus=document.activeElement?.closest(`[data-dashboard-row]`)?.getAttribute(`data-dashboard-row`)??void 0};return t?.addEventListener(`scroll`,n),document.addEventListener(`focusin`,r),()=>{ft(e,ie.current),t?.removeEventListener(`scroll`,n),document.removeEventListener(`focusin`,r)}},[e]);let ae=(0,I.useRef)(!1),oe=v.ready&&(!A||!!j.data&&!j.isFetching);(0,I.useEffect)(()=>{if(!a||ae.current||!oe)return;let e=!1,t=()=>{if(e)return!0;let t=p.current?.closest(`main`)??p.current;t&&(t.scrollTop=a.scroll);let n=!!t&&Math.abs(t.scrollTop-a.scroll)<1;if(!a.focus)return n;let r=document.querySelector(`[data-dashboard-row="${CSS.escape(a.focus)}"] a`);return r?(r.focus({preventScroll:!0}),n):(document.getElementById(`dashboard-needs-you`)?.focus({preventScroll:!0}),!1)},n=()=>{t()&&o()},r=new MutationObserver(n),i=typeof ResizeObserver>`u`?null:new ResizeObserver(n),o=()=>{e=!0,ae.current=!0,r.disconnect(),i?.disconnect()},s=requestAnimationFrame(()=>{n(),e||(r.observe(document.body,{childList:!0,subtree:!0}),p.current&&i?.observe(p.current))}),c=setTimeout(o,5e3),l=[`pointerdown`,`keydown`,`wheel`,`touchstart`];for(let e of l)document.addEventListener(e,o,{once:!0});return()=>{cancelAnimationFrame(s),clearTimeout(c),e=!0,r.disconnect(),i?.disconnect();for(let e of l)document.removeEventListener(e,o)}},[a,oe]);let se=r=>{let a=new URLSearchParams(n);r?a.set(`panel`,r):a.delete(`panel`),i(a,{replace:!0,state:{...t.state,dashboardEntry:e}})},ce=(e,t)=>{m.current=t,se(e)},le=j.data?j.data.counts.questions+j.data.counts.reviews:0;return(0,L.jsx)(st.Provider,{value:e,children:(0,L.jsx)(ct.Provider,{value:!a||!j.isFetching&&!j.isError,children:(0,L.jsxs)(`div`,{ref:p,"data-route":`dashboard`,className:`mx-auto w-full max-w-[1440px] space-y-6 p-4 md:px-8 md:py-7`,children:[(0,L.jsxs)(`header`,{className:`flex flex-wrap items-end justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Dashboard`}),(0,L.jsxs)(`p`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[`Across your workspace · Includes subtasks`,(0,L.jsxs)(`span`,{"data-export-exclude":!0,className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 font-mono text-[10.5px] uppercase tracking-[0.1em]`,children:[(0,L.jsx)(P,{tone:M.connected?`success`:`neutral`,pulse:M.connected}),M.connected?`Live`:`Offline`]})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(tr,{dashboard:p}),(0,L.jsxs)(Oe,{open:g,onOpenChange:_,children:[(0,L.jsx)(De,{asChild:!0,children:(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,children:[(0,L.jsx)(ne,{className:`size-4`}),`Customize`]})}),(0,L.jsxs)(Ee,{align:`end`,className:`max-h-[min(32rem,80dvh)] max-w-[calc(100vw-2rem)] overflow-y-auto`,children:[(0,L.jsx)(`p`,{className:`mb-3 text-sm font-medium`,children:`Optional modules in this view`}),C.map(e=>(0,L.jsxs)(`label`,{className:`flex min-h-11 items-center gap-3 text-sm`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:E[e],disabled:!v.ready,onChange:t=>v.setTiles({...E,[e]:t.target.checked})}),{automations:`Automations`,fleet:`Queue & scheduling`,needsYou:`Needs you`,recent:`Recent results & GitHub`,usage:`Usage & cost`,trends:`Trends`}[e]]},e)),(0,L.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Drag a module by its handle. With keyboard: Space, arrow keys, Space. Escape cancels.`}),v.order.some((e,t)=>e!==T[t])&&(0,L.jsxs)(O,{variant:`ghost`,className:`min-h-11`,onClick:()=>v.setOrder(T),children:[`Reset `,S,` order`]}),(0,L.jsx)(`p`,{className:`my-3 text-xs text-muted-foreground`,children:`Shared across browsers using this workspace`}),C.some(e=>!E[e])&&(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,disabled:!v.ready,onClick:()=>{ee(),_(!1)},children:[`Show all in `,S]})]})]})]})]}),(0,L.jsx)(`nav`,{"aria-label":`Dashboard views`,className:`-mt-2 flex flex-wrap gap-5 border-b`,children:dr.map(([r,i])=>{let a=new URLSearchParams(n);return a.set(`view`,r),a.delete(`panel`),(0,L.jsx)(O,{asChild:!0,variant:`ghost`,className:`-mb-px min-h-11 rounded-none border-b-2 px-0.5 hover:bg-transparent ${x===r?`border-primary text-foreground`:`border-transparent`}`,children:(0,L.jsx)(l,{"aria-current":x===r?`page`:void 0,to:`?${a}`,replace:x===r,state:{...t.state,dashboardEntry:x===r?e:void 0},children:i})},r)})}),v.failed&&(0,L.jsxs)(`p`,{role:`alert`,className:`text-sm`,children:[`Layout changed for this session, but could not be saved.`,` `,(0,L.jsx)(O,{variant:`ghost`,className:`min-h-11`,onClick:v.retry,children:`Retry saving`})]}),A&&!M.connected&&j.data&&(0,L.jsxs)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:[`Tasks disconnected · Last updated `,F(j.data.asOf),` ago`]}),A&&j.isError&&(0,L.jsxs)(`p`,{role:`alert`,className:`rounded-md border p-4 text-sm`,children:[`Could not refresh dashboard.`,` `,j.data?`Showing the last available task state.`:``,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{j.refetch()},children:`Retry`})]}),x===`costs`&&!Object.values(D).some(Boolean)?(0,L.jsxs)(`p`,{role:`status`,className:`flex flex-wrap items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(_e,{className:`size-4`,"aria-hidden":`true`}),`Optional modules in this view are hidden.`,(0,L.jsxs)(O,{variant:`outline`,className:`min-h-11`,onClick:()=>ee(),children:[`Show all in `,S]})]}):null,j.isPending&&(D.fleet||D.needsYou)&&(0,L.jsx)(`p`,{className:`text-sm`,children:`Loading dashboard…`}),A&&j.data&&(0,L.jsx)(K,{coverage:j.data.coverage,count:le,retry:()=>void j.refetch()}),x===`automations`&&(0,L.jsx)(Pt,{}),(0,L.jsx)(Gt,{active:x===`overview`,onCurrent:ce,children:r=>v.ready&&(0,L.jsx)(ir,{order:v.order,onOrder:v.setOrder,modules:{...r,automations:D.automations?(0,L.jsx)(it,{}):null,fleet:D.fleet&&j.data?(0,L.jsxs)(N,{className:`gap-0 py-0`,children:[(0,L.jsx)(R,{rows:Object.entries({queued:j.data.counts.queued,scheduled:j.data.counts.scheduled,monitoring:j.data.counts.monitoring}).map(([e,t])=>({section:`fleet`,metric:e,value:t,unit:`tasks`,asOf:j.data.asOf}))}),(0,L.jsxs)(`div`,{className:`flex min-h-12 flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5`,children:[(0,L.jsx)(`h2`,{className:`section-mark font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground`,children:`Queue & scheduling`}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(P,{tone:M.connected?`success`:`neutral`}),M.connected?`Tasks connected`:`Tasks disconnected`]})]}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 divide-x`,children:[[`queued`,`Queued`,j.data.counts.queued],[`scheduled`,`Scheduled`,j.data.counts.scheduled]].map(([e,t,n])=>(0,L.jsxs)(`button`,{"data-export-keep":!0,"aria-label":`${t}: ${n}`,className:`min-h-24 p-4 text-left transition-colors hover:bg-muted/40 focus-visible:outline-ring`,onClick:t=>ce(e,t.currentTarget),children:[(0,L.jsx)(`span`,{className:`block font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground`,children:t}),(0,L.jsx)(`span`,{className:`mt-3 block text-3xl font-semibold leading-none tracking-tight tabular-nums`,children:n})]},e))}),(0,L.jsxs)(`details`,{open:y,onToggle:e=>b(e.currentTarget.open),className:`border-t px-4 py-3 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-sm text-muted-foreground transition-colors select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&::-webkit-details-marker]:hidden py-2`,children:[(0,L.jsx)(V,{}),`Technical details`]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:[(0,L.jsxs)(`span`,{children:[j.data.counts.monitoring,` monitoring (included in Running)`]}),(0,L.jsx)(`span`,{children:`Agent processes`}),y&&(0,L.jsx)(mr,{running:j.data.counts.running})]})]})]}):null,needsYou:D.needsYou&&j.data?(0,L.jsx)(Bn,{healthy:!j.isError,snapshot:j.data,questions:o,reviews:c,more:(e,t)=>e===`questions`?s(t):u(t)}):null,recent:D.recent?(0,L.jsx)(Wn,{filter:te,setFilter:r=>{let a=new URLSearchParams(n);a.set(`feed`,r||`all`),i(a,{replace:!0,state:{...t.state,dashboardEntry:e}}),f(6)},count:d,more:()=>f(e=>Math.min(60,e+20))}):null,usage:D.usage?(0,L.jsx)(bn,{}):null,trends:D.trends?(0,L.jsx)(In,{}):null}})}),x===`costs`&&(0,L.jsx)(Mt,{}),(0,L.jsx)(we,{open:!!k,onOpenChange:e=>{e||se(null)},children:(0,L.jsxs)(Ce,{className:`w-full overflow-y-auto sm:max-w-lg`,onCloseAutoFocus:e=>{e.preventDefault(),m.current?.focus()},children:[(0,L.jsxs)(be,{children:[(0,L.jsxs)(Se,{children:[k===`needs-you`?`Needs you`:k?k[0].toUpperCase()+k.slice(1):`Tasks`,j.data&&k?` · ${k===`needs-you`?le:j.data.counts[k]}`:``]}),(0,L.jsx)(xe,{children:`Includes subtasks. Open a task to continue in its project.`})]}),!j.data&&j.isPending&&(0,L.jsx)(`p`,{className:`p-4`,role:`status`,children:`Loading tasks…`}),!j.data&&j.isError&&(0,L.jsxs)(`p`,{className:`p-4`,role:`alert`,children:[`Could not load tasks.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{j.refetch()},children:`Retry`})]}),k&&j.data&&(0,L.jsx)(hr,{snapshot:j.data,group:k},k)]})})]})})})}function mr({running:e}){let{connected:t,samples:n}=pe(),r=t?n:[],i=r.filter(e=>e.cpuPct!==null);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(R,{rows:[{section:`telemetry`,metric:`cpuPct`,value:i.length?i.reduce((e,t)=>e+(t.cpuPct??0),0):null,unit:`%`,reportedTasks:i.length,totalTasks:e,note:`Sum of sampled processes; may exceed 100%`},{section:`telemetry`,metric:`rssBytes`,value:r.length?r.reduce((e,t)=>e+t.rssBytes,0):null,unit:`bytes`,reportedTasks:r.length,totalTasks:e}]}),(0,L.jsxs)(`span`,{children:[`CPU`,` `,i.length?`${Math.round(i.reduce((e,t)=>e+(t.cpuPct??0),0))}%`:`unavailable`,` `,`· `,i.length,`/`,e,` measured`]}),(0,L.jsxs)(`span`,{children:[`RSS`,` `,r.length?`${(r.reduce((e,t)=>e+t.rssBytes,0)/1024**3).toFixed(1)} GiB`:`unavailable`,` `,`· `,r.length,`/`,e,` measured`]}),(0,L.jsx)(`span`,{children:`RSS sums process resident memory; CPU may exceed 100%.`})]})}function hr({snapshot:e,group:t}){let n=(0,I.useContext)(st),r=(0,I.useRef)(pt(n,t)).current,[i,a]=(0,I.useState)(r?.count??20),o=(0,I.useRef)(null),s=(0,I.useRef)({count:i,scroll:r?.scroll??0});s.current.count=i,(0,I.useEffect)(()=>{let e=o.current?.closest(`[data-slot="sheet-content"]`),r=()=>{s.current.scroll=e?.scrollTop??0};return e?.addEventListener(`scroll`,r),()=>{mt(n,t,s.current),e?.removeEventListener(`scroll`,r)}},[n,t]);let c=Rn(e,t,i),l=lt(c.data,G,`panel:${t}`,i),u=zn(e,t,i,l.rows.filter(e=>e.removed).map(e=>e.row)),d=(0,I.useRef)(null),f=(0,I.useRef)(!1);(0,I.useEffect)(()=>{if(!c.data||!r||f.current)return;f.current=!0;let e=o.current?.closest(`[data-slot="sheet-content"]`);e&&(e.scrollTop=r.scroll)},[c.data,r]);let p=t===`needs-you`?e.counts.questions+e.counts.reviews:e.counts[t];return(0,L.jsxs)(`div`,{ref:o,children:[(0,L.jsx)(`h3`,{ref:d,tabIndex:-1,className:`sr-only`,children:`Tasks`}),c.isPending&&(0,L.jsx)(`p`,{className:`p-4`,children:`Loading tasks…`}),(c.isError||u.isError)&&(0,L.jsxs)(`p`,{className:`p-4`,role:`alert`,children:[`Could not check current task state.`,` `,(0,L.jsx)(O,{className:`min-h-11`,onClick:()=>{c.refetch(),u.refetch()},children:`Retry`})]}),l.updates>0&&(0,L.jsxs)(O,{className:`m-4 min-h-11`,onClick:()=>{l.show(),d.current?.focus()},children:[l.updates,` updates — Show`]}),l.rows.map(({row:e,removed:n})=>(0,L.jsx)(ht,{row:u.data?.get(G(e))??e,removed:n&&!!u.data&&!u.data.has(G(e)),checking:!c.data||n&&!u.data,checkFailed:!c.data&&c.isError||n&&!u.data&&u.isError,queue:t===`needs-you`},G(e))),i<p&&(0,L.jsxs)(O,{className:`m-4 min-h-11`,disabled:c.isFetching,onClick:()=>a(e=>e+20),children:[`Show `,Math.min(20,p-i),` more tasks`]})]})}export{fr as DashboardRoute};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diff-view-
|
|
2
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{r}from"./button-Cz2i1VWG.js";import{i}from"./bundle-mjs-BT31bpU6.js";import{t as a}from"./diff-stat-CHeIoBxd.js";import{i as o,n as s,r as c,t as l}from"./scroll-within-c541dNeG.js";var u=e(t(),1),d=n();function f(e){let[t,n]=(0,u.useState)(null);return(0,u.useEffect)(()=>{let e=!1;return i(()=>import(`./diff-view-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diff-view-CZg35276.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-runtime-CCIEwYL0.js","assets/button-Cz2i1VWG.js","assets/bundle-mjs-BT31bpU6.js","assets/chevron-right-qEQMQjVX.js","assets/use-submit-shortcut-Ct5pt-M6.js","assets/diff-stat-CHeIoBxd.js","assets/chunk-BO2N2NFS-MDrqQfMl.js","assets/lib-BxQXEXDF.js","assets/markdown-CWuKlrA3.js","assets/alert-dialog-BNZUIiF0.js","assets/index-DUhrduZ3.js","assets/project-router-Bp0y3Wss.js","assets/use-automations-gfSKvY5Q.js","assets/sheet-D3Gui9Gi.js","assets/x-CuaSin2A.js","assets/reference-chip-BY5hNSAj.js","assets/tooltip-CxsyqHYQ.js","assets/triangle-alert-C7nDHB5Y.js","assets/token-metrics-CCt2gB1-.js","assets/check-yNnqjuI0.js","assets/use-now-Dso5ls9n.js","assets/reference-overflow-qtIEQOUG.js","assets/textarea-BtKEy9jU.js","assets/dropdown-menu-B_EzxWgl.js","assets/composer-G626Ezh_.js","assets/square-zWBXFCGI.js","assets/centered-state-BOZwY3o0.js","assets/thread-loading-DFtuUHAW.js","assets/search-x-CDsEIHMC.js","assets/upload-xSXMVMSl.js","assets/pill-DjY9dAt0.js","assets/index-CouNBVzI.css","assets/lib-BQXq3kEf.js","assets/markdown-Bxdits01.js","assets/message-square-DuB2mHor.js","assets/scroll-within-c541dNeG.js","assets/types-BTlmexWF.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{r}from"./button-Cz2i1VWG.js";import{i}from"./bundle-mjs-BT31bpU6.js";import{t as a}from"./diff-stat-CHeIoBxd.js";import{i as o,n as s,r as c,t as l}from"./scroll-within-c541dNeG.js";var u=e(t(),1),d=n();function f(e){let[t,n]=(0,u.useState)(null);return(0,u.useEffect)(()=>{let e=!1;return i(()=>import(`./diff-view-CZg35276.js`).then(t=>{e||n({View:t.DiffView})},()=>{e||n(`failed`)}),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38])),()=>{e=!0}},[]),e.files.length===0?(0,d.jsx)(`p`,{"data-slot":`diff-empty`,className:r(`px-1 text-xs text-soft-foreground`,e.className),children:`No changes.`}):t===`failed`?(0,d.jsx)(p,{...e}):t===null?(0,d.jsx)(`p`,{"data-slot":`diff-loading`,className:r(`px-1 text-xs text-soft-foreground`,e.className),children:`Loading diff…`}):(0,d.jsx)(t.View,{...e})}function p({files:e,wrap:t=!1,imageSrc:n,onOpenInApp:i,viewRef:o,className:c}){let f={adds:e.reduce((e,t)=>e+t.adds,0),dels:e.reduce((e,t)=>e+t.dels,0),files:e.length},p=(0,u.useRef)(null);return(0,u.useImperativeHandle)(o,()=>({scrollToPath:e=>{for(let t of p.current?.querySelectorAll(`[data-slot="diff-file"]`)??[])if(t.dataset.path===e){let e=l(t);e&&s(e,t,Number.parseFloat(getComputedStyle(t).scrollMarginTop)||0);return}}})),(0,d.jsxs)(`div`,{ref:p,"data-slot":`diff`,"data-fallback":`true`,className:r(`flex min-w-0 flex-col gap-3`,c),children:[(0,d.jsxs)(`p`,{"data-slot":`diff-totals`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,d.jsxs)(`span`,{children:[f.files,` `,f.files===1?`file`:`files`,` changed`]}),(0,d.jsx)(a,{stat:f})]}),e.map(e=>(0,d.jsx)(m,{file:e,wrap:t,imageSrc:n,onOpenInApp:i},`${e.oldPath??``}→${e.path}`))]})}function m({file:e,wrap:t,imageSrc:n,onOpenInApp:i}){return(0,d.jsxs)(`section`,{"data-slot":`diff-file`,"data-path":e.path,className:`min-w-0 scroll-mt-[var(--diff-sticky-top,0px)] overflow-clip rounded-md border border-border bg-card`,children:[(0,d.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-border/50 px-3 py-2`,children:[(0,d.jsx)(`span`,{"data-slot":`diff-file-path`,className:`min-w-0 truncate font-mono text-xs font-medium`,children:e.oldPath?`${e.oldPath} → ${e.path}`:e.path}),(0,d.jsx)(`span`,{className:`ml-auto shrink-0`,children:(0,d.jsx)(a,{stat:{adds:e.adds,dels:e.dels,files:1},className:`text-[11px]`})})]}),o(e)?(0,d.jsx)(c,{file:e,imageSrc:n,onOpenInApp:i}):e.binary?(0,d.jsx)(`p`,{className:`px-4 py-2.5 text-xs text-soft-foreground`,children:`Binary file — no text diff.`}):e.patch===``?(0,d.jsx)(`p`,{className:`px-4 py-2.5 text-xs text-soft-foreground`,children:`No content changes (metadata only).`}):(0,d.jsx)(`pre`,{className:r(`py-2 font-mono text-xs leading-[1.7]`,t?`break-words whitespace-pre-wrap`:`overflow-x-auto whitespace-pre`),children:e.patch.split(`
|
|
3
3
|
`).map((e,t)=>(0,d.jsxs)(`span`,{className:r(`block px-4`,e.startsWith(`+`)&&!e.startsWith(`+++`)&&`bg-diff-add`,e.startsWith(`-`)&&!e.startsWith(`---`)&&`bg-diff-del`,e.startsWith(`@@`)&&`text-soft-foreground`),children:[e,e===``?` `:``]},t))})]})}export{f as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{F as r,r as i,t as a}from"./button-Cz2i1VWG.js";import{t as o}from"./chevron-right-qEQMQjVX.js";import{r as s,t as c}from"./use-submit-shortcut-Ct5pt-M6.js";import{t as l}from"./diff-stat-CHeIoBxd.js";import{o as u}from"./chunk-BO2N2NFS-MDrqQfMl.js";import{a as d,i as f,r as p,t as m}from"./markdown-CWuKlrA3.js";import{R as h}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{F as r,r as i,t as a}from"./button-Cz2i1VWG.js";import{t as o}from"./chevron-right-qEQMQjVX.js";import{r as s,t as c}from"./use-submit-shortcut-Ct5pt-M6.js";import{t as l}from"./diff-stat-CHeIoBxd.js";import{o as u}from"./chunk-BO2N2NFS-MDrqQfMl.js";import{a as d,i as f,r as p,t as m}from"./markdown-CWuKlrA3.js";import{R as h}from"./index-DUhrduZ3.js";import{t as g}from"./lib-BQXq3kEf.js";import{n as _,t as v}from"./markdown-Bxdits01.js";import{i as ee,n as y,r as te,t as b}from"./scroll-within-c541dNeG.js";import{n as x,t as ne}from"./types-BTlmexWF.js";var S=r(`message-square-off`,[[`path`,{d:`M19 19H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.7.7 0 0 1 2 21.286V5a2 2 0 0 1 1.184-1.826`,key:`1wyg69`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.656 3H20a2 2 0 0 1 2 2v11.344`,key:`mhl4k6`}]]),C=e(t(),1),w=44;function T(e){if(e.binary===!0||e.patch===``)return 1;let t=e.patch.split(`
|
|
2
2
|
`),n=t.findIndex(e=>e.startsWith(`@@`));return n===-1?t.length:t.length-n}function re(e){return T(e)*20+w}function ie(e){return e.reduce((e,t)=>e+T(t),0)}function ae(e,t){let n=new URLSearchParams(e).get(`diff`);return n===`flat`||n===`virtual`?n:t>1500?`virtual`:`flat`}function E(e){return`${e.oldPath??``}→${e.path}`}function D(e){let t=0;for(let n of e.split(`
|
|
3
3
|
`))n.length>t&&(t=n.length);return t}var O=/[A-Za-z0-9_]+|\s+|[^\sA-Za-z0-9_]+/g,k=300,A=.3;function j(e,t){if(e===t)return null;let n=e.match(O)??[],r=t.match(O)??[];if(n.length===0||r.length===0||n.length>k||r.length>k)return null;let i=r.length+1,a=new Uint16Array((n.length+1)*i);for(let e=1;e<=n.length;e++)for(let t=1;t<=r.length;t++)a[e*i+t]=n[e-1]===r[t-1]?(a[(e-1)*i+(t-1)]??0)+1:Math.max(a[(e-1)*i+t]??0,a[e*i+(t-1)]??0);if((a[n.length*i+r.length]??0)/Math.max(n.length,r.length)<A)return null;let o=Array(n.length).fill(!1),s=Array(r.length).fill(!1),c=n.length,l=r.length;for(;c>0&&l>0;)n[c-1]===r[l-1]?(o[c-1]=!0,s[l-1]=!0,c--,l--):(a[(c-1)*i+l]??0)>=(a[c*i+(l-1)]??0)?c--:l--;return{del:M(n,o),add:M(r,s)}}function M(e,t){let n=[];return e.forEach((e,r)=>{let i=!(t[r]??!1),a=n[n.length-1];a&&a.changed===i?a.text+=e:n.push({text:e,changed:i})}),n}function N(e,t,n){if(!t||t.length===0)return e?e.map(e=>({text:e.content,color:e.color,changed:!1})):n===``?[]:[{text:n,changed:!1}];if(!e||e.length===0)return t.map(e=>({text:e.text,changed:e.changed}));let r=[],i=0,a=0,o=0,s=0;for(;i<e.length&&o<t.length;){let n=e[i],c=t[o],l=n.content.length-a,u=c.text.length-s,d=Math.min(l,u);d>0&&(r.push({text:n.content.slice(a,a+d),color:n.color,changed:c.changed}),a+=d,s+=d),n.content.length-a<=0&&(i++,a=0),c.text.length-s<=0&&(o++,s=0)}for(;i<e.length;){let t=e[i],n=t.content.slice(a);n!==``&&r.push({text:n,color:t.color,changed:!1}),i++,a=0}return r}var P=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/,F=`… (patch truncated)`;function I(e){let t=[],n=!1,r=null,i=0,a=0,o=e.split(`
|
|
4
4
|
`);o.at(-1)===``&&o.pop();for(let e of o){let o=P.exec(e);if(o){r={header:e,oldStart:Number(o[1]),oldCount:o[2]===void 0?1:Number(o[2]),newStart:Number(o[3]),newCount:o[4]===void 0?1:Number(o[4]),lines:[]},i=r.oldStart,a=r.newStart,t.push(r);continue}if(e.includes(F)){n=!0,r=null;continue}r&&(e.startsWith(`+`)?r.lines.push({kind:`add`,text:e.slice(1),newLine:a++}):e.startsWith(`-`)?r.lines.push({kind:`del`,text:e.slice(1),oldLine:i++}):e.startsWith(`\\`)||r.lines.push({kind:`context`,text:e.slice(1),oldLine:i++,newLine:a++}))}return{hunks:t,truncated:n}}function L(e,t=!1){let n=[],r=e[0];if(!r)return n;r.newStart>1&&n.push({beforeHunk:0,count:r.newStart-1,oldStart:1,newStart:1});for(let t=1;t<e.length;t++){let r=e[t-1],i=e[t],a=r.oldStart+r.oldCount,o=r.newStart+r.newCount,s=i.newStart-o;s>0&&n.push({beforeHunk:t,count:s,oldStart:a,newStart:o})}if(t){let t=e[e.length-1];n.push({beforeHunk:e.length,oldStart:t.oldStart+t.oldCount,newStart:t.newStart+t.newCount})}return n}function oe(e,t){let n=e.count===void 0?t.length:e.newStart+e.count-1,r=e.oldStart-e.newStart,i=[];for(let a=e.newStart;a<=Math.min(n,t.length);a++)i.push({kind:`context`,text:t[a-1]??``,oldLine:a+r,newLine:a});return i}function se(e,t){let n=Array(e.length),r=Array(t.length),i=Math.min(e.length,t.length);for(let a=0;a<i;a++){let i=j(e[a].text,t[a].text);i&&(n[a]=i.del,r[a]=i.add)}return{dels:e,adds:t,delSpans:n,addSpans:r}}function R(e,t,n){let r=0;for(;r<e.lines.length;){let i=e.lines[r];if(i.kind===`del`||i.kind===`add`){let t=[],i=[];for(;r<e.lines.length&&e.lines[r].kind===`del`;)t.push(e.lines[r++]);for(;r<e.lines.length&&e.lines[r].kind===`add`;)i.push(e.lines[r++]);n(se(t,i))}else t(i),r++}}function z(e,t=[],n){let r=new Map(t.map(e=>[e.beforeHunk,e])),i=[],a=e=>{let t=r.get(e);if(!t)return;let a=n?.get(e);if(a)for(let e of a)i.push({type:`line`,cell:{line:e}});else i.push({type:`gap`,gap:t})};return e.forEach((e,t)=>{a(t),i.push({type:`hunk`,hunk:e}),R(e,e=>i.push({type:`line`,cell:{line:e}}),e=>{e.dels.forEach((t,n)=>i.push({type:`line`,cell:{line:t,spans:e.delSpans[n]}})),e.adds.forEach((t,n)=>i.push({type:`line`,cell:{line:t,spans:e.addSpans[n]}}))})}),a(e.length),i}function B(e,t=[],n){let r=new Map(t.map(e=>[e.beforeHunk,e])),i=[],a=e=>{let t=r.get(e);if(!t)return;let a=n?.get(e);if(a)for(let e of a)i.push({type:`pair`,left:{line:e},right:{line:e}});else i.push({type:`gap`,gap:t})};return e.forEach((e,t)=>{a(t),i.push({type:`hunk`,hunk:e}),R(e,e=>i.push({type:`pair`,left:{line:e},right:{line:e}}),e=>{let t=Math.max(e.dels.length,e.adds.length);for(let n=0;n<t;n++){let t=e.dels[n],r=e.adds[n];i.push({type:`pair`,...t?{left:{line:t,spans:e.delSpans[n]}}:{},...r?{right:{line:r,spans:e.addSpans[n]}}:{}})}})}),a(e.length),i}var V=n();function H({file:e,loadFileText:t,imageSrc:n}){let r=(0,C.useMemo)(()=>U(e),[e]),i=(0,C.useRef)(t);i.current=t;let a=t!==void 0,[o,s]=(0,C.useState)(null);(0,C.useEffect)(()=>{let t=i.current;if(!t)return;let n=!1;return t(e.path).then(t=>!n&&s({path:e.path,text:t}),()=>!n&&s({path:e.path,text:null})),()=>{n=!0}},[e.path,e.patch,a]);let c=(0,C.useRef)(n);c.current=n;let l=(0,C.useMemo)(()=>le(e.path,e=>c.current?.(e)),[e.path]),u=o?.path===e.path?o:null;if(a&&u===null)return(0,V.jsx)(`p`,{className:`px-4 py-2.5 text-xs text-soft-foreground`,children:`Loading preview…`});let d=u?.text??null;return(0,V.jsxs)(`div`,{"data-slot":`diff-markdown-preview`,className:`px-6 py-6`,children:[d===null&&!r.complete?(0,V.jsx)(`p`,{className:`mx-auto mb-4 max-w-[72ch] text-xs text-soft-foreground`,children:`Showing the changed sections only.`}):null,(0,V.jsx)(m,{variant:`document`,urlTransform:l,children:d??r.text})]})}function U(e){let t=I(e.patch);return{text:t.hunks.map(e=>e.lines.filter(e=>e.kind!==`del`).map(e=>e.text).join(`
|