specrails-desktop 2.26.0 → 2.26.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.
Files changed (91) hide show
  1. package/client/dist/assets/{ActivityFeedPage-1eXnoNAo.js → ActivityFeedPage-bDe4VitF.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-BHW_6Vm0.js → AgentBrowserCapture-DQyeEm2V.js} +1 -1
  3. package/client/dist/assets/{AgentModeCodePane-C89SAJzI.js → AgentModeCodePane-Ci39DcOo.js} +2 -2
  4. package/client/dist/assets/{AgentModeJobsPane-BG_4r4Dm.js → AgentModeJobsPane-C-g1WNVG.js} +1 -1
  5. package/client/dist/assets/{AgentsPage-BrkWfc9s.js → AgentsPage-BWgglK7V.js} +3 -3
  6. package/client/dist/assets/{AnalyticsPage-CMZRUPrT.js → AnalyticsPage-Da21wWWw.js} +1 -1
  7. package/client/dist/assets/{BarChart-BtF3zJHa.js → BarChart-BiLTq3uC.js} +1 -1
  8. package/client/dist/assets/{CodePage-Cime5FRs.js → CodePage-BUcAp7SC.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-CSKHSBBF.js → DesktopAnalyticsPage-COkzgMmd.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-ClTq6Fzj.js → DocsDialog-PZHMN18B.js} +1 -1
  11. package/client/dist/assets/{DocsPage-DTxfOpTu.js → DocsPage-D3fChfkj.js} +1 -1
  12. package/client/dist/assets/{ExportDropdown-Ho9zdPvK.js → ExportDropdown-DDhJH-Jr.js} +1 -1
  13. package/client/dist/assets/{IntegrationsPage-DWNyo6jk.js → IntegrationsPage-F87uxxVH.js} +1 -1
  14. package/client/dist/assets/{InteractiveJobComposer-CYxXOKld.js → InteractiveJobComposer-DqDCiCa0.js} +5 -5
  15. package/client/dist/assets/{JobDetailModal-DrNafHY5.js → JobDetailModal-BWJR60fi.js} +1 -1
  16. package/client/dist/assets/{JobDetailPage-4VKw33GW.js → JobDetailPage-CjWE_jyd.js} +1 -1
  17. package/client/dist/assets/{JobsPage-cFr6wWaH.js → JobsPage-LmnXkyCa.js} +1 -1
  18. package/client/dist/assets/{LoopBuilderPage-Bk8zVvEX.js → LoopBuilderPage-DsLLrtHa.js} +2 -2
  19. package/client/dist/assets/{LoopPreviewModal-XFSO2Vcs.js → LoopPreviewModal-C-fDEgnu.js} +1 -1
  20. package/client/dist/assets/{LoopsPage-DWMwDj9g.js → LoopsPage-DDNO9h9T.js} +1 -1
  21. package/client/dist/assets/{ProjectSettingsDialog-DnSe_yWm.js → ProjectSettingsDialog-CX854C8e.js} +1 -1
  22. package/client/dist/assets/{TemplatePreviewModal-B30-TY_v.js → TemplatePreviewModal-DcHFbLA8.js} +1 -1
  23. package/client/dist/assets/agent-BI6vr-To.js +1 -0
  24. package/client/dist/assets/{agent-D5QNn9np2.js → agent-BUGXI3Ok2.js} +1 -1
  25. package/client/dist/assets/agent-Bph_-xt7.js +1 -0
  26. package/client/dist/assets/agent-Bvy2Csyd.js +1 -0
  27. package/client/dist/assets/{agent-DgFoLgrF2.js → agent-Bwkyg2oX2.js} +1 -1
  28. package/client/dist/assets/agent-CLCyDaZh.js +1 -0
  29. package/client/dist/assets/{agent-6mhkV25_2.js → agent-Cqs14QMr2.js} +1 -1
  30. package/client/dist/assets/{agent-CRYdi9-t.js → agent-DJ0EBUuP.js} +1 -1
  31. package/client/dist/assets/{brain-DcXkQwzO.js → brain-BBNUUrUI.js} +1 -1
  32. package/client/dist/assets/dashboard-BjjS1OrL.js +1 -0
  33. package/client/dist/assets/dashboard-Bk6oSk1H2.js +1 -0
  34. package/client/dist/assets/dashboard-BrH-GdOg2.js +1 -0
  35. package/client/dist/assets/dashboard-BurhUI8_.js +1 -0
  36. package/client/dist/assets/dashboard-C6w0rICe.js +1 -0
  37. package/client/dist/assets/dashboard-CAUnfDQL2.js +1 -0
  38. package/client/dist/assets/dashboard-C_ljpeYO.js +1 -0
  39. package/client/dist/assets/dashboard-D6OqDdj6.js +1 -0
  40. package/client/dist/assets/{dist-js-BAWwLSIj.js → dist-js-BxjTIvdT.js} +1 -1
  41. package/client/dist/assets/{dist-js-6U6hyD6z.js → dist-js-DdP_Gl3p.js} +1 -1
  42. package/client/dist/assets/{index-cvOunQkD.css → index-C695aPdV.css} +1 -1
  43. package/client/dist/assets/index-Dw1N2-ci.js +156 -0
  44. package/client/dist/assets/{lib-Bsny0zZp.js → lib-BviHZ_gK.js} +1 -1
  45. package/client/dist/assets/{settings-DHd1lQ1k.js → settings-BHdPchJP.js} +1 -1
  46. package/client/dist/assets/{settings-FJXpJ3k92.js → settings-BeCczBFS2.js} +1 -1
  47. package/client/dist/assets/{settings-BWIf3vv4.js → settings-BlLi719f.js} +1 -1
  48. package/client/dist/assets/{settings-DTYQ5COE.js → settings-C_nY14Yz.js} +1 -1
  49. package/client/dist/assets/{settings-DE8t6aYv.js → settings-CaZ26a0S.js} +1 -1
  50. package/client/dist/assets/{settings-Dgv_q4qf2.js → settings-D54_cgl12.js} +1 -1
  51. package/client/dist/assets/{settings-DXgPh9-k.js → settings-D9bDDe2O.js} +1 -1
  52. package/client/dist/assets/{settings-BhuXe7ek2.js → settings-cn0tbve62.js} +1 -1
  53. package/client/dist/assets/{setup-iY8vH8pB.js → setup-7J8TjG4O.js} +1 -1
  54. package/client/dist/assets/{setup-D674kWQH.js → setup-BXpw07r-.js} +1 -1
  55. package/client/dist/assets/{setup-B590KsTX.js → setup-BiduSX9d.js} +1 -1
  56. package/client/dist/assets/{setup-cnqZsQSX2.js → setup-BuQNKztt2.js} +1 -1
  57. package/client/dist/assets/{setup-CEj6uY3-2.js → setup-BwMovM9z2.js} +1 -1
  58. package/client/dist/assets/{setup-BkyGoby6.js → setup-D84y3wx-.js} +1 -1
  59. package/client/dist/assets/{setup-CbIerFGf2.js → setup-DU0ULX8q2.js} +1 -1
  60. package/client/dist/assets/{setup-VNqXyB6Y.js → setup-RiUHzq7E.js} +1 -1
  61. package/client/dist/assets/{upload-49vX83IZ.js → upload-CRuuzzvp.js} +1 -1
  62. package/client/dist/assets/{value-Bo8EiTZE.js → value-CIr5hDMt.js} +1 -1
  63. package/client/dist/index.html +21 -8
  64. package/package.json +1 -1
  65. package/server/dist/agent-operator-prompt.js +45 -5
  66. package/server/dist/desktop-router.js +9 -2
  67. package/server/dist/mcp/guide.js +33 -4
  68. package/server/dist/mcp/tools/app-settings.js +18 -2
  69. package/server/dist/mcp/tools/catalog.js +2 -0
  70. package/server/dist/mcp/tools/rails.js +27 -6
  71. package/server/dist/mcp/tools/support.js +324 -0
  72. package/server/dist/pr-publisher.js +17 -15
  73. package/server/dist/project-git.js +57 -0
  74. package/server/dist/rail-isolated-launch.js +27 -3
  75. package/server/dist/rail-pr-decision.js +69 -1
  76. package/server/dist/rail-worktree-release.js +25 -0
  77. package/server/dist/rail-worktrees-store.js +2 -2
  78. package/server/dist/rails-router.js +136 -7
  79. package/client/dist/assets/agent-BZqfQhI_.js +0 -1
  80. package/client/dist/assets/agent-Bjy1SlT5.js +0 -1
  81. package/client/dist/assets/agent-Bn6ZmjHj.js +0 -1
  82. package/client/dist/assets/agent-DgwPsxWQ.js +0 -1
  83. package/client/dist/assets/dashboard-CuGuy2__2.js +0 -1
  84. package/client/dist/assets/dashboard-CxP3TZ3I2.js +0 -1
  85. package/client/dist/assets/dashboard-DWHVfP7U.js +0 -1
  86. package/client/dist/assets/dashboard-D_Pgs6QH2.js +0 -1
  87. package/client/dist/assets/dashboard-Dwnssayh.js +0 -1
  88. package/client/dist/assets/dashboard-S_pT1yxN.js +0 -1
  89. package/client/dist/assets/dashboard-tCxOFOxx.js +0 -1
  90. package/client/dist/assets/dashboard-zefbBNyG.js +0 -1
  91. package/client/dist/assets/index-DnkfABxY.js +0 -156
