specrails-desktop 2.35.0 → 2.36.0

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 (51) hide show
  1. package/client/dist/assets/{ActivityFeedPage-LCBJ5WiD.js → ActivityFeedPage-tAQcWs1R.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-B-xQpyZr.js → AgentBrowserCapture-BX8BNae5.js} +1 -1
  3. package/client/dist/assets/{AgentModeAnalyticsPane-BI1Vcf3T.js → AgentModeAnalyticsPane-BVAqCL0K.js} +2 -2
  4. package/client/dist/assets/{AgentModeCodePane-BTRwCl9h.js → AgentModeCodePane-9XfqQc9c.js} +2 -2
  5. package/client/dist/assets/{AgentModeJobsPane-VzeBJLqP.js → AgentModeJobsPane-BCjLsPhc.js} +1 -1
  6. package/client/dist/assets/{AgentsPage-CJj1K24O.js → AgentsPage-C8J_42sm.js} +1 -1
  7. package/client/dist/assets/{AnalyticsPage-CQpV5_fX.js → AnalyticsPage-BtQuyfJm.js} +1 -1
  8. package/client/dist/assets/{CodePage-9-tFh0jB.js → CodePage-BZ2MwdCu.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-BcZ0_O_C.js → DesktopAnalyticsPage-Bh_29V4g.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-BPAzDICW.js → DocsDialog-C76VdBJC.js} +1 -1
  11. package/client/dist/assets/{DocsPage-Dqo4Hn6G.js → DocsPage-ziMlj6B6.js} +1 -1
  12. package/client/dist/assets/{InteractiveJobComposer-D36fZWai.js → InteractiveJobComposer-BCZiSfzc.js} +1 -1
  13. package/client/dist/assets/{JobDetailModal-BxsktbkQ.js → JobDetailModal-NAJmuYIT.js} +1 -1
  14. package/client/dist/assets/{JobDetailPage-WWyCy6Sp.js → JobDetailPage-fE0ZycUX.js} +1 -1
  15. package/client/dist/assets/{JobsPage-CEbM7uxU.js → JobsPage-z5M_HVJG.js} +1 -1
  16. package/client/dist/assets/{LoopBuilderPage-CYsSN8io.js → LoopBuilderPage-j1FQS47c.js} +1 -1
  17. package/client/dist/assets/{LoopPreviewModal-BJhgX5wY.js → LoopPreviewModal-DhDJjdCe.js} +1 -1
  18. package/client/dist/assets/{LoopsPage-DB4OqMot.js → LoopsPage-Ll7zORZb.js} +1 -1
  19. package/client/dist/assets/{MinimizedChatsContext-CcjBHMHd.js → MinimizedChatsContext-Bd3OqR_S.js} +1 -1
  20. package/client/dist/assets/{PluginsPage-CR8K4nM_.js → PluginsPage-DN4kGvJt.js} +1 -1
  21. package/client/dist/assets/{ProjectSettingsDialog-C45-qhF4.js → ProjectSettingsDialog-OgsgxjzF.js} +1 -1
  22. package/client/dist/assets/{ReviewPacketPage-Cz_QQeC3.js → ReviewPacketPage-DFog4sXn.js} +1 -1
  23. package/client/dist/assets/{TemplatePreviewModal-wFBd2vQP.js → TemplatePreviewModal-L2XxqiOD.js} +1 -1
  24. package/client/dist/assets/{TicketDetailModal-BvZoyDAL.js → TicketDetailModal-CsF-AWZX.js} +1 -1
  25. package/client/dist/assets/{Trans-DXZ-BLXb.js → Trans-Bsz9_gyq.js} +1 -1
  26. package/client/dist/assets/{formatDistanceToNow-C0ImhVKp.js → formatDistanceToNow-DQCvMgUc.js} +1 -1
  27. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-owhDdTXs.js → getTimezoneOffsetInMilliseconds-C16cxSe1.js} +1 -1
  28. package/client/dist/assets/{i18n-DwgvwTnx.js → i18n-hnX2DPmo.js} +2 -2
  29. package/client/dist/assets/{index-DhjjFyU5.js → index-DIhMEAVw.js} +14 -14
  30. package/client/dist/assets/index-DwygcU7s.css +2 -0
  31. package/client/dist/assets/{jira-api-CcZMcEN5.js → jira-api-B1-MUehg.js} +1 -1
  32. package/client/dist/assets/{mcp-DsTwmjST.js → mcp-B8X8wBLu.js} +1 -1
  33. package/client/dist/assets/{mcp-SMkn8boG.js → mcp-C2AojZZN.js} +1 -1
  34. package/client/dist/assets/mcp-D8BT78_L.js +1 -0
  35. package/client/dist/assets/{mcp-D4ZjtIx3.js → mcp-Df5RWBNk.js} +1 -1
  36. package/client/dist/assets/{mcp-DIfBUv2D.js → mcp-Dj7BgMQW.js} +1 -1
  37. package/client/dist/assets/{mcp-D2pc5GGx.js → mcp-Q7iT7rcz.js} +1 -1
  38. package/client/dist/assets/{mcp-fSfiVYAc.js → mcp-YlvNvJbW.js} +1 -1
  39. package/client/dist/assets/{mcp-Czd_iyp0.js → mcp-mKFpTSRb.js} +1 -1
  40. package/client/dist/assets/{spending-BQX3P7Cq.js → spending-EC9xqio-.js} +1 -1
  41. package/client/dist/assets/{useDesktop-BzX769yH.js → useDesktop-BQVt8lFd.js} +1 -1
  42. package/client/dist/index.html +12 -12
  43. package/docs/mcp.md +16 -0
  44. package/package.json +1 -1
  45. package/server/dist/agent-chat-manager.js +2 -0
  46. package/server/dist/agent-mcp-config.js +94 -2
  47. package/server/dist/agent-operator-prompt.js +4 -0
  48. package/server/dist/desktop-router.js +22 -0
  49. package/server/dist/external-mcp.js +370 -0
  50. package/client/dist/assets/index-xBFsOEiJ.css +0 -2
  51. package/client/dist/assets/mcp-uDkXYu4L.js +0 -1
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{o as r,w as i}from"./i18n-DwgvwTnx.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s}from"./dist-bVqfYmby.js";import{X as c,at as l,it as u}from"./TicketDetailModal-BvZoyDAL.js";import{d,u as f}from"./MinimizedChatsContext-CcjBHMHd.js";import{t as p}from"./brain-DI9lHkKY.js";import{n as m}from"./file-text-BcLCfcWZ.js";import{t as h}from"./circle-x-CMYsN4ZH.js";import{t as g}from"./git-branch-BRM0F5GN.js";import{t as _}from"./loader-circle-DcygOQpC.js";import{t as v}from"./play-DNlrawbS.js";import{t as y}from"./search-Cq_gE3Ik.js";import{t as b}from"./triangle-alert-H9T4jAmh.js";import{t as x}from"./x-CBMI9ejn.js";import{a as S}from"./auth-D_5bQv5W.js";import{a as C,r as w}from"./useDesktop-BzX769yH.js";import{t as T}from"./button-CJqFnUOL.js";import{t as E}from"./utils-BC4DHlz2.js";import{n as D,t as O}from"./lib-CGdyxIWg.js";import{C as k,Et as A,I as j,N as M,Ot as N,P,Q as F,S as ee,St as te,Tt as I,_ as L,at as R,c as z,et as ne,gt as re,l as ie,o as ae,ot as oe,s as se,st as ce}from"./index-DhjjFyU5.js";import{t as le}from"./lib-C7Mhm-gT.js";var ue=o(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),de=o(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),fe=o(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),pe=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`}]]),B=n();function me({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,B.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let i=e[n.key]??`idle`,a=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,B.jsxs)(`div`,{className:`flex items-center`,children:[(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,B.jsx)(he,{state:i}),(0,B.jsx)(`span`,{className:E(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,B.jsxs)(P,{side:`bottom`,className:`max-w-[200px]`,children:[(0,B.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,B.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,B.jsx)(`div`,{className:E(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,a===`done`||i===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:a===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function he({state:e}){return(0,B.jsxs)(`div`,{className:E(`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,B.jsx)(_,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,B.jsx)(N,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,B.jsx)(h,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,B.jsx)(u,{className:`w-6 h-6 text-muted-foreground/20`})]})}var V=e(t(),1);function ge(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 _e=new Set;function ve({ticketId:e,onOpen:t,children:n}){let{t:r}=a(`agent`),i=r(`refs.openTicket`,{id:e});return(0,B.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 ye(e){if(!e.includes(`#`))return null;let t=z(e,_e);return t.some(e=>e.kind===`ticket`)?t:null}function be(e,t){let n=ye(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,B.jsx)(ve,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,B.jsx)(V.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var xe=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function Se(e){return e.kind===`ticket`?{type:`link`,url:ae({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function Ce(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!xe.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=z(n.value,_e);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(Se))}else Ce(n)}}function we(){return e=>Ce(e)}function Te(e){let{activeProjectId:t}=w(),{openRef:n}=ie(),r=e??t??void 0;return(0,V.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function H(e,t){let n=`${e.id??t}`,i=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:i}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:i}:ge(t)?{id:n,content:t,type:`assistant`,timestamp:i}:{id:n,content:t,type:`plain`,timestamp:i}: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),a=[];return t.duration_ms&&a.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&a.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&a.push(r.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${r.t(`jobs:logViewer.completed`)}${a.length?` — ${a.join(` · `)}`:``}`,type:`result`,timestamp:i}}catch{return null}return null}function Ee(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 De(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+=`
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{o as r,w as i}from"./i18n-hnX2DPmo.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s}from"./dist-bVqfYmby.js";import{X as c,at as l,it as u}from"./TicketDetailModal-CsF-AWZX.js";import{d,u as f}from"./MinimizedChatsContext-Bd3OqR_S.js";import{t as p}from"./brain-DI9lHkKY.js";import{n as m}from"./file-text-BcLCfcWZ.js";import{t as h}from"./circle-x-CMYsN4ZH.js";import{t as g}from"./git-branch-BRM0F5GN.js";import{t as _}from"./loader-circle-DcygOQpC.js";import{t as v}from"./play-DNlrawbS.js";import{t as y}from"./search-Cq_gE3Ik.js";import{t as b}from"./triangle-alert-H9T4jAmh.js";import{t as x}from"./x-CBMI9ejn.js";import{a as S}from"./auth-D_5bQv5W.js";import{a as C,r as w}from"./useDesktop-BQVt8lFd.js";import{t as T}from"./button-CJqFnUOL.js";import{t as E}from"./utils-BC4DHlz2.js";import{n as D,t as O}from"./lib-CGdyxIWg.js";import{C as k,Et as A,I as j,N as M,Ot as N,P,Q as F,S as ee,St as te,Tt as I,_ as L,at as R,c as z,et as ne,gt as re,l as ie,o as ae,ot as oe,s as se,st as ce}from"./index-DIhMEAVw.js";import{t as le}from"./lib-C7Mhm-gT.js";var ue=o(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),de=o(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),fe=o(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),pe=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`}]]),B=n();function me({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,B.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let i=e[n.key]??`idle`,a=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,B.jsxs)(`div`,{className:`flex items-center`,children:[(0,B.jsxs)(M,{children:[(0,B.jsx)(j,{asChild:!0,children:(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,B.jsx)(he,{state:i}),(0,B.jsx)(`span`,{className:E(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,B.jsxs)(P,{side:`bottom`,className:`max-w-[200px]`,children:[(0,B.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,B.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,B.jsx)(`div`,{className:E(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,a===`done`||i===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:a===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function he({state:e}){return(0,B.jsxs)(`div`,{className:E(`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,B.jsx)(_,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,B.jsx)(N,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,B.jsx)(h,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,B.jsx)(u,{className:`w-6 h-6 text-muted-foreground/20`})]})}var V=e(t(),1);function ge(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 _e=new Set;function ve({ticketId:e,onOpen:t,children:n}){let{t:r}=a(`agent`),i=r(`refs.openTicket`,{id:e});return(0,B.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 ye(e){if(!e.includes(`#`))return null;let t=z(e,_e);return t.some(e=>e.kind===`ticket`)?t:null}function be(e,t){let n=ye(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,B.jsx)(ve,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,B.jsx)(V.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var xe=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function Se(e){return e.kind===`ticket`?{type:`link`,url:ae({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function Ce(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!xe.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=z(n.value,_e);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(Se))}else Ce(n)}}function we(){return e=>Ce(e)}function Te(e){let{activeProjectId:t}=w(),{openRef:n}=ie(),r=e??t??void 0;return(0,V.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function H(e,t){let n=`${e.id??t}`,i=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:i}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:i}:ge(t)?{id:n,content:t,type:`assistant`,timestamp:i}:{id:n,content:t,type:`plain`,timestamp:i}: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),a=[];return t.duration_ms&&a.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&a.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&a.push(r.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${r.t(`jobs:logViewer.completed`)}${a.length?` — ${a.join(` · `)}`:``}`,type:`result`,timestamp:i}}catch{return null}return null}function Ee(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 De(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
2
  `+n.content:t.push({...n})}return t}function Oe(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 ke({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=a(`jobs`),[o,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(!0),[d,p]=(0,V.useState)(new Set),m=(0,V.useRef)(null),h=(0,V.useRef)(null),g=Te(n),{processedLines:_,groups:v,totalLines:b}=(0,V.useMemo)(()=>{let t=Ee(De(e.map((e,t)=>H(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:Oe(t),totalLines:t.length}},[e,i.language]),x=(0,V.useMemo)(()=>{if(!o)return b;let e=o.toLowerCase();return _.filter(t=>t.content.toLowerCase().includes(e)).length},[o,_,b]),S=(0,V.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,V.useEffect)(()=>{l&&S()},[e.length,l,S]);function C(){let e=h.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;u(t)}function w(e){p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,B.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):b===0?(0,B.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,B.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,B.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,B.jsx)(y,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,B.jsx)(L,{placeholder:r(`logViewer.filterPlaceholder`),value:o,onChange:e=>c(e.target.value),className:`pl-7 h-7`})]}),(0,B.jsx)(T,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=_.map(e=>e.content).join(`
