specrails-desktop 2.61.0 → 2.63.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.
- package/cli/dist/specrails-desktop.js +39 -5
- package/client/dist/assets/ActivityFeedPage-Bn2MpG5M.js +1 -0
- package/client/dist/assets/{AgentBrowserCapture-CkNWDZT3.js → AgentBrowserCapture-CHlXWdXq.js} +1 -1
- package/client/dist/assets/AgentModeAnalyticsPane-yj-YCgrK.js +2 -0
- package/client/dist/assets/AgentModeCodePane-Xczcyghb.js +2 -0
- package/client/dist/assets/{AgentModeJobsPane-U1J6PaBo.js → AgentModeJobsPane-DtOW01ln.js} +1 -1
- package/client/dist/assets/AgentsPage-BMfJ4mzU.js +118 -0
- package/client/dist/assets/AnalyticsPage-CGn5cgtc.js +1 -0
- package/client/dist/assets/BarChart-BDMqVFJy.js +55 -0
- package/client/dist/assets/CodePage-C8NIginr.js +3 -0
- package/client/dist/assets/DesktopAnalyticsPage-C87r4y26.js +1 -0
- package/client/dist/assets/{DocsDialog-CSlMPemn.js → DocsDialog-Z50a_KPv.js} +1 -1
- package/client/dist/assets/{DocsPage-BKlYAvWq.js → DocsPage-DIArbEPl.js} +1 -1
- package/client/dist/assets/{ExportDropdown-CweP_1GP.js → ExportDropdown-CJdCqYd7.js} +1 -1
- package/client/dist/assets/IntegrationsPage-EAipiDWm.js +1 -0
- package/client/dist/assets/InteractiveJobComposer-BxLh4me-.js +19 -0
- package/client/dist/assets/{JobDetailModal-DYyGq1Vp.js → JobDetailModal-C7dWoRu6.js} +1 -1
- package/client/dist/assets/JobDetailPage-Ilu294WS.js +1 -0
- package/client/dist/assets/JobsPage-fPq1hefb.js +1 -0
- package/client/dist/assets/LoopBuilderPage-5M7IypEP.js +1 -0
- package/client/dist/assets/{LoopPreviewModal-DkLRfsYX.js → LoopPreviewModal-ChI3NQC7.js} +1 -1
- package/client/dist/assets/{LoopWindowSurface-CuACkXFV.js → LoopWindowSurface-D1WB9i-9.js} +1 -1
- package/client/dist/assets/LoopsPage-CCwc0Biu.js +2 -0
- package/client/dist/assets/MinimizedChatsContext-eH_KaAZ1.js +1 -0
- package/client/dist/assets/PluginsPage-DfDfEfbW.js +2 -0
- package/client/dist/assets/ProjectSettingsDialog-9NHnG8JQ.js +1 -0
- package/client/dist/assets/RepositoryDeliveries-DgzNnJmn.js +5 -0
- package/client/dist/assets/{RepositoryScopeSelector-CeCr6Jz-.js → RepositoryScopeSelector-BSgUqk_u.js} +1 -1
- package/client/dist/assets/ReviewPacketPage-D34bGpSA.js +4 -0
- package/client/dist/assets/{TemplatePreviewModal-B8yd1AGU.js → TemplatePreviewModal-CcfSxWQ7.js} +1 -1
- package/client/dist/assets/TicketDetailModalContext-BoafEcm4.js +16 -0
- package/client/dist/assets/Trans-CVSryAL1.js +1 -0
- package/client/dist/assets/agent-5bSixVzz.js +1 -0
- package/client/dist/assets/agent-BR4EHfhq.js +1 -0
- package/client/dist/assets/agent-C0IKkJP8.js +1 -0
- package/client/dist/assets/agent-C7li9ayC.js +1 -0
- package/client/dist/assets/agent-D0dRmEen.js +1 -0
- package/client/dist/assets/{agent-BjttZLIl.js → agent-DZVGHm7H.js} +1 -1
- package/client/dist/assets/agent-Dip4h2YE.js +1 -0
- package/client/dist/assets/agent-Pp-P-n1p.js +1 -0
- package/client/dist/assets/ban-wqfdzoXt.js +1 -0
- package/client/dist/assets/{button-D1xExSTF.js → button-4FS1ZDTp.js} +1 -1
- package/client/dist/assets/chevron-up-6EFqEHBj.js +1 -0
- package/client/dist/assets/chunk-OB3PAWPO-B1EMk45A.js +3 -0
- package/client/dist/assets/circle-x-D2ttKotB.js +1 -0
- package/client/dist/assets/createLucideIcon-DtODIU64.js +1 -0
- package/client/dist/assets/{dialog-CMgps2MY.js → dialog-DtdR05v1.js} +1 -1
- package/client/dist/assets/download-C9wP_42h.js +1 -0
- package/client/dist/assets/external-link-CZ6Q-v1-.js +1 -0
- package/client/dist/assets/file-text-C0blZHLh.js +1 -0
- package/client/dist/assets/{formatDistanceToNow-DZ3VWsHq.js → formatDistanceToNow-NVM6rK3i.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-9JiGlFrx.js → getTimezoneOffsetInMilliseconds-ZHg7WpdH.js} +1 -1
- package/client/dist/assets/git-branch-yf6LE1Bw.js +1 -0
- package/client/dist/assets/index-Culan6y7.js +83 -0
- package/client/dist/assets/index-D1v33giW.css +2 -0
- package/client/dist/assets/jira-api-Bl8xEIpk.js +1 -0
- package/client/dist/assets/jsx-runtime-BbYvbtY8.js +1 -0
- package/client/dist/assets/layers-BCLTgHXO.js +1 -0
- package/client/dist/assets/{lib-C7Mhm-gT.js → lib-CQJT8S6Q.js} +1 -1
- package/client/dist/assets/{lib-CGdyxIWg.js → lib-DWJfei6y.js} +1 -1
- package/client/dist/assets/loader-circle-BqV9xYGf.js +1 -0
- package/client/dist/assets/{loop-layout-BF8xMiNv.js → loop-layout-CyXj9223.js} +1 -1
- package/client/dist/assets/pencil-CxrRbDwb.js +1 -0
- package/client/dist/assets/plus-fHDdjBk1.js +1 -0
- package/client/dist/assets/{project-repositories-CadLZOnr.js → project-repositories-CvJf1a6H.js} +1 -1
- package/client/dist/assets/react-dom-DDD8FYaU.js +1 -0
- package/client/dist/assets/rotate-ccw-DalJAQQX.js +1 -0
- package/client/dist/assets/save-LmPSfsvZ.js +1 -0
- package/client/dist/assets/search-BDVp3fkH.js +1 -0
- package/client/dist/assets/{settings-Dn-pXukr.js → settings-BO2N-oPf.js} +1 -1
- package/client/dist/assets/{settings-ByVE7jdZ.js → settings-BQChAs_w.js} +1 -1
- package/client/dist/assets/{settings-BBj_kZaD.js → settings-BzmYlcQB.js} +1 -1
- package/client/dist/assets/{settings-COlH_P33.js → settings-CGjXb6TX.js} +1 -1
- package/client/dist/assets/{settings-D77mC_Lb.js → settings-CMxEWY46.js} +1 -1
- package/client/dist/assets/{settings-DZKy7MqN.js → settings-C_dRSgI2.js} +1 -1
- package/client/dist/assets/{settings-B5Hy_Kol.js → settings-Hw7av-B1.js} +1 -1
- package/client/dist/assets/settings-nryN6wuS.js +1 -0
- package/client/dist/assets/sparkles-CCfUdFGY.js +1 -0
- package/client/dist/assets/spending-BfjSJjBd.js +1 -0
- package/client/dist/assets/square-D0JTbRSR.js +1 -0
- package/client/dist/assets/trash-D8zYUmTg.js +1 -0
- package/client/dist/assets/triangle-alert-Cxpn8bqr.js +1 -0
- package/client/dist/assets/upload-CCHvUkRs.js +1 -0
- package/client/dist/assets/{useDesktop-DKNbOF0u.js → useDesktop-C5JVBeur.js} +1 -1
- package/client/dist/assets/{useRuntimeRuns-D3YMw9qx.js → useRuntimeRuns-DohBmeg8.js} +1 -1
- package/client/dist/assets/useSharedWebSocket-CNOvmgTr.js +2 -0
- package/client/dist/assets/{value-s-gzBeyF.js → value-DtOOK0wQ.js} +1 -1
- package/client/dist/assets/x-Bu7X_eR2.js +1 -0
- package/client/dist/assets/zap-bugHyWzQ.js +1 -0
- package/client/dist/index.html +44 -41
- package/docs/ci-cd.md +8 -1
- package/docs/customizing.md +1 -0
- package/docs/getting-started.md +1 -1
- package/docs/guide/de/integrations/6-agent-chat.md +11 -0
- package/docs/guide/de/settings/5-project-environment.md +27 -0
- package/docs/guide/en/integrations/6-agent-chat.md +11 -0
- package/docs/guide/en/settings/5-project-environment.md +27 -0
- package/docs/guide/es/integrations/6-agent-chat.md +11 -0
- package/docs/guide/es/settings/5-project-environment.md +27 -0
- package/docs/guide/fr/integrations/6-agent-chat.md +11 -0
- package/docs/guide/fr/settings/5-project-environment.md +27 -0
- package/docs/guide/it/integrations/6-agent-chat.md +11 -0
- package/docs/guide/it/settings/5-project-environment.md +27 -0
- package/docs/guide/ja/integrations/6-agent-chat.md +11 -0
- package/docs/guide/ja/settings/5-project-environment.md +27 -0
- package/docs/guide/pt/integrations/6-agent-chat.md +11 -0
- package/docs/guide/pt/settings/5-project-environment.md +27 -0
- package/docs/guide/zh/integrations/6-agent-chat.md +11 -0
- package/docs/guide/zh/settings/5-project-environment.md +27 -0
- package/docs/internals/README.md +1 -0
- package/docs/internals/agent-sessions.md +157 -0
- package/docs/internals/api-reference.md +35 -4
- package/docs/internals/configuration.md +80 -5
- package/docs/internals/core-runtime-updates.md +10 -3
- package/docs/internals/operations-runbook.md +11 -0
- package/docs/internals/programmatic-agent-runtime.md +1 -1
- package/docs/internals/safe-pr-review-flow.md +15 -0
- package/docs/internals/source-map.md +42 -1
- package/docs/mcp.md +1 -1
- package/docs/platforms/macos.md +2 -0
- package/docs/platforms/windows-parity.md +4 -4
- package/docs/platforms/windows.md +9 -9
- package/local-runner/dist/specrails-local-runner.js +1 -1
- package/mcp-bridge/dist/specrails-mcp.js +82 -15
- package/package.json +8 -9
- package/server/dist/agent-mcp-config.js +41 -0
- package/server/dist/core-compat.js +2 -0
- package/server/dist/desktop-db.js +101 -4
- package/server/dist/desktop-router.js +31 -2
- package/server/dist/index.js +58 -0
- package/server/dist/mcp/tools/app-settings.js +11 -0
- package/server/dist/mcp/tools/env.js +38 -3
- package/server/dist/mcp/tools/mission.js +45 -2
- package/server/dist/mcp/tools/specs.js +2 -2
- package/server/dist/modules/accounting/runtime/result-event.js +9 -1
- package/server/dist/modules/agent-runtime/runtime/agent-runtime-controls.js +25 -0
- package/server/dist/modules/agent-sessions/adapters/host-process.js +73 -0
- package/server/dist/modules/agent-sessions/adapters/http.js +31 -0
- package/server/dist/modules/agent-sessions/adapters/rpc-client.js +147 -0
- package/server/dist/modules/agent-sessions/application/session-event-pump.js +99 -0
- package/server/dist/modules/agent-sessions/domain/availability.js +25 -0
- package/server/dist/modules/agent-sessions/domain/errors.js +23 -0
- package/server/dist/modules/agent-sessions/domain/host-state.js +80 -0
- package/server/dist/modules/agent-sessions/domain/projection.js +147 -0
- package/server/dist/modules/agent-sessions/domain/protocol.js +59 -0
- package/server/dist/modules/agent-sessions/domain/subagent-policy.js +34 -0
- package/server/dist/modules/agent-sessions/index.js +31 -0
- package/server/dist/modules/agent-sessions/ports.js +2 -0
- package/server/dist/modules/agent-sessions/runtime/core-sessions-availability.js +43 -0
- package/server/dist/modules/agent-sessions/runtime/session-host-registry.js +226 -0
- package/server/dist/modules/agents/runtime/agent-store.js +3 -1
- package/server/dist/modules/execution/runtime/queue-manager.js +8 -0
- package/server/dist/modules/loops/runtime/loop-executors.js +1 -0
- package/server/dist/modules/loops/runtime/loop-implement-recipe.js +15 -4
- package/server/dist/modules/loops/runtime/loop-run-manager.js +11 -0
- package/server/dist/modules/missions/runtime/agent-chat-manager.js +137 -40
- package/server/dist/modules/missions/runtime/agent-chat-router.js +68 -0
- package/server/dist/modules/missions/runtime/agent-operator-prompt.js +8 -9
- package/server/dist/modules/missions/runtime/agent-session-store.js +133 -0
- package/server/dist/modules/missions/runtime/core-session-runner.js +204 -0
- package/server/dist/modules/missions/runtime/mission-core-sessions.js +286 -0
- package/server/dist/modules/missions/runtime/mission-session-projector.js +168 -0
- package/server/dist/modules/project-settings/adapters/http.js +38 -2
- package/server/dist/modules/project-settings/adapters/sqlite.js +30 -2
- package/server/dist/modules/project-settings/domain.js +24 -0
- package/server/dist/modules/project-settings/index.js +2 -1
- package/server/dist/modules/specs/runtime/spec-models.js +1 -1
- package/server/dist/path-resolver.js +135 -20
- package/server/dist/plugins/codex-spawn.js +15 -7
- package/server/dist/project-env.js +265 -17
- package/server/dist/project-registry.js +46 -0
- package/server/dist/project-router-settings.js +24 -1
- package/server/dist/providers/claude-adapter.js +6 -1
- package/server/dist/worktree-node-modules.js +95 -1
- package/client/dist/assets/ActivityFeedPage-Wi5XNgoG.js +0 -1
- package/client/dist/assets/AgentModeAnalyticsPane-CXz2j-Bt.js +0 -2
- package/client/dist/assets/AgentModeCodePane-DnsBPtpS.js +0 -2
- package/client/dist/assets/AgentsPage-CXrqu5vo.js +0 -118
- package/client/dist/assets/AnalyticsPage-Cvtt-LOO.js +0 -1
- package/client/dist/assets/BarChart-nBOMNfiy.js +0 -33
- package/client/dist/assets/CodePage-D35o-MFO.js +0 -3
- package/client/dist/assets/DesktopAnalyticsPage-CsDFy5rp.js +0 -1
- package/client/dist/assets/IntegrationsPage-Bhy58lnQ.js +0 -1
- package/client/dist/assets/InteractiveJobComposer-CFKvbQeJ.js +0 -19
- package/client/dist/assets/JobDetailPage-C6gpdYvj.js +0 -1
- package/client/dist/assets/JobsPage-CgS0pnKd.js +0 -1
- package/client/dist/assets/LoopBuilderPage-jUp20DSZ.js +0 -1
- package/client/dist/assets/LoopsPage-ClSrWzDd.js +0 -2
- package/client/dist/assets/MinimizedChatsContext-CroAs6Kh.js +0 -1
- package/client/dist/assets/PluginsPage-nCKQOwRL.js +0 -2
- package/client/dist/assets/ProjectSettingsDialog-BVDYwllU.js +0 -1
- package/client/dist/assets/RepositoryDeliveries-DJCm1pZr.js +0 -5
- package/client/dist/assets/ReviewPacketPage-kTErrEjx.js +0 -4
- package/client/dist/assets/TicketDetailModalContext-YBJX3RmP.js +0 -16
- package/client/dist/assets/Trans-D5eOjfvG.js +0 -1
- package/client/dist/assets/agent--8QAfoXL.js +0 -1
- package/client/dist/assets/agent-3HxXkIWX.js +0 -1
- package/client/dist/assets/agent-CpFCz32T.js +0 -1
- package/client/dist/assets/agent-DVnw6ybO.js +0 -1
- package/client/dist/assets/agent-Z5s_GTP0.js +0 -1
- package/client/dist/assets/agent-hv57-zyG.js +0 -1
- package/client/dist/assets/agent-xGrZ_aN1.js +0 -1
- package/client/dist/assets/chunk-KS7C4IRE-DEKu087k.js +0 -3
- package/client/dist/assets/circle-x-CMYsN4ZH.js +0 -1
- package/client/dist/assets/createLucideIcon-Bjbbp_KS.js +0 -1
- package/client/dist/assets/download-CFHyyHcw.js +0 -1
- package/client/dist/assets/external-link-D6XxC_Cu.js +0 -1
- package/client/dist/assets/file-text-BcLCfcWZ.js +0 -1
- package/client/dist/assets/git-branch-BRM0F5GN.js +0 -1
- package/client/dist/assets/index-Bfunvi6w.css +0 -2
- package/client/dist/assets/index-lTGJJTuk.js +0 -83
- package/client/dist/assets/jira-api-Bp0zXwjg.js +0 -1
- package/client/dist/assets/jsx-runtime-zu2_FqZY.js +0 -1
- package/client/dist/assets/loader-circle-DcygOQpC.js +0 -1
- package/client/dist/assets/pencil-C9RkrIPZ.js +0 -1
- package/client/dist/assets/plus-CsnjfkmX.js +0 -1
- package/client/dist/assets/react-dom-DiWzBDP9.js +0 -1
- package/client/dist/assets/rotate-ccw-Wh4id13q.js +0 -1
- package/client/dist/assets/save-OsUqVn99.js +0 -1
- package/client/dist/assets/search-Cq_gE3Ik.js +0 -1
- package/client/dist/assets/settings-Dbyd6gmj.js +0 -1
- package/client/dist/assets/sparkles-DrY8hb0X.js +0 -1
- package/client/dist/assets/spending-DQDNtM8q.js +0 -1
- package/client/dist/assets/square-Ci-PFcFe.js +0 -1
- package/client/dist/assets/trash-2-BOU3WdZZ.js +0 -1
- package/client/dist/assets/triangle-alert-H9T4jAmh.js +0 -1
- package/client/dist/assets/upload-DYMjAQ6M.js +0 -1
- package/client/dist/assets/useSharedWebSocket-DaWuiO0S.js +0 -2
- package/client/dist/assets/x-CBMI9ejn.js +0 -1
- package/client/dist/assets/zap-CUOlvtT1.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{r as s}from"./useSharedWebSocket-DaWuiO0S.js";import{n as c,t as l}from"./createLucideIcon-Bjbbp_KS.js";import{a as u,i as d,r as f,s as p}from"./useDesktop-DKNbOF0u.js";import{J as m,V as h,X as g,Y as _,n as v,tt as y}from"./TicketDetailModalContext-YBJX3RmP.js";import{p as b}from"./provider-capabilities-lePfeT_Y.js";import{n as x,r as S}from"./save-OsUqVn99.js";import{c as C}from"./MinimizedChatsContext-CroAs6Kh.js";import{n as w,t as T}from"./file-text-BcLCfcWZ.js";import{t as E}from"./external-link-D6XxC_Cu.js";import{t as D}from"./loader-circle-DcygOQpC.js";import{t as O}from"./search-Cq_gE3Ik.js";import{t as k}from"./sparkles-DrY8hb0X.js";import{t as A}from"./x-CBMI9ejn.js";import{F as j,P as M}from"./dialog-CMgps2MY.js";import{t as N}from"./utils-BC4DHlz2.js";import{n as P,t as F}from"./lib-CGdyxIWg.js";import{n as ee,t as I}from"./project-repositories-CadLZOnr.js";import{Bt as te,Lt as ne,Pt as L,Rt as R,tn as re,wt as z}from"./index-lTGJJTuk.js";var B=l(`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`}]]),ie=l(`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`}]]),V=l(`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`}]]),ae=l(`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`}]]),oe=l(`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`}]]),se=l(`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`}]]),H=e(t(),1),ce=e(r(),1);function U(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 W(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 G(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var K=(e,t)=>Math.abs(e-t)<1.01,le=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},q,ue=()=>{if(q!==void 0)return q;if(typeof navigator>`u`)return q=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return q=!0;let e=navigator.maxTouchPoints;return q=navigator.platform===`MacIntel`&&e!==void 0&&e>0},J=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(J(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(J(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:le(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=W(()=>(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,!(!ue()||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=W(()=>[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=W(()=>[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=U(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=W(()=>[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=W(()=>{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))&&(ue()&&(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=W(()=>[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 G(t[ye(0,t.length-1,r?e=>n[e*2]:e=>G(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&&K(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`?H.useLayoutEffect:H.useEffect;function Se({useFlushSync:e=!0,...t}){let n=H.useReducer(e=>e+1,0)[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,ce.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=H.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,H.createContext)(null);function Z(){return(0,H.useContext)(we)??{apiBase:u()}}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}=c(`code`),a=(0,H.useId)(),o=Z(),{apiBase:l,repositoryId:u,repositoryPath:p}=o,{activeProjectId:h}=f(),{openTicketDetail:g}=v(),{registerHandler:_,unregisterHandler:y}=s(),[b,S]=(0,H.useState)(()=>{if(!h)return`all`;try{let e=localStorage.getItem(Ee(`${h}:${u??`primary`}`));if(e===`all`||e===`touched-by-ai`)return e}catch{}return`all`});(0,H.useEffect)(()=>{if(h)try{localStorage.setItem(Ee(`${h}:${u??`primary`}`),b)}catch{}},[b,h,u]),(0,H.useEffect)(()=>{(n||r)&&S(`touched-by-ai`)},[n,r]);let[C,T]=(0,H.useState)(()=>{if(!h)return new Set;try{let e=localStorage.getItem(De(`${h}:${u??`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,H.useEffect)(()=>{if(h)try{localStorage.setItem(De(`${h}:${u??`primary`}`),JSON.stringify([...C]))}catch{}},[C,h,u]);let E=(0,H.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),D=(0,H.useCallback)(()=>{T(new Set)},[]),O=b===`touched-by-ai`?`${n??`all-jobs`}:${r??`all-specs`}`:`all`,{data:k,refresh:A,isFirstLoad:j,isLoading:M,error:P}=d({namespace:`code-tree-v2:${JSON.stringify([u,p,b,O])}`,projectId:h,initialValue:{entries:[],partial:!1},fetcher:(0,H.useCallback)(async({signal:e})=>{let t=new Map,i=new Set,a=null,o=!1;for(let s=0;s<20;s+=1){e.throwIfAborted();let s=new URLSearchParams({withProvenance:`1`,filter:b});b===`touched-by-ai`&&n&&s.set(`jobId`,n),b===`touched-by-ai`&&typeof r==`number`&&s.set(`ticketId`,String(r)),a&&s.set(`cursor`,a);let c=await fetch(`${l}/code/tree?${s}`,{signal:e});if(!c.ok)throw Error(`tree_request_failed`);let u=await c.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,l])}),F=k.entries,ee=(0,H.useRef)(h);(0,H.useEffect)(()=>{ee.current=h},[h]),(0,H.useEffect)(()=>{if(!h)return;let e=`code-tree-${a}-${h}-${u??`primary`}`,t;return _(e,e=>{let n=e;n.projectId!==ee.current||!Te(n.repositoryId,o)||n.type===`file.provenance_updated`&&(clearTimeout(t),t=setTimeout(()=>{A()},150))}),()=>{clearTimeout(t),y(e)}},[l,u,h,_,y,A,a]);let I=(0,H.useRef)(null),L=(0,H.useMemo)(()=>(F??[]).filter(e=>!Me(e.path,C)),[F,C]),re=(0,H.useCallback)(()=>{T(new Set((F??[]).filter(e=>e.kind===`dir`).map(e=>e.path)))},[F]),B=Ce({count:L.length,getScrollElement:()=>I.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()=>{}}}),ie=(0,H.useId)(),[V,ae]=(0,H.useState)(t),oe=Math.max(0,L.findIndex(e=>e.path===V));(0,H.useEffect)(()=>{t&&(ae(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 se=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!t||se.current===t)return;let e=L.findIndex(e=>e.path===t);e>=0&&(B.scrollToIndex(e,{align:`auto`}),se.current=t)},[t,L,B]);let ce=(t,n)=>{let r=L[n];if(!r)return;let i=n;switch(t.key){case`ArrowDown`:i=Math.min(L.length-1,n+1);break;case`ArrowUp`:i=Math.max(0,n-1);break;case`Home`:i=0;break;case`End`:i=L.length-1;break;case`ArrowRight`:r.kind===`dir`&&C.has(r.path)?E(r.path):r.kind===`dir`&&(i=Math.min(L.length-1,n+1));break;case`ArrowLeft`:if(r.kind===`dir`&&!C.has(r.path))E(r.path);else{let e=r.path.split(`/`).slice(0,-1).join(`/`),t=L.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(),ae(L[i].path),i!==n&&B.scrollToIndex(i,{align:`auto`})},U=L.length===0,W=(0,H.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:()=>S(`touched-by-ai`),className:N(`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:()=>S(`all`),className:N(`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:M,"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)(z,{className:`h-3.5 w-3.5 ${M?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:re,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)(x,{className:`w-3.5 h-3.5`})})]}),b===`touched-by-ai`&&W>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:W})})})]}),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`)}),U&&P?null:U&&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`)})}):U&&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:()=>S(`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`)})]}):U?(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:I,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":L[oe]?`${ie}-${oe}`:void 0,onKeyDown:e=>{e.target===e.currentTarget&&ce(e,oe)},children:(0,Q.jsx)(`div`,{style:{height:B.getTotalSize(),position:`relative`,width:`100%`},children:B.getVirtualItems().map(n=>{let r=L[n.index],a=Oe(r.path)*12,o=r.kind===`file`&&r.path===t,s=r.provenance?.createdByTicketId,c=r.provenance?.modifiedByTicketIds??[],l=r.provenance?.latest??null,u=Ae(l?.jobId),d=je(l?.kind),f=r.kind===`dir`,p=f&&C.has(r.path),h=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:N(`flex items-center gap-2 px-2 text-xs cursor-pointer hover:bg-muted/50`,o&&`bg-accent-primary/10 text-foreground`,r.path===V&&`ring-1 ring-inset ring-accent-primary/30`),onClick:()=>{ae(r.path),I.current?.focus({preventScroll:!0}),f?E(r.path):e(r.path)},onKeyDown:e=>{e.target===e.currentTarget&&ce(e,n.index)},role:`treeitem`,id:`${ie}-${n.index}`,tabIndex:-1,"aria-level":Oe(r.path)+1,"aria-selected":o,title:r.path,"aria-expanded":f?!p: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:[f?(0,Q.jsxs)(Q.Fragment,{children:[p?(0,Q.jsx)(w,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}):(0,Q.jsx)(x,{className:`w-3 h-3 text-muted-foreground flex-shrink-0`}),p?(0,Q.jsx)(ne,{className:`w-3.5 h-3.5 text-accent-info flex-shrink-0`}):(0,Q.jsx)(R,{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)(te,{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:[f&&h>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:h}),children:h}),!f&&d&&(0,Q.jsx)(`span`,{className:N(`h-1.5 w-1.5 rounded-full`,l?.kind===`created`&&`bg-accent-success`,l?.kind===`modified`&&`bg-accent-info`,l?.kind===`deleted`&&`bg-destructive`),title:l?.kind===`created`?i(`tree.latestTitleCreated`):l?.kind===`deleted`?i(`tree.latestTitleDeleted`):i(`tree.latestTitleModified`),children:(0,Q.jsx)(`span`,{className:`sr-only`,children:i(`action.${d}`)})}),!f&&u&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center px-0.5 text-muted-foreground`,title:i(`tree.jobTitle`,{jobId:l?.jobId??``}),children:[(0,Q.jsx)(m,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:u})]}),!f&&typeof s==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),g(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]}),!f&&c.slice(0,2).map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),g(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}=c(`code`),a=re(),o=(0,H.useRef)(null),s=(0,H.useRef)(null),l=(0,H.useRef)(null),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(!1),[m,h]=(0,H.useState)(0),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(``),b=(0,H.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,H.useEffect)(()=>{let e=!1;return d(!1),p(!1),Ue(),i(()=>import(`./editor.main-DxrmGfoq.js`).then(t=>{if(e||!o.current)return;l.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),d(!0)}),__vite__mapDeps([0,1,2,3,4,5,6])).catch(()=>{e||p(!0)}),()=>{e=!0;let t=s.current?.getModel();s.current?.dispose(),t?.dispose(),s.current=null,l.current=null}},[m]),(0,H.useEffect)(()=>{let t=s.current;t&&t.getValue()!==e&&t.setValue(e)},[e]),(0,H.useEffect)(()=>{let e=s.current?.getModel();e&&l.current&&l.current.editor.setModelLanguage(e,t)},[t]),(0,H.useEffect)(()=>{let e=l.current;e&&e.editor.setTheme(He(e,a))},[a]),(0,H.useEffect)(()=>{x(n)},[n,u]),(0,H.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:!u,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:!u,"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:!u||!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`})})]})]}),f?(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:[!u&&(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}=c(`code`),{openTicketDetail:l}=v();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)(C,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})});let u=Ge(t.generatedAt,s.language),d=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,m=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:N(`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:[d&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:o(`story.explainedBy`,{model:d})}),typeof p==`number`&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(p),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-success/20 text-accent-success`,children:[`#`,p]}),m.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(e),className:`text-[10px] px-1.5 py-0.5 rounded bg-accent-info/15 text-accent-info`,children:[`#`,e]},e)),u&&(0,Q.jsx)(`time`,{className:`text-[10px] text-muted-foreground`,dateTime:t.generatedAt,title:f,children:u})]})]}),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)(C,{className:`h-3.5 w-3.5`}),o(`summary.hide`)]})]})})}function qe({content:e}){return(0,Q.jsx)(P,{remarkPlugins:[F],children:e})}var Je=2e3,Ye=256e3;function Xe({path:e,jobId:t}){let{activeProjectId:n}=f(),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}=c(`code`),{apiBase:r}=Z(),[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)(`loading`),[l,u]=(0,H.useState)(0);(0,H.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,l]);let d=(i?.patch??``).slice(0,Ye).split(`
|
|
3
|
-
`),f=d.length>Je||(i?.patch.length??0)>Ye,p=null,m=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:()=>u(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.`})}),f&&(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:d.slice(0,Je).map((e,t)=>{let n=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e),r=null,i=null,a=`meta`;return n?(p=Number(n[1]),m=Number(n[2])):p!==null&&m!==null&&(e.startsWith(`+`)?(a=`added`,i=m++):e.startsWith(`-`)?(a=`removed`,r=p++):e.startsWith(` `)&&(a=`context`,r=p++,i=m++)),(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`?_:e===`deleted`?g:T}function et(e){let t=Z(),{activeProjectId:n}=f(),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}=c(`code`),o=Z(),{apiBase:l,repositoryId:u}=o,{activeProjectId:d,projects:m}=f(),h=m.find(e=>e.id===d)?.provider,g=b(h),{registerHandler:_,unregisterHandler:v}=s(),y=(0,H.useId)(),[x,S]=(0,H.useState)(null),[C,w]=(0,H.useState)(!1),T=(0,H.useRef)(!0),E=(0,H.useRef)(null),D=(0,H.useRef)(new Map);(0,H.useEffect)(()=>(T.current=!0,()=>{T.current=!1,E.current?.abort();for(let e of D.current.values())e.abort();D.current.clear()}),[]);let[O,k]=(0,H.useState)({}),A=(0,H.useRef)(d);(0,H.useEffect)(()=>{A.current=d},[d]);let j=(0,H.useRef)(e);(0,H.useEffect)(()=>{j.current=e},[e]);let M=(0,H.useRef)(0),N=(0,H.useCallback)(async()=>{if(!T.current)return;let t=++M.current;E.current?.abort();let n=new AbortController;E.current=n;try{let r=await fetch(`${l}/code/file/story?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!T.current||n.signal.aborted||t!==M.current)return;if(!r.ok){S([]),w(!0);return}let i=await r.json();if(!T.current||n.signal.aborted||t!==M.current)return;S(Array.isArray(i.story)?i.story:[]),w(!1)}catch{T.current&&!n.signal.aborted&&t===M.current&&(S([]),w(!0))}},[e,d,l]);(0,H.useEffect)(()=>{S(null),k({}),N()},[N]),(0,H.useEffect)(()=>{if(!d)return;let e=`code-story-${d}-${u??`primary`}-${y}`;return _(e,e=>{let t=e;t.projectId!==A.current||!Te(t.repositoryId,o)||t.path===j.current&&(t.type===`file.story_updated`||t.type===`file.provenance_updated`)&&N()}),()=>v(e)},[y,l,u,d,_,v,N]);let P=(0,H.useCallback)(async(t,n)=>{if(!g||!T.current||!t.hasPatch||t.evidence?.kind===`missing`||D.current.has(t.provenanceId))return;let r=new AbortController;D.current.set(t.provenanceId,r),k(e=>({...e,[t.provenanceId]:`busy`}));try{let i=await fetch(`${l}/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(!T.current||r.signal.aborted)return;if(o.skipped===`budget`){k(e=>({...e,[t.provenanceId]:`budget`}));return}if(!i.ok||!o.ok){p.error(a(`story.explainFailed`)),k(e=>{let n={...e};return delete n[t.provenanceId],n});return}if(await N(),!T.current||r.signal.aborted)return;k(e=>{let n={...e};return delete n[t.provenanceId],n})}catch{if(!T.current||r.signal.aborted)return;p.error(a(`story.explainFailed`)),k(e=>{let n={...e};return delete n[t.provenanceId],n})}finally{D.current.delete(t.provenanceId)}},[g,N,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:x===null?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground animate-pulse py-2`,children:a(`story.loading`)}):C?(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:()=>{N()},children:a(`reader.retry`,{defaultValue:`Retry`})})]}):x.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:x.map(t=>(0,Q.jsx)(nt,{entry:t,state:O[t.provenanceId],canExplain:g&&t.hasPatch&&t.evidence?.kind!==`missing`,path:e,onViewDiff:i,onOpenTicket:n,onFilterJob:r,onExplain:e=>{P(t,e)}},t.provenanceId))})})})}function nt({entry:e,state:t,canExplain:n,path:r,onViewDiff:i,onOpenTicket:a,onFilterJob:o,onExplain:s}){let{t:l}=c(`code`),[u,d]=(0,H.useState)(!1),f=$e(e.kind),p=e.ticket?.status??null,m=e.ticket?.title?`#${e.ticket.id} · ${e.ticket.title}`:e.ticketId==null?null:l(`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)(f,{className:`h-3.5 w-3.5 shrink-0`}),l(`story.kindLabel.${e.kind}`)]}),m!=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:l(`story.openSpec`,{ticketId:e.ticketId}),children:m}),m==null&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:l(`story.unknownSpec`)}),p&&(0,Q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] ${Qe[p]??`bg-muted/60 text-muted-foreground`}`,"data-testid":`story-status-pill`,children:p}),(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:l(`story.linesAdded`),children:[`+`,e.addedLines]}),e.removedLines!=null&&e.removedLines>0&&(0,Q.jsxs)(`span`,{className:`font-mono text-[10px] text-destructive`,title:l(`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:l(`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:l(`story.budgetReached`)}),(0,Q.jsx)(`button`,{className:`rounded border px-2 py-1`,onClick:()=>s(!0),children:l(`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`?l(`story.explaining`):l(`reader.regenerateExplanation`,{defaultValue:`Refresh explanation`})})),e.summaryModel&&(0,Q.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:l(`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:l(`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:l(`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:l(`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)(k,{className:t===`busy`?`h-3 w-3 animate-pulse`:`h-3 w-3`}),l(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`?l(`reader.noEvidence`,{defaultValue:`No patch evidence was stored for this change.`}):l(`story.explainUnavailable`)})]})}),e.summary&&(!e.hasPatch||e.evidence?.kind===`missing`)&&(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-accent-warning`,children:l(`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:l(`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):d(e=>!e)},children:l(`reader.viewPatch`,{defaultValue:`View recorded change`})}),u&&(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:l(`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}=f(),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:l}=c(`code`),u=Z(),{apiBase:d,repositoryId:m}=u,{activeProjectId:h,projects:g}=f(),_=g.find(e=>e.id===h)?.provider,y=b(_),{openTicketDetail:S}=v(),{registerHandler:w,unregisterHandler:T}=s(),E=(0,H.useId)(),D=j({allowMove:!1}),O=(0,H.useRef)(null),[k,A]=(0,H.useState)(null),[N,P]=(0,H.useState)(!1),F=(0,H.useRef)(!0),ee=(0,H.useRef)(null),I=(0,H.useRef)(new Set);(0,H.useEffect)(()=>(F.current=!0,()=>{F.current=!1,ee.current?.abort();for(let e of I.current)e.abort();I.current.clear()}),[]);let[te,ne]=(0,H.useState)(n??null),[L,R]=(0,H.useState)(n?`recorded`:`source`);(0,H.useEffect)(()=>{ne(n??null),R(n?`recorded`:`source`)},[n]),(0,H.useEffect)(()=>{t&&!n&&R(`source`)},[t,n]);let re=(0,H.useCallback)(e=>{ne(e),R(`recorded`)},[]),[z,B]=(0,H.useState)(!0),[ie,V]=(0,H.useState)(!1),[ae,oe]=(0,H.useState)(!1),[se,U]=(0,H.useState)(()=>ht(h)),[W,G]=(0,H.useState)(()=>pt(h)),[K,le]=(0,H.useState)(()=>_t(h,r)),[q,ue]=(0,H.useState)(()=>dt(h)),J=(0,H.useRef)(h);(0,H.useEffect)(()=>{J.current=h},[h]);let de=(0,H.useRef)(e);(0,H.useEffect)(()=>{de.current=e},[e]),(0,H.useEffect)(()=>{let e=O.current?.clientHeight||window.innerHeight;U(ht(h)),G(yt(pt(h),e)),le(_t(h,r)),ue(dt(h))},[h,r]);let fe=(0,H.useCallback)(e=>{let t=e.clientY,n=W,r=O.current?.clientHeight||window.innerHeight,i=e.currentTarget;try{i.setPointerCapture(e.pointerId)}catch{}function a(e){G(yt(n+(t-e.clientY),r))}function o(){window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),G(e=>{let t=yt(e,r);return mt(h,t),t})}window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o)},[h,W]),pe=(0,H.useCallback)(()=>{let e=yt(it,O.current?.clientHeight||window.innerHeight);G(e),mt(h,e)},[h]),me=(0,H.useCallback)(()=>{U(e=>{let t=!e;return gt(h,t),t})},[h]),Y=(0,H.useCallback)(()=>{le(e=>{let t=!e;return vt(h,t,r),t})},[h,r]),he=(0,H.useCallback)(e=>{ue(e),ft(h,e)},[h]);(0,H.useEffect)(()=>{xe(t?`raw`:`preview`)},[e,t]);let ge=(0,H.useRef)(0),X=(0,H.useCallback)(async()=>{if(!F.current)return;let t=++ge.current;ee.current?.abort();let n=new AbortController;ee.current=n,B(!0),P(!1);try{let r=await fetch(`${d}/code/file?path=${encodeURIComponent(e)}`,{signal:n.signal});if(!F.current||n.signal.aborted||t!==ge.current)return;if(!r.ok){P(!0);return}let i=await r.json();if(!F.current||n.signal.aborted||t!==ge.current)return;A(i)}catch{F.current&&!n.signal.aborted&&t===ge.current&&P(!0)}finally{F.current&&!n.signal.aborted&&t===ge.current&&B(!1)}},[e,h,d]);(0,H.useEffect)(()=>{X()},[X]),(0,H.useEffect)(()=>{let e=()=>{X()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[X]),(0,H.useEffect)(()=>{if(!h)return;let e=`code-file-${h}-${m??`primary`}-${E}`;return w(e,e=>{let t=e;t.projectId!==J.current||!Te(t.repositoryId,u)||((t.type===`file.summary_updated`||t.type===`file.provenance_updated`||t.type===`file.content_updated`)&&t.path===de.current?(t.type===`file.summary_updated`&&V(!1),X()):t.type===`file.summary_failed`&&t.path===de.current?(p.error(t.reason??l(`summary.generationFailed`)),V(!1)):t.type===`file.summary_skipped`&&t.path===de.current&&(t.reason&&p(l(`summary.skipped`,{reason:t.reason})),V(!1)))}),()=>T(e)},[E,d,m,h,w,T,X,l]);let _e=(0,H.useCallback)(async t=>{if(!y||!F.current||I.current.size>0)return;let n=new AbortController;I.current.add(n),V(!0);try{let r=await fetch(`${d}/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(!F.current||n.signal.aborted)return;if(!r.ok){V(!1);let e=typeof i.skipped==`string`?i.skipped:null;p.error(e?l(`summary.skipped`,{reason:e}):l(`summary.generationFailed`));return}if(i.skipped===`budget`){V(!1),oe(!0);return}if(i.skipped){V(!1),p(l(`summary.skipped`,{reason:i.skipped}));return}await X(),F.current&&!n.signal.aborted&&V(!1)}catch{F.current&&!n.signal.aborted&&(V(!1),p.error(l(`summary.generationFailed`)))}finally{I.current.delete(n)}},[y,X,e,l]),ve=(0,H.useCallback)(async()=>{let t=k?.absolutePath??e;try{if(!navigator.clipboard?.writeText)throw Error(`Clipboard unavailable`);await navigator.clipboard.writeText(t),p.success(l(`viewer.pathCopied`))}catch{p.error(l(`viewer.copyPathFailed`))}},[k,e,l]),ye=(0,H.useMemo)(()=>rt(e,k?.language),[e,k?.language]),[be,xe]=(0,H.useState)(t?`raw`:`preview`),Se=k?.summary??null,Ce=!!k?.summaryStale,we=k?.provenance??[],Ee=k?.reason===`not-found`,De=k?y?Ee?l(`summary.reason.missing`):k?.binary?l(`summary.reason.binary`):k?.tooLarge?l(`summary.reason.tooLarge`):null:l(`summary.reason.providerNoPureOutput`):l(`reader.sourceUnavailable`,{defaultValue:`source unavailable`});return(0,H.useEffect)(()=>{if(a){if(L===`recorded`||z&&!k){a(null);return}return a({hasSummary:!!Se,regenerating:ie,disabledReason:De,onClick:()=>_e(!1)}),()=>a(null)}},[k,_e,z,a,ie,Se,De,L]),(0,H.useEffect)(()=>{if(o){if(z&&!k){o(null);return}return o({onClick:ve}),()=>o(null)}},[ve,k,z,o]),L===`source`&&z&&!k?(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground animate-pulse`,children:l(`viewer.loadingFile`)}):(0,Q.jsxs)(`div`,{ref:O,className:`flex flex-col h-full`,"data-testid":`file-viewer`,children:[L===`source`&&(se?(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)(x,{className:`h-3.5 w-3.5`}),l(`viewer.showSummary`)]})]}):(0,Q.jsx)(Ke,{path:e,summary:Se,stale:Ce,regenerating:ie,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":L===`source`,onClick:()=>R(`source`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:l(`reader.currentFile`,{defaultValue:`Current file`})}),te&&(0,Q.jsx)(`button`,{"aria-pressed":L===`recorded`,onClick:()=>R(`recorded`),className:`rounded px-2 py-1 text-xs hover:bg-muted`,children:l(`reader.recordedChange`,{defaultValue:`Recorded change`})}),L===`source`&&ye&&k?.content!==void 0&&!k.binary&&!k.tooLarge&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,role:`group`,"aria-label":l(`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:l(`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:l(`viewer.raw`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[k?.language&&(0,Q.jsx)(`span`,{children:k.language}),typeof k?.sizeBytes==`number`&&(0,Q.jsxs)(`span`,{children:[(k.sizeBytes/1024).toFixed(1),` KB`]}),(0,Q.jsx)(`button`,{disabled:z,onClick:()=>{X()},className:`rounded px-2 py-1 hover:bg-muted disabled:opacity-50`,children:l(`reader.refresh`,{defaultValue:`Refresh source`})})]})]}),N&&(0,Q.jsxs)(`div`,{role:`alert`,className:`border-b border-border px-4 py-2 text-xs`,children:[l(`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:l(`reader.retry`,{defaultValue:`Retry`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:L===`recorded`&&te?(0,Q.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,Q.jsx)(Xe,{path:e,jobId:te})}):Ee?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-missing`,children:l(`viewer.missingFile`)}):k?.binary?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-binary`,children:l(`viewer.binaryFile`)}):k?.tooLarge?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,"data-testid":`file-too-large`,children:l(`viewer.tooLarge`,{size:Math.round((k.sizeBytes??0)/1024/1024)})}):k?.content===void 0?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-muted-foreground`,children:l(`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:k.content})}):(0,Q.jsx)(We,{content:k.content,language:k.language??`plaintext`,initialLine:t})}),we.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":l(`history.resize`),onPointerDown:K?void 0:fe,onDoubleClick:K?void 0:pe,className:K?`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:K?void 0:l(`resizer.hint`),"data-testid":`code-history-resizer`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground`,children:l(q===`story`?`story.title`:`history.title`,{count:we.length})}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[!K&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-md bg-muted/40 p-0.5`,role:`group`,"aria-label":l(`story.viewMode`),onPointerDown:e=>e.stopPropagation(),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`story`),"aria-pressed":q===`story`,className:q===`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:l(`story.modeStory`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>he(`log`),"aria-pressed":q===`log`,className:q===`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:l(`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:[K?(0,Q.jsx)(C,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(x,{className:`h-3.5 w-3.5`}),l(K?`history.show`:`history.hide`)]})]})]}),!K&&(q===`story`?(0,Q.jsx)(et,{relPath:e,height:W,onOpenTicket:S,onFilterJob:i,onViewDiff:re}):(0,Q.jsx)(St,{rows:we,onOpenTicket:S,onFilterJob:i,height:W}))]}),ae&&(0,ce.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:D.guardBackdrop(()=>oe(!1)),children:[(0,Q.jsxs)(`div`,{ref:D.panelRef,onClick:e=>e.stopPropagation(),className:`bg-card border border-border rounded-lg p-4 w-80 flex flex-col gap-3`,style:D.panelStyle,children:[(0,Q.jsx)(`p`,{className:`text-sm text-foreground`,children:l(`viewer.budgetPrompt`)}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>oe(!1),className:`text-xs px-3 py-1.5 rounded-md text-muted-foreground hover:text-foreground`,children:l(`common:actions.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{oe(!1),_e(!0)},className:`text-xs px-3 py-1.5 rounded-md bg-accent-primary text-white`,children:l(`common:actions.confirm`)})]})]}),(0,Q.jsx)(M,{handles:D.resizeHandles})]}),document.body)]})}function St({rows:e,onOpenTicket:t,onFilterJob:n,height:r}){let{t:i}=c(`code`),[a,o]=(0,H.useState)(null);if(e.length===0)return null;function s(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`?_:e.kind===`deleted`?g:T,c=e.jobId?e.jobId.length>12?e.jobId.slice(0,12):e.jobId:i(`history.unknownJob`),l=`${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)(m,{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:c}):(0,Q.jsx)(`span`,{className:`font-mono truncate`,title:e.jobId??void 0,children:c}),e.jobId&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(e,l),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===l&&(0,Q.jsx)(`div`,{className:`px-2 pb-2`,children:e.jobId&&(0,Q.jsx)(Xe,{path:e.path,jobId:e.jobId})})]},l)})})})}function Ct({projectId:e,repositoryName:t,multipleRepositories:n,active:r=!0,onOpen:i}){let{t:a}=c(`code`),{apiBase:o,repositoryId:s,repositoryPath:l}=Z(),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)(`find`),[m,h]=(0,H.useState)(n),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(``),[b,x]=(0,H.useState)(null),[S,C]=(0,H.useState)(!1),[w,T]=(0,H.useState)(!1),[E,k]=(0,H.useState)(0),A=n&&m,j=A?ee(e):o,M=A?void 0:s,N=A?void 0:t,P=A?void 0:l,F=(0,H.useRef)(0),I=(0,H.useRef)(null);return(0,H.useEffect)(()=>{r&&I.current?.focus()},[r]),(0,H.useEffect)(()=>{let e=++F.current,t=new AbortController;x(null),T(!1);let n=u.trim();if(!n)return C(!1),()=>t.abort();C(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({q:n,limit:f===`find`?`50`:`100`});f===`search`&&r.set(`caseSensitive`,String(g)),f===`search`&&v.trim()&&r.set(`path`,v.trim()),A&&r.set(`kind`,f);let i=await fetch(`${j}/code/${A?`discover`:f}?${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===F.current&&x({...a,matches:a.matches.map(e=>({...e,repositoryId:e.repositoryId??M,repositoryName:e.repositoryName??N}))})}catch{!t.signal.aborted&&e===F.current&&T(!0)}finally{!t.signal.aborted&&e===F.current&&C(!1)}},250);return()=>{clearTimeout(r),t.abort()}},[u,f,g,v,E,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":f===e,onClick:()=>p(e),className:`flex-1 rounded-md px-2 py-1.5 text-xs ${f===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)(O,{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:I,value:u,onChange:e=>d(e.target.value),maxLength:256,"aria-label":a(`search.query`),placeholder:a(f===`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:m?`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`)})]}),f===`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:[!u.trim()&&(0,Q.jsxs)(`div`,{className:`space-y-2 px-5 py-8 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(B,{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)(D,{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:l}=c(`code`),{repositoryId:u,repositoryPath:d}=Z(),{registerHandler:f,unregisterHandler:p}=s(),[h,v]=(0,H.useState)(n),[y,b]=(0,H.useState)(null),[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(!1),E=(0,H.useRef)(0),O=(0,H.useRef)(null),k=(0,H.useId)(),A=JSON.stringify([e,u,d,h,r,i]),j=(0,H.useRef)(A);j.current=A;let M=y?.scope===A?y:null,N=(0,H.useCallback)(async t=>{let n=++E.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`});!h&&u&&o.set(`repositoryId`,u),r&&o.set(`jobId`,r),i&&o.set(`ticketId`,String(i)),t&&o.set(`cursor`,t);let s=await fetch(`${ee(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!==E.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===E.current&&j.current===A&&w(!0)}finally{!a.signal.aborted&&n===E.current&&j.current===A&&S(!1)}},[e,u,d,h,r,i,A]);return(0,H.useEffect)(()=>(N(),()=>{E.current++,O.current?.abort()}),[N]),(0,H.useEffect)(()=>{let t=`code-activity-${e}-${k}`,n;return f(t,t=>{let r=t;r.type!==`file.provenance_updated`||r.projectId!==e||(clearTimeout(n),n=setTimeout(()=>{N()},250))}),()=>{clearTimeout(n),p(t)}},[N,e,k,f,p]),(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)(z,{className:`h-3.5 w-3.5 ${x?`animate-spin`:``}`})})]}),n&&(0,Q.jsxs)(`select`,{"aria-label":o(`activity.scope`),value:h?`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)(L,{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`?_:e.kind===`deleted`?g: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)(m,{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(l.language),children:new Date(e.at).toLocaleDateString(l.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)(D,{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}=f();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}=c(`code`),{t:l}=c(`common`),{activeProjectId:d,projects:p}=f(),[m,h]=a(),g=o(),_=p?.find(e=>e.id===d),v=(0,H.useMemo)(()=>I(_),[_]),[b,x]=(0,H.useState)(()=>({entries:[{repositoryId:n??void 0,path:t}],index:0})),C=e?b.entries[b.index]:{repositoryId:m.get(`repositoryId`)??void 0,path:m.get(`path`),line:Tt(m.get(`line`)),changeJobId:m.get(`changeJobId`)},E=C.repositoryId?v.find(e=>e.id===C.repositoryId):v.find(e=>e.isPrimary),D=!!C.repositoryId&&!!_&&!E,k=(0,H.useMemo)(()=>({apiBase:d?ee(d,E?.id):u(),repositoryId:E?.id,repositoryPath:E?.path,isPrimary:E?.isPrimary}),[d,E?.id,E?.path,E?.isPrimary]),A=JSON.stringify([d,E?.id,E?.path]),[j,M]=(0,H.useState)(`files`),[N,P]=(0,H.useState)(!0),[F,te]=(0,H.useState)(e),[ne,R]=(0,H.useState)(()=>jt(d)),[re,z]=(0,H.useState)(null),[B,ae]=(0,H.useState)(null),[ce,U]=(0,H.useState)({}),W=e?ce.jobId??null:m.get(`jobId`),G=e?ce.ticketId??null:Tt(m.get(`ticketId`))??null,[K,le]=(0,H.useState)(G?String(G):``),q=(0,H.useRef)(null),ue=(0,H.useRef)(null);(0,H.useEffect)(()=>{le(G?String(G):``)},[G]),(0,H.useEffect)(()=>{let e=q.current;if(!e)return;let t=e=>{e&&(te(e<kt),R(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,H.useEffect)(()=>()=>ue.current?.(),[]),(0,H.useEffect)(()=>{F&&C.path&&P(!1)},[F,C.path]);let J=(0,H.useCallback)(t=>{let n={...t,repositoryId:t.repositoryId??E?.id},a=n.repositoryId!==E?.id;if(e)x(e=>({entries:[...e.entries.slice(0,e.index+1),n],index:e.index+1})),a&&U({});else{let e=new URLSearchParams(m);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`)),h(e)}i?.(n.path),n.repositoryId&&r?.(n.repositoryId),F&&n.path&&P(!1)},[e,E?.id,m,h,i,r,F]),de=t=>{if(!e){g(t);return}let n=b.index+t,a=b.entries[n];if(!a)return;let o=a.repositoryId??v.find(e=>e.isPrimary)?.id;o!==E?.id&&U({}),x({...b,index:n}),i?.(a.path),o&&r?.(o)},fe=(0,H.useCallback)(t=>{if(e)U(t);else{let e=new URLSearchParams(m);e.delete(`jobId`),e.delete(`ticketId`),t.jobId&&e.set(`jobId`,t.jobId),t.ticketId&&e.set(`ticketId`,String(t.ticketId)),h(e)}},[e,m,h]),pe=(0,H.useCallback)(e=>{fe({jobId:e}),M(`activity`),P(!0)},[fe]),me=e=>{ue.current?.();let t=e.clientX,n=ne,r=ne,i=e=>{r=Nt(n+e.clientX-t,q.current?.clientWidth||window.innerWidth),R(r)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),Mt(d,r),ue.current=null};ue.current=a,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},Y=N||!C.path,he=!F||!Y,ge=C.path?.split(`/`)??[];return(0,Q.jsx)(we.Provider,{value:k,children:(0,Q.jsxs)(`div`,{ref:q,className:`flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden`,"data-testid":`code-page`,"data-compact":F,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&&b.index===0,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(S,{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&&b.index===b.entries.length-1,className:`rounded p-1.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(y,{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)(oe,{className:`h-4 w-4`}):(0,Q.jsx)(se,{className:`h-4 w-4`})})]}),v.length>0&&(0,Q.jsxs)(`select`,{"aria-label":l(`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=>J({repositoryId:e.target.value,path:null}),children:[D&&(0,Q.jsx)(`option`,{value:C.repositoryId,children:l(`repositories.unavailable`)}),v.map(e=>(0,Q.jsxs)(`option`,{value:e.id,children:[e.name,e.isPrimary?` · ${l(`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})]}),D?(0,Q.jsx)(`p`,{role:`alert`,className:`p-4 text-sm text-destructive`,children:l(`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:F?`100%`:ne},"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:ie},{mode:`search`,Icon:O},{mode:`activity`,Icon:L}].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=>J({path:e}),filterJobId:W,filterTicketId:G},A)}),d&&(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:d,repositoryName:E?.name,multipleRepositories:v.length>1,onOpen:J})}),j===`activity`&&d&&(0,Q.jsx)(wt,{projectId:d,repositoryName:E?.name,multipleRepositories:v.length>1,jobId:W,ticketId:G,onOpen:J})]}),Y&&!F&&(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`page.resizeFileTree`),onPointerDown:me,onDoubleClick:()=>{let e=Nt(Et,q.current?.clientWidth||window.innerWidth);R(e),Mt(d,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:W,ticketId:G,ticketInput:K,onTicketInputChange:le,onApplyTicket:e=>fe({ticketId:Tt(e.trim())}),onClear:()=>fe({}),summaryAction:C.path?re:null,copyPathAction:C.path?B:null}),(W||G)&&(0,Q.jsx)(Lt,{jobId:W,ticketId:G,onOpenFile:e=>J({path:e,changeJobId:W})},`${A}:${W}:${G}`),C.path?(0,Q.jsx)(bt,{compact:F,relPath:C.path,initialLine:C.line,initialJobId:C.changeJobId,onFilterJob:pe,onSummaryActionChange:z,onCopyPathActionChange:ae},`${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)(V,{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:l}=c(`code`),u=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)(ae,{className:`h-3.5 w-3.5`}),l(`toolbar.scope`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:a,"aria-pressed":u===`all`,className:u===`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:l(`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":u===`spec`,className:u===`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:l(`toolbar.spec`)}),(0,Q.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i(n)},placeholder:l(`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:l(`toolbar.copyFilePath`)}),o&&(0,Q.jsxs)(`button`,{type:`button`,onClick:o.onClick,disabled:o.regenerating||!!o.disabledReason,"aria-label":o.hasSummary?l(`toolbar.regenerateSummary`):l(`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?l(`toolbar.summaryUnavailable`,{reason:o.disabledReason}):void 0,children:[(0,Q.jsx)(h,{className:o.regenerating?`h-3.5 w-3.5 animate-spin`:`h-3.5 w-3.5`}),o.hasSummary?o.regenerating?l(`toolbar.regenerating`):l(`toolbar.regenerateSummary`):o.regenerating?l(`toolbar.generating`):l(`toolbar.generateSummary`)]}),u===`job-context`&&(0,Q.jsx)(`span`,{className:`rounded-md bg-accent-info/15 px-2 py-1 text-xs text-accent-info`,children:l(`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)(A,{className:`h-3.5 w-3.5`}),l(`toolbar.clear`)]})]})})}function Lt({jobId:e,ticketId:t,onOpenFile:n}){let{t:r}=c(`code`),{apiBase:i}=Z(),[a,o]=(0,H.useState)(null),[s,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(0);(0,H.useEffect)(()=>{let n=new AbortController;o(null),l(!1),d(!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()]),d(!!e.nextCursor||e.truncated===!0)}).catch(()=>{n.signal.aborted||l(!0)}),()=>n.abort()},[e,t,i,f]);let m=(0,H.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:()=>p(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`)}),u&&(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:m.created,icon:`created`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.changed`),rows:m.modified,icon:`modified`,onOpenFile:n}),(0,Q.jsx)(Rt,{label:r(`action.deleted`),rows:m.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)(E,{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`?_:n===`deleted`?g: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 +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{m as r,r as i}from"./useSharedWebSocket-DaWuiO0S.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{t as s}from"./clsx-CjueKrWZ.js";import{t as c}from"./utils-BC4DHlz2.js";import{ct as l,tn as u,wt as d}from"./index-lTGJJTuk.js";import{$ as f,A as p,B as m,E as h,F as g,H as _,K as v,L as y,N as b,O as x,P as S,Q as C,R as w,S as T,T as ee,U as E,W as D,X as O,Y as te,Z as k,_ as ne,_t as A,a as re,c as ie,d as ae,dt as j,et as M,ft as oe,g as se,gt as ce,h as le,ht as ue,i as de,it as N,j as fe,k as pe,l as P,lt as F,mt as me,n as he,nt as I,o as ge,pt as L,q as R,r as z,rt as B,s as _e,t as ve,u as ye,ut as V,v as be,w as H,z as xe}from"./BarChart-nBOMNfiy.js";var Se=o(`trending-up`,[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]),U=e(t());function W(){return W=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},W.apply(null,arguments)}var G=e=>{var{cx:t,cy:n,r,className:i}=e,a=s(`recharts-dot`,i);return j(t)&&j(n)&&j(r)?U.createElement(`circle`,W({},ce(e),N(e),{className:a,cx:t,cy:n,r})):null},Ce=[`points`];function K(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function q(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?K(Object(n),!0).forEach(function(t){we(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):K(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function we(e,t,n){return(t=Te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Te(e){var t=Ee(e,`string`);return typeof t==`symbol`?t:t+``}function Ee(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function J(){return J=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},J.apply(null,arguments)}function De(e,t){if(e==null)return{};var n,r,i=Oe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Oe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function ke(e){var{option:t,dotProps:n,className:r}=e;if((0,U.isValidElement)(t))return(0,U.cloneElement)(t,n);if(typeof t==`function`)return t(n);var i=s(r,typeof t==`boolean`?``:t.className),a=n??{},{points:o}=a,c=De(a,Ce);return U.createElement(G,J({},c,{className:i}))}function Ae(e,t){return e==null?!1:t?!0:e.length===1}function je(e){var{points:t,dot:n,className:r,dotClassName:i,dataKey:a,baseProps:o,needClip:s,clipPathId:c,zIndex:l=y.scatter}=e;if(!Ae(t,n))return null;var u=H(n),d=ue(n),f=t.map((e,r)=>{var s=q(q(q({r:3},o),d),{},{index:r,cx:e.x??void 0,cy:e.y??void 0,dataKey:a,value:e.value,payload:e.payload,points:t});return U.createElement(ke,{key:`dot-${r}`,option:n,dotProps:s,className:i})}),m={};return s&&c!=null&&(m.clipPath=`url(#clipPath-${u?``:`dots-`}${c})`),U.createElement(p,{zIndex:l},U.createElement(L,J({className:r},m),f))}function Me(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Y(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Me(Object(n),!0).forEach(function(t){Ne(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Me(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ne(e,t,n){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pe(e){var t=Fe(e,`string`);return typeof t==`symbol`?t:t+``}function Fe(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var Ie=e=>{var{point:t,childIndex:n,mainColor:r,activeDot:i,dataKey:a,clipPath:o}=e;if(i===!1||t.x==null||t.y==null)return null;var s=Y(Y(Y({},{index:n,dataKey:a,cx:t.x,cy:t.y,r:4,fill:r??`none`,strokeWidth:2,stroke:`#fff`,payload:t.payload,value:t.value}),A(i)),N(i)),c=(0,U.isValidElement)(i)?(0,U.cloneElement)(i,s):typeof i==`function`?i(s):U.createElement(G,s);return U.createElement(L,{className:`recharts-active-dot`,clipPath:o},c)};function Le(e){var{points:t,mainColor:n,activeDot:r,itemDataKey:i,clipPath:a,zIndex:o=y.activeDot}=e,s=I(fe),c=ye();if(t==null||c==null)return null;var l=t.find(e=>c.includes(e.payload));return V(l)?null:U.createElement(p,{zIndex:o},U.createElement(Ie,{point:l,childIndex:Number(s),mainColor:n,dataKey:i,activeDot:r,clipPath:a}))}var Re=(e,t,n,r)=>b(e,`xAxis`,t,r),ze=(e,t,n,r)=>S(e,`xAxis`,t,r),Be=(e,t,n,r)=>b(e,`yAxis`,n,r),Ve=(e,t,n,r)=>S(e,`yAxis`,n,r),He=M([E,Re,Be,ze,Ve],(e,t,n,r,i)=>f(e,`xAxis`)?te(t,r,!1):te(n,i,!1)),Ue=(e,t,n,r,i)=>i;function We(e){return e.type===`line`}var Ge=M([E,Re,Be,ze,Ve,M([g,Ue],(e,t)=>e.filter(We).find(e=>e.id===t)),He,w],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return gt({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}});function Ke(e){var t=A(e),n=3,r=2;if(t!=null){var{r:i,strokeWidth:a}=t,o=Number(i),s=Number(a);return(Number.isNaN(o)||o<0)&&(o=n),(Number.isNaN(s)||s<0)&&(s=r),{r:o,strokeWidth:s}}return{r:n,strokeWidth:r}}var qe=[`id`],Je=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ye=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function Xe(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Xe(Object(n),!0).forEach(function(t){Ze(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Xe(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ze(e,t,n){return(t=Qe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Qe(e){var t=$e(e,`string`);return typeof t==`symbol`?t:t+``}function $e(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Q(e,t){if(e==null)return{};var n,r,i=et(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function et(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var tt=e=>{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:k(n,t),payload:e}]},nt=U.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:oe,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:k(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return U.createElement(be,{tooltipEntrySettings:d})}),rt=(e,t)=>`${t}px ${e}px`;function it(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i<t;++i)r.push(...n);return r}var at=(e,t,n)=>{var r=n.reduce((e,t)=>e+t,0);if(!r)return rt(t,e);for(var i=Math.floor(e/r),a=e%r,o=[],s=0,c=0;s<n.length;c+=(l=n[s])??0,++s){var l,u=n[s];if(u!=null&&c+u>a){o=[...n.slice(0,s),a-c];break}}var d=o.length%2==0?[0,t]:[t];return[...it(n,i),...o,...d].map(e=>`${e}px`).join(`, `)};function ot(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=ce(Q(r,qe));return U.createElement(je,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function st(e){var{showLabels:t,children:n,points:r}=e,i=(0,U.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return U.createElement(ee,{value:t?i:void 0},n)}function ct(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},me(Q(a,Je))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return U.createElement(U.Fragment,null,r?.length>1&&U.createElement(T,X({shapeType:`curve`,option:u},d,{pathRef:n})),U.createElement(ot,{points:r,clipPathId:t,props:a}))}function lt(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ut(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:g,onAnimationEnd:_,onAnimationStart:v}=n,y=i.current,b=xe(o,`recharts-line-`),x=(0,U.useRef)(b),[S,C]=(0,U.useState)(!1),w=!S,T=(0,U.useCallback)(()=>{typeof _==`function`&&_(),C(!1)},[_]),ee=(0,U.useCallback)(()=>{typeof v==`function`&&v(),C(!0)},[v]),E=lt(r.current),D=(0,U.useRef)(0);x.current!==b&&(D.current=a.current,x.current=b);var O=D.current;return U.createElement(st,{points:o,showLabels:w},n.children,U.createElement(m,{animationId:b,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:T,onAnimationStart:ee,key:b},e=>{var l=F(O,E+O,e),u=Math.min(l,E),d=c?s?at(u,E,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):rt(E,u):s==null?void 0:String(s);if(e>0&&E>0&&(i.current=o,a.current=Math.max(a.current,u)),y){var m=y.length/o.length,h=e===1?o:o.map((t,n)=>{var r=Math.floor(n*m);if(y[r]){var i=y[r];return Z(Z({},t),{},{x:F(i.x,t.x,e),y:F(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:F(p*2,t.x,e),y:F(g/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=h,U.createElement(ct,{props:n,points:h,clipPathId:t,pathRef:r,strokeDasharray:d})}return U.createElement(ct,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),U.createElement(h,{label:n.label}))}function dt(e){var{clipPathId:t,props:n}=e,r=(0,U.useRef)(null),i=(0,U.useRef)(0),a=(0,U.useRef)(null);return U.createElement(ut,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var ft=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:C(e.payload,t)}),pt=class extends U.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:c,width:l,height:u,id:d,needClip:f,zIndex:m}=this.props;if(e)return null;var h=s(`recharts-line`,r),g=d,{r:_,strokeWidth:v}=Ke(t),y=H(t),b=_*2+v,x=f?`url(#clipPath-${y?``:`dots-`}${g})`:void 0;return U.createElement(p,{zIndex:m},U.createElement(L,{className:h},f&&U.createElement(`defs`,null,U.createElement(ge,{clipPathId:g,xAxisId:i,yAxisId:a}),!y&&U.createElement(`clipPath`,{id:`clipPath-dots-${g}`},U.createElement(`rect`,{x:c-b/2,y:o-b/2,width:l+b,height:u+b}))),U.createElement(ie,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:ft,errorBarOffset:0},U.createElement(dt,{props:this.props,clipPathId:g}))),U.createElement(Le,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:x}))}},mt={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:y.line,type:`linear`};function ht(e){var t=B(e,mt),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Q(t,Ye),{needClip:_}=_e(p,m),v=ae(),y=D(),b=R(),x=I(e=>Ge(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return U.createElement(pt,X({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function gt(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=C(e,o);if(t===`horizontal`)return{x:O({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(V(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=V(l)?null:n.scale.map(l),d=O({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function _t(e){var t=B(e,mt),n=R();return U.createElement(se,{id:t.id,type:`line`},e=>U.createElement(U.Fragment,null,U.createElement(ne,{legendPayload:tt(t)}),U.createElement(nt,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),U.createElement(le,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),U.createElement(ht,X({},t,{id:e}))))}var vt=U.memo(_t,_);vt.displayName=`Line`;var yt=[`axis`],bt=(0,U.forwardRef)((e,t)=>U.createElement(he,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:yt,tooltipPayloadSearcher:pe,categoricalChartProps:e,ref:t})),$=n(),xt=[{value:`7d`,labelKey:`periods.d7`},{value:`30d`,labelKey:`periods.d30`},{value:`90d`,labelKey:`periods.d90`},{value:`all`,labelKey:`periods.all`},{value:`custom`,labelKey:`periods.custom`}];function St({period:e,from:t,to:n,onChange:r}){let{t:i}=a(`analytics`);function o(e){e===`custom`?r(`custom`,t,n):r(e)}function s(e){r(`custom`,e,n)}function l(e){r(`custom`,t,e)}return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:xt.map(t=>(0,$.jsx)(`button`,{onClick:()=>o(t.value),className:c(`h-7 px-3 rounded-md text-xs font-medium transition-colors`,e===t.value?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent`),children:i(t.labelKey)},t.value))}),e===`custom`&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`date`,value:t,onChange:e=>s(e.target.value),"aria-label":i(`periods.startDate`),className:`h-7 px-2 rounded-md text-xs bg-card border border-border text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i(`periods.to`)}),(0,$.jsx)(`input`,{type:`date`,value:n,onChange:e=>l(e.target.value),"aria-label":i(`periods.endDate`),className:`h-7 px-2 rounded-md text-xs bg-card border border-border text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]})]})}function Ct({kpi:e,windowLabel:t}){let{t:n}=a(`analytics`),r=e.estimatedCostUsd??0,i=e.estimatedCostToday??0,o=e.includesEstimated??r>0,s=r>0,c=i>0,l=typeof e.pricedRuns==`number`||typeof e.unpricedRuns==`number`,u=e.unpricedRuns??0,d=e.pricedRuns??(l?Math.max(0,e.totalJobs-u):e.totalJobs),f=l&&e.totalCostUsd===0&&u>0&&d===0,p=u>0&&(d>0||e.totalCostUsd>0),m=e.unpricedTodayRuns??0,h=e.pricedTodayRuns??(l?Math.max(0,e.jobsToday-m):e.jobsToday),g=l&&e.costToday===0&&m>0&&h===0;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3`,children:[{key:`totalCost`,label:n(`desktop.totalCost`),value:f?`—`:`${s?`~`:``}$${e.totalCostUsd.toFixed(4)}`,sub:g?n(`desktop.costTodayUnavailable`):n(`desktop.costToday`,{value:`${c?`~`:``}$${e.costToday.toFixed(4)}`}),estimated:s,window:t},{key:`totalJobs`,label:n(`desktop.totalJobs`),value:e.totalJobs.toLocaleString(),sub:n(`desktop.jobsToday`,{n:e.jobsToday}),estimated:!1},{key:`successRate`,label:n(`desktop.successRate`),value:`${(e.successRate*100).toFixed(1)}%`,sub:n(`desktop.acrossAllProjects`),estimated:!1},{key:`avgCostPerJob`,label:n(`desktop.avgCostPerJob`),value:e.totalJobs>0&&u===0?`${s?`~`:``}$${(e.totalCostUsd/e.totalJobs).toFixed(5)}`:`—`,sub:n(u>0?`desktop.averageUnavailable`:`desktop.periodAverage`),estimated:s&&e.totalJobs>0}].map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,"data-estimated":e.estimated?`true`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-1 mb-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.label}),`window`in e&&e.window&&(0,$.jsx)(`span`,{"data-testid":`kpi-window-label`,className:`text-[10px] text-muted-foreground/70 whitespace-nowrap`,children:e.window})]}),(0,$.jsx)(`p`,{className:`text-xl font-semibold font-mono`,children:e.value}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.sub})]},e.key))}),o&&(0,$.jsx)(`p`,{"data-testid":`kpi-estimated-footnote`,className:`text-[10px] text-muted-foreground/70 italic`,title:n(`desktop.includesEstimatedTooltip`,{amount:`$${r.toFixed(4)}`}),children:n(`desktop.includesEstimated`,{amount:`$${r.toFixed(4)}`})}),(f||p)&&(0,$.jsx)(`p`,{"data-testid":`kpi-cost-coverage-note`,className:`text-[10px] text-muted-foreground/70 italic`,children:f?n(`desktop.costUnavailable`):n(`desktop.costPartiallyUnavailable`,{count:u})})]})}function wt({data:e}){let{t}=a(`analytics`),n=u(),i=e.length>0&&e.some(e=>e.costUsd>0),o=e.reduce((e,t)=>e+(t.unpricedCount??0),0),s=!i&&o>0,c=i&&o>0,d=Math.max(1,Math.floor(e.length/7)),f=e.filter((e,t)=>t%d===0).map(e=>e.date),p=new Map(e.map(e=>[e.date,e.estimatedCostUsd??0])),m=e.some(e=>(e.estimatedCostUsd??0)>0);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium`,children:t(`desktop.costOverTime`)}),m&&(0,$.jsx)(`span`,{"data-testid":`timeline-estimated-note`,className:`text-[10px] text-muted-foreground/70 italic`,title:t(`desktop.timelineEstimatedTooltip`),children:t(`desktop.includesEstimatedShort`)}),c&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 italic`,children:t(`desktop.costPartiallyUnavailable`,{count:o})})]}),s?(0,$.jsx)(`div`,{"data-testid":`desktop-timeline-cost-unavailable`,className:`h-[200px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.costUnavailable`)}):i?(0,$.jsx)(v,{width:`100%`,height:200,children:(0,$.jsxs)(bt,{data:e,margin:{top:4,right:8,left:0,bottom:0},children:[(0,$.jsx)(P,{strokeDasharray:`3 3`,stroke:`var(--color-border)`}),(0,$.jsx)(de,{dataKey:`date`,ticks:f,tickFormatter:e=>{try{return l(new Date(e),`MMM d`,{locale:r()})}catch{return e}},tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1}),(0,$.jsx)(z,{tickFormatter:e=>`$${e.toFixed(2)}`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1,width:55}),(0,$.jsx)(x,{content:({active:e,payload:t,label:n})=>{if(!e||!t?.length)return null;let r=(p.get(n)??0)>0;return(0,$.jsxs)(`div`,{className:`bg-popover border border-border/30 rounded-lg p-2 text-xs shadow-lg`,children:[(0,$.jsx)(`p`,{className:`text-muted-foreground mb-1`,children:n}),(0,$.jsxs)(`p`,{className:`font-medium`,children:[r?`~`:``,`$`,t[0].value.toFixed(4)]})]})}}),(0,$.jsx)(vt,{type:`monotone`,dataKey:`costUsd`,stroke:n.chart[0],strokeWidth:2,dot:!1,activeDot:{r:3,fill:n.chart[0]}})]})}):(0,$.jsx)(`div`,{className:`h-[200px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.noCostData`)})]})}function Tt({projects:e}){let{t}=a(`analytics`),n=u();if(e.length===0)return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:t(`desktop.projectComparison`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`desktop.noProjects`)})]});let r=Math.max(...e.map(e=>e.totalCostUsd),1e-4);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-4`,children:t(`desktop.projectComparison`)}),(0,$.jsx)(`div`,{className:`space-y-3`,children:e.map((e,i)=>{let a=e.estimatedCostUsd??0,o=a>0,s=e.unpricedRuns??0,c=e.pricedRuns??Math.max(0,e.totalJobs-s),l=s>0&&c===0,u=s>0&&c>0;return(0,$.jsxs)(`div`,{className:`space-y-1`,"data-estimated":o?`true`:void 0,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsxs)(`span`,{className:`font-medium truncate max-w-[160px] flex items-center gap-1`,title:e.projectName,children:[e.projectName,o&&(0,$.jsx)(`span`,{"data-testid":`project-estimated-badge`,className:`text-[9px] uppercase tracking-wide text-muted-foreground/70 not-italic border border-border/40 rounded px-1`,title:t(`desktop.projectEstimatedTooltip`,{amount:`$${a.toFixed(4)}`}),children:t(`desktop.estimatedBadge`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4 text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:t(`desktop.jobsCount`,{count:e.totalJobs})}),(0,$.jsx)(`span`,{children:t(`desktop.successPct`,{pct:(e.successRate*100).toFixed(0)})}),(0,$.jsx)(`span`,{className:`font-mono text-foreground`,title:u?t(`desktop.costPartiallyUnavailable`,{count:s}):void 0,children:l?t(`desktop.costUnavailableShort`):`${o?`~`:``}$${e.totalCostUsd.toFixed(4)}`})]})]}),(0,$.jsx)(`div`,{className:`h-1.5 rounded-full bg-border/30 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${e.totalCostUsd/r*100}%`,backgroundColor:n.chart[i%n.chart.length]}})})]},e.projectId)})})]})}function Et({projects:e}){let{t}=a(`analytics`),n=u();if(e.length===0)return null;let r=e.map(e=>({name:e.projectName.slice(0,12),costUsd:e.totalCostUsd})),i=e.some(e=>e.totalCostUsd>0),o=e.some(e=>(e.unpricedRuns??0)>0);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:t(`desktop.costByProject`)}),!i&&o?(0,$.jsx)(`div`,{"data-testid":`desktop-project-cost-unavailable`,className:`h-[180px] flex items-center justify-center text-xs text-muted-foreground`,children:t(`desktop.costUnavailable`)}):(0,$.jsx)(v,{width:`100%`,height:180,children:(0,$.jsxs)(ve,{data:r,margin:{top:4,right:8,left:0,bottom:0},children:[(0,$.jsx)(P,{strokeDasharray:`3 3`,stroke:`var(--color-border)`}),(0,$.jsx)(de,{dataKey:`name`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1}),(0,$.jsx)(z,{tickFormatter:e=>`$${e.toFixed(2)}`,tick:{fontSize:10,fill:`var(--color-muted-foreground)`},axisLine:!1,tickLine:!1,width:55}),(0,$.jsx)(x,{content:({active:e,payload:t,label:n})=>e&&t?.length?(0,$.jsxs)(`div`,{className:`bg-popover border border-border/30 rounded-lg p-2 text-xs shadow-lg`,children:[(0,$.jsx)(`p`,{className:`text-muted-foreground mb-1`,children:n}),(0,$.jsxs)(`p`,{className:`font-medium`,children:[`$`,t[0].value.toFixed(4)]})]}):null}),(0,$.jsx)(re,{dataKey:`costUsd`,fill:n.chart[1],radius:[3,3,0,0]})]})})]})}function Dt(){let{t:e}=a(`analytics`),[t,n]=(0,U.useState)(`7d`),[r,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(null),[f,p]=(0,U.useState)(!0),[m,h]=(0,U.useState)(null),{registerHandler:g,unregisterHandler:_}=i(),v=(0,U.useCallback)(e=>{let n=e;(n.type===`spending.invalidated`||n.type===`rail.job_completed`)&&y(t,r,s)},[t,r,s]);(0,U.useEffect)(()=>(g(`desktop-analytics`,v),()=>_(`desktop-analytics`)),[v,g,_]);async function y(e,t,n){p(!0),h(null);try{let r=new URLSearchParams({period:e});e===`custom`&&t&&n&&(r.set(`from`,t),r.set(`to`,n));let i=await fetch(`/api/analytics?${r}`);if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json();u(a)}catch(e){h(e.message)}finally{p(!1)}}(0,U.useEffect)(()=>{y(t,r,s)},[t,r,s]);function b(e,t,r){n(e),t!==void 0&&o(t),r!==void 0&&c(r)}return(0,$.jsx)(`div`,{className:`flex flex-col h-full overflow-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Se,{className:`w-4 h-4 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`text-sm font-semibold`,children:e(`desktop.title`)}),l&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:l.period.label})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mr-8`,children:[(0,$.jsx)(St,{period:t,from:r,to:s,onChange:b}),(0,$.jsx)(`button`,{onClick:()=>y(t,r,s),disabled:f,className:`flex items-center gap-1.5 h-7 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50`,"aria-label":e(`desktop.refreshAria`),children:(0,$.jsx)(d,{className:`w-3 h-3 ${f?`animate-spin`:``}`})})]})]}),m&&(0,$.jsx)(`div`,{className:`rounded-lg border border-red-400/30 aurora-light:border-destructive/30 bg-red-400/10 aurora-light:bg-destructive/10 p-3 text-xs text-red-400 aurora-light:text-destructive`,children:e(`desktop.failedToLoad`,{error:m})}),f&&!l&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3`,children:Array.from({length:4}).map((e,t)=>(0,$.jsx)(`div`,{className:`h-20 rounded-lg border border-border/40 bg-card/50 animate-pulse`},t))}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Array.from({length:2}).map((e,t)=>(0,$.jsx)(`div`,{className:`h-[220px] rounded-lg border border-border/40 bg-card/50 animate-pulse`},t))})]}),l&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ct,{kpi:l.kpi,windowLabel:t===`custom`?l.period.label:e(`windowLabels.${t}`)}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,$.jsx)(wt,{data:l.costTimeline}),(0,$.jsx)(Et,{projects:l.projectBreakdown})]}),(0,$.jsx)(Tt,{projects:l.projectBreakdown})]})]})})}export{Dt as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./jsx-runtime-zu2_FqZY.js";import{i as t}from"./chunk-KS7C4IRE-DEKu087k.js";var n=e();function r(){return(0,n.jsx)(t,{to:`/plugins`,replace:!0})}export{r 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{h as r,l as i,r as a}from"./useSharedWebSocket-DaWuiO0S.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as l,s as u}from"./useDesktop-DKNbOF0u.js";import{$ as d,B as f,Q as p,V as m,tt as h}from"./TicketDetailModalContext-YBJX3RmP.js";import{n as g}from"./provider-capabilities-lePfeT_Y.js";import{n as _}from"./save-OsUqVn99.js";import{l as v}from"./MinimizedChatsContext-CroAs6Kh.js";import{n as y}from"./file-text-BcLCfcWZ.js";import{t as b}from"./circle-x-CMYsN4ZH.js";import{t as x}from"./git-branch-BRM0F5GN.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{n as C,t as w}from"./square-Ci-PFcFe.js";import{t as T}from"./rotate-ccw-Wh4id13q.js";import{t as E}from"./search-Cq_gE3Ik.js";import{t as D}from"./triangle-alert-H9T4jAmh.js";import{t as O}from"./x-CBMI9ejn.js";import{L as k,l as A,n as j,r as M,t as N,u as P}from"./dialog-CMgps2MY.js";import{t as F}from"./utils-BC4DHlz2.js";import{n as I,t as L}from"./lib-CGdyxIWg.js";import{t as R}from"./button-D1xExSTF.js";import{n as z}from"./project-repositories-CadLZOnr.js";import{t as ee}from"./useRuntimeRuns-D3YMw9qx.js";import{$ as te,At as ne,C as re,Ct as B,E as ie,Gt as V,Ht as H,K as U,Mt as W,St as ae,T as oe,U as se,Y as ce,Yt as le,b as ue,et as de,gt as fe,k as pe,kt as me,q as he,st as ge,tn as _e,tt as ve,w as ye,x as be,y as xe,zt as Se}from"./index-lTGJJTuk.js";import{l as Ce,n as we,p as Te,r as Ee,t as De}from"./loop-layout-BF8xMiNv.js";import{t as Oe}from"./lib-C7Mhm-gT.js";import{n as ke}from"./job-time-BCL7wee9.js";var Ae=s(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),je=s(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),Me=s(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),Ne=s(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),Pe=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),Fe=s(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Ie=s(`message-circle-question-mark`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),G=e(t(),1),K=n();function Le({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,K.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let i=e[n.key]??`idle`,a=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(U,{children:[(0,K.jsx)(ce,{asChild:!0,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,K.jsx)(Re,{state:i}),(0,K.jsx)(`span`,{className:F(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,K.jsxs)(he,{side:`bottom`,className:`max-w-[200px]`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,K.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,K.jsx)(`div`,{className:F(`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 Re({state:e}){return(0,K.jsxs)(`div`,{className:F(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,K.jsx)(S,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,K.jsx)(V,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,K.jsx)(b,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,K.jsx)(p,{className:`w-6 h-6 text-muted-foreground/20`})]})}function ze(e,t){let n=ke(e??null),r=(typeof t==`number`?t:ke(t??null)?.getTime()??NaN)-(n?.getTime()??NaN);if(!Number.isFinite(r)||r<0)return`—`;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60),o=i%60;return a<60?`${a}m ${o}s`:`${Math.floor(a/60)}h ${a%60}m`}function Be(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 Ve={steps:0,actionKey:``,actionArg:``,turns:0,tokens:0,lastSeenIdx:0};function He(e){if(e.event_type!==`assistant`)return null;try{let t=JSON.parse(e.payload);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t.message,r=(n&&typeof n==`object`&&!Array.isArray(n)?n:t).usage;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r,a=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return a(i.input_tokens)+a(i.output_tokens)+a(i.cache_read_input_tokens)+a(i.cache_creation_input_tokens)}catch{return null}}function Ue(e,t){if(t.type===`reset`)return Ve;if(t.type===`consume`){let{events:n}=t,r=e.lastSeenIdx>n.length?n.length:e.lastSeenIdx;if(n.length<=r)return r===e.lastSeenIdx?e:{...e,lastSeenIdx:r};let{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c}=e;for(let e=r;e<n.length;e++){let t=be(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``);let r=He(n[e]);r!=null&&(s+=1,c+=r)}return{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c,lastSeenIdx:n.length}}return e}function We(e,t){let[n,r]=(0,G.useReducer)(Ue,Ve),i=(0,G.useRef)(e);return(0,G.useEffect)(()=>{i.current!==e&&(i.current=e,r({type:`reset`})),r({type:`consume`,events:t})},[e,t]),n}function Ge(e,t){let n=t&&e.steps===0?`connecting`:e.actionKey||`thinking`,r=n===`delegating`||xe.has(n),i=r&&e.actionArg!==``;return{key:r&&!i?`working`:n,arg:i?e.actionArg:null}}function Ke(e){return`${(e/1e3).toFixed(1)}k`}function qe(e){let t=!!e.total_cost_usd_estimated,n=e.total_cost_usd==null?null:`${t?`~`:``}$${e.total_cost_usd.toFixed(4)}`,r=e.num_turns==null?null:String(e.num_turns),i=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0);return{cost:n,turns:r,tokens:i==null?null:Ke(i)}}function Je(e){if(e.length<=1)return null;let t=e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null;return{totalCostUsd:e.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:e.some(e=>e.total_cost_usd==null),costEstimated:e.some(e=>!!e.total_cost_usd_estimated),nullCostCount:e.filter(e=>e.total_cost_usd==null).length,costUnavailable:e.every(e=>e.total_cost_usd==null),totalTokensIn:e.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:e.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:e.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:e.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:e.filter(t).length,tokensUnavailable:e.every(t),jobCount:e.length}}function Ye(e){return e.costUnavailable?`—`:`${e.costEstimated?`~`:``}${e.hasNullCost?`≥`:``}$${e.totalCostUsd.toFixed(4)}`}function Xe(e){if(e.tokensUnavailable)return`—`;let t=e.totalTokensIn+e.totalTokensOut+e.totalTokensCacheRead+e.totalTokensCacheCreate;return`${(e.nullTokenCount??0)>0?`≥`:``}${Ke(t)}`}var Ze=`specrails-desktop:job-run-details`;function Qe(e){try{let t=localStorage.getItem(Ze);return t?JSON.parse(t)?.[e]===!0:!1}catch{return!1}}function $e(e,t){try{let n=localStorage.getItem(Ze),r={};if(n)try{let e=JSON.parse(n);e&&typeof e==`object`&&(r=e)}catch{}r[e]=t,localStorage.setItem(Ze,JSON.stringify(r))}catch{}}var et={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`},skipped:{variant:`queued`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}};function tt({job:e,events:t,phases:n,phaseDefinitions:r,projectId:i,variant:a,pipelineTotals:s,actions:c,onOpenRun:l}){let{t:u}=o(`jobs`),{t:d}=o(`agentRuntime`),f=e.status===`running`,p=e.status===`queued`,m=e.command.startsWith(`loop:`),h=et[e.status]??et.queued,[v,y]=(0,G.useState)(()=>Date.now());(0,G.useEffect)(()=>{if(!f)return;y(Date.now());let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[f]);let b=e.finished_at?ze(e.started_at,e.finished_at):f?ze(e.started_at,v):`—`,x=We(e.id,t),C=ee(i,{jobId:e.id,enabled:!!i}),w=C.runs[0],[T,E]=(0,G.useState)(()=>Qe(a)),D=e=>{E(e),$e(a,e)},O=(0,G.useMemo)(()=>r.find(e=>n[e.key]===`running`)?.label??null,[n,r]),k=w?.nextStep?d(`roles.${w.nextStep}`,{defaultValue:w.nextStep}):null,A=O??k,{key:j,arg:M}=Ge(x,f),N=M==null?u(`statusPanel.activity.${j}`):u(`statusPanel.activity.${j}`,{arg:M}),P=f?A?u(`runHeader.phaseActivity`,{phase:A,activity:N}):N:w&&!w.active&&w.nextStep&&(w.canResume||w.pendingQuestion||w.pendingApproval)?u(`runHeader.phaseActivity`,{phase:d(`runs.status.${w.status}`,{defaultValue:w.status}),activity:d(`runs.phase`,{phase:k})}):null,I=m&&f&&x.steps>0?u(`statusPanel.steps`,{count:x.steps}):null,L=qe(e),z=!f&&!p,te=(0,G.useMemo)(()=>z?Be(t):[],[t,z]),ne=f&&x.turns>0,B=C.runs.length>0?C.error:``,V=!!w?.pendingQuestion&&!!w.canResume&&!w.recoverableSteps.length,H=z||ne||!!w&&!!i||!!B,W=C.busy!==null,ae=w?(0,K.jsxs)(K.Fragment,{children:[w.canResume&&!V&&(w.engineVersion===2&&w.recoverableSteps.length>0?(0,K.jsx)(ie,{run:w,busy:W,onRecover:e=>void C.act(w,`recover`,e)},`${i}:${w.runId}`):(0,K.jsx)(R,{size:`sm`,className:`h-7`,disabled:W,onClick:()=>void C.act(w,w.recoverableSteps.length?`recover`:w.pendingApproval?`approve`:`resume`),children:w.recoverableSteps.length?d(`runs.recover`):w.pendingApproval?d(`runs.approve`):d(`runs.resume`)})),V&&(0,K.jsxs)(R,{size:`sm`,variant:`outline`,className:`h-7 border-accent-warning/40 text-accent-warning hover:bg-accent-warning/10`,onClick:()=>D(!0),children:[(0,K.jsx)(Ie,{className:`w-3.5 h-3.5 mr-1.5`,"aria-hidden":!0}),u(`runHeader.questionPending`)]}),w.canSettle&&(0,K.jsx)(R,{size:`sm`,className:`h-7`,disabled:W,onClick:()=>void C.act(w,`settle`),children:d(`runs.prepareDelivery`)}),w.forkSuccessor&&l&&(0,K.jsx)(R,{size:`sm`,variant:`outline`,onClick:()=>l(w.forkSuccessor),children:u(`loopExplorer.openFork`)}),w.canCancel&&(0,K.jsx)(R,{size:`sm`,variant:`secondary`,className:`h-7`,disabled:W,onClick:()=>void C.act(w,`cancel`),children:d(`runs.cancel`)})]}):null;return(0,K.jsxs)(`div`,{"data-testid":`job-run-header`,className:F(`shrink-0`,a===`glass`?`border-b border-border/30 bg-surface/30`:`border-b border-border bg-background`),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap px-3 py-2 min-w-0`,children:[(0,K.jsxs)(U,{children:[(0,K.jsx)(ce,{asChild:!0,children:(0,K.jsx)(`div`,{children:(0,K.jsx)(pe,{variant:h.variant,children:u(h.labelKey)})})}),(0,K.jsx)(he,{children:u(h.tooltipKey)})]}),(0,K.jsxs)(`span`,{className:F(`inline-flex items-center gap-1.5 text-xs tabular-nums`,f?`text-accent-info font-medium`:`text-muted-foreground`),title:u(f?`statusPanel.liveTooltip`:`statusPanel.duration`),children:[f&&(0,K.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,"aria-hidden":!0}),b]}),P&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 flex-1 basis-40 text-xs text-muted-foreground`,children:[f&&(0,K.jsx)(S,{className:`w-3 h-3 shrink-0 text-accent-info animate-spin`,"aria-hidden":!0}),(0,K.jsx)(`span`,{className:`truncate`,"data-testid":`job-run-activity`,children:P})]}),!P&&(0,K.jsx)(`span`,{className:`flex-1`}),I&&(0,K.jsx)(`span`,{className:`text-[11px] text-muted-foreground/70 tabular-nums shrink-0`,children:I}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 ml-auto`,children:[ae,c,H&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>D(!T),"aria-expanded":T,className:`inline-flex items-center gap-1 h-7 px-2 rounded-md text-[11px] text-muted-foreground hover:text-foreground hover:bg-surface/60 transition-colors`,children:[u(`runHeader.details`),(0,K.jsx)(_,{className:F(`w-3.5 h-3.5 transition-transform duration-150`,T&&`rotate-180`),"aria-hidden":!0})]})]})]}),r.length>0&&(0,K.jsx)(`div`,{className:`px-3 pb-2 overflow-x-auto`,children:(0,K.jsx)(Le,{phases:n,phaseDefinitions:r})}),H&&T&&(0,K.jsxs)(`div`,{"data-testid":`job-run-details`,className:`px-3 pb-3 space-y-3 border-t border-border/20 pt-3 text-xs`,children:[ne&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:String(x.turns)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:Ke(x.tokens)})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-1`,children:u(`runHeader.liveReported`)})]}),z&&(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-lg`,children:[(0,K.jsx)(q,{label:u(`statusPanel.cost`),value:L.cost,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:g(e.provider)?u(`statusPanel.costUnknownLocal`):u(`statusPanel.notAvailable`),naTooltip:g(e.provider)?u(`statusPanel.costUnknownLocalTooltip`):void 0}),(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:L.turns,naCaption:u(`statusPanel.notAvailable`)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:L.tokens,naCaption:u(`statusPanel.notAvailable`)})]}),z&&s&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.pipelineTotal`,{count:s.jobCount})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.totalCost`),value:Ye(s),valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,K.jsx)(q,{label:u(`statusPanel.totalTokens`),value:Xe(s)})]}),s.hasNullCost&&!s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:u(`statusPanel.pipelinePartialTooltip`),children:u(`statusPanel.pipelinePartial`,{count:s.nullCostCount??0})}),s.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:u(`statusPanel.pipelineCostUnavailable`)}),(s.nullTokenCount??0)>0&&(0,K.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:u(`statusPanel.pipelineUsageTooltip`),children:s.tokensUnavailable?u(`statusPanel.pipelineUsageUnavailable`):u(`statusPanel.pipelineUsagePartial`,{count:s.nullTokenCount??0})})]}),te.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.filesModified`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:te.map(e=>(0,K.jsx)(`code`,{className:`text-[10px] font-mono bg-muted/30 px-2 py-0.5 rounded text-cyan-400/80 aurora-light:text-accent-info`,children:e},e))})]}),(w||B)&&i&&(0,K.jsxs)(`section`,{"aria-label":d(`runs.implementation`),className:`space-y-2`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[B&&(0,K.jsx)(`p`,{role:`alert`,className:`text-destructive`,children:B}),w?.historical&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`evidence.historical`)}),w?.status===`succeeded`&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.reviewDelivery`)}),w?.canResume&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.preserveProgress`)}),w?.error&&(0,K.jsx)(`p`,{className:`text-destructive`,children:w.error}),w?.pendingApproval?.reason&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:w.pendingApproval.reason}),w?.pendingQuestion&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:d(`runs.question`)}),(0,K.jsx)(`p`,{className:`whitespace-pre-wrap`,children:w.pendingQuestion.question}),V&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[d(`runs.answerLabel`),(0,K.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border border-input bg-background px-2 py-1 text-sm`,maxLength:2e4,placeholder:d(`runs.answerPlaceholder`),value:C.answers[w.runId]??``,onChange:e=>C.setAnswer(w.runId,e.target.value)})]}),(0,K.jsx)(R,{size:`sm`,disabled:W||!C.answers[w.runId]?.trim(),onClick:()=>void C.act(w,`answer`),children:d(`runs.answer`)})]})]}),w?.metrics&&(0,K.jsx)(re,{metrics:w.metrics}),w&&(0,K.jsx)(oe,{projectId:i,runId:w.runId,summary:w.efficiencySummary,historical:w.historical}),w&&(0,K.jsx)(ye,{projectId:i,run:w,onAccepted:C.refresh})]})]})]})}function q({label:e,value:t,valueClass:n,naCaption:r,naTooltip:i}){return(0,K.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-2.5 py-1.5`,title:t==null?i:void 0,children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,K.jsx)(`p`,{className:F(`text-sm font-semibold tabular-nums`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&r&&(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/40`,children:r})]})}function nt(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 rt=new Set;function it({ticketId:e,onOpen:t,children:n}){let{t:r}=o(`agent`),i=r(`refs.openTicket`,{id:e});return(0,K.jsx)(`button`,{type:`button`,"data-testid":`log-ticket-ref`,onClick:n=>{n.stopPropagation(),t(e)},title:i,"aria-label":i,className:`inline cursor-pointer p-0 align-baseline text-accent-primary/90 underline decoration-accent-primary/50 decoration-dotted underline-offset-2 transition-colors hover:text-accent-primary hover:decoration-solid`,children:n})}function at(e){if(!e.includes(`#`))return null;let t=ve(e,rt);return t.some(e=>e.kind===`ticket`)?t:null}function ot(e,t){let n=at(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,K.jsx)(it,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,K.jsx)(G.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var st=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function ct(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 lt(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!st.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=ve(n.value,rt);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(ct))}else lt(n)}}function ut(){return e=>lt(e)}function dt(e){let{activeProjectId:t}=l(),{openRef:n}=ge(),r=e??t??void 0;return(0,G.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function ft(e,t){let n=`${e.id??t}`,i=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:i}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:i}:nt(t)?{id:n,content:t,type:`assistant`,timestamp:i}:{id:n,content:t,type:`plain`,timestamp:i}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),a=[];return t.duration_ms&&a.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&a.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&a.push(r.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${r.t(`jobs:logViewer.completed`)}${a.length?` — ${a.join(` · `)}`:``}`,type:`result`,timestamp:i}}catch{return null}return null}function pt(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 mt(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 ht(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 gt({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=o(`jobs`),[a,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(!0),[d,f]=(0,G.useState)(new Set),p=(0,G.useRef)(null),m=(0,G.useRef)(null),h=dt(n),{processedLines:g,groups:v,totalLines:y}=(0,G.useMemo)(()=>{let t=pt(mt(e.map((e,t)=>ft(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:ht(t),totalLines:t.length}},[e,i.language]),b=(0,G.useMemo)(()=>{if(!a)return y;let e=a.toLowerCase();return g.filter(t=>t.content.toLowerCase().includes(e)).length},[a,g,y]),x=(0,G.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,G.useEffect)(()=>{c&&x()},[e.length,c,x]);function S(){let e=m.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;l(t)}function C(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):y===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,K.jsx)(E,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,K.jsx)(se,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>s(e.target.value),className:`pl-7 h-7`})]}),(0,K.jsx)(R,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=g.map(e=>e.content).join(`
|
|
3
|
-
`);navigator.clipboard.writeText(e).then(()=>{u.success(r(`logViewer.copySuccess`))}).catch(()=>{u.error(r(`logViewer.copyFailed`))})},children:(0,K.jsx)(H,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:b,total:y})})]}),(0,K.jsxs)(`div`,{ref:m,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:S,children:[v.map(e=>(0,K.jsx)(_t,{group:e,filter:a,collapsed:d.has(e.key),onToggle:()=>C(e.key),onOpenTicket:h},e.key)),(0,K.jsx)(`div`,{ref:p})]}),!c&&(0,K.jsxs)(R,{size:`sm`,variant:`secondary`,onClick:()=>{l(!0),x()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,K.jsx)(_,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var _t=(0,G.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:a}=o(`jobs`),s=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return s.length===0?null:(0,K.jsx)(`div`,{children:s.map((e,t)=>(0,K.jsx)(xt,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let c=e.header.content;return(0,K.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:F(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,K.jsx)(y,{className:F(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:c}),e.header.timestamp&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 font-mono tabular-nums shrink-0`,children:new Date(e.header.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:a(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:s.length===0?(0,K.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:a(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):s.map((e,t)=>(0,K.jsx)(xt,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),vt=[Oe],yt=[L],bt=[L,ut],xt=(0,G.memo)(function({line:e,even:t,onOpenTicket:n}){let r=e.type===`assistant`,i=e.type===`diff-add`,a=e.type===`diff-remove`,o=e.type===`diff-meta`,s=e.type===`diff-hunk`,c=i||a||o||s,l=n!=null&&(e.type===`plain`||e.type===`log`),u=(0,G.useMemo)(()=>l&&n?ot(e.content,n):e.content,[l,n,e.content]),d=r&&n?bt:yt,f=(0,G.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=de(e);return r?.kind===`ticket`?(0,K.jsx)(it,{ticketId:r.ticketId,onOpen:n,children:t}):(0,K.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,K.jsxs)(`div`,{className:F(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0 mt-0.5 w-[52px] font-mono tabular-nums`,children:new Date(e.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),r?(0,K.jsx)(`div`,{className:`flex-1 min-w-0 prose prose-invert prose-xs max-w-none
|
|
4
|
-
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,K.jsx)(I,{remarkPlugins:d,rehypePlugins:vt,components:f,children:e.content})}):(0,K.jsx)(`span`,{className:F(`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})]})}),St=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function Ct(e){if(!St(e)||typeof e.entry!=`string`||!Array.isArray(e.nodes)||e.nodes.length>1e4)return null;let t=[];for(let n of e.nodes){if(!St(n)||typeof n.id!=`string`||!n.id||typeof n.kind!=`string`||typeof n.label!=`string`||!St(n.ends)||Object.values(n.ends).some(e=>e!==null&&typeof e!=`string`)||n.component!==void 0&&typeof n.component!=`string`)return null;t.push({id:n.id,kind:n.kind,label:n.label,ends:n.ends,...typeof n.component==`string`?{component:n.component}:{}})}let n=new Set(t.map(e=>e.id));return n.size!==t.length||!n.has(e.entry)||t.some(e=>Object.values(e.ends).some(e=>e!==null&&!n.has(e)))?null:{entry:e.entry,nodes:t}}function wt(e){let t=Ct(e);if(!t||!St(e)||e.components!==void 0&&!St(e.components))return null;let n=Object.create(null);for(let[t,r]of Object.entries(e.components??{})){let e=Ct(r);if(!e)return null;n[t]=e}return{...t,components:n}}var Tt=[`network`,`credential`,`environment-variable`,`toolchain`,`setup`,`environment`,`scope`],J=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Y=e=>typeof e==`number`&&Number.isFinite(e)&&e>=0,Et=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`);function Dt(e){if(!J(e)||!Tt.includes(String(e.kind))||typeof e.requiredAction!=`string`)return;let t=e=>typeof e==`string`?e:``;return{kind:e.kind,reason:t(e.reason),command:t(e.command),args:Et(e.args)?e.args:[],cwd:t(e.cwd),requiredAction:e.requiredAction,...typeof e.evidenceId==`string`?{evidenceId:e.evidenceId}:{}}}var Ot=e=>[e.command,...e.args].filter(Boolean).join(` `);function kt(e){if(!J(e)||e.version!==1||typeof e.execution!=`string`||!Y(e.steps)||!Y(e.deciderEvaluations)||!(e.turns===null||Y(e.turns))||!(e.costUsd===null||Y(e.costUsd))||typeof e.costUncertain!=`boolean`||e.engineVersion===2&&e.completion!==void 0&&(!J(e.completion)||typeof e.completion.ok!=`boolean`||typeof e.completion.verified!=`boolean`||!Et(e.completion.reasons)))return null;if(e.engineVersion===2&&J(e.completion)&&e.completion.blocker!==void 0){let{blocker:t,...n}=e.completion,r=Dt(t);return{...e,completion:{...n,...r?{blocker:r}:{}}}}if(e.core!==null){let t=e.core;if(!J(t)||typeof t.change!=`string`||typeof t.recordedAt!=`string`||!J(t.completion)||![`implementation`,`validation`,`archive`,`delivery`].every(e=>typeof t.completion==`object`&&typeof t.completion[e]==`string`)||!Et(t.completion.reasons)||!Et(t.findings)||!Array.isArray(t.exceptions)||!Array.isArray(t.checks)||!Array.isArray(t.phases)||!t.exceptions.every(e=>J(e)&&[`requirement`,`reason`,`impact`,`acceptedBy`,`approvalEvidence`].every(t=>typeof e[t]==`string`))||!t.checks.every(e=>J(e)&&[`name`,`status`,`scope`,`limitations`].every(t=>typeof e[t]==`string`)&&typeof e.required==`boolean`&&Et(e.evidence))||!t.phases.every(e=>J(e)&&typeof e.name==`string`&&typeof e.status==`string`&&(e.durationMs===null||Y(e.durationMs))&&(e.attempts===null||Y(e.attempts))))return null}return e}function X(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var At=/^\s*━+\s*Step\s+\d+\s*·/,jt=/\s*\(iteration\s+\d+\)\s*$/i;function Mt(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function Nt(e){let t=Mt(e.title);return e.iteration==null?t:t.replace(jt,``)}function Pt(e){return e.meta.nodeId??`${e.meta.kind}::${Mt(e.meta.title).replace(jt,``)}`}function Ft(e){let t=null,n=0,r=null,i=[[]],a=new Map,o=[];for(let s=0;s<e.length;s++){let c=e[s];if(c.event_type===`loop_completion`){r=kt(X(c.payload));continue}if(c.event_type===`runtime-graph`){let e=X(c.payload);if(e&&Array.isArray(e.nodes)&&Array.isArray(e.edges)){let n=e.nodes.filter(e=>!!(e&&typeof e==`object`&&typeof e.path==`string`)),r=e.edges.filter(e=>!!(e&&typeof e==`object`&&typeof e.from==`string`&&typeof e.to==`string`)),i=t;t={...i??{},runtimeTopology:wt(e.graph)??void 0,loopId:typeof e.workflowId==`string`?e.workflowId:i?.loopId,graph:{nodes:n.map((e,t)=>({id:String(e.path),type:`core`,position:{x:0,y:t*100},data:{label:String(e.label??e.path),kind:e.kind}})),edges:r.map((e,t)=>({id:`core-edge-${t}`,source:String(e.from),target:String(e.to),label:String(e.label)})),config:i?.graph.config??{maxIterations:1,timeoutMinutes:0}}}}continue}if(c.event_type===`loop_graph`){let e=X(c.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(c.event_type===`loop_step`){let e=X(c.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),o.push({meta:{index:e.index,traceId:typeof e.traceId==`string`?e.traceId:void 0,spanId:typeof e.spanId==`string`?e.spanId:void 0,nodePath:typeof e.nodePath==`string`?e.nodePath:void 0,scopeId:typeof e.scopeId==`string`?e.scopeId:void 0,branch:typeof e.branch==`string`?e.branch:void 0,attemptId:typeof e.attemptId==`string`?e.attemptId:void 0,attempt:typeof e.attempt==`number`?e.attempt:void 0,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}),typeof e.attemptId==`string`&&a.set(e.attemptId,o.length-1),i.push([]);continue}if(c.event_type===`loop_step_end`){let e=X(c.payload);if(!e||typeof e.index!=`number`)continue;for(let t=o.length-1;t>=0;t--)if(o[t].meta.index===e.index){o[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`paused`?`paused`:e.status===`interrupted`?`interrupted`: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 l=X(c.payload),u=l?.attemptId??(l?.event&&typeof l.event==`object`?l.event.attemptId:void 0),d=typeof u==`string`?a.get(u)??-1:-1,f=d>=0?d:u===void 0?o.length-1:-1,p=f>=0,m=ft(c,s);if(m&&!(p&&At.test(m.content))&&i[f+1].push(m),p){let e=be(c);e.step&&e.actionKey&&(o[f].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let s=e=>pt(mt(e)),c=s(i[0]),l=o.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:s(i[t+1]),end:e.end,lastActivity:e.lastActivity})),u=c.length+l.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:c,segments:l,maxIteration:n,totalLines:u,...r?{completion:r}:{}}}function It(e,t){return e.end?e.end.status:t.isLast||e.meta.attemptId?t.jobSettled?`interrupted`:`running`:`unknown`}function Lt(e){return e===`continue`?0:e===`stop`?2:1}function Rt(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)=>Lt(e.branch)-Lt(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 zt(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Bt(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=Pt(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=It(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r===`stalled`?`failed`:r};if(e.graphMeta)return Rt(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:zt(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:zt(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:zt(e)??Nt(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:zt(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=Pt(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:Nt(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function Vt(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 Ht({topology:e,segments:t,settled:n,onFocus:r,onFork:i,forkBusy:a}){let{t:s}=o(`jobs`),c=_e(),[l,u]=(0,G.useState)(!1),[f,m]=(0,G.useState)(!1),[h,g]=(0,G.useState)([]),[_,v]=(0,G.useState)(null),y=h[h.length-1]??{path:``,body:e},x=e=>y.path?`${y.path}/${e}`:e,C=t.filter(e=>(e.meta.nodePath??e.meta.nodeId)===_),w=(0,G.useMemo)(()=>{let e=y.body.nodes.flatMap(e=>Object.entries(e.ends).flatMap(([t,n])=>n===null?[]:[{id:`${e.id}:${t}`,source:e.id,target:n,label:t,markerEnd:{type:Te.ArrowClosed}}])),r=new Map;for(let e of t){let t=e.meta.nodePath??e.meta.nodeId;if(!t)continue;let n=r.get(t)??new Map;n.set(e.meta.scopeId??`legacy`,e),r.set(t,n)}let i=y.body.nodes.map(e=>{let i=y.path?`${y.path}/${e.id}`:e.id,a=[...(r.get(i)??new Map).values()].map(e=>It(e,{isLast:e===t[t.length-1],jobSettled:n})),o=[`running`,`paused`,`failed`,`stalled`,`interrupted`].find(e=>a.includes(e))??(a.length?a.every(e=>e===`ok`)?`ok`:`unknown`:`pending`),c=o===`running`?`var(--color-accent-primary)`:o===`ok`?`var(--color-accent-success)`:o===`failed`?`var(--color-destructive)`:[`paused`,`stalled`,`interrupted`].includes(o)?`var(--color-accent-warning)`:`var(--color-border)`,l=o===`running`?S:o===`ok`?V:o===`failed`?b:[`paused`,`stalled`,`interrupted`].includes(o)?Ne:o===`unknown`?d:p;return{id:e.id,type:`default`,position:{x:0,y:0},data:{kind:`core`,label:(0,K.jsxs)(`span`,{className:`block text-left`,"data-state":o,children:[(0,K.jsxs)(`strong`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(l,{"aria-hidden":!0,className:`h-4 w-4 shrink-0 ${o===`running`?`motion-safe:animate-spin`:``}`,style:{color:o===`pending`||o===`unknown`?`var(--color-muted-foreground)`:c}}),e.label]}),(0,K.jsxs)(`span`,{className:`mt-1 block text-[10px]`,children:[e.kind,` · `,s(`loopExplorer.graphState.${o}`)]})]})},style:{background:o===`pending`||o===`unknown`?`var(--color-background)`:`color-mix(in srgb, ${c} 12%, var(--color-background))`,color:`var(--color-foreground)`,borderColor:c,borderWidth:o===`pending`||o===`unknown`?1:2,boxShadow:o===`running`?`0 0 0 2px color-mix(in srgb, ${c} 30%, transparent), 0 0 22px color-mix(in srgb, ${c} 35%, transparent)`:void 0}}});return i.sort((e,t)=>e.id===y.body.entry?-1:+(t.id===y.body.entry)),{nodes:De(i,e,`vertical`),edges:e}},[y.body,y.path,t,n,s]),T=y.body.nodes.find(e=>x(e.id)===_),E=T?.component?e.components[T.component]:void 0,D=e=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 py-2 text-xs`,children:[h.length>0&&(0,K.jsx)(R,{size:`sm`,variant:`ghost`,onClick:()=>{g(e=>e.slice(0,-1)),v(null)},children:s(`loopExplorer.graphBack`)}),(0,K.jsx)(`code`,{children:y.path||`/`}),e?(0,K.jsx)(j,{asChild:!0,children:(0,K.jsx)(R,{className:`ml-auto`,size:`sm`,variant:`ghost`,"aria-label":s(`loopExplorer.graphExitFullscreen`),title:s(`loopExplorer.graphExitFullscreen`),children:(0,K.jsx)(me,{className:`h-4 w-4`})})}):(0,K.jsx)(P,{asChild:!0,children:(0,K.jsx)(R,{className:`ml-auto`,size:`sm`,variant:`ghost`,"aria-label":s(`loopExplorer.graphFullscreen`),title:s(`loopExplorer.graphFullscreen`),children:(0,K.jsx)(ne,{className:`h-4 w-4`})})})]}),(0,K.jsx)(`div`,{className:e?`min-h-0 flex-1 rounded border border-border`:`h-72 rounded border border-border`,"aria-label":s(`loopExplorer.runtimeGraph`),children:(0,K.jsxs)(Ce,{colorMode:c.scheme===`dark`?`dark`:`light`,nodes:w.nodes,edges:w.edges,nodesDraggable:!1,nodesConnectable:!1,edgesReconnectable:!1,deleteKeyCode:null,fitView:!0,minZoom:.1,onNodeClick:(e,t)=>v(x(t.id)),children:[(0,K.jsx)(we,{}),(0,K.jsx)(Ee,{showInteractive:!1})]},`${y.path}:${e}`)}),_&&(0,K.jsxs)(`div`,{className:`shrink-0 space-y-2 py-2 text-xs`,children:[(0,K.jsx)(`code`,{className:`break-all`,children:_}),E&&h.length<16&&(0,K.jsx)(R,{size:`sm`,variant:`outline`,onClick:()=>{g(e=>[...e,{path:_,body:E}]),v(null)},children:s(`loopExplorer.graphOpenComponent`)}),C.length===0?(0,K.jsx)(`p`,{children:s(`loopExplorer.graphNoAttempts`)}):(0,K.jsx)(`ul`,{className:`max-h-40 space-y-1 overflow-auto`,children:C.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{className:`text-left underline underline-offset-2`,onClick:()=>r(e.key),children:[e.meta.scopeId??`/`,` · `,e.meta.attemptId??e.meta.index,` · `,s(`loopExplorer.graphState.${It(e,{isLast:!0,jobSettled:n})}`)]}),i&&e.end&&e.meta.nodePath&&e.meta.scopeId&&e.meta.iteration!=null&&(0,K.jsx)(R,{className:`ml-2`,size:`sm`,variant:`outline`,disabled:a,onClick:()=>i(e),children:s(`loopExplorer.repeatFromHere`)}),e.meta.traceId&&(0,K.jsxs)(`code`,{className:`block break-all text-[10px] text-muted-foreground`,children:[`traceId: `,e.meta.traceId,e.meta.spanId?` · spanId: ${e.meta.spanId}`:``]})]},e.key))})]})]});return(0,K.jsxs)(N,{open:f,onOpenChange:m,children:[(0,K.jsxs)(`details`,{className:`shrink-0 border-b border-border p-2`,onToggle:e=>u(e.currentTarget.open),children:[(0,K.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium`,children:s(`loopExplorer.runtimeGraph`)}),l&&D(!1)]}),(0,K.jsxs)(M,{overlayClassName:`z-[2147483646]`,className:`z-[2147483647] flex w-screen max-w-none !max-h-none flex-col gap-0 rounded-none p-3 sm:rounded-none`,style:{height:`calc(100dvh - ${k()}px)`},showCloseButton:!1,"aria-describedby":void 0,children:[(0,K.jsx)(A,{className:`shrink-0 text-sm`,children:s(`loopExplorer.runtimeGraph`)}),D(!0)]})]})}function Ut({blocker:e}){let{t}=o(`loops`),[n,r]=(0,G.useState)(!1),i=Ot(e),a=async()=>{try{await navigator.clipboard.writeText(i),r(!0),window.setTimeout(()=>r(!1),1500)}catch{}};return(0,K.jsxs)(`div`,{"data-testid":`loop-completion-blocker`,className:`rounded-md border border-accent-warning/40 bg-accent-warning/5 px-3 py-2.5 space-y-1.5`,children:[(0,K.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-accent-warning`,children:[(0,K.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),(0,K.jsx)(`span`,{children:t(`core.hostBlocked`)}),(0,K.jsx)(`span`,{className:`ml-auto rounded-full border border-accent-warning/40 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider`,children:t(`core.blockerKind.${e.kind}`,{defaultValue:e.kind})})]}),e.reason&&(0,K.jsx)(`p`,{className:`text-foreground/80`,children:e.reason}),i&&(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/60`,children:t(`core.failingCommand`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":t(`core.copyCommand`),title:t(`core.copyCommand`),className:`p-0.5 text-muted-foreground/50 hover:text-foreground transition-colors cursor-pointer`,children:n?(0,K.jsx)(v,{className:`h-2.5 w-2.5 text-accent-success`}):(0,K.jsx)(H,{className:`h-2.5 w-2.5`})}),n&&(0,K.jsx)(`span`,{className:`text-[9px] text-accent-success`,children:t(`core.copiedCommand`)})]}),(0,K.jsxs)(`pre`,{className:`mt-0.5 font-mono text-[10px] leading-relaxed text-foreground/80 whitespace-pre-wrap break-words`,children:[i,e.cwd?` # ${t(`core.inDirectory`,{cwd:e.cwd})}`:``]})]}),(0,K.jsxs)(`p`,{children:[(0,K.jsxs)(`span`,{className:`font-medium`,children:[t(`core.requiredAction`),`:`]}),` `,e.requiredAction]})]})}function Wt({result:e}){let{t}=o(`jobs`),{t:n}=o(`loops`),r=e.core,i=e=>t(`completion.status.${e}`,{defaultValue:e});return(0,K.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,K.jsxs)(`p`,{className:`font-medium`,children:[t(`completion.execution`),`: `,i(e.execution)]}),e.completion?(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`p`,{className:e.completion.ok?`text-accent-success`:`text-accent-warning`,children:[n(`core.acceptance`),`: `,i(e.completion.ok?`complete`:`blocked`)]}),(0,K.jsxs)(`p`,{children:[n(`core.verified`),`: `,i(e.completion.verified?`verified`:`unverified`)]}),e.completion.blocker?(0,K.jsx)(Ut,{blocker:e.completion.blocker}):e.completion.reasons.map((e,t)=>(0,K.jsx)(`p`,{className:`text-foreground/70`,children:e},t))]}):r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dl`,{className:`grid grid-cols-2 gap-2 md:grid-cols-4`,children:[`implementation`,`validation`,`archive`,`delivery`].map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-foreground/70`,children:t(`completion.${e}`)}),(0,K.jsx)(`dd`,{className:r.completion[e]===`with-exceptions`||r.completion[e]===`blocked`?`text-accent-warning font-medium`:`font-medium`,children:i(r.completion[e])})]},e))}),(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:`cursor-pointer`,children:t(`completion.evidence`)}),(0,K.jsxs)(`div`,{className:`space-y-2 pt-2 break-words`,children:[(0,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.snapshot`,{change:r.change,at:r.recordedAt})}),r.completion.reasons.map((e,t)=>(0,K.jsx)(`p`,{children:e},`reason-${t}`)),r.exceptions.map((e,n)=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:e.requirement}),(0,K.jsxs)(`p`,{children:[e.reason,` — `,e.impact]}),(0,K.jsxs)(`p`,{children:[t(`completion.acceptedBy`,{by:e.acceptedBy}),`: `,e.approvalEvidence]})]},`exception-${n}`)),r.checks.map((e,n)=>(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`font-medium`,children:[e.name,`: `,i(e.status),` (`,t(e.required?`completion.required`:`completion.supplementary`),`)`]}),(0,K.jsxs)(`p`,{children:[e.scope,` — `,e.limitations]}),(0,K.jsx)(`p`,{className:`text-foreground/70`,children:e.evidence.join(`; `)})]},`check-${n}`)),r.findings.map((e,t)=>(0,K.jsx)(`p`,{children:e},`finding-${t}`)),r.phases.map(e=>(0,K.jsxs)(`p`,{children:[e.name,`: `,i(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,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.phaseCostUnavailable`)})]})]})]}):(0,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.noCoreEvidence`)})]})}var Gt={start:C,"ai-step":le,shell:fe,decider:x,condition:x,end:Se},Kt=w,qt={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`},Jt={start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function Yt(e){return Gt[e]??Kt}function Xt({chips:e,iteration:t,onChipClick:n,variant:r}){let{t:i}=o(`jobs`);return e.length===0&&!t?null:(0,K.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":i(`loopExplorer.stepMapAria`),className:F(`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=Yt(e.kind),a=qt[e.kind]??`text-foreground`,o=Jt[e.kind]??`border-border/40`,s=e.label??i(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),c=e.latestSegmentKey!=null;return(0,K.jsxs)(G.Fragment,{children:[t>0&&(0,K.jsx)(y,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,K.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${s} — ${e.state}`,disabled:!c,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:F(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,o,e.state===`pending`&&`opacity-45 border-border/40`,(e.state===`interrupted`||e.state===`paused`)&&`border-dashed border-accent-warning/50`,c?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,K.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,K.jsx)(r,{className:F(`w-3 h-3 shrink-0`,a)}),(0,K.jsx)(`span`,{className:F(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:s}),e.state===`paused`&&(0,K.jsx)(`span`,{className:`text-accent-warning`,children:i(`loopExplorer.paused`)}),e.state===`ok`&&(0,K.jsx)(v,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,K.jsx)(O,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,K.jsx)(m,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,K.jsx)(h,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,K.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,K.jsx)(B,{className:`w-3 h-3`}),t.limit==null?i(`loopExplorer.iterationBadge`,{count:t.current}):i(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var Zt=(0,G.memo)(Xt);function Qt({className:e}){return(0,K.jsxs)(`span`,{className:F(`relative flex h-2 w-2 shrink-0`,e),children:[(0,K.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,K.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function $t(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function en(e,t,n,r){return e.length===0?(0,K.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,K.jsx)(xt,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function tn({label:e,value:t,copyLabel:n}){let[r,i]=(0,G.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,K.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,K.jsx)(v,{className:`w-2.5 h-2.5 text-accent-success`}):(0,K.jsx)(H,{className:`w-2.5 h-2.5`})})]}),(0,K.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function nn({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:a,setRef:s,onOpenTicket:c}){let{t:l}=o(`jobs`),{meta:u,lines:d,end:f,lastActivity:p}=e,m=Yt(u.kind),h=qt[u.kind]??`text-foreground`,g=$t(d,r),_=t===`running`,b=!!(u.template||u.command),[x,S]=(0,G.useState)(!1);return(0,K.jsxs)(`div`,{ref:t=>s(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:F(`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`||t===`paused`)&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,K.jsxs)(`div`,{className:F(`flex items-stretch bg-primary/5 border-b`,t===`failed`||t===`stalled`?`border-destructive/20`:`border-primary/20`),children:[(0,K.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,K.jsx)(y,{className:F(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,K.jsx)(m,{className:F(`w-3.5 h-3.5 shrink-0`,h)}),(0,K.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:Nt(u)}),u.branch&&(0,K.jsx)(`span`,{className:`max-w-40 truncate font-mono text-[10px] text-muted-foreground`,title:u.scopeId,children:u.branch}),t===`paused`&&(0,K.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:l(`loopExplorer.paused`,{defaultValue:`Paused`})}),u.iteration!=null&&u.iteration>=1&&(0,K.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:l(`loopExplorer.iterationBadge`,{count:u.iteration})}),_&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,K.jsx)(Qt,{}),p&&(0,K.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:l(`statusPanel.activity.${p.actionKey}`,{arg:p.actionArg??``})})]}),t===`ok`&&(0,K.jsx)(v,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&f?.reason===`provider_limit`&&(0,K.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:l(`loopExplorer.providerLimitHint`),"data-testid":`loop-step-provider-limit`,children:l(`loopExplorer.providerLimit`)}),t===`failed`&&(0,K.jsx)(O,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`stalled`&&(0,K.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:l(`loopExplorer.stalledIdle`,{count:Math.max(1,Math.round(f.idleMs/6e4))}),children:l(`loopExplorer.stalled`)}),t===`interrupted`&&(0,K.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:l(`loopExplorer.interrupted`)}),(0,K.jsx)(`span`,{className:`flex-1`}),f?.durationMs!=null&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:Vt(f.durationMs)}),t===`failed`&&f?.exitCode!=null&&f.exitCode!==0&&(0,K.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:l(`activeJob.exitCode`,{code:f.exitCode})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:l(`logViewer.phaseLines`,{count:d.length})})]}),b&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>S(e=>!e),"aria-label":l(`loopExplorer.stepDetail`),"aria-expanded":x,title:l(`loopExplorer.stepDetail`),className:F(`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,K.jsx)(W,{className:`w-3 h-3`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(e.key),"aria-label":l(`loopExplorer.copyStep`),title:l(`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,K.jsx)(H,{className:`w-3 h-3`})})]}),x&&b&&(0,K.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:F(`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,K.jsx)(tn,{label:l(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:l(`loopExplorer.copyCommand`)}),u.command&&(0,K.jsx)(tn,{label:l(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:l(`loopExplorer.copyCommand`)})]}),!n&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:en(g,r,l,c)})]})}var rn=(0,G.memo)(nn,(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),an=`__setup__`;function on({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:a}){let{t:s}=o(`jobs`),c=$t(e,n);return(0,K.jsxs)(`div`,{ref:e=>i(an,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(an),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,K.jsx)(y,{className:F(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,K.jsx)(C,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:s(`loopExplorer.setup`)}),(0,K.jsx)(`span`,{className:`flex-1`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:s(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:en(c,n,s,a)})]})}var sn=(0,G.memo)(on,(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 cn(e,t){let{t:n}=o(`jobs`),[r,i]=(0,G.useState)(!1),[a,s]=(0,G.useState)(``),[l,u]=(0,G.useState)(null),d=`${t??`active`}:${e??``}`,f=(0,G.useRef)(d),p=(0,G.useRef)(!1);f.current=d,(0,G.useEffect)(()=>(f.current=d,i(!1),s(``),u(null),p.current=!1,()=>{f.current=``}),[d]);async function m(r){if(!e||p.current||!r.meta.nodePath||!r.meta.scopeId||!r.meta.iteration)return;let a=d;p.current=!0,i(!0),s(``);try{let i=`${t?z(t):c()}/loop-runs/${encodeURIComponent(e)}`,o=await fetch(`${i}/recovery`,{cache:`no-store`});if(!o.ok)throw Error(n(`loopExplorer.forkFailed`));let s=await o.json();if(f.current!==a)return;if(s.forkAdopted&&s.forkRunId){u(s.forkRunId);return}let l={fromNodePath:r.meta.nodePath,scopeId:r.meta.scopeId,visit:r.meta.iteration};if(s.forkRequest&&(s.forkRequest.fromNodePath!==l.fromNodePath||s.forkRequest.scopeId!==l.scopeId||s.forkRequest.visit!==l.visit))throw Error(n(`loopExplorer.forkPending`));let d=s.forkRequest??{...l,requestId:crypto.randomUUID()},p=await fetch(`${i}/fork`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(d)}),m=await p.json();if(!p.ok||!m.loopRunId)throw Error(m.detail??n(`loopExplorer.forkFailed`));f.current===a&&u(m.loopRunId)}catch(e){f.current===a&&s(e instanceof Error?e.message:n(`loopExplorer.forkFailed`))}finally{f.current===a&&(p.current=!1,i(!1))}}return{busy:r,error:a,created:l,fork:m}}function ln(){return(0,K.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,K.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,K.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function un({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i,onOpenRun:a}){let{t:s,i18n:c}=o(`jobs`),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(`follow`),[h,g]=(0,G.useState)(new Set),_=(0,G.useRef)(null),v=(0,G.useRef)(new Map),y=dt(i),{activeProjectId:b}=l(),x=cn(e[0]?.job_id,i??b??void 0),S=(0,G.useMemo)(()=>Ft(e),[e,c.language]),C=t!=null&&t!==`running`&&t!==`queued`,w=t===`running`,T=(0,G.useMemo)(()=>S.segments.map((e,t)=>It(e,{isLast:t===S.segments.length-1,jobSettled:C})),[S,C]),D=(0,G.useMemo)(()=>{let e=S.segments.map(e=>e.key);return S.setup.length>0&&e.push(an),e},[S]),O=S.segments.length>0?S.segments[S.segments.length-1].key:an,k=(0,G.useMemo)(()=>d?new Set(D):p===`follow`?new Set([O]):h,[d,p,O,h,D]),A=(0,G.useRef)(k);A.current=k;let j=(0,G.useRef)(S);j.current=S;let M=(0,G.useCallback)(e=>{let t=new Set(A.current);e?.(t),g(t),m(`manual`)},[]),N=(0,G.useCallback)(e=>{M(t=>{t.has(e)?t.delete(e):t.add(e)})},[M]),P=(0,G.useCallback)(e=>{M(t=>t.add(e)),requestAnimationFrame(()=>{v.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[M]),I=(0,G.useCallback)(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)},[]),L=(0,G.useCallback)(()=>{m(`follow`),requestAnimationFrame(I)},[I]),z=(0,G.useCallback)(()=>{g(new Set(D)),m(`manual`)},[D]),ee=(0,G.useCallback)(()=>{g(new Set),m(`manual`)},[]);(0,G.useEffect)(()=>{p===`follow`&&!d&&I()},[S.totalLines,S.segments.length,p,d,I]);let te=(0,G.useCallback)(()=>{let e=_.current;!e||p!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&M()},[p,M]),ne=(0,G.useCallback)((e,t)=>{t?v.current.set(e,t):v.current.delete(e)},[]),re=(0,G.useCallback)(e=>{let t=j.current.segments.find(t=>t.key===e),n=e===`__setup__`?j.current.setup.map(e=>e.content).join(`
|
|
17
|
-
`):(t?.lines??[]).map(e=>e.content).join(`
|
|
18
|
-
`);navigator.clipboard.writeText(n).then(()=>u.success(s(`loopExplorer.copied`))).catch(()=>u.error(s(`logViewer.copyFailed`)))},[s]),B=(0,G.useCallback)(()=>{let e=j.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${Mt(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
|
|
19
|
-
`)).then(()=>u.success(s(`logViewer.copySuccess`))).catch(()=>u.error(s(`logViewer.copyFailed`)))},[s]),ie=(0,G.useMemo)(()=>Bt(S,{jobSettled:C,jobFailed:t===`failed`}),[S,C,t]),V=S.graphMeta?.iterationLimit??S.graphMeta?.graph.config.maxIterations??null,U=S.maxIteration>0?{current:S.maxIteration,limit:V}:null,W=(0,G.useMemo)(()=>{if(!d)return S.totalLines;let e=d.toLowerCase(),t=S.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of S.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[d,S]),ae=S.segments[S.segments.length-1],oe=w&&(S.segments.length===0||ae?.end!=null);return n?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`logViewer.loading`)})}):S.totalLines===0&&S.segments.length===0?(0,K.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[w&&(0,K.jsx)(ln,{}),s(w?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,K.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex min-h-0 flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:F(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,K.jsx)(E,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,K.jsx)(se,{placeholder:s(`logViewer.filterPlaceholder`),value:d,onChange:e=>f(e.target.value),className:`pl-7 h-7`})]}),(0,K.jsx)(R,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:z,"aria-label":s(`loopExplorer.expandAll`),title:s(`loopExplorer.expandAll`),children:(0,K.jsx)(je,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(R,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ee,"aria-label":s(`loopExplorer.collapseAll`),title:s(`loopExplorer.collapseAll`),children:(0,K.jsx)(Ae,{className:`w-3.5 h-3.5`})}),p===`follow`&&w&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,K.jsx)(ln,{}),s(`loopExplorer.follow`)]}),(0,K.jsx)(`span`,{className:`flex-1`}),(0,K.jsx)(R,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:B,"aria-label":s(`logViewer.copySuccess`),children:(0,K.jsx)(H,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:s(`logViewer.lineCount`,{filtered:W,total:S.totalLines})})]}),S.completion&&(0,K.jsx)(`div`,{"data-testid":`loop-completion-scroll`,className:r===`glass`?`max-h-[45%] min-h-0 shrink-0 overflow-y-auto overscroll-contain`:void 0,tabIndex:r===`glass`?0:void 0,children:(0,K.jsx)(Wt,{result:S.completion})}),S.graphMeta?.runtimeTopology&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ht,{topology:S.graphMeta.runtimeTopology,segments:S.segments,settled:C,onFocus:P,onFork:x.fork,forkBusy:x.busy}),x.error&&(0,K.jsx)(`p`,{role:`alert`,className:`px-2 text-xs text-destructive`,children:x.error}),x.created&&(0,K.jsxs)(`div`,{className:`p-2 text-xs`,children:[(0,K.jsx)(`p`,{children:s(`loopExplorer.forkCreated`)}),(0,K.jsx)(R,{size:`sm`,variant:`outline`,onClick:()=>a?.(x.created),disabled:!a,children:s(`loopExplorer.openFork`)}),(0,K.jsx)(`code`,{className:`ml-2`,children:x.created})]})]}),(0,K.jsx)(Zt,{chips:ie,iteration:U,onChipClick:P,variant:r}),(0,K.jsxs)(`div`,{ref:_,onScroll:te,className:`min-h-0 flex-1 overflow-y-auto p-2 text-xs`,children:[S.setup.length>0&&(0,K.jsx)(sn,{lines:S.setup,collapsed:!k.has(`__setup__`),filter:d,onToggle:N,setRef:ne,onOpenTicket:y}),S.segments.map((e,t)=>(0,K.jsx)(rn,{segment:e,status:T[t],collapsed:!k.has(e.key),filter:d,onToggle:N,onCopy:re,setRef:ne,onOpenTicket:y},e.key)),oe&&(0,K.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,K.jsx)(ln,{}),s(`loopExplorer.waiting`)]})]}),p===`manual`&&w&&!d&&(0,K.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:L,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,K.jsx)(ln,{}),s(`loopExplorer.resumeFollow`)]})]})}var dn=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(`.`)),fn=new Set([`status`,`diff`,`log`,`show`,`branch`,`rev-parse`,`ls-files`,`blame`,`describe`]),pn=new Set([...fn,`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`]),mn=new Set([`run`,`run-script`,`test`,`install`,`ci`,`i`,`add`,`exec`,`start`,`dlx`]),hn=[[/^(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`]],gn=new Set([`vitest`,`jest`,`pytest`,`mocha`,`ava`,`rspec`,`phpunit`]);function _n(e){for(let[t,n]of hn)if(t.test(e))return n;return null}function vn(e){return e.split(/\s+/).map(e=>e.replace(/^['"`]+/,``).replace(/['"`]+$/,``)).filter(e=>e.length>0&&!e.startsWith(`-`))}function yn(e){let t=vn(e);if(t.length===0)return{kind:`plumbing`};let n=t[0].split(`/`).pop()??t[0],r=t.slice(1);if(dn.has(n))return{kind:`plumbing`};if(gn.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(gn.has(e))return{kind:`intent`,code:`activity.testing`};let t=_n(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=>mn.has(e)),t=e===-1?``:r[e];if(t===`install`||t===`ci`||t===`i`||t===`add`)return{kind:`intent`,code:`activity.installing`};let i=_n(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=>pn.has(e))??``;return fn.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===`mvnw`||n===`gradle`||n===`gradlew`){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 bn(e){try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}catch{return{}}}function xn(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 Sn(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,Cn=new Set([`thinking`,`reasoning`]),wn=/^(MEMORY\.md|confidence-score\.json|design-confidence\.json|\d{4}-\d{2}-\d{2}-.+|feedback_.+)$/,Tn=/^(proposal|design|tasks|spec|context-bundle)\.md$/,En=new Set([`reading`,`writing`,`editing`]);function $(e,t,n,r,i,a=``){for(let t=e.length-1;t>=0;t--){let o=e[t];if(o.values.phaseBoundary===1)break;if(o.kind!==`activity`){if(o.stepIndex!==n)break;continue}if(o.stepIndex!==n)break;if((o.values.repository??``)===a&&o.values.action===r&&o.values.target===i){o.values.repeats=Number(o.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,repository:a},stepIndex:n,tone:`neutral`})}var Dn=new Set([`architect`,`developer`,`fixer`,`verify`,`reviewer`,`archive`]),On=/^(?:Host blocker|Fixer reported a host blocker)\b/,kn=3;function An(e,t,n,r,i,a=``){for(let t=e.length-1;t>=0;t--){let o=e[t];if(o.values.phaseBoundary===1||o.stepIndex!==n)break;if(o.kind!==`activity`||(o.values.repository??``)!==a||o.values.action!==r||o.values.fileGroup!==1)continue;let s=String(o.values.allNames??``).split(`\0`).filter(Boolean),c=!!i&&!s.includes(i);c&&s.push(i),o.values.allNames=s.join(`\0`),o.values.files=s.length;let l=String(o.values.names??``).split(`, `).filter(Boolean);c&&l.length<kn&&(l.push(i),o.values.names=l.join(`, `)),o.code=s.length>1?`activity.${r}Files`:i?`activity.${r}`:`activity.${r}Bare`,o.values.repeats=s.length>1?1:Number(o.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,repository:a,files:+!!i,fileGroup:1,repeats:1},stepIndex:n,tone:`neutral`})}function jn({events:e,settled:t}){let n=[],r=new Map,i=new Set,a=null,o=!1,s=!1,c=e.some(e=>e.event_type===`workflow-event`);for(let t of e){if(t.event_type===`loop_graph`){o=!0;continue}if(t.event_type===`loop_step`){let e=bn(t.payload),i=Z(e.index);if(i===null)continue;o=!0;let s=Q(e.kind)??`ai-step`,l={index:i,title:Sn(Q(e.title)??``),roleCode:c?null:xn(Q(e.nodeId),s),kind:s,iteration:Z(e.iteration),ended:!1};r.set(i,l),a=i;let u=Z(e.attempt);n.push({seq:t.seq,kind:`step-start`,code:u!==null&&u>1?`step.startResume`:l.iteration&&l.iteration>1?`step.startRetry`:`step.start`,values:{step:i,title:l.title,iteration:l.iteration??1,...u!==null&&u>1?{attempt:u}:{},...l.roleCode?{roleCode:l.roleCode}:{}},stepIndex:i,tone:`neutral`});continue}if(t.event_type===`loop_step_end`){let e=bn(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:e.recovered===!0&&o===`ok`?`step.recovered`: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===`runtime-efficiency-event`){let e=bn(t.payload),r=e.payload&&typeof e.payload==`object`&&!Array.isArray(e.payload)?e.payload:{},o=Q(e.eventId),s=Q(e.kind);if(e.schemaVersion!==1||!o||i.has(o))continue;i.add(o);let c=Q(r.label),l=Q(r.repositoryId);if(!c||!l||c.length>256||l.length>256)continue;let u=s===`check-started`?`started`:s===`check-reused`?`reused`:s===`check-invalidated`?`invalidated`:s===`check-finished`&&typeof r.exitCode==`number`?r.exitCode===0?`passed`:`failed`:null;u&&n.push({seq:t.seq,kind:`activity`,code:`activity.check.${u}`,values:{target:c,repository:l},stepIndex:a,tone:u===`failed`?`bad`:`neutral`});continue}if(t.event_type===`workflow-event`){let e=bn(t.payload),r=e.event&&typeof e.event==`object`&&!Array.isArray(e.event)?e.event:{},i=Q(r.type),o=Q(r.stepId);if(i===`workflow_resumed`)s=!1,n.push({seq:t.seq,kind:`activity`,code:`activity.phase.resumed`,values:{phaseBoundary:1},stepIndex:a,tone:`neutral`});else if(i===`step_started`&&o&&Dn.has(o)){let e=o===`developer`&&s;o===`developer`&&(s=!0),n.push({seq:t.seq,kind:`activity`,code:e?`activity.phase.corrections`:`activity.phase.${o}`,values:{phaseBoundary:1},stepIndex:a,tone:`neutral`})}else if(!(i===`step_succeeded`&&o===`verify`&&typeof r.message!=`string`||i===`step_blocked`)&&(i===`workflow_failed`||i===`workflow_blocked`||i===`workflow_cancelled`)){let e=Array.isArray(r.reasons)?r.reasons.filter(e=>typeof e==`string`):[],o=Q(r.message)??e[0]??i,s=i===`workflow_failed`&&On.test(o);n.push({seq:t.seq,kind:`activity`,code:s?`activity.phase.blocked`:`activity.phase.stopped`,values:{action:`intent`,target:o,repeats:1},stepIndex:a,tone:`bad`})}continue}let e=t.event_type===`agent-event`?bn(t.payload):{},l=Array.isArray(e.repositories)?e.repositories.map(e=>typeof e?.name==`string`?e.name:``).filter(Boolean).join(` + `):``,u=be(t);if(!(!u.step||!u.actionKey)&&!Cn.has(u.actionKey)&&!(c&&u.actionKey===`working`)){if(c&&u.actionKey===`searching`){$(n,t.seq,a,`searching`,``,l);continue}if(u.actionKey===`running`){let e=ue(t),r=e?yn(e):{kind:`named`,tool:u.actionArg??``};if(r.kind===`plumbing`){$(n,t.seq,a,`exploring`,``,l);continue}if(r.kind===`intent`){$(n,t.seq,a,`intent`,r.code,l);continue}$(n,t.seq,a,`running`,c?``:r.tool,l);continue}if(En.has(u.actionKey)){let e=u.actionArg??``;if(wn.test(e)){$(n,t.seq,a,`intent`,`activity.bookkeeping`,l);continue}if(Tn.test(e)){$(n,t.seq,a,`intent`,`activity.writingSpec`,l);continue}An(n,t.seq,a,u.actionKey,e,l);continue}$(n,t.seq,a,u.actionKey,u.actionArg??``,l)}}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:!o}}var Mn={"step-start":Me,"step-end":v,"step-interrupted":D,decision:T,activity:Me},Nn={neutral:`text-muted-foreground`,good:`text-accent-success`,bad:`text-accent-warning`};function Pn({events:e,settled:t,durationRange:n,elapsedMs:r,variant:i=`page`}){let{t:a}=o(`narration`),s=(0,G.useMemo)(()=>jn({events:e,settled:t}),[e,t]),c=(0,G.useMemo)(()=>e.some(e=>e.event_type===`workflow-event`),[e]),l=(0,G.useMemo)(()=>[...s.milestones].sort((e,t)=>e.seq-t.seq),[s.milestones]);return(0,K.jsxs)(`div`,{className:i===`glass`?`flex h-full flex-col overflow-hidden`:`flex flex-col`,children:[(0,K.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,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(Pe,{className:`size-3`,"aria-hidden":!0}),a(`waiting.elapsed`,{minutes:Math.max(1,Math.round(r/6e4))})]}):null,n?(0,K.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,K.jsx)(`span`,{className:`ml-auto italic opacity-70`,children:a(`aiNote`)})]}),(0,K.jsx)(`ol`,{className:`flex-1 space-y-1 px-3 py-2 ${i===`glass`?`overflow-y-auto`:``}`,"data-testid":`narration-list`,children:l.length===0?(0,K.jsx)(`li`,{className:`py-6 text-center text-xs text-muted-foreground`,children:a(t?`emptySettled`:`emptyLive`)}):l.map((e,t)=>{let n=Mn[e.kind],r=e.kind===`step-start`||e.kind===`step-end`||e.kind===`step-interrupted`,i=Number(e.values.files??0)>1||c?1:Number(e.values.repeats??1);return(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-sm ${r||e.values.phaseBoundary===1?`font-medium text-foreground`:`text-muted-foreground`} ${e.kind===`step-start`&&t>0?`pt-2`:``}`,children:[(0,K.jsx)(n,{className:`mt-0.5 size-3.5 shrink-0 ${Nn[e.tone]}`,"aria-hidden":!0}),(0,K.jsxs)(`span`,{className:`min-w-0 break-words`,children:[typeof e.values.repository==`string`&&e.values.repository&&(0,K.jsx)(`span`,{className:`mr-2 inline-block rounded border border-border px-1.5 py-0.5 text-xs font-medium text-foreground`,children:e.values.repository}),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,K.jsx)(`span`,{className:`ml-1.5 text-[11px] opacity-70`,children:a(`repeats`,{count:i})}):null]})]},`${e.seq}-${e.code}-${t}`)})})]})}var Fn=`specrails-desktop:job-log-mode`;function In(){try{let e=localStorage.getItem(Fn);return e===`log`||e===`narrated`?e:`narrated`}catch{return`narrated`}}function Ln(e){try{localStorage.setItem(Fn,e)}catch{}}var Rn=8e3,zn=new Set([`loop_graph`,`runtime-graph`,`loop_step`,`loop_step_end`,`loop_completion`,`workflow-event`,`runtime-result`,`runtime-efficiency-event`,`result`]);function Bn(e){return e.event_type!==`verification-output`}function Vn(e,t=!1){let n=[],r=Rn;for(let i=e.length-1;i>=0;i--){let a=e[i];Bn(a)&&(zn.has(a.event_type)?n.push(a):r>0?(n.push(a),r--):t=!0)}return{events:n.reverse(),omitted:t}}function Hn(e,t){return!e.omitted||!e.events.length?e.events:[{...e.events[0],id:-1,seq:-1,event_type:`log`,source:`stdout`,payload:JSON.stringify({line:t})},...e.events]}function Un(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 Wn(){try{return a()}catch{return null}}function Gn({jobId:e,projectId:t,settleMode:n,initialAcceptingTurns:r,pendingInterrupts:a,kind:s=`job`,variant:l=`page`,onFinalized:d}){let{t:f}=o(`jobs`),{t:p}=o(`loops`),[m,h]=(0,G.useState)(a??[]),[g,_]=(0,G.useState)(a?.length===1?a[0].id:``);(0,G.useEffect)(()=>{h(a??[]),_(a?.length===1?a[0].id:``)},[a]);let v=m.find(e=>e.id===g),y=v!==void 0&&v.kind!==`question`,b=n??`finalize`,x=()=>t?`${i}/api/projects/${t}`:c(),[C,w]=(0,G.useReducer)(Un,{streaming:!1,queued:0,totals:null,accepting:r??!0,finalizing:!1}),[T,E]=(0,G.useState)(``),[D,O]=(0,G.useState)(!1),k=(0,G.useRef)(null);(0,G.useEffect)(()=>{r!==void 0&&w({type:`accepting`,accepting:r})},[r]);let A=(0,G.useRef)(d);A.current=d;let j=Wn(),M=(0,G.useId)();(0,G.useEffect)(()=>{if(!j)return;let t=`interactive-composer-${e}-${M}`;return j.registerHandler(t,t=>{let n=t;if(n.jobId===e){if(n.type===`job.turn_user`)w({type:`turn-user`,queued:!!n.queued});else if(n.type===`job.turn_done`)w({type:`turn-done`,totals:n.totals});else if(n.type===`job.finalized`)w({type:`finalized`,totals:n.totals??null}),A.current?.();else if(n.type===`job.interactive`&&(w({type:`accepting`,accepting:!!n.acceptingTurns}),Array.isArray(n.pendingInterrupts))){let e=n.pendingInterrupts;h(e),_(e.length===1?e[0].id:``)}}}),()=>j.unregisterHandler(t)},[j,e,M]);let N=s===`loop-step`&&!C.accepting;async function P(t=!1){let n=T.trim();if(!(!n&&!t||D||N||m.length>0&&!v||y&&!t)){O(!0);try{let r=await fetch(`${x()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n,...v?{interruptId:v.id}:{},...t?{approve:!0}:{}})});if(r.ok)E(``),v&&(h([]),_(``),w({type:`accepting`,accepting:!1})),requestAnimationFrame(()=>k.current?.focus());else if(r.status===409&&s===`loop-step`&&!m.length)w({type:`blocked`});else{let e=await r.json().catch(()=>({}));u.error(f(`detail.toast.sendFailed`),{description:e.error})}}catch{u.error(f(`detail.toast.networkError`))}finally{O(!1)}}}async function I(){if(!C.finalizing){w({type:`finalize-request`});try{let t=await fetch(`${x()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)u.success(f(b===`finalize`?`detail.toast.finalizeScheduled`:s===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&s===`loop-step`)w({type:`blocked`}),w({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));u.error(f(`detail.toast.finalizeFailed`),{description:e.error}),w({type:`finalize-reject`})}}catch{u.error(f(`detail.toast.networkError`)),w({type:`finalize-reject`})}}}let L=D||N||!T.trim()||y||m.length>0&&!v,z=f(`detail.interactive.working`);return(0,K.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:F(`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`,l===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[N?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(Fe,{className:`h-3 w-3 motion-safe:animate-pulse`}),f(`detail.interactive.waitingForStepShort`)]}):C.streaming?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(S,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,K.jsxs)(`span`,{className:`relative`,children:[z,(0,K.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:z})]})]}):(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),f(`detail.interactive.ready`)]}),C.queued>0&&(0,K.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:f(`detail.interactive.queued`,{count:C.queued})})]}),(0,K.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[C.totals&&(0,K.jsx)(`span`,{className:`tabular-nums`,children:f(`detail.interactive.liveTotals`,{turns:C.totals.num_turns??f(`completion.unavailable`),cost:C.totals.total_cost_usd?.toFixed(4)??f(`completion.unavailable`)})}),m.length?null:b===`finalize`?(0,K.jsxs)(U,{children:[(0,K.jsx)(ce,{asChild:!0,children:(0,K.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void I(),disabled:C.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,K.jsx)(V,{className:`mr-1.5 h-3.5 w-3.5`}),C.finalizing?f(`detail.finalizing`):f(`detail.finalizeJob`)]})}),(0,K.jsx)(he,{children:f(`detail.finalizeJobTooltip`)})]}):(0,K.jsxs)(U,{children:[(0,K.jsx)(ce,{asChild:!0,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>void I(),disabled:C.finalizing||N,className:F(`text-[11px] underline-offset-2 transition-colors`,N?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:C.finalizing?f(`detail.interactive.wrappingUp`):f(s===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,K.jsx)(he,{children:f(s===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),m.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2 rounded-md border border-accent-warning/30 bg-accent-warning/5 p-3`,children:[(0,K.jsxs)(`label`,{className:`block text-sm`,children:[p(`core.selectInterrupt`),(0,K.jsxs)(`select`,{"aria-label":p(`core.selectInterrupt`),className:`mt-1 w-full rounded border border-border bg-background p-2`,value:g,onChange:e=>_(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:p(`core.selectInterrupt`)}),m.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.nodePath,` · `,p(`core.${e.kind===`question`?`answerQuestion`:`approval`}`)]},e.id))]})]}),v&&typeof v.value==`object`&&v.value!==null&&typeof v.value.prompt==`string`&&(0,K.jsx)(`p`,{className:`whitespace-pre-wrap text-sm`,children:String(v.value.prompt)}),y&&(0,K.jsx)(R,{onClick:()=>void P(!0),disabled:D||N,children:p(`core.approveContinue`)})]}),b===`auto`&&!m.length&&(0,K.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:f(N?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,K.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,K.jsx)(`textarea`,{ref:k,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),P())},rows:2,placeholder:f(N?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":f(`detail.interactive.placeholder`),disabled:N,className:F(`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`,N&&`opacity-60`)}),(0,K.jsxs)(U,{children:[(0,K.jsx)(ce,{asChild:!0,children:(0,K.jsx)(`span`,{className:`shrink-0`,children:(0,K.jsxs)(R,{size:`sm`,onClick:()=>void P(),disabled:L,className:`h-9`,children:[(0,K.jsx)(ae,{className:`mr-1.5 h-3.5 w-3.5`}),f(`detail.interactive.send`)]})})}),L&&!D&&(0,K.jsx)(he,{children:f(N?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{In as a,un as c,Je as d,Vn as i,gt as l,Bn as n,Ln as o,Hn as r,Pn as s,Gn as t,tt as u};
|
|
@@ -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{m as o,r as ee}from"./useSharedWebSocket-DaWuiO0S.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{a as c,r as te,s as l}from"./useDesktop-DKNbOF0u.js";import{dt as u,n as ne}from"./TicketDetailModalContext-YBJX3RmP.js";import{n as d}from"./save-OsUqVn99.js";import{c as f}from"./MinimizedChatsContext-CroAs6Kh.js";import{n as re}from"./file-text-BcLCfcWZ.js";import{a as ie,c as p,d as ae,i as m,l as h,n as oe,o as se,r as ce,s as le,t as ue,u as de}from"./InteractiveJobComposer-CFKvbQeJ.js";import{t as fe}from"./download-CFHyyHcw.js";import{t as pe}from"./rotate-ccw-Wh4id13q.js";import{t as g}from"./utils-BC4DHlz2.js";import{t as me}from"./formatDistanceToNow-DZ3VWsHq.js";import{t as _}from"./button-D1xExSTF.js";import{K as v,Nt as y,W as he,Y as b,q as x}from"./index-lTGJJTuk.js";import{t as ge}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=4;function _e({tickets:e,onTicketClick:t}){let{t:n}=s(`jobs`),[r,i]=(0,S.useState)(!1);if(e.length===0)return null;let a=e.length>=w&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,C.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-card/40 px-4 py-3 space-y-1.5`,children:[a.map(e=>(0,C.jsx)(T,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,C.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showMore`,{count:o}),(0,C.jsx)(d,{className:`w-3 h-3`})]}),r&&e.length>=w&&(0,C.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showLess`),(0,C.jsx)(f,{className:`w-3 h-3`})]})]})}function T({ticket:e,onClick:t}){let{t:n}=s(`jobs`),r=e.title==null,i=`inline-flex items-center px-1.5 py-0.5 rounded-md text-[11px] font-mono tabular-nums shrink-0`;return r?(0,C.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,C.jsx)(`span`,{className:g(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,C.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 min-w-0 w-full text-left group`,title:e.title??void 0,children:[(0,C.jsxs)(`span`,{className:g(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,C.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}function E(){let{t:e}=s(`jobs`),{t}=s(`narration`),{id:n}=r(),{activeProjectId:d,projects:f}=te(),w=f.find(e=>e.id===d)?.provider,T=a(),{openTicketDetail:E}=ne(),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(()=>m([])),j=(0,S.useMemo)(()=>ce(k,e(`logViewer.retainedTail`)),[k,e]),[ve,M]=(0,S.useState)([]),[ye,N]=(0,S.useState)({}),[be,P]=(0,S.useState)([]),[xe,F]=(0,S.useState)(!0),[Se,I]=(0,S.useState)(!1),[L,Ce]=(0,S.useState)(ie),[we,R]=(0,S.useState)(null),Te=(0,S.useCallback)(e=>{Ce(e),se(e)},[]),z=D?.command??null;(0,S.useEffect)(()=>{if(!u||L!==`narrated`||!d||!z)return;let e=!1,t=`command=${encodeURIComponent(z)}`;try{Promise.resolve(fetch(`${c()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||R(t?.range??null)}).catch(()=>{e||R(null)})}catch{R(null)}return()=>{e=!0}},[d,z,L]);let[B,V]=(0,S.useState)(!1),H=(0,S.useRef)(!1),U=(0,S.useRef)(null);(0,S.useEffect)(()=>{H.current=!1,U.current=null,V(!1)},[n]),(0,S.useEffect)(()=>{if(!n)return;let e=new AbortController;K.current={events:[],omitted:!1},q.current&&cancelAnimationFrame(q.current),q.current=null,O(null),A(m([])),M([]),N({}),F(!0),I(!1);async function t(){try{let t=await fetch(`${c()}/jobs/${n}`,{signal:e.signal});if(t.status===404){I(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();if(e.signal.aborted)return;O(r.job),A(m(r.events))}catch(e){if(e.name===`AbortError`)return;I(!0)}finally{e.signal.aborted||F(!1)}}return t(),()=>e.abort()},[n,d]),(0,S.useEffect)(()=>{if(!D?.pipeline_id){P([]);return}let e=D.pipeline_id;fetch(`${c()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&P(e.jobs)}).catch(()=>{})},[D?.pipeline_id,D?.status]);let W=(0,S.useRef)(d);W.current=d;let G=(0,S.useRef)(null);G.current=D?.status??null;let K=(0,S.useRef)({events:[],omitted:!1}),q=(0,S.useRef)(null),J=(0,S.useCallback)(()=>{q.current=null;let e=K.current;e.events.length!==0&&(K.current={events:[],omitted:!1},A(t=>m([...t.events,...e.events],t.omitted||e.omitted)))},[]),Y=(0,S.useCallback)(e=>{if(!oe(e))return;let t=K.current;t.events.push(e),t.events.length>1e4&&(K.current=m(t.events,t.omitted)),q.current||=requestAnimationFrame(J)},[J]);(0,S.useEffect)(()=>()=>{q.current&&cancelAnimationFrame(q.current)},[]);let X=(0,S.useCallback)(e=>{let t=e;if(!(W.current&&t.projectId&&t.projectId!==W.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];M(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;N(n)}else if(t.type===`event`&&t.jobId===n){let e={id:Date.now(),job_id:n??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};Y(e)}else if(t.type===`log`&&t.processId===n){let e={id:Date.now(),job_id:n??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line,...typeof t.attemptId==`string`&&t.attemptId.trim()&&t.attemptId.length<=256?{attemptId:t.attemptId}:{}}),timestamp:t.timestamp};Y(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`runtime.continuation`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;N(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===n);if(e){let t=e.status,r=G.current;O(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${c()}/jobs/${n}`).then(e=>e.json()).then(e=>O(e.job)).catch(()=>{})}}}},[n,Y]),{registerHandler:Z,unregisterHandler:Q}=ee();(0,S.useEffect)(()=>(Z(`job-detail-${n}`,X),()=>Q(`job-detail-${n}`)),[n,X,Z,Q]),(0,S.useEffect)(()=>{if(!n||!D||D.status!==`running`||D.hasTelemetry)return;let e=setInterval(()=>{fetch(`${c()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&O(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,D?.status,D?.hasTelemetry]);async function Ee(){if(!n)return;let t=await he({projectId:null,jobId:n});t.ok?l.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):t.httpStatus===null?l.error(e(`detail.toast.networkError`)):l.error(e(`detail.toast.failed`),{description:t.error})}async function De(){if(D)try{let t=await fetch(`${c()}/jobs/${D.id}/diagnostic`);if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`detail.toast.exportFailedHttp`,{status:t.status}))}let n=await t.blob(),r=URL.createObjectURL(n),i=new Date().toISOString().slice(0,10),a=document.createElement(`a`);a.href=r,a.download=`specrails-diagnostic-${D.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){l.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function Oe(){if(!(!D||H.current)){H.current=!0,V(!0),U.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${D.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${c()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":U.current},body:JSON.stringify({rerunOfJobId:D.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));U.current=null,l.success(e(`detail.toast.jobRequeued`)),T(`/jobs/${n.jobId}`)}catch(e){l.error(e.message)}finally{H.current=!1,V(!1)}}}if(xe)return(0,C.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,C.jsxs)(`div`,{className:`space-y-3`,children:[(0,C.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,C.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,C.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(Se||!D)return(0,C.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,C.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,C.jsx)(_,{asChild:!0,variant:`outline`,size:`sm`,children:(0,C.jsxs)(i,{to:`/`,children:[(0,C.jsx)(y,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let $=D.status===`running`,ke=D.status===`completed`||D.status===`failed`,Ae=!!D.interactive,je=Ae&&$,Me=(D.tickets?.length??0)>0,Ne=D.command.startsWith(`loop:`),Pe=ae(be);return(0,C.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,C.jsxs)(`div`,{className:`px-4 pt-3 pb-2 space-y-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,C.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,C.jsx)(y,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,C.jsx)(re,{className:`w-3 h-3`}),(0,C.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),Me&&(0,C.jsx)(_e,{tickets:D.tickets??[],onTicketClick:E}),(0,C.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap min-w-0`,children:[(0,C.jsx)(`code`,{className:g(`font-mono text-foreground/90 truncate`,Me?`text-xs text-muted-foreground`:`text-sm`),children:ge(D.command,w)}),(0,C.jsx)(`span`,{children:D.started_at?e(`detail.startedAgo`,{timeAgo:me(new Date(D.started_at),{addSuffix:!0,locale:o()})}):e(`detail.queuedWaiting`)}),D.model&&(0,C.jsx)(`span`,{className:`text-muted-foreground/40`,children:D.model})]})]}),(0,C.jsx)(de,{onOpenRun:e=>T(`/jobs/${e}`),job:D,events:j,phases:ye,phaseDefinitions:ve,projectId:d,variant:`page`,pipelineTotals:Pe,actions:(0,C.jsxs)(C.Fragment,{children:[D.hasTelemetry&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,className:`h-7`,onClick:De,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,C.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,C.jsx)(x,{children:e(`detail.exportDiagnosticTooltip`)})]}),ke&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsxs)(_,{variant:`outline`,size:`sm`,onClick:Oe,disabled:B,"aria-busy":B,className:`h-7`,children:[(0,C.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,C.jsx)(x,{children:e(`detail.reExecuteTooltip`)})]}),$&&(0,C.jsxs)(v,{children:[(0,C.jsx)(b,{asChild:!0,children:(0,C.jsx)(_,{variant:`outline`,size:`sm`,onClick:Ee,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(Ae?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,C.jsx)(x,{children:e(`detail.cancelJobTooltip`)})]})]})}),k.omitted&&(0,C.jsx)(`p`,{role:`status`,className:`shrink-0 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:e(`logViewer.retainedTail`)}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:u?(0,C.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,C.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,C.jsx)(`button`,{type:`button`,onClick:()=>Te(e),"aria-pressed":L===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${L===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:L===`narrated`?(0,C.jsx)(le,{events:j,settled:D.status!==`running`&&D.status!==`queued`,durationRange:we,elapsedMs:D.duration_ms??null,variant:`page`}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})})]}):Ne?(0,C.jsx)(p,{events:j,jobStatus:D.status,variant:`page`,onOpenRun:e=>T(`/jobs/${e}`)}):(0,C.jsx)(h,{events:j})}),je&&(0,C.jsx)(ue,{jobId:D.id,settleMode:D.interactiveSettleMode,initialAcceptingTurns:D.interactiveAcceptingTurns,pendingInterrupts:D.pendingInterrupts,kind:D.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{E as default};
|