@@ -1,3 +1,3 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Bn as t,Cn as n,Et as r,G as i,K as a,Kn as o,Ln as s,Pt as c,Q as l,Rn as u,Sn as d,U as f,W as p,X as m,Xt as h,Y as g,Z as _,_n as v,c as y,ct as b,lt as x,nn as S,nt as C,tn as w,vn as T,wn as E,wt as D,yn as O}from"./index-DnkfABxY.js";var k=e(o(),1),A=n(),j=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],M={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function N({state:e,onChanged:t}){let{t:n}=u(`jira`),r=e.connection,[i,a]=(0,k.useState)(r.enabled),[o,c]=(0,k.useState)(!1),[l,d]=(0,k.useState)(!1),[p,m]=(0,k.useState)([]),[h,g]=(0,k.useState)([]),[_,v]=(0,k.useState)(r.discardStatus??``),[y,b]=(0,k.useState)(r.statusMap??{}),x=e.outbox??{pending:0,inflight:0,done:0,dead:0},S=(0,k.useCallback)(async()=>{try{let{ops:e}=await f.listOutbox(`dead`);m(e)}catch{m([])}},[]);(0,k.useEffect)(()=>{S()},[S]),(0,k.useEffect)(()=>{let e=!1;return f.listStatuses().then(({statuses:t})=>{e||g(t)}).catch(()=>{e||g([])}),()=>{e=!0}},[]);async function w(e){let r=_;v(e);try{await f.patchConnection({discardStatus:e||null}),t()}catch(e){v(r),s.error(F(e,n))}}async function T(e,r){let i=y,a={...y,[e]:r||void 0};b(a);let o=Object.fromEntries(Object.entries(a).filter(([,e])=>e));try{await f.patchConnection({statusMap:Object.keys(o).length?o:null}),t()}catch(e){b(i),s.error(F(e,n))}}async function E(){let e=!i;a(e),d(!0);try{await f.setEnabled(e)}catch(t){a(!e),s.error(F(t,n))}finally{d(!1)}}async function D(){c(!0);try{let e=await f.syncNow();s.success(n(`status.syncedToast`,{count:e.upserted}))}catch(e){s.error(F(e,n))}finally{c(!1)}}async function O(){if(window.confirm(n(`status.disconnectConfirm`))){d(!0);try{await f.disconnect(),s.success(n(`status.disconnectedToast`)),t()}catch(e){s.error(F(e,n))}finally{d(!1)}}}async function N(e){try{await f.retryOutbox(e),await S()}catch(e){s.error(F(e,n))}}let I=x.pending+x.inflight;return(0,A.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:n(`status.connected`,{key:r.jiraProjectKey})}),(0,A.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[r.baseUrl,` · `,r.deployment===`cloud`?n(`review.cloud`):n(`review.dc`)]})]}),(0,A.jsx)(`a`,{href:`${r.baseUrl}/browse/${r.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:n(`badge.openInJira`)})]}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`status.enabledLabel`)}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(i?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,A.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":n(`status.enabledLabel`),disabled:l,onClick:E,className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${i?`bg-accent-success`:`bg-input`}`,children:(0,A.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${i?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`wizard.step3Title`)}),(0,A.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:n(`mapping.intro`)}),(0,A.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,A.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,A.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`mapping.${M[e]}`)}),(0,A.jsxs)(`select`,{value:y[e]??``,onChange:t=>void T(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,A.jsx)(`option`,{value:``,children:n(`mapping.auto`)}),h.map(e=>(0,A.jsx)(`option`,{value:e.name,children:e.name},e.id)),y[e]&&!h.some(t=>t.name===y[e])&&(0,A.jsx)(`option`,{value:y[e],children:y[e]})]})]},e))})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`discard.configLabel`)}),(0,A.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:n(`discard.configHelp`)}),(0,A.jsxs)(`select`,{value:_,onChange:e=>void w(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,A.jsx)(`option`,{value:``,children:n(`discard.configNone`)}),h.map(e=>(0,A.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,A.jsx)(`option`,{value:_,children:_})]})]}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(C,{variant:`outline`,size:`sm`,onClick:D,disabled:o,children:n(o?`status.syncing`:`status.syncNow`)}),(0,A.jsx)(C,{variant:`ghost`,size:`sm`,onClick:O,disabled:l,className:`text-destructive`,children:n(`status.disconnect`)})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`outbox.title`)}),x.dead>0?(0,A.jsx)(`p`,{className:`mt-1 text-xs text-accent-warning`,children:n(`outbox.dead`,{count:x.dead})}):I>0?(0,A.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`outbox.pending`,{count:I})}):(0,A.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`outbox.allSynced`)}),p.length>0&&(0,A.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`outbox.deadHelp`)}),p.map(e=>(0,A.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border border-border/60 px-2 py-1`,children:[(0,A.jsxs)(`span`,{className:`truncate text-xs`,children:[P(e,n),` · `,e.deadReason??e.lastError??``]}),(0,A.jsx)(C,{variant:`outline`,size:`sm`,onClick:()=>N(e.id),children:n(`outbox.retry`)})]},e.id))]})]})]})}function P(e,t){return e.opType===`transition`?t(`outbox.opTransition`):e.opType===`comment`?t(`outbox.opComment`):t(`outbox.opCreate`)}function F(e,t){return e instanceof Error?e.message:t(`errors.generic`)}function I({activeProjectId:e}){let{t}=u(`integrations`),[n,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(!0),[l,d]=(0,k.useState)(!1),[h,_]=(0,k.useState)(!1),v=(0,k.useCallback)(async()=>{try{o(await f.getConnection())}catch{o({connected:!1})}finally{c(!1)}},[]);if((0,k.useEffect)(()=>{!p||!e||(c(!0),v())},[e,v]),!p)return null;let b=!!(n?.connected&&n.connection);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 flex flex-col gap-3 h-full`,"data-testid":`jira-integration-card`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,A.jsx)(`div`,{className:`grid place-items-center w-9 h-9 rounded-md bg-accent-info/15 text-accent-info shrink-0`,children:(0,A.jsx)(r,{className:`w-4 h-4`})}),(0,A.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`jiraCard.title`)}),b&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success flex items-center gap-1`,"data-testid":`jira-connected-badge`,children:[(0,A.jsx)(S,{className:`w-3 h-3`}),` `,t(`jiraCard.connected`)]})]}),(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t(`jiraCard.category`)})]})]}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:b&&n?.connection?t(`jiraCard.connectedDescription`,{key:n.connection.jiraProjectKey}):t(`jiraCard.description`)}),(0,A.jsxs)(`ul`,{className:`text-xs space-y-1 list-disc pl-4 text-foreground/80`,children:[(0,A.jsx)(`li`,{children:t(`jiraCard.bullet1`)}),(0,A.jsx)(`li`,{children:t(`jiraCard.bullet2`)}),(0,A.jsx)(`li`,{children:t(`jiraCard.bullet3`)})]}),(0,A.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`jiraCard.requires`)}),(0,A.jsx)(`div`,{className:`mt-auto pt-2 flex items-center justify-end gap-2`,children:s?(0,A.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):b?(0,A.jsx)(`button`,{type:`button`,onClick:()=>_(!0),"data-testid":`jira-manage-btn`,className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-muted/30 inline-flex items-center gap-1.5`,children:t(`jiraCard.manage`)}):(0,A.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`jira-connect-btn`,className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white hover:opacity-90 inline-flex items-center gap-1.5`,children:[(0,A.jsx)(r,{className:`w-3.5 h-3.5`}),t(`jiraCard.connect`)]})}),(0,A.jsx)(i,{open:l,onOpenChange:d,children:(0,A.jsxs)(a,{className:`max-w-lg`,children:[(0,A.jsx)(g,{children:(0,A.jsx)(m,{children:t(`jiraCard.modalTitle`)})}),(0,A.jsx)(y,{onConnected:()=>{d(!1),v()},onSkip:()=>d(!1)})]})}),(0,A.jsx)(i,{open:h,onOpenChange:_,children:(0,A.jsxs)(a,{className:`max-w-lg`,children:[(0,A.jsx)(g,{children:(0,A.jsx)(m,{children:t(`jiraCard.manageTitle`)})}),n?.connected&&n.connection&&(0,A.jsx)(N,{state:n,onChanged:()=>{v().then(()=>_(!1))}})]})})]})}function L(){let{t:e}=u(`integrations`),{activeProjectId:t,projects:n}=T(),r=n.find(e=>e.id===t),i=r?v(r).includes(`claude`):!0,{registerHandler:a,unregisterHandler:o}=d(),s=(0,k.useRef)(t);(0,k.useEffect)(()=>{s.current=t},[t]);let[c,l]=(0,k.useState)(null),[f,m]=(0,k.useState)(null),{data:h,isLoading:g,isFirstLoad:_,refresh:y}=O({namespace:`plugins`,projectId:t,initialValue:[],fetcher:(0,k.useCallback)(async()=>{let e=await fetch(`${E()}/plugins`);if(!e.ok)throw Error(`HTTP ${e.status}`);return(await e.json()).plugins??[]},[])});(0,k.useEffect)(()=>(a(`integrations-page`,e=>{let t=e;t.type&&(t.projectId&&t.projectId!==s.current||t.type.startsWith(`plugin.`)&&y())}),()=>o(`integrations-page`)),[a,o,y]),(0,k.useEffect)(()=>{l(!g&&!h?`Failed to load plugins`:null)},[g,h]);let x=(0,k.useMemo)(()=>(h??[]).filter(e=>e.status!==`orphan`),[h]),S=(0,k.useMemo)(()=>(h??[]).filter(e=>e.status===`orphan`),[h]);return t?(0,A.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,A.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border px-6 pt-4 pb-3 flex items-center gap-2`,children:[(0,A.jsx)(D,{className:`w-4 h-4 text-accent-primary`}),(0,A.jsxs)(`div`,{className:`flex-1`,children:[(0,A.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]})]}),(0,A.jsx)(`div`,{className:`flex-1 overflow-auto p-6`,children:_&&g?(0,A.jsx)(q,{}):c&&i?(0,A.jsx)(J,{onRetry:y}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:[(0,A.jsx)(I,{activeProjectId:t}),i&&x.map(e=>(0,A.jsx)(R,{plugin:e,isInstalling:f===e.name,onInstall:()=>m(e.name),onCloseInstall:()=>{m(null),y()}},e.name))]}),i&&S.length>0&&(0,A.jsxs)(`div`,{className:`mt-10`,children:[(0,A.jsxs)(`h2`,{className:`text-sm font-semibold text-muted-foreground mb-3 flex items-center gap-2`,children:[(0,A.jsx)(b,{className:`w-3.5 h-3.5`}),` `,e(`page.deprecated`)]}),(0,A.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:S.map(e=>(0,A.jsx)(U,{plugin:e,onRemoved:y},e.name))})]}),!p&&(!i||x.length===0)&&(0,A.jsx)(Y,{})]})})]}):(0,A.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground text-sm`,children:e(`page.selectProject`)})}function R({plugin:e,isInstalling:n,onInstall:r,onCloseInstall:i}){let{t:a}=u(`integrations`),[o,s]=(0,k.useState)(!1);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 flex flex-col gap-3 h-full`,children:[(0,A.jsx)(`div`,{className:`flex items-start gap-2`,children:(0,A.jsxs)(`div`,{className:`flex-1`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`v`,e.version]}),e.status===`installed`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success flex items-center gap-1`,children:[(0,A.jsx)(S,{className:`w-3 h-3`}),` `,a(`card.statusActive`)]}),e.status===`deactivated`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground flex items-center gap-1`,children:[(0,A.jsx)(w,{className:`w-3 h-3`}),` `,a(`card.statusDeactivated`)]}),e.status===`degraded`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-warning/20 text-accent-warning flex items-center gap-1`,children:[(0,A.jsx)(b,{className:`w-3 h-3`}),` `,a(`card.statusDegraded`)]}),e.updateAvailable&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/20 text-accent-info flex items-center gap-1`,children:[(0,A.jsx)(h,{className:`w-3 h-3`}),` `,a(`card.updateAvailable`)]})]}),e.category&&(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),e.whatItDoes.length>0&&(0,A.jsx)(`ul`,{className:`text-xs space-y-1 list-disc pl-4 text-foreground/80`,children:e.whatItDoes.map((e,t)=>(0,A.jsx)(`li`,{children:e},t))}),e.requirements.length>0&&(0,A.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:a(`card.requires`,{list:e.requirements.map(e=>`${e.name}${e.minVersion?` ≥ ${e.minVersion}`:``}`).join(`, `)})}),e.healthReason&&e.status===`degraded`&&(0,A.jsx)(`div`,{className:`text-[11px] text-accent-warning`,children:e.healthReason}),e.status===`deactivated`&&(0,A.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-relaxed`,children:(0,A.jsx)(t,{t:a,i18nKey:`card.deactivatedHint`,components:{strong:(0,A.jsx)(`strong`,{})}})}),e.marketplaceConflicts&&e.marketplaceConflicts.length>0&&(0,A.jsx)(H,{pluginName:e.name,conflicts:e.marketplaceConflicts}),e.marketplaceCachedButDisabled&&e.marketplaceCachedButDisabled.length>0&&(0,A.jsx)(B,{keys:e.marketplaceCachedButDisabled}),e.updateAvailable&&(0,A.jsx)(V,{pluginName:e.name}),(0,A.jsx)(`div`,{className:`mt-auto pt-2 flex items-center justify-end gap-2`,children:e.status===`not-installed`?(0,A.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white hover:opacity-90`,children:a(`card.install`)}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(z,{pluginName:e.name,active:e.status===`installed`}),(0,A.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-destructive/10 hover:text-destructive flex items-center gap-1.5`,children:[(0,A.jsx)(x,{className:`w-3 h-3`}),` `,a(`card.uninstall`)]})]})}),n&&(0,A.jsx)(W,{pluginName:e.name,onClose:i}),o&&(0,A.jsx)(G,{pluginName:e.name,onClose:()=>s(!1),onUninstalled:()=>{s(!1)}})]})}function z({pluginName:e,active:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(null);return(0,A.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,A.jsx)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0),o(null);try{let n=`${E()}/plugins/${e}/${t?`deactivate`:`activate`}`,r=await fetch(n,{method:`POST`});if(!r.ok)throw Error((await r.json()).error??`HTTP ${r.status}`)}catch(e){o(e.message)}finally{i(!1)}},role:`switch`,"aria-checked":t,className:`relative inline-flex items-center h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${t?`bg-accent-success`:`bg-muted`}`,title:n(t?`toggle.titleActive`:`toggle.titleDeactivated`),children:(0,A.jsx)(`span`,{className:`inline-block h-4 w-4 rounded-full bg-white shadow transition-transform ${t?`translate-x-4`:`translate-x-0.5`}`})}),(0,A.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(t?`card.statusActive`:`common:states.off`)}),a&&(0,A.jsx)(`span`,{className:`text-[10px] text-destructive`,children:a})]})}function B({keys:e}){let{t:n}=u(`integrations`);return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-2 leading-relaxed space-y-1`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(b,{className:`w-3 h-3 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:n,i18nKey:`cachedNotice.body`,components:{strong:(0,A.jsx)(`strong`,{}),code:(0,A.jsx)(`code`,{className:`bg-muted px-1 rounded`})}})})]}),(0,A.jsx)(`div`,{className:`pl-5 space-y-0.5`,children:e.map(e=>(0,A.jsxs)(`pre`,{className:`text-[10px] bg-muted/40 rounded px-1.5 py-0.5 inline-block font-mono`,children:[`/plugin uninstall `,e]},e))}),(0,A.jsx)(`div`,{className:`pl-5 text-[10px] text-muted-foreground`,children:n(`cachedNotice.runInstruction`)})]})}function V({pluginName:e}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(null);return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-accent-info/30 bg-accent-info/5 p-2 leading-relaxed space-y-1.5`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(h,{className:`w-3 h-3 text-accent-info mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:n,i18nKey:`update.body`,components:{code:(0,A.jsx)(`code`,{className:`bg-muted px-1 rounded`})}})})]}),(0,A.jsxs)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0),o(null);try{let t=await fetch(`${E()}/plugins/${e}/update`,{method:`POST`});if(!t.ok)throw Error((await t.json()).error??`HTTP ${t.status}`)}catch(e){o(e.message)}finally{i(!1)}},className:`text-[10px] px-2 py-0.5 rounded border border-accent-info/40 hover:bg-accent-info/10 disabled:opacity-50 flex items-center gap-1`,children:[r&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),(0,A.jsx)(t,{t:n,i18nKey:`update.button`,components:{code:(0,A.jsx)(`code`,{})}})]}),a&&(0,A.jsx)(`div`,{className:`text-destructive text-[10px]`,children:a})]})}function H({pluginName:e,conflicts:n}){let{t:r}=u(`integrations`),[i,a]=(0,k.useState)(null),[o,s]=(0,k.useState)(null),l=async e=>{a(e),s(null);try{let t=await fetch(`${E()}/plugins/_marketplace/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({key:e})});if(!t.ok)throw Error((await t.json()).error??`HTTP ${t.status}`)}catch(e){s(e.message)}finally{a(null)}};return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-2 leading-relaxed space-y-1.5`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(b,{className:`w-3 h-3 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:r,i18nKey:`conflict.body`,values:{name:e},components:{strong:(0,A.jsx)(`strong`,{})}})})]}),(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1`,children:n.map(e=>(0,A.jsxs)(`button`,{type:`button`,disabled:i===e,onClick:()=>l(e),className:`text-[10px] px-2 py-0.5 rounded border border-yellow-500/40 aurora-light:border-accent-warning/40 hover:bg-yellow-500/10 aurora-light:hover:bg-accent-warning/10 disabled:opacity-50 flex items-center gap-1`,children:[i===e&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),(0,A.jsx)(t,{t:r,i18nKey:`conflict.disableButton`,values:{key:e},components:{code:(0,A.jsx)(`code`,{})}})]},e))}),o&&(0,A.jsx)(`div`,{className:`text-destructive`,children:o})]})}function U({plugin:e,onRemoved:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-4 flex flex-col gap-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,A.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/15 text-yellow-500 aurora-light:text-accent-warning`,children:n(`orphan.badge`)})]}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,A.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,A.jsxs)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0);try{await fetch(`${E()}/plugins/${e.name}`,{method:`DELETE`}),t()}finally{i(!1)}},className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-destructive/10 hover:text-destructive flex items-center gap-1.5`,children:[(0,A.jsx)(x,{className:`w-3 h-3`}),` `,n(`orphan.removeButton`)]})})]})}function W({pluginName:e,onClose:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null),[s,l]=(0,k.useState)(!1),[f,p]=(0,k.useState)(null),[m,g]=(0,k.useState)([]),[_,v]=(0,k.useState)(null),[y,x]=(0,k.useState)([]),{registerHandler:C,unregisterHandler:T}=d(),D=(0,k.useCallback)(()=>{i(null),o(null),fetch(`${E()}/plugins/${e}/preview-install`).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>i(e)).catch(e=>o(e.message))},[e]);(0,k.useEffect)(()=>{D()},[D]),(0,k.useEffect)(()=>(C(`install-${e}`,t=>{let n=t;if(n.type===`plugin.install_progress`&&n.name===e&&n.line&&g(e=>[...e,n.line]),n.type===`plugin.prereq_install_progress`&&n.line&&x(e=>[...e,n.line]),n.type===`plugin.prereq_installed`){v(null);let e=n.reason;e&&x(t=>[...t,`► ${e}`]),n.ok&&D()}}),()=>T(`install-${e}`)),[e,C,T,D]);let O=async e=>{v(e),x([n(`installDialog.installingPrereq`,{name:e})]);try{await fetch(`${E()}/plugins/_prerequisites/${e}/install`,{method:`POST`})}catch(e){x(t=>[...t,n(`installDialog.prereqStartFailed`,{message:e.message})]),v(null)}},j=(r?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum);return(0,A.jsxs)(K,{onClose:t,title:n(`installDialog.title`,{name:e}),children:[a&&(0,A.jsx)(`div`,{className:`text-xs text-destructive`,children:a}),!r&&!a&&(0,A.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,A.jsx)(c,{className:`w-3 h-3 animate-spin`}),` `,n(`installDialog.computingChanges`)]}),r&&(0,A.jsxs)(A.Fragment,{children:[r.platformNote&&(0,A.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5 rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 text-[11px] leading-relaxed`,children:[(0,A.jsx)(b,{className:`w-3.5 h-3.5 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:r.platformNote})]}),(0,A.jsxs)(`section`,{children:[(0,A.jsx)(`h4`,{className:`text-xs font-semibold mb-1.5`,children:n(`installDialog.filesHeading`)}),(0,A.jsx)(`ul`,{className:`text-xs space-y-0.5 font-mono`,children:r.files.map((e,t)=>(0,A.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path,e.summary&&(0,A.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,e.summary]})]},t))})]}),r.requirements.length>0&&(0,A.jsxs)(`section`,{children:[(0,A.jsx)(`h4`,{className:`text-xs font-semibold mb-1.5`,children:n(`installDialog.prerequisites`)}),(0,A.jsx)(`ul`,{className:`text-xs space-y-1`,children:r.requirements.map(e=>{let t=e.installed&&e.executable&&e.meetsMinimum,r=e.name===`uv`;return(0,A.jsxs)(`li`,{className:`flex items-center gap-2`,children:[t?(0,A.jsx)(S,{className:`w-3 h-3 text-accent-success`}):(0,A.jsx)(w,{className:`w-3 h-3 text-accent-warning`}),(0,A.jsxs)(`span`,{children:[e.name,e.minVersion?` ≥ ${e.minVersion}`:``]}),e.version&&(0,A.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]}),!t&&r&&(0,A.jsxs)(`button`,{type:`button`,disabled:_===e.name,onClick:()=>O(e.name),className:`ml-auto text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted disabled:opacity-50 flex items-center gap-1`,children:[_===e.name&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),n(`installDialog.autoInstall`)]})]},e.name)})}),y.length>0&&(0,A.jsx)(`pre`,{className:`mt-2 text-[11px] bg-muted/40 rounded p-2 max-h-24 overflow-auto font-mono`,children:y.join(`
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Bn as t,Cn as n,Et as r,G as i,K as a,Kn as o,Ln as s,Pt as c,Q as l,Rn as u,Sn as d,U as f,W as p,X as m,Xt as h,Y as g,Z as _,_n as v,c as y,ct as b,lt as x,nn as S,nt as C,tn as w,vn as T,wn as E,wt as D,yn as O}from"./index-Dw1N2-ci.js";var k=e(o(),1),A=n(),j=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],M={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function N({state:e,onChanged:t}){let{t:n}=u(`jira`),r=e.connection,[i,a]=(0,k.useState)(r.enabled),[o,c]=(0,k.useState)(!1),[l,d]=(0,k.useState)(!1),[p,m]=(0,k.useState)([]),[h,g]=(0,k.useState)([]),[_,v]=(0,k.useState)(r.discardStatus??``),[y,b]=(0,k.useState)(r.statusMap??{}),x=e.outbox??{pending:0,inflight:0,done:0,dead:0},S=(0,k.useCallback)(async()=>{try{let{ops:e}=await f.listOutbox(`dead`);m(e)}catch{m([])}},[]);(0,k.useEffect)(()=>{S()},[S]),(0,k.useEffect)(()=>{let e=!1;return f.listStatuses().then(({statuses:t})=>{e||g(t)}).catch(()=>{e||g([])}),()=>{e=!0}},[]);async function w(e){let r=_;v(e);try{await f.patchConnection({discardStatus:e||null}),t()}catch(e){v(r),s.error(F(e,n))}}async function T(e,r){let i=y,a={...y,[e]:r||void 0};b(a);let o=Object.fromEntries(Object.entries(a).filter(([,e])=>e));try{await f.patchConnection({statusMap:Object.keys(o).length?o:null}),t()}catch(e){b(i),s.error(F(e,n))}}async function E(){let e=!i;a(e),d(!0);try{await f.setEnabled(e)}catch(t){a(!e),s.error(F(t,n))}finally{d(!1)}}async function D(){c(!0);try{let e=await f.syncNow();s.success(n(`status.syncedToast`,{count:e.upserted}))}catch(e){s.error(F(e,n))}finally{c(!1)}}async function O(){if(window.confirm(n(`status.disconnectConfirm`))){d(!0);try{await f.disconnect(),s.success(n(`status.disconnectedToast`)),t()}catch(e){s.error(F(e,n))}finally{d(!1)}}}async function N(e){try{await f.retryOutbox(e),await S()}catch(e){s.error(F(e,n))}}let I=x.pending+x.inflight;return(0,A.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:n(`status.connected`,{key:r.jiraProjectKey})}),(0,A.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[r.baseUrl,` · `,r.deployment===`cloud`?n(`review.cloud`):n(`review.dc`)]})]}),(0,A.jsx)(`a`,{href:`${r.baseUrl}/browse/${r.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:n(`badge.openInJira`)})]}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`status.enabledLabel`)}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(i?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,A.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":n(`status.enabledLabel`),disabled:l,onClick:E,className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${i?`bg-accent-success`:`bg-input`}`,children:(0,A.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${i?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`wizard.step3Title`)}),(0,A.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:n(`mapping.intro`)}),(0,A.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,A.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,A.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`mapping.${M[e]}`)}),(0,A.jsxs)(`select`,{value:y[e]??``,onChange:t=>void T(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,A.jsx)(`option`,{value:``,children:n(`mapping.auto`)}),h.map(e=>(0,A.jsx)(`option`,{value:e.name,children:e.name},e.id)),y[e]&&!h.some(t=>t.name===y[e])&&(0,A.jsx)(`option`,{value:y[e],children:y[e]})]})]},e))})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`discard.configLabel`)}),(0,A.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:n(`discard.configHelp`)}),(0,A.jsxs)(`select`,{value:_,onChange:e=>void w(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,A.jsx)(`option`,{value:``,children:n(`discard.configNone`)}),h.map(e=>(0,A.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,A.jsx)(`option`,{value:_,children:_})]})]}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(C,{variant:`outline`,size:`sm`,onClick:D,disabled:o,children:n(o?`status.syncing`:`status.syncNow`)}),(0,A.jsx)(C,{variant:`ghost`,size:`sm`,onClick:O,disabled:l,className:`text-destructive`,children:n(`status.disconnect`)})]}),(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium`,children:n(`outbox.title`)}),x.dead>0?(0,A.jsx)(`p`,{className:`mt-1 text-xs text-accent-warning`,children:n(`outbox.dead`,{count:x.dead})}):I>0?(0,A.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`outbox.pending`,{count:I})}):(0,A.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`outbox.allSynced`)}),p.length>0&&(0,A.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`outbox.deadHelp`)}),p.map(e=>(0,A.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border border-border/60 px-2 py-1`,children:[(0,A.jsxs)(`span`,{className:`truncate text-xs`,children:[P(e,n),` · `,e.deadReason??e.lastError??``]}),(0,A.jsx)(C,{variant:`outline`,size:`sm`,onClick:()=>N(e.id),children:n(`outbox.retry`)})]},e.id))]})]})]})}function P(e,t){return e.opType===`transition`?t(`outbox.opTransition`):e.opType===`comment`?t(`outbox.opComment`):t(`outbox.opCreate`)}function F(e,t){return e instanceof Error?e.message:t(`errors.generic`)}function I({activeProjectId:e}){let{t}=u(`integrations`),[n,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(!0),[l,d]=(0,k.useState)(!1),[h,_]=(0,k.useState)(!1),v=(0,k.useCallback)(async()=>{try{o(await f.getConnection())}catch{o({connected:!1})}finally{c(!1)}},[]);if((0,k.useEffect)(()=>{!p||!e||(c(!0),v())},[e,v]),!p)return null;let b=!!(n?.connected&&n.connection);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 flex flex-col gap-3 h-full`,"data-testid":`jira-integration-card`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,A.jsx)(`div`,{className:`grid place-items-center w-9 h-9 rounded-md bg-accent-info/15 text-accent-info shrink-0`,children:(0,A.jsx)(r,{className:`w-4 h-4`})}),(0,A.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`jiraCard.title`)}),b&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success flex items-center gap-1`,"data-testid":`jira-connected-badge`,children:[(0,A.jsx)(S,{className:`w-3 h-3`}),` `,t(`jiraCard.connected`)]})]}),(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t(`jiraCard.category`)})]})]}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:b&&n?.connection?t(`jiraCard.connectedDescription`,{key:n.connection.jiraProjectKey}):t(`jiraCard.description`)}),(0,A.jsxs)(`ul`,{className:`text-xs space-y-1 list-disc pl-4 text-foreground/80`,children:[(0,A.jsx)(`li`,{children:t(`jiraCard.bullet1`)}),(0,A.jsx)(`li`,{children:t(`jiraCard.bullet2`)}),(0,A.jsx)(`li`,{children:t(`jiraCard.bullet3`)})]}),(0,A.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`jiraCard.requires`)}),(0,A.jsx)(`div`,{className:`mt-auto pt-2 flex items-center justify-end gap-2`,children:s?(0,A.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):b?(0,A.jsx)(`button`,{type:`button`,onClick:()=>_(!0),"data-testid":`jira-manage-btn`,className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-muted/30 inline-flex items-center gap-1.5`,children:t(`jiraCard.manage`)}):(0,A.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`jira-connect-btn`,className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white hover:opacity-90 inline-flex items-center gap-1.5`,children:[(0,A.jsx)(r,{className:`w-3.5 h-3.5`}),t(`jiraCard.connect`)]})}),(0,A.jsx)(i,{open:l,onOpenChange:d,children:(0,A.jsxs)(a,{className:`max-w-lg`,children:[(0,A.jsx)(g,{children:(0,A.jsx)(m,{children:t(`jiraCard.modalTitle`)})}),(0,A.jsx)(y,{onConnected:()=>{d(!1),v()},onSkip:()=>d(!1)})]})}),(0,A.jsx)(i,{open:h,onOpenChange:_,children:(0,A.jsxs)(a,{className:`max-w-lg`,children:[(0,A.jsx)(g,{children:(0,A.jsx)(m,{children:t(`jiraCard.manageTitle`)})}),n?.connected&&n.connection&&(0,A.jsx)(N,{state:n,onChanged:()=>{v().then(()=>_(!1))}})]})})]})}function L(){let{t:e}=u(`integrations`),{activeProjectId:t,projects:n}=T(),r=n.find(e=>e.id===t),i=r?v(r).includes(`claude`):!0,{registerHandler:a,unregisterHandler:o}=d(),s=(0,k.useRef)(t);(0,k.useEffect)(()=>{s.current=t},[t]);let[c,l]=(0,k.useState)(null),[f,m]=(0,k.useState)(null),{data:h,isLoading:g,isFirstLoad:_,refresh:y}=O({namespace:`plugins`,projectId:t,initialValue:[],fetcher:(0,k.useCallback)(async()=>{let e=await fetch(`${E()}/plugins`);if(!e.ok)throw Error(`HTTP ${e.status}`);return(await e.json()).plugins??[]},[])});(0,k.useEffect)(()=>(a(`integrations-page`,e=>{let t=e;t.type&&(t.projectId&&t.projectId!==s.current||t.type.startsWith(`plugin.`)&&y())}),()=>o(`integrations-page`)),[a,o,y]),(0,k.useEffect)(()=>{l(!g&&!h?`Failed to load plugins`:null)},[g,h]);let x=(0,k.useMemo)(()=>(h??[]).filter(e=>e.status!==`orphan`),[h]),S=(0,k.useMemo)(()=>(h??[]).filter(e=>e.status===`orphan`),[h]);return t?(0,A.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,A.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border px-6 pt-4 pb-3 flex items-center gap-2`,children:[(0,A.jsx)(D,{className:`w-4 h-4 text-accent-primary`}),(0,A.jsxs)(`div`,{className:`flex-1`,children:[(0,A.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]})]}),(0,A.jsx)(`div`,{className:`flex-1 overflow-auto p-6`,children:_&&g?(0,A.jsx)(q,{}):c&&i?(0,A.jsx)(J,{onRetry:y}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:[(0,A.jsx)(I,{activeProjectId:t}),i&&x.map(e=>(0,A.jsx)(R,{plugin:e,isInstalling:f===e.name,onInstall:()=>m(e.name),onCloseInstall:()=>{m(null),y()}},e.name))]}),i&&S.length>0&&(0,A.jsxs)(`div`,{className:`mt-10`,children:[(0,A.jsxs)(`h2`,{className:`text-sm font-semibold text-muted-foreground mb-3 flex items-center gap-2`,children:[(0,A.jsx)(b,{className:`w-3.5 h-3.5`}),` `,e(`page.deprecated`)]}),(0,A.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:S.map(e=>(0,A.jsx)(U,{plugin:e,onRemoved:y},e.name))})]}),!p&&(!i||x.length===0)&&(0,A.jsx)(Y,{})]})})]}):(0,A.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground text-sm`,children:e(`page.selectProject`)})}function R({plugin:e,isInstalling:n,onInstall:r,onCloseInstall:i}){let{t:a}=u(`integrations`),[o,s]=(0,k.useState)(!1);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 flex flex-col gap-3 h-full`,children:[(0,A.jsx)(`div`,{className:`flex items-start gap-2`,children:(0,A.jsxs)(`div`,{className:`flex-1`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`v`,e.version]}),e.status===`installed`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success flex items-center gap-1`,children:[(0,A.jsx)(S,{className:`w-3 h-3`}),` `,a(`card.statusActive`)]}),e.status===`deactivated`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground flex items-center gap-1`,children:[(0,A.jsx)(w,{className:`w-3 h-3`}),` `,a(`card.statusDeactivated`)]}),e.status===`degraded`&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-warning/20 text-accent-warning flex items-center gap-1`,children:[(0,A.jsx)(b,{className:`w-3 h-3`}),` `,a(`card.statusDegraded`)]}),e.updateAvailable&&(0,A.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/20 text-accent-info flex items-center gap-1`,children:[(0,A.jsx)(h,{className:`w-3 h-3`}),` `,a(`card.updateAvailable`)]})]}),e.category&&(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),e.whatItDoes.length>0&&(0,A.jsx)(`ul`,{className:`text-xs space-y-1 list-disc pl-4 text-foreground/80`,children:e.whatItDoes.map((e,t)=>(0,A.jsx)(`li`,{children:e},t))}),e.requirements.length>0&&(0,A.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:a(`card.requires`,{list:e.requirements.map(e=>`${e.name}${e.minVersion?` ≥ ${e.minVersion}`:``}`).join(`, `)})}),e.healthReason&&e.status===`degraded`&&(0,A.jsx)(`div`,{className:`text-[11px] text-accent-warning`,children:e.healthReason}),e.status===`deactivated`&&(0,A.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-relaxed`,children:(0,A.jsx)(t,{t:a,i18nKey:`card.deactivatedHint`,components:{strong:(0,A.jsx)(`strong`,{})}})}),e.marketplaceConflicts&&e.marketplaceConflicts.length>0&&(0,A.jsx)(H,{pluginName:e.name,conflicts:e.marketplaceConflicts}),e.marketplaceCachedButDisabled&&e.marketplaceCachedButDisabled.length>0&&(0,A.jsx)(B,{keys:e.marketplaceCachedButDisabled}),e.updateAvailable&&(0,A.jsx)(V,{pluginName:e.name}),(0,A.jsx)(`div`,{className:`mt-auto pt-2 flex items-center justify-end gap-2`,children:e.status===`not-installed`?(0,A.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white hover:opacity-90`,children:a(`card.install`)}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(z,{pluginName:e.name,active:e.status===`installed`}),(0,A.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-destructive/10 hover:text-destructive flex items-center gap-1.5`,children:[(0,A.jsx)(x,{className:`w-3 h-3`}),` `,a(`card.uninstall`)]})]})}),n&&(0,A.jsx)(W,{pluginName:e.name,onClose:i}),o&&(0,A.jsx)(G,{pluginName:e.name,onClose:()=>s(!1),onUninstalled:()=>{s(!1)}})]})}function z({pluginName:e,active:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(null);return(0,A.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,A.jsx)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0),o(null);try{let n=`${E()}/plugins/${e}/${t?`deactivate`:`activate`}`,r=await fetch(n,{method:`POST`});if(!r.ok)throw Error((await r.json()).error??`HTTP ${r.status}`)}catch(e){o(e.message)}finally{i(!1)}},role:`switch`,"aria-checked":t,className:`relative inline-flex items-center h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${t?`bg-accent-success`:`bg-muted`}`,title:n(t?`toggle.titleActive`:`toggle.titleDeactivated`),children:(0,A.jsx)(`span`,{className:`inline-block h-4 w-4 rounded-full bg-white shadow transition-transform ${t?`translate-x-4`:`translate-x-0.5`}`})}),(0,A.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(t?`card.statusActive`:`common:states.off`)}),a&&(0,A.jsx)(`span`,{className:`text-[10px] text-destructive`,children:a})]})}function B({keys:e}){let{t:n}=u(`integrations`);return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-2 leading-relaxed space-y-1`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(b,{className:`w-3 h-3 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:n,i18nKey:`cachedNotice.body`,components:{strong:(0,A.jsx)(`strong`,{}),code:(0,A.jsx)(`code`,{className:`bg-muted px-1 rounded`})}})})]}),(0,A.jsx)(`div`,{className:`pl-5 space-y-0.5`,children:e.map(e=>(0,A.jsxs)(`pre`,{className:`text-[10px] bg-muted/40 rounded px-1.5 py-0.5 inline-block font-mono`,children:[`/plugin uninstall `,e]},e))}),(0,A.jsx)(`div`,{className:`pl-5 text-[10px] text-muted-foreground`,children:n(`cachedNotice.runInstruction`)})]})}function V({pluginName:e}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(null);return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-accent-info/30 bg-accent-info/5 p-2 leading-relaxed space-y-1.5`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(h,{className:`w-3 h-3 text-accent-info mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:n,i18nKey:`update.body`,components:{code:(0,A.jsx)(`code`,{className:`bg-muted px-1 rounded`})}})})]}),(0,A.jsxs)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0),o(null);try{let t=await fetch(`${E()}/plugins/${e}/update`,{method:`POST`});if(!t.ok)throw Error((await t.json()).error??`HTTP ${t.status}`)}catch(e){o(e.message)}finally{i(!1)}},className:`text-[10px] px-2 py-0.5 rounded border border-accent-info/40 hover:bg-accent-info/10 disabled:opacity-50 flex items-center gap-1`,children:[r&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),(0,A.jsx)(t,{t:n,i18nKey:`update.button`,components:{code:(0,A.jsx)(`code`,{})}})]}),a&&(0,A.jsx)(`div`,{className:`text-destructive text-[10px]`,children:a})]})}function H({pluginName:e,conflicts:n}){let{t:r}=u(`integrations`),[i,a]=(0,k.useState)(null),[o,s]=(0,k.useState)(null),l=async e=>{a(e),s(null);try{let t=await fetch(`${E()}/plugins/_marketplace/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({key:e})});if(!t.ok)throw Error((await t.json()).error??`HTTP ${t.status}`)}catch(e){s(e.message)}finally{a(null)}};return(0,A.jsxs)(`div`,{className:`text-[11px] rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-2 leading-relaxed space-y-1.5`,children:[(0,A.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,A.jsx)(b,{className:`w-3 h-3 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:(0,A.jsx)(t,{t:r,i18nKey:`conflict.body`,values:{name:e},components:{strong:(0,A.jsx)(`strong`,{})}})})]}),(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1`,children:n.map(e=>(0,A.jsxs)(`button`,{type:`button`,disabled:i===e,onClick:()=>l(e),className:`text-[10px] px-2 py-0.5 rounded border border-yellow-500/40 aurora-light:border-accent-warning/40 hover:bg-yellow-500/10 aurora-light:hover:bg-accent-warning/10 disabled:opacity-50 flex items-center gap-1`,children:[i===e&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),(0,A.jsx)(t,{t:r,i18nKey:`conflict.disableButton`,values:{key:e},components:{code:(0,A.jsx)(`code`,{})}})]},e))}),o&&(0,A.jsx)(`div`,{className:`text-destructive`,children:o})]})}function U({plugin:e,onRemoved:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(!1);return(0,A.jsxs)(`div`,{className:`rounded-lg border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 p-4 flex flex-col gap-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,A.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/15 text-yellow-500 aurora-light:text-accent-warning`,children:n(`orphan.badge`)})]}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,A.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,A.jsxs)(`button`,{type:`button`,disabled:r,onClick:async()=>{i(!0);try{await fetch(`${E()}/plugins/${e.name}`,{method:`DELETE`}),t()}finally{i(!1)}},className:`text-xs px-3 py-1.5 rounded-md border border-border hover:bg-destructive/10 hover:text-destructive flex items-center gap-1.5`,children:[(0,A.jsx)(x,{className:`w-3 h-3`}),` `,n(`orphan.removeButton`)]})})]})}function W({pluginName:e,onClose:t}){let{t:n}=u(`integrations`),[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null),[s,l]=(0,k.useState)(!1),[f,p]=(0,k.useState)(null),[m,g]=(0,k.useState)([]),[_,v]=(0,k.useState)(null),[y,x]=(0,k.useState)([]),{registerHandler:C,unregisterHandler:T}=d(),D=(0,k.useCallback)(()=>{i(null),o(null),fetch(`${E()}/plugins/${e}/preview-install`).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>i(e)).catch(e=>o(e.message))},[e]);(0,k.useEffect)(()=>{D()},[D]),(0,k.useEffect)(()=>(C(`install-${e}`,t=>{let n=t;if(n.type===`plugin.install_progress`&&n.name===e&&n.line&&g(e=>[...e,n.line]),n.type===`plugin.prereq_install_progress`&&n.line&&x(e=>[...e,n.line]),n.type===`plugin.prereq_installed`){v(null);let e=n.reason;e&&x(t=>[...t,`► ${e}`]),n.ok&&D()}}),()=>T(`install-${e}`)),[e,C,T,D]);let O=async e=>{v(e),x([n(`installDialog.installingPrereq`,{name:e})]);try{await fetch(`${E()}/plugins/_prerequisites/${e}/install`,{method:`POST`})}catch(e){x(t=>[...t,n(`installDialog.prereqStartFailed`,{message:e.message})]),v(null)}},j=(r?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum);return(0,A.jsxs)(K,{onClose:t,title:n(`installDialog.title`,{name:e}),children:[a&&(0,A.jsx)(`div`,{className:`text-xs text-destructive`,children:a}),!r&&!a&&(0,A.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,A.jsx)(c,{className:`w-3 h-3 animate-spin`}),` `,n(`installDialog.computingChanges`)]}),r&&(0,A.jsxs)(A.Fragment,{children:[r.platformNote&&(0,A.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5 rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/5 aurora-light:bg-accent-warning/10 text-[11px] leading-relaxed`,children:[(0,A.jsx)(b,{className:`w-3.5 h-3.5 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,A.jsx)(`span`,{children:r.platformNote})]}),(0,A.jsxs)(`section`,{children:[(0,A.jsx)(`h4`,{className:`text-xs font-semibold mb-1.5`,children:n(`installDialog.filesHeading`)}),(0,A.jsx)(`ul`,{className:`text-xs space-y-0.5 font-mono`,children:r.files.map((e,t)=>(0,A.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path,e.summary&&(0,A.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,e.summary]})]},t))})]}),r.requirements.length>0&&(0,A.jsxs)(`section`,{children:[(0,A.jsx)(`h4`,{className:`text-xs font-semibold mb-1.5`,children:n(`installDialog.prerequisites`)}),(0,A.jsx)(`ul`,{className:`text-xs space-y-1`,children:r.requirements.map(e=>{let t=e.installed&&e.executable&&e.meetsMinimum,r=e.name===`uv`;return(0,A.jsxs)(`li`,{className:`flex items-center gap-2`,children:[t?(0,A.jsx)(S,{className:`w-3 h-3 text-accent-success`}):(0,A.jsx)(w,{className:`w-3 h-3 text-accent-warning`}),(0,A.jsxs)(`span`,{children:[e.name,e.minVersion?` ≥ ${e.minVersion}`:``]}),e.version&&(0,A.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]}),!t&&r&&(0,A.jsxs)(`button`,{type:`button`,disabled:_===e.name,onClick:()=>O(e.name),className:`ml-auto text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted disabled:opacity-50 flex items-center gap-1`,children:[_===e.name&&(0,A.jsx)(c,{className:`w-2.5 h-2.5 animate-spin`}),n(`installDialog.autoInstall`)]})]},e.name)})}),y.length>0&&(0,A.jsx)(`pre`,{className:`mt-2 text-[11px] bg-muted/40 rounded p-2 max-h-24 overflow-auto font-mono`,children:y.join(`
2
2
  `)})]}),m.length>0&&(0,A.jsxs)(`section`,{children:[(0,A.jsx)(`h4`,{className:`text-xs font-semibold mb-1.5`,children:n(`installDialog.progress`)}),(0,A.jsx)(`pre`,{className:`text-[11px] bg-muted/40 rounded p-2 max-h-32 overflow-auto font-mono`,children:m.join(`
3
3
  `)})]}),f&&(0,A.jsx)(`div`,{className:`text-xs text-destructive`,children:f})]}),(0,A.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,A.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs px-3 py-1.5 rounded-md border border-border`,children:n(`common:actions.cancel`)}),(0,A.jsxs)(`button`,{type:`button`,disabled:!r||!j||s,onClick:async()=>{l(!0),p(null);try{let n=await fetch(`${E()}/plugins/${e}/install`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`HTTP ${n.status}`);setTimeout(t,1500)}catch(e){p(e.message)}finally{l(!1)}},className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white disabled:opacity-50 flex items-center gap-1.5`,children:[s?(0,A.jsx)(c,{className:`w-3 h-3 animate-spin`}):(0,A.jsx)(h,{className:`w-3 h-3`}),n(`card.install`)]})]})]})}function G({pluginName:e,onClose:n,onUninstalled:r}){let{t:i}=u(`integrations`),[a,o]=(0,k.useState)(!1),[s,l]=(0,k.useState)(null);return(0,A.jsxs)(K,{onClose:n,title:i(`uninstallDialog.title`,{name:e}),children:[(0,A.jsx)(`p`,{className:`text-xs`,children:(0,A.jsx)(t,{t:i,i18nKey:`uninstallDialog.body`,components:{code:(0,A.jsx)(`code`,{})}})}),s&&(0,A.jsx)(`div`,{className:`text-xs text-destructive`,children:s}),(0,A.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,A.jsx)(`button`,{type:`button`,onClick:n,className:`text-xs px-3 py-1.5 rounded-md border border-border`,children:i(`common:actions.cancel`)}),(0,A.jsxs)(`button`,{type:`button`,disabled:a,onClick:async()=>{o(!0);try{let t=await fetch(`${E()}/plugins/${e}`,{method:`DELETE`});if(!t.ok)throw Error((await t.json()).error??`HTTP ${t.status}`);r()}catch(e){l(e.message)}finally{o(!1)}},className:`text-xs px-3 py-1.5 rounded-md bg-destructive text-white disabled:opacity-50 flex items-center gap-1.5`,children:[a&&(0,A.jsx)(c,{className:`w-3 h-3 animate-spin`}),i(`card.uninstall`)]})]})]})}function K({title:e,onClose:t,children:n}){let{panelRef:r,panelStyle:i,headerHandleProps:a,resizeHandles:o,isFloating:s,guardBackdrop:c}=l();return(0,A.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,role:`dialog`,tabIndex:-1,onClick:c(t),children:[(0,A.jsxs)(`div`,{ref:r,className:`bg-card border border-border rounded-lg shadow-xl w-full max-w-md p-5 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),style:i,children:[(0,A.jsx)(`h3`,{className:`text-sm font-semibold ${s?`cursor-grab active:cursor-grabbing`:``}`,...a,children:e}),n]}),(0,A.jsx)(_,{handles:o})]})}function q(){return(0,A.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:3},(e,t)=>(0,A.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-4 h-40 animate-pulse`},t))})}function J({onRetry:e}){let{t}=u(`integrations`);return(0,A.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 gap-3 text-sm text-muted-foreground`,children:[(0,A.jsx)(b,{className:`w-5 h-5 text-destructive`}),(0,A.jsx)(`p`,{children:t(`page.loadError`)}),(0,A.jsx)(`button`,{type:`button`,onClick:e,className:`text-xs px-3 py-1.5 rounded-md border border-border`,children:t(`common:actions.retry`)})]})}function Y(){let{t:e}=u(`integrations`);return(0,A.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 gap-2 text-sm text-muted-foreground`,children:[(0,A.jsx)(D,{className:`w-6 h-6`}),(0,A.jsx)(`p`,{children:e(`page.empty`)})]})}export{L as default};
@@ -1,5 +1,5 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{a as t}from"./auth-Cvsb7-Ek.js";import{t as n}from"./brain-DcXkQwzO.js";import{A as r,B as i,C as a,Cn as o,Dt as s,H as c,It as l,Kn as u,Ln as d,Pt as f,Rn as p,Sn as m,St as h,Vt as g,Wt as _,Zt as v,_t as y,a as b,an as x,at as S,bt as C,en as w,fn as T,ft as E,g as D,gn as O,i as k,j as A,nn as j,nt as M,o as N,on as ee,r as te,rt as P,sn as F,tn as ne,ut as I,vn as L,vt as R,wn as z,xn as B,z as V}from"./index-DnkfABxY.js";import{t as re}from"./lib-Bsny0zZp.js";var ie=O(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),ae=O(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),oe=O(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]);function H(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var se=15e3;function ce(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function le(e){let{projectId:n,jobId:r,timeoutMs:i=se}=e,a=n?`${t}/api/projects/${n}`:z(),o;try{o=await fetch(`${a}/jobs/${r}`,{method:`DELETE`,signal:ce(i)})}catch(e){let t=e;return{ok:!1,error:t?.name===`TimeoutError`||t?.name===`AbortError`?`Request timed out after ${Math.round(i/1e3)}s`:t?.message||String(e),httpStatus:null}}if(o.ok){let e=`canceled`;try{let t=await o.json();t&&typeof t.status==`string`&&(e=t.status)}catch{}return{ok:!0,status:e}}let s=typeof o.status==`number`?o.status:null,c=s==null?``:` (HTTP ${s})`,l=``;try{typeof o.text==`function`?l=await o.text():typeof o.json==`function`&&(l=JSON.stringify(await o.json()))}catch{}let u=l.slice(0,200).trim();try{let e=JSON.parse(l);e&&typeof e.error==`string`&&e.error&&(u=e.error)}catch{}let d=typeof o.statusText==`string`?o.statusText:``;return{ok:!1,error:u?`${u}${c}`:`HTTP ${s??`?`}${d?` ${d}`:``}`,httpStatus:s}}var U=o();function ue({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,U.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let a=e[n.key]??`idle`,o=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,U.jsxs)(`div`,{className:`flex items-center`,children:[(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,U.jsx)(de,{state:a}),(0,U.jsx)(`span`,{className:P(`text-xs font-medium transition-colors`,a===`running`?`text-blue-400 aurora-light:text-accent-info`:a===`done`?`text-emerald-400 aurora-light:text-accent-success`:a===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,U.jsxs)(i,{side:`bottom`,className:`max-w-[200px]`,children:[(0,U.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,U.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),o!==null&&(0,U.jsx)(`div`,{className:P(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,o===`done`||a===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:o===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function de({state:e}){return(0,U.jsxs)(`div`,{className:P(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,U.jsx)(f,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,U.jsx)(j,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,U.jsx)(ne,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,U.jsx)(w,{className:`w-6 h-6 text-muted-foreground/20`})]})}var W=e(u(),1);function fe(e){let t=e.trimStart();return!!(/^#{1,6}\s/.test(t)||/^[-*+]\s/.test(t)||/^\d+\.\s/.test(t)||/^\|.+\|/.test(t)||t.startsWith("```")||t.startsWith(`> `)||/\*\*[^*]+\*\*/.test(e)||/`[^`]+`/.test(e)||/\[.+\]\(.+\)/.test(e)||/^(-{3,}|_{3,}|\*{3,})$/.test(t)||/^- \[[ x]\]\s/.test(t))}var G=new Set;function K({ticketId:e,onOpen:t,children:n}){let{t:r}=p(`agent`),i=r(`refs.openTicket`,{id:e});return(0,U.jsx)(`button`,{type:`button`,"data-testid":`log-ticket-ref`,onClick:n=>{n.stopPropagation(),t(e)},title:i,"aria-label":i,className:`inline cursor-pointer p-0 align-baseline text-accent-primary/90 underline decoration-accent-primary/50 decoration-dotted underline-offset-2 transition-colors hover:text-accent-primary hover:decoration-solid`,children:n})}function pe(e){if(!e.includes(`#`))return null;let t=b(e,G);return t.some(e=>e.kind===`ticket`)?t:null}function me(e,t){let n=pe(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,U.jsx)(K,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,U.jsx)(W.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var he=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function ge(e){return e.kind===`ticket`?{type:`link`,url:te({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function _e(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!he.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=b(n.value,G);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(ge))}else _e(n)}}function ve(){return e=>_e(e)}function ye(e){let{activeProjectId:t}=L(),{openRef:n}=N(),r=e??t??void 0;return(0,W.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function be(e,t){let n=`${e.id??t}`,r=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:r}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:r}:fe(t)?{id:n,content:t,type:`assistant`,timestamp:r}:{id:n,content:t,type:`plain`,timestamp:r}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),i=[];return t.duration_ms&&i.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&i.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&i.push(B.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${B.t(`jobs:logViewer.completed`)}${i.length?` — ${i.join(` · `)}`:``}`,type:`result`,timestamp:r}}catch{return null}return null}function xe(e){let t=`none`,n=[];for(let r of e){let e=r.type;if(e!==`plain`&&e!==`log`){t=`none`,n.push(r);continue}let i=r.content;i.startsWith(`--- `)?(t=`saw_minus`,n.push({...r,type:`diff-meta`})):t===`saw_minus`&&i.startsWith(`+++ `)?(t=`active`,n.push({...r,type:`diff-meta`})):t===`active`&&i.startsWith(`@@ `)?n.push({...r,type:`diff-hunk`}):t===`active`&&i.startsWith(`+`)&&!i.startsWith(`+++`)?n.push({...r,type:`diff-add`}):t===`active`&&i.startsWith(`-`)&&!i.startsWith(`---`)?n.push({...r,type:`diff-remove`}):(t===`active`&&(i.startsWith(` `)||i===``)||(t=`none`),n.push(r))}return n}function Se(e){let t=[];for(let n of e){let e=t.length>0?t[t.length-1]:null;n.type===`assistant`&&e?.type===`assistant`?e.content+=`
2
- `+n.content:t.push({...n})}return t}function Ce(e){let t=[{key:`__preamble__`,header:null,lines:[]}];for(let n of e)n.type===`phase`?t.push({key:n.id,header:n,lines:[]}):t[t.length-1].lines.push(n);return t.filter(e=>e.header!==null||e.lines.length>0)}function we({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=p(`jobs`),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(!0),[l,u]=(0,W.useState)(new Set),f=(0,W.useRef)(null),m=(0,W.useRef)(null),h=ye(n),{processedLines:g,groups:_,totalLines:y}=(0,W.useMemo)(()=>{let t=xe(Se(e.map((e,t)=>be(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:Ce(t),totalLines:t.length}},[e,i.language]),b=(0,W.useMemo)(()=>{if(!a)return y;let e=a.toLowerCase();return g.filter(t=>t.content.toLowerCase().includes(e)).length},[a,g,y]),x=(0,W.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,W.useEffect)(()=>{s&&x()},[e.length,s,x]);function S(){let e=m.current;e&&c(e.scrollHeight-e.scrollTop-e.clientHeight<50)}function C(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):y===0?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,U.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,U.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,U.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,U.jsx)(R,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,U.jsx)(D,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`pl-7 h-7`})]}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=g.map(e=>e.content).join(`
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{a as t}from"./auth-Cvsb7-Ek.js";import{t as n}from"./brain-BBNUUrUI.js";import{A as r,B as i,C as a,Cn as o,Dt as s,H as c,It as l,Kn as u,Ln as d,Pt as f,Rn as p,Sn as m,St as h,Vt as g,Wt as _,Zt as v,_t as y,a as b,an as x,at as S,bt as C,en as w,fn as T,ft as E,gn as D,h as O,i as k,j as A,nn as j,nt as M,o as N,on as ee,r as te,rt as P,sn as F,tn as ne,ut as I,vn as L,vt as R,wn as z,xn as B,z as V}from"./index-Dw1N2-ci.js";import{t as re}from"./lib-BviHZ_gK.js";var ie=D(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),ae=D(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),oe=D(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]);function H(e){return e.command.startsWith(`loop:`)?`loop-run`:e.interactive?`interactive`:`job`}var se=15e3;function ce(e){if(typeof AbortSignal<`u`&&typeof AbortSignal.timeout==`function`)return AbortSignal.timeout(e)}async function le(e){let{projectId:n,jobId:r,timeoutMs:i=se}=e,a=n?`${t}/api/projects/${n}`:z(),o;try{o=await fetch(`${a}/jobs/${r}`,{method:`DELETE`,signal:ce(i)})}catch(e){let t=e;return{ok:!1,error:t?.name===`TimeoutError`||t?.name===`AbortError`?`Request timed out after ${Math.round(i/1e3)}s`:t?.message||String(e),httpStatus:null}}if(o.ok){let e=`canceled`;try{let t=await o.json();t&&typeof t.status==`string`&&(e=t.status)}catch{}return{ok:!0,status:e}}let s=typeof o.status==`number`?o.status:null,c=s==null?``:` (HTTP ${s})`,l=``;try{typeof o.text==`function`?l=await o.text():typeof o.json==`function`&&(l=JSON.stringify(await o.json()))}catch{}let u=l.slice(0,200).trim();try{let e=JSON.parse(l);e&&typeof e.error==`string`&&e.error&&(u=e.error)}catch{}let d=typeof o.statusText==`string`?o.statusText:``;return{ok:!1,error:u?`${u}${c}`:`HTTP ${s??`?`}${d?` ${d}`:``}`,httpStatus:s}}var U=o();function ue({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,U.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let a=e[n.key]??`idle`,o=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,U.jsxs)(`div`,{className:`flex items-center`,children:[(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,U.jsx)(de,{state:a}),(0,U.jsx)(`span`,{className:P(`text-xs font-medium transition-colors`,a===`running`?`text-blue-400 aurora-light:text-accent-info`:a===`done`?`text-emerald-400 aurora-light:text-accent-success`:a===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,U.jsxs)(i,{side:`bottom`,className:`max-w-[200px]`,children:[(0,U.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,U.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),o!==null&&(0,U.jsx)(`div`,{className:P(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,o===`done`||a===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:o===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function de({state:e}){return(0,U.jsxs)(`div`,{className:P(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,U.jsx)(f,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,U.jsx)(j,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,U.jsx)(ne,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,U.jsx)(w,{className:`w-6 h-6 text-muted-foreground/20`})]})}var W=e(u(),1);function fe(e){let t=e.trimStart();return!!(/^#{1,6}\s/.test(t)||/^[-*+]\s/.test(t)||/^\d+\.\s/.test(t)||/^\|.+\|/.test(t)||t.startsWith("```")||t.startsWith(`> `)||/\*\*[^*]+\*\*/.test(e)||/`[^`]+`/.test(e)||/\[.+\]\(.+\)/.test(e)||/^(-{3,}|_{3,}|\*{3,})$/.test(t)||/^- \[[ x]\]\s/.test(t))}var G=new Set;function K({ticketId:e,onOpen:t,children:n}){let{t:r}=p(`agent`),i=r(`refs.openTicket`,{id:e});return(0,U.jsx)(`button`,{type:`button`,"data-testid":`log-ticket-ref`,onClick:n=>{n.stopPropagation(),t(e)},title:i,"aria-label":i,className:`inline cursor-pointer p-0 align-baseline text-accent-primary/90 underline decoration-accent-primary/50 decoration-dotted underline-offset-2 transition-colors hover:text-accent-primary hover:decoration-solid`,children:n})}function pe(e){if(!e.includes(`#`))return null;let t=b(e,G);return t.some(e=>e.kind===`ticket`)?t:null}function me(e,t){let n=pe(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,U.jsx)(K,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,U.jsx)(W.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var he=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function ge(e){return e.kind===`ticket`?{type:`link`,url:te({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function _e(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!he.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=b(n.value,G);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(ge))}else _e(n)}}function ve(){return e=>_e(e)}function ye(e){let{activeProjectId:t}=L(),{openRef:n}=N(),r=e??t??void 0;return(0,W.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function be(e,t){let n=`${e.id??t}`,r=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:r}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:r}:fe(t)?{id:n,content:t,type:`assistant`,timestamp:r}:{id:n,content:t,type:`plain`,timestamp:r}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),i=[];return t.duration_ms&&i.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&i.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&i.push(B.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${B.t(`jobs:logViewer.completed`)}${i.length?` — ${i.join(` · `)}`:``}`,type:`result`,timestamp:r}}catch{return null}return null}function xe(e){let t=`none`,n=[];for(let r of e){let e=r.type;if(e!==`plain`&&e!==`log`){t=`none`,n.push(r);continue}let i=r.content;i.startsWith(`--- `)?(t=`saw_minus`,n.push({...r,type:`diff-meta`})):t===`saw_minus`&&i.startsWith(`+++ `)?(t=`active`,n.push({...r,type:`diff-meta`})):t===`active`&&i.startsWith(`@@ `)?n.push({...r,type:`diff-hunk`}):t===`active`&&i.startsWith(`+`)&&!i.startsWith(`+++`)?n.push({...r,type:`diff-add`}):t===`active`&&i.startsWith(`-`)&&!i.startsWith(`---`)?n.push({...r,type:`diff-remove`}):(t===`active`&&(i.startsWith(` `)||i===``)||(t=`none`),n.push(r))}return n}function Se(e){let t=[];for(let n of e){let e=t.length>0?t[t.length-1]:null;n.type===`assistant`&&e?.type===`assistant`?e.content+=`
2
+ `+n.content:t.push({...n})}return t}function Ce(e){let t=[{key:`__preamble__`,header:null,lines:[]}];for(let n of e)n.type===`phase`?t.push({key:n.id,header:n,lines:[]}):t[t.length-1].lines.push(n);return t.filter(e=>e.header!==null||e.lines.length>0)}function we({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=p(`jobs`),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(!0),[l,u]=(0,W.useState)(new Set),f=(0,W.useRef)(null),m=(0,W.useRef)(null),h=ye(n),{processedLines:g,groups:_,totalLines:y}=(0,W.useMemo)(()=>{let t=xe(Se(e.map((e,t)=>be(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:Ce(t),totalLines:t.length}},[e,i.language]),b=(0,W.useMemo)(()=>{if(!a)return y;let e=a.toLowerCase();return g.filter(t=>t.content.toLowerCase().includes(e)).length},[a,g,y]),x=(0,W.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,W.useEffect)(()=>{s&&x()},[e.length,s,x]);function S(){let e=m.current;e&&c(e.scrollHeight-e.scrollTop-e.clientHeight<50)}function C(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):y===0?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,U.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,U.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,U.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,U.jsx)(R,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,U.jsx)(O,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`pl-7 h-7`})]}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=g.map(e=>e.content).join(`
3
3
  `);navigator.clipboard.writeText(e).then(()=>{d.success(r(`logViewer.copySuccess`))}).catch(()=>{d.error(r(`logViewer.copyFailed`))})},children:(0,U.jsx)(v,{className:`w-3.5 h-3.5`})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:b,total:y})})]}),(0,U.jsxs)(`div`,{ref:m,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:S,children:[_.map(e=>(0,U.jsx)(Te,{group:e,filter:a,collapsed:l.has(e.key),onToggle:()=>C(e.key),onOpenTicket:h},e.key)),(0,U.jsx)(`div`,{ref:f})]}),!s&&(0,U.jsxs)(M,{size:`sm`,variant:`secondary`,onClick:()=>{c(!0),x()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,U.jsx)(ee,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var Te=(0,W.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:a}=p(`jobs`),o=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return o.length===0?null:(0,U.jsx)(`div`,{children:o.map((e,t)=>(0,U.jsx)(q,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let s=e.header.content;return(0,U.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:r,className:P(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,U.jsx)(x,{className:P(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,U.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:s}),e.header.timestamp&&(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 font-mono tabular-nums shrink-0`,children:new Date(e.header.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:a(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,U.jsx)(`div`,{className:`bg-muted/5`,children:o.length===0?(0,U.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:a(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):o.map((e,t)=>(0,U.jsx)(q,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),Ee=[re],De=[r],Oe=[r,ve],q=(0,W.memo)(function({line:e,even:t,onOpenTicket:n}){let r=e.type===`assistant`,i=e.type===`diff-add`,a=e.type===`diff-remove`,o=e.type===`diff-meta`,s=e.type===`diff-hunk`,c=i||a||o||s,l=n!=null&&(e.type===`plain`||e.type===`log`),u=(0,W.useMemo)(()=>l&&n?me(e.content,n):e.content,[l,n,e.content]),d=r&&n?Oe:De,f=(0,W.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=k(e);return r?.kind===`ticket`?(0,U.jsx)(K,{ticketId:r.ticketId,onOpen:n,children:t}):(0,U.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,U.jsxs)(`div`,{className:P(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0 mt-0.5 w-[52px] font-mono tabular-nums`,children:new Date(e.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),r?(0,U.jsx)(`div`,{className:`flex-1 min-w-0 prose prose-invert prose-xs max-w-none
4
4
  prose-p:my-1 prose-p:leading-relaxed
5
5
  prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold
@@ -13,7 +13,7 @@ import{a as e}from"./chunk-BNv3lrIs.js";import{a as t}from"./auth-Cvsb7-Ek.js";i
13
13
  prose-th:px-3 prose-th:py-1.5 prose-th:text-left prose-th:font-semibold prose-th:text-foreground/90
14
14
  prose-td:px-3 prose-td:py-1.5 prose-td:border-border
15
15
  prose-tr:border-border
16
- text-foreground/80`,children:(0,U.jsx)(A,{remarkPlugins:d,rehypePlugins:Ee,components:f,children:e.content})}):(0,U.jsx)(`span`,{className:P(`flex-1 break-all leading-relaxed whitespace-pre-wrap font-mono`,e.type===`tool-use`&&`text-cyan-400/80 aurora-light:text-accent-info text-[11px]`,e.type===`stderr`&&`text-orange-400 aurora-light:text-accent-warning`,e.type===`result`&&`text-emerald-400 aurora-light:text-accent-success font-medium`,e.type===`log`&&`text-foreground/60`,e.type===`plain`&&`text-foreground/70`,e.type===`tool-result`&&`text-muted-foreground/50`,i&&`text-emerald-400 aurora-light:text-accent-success`,a&&`text-red-400 aurora-light:text-destructive`,o&&`text-accent-primary/80`,s&&`text-accent-info/80`),children:u})]})});function J(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var ke=/^\s*━+\s*Step\s+\d+\s*·/,Ae=/\s*\(iteration\s+\d+\)\s*$/i;function Y(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function X(e){let t=Y(e.title);return e.iteration==null?t:t.replace(Ae,``)}function je(e){return e.meta.nodeId??`${e.meta.kind}::${Y(e.meta.title).replace(Ae,``)}`}function Me(e){let t=null,n=0,r=[[]],i=[];for(let o=0;o<e.length;o++){let s=e[o];if(s.event_type===`loop_graph`){let e=J(s.payload);e&&e.graph&&typeof e.graph==`object`&&!Array.isArray(e.graph)&&(t={graph:e.graph,loopId:typeof e.loopId==`string`?e.loopId:void 0,loopName:typeof e.loopName==`string`?e.loopName:void 0,provider:typeof e.provider==`string`?e.provider:void 0,model:typeof e.model==`string`?e.model:void 0,iterationLimit:typeof e.iterationLimit==`number`?e.iterationLimit:void 0});continue}if(s.event_type===`loop_step`){let e=J(s.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),i.push({meta:{index:e.index,kind:typeof e.kind==`string`?e.kind:`ai-step`,title:typeof e.title==`string`?e.title:``,nodeId:typeof e.nodeId==`string`?e.nodeId:null,iteration:t,template:typeof e.template==`string`&&e.template?e.template:void 0,command:typeof e.command==`string`&&e.command?e.command:void 0},end:null,lastActivity:null}),r.push([]);continue}if(s.event_type===`loop_step_end`){let e=J(s.payload);if(!e||typeof e.index!=`number`)continue;for(let t=i.length-1;t>=0;t--)if(i[t].meta.index===e.index){i[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`failed`?`failed`:`ok`,exitCode:typeof e.exitCode==`number`?e.exitCode:null,durationMs:typeof e.durationMs==`number`?e.durationMs:null,decision:e.decision===`continue`||e.decision===`stop`?e.decision:void 0};break}continue}let c=i.length>0,l=be(s,o);if(l&&!(c&&ke.test(l.content))&&r[r.length-1].push(l),c){let e=a(s);e.step&&e.actionKey&&(i[i.length-1].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let o=e=>xe(Se(e)),s=o(r[0]),c=i.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:o(r[t+1]),end:e.end,lastActivity:e.lastActivity})),l=s.length+c.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:s,segments:c,maxIteration:n,totalLines:l}}function Ne(e,t){return e.end?e.end.status:t.isLast?t.jobSettled?`interrupted`:`running`:`unknown`}function Pe(e){return e===`continue`?0:e===`stop`?2:1}function Fe(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set,r=[],i=a=>{if(n.has(a))return;let o=t.get(a);if(!o)return;n.add(a),r.push(o);let s=e.edges.filter(e=>e.source===a).slice().sort((e,t)=>Pe(e.branch)-Pe(t.branch));for(let e of s)i(e.target)},a=e.nodes.find(e=>e.type===`start`);a&&i(a.id);for(let t of e.nodes)i(t.id);return r}function Z(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Ie(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=je(e);r.set(n,{seg:e,idx:t}),e.meta.kind===`decider`&&e.end?.decision&&i.set(n,e.end.decision)});let a=e=>{let r=Ne(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r};if(e.graphMeta)return Fe(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:Z(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:Z(e),state:t.jobSettled?t.jobFailed?`failed`:`ok`:`pending`,latestSegmentKey:null};let n=r.get(e.id);return n?{key:e.id,kind:e.type,label:Z(e)??X(n.seg.meta),state:a(n),decision:e.type===`decider`?i.get(e.id):void 0,latestSegmentKey:n.seg.key}:{key:e.id,kind:e.type,label:Z(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=je(e),r={seg:e,idx:t},c=s.get(n),l=e.meta.kind===`decider`?i.get(n):void 0;if(c!=null){let t=o[c];t.state=a(r),t.decision=l,t.latestSegmentKey=e.key}else s.set(n,o.length),o.push({key:n,kind:e.meta.kind,label:X(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function Le(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}var Re={start:s,"ai-step":n,shell:I,decider:g,condition:g,end:_},ze=E,Be={start:`text-accent-success`,"ai-step":`text-accent-primary`,shell:`text-accent-warning`,decider:`text-accent-highlight`,condition:`text-accent-info`,end:`text-accent-secondary`},Ve={start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function He(e){return Re[e]??ze}function Ue({chips:e,iteration:t,onChipClick:n,variant:r}){let{t:i}=p(`jobs`);return e.length===0&&!t?null:(0,U.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":i(`loopExplorer.stepMapAria`),className:P(`flex items-center gap-1 overflow-x-auto border-b border-border/30 bg-surface/20`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[e.map((e,t)=>{let r=He(e.kind),a=Be[e.kind]??`text-foreground`,o=Ve[e.kind]??`border-border/40`,s=e.label??i(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),c=e.latestSegmentKey!=null;return(0,U.jsxs)(W.Fragment,{children:[t>0&&(0,U.jsx)(x,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,U.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${s} — ${e.state}`,disabled:!c,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:P(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,o,e.state===`pending`&&`opacity-45 border-border/40`,e.state===`interrupted`&&`border-dashed border-accent-warning/50`,c?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,U.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-px rounded-full ring-2 ring-accent-primary/50 motion-safe:animate-pulse pointer-events-none`}),(0,U.jsx)(r,{className:P(`w-3 h-3 shrink-0`,a)}),(0,U.jsx)(`span`,{className:P(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:s}),e.state===`ok`&&(0,U.jsx)(F,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,U.jsx)(S,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,U.jsx)(C,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,U.jsx)(T,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,U.jsxs)(`span`,{"data-testid":`loop-iteration-chip`,className:`ml-auto flex items-center gap-1.5 shrink-0 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-2.5 py-1 text-[10px] font-medium text-accent-highlight tabular-nums`,children:[(0,U.jsx)(h,{className:`w-3 h-3`}),t.limit==null?i(`loopExplorer.iterationBadge`,{count:t.current}):i(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var We=(0,W.memo)(Ue);function Ge({className:e}){return(0,U.jsxs)(`span`,{className:P(`relative flex h-2 w-2 shrink-0`,e),children:[(0,U.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,U.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function Ke(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function qe(e,t,n,r){return e.length===0?(0,U.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:n(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):e.map((e,t)=>(0,U.jsx)(q,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function Je({label:e,value:t,copyLabel:n}){let[r,i]=(0,W.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":`${n} — ${e}`,title:n,className:`p-0.5 text-muted-foreground/40 hover:text-foreground transition-colors cursor-pointer`,children:r?(0,U.jsx)(F,{className:`w-2.5 h-2.5 text-accent-success`}):(0,U.jsx)(v,{className:`w-2.5 h-2.5`})})]}),(0,U.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function Ye({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:a,setRef:o,onOpenTicket:s}){let{t:c}=p(`jobs`),{meta:u,lines:d,end:f,lastActivity:m}=e,h=He(u.kind),g=Be[u.kind]??`text-foreground`,_=Ke(d,r),y=t===`running`,b=!!(u.template||u.command),[C,w]=(0,W.useState)(!1);return(0,U.jsxs)(`div`,{ref:t=>o(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:P(`mt-3 rounded-md overflow-hidden border animate-in fade-in duration-200`,t===`running`&&`border-accent-primary/40`,t===`failed`&&`border-destructive/30`,t===`interrupted`&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,U.jsxs)(`div`,{className:P(`flex items-stretch bg-primary/5 border-b`,t===`failed`?`border-destructive/20`:`border-primary/20`),children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-2 flex-1 min-w-0 text-left px-3 py-2 hover:bg-primary/10 transition-colors duration-150 cursor-pointer`,children:[(0,U.jsx)(x,{className:P(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,U.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,U.jsx)(h,{className:P(`w-3.5 h-3.5 shrink-0`,g)}),(0,U.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:X(u)}),u.iteration!=null&&u.iteration>=1&&(0,U.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/60 px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground tabular-nums`,children:c(`loopExplorer.iterationBadge`,{count:u.iteration})}),y&&(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,U.jsx)(Ge,{}),m&&(0,U.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:c(`statusPanel.activity.${m.actionKey}`,{arg:m.actionArg??``})})]}),t===`ok`&&(0,U.jsx)(F,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&(0,U.jsx)(S,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`interrupted`&&(0,U.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-accent-warning/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-accent-warning`,children:c(`loopExplorer.interrupted`)}),(0,U.jsx)(`span`,{className:`flex-1`}),f?.durationMs!=null&&(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:Le(f.durationMs)}),t===`failed`&&f?.exitCode!=null&&f.exitCode!==0&&(0,U.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:c(`activeJob.exitCode`,{code:f.exitCode})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:c(`logViewer.phaseLines`,{count:d.length})})]}),b&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>w(e=>!e),"aria-label":c(`loopExplorer.stepDetail`),"aria-expanded":C,title:c(`loopExplorer.stepDetail`),className:P(`px-2 flex items-center transition-colors cursor-pointer`,C?`text-foreground bg-primary/10`:`text-muted-foreground/40 hover:text-foreground hover:bg-primary/10`),children:(0,U.jsx)(l,{className:`w-3 h-3`})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>a(e.key),"aria-label":c(`loopExplorer.copyStep`),title:c(`loopExplorer.copyStep`),className:`px-2.5 flex items-center text-muted-foreground/40 hover:text-foreground hover:bg-primary/10 transition-colors cursor-pointer`,children:(0,U.jsx)(v,{className:`w-3 h-3`})})]}),C&&b&&(0,U.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:P(`px-4 py-2.5 space-y-2.5 bg-muted/10 border-b animate-in fade-in duration-150`,t===`failed`?`border-destructive/20`:`border-primary/10`),children:[u.template&&(0,U.jsx)(Je,{label:c(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:c(`loopExplorer.copyCommand`)}),u.command&&(0,U.jsx)(Je,{label:c(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:c(`loopExplorer.copyCommand`)})]}),!n&&(0,U.jsx)(`div`,{className:`bg-muted/5`,children:qe(_,r,c,s)})]})}var Xe=(0,W.memo)(Ye,(e,t)=>e.segment.key===t.segment.key&&e.segment.lines.length===t.segment.lines.length&&e.segment.lines[e.segment.lines.length-1]?.content===t.segment.lines[t.segment.lines.length-1]?.content&&e.segment.meta.template===t.segment.meta.template&&e.segment.meta.command===t.segment.meta.command&&e.segment.end?.status===t.segment.end?.status&&e.segment.end?.durationMs===t.segment.end?.durationMs&&e.segment.end?.decision===t.segment.end?.decision&&e.segment.end?.exitCode===t.segment.end?.exitCode&&e.segment.lastActivity?.actionKey===t.segment.lastActivity?.actionKey&&e.segment.lastActivity?.actionArg===t.segment.lastActivity?.actionArg&&e.status===t.status&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket),Q=`__setup__`;function Ze({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:a}){let{t:o}=p(`jobs`),c=Ke(e,n);return(0,U.jsxs)(`div`,{ref:e=>i(Q,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(Q),className:`flex items-center gap-2 w-full text-left px-3 py-2 bg-muted/10 border-b border-border/20 hover:bg-muted/20 transition-colors duration-150 cursor-pointer`,children:[(0,U.jsx)(x,{className:P(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,U.jsx)(s,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,U.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:o(`loopExplorer.setup`)}),(0,U.jsx)(`span`,{className:`flex-1`}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,U.jsx)(`div`,{className:`bg-muted/5`,children:qe(c,n,o,a)})]})}var Qe=(0,W.memo)(Ze,(e,t)=>e.lines.length===t.lines.length&&e.lines[e.lines.length-1]?.content===t.lines[t.lines.length-1]?.content&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket);function $(){return(0,U.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,U.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,U.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function $e({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i}){let{t:a,i18n:o}=p(`jobs`),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(`follow`),[f,m]=(0,W.useState)(new Set),h=(0,W.useRef)(null),g=(0,W.useRef)(new Map),_=ye(i),y=(0,W.useMemo)(()=>Me(e),[e,o.language]),b=t!=null&&t!==`running`&&t!==`queued`,x=t===`running`,S=(0,W.useMemo)(()=>y.segments.map((e,t)=>Ne(e,{isLast:t===y.segments.length-1,jobSettled:b})),[y,b]),C=(0,W.useMemo)(()=>{let e=y.segments.map(e=>e.key);return y.setup.length>0&&e.push(Q),e},[y]),w=y.segments.length>0?y.segments[y.segments.length-1].key:Q,T=(0,W.useMemo)(()=>s?new Set(C):l===`follow`?new Set([w]):f,[s,l,w,f,C]),E=(0,W.useRef)(T);E.current=T;let O=(0,W.useRef)(y);O.current=y;let k=(0,W.useCallback)(e=>{let t=new Set(E.current);e?.(t),m(t),u(`manual`)},[]),A=(0,W.useCallback)(e=>{k(t=>{t.has(e)?t.delete(e):t.add(e)})},[k]),j=(0,W.useCallback)(e=>{k(t=>t.add(e)),requestAnimationFrame(()=>{g.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[k]),N=(0,W.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]),ee=(0,W.useCallback)(()=>{u(`follow`),requestAnimationFrame(N)},[N]),te=(0,W.useCallback)(()=>{m(new Set(C)),u(`manual`)},[C]),F=(0,W.useCallback)(()=>{m(new Set),u(`manual`)},[]);(0,W.useEffect)(()=>{l===`follow`&&!s&&N()},[y.totalLines,y.segments.length,l,s,N]);let ne=(0,W.useCallback)(()=>{let e=h.current;!e||l!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&k()},[l,k]),I=(0,W.useCallback)((e,t)=>{t?g.current.set(e,t):g.current.delete(e)},[]),L=(0,W.useCallback)(e=>{let t=O.current.segments.find(t=>t.key===e),n=e===`__setup__`?O.current.setup.map(e=>e.content).join(`
16
+ text-foreground/80`,children:(0,U.jsx)(A,{remarkPlugins:d,rehypePlugins:Ee,components:f,children:e.content})}):(0,U.jsx)(`span`,{className:P(`flex-1 break-all leading-relaxed whitespace-pre-wrap font-mono`,e.type===`tool-use`&&`text-cyan-400/80 aurora-light:text-accent-info text-[11px]`,e.type===`stderr`&&`text-orange-400 aurora-light:text-accent-warning`,e.type===`result`&&`text-emerald-400 aurora-light:text-accent-success font-medium`,e.type===`log`&&`text-foreground/60`,e.type===`plain`&&`text-foreground/70`,e.type===`tool-result`&&`text-muted-foreground/50`,i&&`text-emerald-400 aurora-light:text-accent-success`,a&&`text-red-400 aurora-light:text-destructive`,o&&`text-accent-primary/80`,s&&`text-accent-info/80`),children:u})]})});function J(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var ke=/^\s*━+\s*Step\s+\d+\s*·/,Ae=/\s*\(iteration\s+\d+\)\s*$/i;function Y(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function X(e){let t=Y(e.title);return e.iteration==null?t:t.replace(Ae,``)}function je(e){return e.meta.nodeId??`${e.meta.kind}::${Y(e.meta.title).replace(Ae,``)}`}function Me(e){let t=null,n=0,r=[[]],i=[];for(let o=0;o<e.length;o++){let s=e[o];if(s.event_type===`loop_graph`){let e=J(s.payload);e&&e.graph&&typeof e.graph==`object`&&!Array.isArray(e.graph)&&(t={graph:e.graph,loopId:typeof e.loopId==`string`?e.loopId:void 0,loopName:typeof e.loopName==`string`?e.loopName:void 0,provider:typeof e.provider==`string`?e.provider:void 0,model:typeof e.model==`string`?e.model:void 0,iterationLimit:typeof e.iterationLimit==`number`?e.iterationLimit:void 0});continue}if(s.event_type===`loop_step`){let e=J(s.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),i.push({meta:{index:e.index,kind:typeof e.kind==`string`?e.kind:`ai-step`,title:typeof e.title==`string`?e.title:``,nodeId:typeof e.nodeId==`string`?e.nodeId:null,iteration:t,template:typeof e.template==`string`&&e.template?e.template:void 0,command:typeof e.command==`string`&&e.command?e.command:void 0},end:null,lastActivity:null}),r.push([]);continue}if(s.event_type===`loop_step_end`){let e=J(s.payload);if(!e||typeof e.index!=`number`)continue;for(let t=i.length-1;t>=0;t--)if(i[t].meta.index===e.index){i[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`failed`?`failed`:`ok`,exitCode:typeof e.exitCode==`number`?e.exitCode:null,durationMs:typeof e.durationMs==`number`?e.durationMs:null,decision:e.decision===`continue`||e.decision===`stop`?e.decision:void 0};break}continue}let c=i.length>0,l=be(s,o);if(l&&!(c&&ke.test(l.content))&&r[r.length-1].push(l),c){let e=a(s);e.step&&e.actionKey&&(i[i.length-1].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let o=e=>xe(Se(e)),s=o(r[0]),c=i.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:o(r[t+1]),end:e.end,lastActivity:e.lastActivity})),l=s.length+c.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:s,segments:c,maxIteration:n,totalLines:l}}function Ne(e,t){return e.end?e.end.status:t.isLast?t.jobSettled?`interrupted`:`running`:`unknown`}function Pe(e){return e===`continue`?0:e===`stop`?2:1}function Fe(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set,r=[],i=a=>{if(n.has(a))return;let o=t.get(a);if(!o)return;n.add(a),r.push(o);let s=e.edges.filter(e=>e.source===a).slice().sort((e,t)=>Pe(e.branch)-Pe(t.branch));for(let e of s)i(e.target)},a=e.nodes.find(e=>e.type===`start`);a&&i(a.id);for(let t of e.nodes)i(t.id);return r}function Z(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Ie(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=je(e);r.set(n,{seg:e,idx:t}),e.meta.kind===`decider`&&e.end?.decision&&i.set(n,e.end.decision)});let a=e=>{let r=Ne(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r};if(e.graphMeta)return Fe(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:Z(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:Z(e),state:t.jobSettled?t.jobFailed?`failed`:`ok`:`pending`,latestSegmentKey:null};let n=r.get(e.id);return n?{key:e.id,kind:e.type,label:Z(e)??X(n.seg.meta),state:a(n),decision:e.type===`decider`?i.get(e.id):void 0,latestSegmentKey:n.seg.key}:{key:e.id,kind:e.type,label:Z(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=je(e),r={seg:e,idx:t},c=s.get(n),l=e.meta.kind===`decider`?i.get(n):void 0;if(c!=null){let t=o[c];t.state=a(r),t.decision=l,t.latestSegmentKey=e.key}else s.set(n,o.length),o.push({key:n,kind:e.meta.kind,label:X(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function Le(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}var Re={start:s,"ai-step":n,shell:I,decider:g,condition:g,end:_},ze=E,Be={start:`text-accent-success`,"ai-step":`text-accent-primary`,shell:`text-accent-warning`,decider:`text-accent-highlight`,condition:`text-accent-info`,end:`text-accent-secondary`},Ve={start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function He(e){return Re[e]??ze}function Ue({chips:e,iteration:t,onChipClick:n,variant:r}){let{t:i}=p(`jobs`);return e.length===0&&!t?null:(0,U.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":i(`loopExplorer.stepMapAria`),className:P(`flex items-center gap-1 overflow-x-auto border-b border-border/30 bg-surface/20`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[e.map((e,t)=>{let r=He(e.kind),a=Be[e.kind]??`text-foreground`,o=Ve[e.kind]??`border-border/40`,s=e.label??i(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),c=e.latestSegmentKey!=null;return(0,U.jsxs)(W.Fragment,{children:[t>0&&(0,U.jsx)(x,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,U.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${s} — ${e.state}`,disabled:!c,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:P(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,o,e.state===`pending`&&`opacity-45 border-border/40`,e.state===`interrupted`&&`border-dashed border-accent-warning/50`,c?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,U.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-px rounded-full ring-2 ring-accent-primary/50 motion-safe:animate-pulse pointer-events-none`}),(0,U.jsx)(r,{className:P(`w-3 h-3 shrink-0`,a)}),(0,U.jsx)(`span`,{className:P(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:s}),e.state===`ok`&&(0,U.jsx)(F,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,U.jsx)(S,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,U.jsx)(C,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,U.jsx)(T,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,U.jsxs)(`span`,{"data-testid":`loop-iteration-chip`,className:`ml-auto flex items-center gap-1.5 shrink-0 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-2.5 py-1 text-[10px] font-medium text-accent-highlight tabular-nums`,children:[(0,U.jsx)(h,{className:`w-3 h-3`}),t.limit==null?i(`loopExplorer.iterationBadge`,{count:t.current}):i(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var We=(0,W.memo)(Ue);function Ge({className:e}){return(0,U.jsxs)(`span`,{className:P(`relative flex h-2 w-2 shrink-0`,e),children:[(0,U.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,U.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function Ke(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function qe(e,t,n,r){return e.length===0?(0,U.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:n(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):e.map((e,t)=>(0,U.jsx)(q,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function Je({label:e,value:t,copyLabel:n}){let[r,i]=(0,W.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":`${n} — ${e}`,title:n,className:`p-0.5 text-muted-foreground/40 hover:text-foreground transition-colors cursor-pointer`,children:r?(0,U.jsx)(F,{className:`w-2.5 h-2.5 text-accent-success`}):(0,U.jsx)(v,{className:`w-2.5 h-2.5`})})]}),(0,U.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function Ye({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:a,setRef:o,onOpenTicket:s}){let{t:c}=p(`jobs`),{meta:u,lines:d,end:f,lastActivity:m}=e,h=He(u.kind),g=Be[u.kind]??`text-foreground`,_=Ke(d,r),y=t===`running`,b=!!(u.template||u.command),[C,w]=(0,W.useState)(!1);return(0,U.jsxs)(`div`,{ref:t=>o(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:P(`mt-3 rounded-md overflow-hidden border animate-in fade-in duration-200`,t===`running`&&`border-accent-primary/40`,t===`failed`&&`border-destructive/30`,t===`interrupted`&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,U.jsxs)(`div`,{className:P(`flex items-stretch bg-primary/5 border-b`,t===`failed`?`border-destructive/20`:`border-primary/20`),children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-2 flex-1 min-w-0 text-left px-3 py-2 hover:bg-primary/10 transition-colors duration-150 cursor-pointer`,children:[(0,U.jsx)(x,{className:P(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,U.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,U.jsx)(h,{className:P(`w-3.5 h-3.5 shrink-0`,g)}),(0,U.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:X(u)}),u.iteration!=null&&u.iteration>=1&&(0,U.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/60 px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground tabular-nums`,children:c(`loopExplorer.iterationBadge`,{count:u.iteration})}),y&&(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,U.jsx)(Ge,{}),m&&(0,U.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:c(`statusPanel.activity.${m.actionKey}`,{arg:m.actionArg??``})})]}),t===`ok`&&(0,U.jsx)(F,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&(0,U.jsx)(S,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`interrupted`&&(0,U.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-accent-warning/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-accent-warning`,children:c(`loopExplorer.interrupted`)}),(0,U.jsx)(`span`,{className:`flex-1`}),f?.durationMs!=null&&(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:Le(f.durationMs)}),t===`failed`&&f?.exitCode!=null&&f.exitCode!==0&&(0,U.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:c(`activeJob.exitCode`,{code:f.exitCode})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:c(`logViewer.phaseLines`,{count:d.length})})]}),b&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>w(e=>!e),"aria-label":c(`loopExplorer.stepDetail`),"aria-expanded":C,title:c(`loopExplorer.stepDetail`),className:P(`px-2 flex items-center transition-colors cursor-pointer`,C?`text-foreground bg-primary/10`:`text-muted-foreground/40 hover:text-foreground hover:bg-primary/10`),children:(0,U.jsx)(l,{className:`w-3 h-3`})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>a(e.key),"aria-label":c(`loopExplorer.copyStep`),title:c(`loopExplorer.copyStep`),className:`px-2.5 flex items-center text-muted-foreground/40 hover:text-foreground hover:bg-primary/10 transition-colors cursor-pointer`,children:(0,U.jsx)(v,{className:`w-3 h-3`})})]}),C&&b&&(0,U.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:P(`px-4 py-2.5 space-y-2.5 bg-muted/10 border-b animate-in fade-in duration-150`,t===`failed`?`border-destructive/20`:`border-primary/10`),children:[u.template&&(0,U.jsx)(Je,{label:c(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:c(`loopExplorer.copyCommand`)}),u.command&&(0,U.jsx)(Je,{label:c(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:c(`loopExplorer.copyCommand`)})]}),!n&&(0,U.jsx)(`div`,{className:`bg-muted/5`,children:qe(_,r,c,s)})]})}var Xe=(0,W.memo)(Ye,(e,t)=>e.segment.key===t.segment.key&&e.segment.lines.length===t.segment.lines.length&&e.segment.lines[e.segment.lines.length-1]?.content===t.segment.lines[t.segment.lines.length-1]?.content&&e.segment.meta.template===t.segment.meta.template&&e.segment.meta.command===t.segment.meta.command&&e.segment.end?.status===t.segment.end?.status&&e.segment.end?.durationMs===t.segment.end?.durationMs&&e.segment.end?.decision===t.segment.end?.decision&&e.segment.end?.exitCode===t.segment.end?.exitCode&&e.segment.lastActivity?.actionKey===t.segment.lastActivity?.actionKey&&e.segment.lastActivity?.actionArg===t.segment.lastActivity?.actionArg&&e.status===t.status&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket),Q=`__setup__`;function Ze({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:a}){let{t:o}=p(`jobs`),c=Ke(e,n);return(0,U.jsxs)(`div`,{ref:e=>i(Q,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(Q),className:`flex items-center gap-2 w-full text-left px-3 py-2 bg-muted/10 border-b border-border/20 hover:bg-muted/20 transition-colors duration-150 cursor-pointer`,children:[(0,U.jsx)(x,{className:P(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,U.jsx)(s,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,U.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:o(`loopExplorer.setup`)}),(0,U.jsx)(`span`,{className:`flex-1`}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,U.jsx)(`div`,{className:`bg-muted/5`,children:qe(c,n,o,a)})]})}var Qe=(0,W.memo)(Ze,(e,t)=>e.lines.length===t.lines.length&&e.lines[e.lines.length-1]?.content===t.lines[t.lines.length-1]?.content&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket);function $(){return(0,U.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,U.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,U.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function $e({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i}){let{t:a,i18n:o}=p(`jobs`),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(`follow`),[f,m]=(0,W.useState)(new Set),h=(0,W.useRef)(null),g=(0,W.useRef)(new Map),_=ye(i),y=(0,W.useMemo)(()=>Me(e),[e,o.language]),b=t!=null&&t!==`running`&&t!==`queued`,x=t===`running`,S=(0,W.useMemo)(()=>y.segments.map((e,t)=>Ne(e,{isLast:t===y.segments.length-1,jobSettled:b})),[y,b]),C=(0,W.useMemo)(()=>{let e=y.segments.map(e=>e.key);return y.setup.length>0&&e.push(Q),e},[y]),w=y.segments.length>0?y.segments[y.segments.length-1].key:Q,T=(0,W.useMemo)(()=>s?new Set(C):l===`follow`?new Set([w]):f,[s,l,w,f,C]),E=(0,W.useRef)(T);E.current=T;let D=(0,W.useRef)(y);D.current=y;let k=(0,W.useCallback)(e=>{let t=new Set(E.current);e?.(t),m(t),u(`manual`)},[]),A=(0,W.useCallback)(e=>{k(t=>{t.has(e)?t.delete(e):t.add(e)})},[k]),j=(0,W.useCallback)(e=>{k(t=>t.add(e)),requestAnimationFrame(()=>{g.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[k]),N=(0,W.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]),ee=(0,W.useCallback)(()=>{u(`follow`),requestAnimationFrame(N)},[N]),te=(0,W.useCallback)(()=>{m(new Set(C)),u(`manual`)},[C]),F=(0,W.useCallback)(()=>{m(new Set),u(`manual`)},[]);(0,W.useEffect)(()=>{l===`follow`&&!s&&N()},[y.totalLines,y.segments.length,l,s,N]);let ne=(0,W.useCallback)(()=>{let e=h.current;!e||l!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&k()},[l,k]),I=(0,W.useCallback)((e,t)=>{t?g.current.set(e,t):g.current.delete(e)},[]),L=(0,W.useCallback)(e=>{let t=D.current.segments.find(t=>t.key===e),n=e===`__setup__`?D.current.setup.map(e=>e.content).join(`
17
17
  `):(t?.lines??[]).map(e=>e.content).join(`
18
- `);navigator.clipboard.writeText(n).then(()=>d.success(a(`loopExplorer.copied`))).catch(()=>d.error(a(`logViewer.copyFailed`)))},[a]),z=(0,W.useCallback)(()=>{let e=O.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${Y(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
19
- `)).then(()=>d.success(a(`logViewer.copySuccess`))).catch(()=>d.error(a(`logViewer.copyFailed`)))},[a]),B=(0,W.useMemo)(()=>Ie(y,{jobSettled:b,jobFailed:t===`failed`}),[y,b,t]),V=y.graphMeta?.iterationLimit??y.graphMeta?.graph.config.maxIterations??null,re=y.maxIteration>0?{current:y.maxIteration,limit:V}:null,oe=(0,W.useMemo)(()=>{if(!s)return y.totalLines;let e=s.toLowerCase(),t=y.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of y.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[s,y]),H=y.segments[y.segments.length-1],se=x&&(y.segments.length===0||H?.end!=null);return n?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`logViewer.loading`)})}):y.totalLines===0&&y.segments.length===0?(0,U.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[x&&(0,U.jsx)($,{}),a(x?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,U.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex flex-col h-full`,children:[(0,U.jsxs)(`div`,{className:P(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,U.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,U.jsx)(R,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,U.jsx)(D,{placeholder:a(`logViewer.filterPlaceholder`),value:s,onChange:e=>c(e.target.value),className:`pl-7 h-7`})]}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:te,"aria-label":a(`loopExplorer.expandAll`),title:a(`loopExplorer.expandAll`),children:(0,U.jsx)(ae,{className:`w-3.5 h-3.5`})}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:F,"aria-label":a(`loopExplorer.collapseAll`),title:a(`loopExplorer.collapseAll`),children:(0,U.jsx)(ie,{className:`w-3.5 h-3.5`})}),l===`follow`&&x&&(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,U.jsx)($,{}),a(`loopExplorer.follow`)]}),(0,U.jsx)(`span`,{className:`flex-1`}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:z,"aria-label":a(`logViewer.copySuccess`),children:(0,U.jsx)(v,{className:`w-3.5 h-3.5`})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:a(`logViewer.lineCount`,{filtered:oe,total:y.totalLines})})]}),(0,U.jsx)(We,{chips:B,iteration:re,onChipClick:j,variant:r}),(0,U.jsxs)(`div`,{ref:h,onScroll:ne,className:`flex-1 overflow-y-auto p-2 text-xs`,children:[y.setup.length>0&&(0,U.jsx)(Qe,{lines:y.setup,collapsed:!T.has(`__setup__`),filter:s,onToggle:A,setRef:I,onOpenTicket:_}),y.segments.map((e,t)=>(0,U.jsx)(Xe,{segment:e,status:S[t],collapsed:!T.has(e.key),filter:s,onToggle:A,onCopy:L,setRef:I,onOpenTicket:_},e.key)),se&&(0,U.jsxs)(`div`,{"data-testid":`loop-waiting-row`,className:`mt-3 flex items-center gap-2 px-3 py-2 text-[11px] text-muted-foreground/70 italic`,children:[(0,U.jsx)($,{}),a(`loopExplorer.waiting`)]})]}),l===`manual`&&x&&!s&&(0,U.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:ee,className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 rounded-full glass-card border border-accent-primary/30 px-3 py-1.5 text-[11px] font-medium text-foreground shadow-lg hover:border-accent-primary/60 transition-colors cursor-pointer animate-in fade-in slide-in-from-bottom-2 duration-200`,children:[(0,U.jsx)($,{}),a(`loopExplorer.resumeFollow`)]})]})}function et(e,t){switch(t.type){case`turn-user`:return{...e,streaming:!0,accepting:!0,queued:t.queued?e.queued+1:e.queued};case`turn-done`:{let n=Math.max(0,e.queued-1);return{...e,totals:t.totals,queued:n,streaming:e.queued>0}}case`finalized`:return{...e,streaming:!1,finalizing:!1,accepting:!1,queued:0,totals:t.totals??e.totals};case`accepting`:return t.accepting?{...e,accepting:!0}:{...e,accepting:!1,streaming:!1,queued:0};case`finalize-request`:return{...e,finalizing:!0};case`finalize-reject`:return{...e,finalizing:!1};case`blocked`:return{...e,accepting:!1,streaming:!1};default:return e}}function tt(){try{return m()}catch{return null}}function nt({jobId:e,projectId:n,settleMode:r,initialAcceptingTurns:a,kind:o=`job`,variant:s=`page`,onFinalized:l}){let{t:u}=p(`jobs`),m=r??`finalize`,h=()=>n?`${t}/api/projects/${n}`:z(),[g,_]=(0,W.useReducer)(et,{streaming:!1,queued:0,totals:null,accepting:a??!0,finalizing:!1}),[v,b]=(0,W.useState)(``),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(null);(0,W.useEffect)(()=>{a!==void 0&&_({type:`accepting`,accepting:a})},[a]);let w=(0,W.useRef)(l);w.current=l;let T=tt(),E=(0,W.useId)();(0,W.useEffect)(()=>{if(!T)return;let t=`interactive-composer-${e}-${E}`;return T.registerHandler(t,t=>{let n=t;n.jobId===e&&(n.type===`job.turn_user`?_({type:`turn-user`,queued:!!n.queued}):n.type===`job.turn_done`?_({type:`turn-done`,totals:n.totals}):n.type===`job.finalized`?(_({type:`finalized`,totals:n.totals??null}),w.current?.()):n.type===`job.interactive`&&_({type:`accepting`,accepting:!!n.acceptingTurns}))}),()=>T.unregisterHandler(t)},[T,e,E]);let D=o===`loop-step`&&!g.accepting;async function O(){let t=v.trim();if(!(!t||x||D)){S(!0);try{let n=await fetch(`${h()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(n.ok)b(``),requestAnimationFrame(()=>C.current?.focus());else if(n.status===409&&o===`loop-step`)_({type:`blocked`});else{let e=await n.json().catch(()=>({}));d.error(u(`detail.toast.sendFailed`),{description:e.error})}}catch{d.error(u(`detail.toast.networkError`))}finally{S(!1)}}}async function k(){if(!g.finalizing){_({type:`finalize-request`});try{let t=await fetch(`${h()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)d.success(u(m===`finalize`?`detail.toast.finalizeScheduled`:o===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&o===`loop-step`)_({type:`blocked`}),_({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));d.error(u(`detail.toast.finalizeFailed`),{description:e.error}),_({type:`finalize-reject`})}}catch{d.error(u(`detail.toast.networkError`)),_({type:`finalize-reject`})}}}let A=x||D||!v.trim(),N=u(`detail.interactive.working`);return(0,U.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:P(`shrink-0 border-t px-3 py-2 space-y-1.5`,`motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-300`,s===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,U.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[D?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(oe,{className:`h-3 w-3 motion-safe:animate-pulse`}),u(`detail.interactive.waitingForStepShort`)]}):g.streaming?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(f,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,U.jsxs)(`span`,{className:`relative`,children:[N,(0,U.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:N})]})]}):(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),u(`detail.interactive.ready`)]}),g.queued>0&&(0,U.jsx)(`span`,{className:`rounded-full border border-accent-info/30 bg-accent-info/10 px-1.5 py-px text-[10px] tabular-nums text-accent-info motion-safe:animate-in motion-safe:fade-in`,children:u(`detail.interactive.queued`,{count:g.queued})})]}),(0,U.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[g.totals&&(0,U.jsx)(`span`,{className:`tabular-nums`,children:u(`detail.interactive.liveTotals`,{turns:g.totals.num_turns,cost:g.totals.total_cost_usd.toFixed(4)})}),m===`finalize`?(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsxs)(M,{variant:`outline`,size:`sm`,onClick:()=>void k(),disabled:g.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,U.jsx)(j,{className:`mr-1.5 h-3.5 w-3.5`}),g.finalizing?u(`detail.finalizing`):u(`detail.finalizeJob`)]})}),(0,U.jsx)(i,{children:u(`detail.finalizeJobTooltip`)})]}):(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,onClick:()=>void k(),disabled:g.finalizing||D,className:P(`text-[11px] underline-offset-2 transition-colors`,D?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:g.finalizing?u(`detail.interactive.wrappingUp`):u(o===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,U.jsx)(i,{children:u(o===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),m===`auto`&&(0,U.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:u(D?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,U.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,U.jsx)(`textarea`,{ref:C,value:v,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),O())},rows:2,placeholder:u(D?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":u(`detail.interactive.placeholder`),disabled:D,className:P(`flex-1 resize-none rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-sm transition-opacity focus:outline-none focus:ring-2 focus:ring-ring`,D&&`opacity-60`)}),(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`span`,{className:`shrink-0`,children:(0,U.jsxs)(M,{size:`sm`,onClick:()=>void O(),disabled:A,className:`h-9`,children:[(0,U.jsx)(y,{className:`mr-1.5 h-3.5 w-3.5`}),u(`detail.interactive.send`)]})})}),A&&!x&&(0,U.jsx)(i,{children:u(D?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{le as a,ue as i,$e as n,H as o,we as r,nt as t};
18
+ `);navigator.clipboard.writeText(n).then(()=>d.success(a(`loopExplorer.copied`))).catch(()=>d.error(a(`logViewer.copyFailed`)))},[a]),z=(0,W.useCallback)(()=>{let e=D.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${Y(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
19
+ `)).then(()=>d.success(a(`logViewer.copySuccess`))).catch(()=>d.error(a(`logViewer.copyFailed`)))},[a]),B=(0,W.useMemo)(()=>Ie(y,{jobSettled:b,jobFailed:t===`failed`}),[y,b,t]),V=y.graphMeta?.iterationLimit??y.graphMeta?.graph.config.maxIterations??null,re=y.maxIteration>0?{current:y.maxIteration,limit:V}:null,oe=(0,W.useMemo)(()=>{if(!s)return y.totalLines;let e=s.toLowerCase(),t=y.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of y.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[s,y]),H=y.segments[y.segments.length-1],se=x&&(y.segments.length===0||H?.end!=null);return n?(0,U.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`logViewer.loading`)})}):y.totalLines===0&&y.segments.length===0?(0,U.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[x&&(0,U.jsx)($,{}),a(x?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,U.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex flex-col h-full`,children:[(0,U.jsxs)(`div`,{className:P(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,U.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,U.jsx)(R,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,U.jsx)(O,{placeholder:a(`logViewer.filterPlaceholder`),value:s,onChange:e=>c(e.target.value),className:`pl-7 h-7`})]}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:te,"aria-label":a(`loopExplorer.expandAll`),title:a(`loopExplorer.expandAll`),children:(0,U.jsx)(ae,{className:`w-3.5 h-3.5`})}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:F,"aria-label":a(`loopExplorer.collapseAll`),title:a(`loopExplorer.collapseAll`),children:(0,U.jsx)(ie,{className:`w-3.5 h-3.5`})}),l===`follow`&&x&&(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,U.jsx)($,{}),a(`loopExplorer.follow`)]}),(0,U.jsx)(`span`,{className:`flex-1`}),(0,U.jsx)(M,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:z,"aria-label":a(`logViewer.copySuccess`),children:(0,U.jsx)(v,{className:`w-3.5 h-3.5`})}),(0,U.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:a(`logViewer.lineCount`,{filtered:oe,total:y.totalLines})})]}),(0,U.jsx)(We,{chips:B,iteration:re,onChipClick:j,variant:r}),(0,U.jsxs)(`div`,{ref:h,onScroll:ne,className:`flex-1 overflow-y-auto p-2 text-xs`,children:[y.setup.length>0&&(0,U.jsx)(Qe,{lines:y.setup,collapsed:!T.has(`__setup__`),filter:s,onToggle:A,setRef:I,onOpenTicket:_}),y.segments.map((e,t)=>(0,U.jsx)(Xe,{segment:e,status:S[t],collapsed:!T.has(e.key),filter:s,onToggle:A,onCopy:L,setRef:I,onOpenTicket:_},e.key)),se&&(0,U.jsxs)(`div`,{"data-testid":`loop-waiting-row`,className:`mt-3 flex items-center gap-2 px-3 py-2 text-[11px] text-muted-foreground/70 italic`,children:[(0,U.jsx)($,{}),a(`loopExplorer.waiting`)]})]}),l===`manual`&&x&&!s&&(0,U.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:ee,className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 rounded-full glass-card border border-accent-primary/30 px-3 py-1.5 text-[11px] font-medium text-foreground shadow-lg hover:border-accent-primary/60 transition-colors cursor-pointer animate-in fade-in slide-in-from-bottom-2 duration-200`,children:[(0,U.jsx)($,{}),a(`loopExplorer.resumeFollow`)]})]})}function et(e,t){switch(t.type){case`turn-user`:return{...e,streaming:!0,accepting:!0,queued:t.queued?e.queued+1:e.queued};case`turn-done`:{let n=Math.max(0,e.queued-1);return{...e,totals:t.totals,queued:n,streaming:e.queued>0}}case`finalized`:return{...e,streaming:!1,finalizing:!1,accepting:!1,queued:0,totals:t.totals??e.totals};case`accepting`:return t.accepting?{...e,accepting:!0}:{...e,accepting:!1,streaming:!1,queued:0};case`finalize-request`:return{...e,finalizing:!0};case`finalize-reject`:return{...e,finalizing:!1};case`blocked`:return{...e,accepting:!1,streaming:!1};default:return e}}function tt(){try{return m()}catch{return null}}function nt({jobId:e,projectId:n,settleMode:r,initialAcceptingTurns:a,kind:o=`job`,variant:s=`page`,onFinalized:l}){let{t:u}=p(`jobs`),m=r??`finalize`,h=()=>n?`${t}/api/projects/${n}`:z(),[g,_]=(0,W.useReducer)(et,{streaming:!1,queued:0,totals:null,accepting:a??!0,finalizing:!1}),[v,b]=(0,W.useState)(``),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(null);(0,W.useEffect)(()=>{a!==void 0&&_({type:`accepting`,accepting:a})},[a]);let w=(0,W.useRef)(l);w.current=l;let T=tt(),E=(0,W.useId)();(0,W.useEffect)(()=>{if(!T)return;let t=`interactive-composer-${e}-${E}`;return T.registerHandler(t,t=>{let n=t;n.jobId===e&&(n.type===`job.turn_user`?_({type:`turn-user`,queued:!!n.queued}):n.type===`job.turn_done`?_({type:`turn-done`,totals:n.totals}):n.type===`job.finalized`?(_({type:`finalized`,totals:n.totals??null}),w.current?.()):n.type===`job.interactive`&&_({type:`accepting`,accepting:!!n.acceptingTurns}))}),()=>T.unregisterHandler(t)},[T,e,E]);let D=o===`loop-step`&&!g.accepting;async function O(){let t=v.trim();if(!(!t||x||D)){S(!0);try{let n=await fetch(`${h()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(n.ok)b(``),requestAnimationFrame(()=>C.current?.focus());else if(n.status===409&&o===`loop-step`)_({type:`blocked`});else{let e=await n.json().catch(()=>({}));d.error(u(`detail.toast.sendFailed`),{description:e.error})}}catch{d.error(u(`detail.toast.networkError`))}finally{S(!1)}}}async function k(){if(!g.finalizing){_({type:`finalize-request`});try{let t=await fetch(`${h()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)d.success(u(m===`finalize`?`detail.toast.finalizeScheduled`:o===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&o===`loop-step`)_({type:`blocked`}),_({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));d.error(u(`detail.toast.finalizeFailed`),{description:e.error}),_({type:`finalize-reject`})}}catch{d.error(u(`detail.toast.networkError`)),_({type:`finalize-reject`})}}}let A=x||D||!v.trim(),N=u(`detail.interactive.working`);return(0,U.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:P(`shrink-0 border-t px-3 py-2 space-y-1.5`,`motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-300`,s===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,U.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[D?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(oe,{className:`h-3 w-3 motion-safe:animate-pulse`}),u(`detail.interactive.waitingForStepShort`)]}):g.streaming?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(f,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,U.jsxs)(`span`,{className:`relative`,children:[N,(0,U.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:N})]})]}):(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),u(`detail.interactive.ready`)]}),g.queued>0&&(0,U.jsx)(`span`,{className:`rounded-full border border-accent-info/30 bg-accent-info/10 px-1.5 py-px text-[10px] tabular-nums text-accent-info motion-safe:animate-in motion-safe:fade-in`,children:u(`detail.interactive.queued`,{count:g.queued})})]}),(0,U.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[g.totals&&(0,U.jsx)(`span`,{className:`tabular-nums`,children:u(`detail.interactive.liveTotals`,{turns:g.totals.num_turns,cost:g.totals.total_cost_usd.toFixed(4)})}),m===`finalize`?(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsxs)(M,{variant:`outline`,size:`sm`,onClick:()=>void k(),disabled:g.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,U.jsx)(j,{className:`mr-1.5 h-3.5 w-3.5`}),g.finalizing?u(`detail.finalizing`):u(`detail.finalizeJob`)]})}),(0,U.jsx)(i,{children:u(`detail.finalizeJobTooltip`)})]}):(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,onClick:()=>void k(),disabled:g.finalizing||D,className:P(`text-[11px] underline-offset-2 transition-colors`,D?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:g.finalizing?u(`detail.interactive.wrappingUp`):u(o===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,U.jsx)(i,{children:u(o===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),m===`auto`&&(0,U.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:u(D?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,U.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,U.jsx)(`textarea`,{ref:C,value:v,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),O())},rows:2,placeholder:u(D?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":u(`detail.interactive.placeholder`),disabled:D,className:P(`flex-1 resize-none rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-sm transition-opacity focus:outline-none focus:ring-2 focus:ring-ring`,D&&`opacity-60`)}),(0,U.jsxs)(V,{children:[(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`span`,{className:`shrink-0`,children:(0,U.jsxs)(M,{size:`sm`,onClick:()=>void O(),disabled:A,className:`h-9`,children:[(0,U.jsx)(y,{className:`mr-1.5 h-3.5 w-3.5`}),u(`detail.interactive.send`)]})})}),A&&!x&&(0,U.jsx)(i,{children:u(D?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{le as a,ue as i,$e as n,H as o,we as r,nt as t};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{a as t,n}from"./auth-Cvsb7-Ek.js";import{a as r,i,n as a,o,r as s,t as c}from"./InteractiveJobComposer-CYxXOKld.js";import{B as l,Cn as u,Gn as d,H as ee,I as f,Kn as p,Ln as m,Pt as h,Q as g,Rn as _,V as v,Z as y,at as b,b as x,bn as S,nt as C,tt as w,wn as T,z as te}from"./index-DnkfABxY.js";var ne=e(d(),1),E=e(p(),1),D=[1e3,2e3,4e3,8e3,16e3];function O(e,t){let[r,i]=(0,E.useState)(`connecting`),a=(0,E.useRef)(null),o=(0,E.useRef)(0),s=(0,E.useRef)(null),c=(0,E.useRef)(t);c.current=t;let l=(0,E.useCallback)(()=>{let t=n(),r=t?new WebSocket(e,[`specrails-desktop`,t]):new WebSocket(e);a.current=r,i(`connecting`),r.onopen=()=>{o.current=0,i(`connected`)},r.onmessage=e=>{try{let t=JSON.parse(e.data);c.current(t)}catch{}},r.onclose=()=>{a.current=null;let e=o.current;if(e>=D.length){i(`disconnected`);return}let t=D[e];o.current+=1,s.current=setTimeout(l,t)}},[e]);return(0,E.useEffect)(()=>(l(),()=>{s.current&&clearTimeout(s.current);let e=a.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),a.current=null}),[l]),{connectionStatus:r}}var k=u();function re(e,t){let n=new Date(t).getTime()-new Date(e).getTime();if(n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}var A={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`}};function j({jobId:e,onClose:n,projectId:u}){let{t:d}=_(`jobs`),p=(0,E.useCallback)(()=>u?`${t}/api/projects/${u}`:T(),[u]),[D,j]=(0,E.useState)(null),[M,N]=(0,E.useState)([]),[P,F]=(0,E.useState)([]),[I,L]=(0,E.useState)({}),[R,z]=(0,E.useState)(!0),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(!1);(0,E.useEffect)(()=>{async function t(){try{let t=await fetch(`${p()}/jobs/${e}`);if(t.status===404){V(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(j(n.job),N(n.events),n.phaseDefinitions){F(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;L(e)}}catch{V(!0)}finally{z(!1)}}t()},[e,p]);let K=(0,E.useCallback)(()=>{fetch(`${p()}/jobs/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[e,p]),q=(0,E.useRef)([]),J=(0,E.useRef)(null),Y=(0,E.useCallback)(()=>{J.current=null;let e=q.current;e.length!==0&&(q.current=[],N(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,E.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),O(f,(0,E.useCallback)(t=>{let n=t;if(n.type===`event`&&n.jobId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:n.event_type,source:n.source,payload:n.payload,timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`log`&&n.processId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:`log`,source:n.source,payload:JSON.stringify({line:n.line}),timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`job.finalized`&&n.jobId===e)K();else if(n.type===`phase`){let e=n.phase,t=n.state;L(n=>({...n,[e]:t}))}else if(n.type===`queue`){let t=n.jobs?.find(t=>t.id===e);t&&D&&j(e=>e&&{...e,status:t.status})}},[e,D,Y,K])),(0,E.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}n()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,H]);let X=D?o(D):`job`,Z=X===`loop-run`;async function ie(){G(!0);try{let t=await r({projectId:u??null,jobId:e,kind:X});t.ok?(m.success(d(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:d(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):m.error(d(`modal.toast.cancelFailed`),{description:t.error})}finally{G(!1)}}let Q=D?A[D.status]??A.queued:A.queued,$=D?.status===`running`,{panelRef:ae,panelStyle:oe,headerHandleProps:se,resizeHandles:ce,isFloating:le,guardBackdrop:ue}=g();return(0,ne.createPortal)((0,k.jsx)(v,{delayDuration:400,children:(0,k.jsxs)(`div`,{className:`fixed inset-0 z-[65] flex items-stretch justify-center`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:ue(n)}),(0,k.jsxs)(`div`,{ref:ae,className:`relative w-full m-3 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:oe,children:[(0,k.jsxs)(`div`,{...se,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${le?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[D&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(te,{children:[(0,k.jsx)(ee,{asChild:!0,children:(0,k.jsx)(`div`,{children:(0,k.jsx)(w,{variant:Q.variant,children:d(Q.labelKey)})})}),(0,k.jsx)(l,{children:d(Q.tooltipKey)})]}),(0,k.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:D.command}),(0,k.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:x(new Date(D.started_at),{addSuffix:!0,locale:S()})}),D.total_cost_usd!=null&&D.total_cost_usd>0&&(0,k.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,D.total_cost_usd.toFixed(4)]}),D.finished_at&&(0,k.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:re(D.started_at,D.finished_at)})]}),R&&(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:d(`common:states.loading`)})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[P.length>0&&(0,k.jsx)(`div`,{className:`mr-3`,children:(0,k.jsx)(i,{phases:I,phaseDefinitions:P})}),$&&(0,k.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,k.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),d(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}),(0,k.jsx)(`button`,{onClick:n,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,k.jsx)(b,{className:`w-4 h-4`})})]})]}),(0,k.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:B?(0,k.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,k.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d(`modal.notFound`)})}):D?.command.startsWith(`loop:`)?(0,k.jsx)(a,{events:M,jobStatus:D.status,isLoading:R,variant:`glass`,projectId:u}):(0,k.jsx)(s,{events:M,isLoading:R,projectId:u})}),!!D?.interactive&&D.status===`running`&&(0,k.jsx)(c,{jobId:e,projectId:u,settleMode:D.interactiveSettleMode,initialAcceptingTurns:D.interactiveAcceptingTurns,kind:D.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,k.jsx)(y,{handles:ce}),H&&(0,k.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,k.jsxs)(`div`,{className:`relative w-full max-w-sm rounded-xl glass-card border border-border/30 p-5 shadow-xl animate-in fade-in zoom-in-95 duration-150`,children:[(0,k.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:d(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,k.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:d(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,k.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,k.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:d(`modal.keepRunning`)}),(0,k.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),ie()},children:d(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{j as JobDetailModal};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{a as t,n}from"./auth-Cvsb7-Ek.js";import{a as r,i,n as a,o,r as s,t as c}from"./InteractiveJobComposer-DqDCiCa0.js";import{B as l,Cn as u,Gn as d,H as ee,I as f,Kn as p,Ln as m,Pt as h,Q as g,Rn as _,V as v,Z as y,at as b,b as x,bn as S,nt as C,tt as w,wn as T,z as te}from"./index-Dw1N2-ci.js";var ne=e(d(),1),E=e(p(),1),D=[1e3,2e3,4e3,8e3,16e3];function O(e,t){let[r,i]=(0,E.useState)(`connecting`),a=(0,E.useRef)(null),o=(0,E.useRef)(0),s=(0,E.useRef)(null),c=(0,E.useRef)(t);c.current=t;let l=(0,E.useCallback)(()=>{let t=n(),r=t?new WebSocket(e,[`specrails-desktop`,t]):new WebSocket(e);a.current=r,i(`connecting`),r.onopen=()=>{o.current=0,i(`connected`)},r.onmessage=e=>{try{let t=JSON.parse(e.data);c.current(t)}catch{}},r.onclose=()=>{a.current=null;let e=o.current;if(e>=D.length){i(`disconnected`);return}let t=D[e];o.current+=1,s.current=setTimeout(l,t)}},[e]);return(0,E.useEffect)(()=>(l(),()=>{s.current&&clearTimeout(s.current);let e=a.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),a.current=null}),[l]),{connectionStatus:r}}var k=u();function re(e,t){let n=new Date(t).getTime()-new Date(e).getTime();if(n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}var A={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`}};function j({jobId:e,onClose:n,projectId:u}){let{t:d}=_(`jobs`),p=(0,E.useCallback)(()=>u?`${t}/api/projects/${u}`:T(),[u]),[D,j]=(0,E.useState)(null),[M,N]=(0,E.useState)([]),[P,F]=(0,E.useState)([]),[I,L]=(0,E.useState)({}),[R,z]=(0,E.useState)(!0),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(!1);(0,E.useEffect)(()=>{async function t(){try{let t=await fetch(`${p()}/jobs/${e}`);if(t.status===404){V(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(j(n.job),N(n.events),n.phaseDefinitions){F(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;L(e)}}catch{V(!0)}finally{z(!1)}}t()},[e,p]);let K=(0,E.useCallback)(()=>{fetch(`${p()}/jobs/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[e,p]),q=(0,E.useRef)([]),J=(0,E.useRef)(null),Y=(0,E.useCallback)(()=>{J.current=null;let e=q.current;e.length!==0&&(q.current=[],N(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,E.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),O(f,(0,E.useCallback)(t=>{let n=t;if(n.type===`event`&&n.jobId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:n.event_type,source:n.source,payload:n.payload,timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`log`&&n.processId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:`log`,source:n.source,payload:JSON.stringify({line:n.line}),timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`job.finalized`&&n.jobId===e)K();else if(n.type===`phase`){let e=n.phase,t=n.state;L(n=>({...n,[e]:t}))}else if(n.type===`queue`){let t=n.jobs?.find(t=>t.id===e);t&&D&&j(e=>e&&{...e,status:t.status})}},[e,D,Y,K])),(0,E.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}n()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,H]);let X=D?o(D):`job`,Z=X===`loop-run`;async function ie(){G(!0);try{let t=await r({projectId:u??null,jobId:e,kind:X});t.ok?(m.success(d(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:d(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):m.error(d(`modal.toast.cancelFailed`),{description:t.error})}finally{G(!1)}}let Q=D?A[D.status]??A.queued:A.queued,$=D?.status===`running`,{panelRef:ae,panelStyle:oe,headerHandleProps:se,resizeHandles:ce,isFloating:le,guardBackdrop:ue}=g();return(0,ne.createPortal)((0,k.jsx)(v,{delayDuration:400,children:(0,k.jsxs)(`div`,{className:`fixed inset-0 z-[65] flex items-stretch justify-center`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:ue(n)}),(0,k.jsxs)(`div`,{ref:ae,className:`relative w-full m-3 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:oe,children:[(0,k.jsxs)(`div`,{...se,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${le?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[D&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(te,{children:[(0,k.jsx)(ee,{asChild:!0,children:(0,k.jsx)(`div`,{children:(0,k.jsx)(w,{variant:Q.variant,children:d(Q.labelKey)})})}),(0,k.jsx)(l,{children:d(Q.tooltipKey)})]}),(0,k.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:D.command}),(0,k.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:x(new Date(D.started_at),{addSuffix:!0,locale:S()})}),D.total_cost_usd!=null&&D.total_cost_usd>0&&(0,k.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,D.total_cost_usd.toFixed(4)]}),D.finished_at&&(0,k.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:re(D.started_at,D.finished_at)})]}),R&&(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:d(`common:states.loading`)})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[P.length>0&&(0,k.jsx)(`div`,{className:`mr-3`,children:(0,k.jsx)(i,{phases:I,phaseDefinitions:P})}),$&&(0,k.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,k.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),d(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}),(0,k.jsx)(`button`,{onClick:n,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,k.jsx)(b,{className:`w-4 h-4`})})]})]}),(0,k.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:B?(0,k.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,k.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d(`modal.notFound`)})}):D?.command.startsWith(`loop:`)?(0,k.jsx)(a,{events:M,jobStatus:D.status,isLoading:R,variant:`glass`,projectId:u}):(0,k.jsx)(s,{events:M,isLoading:R,projectId:u})}),!!D?.interactive&&D.status===`running`&&(0,k.jsx)(c,{jobId:e,projectId:u,settleMode:D.interactiveSettleMode,initialAcceptingTurns:D.interactiveAcceptingTurns,kind:D.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,k.jsx)(y,{handles:ce}),H&&(0,k.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,k.jsxs)(`div`,{className:`relative w-full max-w-sm rounded-xl glass-card border border-border/30 p-5 shadow-xl animate-in fade-in zoom-in-95 duration-150`,children:[(0,k.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:d(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,k.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:d(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,k.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,k.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:d(`modal.keepRunning`)}),(0,k.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),ie()},children:d(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{j as JobDetailModal};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{a as t,i as n,n as r,r as i,t as a}from"./InteractiveJobComposer-CYxXOKld.js";import{B as o,C as s,Cn as c,H as l,Hn as u,Kn as d,Ln as f,Lt as p,Pt as m,Qt as h,Rn as g,S as _,Sn as v,Un as y,Vn as b,Xt as x,an as S,b as ee,bn as C,in as w,nn as T,nt as E,on as D,rt as O,tn as k,tt as te,vn as ne,wn as A,xt as j,y as M,z as N}from"./index-DnkfABxY.js";import{t as P}from"./format-command-CuWuRvka.js";var F=e(d(),1),I=c();function L(e,t){let n=(typeof t==`number`?t:new Date(t).getTime())-new Date(e).getTime();if(!Number.isFinite(n)||n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}function R(e){let t=new Set;for(let n of e)if(n.event_type===`log`)try{let e=(JSON.parse(n.payload).line??``).match(/(?:Writing|Editing|Created?|Updated?)\s+(?:file:\s*)?([\w./\-]+\.\w+)/i);e&&t.add(e[1])}catch{}return Array.from(t).slice(0,20)}var z={steps:0,actionKey:``,actionArg:``,lastSeenIdx:0};function B(e,t){if(t.type===`reset`)return z;if(t.type===`consume`){let{events:n}=t,r=e.lastSeenIdx>n.length?n.length:e.lastSeenIdx;if(n.length<=r)return r===e.lastSeenIdx?e:{...e,lastSeenIdx:r};let{steps:i,actionKey:a,actionArg:o}=e;for(let e=r;e<n.length;e++){let t=s(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``)}return{steps:i,actionKey:a,actionArg:o,lastSeenIdx:n.length}}return e}function V({job:e,events:t,defaultOpen:n=!0,pipelineTotals:r,phases:i,phaseDefinitions:a}){let{t:o}=g(`jobs`),[s,c]=(0,F.useState)(n),l=(0,F.useMemo)(()=>R(t),[t]),u=e.status===`running`,d=e.status===`completed`,[f,p]=(0,F.useState)(()=>Date.now());(0,F.useEffect)(()=>{if(!u)return;let e=window.setInterval(()=>p(Date.now()),1e3);return()=>window.clearInterval(e)},[u]);let[h,v]=(0,F.useReducer)(B,z),y=(0,F.useRef)(e.id);(0,F.useEffect)(()=>{y.current!==e.id&&(y.current=e.id,v({type:`reset`})),v({type:`consume`,events:t})},[e.id,t]);let[b,x]=(0,F.useState)(!0);(0,F.useEffect)(()=>{if(!u)return;x(!0);let e=window.setTimeout(()=>x(!1),8e3);return()=>window.clearTimeout(e)},[u,e.id]);let S=e.finished_at?L(e.started_at,e.finished_at):u?L(e.started_at,f):`—`,ee=!!e.total_cost_usd_estimated,C=e.total_cost_usd==null?null:`${ee?`~`:``}$${e.total_cost_usd.toFixed(4)}`,w=e.num_turns==null?null:String(e.num_turns),E=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),te=E==null?null:`${(E/1e3).toFixed(1)}k`,ne=(0,F.useMemo)(()=>!i||!a?null:a.find(e=>i[e.key]===`running`)?.label??null,[i,a]),A=u&&h.steps===0?`connecting`:h.actionKey||`thinking`,j=_.has(A)&&h.actionArg!==``,M=_.has(A)&&!j?`working`:A,N=j?o(`statusPanel.activity.${M}`,{arg:h.actionArg}):o(`statusPanel.activity.${M}`),P=ne??(u&&h.steps===0?o(`statusPanel.activity.starting`):null),V=h.steps>0?o(`statusPanel.steps`,{count:h.steps}):null,G=o(u?`statusPanel.inProgress`:d?`statusPanel.completed`:`statusPanel.failed`),re=u?`border-accent-info/20 bg-accent-info/5`:d?`border-emerald-500/20 aurora-light:border-accent-success/30 bg-emerald-500/5 aurora-light:bg-accent-success/5`:`border-red-500/20 aurora-light:border-destructive/30 bg-red-500/5 aurora-light:bg-destructive/5`,K=u?m:d?T:k,q=u?`w-4 h-4 text-accent-info shrink-0 animate-spin`:d?`w-4 h-4 text-emerald-400 aurora-light:text-accent-success shrink-0`:`w-4 h-4 text-red-400 aurora-light:text-destructive shrink-0`;return(0,I.jsxs)(`div`,{className:O(`mx-4 my-2 rounded-xl border transition-colors duration-500`,re),children:[(0,I.jsxs)(`button`,{type:`button`,onClick:()=>c(!s),className:`w-full flex items-center gap-3 px-4 py-3`,children:[(0,I.jsx)(K,{className:q,"aria-hidden":`true`}),(0,I.jsx)(`span`,{className:`text-sm font-semibold flex-1 text-left`,children:G}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`tabular-nums`,children:S}),u?V&&(0,I.jsx)(`span`,{className:`tabular-nums`,children:V}):(0,I.jsxs)(I.Fragment,{children:[C&&(0,I.jsx)(`span`,{className:`tabular-nums text-yellow-400 aurora-light:text-accent-warning`,children:C}),l.length>0&&(0,I.jsx)(`span`,{children:o(`statusPanel.filesCount`,{count:l.length})})]})]}),(0,I.jsx)(D,{className:O(`w-4 h-4 text-muted-foreground/40 transition-transform duration-150 shrink-0`,s&&`rotate-180`)})]}),s&&(0,I.jsx)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/20`,children:u?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneInProgress`)}),(0,I.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 sm:items-stretch`,children:[(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 sm:w-44 shrink-0`,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[o(`statusPanel.duration`),(0,I.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,title:o(`statusPanel.liveTooltip`),"aria-label":o(`statusPanel.liveTooltip`)})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-accent-info`,children:S})]}),(0,I.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 bg-muted/10 rounded-lg px-3 py-2 min-w-0`,children:[(0,I.jsx)(m,{className:`w-3.5 h-3.5 text-accent-info shrink-0 animate-spin`,"aria-hidden":`true`}),P&&(0,I.jsx)(`span`,{className:`text-[11px] font-medium px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info shrink-0`,children:P}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1 min-w-0`,children:N}),V&&(0,I.jsxs)(`span`,{className:`text-[11px] text-muted-foreground/60 tabular-nums shrink-0`,children:[`· `,V]})]})]}),b&&(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground/40 leading-snug`,children:o(`statusPanel.explainer`)}),(0,I.jsx)(`p`,{className:`pt-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider border-t border-accent-info/10 mt-1`,children:o(`statusPanel.zoneFinalPending`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,I.jsx)(W,{label:o(`statusPanel.cost`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.costTooltip`)}),(0,I.jsx)(W,{label:o(`statusPanel.turns`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)}),(0,I.jsx)(W,{label:o(`statusPanel.tokens`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)})]})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneFinal`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[(0,I.jsx)(H,{label:o(`statusPanel.duration`),value:S}),(0,I.jsx)(U,{label:o(`statusPanel.cost`),value:C,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(U,{label:o(`statusPanel.turns`),value:w,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(U,{label:o(`statusPanel.tokens`),value:te,naCaption:o(`statusPanel.notAvailable`)})]}),r&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.pipelineTotal`,{count:r.jobCount})}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(H,{label:o(`statusPanel.totalCost`),value:`${r.costEstimated?`~`:``}${r.hasNullCost?`≥`:``}$${r.totalCostUsd.toFixed(4)}`,valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,I.jsx)(H,{label:o(`statusPanel.totalTokens`),value:`${((r.totalTokensIn+r.totalTokensOut+r.totalTokensCacheRead+r.totalTokensCacheCreate)/1e3).toFixed(1)}k`})]}),r.hasNullCost&&(0,I.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:o(`statusPanel.pipelinePartialTooltip`),children:o(`statusPanel.pipelinePartial`,{count:r.nullCostCount??0})})]}),l.length>0&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.filesModified`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>(0,I.jsx)(`code`,{className:`text-[10px] font-mono bg-muted/30 px-2 py-0.5 rounded text-cyan-400/80 aurora-light:text-accent-info`,children:e},e))})]})]})})]})}function H({label:e,value:t,valueClass:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:O(`text-sm font-semibold tabular-nums mt-0.5`,n),children:t})]})}function U({label:e,value:t,valueClass:n,naCaption:r}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:O(`text-sm font-semibold tabular-nums mt-0.5`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:r})]})}function W({label:e,caption:t,tooltip:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 ring-1 ring-accent-info/10`,title:n,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[e,(0,I.jsx)(h,{className:`w-2.5 h-2.5 text-muted-foreground/30`,"aria-hidden":`true`})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-muted-foreground/40`,children:`—`}),(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:t})]})}var G=4;function re({tickets:e,onTicketClick:t}){let{t:n}=g(`jobs`),[r,i]=(0,F.useState)(!1);if(e.length===0)return null;let a=e.length>=G&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,I.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-card/40 px-4 py-3 space-y-1.5`,children:[a.map(e=>(0,I.jsx)(K,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showMore`,{count:o}),(0,I.jsx)(D,{className:`w-3 h-3`})]}),r&&e.length>=G&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showLess`),(0,I.jsx)(w,{className:`w-3 h-3`})]})]})}function K({ticket:e,onClick:t}){let{t:n}=g(`jobs`),r=e.title==null,i=`inline-flex items-center px-1.5 py-0.5 rounded-md text-[11px] font-mono tabular-nums shrink-0`;return r?(0,I.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,I.jsx)(`span`,{className:O(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,I.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 min-w-0 w-full text-left group`,title:e.title??void 0,children:[(0,I.jsxs)(`span`,{className:O(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,I.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}var q={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`}};function J(){let{t:e}=g(`jobs`),{id:s}=y(),{activeProjectId:c,projects:d}=ne(),m=d.find(e=>e.id===c)?.provider,h=u(),{openTicketDetail:_}=M(),[w,T]=(0,F.useState)(null),[D,k]=(0,F.useState)([]),[L,R]=(0,F.useState)([]),[z,B]=(0,F.useState)({}),[H,U]=(0,F.useState)([]),[W,G]=(0,F.useState)(!0),[K,J]=(0,F.useState)(!1);(0,F.useEffect)(()=>{if(!s)return;let e=new AbortController;T(null),k([]),R([]),B({}),G(!0),J(!1);async function t(){try{let t=await fetch(`${A()}/jobs/${s}`,{signal:e.signal});if(t.status===404){J(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();T(n.job),k(n.events)}catch(e){if(e.name===`AbortError`)return;J(!0)}finally{e.signal.aborted||G(!1)}}return t(),()=>e.abort()},[s,c]),(0,F.useEffect)(()=>{if(!w?.pipeline_id){U([]);return}let e=w.pipeline_id;fetch(`${A()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&U(e.jobs)}).catch(()=>{})},[w?.pipeline_id,w?.status]);let Y=(0,F.useRef)(c);Y.current=c;let ie=(0,F.useRef)(null);ie.current=w?.status??null;let X=(0,F.useRef)([]),Z=(0,F.useRef)(null),ae=(0,F.useCallback)(()=>{Z.current=null;let e=X.current;e.length!==0&&(X.current=[],k(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]),Q=(0,F.useCallback)(e=>{let t=X.current;t.push(e),t.length>1e4&&(X.current=t.slice(-8e3)),Z.current||=requestAnimationFrame(ae)},[ae]);(0,F.useEffect)(()=>()=>{Z.current&&cancelAnimationFrame(Z.current)},[]);let oe=(0,F.useCallback)(e=>{let t=e;if(!(Y.current&&t.projectId&&t.projectId!==Y.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];R(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;B(n)}else if(t.type===`event`&&t.jobId===s)Q({id:Date.now(),job_id:s??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp});else if(t.type===`log`&&t.processId===s)Q({id:Date.now(),job_id:s??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp});else if(t.type===`job.finalized`&&t.jobId===s)fetch(`${A()}/jobs/${s}`).then(e=>e.json()).then(e=>T(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;B(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===s);if(e){let t=e.status,n=ie.current;T(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&n!==`running`)&&fetch(`${A()}/jobs/${s}`).then(e=>e.json()).then(e=>T(e.job)).catch(()=>{})}}}},[s,Q]),{registerHandler:se,unregisterHandler:ce}=v();(0,F.useEffect)(()=>(se(`job-detail-${s}`,oe),()=>ce(`job-detail-${s}`)),[s,oe,se,ce]),(0,F.useEffect)(()=>{if(!s||!w||w.status!==`running`||w.hasTelemetry)return;let e=setInterval(()=>{fetch(`${A()}/jobs/${s}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&T(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[s,w?.status,w?.hasTelemetry]);async function le(){if(!s)return;let n=await t({projectId:null,jobId:s});n.ok?n.status===`deleted`?(f.success(e(`detail.toast.jobDeleted`)),h(`/jobs`)):f.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):n.httpStatus===null?f.error(e(`detail.toast.networkError`)):f.error(e(`detail.toast.failed`),{description:n.error})}async function ue(){if(w)try{let t=await fetch(`${A()}/jobs/${w.id}/diagnostic`);if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`detail.toast.exportFailedHttp`,{status:t.status}))}let n=await t.blob(),r=URL.createObjectURL(n),i=new Date().toISOString().slice(0,10),a=document.createElement(`a`);a.href=r,a.download=`specrails-diagnostic-${w.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){f.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function de(){if(w)try{let t=await fetch(`${A()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({command:w.command})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));f.success(e(`detail.toast.jobRequeued`)),h(`/jobs/${n.jobId}`)}catch(e){f.error(e.message)}}if(W)return(0,I.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,I.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,I.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(K||!w)return(0,I.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:s})}),(0,I.jsx)(E,{asChild:!0,variant:`outline`,size:`sm`,children:(0,I.jsxs)(b,{to:`/`,children:[(0,I.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let $=q[w.status]??q.queued,fe=w.status===`running`,pe=w.status===`completed`||w.status===`failed`,me=!!w.interactive,he=me&&fe,ge=(w.tickets?.length??0)>0,_e=w.command.startsWith(`loop:`),ve=H.length>1?{totalCostUsd:H.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:H.some(e=>e.total_cost_usd==null),costEstimated:H.some(e=>!!e.total_cost_usd_estimated),nullCostCount:H.filter(e=>e.total_cost_usd==null).length,totalTokensIn:H.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:H.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:H.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:H.reduce((e,t)=>e+(t.tokens_cache_create??0),0),jobCount:H.length}:null;return(0,I.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,I.jsxs)(`div`,{className:`px-4 py-4 border-b border-border space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,I.jsxs)(b,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,I.jsx)(p,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,I.jsx)(S,{className:`w-3 h-3`}),(0,I.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:s?.slice(0,8)})})]}),ge&&(0,I.jsx)(re,{tickets:w.tickets??[],onTicketClick:_}),(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(te,{variant:$.variant,children:e($.labelKey)})})}),(0,I.jsx)(o,{children:e($.tooltipKey)})]}),(0,I.jsx)(`code`,{className:O(`font-mono text-foreground/90 truncate`,ge?`text-xs text-muted-foreground`:`text-sm`),children:P(w.command,m)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,I.jsx)(`span`,{children:w.started_at?e(`detail.startedAgo`,{timeAgo:ee(new Date(w.started_at),{addSuffix:!0,locale:C()})}):e(`detail.queuedWaiting`)}),w.model&&(0,I.jsx)(`span`,{className:`text-muted-foreground/40`,children:w.model})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[w.hasTelemetry&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsxs)(E,{variant:`outline`,size:`sm`,className:`h-7`,onClick:ue,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,I.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,I.jsx)(o,{children:e(`detail.exportDiagnosticTooltip`)})]}),pe&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsxs)(E,{variant:`outline`,size:`sm`,onClick:de,className:`h-7`,children:[(0,I.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,I.jsx)(o,{children:e(`detail.reExecuteTooltip`)})]}),fe&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:le,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(me?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,I.jsx)(o,{children:e(`detail.cancelJobTooltip`)})]})]})]}),(0,I.jsx)(n,{phases:z,phaseDefinitions:L})]}),(w.status===`running`||w.status===`completed`||w.status===`failed`)&&(0,I.jsx)(V,{job:w,events:D,defaultOpen:w.status===`completed`||w.status===`running`,pipelineTotals:ve??void 0,phases:z,phaseDefinitions:L}),(0,I.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:_e?(0,I.jsx)(r,{events:D,jobStatus:w.status,variant:`page`}):(0,I.jsx)(i,{events:D})}),he&&(0,I.jsx)(a,{jobId:w.id,settleMode:w.interactiveSettleMode,initialAcceptingTurns:w.interactiveAcceptingTurns,kind:w.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{J as default};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{a as t,i as n,n as r,r as i,t as a}from"./InteractiveJobComposer-DqDCiCa0.js";import{B as o,C as s,Cn as c,H as l,Hn as u,Kn as d,Ln as f,Lt as p,Pt as m,Qt as h,Rn as g,S as _,Sn as v,Un as y,Vn as b,Xt as x,an as S,b as ee,bn as C,in as w,nn as T,nt as E,on as D,rt as O,tn as k,tt as te,vn as ne,wn as A,xt as j,y as M,z as N}from"./index-Dw1N2-ci.js";import{t as P}from"./format-command-CuWuRvka.js";var F=e(d(),1),I=c();function L(e,t){let n=(typeof t==`number`?t:new Date(t).getTime())-new Date(e).getTime();if(!Number.isFinite(n)||n<0)return`—`;let r=Math.round(n/1e3);if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return i<60?`${i}m ${a}s`:`${Math.floor(i/60)}h ${i%60}m`}function R(e){let t=new Set;for(let n of e)if(n.event_type===`log`)try{let e=(JSON.parse(n.payload).line??``).match(/(?:Writing|Editing|Created?|Updated?)\s+(?:file:\s*)?([\w./\-]+\.\w+)/i);e&&t.add(e[1])}catch{}return Array.from(t).slice(0,20)}var z={steps:0,actionKey:``,actionArg:``,lastSeenIdx:0};function B(e,t){if(t.type===`reset`)return z;if(t.type===`consume`){let{events:n}=t,r=e.lastSeenIdx>n.length?n.length:e.lastSeenIdx;if(n.length<=r)return r===e.lastSeenIdx?e:{...e,lastSeenIdx:r};let{steps:i,actionKey:a,actionArg:o}=e;for(let e=r;e<n.length;e++){let t=s(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``)}return{steps:i,actionKey:a,actionArg:o,lastSeenIdx:n.length}}return e}function V({job:e,events:t,defaultOpen:n=!0,pipelineTotals:r,phases:i,phaseDefinitions:a}){let{t:o}=g(`jobs`),[s,c]=(0,F.useState)(n),l=(0,F.useMemo)(()=>R(t),[t]),u=e.status===`running`,d=e.status===`completed`,[f,p]=(0,F.useState)(()=>Date.now());(0,F.useEffect)(()=>{if(!u)return;let e=window.setInterval(()=>p(Date.now()),1e3);return()=>window.clearInterval(e)},[u]);let[h,v]=(0,F.useReducer)(B,z),y=(0,F.useRef)(e.id);(0,F.useEffect)(()=>{y.current!==e.id&&(y.current=e.id,v({type:`reset`})),v({type:`consume`,events:t})},[e.id,t]);let[b,x]=(0,F.useState)(!0);(0,F.useEffect)(()=>{if(!u)return;x(!0);let e=window.setTimeout(()=>x(!1),8e3);return()=>window.clearTimeout(e)},[u,e.id]);let S=e.finished_at?L(e.started_at,e.finished_at):u?L(e.started_at,f):`—`,ee=!!e.total_cost_usd_estimated,C=e.total_cost_usd==null?null:`${ee?`~`:``}$${e.total_cost_usd.toFixed(4)}`,w=e.num_turns==null?null:String(e.num_turns),E=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),te=E==null?null:`${(E/1e3).toFixed(1)}k`,ne=(0,F.useMemo)(()=>!i||!a?null:a.find(e=>i[e.key]===`running`)?.label??null,[i,a]),A=u&&h.steps===0?`connecting`:h.actionKey||`thinking`,j=_.has(A)&&h.actionArg!==``,M=_.has(A)&&!j?`working`:A,N=j?o(`statusPanel.activity.${M}`,{arg:h.actionArg}):o(`statusPanel.activity.${M}`),P=ne??(u&&h.steps===0?o(`statusPanel.activity.starting`):null),V=h.steps>0?o(`statusPanel.steps`,{count:h.steps}):null,G=o(u?`statusPanel.inProgress`:d?`statusPanel.completed`:`statusPanel.failed`),re=u?`border-accent-info/20 bg-accent-info/5`:d?`border-emerald-500/20 aurora-light:border-accent-success/30 bg-emerald-500/5 aurora-light:bg-accent-success/5`:`border-red-500/20 aurora-light:border-destructive/30 bg-red-500/5 aurora-light:bg-destructive/5`,K=u?m:d?T:k,q=u?`w-4 h-4 text-accent-info shrink-0 animate-spin`:d?`w-4 h-4 text-emerald-400 aurora-light:text-accent-success shrink-0`:`w-4 h-4 text-red-400 aurora-light:text-destructive shrink-0`;return(0,I.jsxs)(`div`,{className:O(`mx-4 my-2 rounded-xl border transition-colors duration-500`,re),children:[(0,I.jsxs)(`button`,{type:`button`,onClick:()=>c(!s),className:`w-full flex items-center gap-3 px-4 py-3`,children:[(0,I.jsx)(K,{className:q,"aria-hidden":`true`}),(0,I.jsx)(`span`,{className:`text-sm font-semibold flex-1 text-left`,children:G}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`tabular-nums`,children:S}),u?V&&(0,I.jsx)(`span`,{className:`tabular-nums`,children:V}):(0,I.jsxs)(I.Fragment,{children:[C&&(0,I.jsx)(`span`,{className:`tabular-nums text-yellow-400 aurora-light:text-accent-warning`,children:C}),l.length>0&&(0,I.jsx)(`span`,{children:o(`statusPanel.filesCount`,{count:l.length})})]})]}),(0,I.jsx)(D,{className:O(`w-4 h-4 text-muted-foreground/40 transition-transform duration-150 shrink-0`,s&&`rotate-180`)})]}),s&&(0,I.jsx)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/20`,children:u?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneInProgress`)}),(0,I.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 sm:items-stretch`,children:[(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 sm:w-44 shrink-0`,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[o(`statusPanel.duration`),(0,I.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,title:o(`statusPanel.liveTooltip`),"aria-label":o(`statusPanel.liveTooltip`)})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-accent-info`,children:S})]}),(0,I.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 bg-muted/10 rounded-lg px-3 py-2 min-w-0`,children:[(0,I.jsx)(m,{className:`w-3.5 h-3.5 text-accent-info shrink-0 animate-spin`,"aria-hidden":`true`}),P&&(0,I.jsx)(`span`,{className:`text-[11px] font-medium px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info shrink-0`,children:P}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1 min-w-0`,children:N}),V&&(0,I.jsxs)(`span`,{className:`text-[11px] text-muted-foreground/60 tabular-nums shrink-0`,children:[`· `,V]})]})]}),b&&(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground/40 leading-snug`,children:o(`statusPanel.explainer`)}),(0,I.jsx)(`p`,{className:`pt-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider border-t border-accent-info/10 mt-1`,children:o(`statusPanel.zoneFinalPending`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,I.jsx)(W,{label:o(`statusPanel.cost`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.costTooltip`)}),(0,I.jsx)(W,{label:o(`statusPanel.turns`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)}),(0,I.jsx)(W,{label:o(`statusPanel.tokens`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)})]})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneFinal`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[(0,I.jsx)(H,{label:o(`statusPanel.duration`),value:S}),(0,I.jsx)(U,{label:o(`statusPanel.cost`),value:C,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(U,{label:o(`statusPanel.turns`),value:w,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(U,{label:o(`statusPanel.tokens`),value:te,naCaption:o(`statusPanel.notAvailable`)})]}),r&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.pipelineTotal`,{count:r.jobCount})}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(H,{label:o(`statusPanel.totalCost`),value:`${r.costEstimated?`~`:``}${r.hasNullCost?`≥`:``}$${r.totalCostUsd.toFixed(4)}`,valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,I.jsx)(H,{label:o(`statusPanel.totalTokens`),value:`${((r.totalTokensIn+r.totalTokensOut+r.totalTokensCacheRead+r.totalTokensCacheCreate)/1e3).toFixed(1)}k`})]}),r.hasNullCost&&(0,I.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:o(`statusPanel.pipelinePartialTooltip`),children:o(`statusPanel.pipelinePartial`,{count:r.nullCostCount??0})})]}),l.length>0&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.filesModified`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>(0,I.jsx)(`code`,{className:`text-[10px] font-mono bg-muted/30 px-2 py-0.5 rounded text-cyan-400/80 aurora-light:text-accent-info`,children:e},e))})]})]})})]})}function H({label:e,value:t,valueClass:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:O(`text-sm font-semibold tabular-nums mt-0.5`,n),children:t})]})}function U({label:e,value:t,valueClass:n,naCaption:r}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:O(`text-sm font-semibold tabular-nums mt-0.5`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:r})]})}function W({label:e,caption:t,tooltip:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 ring-1 ring-accent-info/10`,title:n,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[e,(0,I.jsx)(h,{className:`w-2.5 h-2.5 text-muted-foreground/30`,"aria-hidden":`true`})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-muted-foreground/40`,children:`—`}),(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:t})]})}var G=4;function re({tickets:e,onTicketClick:t}){let{t:n}=g(`jobs`),[r,i]=(0,F.useState)(!1);if(e.length===0)return null;let a=e.length>=G&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,I.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-card/40 px-4 py-3 space-y-1.5`,children:[a.map(e=>(0,I.jsx)(K,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showMore`,{count:o}),(0,I.jsx)(D,{className:`w-3 h-3`})]}),r&&e.length>=G&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showLess`),(0,I.jsx)(w,{className:`w-3 h-3`})]})]})}function K({ticket:e,onClick:t}){let{t:n}=g(`jobs`),r=e.title==null,i=`inline-flex items-center px-1.5 py-0.5 rounded-md text-[11px] font-mono tabular-nums shrink-0`;return r?(0,I.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,I.jsx)(`span`,{className:O(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,I.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 min-w-0 w-full text-left group`,title:e.title??void 0,children:[(0,I.jsxs)(`span`,{className:O(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,I.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}var q={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`}};function J(){let{t:e}=g(`jobs`),{id:s}=y(),{activeProjectId:c,projects:d}=ne(),m=d.find(e=>e.id===c)?.provider,h=u(),{openTicketDetail:_}=M(),[w,T]=(0,F.useState)(null),[D,k]=(0,F.useState)([]),[L,R]=(0,F.useState)([]),[z,B]=(0,F.useState)({}),[H,U]=(0,F.useState)([]),[W,G]=(0,F.useState)(!0),[K,J]=(0,F.useState)(!1);(0,F.useEffect)(()=>{if(!s)return;let e=new AbortController;T(null),k([]),R([]),B({}),G(!0),J(!1);async function t(){try{let t=await fetch(`${A()}/jobs/${s}`,{signal:e.signal});if(t.status===404){J(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();T(n.job),k(n.events)}catch(e){if(e.name===`AbortError`)return;J(!0)}finally{e.signal.aborted||G(!1)}}return t(),()=>e.abort()},[s,c]),(0,F.useEffect)(()=>{if(!w?.pipeline_id){U([]);return}let e=w.pipeline_id;fetch(`${A()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&U(e.jobs)}).catch(()=>{})},[w?.pipeline_id,w?.status]);let Y=(0,F.useRef)(c);Y.current=c;let ie=(0,F.useRef)(null);ie.current=w?.status??null;let X=(0,F.useRef)([]),Z=(0,F.useRef)(null),ae=(0,F.useCallback)(()=>{Z.current=null;let e=X.current;e.length!==0&&(X.current=[],k(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]),Q=(0,F.useCallback)(e=>{let t=X.current;t.push(e),t.length>1e4&&(X.current=t.slice(-8e3)),Z.current||=requestAnimationFrame(ae)},[ae]);(0,F.useEffect)(()=>()=>{Z.current&&cancelAnimationFrame(Z.current)},[]);let oe=(0,F.useCallback)(e=>{let t=e;if(!(Y.current&&t.projectId&&t.projectId!==Y.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];R(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;B(n)}else if(t.type===`event`&&t.jobId===s)Q({id:Date.now(),job_id:s??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp});else if(t.type===`log`&&t.processId===s)Q({id:Date.now(),job_id:s??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp});else if(t.type===`job.finalized`&&t.jobId===s)fetch(`${A()}/jobs/${s}`).then(e=>e.json()).then(e=>T(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;B(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===s);if(e){let t=e.status,n=ie.current;T(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&n!==`running`)&&fetch(`${A()}/jobs/${s}`).then(e=>e.json()).then(e=>T(e.job)).catch(()=>{})}}}},[s,Q]),{registerHandler:se,unregisterHandler:ce}=v();(0,F.useEffect)(()=>(se(`job-detail-${s}`,oe),()=>ce(`job-detail-${s}`)),[s,oe,se,ce]),(0,F.useEffect)(()=>{if(!s||!w||w.status!==`running`||w.hasTelemetry)return;let e=setInterval(()=>{fetch(`${A()}/jobs/${s}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&T(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[s,w?.status,w?.hasTelemetry]);async function le(){if(!s)return;let n=await t({projectId:null,jobId:s});n.ok?n.status===`deleted`?(f.success(e(`detail.toast.jobDeleted`)),h(`/jobs`)):f.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):n.httpStatus===null?f.error(e(`detail.toast.networkError`)):f.error(e(`detail.toast.failed`),{description:n.error})}async function ue(){if(w)try{let t=await fetch(`${A()}/jobs/${w.id}/diagnostic`);if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`detail.toast.exportFailedHttp`,{status:t.status}))}let n=await t.blob(),r=URL.createObjectURL(n),i=new Date().toISOString().slice(0,10),a=document.createElement(`a`);a.href=r,a.download=`specrails-diagnostic-${w.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){f.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function de(){if(w)try{let t=await fetch(`${A()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({command:w.command})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));f.success(e(`detail.toast.jobRequeued`)),h(`/jobs/${n.jobId}`)}catch(e){f.error(e.message)}}if(W)return(0,I.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,I.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,I.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(K||!w)return(0,I.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:s})}),(0,I.jsx)(E,{asChild:!0,variant:`outline`,size:`sm`,children:(0,I.jsxs)(b,{to:`/`,children:[(0,I.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let $=q[w.status]??q.queued,fe=w.status===`running`,pe=w.status===`completed`||w.status===`failed`,me=!!w.interactive,he=me&&fe,ge=(w.tickets?.length??0)>0,_e=w.command.startsWith(`loop:`),ve=H.length>1?{totalCostUsd:H.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:H.some(e=>e.total_cost_usd==null),costEstimated:H.some(e=>!!e.total_cost_usd_estimated),nullCostCount:H.filter(e=>e.total_cost_usd==null).length,totalTokensIn:H.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:H.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:H.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:H.reduce((e,t)=>e+(t.tokens_cache_create??0),0),jobCount:H.length}:null;return(0,I.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,I.jsxs)(`div`,{className:`px-4 py-4 border-b border-border space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,I.jsxs)(b,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,I.jsx)(p,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,I.jsx)(S,{className:`w-3 h-3`}),(0,I.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:s?.slice(0,8)})})]}),ge&&(0,I.jsx)(re,{tickets:w.tickets??[],onTicketClick:_}),(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(te,{variant:$.variant,children:e($.labelKey)})})}),(0,I.jsx)(o,{children:e($.tooltipKey)})]}),(0,I.jsx)(`code`,{className:O(`font-mono text-foreground/90 truncate`,ge?`text-xs text-muted-foreground`:`text-sm`),children:P(w.command,m)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,I.jsx)(`span`,{children:w.started_at?e(`detail.startedAgo`,{timeAgo:ee(new Date(w.started_at),{addSuffix:!0,locale:C()})}):e(`detail.queuedWaiting`)}),w.model&&(0,I.jsx)(`span`,{className:`text-muted-foreground/40`,children:w.model})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[w.hasTelemetry&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsxs)(E,{variant:`outline`,size:`sm`,className:`h-7`,onClick:ue,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,I.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,I.jsx)(o,{children:e(`detail.exportDiagnosticTooltip`)})]}),pe&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsxs)(E,{variant:`outline`,size:`sm`,onClick:de,className:`h-7`,children:[(0,I.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,I.jsx)(o,{children:e(`detail.reExecuteTooltip`)})]}),fe&&(0,I.jsxs)(N,{children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:le,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(me?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,I.jsx)(o,{children:e(`detail.cancelJobTooltip`)})]})]})]}),(0,I.jsx)(n,{phases:z,phaseDefinitions:L})]}),(w.status===`running`||w.status===`completed`||w.status===`failed`)&&(0,I.jsx)(V,{job:w,events:D,defaultOpen:w.status===`completed`||w.status===`running`,pipelineTotals:ve??void 0,phases:z,phaseDefinitions:L}),(0,I.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:_e?(0,I.jsx)(r,{events:D,jobStatus:w.status,variant:`page`}):(0,I.jsx)(i,{events:D})}),he&&(0,I.jsx)(a,{jobId:w.id,settleMode:w.interactiveSettleMode,initialAcceptingTurns:w.interactiveAcceptingTurns,kind:w.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{J as default};