3
3
  `);navigator.clipboard.writeText(e).then(()=>{s.success(r(`logViewer.copySuccess`))}).catch(()=>{s.error(r(`logViewer.copyFailed`))})},children:(0,B.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:x,total:b})})]}),(0,B.jsxs)(`div`,{ref:h,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:C,children:[v.map(e=>(0,B.jsx)(Ae,{group:e,filter:o,collapsed:d.has(e.key),onToggle:()=>w(e.key),onOpenTicket:g},e.key)),(0,B.jsx)(`div`,{ref:m})]}),!l&&(0,B.jsxs)(T,{size:`sm`,variant:`secondary`,onClick:()=>{u(!0),S()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,B.jsx)(f,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var Ae=(0,V.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:o}=a(`jobs`),s=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return s.length===0?null:(0,B.jsx)(`div`,{children:s.map((e,t)=>(0,B.jsx)(U,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let c=e.header.content;return(0,B.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:r,className:E(`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,B.jsx)(m,{className:E(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,B.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:c}),e.header.timestamp&&(0,B.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,B.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,B.jsx)(`div`,{className:`bg-muted/5`,children:s.length===0?(0,B.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:o(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):s.map((e,t)=>(0,B.jsx)(U,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),je=[le],Me=[O],Ne=[O,we],U=(0,V.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,V.useMemo)(()=>l&&n?be(e.content,n):e.content,[l,n,e.content]),d=r&&n?Ne:Me,f=(0,V.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=se(e);return r?.kind===`ticket`?(0,B.jsx)(ve,{ticketId:r.ticketId,onOpen:n,children:t}):(0,B.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,B.jsxs)(`div`,{className:E(`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,B.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,B.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
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{a as i}from"./i18n-DwgvwTnx.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o}from"./dist-bVqfYmby.js";import{C as s,R as c}from"./TicketDetailModal-BvZoyDAL.js";import{a as l,i as ee,n as te,o as u,r as d,s as f,t as p}from"./InteractiveJobComposer-D36fZWai.js";import{t as ne}from"./loader-circle-DcygOQpC.js";import{t as re}from"./x-CBMI9ejn.js";import{a as ie,n as m}from"./auth-D_5bQv5W.js";import{a as ae}from"./useDesktop-BzX769yH.js";import{c as oe,s as se}from"./dialog-CdWCb02j.js";import{t as h}from"./button-CJqFnUOL.js";import{t as g}from"./formatDistanceToNow-C0ImhVKp.js";import{F as _,I as ce,L as v,N as y,P as le,i as ue,r as de}from"./index-DhjjFyU5.js";import{n as b,t as x}from"./job-time-BCL7wee9.js";var S=e(r(),1),C=e(t(),1),w=[1e3,2e3,4e3,8e3,16e3];function fe(e,t){let[n,r]=(0,C.useState)(`connecting`),i=(0,C.useRef)(null),a=(0,C.useRef)(0),o=(0,C.useRef)(null),s=(0,C.useRef)(t);s.current=t;let c=(0,C.useCallback)(()=>{let t=m(),n=t?new WebSocket(e,[`specrails-desktop`,t]):new WebSocket(e);i.current=n,r(`connecting`),n.onopen=()=>{a.current=0,r(`connected`)},n.onmessage=e=>{try{let t=JSON.parse(e.data);s.current(t)}catch{}},n.onclose=()=>{i.current=null;let e=a.current;if(e>=w.length){r(`disconnected`);return}let t=w[e];a.current+=1,o.current=setTimeout(c,t)}},[e]);return(0,C.useEffect)(()=>(c(),()=>{o.current&&clearTimeout(o.current);let e=i.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),i.current=null}),[c]),{connectionStatus:n}}var T=n();function pe(e,t){let n=b(e),r=b(t);if(!n||!r)return`—`;let i=r.getTime()-n.getTime();if(i<0)return`—`;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}var E={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 D({jobId:e,onClose:t,projectId:n}){let{t:r}=a(`jobs`),{t:m}=a(`narration`),w=(0,C.useCallback)(()=>n?`${ie}/api/projects/${n}`:ae(),[n]),[D,O]=(0,C.useState)(te),k=(0,C.useCallback)(e=>{O(e),d(e)},[]),[A,j]=(0,C.useState)(null),[M,N]=(0,C.useState)([]),[P,F]=(0,C.useState)([]),[I,L]=(0,C.useState)({}),[R,z]=(0,C.useState)(!0),[B,V]=(0,C.useState)(!1),[H,U]=(0,C.useState)(!1),[W,G]=(0,C.useState)(!1);(0,C.useEffect)(()=>{async function t(){try{let t=await fetch(`${w()}/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,w]);let K=(0,C.useCallback)(()=>{fetch(`${w()}/jobs/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[e,w]),q=(0,C.useRef)([]),J=(0,C.useRef)(null),Y=(0,C.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,C.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),fe(s,(0,C.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||n.type===`job.interactive`&&n.jobId===e||(n.type===`loop.run_paused`||n.type===`loop.run_resumed`)&&n.loopRunId===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&&A&&j(e=>e&&{...e,status:t.status})}},[e,A,Y,K])),(0,C.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let X=A?ue(A):`job`,Z=X===`loop-run`;async function me(){G(!0);try{let t=await de({projectId:n??null,jobId:e,kind:X});t.ok?(o.success(r(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:r(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):o.error(r(`modal.toast.cancelFailed`),{description:t.error})}finally{G(!1)}}let Q=A?E[A.status]??E.queued:E.queued,he=A?.status===`running`,$=A?b(x(A)):null,{panelRef:ge,panelStyle:_e,headerHandleProps:ve,resizeHandles:ye,isFloating:be,guardBackdrop:xe}=oe();return(0,S.createPortal)((0,T.jsx)(_,{delayDuration:400,children:(0,T.jsxs)(`div`,{className:`fixed inset-0 z-[65] flex items-stretch justify-center`,children:[(0,T.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:xe(t)}),(0,T.jsxs)(`div`,{ref:ge,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:_e,children:[(0,T.jsxs)(`div`,{...ve,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${be?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[A&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(y,{children:[(0,T.jsx)(ce,{asChild:!0,children:(0,T.jsx)(`div`,{children:(0,T.jsx)(v,{variant:Q.variant,children:r(Q.labelKey)})})}),(0,T.jsx)(le,{children:r(Q.tooltipKey)})]}),(0,T.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:A.command}),(0,T.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:$?g($,{addSuffix:!0,locale:i()}):`—`}),A.total_cost_usd!=null&&A.total_cost_usd>0&&(0,T.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,A.total_cost_usd.toFixed(4)]}),A.started_at&&A.finished_at&&(0,T.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:pe(A.started_at,A.finished_at)})]}),R&&(0,T.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`common:states.loading`)})]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[P.length>0&&(0,T.jsx)(`div`,{className:`mr-3`,children:(0,T.jsx)(f,{phases:I,phaseDefinitions:P})}),he&&(0,T.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,T.jsx)(ne,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),r(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}),(0,T.jsx)(`button`,{onClick:t,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,T.jsx)(re,{className:`w-4 h-4`})})]})]}),(0,T.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:B?(0,T.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`modal.notFound`)})}):c&&A?(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>k(e),"aria-pressed":D===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${D===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:m(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,T.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:D===`narrated`?(0,T.jsx)(ee,{events:M,settled:A.status!==`running`&&A.status!==`queued`,elapsedMs:A.duration_ms??null,variant:`glass`}):A.command.startsWith(`loop:`)?(0,T.jsx)(l,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n}):(0,T.jsx)(u,{events:M,isLoading:R,projectId:n})})]}):A?.command.startsWith(`loop:`)?(0,T.jsx)(l,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n}):(0,T.jsx)(u,{events:M,isLoading:R,projectId:n})}),!!A?.interactive&&A.status===`running`&&(0,T.jsx)(p,{jobId:e,projectId:n,settleMode:A.interactiveSettleMode,initialAcceptingTurns:A.interactiveAcceptingTurns,kind:A.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,T.jsx)(se,{handles:ye}),H&&(0,T.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,T.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,T.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,T.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:r(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,T.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:r(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,T.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,T.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:r(`modal.keepRunning`)}),(0,T.jsx)(h,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),me()},children:r(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{D as JobDetailModal};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{a as i}from"./i18n-hnX2DPmo.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o}from"./dist-bVqfYmby.js";import{C as s,R as c}from"./TicketDetailModal-CsF-AWZX.js";import{a as l,i as ee,n as te,o as u,r as d,s as f,t as p}from"./InteractiveJobComposer-BCZiSfzc.js";import{t as ne}from"./loader-circle-DcygOQpC.js";import{t as re}from"./x-CBMI9ejn.js";import{a as ie,n as m}from"./auth-D_5bQv5W.js";import{a as ae}from"./useDesktop-BQVt8lFd.js";import{c as oe,s as se}from"./dialog-CdWCb02j.js";import{t as h}from"./button-CJqFnUOL.js";import{t as g}from"./formatDistanceToNow-DQCvMgUc.js";import{F as _,I as ce,L as v,N as y,P as le,i as ue,r as de}from"./index-DIhMEAVw.js";import{n as b,t as x}from"./job-time-BCL7wee9.js";var S=e(r(),1),C=e(t(),1),w=[1e3,2e3,4e3,8e3,16e3];function fe(e,t){let[n,r]=(0,C.useState)(`connecting`),i=(0,C.useRef)(null),a=(0,C.useRef)(0),o=(0,C.useRef)(null),s=(0,C.useRef)(t);s.current=t;let c=(0,C.useCallback)(()=>{let t=m(),n=t?new WebSocket(e,[`specrails-desktop`,t]):new WebSocket(e);i.current=n,r(`connecting`),n.onopen=()=>{a.current=0,r(`connected`)},n.onmessage=e=>{try{let t=JSON.parse(e.data);s.current(t)}catch{}},n.onclose=()=>{i.current=null;let e=a.current;if(e>=w.length){r(`disconnected`);return}let t=w[e];a.current+=1,o.current=setTimeout(c,t)}},[e]);return(0,C.useEffect)(()=>(c(),()=>{o.current&&clearTimeout(o.current);let e=i.current;e&&(e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e.close()),i.current=null}),[c]),{connectionStatus:n}}var T=n();function pe(e,t){let n=b(e),r=b(t);if(!n||!r)return`—`;let i=r.getTime()-n.getTime();if(i<0)return`—`;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}var E={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 D({jobId:e,onClose:t,projectId:n}){let{t:r}=a(`jobs`),{t:m}=a(`narration`),w=(0,C.useCallback)(()=>n?`${ie}/api/projects/${n}`:ae(),[n]),[D,O]=(0,C.useState)(te),k=(0,C.useCallback)(e=>{O(e),d(e)},[]),[A,j]=(0,C.useState)(null),[M,N]=(0,C.useState)([]),[P,F]=(0,C.useState)([]),[I,L]=(0,C.useState)({}),[R,z]=(0,C.useState)(!0),[B,V]=(0,C.useState)(!1),[H,U]=(0,C.useState)(!1),[W,G]=(0,C.useState)(!1);(0,C.useEffect)(()=>{async function t(){try{let t=await fetch(`${w()}/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,w]);let K=(0,C.useCallback)(()=>{fetch(`${w()}/jobs/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[e,w]),q=(0,C.useRef)([]),J=(0,C.useRef)(null),Y=(0,C.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,C.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),fe(s,(0,C.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||n.type===`job.interactive`&&n.jobId===e||(n.type===`loop.run_paused`||n.type===`loop.run_resumed`)&&n.loopRunId===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&&A&&j(e=>e&&{...e,status:t.status})}},[e,A,Y,K])),(0,C.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let X=A?ue(A):`job`,Z=X===`loop-run`;async function me(){G(!0);try{let t=await de({projectId:n??null,jobId:e,kind:X});t.ok?(o.success(r(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:r(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):o.error(r(`modal.toast.cancelFailed`),{description:t.error})}finally{G(!1)}}let Q=A?E[A.status]??E.queued:E.queued,he=A?.status===`running`,$=A?b(x(A)):null,{panelRef:ge,panelStyle:_e,headerHandleProps:ve,resizeHandles:ye,isFloating:be,guardBackdrop:xe}=oe();return(0,S.createPortal)((0,T.jsx)(_,{delayDuration:400,children:(0,T.jsxs)(`div`,{className:`fixed inset-0 z-[65] flex items-stretch justify-center`,children:[(0,T.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:xe(t)}),(0,T.jsxs)(`div`,{ref:ge,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:_e,children:[(0,T.jsxs)(`div`,{...ve,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${be?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[A&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(y,{children:[(0,T.jsx)(ce,{asChild:!0,children:(0,T.jsx)(`div`,{children:(0,T.jsx)(v,{variant:Q.variant,children:r(Q.labelKey)})})}),(0,T.jsx)(le,{children:r(Q.tooltipKey)})]}),(0,T.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:A.command}),(0,T.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:$?g($,{addSuffix:!0,locale:i()}):`—`}),A.total_cost_usd!=null&&A.total_cost_usd>0&&(0,T.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,A.total_cost_usd.toFixed(4)]}),A.started_at&&A.finished_at&&(0,T.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:pe(A.started_at,A.finished_at)})]}),R&&(0,T.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`common:states.loading`)})]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[P.length>0&&(0,T.jsx)(`div`,{className:`mr-3`,children:(0,T.jsx)(f,{phases:I,phaseDefinitions:P})}),he&&(0,T.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,T.jsx)(ne,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),r(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}),(0,T.jsx)(`button`,{onClick:t,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,T.jsx)(re,{className:`w-4 h-4`})})]})]}),(0,T.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:B?(0,T.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`modal.notFound`)})}):c&&A?(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>k(e),"aria-pressed":D===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${D===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:m(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,T.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:D===`narrated`?(0,T.jsx)(ee,{events:M,settled:A.status!==`running`&&A.status!==`queued`,elapsedMs:A.duration_ms??null,variant:`glass`}):A.command.startsWith(`loop:`)?(0,T.jsx)(l,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n}):(0,T.jsx)(u,{events:M,isLoading:R,projectId:n})})]}):A?.command.startsWith(`loop:`)?(0,T.jsx)(l,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n}):(0,T.jsx)(u,{events:M,isLoading:R,projectId:n})}),!!A?.interactive&&A.status===`running`&&(0,T.jsx)(p,{jobId:e,projectId:n,settleMode:A.interactiveSettleMode,initialAcceptingTurns:A.interactiveAcceptingTurns,kind:A.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,T.jsx)(se,{handles:ye}),H&&(0,T.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,T.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,T.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,T.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:r(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,T.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:r(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,T.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,T.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:r(`modal.keepRunning`)}),(0,T.jsx)(h,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),me()},children:r(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{D as JobDetailModal};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,n as i,u as a}from"./chunk-KS7C4IRE-DEKu087k.js";import{a as o,w as s}from"./i18n-DwgvwTnx.js";import{n as c}from"./createLucideIcon-Bjbbp_KS.js";import{n as l}from"./dist-bVqfYmby.js";import{R as u,o as d}from"./TicketDetailModal-BvZoyDAL.js";import{l as f,u as p}from"./MinimizedChatsContext-CcjBHMHd.js";import{n as ee}from"./file-text-BcLCfcWZ.js";import{a as m,i as h,n as g,o as _,r as te,s as v,t as y}from"./InteractiveJobComposer-D36fZWai.js";import{t as ne}from"./circle-x-CMYsN4ZH.js";import{t as re}from"./download-CFHyyHcw.js";import{t as b}from"./loader-circle-DcygOQpC.js";import{a as x,r as ie}from"./useDesktop-BzX769yH.js";import{t as S}from"./button-CJqFnUOL.js";import{t as C}from"./utils-BC4DHlz2.js";import{t as ae}from"./formatDistanceToNow-C0ImhVKp.js";import{C as w,Et as T,I as E,L as D,N as O,Ot as k,P as A,_t as j,ot as oe,r as se,x as M}from"./index-DhjjFyU5.js";import{n as N}from"./job-time-BCL7wee9.js";import{t as ce}from"./format-command-C0D9IPmV.js";var P=e(t(),1),F=n();function I(e,t){let n=N(e),r=(typeof t==`number`?t:N(t)?.getTime()??NaN)-(n?.getTime()??NaN);if(!Number.isFinite(r)||r<0)return`—`;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60),o=i%60;return a<60?`${a}m ${o}s`:`${Math.floor(a/60)}h ${a%60}m`}function L(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 R={steps:0,actionKey:``,actionArg:``,lastSeenIdx:0};function z(e,t){if(t.type===`reset`)return R;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=w(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 le({job:e,events:t,defaultOpen:n=!0,pipelineTotals:r,phases:i,phaseDefinitions:a}){let{t:o}=c(`jobs`),[s,l]=(0,P.useState)(n),u=(0,P.useMemo)(()=>L(t),[t]),d=e.status===`running`,f=e.status===`completed`,[ee,m]=(0,P.useState)(()=>Date.now());(0,P.useEffect)(()=>{if(!d)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[d]);let[h,g]=(0,P.useReducer)(z,R),_=(0,P.useRef)(e.id);(0,P.useEffect)(()=>{_.current!==e.id&&(_.current=e.id,g({type:`reset`})),g({type:`consume`,events:t})},[e.id,t]);let[te,v]=(0,P.useState)(!0);(0,P.useEffect)(()=>{if(!d)return;v(!0);let e=window.setTimeout(()=>v(!1),8e3);return()=>window.clearTimeout(e)},[d,e.id]);let y=e.finished_at?I(e.started_at,e.finished_at):d?I(e.started_at,ee):`—`,re=!!e.total_cost_usd_estimated,x=e.total_cost_usd==null?null:`${re?`~`:``}$${e.total_cost_usd.toFixed(4)}`,ie=e.num_turns==null?null:String(e.num_turns),S=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),ae=S==null?null:`${(S/1e3).toFixed(1)}k`,w=(0,P.useMemo)(()=>!i||!a?null:a.find(e=>i[e.key]===`running`)?.label??null,[i,a]),T=d&&h.steps===0?`connecting`:h.actionKey||`thinking`,E=M.has(T)&&h.actionArg!==``,D=M.has(T)&&!E?`working`:T,O=E?o(`statusPanel.activity.${D}`,{arg:h.actionArg}):o(`statusPanel.activity.${D}`),A=w??(d&&h.steps===0?o(`statusPanel.activity.starting`):null),j=h.steps>0?o(`statusPanel.steps`,{count:h.steps}):null,oe=o(d?`statusPanel.inProgress`:f?`statusPanel.completed`:`statusPanel.failed`),se=d?`border-accent-info/20 bg-accent-info/5`:f?`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`,N=d?b:f?k:ne,ce=d?`w-4 h-4 text-accent-info shrink-0 animate-spin`:f?`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,F.jsxs)(`div`,{className:C(`mx-4 my-2 rounded-xl border transition-colors duration-500`,se),children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>l(!s),className:`w-full flex items-center gap-3 px-4 py-3`,children:[(0,F.jsx)(N,{className:ce,"aria-hidden":`true`}),(0,F.jsx)(`span`,{className:`text-sm font-semibold flex-1 text-left`,children:oe}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`tabular-nums`,children:y}),d?j&&(0,F.jsx)(`span`,{className:`tabular-nums`,children:j}):(0,F.jsxs)(F.Fragment,{children:[x&&(0,F.jsx)(`span`,{className:`tabular-nums text-yellow-400 aurora-light:text-accent-warning`,children:x}),u.length>0&&(0,F.jsx)(`span`,{children:o(`statusPanel.filesCount`,{count:u.length})})]})]}),(0,F.jsx)(p,{className:C(`w-4 h-4 text-muted-foreground/40 transition-transform duration-150 shrink-0`,s&&`rotate-180`)})]}),s&&(0,F.jsx)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/20`,children:d?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneInProgress`)}),(0,F.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 sm:items-stretch`,children:[(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 sm:w-44 shrink-0`,children:[(0,F.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[o(`statusPanel.duration`),(0,F.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,F.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-accent-info`,children:y})]}),(0,F.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 bg-muted/10 rounded-lg px-3 py-2 min-w-0`,children:[(0,F.jsx)(b,{className:`w-3.5 h-3.5 text-accent-info shrink-0 animate-spin`,"aria-hidden":`true`}),A&&(0,F.jsx)(`span`,{className:`text-[11px] font-medium px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info shrink-0`,children:A}),(0,F.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1 min-w-0`,children:O}),j&&(0,F.jsxs)(`span`,{className:`text-[11px] text-muted-foreground/60 tabular-nums shrink-0`,children:[`· `,j]})]})]}),te&&(0,F.jsx)(`p`,{className:`text-[11px] text-muted-foreground/40 leading-snug`,children:o(`statusPanel.explainer`)}),(0,F.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,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,F.jsx)(H,{label:o(`statusPanel.cost`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.costTooltip`)}),(0,F.jsx)(H,{label:o(`statusPanel.turns`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)}),(0,F.jsx)(H,{label:o(`statusPanel.tokens`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)})]})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneFinal`)}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[(0,F.jsx)(B,{label:o(`statusPanel.duration`),value:y}),(0,F.jsx)(V,{label:o(`statusPanel.cost`),value:x,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:o(`statusPanel.notAvailable`)}),(0,F.jsx)(V,{label:o(`statusPanel.turns`),value:ie,naCaption:o(`statusPanel.notAvailable`)}),(0,F.jsx)(V,{label:o(`statusPanel.tokens`),value:ae,naCaption:o(`statusPanel.notAvailable`)})]}),r&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.pipelineTotal`,{count:r.jobCount})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,F.jsx)(B,{label:o(`statusPanel.totalCost`),value:r.costUnavailable?`—`:`${r.costEstimated?`~`:``}${r.hasNullCost?`≥`:``}$${r.totalCostUsd.toFixed(4)}`,valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,F.jsx)(B,{label:o(`statusPanel.totalTokens`),value:r.tokensUnavailable?`—`:`${(r.nullTokenCount??0)>0?`≥`:``}${((r.totalTokensIn+r.totalTokensOut+r.totalTokensCacheRead+r.totalTokensCacheCreate)/1e3).toFixed(1)}k`})]}),r.hasNullCost&&!r.costUnavailable&&(0,F.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})}),r.costUnavailable&&(0,F.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:o(`statusPanel.pipelineCostUnavailable`)}),(r.nullTokenCount??0)>0&&(0,F.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:o(`statusPanel.pipelineUsageTooltip`),children:r.tokensUnavailable?o(`statusPanel.pipelineUsageUnavailable`):o(`statusPanel.pipelineUsagePartial`,{count:r.nullTokenCount??0})})]}),u.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.filesModified`)}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>(0,F.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 B({label:e,value:t,valueClass:n}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,F.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,n),children:t})]})}function V({label:e,value:t,valueClass:n,naCaption:r}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,F.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:r})]})}function H({label:e,caption:t,tooltip:n}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 ring-1 ring-accent-info/10`,title:n,children:[(0,F.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[e,(0,F.jsx)(T,{className:`w-2.5 h-2.5 text-muted-foreground/30`,"aria-hidden":`true`})]}),(0,F.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-muted-foreground/40`,children:`—`}),(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:t})]})}var U=4;function ue({tickets:e,onTicketClick:t}){let{t:n}=c(`jobs`),[r,i]=(0,P.useState)(!1);if(e.length===0)return null;let a=e.length>=U&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,F.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,F.jsx)(de,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,F.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,F.jsx)(p,{className:`w-3 h-3`})]}),r&&e.length>=U&&(0,F.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,F.jsx)(f,{className:`w-3 h-3`})]})]})}function de({ticket:e,onClick:t}){let{t:n}=c(`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,F.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,F.jsx)(`span`,{className:C(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,F.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,F.jsxs)(`span`,{className:C(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,F.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}var fe={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 W(){let{t:e}=c(`jobs`),{t}=c(`narration`),{id:n}=r(),{activeProjectId:f,projects:p}=ie(),ne=p.find(e=>e.id===f)?.provider,b=a(),{openTicketDetail:w}=d(),[T,k]=(0,P.useState)(null),[M,N]=(0,P.useState)([]),[I,L]=(0,P.useState)([]),[R,z]=(0,P.useState)({}),[B,V]=(0,P.useState)([]),[H,U]=(0,P.useState)(!0),[de,W]=(0,P.useState)(!1),[G,pe]=(0,P.useState)(g),[me,K]=(0,P.useState)(null),he=(0,P.useCallback)(e=>{pe(e),te(e)},[]),q=T?.command??null;(0,P.useEffect)(()=>{if(!u||G!==`narrated`||!f||!q)return;let e=!1,t=`command=${encodeURIComponent(q)}`;try{Promise.resolve(fetch(`${x()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||K(t?.range??null)}).catch(()=>{e||K(null)})}catch{K(null)}return()=>{e=!0}},[f,q,G]);let[ge,J]=(0,P.useState)(!1),Y=(0,P.useRef)(!1),X=(0,P.useRef)(null);(0,P.useEffect)(()=>{Y.current=!1,X.current=null,J(!1)},[n]),(0,P.useEffect)(()=>{if(!n)return;let e=new AbortController;k(null),N([]),L([]),z({}),U(!0),W(!1);async function t(){try{let t=await fetch(`${x()}/jobs/${n}`,{signal:e.signal});if(t.status===404){W(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();k(r.job),N(r.events)}catch(e){if(e.name===`AbortError`)return;W(!0)}finally{e.signal.aborted||U(!1)}}return t(),()=>e.abort()},[n,f]),(0,P.useEffect)(()=>{if(!T?.pipeline_id){V([]);return}let e=T.pipeline_id;fetch(`${x()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&V(e.jobs)}).catch(()=>{})},[T?.pipeline_id,T?.status]);let Z=(0,P.useRef)(f);Z.current=f;let _e=(0,P.useRef)(null);_e.current=T?.status??null;let Q=(0,P.useRef)([]),$=(0,P.useRef)(null),ve=(0,P.useCallback)(()=>{$.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}))},[]),ye=(0,P.useCallback)(e=>{let t=Q.current;t.push(e),t.length>1e4&&(Q.current=t.slice(-8e3)),$.current||=requestAnimationFrame(ve)},[ve]);(0,P.useEffect)(()=>()=>{$.current&&cancelAnimationFrame($.current)},[]);let be=(0,P.useCallback)(e=>{let t=e;if(!(Z.current&&t.projectId&&t.projectId!==Z.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];L(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;z(n)}else if(t.type===`event`&&t.jobId===n){let e={id:Date.now(),job_id:n??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};ye(e)}else if(t.type===`log`&&t.processId===n){let e={id:Date.now(),job_id:n??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp};ye(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${x()}/jobs/${n}`).then(e=>e.json()).then(e=>k(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;z(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===n);if(e){let t=e.status,r=_e.current;k(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${x()}/jobs/${n}`).then(e=>e.json()).then(e=>k(e.job)).catch(()=>{})}}}},[n,ye]),{registerHandler:xe,unregisterHandler:Se}=s();(0,P.useEffect)(()=>(xe(`job-detail-${n}`,be),()=>Se(`job-detail-${n}`)),[n,be,xe,Se]),(0,P.useEffect)(()=>{if(!n||!T||T.status!==`running`||T.hasTelemetry)return;let e=setInterval(()=>{fetch(`${x()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&k(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,T?.status,T?.hasTelemetry]);async function Ce(){if(!n)return;let t=await se({projectId:null,jobId:n});t.ok?l.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):t.httpStatus===null?l.error(e(`detail.toast.networkError`)):l.error(e(`detail.toast.failed`),{description:t.error})}async function we(){if(T)try{let t=await fetch(`${x()}/jobs/${T.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-${T.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){l.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function Te(){if(!(!T||Y.current)){Y.current=!0,J(!0),X.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${T.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${x()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":X.current},body:JSON.stringify({rerunOfJobId:T.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));X.current=null,l.success(e(`detail.toast.jobRequeued`)),b(`/jobs/${n.jobId}`)}catch(e){l.error(e.message)}finally{Y.current=!1,J(!1)}}}if(H)return(0,F.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,F.jsxs)(`div`,{className:`space-y-3`,children:[(0,F.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,F.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,F.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(de||!T)return(0,F.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,F.jsx)(S,{asChild:!0,variant:`outline`,size:`sm`,children:(0,F.jsxs)(i,{to:`/`,children:[(0,F.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let Ee=fe[T.status]??fe.queued,De=T.status===`running`,Oe=T.status===`completed`||T.status===`failed`,ke=!!T.interactive,Ae=ke&&De,je=(T.tickets?.length??0)>0,Me=T.command.startsWith(`loop:`),Ne=B.length>1?{totalCostUsd:B.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:B.some(e=>e.total_cost_usd==null),costEstimated:B.some(e=>!!e.total_cost_usd_estimated),nullCostCount:B.filter(e=>e.total_cost_usd==null).length,costUnavailable:B.every(e=>e.total_cost_usd==null),totalTokensIn:B.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:B.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:B.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:B.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:B.filter(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null).length,tokensUnavailable:B.every(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null),jobCount:B.length}:null;return(0,F.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,F.jsxs)(`div`,{className:`px-4 py-4 border-b border-border space-y-3`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,F.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,F.jsx)(j,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,F.jsx)(ee,{className:`w-3 h-3`}),(0,F.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),je&&(0,F.jsx)(ue,{tickets:T.tickets??[],onTicketClick:w}),(0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,F.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(D,{variant:Ee.variant,children:e(Ee.labelKey)})})}),(0,F.jsx)(A,{children:e(Ee.tooltipKey)})]}),(0,F.jsx)(`code`,{className:C(`font-mono text-foreground/90 truncate`,je?`text-xs text-muted-foreground`:`text-sm`),children:ce(T.command,ne)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,F.jsx)(`span`,{children:T.started_at?e(`detail.startedAgo`,{timeAgo:ae(new Date(T.started_at),{addSuffix:!0,locale:o()})}):e(`detail.queuedWaiting`)}),T.model&&(0,F.jsx)(`span`,{className:`text-muted-foreground/40`,children:T.model})]})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[T.hasTelemetry&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsxs)(S,{variant:`outline`,size:`sm`,className:`h-7`,onClick:we,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,F.jsx)(re,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,F.jsx)(A,{children:e(`detail.exportDiagnosticTooltip`)})]}),Oe&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsxs)(S,{variant:`outline`,size:`sm`,onClick:Te,disabled:ge,"aria-busy":ge,className:`h-7`,children:[(0,F.jsx)(oe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,F.jsx)(A,{children:e(`detail.reExecuteTooltip`)})]}),De&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(S,{variant:`outline`,size:`sm`,onClick:Ce,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(ke?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,F.jsx)(A,{children:e(`detail.cancelJobTooltip`)})]})]})]}),(0,F.jsx)(v,{phases:R,phaseDefinitions:I})]}),(T.status===`running`||T.status===`completed`||T.status===`failed`)&&(0,F.jsx)(le,{job:T,events:M,defaultOpen:T.status===`completed`||T.status===`running`,pipelineTotals:Ne??void 0,phases:R,phaseDefinitions:I}),(0,F.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:u?(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,F.jsx)(`button`,{type:`button`,onClick:()=>he(e),"aria-pressed":G===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${G===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,F.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:G===`narrated`?(0,F.jsx)(h,{events:M,settled:T.status!==`running`&&T.status!==`queued`,durationRange:me,elapsedMs:T.duration_ms??null,variant:`page`}):Me?(0,F.jsx)(m,{events:M,jobStatus:T.status,variant:`page`}):(0,F.jsx)(_,{events:M})})]}):Me?(0,F.jsx)(m,{events:M,jobStatus:T.status,variant:`page`}):(0,F.jsx)(_,{events:M})}),Ae&&(0,F.jsx)(y,{jobId:T.id,settleMode:T.interactiveSettleMode,initialAcceptingTurns:T.interactiveAcceptingTurns,kind:T.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{W as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,n as i,u as a}from"./chunk-KS7C4IRE-DEKu087k.js";import{a as o,w as s}from"./i18n-hnX2DPmo.js";import{n as c}from"./createLucideIcon-Bjbbp_KS.js";import{n as l}from"./dist-bVqfYmby.js";import{R as u,o as d}from"./TicketDetailModal-CsF-AWZX.js";import{l as f,u as p}from"./MinimizedChatsContext-Bd3OqR_S.js";import{n as ee}from"./file-text-BcLCfcWZ.js";import{a as m,i as h,n as g,o as _,r as te,s as v,t as y}from"./InteractiveJobComposer-BCZiSfzc.js";import{t as ne}from"./circle-x-CMYsN4ZH.js";import{t as re}from"./download-CFHyyHcw.js";import{t as b}from"./loader-circle-DcygOQpC.js";import{a as x,r as ie}from"./useDesktop-BQVt8lFd.js";import{t as S}from"./button-CJqFnUOL.js";import{t as C}from"./utils-BC4DHlz2.js";import{t as ae}from"./formatDistanceToNow-DQCvMgUc.js";import{C as w,Et as T,I as E,L as D,N as O,Ot as k,P as A,_t as j,ot as oe,r as se,x as M}from"./index-DIhMEAVw.js";import{n as N}from"./job-time-BCL7wee9.js";import{t as ce}from"./format-command-C0D9IPmV.js";var P=e(t(),1),F=n();function I(e,t){let n=N(e),r=(typeof t==`number`?t:N(t)?.getTime()??NaN)-(n?.getTime()??NaN);if(!Number.isFinite(r)||r<0)return`—`;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60),o=i%60;return a<60?`${a}m ${o}s`:`${Math.floor(a/60)}h ${a%60}m`}function L(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 R={steps:0,actionKey:``,actionArg:``,lastSeenIdx:0};function z(e,t){if(t.type===`reset`)return R;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=w(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 le({job:e,events:t,defaultOpen:n=!0,pipelineTotals:r,phases:i,phaseDefinitions:a}){let{t:o}=c(`jobs`),[s,l]=(0,P.useState)(n),u=(0,P.useMemo)(()=>L(t),[t]),d=e.status===`running`,f=e.status===`completed`,[ee,m]=(0,P.useState)(()=>Date.now());(0,P.useEffect)(()=>{if(!d)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[d]);let[h,g]=(0,P.useReducer)(z,R),_=(0,P.useRef)(e.id);(0,P.useEffect)(()=>{_.current!==e.id&&(_.current=e.id,g({type:`reset`})),g({type:`consume`,events:t})},[e.id,t]);let[te,v]=(0,P.useState)(!0);(0,P.useEffect)(()=>{if(!d)return;v(!0);let e=window.setTimeout(()=>v(!1),8e3);return()=>window.clearTimeout(e)},[d,e.id]);let y=e.finished_at?I(e.started_at,e.finished_at):d?I(e.started_at,ee):`—`,re=!!e.total_cost_usd_estimated,x=e.total_cost_usd==null?null:`${re?`~`:``}$${e.total_cost_usd.toFixed(4)}`,ie=e.num_turns==null?null:String(e.num_turns),S=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),ae=S==null?null:`${(S/1e3).toFixed(1)}k`,w=(0,P.useMemo)(()=>!i||!a?null:a.find(e=>i[e.key]===`running`)?.label??null,[i,a]),T=d&&h.steps===0?`connecting`:h.actionKey||`thinking`,E=M.has(T)&&h.actionArg!==``,D=M.has(T)&&!E?`working`:T,O=E?o(`statusPanel.activity.${D}`,{arg:h.actionArg}):o(`statusPanel.activity.${D}`),A=w??(d&&h.steps===0?o(`statusPanel.activity.starting`):null),j=h.steps>0?o(`statusPanel.steps`,{count:h.steps}):null,oe=o(d?`statusPanel.inProgress`:f?`statusPanel.completed`:`statusPanel.failed`),se=d?`border-accent-info/20 bg-accent-info/5`:f?`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`,N=d?b:f?k:ne,ce=d?`w-4 h-4 text-accent-info shrink-0 animate-spin`:f?`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,F.jsxs)(`div`,{className:C(`mx-4 my-2 rounded-xl border transition-colors duration-500`,se),children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>l(!s),className:`w-full flex items-center gap-3 px-4 py-3`,children:[(0,F.jsx)(N,{className:ce,"aria-hidden":`true`}),(0,F.jsx)(`span`,{className:`text-sm font-semibold flex-1 text-left`,children:oe}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`tabular-nums`,children:y}),d?j&&(0,F.jsx)(`span`,{className:`tabular-nums`,children:j}):(0,F.jsxs)(F.Fragment,{children:[x&&(0,F.jsx)(`span`,{className:`tabular-nums text-yellow-400 aurora-light:text-accent-warning`,children:x}),u.length>0&&(0,F.jsx)(`span`,{children:o(`statusPanel.filesCount`,{count:u.length})})]})]}),(0,F.jsx)(p,{className:C(`w-4 h-4 text-muted-foreground/40 transition-transform duration-150 shrink-0`,s&&`rotate-180`)})]}),s&&(0,F.jsx)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/20`,children:d?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneInProgress`)}),(0,F.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 sm:items-stretch`,children:[(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 sm:w-44 shrink-0`,children:[(0,F.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[o(`statusPanel.duration`),(0,F.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,F.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-accent-info`,children:y})]}),(0,F.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 bg-muted/10 rounded-lg px-3 py-2 min-w-0`,children:[(0,F.jsx)(b,{className:`w-3.5 h-3.5 text-accent-info shrink-0 animate-spin`,"aria-hidden":`true`}),A&&(0,F.jsx)(`span`,{className:`text-[11px] font-medium px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info shrink-0`,children:A}),(0,F.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1 min-w-0`,children:O}),j&&(0,F.jsxs)(`span`,{className:`text-[11px] text-muted-foreground/60 tabular-nums shrink-0`,children:[`· `,j]})]})]}),te&&(0,F.jsx)(`p`,{className:`text-[11px] text-muted-foreground/40 leading-snug`,children:o(`statusPanel.explainer`)}),(0,F.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,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,F.jsx)(H,{label:o(`statusPanel.cost`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.costTooltip`)}),(0,F.jsx)(H,{label:o(`statusPanel.turns`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)}),(0,F.jsx)(H,{label:o(`statusPanel.tokens`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)})]})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneFinal`)}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[(0,F.jsx)(B,{label:o(`statusPanel.duration`),value:y}),(0,F.jsx)(V,{label:o(`statusPanel.cost`),value:x,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:o(`statusPanel.notAvailable`)}),(0,F.jsx)(V,{label:o(`statusPanel.turns`),value:ie,naCaption:o(`statusPanel.notAvailable`)}),(0,F.jsx)(V,{label:o(`statusPanel.tokens`),value:ae,naCaption:o(`statusPanel.notAvailable`)})]}),r&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.pipelineTotal`,{count:r.jobCount})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,F.jsx)(B,{label:o(`statusPanel.totalCost`),value:r.costUnavailable?`—`:`${r.costEstimated?`~`:``}${r.hasNullCost?`≥`:``}$${r.totalCostUsd.toFixed(4)}`,valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,F.jsx)(B,{label:o(`statusPanel.totalTokens`),value:r.tokensUnavailable?`—`:`${(r.nullTokenCount??0)>0?`≥`:``}${((r.totalTokensIn+r.totalTokensOut+r.totalTokensCacheRead+r.totalTokensCacheCreate)/1e3).toFixed(1)}k`})]}),r.hasNullCost&&!r.costUnavailable&&(0,F.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})}),r.costUnavailable&&(0,F.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:o(`statusPanel.pipelineCostUnavailable`)}),(r.nullTokenCount??0)>0&&(0,F.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:o(`statusPanel.pipelineUsageTooltip`),children:r.tokensUnavailable?o(`statusPanel.pipelineUsageUnavailable`):o(`statusPanel.pipelineUsagePartial`,{count:r.nullTokenCount??0})})]}),u.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.filesModified`)}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>(0,F.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 B({label:e,value:t,valueClass:n}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,F.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,n),children:t})]})}function V({label:e,value:t,valueClass:n,naCaption:r}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,F.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:r})]})}function H({label:e,caption:t,tooltip:n}){return(0,F.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 ring-1 ring-accent-info/10`,title:n,children:[(0,F.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[e,(0,F.jsx)(T,{className:`w-2.5 h-2.5 text-muted-foreground/30`,"aria-hidden":`true`})]}),(0,F.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-muted-foreground/40`,children:`—`}),(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:t})]})}var U=4;function ue({tickets:e,onTicketClick:t}){let{t:n}=c(`jobs`),[r,i]=(0,P.useState)(!1);if(e.length===0)return null;let a=e.length>=U&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,F.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,F.jsx)(de,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,F.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,F.jsx)(p,{className:`w-3 h-3`})]}),r&&e.length>=U&&(0,F.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,F.jsx)(f,{className:`w-3 h-3`})]})]})}function de({ticket:e,onClick:t}){let{t:n}=c(`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,F.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,F.jsx)(`span`,{className:C(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,F.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,F.jsxs)(`span`,{className:C(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,F.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}var fe={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 W(){let{t:e}=c(`jobs`),{t}=c(`narration`),{id:n}=r(),{activeProjectId:f,projects:p}=ie(),ne=p.find(e=>e.id===f)?.provider,b=a(),{openTicketDetail:w}=d(),[T,k]=(0,P.useState)(null),[M,N]=(0,P.useState)([]),[I,L]=(0,P.useState)([]),[R,z]=(0,P.useState)({}),[B,V]=(0,P.useState)([]),[H,U]=(0,P.useState)(!0),[de,W]=(0,P.useState)(!1),[G,pe]=(0,P.useState)(g),[me,K]=(0,P.useState)(null),he=(0,P.useCallback)(e=>{pe(e),te(e)},[]),q=T?.command??null;(0,P.useEffect)(()=>{if(!u||G!==`narrated`||!f||!q)return;let e=!1,t=`command=${encodeURIComponent(q)}`;try{Promise.resolve(fetch(`${x()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||K(t?.range??null)}).catch(()=>{e||K(null)})}catch{K(null)}return()=>{e=!0}},[f,q,G]);let[ge,J]=(0,P.useState)(!1),Y=(0,P.useRef)(!1),X=(0,P.useRef)(null);(0,P.useEffect)(()=>{Y.current=!1,X.current=null,J(!1)},[n]),(0,P.useEffect)(()=>{if(!n)return;let e=new AbortController;k(null),N([]),L([]),z({}),U(!0),W(!1);async function t(){try{let t=await fetch(`${x()}/jobs/${n}`,{signal:e.signal});if(t.status===404){W(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();k(r.job),N(r.events)}catch(e){if(e.name===`AbortError`)return;W(!0)}finally{e.signal.aborted||U(!1)}}return t(),()=>e.abort()},[n,f]),(0,P.useEffect)(()=>{if(!T?.pipeline_id){V([]);return}let e=T.pipeline_id;fetch(`${x()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&V(e.jobs)}).catch(()=>{})},[T?.pipeline_id,T?.status]);let Z=(0,P.useRef)(f);Z.current=f;let _e=(0,P.useRef)(null);_e.current=T?.status??null;let Q=(0,P.useRef)([]),$=(0,P.useRef)(null),ve=(0,P.useCallback)(()=>{$.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}))},[]),ye=(0,P.useCallback)(e=>{let t=Q.current;t.push(e),t.length>1e4&&(Q.current=t.slice(-8e3)),$.current||=requestAnimationFrame(ve)},[ve]);(0,P.useEffect)(()=>()=>{$.current&&cancelAnimationFrame($.current)},[]);let be=(0,P.useCallback)(e=>{let t=e;if(!(Z.current&&t.projectId&&t.projectId!==Z.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];L(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;z(n)}else if(t.type===`event`&&t.jobId===n){let e={id:Date.now(),job_id:n??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};ye(e)}else if(t.type===`log`&&t.processId===n){let e={id:Date.now(),job_id:n??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp};ye(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${x()}/jobs/${n}`).then(e=>e.json()).then(e=>k(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;z(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===n);if(e){let t=e.status,r=_e.current;k(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${x()}/jobs/${n}`).then(e=>e.json()).then(e=>k(e.job)).catch(()=>{})}}}},[n,ye]),{registerHandler:xe,unregisterHandler:Se}=s();(0,P.useEffect)(()=>(xe(`job-detail-${n}`,be),()=>Se(`job-detail-${n}`)),[n,be,xe,Se]),(0,P.useEffect)(()=>{if(!n||!T||T.status!==`running`||T.hasTelemetry)return;let e=setInterval(()=>{fetch(`${x()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&k(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,T?.status,T?.hasTelemetry]);async function Ce(){if(!n)return;let t=await se({projectId:null,jobId:n});t.ok?l.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):t.httpStatus===null?l.error(e(`detail.toast.networkError`)):l.error(e(`detail.toast.failed`),{description:t.error})}async function we(){if(T)try{let t=await fetch(`${x()}/jobs/${T.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-${T.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){l.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function Te(){if(!(!T||Y.current)){Y.current=!0,J(!0),X.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${T.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${x()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":X.current},body:JSON.stringify({rerunOfJobId:T.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));X.current=null,l.success(e(`detail.toast.jobRequeued`)),b(`/jobs/${n.jobId}`)}catch(e){l.error(e.message)}finally{Y.current=!1,J(!1)}}}if(H)return(0,F.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,F.jsxs)(`div`,{className:`space-y-3`,children:[(0,F.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,F.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,F.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(de||!T)return(0,F.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,F.jsx)(S,{asChild:!0,variant:`outline`,size:`sm`,children:(0,F.jsxs)(i,{to:`/`,children:[(0,F.jsx)(j,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let Ee=fe[T.status]??fe.queued,De=T.status===`running`,Oe=T.status===`completed`||T.status===`failed`,ke=!!T.interactive,Ae=ke&&De,je=(T.tickets?.length??0)>0,Me=T.command.startsWith(`loop:`),Ne=B.length>1?{totalCostUsd:B.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:B.some(e=>e.total_cost_usd==null),costEstimated:B.some(e=>!!e.total_cost_usd_estimated),nullCostCount:B.filter(e=>e.total_cost_usd==null).length,costUnavailable:B.every(e=>e.total_cost_usd==null),totalTokensIn:B.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:B.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:B.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:B.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:B.filter(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null).length,tokensUnavailable:B.every(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null),jobCount:B.length}:null;return(0,F.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,F.jsxs)(`div`,{className:`px-4 py-4 border-b border-border space-y-3`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,F.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,F.jsx)(j,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,F.jsx)(ee,{className:`w-3 h-3`}),(0,F.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),je&&(0,F.jsx)(ue,{tickets:T.tickets??[],onTicketClick:w}),(0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,F.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(D,{variant:Ee.variant,children:e(Ee.labelKey)})})}),(0,F.jsx)(A,{children:e(Ee.tooltipKey)})]}),(0,F.jsx)(`code`,{className:C(`font-mono text-foreground/90 truncate`,je?`text-xs text-muted-foreground`:`text-sm`),children:ce(T.command,ne)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,F.jsx)(`span`,{children:T.started_at?e(`detail.startedAgo`,{timeAgo:ae(new Date(T.started_at),{addSuffix:!0,locale:o()})}):e(`detail.queuedWaiting`)}),T.model&&(0,F.jsx)(`span`,{className:`text-muted-foreground/40`,children:T.model})]})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[T.hasTelemetry&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsxs)(S,{variant:`outline`,size:`sm`,className:`h-7`,onClick:we,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,F.jsx)(re,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,F.jsx)(A,{children:e(`detail.exportDiagnosticTooltip`)})]}),Oe&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsxs)(S,{variant:`outline`,size:`sm`,onClick:Te,disabled:ge,"aria-busy":ge,className:`h-7`,children:[(0,F.jsx)(oe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,F.jsx)(A,{children:e(`detail.reExecuteTooltip`)})]}),De&&(0,F.jsxs)(O,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(S,{variant:`outline`,size:`sm`,onClick:Ce,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(ke?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,F.jsx)(A,{children:e(`detail.cancelJobTooltip`)})]})]})]}),(0,F.jsx)(v,{phases:R,phaseDefinitions:I})]}),(T.status===`running`||T.status===`completed`||T.status===`failed`)&&(0,F.jsx)(le,{job:T,events:M,defaultOpen:T.status===`completed`||T.status===`running`,pipelineTotals:Ne??void 0,phases:R,phaseDefinitions:I}),(0,F.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:u?(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,F.jsx)(`button`,{type:`button`,onClick:()=>he(e),"aria-pressed":G===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${G===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,F.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:G===`narrated`?(0,F.jsx)(h,{events:M,settled:T.status!==`running`&&T.status!==`queued`,durationRange:me,elapsedMs:T.duration_ms??null,variant:`page`}):Me?(0,F.jsx)(m,{events:M,jobStatus:T.status,variant:`page`}):(0,F.jsx)(_,{events:M})})]}):Me?(0,F.jsx)(m,{events:M,jobStatus:T.status,variant:`page`}):(0,F.jsx)(_,{events:M})}),Ae&&(0,F.jsx)(y,{jobId:T.id,settleMode:T.interactiveSettleMode,initialAcceptingTurns:T.interactiveAcceptingTurns,kind:T.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{W as default};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{a as i}from"./i18n-DwgvwTnx.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s}from"./dist-bVqfYmby.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./trash-2-BOU3WdZZ.js";import{t as u}from"./triangle-alert-H9T4jAmh.js";import{t as d}from"./x-CBMI9ejn.js";import{a as f}from"./auth-D_5bQv5W.js";import{a as p,i as m,r as h}from"./useDesktop-BzX769yH.js";import{a as g,c as _,i as v,n as y,o as b,r as x,s as S,t as ee}from"./dialog-CdWCb02j.js";import{t as C}from"./button-CJqFnUOL.js";import{n as te,t as ne}from"./lib-CGdyxIWg.js";import{t as w}from"./formatDistanceToNow-C0ImhVKp.js";import{Dt as T,I as E,L as re,N as D,Ot as O,P as k,ht as ie,t as A}from"./index-DhjjFyU5.js";import{n as j,t as M}from"./job-time-BCL7wee9.js";import{t as ae}from"./format-command-C0D9IPmV.js";import{t as N}from"./ExportDropdown-BrtfWzEG.js";var oe=o(`git-compare-arrows`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`M12 18H7a2 2 0 0 1-2-2V9`,key:`16sdep`}],[`path`,{d:`m9 15 3 3-3 3`,key:`1m3kbl`}]]),P=e(t(),1),F=n();function I(e){if(e==null)return`—`;let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function L(e){return e==null?`—`:e===0?`$0`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function R(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function z({label:e,a:t,b:n,highlight:r}){return(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 py-2 border-b border-border/20 last:border-0 text-xs`,children:[(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`a`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:t}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`b`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:n})]})}function B(e,t,n=!0){return e==null||t==null||e===t?null:n?e<t?`a`:`b`:e>t?`a`:`b`}function se({jobIds:e,onClose:t}){let{t:n}=a(`jobs`),[r,i]=(0,P.useState)(null),[o,s]=(0,P.useState)(!0),[l,u]=(0,P.useState)(null),{panelRef:f,panelStyle:m,headerHandleProps:h,resizeHandles:g,isFloating:v,guardBackdrop:y}=_();(0,P.useEffect)(()=>{let t=new AbortController;return fetch(`${p()}/jobs/compare?jobIds=${e.join(`,`)}`,{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{i(e),s(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),s(!1))}),()=>t.abort()},[e]);function b(e,t){return(0,F.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-medium uppercase tracking-wider`,children:n(`comparison.jobN`,{n:t+1})}),(0,F.jsx)(`code`,{className:`text-[10px] text-foreground/70 block truncate max-w-[160px] mx-auto`,children:e.command}),(0,F.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-[10px]`,children:[e.status===`completed`?(0,F.jsx)(O,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,F.jsx)(c,{className:`w-3 h-3 text-rose-400 aurora-light:text-destructive`}),(0,F.jsx)(`span`,{className:`capitalize text-muted-foreground`,children:n(`statusLabel.${e.status}`,{defaultValue:e.status})})]}),(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-mono`,children:e.id.slice(0,8)})]})}return(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:y(t),children:[(0,F.jsxs)(`div`,{ref:f,className:`w-full max-w-lg rounded-xl border border-border/30 bg-popover p-5 shadow-xl space-y-4 mx-4`,onClick:e=>e.stopPropagation(),style:m,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between ${v?`cursor-grab active:cursor-grabbing`:``}`,...h,children:[(0,F.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`comparison.title`)}),(0,F.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,F.jsx)(d,{className:`w-4 h-4`})})]}),o&&(0,F.jsx)(`div`,{className:`space-y-2`,children:[0,1,2,3].map(e=>(0,F.jsx)(`div`,{className:`h-8 bg-muted/20 rounded animate-pulse`},e))}),l&&(0,F.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:l})}),r&&(()=>{let[e,t]=r.jobs,i=B(e.durationMs,t.durationMs,!0),a=B(e.totalCostUsd,t.totalCostUsd,!0),o=B(e.tokensOut==null?null:e.tokensOut,t.tokensOut==null?null:t.tokensOut,!0);return(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 pb-3 border-b border-border/30 mb-1`,children:[(0,F.jsx)(`div`,{}),b(e,0),b(t,1)]}),(0,F.jsx)(z,{label:n(`comparison.duration`),a:I(e.durationMs),b:I(t.durationMs),highlight:i}),(0,F.jsx)(z,{label:n(`comparison.cost`),a:L(e.totalCostUsd),b:L(t.totalCostUsd),highlight:a}),(0,F.jsx)(z,{label:n(`comparison.tokensOut`),a:R(e.tokensOut),b:R(t.tokensOut),highlight:o}),(0,F.jsx)(z,{label:n(`comparison.tokensIn`),a:R(e.tokensIn),b:R(t.tokensIn),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.cacheRead`),a:R(e.tokensCacheRead),b:R(t.tokensCacheRead),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.model`),a:e.model??`—`,b:t.model??`—`,highlight:null}),(0,F.jsx)(z,{label:n(`comparison.phasesDone`),a:e.phasesCompleted.length>0?e.phasesCompleted.join(`, `):`—`,b:t.phasesCompleted.length>0?t.phasesCompleted.join(`, `):`—`,highlight:null})]})})(),r&&(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 text-center`,children:n(`comparison.betterValueHint`)})]}),(0,F.jsx)(S,{handles:g})]})}var ce={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.done`,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.queuedToRun`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`},skipped:{variant:`warning`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}},le=[`running`,`completed`,`failed`,`canceled`,`zombie_terminated`,`queued`,`skipped`],ue={critical:{className:`bg-red-500/15 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive border-red-500/30 aurora-light:border-destructive/30`,labelKey:`recent.priority.critical`},high:{className:`bg-orange-500/15 aurora-light:bg-accent-warning/10 text-orange-400 aurora-light:text-accent-warning border-orange-500/30 aurora-light:border-accent-warning/30`,labelKey:`recent.priority.high`},normal:{className:``,labelKey:`recent.priority.normal`},low:{className:`bg-gray-500/15 aurora-light:bg-muted text-gray-400 aurora-light:text-muted-foreground border-gray-500/30 aurora-light:border-border`,labelKey:`recent.priority.low`}};function de(e){return e==null||e===0?null:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function fe(e,t){let n=j(e),r=j(t);if(!n||!r)return null;let i=r.getTime()-n.getTime();if(i<0)return null;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}function pe(e){return e==null||e===0?null:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function me(e){let t=j(e);return t?w(t,{addSuffix:!0,locale:i()}):`—`}function he(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).getTime()}function ge(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r+1).getTime()-1}function _e(e,t,n){if(!t&&!n)return!0;let r=j(e);if(!r)return!0;let i=r.getTime();return!(t&&i<he(t)||n&&i>ge(n))}var V=10;function H({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:o,onProposalClick:c,onProposalDelete:d}){let{t:f}=a(`jobs`),m=r(),{activeProjectId:te,projects:ne}=h(),w=ne.find(e=>e.id===te)?.provider,[O,A]=(0,P.useState)(null),[j,N]=(0,P.useState)(``),[I,L]=(0,P.useState)(``),[R,z]=(0,P.useState)(!1),[B,H]=(0,P.useState)(``),[U,W]=(0,P.useState)(``),[G,ve]=(0,P.useState)(!1),[K,q]=(0,P.useState)(null),[J,ye]=(0,P.useState)(V),[Y,be]=(0,P.useState)(!1),[X,Z]=(0,P.useState)([]),[xe,Q]=(0,P.useState)(null),{panelRef:Se,panelStyle:Ce,headerHandleProps:we,resizeHandles:Te,isFloating:Ee,guardBackdrop:De}=_();(0,P.useEffect)(()=>{ye(V)},[e.length]);function Oe(){be(e=>!e),Z([])}function ke(e){Z(t=>{if(t.includes(e))return t.filter(t=>t!==e);if(t.length>=2)return t;let n=[...t,e];return n.length===2&&Q(n),n})}let $=e.filter(e=>O&&e.status!==O?!1:_e(M(e),j,I)),Ae=e.filter(e=>_e(M(e),B,U)).length;async function je(e){ve(!0);try{let t={};e===`range`&&(B&&(t.from=new Date(he(B)).toISOString()),U&&(t.to=new Date(ge(U)).toISOString()));let n=await fetch(`${p()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();s.success(f(`recent.toast.cleared`,{count:e.deleted})),z(!1),H(``),W(``),o?.()}else s.error(f(`recent.toast.clearFailed`))}catch{s.error(f(`recent.toast.networkError`))}finally{ve(!1)}}let Me=n?(0,F.jsxs)(`div`,{role:`alert`,"data-testid":`jobs-load-error`,className:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,F.jsx)(u,{className:`h-4 w-4 shrink-0`}),(0,F.jsx)(`span`,{className:`flex-1`,children:f(`recent.loadFailed`)}),i&&(0,F.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:f(`common:actions.retry`)})]}):null;return n&&e.length===0?(0,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:Me}):t&&e.length===0?(0,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-1`,children:[0,1,2].map(e=>(0,F.jsx)(`div`,{className:`h-9 bg-muted/30 rounded-md animate-pulse`},e))}):e.length===0?(0,F.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 bg-card/50 p-8 text-center space-y-2`,children:[(0,F.jsx)(T,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,F.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:f(`recent.emptyTitle`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:f(`recent.emptyDescription`)})]}):(0,F.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-2`,children:[Me,(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,F.jsx)(`button`,{type:`button`,onClick:()=>A(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${O===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterAll`,{count:e.length})}),le.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,F.jsx)(`button`,{type:`button`,onClick:()=>A(O===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${O===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterStatus`,{status:f(`statusName.${t}`),count:n})},t)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:j,onChange:e=>N(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.fromDate`)}),(0,F.jsx)(`input`,{type:`date`,value:I,onChange:e=>L(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.toDate`)}),(j||I)&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{N(``),L(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:f(`recent.clear`)}),(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 transition-colors ${Y?`text-foreground bg-accent`:`text-muted-foreground hover:text-foreground`}`,onClick:Oe,children:(0,F.jsx)(oe,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(k,{children:f(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>z(!0),children:(0,F.jsx)(l,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(k,{children:f(`recent.clearJobs`)})]})]})]}),Y&&(0,F.jsxs)(`div`,{className:`flex items-center justify-between rounded-md bg-accent/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,F.jsxs)(`span`,{children:[X.length===0&&f(`recent.selectTwoToCompare`),X.length===1&&f(`recent.selectOneMore`),X.length===2&&f(`recent.readyToCompare`)]}),X.length===2&&(0,F.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:f(`recent.compareAction`)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1 text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,F.jsx)(`span`,{className:`w-14`,children:f(`recent.colStatus`)}),(0,F.jsx)(`span`,{className:`flex-1 min-w-0`,children:f(`recent.colCommand`)}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:f(`recent.colDuration`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colTokens`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colCost`)}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:f(`recent.colStarted`)})]})]}),(0,F.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=ce[e.status]??ce.queued,n=de(e.total_cost_usd),r=fe(e.started_at,e.finished_at),i=pe((e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0)||null),a=e.id.startsWith(`proposal:`),o=a?e.id.replace(`proposal:`,``):null,s=X.includes(e.id),u=Y&&!a&&X.length===2&&!s,d=()=>{if(Y&&!a){ke(e.id);return}a&&o?c?.(o):m(`/jobs/${e.id}`)};return(0,F.jsxs)(`div`,{role:`button`,tabIndex:0,className:`flex items-center gap-3 px-3 py-2 rounded-md transition-colors cursor-pointer group ${s?`bg-accent/70 ring-1 ring-border`:u?`opacity-40 cursor-not-allowed`:`hover:bg-accent/50`}`,onClick:d,onKeyDown:e=>{e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),d()))},children:[(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(re,{variant:t.variant,children:f(t.labelKey)})})}),(0,F.jsx)(k,{children:f(t.tooltipKey)})]}),e.priority&&e.priority!==`normal`&&(0,F.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border ${ue[e.priority].className}`,children:f(ue[e.priority].labelKey)}),e.profile_name&&(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border border-accent-primary/40 bg-accent-primary/10 text-accent-primary/90`,children:e.profile_name})}),(0,F.jsx)(k,{children:f(`recent.profileTooltip`,{name:e.profile_name})})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[e.pipeline_id&&(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(ie,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,F.jsxs)(k,{children:[f(`recent.pipelinePart`),e.depends_on_job_id&&` ${f(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,F.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:ae(e.command,w)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:r??`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:i?`${i}`:`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:n??`—`}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:e.status===`queued`?`—`:me(e.started_at)}),a&&o&&(0,F.jsx)(`button`,{type:`button`,className:`w-4 h-4 md:opacity-0 md:group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-all`,onClick:e=>{e.stopPropagation(),q(o)},title:f(`recent.deleteProposal`),children:(0,F.jsx)(l,{className:`w-3 h-3`})})]})]},e.id)})}),$.length>J&&(0,F.jsx)(`div`,{className:`pt-1 text-center`,children:(0,F.jsx)(`button`,{type:`button`,onClick:()=>ye(e=>e+V),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:f(`recent.loadMore`,{count:$.length-J})})}),R&&(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>z(!1)),children:[(0,F.jsxs)(`div`,{ref:Se,className:`w-80 rounded-xl border border-border/30 bg-popover p-4 shadow-lg space-y-4`,onClick:e=>e.stopPropagation(),style:Ce,children:[(0,F.jsxs)(`div`,{...we,className:Ee?`cursor-grab active:cursor-grabbing`:void 0,children:[(0,F.jsx)(`h3`,{className:`text-sm font-semibold`,children:f(`recent.clearModal.title`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:f(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:G,onClick:()=>je(`all`),children:f(`recent.clearModal.clearAll`,{count:e.length})}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`recent.clearModal.orByRange`)}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:B,onChange:e=>H(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.fromPlaceholder`)}),(0,F.jsx)(`input`,{type:`date`,value:U,onChange:e=>W(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.toPlaceholder`)})]}),(0,F.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:G||!B&&!U,onClick:()=>je(`range`),children:B||U?f(`recent.clearModal.clearInRange`,{count:Ae}):f(`recent.clearModal.clearRange`)})]}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>z(!1),children:f(`common:actions.cancel`)})]}),(0,F.jsx)(S,{handles:Te})]}),(0,F.jsx)(ee,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,F.jsxs)(y,{className:`max-w-sm`,children:[(0,F.jsxs)(g,{children:[(0,F.jsx)(b,{children:f(`recent.deleteProposalConfirm.title`)}),(0,F.jsx)(x,{children:f(`recent.deleteProposalConfirm.description`)})]}),(0,F.jsxs)(v,{children:[(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:f(`common:actions.cancel`)}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&d?.(K),q(null)},children:f(`common:actions.delete`)})]})]})}),xe&&(0,F.jsx)(se,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var U={input:`page.proposal.status.input`,exploring:`page.proposal.status.exploring`,review:`page.proposal.status.review`,refining:`page.proposal.status.refining`,creating_issue:`page.proposal.status.creatingIssue`,created:`page.proposal.status.created`,cancelled:`page.proposal.status.cancelled`};function W(e){return`${f}/api/projects/${encodeURIComponent(e)}`}function G(){let{t:e}=a(`jobs`),{activeProjectId:t}=h(),{recentJobs:n}=A(t),{data:r,isFirstLoad:i,isLoading:o,error:c,refresh:l}=m({namespace:`jobs`,projectId:t,initialValue:n,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4}),{data:u,isFirstLoad:d,isLoading:f,error:_,refresh:x}=m({namespace:`proposals`,projectId:t,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),S={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},w=u.map(e=>({id:`proposal:${e.id}`,command:`/specrails:propose-feature ${e.idea.length>60?e.idea.slice(0,57)+`...`:e.idea}`,started_at:e.created_at,enqueued_at:e.created_at,status:S[e.status]??`queued`})),T=[...r,...w].sort((e,t)=>(j(M(t))?.getTime()??0)-(j(M(e))?.getTime()??0)),[E,D]=(0,P.useState)(null),O=(0,P.useCallback)(async e=>{try{let t=await fetch(`${p()}/propose/${e}`);if(!t.ok)return;let n=await t.json();D(n.proposal)}catch{}},[]),k=(0,P.useCallback)(async t=>{try{(await fetch(`${p()}/propose/${t}`,{method:`DELETE`})).ok&&(s.success(e(`page.proposalDeleted`)),await x())}catch{}},[x,e]);return(0,F.jsxs)(`div`,{className:`max-w-4xl mx-auto px-4 py-6`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,F.jsx)(`h1`,{className:`text-sm font-semibold`,children:e(`page.title`)}),(0,F.jsx)(N,{baseUrl:`${p()}/jobs/export`,label:e(`page.exportJobs`)})]}),(0,F.jsx)(H,{jobs:T,isLoading:i||d||o||f,error:c??_,onRetry:()=>{Promise.all([l(),x()])},onJobsCleared:l,onProposalClick:O,onProposalDelete:k}),(0,F.jsx)(ee,{open:E!==null,onOpenChange:e=>!e&&D(null),children:(0,F.jsx)(y,{className:`max-w-3xl glass-card`,children:E&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(g,{children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(b,{className:`flex-1 min-w-0`,children:e(`page.proposal.title`)}),(0,F.jsx)(re,{variant:E.status===`created`?`success`:E.status===`cancelled`?`destructive`:`secondary`,children:e(U[E.status]??`page.proposal.status.unknown`,{status:E.status})})]})}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:E.idea}),E.result_markdown?(0,F.jsx)(`div`,{className:`max-h-[400px] overflow-y-auto rounded-lg px-3 py-2 text-xs bg-muted/40`,children:(0,F.jsx)(`div`,{className:`prose prose-invert prose-xs max-w-none prose-p:my-1 prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-code:text-cyan-300 prose-code:text-[10px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded text-foreground/80`,children:(0,F.jsx)(te,{remarkPlugins:[ne],children:E.result_markdown})})}):(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:e(`page.proposal.noContent`)}),E.issue_url&&(0,F.jsxs)(`div`,{className:`text-xs`,children:[e(`page.proposal.githubIssue`),` `,(0,F.jsx)(`a`,{href:E.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:E.issue_url})]}),(0,F.jsxs)(v,{children:[(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{k(E.id),D(null)},children:e(`common:actions.delete`)}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>D(null),children:e(`common:actions.close`)})]})]})})})]})}export{G as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{a as i}from"./i18n-hnX2DPmo.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s}from"./dist-bVqfYmby.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./trash-2-BOU3WdZZ.js";import{t as u}from"./triangle-alert-H9T4jAmh.js";import{t as d}from"./x-CBMI9ejn.js";import{a as f}from"./auth-D_5bQv5W.js";import{a as p,i as m,r as h}from"./useDesktop-BQVt8lFd.js";import{a as g,c as _,i as v,n as y,o as b,r as x,s as S,t as ee}from"./dialog-CdWCb02j.js";import{t as C}from"./button-CJqFnUOL.js";import{n as te,t as ne}from"./lib-CGdyxIWg.js";import{t as w}from"./formatDistanceToNow-DQCvMgUc.js";import{Dt as T,I as E,L as re,N as D,Ot as O,P as k,ht as ie,t as A}from"./index-DIhMEAVw.js";import{n as j,t as M}from"./job-time-BCL7wee9.js";import{t as ae}from"./format-command-C0D9IPmV.js";import{t as N}from"./ExportDropdown-BrtfWzEG.js";var oe=o(`git-compare-arrows`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`M12 18H7a2 2 0 0 1-2-2V9`,key:`16sdep`}],[`path`,{d:`m9 15 3 3-3 3`,key:`1m3kbl`}]]),P=e(t(),1),F=n();function I(e){if(e==null)return`—`;let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function L(e){return e==null?`—`:e===0?`$0`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function R(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function z({label:e,a:t,b:n,highlight:r}){return(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 py-2 border-b border-border/20 last:border-0 text-xs`,children:[(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`a`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:t}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`b`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:n})]})}function B(e,t,n=!0){return e==null||t==null||e===t?null:n?e<t?`a`:`b`:e>t?`a`:`b`}function se({jobIds:e,onClose:t}){let{t:n}=a(`jobs`),[r,i]=(0,P.useState)(null),[o,s]=(0,P.useState)(!0),[l,u]=(0,P.useState)(null),{panelRef:f,panelStyle:m,headerHandleProps:h,resizeHandles:g,isFloating:v,guardBackdrop:y}=_();(0,P.useEffect)(()=>{let t=new AbortController;return fetch(`${p()}/jobs/compare?jobIds=${e.join(`,`)}`,{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{i(e),s(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),s(!1))}),()=>t.abort()},[e]);function b(e,t){return(0,F.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-medium uppercase tracking-wider`,children:n(`comparison.jobN`,{n:t+1})}),(0,F.jsx)(`code`,{className:`text-[10px] text-foreground/70 block truncate max-w-[160px] mx-auto`,children:e.command}),(0,F.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-[10px]`,children:[e.status===`completed`?(0,F.jsx)(O,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,F.jsx)(c,{className:`w-3 h-3 text-rose-400 aurora-light:text-destructive`}),(0,F.jsx)(`span`,{className:`capitalize text-muted-foreground`,children:n(`statusLabel.${e.status}`,{defaultValue:e.status})})]}),(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-mono`,children:e.id.slice(0,8)})]})}return(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:y(t),children:[(0,F.jsxs)(`div`,{ref:f,className:`w-full max-w-lg rounded-xl border border-border/30 bg-popover p-5 shadow-xl space-y-4 mx-4`,onClick:e=>e.stopPropagation(),style:m,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between ${v?`cursor-grab active:cursor-grabbing`:``}`,...h,children:[(0,F.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`comparison.title`)}),(0,F.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,F.jsx)(d,{className:`w-4 h-4`})})]}),o&&(0,F.jsx)(`div`,{className:`space-y-2`,children:[0,1,2,3].map(e=>(0,F.jsx)(`div`,{className:`h-8 bg-muted/20 rounded animate-pulse`},e))}),l&&(0,F.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:l})}),r&&(()=>{let[e,t]=r.jobs,i=B(e.durationMs,t.durationMs,!0),a=B(e.totalCostUsd,t.totalCostUsd,!0),o=B(e.tokensOut==null?null:e.tokensOut,t.tokensOut==null?null:t.tokensOut,!0);return(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 pb-3 border-b border-border/30 mb-1`,children:[(0,F.jsx)(`div`,{}),b(e,0),b(t,1)]}),(0,F.jsx)(z,{label:n(`comparison.duration`),a:I(e.durationMs),b:I(t.durationMs),highlight:i}),(0,F.jsx)(z,{label:n(`comparison.cost`),a:L(e.totalCostUsd),b:L(t.totalCostUsd),highlight:a}),(0,F.jsx)(z,{label:n(`comparison.tokensOut`),a:R(e.tokensOut),b:R(t.tokensOut),highlight:o}),(0,F.jsx)(z,{label:n(`comparison.tokensIn`),a:R(e.tokensIn),b:R(t.tokensIn),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.cacheRead`),a:R(e.tokensCacheRead),b:R(t.tokensCacheRead),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.model`),a:e.model??`—`,b:t.model??`—`,highlight:null}),(0,F.jsx)(z,{label:n(`comparison.phasesDone`),a:e.phasesCompleted.length>0?e.phasesCompleted.join(`, `):`—`,b:t.phasesCompleted.length>0?t.phasesCompleted.join(`, `):`—`,highlight:null})]})})(),r&&(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 text-center`,children:n(`comparison.betterValueHint`)})]}),(0,F.jsx)(S,{handles:g})]})}var ce={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.done`,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.queuedToRun`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`},skipped:{variant:`warning`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}},le=[`running`,`completed`,`failed`,`canceled`,`zombie_terminated`,`queued`,`skipped`],ue={critical:{className:`bg-red-500/15 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive border-red-500/30 aurora-light:border-destructive/30`,labelKey:`recent.priority.critical`},high:{className:`bg-orange-500/15 aurora-light:bg-accent-warning/10 text-orange-400 aurora-light:text-accent-warning border-orange-500/30 aurora-light:border-accent-warning/30`,labelKey:`recent.priority.high`},normal:{className:``,labelKey:`recent.priority.normal`},low:{className:`bg-gray-500/15 aurora-light:bg-muted text-gray-400 aurora-light:text-muted-foreground border-gray-500/30 aurora-light:border-border`,labelKey:`recent.priority.low`}};function de(e){return e==null||e===0?null:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function fe(e,t){let n=j(e),r=j(t);if(!n||!r)return null;let i=r.getTime()-n.getTime();if(i<0)return null;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}function pe(e){return e==null||e===0?null:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function me(e){let t=j(e);return t?w(t,{addSuffix:!0,locale:i()}):`—`}function he(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).getTime()}function ge(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r+1).getTime()-1}function _e(e,t,n){if(!t&&!n)return!0;let r=j(e);if(!r)return!0;let i=r.getTime();return!(t&&i<he(t)||n&&i>ge(n))}var V=10;function H({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:o,onProposalClick:c,onProposalDelete:d}){let{t:f}=a(`jobs`),m=r(),{activeProjectId:te,projects:ne}=h(),w=ne.find(e=>e.id===te)?.provider,[O,A]=(0,P.useState)(null),[j,N]=(0,P.useState)(``),[I,L]=(0,P.useState)(``),[R,z]=(0,P.useState)(!1),[B,H]=(0,P.useState)(``),[U,W]=(0,P.useState)(``),[G,ve]=(0,P.useState)(!1),[K,q]=(0,P.useState)(null),[J,ye]=(0,P.useState)(V),[Y,be]=(0,P.useState)(!1),[X,Z]=(0,P.useState)([]),[xe,Q]=(0,P.useState)(null),{panelRef:Se,panelStyle:Ce,headerHandleProps:we,resizeHandles:Te,isFloating:Ee,guardBackdrop:De}=_();(0,P.useEffect)(()=>{ye(V)},[e.length]);function Oe(){be(e=>!e),Z([])}function ke(e){Z(t=>{if(t.includes(e))return t.filter(t=>t!==e);if(t.length>=2)return t;let n=[...t,e];return n.length===2&&Q(n),n})}let $=e.filter(e=>O&&e.status!==O?!1:_e(M(e),j,I)),Ae=e.filter(e=>_e(M(e),B,U)).length;async function je(e){ve(!0);try{let t={};e===`range`&&(B&&(t.from=new Date(he(B)).toISOString()),U&&(t.to=new Date(ge(U)).toISOString()));let n=await fetch(`${p()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();s.success(f(`recent.toast.cleared`,{count:e.deleted})),z(!1),H(``),W(``),o?.()}else s.error(f(`recent.toast.clearFailed`))}catch{s.error(f(`recent.toast.networkError`))}finally{ve(!1)}}let Me=n?(0,F.jsxs)(`div`,{role:`alert`,"data-testid":`jobs-load-error`,className:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,F.jsx)(u,{className:`h-4 w-4 shrink-0`}),(0,F.jsx)(`span`,{className:`flex-1`,children:f(`recent.loadFailed`)}),i&&(0,F.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:f(`common:actions.retry`)})]}):null;return n&&e.length===0?(0,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:Me}):t&&e.length===0?(0,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-1`,children:[0,1,2].map(e=>(0,F.jsx)(`div`,{className:`h-9 bg-muted/30 rounded-md animate-pulse`},e))}):e.length===0?(0,F.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 bg-card/50 p-8 text-center space-y-2`,children:[(0,F.jsx)(T,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,F.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:f(`recent.emptyTitle`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:f(`recent.emptyDescription`)})]}):(0,F.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-2`,children:[Me,(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,F.jsx)(`button`,{type:`button`,onClick:()=>A(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${O===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterAll`,{count:e.length})}),le.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,F.jsx)(`button`,{type:`button`,onClick:()=>A(O===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${O===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterStatus`,{status:f(`statusName.${t}`),count:n})},t)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:j,onChange:e=>N(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.fromDate`)}),(0,F.jsx)(`input`,{type:`date`,value:I,onChange:e=>L(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.toDate`)}),(j||I)&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{N(``),L(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:f(`recent.clear`)}),(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 transition-colors ${Y?`text-foreground bg-accent`:`text-muted-foreground hover:text-foreground`}`,onClick:Oe,children:(0,F.jsx)(oe,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(k,{children:f(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>z(!0),children:(0,F.jsx)(l,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(k,{children:f(`recent.clearJobs`)})]})]})]}),Y&&(0,F.jsxs)(`div`,{className:`flex items-center justify-between rounded-md bg-accent/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,F.jsxs)(`span`,{children:[X.length===0&&f(`recent.selectTwoToCompare`),X.length===1&&f(`recent.selectOneMore`),X.length===2&&f(`recent.readyToCompare`)]}),X.length===2&&(0,F.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:f(`recent.compareAction`)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1 text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,F.jsx)(`span`,{className:`w-14`,children:f(`recent.colStatus`)}),(0,F.jsx)(`span`,{className:`flex-1 min-w-0`,children:f(`recent.colCommand`)}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:f(`recent.colDuration`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colTokens`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colCost`)}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:f(`recent.colStarted`)})]})]}),(0,F.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=ce[e.status]??ce.queued,n=de(e.total_cost_usd),r=fe(e.started_at,e.finished_at),i=pe((e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0)||null),a=e.id.startsWith(`proposal:`),o=a?e.id.replace(`proposal:`,``):null,s=X.includes(e.id),u=Y&&!a&&X.length===2&&!s,d=()=>{if(Y&&!a){ke(e.id);return}a&&o?c?.(o):m(`/jobs/${e.id}`)};return(0,F.jsxs)(`div`,{role:`button`,tabIndex:0,className:`flex items-center gap-3 px-3 py-2 rounded-md transition-colors cursor-pointer group ${s?`bg-accent/70 ring-1 ring-border`:u?`opacity-40 cursor-not-allowed`:`hover:bg-accent/50`}`,onClick:d,onKeyDown:e=>{e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),d()))},children:[(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(re,{variant:t.variant,children:f(t.labelKey)})})}),(0,F.jsx)(k,{children:f(t.tooltipKey)})]}),e.priority&&e.priority!==`normal`&&(0,F.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border ${ue[e.priority].className}`,children:f(ue[e.priority].labelKey)}),e.profile_name&&(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border border-accent-primary/40 bg-accent-primary/10 text-accent-primary/90`,children:e.profile_name})}),(0,F.jsx)(k,{children:f(`recent.profileTooltip`,{name:e.profile_name})})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[e.pipeline_id&&(0,F.jsxs)(D,{children:[(0,F.jsx)(E,{asChild:!0,children:(0,F.jsx)(ie,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,F.jsxs)(k,{children:[f(`recent.pipelinePart`),e.depends_on_job_id&&` ${f(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,F.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:ae(e.command,w)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:r??`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:i?`${i}`:`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:n??`—`}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:e.status===`queued`?`—`:me(e.started_at)}),a&&o&&(0,F.jsx)(`button`,{type:`button`,className:`w-4 h-4 md:opacity-0 md:group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-all`,onClick:e=>{e.stopPropagation(),q(o)},title:f(`recent.deleteProposal`),children:(0,F.jsx)(l,{className:`w-3 h-3`})})]})]},e.id)})}),$.length>J&&(0,F.jsx)(`div`,{className:`pt-1 text-center`,children:(0,F.jsx)(`button`,{type:`button`,onClick:()=>ye(e=>e+V),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:f(`recent.loadMore`,{count:$.length-J})})}),R&&(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>z(!1)),children:[(0,F.jsxs)(`div`,{ref:Se,className:`w-80 rounded-xl border border-border/30 bg-popover p-4 shadow-lg space-y-4`,onClick:e=>e.stopPropagation(),style:Ce,children:[(0,F.jsxs)(`div`,{...we,className:Ee?`cursor-grab active:cursor-grabbing`:void 0,children:[(0,F.jsx)(`h3`,{className:`text-sm font-semibold`,children:f(`recent.clearModal.title`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:f(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:G,onClick:()=>je(`all`),children:f(`recent.clearModal.clearAll`,{count:e.length})}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`recent.clearModal.orByRange`)}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:B,onChange:e=>H(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.fromPlaceholder`)}),(0,F.jsx)(`input`,{type:`date`,value:U,onChange:e=>W(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.toPlaceholder`)})]}),(0,F.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:G||!B&&!U,onClick:()=>je(`range`),children:B||U?f(`recent.clearModal.clearInRange`,{count:Ae}):f(`recent.clearModal.clearRange`)})]}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>z(!1),children:f(`common:actions.cancel`)})]}),(0,F.jsx)(S,{handles:Te})]}),(0,F.jsx)(ee,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,F.jsxs)(y,{className:`max-w-sm`,children:[(0,F.jsxs)(g,{children:[(0,F.jsx)(b,{children:f(`recent.deleteProposalConfirm.title`)}),(0,F.jsx)(x,{children:f(`recent.deleteProposalConfirm.description`)})]}),(0,F.jsxs)(v,{children:[(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:f(`common:actions.cancel`)}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&d?.(K),q(null)},children:f(`common:actions.delete`)})]})]})}),xe&&(0,F.jsx)(se,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var U={input:`page.proposal.status.input`,exploring:`page.proposal.status.exploring`,review:`page.proposal.status.review`,refining:`page.proposal.status.refining`,creating_issue:`page.proposal.status.creatingIssue`,created:`page.proposal.status.created`,cancelled:`page.proposal.status.cancelled`};function W(e){return`${f}/api/projects/${encodeURIComponent(e)}`}function G(){let{t:e}=a(`jobs`),{activeProjectId:t}=h(),{recentJobs:n}=A(t),{data:r,isFirstLoad:i,isLoading:o,error:c,refresh:l}=m({namespace:`jobs`,projectId:t,initialValue:n,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4}),{data:u,isFirstLoad:d,isLoading:f,error:_,refresh:x}=m({namespace:`proposals`,projectId:t,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),S={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},w=u.map(e=>({id:`proposal:${e.id}`,command:`/specrails:propose-feature ${e.idea.length>60?e.idea.slice(0,57)+`...`:e.idea}`,started_at:e.created_at,enqueued_at:e.created_at,status:S[e.status]??`queued`})),T=[...r,...w].sort((e,t)=>(j(M(t))?.getTime()??0)-(j(M(e))?.getTime()??0)),[E,D]=(0,P.useState)(null),O=(0,P.useCallback)(async e=>{try{let t=await fetch(`${p()}/propose/${e}`);if(!t.ok)return;let n=await t.json();D(n.proposal)}catch{}},[]),k=(0,P.useCallback)(async t=>{try{(await fetch(`${p()}/propose/${t}`,{method:`DELETE`})).ok&&(s.success(e(`page.proposalDeleted`)),await x())}catch{}},[x,e]);return(0,F.jsxs)(`div`,{className:`max-w-4xl mx-auto px-4 py-6`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,F.jsx)(`h1`,{className:`text-sm font-semibold`,children:e(`page.title`)}),(0,F.jsx)(N,{baseUrl:`${p()}/jobs/export`,label:e(`page.exportJobs`)})]}),(0,F.jsx)(H,{jobs:T,isLoading:i||d||o||f,error:c??_,onRetry:()=>{Promise.all([l(),x()])},onJobsCleared:l,onProposalClick:O,onProposalDelete:k}),(0,F.jsx)(ee,{open:E!==null,onOpenChange:e=>!e&&D(null),children:(0,F.jsx)(y,{className:`max-w-3xl glass-card`,children:E&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(g,{children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(b,{className:`flex-1 min-w-0`,children:e(`page.proposal.title`)}),(0,F.jsx)(re,{variant:E.status===`created`?`success`:E.status===`cancelled`?`destructive`:`secondary`,children:e(U[E.status]??`page.proposal.status.unknown`,{status:E.status})})]})}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:E.idea}),E.result_markdown?(0,F.jsx)(`div`,{className:`max-h-[400px] overflow-y-auto rounded-lg px-3 py-2 text-xs bg-muted/40`,children:(0,F.jsx)(`div`,{className:`prose prose-invert prose-xs max-w-none prose-p:my-1 prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-code:text-cyan-300 prose-code:text-[10px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded text-foreground/80`,children:(0,F.jsx)(te,{remarkPlugins:[ne],children:E.result_markdown})})}):(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:e(`page.proposal.noContent`)}),E.issue_url&&(0,F.jsxs)(`div`,{className:`text-xs`,children:[e(`page.proposal.githubIssue`),` `,(0,F.jsx)(`a`,{href:E.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:E.issue_url})]}),(0,F.jsxs)(v,{children:[(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{k(E.id),D(null)},children:e(`common:actions.delete`)}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>D(null),children:e(`common:actions.close`)})]})]})})})]})}export{G as default};