specrails-desktop 2.59.3 → 2.60.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 (132) hide show
  1. package/client/dist/assets/{ActivityFeedPage-BGEayjTY.js → ActivityFeedPage-3J7fR8yB.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-Qvg4y5Tr.js → AgentBrowserCapture-D4a3wYM1.js} +1 -1
  3. package/client/dist/assets/{AgentModeAnalyticsPane-CR7aFeLJ.js → AgentModeAnalyticsPane-Dps30tk9.js} +2 -2
  4. package/client/dist/assets/{AgentModeCodePane-gAd88Gng.js → AgentModeCodePane-CvLimey8.js} +2 -2
  5. package/client/dist/assets/{AgentModeJobsPane-EjCDuTow.js → AgentModeJobsPane-25tQlLpF.js} +1 -1
  6. package/client/dist/assets/{AgentsPage-CRHHcp1V.js → AgentsPage-CUDp_sfw.js} +2 -2
  7. package/client/dist/assets/{AnalyticsPage-a0b1fNEl.js → AnalyticsPage-DXWMGn8b.js} +1 -1
  8. package/client/dist/assets/{CodePage-BmV1m7l3.js → CodePage-D981zRHy.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-B87WmXOQ.js → DesktopAnalyticsPage-BkFBq0E6.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-Co0O672q.js → DocsDialog-BL7uSbIJ.js} +1 -1
  11. package/client/dist/assets/{DocsPage-DxGI6A2T.js → DocsPage-CsDLbmZX.js} +1 -1
  12. package/client/dist/assets/{ExportDropdown-1Ce031vB.js → ExportDropdown-B4Olg1Fk.js} +1 -1
  13. package/client/dist/assets/{InteractiveJobComposer-DkqR77pO.js → InteractiveJobComposer-Z6fl4791.js} +1 -1
  14. package/client/dist/assets/{JobDetailModal-DVLDVgzz.js → JobDetailModal-DS_Owxs6.js} +1 -1
  15. package/client/dist/assets/{JobDetailPage-RcP9N-D-.js → JobDetailPage-1TUQ9vlE.js} +1 -1
  16. package/client/dist/assets/{JobsPage-R9M4xQnp.js → JobsPage-BSrl8P7u.js} +1 -1
  17. package/client/dist/assets/LoopBuilderPage-Dh5uk2Qy.js +1 -0
  18. package/client/dist/assets/{LoopPreviewModal-DA2JeKWX.js → LoopPreviewModal-CH1r-KhU.js} +1 -1
  19. package/client/dist/assets/{LoopWindowSurface-BkkeD0hx.js → LoopWindowSurface-CiZdI6aw.js} +1 -1
  20. package/client/dist/assets/{LoopsPage-BHv--iI7.js → LoopsPage-BwFujdGi.js} +1 -1
  21. package/client/dist/assets/{MinimizedChatsContext-Bc9xHByW.js → MinimizedChatsContext-BD2bsRBe.js} +1 -1
  22. package/client/dist/assets/{PluginsPage-BEy62gxK.js → PluginsPage-B8f49Mvn.js} +1 -1
  23. package/client/dist/assets/{ProjectSettingsDialog-DDQ_f94T.js → ProjectSettingsDialog-D7q-O6h3.js} +1 -1
  24. package/client/dist/assets/{RepositoryDeliveries-DIWDFLRM.js → RepositoryDeliveries-NNorcGzT.js} +1 -1
  25. package/client/dist/assets/{RepositoryScopeSelector-D3PlHIM-.js → RepositoryScopeSelector-D-jb4bI_.js} +1 -1
  26. package/client/dist/assets/{ReviewPacketPage-BXdPwmdE.js → ReviewPacketPage-DpZSzF-Q.js} +1 -1
  27. package/client/dist/assets/{TemplatePreviewModal-C7-G6lvI.js → TemplatePreviewModal-5CZdAZ0G.js} +1 -1
  28. package/client/dist/assets/{TicketDetailModalContext-gGUv7gsQ.js → TicketDetailModalContext-BHmtj1As.js} +1 -1
  29. package/client/dist/assets/{Trans-Br_OIUKP.js → Trans-wmTUDVyC.js} +1 -1
  30. package/client/dist/assets/{agentRuntime-TXPQowKJ.js → agentRuntime-7Ydcvr6P.js} +1 -1
  31. package/client/dist/assets/{agentRuntime-Bpx3yWHK.js → agentRuntime-BHVw9orA.js} +1 -1
  32. package/client/dist/assets/{agentRuntime-15Pkk6we.js → agentRuntime-DCPDaQcV.js} +1 -1
  33. package/client/dist/assets/{agentRuntime-C78n13To.js → agentRuntime-DKTw4Ajg.js} +1 -1
  34. package/client/dist/assets/{agentRuntime-CCI7XF4c.js → agentRuntime-DVhij_i_.js} +1 -1
  35. package/client/dist/assets/{agentRuntime-Ddqvp2bP.js → agentRuntime-Doss-T8o.js} +1 -1
  36. package/client/dist/assets/{agentRuntime-CKDHe2-a.js → agentRuntime-eZSMUlkM.js} +1 -1
  37. package/client/dist/assets/{agentRuntime-hqZRy08E.js → agentRuntime-qSSU7fQk.js} +1 -1
  38. package/client/dist/assets/agents-B6ZsnARo.js +1 -0
  39. package/client/dist/assets/agents-BORdhe0K.js +1 -0
  40. package/client/dist/assets/agents-C6aq9Oqs.js +1 -0
  41. package/client/dist/assets/agents-Cbsc4bcX.js +1 -0
  42. package/client/dist/assets/agents-D0uYR6hq.js +1 -0
  43. package/client/dist/assets/agents-Doe1sHY5.js +1 -0
  44. package/client/dist/assets/agents-DyNi_I9m.js +1 -0
  45. package/client/dist/assets/agents-StKxiTg0.js +1 -0
  46. package/client/dist/assets/agentstudio-7cYCXn-L.js +1 -0
  47. package/client/dist/assets/{agentstudio-QdAJIDef.js → agentstudio-BHWQh8G3.js} +1 -1
  48. package/client/dist/assets/agentstudio-BjnWHyRs.js +1 -0
  49. package/client/dist/assets/{agentstudio-fLXpRGIi.js → agentstudio-BkV8vcK4.js} +1 -1
  50. package/client/dist/assets/{agentstudio-BWAKeGgB.js → agentstudio-BzugqB_N.js} +1 -1
  51. package/client/dist/assets/{agentstudio-Cja8Sjcp.js → agentstudio-CWbp7KvH.js} +1 -1
  52. package/client/dist/assets/agentstudio-DG6plf5o.js +1 -0
  53. package/client/dist/assets/agentstudio-DkZVF-Cc.js +1 -0
  54. package/client/dist/assets/{formatDistanceToNow-Q7QPRFV4.js → formatDistanceToNow-Dax4zqPF.js} +1 -1
  55. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-Bq0CXBaJ.js → getTimezoneOffsetInMilliseconds-dpIo42JZ.js} +1 -1
  56. package/client/dist/assets/{index-DVkWHOR3.js → index-g8S62tpS.js} +7 -7
  57. package/client/dist/assets/{jira-api-C2Tzc362.js → jira-api-CLrIvXFm.js} +1 -1
  58. package/client/dist/assets/{project-repositories-DZKmieH3.js → project-repositories-BkyT8AjU.js} +1 -1
  59. package/client/dist/assets/{spending-EXaboRU0.js → spending-Oov7p52A.js} +1 -1
  60. package/client/dist/assets/{useDesktop-ChSmmJfc.js → useDesktop-DpiS8Uov.js} +1 -1
  61. package/client/dist/assets/{useRuntimeRuns-w9-5OzZl.js → useRuntimeRuns-DBm1mul0.js} +1 -1
  62. package/client/dist/assets/{useSharedWebSocket-g0nTHfTT.js → useSharedWebSocket-BZxKaVNT.js} +2 -2
  63. package/client/dist/index.html +17 -17
  64. package/docs/getting-started.md +2 -2
  65. package/docs/guide/de/agents/1-meet-the-agents.md +1 -1
  66. package/docs/guide/de/agents/2-profiles-and-the-balanced-default.md +1 -1
  67. package/docs/guide/de/agents/3-customizing-models-per-agent.md +1 -1
  68. package/docs/guide/de/agents/4-custom-agents-catalog.md +3 -3
  69. package/docs/guide/en/agents/1-meet-the-agents.md +1 -1
  70. package/docs/guide/en/agents/2-profiles-and-the-balanced-default.md +1 -1
  71. package/docs/guide/en/agents/3-customizing-models-per-agent.md +1 -1
  72. package/docs/guide/en/agents/4-custom-agents-catalog.md +3 -3
  73. package/docs/guide/es/agents/1-meet-the-agents.md +1 -1
  74. package/docs/guide/es/agents/2-profiles-and-the-balanced-default.md +1 -1
  75. package/docs/guide/es/agents/3-customizing-models-per-agent.md +1 -1
  76. package/docs/guide/es/agents/4-custom-agents-catalog.md +3 -3
  77. package/docs/guide/fr/agents/1-meet-the-agents.md +1 -1
  78. package/docs/guide/fr/agents/2-profiles-and-the-balanced-default.md +1 -1
  79. package/docs/guide/fr/agents/3-customizing-models-per-agent.md +1 -1
  80. package/docs/guide/fr/agents/4-custom-agents-catalog.md +3 -3
  81. package/docs/guide/it/agents/1-meet-the-agents.md +1 -1
  82. package/docs/guide/it/agents/2-profiles-and-the-balanced-default.md +1 -1
  83. package/docs/guide/it/agents/3-customizing-models-per-agent.md +1 -1
  84. package/docs/guide/it/agents/4-custom-agents-catalog.md +3 -3
  85. package/docs/guide/ja/agents/1-meet-the-agents.md +1 -1
  86. package/docs/guide/ja/agents/2-profiles-and-the-balanced-default.md +1 -1
  87. package/docs/guide/ja/agents/3-customizing-models-per-agent.md +1 -1
  88. package/docs/guide/ja/agents/4-custom-agents-catalog.md +3 -3
  89. package/docs/guide/pt/agents/1-meet-the-agents.md +1 -1
  90. package/docs/guide/pt/agents/2-profiles-and-the-balanced-default.md +1 -1
  91. package/docs/guide/pt/agents/3-customizing-models-per-agent.md +1 -1
  92. package/docs/guide/pt/agents/4-custom-agents-catalog.md +3 -3
  93. package/docs/guide/zh/agents/1-meet-the-agents.md +1 -1
  94. package/docs/guide/zh/agents/2-profiles-and-the-balanced-default.md +1 -1
  95. package/docs/guide/zh/agents/3-customizing-models-per-agent.md +1 -1
  96. package/docs/guide/zh/agents/4-custom-agents-catalog.md +3 -3
  97. package/docs/internals/adding-a-provider.md +7 -6
  98. package/docs/internals/core-runtime-updates.md +19 -0
  99. package/docs/internals/profiles.md +17 -10
  100. package/docs/internals/review-packet.md +1 -1
  101. package/docs/internals/source-map.md +1 -1
  102. package/docs/running-pipelines.md +2 -2
  103. package/package.json +1 -1
  104. package/server/dist/core-compat.js +7 -3
  105. package/server/dist/mcp/guide.js +4 -3
  106. package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +7 -3
  107. package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings.js +24 -1
  108. package/server/dist/modules/agents/runtime/profiles-router.js +74 -36
  109. package/server/dist/modules/execution/runtime/queue-manager.js +7 -9
  110. package/server/dist/modules/loops/runtime/loop-agents.js +2 -5
  111. package/server/dist/modules/loops/runtime/loop-command-catalog.js +5 -5
  112. package/server/dist/modules/loops/runtime/loop-definition.js +1 -1
  113. package/server/dist/modules/loops/runtime/loop-executors.js +0 -2
  114. package/server/dist/modules/loops/runtime/loop-implement-recipe.js +5 -4
  115. package/server/dist/modules/loops/runtime/loops-router.js +3 -1
  116. package/server/dist/providers/gemini-agent-ack.js +13 -10
  117. package/server/dist/setup-manager.js +28 -43
  118. package/server/dist/workspace-manager.js +13 -71
  119. package/client/dist/assets/LoopBuilderPage-C4S-rkWp.js +0 -1
  120. package/client/dist/assets/agents-CA5eT1d0.js +0 -1
  121. package/client/dist/assets/agents-CAgy-5uS.js +0 -1
  122. package/client/dist/assets/agents-CNm6Qzlv.js +0 -1
  123. package/client/dist/assets/agents-CTwbx-fb.js +0 -1
  124. package/client/dist/assets/agents-DEGV1Vao.js +0 -1
  125. package/client/dist/assets/agents-HsDF1aQU.js +0 -1
  126. package/client/dist/assets/agents-IQjdA-z9.js +0 -1
  127. package/client/dist/assets/agents-RkGoteXh.js +0 -1
  128. package/client/dist/assets/agentstudio-B2CTtQgZ.js +0 -1
  129. package/client/dist/assets/agentstudio-DtfPcr99.js +0 -1
  130. package/client/dist/assets/agentstudio-X70BKf6u.js +0 -1
  131. package/client/dist/assets/agentstudio-qXKqVnWS.js +0 -1
  132. package/server/dist/modules/loops/runtime/loop-agent-defaults.json +0 -6
