specrails-desktop 2.45.0 → 2.46.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 (122) hide show
  1. package/client/dist/assets/{ActivityFeedPage-D3SQklu5.js → ActivityFeedPage-CsHQPpvl.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-DNGxE33d.js → AgentBrowserCapture-BVcCK7x0.js} +1 -1
  3. package/client/dist/assets/AgentModeAnalyticsPane-C5F3m29G.js +2 -0
  4. package/client/dist/assets/AgentModeCodePane-C5QuKsu0.js +2 -0
  5. package/client/dist/assets/AgentModeJobsPane-rnD-EPMd.js +1 -0
  6. package/client/dist/assets/AgentsPage-DiyJWZcU.js +87 -0
  7. package/client/dist/assets/{AnalyticsPage-BqV6mM2O.js → AnalyticsPage-Dkmb0dnd.js} +1 -1
  8. package/client/dist/assets/CodePage-C0dH99-t.js +3 -0
  9. package/client/dist/assets/{DesktopAnalyticsPage-D6WNax3K.js → DesktopAnalyticsPage-DuTjr2n8.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-68jKUH9f.js → DocsDialog-BVZJZHVR.js} +1 -1
  11. package/client/dist/assets/{DocsPage-BoGJgRpm.js → DocsPage-D6KHTv8V.js} +1 -1
  12. package/client/dist/assets/{ExportDropdown-B2C_XLGp.js → ExportDropdown-pWZGYCv3.js} +1 -1
  13. package/client/dist/assets/InteractiveJobComposer-Ck3PQxjN.js +19 -0
  14. package/client/dist/assets/JobDetailModal-DkoMH3ie.js +1 -0
  15. package/client/dist/assets/JobDetailPage-CBVivcl2.js +1 -0
  16. package/client/dist/assets/JobsPage-CzxEeca9.js +1 -0
  17. package/client/dist/assets/{LoopBuilderPage-D21GxFmL.js → LoopBuilderPage-CtmOE4-b.js} +2 -2
  18. package/client/dist/assets/{LoopPreviewModal-Bo3fYFxN.js → LoopPreviewModal-BYeLjQbr.js} +1 -1
  19. package/client/dist/assets/{LoopsPage-BcrBw1cg.js → LoopsPage-6iW7g25k.js} +1 -1
  20. package/client/dist/assets/{MinimizedChatsContext-Dsv2eHf_.js → MinimizedChatsContext-B6wVevPq.js} +1 -1
  21. package/client/dist/assets/{PluginsPage-BbyTmSLx.js → PluginsPage-Bf1z3WPF.js} +2 -2
  22. package/client/dist/assets/{ProjectSettingsDialog-B3lEXLv7.js → ProjectSettingsDialog-DsCRIc4v.js} +1 -1
  23. package/client/dist/assets/{RepositoryDeliveries-ok_Wo65C.js → RepositoryDeliveries-BQm_3TO8.js} +1 -1
  24. package/client/dist/assets/{RepositoryScopeSelector-DU6QwNaS.js → RepositoryScopeSelector-DnAFtjTz.js} +1 -1
  25. package/client/dist/assets/{ReviewPacketPage-BBCeHtgd.js → ReviewPacketPage-CaXAwtR7.js} +1 -1
  26. package/client/dist/assets/{TemplatePreviewModal-CfNmxS6O.js → TemplatePreviewModal-9aRFpJ_J.js} +1 -1
  27. package/client/dist/assets/{TicketDetailModalContext-DW3eQ0I7.js → TicketDetailModalContext-B1X5glzV.js} +1 -1
  28. package/client/dist/assets/{Trans-BHPMWkOw.js → Trans-BwLgX6n7.js} +1 -1
  29. package/client/dist/assets/agentRuntime-BUagD2I_.js +1 -0
  30. package/client/dist/assets/agentRuntime-BkL70WtX.js +1 -0
  31. package/client/dist/assets/agentRuntime-CWXVqgqE.js +1 -0
  32. package/client/dist/assets/agentRuntime-CvNBdUAe.js +1 -0
  33. package/client/dist/assets/agentRuntime-D4RmeuNY.js +1 -0
  34. package/client/dist/assets/agentRuntime-DTidBWKg.js +1 -0
  35. package/client/dist/assets/agentRuntime-DhKYfyaU.js +1 -0
  36. package/client/dist/assets/agentRuntime-LL8_GLx9.js +1 -0
  37. package/client/dist/assets/format-duration-NJVPOPBG.js +1 -0
  38. package/client/dist/assets/{formatDistanceToNow-Bq8iptrG.js → formatDistanceToNow-CeZv93iR.js} +1 -1
  39. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-BVFky3l_.js → getTimezoneOffsetInMilliseconds-DxAkjvJb.js} +1 -1
  40. package/client/dist/assets/index-Cfh9aaep.css +2 -0
  41. package/client/dist/assets/index-DYoyDWim.js +76 -0
  42. package/client/dist/assets/{jira-api-zrRdZFBB.js → jira-api-ChjVGJx_.js} +1 -1
  43. package/client/dist/assets/narration-4OSg0b5-.js +1 -0
  44. package/client/dist/assets/narration-BPMOQPFe.js +1 -0
  45. package/client/dist/assets/narration-BSldQfjd.js +1 -0
  46. package/client/dist/assets/narration-CvQdWdR5.js +1 -0
  47. package/client/dist/assets/narration-D-e9ssxA.js +1 -0
  48. package/client/dist/assets/narration-DKLjXIFI.js +1 -0
  49. package/client/dist/assets/narration-DnrKC3mF.js +1 -0
  50. package/client/dist/assets/narration-Dypjxeel.js +1 -0
  51. package/client/dist/assets/{project-repositories-CFRaB9UB.js → project-repositories-BvBj9XH9.js} +1 -1
  52. package/client/dist/assets/{provider-capabilities-B-wOHfLP.js → provider-capabilities-CXipwrXJ.js} +1 -1
  53. package/client/dist/assets/{settings-OOyDrZQo.js → settings-B3rWEwOx.js} +1 -1
  54. package/client/dist/assets/{settings-CNiERE-R.js → settings-BcVoiMyw.js} +1 -1
  55. package/client/dist/assets/settings-BlYvaQ7w.js +1 -0
  56. package/client/dist/assets/{settings-DJ2jl3hJ.js → settings-CD5uEBiL.js} +1 -1
  57. package/client/dist/assets/{settings-a7NIODme.js → settings-CyhS0DLJ.js} +1 -1
  58. package/client/dist/assets/{settings-DVRVybR_.js → settings-DCMFUGDs.js} +1 -1
  59. package/client/dist/assets/{settings-CrtCs5-B.js → settings-DEgcA0jd.js} +1 -1
  60. package/client/dist/assets/{settings-ChOCVjX_.js → settings-DmbYKyMJ.js} +1 -1
  61. package/client/dist/assets/{spending-lTZ-bm_y.js → spending-DNM6NAoA.js} +1 -1
  62. package/client/dist/assets/{useDesktop-Duv5ddAa.js → useDesktop-mxHVQOdx.js} +1 -1
  63. package/client/dist/assets/{useSharedWebSocket-5mj2SMKn.js → useSharedWebSocket-DnxHj8jP.js} +2 -2
  64. package/client/dist/index.html +19 -18
  65. package/docs/internals/programmatic-agent-runtime.md +19 -8
  66. package/package.json +1 -1
  67. package/server/dist/agent-mcp-config.js +5 -0
  68. package/server/dist/agent-operator-prompt.js +2 -2
  69. package/server/dist/agent-runtime-bridge.js +62 -14
  70. package/server/dist/agent-runtime-controls-router.js +42 -0
  71. package/server/dist/agent-runtime-controls.js +68 -4
  72. package/server/dist/agent-runtime-loader.js +6 -0
  73. package/server/dist/agent-runtime-metrics.js +46 -0
  74. package/server/dist/agent-runtime-repositories.js +37 -0
  75. package/server/dist/agent-runtime-settings-router.js +5 -3
  76. package/server/dist/agent-runtime-settings.js +125 -21
  77. package/server/dist/agent-runtime-settlement.js +133 -0
  78. package/server/dist/contract-refine-runner.js +7 -7
  79. package/server/dist/core-completion.js +8 -5
  80. package/server/dist/desktop-router.js +26 -0
  81. package/server/dist/job-listing.js +7 -3
  82. package/server/dist/loop-command-catalog.js +2 -2
  83. package/server/dist/loop-executors.js +5 -3
  84. package/server/dist/loop-run-manager.js +2 -2
  85. package/server/dist/mcp/tools/specs.js +7 -4
  86. package/server/dist/multi-repo-execution.js +1 -0
  87. package/server/dist/project-router-jobs.js +8 -2
  88. package/server/dist/project-router-tickets.js +4 -4
  89. package/server/dist/providers/runtime.js +6 -0
  90. package/server/dist/rail-isolated-launch.js +1 -1
  91. package/server/dist/rails-router.js +3 -1
  92. package/server/dist/runtime-role-prompts-router.js +25 -0
  93. package/server/dist/schemas/agent-runtime.schema.json +7 -2
  94. package/server/dist/worktree-overlay.js +32 -1
  95. package/client/dist/assets/AgentModeAnalyticsPane-BUvZNoj0.js +0 -2
  96. package/client/dist/assets/AgentModeCodePane-YW717UvJ.js +0 -2
  97. package/client/dist/assets/AgentModeJobsPane-Cxg_eNmd.js +0 -1
  98. package/client/dist/assets/AgentsPage-B_DCByok.js +0 -87
  99. package/client/dist/assets/CodePage-PyZKCj1B.js +0 -3
  100. package/client/dist/assets/InteractiveJobComposer-l8q-r5Yy.js +0 -19
  101. package/client/dist/assets/JobDetailModal-C-X2GI9j.js +0 -1
  102. package/client/dist/assets/JobDetailPage-C6Jdm7S9.js +0 -1
  103. package/client/dist/assets/JobsPage-DycM6Vgp.js +0 -1
  104. package/client/dist/assets/agentRuntime-14faDjWM.js +0 -1
  105. package/client/dist/assets/agentRuntime-BIokojkJ.js +0 -1
  106. package/client/dist/assets/agentRuntime-Bu4xEcRw.js +0 -1
  107. package/client/dist/assets/agentRuntime-Cz0ASixB.js +0 -1
  108. package/client/dist/assets/agentRuntime-DESdGXLV.js +0 -1
  109. package/client/dist/assets/agentRuntime-DhX5Xy5S.js +0 -1
  110. package/client/dist/assets/agentRuntime-Dpbh_gLp.js +0 -1
  111. package/client/dist/assets/agentRuntime-jS2lplFm.js +0 -1
  112. package/client/dist/assets/index-CBLYwPw6.css +0 -2
  113. package/client/dist/assets/index-DOKftX7y.js +0 -76
  114. package/client/dist/assets/narration-BA8Yw5ZL.js +0 -1
  115. package/client/dist/assets/narration-BuMFUS7Q.js +0 -1
  116. package/client/dist/assets/narration-Bv_iQQG5.js +0 -1
  117. package/client/dist/assets/narration-C6Ost9nL.js +0 -1
  118. package/client/dist/assets/narration-CIbjo2pA.js +0 -1
  119. package/client/dist/assets/narration-CNJ2-2-a.js +0 -1
  120. package/client/dist/assets/narration-OzsPJCXM.js +0 -1
  121. package/client/dist/assets/narration-zCdgiuSU.js +0 -1
  122. package/client/dist/assets/settings-DzXZCb1h.js +0 -1
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor.main-DxrmGfoq.js","assets/rolldown-runtime-CNC7AqOf.js","assets/preload-helper-Czpn1I53.js","assets/editor.api2-4ndOupAA.js","assets/editor-Br_kD0ds.css","assets/monaco.contribution-Bt92R3Vw.js","assets/workers-uOo7WLaa.js"])))=>i.map(i=>d[i]);
2
- 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{t as i}from"./preload-helper-Czpn1I53.js";import{f as a,u as o}from"./chunk-KS7C4IRE-DEKu087k.js";import{G as s,K as c,W as l,X as u,n as d,z as f}from"./TicketDetailModalContext-DW3eQ0I7.js";import{r as p}from"./useSharedWebSocket-5mj2SMKn.js";import{n as m,t as h}from"./createLucideIcon-Bjbbp_KS.js";import{a as g,i as _,r as v,s as y}from"./useDesktop-Duv5ddAa.js";import{n as b}from"./save-B6wGWwBR.js";import{c as x,l as S,u as C}from"./MinimizedChatsContext-Dsv2eHf_.js";import{n as w,t as T}from"./file-text-BcLCfcWZ.js";import{t as E}from"./loader-circle-DcygOQpC.js";import{t as D}from"./search-Cq_gE3Ik.js";import{t as O}from"./sparkles-DrY8hb0X.js";import{t as k}from"./x-CBMI9ejn.js";import{M as A,j}from"./dialog-xXB2q5HJ.js";import{t as M}from"./utils-BC4DHlz2.js";import{n as N,t as P}from"./lib-CGdyxIWg.js";import{n as F,t as I}from"./project-repositories-CFRaB9UB.js";import{c as L}from"./provider-capabilities-B-wOHfLP.js";import{Ct as R,Et as ee,Ht as z,Ot as B,Tt as te,pt as V}from"./index-DOKftX7y.js";var ne=h(`file-search`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`11.5`,cy:`14.5`,r:`2.5`,key:`1bq0ko`}],[`path`,{d:`M13.3 16.3 15 18`,key:`2quom7`}]]),re=h(`files`,[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]),H=h(`folder-search`,[[`path`,{d:`M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1`,key:`1bw5m7`}],[`path`,{d:`m21 21-1.9-1.9`,key:`1g2n9r`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}]]),ie=h(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),ae=h(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),oe=h(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),U=e(t(),1),se=e(r(),1);function W(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function G(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function K(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var q=(e,t)=>Math.abs(e-t)<1.01,ce=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},J,le=()=>{if(J!==void 0)return J;if(typeof navigator>`u`)return J=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return J=!0;let e=navigator.maxTouchPoints;return J=navigator.platform===`MacIntel`&&e!==void 0&&e>0},ue=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},de=e=>e,fe=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},pe=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(ue(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(ue(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},me={passive:!0},Y=typeof window>`u`||`onscrollend`in window,he=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Y,o=0,s=a?null:ce(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,me),a&&r.addEventListener(`scrollend`,u,me),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},ge=(e,t)=>he(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),X=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},_e=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},ve=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:de,rangeExtractor:fe,onChange:()=>{},measureElement:X,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}this.options=t},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=G(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!le()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,me),e.addEventListener(`touchend`,n,me),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=G(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=G(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{let c=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let l=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=this.options.gap,a=e*2,o=this._flatMeasurements;if(!o||o.length<a){let e=new Float64Array(a);o&&l>0&&e.set(o.subarray(0,l*2)),o=e,this._flatMeasurements=o}let s;if(l===0)s=t+n;else{let e=l-1;s=o[e*2]+o[e*2+1]+i}for(let t=l;t<e;t++){let e=r(t),n=c.get(e),a=typeof n==`number`?n:this.options.estimateSize(t);o[t*2]=s,o[t*2+1]=a,s+=a+i}let u=W(e,o,r);return this.measurementsCache=u,u}let u=this.measurementsCache.slice(0,l),d=Array(a).fill(void 0);for(let e=0;e<l;e++){let t=u[e];t&&(d[t.lane]=e)}for(let i=l;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,l,f=o===`estimate`||c.has(e);if(a!==void 0&&this.options.lanes>1){s=a;let e=d[s],r=e===void 0?void 0:u[e];l=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?u[i-1]:this.getFurthestMeasurement(u,i);l=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,s)}let p=c.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=l+m;u[i]={index:i,start:l,size:m,end:h,key:e,lane:s},d[s]=i}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=G(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?be({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:r===1&&this._flatMeasurements!=null?this._flatMeasurements:null}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=G(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(e<0||e>=this.options.count)return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=t-(this.itemSizeCache.get(i)??n);o!==0&&(this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?r<this.getScrollOffset()+this.scrollAdjustments&&this.scrollDirection!==`backward`:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},o,this))&&(le()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=o:this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=o,behavior:void 0})),(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++,this.notify(!1))},this.getVirtualItems=G(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return K(t[ye(0,t.length-1,r?e=>n[e*2]:e=>K(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&q(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},ye=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function be({measurements:e,outerSize:t,scrollOffset:n,lanes:r,flat:i}){let a=e.length-1,o=i?e=>i[e*2]:t=>e[t].start,s=i?e=>i[e*2]+i[e*2+1]:t=>e[t].end;if(e.length<=r)return{startIndex:0,endIndex:a};let c=ye(0,a,o,n),l=c;if(r===1)for(;l<a&&s(l)<n+t;)l++;else if(r>1){let i=Array(r).fill(0);for(;l<a&&i.some(e=>e<n+t);){let t=e[l];i[t.lane]=t.end,l++}let o=Array(r).fill(n+t);for(;c>=0&&o.some(e=>e>=n);){let t=e[c];o[t.lane]=t.start,c--}c=Math.max(0,c-c%r),l=Math.min(a,l+(r-1-l%r))}return{startIndex:c,endIndex:l}}var xe=typeof document<`u`?U.useLayoutEffect:U.useEffect;function Se({useFlushSync:e=!0,...t}){let n=U.useReducer(e=>e+1,0)[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,se.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=U.useState(()=>new ve(r));return i.setOptions(r),xe(()=>i._didMount(),[]),xe(()=>i._willUpdate()),i}function Ce(e){return Se({observeElementRect:pe,observeElementOffset:ge,scrollToFn:_e,...e})}var we=(0,U.createContext)(null);function Z(){return(0,U.useContext)(we)??{apiBase:g()}}function Te(e,t){return e?e===t.repositoryId:!t.repositoryId||t.isPrimary===!0}var Q=n(),Ee=e=>`specrails-desktop:code-tree-filter:${e}`,De=e=>`specrails-desktop:code-tree-collapsed:${e}`;function Oe(e){return e.split(`/`).length-1}function ke(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function Ae(e){return e?e.length>10?e.slice(0,10):e:null}function je(e){return e===`created`?`added`:e===`modified`?`changed`:e===`deleted`?`deleted`:null}function Me(e,t){if(t.size===0)return!1;let n=e.split(`/`);for(let e=1;e<n.length;e++)if(t.has(n.slice(0,e).join(`/`)))return!0;return!1}function Ne({onOpenFile:e,selectedPath:t,filterJobId:n,filterTicketId:r}){let{t:i}=m(`code`),a=(0,U.useId)(),o=Z(),{apiBase:s,repositoryId:c,repositoryPath:u}=o,{activeProjectId:f}=v(),{openTicketDetail:h}=d(),{registerHandler:g,unregisterHandler:y}=p(),[b,x]=(0,U.useState)(()=>{if(!f)return`all`;try{let e=localStorage.getItem(Ee(`${f}:${c??`primary`}`));if(e===`all`||e===`touched-by-ai`)return e}catch{}return`all`});(0,U.useEffect)(()=>{if(f)try{localStorage.setItem(Ee(`${f}:${c??`primary`}`),b)}catch{}},[b,f,c]),(0,U.useEffect)(()=>{(n||r)&&x(`touched-by-ai`)},[n,r]);let[S,T]=(0,U.useState)(()=>{if(!f)return new Set;try{let e=localStorage.getItem(De(`${f}:${c??`primary`}`));if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>typeof e==`string`))}catch{}return new Set});(0,U.useEffect)(()=>{if(f)try{localStorage.setItem(De(`${f}:${c??`primary`}`),JSON.stringify([...S]))}catch{}},[S,f,c]);let E=(0,U.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),D=(0,U.useCallback)(()=>{T(new Set)},[]),O=b===`touched-by-ai`?`${n??`all-jobs`}:${r??`all-specs`}`:`all`,{data:k,refresh:A,isFirstLoad:j,isLoading:N,error:P}=_({namespace:`code-tree-v2:${JSON.stringify([c,u,b,O])}`,projectId:f,initialValue:{entries:[],partial:!1},fetcher:(0,U.useCallback)(async({signal:e})=>{let t=new Map,i=new Set,a=null,o=!1;for(let c=0;c<20;c+=1){e.throwIfAborted();let c=new URLSearchParams({withProvenance:`1`,filter:b});b===`touched-by-ai`&&n&&c.set(`jobId`,n),b===`touched-by-ai`&&typeof r==`number`&&c.set(`ticketId`,String(r)),a&&c.set(`cursor`,a);let l=await fetch(`${s}/code/tree?${c}`,{signal:e});if(!l.ok)throw Error(`tree_request_failed`);let u=await l.json();if(e.throwIfAborted(),!Array.isArray(u.entries))throw Error(`invalid_tree_response`);for(let e of u.entries)t.set(e.path,e);if(o||=u.truncated===!0,a=u.nextCursor??null,!a)break;if(i.has(a)||t.size>=2e4){o=!0;break}i.add(a)}return{entries:[...t.values()].slice(0,2e4),partial:o||!!a}},[b,n,r,s])}),F=k.entries,I=(0,U.useRef)(f);(0,U.useEffect)(()=>{I.current=f},[f]),(0,U.useEffect)(()=>{if(!f)return;let e=`code-tree-${a}-${f}-${c??`primary`}`,t;return g(e,e=>{let n=e;n.projectId!==I.current||!Te(n.repositoryId,o)||n.type===`file.provenance_updated`&&(clearTimeout(t),t=setTimeout(()=>{A()},150))}),()=>{clearTimeout(t),y(e)}},[s,c,f,g,y,A,a]);let L=(0,U.useRef)(null),R=(0,U.useMemo)(()=>(F??[]).filter(e=>!Me(e.path,S)),[F,S]),z=(0,U.useCallback)(()=>{T(new Set((F??[]).filter(e=>e.kind===`dir`).map(e=>e.path)))},[F]),ne=Ce({count:R.length,getScrollElement:()=>L.current,estimateSize:()=>28,overscan:12,initialRect:{width:320,height:600},observeElementRect:(e,t)=>{let n=e.scrollElement;if(!n)return()=>{};let r=()=>{let e=n.getBoundingClientRect(),r=e.height||n.clientHeight||600;t({width:e.width||n.clientWidth||320,height:r})};if(r(),typeof ResizeObserver<`u`){let e=new ResizeObserver(r);return e.observe(n),()=>e.disconnect()}return()=>{}}}),re=(0,U.useId)(),[H,ie]=(0,U.useState)(t),ae=Math.max(0,R.findIndex(e=>e.path===H));(0,U.useEffect)(()=>{t&&(ie(t),T(e=>{let n=new Set(e),r=t.split(`/`);for(let e=1;e<r.length;e++)n.delete(r.slice(0,e).join(`/`));return n}))},[t]);let oe=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!t||oe.current===t)return;let e=R.findIndex(e=>e.path===t);e>=0&&(ne.scrollToIndex(e,{align:`auto`}),oe.current=t)},[t,R,ne]);let se=(t,n)=>{let r=R[n];if(!r)return;let i=n;switch(t.key){case`ArrowDown`:i=Math.min(R.length-1,n+1);break;case`ArrowUp`:i=Math.max(0,n-1);break;case`Home`:i=0;break;case`End`:i=R.length-1;break;case`ArrowRight`:r.kind===`dir`&&S.has(r.path)?E(r.path):r.kind===`dir`&&(i=Math.min(R.length-1,n+1));break;case`ArrowLeft`:if(r.kind===`dir`&&!S.has(r.path))E(r.path);else{let e=r.path.split(`/`).slice(0,-1).join(`/`),t=R.findIndex(t=>t.path===e);t>=0&&(i=t)}break;case`Enter`:case` `:r.kind===`dir`?E(r.path):e(r.path);break;default:return}t.preventDefault(),t.stopPropagation(),ie(R[i].path),i!==n&&ne.scrollToIndex(i,{align:`auto`})},W=R.length===0,G=(0,U.useMemo)(()=>(F??[]).filter(e=>e.kind===`file`).length,[F]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full`,"data-testid":`file-tree`,children:[(0,Q.jsxs)(`div`,{className:`px-2 py-2 border-b border-border text-xs space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`touched-by-ai`),className:M(`px-2 py-1 rounded-md transition-colors`,b===`touched-by-ai`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":b===`touched-by-ai`,children:i(n?`tree.jobFiles`:r?`tree.specFiles`:`tree.touchedByAi`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`all`),className:M(`px-2 py-1 rounded-md transition-colors`,b===`all`?`bg-accent-primary/20 text-accent-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),"aria-pressed":b===`all`,children:i(`tree.allFiles`)}),(0,Q.jsx)(`div`,{className:`flex-1`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{A()},disabled:N,"aria-label":i(`explore.refresh`),title:i(`explore.refresh`),className:`rounded p-1 text-muted-foreground hover:bg-muted disabled:opacity-40`,children:(0,Q.jsx)(V,{className:`h-3.5 w-3.5 ${N?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:z,title:i(`tree.collapseAll`),className:`px-1.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,"aria-label":i(`tree.collapseAll`),children:(0,Q.jsx)(w,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:D,title:i(`tree.expandAll`),className:`px-1.5 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,"aria-label":i(`tree.expandAll`),children:(0,Q.jsx)(C,{className:`w-3.5 h-3.5`})})]}),b===`touched-by-ai`&&G>0&&(0,Q.jsx)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:(0,Q.jsx)(`span`,{children:i(`tree.touchedCount`,{count:G})})})]}),P&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-1 border-b border-border p-3 text-xs`,children:[(0,Q.jsx)(`p`,{children:i(`tree.loadFailed`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{A()},className:`text-accent-primary underline`,children:i(`explore.retry`)})]}),k.partial&&(0,Q.jsx)(`p`,{role:`status`,className:`border-b border-border p-3 text-xs text-amber-600 dark:text-amber-400`,children:i(`tree.partial`)}),W&&P?null:W&&j?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center px-4 text-center`,"data-testid":`file-tree-loading`,children:(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground animate-pulse`,children:i(`tree.loadingFiles`)})}):W&&b===`touched-by-ai`?(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-4 text-center gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`tree.emptyTouched`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(`all`),className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:i(`tree.showAllFiles`)})]}):W?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-xs text-muted-foreground px-4 text-center`,children:i(`tree.noFiles`)}):(0,Q.jsx)(`div`,{ref:L,className:`min-h-0 flex-1 overflow-auto outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary/50`,"data-testid":`file-tree-scroller`,role:`tree`,tabIndex:0,"aria-label":i(`explore.files`),"aria-activedescendant":R[ae]?`${re}-${ae}`:void 0,onKeyDown:e=>{e.target===e.currentTarget&&se(e,ae)},children:(0,Q.jsx)(`div`,{style:{height:ne.getTotalSize(),position:`relative`,width:`100%`},children:ne.getVirtualItems().map(n=>{let r=R[n.index],a=Oe(r.path)*12,o=r.kind===`file`&&r.path===t,s=r.provenance?.createdByTicketId,c=r.provenance?.modifiedByTicketIds??[],u=r.provenance?.latest??null,d=Ae(u?.jobId),f=je(u?.kind),p=r.kind===`dir`,m=p&&S.has(r.path),g=r.provenance?.touchedFileCount??0;return(0,Q.jsxs)(`div`,{style:{position:`absolute`,top:0,left:0,transform:`translateY(${n.start}px)`,height:n.size,width:`100%`},className:M(`flex items-center gap-2 px-2 text-xs cursor-pointer hover:bg-muted/50`,o&&`bg-accent-primary/10 text-foreground`,r.path===H&&`ring-1 ring-inset ring-accent-primary/30`),onClick:()=>{ie(r.path),L.current?.focus({preventScroll:!0}),p?E(r.path):e(r.path)},onKeyDown:e=>{e.target===e.currentTarget&&se(e,n.index)},role:`treeitem`,id:`${re}-${n.index}`,tabIndex:-1,"aria-level":Oe(r.path)+1,"aria-selected":o,title:r.path,"aria-expanded":p?!m:void 0,"data-testid":`file-tree-row-${r.path}`,children:[(0,Q.jsxs)(`span`,{style:{paddingLeft:a},className:`flex items-center gap-1 min-w-0 flex-1`,children:[p?(0,Q.jsxs)(Q.Fragment,{children:[m?(0,Q.jsx)(w,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}):(0,Q.jsx)(C,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}),m?(0,Q.jsx)(te,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`}):(0,Q.jsx)(ee,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`w-3 flex-shrink-0`}),(0,Q.jsx)(B,{className:`w-3.5 h-3.5 text-muted-foreground flex-shrink-0`})]}),(0,Q.jsx)(`span`,{className:`truncate ml-0.5`,children:ke(r.path)})]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 flex-shrink-0`,children:[p&&g>0&&(0,Q.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/60 text-muted-foreground`,title:i(`tree.folderTouched`,{count:g}),children:g}),!p&&f&&(0,Q.jsx)(`span`,{className:M(`h-1.5 w-1.5 rounded-full`,u?.kind===`created`&&`bg-accent-success`,u?.kind===`modified`&&`bg-accent-info`,u?.kind===`deleted`&&`bg-destructive`),title:u?.kind===`created`?i(`tree.latestTitleCreated`):u?.kind===`deleted`?i(`tree.latestTitleDeleted`):i(`tree.latestTitleModified`),children:(0,Q.jsx)(`span`,{className:`sr-only`,children:i(`action.${f}`)})}),!p&&d&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center px-0.5 text-muted-foreground`,title:i(`tree.jobTitle`,{jobId:u?.jobId??``}),children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:d})]}),!p&&typeof s==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h(s)},className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,"data-testid":`provenance-chip-created-${s}`,title:i(`tree.createdBySpec`,{id:s}),children:[`#`,s]}),!p&&c.slice(0,2).map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),h(e)},className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,"data-testid":`provenance-chip-modified-${e}`,title:i(`tree.modifiedBySpec`,{id:e}),children:[`#`,e]},e))]})]},r.path)})})})]})}function Pe(e){return new Worker(`/assets/editor.worker-tytyn86m.js`,{name:e?.name})}function Fe(e){return new Worker(`/assets/json.worker-Oa9UrkKE.js`,{name:e?.name})}function Ie(e){return new Worker(`/assets/css.worker-yKcq13f2.js`,{name:e?.name})}function Le(e){return new Worker(`/assets/html.worker-DSJ9zmd7.js`,{name:e?.name})}function Re(e){return new Worker(`/assets/ts.worker-BtjBFNHX.js`,{name:e?.name})}var ze=!1;function Be(e){let t=e.trim().match(/^hsl\(\s*([-\d.]+)[\s,]+([\d.]+)%[\s,]+([\d.]+)%\s*\)$/i);return t?[parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3])]:null}function $(e,t=`#1e1e1e`){if(e.startsWith(`#`))return e;let n=Be(e);if(!n)return t;let[r,i,a]=n,o=i/100,s=a/100,c=(1-Math.abs(2*s-1))*o,l=(r%360+360)%360/60,u=c*(1-Math.abs(l%2-1)),d=0,f=0,p=0;l<1?(d=c,f=u):l<2?(d=u,f=c):l<3?(f=c,p=u):l<4?(f=u,p=c):l<5?(d=u,p=c):(d=c,p=u);let m=s-c/2,h=e=>Math.round((e+m)*255).toString(16).padStart(2,`0`);return`#${h(d)}${h(f)}${h(p)}`}function Ve(e){return`specrails-${e}`}function He(e,t){let n=Ve(t.id),r=t.xterm,i=$(r.background),a=$(r.foreground),o=$(r.brightBlack),s=$(r.magenta),c=$(r.yellow),l=$(r.cyan),u=$(r.blue),d=$(r.green),f=$(r.brightBlack),p=$(r.brightCyan),m=$(r.red),h=$(r.selectionBackground);return e.editor.defineTheme(n,{base:t.scheme===`light`?`vs`:`vs-dark`,inherit:!0,rules:[{token:``,foreground:a.slice(1)},{token:`comment`,foreground:f.slice(1),fontStyle:`italic`},{token:`keyword`,foreground:s.slice(1)},{token:`string`,foreground:c.slice(1)},{token:`number`,foreground:l.slice(1)},{token:`constant`,foreground:p.slice(1)},{token:`constant.numeric`,foreground:l.slice(1)},{token:`type`,foreground:d.slice(1)},{token:`type.identifier`,foreground:d.slice(1)},{token:`identifier`,foreground:a.slice(1)},{token:`function`,foreground:u.slice(1)},{token:`tag`,foreground:m.slice(1)},{token:`attribute.name`,foreground:p.slice(1)},{token:`attribute.value`,foreground:c.slice(1)},{token:`delimiter`,foreground:o.slice(1)},{token:`operator`,foreground:o.slice(1)}],colors:{"editor.background":i,"editor.foreground":a,"editorLineNumber.foreground":o,"editorLineNumber.activeForeground":a,"editorCursor.foreground":$(r.cursor),"editor.selectionBackground":h,"editor.inactiveSelectionBackground":h,"editor.lineHighlightBackground":$(r.black),"editor.lineHighlightBorder":$(r.black),"editorGutter.background":i,"editorWhitespace.foreground":o,"editorIndentGuide.background1":$(r.black),"editorIndentGuide.activeBackground1":o,"scrollbarSlider.background":`${o}55`,"scrollbarSlider.hoverBackground":`${o}88`,"scrollbarSlider.activeBackground":`${o}bb`,"minimap.background":i}}),n}function Ue(){ze||=(self.MonacoEnvironment={getWorker(e,t){switch(t){case`json`:return new Fe;case`css`:case`scss`:case`less`:return new Ie;case`html`:case`handlebars`:case`razor`:return new Le;case`typescript`:case`javascript`:return new Re;default:return new Pe}}},!0)}function We({content:e,language:t,initialLine:n}){let{t:r}=m(`code`),a=z(),o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(null),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(!1),[p,h]=(0,U.useState)(0),[g,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(``),b=(0,U.useRef)({content:e,language:t,theme:a,initialLine:n,wrap:g});b.current={content:e,language:t,theme:a,initialLine:n,wrap:g};let x=(e,t=!1)=>{let n=s.current,r=n?.getModel();if(!n||!r||!Number.isFinite(e)||e<1)return;let i=Math.min(r.getLineCount(),Math.max(1,Math.floor(e)));n.setSelection({startLineNumber:i,startColumn:1,endLineNumber:i,endColumn:r.getLineMaxColumn(i)}),n.revealLineInCenter(i),t&&n.focus()};return(0,U.useEffect)(()=>{let e=!1;return u(!1),f(!1),Ue(),i(()=>import(`./editor.main-DxrmGfoq.js`).then(t=>{if(e||!o.current)return;c.current=t;let n=b.current,r=t.editor.create(o.current,{value:n.content,language:n.language,readOnly:!0,domReadOnly:!0,theme:He(t,n.theme),minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,renderValidationDecorations:`off`,wordWrap:n.wrap?`on`:`off`,fontSize:13});s.current=r,x(n.initialLine),u(!0)}),__vite__mapDeps([0,1,2,3,4,5,6])).catch(()=>{e||f(!0)}),()=>{e=!0;let t=s.current?.getModel();s.current?.dispose(),t?.dispose(),s.current=null,c.current=null}},[p]),(0,U.useEffect)(()=>{let t=s.current;t&&t.getValue()!==e&&t.setValue(e)},[e]),(0,U.useEffect)(()=>{let e=s.current?.getModel();e&&c.current&&c.current.editor.setModelLanguage(e,t)},[t]),(0,U.useEffect)(()=>{let e=c.current;e&&e.editor.setTheme(He(e,a))},[a]),(0,U.useEffect)(()=>{x(n)},[n,l]),(0,U.useEffect)(()=>{s.current?.updateOptions({wordWrap:g?`on`:`off`})},[g]),(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border bg-muted/20 px-3 py-1 text-xs`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!l,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,onClick:()=>{s.current?.getAction(`actions.find`)?.run()},children:r(`reader.find`,{defaultValue:`Find in file`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!l,"aria-pressed":g,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,onClick:()=>_(e=>!e),children:r(`reader.wrap`,{defaultValue:`Wrap lines`})}),(0,Q.jsxs)(`form`,{className:`ml-auto flex items-center gap-1`,onSubmit:e=>{e.preventDefault(),x(Number(v),!0)},children:[(0,Q.jsx)(`input`,{type:`number`,min:1,step:1,"aria-label":r(`reader.line`,{defaultValue:`Line number`}),placeholder:`#`,title:r(`reader.line`,{defaultValue:`Line number`}),value:v,onChange:e=>y(e.target.value),className:`w-28 rounded border border-border bg-background px-2 py-1`}),(0,Q.jsx)(`button`,{type:`submit`,disabled:!l||!Number.isInteger(Number(v))||Number(v)<1,className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,children:r(`reader.go`,{defaultValue:`Go`})})]})]}),d?(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 text-sm text-muted-foreground`,"data-testid":`monaco-load-error`,children:[(0,Q.jsx)(`span`,{children:r(`monaco.loadFailed`)}),(0,Q.jsx)(`button`,{onClick:()=>h(e=>e+1),className:`rounded border px-3 py-1`,children:r(`reader.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[!l&&(0,Q.jsx)(`div`,{role:`status`,className:`absolute inset-0 flex items-center justify-center text-sm text-muted-foreground`,children:r(`reader.loading`,{defaultValue:`Loading source viewer…`})}),(0,Q.jsx)(`div`,{ref:o,className:`h-full w-full`,"data-testid":`monaco-host`})]})]})}function Ge(e,t){if(!e)return null;let n=Date.parse(e);if(Number.isNaN(n))return null;let r=Math.round((n-Date.now())/1e3),i=new Intl.RelativeTimeFormat(t,{numeric:`auto`}),a=Math.abs(r);return a<60?i.format(r,`second`):a<3600?i.format(Math.round(r/60),`minute`):a<86400?i.format(Math.round(r/3600),`hour`):i.format(Math.round(r/86400),`day`)}function Ke({path:e,summary:t,stale:n,regenerating:r,generateDisabledReason:i,onCollapse:a}){let{t:o,i18n:s}=m(`code`),{openTicketDetail:c}=d();if(!t)return(0,Q.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header-empty`,children:(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i?o(`summary.unavailable`,{reason:i}):o(`summary.empty`)})]}),a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})});let l=Ge(t.generatedAt,s.language),u=t.generatedBy?.model??t.model,f=t.generatedAt&&Number.isFinite(Date.parse(t.generatedAt))?new Date(t.generatedAt).toLocaleString(s.language):void 0,p=t.triggeredBy?.ticketId,h=t.triggeredBy?.modifiedTicketIds??[];return(0,Q.jsx)(`div`,{className:`border-b border-border px-4 py-3 bg-surface`,"data-testid":`summary-header`,children:(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:e}),n&&(0,Q.jsx)(`span`,{className:M(`text-[10px] px-1.5 py-0.5 rounded bg-accent-warning/20 text-accent-warning font-medium`),"data-testid":`summary-stale-badge`,children:o(`summary.stale`)}),r&&(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-accent-primary animate-pulse`,"aria-hidden":!0})]}),(0,Q.jsx)(`p`,{className:`text-sm text-foreground mt-1 whitespace-pre-wrap break-words`,children:t.summary}),t.generatedBy?.truncated&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-accent-warning`,children:o(`reader.summaryPartial`,{defaultValue:`Generated from a partial source snapshot. This summary may not cover the entire file.`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 flex-wrap`,children:[u&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:o(`story.explainedBy`,{model:u})}),typeof p==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(p),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,children:[`#`,p]}),h.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,children:[`#`,e]},e)),l&&(0,Q.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:t.generatedAt,title:f,children:l})]})]}),a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})})}function qe({content:e}){return(0,Q.jsx)(N,{remarkPlugins:[P],children:e})}var Je=2e3,Ye=256e3;function Xe({path:e,jobId:t}){let{activeProjectId:n}=v(),r=Z(),i=JSON.stringify([n,r.apiBase,r.repositoryPath,e,t]);return(0,Q.jsx)(Ze,{path:e,jobId:t},i)}function Ze({path:e,jobId:t}){let{t:n}=m(`code`),{apiBase:r}=Z(),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(`loading`),[c,l]=(0,U.useState)(0);(0,U.useEffect)(()=>{let n=new AbortController;s(`loading`);let i=new URLSearchParams({path:e,jobId:t});return fetch(`${r}/code/diff?${i}`,{signal:n.signal}).then(async e=>{if(e.status===404){n.signal.aborted||s(`missing`);return}if(!e.ok)throw Error(`Diff request failed`);let t=await e.json();if(typeof t.patch!=`string`)throw Error(`Invalid patch response`);n.signal.aborted||(a({patch:t.patch,truncated:t.truncated===!0}),s(t.patch?`ready`:`missing`))}).catch(()=>{n.signal.aborted||s(`failed`)}),()=>n.abort()},[r,e,t,c]);let u=(i?.patch??``).slice(0,Ye).split(`
3
- `),d=u.length>Je||(i?.patch.length??0)>Ye,f=null,p=null;return(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-col gap-2 text-xs`,"data-testid":`recorded-diff`,children:[(0,Q.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 px-3 py-2`,children:[(0,Q.jsxs)(`p`,{className:`font-medium`,children:[n(`reader.recordedChange`,{defaultValue:`Recorded change`}),` · `,(0,Q.jsx)(`span`,{className:`font-mono`,title:t,children:t.slice(0,12)})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:n(`reader.recordedNotice`,{defaultValue:`This patch records a past run. It may differ from the current registered checkout.`})})]}),o===`loading`&&(0,Q.jsx)(`p`,{role:`status`,children:n(`history.loadingDiff`)}),o===`missing`&&(0,Q.jsx)(`p`,{children:n(`history.diffUnavailable`)}),o===`failed`&&(0,Q.jsxs)(`div`,{role:`alert`,children:[(0,Q.jsx)(`p`,{children:n(`reader.diffFailed`,{defaultValue:`Could not load the recorded change.`})}),(0,Q.jsx)(`button`,{className:`mt-2 rounded border px-2 py-1`,onClick:()=>l(e=>e+1),children:n(`reader.retry`,{defaultValue:`Retry`})})]}),o===`ready`&&i&&(0,Q.jsxs)(Q.Fragment,{children:[i.truncated&&(0,Q.jsx)(`p`,{className:`text-accent-warning`,children:n(`reader.patchIncomplete`,{defaultValue:`The stored patch is incomplete. Missing content cannot be reconstructed from this record.`})}),d&&(0,Q.jsx)(`p`,{className:`text-accent-warning`,children:n(`reader.displayLimited`,{defaultValue:`Preview limited to {{count}} lines or {{chars}} characters. The remaining patch is not shown.`,count:Je,chars:Ye})}),(0,Q.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border bg-background font-mono text-[11px] leading-5`,tabIndex:0,"aria-label":n(`reader.patch`,{defaultValue:`Recorded patch`}),children:u.slice(0,Je).map((e,t)=>{let n=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e),r=null,i=null,a=`meta`;return n?(f=Number(n[1]),p=Number(n[2])):f!==null&&p!==null&&(e.startsWith(`+`)?(a=`added`,i=p++):e.startsWith(`-`)?(a=`removed`,r=f++):e.startsWith(` `)&&(a=`context`,r=f++,i=p++)),(0,Q.jsxs)(`div`,{"data-kind":a,className:`flex min-w-max ${a===`added`?`bg-accent-success/10`:a===`removed`?`bg-destructive/10`:a===`meta`?`text-muted-foreground`:``}`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`w-12 shrink-0 select-none border-r border-border/40 px-2 text-right text-muted-foreground`,children:r}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`w-12 shrink-0 select-none border-r border-border/40 px-2 text-right text-muted-foreground`,children:i}),(0,Q.jsx)(`code`,{className:`whitespace-pre px-3`,children:e||` `})]},t)})})]})]})}var Qe={done:`bg-accent-success/15 text-accent-success`,in_progress:`bg-accent-info/15 text-accent-info`,on_review:`bg-accent-warning/15 text-accent-warning`,todo:`bg-muted/60 text-muted-foreground`,draft:`bg-accent-secondary/15 text-accent-secondary`};function $e(e){return e===`created`?s:e===`deleted`?c:T}function et(e){let t=Z(),{activeProjectId:n}=v(),r=JSON.stringify([n,t.apiBase,t.repositoryPath,e.relPath]);return(0,Q.jsx)(tt,{...e},r)}function tt({relPath:e,height:t,onOpenTicket:n,onFilterJob:r,onViewDiff:i}){let{t:a}=m(`code`),o=Z(),{apiBase:s,repositoryId:c}=o,{activeProjectId:l,projects:u}=v(),d=u.find(e=>e.id===l)?.provider,f=L(d),{registerHandler:h,unregisterHandler:g}=p(),_=(0,U.useId)(),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(!1),w=(0,U.useRef)(!0),T=(0,U.useRef)(null),E=(0,U.useRef)(new Map);(0,U.useEffect)(()=>(w.current=!0,()=>{w.current=!1,T.current?.abort();for(let e of E.current.values())e.abort();E.current.clear()}),[]);let[D,O]=(0,U.useState)({}),k=(0,U.useRef)(l);(0,U.useEffect)(()=>{k.current=l},[l]);let A=(0,U.useRef)(e);(0,U.useEffect)(()=>{A.current=e},[e]);let j=(0,U.useRef)(0),M=(0,U.useCallback)(async()=>{if(!w.current)return;let t=++j.current;T.current?.abort();let n=new AbortController;T.current=n;try{let r=await fetch(`${s}/code/file/story?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!w.current||n.signal.aborted||t!==j.current)return;if(!r.ok){x([]),C(!0);return}let i=await r.json();if(!w.current||n.signal.aborted||t!==j.current)return;x(Array.isArray(i.story)?i.story:[]),C(!1)}catch{w.current&&!n.signal.aborted&&t===j.current&&(x([]),C(!0))}},[e,l,s]);(0,U.useEffect)(()=>{x(null),O({}),M()},[M]),(0,U.useEffect)(()=>{if(!l)return;let e=`code-story-${l}-${c??`primary`}-${_}`;return h(e,e=>{let t=e;t.projectId!==k.current||!Te(t.repositoryId,o)||t.path===A.current&&(t.type===`file.story_updated`||t.type===`file.provenance_updated`)&&M()}),()=>g(e)},[_,s,c,l,h,g,M]);let N=(0,U.useCallback)(async(t,n)=>{if(!f||!w.current||!t.hasPatch||t.evidence?.kind===`missing`||E.current.has(t.provenanceId))return;let r=new AbortController;E.current.set(t.provenanceId,r),O(e=>({...e,[t.provenanceId]:`busy`}));try{let i=await fetch(`${s}/code/file/story/explain?path=${encodeURIComponent(e)}`,{method:`POST`,signal:r.signal,headers:{"content-type":`application/json`},body:JSON.stringify({provenanceId:t.provenanceId,overrideBudget:n,...t.summaryStale?{force:!0}:{}})}),o=await i.json().catch(()=>({}));if(!w.current||r.signal.aborted)return;if(o.skipped===`budget`){O(e=>({...e,[t.provenanceId]:`budget`}));return}if(!i.ok||!o.ok){y.error(a(`story.explainFailed`)),O(e=>{let n={...e};return delete n[t.provenanceId],n});return}if(await M(),!w.current||r.signal.aborted)return;O(e=>{let n={...e};return delete n[t.provenanceId],n})}catch{if(!w.current||r.signal.aborted)return;y.error(a(`story.explainFailed`)),O(e=>{let n={...e};return delete n[t.provenanceId],n})}finally{E.current.delete(t.provenanceId)}},[f,M,e,a]);return(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border bg-card/40 px-4 py-3 overflow-hidden`,style:{height:t},"data-testid":`construction-story`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:b===null?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground animate-pulse py-2`,children:a(`story.loading`)}):S?(0,Q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-failed`,role:`alert`,children:[a(`story.loadFailed`),` `,(0,Q.jsx)(`button`,{className:`ml-2 underline`,onClick:()=>{M()},children:a(`reader.retry`,{defaultValue:`Retry`})})]}):b.length===0?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground py-2`,"data-testid":`story-empty`,children:a(`story.empty`)}):(0,Q.jsx)(`ol`,{className:`relative ml-1.5 border-l border-border/60 space-y-3 py-1`,children:b.map(t=>(0,Q.jsx)(nt,{entry:t,state:D[t.provenanceId],canExplain:f&&t.hasPatch&&t.evidence?.kind!==`missing`,path:e,onViewDiff:i,onOpenTicket:n,onFilterJob:r,onExplain:e=>{N(t,e)}},t.provenanceId))})})})}function nt({entry:e,state:t,canExplain:n,path:r,onViewDiff:i,onOpenTicket:a,onFilterJob:o,onExplain:s}){let{t:c}=m(`code`),[l,u]=(0,U.useState)(!1),d=$e(e.kind),f=e.ticket?.status??null,p=e.ticket?.title?`#${e.ticket.id} · ${e.ticket.title}`:e.ticketId==null?null:c(`story.spec`,{ticketId:e.ticketId}),h=e.ticketId==null?`${e.kind}NoSpec`:e.kind;return(0,Q.jsxs)(`li`,{className:`relative pl-4`,"data-testid":`story-card`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`absolute -left-[5px] top-2 h-2.5 w-2.5 rounded-full border-2 border-background ${e.kind===`created`?`bg-accent-success`:e.kind===`deleted`?`bg-destructive`:`bg-accent-info`}`}),(0,Q.jsxs)(`article`,{className:`rounded-lg border border-border/60 bg-card/60 px-3 py-2.5 backdrop-blur-sm transition-colors hover:border-border`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(d,{className:`h-3.5 w-3.5 shrink-0`}),c(`story.kindLabel.${e.kind}`)]}),p!=null&&e.ticketId!=null&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(e.ticketId),className:`min-w-0 max-w-full truncate rounded bg-accent-primary/15 px-1.5 py-0.5 text-left text-[11px] font-medium text-accent-primary hover:bg-accent-primary/25`,title:c(`story.openSpec`,{ticketId:e.ticketId}),children:p}),p==null&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:c(`story.unknownSpec`)}),f&&(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] ${Qe[f]??`bg-muted/60 text-muted-foreground`}`,"data-testid":`story-status-pill`,children:f}),(0,Q.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-2`,children:[e.addedLines!=null&&e.addedLines>0&&(0,Q.jsxs)(`span`,{className:`font-mono text-[10px] text-accent-success`,title:c(`story.linesAdded`),children:[`+`,e.addedLines]}),e.removedLines!=null&&e.removedLines>0&&(0,Q.jsxs)(`span`,{className:`font-mono text-[10px] text-destructive`,title:c(`story.linesRemoved`),children:[`−`,e.removedLines]}),(0,Q.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]})]}),(0,Q.jsx)(`div`,{className:`mt-1.5`,children:e.summary?(0,Q.jsxs)(Q.Fragment,{children:[e.summaryStale&&(0,Q.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:c(`summary.stale`)}),(0,Q.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground/90`,"data-testid":`story-contribution`,children:e.summary}),e.summaryGeneratedAt&&(0,Q.jsx)(`time`,{className:`mt-1 block text-[10px] text-muted-foreground`,dateTime:e.summaryGeneratedAt,children:new Date(e.summaryGeneratedAt).toLocaleString()}),e.summaryStale&&n&&(t===`budget`?(0,Q.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-2 text-[11px] text-accent-warning`,children:[(0,Q.jsx)(`span`,{children:c(`story.budgetReached`)}),(0,Q.jsx)(`button`,{className:`rounded border px-2 py-1`,onClick:()=>s(!0),children:c(`story.generateAnyway`)})]}):(0,Q.jsx)(`button`,{disabled:t===`busy`,className:`mt-1 rounded border px-2 py-1 text-[11px]`,onClick:()=>s(!1),children:t===`busy`?c(`story.explaining`):c(`reader.regenerateExplanation`,{defaultValue:`Refresh explanation`})})),e.summaryModel&&(0,Q.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:c(`story.explainedBy`,{model:e.summaryModel})})]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`story-fallback`,children:c(`story.fallback.${h}`)}),n?t===`budget`?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:c(`story.budgetReached`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`rounded bg-accent-warning/15 px-1.5 py-0.5 text-[10px] text-accent-warning hover:bg-accent-warning/25`,children:c(`story.generateAnyway`)})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!1),disabled:t===`busy`,className:`inline-flex items-center gap-1 rounded bg-accent-primary/10 px-1.5 py-0.5 text-[10px] text-accent-primary hover:bg-accent-primary/20 disabled:opacity-60`,"data-testid":`story-explain`,children:[(0,Q.jsx)(O,{className:t===`busy`?`h-3 w-3 animate-pulse`:`h-3 w-3`}),c(t===`busy`?`story.explaining`:`story.explain`)]}):(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,"data-testid":`story-explain-unavailable`,children:!e.hasPatch||e.evidence?.kind===`missing`?c(`reader.noEvidence`,{defaultValue:`No patch evidence was stored for this change.`}):c(`story.explainUnavailable`)})]})}),e.summary&&(!e.hasPatch||e.evidence?.kind===`missing`)&&(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-accent-warning`,children:c(`reader.noEvidence`,{defaultValue:`No patch evidence was stored for this change.`})}),(e.summaryEvidence?.truncated??e.evidence?.truncated)&&(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-accent-warning`,children:c(`reader.excerptEvidence`,{defaultValue:`This explanation uses incomplete patch evidence.`})}),e.jobId&&(0,Q.jsxs)(`div`,{className:`mt-2`,children:[(0,Q.jsx)(`button`,{className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>{i?i(e.jobId):u(e=>!e)},children:c(`reader.viewPatch`,{defaultValue:`View recorded change`})}),l&&(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(Xe,{path:r,jobId:e.jobId})})]}),e.jobId&&o&&(0,Q.jsx)(`footer`,{className:`mt-1.5`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(e.jobId),className:`font-mono text-[10px] text-muted-foreground hover:text-foreground`,title:c(`history.filterByJob`,{jobId:e.jobId}),children:e.jobId.length>12?e.jobId.slice(0,12):e.jobId})})]})]})}function rt(e,t){return t===`markdown`||t===`md`||/\.(md|mdx|markdown)$/i.test(e)}var it=180,at=120,ot=240;function st(e){return e?`specrails-desktop:code-summary-collapsed:${e}`:null}function ct(e){return e?`specrails-desktop:code-history-height:${e}`:null}function lt(e){return e?`specrails-desktop:code-history-collapsed:${e}`:null}function ut(e){return e?`specrails-desktop:code-history-mode:${e}`:null}function dt(e){let t=ut(e);if(!t)return`story`;try{return localStorage.getItem(t)===`log`?`log`:`story`}catch{return`story`}}function ft(e,t){let n=ut(e);if(n)try{localStorage.setItem(n,t)}catch{}}function pt(e){let t=ct(e);if(!t)return it;try{let e=localStorage.getItem(t),n=e?Number(e):NaN;return Number.isFinite(n)&&n>0?n:it}catch{return it}}function mt(e,t){let n=ct(e);if(n)try{localStorage.setItem(n,String(Math.round(t)))}catch{}}function ht(e){let t=st(e);if(!t)return!1;try{return localStorage.getItem(t)===`true`}catch{return!1}}function gt(e,t){let n=st(e);if(n)try{localStorage.setItem(n,t?`true`:`false`)}catch{}}function _t(e,t=!1){let n=lt(e);if(!n)return t;let r=t?n+`:compact`:n;try{let e=localStorage.getItem(r);return e===null?t:e===`true`}catch{return t}}function vt(e,t,n=!1){let r=lt(e),i=r&&n?r+`:compact`:r;if(i)try{localStorage.setItem(i,t?`true`:`false`)}catch{}}function yt(e,t){let n=Math.max(at,t-ot);return Math.min(Math.max(e,at),n)}function bt(e){let{activeProjectId:t}=v(),n=Z(),r=JSON.stringify([t,n.apiBase,n.repositoryId,n.repositoryPath,e.relPath,e.initialJobId]);return(0,Q.jsx)(xt,{...e},r)}function xt({relPath:e,initialLine:t,initialJobId:n,compact:r=!1,onFilterJob:i,onSummaryActionChange:a,onCopyPathActionChange:o}){let{t:s}=m(`code`),c=Z(),{apiBase:l,repositoryId:u}=c,{activeProjectId:f,projects:h}=v(),g=h.find(e=>e.id===f)?.provider,_=L(g),{openTicketDetail:b}=d(),{registerHandler:x,unregisterHandler:w}=p(),T=(0,U.useId)(),E=A({allowMove:!1}),D=(0,U.useRef)(null),[O,k]=(0,U.useState)(null),[M,N]=(0,U.useState)(!1),P=(0,U.useRef)(!0),F=(0,U.useRef)(null),I=(0,U.useRef)(new Set);(0,U.useEffect)(()=>(P.current=!0,()=>{P.current=!1,F.current?.abort();for(let e of I.current)e.abort();I.current.clear()}),[]);let[R,ee]=(0,U.useState)(n??null),[z,B]=(0,U.useState)(n?`recorded`:`source`);(0,U.useEffect)(()=>{ee(n??null),B(n?`recorded`:`source`)},[n]),(0,U.useEffect)(()=>{t&&!n&&B(`source`)},[t,n]);let te=(0,U.useCallback)(e=>{ee(e),B(`recorded`)},[]),[V,ne]=(0,U.useState)(!0),[re,H]=(0,U.useState)(!1),[ie,ae]=(0,U.useState)(!1),[oe,W]=(0,U.useState)(()=>ht(f)),[G,K]=(0,U.useState)(()=>pt(f)),[q,ce]=(0,U.useState)(()=>_t(f,r)),[J,le]=(0,U.useState)(()=>dt(f)),ue=(0,U.useRef)(f);(0,U.useEffect)(()=>{ue.current=f},[f]);let de=(0,U.useRef)(e);(0,U.useEffect)(()=>{de.current=e},[e]),(0,U.useEffect)(()=>{let e=D.current?.clientHeight||window.innerHeight;W(ht(f)),K(yt(pt(f),e)),ce(_t(f,r)),le(dt(f))},[f,r]);let fe=(0,U.useCallback)(e=>{let t=e.clientY,n=G,r=D.current?.clientHeight||window.innerHeight,i=e.currentTarget;try{i.setPointerCapture(e.pointerId)}catch{}function a(e){K(yt(n+(t-e.clientY),r))}function o(){window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),K(e=>{let t=yt(e,r);return mt(f,t),t})}window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o)},[f,G]),pe=(0,U.useCallback)(()=>{let e=yt(it,D.current?.clientHeight||window.innerHeight);K(e),mt(f,e)},[f]),me=(0,U.useCallback)(()=>{W(e=>{let t=!e;return gt(f,t),t})},[f]),Y=(0,U.useCallback)(()=>{ce(e=>{let t=!e;return vt(f,t,r),t})},[f,r]),he=(0,U.useCallback)(e=>{le(e),ft(f,e)},[f]);(0,U.useEffect)(()=>{xe(t?`raw`:`preview`)},[e,t]);let ge=(0,U.useRef)(0),X=(0,U.useCallback)(async()=>{if(!P.current)return;let t=++ge.current;F.current?.abort();let n=new AbortController;F.current=n,ne(!0),N(!1);try{let r=await fetch(`${l}/code/file?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!P.current||n.signal.aborted||t!==ge.current)return;if(!r.ok){N(!0);return}let i=await r.json();if(!P.current||n.signal.aborted||t!==ge.current)return;k(i)}catch{P.current&&!n.signal.aborted&&t===ge.current&&N(!0)}finally{P.current&&!n.signal.aborted&&t===ge.current&&ne(!1)}},[e,f,l]);(0,U.useEffect)(()=>{X()},[X]),(0,U.useEffect)(()=>{let e=()=>{X()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[X]),(0,U.useEffect)(()=>{if(!f)return;let e=`code-file-${f}-${u??`primary`}-${T}`;return x(e,e=>{let t=e;t.projectId!==ue.current||!Te(t.repositoryId,c)||((t.type===`file.summary_updated`||t.type===`file.provenance_updated`||t.type===`file.content_updated`)&&t.path===de.current?(t.type===`file.summary_updated`&&H(!1),X()):t.type===`file.summary_failed`&&t.path===de.current?(y.error(t.reason??s(`summary.generationFailed`)),H(!1)):t.type===`file.summary_skipped`&&t.path===de.current&&(t.reason&&y(s(`summary.skipped`,{reason:t.reason})),H(!1)))}),()=>w(e)},[T,l,u,f,x,w,X,s]);let _e=(0,U.useCallback)(async t=>{if(!_||!P.current||I.current.size>0)return;let n=new AbortController;I.current.add(n),H(!0);try{let r=await fetch(`${l}/code/file/regenerate-summary?path=${encodeURIComponent(e)}`,{method:`POST`,signal:n.signal,headers:{"content-type":`application/json`},body:JSON.stringify({overrideBudget:t})}),i=await r.json().catch(()=>({}));if(!P.current||n.signal.aborted)return;if(!r.ok){H(!1);let e=typeof i.skipped==`string`?i.skipped:null;y.error(e?s(`summary.skipped`,{reason:e}):s(`summary.generationFailed`));return}if(i.skipped===`budget`){H(!1),ae(!0);return}if(i.skipped){H(!1),y(s(`summary.skipped`,{reason:i.skipped}));return}await X(),P.current&&!n.signal.aborted&&H(!1)}catch{P.current&&!n.signal.aborted&&(H(!1),y.error(s(`summary.generationFailed`)))}finally{I.current.delete(n)}},[_,X,e,s]),ve=(0,U.useCallback)(async()=>{let t=O?.absolutePath??e;try{if(!navigator.clipboard?.writeText)throw Error(`Clipboard unavailable`);await navigator.clipboard.writeText(t),y.success(s(`viewer.pathCopied`))}catch{y.error(s(`viewer.copyPathFailed`))}},[O,e,s]),ye=(0,U.useMemo)(()=>rt(e,O?.language),[e,O?.language]),[be,xe]=(0,U.useState)(t?`raw`:`preview`),Se=O?.summary??null,Ce=!!O?.summaryStale,we=O?.provenance??[],Ee=O?.reason===`not-found`,De=O?_?Ee?s(`summary.reason.missing`):O?.binary?s(`summary.reason.binary`):O?.tooLarge?s(`summary.reason.tooLarge`):null:s(`summary.reason.providerNoPureOutput`):s(`reader.sourceUnavailable`,{defaultValue:`source unavailable`});return(0,U.useEffect)(()=>{if(a){if(z===`recorded`||V&&!O){a(null);return}return a({hasSummary:!!Se,regenerating:re,disabledReason:De,onClick:()=>_e(!1)}),()=>a(null)}},[O,_e,V,a,re,Se,De,z]),(0,U.useEffect)(()=>{if(o){if(V&&!O){o(null);return}return o({onClick:ve}),()=>o(null)}},[ve,O,V,o]),z===`source`&&V&&!O?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground animate-pulse`,children:s(`viewer.loadingFile`)}):(0,Q.jsxs)(`div`,{ref:D,className:`flex flex-col h-full`,"data-testid":`file-viewer`,children:[z===`source`&&(oe?(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center justify-between border-b border-border bg-surface px-4`,"data-testid":`summary-header-collapsed`,children:[(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e}),(0,Q.jsxs)(`button`,{type:`button`,onClick:me,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}),s(`viewer.showSummary`)]})]}):(0,Q.jsx)(Ke,{path:e,summary:Se,stale:Ce,regenerating:re,generateDisabledReason:De,onCollapse:me})),(0,Q.jsxs)(`div`,{className:`px-4 py-1 border-b border-border flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,Q.jsx)(`button`,{"aria-pressed":z===`source`,onClick:()=>B(`source`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:s(`reader.currentFile`,{defaultValue:`Current file`})}),R&&(0,Q.jsx)(`button`,{"aria-pressed":z===`recorded`,onClick:()=>B(`recorded`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:s(`reader.recordedChange`,{defaultValue:`Recorded change`})}),z===`source`&&ye&&O?.content!==void 0&&!O.binary&&!O.tooLarge&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,role:`group`,"aria-label":s(`viewer.markdownViewMode`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xe(`preview`),"aria-pressed":be===`preview`,className:be===`preview`?`px-2 py-1 rounded-md bg-accent-primary/20 text-accent-primary`:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:s(`viewer.preview`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xe(`raw`),"aria-pressed":be===`raw`,className:be===`raw`?`px-2 py-1 rounded-md bg-accent-primary/20 text-accent-primary`:`px-2 py-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:s(`viewer.raw`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[O?.language&&(0,Q.jsx)(`span`,{children:O.language}),typeof O?.sizeBytes==`number`&&(0,Q.jsxs)(`span`,{children:[(O.sizeBytes/1024).toFixed(1),` KB`]}),(0,Q.jsx)(`button`,{disabled:V,onClick:()=>{X()},className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,children:s(`reader.refresh`,{defaultValue:`Refresh source`})})]})]}),M&&(0,Q.jsxs)(`div`,{role:`alert`,className:`border-b border-border px-4 py-2 text-xs`,children:[s(`reader.sourceFailed`,{defaultValue:`Could not refresh the current file. Any displayed source is the last successful read.`}),(0,Q.jsx)(`button`,{className:`ml-2 underline`,onClick:()=>{X()},children:s(`reader.retry`,{defaultValue:`Retry`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:z===`recorded`&&R?(0,Q.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,Q.jsx)(Xe,{path:e,jobId:R})}):Ee?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-missing`,children:s(`viewer.missingFile`)}):O?.binary?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-binary`,children:s(`viewer.binaryFile`)}):O?.tooLarge?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-too-large`,children:s(`viewer.tooLarge`,{size:Math.round((O.sizeBytes??0)/1024/1024)})}):O?.content===void 0?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,children:s(`viewer.noContent`)}):ye&&be===`preview`?(0,Q.jsx)(`div`,{className:`h-full overflow-auto px-6 py-4 prose prose-invert prose-sm max-w-none prose-p:my-2 prose-headings:mt-4 prose-headings:mb-2 prose-pre:bg-muted/40 prose-pre:rounded-md prose-code:before:content-none prose-code:after:content-none`,"data-testid":`markdown-preview`,children:(0,Q.jsx)(qe,{content:O.content})}):(0,Q.jsx)(We,{content:O.content,language:O.language??`plaintext`,initialLine:t})}),we.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":s(`history.resize`),onPointerDown:q?void 0:fe,onDoubleClick:q?void 0:pe,className:q?`flex h-8 shrink-0 items-center justify-between border-t border-border bg-card/35 px-4`:`flex h-8 shrink-0 cursor-row-resize items-center justify-between border-y border-border/40 bg-card/35 px-4 hover:bg-accent-primary/10`,title:q?void 0:s(`resizer.hint`),"data-testid":`code-history-resizer`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground`,children:s(J===`story`?`story.title`:`history.title`,{count:we.length})}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[!q&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-md bg-muted/40 p-0.5`,role:`group`,"aria-label":s(`story.viewMode`),onPointerDown:e=>e.stopPropagation(),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`story`),"aria-pressed":J===`story`,className:J===`story`?`rounded px-2 py-0.5 text-[10px] bg-accent-primary/20 text-accent-primary`:`rounded px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground`,children:s(`story.modeStory`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`log`),"aria-pressed":J===`log`,className:J===`log`?`rounded px-2 py-0.5 text-[10px] bg-accent-primary/20 text-accent-primary`:`rounded px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground`,children:s(`story.modeLog`)})]}),(0,Q.jsxs)(`button`,{type:`button`,onPointerDown:e=>e.stopPropagation(),onClick:Y,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[q?(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}),s(q?`history.show`:`history.hide`)]})]})]}),!q&&(J===`story`?(0,Q.jsx)(et,{relPath:e,height:G,onOpenTicket:b,onFilterJob:i,onViewDiff:te}):(0,Q.jsx)(St,{rows:we,onOpenTicket:b,onFilterJob:i,height:G}))]}),ie&&(0,se.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,role:`dialog`,"aria-modal":`true`,"data-testid":`budget-prompt`,onClick:E.guardBackdrop(()=>ae(!1)),children:[(0,Q.jsxs)(`div`,{ref:E.panelRef,onClick:e=>e.stopPropagation(),className:`bg-card border border-border rounded-lg p-4 w-80 flex flex-col gap-3`,style:E.panelStyle,children:[(0,Q.jsx)(`p`,{className:`text-sm text-foreground`,children:s(`viewer.budgetPrompt`)}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ae(!1),className:`text-xs px-3 py-1.5 rounded-md text-muted-foreground hover:text-foreground`,children:s(`common:actions.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{ae(!1),_e(!0)},className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white`,children:s(`common:actions.confirm`)})]})]}),(0,Q.jsx)(j,{handles:E.resizeHandles})]}),document.body)]})}function St({rows:e,onOpenTicket:t,onFilterJob:n,height:r}){let{t:i}=m(`code`),[a,o]=(0,U.useState)(null);if(e.length===0)return null;function u(e,t){o(e=>e===t?null:t)}return(0,Q.jsx)(`div`,{className:`shrink-0 border-t border-border bg-card/40 px-4 py-3 overflow-hidden`,style:{height:r},"data-testid":`file-provenance-timeline`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto space-y-1`,children:e.map((e,r)=>{let o=e.kind===`created`?s:e.kind===`deleted`?c:T,d=e.jobId?e.jobId.length>12?e.jobId.slice(0,12):e.jobId:i(`history.unknownJob`),f=`${e.jobId??`job`}:${e.path}:${e.at}:${r}`;return(0,Q.jsxs)(`div`,{className:`rounded-md hover:bg-muted/40`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(72px,auto)_minmax(0,1fr)_auto] items-center gap-2 text-xs px-2 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0`,children:[(0,Q.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Q.jsx)(`span`,{className:`capitalize`,children:i(`kind.${e.kind}`)})]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 min-w-0 text-muted-foreground`,children:[(0,Q.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}),e.jobId&&n?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(e.jobId),className:`font-mono truncate hover:text-foreground`,title:i(`history.filterByJob`,{jobId:e.jobId}),children:d}):(0,Q.jsx)(`span`,{className:`font-mono truncate`,title:e.jobId??void 0,children:d}),e.jobId&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>u(e,f),className:`shrink-0 rounded bg-muted/60 px-1.5 py-0.5 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:i(`history.diff`)}),typeof e.ticketId==`number`&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.ticketId),className:`shrink-0 rounded bg-accent-primary/15 px-1.5 py-0.5 text-[10px] text-accent-primary hover:bg-accent-primary/25`,title:i(`history.openSpec`,{ticketId:e.ticketId}),children:i(`history.specChip`,{ticketId:e.ticketId})})]}),(0,Q.jsx)(`time`,{className:`text-[11px] text-muted-foreground`,dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]}),a===f&&(0,Q.jsx)(`div`,{className:`px-2 pb-2`,children:e.jobId&&(0,Q.jsx)(Xe,{path:e.path,jobId:e.jobId})})]},f)})})})}function Ct({projectId:e,repositoryName:t,multipleRepositories:n,active:r=!0,onOpen:i}){let{t:a}=m(`code`),{apiBase:o,repositoryId:s,repositoryPath:c}=Z(),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(`find`),[p,h]=(0,U.useState)(n),[g,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(``),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(!1),[O,k]=(0,U.useState)(0),A=n&&p,j=A?F(e):o,M=A?void 0:s,N=A?void 0:t,P=A?void 0:c,I=(0,U.useRef)(0),L=(0,U.useRef)(null);return(0,U.useEffect)(()=>{r&&L.current?.focus()},[r]),(0,U.useEffect)(()=>{let e=++I.current,t=new AbortController;x(null),T(!1);let n=l.trim();if(!n)return C(!1),()=>t.abort();C(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({q:n,limit:d===`find`?`50`:`100`});d===`search`&&r.set(`caseSensitive`,String(g)),d===`search`&&v.trim()&&r.set(`path`,v.trim()),A&&r.set(`kind`,d);let i=await fetch(`${j}/code/${A?`discover`:d}?${r}`,{signal:t.signal});if(!i.ok)throw Error(`search_failed`);let a=await i.json();if(!Array.isArray(a.matches))throw Error(`invalid_search_response`);!t.signal.aborted&&e===I.current&&x({...a,matches:a.matches.map(e=>({...e,repositoryId:e.repositoryId??M,repositoryName:e.repositoryName??N}))})}catch{!t.signal.aborted&&e===I.current&&T(!0)}finally{!t.signal.aborted&&e===I.current&&C(!1)}},250);return()=>{clearTimeout(r),t.abort()}},[l,d,g,v,O,A,j,M,N,P]),(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col`,"aria-label":a(`explore.search`),children:[(0,Q.jsxs)(`div`,{className:`space-y-2 border-b border-border p-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted/40 p-1`,children:[`find`,`search`].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":d===e,onClick:()=>f(e),className:`flex-1 rounded-md px-2 py-1.5 text-xs ${d===e?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:a(`search.${e}`)},e))}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(D,{className:`pointer-events-none absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`input`,{ref:L,value:l,onChange:e=>u(e.target.value),maxLength:256,"aria-label":a(`search.query`),placeholder:a(d===`find`?`search.filePlaceholder`:`search.contentPlaceholder`),className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-2 text-xs outline-none focus:border-accent-primary`})]}),n&&(0,Q.jsxs)(`select`,{"aria-label":a(`search.scope`),value:p?`all`:`current`,onChange:e=>h(e.target.value===`all`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`all`,children:a(`search.allRepositories`)}),(0,Q.jsx)(`option`,{value:`current`,children:t??a(`search.currentRepository`)})]}),d===`search`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:a(`search.pathPlaceholder`),"aria-label":a(`search.withinPath`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs outline-none focus:border-accent-primary`}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked)}),a(`search.caseSensitive`)]})]})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,"aria-busy":S,children:[!l.trim()&&(0,Q.jsxs)(`div`,{className:`space-y-2 px-5 py-8 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(ne,{className:`mx-auto h-7 w-7 opacity-50`}),(0,Q.jsx)(`p`,{children:a(`search.hint`)})]}),S&&(0,Q.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Q.jsx)(E,{className:`h-3.5 w-3.5 animate-spin`}),a(`search.loading`)]}),w&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-4 text-xs`,children:[(0,Q.jsx)(`p`,{children:a(`search.failed`)}),(0,Q.jsx)(`button`,{type:`button`,className:`text-accent-primary underline`,onClick:()=>k(e=>e+1),children:a(`explore.retry`)})]}),b&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`status`,className:`space-y-1 border-b border-border/50 px-3 py-2 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`p`,{children:a(`search.results`,{count:b.matches.length})}),b.truncated&&(0,Q.jsx)(`p`,{className:`text-amber-600 dark:text-amber-400`,children:a(`search.partial`)}),b.repositories?.filter(e=>![`ok`,`partial`].includes(e.status)).map(e=>(0,Q.jsx)(`p`,{children:a(`search.repositoryIncomplete`,{name:e.repositoryName})},e.repositoryId))]}),b.matches.length===0&&(0,Q.jsx)(`p`,{className:`p-4 text-xs text-muted-foreground`,children:a(b.truncated?`search.noMatchesPartial`:`search.noMatches`)}),(0,Q.jsx)(`ul`,{className:`divide-y divide-border/40`,children:b.matches.map((e,t)=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i({repositoryId:e.repositoryId,path:e.path,line:e.lineNumber}),className:`w-full space-y-1 px-3 py-3 text-left hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-accent-primary`,title:`${e.repositoryName??``} / ${e.path}`,children:[n&&(0,Q.jsx)(`span`,{className:`block text-[10px] font-medium text-accent-primary`,children:e.repositoryName}),(0,Q.jsxs)(`span`,{className:`block break-all font-mono text-xs text-foreground`,children:[e.path,e.lineNumber?(0,Q.jsxs)(`span`,{className:`text-accent-primary`,children:[`:`,e.lineNumber]}):null]}),e.snippet!==void 0&&(0,Q.jsxs)(`span`,{className:`block overflow-hidden text-ellipsis whitespace-pre font-mono text-[11px] text-muted-foreground`,children:[e.snippetTruncated?`… `:``,e.snippet]})]})},`${e.repositoryId}:${e.path}:${e.lineNumber??0}:${t}`))})]})]})]})}function wt({projectId:e,repositoryName:t,multipleRepositories:n,jobId:r,ticketId:i,onOpen:a}){let{t:o,i18n:u}=m(`code`),{repositoryId:d,repositoryPath:f}=Z(),{registerHandler:h,unregisterHandler:g}=p(),[_,v]=(0,U.useState)(n),[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(!1),D=(0,U.useRef)(0),O=(0,U.useRef)(null),k=(0,U.useId)(),A=JSON.stringify([e,d,f,_,r,i]),j=(0,U.useRef)(A);j.current=A;let M=y?.scope===A?y:null,N=(0,U.useCallback)(async t=>{let n=++D.current;O.current?.abort();let a=new AbortController;O.current=a,S(!0),w(!1),t||b(null);try{let o=new URLSearchParams({limit:`50`});!_&&d&&o.set(`repositoryId`,d),r&&o.set(`jobId`,r),i&&o.set(`ticketId`,String(i)),t&&o.set(`cursor`,t);let s=await fetch(`${F(e)}/code/activity?${o}`,{signal:a.signal});if(!s.ok)throw Error(`activity_failed`);let c=await s.json();if(!Array.isArray(c.entries)||t&&c.nextCursor===t)throw Error(`invalid_activity_page`);if(a.signal.aborted||n!==D.current||j.current!==A)return;b(e=>{let n=t&&e?.scope===A?[...e.entries,...c.entries]:c.entries,r=[...new Map(n.map(e=>[e.id,e])).values()],i=r.length>1e3||r.length===1e3&&c.nextCursor!==null;return{...c,scope:A,entries:r.slice(0,1e3),nextCursor:i?null:c.nextCursor,truncated:c.truncated||i||!!t&&e?.scope===A&&e.truncated}})}catch{!a.signal.aborted&&n===D.current&&j.current===A&&w(!0)}finally{!a.signal.aborted&&n===D.current&&j.current===A&&S(!1)}},[e,d,f,_,r,i,A]);return(0,U.useEffect)(()=>(N(),()=>{D.current++,O.current?.abort()}),[N]),(0,U.useEffect)(()=>{let t=`code-activity-${e}-${k}`,n;return h(t,t=>{let r=t;r.type!==`file.provenance_updated`||r.projectId!==e||(clearTimeout(n),n=setTimeout(()=>{N()},250))}),()=>{clearTimeout(n),g(t)}},[N,e,k,h,g]),(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col`,"aria-label":o(`explore.activity`),children:[(0,Q.jsxs)(`div`,{className:`space-y-2 border-b border-border p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:o(`activity.description`)}),(0,Q.jsx)(`button`,{type:`button`,disabled:x,onClick:()=>{N()},"aria-label":o(`explore.refresh`),title:o(`explore.refresh`),className:`rounded p-1 text-muted-foreground hover:bg-muted disabled:opacity-40`,children:(0,Q.jsx)(V,{className:`h-3.5 w-3.5 ${x?`animate-spin`:``}`})})]}),n&&(0,Q.jsxs)(`select`,{"aria-label":o(`activity.scope`),value:_?`all`:`current`,onChange:e=>v(e.target.value===`all`),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`all`,children:o(`search.allRepositories`)}),(0,Q.jsx)(`option`,{value:`current`,children:t??o(`search.currentRepository`)})]}),(i||r)&&(0,Q.jsx)(`p`,{className:`break-all text-[11px] text-accent-primary`,children:i?o(`provenancePanel.specTitle`,{ticketId:i}):o(`provenancePanel.jobTitle`,{jobId:r})})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,"aria-busy":x,children:[C&&(0,Q.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-3 text-xs`,children:[(0,Q.jsx)(`p`,{children:o(`activity.failed`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{N(M?.nextCursor??void 0)},className:`text-accent-primary underline`,children:o(`explore.retry`)})]}),M?.truncated&&(0,Q.jsx)(`p`,{role:`status`,className:`border-b border-border p-3 text-xs text-amber-600 dark:text-amber-400`,children:o(`activity.partial`)}),M&&M.entries.length===0&&!M.truncated&&!M.nextCursor&&!x&&(0,Q.jsxs)(`div`,{className:`space-y-2 p-6 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(R,{className:`mx-auto h-6 w-6 opacity-50`}),(0,Q.jsx)(`p`,{children:o(`activity.empty`)})]}),(0,Q.jsx)(`ol`,{children:M?.entries.map((e,t)=>{let n=M.entries[t-1],r=!n||n.repositoryId!==e.repositoryId||n.jobId!==e.jobId||n.ticketId!==e.ticketId,i=e.kind===`created`?s:e.kind===`deleted`?c:T;return(0,Q.jsxs)(`li`,{children:[r&&(0,Q.jsxs)(`div`,{className:`sticky top-0 z-[1] space-y-1 border-y border-border bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.repositoryName}),e.ticketId!=null&&(0,Q.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-accent-primary`,children:o(`story.spec`,{ticketId:e.ticketId})})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[10px] text-muted-foreground`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,title:e.jobId??void 0,children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),e.jobId?.slice(0,10)??o(`history.unknownJob`)]}),(0,Q.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),title:new Date(e.at).toLocaleString(u.language),children:new Date(e.at).toLocaleDateString(u.language,{month:`short`,day:`numeric`})})]})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a({repositoryId:e.repositoryId,path:e.path,changeJobId:e.jobId}),className:`flex w-full items-start gap-2 border-b border-border/30 px-3 py-3 text-left hover:bg-muted/50`,title:e.path,children:[(0,Q.jsx)(i,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 ${e.kind===`created`?`text-accent-success`:e.kind===`deleted`?`text-destructive`:`text-accent-info`}`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`span`,{className:`block break-all font-mono text-xs`,children:e.path}),(0,Q.jsxs)(`span`,{className:`block text-[10px] text-muted-foreground`,children:[o(`story.kindLabel.${e.kind}`),` · `,o(e.hasPatch?e.patchTruncated?`activity.partialPatch`:`activity.patch`:`activity.noPatch`)]})]})]})]},e.id)})}),x&&(0,Q.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Q.jsx)(E,{className:`h-3.5 w-3.5 animate-spin`}),o(`activity.loading`)]}),M?.nextCursor&&!x&&!C&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{N(M.nextCursor)},className:`m-3 rounded-md border border-border px-3 py-1.5 text-xs hover:bg-muted/50`,children:o(`activity.loadMore`)})]})]})}function Tt(e){if(!e||!/^\d+$/.test(e))return;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:void 0}var Et=320,Dt=240,Ot=420,kt=760,At=e=>`specrails-desktop:code-tree-width:${e}`;function jt(e){try{let t=Number(localStorage.getItem(At(e)));return t>0&&Number.isFinite(t)?t:Et}catch{return Et}}function Mt(e,t){if(e)try{localStorage.setItem(At(e),String(Math.round(t)))}catch{}}function Nt(e,t){return Math.min(Math.max(e,Dt),Math.max(Dt,t-Ot))}function Pt(e={}){let{activeProjectId:t}=v();return(0,Q.jsx)(Ft,{...e},t??`no-project`)}function Ft({embedded:e=!1,initialPath:t=null,initialRepositoryId:n,onRepositoryChange:r,onSelectedPathChange:i}){let{t:s}=m(`code`),{t:c}=m(`common`),{activeProjectId:l,projects:d}=v(),[f,p]=a(),h=o(),_=d?.find(e=>e.id===l),y=(0,U.useMemo)(()=>I(_),[_]),[x,S]=(0,U.useState)(()=>({entries:[{repositoryId:n??void 0,path:t}],index:0})),C=e?x.entries[x.index]:{repositoryId:f.get(`repositoryId`)??void 0,path:f.get(`path`),line:Tt(f.get(`line`)),changeJobId:f.get(`changeJobId`)},E=C.repositoryId?y.find(e=>e.id===C.repositoryId):y.find(e=>e.isPrimary),O=!!C.repositoryId&&!!_&&!E,k=(0,U.useMemo)(()=>({apiBase:l?F(l,E?.id):g(),repositoryId:E?.id,repositoryPath:E?.path,isPrimary:E?.isPrimary}),[l,E?.id,E?.path,E?.isPrimary]),A=JSON.stringify([l,E?.id,E?.path]),[j,M]=(0,U.useState)(`files`),[N,P]=(0,U.useState)(!0),[L,ee]=(0,U.useState)(e),[z,B]=(0,U.useState)(()=>jt(l)),[te,V]=(0,U.useState)(null),[ne,ie]=(0,U.useState)(null),[se,W]=(0,U.useState)({}),G=e?se.jobId??null:f.get(`jobId`),K=e?se.ticketId??null:Tt(f.get(`ticketId`))??null,[q,ce]=(0,U.useState)(K?String(K):``),J=(0,U.useRef)(null),le=(0,U.useRef)(null);(0,U.useEffect)(()=>{ce(K?String(K):``)},[K]),(0,U.useEffect)(()=>{let e=J.current;if(!e)return;let t=e=>{e&&(ee(e<kt),B(t=>Nt(t,e)))};if(t(e.clientWidth),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(e=>t(e[0]?.contentRect.width??0));return n.observe(e),()=>n.disconnect()},[]),(0,U.useEffect)(()=>()=>le.current?.(),[]),(0,U.useEffect)(()=>{L&&C.path&&P(!1)},[L,C.path]);let ue=(0,U.useCallback)(t=>{let n={...t,repositoryId:t.repositoryId??E?.id},a=n.repositoryId!==E?.id;if(e)S(e=>({entries:[...e.entries.slice(0,e.index+1),n],index:e.index+1})),a&&W({});else{let e=new URLSearchParams(f);for(let t of[`path`,`line`,`changeJobId`])e.delete(t);n.repositoryId&&e.set(`repositoryId`,n.repositoryId),n.path&&e.set(`path`,n.path),n.line&&e.set(`line`,String(n.line)),n.changeJobId&&e.set(`changeJobId`,n.changeJobId),a&&(e.delete(`jobId`),e.delete(`ticketId`)),p(e)}i?.(n.path),n.repositoryId&&r?.(n.repositoryId),L&&n.path&&P(!1)},[e,E?.id,f,p,i,r,L]),de=t=>{if(!e){h(t);return}let n=x.index+t,a=x.entries[n];if(!a)return;let o=a.repositoryId??y.find(e=>e.isPrimary)?.id;o!==E?.id&&W({}),S({...x,index:n}),i?.(a.path),o&&r?.(o)},fe=(0,U.useCallback)(t=>{if(e)W(t);else{let e=new URLSearchParams(f);e.delete(`jobId`),e.delete(`ticketId`),t.jobId&&e.set(`jobId`,t.jobId),t.ticketId&&e.set(`ticketId`,String(t.ticketId)),p(e)}},[e,f,p]),pe=(0,U.useCallback)(e=>{fe({jobId:e}),M(`activity`),P(!0)},[fe]),me=e=>{le.current?.();let t=e.clientX,n=z,r=z,i=e=>{r=Nt(n+e.clientX-t,J.current?.clientWidth||window.innerWidth),B(r)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),Mt(l,r),le.current=null};le.current=a,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},Y=N||!C.path,he=!L||!Y,ge=C.path?.split(`/`)??[];return(0,Q.jsx)(we.Provider,{value:k,children:(0,Q.jsxs)(`div`,{ref:J,className:`flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden`,"data-testid":`code-page`,"data-compact":L,children:[(0,Q.jsxs)(`header`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border bg-card/30 px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(`explore.back`),title:s(`explore.back`),onClick:()=>de(-1),disabled:e&&x.index===0,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(b,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(`explore.forward`),title:s(`explore.forward`),onClick:()=>de(1),disabled:e&&x.index===x.entries.length-1,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(u,{className:`h-3.5 w-3.5`})}),C.path&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":s(Y?`explore.hideNavigation`:`explore.showNavigation`),title:s(Y?`explore.hideNavigation`:`explore.showNavigation`),onClick:()=>P(!Y),className:`rounded p-1.5 text-muted-foreground hover:bg-muted`,children:Y?(0,Q.jsx)(ae,{className:`h-4 w-4`}):(0,Q.jsx)(oe,{className:`h-4 w-4`})})]}),y.length>0&&(0,Q.jsxs)(`select`,{"aria-label":c(`repositories.select`),className:`max-w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs`,value:E?.id??C.repositoryId??``,onChange:e=>ue({repositoryId:e.target.value,path:null}),children:[O&&(0,Q.jsx)(`option`,{value:C.repositoryId,children:c(`repositories.unavailable`)}),y.map(e=>(0,Q.jsxs)(`option`,{value:e.id,children:[e.name,e.isPrimary?` · ${c(`repositories.primary`)}`:``]},e.id))]}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-muted-foreground`,title:E?.path,children:E?.path})]}),O?(0,Q.jsx)(`p`,{role:`alert`,className:`p-4 text-sm text-destructive`,children:c(`repositories.invalidSelection`)}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[(0,Q.jsxs)(`aside`,{hidden:!Y,className:`${Y?`flex`:`hidden`} min-h-0 min-w-0 shrink-0 flex-col overflow-hidden bg-card/15`,style:{width:L?`100%`:z},"aria-label":s(`explore.navigation`),children:[(0,Q.jsx)(`nav`,{className:`flex shrink-0 gap-0.5 border-b border-border px-2 pt-2`,"aria-label":s(`explore.views`),children:[{mode:`files`,Icon:re},{mode:`search`,Icon:D},{mode:`activity`,Icon:R}].map(({mode:e,Icon:t})=>(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":j===e,onClick:()=>M(e),className:`flex min-w-0 flex-1 items-center justify-center gap-1.5 border-b-2 px-1 py-2 text-xs ${j===e?`border-accent-primary text-accent-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}),s(`explore.${e}`)]},e))}),(0,Q.jsx)(`div`,{className:j===`files`?`min-h-0 flex-1`:`hidden`,children:(0,Q.jsx)(Ne,{selectedPath:C.path,onOpenFile:e=>ue({path:e}),filterJobId:G,filterTicketId:K},A)}),l&&(0,Q.jsx)(`div`,{className:j===`search`?`flex min-h-0 flex-1 flex-col`:`hidden`,children:(0,Q.jsx)(Ct,{active:j===`search`&&Y,projectId:l,repositoryName:E?.name,multipleRepositories:y.length>1,onOpen:ue})}),j===`activity`&&l&&(0,Q.jsx)(wt,{projectId:l,repositoryName:E?.name,multipleRepositories:y.length>1,jobId:G,ticketId:K,onOpen:ue})]}),Y&&!L&&(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`page.resizeFileTree`),onPointerDown:me,onDoubleClick:()=>{let e=Nt(Et,J.current?.clientWidth||window.innerWidth);B(e),Mt(l,e)},className:`w-1.5 shrink-0 cursor-col-resize touch-none select-none border-x border-border/40 hover:bg-accent-primary/20`,title:s(`resizer.hint`),"data-testid":`code-tree-resizer`}),(0,Q.jsxs)(`main`,{hidden:!he,className:`${he?`flex`:`hidden`} min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[C.path&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b border-border/60 px-3 py-2 text-[11px]`,"aria-label":s(`explore.breadcrumb`),children:[(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),ge.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 ${t===ge.length-1?`font-medium text-foreground`:`text-muted-foreground`}`,children:[t>0&&(0,Q.jsx)(w,{className:`h-3 w-3`}),e]},t)),C.line&&(0,Q.jsxs)(`span`,{className:`ml-1 shrink-0 text-accent-primary`,children:[`:`,C.line]})]}),(0,Q.jsx)(It,{jobId:G,ticketId:K,ticketInput:q,onTicketInputChange:ce,onApplyTicket:e=>fe({ticketId:Tt(e.trim())}),onClear:()=>fe({}),summaryAction:C.path?te:null,copyPathAction:C.path?ne:null}),(G||K)&&(0,Q.jsx)(Lt,{jobId:G,ticketId:K,onOpenFile:e=>ue({path:e,changeJobId:G})},`${A}:${G}:${K}`),C.path?(0,Q.jsx)(bt,{compact:L,relPath:C.path,initialLine:C.line,initialJobId:C.changeJobId,onFilterJob:pe,onSummaryActionChange:V,onCopyPathActionChange:ie},`${A}:${C.path}`):(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center overflow-auto p-6`,children:(0,Q.jsxs)(`div`,{className:`max-w-sm space-y-4 text-center`,children:[(0,Q.jsx)(`div`,{className:`mx-auto flex h-14 w-14 items-center justify-center rounded-2xl border border-accent-primary/20 bg-accent-primary/10 text-accent-primary`,children:(0,Q.jsx)(H,{className:`h-7 w-7`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:s(`explore.welcome`)}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:s(`explore.description`)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{M(`search`),P(!0)},className:`rounded-lg bg-accent-primary/15 px-3 py-2 text-xs text-accent-primary`,children:s(`explore.findCode`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{M(`activity`),P(!0)},className:`rounded-lg border border-border px-3 py-2 text-xs text-muted-foreground hover:text-foreground`,children:s(`explore.viewActivity`)})]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground/80`,children:s(`explore.sourceHint`)})]})})]})]})]})})}function It({jobId:e,ticketId:t,ticketInput:n,onTicketInputChange:r,onApplyTicket:i,onClear:a,summaryAction:o,copyPathAction:s}){let{t:c}=m(`code`),l=t?`spec`:e?`job-context`:`all`;return(0,Q.jsx)(`div`,{className:`border-b border-border bg-background/80 px-4 py-2`,"data-testid":`code-provenance-toolbar`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground`,children:[(0,Q.jsx)(ie,{className:`h-3.5 w-3.5`}),c(`toolbar.scope`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,"aria-pressed":l===`all`,className:l===`all`?`rounded-md bg-accent-primary/20 px-2 py-1 text-xs text-accent-primary`:`rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.allAi`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/70 bg-card/40 px-1 py-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(n),"aria-pressed":l===`spec`,className:l===`spec`?`rounded bg-accent-success/20 px-2 py-0.5 text-xs text-accent-success`:`rounded px-2 py-0.5 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.spec`)}),(0,Q.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i(n)},placeholder:c(`toolbar.ticketIdPlaceholder`),inputMode:`numeric`,className:`h-6 w-20 bg-transparent px-1 font-mono text-xs outline-none placeholder:text-muted-foreground/60`})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),s&&(0,Q.jsx)(`button`,{type:`button`,onClick:s.onClick,className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:c(`toolbar.copyFilePath`)}),o&&(0,Q.jsxs)(`button`,{type:`button`,onClick:o.onClick,disabled:o.regenerating||!!o.disabledReason,"aria-label":o.hasSummary?c(`toolbar.regenerateSummary`):c(`toolbar.generateSummary`),className:`inline-flex items-center gap-1.5 rounded-md bg-accent-primary/15 px-2.5 py-1 text-xs text-accent-primary hover:bg-accent-primary/25 disabled:opacity-50`,title:o.disabledReason?c(`toolbar.summaryUnavailable`,{reason:o.disabledReason}):void 0,children:[(0,Q.jsx)(f,{className:o.regenerating?`h-3.5 w-3.5 animate-spin`:`h-3.5 w-3.5`}),o.hasSummary?o.regenerating?c(`toolbar.regenerating`):c(`toolbar.regenerateSummary`):o.regenerating?c(`toolbar.generating`):c(`toolbar.generateSummary`)]}),l===`job-context`&&(0,Q.jsx)(`span`,{className:`rounded-md bg-accent-info/15 px-2 py-1 text-xs text-accent-info`,children:c(`toolbar.jobContext`)}),(e||t)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(k,{className:`h-3.5 w-3.5`}),c(`toolbar.clear`)]})]})})}function Lt({jobId:e,ticketId:t,onOpenFile:n}){let{t:r}=m(`code`),{apiBase:i}=Z(),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(0);(0,U.useEffect)(()=>{let n=new AbortController;o(null),c(!1),u(!1);let r=new URLSearchParams({limit:`100`});return e&&r.set(`jobId`,e),t&&r.set(`ticketId`,String(t)),fetch(`${i}/code/activity?${r}`,{signal:n.signal}).then(async e=>{if(!e.ok)throw Error(`activity_failed`);return e.json()}).then(e=>{if(n.signal.aborted)return;if(!Array.isArray(e.entries))throw Error(`invalid_activity_response`);let t=new Map;for(let n of e.entries)t.has(n.path)||t.set(n.path,n);o([...t.values()]),u(!!e.nextCursor||e.truncated===!0)}).catch(()=>{n.signal.aborted||c(!0)}),()=>n.abort()},[e,t,i,d]);let p=(0,U.useMemo)(()=>{let e=a??[];return{created:e.filter(e=>e.kind===`created`),modified:e.filter(e=>e.kind===`modified`),deleted:e.filter(e=>e.kind===`deleted`)}},[a]),h=a?.length??0,g=e?r(`provenancePanel.jobTitle`,{jobId:e}):r(`provenancePanel.specTitle`,{ticketId:t});return(0,Q.jsxs)(`section`,{className:`max-h-52 shrink-0 overflow-auto border-b border-border bg-card/35 px-4 py-3`,"data-testid":`provenance-result-panel`,children:[s&&(0,Q.jsxs)(`p`,{role:`alert`,className:`mb-2 text-xs`,children:[r(`activity.failed`),` `,(0,Q.jsx)(`button`,{type:`button`,className:`text-accent-primary underline`,onClick:()=>f(e=>e+1),children:r(`explore.retry`)})]}),!a&&!s&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`activity.loading`)}),l&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-amber-600 dark:text-amber-400`,children:r(`activity.partial`)}),(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold truncate`,children:g}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:a?r(`provenancePanel.touchedFiles`,{count:h}):`—`})]}),(0,Q.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[(0,Q.jsx)(Rt,{label:r(`action.added`),rows:p.created,icon:`created`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.changed`),rows:p.modified,icon:`modified`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.deleted`),rows:p.deleted,icon:`deleted`,onOpenFile:n})]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:e&&(0,Q.jsxs)(`a`,{href:`/jobs/${encodeURIComponent(e)}`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(x,{className:`h-3.5 w-3.5`}),r(`provenancePanel.log`)]})})]})]})}function Rt({label:e,rows:t,icon:n,onOpenFile:r}){return(0,Q.jsxs)(`details`,{className:`group min-w-[180px] max-w-[320px]`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1.5 rounded-md bg-muted/35 px-2 py-1 text-xs hover:bg-muted/55`,children:[(0,Q.jsx)(n===`created`?s:n===`deleted`?c:T,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:t.length})]}),t.length>0&&(0,Q.jsx)(`div`,{className:`mt-1 max-h-28 overflow-auto rounded-md border border-border/60 bg-background/60 p-1`,children:t.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(e.path),className:`block w-full truncate rounded px-1.5 py-1 text-left font-mono text-[11px] text-muted-foreground hover:bg-muted/50 hover:text-foreground`,title:e.path,children:e.path},`${e.path}-${e.jobId??`job`}-${e.at}-${t}`))})]})}export{Pt as default};
@@ -1,19 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{J as r,X as i,z as a}from"./TicketDetailModalContext-DW3eQ0I7.js";import{h as o,l as s,r as c}from"./useSharedWebSocket-5mj2SMKn.js";import{n as l,t as u}from"./createLucideIcon-Bjbbp_KS.js";import{a as d,r as f,s as p}from"./useDesktop-Duv5ddAa.js";import{d as m,u as h}from"./MinimizedChatsContext-Dsv2eHf_.js";import{t as g}from"./brain-DI9lHkKY.js";import{n as _}from"./file-text-BcLCfcWZ.js";import{t as v}from"./circle-x-CMYsN4ZH.js";import{t as y}from"./git-branch-BRM0F5GN.js";import{t as b}from"./loader-circle-DcygOQpC.js";import{n as x,t as S}from"./square-Ci-PFcFe.js";import{t as C}from"./search-Cq_gE3Ik.js";import{t as w}from"./triangle-alert-H9T4jAmh.js";import{t as T}from"./x-CBMI9ejn.js";import{t as E}from"./utils-BC4DHlz2.js";import{n as D,t as O}from"./lib-CGdyxIWg.js";import{t as k}from"./button-Ccc9Dc-D.js";import{At as A,B as j,Dt as M,H as N,I as ee,J as P,K as te,Mt as F,Y as ne,dt as re,ft as I,it as ie,m as ae,p as oe,q as se,ut as ce,xt as le,z as L}from"./index-DOKftX7y.js";import{t as ue}from"./lib-C7Mhm-gT.js";var de=u(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),fe=u(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),pe=u(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),me=u(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),he=u(`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`}]]),R=n();function ge({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,R.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,R.jsxs)(`div`,{className:`flex items-center`,children:[(0,R.jsxs)(L,{children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,R.jsx)(_e,{state:i}),(0,R.jsx)(`span`,{className:E(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,R.jsxs)(j,{side:`bottom`,className:`max-w-[200px]`,children:[(0,R.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,R.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,R.jsx)(`div`,{className:E(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,a===`done`||i===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:a===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function _e({state:e}){return(0,R.jsxs)(`div`,{className:E(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,R.jsx)(b,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,R.jsx)(F,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,R.jsx)(v,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,R.jsx)(r,{className:`w-6 h-6 text-muted-foreground/20`})]})}var z=e(t(),1);function ve(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 ye=new Set;function be({ticketId:e,onOpen:t,children:n}){let{t:r}=l(`agent`),i=r(`refs.openTicket`,{id:e});return(0,R.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 xe(e){if(!e.includes(`#`))return null;let t=P(e,ye);return t.some(e=>e.kind===`ticket`)?t:null}function Se(e,t){let n=xe(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,R.jsx)(be,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,R.jsx)(z.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var Ce=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function we(e){return e.kind===`ticket`?{type:`link`,url:te({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function Te(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!Ce.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=P(n.value,ye);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(we))}else Te(n)}}function Ee(){return e=>Te(e)}function De(e){let{activeProjectId:t}=f(),{openRef:n}=ne(),r=e??t??void 0;return(0,z.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function Oe(e,t){let n=`${e.id??t}`,r=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:r}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:r}:ve(t)?{id:n,content:t,type:`assistant`,timestamp:r}:{id:n,content:t,type:`plain`,timestamp:r}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),i=[];return t.duration_ms&&i.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&i.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&i.push(o.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${o.t(`jobs:logViewer.completed`)}${i.length?` — ${i.join(` · `)}`:``}`,type:`result`,timestamp:r}}catch{return null}return null}function ke(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 Ae(e){let t=[];for(let n of e){let e=t.length>0?t[t.length-1]:null;n.type===`assistant`&&e?.type===`assistant`?e.content+=`
2
- `+n.content:t.push({...n})}return t}function je(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 Me({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=l(`jobs`),[a,o]=(0,z.useState)(``),[s,c]=(0,z.useState)(!0),[u,d]=(0,z.useState)(new Set),f=(0,z.useRef)(null),m=(0,z.useRef)(null),g=De(n),{processedLines:_,groups:v,totalLines:y}=(0,z.useMemo)(()=>{let t=ke(Ae(e.map((e,t)=>Oe(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:je(t),totalLines:t.length}},[e,i.language]),b=(0,z.useMemo)(()=>{if(!a)return y;let e=a.toLowerCase();return _.filter(t=>t.content.toLowerCase().includes(e)).length},[a,_,y]),x=(0,z.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,z.useEffect)(()=>{s&&x()},[e.length,s,x]);function S(){let e=m.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;c(t)}function w(e){d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,R.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):y===0?(0,R.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,R.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,R.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,R.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,R.jsx)(C,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,R.jsx)(ee,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`pl-7 h-7`})]}),(0,R.jsx)(k,{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
- `);navigator.clipboard.writeText(e).then(()=>{p.success(r(`logViewer.copySuccess`))}).catch(()=>{p.error(r(`logViewer.copyFailed`))})},children:(0,R.jsx)(A,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:b,total:y})})]}),(0,R.jsxs)(`div`,{ref:m,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:S,children:[v.map(e=>(0,R.jsx)(Ne,{group:e,filter:a,collapsed:u.has(e.key),onToggle:()=>w(e.key),onOpenTicket:g},e.key)),(0,R.jsx)(`div`,{ref:f})]}),!s&&(0,R.jsxs)(k,{size:`sm`,variant:`secondary`,onClick:()=>{c(!0),x()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,R.jsx)(h,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var Ne=(0,z.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:a}=l(`jobs`),o=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return o.length===0?null:(0,R.jsx)(`div`,{children:o.map((e,t)=>(0,R.jsx)(B,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let s=e.header.content;return(0,R.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:r,className:E(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,R.jsx)(_,{className:E(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,R.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:s}),e.header.timestamp&&(0,R.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,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:a(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,R.jsx)(`div`,{className:`bg-muted/5`,children:o.length===0?(0,R.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:a(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):o.map((e,t)=>(0,R.jsx)(B,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),Pe=[ue],Fe=[O],Ie=[O,Ee],B=(0,z.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,z.useMemo)(()=>l&&n?Se(e.content,n):e.content,[l,n,e.content]),d=r&&n?Ie:Fe,f=(0,z.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=se(e);return r?.kind===`ticket`?(0,R.jsx)(be,{ticketId:r.ticketId,onOpen:n,children:t}):(0,R.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,R.jsxs)(`div`,{className:E(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,R.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,R.jsx)(`div`,{className:`flex-1 min-w-0 prose prose-invert prose-xs max-w-none
4
- prose-p:my-1 prose-p:leading-relaxed
5
- prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold
6
- prose-ul:my-1 prose-ol:my-1 prose-li:my-0
7
- prose-code:text-cyan-300 prose-code:text-[11px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded
8
- prose-pre:my-1 prose-pre:bg-muted/30 prose-pre:rounded-md prose-pre:p-2 prose-pre:text-[11px]
9
- prose-strong:text-foreground prose-em:text-foreground/70
10
- prose-a:text-blue-400 prose-a:no-underline hover:prose-a:underline
11
- prose-table:my-2 prose-table:text-[11px]
12
- prose-thead:border-border prose-thead:bg-muted/30
13
- prose-th:px-3 prose-th:py-1.5 prose-th:text-left prose-th:font-semibold prose-th:text-foreground/90
14
- prose-td:px-3 prose-td:py-1.5 prose-td:border-border
15
- prose-tr:border-border
16
- text-foreground/80`,children:(0,R.jsx)(D,{remarkPlugins:d,rehypePlugins:Pe,components:f,children:e.content})}):(0,R.jsx)(`span`,{className:E(`flex-1 break-all leading-relaxed whitespace-pre-wrap font-mono`,e.type===`tool-use`&&`text-cyan-400/80 aurora-light:text-accent-info text-[11px]`,e.type===`stderr`&&`text-orange-400 aurora-light:text-accent-warning`,e.type===`result`&&`text-emerald-400 aurora-light:text-accent-success font-medium`,e.type===`log`&&`text-foreground/60`,e.type===`plain`&&`text-foreground/70`,e.type===`tool-result`&&`text-muted-foreground/50`,i&&`text-emerald-400 aurora-light:text-accent-success`,a&&`text-red-400 aurora-light:text-destructive`,o&&`text-accent-primary/80`,s&&`text-accent-info/80`),children:u})]})}),V=e=>typeof e==`object`&&!!e&&!Array.isArray(e),H=e=>typeof e==`number`&&Number.isFinite(e)&&e>=0,U=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`);function Le(e){if(!V(e)||e.version!==1||typeof e.execution!=`string`||!H(e.steps)||!H(e.deciderEvaluations)||!(e.turns===null||H(e.turns))||!(e.costUsd===null||H(e.costUsd))||typeof e.costUncertain!=`boolean`)return null;if(e.core!==null){let t=e.core;if(!V(t)||typeof t.change!=`string`||typeof t.recordedAt!=`string`||!V(t.completion)||![`implementation`,`validation`,`archive`,`delivery`].every(e=>typeof t.completion==`object`&&typeof t.completion[e]==`string`)||!U(t.completion.reasons)||!U(t.findings)||!Array.isArray(t.exceptions)||!Array.isArray(t.checks)||!Array.isArray(t.phases)||!t.exceptions.every(e=>V(e)&&[`requirement`,`reason`,`impact`,`acceptedBy`,`approvalEvidence`].every(t=>typeof e[t]==`string`))||!t.checks.every(e=>V(e)&&[`name`,`status`,`scope`,`limitations`].every(t=>typeof e[t]==`string`)&&typeof e.required==`boolean`&&U(e.evidence))||!t.phases.every(e=>V(e)&&typeof e.name==`string`&&typeof e.status==`string`&&(e.durationMs===null||H(e.durationMs))&&(e.attempts===null||H(e.attempts))))return null}return e}function W(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var Re=/^\s*━+\s*Step\s+\d+\s*·/,ze=/\s*\(iteration\s+\d+\)\s*$/i;function G(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function K(e){let t=G(e.title);return e.iteration==null?t:t.replace(ze,``)}function Be(e){return e.meta.nodeId??`${e.meta.kind}::${G(e.meta.title).replace(ze,``)}`}function Ve(e){let t=null,n=0,r=null,i=[[]],a=[];for(let o=0;o<e.length;o++){let s=e[o];if(s.event_type===`loop_completion`){r=Le(W(s.payload));continue}if(s.event_type===`loop_graph`){let e=W(s.payload);e&&e.graph&&typeof e.graph==`object`&&!Array.isArray(e.graph)&&(t={graph:e.graph,loopId:typeof e.loopId==`string`?e.loopId:void 0,loopName:typeof e.loopName==`string`?e.loopName:void 0,provider:typeof e.provider==`string`?e.provider:void 0,model:typeof e.model==`string`?e.model:void 0,iterationLimit:typeof e.iterationLimit==`number`?e.iterationLimit:void 0});continue}if(s.event_type===`loop_step`){let e=W(s.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),a.push({meta:{index:e.index,kind:typeof e.kind==`string`?e.kind:`ai-step`,title:typeof e.title==`string`?e.title:``,nodeId:typeof e.nodeId==`string`?e.nodeId:null,iteration:t,template:typeof e.template==`string`&&e.template?e.template:void 0,command:typeof e.command==`string`&&e.command?e.command:void 0},end:null,lastActivity:null}),i.push([]);continue}if(s.event_type===`loop_step_end`){let e=W(s.payload);if(!e||typeof e.index!=`number`)continue;for(let t=a.length-1;t>=0;t--)if(a[t].meta.index===e.index){a[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`stalled`?`stalled`:e.status===`failed`?`failed`:`ok`,exitCode:typeof e.exitCode==`number`?e.exitCode:null,durationMs:typeof e.durationMs==`number`?e.durationMs:null,decision:e.decision===`continue`||e.decision===`stop`?e.decision:void 0,...e.reason===`idle_timeout`||e.reason===`provider_limit`?{reason:e.reason}:{},...typeof e.idleMs==`number`?{idleMs:e.idleMs}:{}};break}continue}let c=a.length>0,l=Oe(s,o);if(l&&!(c&&Re.test(l.content))&&i[i.length-1].push(l),c){let e=ae(s);e.step&&e.actionKey&&(a[a.length-1].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let o=e=>ke(Ae(e)),s=o(i[0]),c=a.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:o(i[t+1]),end:e.end,lastActivity:e.lastActivity})),l=s.length+c.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:s,segments:c,maxIteration:n,totalLines:l,...r?{completion:r}:{}}}function He(e,t){return e.end?e.end.status:t.isLast?t.jobSettled?`interrupted`:`running`:`unknown`}function Ue(e){return e===`continue`?0:e===`stop`?2:1}function We(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set,r=[],i=a=>{if(n.has(a))return;let o=t.get(a);if(!o)return;n.add(a),r.push(o);let s=e.edges.filter(e=>e.source===a).slice().sort((e,t)=>Ue(e.branch)-Ue(t.branch));for(let e of s)i(e.target)},a=e.nodes.find(e=>e.type===`start`);a&&i(a.id);for(let t of e.nodes)i(t.id);return r}function q(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Ge(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=Be(e);r.set(n,{seg:e,idx:t}),e.meta.kind===`decider`&&e.end?.decision&&i.set(n,e.end.decision)});let a=e=>{let r=He(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r===`stalled`?`failed`:r};if(e.graphMeta)return We(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:q(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:q(e),state:t.jobSettled?t.jobFailed?`failed`:`ok`:`pending`,latestSegmentKey:null};let n=r.get(e.id);return n?{key:e.id,kind:e.type,label:q(e)??K(n.seg.meta),state:a(n),decision:e.type===`decider`?i.get(e.id):void 0,latestSegmentKey:n.seg.key}:{key:e.id,kind:e.type,label:q(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=Be(e),r={seg:e,idx:t},c=s.get(n),l=e.meta.kind===`decider`?i.get(n):void 0;if(c!=null){let t=o[c];t.state=a(r),t.decision=l,t.latestSegmentKey=e.key}else s.set(n,o.length),o.push({key:n,kind:e.meta.kind,label:K(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function Ke(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function qe({result:e}){let{t}=l(`jobs`),n=e.core,r=e=>t(`completion.status.${e}`,{defaultValue:e});return(0,R.jsxs)(`section`,{"aria-label":t(`completion.title`),className:`border-b border-border/40 px-4 py-3 text-xs space-y-2`,"data-testid":`loop-completion`,children:[(0,R.jsxs)(`p`,{className:`font-medium`,children:[t(`completion.execution`),`: `,r(e.execution)]}),(0,R.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.counters`,{steps:e.steps,evaluations:e.deciderEvaluations,turns:e.turns??t(`completion.unavailable`)})}),n?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`dl`,{className:`grid grid-cols-2 gap-2 md:grid-cols-4`,children:[`implementation`,`validation`,`archive`,`delivery`].map(e=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`dt`,{className:`text-foreground/70`,children:t(`completion.${e}`)}),(0,R.jsx)(`dd`,{className:n.completion[e]===`with-exceptions`||n.completion[e]===`blocked`?`text-accent-warning font-medium`:`font-medium`,children:r(n.completion[e])})]},e))}),(0,R.jsxs)(`details`,{children:[(0,R.jsx)(`summary`,{className:`cursor-pointer`,children:t(`completion.evidence`)}),(0,R.jsxs)(`div`,{className:`space-y-2 pt-2 break-words`,children:[(0,R.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.snapshot`,{change:n.change,at:n.recordedAt})}),n.completion.reasons.map((e,t)=>(0,R.jsx)(`p`,{children:e},`reason-${t}`)),n.exceptions.map((e,n)=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`font-medium`,children:e.requirement}),(0,R.jsxs)(`p`,{children:[e.reason,` — `,e.impact]}),(0,R.jsxs)(`p`,{children:[t(`completion.acceptedBy`,{by:e.acceptedBy}),`: `,e.approvalEvidence]})]},`exception-${n}`)),n.checks.map((e,n)=>(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`p`,{className:`font-medium`,children:[e.name,`: `,r(e.status),` (`,t(e.required?`completion.required`:`completion.supplementary`),`)`]}),(0,R.jsxs)(`p`,{children:[e.scope,` — `,e.limitations]}),(0,R.jsx)(`p`,{className:`text-foreground/70`,children:e.evidence.join(`; `)})]},`check-${n}`)),n.findings.map((e,t)=>(0,R.jsx)(`p`,{children:e},`finding-${t}`)),n.phases.map(e=>(0,R.jsxs)(`p`,{children:[e.name,`: `,r(e.status),` · `,e.durationMs==null?t(`completion.unavailable`):`${(e.durationMs/1e3).toFixed(1)}s`,` · `,e.attempts==null?t(`completion.unavailable`):t(`completion.attempts`,{count:e.attempts})]},e.name)),(0,R.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.phaseCostUnavailable`)})]})]})]}):(0,R.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.noCoreEvidence`)})]})}var Je={start:x,"ai-step":g,shell:ie,decider:y,condition:y,end:M},Ye=S,Xe={start:`text-accent-success`,"ai-step":`text-accent-primary`,shell:`text-accent-warning`,decider:`text-accent-highlight`,condition:`text-accent-info`,end:`text-accent-secondary`},Ze={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 Qe(e){return Je[e]??Ye}function $e({chips:e,iteration:t,onChipClick:n,variant:r}){let{t:o}=l(`jobs`);return e.length===0&&!t?null:(0,R.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":o(`loopExplorer.stepMapAria`),className:E(`flex items-center gap-1 overflow-x-auto border-b border-border/30 bg-surface/20`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[e.map((e,t)=>{let r=Qe(e.kind),s=Xe[e.kind]??`text-foreground`,c=Ze[e.kind]??`border-border/40`,l=e.label??o(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),u=e.latestSegmentKey!=null;return(0,R.jsxs)(z.Fragment,{children:[t>0&&(0,R.jsx)(_,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,R.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${l} — ${e.state}`,disabled:!u,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:E(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,c,e.state===`pending`&&`opacity-45 border-border/40`,e.state===`interrupted`&&`border-dashed border-accent-warning/50`,u?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,R.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-px rounded-full ring-2 ring-accent-primary/50 motion-safe:animate-pulse pointer-events-none`}),(0,R.jsx)(r,{className:E(`w-3 h-3 shrink-0`,s)}),(0,R.jsx)(`span`,{className:E(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:l}),e.state===`ok`&&(0,R.jsx)(m,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,R.jsx)(T,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,R.jsx)(a,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,R.jsx)(i,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,R.jsxs)(`span`,{"data-testid":`loop-iteration-chip`,className:`ml-auto flex items-center gap-1.5 shrink-0 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-2.5 py-1 text-[10px] font-medium text-accent-highlight tabular-nums`,children:[(0,R.jsx)(I,{className:`w-3 h-3`}),t.limit==null?o(`loopExplorer.iterationBadge`,{count:t.current}):o(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var et=(0,z.memo)($e);function tt({className:e}){return(0,R.jsxs)(`span`,{className:E(`relative flex h-2 w-2 shrink-0`,e),children:[(0,R.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,R.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function nt(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function rt(e,t,n,r){return e.length===0?(0,R.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:n(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):e.map((e,t)=>(0,R.jsx)(B,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function it({label:e,value:t,copyLabel:n}){let[r,i]=(0,z.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":`${n} — ${e}`,title:n,className:`p-0.5 text-muted-foreground/40 hover:text-foreground transition-colors cursor-pointer`,children:r?(0,R.jsx)(m,{className:`w-2.5 h-2.5 text-accent-success`}):(0,R.jsx)(A,{className:`w-2.5 h-2.5`})})]}),(0,R.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function at({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:a,setRef:o,onOpenTicket:s}){let{t:c}=l(`jobs`),{meta:u,lines:d,end:f,lastActivity:p}=e,h=Qe(u.kind),g=Xe[u.kind]??`text-foreground`,v=nt(d,r),y=t===`running`,b=!!(u.template||u.command),[x,S]=(0,z.useState)(!1);return(0,R.jsxs)(`div`,{ref:t=>o(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:E(`mt-3 rounded-md overflow-hidden border animate-in fade-in duration-200`,t===`running`&&`border-accent-primary/40`,t===`failed`&&`border-destructive/30`,t===`stalled`&&`border-dashed border-destructive/40`,t===`interrupted`&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,R.jsxs)(`div`,{className:E(`flex items-stretch bg-primary/5 border-b`,t===`failed`||t===`stalled`?`border-destructive/20`:`border-primary/20`),children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-2 flex-1 min-w-0 text-left px-3 py-2 hover:bg-primary/10 transition-colors duration-150 cursor-pointer`,children:[(0,R.jsx)(_,{className:E(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,R.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,R.jsx)(h,{className:E(`w-3.5 h-3.5 shrink-0`,g)}),(0,R.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:K(u)}),u.iteration!=null&&u.iteration>=1&&(0,R.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/60 px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground tabular-nums`,children:c(`loopExplorer.iterationBadge`,{count:u.iteration})}),y&&(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,R.jsx)(tt,{}),p&&(0,R.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:c(`statusPanel.activity.${p.actionKey}`,{arg:p.actionArg??``})})]}),t===`ok`&&(0,R.jsx)(m,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&f?.reason===`provider_limit`&&(0,R.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-destructive/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-destructive`,title:c(`loopExplorer.providerLimitHint`),"data-testid":`loop-step-provider-limit`,children:c(`loopExplorer.providerLimit`)}),t===`failed`&&(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`stalled`&&(0,R.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-destructive/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-destructive`,title:f?.idleMs==null?void 0:c(`loopExplorer.stalledIdle`,{count:Math.max(1,Math.round(f.idleMs/6e4))}),children:c(`loopExplorer.stalled`)}),t===`interrupted`&&(0,R.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-accent-warning/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-accent-warning`,children:c(`loopExplorer.interrupted`)}),(0,R.jsx)(`span`,{className:`flex-1`}),f?.durationMs!=null&&(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:Ke(f.durationMs)}),t===`failed`&&f?.exitCode!=null&&f.exitCode!==0&&(0,R.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:c(`activeJob.exitCode`,{code:f.exitCode})}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:c(`logViewer.phaseLines`,{count:d.length})})]}),b&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>S(e=>!e),"aria-label":c(`loopExplorer.stepDetail`),"aria-expanded":x,title:c(`loopExplorer.stepDetail`),className:E(`px-2 flex items-center transition-colors cursor-pointer`,x?`text-foreground bg-primary/10`:`text-muted-foreground/40 hover:text-foreground hover:bg-primary/10`),children:(0,R.jsx)(le,{className:`w-3 h-3`})}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(e.key),"aria-label":c(`loopExplorer.copyStep`),title:c(`loopExplorer.copyStep`),className:`px-2.5 flex items-center text-muted-foreground/40 hover:text-foreground hover:bg-primary/10 transition-colors cursor-pointer`,children:(0,R.jsx)(A,{className:`w-3 h-3`})})]}),x&&b&&(0,R.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:E(`px-4 py-2.5 space-y-2.5 bg-muted/10 border-b animate-in fade-in duration-150`,t===`failed`?`border-destructive/20`:`border-primary/10`),children:[u.template&&(0,R.jsx)(it,{label:c(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:c(`loopExplorer.copyCommand`)}),u.command&&(0,R.jsx)(it,{label:c(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:c(`loopExplorer.copyCommand`)})]}),!n&&(0,R.jsx)(`div`,{className:`bg-muted/5`,children:rt(v,r,c,s)})]})}var ot=(0,z.memo)(at,(e,t)=>e.segment.key===t.segment.key&&e.segment.lines.length===t.segment.lines.length&&e.segment.lines[e.segment.lines.length-1]?.content===t.segment.lines[t.segment.lines.length-1]?.content&&e.segment.meta.template===t.segment.meta.template&&e.segment.meta.command===t.segment.meta.command&&e.segment.end?.status===t.segment.end?.status&&e.segment.end?.durationMs===t.segment.end?.durationMs&&e.segment.end?.decision===t.segment.end?.decision&&e.segment.end?.exitCode===t.segment.end?.exitCode&&e.segment.lastActivity?.actionKey===t.segment.lastActivity?.actionKey&&e.segment.lastActivity?.actionArg===t.segment.lastActivity?.actionArg&&e.status===t.status&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket),J=`__setup__`;function st({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:a}){let{t:o}=l(`jobs`),s=nt(e,n);return(0,R.jsxs)(`div`,{ref:e=>i(J,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(J),className:`flex items-center gap-2 w-full text-left px-3 py-2 bg-muted/10 border-b border-border/20 hover:bg-muted/20 transition-colors duration-150 cursor-pointer`,children:[(0,R.jsx)(_,{className:E(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,R.jsx)(x,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,R.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:o(`loopExplorer.setup`)}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,R.jsx)(`div`,{className:`bg-muted/5`,children:rt(s,n,o,a)})]})}var ct=(0,z.memo)(st,(e,t)=>e.lines.length===t.lines.length&&e.lines[e.lines.length-1]?.content===t.lines[t.lines.length-1]?.content&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket);function Y(){return(0,R.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,R.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,R.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function lt({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i}){let{t:a,i18n:o}=l(`jobs`),[s,c]=(0,z.useState)(``),[u,d]=(0,z.useState)(`follow`),[f,m]=(0,z.useState)(new Set),h=(0,z.useRef)(null),g=(0,z.useRef)(new Map),_=De(i),v=(0,z.useMemo)(()=>Ve(e),[e,o.language]),y=t!=null&&t!==`running`&&t!==`queued`,b=t===`running`,x=(0,z.useMemo)(()=>v.segments.map((e,t)=>He(e,{isLast:t===v.segments.length-1,jobSettled:y})),[v,y]),S=(0,z.useMemo)(()=>{let e=v.segments.map(e=>e.key);return v.setup.length>0&&e.push(J),e},[v]),w=v.segments.length>0?v.segments[v.segments.length-1].key:J,T=(0,z.useMemo)(()=>s?new Set(S):u===`follow`?new Set([w]):f,[s,u,w,f,S]),D=(0,z.useRef)(T);D.current=T;let O=(0,z.useRef)(v);O.current=v;let j=(0,z.useCallback)(e=>{let t=new Set(D.current);e?.(t),m(t),d(`manual`)},[]),M=(0,z.useCallback)(e=>{j(t=>{t.has(e)?t.delete(e):t.add(e)})},[j]),N=(0,z.useCallback)(e=>{j(t=>t.add(e)),requestAnimationFrame(()=>{g.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[j]),P=(0,z.useCallback)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[]),te=(0,z.useCallback)(()=>{d(`follow`),requestAnimationFrame(P)},[P]),F=(0,z.useCallback)(()=>{m(new Set(S)),d(`manual`)},[S]),ne=(0,z.useCallback)(()=>{m(new Set),d(`manual`)},[]);(0,z.useEffect)(()=>{u===`follow`&&!s&&P()},[v.totalLines,v.segments.length,u,s,P]);let re=(0,z.useCallback)(()=>{let e=h.current;!e||u!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&j()},[u,j]),I=(0,z.useCallback)((e,t)=>{t?g.current.set(e,t):g.current.delete(e)},[]),ie=(0,z.useCallback)(e=>{let t=O.current.segments.find(t=>t.key===e),n=e===`__setup__`?O.current.setup.map(e=>e.content).join(`
17
- `):(t?.lines??[]).map(e=>e.content).join(`
18
- `);navigator.clipboard.writeText(n).then(()=>p.success(a(`loopExplorer.copied`))).catch(()=>p.error(a(`logViewer.copyFailed`)))},[a]),ae=(0,z.useCallback)(()=>{let e=O.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${G(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
19
- `)).then(()=>p.success(a(`logViewer.copySuccess`))).catch(()=>p.error(a(`logViewer.copyFailed`)))},[a]),oe=(0,z.useMemo)(()=>Ge(v,{jobSettled:y,jobFailed:t===`failed`}),[v,y,t]),se=v.graphMeta?.iterationLimit??v.graphMeta?.graph.config.maxIterations??null,ce=v.maxIteration>0?{current:v.maxIteration,limit:se}:null,le=(0,z.useMemo)(()=>{if(!s)return v.totalLines;let e=s.toLowerCase(),t=v.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of v.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[s,v]),L=v.segments[v.segments.length-1],ue=b&&(v.segments.length===0||L?.end!=null);return n?(0,R.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`logViewer.loading`)})}):v.totalLines===0&&v.segments.length===0?(0,R.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,R.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[b&&(0,R.jsx)(Y,{}),a(b?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,R.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex flex-col h-full`,children:[(0,R.jsxs)(`div`,{className:E(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,R.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,R.jsx)(C,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,R.jsx)(ee,{placeholder:a(`logViewer.filterPlaceholder`),value:s,onChange:e=>c(e.target.value),className:`pl-7 h-7`})]}),(0,R.jsx)(k,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:F,"aria-label":a(`loopExplorer.expandAll`),title:a(`loopExplorer.expandAll`),children:(0,R.jsx)(fe,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(k,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ne,"aria-label":a(`loopExplorer.collapseAll`),title:a(`loopExplorer.collapseAll`),children:(0,R.jsx)(de,{className:`w-3.5 h-3.5`})}),u===`follow`&&b&&(0,R.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,R.jsx)(Y,{}),a(`loopExplorer.follow`)]}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsx)(k,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ae,"aria-label":a(`logViewer.copySuccess`),children:(0,R.jsx)(A,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:a(`logViewer.lineCount`,{filtered:le,total:v.totalLines})})]}),v.completion&&(0,R.jsx)(qe,{result:v.completion}),(0,R.jsx)(et,{chips:oe,iteration:ce,onChipClick:N,variant:r}),(0,R.jsxs)(`div`,{ref:h,onScroll:re,className:`flex-1 overflow-y-auto p-2 text-xs`,children:[v.setup.length>0&&(0,R.jsx)(ct,{lines:v.setup,collapsed:!T.has(`__setup__`),filter:s,onToggle:M,setRef:I,onOpenTicket:_}),v.segments.map((e,t)=>(0,R.jsx)(ot,{segment:e,status:x[t],collapsed:!T.has(e.key),filter:s,onToggle:M,onCopy:ie,setRef:I,onOpenTicket:_},e.key)),ue&&(0,R.jsxs)(`div`,{"data-testid":`loop-waiting-row`,className:`mt-3 flex items-center gap-2 px-3 py-2 text-[11px] text-muted-foreground/70 italic`,children:[(0,R.jsx)(Y,{}),a(`loopExplorer.waiting`)]})]}),u===`manual`&&b&&!s&&(0,R.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:te,className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 rounded-full glass-card border border-accent-primary/30 px-3 py-1.5 text-[11px] font-medium text-foreground shadow-lg hover:border-accent-primary/60 transition-colors cursor-pointer animate-in fade-in slide-in-from-bottom-2 duration-200`,children:[(0,R.jsx)(Y,{}),a(`loopExplorer.resumeFollow`)]})]})}var ut=new Set(`grep.rg.ag.ack.find.fd.ls.cat.head.tail.sed.awk.cut.sort.uniq.wc.jq.yq.tr.xargs.tee.column.less.more.cd.pwd.echo.printf.which.type.test.true.false.env.export.set.source.date.basename.dirname.realpath.readlink.stat.file.tree.diff.sleep.seq.hostname.whoami.uname.mkdir.rmdir.cp.mv.rm.touch.ln.chmod.chown.install.[[.[.]].].for.while.until.if.then.else.elif.fi.do.done.case.esac.exec.eval.trap.read.shift.wait`.split(`.`)),dt=new Set([`status`,`diff`,`log`,`show`,`branch`,`rev-parse`,`ls-files`,`blame`,`describe`]),ft=new Set([...dt,`commit`,`add`,`stage`,`push`,`pull`,`fetch`,`checkout`,`switch`,`merge`,`rebase`,`reset`,`stash`,`tag`,`clone`,`worktree`,`cherry-pick`,`restore`,`apply`,`init`,`remote`,`config`,`update-ref`,`for-each-ref`]),pt=new Set([`run`,`run-script`,`test`,`install`,`ci`,`i`,`add`,`exec`,`start`,`dlx`]),mt=[[/^(test|tests|test:.*|vitest|jest|spec)$/,`activity.testing`],[/^(build|compile|bundle|dist)$/,`activity.building`],[/^(typecheck|tsc|types?)$/,`activity.typechecking`],[/^(lint|lint:.*|eslint|format|fmt|prettier)$/,`activity.linting`]],ht=new Set([`vitest`,`jest`,`pytest`,`mocha`,`ava`,`rspec`,`phpunit`]);function gt(e){for(let[t,n]of mt)if(t.test(e))return n;return null}function _t(e){return e.split(/\s+/).map(e=>e.replace(/^['"`]+/,``).replace(/['"`]+$/,``)).filter(e=>e.length>0&&!e.startsWith(`-`))}function vt(e){let t=_t(e);if(t.length===0)return{kind:`plumbing`};let n=t[0].split(`/`).pop()??t[0],r=t.slice(1);if(ut.has(n))return{kind:`plumbing`};if(ht.has(n))return{kind:`intent`,code:`activity.testing`};if((n===`npx`||n===`pnpm`||n===`yarn`||n===`bunx`)&&r.length>0){let e=r[0]===`dlx`||r[0]===`exec`?r[1]??``:r[0];if(ht.has(e))return{kind:`intent`,code:`activity.testing`};let t=gt(e===`run`?r[r.indexOf(`run`)+1]??``:e);if(t)return{kind:`intent`,code:t};if(e===`tsc`)return{kind:`intent`,code:`activity.typechecking`}}if(n===`npm`||n===`yarn`||n===`pnpm`||n===`bun`){let e=r.findIndex(e=>pt.has(e)),t=e===-1?``:r[e];if(t===`install`||t===`ci`||t===`i`||t===`add`)return{kind:`intent`,code:`activity.installing`};let i=gt(t===`run`||t===`run-script`?r[e+1]??``:t);return i?{kind:`intent`,code:i}:{kind:`named`,tool:n}}if(n===`git`){let e=r.find(e=>ft.has(e))??``;return dt.has(e)?{kind:`plumbing`}:e===`commit`||e===`add`||e===`stage`?{kind:`intent`,code:`activity.savingWork`}:{kind:`named`,tool:n}}if(n===`cargo`||n===`go`||n===`dotnet`||n===`mvn`||n===`gradle`){let e=r.find(e=>e===`test`||e===`build`||e===`compile`)??``;return e===`test`?{kind:`intent`,code:`activity.testing`}:e===`build`||e===`compile`?{kind:`intent`,code:`activity.building`}:{kind:`named`,tool:n}}return n===`tsc`?{kind:`intent`,code:`activity.typechecking`}:n===`openspec`?{kind:`intent`,code:`activity.checkingSpec`}:{kind:`named`,tool:n}}function X(e){try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}catch{return{}}}function yt(e,t){return e&&/^main-\d+$/.test(e)?`step.role.work`:e===`verify`?`step.role.verify`:e===`decide`||t===`decider`?`step.role.decide`:e===`fix`?`step.role.fix`:null}function bt(e){return e.replace(/^[^\p{L}\p{N}(]+/u,``).trim()}var Z=e=>typeof e==`number`&&Number.isFinite(e)?e:null,Q=e=>typeof e==`string`&&e.length>0?e:null,xt=new Set([`thinking`,`reasoning`]),St=/^(MEMORY\.md|confidence-score\.json|design-confidence\.json|\d{4}-\d{2}-\d{2}-.+|feedback_.+)$/,Ct=/^(proposal|design|tasks|spec|context-bundle)\.md$/,wt=new Set([`reading`,`writing`,`editing`]);function $(e,t,n,r,i){for(let t=e.length-1;t>=0;t--){let a=e[t];if(a.kind!==`activity`){if(a.stepIndex!==n)break;continue}if(a.stepIndex!==n)break;if(a.values.action===r&&a.values.target===i){a.values.repeats=Number(a.values.repeats??1)+1;return}}e.push({seq:t,kind:`activity`,code:r===`intent`?i:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,repeats:1},stepIndex:n,tone:`neutral`})}var Tt=new Set([`architect`,`developer`,`verify`,`reviewer`,`archive`]),Et=3;function Dt(e,t,n,r,i){for(let t=e.length-1;t>=0;t--){let a=e[t];if(a.stepIndex!==n)break;if(a.kind!==`activity`||a.values.action!==r||a.values.fileGroup!==1)continue;let o=String(a.values.allNames??``).split(`\0`).filter(Boolean),s=!!i&&!o.includes(i);s&&o.push(i),a.values.allNames=o.join(`\0`),a.values.files=o.length;let c=String(a.values.names??``).split(`, `).filter(Boolean);s&&c.length<Et&&(c.push(i),a.values.names=c.join(`, `)),a.code=o.length>1?`activity.${r}Files`:i?`activity.${r}`:`activity.${r}Bare`,a.values.repeats=o.length>1?1:Number(a.values.repeats??1)+1;return}e.push({seq:t,kind:`activity`,code:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,names:i,allNames:i,files:+!!i,fileGroup:1,repeats:1},stepIndex:n,tone:`neutral`})}function Ot({events:e,settled:t}){let n=[],r=new Map,i=null,a=!1,o=!1;for(let t of e){if(t.event_type===`loop_graph`){a=!0;continue}if(t.event_type===`loop_step`){let e=X(t.payload),o=Z(e.index);if(o===null)continue;a=!0;let s=Q(e.kind)??`ai-step`,c={index:o,title:bt(Q(e.title)??``),roleCode:yt(Q(e.nodeId),s),kind:s,iteration:Z(e.iteration),ended:!1};r.set(o,c),i=o;let l=Z(e.attempt);n.push({seq:t.seq,kind:`step-start`,code:l!==null&&l>1?`step.startResume`:c.iteration&&c.iteration>1?`step.startRetry`:`step.start`,values:{step:o,title:c.title,iteration:c.iteration??1,...l!==null&&l>1?{attempt:l}:{},...c.roleCode?{roleCode:c.roleCode}:{}},stepIndex:o,tone:`neutral`});continue}if(t.event_type===`loop_step_end`){let e=X(t.payload),i=Z(e.index);if(i===null)continue;let a=i===null?void 0:r.get(i);a&&(a.ended=!0);let o=Q(e.status),s=Z(e.durationMs),c=Z(e.exitCode),l=Z(e.idleMs),u=o===`stalled`,d=o===`failed`||u,f=o===`failed`&&Q(e.reason)===`provider_limit`;n.push({seq:t.seq,kind:`step-end`,code:u?`step.stalled`:f?`step.providerLimit`:d?`step.failed`:s===null?`step.done`:s>=9e4?`step.doneTimedMin`:`step.doneTimed`,values:{step:i,title:a?.title??``,seconds:s===null?0:Math.max(1,Math.round(s/1e3)),minutes:s===null?0:Math.max(1,Math.round(s/6e4)),...u?{idleMinutes:l===null?0:Math.max(1,Math.round(l/6e4))}:{},...a?.roleCode?{roleCode:a.roleCode}:{},...c===null?{}:{exitCode:c}},stepIndex:i,tone:d?`bad`:`good`});let p=Q(e.decision);(p===`continue`||p===`stop`)&&n.push({seq:t.seq,kind:`decision`,code:p===`continue`?`decision.another`:`decision.satisfied`,values:{step:i},stepIndex:i,tone:p===`continue`?`neutral`:`good`});continue}if(t.event_type===`workflow-event`){let e=X(t.payload),r=e.event&&typeof e.event==`object`&&!Array.isArray(e.event)?e.event:{},a=Q(r.type),s=Q(r.stepId);if(a===`step_started`&&s&&Tt.has(s)){let e=s===`developer`&&o;s===`developer`&&(o=!0),$(n,t.seq,i,`intent`,e?`activity.phase.corrections`:`activity.phase.${s}`)}else a===`step_succeeded`&&s===`verify`&&typeof r.message!=`string`||a===`step_blocked`||(a===`workflow_failed`||a===`workflow_blocked`||a===`workflow_cancelled`)&&n.push({seq:t.seq,kind:`activity`,code:`activity.phase.stopped`,values:{action:`intent`,target:Q(r.message)??a,repeats:1},stepIndex:i,tone:`bad`});continue}let e=ae(t);if(!(!e.step||!e.actionKey)&&!xt.has(e.actionKey)){if(e.actionKey===`running`){let r=oe(t),a=r?vt(r):{kind:`named`,tool:e.actionArg??``};if(a.kind===`plumbing`){$(n,t.seq,i,`exploring`,``);continue}if(a.kind===`intent`){$(n,t.seq,i,`intent`,a.code);continue}$(n,t.seq,i,`running`,a.tool);continue}if(wt.has(e.actionKey)){let r=e.actionArg??``;if(St.test(r)){$(n,t.seq,i,`intent`,`activity.bookkeeping`);continue}if(Ct.test(r)){$(n,t.seq,i,`intent`,`activity.writingSpec`);continue}Dt(n,t.seq,i,e.actionKey,r);continue}$(n,t.seq,i,e.actionKey,e.actionArg??``)}}if(t)for(let e of r.values())e.ended||n.push({seq:2**53-1-(1e3-e.index),kind:`step-interrupted`,code:`step.interrupted`,values:{step:e.index,title:e.title},stepIndex:e.index,tone:`bad`});return{milestones:n,stepCount:r.size,plainJob:!a}}var kt={"step-start":pe,"step-end":m,"step-interrupted":w,decision:re,activity:pe},At={neutral:`text-muted-foreground`,good:`text-accent-success`,bad:`text-accent-warning`};function jt({events:e,settled:t,durationRange:n,elapsedMs:r,variant:i=`page`}){let{t:a}=l(`narration`),o=(0,z.useMemo)(()=>Ot({events:e,settled:t}),[e,t]),s=(0,z.useMemo)(()=>[...o.milestones].sort((e,t)=>e.seq-t.seq),[o.milestones]);return(0,R.jsxs)(`div`,{className:i===`glass`?`flex h-full flex-col overflow-hidden`:`flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-b border-border/50 px-3 py-2 text-[11px] text-muted-foreground`,children:[typeof r==`number`&&r>0?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,R.jsx)(me,{className:`size-3`,"aria-hidden":!0}),a(`waiting.elapsed`,{minutes:Math.max(1,Math.round(r/6e4))})]}):null,n?(0,R.jsx)(`span`,{"data-testid":`narration-range`,children:a(`waiting.range`,{low:Math.max(1,Math.round(n.p25Ms/6e4)),high:Math.max(1,Math.round(n.p75Ms/6e4)),count:n.sampleCount})}):null,(0,R.jsx)(`span`,{className:`ml-auto italic opacity-70`,children:a(`aiNote`)})]}),(0,R.jsx)(`ol`,{className:`flex-1 space-y-1 px-3 py-2 ${i===`glass`?`overflow-y-auto`:``}`,"data-testid":`narration-list`,children:s.length===0?(0,R.jsx)(`li`,{className:`py-6 text-center text-xs text-muted-foreground`,children:a(t?`emptySettled`:`emptyLive`)}):s.map((e,t)=>{let n=kt[e.kind],r=e.kind===`step-start`||e.kind===`step-end`||e.kind===`step-interrupted`,i=Number(e.values.files??0)>1?1:Number(e.values.repeats??1);return(0,R.jsxs)(`li`,{className:`flex items-start gap-2 text-sm ${r?`font-medium text-foreground`:`text-muted-foreground`} ${e.kind===`step-start`&&t>0?`pt-2`:``}`,children:[(0,R.jsx)(n,{className:`mt-0.5 size-3.5 shrink-0 ${At[e.tone]}`,"aria-hidden":!0}),(0,R.jsxs)(`span`,{children:[e.kind===`step-start`&&typeof e.values.roleCode==`string`?a(e.code,{...e.values,title:a(e.values.roleCode),defaultValue:e.code}):a(e.code,{...e.values,defaultValue:e.code}),i>1?(0,R.jsx)(`span`,{className:`ml-1.5 text-[11px] opacity-70`,children:a(`repeats`,{count:i})}):null]})]},`${e.seq}-${e.code}-${t}`)})})]})}var Mt=`specrails-desktop:job-log-mode`;function Nt(){try{let e=localStorage.getItem(Mt);return e===`log`||e===`narrated`?e:`narrated`}catch{return`narrated`}}function Pt(e){try{localStorage.setItem(Mt,e)}catch{}}function Ft(e,t){switch(t.type){case`turn-user`:return{...e,streaming:!0,accepting:!0,queued:t.queued?e.queued+1:e.queued};case`turn-done`:{let n=Math.max(0,e.queued-1);return{...e,totals:t.totals,queued:n,streaming:e.queued>0}}case`finalized`:return{...e,streaming:!1,finalizing:!1,accepting:!1,queued:0,totals:t.totals??e.totals};case`accepting`:return t.accepting?{...e,accepting:!0}:{...e,accepting:!1,streaming:!1,queued:0};case`finalize-request`:return{...e,finalizing:!0};case`finalize-reject`:return{...e,finalizing:!1};case`blocked`:return{...e,accepting:!1,streaming:!1};default:return e}}function It(){try{return c()}catch{return null}}function Lt({jobId:e,projectId:t,settleMode:n,initialAcceptingTurns:r,kind:i=`job`,variant:a=`page`,onFinalized:o}){let{t:c}=l(`jobs`),u=n??`finalize`,f=()=>t?`${s}/api/projects/${t}`:d(),[m,h]=(0,z.useReducer)(Ft,{streaming:!1,queued:0,totals:null,accepting:r??!0,finalizing:!1}),[g,_]=(0,z.useState)(``),[v,y]=(0,z.useState)(!1),x=(0,z.useRef)(null);(0,z.useEffect)(()=>{r!==void 0&&h({type:`accepting`,accepting:r})},[r]);let S=(0,z.useRef)(o);S.current=o;let C=It(),w=(0,z.useId)();(0,z.useEffect)(()=>{if(!C)return;let t=`interactive-composer-${e}-${w}`;return C.registerHandler(t,t=>{let n=t;n.jobId===e&&(n.type===`job.turn_user`?h({type:`turn-user`,queued:!!n.queued}):n.type===`job.turn_done`?h({type:`turn-done`,totals:n.totals}):n.type===`job.finalized`?(h({type:`finalized`,totals:n.totals??null}),S.current?.()):n.type===`job.interactive`&&h({type:`accepting`,accepting:!!n.acceptingTurns}))}),()=>C.unregisterHandler(t)},[C,e,w]);let T=i===`loop-step`&&!m.accepting;async function D(){let t=g.trim();if(!(!t||v||T)){y(!0);try{let n=await fetch(`${f()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(n.ok)_(``),requestAnimationFrame(()=>x.current?.focus());else if(n.status===409&&i===`loop-step`)h({type:`blocked`});else{let e=await n.json().catch(()=>({}));p.error(c(`detail.toast.sendFailed`),{description:e.error})}}catch{p.error(c(`detail.toast.networkError`))}finally{y(!1)}}}async function O(){if(!m.finalizing){h({type:`finalize-request`});try{let t=await fetch(`${f()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)p.success(c(u===`finalize`?`detail.toast.finalizeScheduled`:i===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&i===`loop-step`)h({type:`blocked`}),h({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));p.error(c(`detail.toast.finalizeFailed`),{description:e.error}),h({type:`finalize-reject`})}}catch{p.error(c(`detail.toast.networkError`)),h({type:`finalize-reject`})}}}let A=v||T||!g.trim(),M=c(`detail.interactive.working`);return(0,R.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:E(`shrink-0 border-t px-3 py-2 space-y-1.5`,`motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-300`,a===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,R.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[T?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(he,{className:`h-3 w-3 motion-safe:animate-pulse`}),c(`detail.interactive.waitingForStepShort`)]}):m.streaming?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(b,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,R.jsxs)(`span`,{className:`relative`,children:[M,(0,R.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:M})]})]}):(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),c(`detail.interactive.ready`)]}),m.queued>0&&(0,R.jsx)(`span`,{className:`rounded-full border border-accent-info/30 bg-accent-info/10 px-1.5 py-px text-[10px] tabular-nums text-accent-info motion-safe:animate-in motion-safe:fade-in`,children:c(`detail.interactive.queued`,{count:m.queued})})]}),(0,R.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[m.totals&&(0,R.jsx)(`span`,{className:`tabular-nums`,children:c(`detail.interactive.liveTotals`,{turns:m.totals.num_turns,cost:m.totals.total_cost_usd.toFixed(4)})}),u===`finalize`?(0,R.jsxs)(L,{children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.jsxs)(k,{variant:`outline`,size:`sm`,onClick:()=>void O(),disabled:m.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,R.jsx)(F,{className:`mr-1.5 h-3.5 w-3.5`}),m.finalizing?c(`detail.finalizing`):c(`detail.finalizeJob`)]})}),(0,R.jsx)(j,{children:c(`detail.finalizeJobTooltip`)})]}):(0,R.jsxs)(L,{children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:()=>void O(),disabled:m.finalizing||T,className:E(`text-[11px] underline-offset-2 transition-colors`,T?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:m.finalizing?c(`detail.interactive.wrappingUp`):c(i===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,R.jsx)(j,{children:c(i===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),u===`auto`&&(0,R.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:c(T?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(`textarea`,{ref:x,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),D())},rows:2,placeholder:c(T?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":c(`detail.interactive.placeholder`),disabled:T,className:E(`flex-1 resize-none rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-sm transition-opacity focus:outline-none focus:ring-2 focus:ring-ring`,T&&`opacity-60`)}),(0,R.jsxs)(L,{children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.jsx)(`span`,{className:`shrink-0`,children:(0,R.jsxs)(k,{size:`sm`,onClick:()=>void D(),disabled:A,className:`h-9`,children:[(0,R.jsx)(ce,{className:`mr-1.5 h-3.5 w-3.5`}),c(`detail.interactive.send`)]})})}),A&&!v&&(0,R.jsx)(j,{children:c(T?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{lt as a,me as c,jt as i,Nt as n,Me as o,Pt as r,ge as s,Lt as t};
@@ -1 +0,0 @@
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{ct as i,it as a}from"./TicketDetailModalContext-DW3eQ0I7.js";import{a as o,c as s,l as c,m as l}from"./useSharedWebSocket-5mj2SMKn.js";import{n as u}from"./createLucideIcon-Bjbbp_KS.js";import{a as d,s as f}from"./useDesktop-Duv5ddAa.js";import{a as p,i as ee,n as m,o as h,r as g,s as _,t as te}from"./InteractiveJobComposer-l8q-r5Yy.js";import{t as v}from"./loader-circle-DcygOQpC.js";import{t as y}from"./x-CBMI9ejn.js";import{M as b,N as x,j as ne}from"./dialog-xXB2q5HJ.js";import{t as re}from"./formatDistanceToNow-Bq8iptrG.js";import{t as S}from"./button-Ccc9Dc-D.js";import{B as ie,H as ae,L as oe,R as se,S as ce,V as le,z as ue}from"./index-DOKftX7y.js";import{n as C,t as de}from"./job-time-BCL7wee9.js";var fe=e(r(),1),w=e(t(),1),T=[1e3,2e3,4e3,8e3,16e3];function E(e,t){let[n,r]=(0,w.useState)(`connecting`),i=(0,w.useRef)(t);return i.current=t,(0,w.useEffect)(()=>{let t=!1,n=!1,a=null,c=0,l=null;async function u(){if(!(t||n||a)){n=!0;try{await s()}catch{}finally{n=!1}!t&&!a&&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||a)return;let n=o(),s;try{s=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e)}catch{d();return}a=s,r(`connecting`),s.onopen=()=>{t||a!==s||(c=0,r(`connected`))},s.onmessage=e=>{if(!(t||a!==s))try{i.current(JSON.parse(e.data))}catch{}},s.onclose=()=>{t||a!==s||(a=null,d())}}let p=()=>{t||a||(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=a;if(a=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 pe(e,t){let n=C(e),r=C(t);if(!n||!r)return`—`;let i=r.getTime()-n.getTime();if(i<0)return`—`;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}var O={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`}};function k({jobId:e,onClose:t,projectId:n}){let{t:r}=u(`jobs`),{t:o}=u(`narration`),s=(0,w.useCallback)(()=>n?`${c}/api/projects/${n}`:d(),[n]),[T,k]=(0,w.useState)(m),A=(0,w.useCallback)(e=>{k(e),g(e)},[]),[j,M]=(0,w.useState)(null),[N,P]=(0,w.useState)([]),[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)(()=>{async function t(){try{let t=await fetch(`${s()}/jobs/${e}`);if(t.status===404){V(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let n=await t.json();if(M(n.job),P(n.events),n.phaseDefinitions){I(n.phaseDefinitions);let e={};for(let t of n.phaseDefinitions)e[t.key]=`idle`;R(e)}}catch{V(!0)}finally{B(!1)}}t()},[e,s]);let K=(0,w.useCallback)(()=>{fetch(`${s()}/jobs/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&M(e.job)}).catch(()=>{})},[e,s]),q=(0,w.useRef)([]),J=(0,w.useRef)(null),Y=(0,w.useCallback)(()=>{J.current=null;let e=q.current;e.length!==0&&(q.current=[],P(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,w.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),E(i,(0,w.useCallback)(t=>{let n=t;if(n.type===`event`&&n.jobId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:n.event_type,source:n.source,payload:n.payload,timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`log`&&n.processId===e){let t={id:Date.now(),job_id:e,seq:0,event_type:`log`,source:n.source,payload:JSON.stringify({line:n.line}),timestamp:n.timestamp};q.current.push(t),J.current||=requestAnimationFrame(Y)}else if(n.type===`job.finalized`&&n.jobId===e||n.type===`job.interactive`&&n.jobId===e||(n.type===`loop.run_paused`||n.type===`loop.run_resumed`)&&n.loopRunId===e)K();else if(n.type===`phase`){let e=n.phase,t=n.state;R(n=>({...n,[e]:t}))}else if(n.type===`queue`){let t=n.jobs?.find(t=>t.id===e);t&&j&&M(e=>e&&{...e,status:t.status})}},[e,j,Y,K])),(0,w.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let X=j?se(j):`job`,Z=X===`loop-run`;async function he(){G(!0);try{let t=await oe({projectId:n??null,jobId:e,kind:X});t.ok?(f.success(r(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:r(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):f.error(r(`modal.toast.cancelFailed`),{description:t.error})}finally{G(!1)}}let Q=j?O[j.status]??O.queued:O.queued,ge=j?.status===`running`,$=j?C(de(j)):null,{panelRef:_e,panelStyle:ve,headerHandleProps:ye,resizeHandles:be,isFloating:xe,guardBackdrop:Se}=b();return(0,fe.createPortal)((0,D.jsx)(le,{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:[j&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(ue,{children:[(0,D.jsx)(ae,{asChild:!0,children:(0,D.jsx)(`div`,{children:(0,D.jsx)(ce,{variant:Q.variant,children:r(Q.labelKey)})})}),(0,D.jsx)(ie,{children:r(Q.tooltipKey)})]}),(0,D.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:j.command}),(0,D.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:$?re($,{addSuffix:!0,locale:l()}):`—`}),j.total_cost_usd!=null&&j.total_cost_usd>0&&(0,D.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`$`,j.total_cost_usd.toFixed(4)]}),j.started_at&&j.finished_at&&(0,D.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:pe(j.started_at,j.finished_at)})]}),z&&(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`common:states.loading`)})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[F.length>0&&(0,D.jsx)(`div`,{className:`mr-3`,children:(0,D.jsx)(_,{phases:L,phaseDefinitions:F})}),ge&&(0,D.jsxs)(S,{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}),r(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}),(0,D.jsx)(`button`,{onClick:t,className:`h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,D.jsx)(y,{className:`w-4 h-4`})})]})]}),(0,D.jsx)(`div`,{className:`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:r(`modal.notFound`)})}):a&&j?(0,D.jsxs)(`div`,{className:`flex h-full 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:()=>A(e),"aria-pressed":T===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${T===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:o(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,D.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:T===`narrated`?(0,D.jsx)(ee,{events:N,settled:j.status!==`running`&&j.status!==`queued`,elapsedMs:j.duration_ms??null,variant:`glass`}):j.command.startsWith(`loop:`)?(0,D.jsx)(p,{events:N,jobStatus:j.status,isLoading:z,variant:`glass`,projectId:n}):(0,D.jsx)(h,{events:N,isLoading:z,projectId:n})})]}):j?.command.startsWith(`loop:`)?(0,D.jsx)(p,{events:N,jobStatus:j.status,isLoading:z,variant:`glass`,projectId:n}):(0,D.jsx)(h,{events:N,isLoading:z,projectId:n})}),!!j?.interactive&&j.status===`running`&&(0,D.jsx)(te,{jobId:e,projectId:n,settleMode:j.interactiveSettleMode,initialAcceptingTurns:j.interactiveAcceptingTurns,kind:j.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,D.jsx)(ne,{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:r(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:r(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,D.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,D.jsx)(S,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:r(`modal.keepRunning`)}),(0,D.jsx)(S,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),he()},children:r(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{k as JobDetailModal};
@@ -1 +0,0 @@
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{it as o,n as s}from"./TicketDetailModalContext-DW3eQ0I7.js";import{m as ee,r as c}from"./useSharedWebSocket-5mj2SMKn.js";import{n as l}from"./createLucideIcon-Bjbbp_KS.js";import{a as u,r as d,s as f}from"./useDesktop-Duv5ddAa.js";import{l as p,u as m}from"./MinimizedChatsContext-Dsv2eHf_.js";import{n as h}from"./file-text-BcLCfcWZ.js";import{a as g,c as _,i as te,n as v,o as y,r as ne,s as b,t as re}from"./InteractiveJobComposer-l8q-r5Yy.js";import{t as ie}from"./circle-x-CMYsN4ZH.js";import{t as x}from"./download-CFHyyHcw.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./utils-BC4DHlz2.js";import{t as ae}from"./formatDistanceToNow-Bq8iptrG.js";import{t as w}from"./button-Ccc9Dc-D.js";import{B as T,H as E,L as D,Mt as O,S as oe,St as k,dt as A,f as j,m as M,z as N}from"./index-DOKftX7y.js";import{n as P}from"./job-time-BCL7wee9.js";import{t as se}from"./format-command-C0D9IPmV.js";var F=e(t(),1),I=n();function L(e,t){let n=P(e),r=(typeof t==`number`?t:P(t)?.getTime()??NaN)-(n?.getTime()??NaN);if(!Number.isFinite(r)||r<0)return`—`;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60),o=i%60;return a<60?`${a}m ${o}s`:`${Math.floor(a/60)}h ${a%60}m`}function R(e){let t=new Set;for(let n of e)if(n.event_type===`log`)try{let e=(JSON.parse(n.payload).line??``).match(/(?:Writing|Editing|Created?|Updated?)\s+(?:file:\s*)?([\w./\-]+\.\w+)/i);e&&t.add(e[1])}catch{}return Array.from(t).slice(0,20)}var z={steps:0,actionKey:``,actionArg:``,lastSeenIdx:0};function B(e,t){if(t.type===`reset`)return z;if(t.type===`consume`){let{events:n}=t,r=e.lastSeenIdx>n.length?n.length:e.lastSeenIdx;if(n.length<=r)return r===e.lastSeenIdx?e:{...e,lastSeenIdx:r};let{steps:i,actionKey:a,actionArg:o}=e;for(let e=r;e<n.length;e++){let t=M(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``)}return{steps:i,actionKey:a,actionArg:o,lastSeenIdx:n.length}}return e}function ce({job:e,events:t,defaultOpen:n=!0,pipelineTotals:r,phases:i,phaseDefinitions:a}){let{t:o}=l(`jobs`),[s,ee]=(0,F.useState)(n),c=(0,F.useMemo)(()=>R(t),[t]),u=e.status===`running`,d=e.status===`completed`,[f,p]=(0,F.useState)(()=>Date.now());(0,F.useEffect)(()=>{if(!u)return;let e=window.setInterval(()=>p(Date.now()),1e3);return()=>window.clearInterval(e)},[u]);let[h,g]=(0,F.useReducer)(B,z),_=(0,F.useRef)(e.id);(0,F.useEffect)(()=>{_.current!==e.id&&(_.current=e.id,g({type:`reset`})),g({type:`consume`,events:t})},[e.id,t]);let[te,v]=(0,F.useState)(!0);(0,F.useEffect)(()=>{if(!u)return;v(!0);let e=window.setTimeout(()=>v(!1),8e3);return()=>window.clearTimeout(e)},[u,e.id]);let y=e.finished_at?L(e.started_at,e.finished_at):u?L(e.started_at,f):`—`,ne=!!e.total_cost_usd_estimated,b=e.total_cost_usd==null?null:`${ne?`~`:``}$${e.total_cost_usd.toFixed(4)}`,re=e.num_turns==null?null:String(e.num_turns),x=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0),ae=x==null?null:`${(x/1e3).toFixed(1)}k`,w=(0,F.useMemo)(()=>!i||!a?null:a.find(e=>i[e.key]===`running`)?.label??null,[i,a]),T=u&&h.steps===0?`connecting`:h.actionKey||`thinking`,E=j.has(T)&&h.actionArg!==``,D=j.has(T)&&!E?`working`:T,oe=E?o(`statusPanel.activity.${D}`,{arg:h.actionArg}):o(`statusPanel.activity.${D}`),k=w??(u&&h.steps===0?o(`statusPanel.activity.starting`):null),A=h.steps>0?o(`statusPanel.steps`,{count:h.steps}):null,M=o(u?`statusPanel.inProgress`:d?`statusPanel.completed`:`statusPanel.failed`),N=u?`border-accent-info/20 bg-accent-info/5`:d?`border-emerald-500/20 aurora-light:border-accent-success/30 bg-emerald-500/5 aurora-light:bg-accent-success/5`:`border-red-500/20 aurora-light:border-destructive/30 bg-red-500/5 aurora-light:bg-destructive/5`,P=u?S:d?O:ie,se=u?`w-4 h-4 text-accent-info shrink-0 animate-spin`:d?`w-4 h-4 text-emerald-400 aurora-light:text-accent-success shrink-0`:`w-4 h-4 text-red-400 aurora-light:text-destructive shrink-0`;return(0,I.jsxs)(`div`,{className:C(`mx-4 my-2 rounded-xl border transition-colors duration-500`,N),children:[(0,I.jsxs)(`button`,{type:`button`,onClick:()=>ee(!s),className:`w-full flex items-center gap-3 px-4 py-3`,children:[(0,I.jsx)(P,{className:se,"aria-hidden":`true`}),(0,I.jsx)(`span`,{className:`text-sm font-semibold flex-1 text-left`,children:M}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`tabular-nums`,children:y}),u?A&&(0,I.jsx)(`span`,{className:`tabular-nums`,children:A}):(0,I.jsxs)(I.Fragment,{children:[b&&(0,I.jsx)(`span`,{className:`tabular-nums text-yellow-400 aurora-light:text-accent-warning`,children:b}),c.length>0&&(0,I.jsx)(`span`,{children:o(`statusPanel.filesCount`,{count:c.length})})]})]}),(0,I.jsx)(m,{className:C(`w-4 h-4 text-muted-foreground/40 transition-transform duration-150 shrink-0`,s&&`rotate-180`)})]}),s&&(0,I.jsx)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/20`,children:u?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneInProgress`)}),(0,I.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 sm:items-stretch`,children:[(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 sm:w-44 shrink-0`,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[o(`statusPanel.duration`),(0,I.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,title:o(`statusPanel.liveTooltip`),"aria-label":o(`statusPanel.liveTooltip`)})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-accent-info`,children:y})]}),(0,I.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 bg-muted/10 rounded-lg px-3 py-2 min-w-0`,children:[(0,I.jsx)(S,{className:`w-3.5 h-3.5 text-accent-info shrink-0 animate-spin`,"aria-hidden":`true`}),k&&(0,I.jsx)(`span`,{className:`text-[11px] font-medium px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info shrink-0`,children:k}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1 min-w-0`,children:oe}),A&&(0,I.jsxs)(`span`,{className:`text-[11px] text-muted-foreground/60 tabular-nums shrink-0`,children:[`· `,A]})]})]}),te&&(0,I.jsx)(`p`,{className:`text-[11px] text-muted-foreground/40 leading-snug`,children:o(`statusPanel.explainer`)}),(0,I.jsx)(`p`,{className:`pt-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider border-t border-accent-info/10 mt-1`,children:o(`statusPanel.zoneFinalPending`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,I.jsx)(U,{label:o(`statusPanel.cost`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.costTooltip`)}),(0,I.jsx)(U,{label:o(`statusPanel.turns`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)}),(0,I.jsx)(U,{label:o(`statusPanel.tokens`),caption:o(`statusPanel.pendingCaption`),tooltip:o(`statusPanel.pendingTooltip`)})]})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{className:`pt-3 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:o(`statusPanel.zoneFinal`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[(0,I.jsx)(V,{label:o(`statusPanel.duration`),value:y}),(0,I.jsx)(H,{label:o(`statusPanel.cost`),value:b,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(H,{label:o(`statusPanel.turns`),value:re,naCaption:o(`statusPanel.notAvailable`)}),(0,I.jsx)(H,{label:o(`statusPanel.tokens`),value:ae,naCaption:o(`statusPanel.notAvailable`)})]}),r&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.pipelineTotal`,{count:r.jobCount})}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(V,{label:o(`statusPanel.totalCost`),value:r.costUnavailable?`—`:`${r.costEstimated?`~`:``}${r.hasNullCost?`≥`:``}$${r.totalCostUsd.toFixed(4)}`,valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,I.jsx)(V,{label:o(`statusPanel.totalTokens`),value:r.tokensUnavailable?`—`:`${(r.nullTokenCount??0)>0?`≥`:``}${((r.totalTokensIn+r.totalTokensOut+r.totalTokensCacheRead+r.totalTokensCacheCreate)/1e3).toFixed(1)}k`})]}),r.hasNullCost&&!r.costUnavailable&&(0,I.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:o(`statusPanel.pipelinePartialTooltip`),children:o(`statusPanel.pipelinePartial`,{count:r.nullCostCount??0})}),r.costUnavailable&&(0,I.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:o(`statusPanel.pipelineCostUnavailable`)}),(r.nullTokenCount??0)>0&&(0,I.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:o(`statusPanel.pipelineUsageTooltip`),children:r.tokensUnavailable?o(`statusPanel.pipelineUsageUnavailable`):o(`statusPanel.pipelineUsagePartial`,{count:r.nullTokenCount??0})})]}),c.length>0&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:o(`statusPanel.filesModified`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>(0,I.jsx)(`code`,{className:`text-[10px] font-mono bg-muted/30 px-2 py-0.5 rounded text-cyan-400/80 aurora-light:text-accent-info`,children:e},e))})]})]})})]})}function V({label:e,value:t,valueClass:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,n),children:t})]})}function H({label:e,value:t,valueClass:n,naCaption:r}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,I.jsx)(`p`,{className:C(`text-sm font-semibold tabular-nums mt-0.5`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:r})]})}function U({label:e,caption:t,tooltip:n}){return(0,I.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-3 py-2 ring-1 ring-accent-info/10`,title:n,children:[(0,I.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:[e,(0,I.jsx)(_,{className:`w-2.5 h-2.5 text-muted-foreground/30`,"aria-hidden":`true`})]}),(0,I.jsx)(`p`,{className:`text-sm font-semibold tabular-nums mt-0.5 text-muted-foreground/40`,children:`—`}),(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/30 mt-0.5`,children:t})]})}var W=4;function le({tickets:e,onTicketClick:t}){let{t:n}=l(`jobs`),[r,i]=(0,F.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,I.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-card/40 px-4 py-3 space-y-1.5`,children:[a.map(e=>(0,I.jsx)(ue,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showMore`,{count:o}),(0,I.jsx)(m,{className:`w-3 h-3`})]}),r&&e.length>=W&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showLess`),(0,I.jsx)(p,{className:`w-3 h-3`})]})]})}function ue({ticket:e,onClick:t}){let{t:n}=l(`jobs`),r=e.title==null,i=`inline-flex items-center px-1.5 py-0.5 rounded-md text-[11px] font-mono tabular-nums shrink-0`;return r?(0,I.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,I.jsx)(`span`,{className:C(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,I.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 min-w-0 w-full text-left group`,title:e.title??void 0,children:[(0,I.jsxs)(`span`,{className:C(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,I.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}var de={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`}};function G(){let{t:e}=l(`jobs`),{t}=l(`narration`),{id:n}=r(),{activeProjectId:p,projects:m}=d(),_=m.find(e=>e.id===p)?.provider,ie=a(),{openTicketDetail:S}=s(),[O,j]=(0,F.useState)(null),[M,P]=(0,F.useState)([]),[L,R]=(0,F.useState)([]),[z,B]=(0,F.useState)({}),[V,H]=(0,F.useState)([]),[U,W]=(0,F.useState)(!0),[ue,G]=(0,F.useState)(!1),[K,fe]=(0,F.useState)(v),[pe,q]=(0,F.useState)(null),me=(0,F.useCallback)(e=>{fe(e),ne(e)},[]),J=O?.command??null;(0,F.useEffect)(()=>{if(!o||K!==`narrated`||!p||!J)return;let e=!1,t=`command=${encodeURIComponent(J)}`;try{Promise.resolve(fetch(`${u()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||q(t?.range??null)}).catch(()=>{e||q(null)})}catch{q(null)}return()=>{e=!0}},[p,J,K]);let[he,Y]=(0,F.useState)(!1),X=(0,F.useRef)(!1),Z=(0,F.useRef)(null);(0,F.useEffect)(()=>{X.current=!1,Z.current=null,Y(!1)},[n]),(0,F.useEffect)(()=>{if(!n)return;let e=new AbortController;j(null),P([]),R([]),B({}),W(!0),G(!1);async function t(){try{let t=await fetch(`${u()}/jobs/${n}`,{signal:e.signal});if(t.status===404){G(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();j(r.job),P(r.events)}catch(e){if(e.name===`AbortError`)return;G(!0)}finally{e.signal.aborted||W(!1)}}return t(),()=>e.abort()},[n,p]),(0,F.useEffect)(()=>{if(!O?.pipeline_id){H([]);return}let e=O.pipeline_id;fetch(`${u()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&H(e.jobs)}).catch(()=>{})},[O?.pipeline_id,O?.status]);let ge=(0,F.useRef)(p);ge.current=p;let _e=(0,F.useRef)(null);_e.current=O?.status??null;let Q=(0,F.useRef)([]),$=(0,F.useRef)(null),ve=(0,F.useCallback)(()=>{$.current=null;let e=Q.current;e.length!==0&&(Q.current=[],P(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]),ye=(0,F.useCallback)(e=>{let t=Q.current;t.push(e),t.length>1e4&&(Q.current=t.slice(-8e3)),$.current||=requestAnimationFrame(ve)},[ve]);(0,F.useEffect)(()=>()=>{$.current&&cancelAnimationFrame($.current)},[]);let be=(0,F.useCallback)(e=>{let t=e;if(!(ge.current&&t.projectId&&t.projectId!==ge.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];R(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;B(n)}else if(t.type===`event`&&t.jobId===n){let e={id:Date.now(),job_id:n??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};ye(e)}else if(t.type===`log`&&t.processId===n){let e={id:Date.now(),job_id:n??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp};ye(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${u()}/jobs/${n}`).then(e=>e.json()).then(e=>j(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;B(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===n);if(e){let t=e.status,r=_e.current;j(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${u()}/jobs/${n}`).then(e=>e.json()).then(e=>j(e.job)).catch(()=>{})}}}},[n,ye]),{registerHandler:xe,unregisterHandler:Se}=c();(0,F.useEffect)(()=>(xe(`job-detail-${n}`,be),()=>Se(`job-detail-${n}`)),[n,be,xe,Se]),(0,F.useEffect)(()=>{if(!n||!O||O.status!==`running`||O.hasTelemetry)return;let e=setInterval(()=>{fetch(`${u()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&j(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,O?.status,O?.hasTelemetry]);async function Ce(){if(!n)return;let t=await D({projectId:null,jobId:n});t.ok?f.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):t.httpStatus===null?f.error(e(`detail.toast.networkError`)):f.error(e(`detail.toast.failed`),{description:t.error})}async function we(){if(O)try{let t=await fetch(`${u()}/jobs/${O.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-${O.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){f.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function Te(){if(!(!O||X.current)){X.current=!0,Y(!0),Z.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${O.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${u()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":Z.current},body:JSON.stringify({rerunOfJobId:O.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));Z.current=null,f.success(e(`detail.toast.jobRequeued`)),ie(`/jobs/${n.jobId}`)}catch(e){f.error(e.message)}finally{X.current=!1,Y(!1)}}}if(U)return(0,I.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,I.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,I.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(ue||!O)return(0,I.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,I.jsx)(w,{asChild:!0,variant:`outline`,size:`sm`,children:(0,I.jsxs)(i,{to:`/`,children:[(0,I.jsx)(k,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let Ee=de[O.status]??de.queued,De=O.status===`running`,Oe=O.status===`completed`||O.status===`failed`,ke=!!O.interactive,Ae=ke&&De,je=(O.tickets?.length??0)>0,Me=O.command.startsWith(`loop:`),Ne=V.length>1?{totalCostUsd:V.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:V.some(e=>e.total_cost_usd==null),costEstimated:V.some(e=>!!e.total_cost_usd_estimated),nullCostCount:V.filter(e=>e.total_cost_usd==null).length,costUnavailable:V.every(e=>e.total_cost_usd==null),totalTokensIn:V.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:V.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:V.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:V.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:V.filter(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null).length,tokensUnavailable:V.every(e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null),jobCount:V.length}:null;return(0,I.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,I.jsxs)(`div`,{className:`px-4 py-4 border-b border-border space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,I.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,I.jsx)(k,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,I.jsx)(h,{className:`w-3 h-3`}),(0,I.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),je&&(0,I.jsx)(le,{tickets:O.tickets??[],onTicketClick:S}),(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,I.jsxs)(N,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(oe,{variant:Ee.variant,children:e(Ee.labelKey)})})}),(0,I.jsx)(T,{children:e(Ee.tooltipKey)})]}),(0,I.jsx)(`code`,{className:C(`font-mono text-foreground/90 truncate`,je?`text-xs text-muted-foreground`:`text-sm`),children:se(O.command,_)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,I.jsx)(`span`,{children:O.started_at?e(`detail.startedAgo`,{timeAgo:ae(new Date(O.started_at),{addSuffix:!0,locale:ee()})}):e(`detail.queuedWaiting`)}),O.model&&(0,I.jsx)(`span`,{className:`text-muted-foreground/40`,children:O.model})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[O.hasTelemetry&&(0,I.jsxs)(N,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsxs)(w,{variant:`outline`,size:`sm`,className:`h-7`,onClick:we,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,I.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,I.jsx)(T,{children:e(`detail.exportDiagnosticTooltip`)})]}),Oe&&(0,I.jsxs)(N,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsxs)(w,{variant:`outline`,size:`sm`,onClick:Te,disabled:he,"aria-busy":he,className:`h-7`,children:[(0,I.jsx)(A,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,I.jsx)(T,{children:e(`detail.reExecuteTooltip`)})]}),De&&(0,I.jsxs)(N,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(w,{variant:`outline`,size:`sm`,onClick:Ce,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(ke?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,I.jsx)(T,{children:e(`detail.cancelJobTooltip`)})]})]})]}),(0,I.jsx)(b,{phases:z,phaseDefinitions:L})]}),(O.status===`running`||O.status===`completed`||O.status===`failed`)&&(0,I.jsx)(ce,{job:O,events:M,defaultOpen:O.status===`completed`||O.status===`running`,pipelineTotals:Ne??void 0,phases:z,phaseDefinitions:L}),(0,I.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:o?(0,I.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,I.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>me(e),"aria-pressed":K===e,"data-testid":`job-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`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,I.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:K===`narrated`?(0,I.jsx)(te,{events:M,settled:O.status!==`running`&&O.status!==`queued`,durationRange:pe,elapsedMs:O.duration_ms??null,variant:`page`}):Me?(0,I.jsx)(g,{events:M,jobStatus:O.status,variant:`page`}):(0,I.jsx)(y,{events:M})})]}):Me?(0,I.jsx)(g,{events:M,jobStatus:O.status,variant:`page`}):(0,I.jsx)(y,{events:M})}),Ae&&(0,I.jsx)(re,{jobId:O.id,settleMode:O.interactiveSettleMode,initialAcceptingTurns:O.interactiveAcceptingTurns,kind:O.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{G as default};
@@ -1 +0,0 @@
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}from"./useSharedWebSocket-5mj2SMKn.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,i as l,r as u,s as d}from"./useDesktop-Duv5ddAa.js";import{t as f}from"./circle-x-CMYsN4ZH.js";import{t as p}from"./trash-2-BOU3WdZZ.js";import{t as m}from"./triangle-alert-H9T4jAmh.js";import{t as h}from"./x-CBMI9ejn.js";import{M as g,a as _,i as v,j as y,l as b,o as x,r as ee,t as te}from"./dialog-xXB2q5HJ.js";import{n as ne,t as re}from"./lib-CGdyxIWg.js";import{t as S}from"./formatDistanceToNow-Bq8iptrG.js";import{t as C}from"./button-Ccc9Dc-D.js";import{B as w,H as T,Mt as E,S as ie,bt as ae,jt as D,t as O,z as k}from"./index-DOKftX7y.js";import{n as A,t as j}from"./job-time-BCL7wee9.js";import{t as oe}from"./format-command-C0D9IPmV.js";import{t as M}from"./ExportDropdown-B2C_XLGp.js";var se=s(`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`}]]),N=e(t(),1),P=n();function F(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 I(e){return e==null?`—`:e===0?`$0`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function L(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function R({label:e,a:t,b:n,highlight:r}){return(0,P.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 py-2 border-b border-border/20 last:border-0 text-xs`,children:[(0,P.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,P.jsx)(`span`,{className:`font-mono text-right ${r===`a`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:t}),(0,P.jsx)(`span`,{className:`font-mono text-right ${r===`b`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:n})]})}function z(e,t,n=!0){return e==null||t==null||e===t?null:n?e<t?`a`:`b`:e>t?`a`:`b`}function ce({jobIds:e,onClose:t}){let{t:n}=o(`jobs`),[r,i]=(0,N.useState)(null),[a,s]=(0,N.useState)(!0),[l,u]=(0,N.useState)(null),{panelRef:d,panelStyle:p,headerHandleProps:m,resizeHandles:_,isFloating:v,guardBackdrop:b}=g();(0,N.useEffect)(()=>{let t=new AbortController;return fetch(`${c()}/jobs/compare?jobIds=${e.join(`,`)}`,{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{i(e),s(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),s(!1))}),()=>t.abort()},[e]);function x(e,t){return(0,P.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-medium uppercase tracking-wider`,children:n(`comparison.jobN`,{n:t+1})}),(0,P.jsx)(`code`,{className:`text-[10px] text-foreground/70 block truncate max-w-[160px] mx-auto`,children:e.command}),(0,P.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-[10px]`,children:[e.status===`completed`?(0,P.jsx)(E,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,P.jsx)(f,{className:`w-3 h-3 text-rose-400 aurora-light:text-destructive`}),(0,P.jsx)(`span`,{className:`capitalize text-muted-foreground`,children:n(`statusLabel.${e.status}`,{defaultValue:e.status})})]}),(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-mono`,children:e.id.slice(0,8)})]})}return(0,P.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:b(t),children:[(0,P.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:p,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between ${v?`cursor-grab active:cursor-grabbing`:``}`,...m,children:[(0,P.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`comparison.title`)}),(0,P.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,P.jsx)(h,{className:`w-4 h-4`})})]}),a&&(0,P.jsx)(`div`,{className:`space-y-2`,children:[0,1,2,3].map(e=>(0,P.jsx)(`div`,{className:`h-8 bg-muted/20 rounded animate-pulse`},e))}),l&&(0,P.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:l})}),r&&(()=>{let[e,t]=r.jobs,i=z(e.durationMs,t.durationMs,!0),a=z(e.totalCostUsd,t.totalCostUsd,!0),o=z(e.tokensOut==null?null:e.tokensOut,t.tokensOut==null?null:t.tokensOut,!0);return(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 pb-3 border-b border-border/30 mb-1`,children:[(0,P.jsx)(`div`,{}),x(e,0),x(t,1)]}),(0,P.jsx)(R,{label:n(`comparison.duration`),a:F(e.durationMs),b:F(t.durationMs),highlight:i}),(0,P.jsx)(R,{label:n(`comparison.cost`),a:I(e.totalCostUsd),b:I(t.totalCostUsd),highlight:a}),(0,P.jsx)(R,{label:n(`comparison.tokensOut`),a:L(e.tokensOut),b:L(t.tokensOut),highlight:o}),(0,P.jsx)(R,{label:n(`comparison.tokensIn`),a:L(e.tokensIn),b:L(t.tokensIn),highlight:null}),(0,P.jsx)(R,{label:n(`comparison.cacheRead`),a:L(e.tokensCacheRead),b:L(t.tokensCacheRead),highlight:null}),(0,P.jsx)(R,{label:n(`comparison.model`),a:e.model??`—`,b:t.model??`—`,highlight:null}),(0,P.jsx)(R,{label:n(`comparison.phasesDone`),a:e.phasesCompleted.length>0?e.phasesCompleted.join(`, `):`—`,b:t.phasesCompleted.length>0?t.phasesCompleted.join(`, `):`—`,highlight:null})]})})(),r&&(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 text-center`,children:n(`comparison.betterValueHint`)})]}),(0,P.jsx)(y,{handles:_})]})}var le={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=A(e),r=A(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=A(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 B(e,t,n){if(!t&&!n)return!0;let r=A(e);if(!r)return!0;let i=r.getTime();return!(t&&i<ge(t)||n&&i>_e(n))}var V=10;function H({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:a,onProposalClick:s,onProposalDelete:l}){let{t:f}=o(`jobs`),h=r(),{activeProjectId:ne,projects:re}=u(),S=re.find(e=>e.id===ne)?.provider,[E,O]=(0,N.useState)(null),[A,M]=(0,N.useState)(``),[F,I]=(0,N.useState)(``),[L,R]=(0,N.useState)(!1),[z,H]=(0,N.useState)(``),[U,W]=(0,N.useState)(``),[G,ve]=(0,N.useState)(!1),[K,q]=(0,N.useState)(null),[J,ye]=(0,N.useState)(V),[Y,be]=(0,N.useState)(!1),[X,Z]=(0,N.useState)([]),[xe,Q]=(0,N.useState)(null),{panelRef:Se,panelStyle:Ce,headerHandleProps:we,resizeHandles:Te,isFloating:Ee,guardBackdrop:De}=g();(0,N.useEffect)(()=>{ye(V)},[e.length]);function Oe(){be(e=>!e),Z([])}function ke(e){Z(t=>{if(t.includes(e))return t.filter(t=>t!==e);if(t.length>=2)return t;let n=[...t,e];return n.length===2&&Q(n),n})}let $=e.filter(e=>E&&e.status!==E?!1:B(j(e),A,F)),Ae=e.filter(e=>B(j(e),z,U)).length;async function je(e){ve(!0);try{let t={};e===`range`&&(z&&(t.from=new Date(ge(z)).toISOString()),U&&(t.to=new Date(_e(U)).toISOString()));let n=await fetch(`${c()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();d.success(f(`recent.toast.cleared`,{count:e.deleted})),R(!1),H(``),W(``),a?.()}else d.error(f(`recent.toast.clearFailed`))}catch{d.error(f(`recent.toast.networkError`))}finally{ve(!1)}}let Me=n?(0,P.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,P.jsx)(m,{className:`h-4 w-4 shrink-0`}),(0,P.jsx)(`span`,{className:`flex-1`,children:f(`recent.loadFailed`)}),i&&(0,P.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:f(`common:actions.retry`)})]}):null;return n&&e.length===0?(0,P.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:Me}):t&&e.length===0?(0,P.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-1`,children:[0,1,2].map(e=>(0,P.jsx)(`div`,{className:`h-9 bg-muted/30 rounded-md animate-pulse`},e))}):e.length===0?(0,P.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 bg-card/50 p-8 text-center space-y-2`,children:[(0,P.jsx)(D,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,P.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:f(`recent.emptyTitle`)}),(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:f(`recent.emptyDescription`)})]}):(0,P.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-2`,children:[Me,(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>O(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${E===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterAll`,{count:e.length})}),ue.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,P.jsx)(`button`,{type:`button`,onClick:()=>O(E===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${E===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:f(`recent.filterStatus`,{status:f(`statusName.${t}`),count:n})},t)})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`input`,{type:`date`,value:A,onChange:e=>M(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.fromDate`)}),(0,P.jsx)(`input`,{type:`date`,value:F,onChange:e=>I(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:f(`recent.toDate`)}),(A||F)&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>{M(``),I(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:f(`recent.clear`)}),(0,P.jsxs)(k,{children:[(0,P.jsx)(T,{asChild:!0,children:(0,P.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,P.jsx)(se,{className:`w-3.5 h-3.5`})})}),(0,P.jsx)(w,{children:f(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,P.jsxs)(k,{children:[(0,P.jsx)(T,{asChild:!0,children:(0,P.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>R(!0),children:(0,P.jsx)(p,{className:`w-3.5 h-3.5`})})}),(0,P.jsx)(w,{children:f(`recent.clearJobs`)})]})]})]}),Y&&(0,P.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,P.jsxs)(`span`,{children:[X.length===0&&f(`recent.selectTwoToCompare`),X.length===1&&f(`recent.selectOneMore`),X.length===2&&f(`recent.readyToCompare`)]}),X.length===2&&(0,P.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:f(`recent.compareAction`)})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1 text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,P.jsx)(`span`,{className:`w-14`,children:f(`recent.colStatus`)}),(0,P.jsx)(`span`,{className:`flex-1 min-w-0`,children:f(`recent.colCommand`)}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,P.jsx)(`span`,{className:`w-14 text-right`,children:f(`recent.colDuration`)}),(0,P.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colTokens`)}),(0,P.jsx)(`span`,{className:`w-12 text-right`,children:f(`recent.colCost`)}),(0,P.jsx)(`span`,{className:`w-20 text-right`,children:f(`recent.colStarted`)})]})]}),(0,P.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=le[e.status]??le.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:`),o=a?e.id.replace(`proposal:`,``):null,c=X.includes(e.id),l=Y&&!a&&X.length===2&&!c,u=()=>{if(Y&&!a){ke(e.id);return}a&&o?s?.(o):h(`/jobs/${e.id}`)};return(0,P.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:u,onKeyDown:e=>{e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),u()))},children:[(0,P.jsxs)(k,{children:[(0,P.jsx)(T,{asChild:!0,children:(0,P.jsx)(`div`,{children:(0,P.jsx)(ie,{variant:t.variant,children:f(t.labelKey)})})}),(0,P.jsx)(w,{children:f(t.tooltipKey)})]}),e.priority&&e.priority!==`normal`&&(0,P.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border ${de[e.priority].className}`,children:f(de[e.priority].labelKey)}),e.profile_name&&(0,P.jsxs)(k,{children:[(0,P.jsx)(T,{asChild:!0,children:(0,P.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,P.jsx)(w,{children:f(`recent.profileTooltip`,{name:e.profile_name})})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[e.pipeline_id&&(0,P.jsxs)(k,{children:[(0,P.jsx)(T,{asChild:!0,children:(0,P.jsx)(ae,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,P.jsxs)(w,{children:[f(`recent.pipelinePart`),e.depends_on_job_id&&` ${f(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,P.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:oe(e.command,S)})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground shrink-0`,children:[(0,P.jsx)(`span`,{className:`w-14 text-right`,children:r??`—`}),(0,P.jsx)(`span`,{className:`w-12 text-right`,children:i?`${i}`:`—`}),(0,P.jsx)(`span`,{className:`w-12 text-right`,children:n??`—`}),(0,P.jsx)(`span`,{className:`w-20 text-right`,children:e.status===`queued`?`—`:he(e.started_at)}),a&&o&&(0,P.jsx)(`button`,{type:`button`,className:`w-4 h-4 md:opacity-0 md:group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-all`,onClick:e=>{e.stopPropagation(),q(o)},title:f(`recent.deleteProposal`),children:(0,P.jsx)(p,{className:`w-3 h-3`})})]})]},e.id)})}),$.length>J&&(0,P.jsx)(`div`,{className:`pt-1 text-center`,children:(0,P.jsx)(`button`,{type:`button`,onClick:()=>ye(e=>e+V),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:f(`recent.loadMore`,{count:$.length-J})})}),L&&(0,P.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>R(!1)),children:[(0,P.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,P.jsxs)(`div`,{...we,className:Ee?`cursor-grab active:cursor-grabbing`:void 0,children:[(0,P.jsx)(`h3`,{className:`text-sm font-semibold`,children:f(`recent.clearModal.title`)}),(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:f(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,P.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:G,onClick:()=>je(`all`),children:f(`recent.clearModal.clearAll`,{count:e.length})}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`recent.clearModal.orByRange`)}),(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(`input`,{type:`date`,value:z,onChange:e=>H(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.fromPlaceholder`)}),(0,P.jsx)(`input`,{type:`date`,value:U,onChange:e=>W(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:f(`recent.clearModal.toPlaceholder`)})]}),(0,P.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:G||!z&&!U,onClick:()=>je(`range`),children:z||U?f(`recent.clearModal.clearInRange`,{count:Ae}):f(`recent.clearModal.clearRange`)})]}),(0,P.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>R(!1),children:f(`common:actions.cancel`)})]}),(0,P.jsx)(y,{handles:Te})]}),(0,P.jsx)(te,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,P.jsxs)(ee,{className:`max-w-sm`,children:[(0,P.jsxs)(x,{children:[(0,P.jsx)(b,{children:f(`recent.deleteProposalConfirm.title`)}),(0,P.jsx)(v,{children:f(`recent.deleteProposalConfirm.description`)})]}),(0,P.jsxs)(_,{children:[(0,P.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:f(`common:actions.cancel`)}),(0,P.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&l?.(K),q(null)},children:f(`common:actions.delete`)})]})]})}),xe&&(0,P.jsx)(ce,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var U={input:`page.proposal.status.input`,exploring:`page.proposal.status.exploring`,review:`page.proposal.status.review`,refining:`page.proposal.status.refining`,creating_issue:`page.proposal.status.creatingIssue`,created:`page.proposal.status.created`,cancelled:`page.proposal.status.cancelled`};function W(e){return`${i}/api/projects/${encodeURIComponent(e)}`}function G(){let{t:e}=o(`jobs`),{activeProjectId:t}=u(),{recentJobs:n}=O(t),{data:r,isFirstLoad:i,isLoading:a,error:s,refresh:f}=l({namespace:`jobs`,projectId:t,initialValue:n,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4}),{data:p,isFirstLoad:m,isLoading:h,error:g,refresh:v}=l({namespace:`proposals`,projectId:t,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${W(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),y={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},S=p.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:y[e.status]??`queued`})),w=[...r,...S].sort((e,t)=>(A(j(t))?.getTime()??0)-(A(j(e))?.getTime()??0)),[T,E]=(0,N.useState)(null),ae=(0,N.useCallback)(async e=>{try{let t=await fetch(`${c()}/propose/${e}`);if(!t.ok)return;let n=await t.json();E(n.proposal)}catch{}},[]),D=(0,N.useCallback)(async t=>{try{(await fetch(`${c()}/propose/${t}`,{method:`DELETE`})).ok&&(d.success(e(`page.proposalDeleted`)),await v())}catch{}},[v,e]);return(0,P.jsxs)(`div`,{className:`max-w-4xl mx-auto px-4 py-6`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,P.jsx)(`h1`,{className:`text-sm font-semibold`,children:e(`page.title`)}),(0,P.jsx)(M,{baseUrl:`${c()}/jobs/export`,label:e(`page.exportJobs`)})]}),(0,P.jsx)(H,{jobs:w,isLoading:i||m||a||h,error:s??g,onRetry:()=>{Promise.all([f(),v()])},onJobsCleared:f,onProposalClick:ae,onProposalDelete:D}),(0,P.jsx)(te,{open:T!==null,onOpenChange:e=>!e&&E(null),children:(0,P.jsx)(ee,{className:`max-w-3xl glass-card`,children:T&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(x,{children:(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(b,{className:`flex-1 min-w-0`,children:e(`page.proposal.title`)}),(0,P.jsx)(ie,{variant:T.status===`created`?`success`:T.status===`cancelled`?`destructive`:`secondary`,children:e(U[T.status]??`page.proposal.status.unknown`,{status:T.status})})]})}),(0,P.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:T.idea}),T.result_markdown?(0,P.jsx)(`div`,{className:`max-h-[400px] overflow-y-auto rounded-lg px-3 py-2 text-xs bg-muted/40`,children:(0,P.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,P.jsx)(ne,{remarkPlugins:[re],children:T.result_markdown})})}):(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:e(`page.proposal.noContent`)}),T.issue_url&&(0,P.jsxs)(`div`,{className:`text-xs`,children:[e(`page.proposal.githubIssue`),` `,(0,P.jsx)(`a`,{href:T.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:T.issue_url})]}),(0,P.jsxs)(_,{children:[(0,P.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{D(T.id),E(null)},children:e(`common:actions.delete`)}),(0,P.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>E(null),children:e(`common:actions.close`)})]})]})})})]})}export{G as default};
@@ -1 +0,0 @@
1
- var e=`Motor de agentes`,t=`Arquitecto, desarrollador y revisor se ejecutan como fases separadas con verificación determinista entre ellas. Elige un proveedor por rol; todo lo demás tiene un valor por defecto que funciona.`,n=`Cargando configuración…`,r=`No se pudo cargar la configuración. Reintenta antes de modificarla.`,i=`Reintentar`,a=`Usar el motor de agentes para implementar`,o=`Guardar no inicia agentes. Al activarlo, las implementaciones de este proyecto usan el motor; los proyectos desactivados conservan su modo de ejecución actual.`,s=`Esta instalación de Core no incluye el motor de agentes. Actualiza Core antes de activarlo; puedes preparar la configuración mientras está desactivado.`,c=`Guardar configuración`,l=`Guardando…`,u=`Configuración guardada`,d=`No se pudo guardar la configuración.`,f=`Pausar para aprobación antes de completar el flujo`,p={title:`Proveedores`,hint:`Los proveedores CLI usan su sesión existente. Los proveedores API solo aceptan el nombre de una variable de entorno, nunca una clave. Los servicios locales pueden dejarlo vacío. Asigna otro proveedor al rol antes de eliminar el actual.`,entry:`Proveedor {{index}}`,id:`ID del proveedor`,kind:`Tipo de conexión`,cli:`CLI de programación instalado`,compatible:`API compatible con OpenAI`,command:`CLI de programación`,baseUrl:`URL base de la API`,apiKeyEnv:`Variable de entorno de la clave (opcional)`,remove:`Eliminar proveedor`,addCli:`Añadir proveedor CLI`,addLocal:`Añadir proveedor local / API`,show:`Mostrar conexiones de proveedores`,hide:`Ocultar conexiones de proveedores`},m={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},h={architect:`Arquitecto`,developer:`Desarrollador`,reviewer:`Revisor`,verify:`Verificación`,archive:`Finalización`},g={title:`Asignación de roles`,hint:`Cada rol ejecuta su propia sesión del proveedor. Deja el modelo en el predeterminado salvo que necesites uno concreto. Los turnos son las llamadas a herramientas que puede hacer un rol (por defecto {{turns}}).`,provider:`Proveedor`,model:`Modelo`,modelPlaceholder:`ID del modelo o predeterminado del CLI`,maxTurns:`Máximo de turnos (por defecto {{turns}})`,defaultModel:`Predeterminado ({{model}})`},_={title:`Límites del flujo`,hint:`Los campos vacíos usan los valores de Core: {{attempts}} intentos del desarrollador y {{minutes}} minutos por flujo. Los topes de tokens y USD son opcionales; el tope en USD requiere Claude en todos los roles.`,maxAttempts:`Máximo de intentos del desarrollador (por defecto {{attempts}})`,timeoutMinutes:`Tiempo máximo en minutos (por defecto {{minutes}})`,maxTokens:`Máximo de tokens`,maxCostUsd:`Coste máximo (USD)`,unlimited:`Sin límite`},v={title:`Comandos de verificación`,hint:`Opcional. Se ejecutan cuando el desarrollador termina y sus fallos vuelven al desarrollador. Si dejas la lista vacía, el arquitecto propone las comprobaciones propias del proyecto en cada ejecución; los repositorios sin comprobación automática se revisan igualmente.`,detect:`Detectar comprobaciones del proyecto`,detecting:`Detectando…`,detected:`Rellenado con las comprobaciones que este proyecto ya define.`,nothingDetected:`No se encontró ningún comando de test, comprobación de tipos o build. No pasa nada: el arquitecto propone comprobaciones en cada ejecución cuando es posible.`,detectFailed:`No se pudieron inspeccionar los repositorios del proyecto.`,repository:`Repositorio`,command:`Comando`,reason:`Detectado en {{reason}}`,remove:`Eliminar`,add:`Añadir comando`,invalidLine:`El comando de verificación está vacío o tiene comillas sin cerrar: {{line}}`},y={title:`Ejecuciones guardadas`,refresh:`Actualizar`,hint:`Continúa en el worktree original con el alcance y la configuración guardados; el progreso aparece en el registro de ese trabajo. No publica ni reinicia la entrega de Desktop. Las ejecuciones activas se detienen desde sus controles de trabajo.`,empty:`No hay ejecuciones guardadas.`,loadFailed:`No se pudieron cargar las ejecuciones.`,actionFailed:`No se pudo actualizar esta ejecución.`,phase:`Siguiente fase: {{phase}}`,approve:`Aprobar finalización`,recover:`Recuperar fase interrumpida`,resume:`Reanudar`,cancel:`Cancelar continuación`,status:{running:`Continuando…`,succeeded:`Completado`,failed:`Fallido`,blocked:`Bloqueado`,paused:`En pausa`,cancelled:`Cancelado`,interrupted:`Interrumpido`,unavailable:`No disponible`},question:`El arquitecto pregunta:`,answerLabel:`Tu respuesta`,answerPlaceholder:`Responde a la pregunta; el arquitecto continúa con ella.`,answer:`Responder y reanudar`},b={architect:`Lee el código y escribe la propuesta, el diseño, las tareas y la spec. Solo lectura.`,developer:`Implementa las tareas con tests. Puede editar archivos y ejecutar comandos dentro del sandbox del CLI.`,reviewer:`Comprueba el resultado contra la spec y la evidencia de verificación. Solo lectura.`},x={title:`Umbral de revisión`,hint:`Los campos vacíos usan el umbral de Core. Los valores solo pueden elevarlo: puntuación global mínima {{score}}, seguridad mínima {{security}}, resto de aspectos mínimo {{aspect}}.`,minScore:`Puntuación global mínima (por defecto {{score}})`,aspects:{type_correctness:`Corrección de tipos (por defecto {{score}})`,pattern_adherence:`Adhesión a patrones (por defecto {{score}})`,test_coverage:`Cobertura de pruebas (por defecto {{score}})`,security:`Seguridad (por defecto {{score}})`,architectural_alignment:`Alineación arquitectónica (por defecto {{score}})`}},S={title:`Confianza del arquitecto`,hint:`Tras una pasada de investigación autónoma, un diseño con confianza aún baja se pausa con la pregunta del arquitecto o continúa con supuestos declarados.`,onLowConfidence:`Con confianza baja`,ask:`Preguntar (pausar con la pregunta)`,proceed:`Continuar con supuestos declarados`},C={title:e,description:t,loading:n,loadFailed:r,retry:i,enabled:a,enableHint:o,unavailable:s,save:c,saving:l,saved:u,saveFailed:d,approvalBeforeArchive:f,providers:p,cliNames:m,roles:h,agents:g,limits:_,verification:v,runs:y,roleHints:b,review:x,architect:S};export{g as agents,f as approvalBeforeArchive,S as architect,m as cliNames,C as default,t as description,o as enableHint,a as enabled,_ as limits,r as loadFailed,n as loading,p as providers,i as retry,x as review,b as roleHints,h as roles,y as runs,c as save,d as saveFailed,u as saved,l as saving,e as title,s as unavailable,v as verification};
@@ -1 +0,0 @@
1
- var e=`エージェント実行エンジン`,t=`アーキテクト、デベロッパー、レビュアーが別々のフェーズとして実行され、その間に決定的な検証が入ります。役割ごとにプロバイダーを選ぶだけで、他はそのまま動く既定値です。`,n=`実行設定を読み込み中…`,r=`実行設定を読み込めませんでした。変更する前に再試行してください。`,i=`再試行`,a=`実装にエージェント実行エンジンを使用`,o=`保存してもエージェントは起動しません。有効にすると、このプロジェクトの実装は実行エンジンを使います。無効なプロジェクトは現在の実行方式を維持します。`,s=`この Core にはエージェント実行エンジンが含まれていません。有効にする前に Core を更新してください。無効な状態で設定を準備できます。`,c=`実行設定を保存`,l=`保存中…`,u=`実行設定を保存しました`,d=`実行設定を保存できませんでした。`,f=`ワークフロー完了前に承認を待つ`,p={title:`プロバイダー`,hint:`CLI は既存のログインを使用します。API には環境変数名のみを指定し、キー自体は入力しないでください。ローカルの場合は空欄にできます。削除前に役割を別のプロバイダーに割り当ててください。`,entry:`プロバイダー {{index}}`,id:`プロバイダー ID`,kind:`接続方式`,cli:`インストール済みの開発 CLI`,compatible:`OpenAI 互換エンドポイント`,command:`開発 CLI`,baseUrl:`API ベース URL`,apiKeyEnv:`API キーの環境変数(任意)`,remove:`プロバイダーを削除`,addCli:`CLI プロバイダーを追加`,addLocal:`ローカル / API プロバイダーを追加`,show:`プロバイダー接続を表示`,hide:`プロバイダー接続を隠す`},m={claude:`Claude`,codex:`Codex`,gemini:`Gemini`,kimi:`Kimi`},h={architect:`設計担当`,developer:`開発担当`,reviewer:`レビュー担当`,verify:`検証`,archive:`完了`},g={title:`役割の割り当て`,hint:`各役割は独自のプロバイダーセッションで実行されます。特定のモデルが必要な場合以外は既定のままにしてください。ターン数は役割が行えるツール呼び出しの回数です(既定 {{turns}})。`,provider:`プロバイダー`,model:`モデル`,modelPlaceholder:`モデル ID または CLI の既定値`,maxTurns:`最大ターン数(既定 {{turns}})`,defaultModel:`既定({{model}})`},_={title:`ワークフローの制限`,hint:`空欄は Core の既定値を使います: デベロッパーの試行 {{attempts}} 回、ワークフローあたり {{minutes}} 分。トークンと USD の上限は任意で、USD 上限にはすべての AI 役割で Claude が必要です。`,maxAttempts:`デベロッパーの最大試行回数(既定 {{attempts}})`,timeoutMinutes:`タイムアウト(分、既定 {{minutes}})`,maxTokens:`最大トークン数`,maxCostUsd:`最大コスト(USD)`,unlimited:`制限なし`},v={title:`検証コマンド`,hint:`任意。デベロッパー完了後に実行され、失敗はデベロッパーに戻されます。空のままなら、毎回アーキテクトがプロジェクト自身のチェックを提案します。自動チェックのないリポジトリもレビューされます。`,detect:`プロジェクトのチェックを検出`,detecting:`検出中…`,detected:`このプロジェクトが定義済みのチェックで埋めました。`,nothingDetected:`テスト・型チェック・ビルドのコマンドは見つかりませんでした。問題ありません。可能な場合はアーキテクトが実行時にチェックを提案します。`,detectFailed:`プロジェクトのリポジトリを調べられませんでした。`,repository:`リポジトリ`,command:`コマンド`,reason:`{{reason}} から検出`,remove:`削除`,add:`コマンドを追加`,invalidLine:`検証コマンドが空か、引用符が閉じていません: {{line}}`},y={title:`保存された実行`,refresh:`更新`,hint:`元のワークツリーで保存された範囲と設定を使って続行し、進行状況はそのジョブのログに表示されます。公開や Desktop の配信再開は行いません。実行中のレールはジョブの操作から停止してください。`,empty:`保存された実行はありません。`,loadFailed:`保存された実行を読み込めませんでした。`,actionFailed:`この実行を更新できませんでした。`,phase:`次のフェーズ: {{phase}}`,approve:`完了を承認`,recover:`中断したフェーズを復旧`,resume:`再開`,cancel:`続行をキャンセル`,status:{running:`続行中…`,succeeded:`成功`,failed:`失敗`,blocked:`ブロック中`,paused:`一時停止`,cancelled:`キャンセル済み`,interrupted:`中断`,unavailable:`利用不可`},question:`アーキテクトからの質問:`,answerLabel:`あなたの回答`,answerPlaceholder:`質問に回答すると、アーキテクトはそれをもとに続行します。`,answer:`回答して再開`},b={architect:`コードを読み、提案・設計・タスク・仕様を書きます。読み取り専用。`,developer:`タスクをテスト付きで実装します。CLI のサンドボックス内でファイル編集とコマンド実行ができます。`,reviewer:`仕様と検証結果に照らして成果を確認します。読み取り専用。`},x={title:`レビュー基準`,hint:`空欄は Core の基準を使います。値は基準を厳しくする方向にのみ設定できます: 総合スコア {{score}} 以上、セキュリティ {{security}} 以上、その他の観点 {{aspect}} 以上。`,minScore:`最低総合スコア(既定 {{score}})`,aspects:{type_correctness:`型の正確さ(既定 {{score}})`,pattern_adherence:`パターン準拠(既定 {{score}})`,test_coverage:`テストカバレッジ(既定 {{score}})`,security:`セキュリティ(既定 {{score}})`,architectural_alignment:`アーキテクチャ整合性(既定 {{score}})`}},S={title:`アーキテクトの確信度`,hint:`自律的な調査を1回行っても確信度が低い設計は、アーキテクトの質問で一時停止するか、明示した前提のもとで続行します。`,onLowConfidence:`確信度が低いとき`,ask:`質問する(質問で一時停止)`,proceed:`明示した前提で続行`},C={title:e,description:t,loading:n,loadFailed:r,retry:i,enabled:a,enableHint:o,unavailable:s,save:c,saving:l,saved:u,saveFailed:d,approvalBeforeArchive:f,providers:p,cliNames:m,roles:h,agents:g,limits:_,verification:v,runs:y,roleHints:b,review:x,architect:S};export{g as agents,f as approvalBeforeArchive,S as architect,m as cliNames,C as default,t as description,o as enableHint,a as enabled,_ as limits,r as loadFailed,n as loading,p as providers,i as retry,x as review,b as roleHints,h as roles,y as runs,c as save,d as saveFailed,u as saved,l as saving,e as title,s as unavailable,v as verification};