@@ -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{h as r,l as i,r as a}from"./useSharedWebSocket-g0nTHfTT.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as l,s as u}from"./useDesktop-ChSmmJfc.js";import{$ as d,Q as f,V as p,tt as m}from"./TicketDetailModalContext-gGUv7gsQ.js";import{n as h}from"./provider-capabilities-lePfeT_Y.js";import{n as g}from"./save-OsUqVn99.js";import{l as _}from"./MinimizedChatsContext-Bc9xHByW.js";import{n as v}from"./file-text-BcLCfcWZ.js";import{t as y}from"./circle-x-CMYsN4ZH.js";import{t as b}from"./git-branch-BRM0F5GN.js";import{t as x}from"./loader-circle-DcygOQpC.js";import{n as S,t as C}from"./square-Ci-PFcFe.js";import{t as w}from"./rotate-ccw-Wh4id13q.js";import{t as T}from"./search-Cq_gE3Ik.js";import{t as E}from"./triangle-alert-H9T4jAmh.js";import{t as D}from"./x-CBMI9ejn.js";import{L as O,l as k,n as A,r as j,t as M,u as N}from"./dialog-CMgps2MY.js";import{t as P}from"./utils-BC4DHlz2.js";import{n as F,t as I}from"./lib-CGdyxIWg.js";import{t as L}from"./button-D1xExSTF.js";import{n as R}from"./project-repositories-DZKmieH3.js";import{t as ee}from"./useRuntimeRuns-w9-5OzZl.js";import{$ as z,At as te,C as ne,Ct as re,E as ie,Gt as B,Ht as V,K as H,Mt as ae,St as U,T as oe,U as se,Y as W,Yt as ce,b as le,et as ue,gt as de,k as fe,kt as pe,q as me,st as he,tn as ge,tt as _e,w as ve,x as ye,y as be,zt as xe}from"./index-DVkWHOR3.js";import{l as Se,n as Ce,p as we,r as Te,t as Ee}from"./loop-layout-BF8xMiNv.js";import{t as De}from"./lib-C7Mhm-gT.js";import{n as Oe}from"./job-time-BCL7wee9.js";var ke=s(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),Ae=s(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),je=s(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),Me=s(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),Ne=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),Pe=s(`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`}]]),Fe=s(`message-circle-question-mark`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),G=e(t(),1),K=n();function Ie({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,K.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,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(H,{children:[(0,K.jsx)(W,{asChild:!0,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,K.jsx)(Le,{state:i}),(0,K.jsx)(`span`,{className:P(`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,K.jsxs)(me,{side:`bottom`,className:`max-w-[200px]`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,K.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,K.jsx)(`div`,{className:P(`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 Le({state:e}){return(0,K.jsxs)(`div`,{className:P(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,K.jsx)(x,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,K.jsx)(B,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,K.jsx)(y,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,K.jsx)(f,{className:`w-6 h-6 text-muted-foreground/20`})]})}function Re(e,t){let n=Oe(e??null),r=(typeof t==`number`?t:Oe(t??null)?.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 ze(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 Be={steps:0,actionKey:``,actionArg:``,turns:0,tokens:0,lastSeenIdx:0};function Ve(e){if(e.event_type!==`assistant`)return null;try{let t=JSON.parse(e.payload);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t.message,r=(n&&typeof n==`object`&&!Array.isArray(n)?n:t).usage;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r,a=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return a(i.input_tokens)+a(i.output_tokens)+a(i.cache_read_input_tokens)+a(i.cache_creation_input_tokens)}catch{return null}}function He(e,t){if(t.type===`reset`)return Be;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,turns:s,tokens:c}=e;for(let e=r;e<n.length;e++){let t=ye(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``);let r=Ve(n[e]);r!=null&&(s+=1,c+=r)}return{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c,lastSeenIdx:n.length}}return e}function Ue(e,t){let[n,r]=(0,G.useReducer)(He,Be),i=(0,G.useRef)(e);return(0,G.useEffect)(()=>{i.current!==e&&(i.current=e,r({type:`reset`})),r({type:`consume`,events:t})},[e,t]),n}function We(e,t){let n=t&&e.steps===0?`connecting`:e.actionKey||`thinking`,r=n===`delegating`||be.has(n),i=r&&e.actionArg!==``;return{key:r&&!i?`working`:n,arg:i?e.actionArg:null}}function Ge(e){return`${(e/1e3).toFixed(1)}k`}function Ke(e){let t=!!e.total_cost_usd_estimated,n=e.total_cost_usd==null?null:`${t?`~`:``}$${e.total_cost_usd.toFixed(4)}`,r=e.num_turns==null?null:String(e.num_turns),i=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0);return{cost:n,turns:r,tokens:i==null?null:Ge(i)}}function qe(e){if(e.length<=1)return null;let t=e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null;return{totalCostUsd:e.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:e.some(e=>e.total_cost_usd==null),costEstimated:e.some(e=>!!e.total_cost_usd_estimated),nullCostCount:e.filter(e=>e.total_cost_usd==null).length,costUnavailable:e.every(e=>e.total_cost_usd==null),totalTokensIn:e.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:e.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:e.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:e.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:e.filter(t).length,tokensUnavailable:e.every(t),jobCount:e.length}}function Je(e){return e.costUnavailable?`—`:`${e.costEstimated?`~`:``}${e.hasNullCost?`≥`:``}$${e.totalCostUsd.toFixed(4)}`}function Ye(e){if(e.tokensUnavailable)return`—`;let t=e.totalTokensIn+e.totalTokensOut+e.totalTokensCacheRead+e.totalTokensCacheCreate;return`${(e.nullTokenCount??0)>0?`≥`:``}${Ge(t)}`}var Xe=`specrails-desktop:job-run-details`;function Ze(e){try{let t=localStorage.getItem(Xe);return t?JSON.parse(t)?.[e]===!0:!1}catch{return!1}}function Qe(e,t){try{let n=localStorage.getItem(Xe),r={};if(n)try{let e=JSON.parse(n);e&&typeof e==`object`&&(r=e)}catch{}r[e]=t,localStorage.setItem(Xe,JSON.stringify(r))}catch{}}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`},skipped:{variant:`queued`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}};function et({job:e,events:t,phases:n,phaseDefinitions:r,projectId:i,variant:a,pipelineTotals:s,actions:c,onOpenRun:l}){let{t:u}=o(`jobs`),{t:d}=o(`agentRuntime`),f=e.status===`running`,p=e.status===`queued`,m=e.command.startsWith(`loop:`),_=$e[e.status]??$e.queued,[v,y]=(0,G.useState)(()=>Date.now());(0,G.useEffect)(()=>{if(!f)return;y(Date.now());let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[f]);let b=e.finished_at?Re(e.started_at,e.finished_at):f?Re(e.started_at,v):`—`,S=Ue(e.id,t),C=ee(i,{jobId:e.id,enabled:!!i}),w=C.runs[0],[T,E]=(0,G.useState)(()=>Ze(a)),D=e=>{E(e),Qe(a,e)},O=(0,G.useMemo)(()=>r.find(e=>n[e.key]===`running`)?.label??null,[n,r]),k=w?.nextStep?d(`roles.${w.nextStep}`,{defaultValue:w.nextStep}):null,A=O??k,{key:j,arg:M}=We(S,f),N=M==null?u(`statusPanel.activity.${j}`):u(`statusPanel.activity.${j}`,{arg:M}),F=f?A?u(`runHeader.phaseActivity`,{phase:A,activity:N}):N:w&&!w.active&&w.nextStep&&(w.canResume||w.pendingQuestion||w.pendingApproval)?u(`runHeader.phaseActivity`,{phase:d(`runs.status.${w.status}`,{defaultValue:w.status}),activity:d(`runs.phase`,{phase:k})}):null,I=m&&f&&S.steps>0?u(`statusPanel.steps`,{count:S.steps}):null,R=Ke(e),z=!f&&!p,te=(0,G.useMemo)(()=>z?ze(t):[],[t,z]),re=f&&S.turns>0,B=C.runs.length>0?C.error:``,V=!!w?.pendingQuestion&&!!w.canResume&&!w.recoverableSteps.length,ae=z||re||!!w&&!!i||!!B,U=C.busy!==null,se=w?(0,K.jsxs)(K.Fragment,{children:[w.canResume&&!V&&(w.engineVersion===2&&w.recoverableSteps.length>0?(0,K.jsx)(ie,{run:w,busy:U,onRecover:e=>void C.act(w,`recover`,e)},`${i}:${w.runId}`):(0,K.jsx)(L,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,w.recoverableSteps.length?`recover`:w.pendingApproval?`approve`:`resume`),children:w.recoverableSteps.length?d(`runs.recover`):w.pendingApproval?d(`runs.approve`):d(`runs.resume`)})),V&&(0,K.jsxs)(L,{size:`sm`,variant:`outline`,className:`h-7 border-accent-warning/40 text-accent-warning hover:bg-accent-warning/10`,onClick:()=>D(!0),children:[(0,K.jsx)(Fe,{className:`w-3.5 h-3.5 mr-1.5`,"aria-hidden":!0}),u(`runHeader.questionPending`)]}),w.canSettle&&(0,K.jsx)(L,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,`settle`),children:d(`runs.prepareDelivery`)}),w.forkSuccessor&&l&&(0,K.jsx)(L,{size:`sm`,variant:`outline`,onClick:()=>l(w.forkSuccessor),children:u(`loopExplorer.openFork`)}),w.canCancel&&(0,K.jsx)(L,{size:`sm`,variant:`secondary`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,`cancel`),children:d(`runs.cancel`)})]}):null;return(0,K.jsxs)(`div`,{"data-testid":`job-run-header`,className:P(`shrink-0`,a===`glass`?`border-b border-border/30 bg-surface/30`:`border-b border-border bg-background`),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap px-3 py-2 min-w-0`,children:[(0,K.jsxs)(H,{children:[(0,K.jsx)(W,{asChild:!0,children:(0,K.jsx)(`div`,{children:(0,K.jsx)(fe,{variant:_.variant,children:u(_.labelKey)})})}),(0,K.jsx)(me,{children:u(_.tooltipKey)})]}),(0,K.jsxs)(`span`,{className:P(`inline-flex items-center gap-1.5 text-xs tabular-nums`,f?`text-accent-info font-medium`:`text-muted-foreground`),title:u(f?`statusPanel.liveTooltip`:`statusPanel.duration`),children:[f&&(0,K.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,"aria-hidden":!0}),b]}),F&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 flex-1 basis-40 text-xs text-muted-foreground`,children:[f&&(0,K.jsx)(x,{className:`w-3 h-3 shrink-0 text-accent-info animate-spin`,"aria-hidden":!0}),(0,K.jsx)(`span`,{className:`truncate`,"data-testid":`job-run-activity`,children:F})]}),!F&&(0,K.jsx)(`span`,{className:`flex-1`}),I&&(0,K.jsx)(`span`,{className:`text-[11px] text-muted-foreground/70 tabular-nums shrink-0`,children:I}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 ml-auto`,children:[se,c,ae&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>D(!T),"aria-expanded":T,className:`inline-flex items-center gap-1 h-7 px-2 rounded-md text-[11px] text-muted-foreground hover:text-foreground hover:bg-surface/60 transition-colors`,children:[u(`runHeader.details`),(0,K.jsx)(g,{className:P(`w-3.5 h-3.5 transition-transform duration-150`,T&&`rotate-180`),"aria-hidden":!0})]})]})]}),r.length>0&&(0,K.jsx)(`div`,{className:`px-3 pb-2 overflow-x-auto`,children:(0,K.jsx)(Ie,{phases:n,phaseDefinitions:r})}),ae&&T&&(0,K.jsxs)(`div`,{"data-testid":`job-run-details`,className:`px-3 pb-3 space-y-3 border-t border-border/20 pt-3 text-xs`,children:[re&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:String(S.turns)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:Ge(S.tokens)})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-1`,children:u(`runHeader.liveReported`)})]}),z&&(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-lg`,children:[(0,K.jsx)(q,{label:u(`statusPanel.cost`),value:R.cost,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:h(e.provider)?u(`statusPanel.costUnknownLocal`):u(`statusPanel.notAvailable`),naTooltip:h(e.provider)?u(`statusPanel.costUnknownLocalTooltip`):void 0}),(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:R.turns,naCaption:u(`statusPanel.notAvailable`)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:R.tokens,naCaption:u(`statusPanel.notAvailable`)})]}),z&&s&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.pipelineTotal`,{count:s.jobCount})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.totalCost`),value:Je(s),valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,K.jsx)(q,{label:u(`statusPanel.totalTokens`),value:Ye(s)})]}),s.hasNullCost&&!s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:u(`statusPanel.pipelinePartialTooltip`),children:u(`statusPanel.pipelinePartial`,{count:s.nullCostCount??0})}),s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:u(`statusPanel.pipelineCostUnavailable`)}),(s.nullTokenCount??0)>0&&(0,K.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:u(`statusPanel.pipelineUsageTooltip`),children:s.tokensUnavailable?u(`statusPanel.pipelineUsageUnavailable`):u(`statusPanel.pipelineUsagePartial`,{count:s.nullTokenCount??0})})]}),te.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.filesModified`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:te.map(e=>(0,K.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))})]}),(w||B)&&i&&(0,K.jsxs)(`section`,{"aria-label":d(`runs.implementation`),className:`space-y-2`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[B&&(0,K.jsx)(`p`,{role:`alert`,className:`text-destructive`,children:B}),w?.historical&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`evidence.historical`)}),w?.status===`succeeded`&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.reviewDelivery`)}),w?.canResume&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.preserveProgress`)}),w?.error&&(0,K.jsx)(`p`,{className:`text-destructive`,children:w.error}),w?.pendingApproval?.reason&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:w.pendingApproval.reason}),w?.pendingQuestion&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:d(`runs.question`)}),(0,K.jsx)(`p`,{className:`whitespace-pre-wrap`,children:w.pendingQuestion.question}),V&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[d(`runs.answerLabel`),(0,K.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border border-input bg-background px-2 py-1 text-sm`,maxLength:2e4,placeholder:d(`runs.answerPlaceholder`),value:C.answers[w.runId]??``,onChange:e=>C.setAnswer(w.runId,e.target.value)})]}),(0,K.jsx)(L,{size:`sm`,disabled:U||!C.answers[w.runId]?.trim(),onClick:()=>void C.act(w,`answer`),children:d(`runs.answer`)})]})]}),w?.metrics&&(0,K.jsx)(ne,{metrics:w.metrics}),w&&(0,K.jsx)(oe,{projectId:i,runId:w.runId,summary:w.efficiencySummary,historical:w.historical}),w&&(0,K.jsx)(ve,{projectId:i,run:w,onAccepted:C.refresh})]})]})]})}function q({label:e,value:t,valueClass:n,naCaption:r,naTooltip:i}){return(0,K.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-2.5 py-1.5`,title:t==null?i:void 0,children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,K.jsx)(`p`,{className:P(`text-sm font-semibold tabular-nums`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&r&&(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/40`,children:r})]})}function tt(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 nt=new Set;function rt({ticketId:e,onOpen:t,children:n}){let{t:r}=o(`agent`),i=r(`refs.openTicket`,{id:e});return(0,K.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 it(e){if(!e.includes(`#`))return null;let t=_e(e,nt);return t.some(e=>e.kind===`ticket`)?t:null}function at(e,t){let n=it(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,K.jsx)(rt,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,K.jsx)(G.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var ot=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function st(e){return e.kind===`ticket`?{type:`link`,url:z({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function ct(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!ot.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=_e(n.value,nt);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(st))}else ct(n)}}function lt(){return e=>ct(e)}function ut(e){let{activeProjectId:t}=l(),{openRef:n}=he(),r=e??t??void 0;return(0,G.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function dt(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}:tt(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 ft(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 pt(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{h as r,l as i,r as a}from"./useSharedWebSocket-BZxKaVNT.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as l,s as u}from"./useDesktop-DpiS8Uov.js";import{$ as d,Q as f,V as p,tt as m}from"./TicketDetailModalContext-BHmtj1As.js";import{n as h}from"./provider-capabilities-lePfeT_Y.js";import{n as g}from"./save-OsUqVn99.js";import{l as _}from"./MinimizedChatsContext-BD2bsRBe.js";import{n as v}from"./file-text-BcLCfcWZ.js";import{t as y}from"./circle-x-CMYsN4ZH.js";import{t as b}from"./git-branch-BRM0F5GN.js";import{t as x}from"./loader-circle-DcygOQpC.js";import{n as S,t as C}from"./square-Ci-PFcFe.js";import{t as w}from"./rotate-ccw-Wh4id13q.js";import{t as T}from"./search-Cq_gE3Ik.js";import{t as E}from"./triangle-alert-H9T4jAmh.js";import{t as D}from"./x-CBMI9ejn.js";import{L as O,l as k,n as A,r as j,t as M,u as N}from"./dialog-CMgps2MY.js";import{t as P}from"./utils-BC4DHlz2.js";import{n as F,t as I}from"./lib-CGdyxIWg.js";import{t as L}from"./button-D1xExSTF.js";import{n as R}from"./project-repositories-BkyT8AjU.js";import{t as ee}from"./useRuntimeRuns-DBm1mul0.js";import{$ as z,At as te,C as ne,Ct as re,E as ie,Gt as B,Ht as V,K as H,Mt as ae,St as U,T as oe,U as se,Y as W,Yt as ce,b as le,et as ue,gt as de,k as fe,kt as pe,q as me,st as he,tn as ge,tt as _e,w as ve,x as ye,y as be,zt as xe}from"./index-g8S62tpS.js";import{l as Se,n as Ce,p as we,r as Te,t as Ee}from"./loop-layout-BF8xMiNv.js";import{t as De}from"./lib-C7Mhm-gT.js";import{n as Oe}from"./job-time-BCL7wee9.js";var ke=s(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),Ae=s(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),je=s(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),Me=s(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),Ne=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),Pe=s(`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`}]]),Fe=s(`message-circle-question-mark`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),G=e(t(),1),K=n();function Ie({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,K.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,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(H,{children:[(0,K.jsx)(W,{asChild:!0,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,K.jsx)(Le,{state:i}),(0,K.jsx)(`span`,{className:P(`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,K.jsxs)(me,{side:`bottom`,className:`max-w-[200px]`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,K.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,K.jsx)(`div`,{className:P(`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 Le({state:e}){return(0,K.jsxs)(`div`,{className:P(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,K.jsx)(x,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,K.jsx)(B,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,K.jsx)(y,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,K.jsx)(f,{className:`w-6 h-6 text-muted-foreground/20`})]})}function Re(e,t){let n=Oe(e??null),r=(typeof t==`number`?t:Oe(t??null)?.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 ze(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 Be={steps:0,actionKey:``,actionArg:``,turns:0,tokens:0,lastSeenIdx:0};function Ve(e){if(e.event_type!==`assistant`)return null;try{let t=JSON.parse(e.payload);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t.message,r=(n&&typeof n==`object`&&!Array.isArray(n)?n:t).usage;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r,a=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return a(i.input_tokens)+a(i.output_tokens)+a(i.cache_read_input_tokens)+a(i.cache_creation_input_tokens)}catch{return null}}function He(e,t){if(t.type===`reset`)return Be;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,turns:s,tokens:c}=e;for(let e=r;e<n.length;e++){let t=ye(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``);let r=Ve(n[e]);r!=null&&(s+=1,c+=r)}return{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c,lastSeenIdx:n.length}}return e}function Ue(e,t){let[n,r]=(0,G.useReducer)(He,Be),i=(0,G.useRef)(e);return(0,G.useEffect)(()=>{i.current!==e&&(i.current=e,r({type:`reset`})),r({type:`consume`,events:t})},[e,t]),n}function We(e,t){let n=t&&e.steps===0?`connecting`:e.actionKey||`thinking`,r=n===`delegating`||be.has(n),i=r&&e.actionArg!==``;return{key:r&&!i?`working`:n,arg:i?e.actionArg:null}}function Ge(e){return`${(e/1e3).toFixed(1)}k`}function Ke(e){let t=!!e.total_cost_usd_estimated,n=e.total_cost_usd==null?null:`${t?`~`:``}$${e.total_cost_usd.toFixed(4)}`,r=e.num_turns==null?null:String(e.num_turns),i=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0);return{cost:n,turns:r,tokens:i==null?null:Ge(i)}}function qe(e){if(e.length<=1)return null;let t=e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null;return{totalCostUsd:e.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:e.some(e=>e.total_cost_usd==null),costEstimated:e.some(e=>!!e.total_cost_usd_estimated),nullCostCount:e.filter(e=>e.total_cost_usd==null).length,costUnavailable:e.every(e=>e.total_cost_usd==null),totalTokensIn:e.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:e.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:e.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:e.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:e.filter(t).length,tokensUnavailable:e.every(t),jobCount:e.length}}function Je(e){return e.costUnavailable?`—`:`${e.costEstimated?`~`:``}${e.hasNullCost?`≥`:``}$${e.totalCostUsd.toFixed(4)}`}function Ye(e){if(e.tokensUnavailable)return`—`;let t=e.totalTokensIn+e.totalTokensOut+e.totalTokensCacheRead+e.totalTokensCacheCreate;return`${(e.nullTokenCount??0)>0?`≥`:``}${Ge(t)}`}var Xe=`specrails-desktop:job-run-details`;function Ze(e){try{let t=localStorage.getItem(Xe);return t?JSON.parse(t)?.[e]===!0:!1}catch{return!1}}function Qe(e,t){try{let n=localStorage.getItem(Xe),r={};if(n)try{let e=JSON.parse(n);e&&typeof e==`object`&&(r=e)}catch{}r[e]=t,localStorage.setItem(Xe,JSON.stringify(r))}catch{}}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`},skipped:{variant:`queued`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}};function et({job:e,events:t,phases:n,phaseDefinitions:r,projectId:i,variant:a,pipelineTotals:s,actions:c,onOpenRun:l}){let{t:u}=o(`jobs`),{t:d}=o(`agentRuntime`),f=e.status===`running`,p=e.status===`queued`,m=e.command.startsWith(`loop:`),_=$e[e.status]??$e.queued,[v,y]=(0,G.useState)(()=>Date.now());(0,G.useEffect)(()=>{if(!f)return;y(Date.now());let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[f]);let b=e.finished_at?Re(e.started_at,e.finished_at):f?Re(e.started_at,v):`—`,S=Ue(e.id,t),C=ee(i,{jobId:e.id,enabled:!!i}),w=C.runs[0],[T,E]=(0,G.useState)(()=>Ze(a)),D=e=>{E(e),Qe(a,e)},O=(0,G.useMemo)(()=>r.find(e=>n[e.key]===`running`)?.label??null,[n,r]),k=w?.nextStep?d(`roles.${w.nextStep}`,{defaultValue:w.nextStep}):null,A=O??k,{key:j,arg:M}=We(S,f),N=M==null?u(`statusPanel.activity.${j}`):u(`statusPanel.activity.${j}`,{arg:M}),F=f?A?u(`runHeader.phaseActivity`,{phase:A,activity:N}):N:w&&!w.active&&w.nextStep&&(w.canResume||w.pendingQuestion||w.pendingApproval)?u(`runHeader.phaseActivity`,{phase:d(`runs.status.${w.status}`,{defaultValue:w.status}),activity:d(`runs.phase`,{phase:k})}):null,I=m&&f&&S.steps>0?u(`statusPanel.steps`,{count:S.steps}):null,R=Ke(e),z=!f&&!p,te=(0,G.useMemo)(()=>z?ze(t):[],[t,z]),re=f&&S.turns>0,B=C.runs.length>0?C.error:``,V=!!w?.pendingQuestion&&!!w.canResume&&!w.recoverableSteps.length,ae=z||re||!!w&&!!i||!!B,U=C.busy!==null,se=w?(0,K.jsxs)(K.Fragment,{children:[w.canResume&&!V&&(w.engineVersion===2&&w.recoverableSteps.length>0?(0,K.jsx)(ie,{run:w,busy:U,onRecover:e=>void C.act(w,`recover`,e)},`${i}:${w.runId}`):(0,K.jsx)(L,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,w.recoverableSteps.length?`recover`:w.pendingApproval?`approve`:`resume`),children:w.recoverableSteps.length?d(`runs.recover`):w.pendingApproval?d(`runs.approve`):d(`runs.resume`)})),V&&(0,K.jsxs)(L,{size:`sm`,variant:`outline`,className:`h-7 border-accent-warning/40 text-accent-warning hover:bg-accent-warning/10`,onClick:()=>D(!0),children:[(0,K.jsx)(Fe,{className:`w-3.5 h-3.5 mr-1.5`,"aria-hidden":!0}),u(`runHeader.questionPending`)]}),w.canSettle&&(0,K.jsx)(L,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,`settle`),children:d(`runs.prepareDelivery`)}),w.forkSuccessor&&l&&(0,K.jsx)(L,{size:`sm`,variant:`outline`,onClick:()=>l(w.forkSuccessor),children:u(`loopExplorer.openFork`)}),w.canCancel&&(0,K.jsx)(L,{size:`sm`,variant:`secondary`,className:`h-7`,disabled:U,onClick:()=>void C.act(w,`cancel`),children:d(`runs.cancel`)})]}):null;return(0,K.jsxs)(`div`,{"data-testid":`job-run-header`,className:P(`shrink-0`,a===`glass`?`border-b border-border/30 bg-surface/30`:`border-b border-border bg-background`),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap px-3 py-2 min-w-0`,children:[(0,K.jsxs)(H,{children:[(0,K.jsx)(W,{asChild:!0,children:(0,K.jsx)(`div`,{children:(0,K.jsx)(fe,{variant:_.variant,children:u(_.labelKey)})})}),(0,K.jsx)(me,{children:u(_.tooltipKey)})]}),(0,K.jsxs)(`span`,{className:P(`inline-flex items-center gap-1.5 text-xs tabular-nums`,f?`text-accent-info font-medium`:`text-muted-foreground`),title:u(f?`statusPanel.liveTooltip`:`statusPanel.duration`),children:[f&&(0,K.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,"aria-hidden":!0}),b]}),F&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 flex-1 basis-40 text-xs text-muted-foreground`,children:[f&&(0,K.jsx)(x,{className:`w-3 h-3 shrink-0 text-accent-info animate-spin`,"aria-hidden":!0}),(0,K.jsx)(`span`,{className:`truncate`,"data-testid":`job-run-activity`,children:F})]}),!F&&(0,K.jsx)(`span`,{className:`flex-1`}),I&&(0,K.jsx)(`span`,{className:`text-[11px] text-muted-foreground/70 tabular-nums shrink-0`,children:I}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 ml-auto`,children:[se,c,ae&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>D(!T),"aria-expanded":T,className:`inline-flex items-center gap-1 h-7 px-2 rounded-md text-[11px] text-muted-foreground hover:text-foreground hover:bg-surface/60 transition-colors`,children:[u(`runHeader.details`),(0,K.jsx)(g,{className:P(`w-3.5 h-3.5 transition-transform duration-150`,T&&`rotate-180`),"aria-hidden":!0})]})]})]}),r.length>0&&(0,K.jsx)(`div`,{className:`px-3 pb-2 overflow-x-auto`,children:(0,K.jsx)(Ie,{phases:n,phaseDefinitions:r})}),ae&&T&&(0,K.jsxs)(`div`,{"data-testid":`job-run-details`,className:`px-3 pb-3 space-y-3 border-t border-border/20 pt-3 text-xs`,children:[re&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:String(S.turns)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:Ge(S.tokens)})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-1`,children:u(`runHeader.liveReported`)})]}),z&&(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-lg`,children:[(0,K.jsx)(q,{label:u(`statusPanel.cost`),value:R.cost,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:h(e.provider)?u(`statusPanel.costUnknownLocal`):u(`statusPanel.notAvailable`),naTooltip:h(e.provider)?u(`statusPanel.costUnknownLocalTooltip`):void 0}),(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:R.turns,naCaption:u(`statusPanel.notAvailable`)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:R.tokens,naCaption:u(`statusPanel.notAvailable`)})]}),z&&s&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.pipelineTotal`,{count:s.jobCount})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.totalCost`),value:Je(s),valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,K.jsx)(q,{label:u(`statusPanel.totalTokens`),value:Ye(s)})]}),s.hasNullCost&&!s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:u(`statusPanel.pipelinePartialTooltip`),children:u(`statusPanel.pipelinePartial`,{count:s.nullCostCount??0})}),s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:u(`statusPanel.pipelineCostUnavailable`)}),(s.nullTokenCount??0)>0&&(0,K.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:u(`statusPanel.pipelineUsageTooltip`),children:s.tokensUnavailable?u(`statusPanel.pipelineUsageUnavailable`):u(`statusPanel.pipelineUsagePartial`,{count:s.nullTokenCount??0})})]}),te.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.filesModified`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:te.map(e=>(0,K.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))})]}),(w||B)&&i&&(0,K.jsxs)(`section`,{"aria-label":d(`runs.implementation`),className:`space-y-2`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[B&&(0,K.jsx)(`p`,{role:`alert`,className:`text-destructive`,children:B}),w?.historical&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`evidence.historical`)}),w?.status===`succeeded`&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.reviewDelivery`)}),w?.canResume&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.preserveProgress`)}),w?.error&&(0,K.jsx)(`p`,{className:`text-destructive`,children:w.error}),w?.pendingApproval?.reason&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:w.pendingApproval.reason}),w?.pendingQuestion&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:d(`runs.question`)}),(0,K.jsx)(`p`,{className:`whitespace-pre-wrap`,children:w.pendingQuestion.question}),V&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[d(`runs.answerLabel`),(0,K.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border border-input bg-background px-2 py-1 text-sm`,maxLength:2e4,placeholder:d(`runs.answerPlaceholder`),value:C.answers[w.runId]??``,onChange:e=>C.setAnswer(w.runId,e.target.value)})]}),(0,K.jsx)(L,{size:`sm`,disabled:U||!C.answers[w.runId]?.trim(),onClick:()=>void C.act(w,`answer`),children:d(`runs.answer`)})]})]}),w?.metrics&&(0,K.jsx)(ne,{metrics:w.metrics}),w&&(0,K.jsx)(oe,{projectId:i,runId:w.runId,summary:w.efficiencySummary,historical:w.historical}),w&&(0,K.jsx)(ve,{projectId:i,run:w,onAccepted:C.refresh})]})]})]})}function q({label:e,value:t,valueClass:n,naCaption:r,naTooltip:i}){return(0,K.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-2.5 py-1.5`,title:t==null?i:void 0,children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,K.jsx)(`p`,{className:P(`text-sm font-semibold tabular-nums`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&r&&(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/40`,children:r})]})}function tt(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 nt=new Set;function rt({ticketId:e,onOpen:t,children:n}){let{t:r}=o(`agent`),i=r(`refs.openTicket`,{id:e});return(0,K.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 it(e){if(!e.includes(`#`))return null;let t=_e(e,nt);return t.some(e=>e.kind===`ticket`)?t:null}function at(e,t){let n=it(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,K.jsx)(rt,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,K.jsx)(G.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var ot=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function st(e){return e.kind===`ticket`?{type:`link`,url:z({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function ct(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!ot.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=_e(n.value,nt);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(st))}else ct(n)}}function lt(){return e=>ct(e)}function ut(e){let{activeProjectId:t}=l(),{openRef:n}=he(),r=e??t??void 0;return(0,G.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function dt(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}:tt(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 ft(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 pt(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 mt(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 ht({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=o(`jobs`),[a,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(!0),[d,f]=(0,G.useState)(new Set),p=(0,G.useRef)(null),m=(0,G.useRef)(null),h=ut(n),{processedLines:_,groups:v,totalLines:y}=(0,G.useMemo)(()=>{let t=ft(pt(e.map((e,t)=>dt(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:mt(t),totalLines:t.length}},[e,i.language]),b=(0,G.useMemo)(()=>{if(!a)return y;let e=a.toLowerCase();return _.filter(t=>t.content.toLowerCase().includes(e)).length},[a,_,y]),x=(0,G.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,G.useEffect)(()=>{c&&x()},[e.length,c,x]);function S(){let e=m.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;l(t)}function C(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):y===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,K.jsx)(T,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,K.jsx)(se,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>s(e.target.value),className:`pl-7 h-7`})]}),(0,K.jsx)(L,{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(()=>{u.success(r(`logViewer.copySuccess`))}).catch(()=>{u.error(r(`logViewer.copyFailed`))})},children:(0,K.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:b,total:y})})]}),(0,K.jsxs)(`div`,{ref:m,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:S,children:[v.map(e=>(0,K.jsx)(gt,{group:e,filter:a,collapsed:d.has(e.key),onToggle:()=>C(e.key),onOpenTicket:h},e.key)),(0,K.jsx)(`div`,{ref:p})]}),!c&&(0,K.jsxs)(L,{size:`sm`,variant:`secondary`,onClick:()=>{l(!0),x()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,K.jsx)(g,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var gt=(0,G.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:a}=o(`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,K.jsx)(`div`,{children:s.map((e,t)=>(0,K.jsx)(bt,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let c=e.header.content;return(0,K.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:P(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,K.jsx)(v,{className:P(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:c}),e.header.timestamp&&(0,K.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,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:a(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:s.length===0?(0,K.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:a(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):s.map((e,t)=>(0,K.jsx)(bt,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),_t=[De],vt=[I],yt=[I,lt],bt=(0,G.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,G.useMemo)(()=>l&&n?at(e.content,n):e.content,[l,n,e.content]),d=r&&n?yt:vt,f=(0,G.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=ue(e);return r?.kind===`ticket`?(0,K.jsx)(rt,{ticketId:r.ticketId,onOpen:n,children:t}):(0,K.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,K.jsxs)(`div`,{className:P(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,K.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,K.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,c as a,l as o,m as s}from"./useSharedWebSocket-g0nTHfTT.js";import{n as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,s as u}from"./useDesktop-ChSmmJfc.js";import{dt as d,gt as f}from"./TicketDetailModalContext-gGUv7gsQ.js";import{a as p,c as m,i as h,l as g,n as ee,o as te,r as ne,s as re,t as ie,u as _}from"./InteractiveJobComposer-DkqR77pO.js";import{t as v}from"./loader-circle-DcygOQpC.js";import{t as y}from"./x-CBMI9ejn.js";import{F as b,I as x,P as S}from"./dialog-CMgps2MY.js";import{t as ae}from"./formatDistanceToNow-Q7QPRFV4.js";import{t as C}from"./button-D1xExSTF.js";import{G as oe,J as se,W as ce}from"./index-DVkWHOR3.js";import{n as le,t as ue}from"./job-time-BCL7wee9.js";var de=e(r(),1),w=e(t(),1),T=[1e3,2e3,4e3,8e3,16e3];function E(e,t){let[n,r]=(0,w.useState)(`connecting`),o=(0,w.useRef)(t);return o.current=t,(0,w.useEffect)(()=>{let t=!1,n=!1,s=null,c=0,l=null;async function u(){if(!(t||n||s)){n=!0;try{await a()}catch{}finally{n=!1}!t&&!s&&f()}}function d(){if(t)return;l!==null&&clearTimeout(l),r(`connecting`);let e=T[c++]??3e4;l=setTimeout(()=>{l=null,u()},e)}function f(){if(t||s)return;let n=i(),a;try{a=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e)}catch{d();return}s=a,r(`connecting`),a.onopen=()=>{t||s!==a||(c=0,r(`connected`))},a.onmessage=e=>{if(!(t||s!==a))try{o.current(JSON.parse(e.data))}catch{}},a.onclose=()=>{t||s!==a||(s=null,d())}}let p=()=>{t||s||(l!==null&&clearTimeout(l),l=null,u())};return window.addEventListener(`online`,p),window.addEventListener(`focus`,p),f(),()=>{t=!0,window.removeEventListener(`online`,p),window.removeEventListener(`focus`,p),l!==null&&clearTimeout(l);let e=s;if(s=null,e){e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null;try{e.close()}catch{}}}},[e]),{connectionStatus:n}}var D=n();function O({jobId:e,onClose:t,projectId:n}){let[r,i]=(0,w.useState)(e);(0,w.useEffect)(()=>{i(e)},[e]);let{t:a}=c(`jobs`),{t:T}=c(`narration`),O=(0,w.useCallback)(()=>n?`${o}/api/projects/${n}`:l(),[n]),[k,fe]=(0,w.useState)(p),pe=(0,w.useCallback)(e=>{fe(e),te(e)},[]),[A,j]=(0,w.useState)(null),[M,N]=(0,w.useState)(()=>h([])),P=(0,w.useMemo)(()=>ne(M,a(`logViewer.retainedTail`)),[M,a]),[F,I]=(0,w.useState)([]),[L,R]=(0,w.useState)({}),[z,B]=(0,w.useState)(!0),[me,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(!1);(0,w.useEffect)(()=>{let e=!1;q.current={events:[],omitted:!1},J.current&&cancelAnimationFrame(J.current),J.current=null,N(h([])),j(null),B(!0),V(!1);async function t(){try{let t=await fetch(`${O()}/jobs/${r}`);if(e)return;if(t.status===404){V(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(e)return;if(j(n.job),N(h(n.events)),n.phaseDefinitions){I(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;R(e)}}catch{e||V(!0)}finally{e||B(!1)}}return t(),()=>{e=!0}},[r,O]);let K=(0,w.useCallback)(()=>{fetch(`${O()}/jobs/${r}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[r,O]),q=(0,w.useRef)({events:[],omitted:!1}),J=(0,w.useRef)(null),Y=(0,w.useCallback)(()=>{J.current=null;let e=q.current;e.events.length!==0&&(q.current={events:[],omitted:!1},N(t=>h([...t.events,...e.events],t.omitted||e.omitted)))},[]),X=(0,w.useCallback)(e=>{if(!ee(e))return;let t=q.current;t.events.push(e),t.events.length>1e4&&(q.current=h(t.events,t.omitted)),J.current||=requestAnimationFrame(Y)},[Y]);(0,w.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),E(f,(0,w.useCallback)(e=>{let t=e;if(t.type===`event`&&t.jobId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};X(e)}else if(t.type===`log`&&t.processId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line,...typeof t.attemptId==`string`&&t.attemptId.trim()&&t.attemptId.length<=256?{attemptId:t.attemptId}:{}}),timestamp:t.timestamp};X(e)}else if(t.type===`job.finalized`&&t.jobId===r||t.type===`runtime.continuation`&&t.jobId===r||t.type===`job.interactive`&&t.jobId===r||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===r)K();else if(t.type===`phase`){let e=t.phase,n=t.state;R(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===r);e&&A&&j(t=>t&&{...t,status:e.status})}},[r,A,X,K])),(0,w.useEffect)(()=>{function e(e){if(!(e.key!==`Escape`||e.defaultPrevented)){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let Z=A?oe(A):`job`,Q=Z===`loop-run`;async function he(){G(!0);try{let e=await ce({projectId:n??null,jobId:r,kind:Z});e.ok?(u.success(a(Q?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:a(Q?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):u.error(a(`modal.toast.cancelFailed`),{description:e.error})}finally{G(!1)}}let ge=A?.status===`running`,$=A?le(ue(A)):null,{panelRef:_e,panelStyle:ve,headerHandleProps:ye,resizeHandles:be,isFloating:xe,guardBackdrop:Se}=b();return(0,de.createPortal)((0,D.jsx)(se,{delayDuration:400,children:(0,D.jsxs)(`div`,{style:x(),className:`fixed inset-0 z-[65] flex items-stretch justify-center p-[clamp(12px,2vmin,24px)]`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:Se(t)}),(0,D.jsxs)(`div`,{ref:_e,className:`relative w-full min-w-0 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:ve,children:[(0,D.jsxs)(`div`,{...ye,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${xe?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[A&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:A.command}),(0,D.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:$?ae($,{addSuffix:!0,locale:s()}):`—`})]}),z&&(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a(`common:states.loading`)})]}),(0,D.jsx)(`button`,{onClick:t,className:`h-7 w-7 shrink-0 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,D.jsx)(y,{className:`w-4 h-4`})})]}),A&&(0,D.jsx)(_,{onOpenRun:i,job:A,events:P,phases:L,phaseDefinitions:F,projectId:n,variant:`glass`,actions:ge?(0,D.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,D.jsx)(v,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),a(Q?`dashboard:railControls.stop`:Z===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}):null}),M.omitted&&(0,D.jsx)(`p`,{role:`status`,className:`shrink-0 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:a(`logViewer.retainedTail`)}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden relative`,children:me?(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a(`modal.notFound`)})}):d&&A?(0,D.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,D.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>pe(e),"aria-pressed":k===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${k===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:T(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:k===`narrated`?(0,D.jsx)(re,{events:P,settled:A.status!==`running`&&A.status!==`queued`,elapsedMs:A.duration_ms??null,variant:`glass`}):A.command.startsWith(`loop:`)?(0,D.jsx)(m,{events:P,jobStatus:A.status,isLoading:z,variant:`glass`,projectId:n,onOpenRun:i}):(0,D.jsx)(g,{events:P,isLoading:z,projectId:n})})]}):A?.command.startsWith(`loop:`)?(0,D.jsx)(m,{events:P,jobStatus:A.status,isLoading:z,variant:`glass`,projectId:n,onOpenRun:i}):(0,D.jsx)(g,{events:P,isLoading:z,projectId:n})}),!!A?.interactive&&A.status===`running`&&(0,D.jsx)(ie,{jobId:r,projectId:n,settleMode:A.interactiveSettleMode,initialAcceptingTurns:A.interactiveAcceptingTurns,pendingInterrupts:A.pendingInterrupts,kind:A.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,D.jsx)(S,{handles:be}),H&&(0,D.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,D.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,D.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:a(Q?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:a(Q?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,D.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,D.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:a(`modal.keepRunning`)}),(0,D.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),he()},children:a(Q?`modal.stopRun`:Z===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{O 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,c as a,l as o,m as s}from"./useSharedWebSocket-BZxKaVNT.js";import{n as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,s as u}from"./useDesktop-DpiS8Uov.js";import{dt as d,gt as f}from"./TicketDetailModalContext-BHmtj1As.js";import{a as p,c as m,i as h,l as g,n as ee,o as te,r as ne,s as re,t as ie,u as _}from"./InteractiveJobComposer-Z6fl4791.js";import{t as v}from"./loader-circle-DcygOQpC.js";import{t as y}from"./x-CBMI9ejn.js";import{F as b,I as x,P as S}from"./dialog-CMgps2MY.js";import{t as ae}from"./formatDistanceToNow-Dax4zqPF.js";import{t as C}from"./button-D1xExSTF.js";import{G as oe,J as se,W as ce}from"./index-g8S62tpS.js";import{n as le,t as ue}from"./job-time-BCL7wee9.js";var de=e(r(),1),w=e(t(),1),T=[1e3,2e3,4e3,8e3,16e3];function E(e,t){let[n,r]=(0,w.useState)(`connecting`),o=(0,w.useRef)(t);return o.current=t,(0,w.useEffect)(()=>{let t=!1,n=!1,s=null,c=0,l=null;async function u(){if(!(t||n||s)){n=!0;try{await a()}catch{}finally{n=!1}!t&&!s&&f()}}function d(){if(t)return;l!==null&&clearTimeout(l),r(`connecting`);let e=T[c++]??3e4;l=setTimeout(()=>{l=null,u()},e)}function f(){if(t||s)return;let n=i(),a;try{a=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e)}catch{d();return}s=a,r(`connecting`),a.onopen=()=>{t||s!==a||(c=0,r(`connected`))},a.onmessage=e=>{if(!(t||s!==a))try{o.current(JSON.parse(e.data))}catch{}},a.onclose=()=>{t||s!==a||(s=null,d())}}let p=()=>{t||s||(l!==null&&clearTimeout(l),l=null,u())};return window.addEventListener(`online`,p),window.addEventListener(`focus`,p),f(),()=>{t=!0,window.removeEventListener(`online`,p),window.removeEventListener(`focus`,p),l!==null&&clearTimeout(l);let e=s;if(s=null,e){e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null;try{e.close()}catch{}}}},[e]),{connectionStatus:n}}var D=n();function O({jobId:e,onClose:t,projectId:n}){let[r,i]=(0,w.useState)(e);(0,w.useEffect)(()=>{i(e)},[e]);let{t:a}=c(`jobs`),{t:T}=c(`narration`),O=(0,w.useCallback)(()=>n?`${o}/api/projects/${n}`:l(),[n]),[k,fe]=(0,w.useState)(p),pe=(0,w.useCallback)(e=>{fe(e),te(e)},[]),[A,j]=(0,w.useState)(null),[M,N]=(0,w.useState)(()=>h([])),P=(0,w.useMemo)(()=>ne(M,a(`logViewer.retainedTail`)),[M,a]),[F,I]=(0,w.useState)([]),[L,R]=(0,w.useState)({}),[z,B]=(0,w.useState)(!0),[me,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(!1);(0,w.useEffect)(()=>{let e=!1;q.current={events:[],omitted:!1},J.current&&cancelAnimationFrame(J.current),J.current=null,N(h([])),j(null),B(!0),V(!1);async function t(){try{let t=await fetch(`${O()}/jobs/${r}`);if(e)return;if(t.status===404){V(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(e)return;if(j(n.job),N(h(n.events)),n.phaseDefinitions){I(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;R(e)}}catch{e||V(!0)}finally{e||B(!1)}}return t(),()=>{e=!0}},[r,O]);let K=(0,w.useCallback)(()=>{fetch(`${O()}/jobs/${r}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[r,O]),q=(0,w.useRef)({events:[],omitted:!1}),J=(0,w.useRef)(null),Y=(0,w.useCallback)(()=>{J.current=null;let e=q.current;e.events.length!==0&&(q.current={events:[],omitted:!1},N(t=>h([...t.events,...e.events],t.omitted||e.omitted)))},[]),X=(0,w.useCallback)(e=>{if(!ee(e))return;let t=q.current;t.events.push(e),t.events.length>1e4&&(q.current=h(t.events,t.omitted)),J.current||=requestAnimationFrame(Y)},[Y]);(0,w.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),E(f,(0,w.useCallback)(e=>{let t=e;if(t.type===`event`&&t.jobId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};X(e)}else if(t.type===`log`&&t.processId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line,...typeof t.attemptId==`string`&&t.attemptId.trim()&&t.attemptId.length<=256?{attemptId:t.attemptId}:{}}),timestamp:t.timestamp};X(e)}else if(t.type===`job.finalized`&&t.jobId===r||t.type===`runtime.continuation`&&t.jobId===r||t.type===`job.interactive`&&t.jobId===r||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===r)K();else if(t.type===`phase`){let e=t.phase,n=t.state;R(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===r);e&&A&&j(t=>t&&{...t,status:e.status})}},[r,A,X,K])),(0,w.useEffect)(()=>{function e(e){if(!(e.key!==`Escape`||e.defaultPrevented)){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let Z=A?oe(A):`job`,Q=Z===`loop-run`;async function he(){G(!0);try{let e=await ce({projectId:n??null,jobId:r,kind:Z});e.ok?(u.success(a(Q?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:a(Q?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):u.error(a(`modal.toast.cancelFailed`),{description:e.error})}finally{G(!1)}}let ge=A?.status===`running`,$=A?le(ue(A)):null,{panelRef:_e,panelStyle:ve,headerHandleProps:ye,resizeHandles:be,isFloating:xe,guardBackdrop:Se}=b();return(0,de.createPortal)((0,D.jsx)(se,{delayDuration:400,children:(0,D.jsxs)(`div`,{style:x(),className:`fixed inset-0 z-[65] flex items-stretch justify-center p-[clamp(12px,2vmin,24px)]`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:Se(t)}),(0,D.jsxs)(`div`,{ref:_e,className:`relative w-full min-w-0 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:ve,children:[(0,D.jsxs)(`div`,{...ye,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${xe?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[A&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:A.command}),(0,D.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:$?ae($,{addSuffix:!0,locale:s()}):`—`})]}),z&&(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a(`common:states.loading`)})]}),(0,D.jsx)(`button`,{onClick:t,className:`h-7 w-7 shrink-0 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,D.jsx)(y,{className:`w-4 h-4`})})]}),A&&(0,D.jsx)(_,{onOpenRun:i,job:A,events:P,phases:L,phaseDefinitions:F,projectId:n,variant:`glass`,actions:ge?(0,D.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,D.jsx)(v,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),a(Q?`dashboard:railControls.stop`:Z===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}):null}),M.omitted&&(0,D.jsx)(`p`,{role:`status`,className:`shrink-0 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:a(`logViewer.retainedTail`)}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden relative`,children:me?(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a(`modal.notFound`)})}):d&&A?(0,D.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,D.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>pe(e),"aria-pressed":k===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${k===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:T(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:k===`narrated`?(0,D.jsx)(re,{events:P,settled:A.status!==`running`&&A.status!==`queued`,elapsedMs:A.duration_ms??null,variant:`glass`}):A.command.startsWith(`loop:`)?(0,D.jsx)(m,{events:P,jobStatus:A.status,isLoading:z,variant:`glass`,projectId:n,onOpenRun:i}):(0,D.jsx)(g,{events:P,isLoading:z,projectId:n})})]}):A?.command.startsWith(`loop:`)?(0,D.jsx)(m,{events:P,jobStatus:A.status,isLoading:z,variant:`glass`,projectId:n,onOpenRun:i}):(0,D.jsx)(g,{events:P,isLoading:z,projectId:n})}),!!A?.interactive&&A.status===`running`&&(0,D.jsx)(ie,{jobId:r,projectId:n,settleMode:A.interactiveSettleMode,initialAcceptingTurns:A.interactiveAcceptingTurns,pendingInterrupts:A.pendingInterrupts,kind:A.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,D.jsx)(S,{handles:be}),H&&(0,D.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,D.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,D.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:a(Q?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:a(Q?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,D.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,D.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:a(`modal.keepRunning`)}),(0,D.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),he()},children:a(Q?`modal.stopRun`:Z===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{O 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{m as o,r as ee}from"./useSharedWebSocket-g0nTHfTT.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as te,s as l}from"./useDesktop-ChSmmJfc.js";import{dt as u,n as ne}from"./TicketDetailModalContext-gGUv7gsQ.js";import{n as d}from"./save-OsUqVn99.js";import{c as f}from"./MinimizedChatsContext-Bc9xHByW.js";import{n as re}from"./file-text-BcLCfcWZ.js";import{a as ie,c as p,d as ae,i as m,l as h,n as oe,o as se,r as ce,s as le,t as ue,u as de}from"./InteractiveJobComposer-DkqR77pO.js";import{t as fe}from"./download-CFHyyHcw.js";import{t as pe}from"./rotate-ccw-Wh4id13q.js";import{t as g}from"./utils-BC4DHlz2.js";import{t as me}from"./formatDistanceToNow-Q7QPRFV4.js";import{t as _}from"./button-D1xExSTF.js";import{K as v,Nt as y,W as he,Y as b,q as x}from"./index-DVkWHOR3.js";import{t as ge}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=4;function _e({tickets:e,onTicketClick:t}){let{t:n}=s(`jobs`),[r,i]=(0,S.useState)(!1);if(e.length===0)return null;let a=e.length>=w&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,C.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,C.jsx)(T,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,C.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,C.jsx)(d,{className:`w-3 h-3`})]}),r&&e.length>=w&&(0,C.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,C.jsx)(f,{className:`w-3 h-3`})]})]})}function T({ticket:e,onClick:t}){let{t:n}=s(`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,C.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,C.jsx)(`span`,{className:g(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,C.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,C.jsxs)(`span`,{className:g(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,C.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}function E(){let{t:e}=s(`jobs`),{t}=s(`narration`),{id:n}=r(),{activeProjectId:d,projects:f}=te(),w=f.find(e=>e.id===d)?.provider,T=a(),{openTicketDetail:E}=ne(),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(()=>m([])),j=(0,S.useMemo)(()=>ce(k,e(`logViewer.retainedTail`)),[k,e]),[ve,M]=(0,S.useState)([]),[ye,N]=(0,S.useState)({}),[be,P]=(0,S.useState)([]),[xe,F]=(0,S.useState)(!0),[Se,I]=(0,S.useState)(!1),[L,Ce]=(0,S.useState)(ie),[we,R]=(0,S.useState)(null),Te=(0,S.useCallback)(e=>{Ce(e),se(e)},[]),z=D?.command??null;(0,S.useEffect)(()=>{if(!u||L!==`narrated`||!d||!z)return;let e=!1,t=`command=${encodeURIComponent(z)}`;try{Promise.resolve(fetch(`${c()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||R(t?.range??null)}).catch(()=>{e||R(null)})}catch{R(null)}return()=>{e=!0}},[d,z,L]);let[B,V]=(0,S.useState)(!1),H=(0,S.useRef)(!1),U=(0,S.useRef)(null);(0,S.useEffect)(()=>{H.current=!1,U.current=null,V(!1)},[n]),(0,S.useEffect)(()=>{if(!n)return;let e=new AbortController;K.current={events:[],omitted:!1},q.current&&cancelAnimationFrame(q.current),q.current=null,O(null),A(m([])),M([]),N({}),F(!0),I(!1);async function t(){try{let t=await fetch(`${c()}/jobs/${n}`,{signal:e.signal});if(t.status===404){I(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();if(e.signal.aborted)return;O(r.job),A(m(r.events))}catch(e){if(e.name===`AbortError`)return;I(!0)}finally{e.signal.aborted||F(!1)}}return t(),()=>e.abort()},[n,d]),(0,S.useEffect)(()=>{if(!D?.pipeline_id){P([]);return}let e=D.pipeline_id;fetch(`${c()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&P(e.jobs)}).catch(()=>{})},[D?.pipeline_id,D?.status]);let W=(0,S.useRef)(d);W.current=d;let G=(0,S.useRef)(null);G.current=D?.status??null;let K=(0,S.useRef)({events:[],omitted:!1}),q=(0,S.useRef)(null),J=(0,S.useCallback)(()=>{q.current=null;let e=K.current;e.events.length!==0&&(K.current={events:[],omitted:!1},A(t=>m([...t.events,...e.events],t.omitted||e.omitted)))},[]),Y=(0,S.useCallback)(e=>{if(!oe(e))return;let t=K.current;t.events.push(e),t.events.length>1e4&&(K.current=m(t.events,t.omitted)),q.current||=requestAnimationFrame(J)},[J]);(0,S.useEffect)(()=>()=>{q.current&&cancelAnimationFrame(q.current)},[]);let X=(0,S.useCallback)(e=>{let t=e;if(!(W.current&&t.projectId&&t.projectId!==W.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];M(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;N(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};Y(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,...typeof t.attemptId==`string`&&t.attemptId.trim()&&t.attemptId.length<=256?{attemptId:t.attemptId}:{}}),timestamp:t.timestamp};Y(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`runtime.continuation`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;N(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=G.current;O(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{})}}}},[n,Y]),{registerHandler:Z,unregisterHandler:Q}=ee();(0,S.useEffect)(()=>(Z(`job-detail-${n}`,X),()=>Q(`job-detail-${n}`)),[n,X,Z,Q]),(0,S.useEffect)(()=>{if(!n||!D||D.status!==`running`||D.hasTelemetry)return;let e=setInterval(()=>{fetch(`${c()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&O(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,D?.status,D?.hasTelemetry]);async function Ee(){if(!n)return;let t=await he({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 De(){if(D)try{let t=await fetch(`${c()}/jobs/${D.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-${D.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 Oe(){if(!(!D||H.current)){H.current=!0,V(!0),U.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${D.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${c()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":U.current},body:JSON.stringify({rerunOfJobId:D.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));U.current=null,l.success(e(`detail.toast.jobRequeued`)),T(`/jobs/${n.jobId}`)}catch(e){l.error(e.message)}finally{H.current=!1,V(!1)}}}if(xe)return(0,C.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,C.jsxs)(`div`,{className:`space-y-3`,children:[(0,C.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,C.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,C.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(Se||!D)return(0,C.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,C.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,C.jsx)(_,{asChild:!0,variant:`outline`,size:`sm`,children:(0,C.jsxs)(i,{to:`/`,children:[(0,C.jsx)(y,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let $=D.status===`running`,ke=D.status===`completed`||D.status===`failed`,Ae=!!D.interactive,je=Ae&&$,Me=(D.tickets?.length??0)>0,Ne=D.command.startsWith(`loop:`),Pe=ae(be);return(0,C.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,C.jsxs)(`div`,{className:`px-4 pt-3 pb-2 space-y-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,C.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,C.jsx)(y,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,C.jsx)(re,{className:`w-3 h-3`}),(0,C.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),Me&&(0,C.jsx)(_e,{tickets:D.tickets??[],onTicketClick:E}),(0,C.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap min-w-0`,children:[(0,C.jsx)(`code`,{className:g(`font-mono text-foreground/90 truncate`,Me?`text-xs text-muted-foreground`:`text-sm`),children:ge(D.command,w)}),(0,C.jsx)(`span`,{children:D.started_at?e(`detail.startedAgo`,{timeAgo:me(new Date(D.started_at),{addSuffix:!0,locale:o()})}):e(`detail.queuedWaiting`)}),D.model&&(0,C.jsx)(`span`,{className:`text-muted-foreground/40`,children:D.model})]})]}),(0,C.jsx)(de,{onOpenRun:e=>T(`/jobs/${e}`),job:D,events:j,phases:ye,phaseDefinitions:ve,projectId:d,variant:`page`,pipelineTotals:Pe,actions:(0,C.jsxs)(C.Fragment,{children:[D.hasTelemetry&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,className:`h-7`,onClick:De,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,C.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,C.jsx)(x,{children:e(`detail.exportDiagnosticTooltip`)})]}),ke&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,onClick:Oe,disabled:B,"aria-busy":B,className:`h-7`,children:[(0,C.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,C.jsx)(x,{children:e(`detail.reExecuteTooltip`)})]}),$&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsx)(_,{variant:`outline`,size:`sm`,onClick:Ee,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(Ae?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,C.jsx)(x,{children:e(`detail.cancelJobTooltip`)})]})]})}),k.omitted&&(0,C.jsx)(`p`,{role:`status`,className:`shrink-0 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:e(`logViewer.retainedTail`)}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:u?(0,C.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,C.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,C.jsx)(`button`,{type:`button`,onClick:()=>Te(e),"aria-pressed":L===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${L===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:L===`narrated`?(0,C.jsx)(le,{events:j,settled:D.status!==`running`&&D.status!==`queued`,durationRange:we,elapsedMs:D.duration_ms??null,variant:`page`}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})})]}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})}),je&&(0,C.jsx)(ue,{jobId:D.id,settleMode:D.interactiveSettleMode,initialAcceptingTurns:D.interactiveAcceptingTurns,pendingInterrupts:D.pendingInterrupts,kind:D.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{E 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{m as o,r as ee}from"./useSharedWebSocket-BZxKaVNT.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as te,s as l}from"./useDesktop-DpiS8Uov.js";import{dt as u,n as ne}from"./TicketDetailModalContext-BHmtj1As.js";import{n as d}from"./save-OsUqVn99.js";import{c as f}from"./MinimizedChatsContext-BD2bsRBe.js";import{n as re}from"./file-text-BcLCfcWZ.js";import{a as ie,c as p,d as ae,i as m,l as h,n as oe,o as se,r as ce,s as le,t as ue,u as de}from"./InteractiveJobComposer-Z6fl4791.js";import{t as fe}from"./download-CFHyyHcw.js";import{t as pe}from"./rotate-ccw-Wh4id13q.js";import{t as g}from"./utils-BC4DHlz2.js";import{t as me}from"./formatDistanceToNow-Dax4zqPF.js";import{t as _}from"./button-D1xExSTF.js";import{K as v,Nt as y,W as he,Y as b,q as x}from"./index-g8S62tpS.js";import{t as ge}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=4;function _e({tickets:e,onTicketClick:t}){let{t:n}=s(`jobs`),[r,i]=(0,S.useState)(!1);if(e.length===0)return null;let a=e.length>=w&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,C.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,C.jsx)(T,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,C.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,C.jsx)(d,{className:`w-3 h-3`})]}),r&&e.length>=w&&(0,C.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,C.jsx)(f,{className:`w-3 h-3`})]})]})}function T({ticket:e,onClick:t}){let{t:n}=s(`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,C.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,C.jsx)(`span`,{className:g(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,C.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,C.jsxs)(`span`,{className:g(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,C.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}function E(){let{t:e}=s(`jobs`),{t}=s(`narration`),{id:n}=r(),{activeProjectId:d,projects:f}=te(),w=f.find(e=>e.id===d)?.provider,T=a(),{openTicketDetail:E}=ne(),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(()=>m([])),j=(0,S.useMemo)(()=>ce(k,e(`logViewer.retainedTail`)),[k,e]),[ve,M]=(0,S.useState)([]),[ye,N]=(0,S.useState)({}),[be,P]=(0,S.useState)([]),[xe,F]=(0,S.useState)(!0),[Se,I]=(0,S.useState)(!1),[L,Ce]=(0,S.useState)(ie),[we,R]=(0,S.useState)(null),Te=(0,S.useCallback)(e=>{Ce(e),se(e)},[]),z=D?.command??null;(0,S.useEffect)(()=>{if(!u||L!==`narrated`||!d||!z)return;let e=!1,t=`command=${encodeURIComponent(z)}`;try{Promise.resolve(fetch(`${c()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||R(t?.range??null)}).catch(()=>{e||R(null)})}catch{R(null)}return()=>{e=!0}},[d,z,L]);let[B,V]=(0,S.useState)(!1),H=(0,S.useRef)(!1),U=(0,S.useRef)(null);(0,S.useEffect)(()=>{H.current=!1,U.current=null,V(!1)},[n]),(0,S.useEffect)(()=>{if(!n)return;let e=new AbortController;K.current={events:[],omitted:!1},q.current&&cancelAnimationFrame(q.current),q.current=null,O(null),A(m([])),M([]),N({}),F(!0),I(!1);async function t(){try{let t=await fetch(`${c()}/jobs/${n}`,{signal:e.signal});if(t.status===404){I(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();if(e.signal.aborted)return;O(r.job),A(m(r.events))}catch(e){if(e.name===`AbortError`)return;I(!0)}finally{e.signal.aborted||F(!1)}}return t(),()=>e.abort()},[n,d]),(0,S.useEffect)(()=>{if(!D?.pipeline_id){P([]);return}let e=D.pipeline_id;fetch(`${c()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&P(e.jobs)}).catch(()=>{})},[D?.pipeline_id,D?.status]);let W=(0,S.useRef)(d);W.current=d;let G=(0,S.useRef)(null);G.current=D?.status??null;let K=(0,S.useRef)({events:[],omitted:!1}),q=(0,S.useRef)(null),J=(0,S.useCallback)(()=>{q.current=null;let e=K.current;e.events.length!==0&&(K.current={events:[],omitted:!1},A(t=>m([...t.events,...e.events],t.omitted||e.omitted)))},[]),Y=(0,S.useCallback)(e=>{if(!oe(e))return;let t=K.current;t.events.push(e),t.events.length>1e4&&(K.current=m(t.events,t.omitted)),q.current||=requestAnimationFrame(J)},[J]);(0,S.useEffect)(()=>()=>{q.current&&cancelAnimationFrame(q.current)},[]);let X=(0,S.useCallback)(e=>{let t=e;if(!(W.current&&t.projectId&&t.projectId!==W.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];M(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;N(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};Y(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,...typeof t.attemptId==`string`&&t.attemptId.trim()&&t.attemptId.length<=256?{attemptId:t.attemptId}:{}}),timestamp:t.timestamp};Y(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`runtime.continuation`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;N(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=G.current;O(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{})}}}},[n,Y]),{registerHandler:Z,unregisterHandler:Q}=ee();(0,S.useEffect)(()=>(Z(`job-detail-${n}`,X),()=>Q(`job-detail-${n}`)),[n,X,Z,Q]),(0,S.useEffect)(()=>{if(!n||!D||D.status!==`running`||D.hasTelemetry)return;let e=setInterval(()=>{fetch(`${c()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&O(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,D?.status,D?.hasTelemetry]);async function Ee(){if(!n)return;let t=await he({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 De(){if(D)try{let t=await fetch(`${c()}/jobs/${D.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-${D.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 Oe(){if(!(!D||H.current)){H.current=!0,V(!0),U.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${D.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${c()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":U.current},body:JSON.stringify({rerunOfJobId:D.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));U.current=null,l.success(e(`detail.toast.jobRequeued`)),T(`/jobs/${n.jobId}`)}catch(e){l.error(e.message)}finally{H.current=!1,V(!1)}}}if(xe)return(0,C.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,C.jsxs)(`div`,{className:`space-y-3`,children:[(0,C.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,C.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,C.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(Se||!D)return(0,C.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,C.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,C.jsx)(_,{asChild:!0,variant:`outline`,size:`sm`,children:(0,C.jsxs)(i,{to:`/`,children:[(0,C.jsx)(y,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let $=D.status===`running`,ke=D.status===`completed`||D.status===`failed`,Ae=!!D.interactive,je=Ae&&$,Me=(D.tickets?.length??0)>0,Ne=D.command.startsWith(`loop:`),Pe=ae(be);return(0,C.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,C.jsxs)(`div`,{className:`px-4 pt-3 pb-2 space-y-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,C.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,C.jsx)(y,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,C.jsx)(re,{className:`w-3 h-3`}),(0,C.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),Me&&(0,C.jsx)(_e,{tickets:D.tickets??[],onTicketClick:E}),(0,C.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap min-w-0`,children:[(0,C.jsx)(`code`,{className:g(`font-mono text-foreground/90 truncate`,Me?`text-xs text-muted-foreground`:`text-sm`),children:ge(D.command,w)}),(0,C.jsx)(`span`,{children:D.started_at?e(`detail.startedAgo`,{timeAgo:me(new Date(D.started_at),{addSuffix:!0,locale:o()})}):e(`detail.queuedWaiting`)}),D.model&&(0,C.jsx)(`span`,{className:`text-muted-foreground/40`,children:D.model})]})]}),(0,C.jsx)(de,{onOpenRun:e=>T(`/jobs/${e}`),job:D,events:j,phases:ye,phaseDefinitions:ve,projectId:d,variant:`page`,pipelineTotals:Pe,actions:(0,C.jsxs)(C.Fragment,{children:[D.hasTelemetry&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,className:`h-7`,onClick:De,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,C.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,C.jsx)(x,{children:e(`detail.exportDiagnosticTooltip`)})]}),ke&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,onClick:Oe,disabled:B,"aria-busy":B,className:`h-7`,children:[(0,C.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,C.jsx)(x,{children:e(`detail.reExecuteTooltip`)})]}),$&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsx)(_,{variant:`outline`,size:`sm`,onClick:Ee,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(Ae?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,C.jsx)(x,{children:e(`detail.cancelJobTooltip`)})]})]})}),k.omitted&&(0,C.jsx)(`p`,{role:`status`,className:`shrink-0 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:e(`logViewer.retainedTail`)}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:u?(0,C.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,C.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,C.jsx)(`button`,{type:`button`,onClick:()=>Te(e),"aria-pressed":L===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${L===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:L===`narrated`?(0,C.jsx)(le,{events:j,settled:D.status!==`running`&&D.status!==`queued`,durationRange:we,elapsedMs:D.duration_ms??null,variant:`page`}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})})]}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})}),je&&(0,C.jsx)(ue,{jobId:D.id,settleMode:D.interactiveSettleMode,initialAcceptingTurns:D.interactiveAcceptingTurns,pendingInterrupts:D.pendingInterrupts,kind:D.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{E 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{l as i,m as a,r as o}from"./useSharedWebSocket-g0nTHfTT.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,i as u,r as d,s as f}from"./useDesktop-ChSmmJfc.js";import{t as p}from"./circle-x-CMYsN4ZH.js";import{t as m}from"./trash-2-BOU3WdZZ.js";import{t as h}from"./triangle-alert-H9T4jAmh.js";import{t as g}from"./x-CBMI9ejn.js";import{F as _,P as v,a as y,i as b,l as x,o as ee,r as te,t as ne}from"./dialog-CMgps2MY.js";import{n as re,t as ie}from"./lib-CGdyxIWg.js";import{t as S}from"./formatDistanceToNow-Q7QPRFV4.js";import{t as C}from"./button-D1xExSTF.js";import{Gt as w,K as T,S as E,Wt as ae,Y as D,jt as oe,k as se,q as O,t as k}from"./index-DVkWHOR3.js";import{t as A}from"./format-command-C0D9IPmV.js";import{t as j}from"./ExportDropdown-1Ce031vB.js";import{n as M,t as N}from"./job-time-BCL7wee9.js";var ce=c(`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 le({jobIds:e,onClose:t}){let{t:n}=s(`jobs`),[r,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(!0),[c,u]=(0,P.useState)(null),{panelRef:d,panelStyle:f,headerHandleProps:m,resizeHandles:h,isFloating:y,guardBackdrop:b}=_();(0,P.useEffect)(()=>{let t=new AbortController;return fetch(`${l()}/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),o(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),o(!1))}),()=>t.abort()},[e]);function x(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)(w,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,F.jsx)(p,{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:b(t),children:[(0,F.jsxs)(`div`,{ref:d,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:f,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between ${y?`cursor-grab active:cursor-grabbing`:``}`,...m,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)(g,{className:`w-4 h-4`})})]}),a&&(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))}),c&&(0,F.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:c})}),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`,{}),x(e,0),x(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)(v,{handles:h})]})}var V={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`}},ue=[`running`,`completed`,`failed`,`canceled`,`zombie_terminated`,`queued`,`skipped`],de={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 fe(e){return e==null||e===0?null:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function pe(e,t){let n=M(e),r=M(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 me(e){return e==null||e===0?null:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function he(e){let t=M(e);return t?S(t,{addSuffix:!0,locale:a()}):`—`}function ge(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).getTime()}function _e(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r+1).getTime()-1}function ve(e,t,n){if(!t&&!n)return!0;let r=M(e);if(!r)return!0;let i=r.getTime();return!(t&&i<ge(t)||n&&i>_e(n))}var H=10;function U({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:a,onProposalClick:o,onProposalDelete:c}){let{t:u}=s(`jobs`),p=r(),{activeProjectId:g,projects:re}=d(),ie=re.find(e=>e.id===g)?.provider,[S,w]=(0,P.useState)(null),[E,k]=(0,P.useState)(``),[j,M]=(0,P.useState)(``),[I,L]=(0,P.useState)(!1),[R,z]=(0,P.useState)(``),[B,U]=(0,P.useState)(``),[W,G]=(0,P.useState)(!1),[K,q]=(0,P.useState)(null),[J,ye]=(0,P.useState)(H),[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(H)},[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=>S&&e.status!==S?!1:ve(N(e),E,j)),Ae=e.filter(e=>ve(N(e),R,B)).length;async function je(e){G(!0);try{let t={};e===`range`&&(R&&(t.from=new Date(ge(R)).toISOString()),B&&(t.to=new Date(_e(B)).toISOString()));let n=await fetch(`${l()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();f.success(u(`recent.toast.cleared`,{count:e.deleted})),L(!1),z(``),U(``),a?.()}else f.error(u(`recent.toast.clearFailed`))}catch{f.error(u(`recent.toast.networkError`))}finally{G(!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)(h,{className:`h-4 w-4 shrink-0`}),(0,F.jsx)(`span`,{className:`flex-1`,children:u(`recent.loadFailed`)}),i&&(0,F.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:u(`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)(ae,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,F.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:u(`recent.emptyTitle`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:u(`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:()=>w(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${S===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterAll`,{count:e.length})}),ue.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,F.jsx)(`button`,{type:`button`,onClick:()=>w(S===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${S===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterStatus`,{status:u(`statusName.${t}`),count:n})},t)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:E,onChange:e=>k(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.fromDate`)}),(0,F.jsx)(`input`,{type:`date`,value:j,onChange:e=>M(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.toDate`)}),(E||j)&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{k(``),M(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:u(`recent.clear`)}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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)(ce,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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:()=>L(!0),children:(0,F.jsx)(m,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(`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&&u(`recent.selectTwoToCompare`),X.length===1&&u(`recent.selectOneMore`),X.length===2&&u(`recent.readyToCompare`)]}),X.length===2&&(0,F.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:u(`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:u(`recent.colStatus`)}),(0,F.jsx)(`span`,{className:`flex-1 min-w-0`,children:u(`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:u(`recent.colDuration`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colTokens`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colCost`)}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:u(`recent.colStarted`)})]})]}),(0,F.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=V[e.status]??V.queued,n=fe(e.total_cost_usd),r=pe(e.started_at,e.finished_at),i=me((e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0)||null),a=e.id.startsWith(`proposal:`),s=a?e.id.replace(`proposal:`,``):null,c=X.includes(e.id),l=Y&&!a&&X.length===2&&!c,d=()=>{if(Y&&!a){ke(e.id);return}a&&s?o?.(s):p(`/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 ${c?`bg-accent/70 ring-1 ring-border`:l?`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)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(se,{variant:t.variant,children:u(t.labelKey)})})}),(0,F.jsx)(O,{children:u(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 ${de[e.priority].className}`,children:u(de[e.priority].labelKey)}),e.profile_name&&(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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)(O,{children:u(`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)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(oe,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,F.jsxs)(O,{children:[u(`recent.pipelinePart`),e.depends_on_job_id&&` ${u(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,F.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:A(e.command,ie)})]}),(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`?`—`:he(e.started_at)}),a&&s&&(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(s)},title:u(`recent.deleteProposal`),children:(0,F.jsx)(m,{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+H),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:u(`recent.loadMore`,{count:$.length-J})})}),I&&(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>L(!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:u(`recent.clearModal.title`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:u(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:W,onClick:()=>je(`all`),children:u(`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:u(`recent.clearModal.orByRange`)}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:R,onChange:e=>z(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.fromPlaceholder`)}),(0,F.jsx)(`input`,{type:`date`,value:B,onChange:e=>U(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.toPlaceholder`)})]}),(0,F.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:W||!R&&!B,onClick:()=>je(`range`),children:R||B?u(`recent.clearModal.clearInRange`,{count:Ae}):u(`recent.clearModal.clearRange`)})]}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>L(!1),children:u(`common:actions.cancel`)})]}),(0,F.jsx)(v,{handles:Te})]}),(0,F.jsx)(ne,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,F.jsxs)(te,{className:`max-w-sm`,children:[(0,F.jsxs)(ee,{children:[(0,F.jsx)(x,{children:u(`recent.deleteProposalConfirm.title`)}),(0,F.jsx)(b,{children:u(`recent.deleteProposalConfirm.description`)})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:u(`common:actions.cancel`)}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&c?.(K),q(null)},children:u(`common:actions.delete`)})]})]})}),xe&&(0,F.jsx)(le,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var W={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 G(e){return`${i}/api/projects/${encodeURIComponent(e)}`}function K(){let[e,t]=(0,P.useState)(!1),{registerHandler:n,unregisterHandler:r}=o(),{t:i}=s(`jobs`),{activeProjectId:a}=d(),{recentJobs:c}=k(a),{data:p,isFirstLoad:m,isLoading:h,error:g,refresh:_}=u({namespace:`jobs`,projectId:a,initialValue:c,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4});(0,P.useEffect)(()=>(n(`jobs-runtime-continuation`,e=>{let t=e;t.type===`runtime.continuation`&&t.projectId===a&&_()}),()=>r(`jobs-runtime-continuation`)),[a,_,n,r]);let{data:v,isFirstLoad:b,isLoading:S,error:w,refresh:T}=u({namespace:`proposals`,projectId:a,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),ae={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},D=v.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:ae[e.status]??`queued`})),oe=[...p,...D].sort((e,t)=>(M(N(t))?.getTime()??0)-(M(N(e))?.getTime()??0)),[O,A]=(0,P.useState)(null),ce=(0,P.useCallback)(async e=>{try{let t=await fetch(`${l()}/propose/${e}`);if(!t.ok)return;let n=await t.json();A(n.proposal)}catch{}},[]),I=(0,P.useCallback)(async e=>{try{(await fetch(`${l()}/propose/${e}`,{method:`DELETE`})).ok&&(f.success(i(`page.proposalDeleted`)),await T())}catch{}},[T,i]);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:i(`page.title`)}),(0,F.jsx)(j,{baseUrl:`${l()}/jobs/export`,label:i(`page.exportJobs`)})]}),a&&(0,F.jsxs)(`details`,{className:`mb-4 rounded-lg border border-border`,onToggle:e=>t(e.currentTarget.open),children:[(0,F.jsx)(`summary`,{className:`cursor-pointer p-3 text-sm`,children:i(`agentRuntime:runs.title`)}),e&&(0,F.jsx)(E,{projectId:a})]}),(0,F.jsx)(U,{jobs:oe,isLoading:m||b||h||S,error:g??w,onRetry:()=>{Promise.all([_(),T()])},onJobsCleared:_,onProposalClick:ce,onProposalDelete:I}),(0,F.jsx)(ne,{open:O!==null,onOpenChange:e=>!e&&A(null),children:(0,F.jsx)(te,{className:`max-w-3xl glass-card`,children:O&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(ee,{children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(x,{className:`flex-1 min-w-0`,children:i(`page.proposal.title`)}),(0,F.jsx)(se,{variant:O.status===`created`?`success`:O.status===`cancelled`?`destructive`:`secondary`,children:i(W[O.status]??`page.proposal.status.unknown`,{status:O.status})})]})}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:O.idea}),O.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)(re,{remarkPlugins:[ie],children:O.result_markdown})})}):(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:i(`page.proposal.noContent`)}),O.issue_url&&(0,F.jsxs)(`div`,{className:`text-xs`,children:[i(`page.proposal.githubIssue`),` `,(0,F.jsx)(`a`,{href:O.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:O.issue_url})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{I(O.id),A(null)},children:i(`common:actions.delete`)}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>A(null),children:i(`common:actions.close`)})]})]})})})]})}export{K 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{l as i,m as a,r as o}from"./useSharedWebSocket-BZxKaVNT.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,i as u,r as d,s as f}from"./useDesktop-DpiS8Uov.js";import{t as p}from"./circle-x-CMYsN4ZH.js";import{t as m}from"./trash-2-BOU3WdZZ.js";import{t as h}from"./triangle-alert-H9T4jAmh.js";import{t as g}from"./x-CBMI9ejn.js";import{F as _,P as v,a as y,i as b,l as x,o as ee,r as te,t as ne}from"./dialog-CMgps2MY.js";import{n as re,t as ie}from"./lib-CGdyxIWg.js";import{t as S}from"./formatDistanceToNow-Dax4zqPF.js";import{t as C}from"./button-D1xExSTF.js";import{Gt as w,K as T,S as E,Wt as ae,Y as D,jt as oe,k as se,q as O,t as k}from"./index-g8S62tpS.js";import{t as A}from"./format-command-C0D9IPmV.js";import{t as j}from"./ExportDropdown-B4Olg1Fk.js";import{n as M,t as N}from"./job-time-BCL7wee9.js";var ce=c(`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 le({jobIds:e,onClose:t}){let{t:n}=s(`jobs`),[r,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(!0),[c,u]=(0,P.useState)(null),{panelRef:d,panelStyle:f,headerHandleProps:m,resizeHandles:h,isFloating:y,guardBackdrop:b}=_();(0,P.useEffect)(()=>{let t=new AbortController;return fetch(`${l()}/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),o(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),o(!1))}),()=>t.abort()},[e]);function x(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)(w,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,F.jsx)(p,{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:b(t),children:[(0,F.jsxs)(`div`,{ref:d,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:f,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between ${y?`cursor-grab active:cursor-grabbing`:``}`,...m,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)(g,{className:`w-4 h-4`})})]}),a&&(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))}),c&&(0,F.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:c})}),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`,{}),x(e,0),x(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)(v,{handles:h})]})}var V={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`}},ue=[`running`,`completed`,`failed`,`canceled`,`zombie_terminated`,`queued`,`skipped`],de={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 fe(e){return e==null||e===0?null:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function pe(e,t){let n=M(e),r=M(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 me(e){return e==null||e===0?null:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function he(e){let t=M(e);return t?S(t,{addSuffix:!0,locale:a()}):`—`}function ge(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).getTime()}function _e(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r+1).getTime()-1}function ve(e,t,n){if(!t&&!n)return!0;let r=M(e);if(!r)return!0;let i=r.getTime();return!(t&&i<ge(t)||n&&i>_e(n))}var H=10;function U({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:a,onProposalClick:o,onProposalDelete:c}){let{t:u}=s(`jobs`),p=r(),{activeProjectId:g,projects:re}=d(),ie=re.find(e=>e.id===g)?.provider,[S,w]=(0,P.useState)(null),[E,k]=(0,P.useState)(``),[j,M]=(0,P.useState)(``),[I,L]=(0,P.useState)(!1),[R,z]=(0,P.useState)(``),[B,U]=(0,P.useState)(``),[W,G]=(0,P.useState)(!1),[K,q]=(0,P.useState)(null),[J,ye]=(0,P.useState)(H),[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(H)},[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=>S&&e.status!==S?!1:ve(N(e),E,j)),Ae=e.filter(e=>ve(N(e),R,B)).length;async function je(e){G(!0);try{let t={};e===`range`&&(R&&(t.from=new Date(ge(R)).toISOString()),B&&(t.to=new Date(_e(B)).toISOString()));let n=await fetch(`${l()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();f.success(u(`recent.toast.cleared`,{count:e.deleted})),L(!1),z(``),U(``),a?.()}else f.error(u(`recent.toast.clearFailed`))}catch{f.error(u(`recent.toast.networkError`))}finally{G(!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)(h,{className:`h-4 w-4 shrink-0`}),(0,F.jsx)(`span`,{className:`flex-1`,children:u(`recent.loadFailed`)}),i&&(0,F.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:u(`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)(ae,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,F.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:u(`recent.emptyTitle`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:u(`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:()=>w(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${S===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterAll`,{count:e.length})}),ue.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,F.jsx)(`button`,{type:`button`,onClick:()=>w(S===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${S===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterStatus`,{status:u(`statusName.${t}`),count:n})},t)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:E,onChange:e=>k(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.fromDate`)}),(0,F.jsx)(`input`,{type:`date`,value:j,onChange:e=>M(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.toDate`)}),(E||j)&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{k(``),M(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:u(`recent.clear`)}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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)(ce,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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:()=>L(!0),children:(0,F.jsx)(m,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(`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&&u(`recent.selectTwoToCompare`),X.length===1&&u(`recent.selectOneMore`),X.length===2&&u(`recent.readyToCompare`)]}),X.length===2&&(0,F.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:u(`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:u(`recent.colStatus`)}),(0,F.jsx)(`span`,{className:`flex-1 min-w-0`,children:u(`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:u(`recent.colDuration`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colTokens`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colCost`)}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:u(`recent.colStarted`)})]})]}),(0,F.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=V[e.status]??V.queued,n=fe(e.total_cost_usd),r=pe(e.started_at,e.finished_at),i=me((e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0)||null),a=e.id.startsWith(`proposal:`),s=a?e.id.replace(`proposal:`,``):null,c=X.includes(e.id),l=Y&&!a&&X.length===2&&!c,d=()=>{if(Y&&!a){ke(e.id);return}a&&s?o?.(s):p(`/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 ${c?`bg-accent/70 ring-1 ring-border`:l?`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)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(se,{variant:t.variant,children:u(t.labelKey)})})}),(0,F.jsx)(O,{children:u(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 ${de[e.priority].className}`,children:u(de[e.priority].labelKey)}),e.profile_name&&(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{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)(O,{children:u(`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)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(oe,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,F.jsxs)(O,{children:[u(`recent.pipelinePart`),e.depends_on_job_id&&` ${u(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,F.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:A(e.command,ie)})]}),(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`?`—`:he(e.started_at)}),a&&s&&(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(s)},title:u(`recent.deleteProposal`),children:(0,F.jsx)(m,{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+H),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:u(`recent.loadMore`,{count:$.length-J})})}),I&&(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>L(!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:u(`recent.clearModal.title`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:u(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:W,onClick:()=>je(`all`),children:u(`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:u(`recent.clearModal.orByRange`)}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:R,onChange:e=>z(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.fromPlaceholder`)}),(0,F.jsx)(`input`,{type:`date`,value:B,onChange:e=>U(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.toPlaceholder`)})]}),(0,F.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:W||!R&&!B,onClick:()=>je(`range`),children:R||B?u(`recent.clearModal.clearInRange`,{count:Ae}):u(`recent.clearModal.clearRange`)})]}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>L(!1),children:u(`common:actions.cancel`)})]}),(0,F.jsx)(v,{handles:Te})]}),(0,F.jsx)(ne,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,F.jsxs)(te,{className:`max-w-sm`,children:[(0,F.jsxs)(ee,{children:[(0,F.jsx)(x,{children:u(`recent.deleteProposalConfirm.title`)}),(0,F.jsx)(b,{children:u(`recent.deleteProposalConfirm.description`)})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:u(`common:actions.cancel`)}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&c?.(K),q(null)},children:u(`common:actions.delete`)})]})]})}),xe&&(0,F.jsx)(le,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var W={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 G(e){return`${i}/api/projects/${encodeURIComponent(e)}`}function K(){let[e,t]=(0,P.useState)(!1),{registerHandler:n,unregisterHandler:r}=o(),{t:i}=s(`jobs`),{activeProjectId:a}=d(),{recentJobs:c}=k(a),{data:p,isFirstLoad:m,isLoading:h,error:g,refresh:_}=u({namespace:`jobs`,projectId:a,initialValue:c,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4});(0,P.useEffect)(()=>(n(`jobs-runtime-continuation`,e=>{let t=e;t.type===`runtime.continuation`&&t.projectId===a&&_()}),()=>r(`jobs-runtime-continuation`)),[a,_,n,r]);let{data:v,isFirstLoad:b,isLoading:S,error:w,refresh:T}=u({namespace:`proposals`,projectId:a,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),ae={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},D=v.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:ae[e.status]??`queued`})),oe=[...p,...D].sort((e,t)=>(M(N(t))?.getTime()??0)-(M(N(e))?.getTime()??0)),[O,A]=(0,P.useState)(null),ce=(0,P.useCallback)(async e=>{try{let t=await fetch(`${l()}/propose/${e}`);if(!t.ok)return;let n=await t.json();A(n.proposal)}catch{}},[]),I=(0,P.useCallback)(async e=>{try{(await fetch(`${l()}/propose/${e}`,{method:`DELETE`})).ok&&(f.success(i(`page.proposalDeleted`)),await T())}catch{}},[T,i]);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:i(`page.title`)}),(0,F.jsx)(j,{baseUrl:`${l()}/jobs/export`,label:i(`page.exportJobs`)})]}),a&&(0,F.jsxs)(`details`,{className:`mb-4 rounded-lg border border-border`,onToggle:e=>t(e.currentTarget.open),children:[(0,F.jsx)(`summary`,{className:`cursor-pointer p-3 text-sm`,children:i(`agentRuntime:runs.title`)}),e&&(0,F.jsx)(E,{projectId:a})]}),(0,F.jsx)(U,{jobs:oe,isLoading:m||b||h||S,error:g??w,onRetry:()=>{Promise.all([_(),T()])},onJobsCleared:_,onProposalClick:ce,onProposalDelete:I}),(0,F.jsx)(ne,{open:O!==null,onOpenChange:e=>!e&&A(null),children:(0,F.jsx)(te,{className:`max-w-3xl glass-card`,children:O&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(ee,{children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(x,{className:`flex-1 min-w-0`,children:i(`page.proposal.title`)}),(0,F.jsx)(se,{variant:O.status===`created`?`success`:O.status===`cancelled`?`destructive`:`secondary`,children:i(W[O.status]??`page.proposal.status.unknown`,{status:O.status})})]})}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:O.idea}),O.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)(re,{remarkPlugins:[ie],children:O.result_markdown})})}):(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:i(`page.proposal.noContent`)}),O.issue_url&&(0,F.jsxs)(`div`,{className:`text-xs`,children:[i(`page.proposal.githubIssue`),` `,(0,F.jsx)(`a`,{href:O.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:O.issue_url})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{I(O.id),A(null)},children:i(`common:actions.delete`)}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>A(null),children:i(`common:actions.close`)})]})]})})})]})}export{K as default};
@@ -0,0 +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,u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{a as s,r as c,s as l}from"./useDesktop-DpiS8Uov.js";import{r as u}from"./provider-capabilities-lePfeT_Y.js";import{n as d,r as f,t as p}from"./save-OsUqVn99.js";import{t as m}from"./external-link-D6XxC_Cu.js";import{t as h}from"./git-branch-BRM0F5GN.js";import{n as g,t as _}from"./square-Ci-PFcFe.js";import{t as v}from"./plus-CsnjfkmX.js";import{t as ee}from"./rotate-ccw-Wh4id13q.js";import{t as y}from"./trash-2-BOU3WdZZ.js";import{t as te}from"./triangle-alert-H9T4jAmh.js";import{t as ne}from"./upload-DYMjAQ6M.js";import{t as re}from"./x-CBMI9ejn.js";import{a as ie,i as ae,l as oe,o as b,r as x,t as se}from"./dialog-CMgps2MY.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-D1xExSTF.js";import{n as w,t as T}from"./project-repositories-BkyT8AjU.js";import{Ft as ce,J as le,K as ue,Mt as de,U as E,Ut as fe,Vt as pe,Y as me,Yt as he,bt as ge,c as D,d as _e,f as ve,gt as O,in as ye,it as k,l as A,m as j,ot as M,p as be,q as xe,rn as Se,rt as Ce,tn as we,u as N,xt as P,zt as Te}from"./index-g8S62tpS.js";import{a as Ee,c as De,d as Oe,f as ke,i as F,l as Ae,m as I,n as je,o as Me,p as Ne,r as Pe,s as Fe,t as Ie,u as Le}from"./loop-layout-BF8xMiNv.js";var Re=o(`grid-3x3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ze=o(`move-horizontal`,[[`path`,{d:`m18 8 4 4-4 4`,key:`1ak13k`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}]]),Be=o(`move-vertical`,[[`path`,{d:`M12 2v20`,key:`t6zp3m`}],[`path`,{d:`m8 18 4 4 4-4`,key:`bh5tu3`}],[`path`,{d:`m8 6 4-4 4 4`,key:`ybng9g`}]]),L=e(t(),1),R=n(),z=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function Ve({roles:e={},provider:t,supported:n,onChange:r,renderEngine:i,visibleRoleIds:o,manageRoles:s=!0}){let{t:c}=a(`agentRuntime`),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(!1),p=Object.entries(e).filter(([e])=>!ve.includes(e)&&(!o||o.includes(e)));function m(){if(!D.test(l)||l===`fixer`||ve.includes(l)||Object.prototype.hasOwnProperty.call(e,l)){f(!0);return}r({...e,[l]:{provider:t,access:`read`,artifacts:`none`}}),u(``),f(!1)}return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-labelledby":`custom-runtime-roles`,children:[s&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{id:`custom-runtime-roles`,className:`text-sm font-medium`,children:c(`customRoles.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.hint`)})]}),!n&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.unsupported`)}),p.map(([t,a])=>{let o=n=>r({...e,[t]:{...a,...n}});return(0,R.jsxs)(`fieldset`,{className:`space-y-3 rounded-lg border p-3`,"aria-label":t,children:[(0,R.jsx)(`legend`,{className:`px-1 font-mono text-sm`,children:t}),s&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>{let n={...e};delete n[t],r(n)},children:c(`customRoles.remove`,{id:t})})}),(0,R.jsxs)(`fieldset`,{disabled:!n,className:`space-y-3`,children:[i(t),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.access`),(0,R.jsxs)(`select`,{className:z,value:a.access,onChange:e=>o({access:e.target.value}),children:[(0,R.jsx)(`option`,{value:`read`,children:c(`customRoles.read`)}),(0,R.jsx)(`option`,{value:`write`,children:c(`customRoles.write`)})]})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.artifacts`),(0,R.jsxs)(`select`,{className:z,value:a.artifacts,onChange:e=>o({artifacts:e.target.value}),children:[(0,R.jsx)(`option`,{value:`none`,children:c(`customRoles.none`)}),(0,R.jsx)(`option`,{value:`tasks-checkboxes`,children:c(`customRoles.tasks`)}),(0,R.jsx)(`option`,{value:`all`,children:c(`customRoles.all`)})]})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.skill`),(0,R.jsxs)(`select`,{className:z,value:a.openspecSkill??``,onChange:e=>o({openspecSkill:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:c(`customRoles.noSkill`)}),[`openspec-ff-change`,`openspec-apply-change`,`openspec-verify-change`].map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:a.prompt??``,rows:5,maxLength:2e4,onChange:e=>o({prompt:e.target.value||void 0})})]})]})]},t)}),s&&(0,R.jsxs)(`fieldset`,{disabled:!n||!t,className:`flex items-end gap-2`,children:[(0,R.jsxs)(`label`,{className:`min-w-0 flex-1 space-y-1 text-xs`,children:[c(`customRoles.id`),(0,R.jsx)(E,{value:l,maxLength:64,placeholder:`security-reviewer`,onChange:e=>{u(e.target.value),f(!1)}})]}),(0,R.jsx)(C,{variant:`secondary`,onClick:m,children:c(`customRoles.add`)})]}),d&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`customRoles.invalidId`)})]})}var He={architect:fe,developer:ce,host:O};function Ue({projectId:e,catalogUrl:t,guardrails:n,onChange:r}){let{t:i,i18n:o}=a(`agentRuntime`),[s,c]=(0,L.useState)(!0),[l,u]=(0,L.useState)({status:`loading`});(0,L.useEffect)(()=>{let n=!1;return u({status:`loading`}),fetch(t??`${w(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let r=await e.json(),i=t?r.guardrails:r;if(!be(i))throw Error(`guardrails`);n||u({status:`ready`,supported:i.supported,catalog:i.catalog})}).catch(()=>{n||u({status:`unsupported`})}),()=>{n=!0}},[e,t]);let f=l.status===`ready`?l.catalog:[],p=l.status===`ready`&&l.supported,m=f.filter(e=>n?.[e.id]===!1).length,h=f.length,g=e=>o.exists(`agentRuntime:guardrails.items.${e}.title`),_=`pipeline-guardrails-body`;return(0,R.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,R.jsx)(`legend`,{className:`sr-only`,children:i(`guardrails.title`)}),(0,R.jsxs)(`button`,{type:`button`,"aria-expanded":s,"aria-controls":_,"aria-label":`${i(s?`pipeline.collapse`:`pipeline.open`)}: ${i(`guardrails.title`)}`,onClick:()=>c(e=>!e),className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,R.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent-success/15 text-accent-success`,children:(0,R.jsx)(ge,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,R.jsx)(`span`,{className:`text-xs font-medium`,children:i(`guardrails.title`)}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[l.status===`ready`&&p&&(0,R.jsx)(`span`,{"data-testid":`guardrails-active`,className:S(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,m?`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:i(`guardrails.active`,{on:h-m,total:h})}),(0,R.jsx)(d,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${s?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,R.jsxs)(`div`,{id:_,hidden:!s,className:`space-y-3 px-3 pb-3`,children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`guardrails.intro`)}),l.status===`loading`&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),(l.status===`unsupported`||l.status===`ready`&&!p)&&(0,R.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`guardrails.unsupported`)}),l.status===`ready`&&(0,R.jsxs)(`fieldset`,{disabled:!p,className:`space-y-3 disabled:opacity-60`,children:[m>0&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>r(void 0),children:i(`guardrails.reset`)})}),A.map(e=>{let t=f.filter(t=>t.phase===e);if(!t.length)return null;let a=He[e];return(0,R.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,R.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,R.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`guardrails.phases.${e}`)]}),(0,R.jsx)(`ul`,{className:`divide-y divide-border/60 rounded-md border border-border/60`,children:t.map(e=>{let t=n?.[e.id]!==!1,a=g(e.id)?i(`guardrails.items.${e.id}.title`):e.id,o=g(e.id)?i(`guardrails.items.${e.id}.description`):i(`guardrails.unknown`),s=g(e.id)?i(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,R.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,R.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>r(j(n,e.id,!t)),className:S(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-accent-primary/70`:`bg-muted-foreground/30`),children:(0,R.jsx)(`span`,{className:S(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`p`,{id:c,className:S(`text-xs font-medium`,!t&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,R.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,R.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var We=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function B({config:e,onChange:t}){let{t:n}=a(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,R.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,R.jsxs)(`select`,{className:We,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,R.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,R.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,R.jsx)(E,{type:`number`,min:`1`,max:`4`,step:`1`,value:r.verification?.maxConcurrency??1,onChange:n=>t({...e,efficiency:{...r,verification:{...r.verification,maxConcurrency:Number(n.target.value)}}})})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function Ge(e){let t=[],n=0;function r(i,a,o){if(!(o.length>=32||t.length>=1e4))for(let s of i.nodes){if(++n>1e4)return;if(s.type!==`core`)continue;let i=a+s.id,c=s.data?.kind,l=V(s.data?.params);(c===`role-turn`||c===`implementation-step`&&l.phase===`reviewer`)&&t.push(i);let u=c===`component`?l.ref:c===`map`?l.body:void 0;typeof u==`string`&&!o.includes(u)&&e.components?.[u]&&r(e.components[u],i+`/`,[...o,u])}}return r(e,``,[]),t.sort()}var V=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function H(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function U(e){if(`default`in e)return structuredClone(e.default);if(`const`in e)return structuredClone(e.const);if(Array.isArray(e.enum))return structuredClone(e.enum[0]);let t=e.oneOf??e.anyOf;if(Array.isArray(t)&&!e.properties)return U(V(t[0]));switch(H(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=V(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,U(V(t[e]))]))}default:return``}}function Ke(e){let t=V(U(e.paramsSchema));return e.kind===`prompt`&&(t.text=``,t.engine={provider:`claude`},t.access=`read`),e.kind===`shell`&&(t.argv=[``]),e.kind===`assign`&&(t.set={}),{kind:`core`,coreKind:e.kind,params:t}}function qe(e,t,n={}){if(!e)return[];let r=e.outcomes;return e.kind===`prompt`&&(r=t.sentinel===`verification`?[`pass`,`fail`,`failed`]:t.sentinel===`blocked`?[`next`,`blocked`,`failed`]:[`next`,`failed`]),e.kind===`role-turn`&&(r=t.structuredOutput?[`next`,`invalid`,`failed`]:[`next`,`failed`]),e.kind===`component`?n[String(t.ref)]?.outputs??[`next`,`failed`]:r.filter(t=>e.outcomes.includes(t))}var Je=e=>[`prompt`,`role-turn`,`decider`,`implementation`,`implementation-step`].includes(e)?`ai`:[`verify`,`shell`].includes(e)?`verification`:e===`artifact-contract`||e.startsWith(`openspec-`)?`openspec`:`control`;function Ye(e,t,n){return t===`implementation`?[`architect`,`developer`,`reviewer`,`fixer`]:t===`implementation-step`?[`architect`,`developer`,`reviewer`,`fixer`].includes(String(n.phase))?[String(n.phase)]:[]:t===`prompt`?[e===`fix`?`fixer`:e===`prepare`?`architect`:n.access===`read`?`reviewer`:`developer`]:(t===`role-turn`||t===`decider`)&&typeof n.roleId==`string`?[n.roleId]:[]}function Xe(e){let t=new Set,n=new Set;function r(i){for(let a of i.nodes){if(a.type!==`core`)continue;let i=V(a.data?.params),o=a.data?.kind;Ye(a.id,o,i).forEach(e=>t.add(e));let s=o===`component`?i.ref:o===`map`?i.body:void 0;typeof s==`string`&&!n.has(s)&&e.components?.[s]&&(n.add(s),r(e.components[s]))}}return r(e),[...t]}var W=`w-full rounded-md border border-input bg-background px-2 py-1 text-xs`,G=[`architect`,`developer`,`reviewer`,`fixer`];function Ze({value:e,onChange:t,selectedRole:n,graph:r,mode:i=`all`}){let{t:o}=a(`agentRuntime`),{activeProjectId:l}=c(),d=(0,L.useRef)(l);d.current=l;let[f,p]=(0,L.useState)([]),[m,h]=(0,L.useState)({}),[g,_]=(0,L.useState)(),[v,ee]=(0,L.useState)(null),[y,te]=(0,L.useState)(``),[ne,re]=(0,L.useState)(!1),[ie,ae]=(0,L.useState)(!1),oe=r?Xe(r):[...G,...Object.keys(e?.roles??{})],b=i===`step`?[n??``]:ie?void 0:oe,x=i!==`workflow`,se=i!==`step`,S=i===`step`?`loopAgents.stepTitle`:i===`workflow`?`loopAgents.policy`:`loopAgents.title`,w=[...G,...Object.keys(e?.roles??{})].some(e=>!oe.includes(e));(0,L.useEffect)(()=>{let e=new AbortController;return Promise.all([`/api/runtime-providers`,`/api/loop-agent-defaults`].map(t=>fetch(t,{signal:e.signal}).then(async e=>{if(!e.ok)throw Error(o(`loadFailed`));return e.json()}))).then(([t,n])=>{e.signal.aborted||(p(t.providers??[]),_(n.agents),ee(n.rolePromptDefaults??null),h(Object.fromEntries(Object.entries(t.status??{}).map(([e,t])=>[e,t.models??[]]))))}).catch(()=>{e.signal.aborted||te(o(`loadFailed`))}),()=>e.abort()},[o]);async function T(){let e=l;re(!0),te(``);try{let n=s(),[r,i]=await Promise.all([fetch(`${n}/agent-runtime/config`),fetch(`${n}/agent-runtime/loop-roles`)]);if(!r.ok||!i.ok)throw Error(o(`loadFailed`));let a=await r.json(),c=await i.json(),{agents:l,fixer:u,roles:f,rolePrompts:p,limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y}=a.config;if(!e||d.current!==e)return;t({schemaVersion:1,agents:l,fixer:u,roles:{...g?.roles,...Object.fromEntries(Object.entries(f??{}).map(([e,t])=>[e,{...t,prompt:p?.[e]??t.prompt}])),...c.roles?.decider?{"loop-decider":{...g.roles[`loop-decider`],...c.roles.decider}}:{}},rolePrompts:Object.fromEntries(Object.entries({...g?.rolePrompts,...p}).filter(([e])=>G.includes(e))),limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y})}catch{te(o(`loadFailed`))}finally{re(!1)}}function ce(n){if(!e)return null;let r=G.includes(n),i=n===`fixer`?e.fixer??e.agents.developer:r?e.agents[n]:e.roles?.[n];if(!i)return null;let a=i=>t(n===`fixer`?{...e,fixer:i}:r?{...e,agents:{...e.agents,[n]:i}}:{...e,roles:{...e.roles,[n]:{...e.roles[n],...i}}}),s=f.find(e=>e.id===i.provider),c=s?.kind===`cli`?M(s.cli).map(e=>e.value):m[i.provider]??[];return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.provider`),(0,R.jsxs)(`select`,{className:W,value:i.provider,onChange:e=>a({provider:e.target.value,maxTurns:i.maxTurns}),children:[(0,R.jsx)(`option`,{value:`inherit`,children:o(`loopAgents.inheritProvider`)}),!s&&i.provider!==`inherit`&&u(i.provider)&&(0,R.jsx)(`option`,{value:i.provider,children:i.provider}),f.filter(e=>u(e.kind===`cli`?e.cli:e.id)).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.kind===`openai-compatible`?e.label??e.id:e.id},e.id))]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.model`),(0,R.jsx)(E,{value:i.model??``,list:`loop-models-${n}`,onChange:e=>a({...i,model:e.target.value||void 0})}),(0,R.jsx)(`datalist`,{id:`loop-models-${n}`,children:c.map(e=>(0,R.jsx)(`option`,{value:e},e))})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.effort`),(0,R.jsx)(E,{value:i.effort??``,onChange:e=>a({...i,effort:e.target.value||void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.maxTurns`,{turns:100}),(0,R.jsx)(E,{type:`number`,min:1,value:i.maxTurns??``,onChange:e=>a({...i,maxTurns:e.target.value?Number(e.target.value):void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.thinking`),(0,R.jsxs)(`select`,{className:W,value:i.thinking??``,onChange:e=>a({...i,thinking:e.target.value?e.target.value:void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`loopAgents.default`)}),(0,R.jsx)(`option`,{value:`off`,children:o(`agents.thinking_off`)}),(0,R.jsx)(`option`,{value:`on`,children:o(`agents.thinking_on`)})]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationModel`),(0,R.jsx)(E,{value:i.escalation?.model??``,onChange:e=>a({...i,escalation:e.target.value?{...i.escalation,model:e.target.value}:void 0})})]}),i.escalation&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationEffort`),(0,R.jsx)(E,{value:i.escalation.effort??``,onChange:e=>a({...i,escalation:{model:i.escalation.model,effort:e.target.value||void 0}})})]})]})}let le=e?{...e,enabled:!0,providers:f,verification:[]}:void 0;return(0,R.jsxs)(`section`,{className:`space-y-3 border-b border-border pb-4`,"aria-label":o(S),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:o(S)}),x&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(i===`step`?`loopAgents.stepHint`:`loopAgents.hint`)}),y&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:y}),!e&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-accent-warning`,children:o(`loopAgents.legacy`)}),(0,R.jsx)(C,{size:`sm`,disabled:!g,onClick:()=>g&&t(structuredClone(g)),children:o(`loopAgents.enable`)})]}),i!==`step`&&(0,R.jsx)(C,{size:`sm`,variant:`secondary`,disabled:!l||!g||ne,onClick:()=>void T(),children:o(`loopAgents.import`)}),e&&(0,R.jsxs)(R.Fragment,{children:[i===`all`&&w&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>ae(e.target.checked)}),o(`loopAgents.showUnused`)]}),x&&G.filter(e=>!b||b.includes(e)).map(r=>(0,R.jsxs)(`details`,{open:n===r,className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[ce(r),e.rolePrompts?.[r]===`inherit`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`loopAgents.inheritDefinition`)}),(0,R.jsx)(`textarea`,{readOnly:!0,"aria-label":o(`customRoles.prompt`),className:`${W} opacity-80`,rows:8,value:v?.[r]??o(`loopAgents.coreDefinitionUnavailable`)}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,disabled:!v?.[r],onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:v?.[r]??``}}),children:o(`loopAgents.customizeDefinition`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:W,rows:10,maxLength:2e4,value:e.rolePrompts?.[r]??``,onChange:n=>t({...e,rolePrompts:{...e.rolePrompts,[r]:n.target.value}})})]}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:`inherit`}}),children:o(`loopAgents.restoreDefinition`)})]})]})]},r)),i===`step`&&n&&![...G,`archive`,`verify`].includes(n)&&!e.roles?.[n]&&(0,R.jsx)(C,{size:`sm`,disabled:!f.length,onClick:()=>t({...e,roles:{...e.roles,[n]:{provider:`inherit`,access:`read`,artifacts:`none`}}}),children:o(`customRoles.add`)}),(x||i===`workflow`)&&(0,R.jsx)(Ve,{manageRoles:i!==`step`,visibleRoleIds:i===`workflow`?[]:b,roles:e.roles,provider:`inherit`,supported:!0,onChange:n=>{Object.keys(n).some(t=>!e.roles?.[t])&&ae(!0),t({...e,roles:n,rolePrompts:Object.fromEntries(Object.entries(e.rolePrompts??{}).filter(([e])=>G.includes(e)))})},renderEngine:ce}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[se&&(0,R.jsxs)(`details`,{className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:o(`loopAgents.policy`)}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[[`maxAttempts`,`maxTokens`,`maxCostUsd`,`timeoutMs`].map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.${n}`),(0,R.jsx)(E,{type:`number`,min:1,value:e.limits?.[n]??``,onChange:r=>t({...e,limits:{...e.limits,[n]:r.target.value?Number(r.target.value):void 0}})})]},n)),(0,R.jsx)(Ue,{catalogUrl:`/api/loop-agent-defaults`,guardrails:e.guardrails,onChange:n=>t({...e,guardrails:n})}),le&&(0,R.jsx)(B,{config:le,onChange:n=>t({...e,efficiency:n.efficiency})})]})]}),(i===`all`||i===`step`&&n===`reviewer`)&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.minScore`,{score:70}),(0,R.jsx)(E,{type:`number`,min:70,max:100,value:e.review?.minScore??``,onChange:n=>t({...e,review:{...e.review,minScore:n.target.value?Number(n.target.value):void 0}})})]}),N.map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.aspects.${n}`,{score:_e.aspects[n]}),(0,R.jsx)(E,{type:`number`,min:_e.aspects[n],max:100,value:e.review?.aspects?.[n]??``,onChange:r=>t({...e,review:{...e.review,aspects:{...e.review?.aspects,[n]:r.target.value?Number(r.target.value):void 0}}})})]},n))]}),(i===`all`||i===`step`&&n===`architect`)&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`architect.onLowConfidence`),(0,R.jsxs)(`select`,{className:W,value:e.architect?.onLowConfidence??`ask`,onChange:n=>t({...e,architect:{onLowConfidence:n.target.value}}),children:[(0,R.jsx)(`option`,{value:`ask`,children:o(`architect.ask`)}),(0,R.jsx)(`option`,{value:`proceed`,children:o(`architect.proceed`)})]})]}),(i===`all`||i===`step`&&n===`archive`)&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.approvalBeforeArchive??!1,onChange:n=>t({...e,approvalBeforeArchive:n.target.checked})}),o(`approvalBeforeArchive`)]})]})]})]})}var K=`w-full min-w-0 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`;function q({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,L.useId)(),[l,u]=(0,L.useState)(``);if(o>24)return(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s(`builder.core.tooDeep`)});let d=typeof e.title==`string`?e.title:r.split(`.`).slice(-1)[0],f=(e,n,a,s)=>(0,R.jsx)(q,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof V(t).provider==`string`?String(V(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(V),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):H(e)===(Array.isArray(t)?`array`:typeof t)));return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,R.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,R.jsx)(`select`,{id:c,className:K,value:r,onChange:t=>n(U(e[Number(t.target.value)])),children:e.map((e,t)=>(0,R.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):H(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,R.jsxs)(`p`,{className:`text-xs`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsxs)(`select`,{className:K,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,R.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,R.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=H(e);if(m===`object`){let r=V(t),i=V(e.properties),a=new Set(Array.isArray(e.required)?e.required:[]),o=[...Object.keys(i),...Object.keys(r).filter(e=>!(e in i))],c=(e,t)=>{let a={...r};e===`provider`&&t!==r.provider&&i.model&&(delete a.model,delete a.effort),t===void 0?delete a[e]:Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n(a)},m=Array.isArray(p)?p.map(e=>V(e).required).filter(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)):[],h=t=>{let a={...r};if(m.some(e=>e.includes(t)))for(let e of m)for(let n of e)n!==t&&delete a[n];Object.defineProperty(a,t,{value:U(V(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,R.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-semibold text-foreground mb-1`,children:d}),o.map(t=>{let n=Object.prototype.hasOwnProperty.call(r,t),o=a.has(t);return!n&&!o?(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs rounded border border-border px-2 py-1 mr-1 hover:bg-muted`,onClick:()=>h(t),"aria-label":s(`builder.core.addField`,{name:t}),children:[(0,R.jsx)(v,{className:`h-3 w-3`}),t]},t):(0,R.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,R.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>c(t,void 0),"aria-label":s(`builder.core.removeField`,{name:t}),children:(0,R.jsx)(re,{className:`h-3.5 w-3.5`})}),f(t,V(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{className:K,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`p-1.5 text-accent-primary disabled:opacity-40`,disabled:!l.trim()||Object.prototype.hasOwnProperty.call(r,l.trim())||[`__proto__`,`constructor`,`prototype`].includes(l.trim()),onClick:()=>{h(l.trim()),u(``)},"aria-label":s(`builder.core.addField`,{name:l}),children:(0,R.jsx)(v,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=V(e.items);return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,R.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,R.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>n(r.filter((e,n)=>n!==t)),"aria-label":s(`builder.core.removeField`,{name:`${d} ${t+1}`}),children:(0,R.jsx)(re,{className:`h-3.5 w-3.5`})}),f(String(t+1),i,e,e=>n(r.map((n,r)=>r===t?e:n)))]},t)),(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs text-accent-primary`,disabled:typeof e.maxItems==`number`&&r.length>=e.maxItems,onClick:()=>n([...r,U(i)]),children:[(0,R.jsx)(v,{className:`h-3 w-3`}),s(`builder.core.addItem`)]})]})}if(!Object.keys(e).length){let e=t===null?`null`:Array.isArray(t)?`array`:typeof t,r=[`object`,`array`,`boolean`,`number`,`null`].includes(e)?e:`string`;return(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,R.jsx)(`select`,{className:K,value:r,onChange:e=>n(e.target.value===`null`?null:U({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,R.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,R.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>n(e.target.checked),className:`accent-accent-primary`}),d]});if(m===`number`||m===`integer`)return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsx)(`input`,{type:`number`,className:K,value:typeof t==`number`?t:``,min:typeof e.minimum==`number`?e.minimum:void 0,max:typeof e.maximum==`number`?e.maximum:void 0,step:m===`integer`?1:`any`,onChange:e=>n(e.target.value===``?void 0:Number(e.target.value))})]});let h=d===`provider`?i.providers:d===`roleId`?i.roles:[`ref`,`body`].includes(d)?i.components:void 0,g=d===`model`?i.models?.[i.selectedProvider??``]:void 0,_=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,h?.length&&d!==`roleId`?(0,R.jsxs)(`select`,{className:K,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,R.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!h.includes(String(t))?(0,R.jsx)(`option`,{value:String(t),children:String(t)}):null,h.map(e=>(0,R.jsx)(`option`,{children:e},e))]}):_?(0,R.jsx)(`textarea`,{className:`${K} min-h-24 resize-y font-mono`,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}):(0,R.jsx)(`input`,{list:g?.length||d===`roleId`&&h?.length?c:void 0,className:K,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}),g?.length||d===`roleId`&&h?.length?(0,R.jsx)(`datalist`,{id:c,children:(g??h??[]).map(e=>(0,R.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var J=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,Qe=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function $e({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,L.useState)(``),l=V(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(Qe.filter(e=>l[e]).map(e=>[e,l[e]])),...V(V(l.budget).properties).maxTokens?{maxTokens:V(V(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>Qe.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:Ge(e);return(0,R.jsxs)(R.Fragment,{children:[!t&&(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,R.jsxs)(`select`,{className:J,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,R.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,R.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}),(0,R.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,R.jsx)(q,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!Qe.includes(e)));r({...e,config:{...n,...t}})}}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`text-xs rounded border border-border px-2 py-1 hover:bg-muted`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`input`,{className:J,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,disabled:!/^[a-z][a-z0-9-]{0,63}$/.test(s)||!!e.components?.[s],onClick:()=>{i(s,!0),c(``)},"aria-label":o(`builder.core.addComponent`),className:`text-accent-primary disabled:opacity-40`,children:(0,R.jsx)(v,{className:`w-4 h-4`})})]}),f&&t&&(0,R.jsx)(q,{schema:{type:`object`,additionalProperties:!1,required:[`inputs`,`outputs`],properties:{inputs:{type:`array`,items:{type:`string`}},outputs:{type:`array`,items:{type:`string`}}}},value:{inputs:f.inputs??[],outputs:f.outputs??[`next`,`failed`]},path:t,onChange:n=>{r({...e,components:{...e.components,[t]:{...f,...n}}})}})]})]})}function et({nodeId:e,data:t,piece:n,choices:r,schema:i,onChange:o,onDelete:s,onOpenCanvas:c}){let{t:l}=a(`loops`),u=t.params?.ref??t.params?.body,d=V(V(i.$defs).retry),f=n?.paramsSchema??{},p=t.coreKind===`assign`?{set:l(`builder.core.assignment.set`),increment:l(`builder.core.assignment.increment`)}:t.coreKind===`decider`?{continueWhen:l(`builder.core.requiredContinue`)}:{},m=Object.keys(p).length?{...f,properties:Object.fromEntries(Object.entries(V(f.properties)).map(([e,t])=>[e,p[e]?{...V(t),title:p[e]}:t]))}:f;return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`h-4 w-4`})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,R.jsx)(`input`,{className:J,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),[`implementation`,`implementation-step`].includes(t.coreKind??``)&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.legacyImplementation`)}),n?(0,R.jsx)(q,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,R.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,R.jsx)(q,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function tt(e){return e===`continue`||e===`stop`?e:void 0}function nt(e){switch(e){case`core`:return{kind:e,coreKind:`prompt`,params:{text:``,access:`write`,sessionContinuity:`run`}};case`ai-step`:return{kind:e,prompt:``,provider:`claude`,model:``,effort:`medium`,maxTurns:0};case`shell`:return{kind:e,command:``};case`decider`:return{kind:e,goal:``};case`condition`:return{kind:e,join:`AND`};case`end`:return{kind:e,outcome:`success`};default:return{kind:e}}}function Y(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function rt(e,t){return{id:Y(),type:`loop`,position:t,data:nt(e)}}function it(e){let t=(e.nodes??[]).map(e=>({id:e.id,type:`loop`,position:e.position??{x:0,y:0},data:{...e.data??{},...e.type===`core`?{coreKind:e.data?.kind}:{},kind:e.type}})),n=new Map((e.nodes??[]).map(e=>[e.id,e.type]));return{nodes:t,edges:(e.edges??[]).map(e=>{let t=e.branch??(n.get(e.source)===`decider`?n.get(e.target)===`end`?`stop`:`continue`:void 0);return{id:e.id,source:e.source,target:e.target,sourceHandle:e.label??t??void 0,type:`smoothstep`,markerEnd:{type:Ne.ArrowClosed,width:16,height:16},label:e.label??e.join,data:{...e.join?{join:e.join}:{},...t?{branch:t}:{},...e.label?{label:e.label}:{}},...t?{style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:{}}})}}function at(e,t,n,r){let i={...n};return i.legacyDeciderRole&&!e.some(e=>e.data.coreKind===`decider`&&e.data.params?.roleId===i.legacyDeciderRole)&&delete i.legacyDeciderRole,{nodes:e.map(e=>{let{kind:t,coreKind:n,...r}=e.data,i={id:e.id,type:t,position:e.position};return(Object.keys(r).length>0||n)&&(i.data={...r,...t===`core`?{kind:n}:{}}),i}),edges:t.map(t=>{let n=t.data?.join;if(e.find(e=>e.id===t.source)?.data.kind===`core`){let e=t.sourceHandle??t.data?.label;return{id:t.id,source:t.source,target:t.target,...e?{label:e}:{}}}let r=tt(t.sourceHandle)??tt(t.data?.branch);return{id:t.id,source:t.source,target:t.target,...n?{join:n}:{},...r?{branch:r}:{}}}),config:i,...r?{components:r}:{}}}var ot=`specrailsNodes`;function st(e,t){let n=e.filter(e=>e.selected);if(n.length===0)return null;let r=new Set(n.map(e=>e.id));return{specrailsNodes:1,nodes:n,edges:t.filter(e=>r.has(e.source)&&r.has(e.target))}}function ct(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[ot]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function lt(e,t){let n=t.offset??{x:40,y:40},r=new Set(t.excludeKinds??[]),i=new Map;return{nodes:e.nodes.filter(e=>!r.has(String(e.data?.kind))).map(e=>{let r=t.mintId();return i.set(e.id,r),{...e,id:r,position:{x:e.position.x+n.x,y:e.position.y+n.y},selected:!0}}),edges:e.edges.filter(e=>i.has(e.source)&&i.has(e.target)).map(e=>({...e,id:t.mintId(),source:i.get(e.source),target:i.get(e.target),selected:!1}))}}function ut(e){return typeof e!=`string`||e.trim().length===0}function dt(e,t){let n=e.find(e=>e.data.kind===`start`),r=new Set;if(!n)return r;let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e.target);let a=[n.id];for(;a.length;){let e=a.shift();if(!r.has(e)){r.add(e);for(let t of i.get(e)??[])r.has(t)||a.push(t)}}return r}function ft(e,t){let n=[],r=e.filter(e=>e.data.kind===`start`);r.length===0&&n.push({severity:`error`,code:`NO_START`});for(let e of r.slice(1))n.push({severity:`error`,code:`MULTIPLE_START`,nodeId:e.id});if(e.some(e=>e.data.kind===`end`||e.data.kind===`core`&&e.data.coreKind===`end`)||n.push({severity:`error`,code:`NO_END`}),e.some(e=>e.data.kind===`core`)&&e.some(e=>![`start`,`core`,`end`].includes(e.data.kind))&&n.push({severity:`error`,code:`MIXED_ENGINES`}),r.length===1){let r=dt(e,t);for(let t of e)r.has(t.id)||n.push({severity:`error`,code:`ORPHAN`,nodeId:t.id})}let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e);for(let t of e){let e=i.get(t.id)??[];switch(t.data.kind){case`core`:{(!t.data.coreKind||!t.data.params||typeof t.data.params!=`object`||Array.isArray(t.data.params))&&n.push({severity:`error`,code:`CORE_PIECE`,nodeId:t.id});let r=e.map(e=>e.sourceHandle??e.data?.label);(t.data.coreKind===`end`?e.length>0:!r.length||r.some(e=>!e||!/^[a-z][a-z0-9-]{0,31}$/.test(e))||new Set(r).size!==r.length)&&n.push({severity:`error`,code:`CORE_OUTCOMES`,nodeId:t.id});break}case`decider`:{let r=new Set(e.map(e=>e.sourceHandle??e.data?.branch));(!r.has(`continue`)||!r.has(`stop`))&&n.push({severity:`error`,code:`DECIDER_BRANCHES`,nodeId:t.id}),ut(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:ut(t.data.prompt)&&n.push({severity:`warning`,code:`EMPTY_PROMPT`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`shell`:ut(t.data.command)&&n.push({severity:`warning`,code:`EMPTY_COMMAND`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`start`:e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;default:break}}return n}function pt(e){let t=new Map;for(let n of e)n.nodeId&&(n.severity===`error`||!t.has(n.nodeId))&&t.set(n.nodeId,n.severity);return t}var mt=(0,L.createContext)(new Map),ht=(0,L.createContext)({pieces:[]}),gt=[`start`,`ai-step`,`shell`,`decider`,`end`],_t={core:he,start:g,"ai-step":he,shell:O,decider:h,condition:h,end:Te},vt={core:`border-accent-primary/60`,start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function yt({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=_t[i]??_,s=String(t.label??``).trim(),c=(0,L.useContext)(mt).get(e),l=(0,L.useContext)(ht),u=qe(l.pieces.find(e=>e.kind===t.coreKind),t.params??{},l.components),d=i===`core`?String(t.params?.roleId??t.params?.ref??t.params?.body??t.params?.text??t.params?.expr??``):i===`ai-step`?String(t.model||t.provider||``):i===`shell`?String(t.command||``):i===`decider`?String(t.goal||``):i===`condition`?String(t.join||`AND`):i===`end`?String(t.outcome||`success`):``;return(0,R.jsxs)(`div`,{className:S(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,vt[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,R.jsx)(F,{type:`target`,position:I.Top}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,R.jsx)(`span`,{className:`text-xs font-semibold text-foreground truncate max-w-[150px]`,children:s||r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)}),s&&(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 flex-shrink-0`,children:r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)})]}),d&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,R.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,R.jsx)(F,{id:e,type:`source`,position:I.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,R.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,R.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,R.jsx)(F,{id:`continue`,type:`source`,position:I.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,R.jsx)(F,{id:`stop`,type:`source`,position:I.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,R.jsx)(F,{type:`source`,position:I.Bottom})]})}function bt({loopId:e,onExit:t,onWindowOpened:n}){let{t:o}=a(`loops`),u=i(),{id:d}=r(),h=e??d,g=(0,L.useCallback)(()=>{t?t():u(`/loops`)},[t,u]),_=we(),{fitView:y,screenToFlowPosition:re}=ke(),{activeProjectId:w}=c(),[T,ce]=(0,L.useState)([]),[E,fe]=(0,L.useState)({}),[he,ge]=(0,L.useState)(!1),[D,_e]=(0,L.useState)({}),[ve,O]=(0,L.useState)([]),[A,j]=(0,L.useState)(null),[M,be]=(0,L.useState)(null);(0,L.useEffect)(()=>{let e=!1;return k.catalog().then(t=>{e||(ce(t.nodeKinds),fe(t.definitionSchema??{}),ge(!1))}).catch(()=>{e||ge(!0)}),()=>{e=!0}},[]),(0,L.useEffect)(()=>{let e=new AbortController;_e({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([w&&A&&!A.config.agents?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||_e({providers:(t?.config?.providers??n?.providers??[]).map(e=>e.id),roles:[...new Set([...Object.keys(t?.config?.agents??{}),...Object.keys(t?.config?.roles??{}),...Object.keys(t?.workflowRoleDefaults??{})])],models:Object.fromEntries(Object.entries(n?.status??{}).map(([e,t])=>[e,t.models??[]]))})}),()=>e.abort()},[w,!!A,!!A?.config.agents]);let[N,P,Te]=Oe([]),[F,I,Fe]=Le([]),[z,Ve]=(0,L.useState)(``),[He,Ue]=(0,L.useState)(!1),[We,B]=(0,L.useState)(!1),[Ge,V]=(0,L.useState)(10),[H,U]=(0,L.useState)(30),[Xe,W]=(0,L.useState)(null),[G,K]=(0,L.useState)(null),[q,J]=(0,L.useState)(!1);(0,L.useEffect)(()=>J(!1),[h]);let[Qe,tt]=(0,L.useState)(!0),[nt,ot]=(0,L.useState)(!1),[ut,dt]=(0,L.useState)(!1),[vt,bt]=(0,L.useState)(null),[xt,St]=(0,L.useState)(!1),X=(0,L.useMemo)(()=>[...ft(N,F),...ve.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[N,F,ve]),Ct=(0,L.useMemo)(()=>pt(X),[X]),wt=X.filter(e=>e.severity===`error`).length,[Ot,kt]=(0,L.useState)(`manual`),At=(0,L.useRef)(new Map),[jt,Mt]=(0,L.useState)([]),[Nt,Pt]=(0,L.useState)(!1),Ft=(0,L.useCallback)(async()=>{try{Mt(await k.loopConstants())}catch{}},[]);(0,L.useEffect)(()=>{Ft()},[Ft]);let It=(0,L.useMemo)(()=>({loop:yt}),[]),Lt=(0,L.useCallback)(e=>{j(e.graph),be(null);let{nodes:t,edges:n}=it(e.graph);At.current=new Map(t.map(e=>[e.id,{...e.position}]));let r=e.graph.config?.layout,i=r===`vertical`||r===`horizontal`||r===`grid`?r:`manual`;kt(i),P(i===`manual`?t:Ie(t,n,i)),I(n),Ve(e.name),V(e.graph.config?.maxIterations??10),U(e.graph.config?.timeoutMinutes??30),W(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Ue(!!e.builtinId)},[P,I]);(0,L.useEffect)(()=>{if(!h)return;let e=!1;return k.get(h).then(t=>{e||Lt(t)}).catch(()=>l.error(o(`errors.load`))).finally(()=>{e||tt(!1)}),()=>{e=!0}},[h,Lt,o]);let Rt=(0,L.useCallback)(async()=>{if(h){B(!1);try{Lt(await k.restoreBuiltin(h)),O([]),l.success(o(`builder.builtin.restored`))}catch(e){l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}}},[h,Lt,o]),zt=(0,L.useCallback)(e=>{if(O([]),N.find(t=>t.id===e.source)?.data.kind===`core`){I(t=>De({...e,label:e.sourceHandle,data:{label:e.sourceHandle}},t));return}let t=e.sourceHandle===`continue`||e.sourceHandle===`stop`?e.sourceHandle:void 0,n=t?{...e,data:{branch:t},style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:e;I(e=>De(n,e))},[I,N]),Bt=(0,L.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=N.find(t=>t.id===e.source)?.data.kind,n=N.find(t=>t.id===e.target)?.data.kind;if(!t||!n||e.source===e.target&&t!==`core`||t===`end`)return!1;if(t===`core`){let t=N.find(t=>t.id===e.source),n=qe(T.find(e=>e.kind===t.data.coreKind),t.data.params??{},A?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||F.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&F.some(t=>t.source===e.source)||n===`start`)},[N,F,T,A]),Vt=(0,L.useCallback)(e=>{kt(e==="default"?`manual`:e),P(t=>e==="default"?t.map(e=>{let t=At.current.get(e.id);return t?{...e,position:{...t}}:e}):Ie(t,F,e)),requestAnimationFrame(()=>y({padding:.25,maxZoom:.85,duration:300}))},[P,F,y]),Ht=(0,L.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&kt(`manual`),Te(e)},[Te]),Ut=(0,L.useRef)(N);Ut.current=N;let Wt=(0,L.useRef)(F);Wt.current=F,(0,L.useEffect)(()=>{let e=()=>{let e=window.document.activeElement;return!!e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable)},t=t=>{if(e())return;let n=st(Ut.current,Wt.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},n=t=>{if(e())return;let n=ct(t.clipboardData?.getData(`text/plain`)??``);if(!n)return;t.preventDefault();let r=lt(n,{mintId:Y,offset:{x:40,y:40},excludeKinds:Ut.current.some(e=>e.data.kind===`start`)?[`start`]:[]});r.nodes.length!==0&&(P(e=>[...e.map(e=>({...e,selected:!1})),...r.nodes]),I(e=>[...e,...r.edges]),kt(`manual`),l.success(o(`builder.paste.done`,{count:r.nodes.length})))};return window.addEventListener(`copy`,t),window.addEventListener(`paste`,n),()=>{window.removeEventListener(`copy`,t),window.removeEventListener(`paste`,n)}},[P,I,o]);let Gt=(0,L.useCallback)(e=>{let t=rt(e,{x:120+Math.random()*120,y:80+Math.random()*240});P(e=>[...e,t]),J(!1),K(t.id)},[P]),Kt=(0,L.useCallback)(e=>{O([]),P(t=>t.map(t=>t.id===G?{...t,data:{...t.data,...e}}:t))},[G,P]),qt=(0,L.useCallback)(()=>{G&&(P(e=>e.filter(e=>e.id!==G)),I(e=>e.filter(e=>e.source!==G&&e.target!==G)),K(null))},[G,P,I]),Z=!!A&&!N.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,L.useCallback)(()=>{let e={...A?.config,maxIterations:Ge,timeoutMinutes:H,maxCostUsd:Xe??void 0,layout:Ot},t=M?A?.components?.[M]:A,n={...t,...at(N,F,M?t?.config??e:e)};return M?{...A,config:e,components:{...A?.components,[M]:n}}:{...n,components:A?.components}},[A,M,N,F,Ge,H,Xe,Ot]),Jt=(0,L.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:Y(),type:`start`,position:{x:160,y:40}},{id:Y(),type:`core`,position:{x:160,y:220},data:{kind:`end`,params:{outcome:`success`}}}],edges:[],config:{maxIterations:10,timeoutMinutes:0},inputs:[],outputs:[`next`,`failed`]}});let r=e?n.components?.[e]:n;if(!r)return;let i=it(r);j(n),be(e),P(i.nodes),I(i.edges),K(null),O([]),requestAnimationFrame(()=>y({padding:.25}))},[Q,P,I,y]),Yt=(0,L.useCallback)((e,t)=>{let n={id:Y(),type:`loop`,position:t??{x:160+N.length*20,y:100+N.length*30},data:Ke(e)};if(e.kind===`role-turn`&&A){let e=D.providers?.[0]??`claude`,t=(`agent-`+n.id.replace(/[^a-z0-9-]/g,`-`)).slice(0,64),r=A.config.agents??{schemaVersion:1,agents:{architect:{provider:e},developer:{provider:e},reviewer:{provider:e}}};n.data.params={roleId:t,prompt:o(`builder.core.agentTaskDefault`)},j({...A,config:{...A.config,agents:{...r,roles:{...r.roles,[t]:{provider:e,access:`write`,artifacts:`none`,prompt:``}}}}})}e.kind===`prompt`&&D.providers?.length&&(n.data.params.engine={provider:D.providers[0]}),P(e=>[...e,n]),J(!1),K(n.id)},[N.length,P,D.providers,A,o]),Xt=(0,L.useCallback)(async()=>{St(!0);try{let e=Q(),{steps:t}=await k.previewLoop(e);bt(t)}catch{l.error(o(`builder.preview.error`))}finally{St(!1)}},[Q,o]),Zt=(0,L.useCallback)(async()=>{if(!h)return!1;ot(!0);try{let e=Q();return await k.update(h,{name:z,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:o(`errors.save`)),!1}finally{ot(!1)}},[h,Q,z,o]),Qt=(0,L.useCallback)(async()=>{if(h&&await Zt())try{await k.publish(h),l.success(o(`builder.published`)),g()}catch(e){e instanceof Ce?(O(e.errors),dt(!0),l.error(o(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}},[h,Zt,g,o]),$=N.find(e=>e.id===G)??null;return(0,R.jsx)(mt.Provider,{value:Ct,children:(0,R.jsx)(ht.Provider,{value:{pieces:T,components:A?.components},children:(0,R.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:g,className:`text-muted-foreground hover:text-foreground`,"aria-label":o(`builder.back`),children:(0,R.jsx)(f,{className:`w-4 h-4`})}),(0,R.jsx)(`input`,{value:z,onChange:e=>Ve(e.target.value),className:`text-sm font-semibold bg-transparent text-foreground border-b border-transparent focus:border-border focus:outline-none min-w-0`,"aria-label":`name`})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(le,{delayDuration:150,children:[(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxIterations`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxIterations`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxIterationsHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:1,value:Ge,onChange:e=>V(Math.max(1,Number(e.target.value)||1)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.timeout`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.timeout`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.timeoutHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,"aria-label":o(`builder.config.timeout`),value:H,onChange:e=>U(Math.max(0,Number(e.target.value)||0)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxCost`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxCost`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxCostHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:Xe??``,onChange:e=>{let t=Number(e.target.value);W(e.target.value===``||!(t>0)?null:t)},className:`w-16 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]})]}),Z&&(0,R.jsx)(`button`,{type:`button`,"aria-pressed":q,onClick:()=>J(e=>!e),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:o(`builder.loopSettings`)}),He&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(!0),disabled:nt,"data-testid":`builder-restore-builtin`,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(ee,{className:`w-3 h-3`}),` `,o(`actions.restoreBuiltin`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Xt(),disabled:xt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(pe,{className:`w-3 h-3`}),` `,o(`builder.preview.label`)]}),!Se()&&(0,R.jsxs)(`button`,{type:`button`,disabled:nt,onClick:()=>void Zt().then(async e=>{if(!(!e||!h))try{await ye(w,h),n?n():g()}catch(e){l.error(String(e))}}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted disabled:opacity-50`,children:[(0,R.jsx)(m,{className:`w-3 h-3`}),o(`window.open`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Zt().then(e=>e&&l.success(o(`builder.saved`))),disabled:nt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,o(`builder.save`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Qt(),disabled:nt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-50`,children:[(0,R.jsx)(ne,{className:`w-3 h-3`}),` `,o(`builder.publish`)]})]})]}),He&&(0,R.jsx)(`div`,{role:`note`,"data-testid":`builder-builtin-note`,className:`px-4 py-1.5 border-b border-border bg-accent-info/10 text-[11px] text-accent-info flex-shrink-0`,children:o(`builder.builtin.note`)}),(0,R.jsx)(se,{open:We,onOpenChange:e=>{e||B(!1)},children:(0,R.jsxs)(x,{className:`max-w-sm`,children:[(0,R.jsxs)(b,{children:[(0,R.jsx)(oe,{children:o(`builder.builtin.confirmTitle`)}),(0,R.jsx)(ae,{children:o(`builder.builtin.confirmBody`)})]}),(0,R.jsxs)(ie,{children:[(0,R.jsx)(C,{variant:`ghost`,onClick:()=>B(!1),children:o(`common:actions.cancel`)}),(0,R.jsx)(C,{"data-testid":`builder-restore-confirm`,onClick:()=>void Rt(),children:o(`actions.restoreBuiltin`)})]})]})}),(0,R.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,R.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,R.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:o(`builder.addNode`)}),Z&&he&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:o(`builder.core.unavailable`)}),Z&&T.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,R.jsxs)(`div`,{className:`pt-2`,children:[(0,R.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:o(`builder.core.groups.${e}`)}),T.filter(t=>![`implementation`,`implementation-step`].includes(t.kind)&&Je(t.kind)===e).map(e=>(0,R.jsxs)(`button`,{type:`button`,draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/specrails-core-piece`,e.kind),t.dataTransfer.effectAllowed=`copy`},onClick:()=>Yt(e),className:`flex items-center gap-2 w-full min-h-8 px-2 rounded text-left text-xs hover:bg-muted focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,R.jsx)(v,{className:`h-3 w-3 flex-shrink-0`}),o(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:gt).map(e=>{let t=_t[e];return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>Gt(e),disabled:e===`start`&&N.some(e=>e.data.kind===`start`),className:`flex items-center gap-2 w-full h-8 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:[(0,R.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,R.jsx)(`span`,{className:`truncate`,children:o(`builder.nodes.${e}`)}),(0,R.jsx)(v,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,R.jsx)(`div`,{className:`flex-1 min-w-0 relative`,onDragOver:e=>{e.dataTransfer.types.includes(`application/specrails-core-piece`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=T.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Yt(t,re({x:e.clientX,y:e.clientY})))},children:Qe?(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,R.jsxs)(Ae,{nodes:N,edges:F,onNodesChange:Ht,onEdgesChange:Fe,onConnect:zt,isValidConnection:Bt,onNodeClick:(e,t)=>{J(!1),K(t.id)},onPaneClick:()=>{J(!1),K(null)},nodeTypes:It,colorMode:_.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Ne.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,R.jsx)(Me,{position:`top-center`,children:(0,R.jsxs)(`nav`,{className:`flex items-center gap-1 rounded border border-border bg-card/95 p-1 text-xs`,"aria-label":o(`builder.core.breadcrumbs`),children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>Jt(null),className:`px-2 py-1 hover:bg-muted`,children:z||o(`builder.core.root`)}),M&&(0,R.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,M]})]})}),(0,R.jsx)(je,{}),(0,R.jsx)(Pe,{}),(0,R.jsx)(Ee,{pannable:!0,zoomable:!0}),(0,R.jsx)(Me,{position:`top-left`,children:(0,R.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-md border border-border bg-card/90 backdrop-blur p-0.5`,role:`group`,"aria-label":o(`builder.arrange.label`),children:[[`vertical`,Be],[`horizontal`,ze],[`grid`,Re],[`default`,ee]].map(([e,t])=>{let n=e==="default"?`reset`:e,r=e==="default"?Ot===`manual`:Ot===e;return(0,R.jsx)(`button`,{type:`button`,title:o(`builder.arrange.${n}`),"aria-label":o(`builder.arrange.${n}`),"aria-pressed":r,onClick:()=>Vt(e),className:S(`inline-flex items-center justify-center w-7 h-7 rounded hover:bg-muted`,r?`bg-muted text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:(0,R.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,R.jsx)(Me,{position:`top-right`,children:(0,R.jsx)(le,{delayDuration:150,children:(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 h-6 px-2 rounded-md text-[10px] border border-border bg-card/90 text-muted-foreground hover:text-foreground backdrop-blur`,children:[(0,R.jsx)(de,{className:`w-3 h-3`}),o(`builder.edgesHelp.label`)]})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,R.jsx)(Me,{position:`bottom-center`,children:(0,R.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>dt(e=>!e),className:S(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,wt>0?`text-destructive`:`text-accent-warning`),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),o(`builder.problems.count`,{count:X.length})]}),ut&&(0,R.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>{e.nodeId&&(J(!1),K(e.nodeId))},className:`flex items-start gap-1.5 w-full text-left px-2.5 py-1 hover:bg-muted disabled:cursor-default`,children:[(0,R.jsx)(`span`,{className:S(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,R.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):o(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,R.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[!q&&($?$.data.kind===`core`?(0,R.jsx)(et,{nodeId:$.id,data:$.data,piece:T.find(e=>e.kind===$.data.coreKind),choices:{...D,roles:A?.config.agents?[...Object.keys(A.config.agents.agents),...Object.keys(A.config.agents.roles??{})]:D.roles,components:Object.keys(A?.components??{})},schema:E,onChange:Kt,onDelete:qt,onOpenCanvas:Jt}):(0,R.jsx)(Dt,{data:$.data,onChange:Kt,onDelete:qt,constants:jt,onManageConstants:()=>Pt(!0)}):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`builder.inspector.selectNode`)})),!q&&Z&&A&&$&&(Ye($.id,$.data.coreKind,$.data.params??{}).length>0||$.data.coreKind===`implementation-step`&&$.data.params?.phase===`archive`)&&(0,R.jsx)(Ze,{mode:$.data.coreKind===`implementation`?`all`:`step`,graph:Q(),value:A.config.agents,selectedRole:String($.data.params?.phase??Ye($.id,$.data.coreKind,$.data.params??{})[0]??``),onChange:e=>j({...A,config:{...A.config,agents:e}})},`${h}:${$.id}`),q&&Z&&A&&(0,R.jsx)(Ze,{mode:`workflow`,graph:Q(),value:A.config.agents,selectedRole:$?Ye($.id,$.data.coreKind,$.data.params??{})[0]:void 0,onChange:e=>j({...A,config:{...A.config,agents:e}})},h),q&&Z&&A&&(0,R.jsx)($e,{graph:A,canvas:M,schema:E,onChange:j,onOpenCanvas:Jt})]})]}),(0,R.jsx)(Tt,{open:Nt,onClose:()=>Pt(!1),constants:jt,onChanged:Ft,t:o}),(0,R.jsx)(Et,{steps:vt,onClose:()=>bt(null),t:o})]})})})}var xt=[{labelKey:`builder.inspector.tokensSpec`,tokens:[{token:`{{spec.title}}`,label:`spec.title`},{token:`{{spec.description}}`,label:`spec.description`},{token:`{{spec.id}}`,label:`spec.id`},{token:`{{spec.status}}`,label:`spec.status`},{token:`{{spec.priority}}`,label:`spec.priority`},{token:`{{spec.labels}}`,label:`spec.labels`}]},{labelKey:`builder.inspector.tokensJira`,tokens:[{token:`{{spec.jira_key}}`,label:`spec.jira_key`},{token:`{{spec.jira_url}}`,label:`spec.jira_url`}]}];function St({token:e,label:t,description:n,onInsert:r}){return(0,R.jsx)(`button`,{type:`button`,draggable:!0,onDragStart:t=>t.dataTransfer.setData(`text/plain`,e),onClick:()=>r(e),title:n?`${e} — ${n}`:e,className:`px-1.5 py-0.5 rounded border border-border bg-surface/40 text-[10px] font-mono text-accent-primary hover:bg-accent-primary/10 cursor-grab active:cursor-grabbing`,children:t})}function X({t:e,onInsert:t}){let[n,r]=(0,L.useState)([]);return(0,L.useEffect)(()=>{let e=!1;return k.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,R.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[xt.map(n=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,R.jsx)(St,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,R.jsx)(St,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function Ct({t:e,constants:t,onInsert:n,onManage:r}){return(0,R.jsxs)(`div`,{className:`mb-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,R.jsx)(`button`,{type:`button`,onClick:r,title:e(`builder.constants.manage`),"aria-label":e(`builder.constants.manage`),className:`text-muted-foreground hover:text-foreground`,children:(0,R.jsx)(P,{className:`w-3 h-3`})})]}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,R.jsx)(St,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function wt({c:e,onSave:t,onDelete:n}){let[r,i]=(0,L.useState)(e.value);return(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.jsx)(`input`,{className:`flex-1 text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground`,value:r,onChange:e=>i(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,disabled:r===e.value||!r,onClick:()=>t(r),className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,"aria-label":`save`,children:(0,R.jsx)(p,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]})}function Tt({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(``),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await k.createConstant(a.trim(),s),o(``),c(``),await r()}catch(e){u(e instanceof Error?e.message:`error`)}finally{f(!1)}},g=`text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`;return(0,R.jsx)(se,{open:e,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-md`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:i(`builder.constants.title`)})}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,R.jsx)(wt,{c:e,onSave:t=>void k.updateConstant(e.id,t).then(r),onDelete:()=>void k.deleteConstant(e.id).then(r)},e.id))]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,R.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,R.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,R.jsx)(C,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,R.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,R.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,R.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function Et({steps:e,onClose:t,t:n}){return(0,R.jsx)(se,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-2xl`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:n(`builder.preview.title`)})}),(0,R.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,R.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,R.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,R.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)}),(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)]})]}),(0,R.jsx)(`pre`,{className:`px-2.5 py-2 text-[11px] text-foreground whitespace-pre-wrap break-words font-mono`,children:e.text||`—`})]},`${e.nodeId}-${t}`))]}),(0,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function Dt({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=T(l.find(e=>e.id===s)),d=e.kind,f=`block text-[10px] font-medium text-muted-foreground mb-1`,p=`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,m=(0,L.useRef)(null),h=(0,L.useRef)(null),g=(n,r,i)=>{let a=n.current,o=String(e[r]??``);if(!a){t({[r]:o+i});return}let s=a.selectionStart??o.length,c=a.selectionEnd??o.length;t({[r]:o.slice(0,s)+i+o.slice(c)}),requestAnimationFrame(()=>{a.focus();let e=s+i.length;a.setSelectionRange(e,e)})},_=e=>g(m,`prompt`,e);return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,R.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,R.jsx)(X,{t:o,onInsert:_}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:_,onManage:i}),(0,R.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,R.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,R.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,R.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,R.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,R.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,R.jsx)(`option`,{value:`AND`,children:`AND`}),(0,R.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,R.jsx)(`option`,{value:`success`,children:`success`}),(0,R.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function Ot({loopId:e,onExit:t,onWindowOpened:n}={}){return(0,R.jsx)(Fe,{children:(0,R.jsx)(bt,{loopId:e,onExit:t,onWindowOpened:n})})}export{Ot 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{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{t as o}from"./pencil-C9RkrIPZ.js";import{t as s}from"./square-Ci-PFcFe.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-D1xExSTF.js";import{Yt as u}from"./index-DVkWHOR3.js";import{r as d,t as f}from"./TemplatePreviewModal-C7-G6lvI.js";var p=e(t(),1),m=e(r(),1),h=n();function g({loop:e,onClose:t}){let{t:n}=a(`loops`),r=i();return(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.createPortal)((0,h.jsxs)(`div`,{"data-testid":`loop-preview-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t,"aria-hidden":!0}),(0,h.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.name,className:`relative flex max-h-[80vh] w-full max-w-lg flex-col gap-4 overflow-hidden rounded-xl border border-border/30 bg-popover p-6 shadow-xl backdrop-blur-md`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 pr-6`,children:[(0,h.jsx)(u,{className:`h-4 w-4 shrink-0 text-accent-highlight`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:e.name}),(0,h.jsx)(`span`,{className:c(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,e.builtin?`border-accent-info/40 bg-accent-info/10 text-accent-info`:e.status===`published`?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`),children:e.builtin?n(`preview.builtin`):n(`status.${e.status??`draft`}`,{defaultValue:e.status??``})})]}),e.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]}),(0,h.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.graph.config.timeoutMinutes>0?n(`preview.limits`,{iterations:e.graph.config.maxIterations,timeout:e.graph.config.timeoutMinutes}):n(`preview.limitsNoTimeout`,{iterations:e.graph.config.maxIterations})}),(0,h.jsxs)(`div`,{className:`min-h-0 space-y-1.5 overflow-y-auto pr-1`,children:[(0,h.jsx)(`span`,{className:`block text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`preview.steps`)}),e.graph.nodes.map((e,t)=>{let r=f[e.type]??s,i=d(e);return(0,h.jsxs)(`div`,{className:`rounded border border-border bg-surface/30 p-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,h.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[t+1,`.`]}),(0,h.jsx)(r,{className:`h-3.5 w-3.5 text-accent-primary`}),n(`builder.nodes.${e.type}`)]}),i&&(0,h.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-mono text-[11px] text-muted-foreground`,children:i})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,h.jsx)(l,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)}),!e.locked&&(0,h.jsxs)(l,{"data-testid":`loop-preview-open-builder`,onClick:()=>{t(),r(`/loops/${encodeURIComponent(e.id)}/edit`)},children:[(0,h.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),n(`preview.openInBuilder`)]})]})]})]}),document.body)}export{g as LoopPreviewModal};
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{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{t as o}from"./pencil-C9RkrIPZ.js";import{t as s}from"./square-Ci-PFcFe.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-D1xExSTF.js";import{Yt as u}from"./index-g8S62tpS.js";import{r as d,t as f}from"./TemplatePreviewModal-5CZdAZ0G.js";var p=e(t(),1),m=e(r(),1),h=n();function g({loop:e,onClose:t}){let{t:n}=a(`loops`),r=i();return(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.createPortal)((0,h.jsxs)(`div`,{"data-testid":`loop-preview-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t,"aria-hidden":!0}),(0,h.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.name,className:`relative flex max-h-[80vh] w-full max-w-lg flex-col gap-4 overflow-hidden rounded-xl border border-border/30 bg-popover p-6 shadow-xl backdrop-blur-md`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 pr-6`,children:[(0,h.jsx)(u,{className:`h-4 w-4 shrink-0 text-accent-highlight`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:e.name}),(0,h.jsx)(`span`,{className:c(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,e.builtin?`border-accent-info/40 bg-accent-info/10 text-accent-info`:e.status===`published`?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`),children:e.builtin?n(`preview.builtin`):n(`status.${e.status??`draft`}`,{defaultValue:e.status??``})})]}),e.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]}),(0,h.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.graph.config.timeoutMinutes>0?n(`preview.limits`,{iterations:e.graph.config.maxIterations,timeout:e.graph.config.timeoutMinutes}):n(`preview.limitsNoTimeout`,{iterations:e.graph.config.maxIterations})}),(0,h.jsxs)(`div`,{className:`min-h-0 space-y-1.5 overflow-y-auto pr-1`,children:[(0,h.jsx)(`span`,{className:`block text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`preview.steps`)}),e.graph.nodes.map((e,t)=>{let r=f[e.type]??s,i=d(e);return(0,h.jsxs)(`div`,{className:`rounded border border-border bg-surface/30 p-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,h.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[t+1,`.`]}),(0,h.jsx)(r,{className:`h-3.5 w-3.5 text-accent-primary`}),n(`builder.nodes.${e.type}`)]}),i&&(0,h.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-mono text-[11px] text-muted-foreground`,children:i})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,h.jsx)(l,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)}),!e.locked&&(0,h.jsxs)(l,{"data-testid":`loop-preview-open-builder`,onClick:()=>{t(),r(`/loops/${encodeURIComponent(e.id)}/edit`)},children:[(0,h.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),n(`preview.openInBuilder`)]})]})]})]}),document.body)}export{g as LoopPreviewModal};
@@ -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{r}from"./useDesktop-ChSmmJfc.js";import i from"./LoopsPage-BHv--iI7.js";import a from"./LoopBuilderPage-C4S-rkWp.js";var o=e(t(),1),s=n();function c(){let{projects:e,isLoading:t,setActiveProjectId:n}=r(),[c,l]=(0,o.useState)(()=>new URLSearchParams(window.location.search).get(`loopId`)),u=(0,o.useRef)(!1),d=new URLSearchParams(window.location.search).get(`projectId`);return(0,o.useEffect)(()=>{!t&&!u.current&&(u.current=!0,n(e.some(e=>e.id===d)?d:null))},[t,d,e,n]),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 bg-background`,children:c?(0,s.jsx)(a,{loopId:c,onExit:()=>l(null)},c):(0,s.jsx)(i,{onOpenBuilder:l})})}export{c as LoopWindowSurface};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{r}from"./useDesktop-DpiS8Uov.js";import i from"./LoopsPage-BwFujdGi.js";import a from"./LoopBuilderPage-Dh5uk2Qy.js";var o=e(t(),1),s=n();function c(){let{projects:e,isLoading:t,setActiveProjectId:n}=r(),[c,l]=(0,o.useState)(()=>new URLSearchParams(window.location.search).get(`loopId`)),u=(0,o.useRef)(!1),d=new URLSearchParams(window.location.search).get(`projectId`);return(0,o.useEffect)(()=>{!t&&!u.current&&(u.current=!0,n(e.some(e=>e.id===d)?d:null))},[t,d,e,n]),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 bg-background`,children:c?(0,s.jsx)(a,{loopId:c,onExit:()=>l(null)},c):(0,s.jsx)(i,{onOpenBuilder:l})})}export{c as LoopWindowSurface};