@open-mercato/cezar 0.16.2 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/api-origin.d.ts +6 -0
  2. package/dist/api-origin.js +32 -0
  3. package/dist/api-origin.js.map +1 -0
  4. package/dist/automations/schedule-runner.d.ts +1 -0
  5. package/dist/automations/schedule-runner.js +2 -2
  6. package/dist/automations/schedule-runner.js.map +1 -1
  7. package/dist/core/agent-errors.d.ts +5 -0
  8. package/dist/core/agent-errors.js +49 -0
  9. package/dist/core/agent-errors.js.map +1 -1
  10. package/dist/core/claude-cli-runner.d.ts +3 -0
  11. package/dist/core/claude-cli-runner.js +20 -4
  12. package/dist/core/claude-cli-runner.js.map +1 -1
  13. package/dist/core/codex-ui-mapper.js +4 -1
  14. package/dist/core/codex-ui-mapper.js.map +1 -1
  15. package/dist/core/copilot-acp-runner.d.ts +1 -1
  16. package/dist/core/copilot-acp-runner.js +26 -5
  17. package/dist/core/copilot-acp-runner.js.map +1 -1
  18. package/dist/core/model-presets.d.ts +11 -0
  19. package/dist/core/model-presets.js +35 -1
  20. package/dist/core/model-presets.js.map +1 -1
  21. package/dist/core/opencode-model-catalog.js +3 -0
  22. package/dist/core/opencode-model-catalog.js.map +1 -1
  23. package/dist/core/opencode-server-runner.d.ts +7 -0
  24. package/dist/core/opencode-server-runner.js +36 -1
  25. package/dist/core/opencode-server-runner.js.map +1 -1
  26. package/dist/core/pi-runner.js +2 -0
  27. package/dist/core/pi-runner.js.map +1 -1
  28. package/dist/core/provider-auth.d.ts +6 -0
  29. package/dist/core/provider-auth.js +59 -13
  30. package/dist/core/provider-auth.js.map +1 -1
  31. package/dist/core/usage-limit.js +8 -2
  32. package/dist/core/usage-limit.js.map +1 -1
  33. package/dist/index.js +3 -19
  34. package/dist/index.js.map +1 -1
  35. package/dist/release/bump.d.ts +1 -1
  36. package/dist/release/bump.js +1 -1
  37. package/dist/release/stable.d.ts +21 -4
  38. package/dist/release/stable.js +48 -15
  39. package/dist/release/stable.js.map +1 -1
  40. package/dist/runs/agent-error-telemetry.js +4 -2
  41. package/dist/runs/agent-error-telemetry.js.map +1 -1
  42. package/dist/runs/store.d.ts +1 -1
  43. package/dist/runs/store.js +31 -4
  44. package/dist/runs/store.js.map +1 -1
  45. package/dist/server/git-changes.d.ts +22 -0
  46. package/dist/server/git-changes.js +19 -1
  47. package/dist/server/git-changes.js.map +1 -1
  48. package/dist/server/open-in-app.js +14 -3
  49. package/dist/server/open-in-app.js.map +1 -1
  50. package/dist/server/preview/location-reporter.d.ts +12 -0
  51. package/dist/server/preview/location-reporter.js +45 -0
  52. package/dist/server/preview/location-reporter.js.map +1 -0
  53. package/dist/server/preview/picker-script.d.ts +0 -22
  54. package/dist/server/preview/picker-script.js +3 -1
  55. package/dist/server/preview/picker-script.js.map +1 -1
  56. package/dist/server/provider-telemetry.d.ts +3 -1
  57. package/dist/server/provider-telemetry.js +4 -2
  58. package/dist/server/provider-telemetry.js.map +1 -1
  59. package/dist/server/repo-sync.js +5 -10
  60. package/dist/server/repo-sync.js.map +1 -1
  61. package/dist/server/server.d.ts +1854 -1854
  62. package/dist/server/server.js +7 -2
  63. package/dist/server/server.js.map +1 -1
  64. package/dist/server/worktree-lifecycle.d.ts +8 -8
  65. package/dist/telemetry.js +3 -1
  66. package/dist/telemetry.js.map +1 -1
  67. package/dist/workflows/continuation-context.d.ts +3 -1
  68. package/dist/workflows/continuation-context.js +22 -3
  69. package/dist/workflows/continuation-context.js.map +1 -1
  70. package/dist/workflows/run.d.ts +20 -9
  71. package/dist/workflows/run.js +49 -11
  72. package/dist/workflows/run.js.map +1 -1
  73. package/package.json +3 -3
  74. package/scripts/mock-copilot-acp.mjs +4 -0
  75. package/web/dist/assets/{agent-task-pickers-DEW3Vgdv.js → agent-task-pickers-CNuwgeJL.js} +1 -1
  76. package/web/dist/assets/{automations-route-Cx7mzYhD.js → automations-route-Cs1tsu1W.js} +1 -1
  77. package/web/dist/assets/{commit-list-xMdmPYbz.js → commit-list-Ti2arrt8.js} +1 -1
  78. package/web/dist/assets/{compare-variants-B6ja1M4D.js → compare-variants-CdchlJMs.js} +1 -1
  79. package/web/dist/assets/{dashboard-ClEGBFFq.js → dashboard-wi0EQack.js} +2 -2
  80. package/web/dist/assets/{file-preview-iucr8WDo.js → file-preview-pS9i9ZDR.js} +1 -1
  81. package/web/dist/assets/git-tab-loading-BC6WP7W4.js +1 -0
  82. package/web/dist/assets/{git-toolbar-DU5Ca6RI.js → git-toolbar-Dra1QlHb.js} +1 -1
  83. package/web/dist/assets/github-DZcdhMzw.js +1 -0
  84. package/web/dist/assets/{host-usage-DjDYDU0A.js → host-usage-DnkXF0CT.js} +1 -1
  85. package/web/dist/assets/index-qeFtKZ4e.js +22 -0
  86. package/web/dist/assets/{layout-cards-Sur4EWtx.js → layout-cards-CXMlrDUf.js} +1 -1
  87. package/web/dist/assets/{project-router-DZsR9P9C.js → project-router-CZzr7lzN.js} +2 -2
  88. package/web/dist/assets/queries-Bn7zl9OU.js +1 -0
  89. package/web/dist/assets/{reference-chip-DnemrSPW.js → reference-chip-CScP5y_O.js} +1 -1
  90. package/web/dist/assets/repo-git-CV-yXaSx.js +1 -0
  91. package/web/dist/assets/{run-diff-BPZ85gAE.js → run-diff-GHEaeAio.js} +2 -2
  92. package/web/dist/assets/{skills-BgCN1gTp.js → skills-DuSNv5op.js} +1 -1
  93. package/web/dist/assets/{task-commits-W1ZZiEt4.js → task-commits-D_gLpFQo.js} +1 -1
  94. package/web/dist/assets/{task-graph-DI2fn5M8.js → task-graph-BgHk8Y3v.js} +1 -1
  95. package/web/dist/assets/{task-notes-lmvd1UM7.js → task-notes-BBp0rdzM.js} +1 -1
  96. package/web/dist/assets/task-workspace-Cr9AjTxP.js +27 -0
  97. package/web/dist/assets/{terminal-drawer-DAkquqSe.js → terminal-drawer-CcPOjWwP.js} +2 -2
  98. package/web/dist/assets/{tracker-Cqdpt9RN.js → tracker-BHwMGsDY.js} +2 -2
  99. package/web/dist/assets/use-automations-Dh3Wj-79.js +5 -0
  100. package/web/dist/assets/{use-now-pBdvhv13.js → use-now-BB7W0F--.js} +1 -1
  101. package/web/dist/assets/{workflow-graph-l7O50dsV.js → workflow-graph-CcOTCItr.js} +3 -3
  102. package/web/dist/assets/worktree-lifecycle-operation-vTgExKUM.js +18 -0
  103. package/web/dist/index.html +10 -10
  104. package/web/dist/assets/git-tab-loading-BfC2ir8N.js +0 -1
  105. package/web/dist/assets/github-CELdSmld.js +0 -1
  106. package/web/dist/assets/index-BBND6Sg3.js +0 -22
  107. package/web/dist/assets/queries-CI0EmEcH.js +0 -1
  108. package/web/dist/assets/repo-git-Bj0PBOjX.js +0 -1
  109. package/web/dist/assets/task-workspace-B8Fpho3e.js +0 -27
  110. package/web/dist/assets/use-automations-v77gHYDG.js +0 -5
  111. package/web/dist/assets/worktree-lifecycle-operation-DOTiqQFx.js +0 -18
@@ -0,0 +1,27 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-drawer-CcPOjWwP.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-runtime-CCIEwYL0.js","assets/queries-Bn7zl9OU.js","assets/button-Clwd6u4_.js","assets/bundle-mjs-BT31bpU6.js","assets/host-usage-DnkXF0CT.js","assets/use-desktop-BNN3U2y9.js","assets/tooltip-B628Gs7C.js","assets/icon-tooltip-YXzUubMO.js","assets/terminal-F3ZJ5fI8.js","assets/loader-circle-D-ter0qP.js","assets/square-8OFxLPoA.js","assets/plus-CBVm02wz.js","assets/x-DMIsmLBt.js","assets/alert-dialog-DvPnvVvK.js","assets/tabs-BUk8rSoE.js","assets/input-DIWTlsx6.js","assets/drawer-state-DasOAIpO.js","assets/terminal-drawer-BrP-ENHg.css","assets/task-graph-BgHk8Y3v.js","assets/project-router-CZzr7lzN.js","assets/git-tab-loading-BC6WP7W4.js","assets/reference-chip-CScP5y_O.js","assets/circle-check-DnEaQ9Rj.js","assets/triangle-alert-BqI_9MkV.js","assets/git-pull-request-draft-Cn24ayXz.js","assets/token-metrics-Dk2ZNHb_.js","assets/textarea-ewNKsXDa.js","assets/check-Dt8U0Zvm.js","assets/git-toolbar-Dra1QlHb.js","assets/upload-J0hBTVF7.js","assets/diff-stat-CiWUpWY0.js","assets/use-submit-shortcut-hAaAH4HY.js","assets/search-x-CuinYQnl.js","assets/collapsible-Bdyuw-he.js","assets/centered-state-nM7v9xtl.js","assets/workflow-graph-CcOTCItr.js","assets/download-DOJ8Dqfh.js","assets/settings-2-COky68xN.js","assets/message-square-EWpWB_Gr.js","assets/save-B8DEQI2V.js","assets/tag-yruQH0i-.js","assets/index-qeFtKZ4e.js","assets/use-automations-Dh3Wj-79.js","assets/use-now-BB7W0F--.js","assets/arrow-left-BELOeFyX.js","assets/worktree-lifecycle-operation-vTgExKUM.js","assets/file-1a6_DhLG.js","assets/chevron-right-VbYrJ_st.js","assets/markdown-Rbaca31B.js","assets/chunk-BO2N2NFS-MDrqQfMl.js","assets/lib-BxQXEXDF.js","assets/index-BCATUrmu.css","assets/workflow-graph-DLioOiRN.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{Br as r,Ci as i,Ct as a,F as o,Gr as s,Hr as c,In as l,Jr as u,K as d,Nt as f,Qt as p,Ri as m,Rn as h,Rr as g,Ur as _,V as v,Vr as y,Wr as b,Xt as x,Yn as S,_a as C,_t as w,a as T,b as E,ft as D,h as O,hr as k,ia as A,ii as ee,it as j,j as te,jt as M,ma as N,mn as P,mr as F,nr as I,oi as L,pn as ne,pt as re,qi as ie,r as R,rt as z,ta as B,u as V,ur as H,va as U,vi as ae,vt as oe,wt as W,x as se,xa as G,ya as ce,yi as K,z as le,zr as ue}from"./queries-Bn7zl9OU.js";import{B as de,Ct as fe,F as pe,i as me,jt as he,r as q,t as J}from"./button-Clwd6u4_.js";import{i as ge}from"./bundle-mjs-BT31bpU6.js";import{C as _e,T as ve,c as ye,f as Y,m as be,s as xe,t as Se,w as Ce,x as we}from"./project-router-CZzr7lzN.js";import{_ as Te,f as Ee,g as De,h as Oe,m as ke,p as Ae,s as je,v as Me,y as Ne}from"./reference-chip-CScP5y_O.js";import{a as Pe,b as Fe,i as Ie,n as Le,o as Re,s as ze,v as Be,y as Ve}from"./use-now-BB7W0F--.js";import{t as He}from"./use-desktop-BNN3U2y9.js";import{A as Ue,An as We,B as Ge,Cn as Ke,Ct as qe,D as Je,En as Ye,Et as Xe,G as Ze,Gt as Qe,H as $e,I as et,J as tt,Jt as nt,K as rt,Kt as it,On as at,St as ot,T as st,Tt as ct,U as lt,Ut as ut,V as dt,W as ft,Wt as pt,X as mt,Z as ht,Zt as gt,_ as _t,_t as vt,at as yt,bn as bt,bt as xt,ct as St,dn as Ct,dt as wt,et as Tt,fn as Et,ft as Dt,g as Ot,gt as kt,ht as At,it as jt,jn as Mt,jt as Nt,k as Pt,l as Ft,lt as It,mt as Lt,n as Rt,nt as zt,ot as Bt,pt as Vt,q as Ht,qt as Ut,r as Wt,rt as Gt,st as Kt,tn as qt,tt as Jt,u as Yt,ut as Xt,v as Zt,vt as Qt,wn as $t,wt as en,xn as tn,xt as nn,yn as rn,yt as an,z as on}from"./git-tab-loading-BC6WP7W4.js";import{c as sn,i as cn,l as ln,n as un,o as dn,r as fn,s as pn,t as mn,u as hn}from"./file-preview-pS9i9ZDR.js";import{t as gn}from"./arrow-left-BELOeFyX.js";import{C as _n,E as vn,G as yn,O as bn,U as xn,W as Sn,i as Cn,m as wn,n as Tn,p as En,r as Dn,x as On,y as kn}from"./worktree-lifecycle-operation-vTgExKUM.js";import{t as An}from"./file-1a6_DhLG.js";import{a as jn,i as Mn,r as Nn,t as Pn}from"./textarea-ewNKsXDa.js";import{t as Fn}from"./check-Dt8U0Zvm.js";import{f as In,i as Ln,n as Rn,r as zn,t as Bn}from"./tooltip-B628Gs7C.js";import{t as Vn}from"./chevron-right-VbYrJ_st.js";import{t as Hn}from"./circle-check-DnEaQ9Rj.js";import{a as Un,c as Wn,i as Gn,n as Kn,r as qn,t as Jn,u as Yn}from"./icon-tooltip-YXzUubMO.js";import{n as Xn,t as Zn}from"./terminal-F3ZJ5fI8.js";import{a as Qn,f as $n,l as er,m as tr,p as nr,r as rr}from"./git-toolbar-Dra1QlHb.js";import{t as ir}from"./file-text-DmMQx3hx.js";import{n as ar}from"./upload-J0hBTVF7.js";import{n as or,t as sr}from"./triangle-alert-BqI_9MkV.js";import{t as cr}from"./loader-circle-D-ter0qP.js";import{t as lr}from"./message-square-EWpWB_Gr.js";import{r as ur,t as dr}from"./use-submit-shortcut-hAaAH4HY.js";import{n as fr}from"./square-8OFxLPoA.js";import{t as pr}from"./plus-CBVm02wz.js";import{t as mr}from"./search-x-CuinYQnl.js";import{t as hr}from"./x-DMIsmLBt.js";import{n as gr,r as _r,t as vr}from"./collapsible-Bdyuw-he.js";import{a as yr,c as br,i as xr,n as Sr,o as Cr,r as wr,s as Tr,t as Er}from"./alert-dialog-DvPnvVvK.js";import{i as Dr,r as Or,t as kr}from"./tabs-BUk8rSoE.js";import{t as Ar}from"./input-DIWTlsx6.js";import{i as jr}from"./token-metrics-Dk2ZNHb_.js";import{n as Mr,r as Nr}from"./drawer-state-DasOAIpO.js";import{n as Pr,t as Fr}from"./centered-state-nM7v9xtl.js";import{t as Ir}from"./markdown-Rbaca31B.js";import{a as Lr,o as Rr}from"./scroll-within-Cm6fjjNd.js";import{t as zr}from"./markdown-BzqT8I8y.js";import{n as Br,t as Vr}from"./types-BTlmexWF.js";import{t as Hr}from"./run-diff-GHEaeAio.js";import{t as Ur}from"./diff-CJKocK17.js";import{i as Wr,r as Gr,t as Kr}from"./task-commits-D_gLpFQo.js";import{n as qr,t as Jr}from"./layout-cards-CXMlrDUf.js";var Yr=120;function Xr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zr(e){let t=e.replace(/\s+/g,` `).trim();return t.length>Yr?`${t.slice(0,Yr-1)}…`:t}function X(e,...t){if(Xr(e))for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim()!==``)return Zr(t)}}function Qr(e){if(!Xr(e))return;let t=e.command;if(typeof t==`string`&&t.trim()!==``)return Zr(t);if(Array.isArray(t)){let e=t.filter(e=>typeof e==`string`);if(e.length>0)return Zr(e.join(` `))}}function $r(e){if(!Xr(e)||!Array.isArray(e.changes))return[];let t=[];for(let n of e.changes)Xr(n)&&typeof n.path==`string`&&n.path.trim()!==``&&t.push(n.path);return t}function ei(e){return X(e,`description`,`query`,`url`,`filePath`,`file_path`,`path`,`pattern`,`name`)}function ti(e,t){return t?`${e} ${t}`:e}function ni(e,t){let n=typeof e==`string`?e.toLowerCase():``;switch(n){case`bash`:case`commandexecution`:return{toolKind:`execute`,title:ti(`Ran`,Qr(t)),subtitle:X(t,`description`)};case`edit`:case`multiedit`:return{toolKind:`edit`,title:ti(`Edit`,X(t,`file_path`,`filePath`,`path`))};case`write`:return{toolKind:`edit`,title:ti(`Write`,X(t,`file_path`,`filePath`,`path`))};case`notebookedit`:return{toolKind:`edit`,title:ti(`Edit`,X(t,`notebook_path`,`notebookPath`,`file_path`,`filePath`,`path`))};case`filechange`:{let e=$r(t);return{toolKind:`edit`,title:ti(`Edit`,e.length===1?e[0]:e.length>1?`${e.length} files`:void 0)}}case`read`:return{toolKind:`read`,title:ti(`Read`,X(t,`file_path`,`filePath`,`path`))};case`imageview`:return{toolKind:`read`,title:ti(`View image`,X(t,`path`))};case`glob`:case`grep`:return{toolKind:`search`,title:ti(`Search`,X(t,`pattern`,`query`)),subtitle:X(t,`path`)};case`webfetch`:return{toolKind:`fetch`,title:ti(`Fetch`,X(t,`url`))};case`websearch`:return{toolKind:`fetch`,title:ti(`Web search`,X(t,`query`))};case`task`:case`agent`:{let e=n===`agent`?`Agent`:`Task`,r=X(t,`subagent_type`,`subagentType`),i=X(t,`description`,`prompt`)??r;return{toolKind:`task`,title:i?`${e}: ${i}`:e,subtitle:i===r?void 0:r}}case`skill`:{let e=X(t,`skill`,`name`,`command`);return{toolKind:`skill`,title:e?`Skill: ${e}`:`Skill`,subtitle:X(t,`args`,`description`)}}case`todowrite`:case`todolist`:case`plan`:case`taskcreate`:case`taskupdate`:case`tasklist`:return{toolKind:`plan`,title:`Update plan`};case`contextcompaction`:return{toolKind:`other`,title:`Compacted context`};case`mcptoolcall`:{let e=X(t,`server`),n=X(t,`tool`);return e&&n?{toolKind:`other`,title:`${e}.${n}`}:{toolKind:`other`,title:`MCP tool`,subtitle:ei(t)}}}if(n.startsWith(`mcp__`)){let t=e.split(`__`).filter(e=>e!==``);if(t.length>=3)return{toolKind:`other`,title:`${t[1]}.${t.slice(2).join(`__`)}`}}return{toolKind:`other`,title:typeof e==`string`&&e.trim()!==``?Zr(e):`Tool`,subtitle:ei(t)}}var ri=pe(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),ii=pe(`corner-up-left`,[[`path`,{d:`M20 20v-7a4 4 0 0 0-4-4H4`,key:`1nkjon`}],[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}]]),ai=pe(`folder-input`,[[`path`,{d:`M2 9V5a2 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 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1`,key:`fm4g5t`}],[`path`,{d:`M2 13h10`,key:`pgb2dq`}],[`path`,{d:`m9 16 3-3-3-3`,key:`6m91ic`}]]),oi=pe(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),si=pe(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),ci=pe(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),li=pe(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),Z=e(t(),1);function ui(e,t,n){let[r,i]=(0,Z.useState)({key:n,value:e}),a=(0,Z.useRef)(e);a.current=e;let o=(0,Z.useRef)(n);o.current=n;let s=(0,Z.useRef)(0),c=(0,Z.useRef)(void 0),l=(0,Z.useRef)(!1),u=!Object.is(r.value,e);return r.key===n?u&&c.current===void 0&&Date.now()-s.current>=t&&i({key:n,value:e}):i({key:n,value:e}),(0,Z.useEffect)(()=>{if(!l.current){l.current=!0;return}clearTimeout(c.current),c.current=void 0,s.current=Date.now()},[r]),(0,Z.useEffect)(()=>{if(Object.is(r.value,e)||c.current!==void 0)return;let n=Math.max(0,s.current+t-Date.now());c.current=setTimeout(()=>{c.current=void 0,s.current=Date.now(),i({key:o.current,value:a.current})},n)},[r,e,t]),(0,Z.useEffect)(()=>()=>clearTimeout(c.current),[]),r.value}var di=5,fi=120,pi=200,mi=5e3,hi=15e3,gi=[];function _i(...e){let t=new Map;for(let n of e)for(let e of n)t.set(e.seq,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}function vi(e){let t=-1/0;for(let n of e){if(n.seq<=t)return!1;t=n.seq}return!0}function yi(e){for(let t=e.length-1;t>=0;--t)if(e[t].newerCursor===void 0)return e[t]}function bi(...e){if(!e.every(vi))return _i(...e);let t=e.map(()=>0),n=[];for(;;){let r=1/0;for(let n=0;n<e.length;n+=1){let i=e[n][t[n]];i!==void 0&&i.seq<r&&(r=i.seq)}if(r===1/0)return n;let i;for(let n=0;n<e.length;n+=1){let a=e[n][t[n]];a?.seq===r&&(i=a,t[n]=t[n]+1)}i!==void 0&&n.push(i)}}function xi(e,t,n=-1/0){let r=new Set(t.map(({seq:e})=>e)),i=new Map;for(let e of t){if(e.type!==`item.updated`&&e.type!==`item.completed`)continue;let t=Be(e);t!==void 0&&i.set(t,Math.max(i.get(t)??-1/0,e.seq))}return e.filter(e=>{if(r.has(e.seq)||e.seq<=n&&e.type!==`item.delta`&&e.type!==`item.updated`)return!0;if(e.type!==`item.delta`&&e.type!==`item.updated`)return!1;let t=i.get(Be(e)??``);return t!==void 0&&t>e.seq}).map(({seq:e})=>e)}function Si(e,t){if(t.length===0)return e.slice();let n=e.at(-1)?.seq??-1/0,r=-1/0;for(let n of t){if(n.seq<=r)return _i(e,t);r=n.seq}return e.length===0||t[0].seq>n?[...e,...t]:bi(e,t)}function Ci(e){let t=de(),n=G(),i=[`run-history`,t,e],a=[`run-history-context`,t,e],o=[`run-history-tail`,t,e],s=C({queryKey:i,enabled:e!==void 0,initialPageParam:void 0,queryFn:({pageParam:t,signal:n})=>r(e,t,{signal:n}),getPreviousPageParam:e=>e.olderCursor,getNextPageParam:e=>e.newerCursor,maxPages:di,retry:1}),c=ce({queryKey:a,enabled:e!==void 0,queryFn:({signal:t})=>y(e,{signal:t}),retry:1}),l=s.isError&&s.data===void 0&&!s.isFetchPreviousPageError&&!s.isFetchNextPageError&&!s.isRefetchError,u=c.isError&&c.data===void 0&&!c.isRefetchError,d=s.data?.pages??[],f=(0,Z.useRef)(void 0),p=`${t}\0${e??``}`,m=(0,Z.useRef)({key:p,fallbackLatched:!1}),h=(0,Z.useRef)(Promise.resolve()),g=(0,Z.useRef)(0);m.current.key!==p&&(m.current={key:p,fallbackLatched:!1},h.current=Promise.resolve(),g.current+=1,f.current=void 0),(l||u)&&(m.current.fallbackLatched=!0);let _=m.current.fallbackLatched,v=(0,Z.useCallback)(e=>{let t=h.current,n;return h.current=new Promise(e=>{n=e}),t.then(e).finally(n)},[]),b=yi(d),x=d.length>0?n.getQueryData(o):void 0;b&&(!f.current||b.asOfSeq>=f.current.asOfSeq)?f.current=b:x&&(!f.current||x.asOfSeq>=f.current.asOfSeq)&&(f.current=x);let S=f.current??b??x??(d.length>0?d.at(-1):void 0),w=(0,Z.useRef)(void 0),T=(0,Z.useCallback)(async t=>{if(e===void 0||w.current===p)return!1;w.current=p;let a=g.current,s=new AbortController,c;try{let l=await Promise.race([r(e,void 0,{signal:s.signal}),new Promise((e,t)=>{c=setTimeout(()=>{s.abort(),t(Error(`history compaction timed out`))},hi)})]);if(m.current.key!==p||g.current!==a)return!1;let u=n.getQueryData(i),d=yi(u?.pages??[]),h=n.getQueryData(o);if(Math.max(d?.asOfSeq??-1/0,h?.asOfSeq??-1/0,f.current?.asOfSeq??-1/0)>=l.asOfSeq)return!1;let _=u?(()=>{let e=[...u.pages],t=[...u.pageParams],n=d?e.indexOf(d):-1;for(n>=0?(e[n]=l,t[n]=void 0):(e.push(l),t.push(void 0));e.length>di;)e.shift(),t.shift();return{pages:e,pageParams:t}})():{pages:[l],pageParams:[void 0]};return n.setQueryData(i,_),n.setQueryData(o,l),f.current=l,xi(t,_.pages.flatMap(e=>e.events),l.asOfSeq)}catch{return!1}finally{clearTimeout(c),s.abort(),w.current===p&&(w.current=void 0)}},[i,p,n,e,o]),E=Fe(S&&!_?e:void 0,S?{cursor:S.liveCursor,afterSeq:S.asOfSeq,compactWhenOver:mi,compactAt:pi,onCompact:T}:{}),D=Fe(_?e:void 0),O=ui(E,fi,e),k=ui(D,fi,e),A=(0,Z.useRef)({runId:void 0,scope:t,events:[]});(A.current.runId!==e||A.current.scope!==t)&&(A.current={runId:e,scope:t,events:[]}),_||(A.current.events=O);let ee=_?A.current.events:gi,j=(0,Z.useMemo)(()=>{let e=d.map(e=>e.events);return S!==void 0&&!d.includes(S)&&e.push(S.events),_i(...e)},[S,d]);(0,Z.useEffect)(()=>{let e=yi(d);e&&n.setQueryData(o,e)},[d,n,e,t]);let te=(0,Z.useMemo)(()=>_?bi(j,ee,k):Si(j,O),[_,k,ee,O,j]),M=(0,Z.useMemo)(()=>{if(_)return te;let e=c.data?.contextEvents??[],t=c.data?.asOfSeq??0;return bi(e,te.filter(({seq:e})=>e>t),O.filter(({seq:e})=>e<=t))},[c.data,_,O,te]),N=(0,Z.useCallback)(async()=>{let e=p,t=g.current,r=yi(n.getQueryData(i)?.pages??[]);r&&n.setQueryData(o,r);try{await v(()=>s.fetchPreviousPage())}finally{if(m.current.key!==e||g.current!==t)return;let r=f.current;if(!r)return;n.setQueryData(i,e=>{if(!e)return e;let t=yi(e.pages),n=t?e.pages.indexOf(t):-1;if(n<0||e.pages[n].asOfSeq>=r.asOfSeq)return e;let i=[...e.pages];return i[n]=r,{...e,pages:i}})}},[v,s.fetchPreviousPage,i,n,o]),P=(0,Z.useCallback)(async()=>{g.current+=1,h.current=Promise.resolve();let e=e=>f.current??yi(e)??n.getQueryData(o),t=n.getQueryData(i);if(!e(t?.pages??[])){f.current=void 0,n.removeQueries({queryKey:o,exact:!0}),n.resetQueries({queryKey:i,exact:!0});return}if(t?.pages.length===1&&t.pages[0]===e(t.pages)&&!s.isFetchingPreviousPage)return;await n.cancelQueries({queryKey:i,exact:!0});let r=e(n.getQueryData(i)?.pages??[]);r&&(n.setQueryData(i,{pages:[r],pageParams:[void 0]}),n.setQueryData(o,r),f.current=r)},[s.isFetchingPreviousPage,i,n,o]);return{visibleEvents:te,currentEvents:M,isPending:!_&&s.isPending,contextPending:!_&&c.isPending,fallback:_,hasOlder:!_&&!!s.hasPreviousPage,isFetchingOlder:s.isFetchingPreviousPage,olderError:s.isFetchPreviousPageError?s.error instanceof Error?s.error.message:`Could not load earlier items`:void 0,loadOlder:N,jumpToLatest:P,retainedPages:d.length}}var wi=`design-picks`,Ti=1e5,Ei=(e,t)=>typeof e==`string`?e.slice(0,t):``,Di=e=>typeof e==`number`&&Number.isFinite(e)?Math.round(e):0;function Oi(e){if(typeof e!=`object`||!e)return null;let t=e,n=Ei(t.selector,400),r=Ei(t.tag,40);if(n===``||r===``)return null;let i=t.rect??{},a=t.viewport??{},o={};if(t.styles!==null&&typeof t.styles==`object`)for(let[e,n]of Object.entries(t.styles).slice(0,30))typeof n==`string`&&/^[a-z-]{1,40}$/.test(e)&&(o[e]=n.slice(0,160));return{url:Ei(t.url,2e3),selector:n,tag:r,text:Ei(t.text,200),html:Ei(t.html,1600),styles:o,rect:{x:Di(i.x),y:Di(i.y),width:Di(i.width),height:Di(i.height)},viewport:{width:Di(a.width),height:Di(a.height)},components:Array.isArray(t.components)?t.components.filter(e=>typeof e==`string`).slice(0,6).map(e=>e.slice(0,80)):[],source:Ei(t.source,300),...typeof t.mark==`string`&&/^[a-z0-9-]{1,24}$/.test(t.mark)?{mark:t.mark}:{}}}function ki(e){let t=e.selector.split(` > `).at(-1)??e.tag;return e.components[0]?`${e.components[0]} · ${t}`:t}var Ai=`Elements selected in the app preview:`;function ji(e,t){let n=Math.max(0,...(e.match(/`+/g)??[]).map(e=>e.length)),r="`".repeat(Math.max(3,n+1));return`${r}${t}\n${e}\n${r}`}var Mi=e=>e.split(`
3
+ `).map(e=>e===``?``:` ${e}`).join(`
4
+ `);function Ni(e){return e.length===0?``:`${Ai}\n\n${e.map(e=>{let t=[`- \`${e.selector}\`${e.url?` on ${e.url}`:``}`];e.components.length>0?t.push(` component: ${[...e.components].reverse().join(` › `)}${e.source?` (${e.source})`:``}`):e.source&&t.push(` source: ${e.source}`),t.push(` box: ${e.rect.width}×${e.rect.height} at ${e.rect.x},${e.rect.y} (viewport ${e.viewport.width}×${e.viewport.height})`),e.text&&t.push(` text: ${JSON.stringify(e.text)}`);let n=Object.entries(e.styles);return n.length>0&&t.push(` styles: ${n.map(([e,t])=>`${e}: ${t}`).join(`; `)}`),`${t.join(`
5
+ `)}\n\n${Mi(ji(e.html,`html`))}`}).join(`
6
+
7
+ `)}`}function Pi(e,t){let n=Ni(t);if(n===``)return e;let r=e.trim()===``?n:`${e}\n\n${n}`;if(r.length>Ti)throw Error(`Too long with the ${t.length===1?`selected element`:`${t.length} selected elements`} attached — remove some of them.`);return r}var Q=n(),Fi=12e3,Ii=/^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[?::1\]?|.+\.local)$/i;function Li({state:e,onChange:t,onPickElement:n,designMarks:r,renderDesignNote:i,onDesignEscape:a,renderEmpty:o}){let s=e.tabs.length>0?e.tabs:[``],c=Math.min(e.active,s.length-1),l=s[c]??``,[u,d]=(0,Z.useState)(l),[f,p]=(0,Z.useState)(l===``?`idle`:`loading`),[m,h]=(0,Z.useState)(0),[g,_]=(0,Z.useState)(l),v=te(),y=(0,Z.useRef)(null),[b,x]=(0,Z.useState)({}),S=b[c]??Wi(l),C=S.position>0,w=S.position>=0&&S.position<S.stack.length-1,[T,E]=(0,Z.useState)(null),D=(0,Z.useRef)(0),O=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{if(y.current&&y.current.index===c&&y.current.url===l){y.current=null;return}y.current=null,d(l),_(l),p(l===``?`idle`:`loading`),O.current&&h(e=>e+1),O.current=!0},[c,l]);let k=v.data?.capabilities?.localHandoff??!0,A=g!==``&&!k&&ea(g),[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(null),[F,I]=(0,Z.useState)(!1),L=(0,Z.useRef)(null),ne=(0,Z.useRef)(null),re=n!==void 0,ie=re&&(v.data?.capabilities?.designMode??!1),R=ie?null:v.data?.capabilities?.localHandoff===!1?`Design Mode needs a local cockpit — a hosted one cannot reach the task's local dev server`:`Design Mode is turned off on this cockpit (CEZ_DESIGN_MODE=0)`,z=Ji(g),B=ie&&j&&z!==null,V=N!==null&&N.upstream===z?N.origin:null,H=B&&V===null,U=(0,Z.useCallback)(e=>V!==null&&z!==null?V+e.slice(z.length):e,[V,z]),ae=U(g),oe=`${Xi(ae)}#${m}`,W=T??g;(0,Z.useEffect)(()=>{E(null),D.current=0},[oe]),(0,Z.useEffect)(()=>{if(!B||z===null)return;let e=!1;return ee({target:z,parentOrigin:window.location.origin}).then(t=>{e||P({upstream:z,origin:t.origin})}).catch(t=>{e||(M(!1),Y(t instanceof Error&&t.message?t.message:`Design Mode could not start.`,{tone:`danger`}))}),()=>{e=!0}},[B,m,z]),(0,Z.useEffect)(()=>I(!1),[oe]),(0,Z.useEffect)(()=>{!F||V===null||L.current?.contentWindow?.postMessage({source:`cezar-design-host`,type:`set-active`,active:B},V)},[B,V,F]);let se=i!==void 0,[G,ce]=(0,Z.useState)(!1),[K,le]=(0,Z.useState)(null),[ue,de]=(0,Z.useState)({}),[fe,pe]=(0,Z.useState)(!1),me=(0,Z.useRef)(null),he=(0,Z.useRef)(null),[ge,_e]=(0,Z.useState)(null),ve=(0,Z.useCallback)(()=>ce(!1),[]),ye=r??zi,be=K!==null&&ye.some(e=>e.key===K),xe=se&&ie&&G&&be,Se=K===null?void 0:ue[K],Ce=se&&V!==null&&fe?ye.filter(e=>e.draft&&!(e.key in ue)):zi,we=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{be?we.current=K:G&&we.current===K&&ce(!1)},[K,be,G]),(0,Z.useEffect)(()=>{de({}),pe(!1)},[oe]),(0,Z.useLayoutEffect)(()=>{if(!xe)return;let e=me.current,t=he.current;!e||!t||_e(Ui(Se,{width:e.clientWidth,height:e.clientHeight},{width:t.offsetWidth,height:t.offsetHeight}))},[K,Se,xe]);let Te=ge!==null;(0,Z.useEffect)(()=>{xe&&Te&&he.current?.querySelector(`textarea`)?.focus()},[K,xe,Te]);let Ee=JSON.stringify(ye.map(({key:e,n:t,selector:n,path:r})=>({key:e,n:t,selector:n,path:r}))),De=(0,Z.useCallback)(()=>{V!==null&&L.current?.contentWindow?.postMessage({source:`cezar-design-host`,type:`set-marks`,marks:JSON.parse(Ee)},V)},[Ee,V]);(0,Z.useEffect)(()=>{F&&De()},[F,De]);let Oe=(0,Z.useRef)(null);Oe.current=xe?K:null,(0,Z.useEffect)(()=>{if(V===null)return;let e=e=>{if(e.origin!==V||e.source!==L.current?.contentWindow)return;let t=e.data;if(!(typeof t!=`object`||!t||t.source!==`cezar-design`)){if(t.type===`ready`)I(!0);else if(t.type===`cancel`)Oe.current===null?M(!1):(a?.(Oe.current),ce(!1));else if(t.type===`mark-clicked`&&typeof t.key==`string`)le(t.key),ce(!0);else if(t.type===`rects`)de(Bi(t.rects)),pe(!0);else if(t.type===`picked`){let e=Oi(t.element);if(!e||!n?.(e)){De();return}if(!se){Y(`Element picked.`);return}let r=e.mark;r!==void 0&&de(t=>({...t,[r]:e.rect})),le(r??null),ce(!0)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[se,V,a,n,De]);let ke=(0,Z.useCallback)(()=>{j||P(null)},[j]);(0,Z.useEffect)(()=>{if(f!==`loading`||g===``||A)return;let e=setTimeout(()=>p(`failed`),Fi);return()=>clearTimeout(e)},[A,m,f,g]);let Ae=(0,Z.useCallback)(n=>{s[c]===n||n.length>mt||(y.current={index:c,url:n},t({...e,tabs:s.map((e,t)=>t===c?n:e)}))},[c,t,e,s]),je=(0,Z.useCallback)(e=>{if(f===`idle`&&!A&&e!==W&&Zi(W,e)){E(null),_(e),d(e),e===g&&L.current&&(L.current.src=U(e)),Ae(e);return}ke(),E(null),_(e),d(e),p(`loading`),h(e=>e+1)},[U,Ae,A,ke,W,f,g]),Me=(0,Z.useCallback)(e=>{let t=qi(e);t!==null&&(x(e=>{let n=e[c]??Wi(l),r=n.stack.slice(0,n.position+1);if(r[r.length-1]===t)return e;let i=[...r,t].slice(-Gi);return{...e,[c]:{stack:i,position:i.length-1}}}),je(t))},[c,l,je]),Ne=(0,Z.useCallback)(e=>{let t=S.position+e,n=S.stack[t];n!==void 0&&(x(e=>({...e,[c]:{stack:S.stack,position:t}})),je(n))},[c,S.position,S.stack,je]),Pe=(0,Z.useCallback)(()=>{g!==``&&(D.current+=1,p(`idle`),Ae(W))},[Ae,W,g]),Fe=(0,Z.useCallback)((e,t)=>{E(e),d(t=>t===W||document.activeElement!==ne.current?e:t),x(n=>{let r=n[c]??Wi(l);if(r.stack[r.position]===e)return n;let i;if(r.stack[r.position-1]===e&&t===`pop`)i={stack:r.stack,position:r.position-1};else if(r.stack[r.position+1]===e&&t===`pop`)i={stack:r.stack,position:r.position+1};else if(t===`push`||t===`load`&&D.current>0||r.position<0){let t=[...r.stack.slice(0,r.position+1),e].slice(-Gi);i={stack:t,position:t.length-1}}else i={stack:r.stack.map((t,n)=>n===r.position?e:t),position:r.position};return{...n,[c]:i}}),f===`idle`&&Ae(e)},[c,l,Ae,W,f]),Ie=Qi(ae);(0,Z.useEffect)(()=>{if(Ie===null)return;let e=e=>{if(e.origin!==Ie||e.source!==L.current?.contentWindow)return;let t=e.data;if(typeof t!=`object`||!t||t.source!==`cezar-preview`||t.type!==`location`||typeof t.url!=`string`)return;let n=$i(t.url,Ie,V===null?null:z);n!==null&&Fe(n,typeof t.how==`string`?t.how:`replace`)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[Fe,Ie,V,z]);let Le=(0,Z.useCallback)(()=>{s.length>=Ht||t({tabs:[...s,``],active:s.length})},[t,s]),Re=(0,Z.useCallback)(e=>{let n=s.filter((t,n)=>n!==e);if(n.length===0){t(It()),x({});return}t({tabs:n,active:e<c?c-1:Math.min(c,n.length-1)}),x(t=>{let n={};for(let[r,i]of Object.entries(t)){let t=Number(r);t!==e&&(n[t>e?t-1:t]=i)}return n})},[c,t,s]);return(0,Q.jsxs)(`div`,{"data-slot":`browser-view`,className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(kr,{value:String(c),onValueChange:n=>t({...e,active:Number(n)}),className:`shrink-0 gap-0`,children:(0,Q.jsxs)(Or,{"aria-label":`Browser tabs`,className:`flex w-full justify-start gap-0.5 overflow-x-auto rounded-none bg-transparent px-3 py-0`,children:[s.map((n,r)=>(0,Q.jsxs)(`div`,{"data-slot":`browser-tab`,"data-active":r===c?``:void 0,className:q(`group flex h-6 shrink-0 items-center rounded-sm pl-2 pr-0.5 text-xs font-medium`,r===c?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:[(0,Q.jsx)(Dr,{value:String(r),onClick:()=>{r!==c&&t({...e,active:r})},title:n||`New tab`,className:`inline-block h-auto max-w-32 flex-none truncate rounded-none border-0 p-0 text-xs font-medium text-inherit hover:text-inherit focus-visible:underline focus-visible:ring-0 focus-visible:outline-0 data-[state=active]:bg-transparent data-[state=active]:font-medium data-[state=active]:text-inherit group-data-[variant=default]/tabs-list:data-[state=active]:shadow-none`,children:Ki(n)}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close tab ${Ki(n)}`,onClick:()=>Re(r),className:q(`ml-1 size-4 rounded text-inherit opacity-0 transition-opacity hover:bg-background hover:text-inherit focus-visible:opacity-100 group-hover:opacity-100`,r===c&&`opacity-60`),children:(0,Q.jsx)(hr,{"aria-hidden":`true`,className:`size-3`})})]},r)),s.length<Ht?(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`New tab`,title:`New tab`,onClick:Le,className:`size-6 rounded`,children:(0,Q.jsx)(pr,{"aria-hidden":`true`,className:`size-3.5`})}):null]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/70 px-3 pb-2`,children:[(0,Q.jsx)(Ri,{label:`Back`,disabled:!C,onClick:()=>Ne(-1),icon:(0,Q.jsx)(gn,{"aria-hidden":`true`,className:`size-3.5`})}),(0,Q.jsx)(Ri,{label:`Forward`,disabled:!w,onClick:()=>Ne(1),icon:(0,Q.jsx)(yn,{"aria-hidden":`true`,className:`size-3.5`})}),(0,Q.jsx)(Ri,{label:`Reload`,onClick:()=>{g!==``&&(ke(),E(null),_(W),d(W),p(`loading`),h(e=>e+1))},icon:(0,Q.jsx)(ci,{"aria-hidden":`true`,className:q(`size-3.5`,f===`loading`&&`animate-spin`)})}),(0,Q.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),Me(u)},children:(0,Q.jsx)(Ar,{ref:ne,value:u,onChange:e=>d(e.target.value),placeholder:`Enter an address, e.g. http://localhost:3000`,"aria-label":`Address`,spellCheck:!1,className:`h-8 text-[13px] focus-visible:ring-ring/30 md:text-[13px]`})}),re?(0,Q.jsxs)(J,{type:`button`,"data-slot":`browser-design-toggle`,variant:B?`primary`:`outline`,size:`sm`,"aria-pressed":B,disabled:R!==null||z===null,title:R??(z===null?`Design Mode works on local http:// addresses`:B?`Stop selecting elements (Esc)`:`Click an element of the page to send it to the agent`),onClick:()=>M(e=>!e),className:`ml-1 disabled:opacity-40`,children:[(0,Q.jsx)(pn,{"aria-hidden":`true`,className:`size-3.5`}),`Design Mode`]}):null]}),(0,Q.jsxs)(`div`,{ref:me,className:`relative min-h-0 flex-1`,children:[A?(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(sr,{}),tone:`neutral`,heading:`h2`,title:`This address points at the machine you are sitting at`,subtitle:`This cockpit runs remotely, so a local address would open on your computer rather than on the task's host. Open the cockpit on the task's machine to preview its app.`}):g===``&&o&&k?o(Me):g===``?(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(Ye,{}),tone:`neutral`,heading:`h2`,title:`Empty tab`,subtitle:`Enter the address of the task's app, e.g. http://localhost:3000 — then switch on Design Mode to point at an element and tell the agent what to change.`}):(0,Q.jsxs)(Q.Fragment,{children:[f===`failed`?(0,Q.jsxs)(`div`,{"data-slot":`browser-failed`,className:`absolute inset-x-0 top-0 z-10 border-b border-border bg-background px-3 py-2 text-xs text-soft-foreground`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:`Could not open`}),` — the page did not respond or does not allow embedding. The address is still in the bar; you can fix it.`]}):null,Ce.length>0?(0,Q.jsx)(`div`,{"data-slot":`browser-design-adrift`,className:`absolute bottom-3 left-3 z-10 flex max-w-[60%] flex-wrap gap-1.5`,children:Ce.map(e=>(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,title:`A note in progress — its element could not be found on this page`,onClick:()=>{le(e.key),ce(!0)},className:`max-w-48`,children:(0,Q.jsxs)(`span`,{className:`truncate`,children:[`Draft · `,e.label]})},e.key))}):null,B&&f===`idle`&&!xe&&Ce.length===0?(0,Q.jsx)(`p`,{"data-slot":`browser-design-hint`,className:`pointer-events-none absolute bottom-3 left-1/2 z-10 -translate-x-1/2 rounded-full border border-border bg-background/95 px-3 py-1 text-xs whitespace-nowrap text-soft-foreground shadow-sm`,children:se?`Click an element to write a note about it · Esc to stop`:`Click an element to pick it · Esc to stop`}):null,H?null:(0,Q.jsx)(`iframe`,{ref:L,src:ae,title:`Preview`,onLoad:Pe,sandbox:`allow-same-origin allow-scripts allow-forms allow-modals allow-popups`,allow:``,referrerPolicy:`no-referrer`,className:q(`size-full border-0`,f===`loading`&&`invisible`)},oe),f===`loading`?(0,Q.jsx)(`p`,{className:`absolute inset-0 grid place-items-center text-xs text-soft-foreground`,children:`Loading…`}):null]}),xe?(0,Q.jsx)(`div`,{ref:he,"data-slot":`browser-design-note`,role:`dialog`,"aria-label":`Note about the selected elements`,style:ge?{left:ge.left,top:ge.top}:{left:0,top:0,visibility:`hidden`},className:`absolute z-20 w-[min(360px,calc(100%-16px))] rounded-xl border border-border bg-background shadow-lg`,children:K===null?null:i({mark:K,close:ve})}):null]})]})}function Ri({label:e,icon:t,onClick:n,disabled:r}){return(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":e,title:e,onClick:n,disabled:r,className:`disabled:opacity-40`,children:t})}var zi=[];function Bi(e){let t={};if(!Array.isArray(e))return t;for(let n of e.slice(0,50)){if(typeof n!=`object`||!n)continue;let e=n;if(typeof e.key!=`string`||!/^[a-z0-9-]{1,24}$/.test(e.key))continue;let r=e=>typeof e==`number`&&Number.isFinite(e)?e:0;t[e.key]={x:r(e.x),y:r(e.y),width:r(e.width),height:r(e.height)}}return t}var Vi=10,Hi=8;function Ui(e,t,n){let r=Math.max(Hi,t.width-n.width-Hi),i=Math.max(Hi,t.height-n.height-Hi);if(!e)return{left:r,top:i};let a=(e,t)=>Math.min(Math.max(e,Hi),t),o=e.y+e.height+Vi,s=e.y-Vi-n.height,c=o+n.height+Hi<=t.height?o:s>=Hi?s:o;return{left:a(e.x,r),top:a(c,i)}}function Wi(e){return e===``?{stack:[],position:-1}:{stack:[e],position:0}}var Gi=50;function Ki(e){if(e===``)return`New tab`;try{let t=new URL(e),n=t.pathname===`/`?``:t.pathname;return`${t.host}${n}`}catch{return e}}function qi(e){let t=e.trim();if(t===``)return null;let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(t);if(!n&&/^[a-z][a-z0-9+.-]*:(?!\d)/i.test(t))return null;let r=n?t:`http://${t}`,i;try{i=new URL(r)}catch{return null}return i.protocol!==`http:`&&i.protocol!==`https:`?null:i.toString()}function Ji(e){if(e===``)return null;try{let t=new URL(e);return t.protocol!==`http:`||!Yi.test(t.hostname)?null:t.origin}catch{return null}}var Yi=/^(localhost|127\.0\.0\.1|\[::1\])$/i;function Xi(e){let t=e.indexOf(`#`);return t===-1?e:e.slice(0,t)}function Zi(e,t){return e!==``&&t.includes(`#`)&&Xi(e)===Xi(t)}function Qi(e){try{let t=new URL(e).origin;return t===`null`?null:t}catch{return null}}function $i(e,t,n){let r;try{r=new URL(e)}catch{return null}if(r.origin!==t)return null;let i=r.pathname+r.search+r.hash;return qi((n??t)+i)}function ea(e){try{return Ii.test(new URL(e).hostname)}catch{return!1}}var ta=5,na=[{scope:`project`,title:`Team`,detail:`Saved in the repo's .ai/cezar/config.json. Commit it and everyone gets the same Start app.`},{scope:`personal`,title:`Only me`,detail:`Saved in your ~/.cezar/config.json, and used instead of the team recipe.`}];function ra({open:e,onOpenChange:t,suggestion:n,onSaved:r}){let[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(`project`),[c,l]=(0,Z.useState)([``]),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),_=e=>{let t=e??n;l(t.services.length>0?[...t.services]:[``]),f(t.url??``)};(0,Z.useEffect)(()=>{if(!e)return;m(null);let t=!1;return u().then(e=>{if(t)return;a(e);let n=e.personal?`personal`:`project`;s(n),_(e[n])}).catch(e=>!t&&m(e instanceof Error?e.message:String(e))),()=>{t=!0}},[e]);let v=async e=>{g(!0),m(null);try{a(await ie({scope:o,recipe:e})),r(),t(!1)}catch(e){m(e instanceof Error?e.message:String(e))}finally{g(!1)}},y=c.map(e=>e.trim()).filter(Boolean),b=d.trim(),x=b!==``&&!/^https?:\/\/\S+$/.test(b);return(0,Q.jsx)(Ee,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ae,{className:`sm:max-w-lg`,children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(Te,{children:`Start recipe`}),(0,Q.jsx)(ke,{children:`What starts this project's app for the Preview. Each command runs in its own terminal tab of the task. Installing dependencies is not part of it.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`div`,{role:`radiogroup`,"aria-label":`Who uses this recipe`,className:`grid grid-cols-2 gap-2`,children:na.map(e=>{let t=e.scope===`personal`&&i?.personalAvailable===!1,n=o===e.scope;return(0,Q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,disabled:t,onClick:()=>{s(e.scope),_(i?.[e.scope]??null)},className:q(`flex flex-col gap-1 rounded-md border p-2.5 text-left text-xs transition-colors disabled:opacity-50`,n?`border-foreground/40 bg-muted`:`border-border hover:bg-muted/50`),children:[(0,Q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.title,i?.[e.scope]?(0,Q.jsx)(`span`,{className:`ml-1.5 font-normal text-muted-foreground`,children:`· saved`}):null]}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:t?`This project is not in your project list.`:e.detail})]},e.scope)})}),(0,Q.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`legend`,{className:`mb-1.5 text-xs font-medium text-foreground`,children:`Services`}),c.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Ar,{value:e,onChange:e=>l(n=>n.map((n,r)=>r===t?e.target.value:n)),placeholder:t===0?`npm run dev`:`npm run api`,"aria-label":`Service ${t+1}`,spellCheck:!1,className:`h-8 font-mono text-xs md:text-xs`}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Remove service ${t+1}`,disabled:c.length===1,onClick:()=>l(e=>e.filter((e,n)=>n!==t)),children:(0,Q.jsx)(hr,{"aria-hidden":`true`})})]},t)),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`xs`,className:`self-start text-muted-foreground`,disabled:c.length>=ta,onClick:()=>l(e=>[...e,``]),children:[(0,Q.jsx)(pr,{"aria-hidden":`true`}),`Add service`]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:`Address to show (optional)`}),(0,Q.jsx)(Ar,{value:d,onChange:e=>f(e.target.value),placeholder:`http://localhost:5173 — empty: the first address a service prints`,"aria-label":`Address to show`,"aria-invalid":x,spellCheck:!1,className:`h-8 font-mono text-xs md:text-xs`}),x?(0,Q.jsx)(`span`,{className:`text-danger`,children:`Start it with http:// or https://`}):null]}),p?(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:p}):null]}),(0,Q.jsxs)(Oe,{className:`gap-2 sm:justify-between`,children:[i?.[o]?(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,disabled:h,onClick:()=>void v(null),children:[`Remove `,o===`project`?`team`:`your`,` recipe`]}):(0,Q.jsx)(`span`,{}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(J,{type:`button`,disabled:h||y.length===0||x,onClick:()=>void v({services:y,...b?{url:b}:{}}),children:`Save`})]})]})]})})}var ia=1e3,aa=12e4,oa=6e5,sa=[`dev`,`start`,`serve`,`preview`,`run`],ca=e=>`cez:preview-run:${e??`default`}`;function la(e){try{return window.localStorage.getItem(ca(e))}catch{return null}}function ua(e,t){try{window.localStorage.setItem(ca(e),t)}catch{}}function da(e){for(let t of sa){let n=e.find(e=>RegExp(`^(npm run|make) ${t}$`).test(e.command));if(n)return n.command}return null}function fa(e,t){try{let n=new URL(e),r=new URL(t),i=e=>e.hostname===`127.0.0.1`||e.hostname===`[::1]`?`localhost`:e.hostname,a=e=>e.port||(e.protocol===`https:`?`443`:`80`);return n.protocol===r.protocol&&i(n)===i(r)&&a(n)===a(r)}catch{return!1}}function pa(e,t,n){let r=e.filter(e=>Date.parse(e.lastSeenAt)>=t&&e.running!==!1);return n?r.some(e=>fa(e.url,n))?n:null:(r.find(e=>e.running===!0)??r[0])?.url??null}function ma({runId:e,projectId:t,onOpen:n,onShowTerminal:r,setup:i}){let a=i?.phase===`setup`&&i.needsAttention,o=i?.phase===`setup`&&!i.needsAttention&&i.activeOperationId!==void 0,[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(()=>la(t)),[g,v]=(0,Z.useState)(``),[y,x]=(0,Z.useState)({kind:`idle`}),[S,C]=(0,Z.useState)(!1),w=(0,Z.useCallback)(()=>{let t=!1;return b(e).then(e=>{t||(l(e.commands),d(e.install??null),p(e.recipe??null))}).catch(()=>!t&&l([])),()=>{t=!0}},[e]);(0,Z.useEffect)(()=>w(),[w]);let T=m??(c?da(c):null),E=(0,Z.useRef)(null),D=(0,Z.useRef)([]);(0,Z.useEffect)(()=>()=>{E.current=null;for(let e of D.current)clearTimeout(e)},[]);let O=(0,Z.useCallback)((r,i={})=>{let a=r.services.map(e=>e.trim()).filter(Boolean);if(a.length===0)return;let o={};E.current=o;let c=()=>E.current===o,l=e=>D.current.push(setTimeout(e,ia)),f={services:a,...r.url?{url:r.url}:{}};i.remember&&a[0]&&(ua(t,a[0]),h(a[0]));let p=async t=>{let n=await _(e).catch(()=>null);for(let[e,r]of t.entries()){let t=n?.sessions.find(e=>e.id===r)?.exitCode;if(t!=null)return{index:e,code:t}}return null},m=async()=>{x({kind:`starting`,plan:f});let t=Date.now()-1e3,r=[];for(let t of a){let n=await k(e,{});if(!c())return;r.push(n.id),await A(e,n.id,`${t}\r`)}let i=async()=>{if(!c())return;if(Date.now()-t>aa){x({kind:`no-address`,plan:f});return}let o=await s(e).catch(()=>null);if(!c())return;let u=o?pa(o.urls,t,f.url):null;if(u){E.current=null,n(u);return}let d=await p(r);if(c()){if(d){x({kind:`exited`,command:a[d.index],code:d.code});return}l(()=>void i())}};await i()};(async()=>{if(!u)return m();x({kind:`installing`,install:u,plan:f});let t=Date.now(),n=await k(e,{});if(!c())return;await A(e,n.id,`${u} && exit 0 || exit 1\r`);let r=async()=>{if(!c())return;if(Date.now()-t>oa){x({kind:`no-address`,plan:f});return}let e=await p([n.id]);if(c()){if(!e)return l(()=>void r());if(e.code!==0){x({kind:`exited`,command:u,code:e.code});return}d(null),await m()}};l(()=>void r())})().catch(()=>{c()&&x({kind:`failed`})})},[u,n,t,e]),ee=(c??[]).filter(e=>f!==null||e.command!==T),j=r?(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:[(0,Q.jsx)(Zn,{"aria-hidden":`true`}),`Show terminal`]}):null,te=(0,Q.jsx)(ra,{open:S,onOpenChange:C,suggestion:f?{services:f.services,...f.url?{url:f.url}:{}}:{services:T?[T]:[``]},onSaved:w});if(y.kind===`installing`||y.kind===`starting`){let e=y.plan.services.join(` · `);return(0,Q.jsx)(ha,{icon:(0,Q.jsx)(cr,{"aria-hidden":`true`,className:`size-5 motion-safe:animate-spin`}),title:y.kind===`installing`?`Installing dependencies (${y.install})`:`Starting ${e}`,subtitle:y.kind===`installing`?`This worktree has no dependencies yet. ${e} starts as soon as they are installed.`:`Running in ${y.plan.services.length>1?`new terminal tabs`:`a new terminal tab`} of this task. The page opens here as soon as the app is up${y.plan.url?` at ${y.plan.url}`:``}.`,children:j})}let M=y.kind===`exited`?`${y.command} exited with code ${y.code} before the app was up.`:y.kind===`no-address`?`${y.plan.services.join(` · `)} is still running, but ${y.plan.url?`nothing answered at ${y.plan.url}`:`printed no address`} yet. Enter it above, or check the terminal.`:y.kind===`failed`?`Could not open a terminal for this task.`:null,N=(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)(Yn,{asChild:!0,children:(0,Q.jsxs)(J,{type:`button`,variant:f||T?`outline`:`primary`,size:`sm`,"data-action":`run-app-other`,disabled:o,children:[f||T?`Other command`:`Choose a command`,(0,Q.jsx)(In,{"aria-hidden":`true`})]})}),(0,Q.jsxs)(qn,{align:`center`,className:`max-h-80 w-80 overflow-y-auto`,children:[(0,Q.jsx)(Un,{children:`Project commands`}),ee.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-soft-foreground`,children:c===null?`Looking…`:`No other commands in package.json or a Makefile.`}):ee.map(e=>(0,Q.jsxs)(Gn,{onSelect:()=>O({services:[e.command]},{remember:!0}),className:`flex-col items-start gap-0`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:e.command}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-soft-foreground`,children:[e.source,e.detail?` — ${e.detail}`:``]})]},`${e.source}:${e.command}`)),(0,Q.jsx)(Wn,{}),(0,Q.jsx)(Un,{className:`font-normal text-soft-foreground`,children:`Custom command`}),(0,Q.jsx)(`form`,{className:`px-2 pb-1`,onSubmit:e=>{e.preventDefault(),O({services:[g]},{remember:!0}),v(``)},children:(0,Q.jsx)(Ar,{value:g,onChange:e=>v(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:`e.g. npm run dev`,"aria-label":`Custom command`,spellCheck:!1,className:`h-8 px-2 font-mono text-xs shadow-none focus-visible:ring-0 md:text-xs`})})]})]}),P=u?` Installs its dependencies first (${u}).`:``,F=o?`This worktree's setup scripts are still running. Start the app when they finish.`:a?`This worktree's setup needs attention — retry it from the task's Chat, or start the app anyway.`:null;return(0,Q.jsxs)(ha,{icon:(0,Q.jsx)(fr,{"aria-hidden":`true`,className:`size-5`}),title:f?`Start the app`:`Run the app`,subtitle:M??(f?`${f.scope===`personal`?`Your`:`This project's`} start recipe runs each service in its own terminal tab and opens ${f.url??`the address it prints`}.${P}`:`Starts the task's app in a terminal of its worktree and opens the address it prints.${P} Or enter an address above.`),children:[F?(0,Q.jsx)(`p`,{"data-slot":`run-app-setup`,role:`status`,className:`max-w-md text-xs text-foreground`,children:F}):null,f?(0,Q.jsx)(`ul`,{"data-slot":`start-app-services`,className:`flex flex-col gap-0.5 font-mono text-xs text-foreground`,children:f.services.map((e,t)=>(0,Q.jsx)(`li`,{children:e},t))}):null,(0,Q.jsxs)(`div`,{"data-slot":`run-app-actions`,className:`flex flex-wrap items-center justify-center gap-2`,children:[f?(0,Q.jsxs)(J,{type:`button`,size:`sm`,"data-action":`start-app`,disabled:o,onClick:()=>O(f),children:[(0,Q.jsx)(fr,{"aria-hidden":`true`}),`Start app`]}):T?(0,Q.jsxs)(J,{type:`button`,size:`sm`,"data-action":`run-app`,disabled:o,onClick:()=>O({services:[T]},{remember:!0}),children:[(0,Q.jsx)(fr,{"aria-hidden":`true`}),`Run `,(0,Q.jsx)(`code`,{className:`font-mono text-[12px]`,children:T})]}):null,N,M?j:null]}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`xs`,"data-action":`edit-start-app`,className:`text-muted-foreground`,onClick:()=>C(!0),children:[(0,Q.jsx)(ur,{"aria-hidden":`true`}),f?`Edit start recipe`:`Save a start recipe for this project`]}),te]})}function ha({icon:e,title:t,subtitle:n,children:r}){return(0,Q.jsxs)(`div`,{"data-slot":`run-app`,className:`flex h-full flex-col items-center justify-center gap-3 px-6 py-8 text-center`,children:[(0,Q.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground`,children:e}),(0,Q.jsxs)(`div`,{className:`flex max-w-md flex-col gap-1`,children:[(0,Q.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:t}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]}),r]})}var ga={running:{label:`In progress`,tone:`pending`,pulse:!0},asking:{label:`Agent is waiting for your answer`,tone:`violet`},done:{label:`Done`,tone:`success`}};function _a(e){return e===`running`?{action:`Send`,hint:`The agent is working — the note goes into its session now.`}:e===`waiting`?{action:`Send`,hint:`The agent is free — this starts right away.`}:e===`queued`?{action:`Send`,hint:`This task has not started — the note joins its first prompt.`}:{action:`Reopen & send`,hint:`The session is closed — this reopens it with the note.`}}function va({note:e,run:t,notes:n,onClose:r}){let[i,a]=(0,Z.useState)(!1),o=e.phase===`draft`,s=async(e,t)=>{a(!0);try{return await e(),!0}catch(e){return Y(e instanceof Error&&e.message?e.message:t,{tone:`danger`}),!1}finally{a(!1)}},c=()=>{o&&n.discard(e.key),r()},l=async()=>{e.text.trim()===``||i||await s(()=>n.send(e.key),`Could not send the note.`)&&r()},u=_a(t.status),d=o?null:ga[e.phase];return(0,Q.jsxs)(`div`,{"data-slot":`design-note`,"data-phase":e.phase,className:`flex flex-col gap-2 p-2.5 text-xs`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.number===void 0?null:(0,Q.jsxs)(`span`,{"data-slot":`design-note-number`,"aria-label":`Note ${e.number}`,className:`flex h-[21px] shrink-0 items-center gap-1 rounded-md bg-primary pr-[7px] pl-1.5 text-xs leading-none font-bold text-primary-foreground`,children:[(0,Q.jsx)(lr,{"aria-hidden":`true`,className:`size-3`,strokeWidth:2.5}),e.number]}),(0,Q.jsx)(`span`,{"data-slot":`design-note-element`,className:`min-w-0 flex-1 truncate font-mono text-[11px] font-medium text-foreground`,title:e.pick.selector,children:ki(e.pick)}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-6`,"aria-label":o?`Discard note`:`Close`,title:o?`Discard this note and deselect the element (Esc)`:`Close (Esc)`,onClick:c,children:(0,Q.jsx)(hr,{"aria-hidden":`true`})})]}),d?(0,Q.jsxs)(`p`,{"data-slot":`design-note-status`,className:`flex items-center gap-1.5 text-soft-foreground`,children:[(0,Q.jsx)(jr,{tone:d.tone,pulse:d.pulse??!1}),d.label]}):null,o?(0,Q.jsx)(Pn,{value:e.text,onChange:t=>n.setText(e.key,t.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),c()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),l())},placeholder:`What should change here?`,"aria-label":`Note for the agent`,autoFocus:!0,rows:3,className:`min-h-16 resize-none text-[13px] md:text-[13px]`}):(0,Q.jsx)(`p`,{"data-slot":`design-note-text`,className:`max-h-40 overflow-y-auto rounded-md border border-border bg-muted/40 px-2 py-1.5 text-[13px] break-words whitespace-pre-wrap text-foreground`,children:e.text}),o?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{"data-slot":`design-note-hint`,className:`min-w-0 flex-1 text-soft-foreground`,children:u.hint}),(0,Q.jsx)(J,{type:`button`,size:`sm`,disabled:i||e.text.trim()===``,onClick:()=>void l(),children:u.action})]}):null]})}function ya(e){return e===`running`||e===`waiting`||e===`queued`?`live`:`continue`}var ba=[250,500,1e3,1e3,2e3,2e3,3e3],xa=e=>new Promise(t=>setTimeout(t,e));function Sa(e){return e instanceof S&&e.status===409&&e.message===`session closed`}function Ca(e){return e instanceof S&&e.status===409&&e.message===`run is still active`}function wa(e,t){return e===`live`?Sa(t):Ca(t)}var Ta=e=>e.steps.filter(e=>e.id.startsWith(`continue-`)).length;function Ea(e,t,n={}){let{wait:r=xa,surface:i=`existing_session`}=n,a=G(),{mutateAsync:o}=M(e.id),s=Ta(e);return(0,Z.useCallback)(async(n,c)=>{let l=async e=>{let r=await(e===`live`?o({text:n,images:c}):t(n,c));return i&&Et(i),r},u=()=>a.fetchQuery({...T(e.id),staleTime:0}),d=ya(e.status),f;try{return await l(d)}catch(e){f=e}if(d===`continue`&&f instanceof S&&f.status===0){let e=await u().catch(()=>void 0);if(!e||ya(e.status)!==`continue`||Ta(e)!==s)throw f;try{return await l(`continue`)}catch(e){f=e}}if(!(f instanceof S)||f.status!==409)throw f;let p=f;for(let e=0;;e+=1){let t;try{t=await u()}catch{throw p}let i=ya(t.status);if(i===d){let t=wa(d,p)?ba[e]:void 0;if(t===void 0)throw p;await r(t);try{return await l(d)}catch(e){if(!wa(d,e))throw e;p=e;continue}}if(i===`live`&&n.trim()===``&&c.length===0)return;if(i===`continue`&&Qe(t)===void 0)throw p;return await l(i)}},[t,s,a,e.id,e.status,o,i,r])}var Da=2e4,Oa=new Map;function ka(e){let t=Oa.get(e);return t||(t={drafts:void 0,sent:[],counter:0,listeners:new Set,chain:Promise.resolve(),timer:void 0,version:0},Oa.set(e,t)),t}function Aa(e){if(e===``)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let n=[];for(let e of t.slice(0,12)){if(typeof e!=`object`||!e)continue;let t=e,r=Oi(t.pick);!r||r.mark===void 0||n.push({key:r.mark,pick:{...r,mark:r.mark},text:typeof t.text==`string`?t.text.slice(0,Da):``})}return n}var ja=e=>e.length===0?``:JSON.stringify(e.map(e=>({pick:e.pick,text:e.text}))),Ma=e=>{try{return new URL(e).pathname}catch{return}};function Na(e){return Pi(e.text.trim(),[{...e.pick,id:e.key}])}function Pa(e,t,n){let r=t.status===`running`,i=!1,a=e.map(e=>{let a=e;return a.phase===`asking`&&r&&(a={...a,phase:`running`,sawRunning:!0}),a.phase===`running`&&(r?a.sawRunning||(a={...a,sawRunning:!0}):(a.sawRunning||n-(a.deliveredAt??n)>Fa)&&(a={...a,phase:t.asking?`asking`:`done`})),a!==e&&(i=!0),a}),o=a.filter(e=>e.phase===`running`||e.phase===`asking`);if(o.length>1){let e=o.reduce((e,t)=>(t.deliveredAt??0)>=(e.deliveredAt??0)?t:e);a=a.map(t=>o.includes(t)&&t!==e?{...t,phase:`done`}:t),i=!0}return i?a:e}var Fa=15e3;function Ia(e){let t=e.id,n=ka(t),r=w(t),i=r.data?.surfaces?.[wi]?.text;(0,Z.useSyncExternalStore)((0,Z.useCallback)(e=>(n.listeners.add(e),()=>n.listeners.delete(e)),[n]),()=>n.version);let a=(0,Z.useCallback)(()=>{n.version++,n.listeners.forEach(e=>e())},[n]);(0,Z.useEffect)(()=>{!r.isSuccess||n.drafts!==void 0||(n.drafts=Aa(typeof i==`string`?i:``),a())},[r.isSuccess,a,n,i]);let o=(0,Z.useCallback)(e=>{clearTimeout(n.timer),n.timer=setTimeout(()=>{let e=ja(n.drafts??[]);e.length>1e5||(n.chain=n.chain.catch(()=>{}).then(()=>ae(t,wi,{text:e,images:[]})).catch(()=>{}))},e)},[t,n]),s=Ea(e,(0,Z.useCallback)(e=>H(t,{text:e}),[t]),{surface:null}),c=(0,Z.useRef)(s);c.current=s;let l=e.status===`waiting`&&e.askParked===!0;(0,Z.useEffect)(()=>{let t=Pa(n.sent,{status:e.status,asking:l},Date.now());t!==n.sent&&(n.sent=t,a())},[l,a,e.status,n,n.version]);let u=(0,Z.useCallback)(e=>n.drafts===void 0?(Y(`Still loading this task — click the element again in a moment.`),!1):e.mark===void 0?!1:n.drafts.length>=12?(Y(`12 notes are already open — send or close some first.`,{tone:`danger`}),!1):(n.drafts=[...n.drafts,{key:e.mark,pick:{...e,mark:e.mark},text:``}],a(),o(0),!0),[o,a,n]),d=(0,Z.useCallback)((e,t)=>{n.drafts?.some(t=>t.key===e)&&(n.drafts=n.drafts.map(n=>n.key===e?{...n,text:t.slice(0,Da)}:n),a(),o(500))},[o,a,n]),f=(0,Z.useCallback)(e=>{n.drafts?.some(t=>t.key===e)&&(n.drafts=n.drafts.filter(t=>t.key!==e),a(),o(0))},[o,a,n]),p=(0,Z.useCallback)(async e=>{let t=n.drafts?.find(t=>t.key===e);if(!t||t.text.trim()===``)return;let r=Na(t);await c.current(r,[]);let i=Date.now();n.counter++,n.sent=[...n.sent,{key:e,pick:t.pick,text:t.text.trim(),number:n.counter,sawRunning:!1,phase:`running`,deliveredAt:i}],n.drafts=(n.drafts??[]).filter(t=>t.key!==e),a(),o(0)},[o,a,n]),m=(0,Z.useMemo)(()=>[...(n.drafts??[]).map(e=>({...e,phase:`draft`})),...n.sent],[n,n.version]);return{notes:m,marks:(0,Z.useMemo)(()=>m.map(e=>e.phase===`draft`?{key:e.key,selector:e.pick.selector,path:Ma(e.pick.url),label:ki(e.pick),draft:!0}:{key:e.key,n:e.number,label:ki(e.pick),draft:!1}),[m]),note:(0,Z.useCallback)(e=>m.find(t=>t.key===e),[m]),addDraft:u,setText:d,discard:f,send:p}}var La=`diff-comments`;function Ra(e){if(e===``)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let t=e;typeof t.id!=`string`||typeof t.path!=`string`||t.side!==`old`&&t.side!==`new`||typeof t.line!=`number`||typeof t.body!=`string`||n.push({id:t.id,path:t.path,side:t.side,line:t.line,body:t.body,excerpt:typeof t.excerpt==`string`?t.excerpt:``,...typeof t.oldPath==`string`&&t.oldPath!==``?{oldPath:t.oldPath}:{},...za(t.start)?{start:{side:t.start.side,line:t.start.line}}:{}})}return n}function za(e){if(typeof e!=`object`||!e)return!1;let t=e;return(t.side===`old`||t.side===`new`)&&typeof t.line==`number`}function Ba(e){return Br(e,e.start)}function Va(e){let t=e=>e.side===`old`?0:1,n=e=>e.start??e;return[...e].sort((e,r)=>e.path.localeCompare(r.path)||t(n(e))-t(n(r))||n(e).line-n(r).line)}var Ha=`Review comments on the diff:`;function Ua(e){return e.length===0?``:`${Ha}\n\n${Va(e).map(e=>{let t=e.side===`old`?`\`${e.oldPath??e.path}\` line ${e.line} (removed line${e.oldPath?`, renamed to \`${e.path}\``:``})`:`\`${e.path}\` line ${e.line}`;return`- ${e.start?Xa(e):t}:\n\n${Qa(Za(e.excerpt))}\n\n${Qa(e.body)}`}).join(`
8
+
9
+ `)}`}var Wa=/^- `([^`]+)` (.+):$/;function Ga(e){let t=e.indexOf(`${Ha}\n\n`);if(t===-1||t>0&&e[t-1]!==`
10
+ `)return;let n=e.slice(0,t).trim(),r=e.slice(t+28+2).split(`
11
+ `),i=[],a=0;for(;a<r.length;){let e=Wa.exec(r[a]??``);if(!e){if((r[a]??``).trim()===``){a++;continue}return}a++;let t=[];for(;a<r.length&&!Wa.test(r[a]??``);)t.push((r[a]??``).replace(/^ {2}/,``)),a++;i.push(Ka(e[1],e[2],t))}return i.length>0?{lead:n,items:i}:void 0}function Ka(e,t,n){let r=/renamed to `([^`]+)`/.exec(t)?.[1],i=/lines? (\d+)/.exec(t),a=t.startsWith(`removed `)||t.includes(`(removed line`)?`old`:`new`,o=n;for(;o[0]?.trim()===``;)o=o.slice(1);let s=``,c=/^(`{3,})\s*$/.exec(o[0]??``);if(c){let e=o.findIndex((e,t)=>t>0&&e.trim()===c[1]);s=o.slice(1,e===-1?void 0:e).join(`
12
+ `),o=e===-1?[]:o.slice(e+1)}else{let e=[];for(;o[0]?.startsWith(`> `);)e.push(o[0].slice(2)),o=o.slice(1);s=e.join(`
13
+ `)}return{path:r??e,label:t,...i?{line:Number(i[1])}:{},side:a,excerpt:s,body:o.join(`
14
+ `).trim()}}function qa(e,t){let n=Ua(t);return n===``?e:e.trim()===``?n:`${e}\n\n${n}`}function Ja(e){return/^\/([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s|$)/.exec(e.trimStart())?.[1]}function Ya(e,t){let n=Ja(e);return n===void 0||(t?.includes(n)??!1)}function Xa(e){let t=e.side===`old`||e.start?.side===`old`,n=e.oldPath&&t?` (removed lines numbered in \`${e.oldPath}\`)`:``;return`\`${e.path}\` ${Ba(e)}${n}`}function Za(e){let t=Math.max(0,...(e.match(/`+/g)??[]).map(e=>e.length)),n="`".repeat(Math.max(3,t+1));return`${n}\n${to(e).split(`
15
+ `).map(e=>e.trimEnd()).join(`
16
+ `)}\n${n}`}function Qa(e){return e.split(`
17
+ `).map(e=>` ${e}`).join(`
18
+ `)}var $a=1e3;function eo(e,t=200){let n=to(e);return n.length<=t?n:`${n.slice(0,t)}…`}function to(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``).replace(/\s+$/,``)}function no(e,t){let n=qa(e,t);if(n.length>1e5)throw Error(`Too long with the ${t.length===1?`diff comment`:`${t.length} diff comments`} attached — shorten the message or remove some comments.`);return n}function ro(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}var io=new WeakMap;function ao(e){let t=io.get(e);return t||(t={lists:new Map,listeners:new Map,chains:new Map,removed:new Map,base:new Map,pending:new Map},io.set(e,t)),t}var oo=[];function so(e){let t=G(),n=ao(t),r=w(e===``?void 0:e),i=r.data?.surfaces?.[La]?.text,a=(0,Z.useMemo)(()=>Ra(typeof i==`string`?i:``),[i]),o=(0,Z.useSyncExternalStore)((0,Z.useCallback)(t=>{let r=n.listeners.get(e)??new Set;return r.add(t),n.listeners.set(e,r),()=>r.delete(t)},[e,n]),()=>n.lists.get(e));(0,Z.useEffect)(()=>{if(!r.isSuccess)return;let t=n.lists.get(e);if(t===void 0){n.lists.set(e,a),n.base.set(e,a),n.listeners.get(e)?.forEach(e=>e());return}if((n.pending.get(e)??0)>0)return;let i=lo(t,a,n.base.get(e)??[],n.removed.get(e));n.base.set(e,a),i!==t&&(n.lists.set(e,i),n.listeners.get(e)?.forEach(e=>e()))},[r.isSuccess,e,a,n]),(0,Z.useEffect)(()=>{if(e===``)return;let n=()=>{document.visibilityState===`visible`&&t.invalidateQueries({queryKey:R.runs.drafts(e)})};return window.addEventListener(`focus`,n),document.addEventListener(`visibilitychange`,n),()=>{window.removeEventListener(`focus`,n),document.removeEventListener(`visibilitychange`,n)}},[t,e]);let s=o??(r.isSuccess?a:oo),c=(0,Z.useCallback)(()=>n.lists.get(e)??a,[e,a,n]),l=(0,Z.useCallback)(r=>{n.lists.set(e,r),n.listeners.get(e)?.forEach(e=>e());let i=co(r);t.setQueryData(R.runs.drafts(e),e=>{let t={...e?.surfaces??{}};return i===``?delete t[La]:t[La]={text:i,images:[],updatedAt:new Date().toISOString()},{surfaces:t}})},[t,e,n]),u=(0,Z.useCallback)((t,r=[])=>{if(co(t).length>1e5)return Y(`Too many comments to keep as a draft — send the ones you have first.`,{tone:`danger`}),!1;if(r.length>0){let t=n.removed.get(e)??new Set;for(let e of r)t.add(e);n.removed.set(e,t)}l(t),n.pending.set(e,(n.pending.get(e)??0)+1);let i=(n.chains.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{let r=n.lists.get(e)??t,i=r;try{let t=(await g(e)).surfaces?.[La]?.text;i=lo(r,Ra(typeof t==`string`?t:``),n.base.get(e)??[],n.removed.get(e))}catch{}i!==r&&l(i);let a=co(i);a.length>1e5||(await ae(e,La,{text:a,images:[]}),n.base.set(e,i))}).catch(()=>{}).finally(()=>{n.pending.set(e,Math.max(0,(n.pending.get(e)??1)-1))});return n.chains.set(e,i),!0},[l,e,n]),d=(0,Z.useCallback)(e=>u([...c(),{...e,body:e.body.slice(0,Vr),excerpt:eo(e.excerpt,e.start?$a:200),id:ro()}]),[c,u]),f=(0,Z.useCallback)((e,t)=>u(c().map(n=>n.id===e?{...n,body:t.slice(0,Vr)}:n)),[c,u]),p=(0,Z.useCallback)(e=>void u(c().filter(t=>t.id!==e),[e]),[c,u]),m=(0,Z.useCallback)(()=>void u([],c().map(e=>e.id)),[c,u]),h=(0,Z.useCallback)(async e=>{let t=c(),n=await e(t);if(t.length>0){let e=new Map(t.map(e=>[e.id,e.body])),n=c();u(n.filter(t=>e.get(t.id)!==t.body),n.filter(t=>e.get(t.id)===t.body).map(e=>e.id))}return n},[c,u]);return{ready:o!==void 0||r.isSuccess,comments:s,add:d,update:f,remove:p,clear:m,submit:h}}function co(e){return e.length===0?``:JSON.stringify(e)}function lo(e,t,n,r){let i=new Map(n.map(e=>[e.id,e])),a=new Map(t.map(e=>[e.id,e])),o=[];for(let t of e){let e=i.get(t.id),n=a.get(t.id);if(e&&!n)continue;let r=!e||e.body!==t.body;o.push(n&&!r?n:t)}let s=new Set(e.map(e=>e.id));for(let e of t)!s.has(e.id)&&!r?.has(e.id)&&o.push(e);return o.length===e.length&&o.every((t,n)=>t===e[n]||JSON.stringify(t)===JSON.stringify(e[n]))?e:o}function uo(e,t=null){let n=d(),r=N(n.data),i=e.runner??`claude`,a=Ue(t,r,i),o=r.includes(i),s=n.isSuccess&&r.length>0,c=n.isPending?`Checking agent providers…`:n.isError?`Provider authentication could not be verified.`:s?void 0:`Connect an agent provider to continue.`;return{runners:r,currentRunner:i,runner:a,currentRunnerConnected:o,canContinue:s,providerPending:n.isPending,providerError:n.isError,reason:c,runnerOverride:t!==null||!o?a:void 0}}function fo(e){let t=G(),n=Ut(e).continueRun,r=O(),[i,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),d=uo(e,i),{runners:f,canContinue:p,currentRunner:m,runner:h}=d,g=a(h,n),_=r.data?.modelsLocked===!0,v=h!==m,y=!_&&!v&&e.model?{...r.data?.defaultModels,[h]:e.model}:r.data?.defaultModels,b=_?null:s,x=Je(h,g.data,[b,y?.[h]]),S=Pt(b,h,y,g.data),{accounts:C,repoAccount:w}=wn(),T=[...e.steps].reverse().find(e=>e.profileId)?.profileId??e.agentProfile??`default`,E=v?w:{...w,[m]:T},D=C.some(e=>e.provider===h&&e.id===l)?l:null,k=U({mutationFn:({text:t,images:n})=>p?H(e.id,{text:t.trim()?t:void 0,images:n.length?n:void 0,runner:d.runnerOverride,model:!_&&s!==null?S:void 0,agentProfile:D??void 0}):Promise.reject(Error(d.reason??`Connect an agent provider to continue.`)),onSuccess:()=>t.invalidateQueries({queryKey:R.runs.all})});return{available:n,canContinue:p,reason:d.reason,providerPending:d.providerPending,pills:(0,Q.jsxs)(`div`,{"data-slot":`follow-up-engine`,className:`flex flex-wrap items-center gap-1.5`,children:[f.length>1||f.some(e=>En(C,e))?(0,Q.jsx)(Zt,{runners:f,value:h,accounts:C,account:D,repoAccount:E,onPick:(e,t)=>{u(t),e!==h&&(o(e),c(null))}}):null,(0,Q.jsx)(_t,{slot:`follow-up-model-pill`,ariaLabel:`Model`,label:x.find(e=>e.id===S)?.label??`auto`,value:S,readOnly:_,disabledHint:`Model selection is locked to native coding-agent settings.`,onPick:e=>c(e),options:x.map(e=>({value:e.id,label:e.label,desc:e.desc})),status:st(h,g.data,g.isError)})]}),continueWith:(e,t)=>k.mutateAsync({text:e,images:t})}}function po({items:e}){let{id:t}=Ce();return(0,Q.jsxs)(`div`,{"data-slot":`review-comments`,className:`mt-1 flex flex-col gap-2 text-left`,children:[(0,Q.jsxs)(`p`,{className:`text-[12px] font-medium text-muted-foreground`,children:[e.length,` `,e.length===1?`comment`:`comments`,` on the diff`]}),e.map((e,n)=>(0,Q.jsxs)(`div`,{"data-slot":`review-comment`,className:`overflow-hidden rounded-lg border border-border bg-background/60`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 border-b border-border/60 px-2.5 py-1.5 text-[12px]`,children:[(0,Q.jsx)(An,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),t?(0,Q.jsx)(Se,{to:mo(t,e),className:`min-w-0 truncate font-mono font-medium text-foreground underline-offset-2 hover:underline`,title:`Open ${e.path} on the Changes tab`,children:e.path}):(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono font-medium`,children:e.path}),(0,Q.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[`· `,e.label]})]}),e.excerpt===``?null:(0,Q.jsx)(`pre`,{"data-slot":`review-comment-code`,className:`max-h-48 overflow-auto border-b border-border/60 bg-muted/40 px-2.5 py-1.5 font-mono text-[12px] leading-[1.6] whitespace-pre text-muted-foreground`,children:e.excerpt}),(0,Q.jsx)(`p`,{"data-slot":`review-comment-body`,className:`px-2.5 py-2 break-words whitespace-pre-wrap text-foreground`,children:e.body})]},n))]})}function mo(e,t){let n=new URLSearchParams({file:t.path,side:t.side});return t.line!==void 0&&n.set(`line`,String(t.line)),t.commentId!==void 0&&n.set(`comment`,t.commentId),`/tasks/${e}/changes?${n.toString()}`}function ho(e){let t=e.get(`file`);if(!t)return;let n=Number(e.get(`line`)),r=e.get(`comment`);return{path:t,side:e.get(`side`)===`old`?`old`:`new`,...Number.isInteger(n)&&n>0?{line:n}:{},...r?{commentId:r}:{}}}function go({runId:e,comments:t,onRemove:n,onOpen:r}){return t.length===0?null:(0,Q.jsx)(zn,{delayDuration:300,children:Va(t).map(t=>{let i=t.path.split(`/`).at(-1)??t.path,a=e=>e===`old`?`−`:`+`,o=`${i} ${t.start&&(t.start.side!==t.side||t.start.line!==t.line)?t.start.side===t.side?`${a(t.side)}${t.start.line}–${t.line}`:`${a(t.start.side)}${t.start.line}–${a(t.side)}${t.line}`:`${a(t.side)}${t.line}`}`,s=Ba(t);return(0,Q.jsxs)(Bn,{children:[(0,Q.jsx)(Ln,{asChild:!0,children:(0,Q.jsxs)(`span`,{"data-slot":`diff-comment-chip`,className:`flex h-8 max-w-[260px] items-center overflow-hidden rounded-md border border-border bg-muted/40 text-xs text-foreground`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex h-full items-center border-r border-border px-2 text-muted-foreground`,children:(0,Q.jsx)(An,{className:`size-3.5`})}),r?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),className:`min-w-0 truncate px-2 font-medium hover:underline`,"aria-label":`Show comment on ${t.path} ${s}`,children:o}):(0,Q.jsx)(Se,{to:mo(e,{path:t.path,side:t.side,line:t.line,commentId:t.id}),className:`min-w-0 truncate px-2 font-medium hover:underline`,"aria-label":`Comment on ${t.path} ${s}`,children:o}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Remove comment on ${i} ${s}`,onClick:()=>n(t.id),className:`flex h-full items-center px-1.5 text-soft-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(hr,{"aria-hidden":`true`,className:`size-3.5`})})]})}),(0,Q.jsx)(Rn,{side:`top`,sideOffset:6,className:`max-w-[320px] text-left`,children:(0,Q.jsxs)(`div`,{"data-slot":`diff-comment-tooltip`,className:`flex flex-col gap-1`,children:[(0,Q.jsxs)(`span`,{className:`font-mono text-[11px] text-contrast-foreground/80`,children:[t.path,` · `,s]}),(0,Q.jsx)(`span`,{className:`line-clamp-6 break-words whitespace-pre-wrap`,children:t.body})]})})]},t.id)})})}function _o({run:e,draft:t,diffComments:n,continueAction:r,getMentionCandidates:i,onSendingChange:a,onOpenComment:o}){let s=e.status===`running`||e.status===`waiting`,c=e.status===`queued`,l=!s&&!c&&r.available,u=l&&r.canContinue,d=Ea(e,r.continueWith),p=n.comments.length>0,m=f(p),h=(0,Z.useMemo)(()=>Array.isArray(m.data)?m.data.map(e=>e.name):void 0,[m.data]),g=qt(e),_=s&&!g.usable,v=l&&!r.canContinue,y=_||v,b=_?g.reason:r.reason,x=u?r.pills:(0,Q.jsxs)(Q.Fragment,{children:[y&&!r.providerPending?(0,Q.jsx)(Se,{to:`/settings/agents#providers`,className:`text-xs font-medium text-foreground underline underline-offset-4`,children:`Configure providers`}):null,(0,Q.jsx)(Ot,{run:e})]}),S=et(e),C=e.status===`running`||e.status===`queued`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Cn,{value:t.text,onValueChange:t.setText,images:t.images,onImagesChange:t.setImages,onSubmit:async(e,r,i)=>{if(i?.quickReply)return d(e,r);a?.(!0);try{return await t.submit(()=>p&&!Ya(e,h)?(Y(`Diff comments kept — /${Ja(e)} is a command, so they go with your next message.`),d(e,r)):n.submit(async t=>d(no(e,t),r)))}finally{a?.(!1)}},draftItems:p?(0,Q.jsx)(go,{runId:e.id,comments:n.comments,onRemove:n.remove,onOpen:o}):void 0,disabled:y||!s&&!c&&!u,disabledReason:y?b:`Session closed — no session to resume.`,footerEnd:x,allowEmptySubmit:u||p,sendAriaLabel:u?`Continue`:`Send`,stop:C?{label:`Stop the run`,onStop:S.request,pending:S.pending}:void 0,placeholder:c?`Add to the prompt — sent when the run starts…`:u?`Continue — add a prompt, or send to just reopen the session…`:e.status===`waiting`?`Reply — / for skills, @ for files…`:`Message the agent — / for skills, @ for files…`,autocompleteSkills:!0,quickReplies:!0,getMentionCandidates:i}),S.dialog]})}function vo({children:e,overlay:t,floating:n=!1,className:r,style:i,ref:a}){return(0,Q.jsxs)(`div`,{ref:a,"data-slot":`thread-dock`,"data-floating":n||void 0,style:i,className:q(`sticky bottom-[var(--kb,0px)] z-10 bg-background px-3 pt-1 pb-2 max-md:border-t max-md:border-border md:px-6 md:pt-1.5 md:pb-4`,n&&`pointer-events-none bg-transparent max-md:border-t-0 [&_[data-slot=composer]]:shadow-lg`,r),children:[t,(0,Q.jsx)(`div`,{className:q(`mx-auto flex w-full max-w-[var(--measure)] flex-col gap-1.5 md:gap-2.5`,n&&`pointer-events-auto`),children:e})]})}function yo({run:e,embedded:t=!1,stateKey:n}){let r=te();j();let i=re(e.id,nt(e.status)),a=He(),[o,s]=(0,Z.useState)(`unified`),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=Wr(n,null),h=(0,Z.useRef)(null),g=so(e.id),{add:_}=g,v=(0,Z.useCallback)(e=>{let t=_(e);return t&&Ct(e.start?`multi_line`:`single_line`),t},[_]),y=g.comments.length,b=Yt(e.id,`composer`),[x,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1);y>0&&!w&&T(!0),w&&y===0&&!b.hasDraft&&!x&&T(!1);let E=y>0||x||w&&b.hasDraft,[D,O]=(0,Z.useState)(0),k=(0,Z.useCallback)(e=>{if(!e){O(0);return}if(O(e.offsetHeight),typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>O(e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),A=(0,Z.useMemo)(()=>{let e=new Map;for(let t of g.comments)e.set(t.path,(e.get(t.path)??0)+1);return e},[g.comments]);G();let ee=U({mutationFn:t=>L(e.id,t),onError:e=>Y(e.message,{tone:`danger`})}),M=i.isError&&i.error instanceof S&&i.error.status===409,N=i.data?.files??xo,P=(0,Z.useDeferredValue)(N,xo),F=P!==N,I=!i.isPending&&!i.isError&&N.length>0,ne=(0,Z.useMemo)(()=>cn(N),[N]),ie=(0,Z.useMemo)(()=>N.some(zr),[N]),R=a?o:`unified`,z=!a||c,B=(0,Z.useCallback)(e=>{let t=h.current;`side`in e&&t?.reveal?t.reveal(e):t?.scrollToPath(e.path)},[]),[V,H]=(0,Z.useState)(null),ae=(0,Z.useCallback)(e=>{h.current&&!F?B(e):H(e)},[F,B]);(0,Z.useEffect)(()=>{if(V===null||F)return;let e=0,t=setInterval(()=>{!h.current&&++e<40||(clearInterval(t),B(V),H(null))},75);return()=>clearInterval(t)},[F,B,V]);let oe=e=>{p(e),ae({path:e})},W=(0,Z.useCallback)(e=>{p(e.path),ae(e)},[ae,p]),[se]=ve(),ce=(0,Z.useMemo)(()=>ho(se),[se]),K=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!ce||!I||F)return;let e=se.toString();if(K.current===e)return;let t=0,n=setInterval(()=>{!h.current&&++t<40||(clearInterval(n),K.current=e,W(ce))},75);return()=>clearInterval(n)},[F,I,W,se,ce]),(0,Q.jsxs)(`div`,{"data-route":`task-changes`,className:q(`flex min-h-full flex-col md:h-full`,t&&`@container`),children:[t?null:(0,Q.jsx)(Wt,{run:e,tab:`changes`}),(0,Q.jsx)(Qn,{branch:e.branch,stat:i.data?.stat,mode:R,wrap:z,preview:u,onModeChange:s,onWrapChange:l,onPreviewChange:ie?d:void 0}),i.data?.repointedHead?(0,Q.jsxs)(`p`,{"data-slot":`repointed-head-note`,className:`border-b px-4 py-2 text-xs text-soft-foreground md:px-6`,children:[`HEAD is on `,(0,Q.jsx)(`code`,{children:i.data.repointedHead.headBranch}),`, not this task's branch`,` `,(0,Q.jsx)(`code`,{children:i.data.repointedHead.taskBranch}),` — showing only what this task changed there.`]}):null,i.isPending?(0,Q.jsx)(`p`,{"data-slot":`changes-loading`,className:`px-4 py-6 text-center text-xs text-soft-foreground md:px-6`,children:`Loading changes…`}):i.isError?(0,Q.jsx)(Fr,{icon:M?(0,Q.jsx)(nr,{}):(0,Q.jsx)(ar,{}),tone:M?`neutral`:`danger`,heading:`h2`,title:M?`No changes to show`:`Could not load the changes`,subtitle:i.error.message}):N.length===0?(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(nr,{}),tone:`neutral`,heading:`h2`,title:`No changes yet`,subtitle:`The worktree matches its base branch. Changes appear here as the agent works.`}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 px-4 py-4 max-md:pb-[calc(1rem_+_var(--changes-dock,0px))] md:px-6 md:py-0`,style:{"--changes-dock":`${E?D:0}px`},children:[(0,Q.jsx)(`aside`,{"data-slot":`changes-tree-pane`,className:q(`hidden w-60 shrink-0 overflow-y-auto overscroll-contain pt-4 pb-[calc(1rem_+_var(--changes-dock,0px))]`,t?`md:@xl:block @4xl:w-72`:`md:block lg:w-72`),children:(0,Q.jsx)(dn,{root:ne,selected:f,onSelect:oe,commentCounts:A})}),(0,Q.jsx)(`div`,{"data-slot":`diff-pane`,"data-diff-scroller":a?``:void 0,className:`min-w-0 flex-1 md:overflow-y-auto md:overscroll-contain`,children:P.length===0?(0,Q.jsxs)(`p`,{"data-slot":`diff-rendering`,className:`px-1 pt-4 text-xs text-soft-foreground`,children:[`Rendering `,N.length.toLocaleString(),` `,N.length===1?`file`:`files`,`…`]}):(0,Q.jsx)(Ur,{files:P,viewRef:h,mode:R,wrap:z,preview:a&&ie&&u,loadFileText:t=>So(e.id,t),imageSrc:t=>m(e.id,t),onOpenInApp:r.data?.capabilities.localHandoff?e=>ee.mutate(e):void 0,comments:g.comments,onAddComment:g.ready?v:void 0,onEditComment:g.update,onRemoveComment:g.remove,className:`min-w-0 md:pt-4 md:pb-[calc(1rem_+_var(--changes-dock,0px))] [&_[data-slot=diff-comment-editor]]:scroll-mb-[var(--changes-dock,0px)] [&_[data-slot=diff-line-comment]]:scroll-mb-[var(--changes-dock,0px)] [&_[data-slot=diff-line]]:scroll-mb-[var(--changes-dock,0px)]`},e.id)})]}),E?(0,Q.jsx)(vo,{ref:k,floating:!0,className:`mt-auto`,style:{marginTop:I&&D?-D:void 0},children:(0,Q.jsx)(bo,{run:e,draft:b,diffComments:g,onSendingChange:C,onOpenComment:e=>W({path:e.path,side:e.side,line:e.line,commentId:e.id}),getMentionCandidates:()=>N.map(e=>e.path)})}):null]})}function bo(e){let t=fo(e.run);return je(),(0,Q.jsx)(_o,{...e,continueAction:t})}var xo=[];async function So(e,t){try{let n=await ue(e,t);return n.type!==`file`||n.binary||n.tooLarge?null:n.content??null}catch{return null}}function Co({runId:e,selected:t,onSelect:n}){return(0,Q.jsx)(`nav`,{"data-slot":`files-tree`,"aria-label":`Worktree files`,className:`min-w-0 text-[13px]`,children:(0,Q.jsx)(`ul`,{className:`flex flex-col gap-px`,children:(0,Q.jsx)(wo,{runId:e,path:``,depth:0,selected:t,onSelect:n})})})}function wo({runId:e,path:t,depth:n,selected:r,onSelect:i}){let a=oe(e,t);return a.isPending?(0,Q.jsx)(`li`,{"data-slot":`files-tree-loading`,className:`px-1.5 py-1 text-xs text-soft-foreground`,style:{paddingLeft:`${24+n*14}px`},children:`Loading…`}):a.isError?(0,Q.jsx)(`li`,{"data-slot":`files-tree-error`,className:`px-1.5 py-1 text-xs text-danger`,style:{paddingLeft:`${24+n*14}px`},children:a.error.message}):a.data.type===`dir`?a.data.entries.length===0?(0,Q.jsx)(`li`,{"data-slot":`files-tree-empty`,className:`px-1.5 py-1 text-xs text-soft-foreground`,style:{paddingLeft:`${24+n*14}px`},children:`Empty directory`}):(0,Q.jsx)(Q.Fragment,{children:a.data.entries.map(a=>a.type===`dir`?(0,Q.jsx)(To,{runId:e,name:a.name,path:t===``?a.name:`${t}/${a.name}`,depth:n,selected:r,onSelect:i},a.name):(0,Q.jsx)(Eo,{name:a.name,path:t===``?a.name:`${t}/${a.name}`,size:a.size,depth:n,selected:r,onSelect:i},a.name))}):null}function To({runId:e,name:t,path:n,depth:r,selected:i,onSelect:a}){let[o,s]=(0,Z.useState)(!1);return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`files-dir`,"data-path":n,"data-state":o?`open`:`closed`,"aria-expanded":o,onClick:()=>s(e=>!e),className:`flex w-full min-w-0 items-center gap-1.5 rounded-sm px-1.5 py-1 text-left text-muted-foreground hover:bg-muted hover:text-foreground`,style:{paddingLeft:`${6+r*14}px`},children:[(0,Q.jsx)(Vn,{"aria-hidden":`true`,className:q(`size-3.5 shrink-0 transition-transform`,o&&`rotate-90`)}),(0,Q.jsx)($n,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:t})]}),o?(0,Q.jsx)(`ul`,{className:`flex flex-col gap-px`,children:(0,Q.jsx)(wo,{runId:e,path:n,depth:r+1,selected:i,onSelect:a})}):null]})}function Eo({name:e,path:t,size:n,depth:r,selected:i,onSelect:a}){let o=i===t,s=fn(t)?sn:An;return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`files-file`,"data-path":t,"aria-current":o?`true`:void 0,onClick:()=>a(t),className:q(`flex w-full min-w-0 items-center gap-1.5 rounded-sm px-1.5 py-1 text-left hover:bg-muted`,o?`bg-muted font-medium text-foreground`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${24+r*14}px`},children:[(0,Q.jsx)(s,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),n===void 0?null:(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 font-mono text-[11px] tabular-nums text-soft-foreground`,children:un(n)})]})})}function Do({run:e,embedded:t=!1,stateKey:n}){let r=oe(e.id,``),[i,a]=Wr(n,null),o=He(),s=r.isError&&r.error instanceof S&&r.error.status===409;return(0,Q.jsxs)(`div`,{"data-route":`task-files`,className:q(`flex min-h-full flex-col md:h-full`,t&&`@container`),children:[t?null:(0,Q.jsx)(Wt,{run:e,tab:`files`}),r.isPending?(0,Q.jsx)(`p`,{"data-slot":`files-loading`,className:`px-4 py-6 text-center text-xs text-soft-foreground md:px-6`,children:`Loading files…`}):r.isError?(0,Q.jsx)(Fr,{icon:s?(0,Q.jsx)(ln,{}):(0,Q.jsx)(sr,{}),tone:s?`neutral`:`danger`,heading:`h2`,title:s?`No files to browse`:`Could not load the files`,subtitle:r.error.message}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-5 px-4 py-4 md:flex-row md:px-6 md:py-0`,children:[(0,Q.jsx)(`aside`,{"data-slot":`files-tree-pane`,className:q(`w-full shrink-0 md:overflow-y-auto md:overscroll-contain md:py-4`,t?`md:w-44 @xl:w-60 @4xl:w-72`:`md:w-60 lg:w-72`),children:(0,Q.jsx)(Co,{runId:e.id,selected:i,onSelect:a})}),(0,Q.jsx)(`div`,{"data-slot":`file-preview-pane`,...o?{role:`region`,"aria-label":`File preview`,tabIndex:0}:{},className:`min-w-0 flex-1 md:overflow-y-auto md:overscroll-contain`,children:(0,Q.jsx)(`div`,{className:`md:py-4`,children:(0,Q.jsx)(mn,{source:{kind:`run`,runId:e.id},path:i,className:`min-w-0`})})})]})]})}var Oo=2e3;function ko(e){let t=0,n=0;for(let r of e)typeof r.seq==`number`&&(r.type===`session.ended`&&r.seq>t&&(t=r.seq),(r.type===`session.started`||r.type===`step-start`&&r.kind===`agent`)&&r.seq>n&&(n=r.seq));return{lastEnd:t,lastStart:n}}function Ao(e){let{lastEnd:t,lastStart:n}=ko(e);return t>n?t:0}function jo(e){let{lastEnd:t,lastStart:n}=ko(e);return n>t?n:0}function Mo(e,t){let n=G(),r=(0,Z.useMemo)(()=>Ao(t),[t]),i=(0,Z.useMemo)(()=>jo(t),[t]),a=e?.id,o=e?.status;(0,Z.useEffect)(()=>{if(a===void 0||o===void 0||o===`queued`||!(o===`running`||o===`waiting`?r>0:i>0))return;let e=setTimeout(()=>{n.invalidateQueries({queryKey:R.runs.detail(a)}),n.invalidateQueries({queryKey:R.runs.list()})},Oo);return()=>clearTimeout(e)},[r,i,a,o,n])}function No({run:e}){let t=G(),n=U({mutationFn:()=>I(e.id),onSuccess:()=>{t.invalidateQueries({queryKey:R.runs.detail(e.id)}),t.invalidateQueries({queryKey:R.runs.list()}),Y(`This task will not resume itself`)},onError:e=>Y(e.message,{tone:`danger`})});if(e.status!==`failed`||!e.autoResumeAt)return null;let r=new Date(e.autoResumeAt);if(!Number.isFinite(r.getTime()))return null;let i=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`long`}).format(r);return(0,Q.jsxs)(`div`,{"data-slot":`auto-resume-hint`,role:`status`,className:`flex flex-wrap items-center gap-x-2 gap-y-1 px-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(jr,{tone:`pending`,pulse:!0}),(0,Q.jsxs)(`span`,{children:[`Usage limit reached — this task resumes automatically at`,` `,(0,Q.jsx)(`time`,{dateTime:e.autoResumeAt,className:`font-medium text-foreground`,children:i})]}),(0,Q.jsx)(`button`,{type:`button`,"data-action":`auto-resume-cancel`,disabled:n.isPending,onClick:()=>n.mutate(),className:`font-medium text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground disabled:opacity-50`,children:`Don’t resume`}),(0,Q.jsx)(be,{to:`/settings/global/resources`,"data-slot":`auto-resume-settings-link`,className:`font-medium text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground`,children:`Auto-resume settings`})]})}function Po({run:e}){let t=e.status===`done`||e.status===`review`||e.status===`failed`||e.status===`cancelled`;return e.workflow!==`e2e-setup`||!t?null:(0,Q.jsx)(Fo,{run:e})}function Fo({run:e}){let t=!!E().data?.configFile,n=e.status===`done`||e.status===`review`,r=e.steps.find(e=>e.status===`failed`&&e.id!==`pr`),i=e.pullRequestUrl&&/^https?:\/\//.test(e.pullRequestUrl)?e.pullRequestUrl:void 0,a=(0,Q.jsx)(Se,{className:`font-medium underline underline-offset-2`,to:`/settings/integrations`,children:`Settings → External integrations`});return(0,Q.jsxs)(`div`,{"data-slot":`e2e-setup-verdict`,"data-verdict":n?`works`:`not-working`,role:`status`,className:q(`mt-4 flex gap-3 rounded-lg border p-4 text-sm`,n?`border-success/40 bg-success/5`:`border-danger/40 bg-danger/5`),children:[n?(0,Q.jsx)(Hn,{className:`mt-0.5 size-5 shrink-0 text-success`,"aria-hidden":!0}):(0,Q.jsx)(Ne,{className:`mt-0.5 size-5 shrink-0 text-danger`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`font-semibold`,children:n?`e2e works`:e.status===`cancelled`?`e2e is not set up — the setup was cancelled`:`e2e is not working yet`}),n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`The config loads and the smoke test passed in a real browser.`}),(0,Q.jsx)(`p`,{className:`mt-1`,children:t?(0,Q.jsxs)(Q.Fragment,{children:[`It is live in this project: pick the `,(0,Q.jsx)(`code`,{children:`implement-and-e2e`}),` workflow for your next task.`]}):i?(0,Q.jsxs)(Q.Fragment,{children:[`One step left: merge the `,(0,Q.jsx)(`a`,{className:`font-medium underline underline-offset-2`,href:i,target:`_blank`,rel:`noreferrer`,children:`draft PR`}),`. Then pick the `,(0,Q.jsx)(`code`,{children:`implement-and-e2e`}),` workflow for your next task.`]}):(0,Q.jsxs)(Q.Fragment,{children:[`One step left: merge branch `,(0,Q.jsx)(`code`,{children:e.branch??`of this task`}),` (or open a draft PR from the header). Then pick the `,(0,Q.jsx)(`code`,{children:`implement-and-e2e`}),` workflow for your next task.`]})})]}):e.status===`cancelled`?(0,Q.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Start it again from `,a,`.`]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[`“`,r.name,`” did not pass — its output is above.`]}):`The setup stopped before it could prove e2e works — the reason is above.`}),(0,Q.jsxs)(`p`,{className:`mt-1`,children:[`Continue this task to fix it, or set it up again from `,a,`.`]})]})]})]})}var Io=e=>e.kind===`tool`,Lo=e=>(e.toolKind===`read`||e.toolKind===`search`)&&e.status===`completed`,Ro=(e,t,n)=>`${e} ${e===1?t:n}`;function zo(e,t){let n=[];return e>0&&n.push(Ro(e,`file`,`files`)),t>0&&n.push(Ro(t,`search`,`searches`)),`Explored ${n.join(` · `)}`}function Bo(e){return`${e} earlier tool call${e===1?``:`s`}`}var Vo=[`Web search`,`Ran`,`Edit`,`Write`,`Read`,`Search`,`Fetch`,`Task:`,`Skill:`];function Ho(e){for(let t of Vo)if(e.startsWith(`${t} `)&&e.length>t.length+1)return{verb:t.endsWith(`:`)?t.slice(0,-1):t,detail:e.slice(t.length+1)};return{verb:e}}function Uo(e){let t=e.filter(e=>!(e.kind===`tool`&&e.toolKind===`plan`)&&!(e.kind===`reasoning`&&e.text.trim()===``)),n=new Set(t.filter(Io).map(e=>e.id)),r=new Map,i=[];for(let e of t){let t=(e.kind===`message`||e.kind===`reasoning`||e.kind===`tool`)&&e.parentItemId!==void 0&&e.parentItemId!==e.id&&n.has(e.parentItemId)?e.parentItemId:void 0;if(t===void 0)i.push(e);else{let n=r.get(t);n?n.push(e):r.set(t,[e])}}let a=[],o=[],s=()=>{if(o.length>=2){let e=o.filter(e=>e.toolKind===`read`).length;a.push({kind:`context-group`,id:`group:${o[0].id}`,tools:o,files:e,searches:o.length-e,label:zo(e,o.length-e)})}else for(let e of o)a.push({kind:`tool-card`,id:e.id,item:e,children:r.get(e.id)??[]});o=[]};for(let e of i)Io(e)&&Lo(e)&&!r.has(e.id)?o.push(e):(s(),Io(e)?a.push({kind:`tool-card`,id:e.id,item:e,children:r.get(e.id)??[]}):a.push({kind:`entry`,id:e.id,entry:e}));s();let c=e=>e.kind===`context-group`||e.kind===`tool-card`&&e.item.status===`completed`,l=e=>e.kind===`context-group`?e.tools.length:1,u=[],d=[],f=()=>{if(d.length>3){let e=d.slice(0,d.length-3);u.push({kind:`streak`,id:`streak:${e[0].id}`,count:e.reduce((e,t)=>e+l(t),0),blocks:e}),u.push(...d.slice(d.length-3))}else u.push(...d);d=[]};for(let e of a)c(e)?d.push(e):(f(),u.push(e));return f(),u}var Wo=new Map,Go=(0,Z.createContext)(null);function Ko(){return(0,Z.useContext)(Go)}function qo({runId:e,children:t}){let n=(0,Z.useMemo)(()=>({get:t=>Wo.get(e)?.get(t),set:(t,n)=>{let r=Wo.get(e)??new Map;r.set(t,n),Wo.set(e,r)}}),[e]);return(0,Q.jsx)(Go.Provider,{value:n,children:t})}function Jo(e){let t=`flex w-full flex-col pb-2.5`;return e?`${t} [contain-intrinsic-block-size:auto_3rem] [content-visibility:auto]`:t}function Yo(e){return e.scrollTop<Math.max(600,e.clientHeight)}function Xo(e,t){let n=t.find(({bottom:t})=>t>e);return n===void 0?void 0:{key:n.key,offset:n.top-e}}function Zo(e,t,n,r,i){if(n===void 0)return i;let a=r.find(({key:e})=>e===n.key);return a===void 0?i:e+(a.top-t-n.offset)}function Qo(e,t=24){return e.scrollHeight-e.scrollTop-e.clientHeight<t}function $o(e,t){let n=new URLSearchParams(e).get(`thread`);return n===`flat`||n===`virtual`?n:t>300?`virtual`:`flat`}var es=new Map;function ts(e,t){es.set(e,t)}function ns(e){return es.get(e)}var rs=new Map;function is(e,t){rs.set(e,t)}function as(e,t){let n=rs.get(e);return n!==void 0&&n.rows===t?n.cache:void 0}var os=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}),ss=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`medium`}),cs=new Intl.DateTimeFormat(void 0,{weekday:`short`,month:`short`,day:`numeric`}),ls=new Intl.DateTimeFormat(void 0,{weekday:`short`,year:`numeric`,month:`short`,day:`numeric`}),us=new Intl.DateTimeFormat(void 0,{dateStyle:`full`});function ds(e){if(typeof e!=`string`||e===``)return;let t=new Date(e);return Number.isFinite(t.getTime())?t:void 0}function fs(e){let t=ds(e);return t===void 0?void 0:os.format(t)}function ps(e){let t=ds(e);return t===void 0?void 0:ss.format(t)}var ms=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;function hs(e){let t=ds(e);return t===void 0?void 0:ms(t)}function gs(e,t=new Date){let n=ds(e);if(n===void 0)return;let r=ms(n);return r===ms(t)?`Today`:r===ms(new Date(t.getFullYear(),t.getMonth(),t.getDate()-1))?`Yesterday`:(n.getFullYear()===t.getFullYear()?cs:ls).format(n)}function _s(e,t){let n=ds(e),r=ds(t);if(!(n===void 0||r===void 0))return ys(Math.round((r.getTime()-n.getTime())/1e3))}function vs(e,t){let n=ds(e);if(n!==void 0)return ys(Math.floor((t-n.getTime())/1e3))}function ys(e){if(e<0)return;if(e<60)return`${e}s`;let t=Math.floor(e/60);return t<60?`${t}m ${String(e%60).padStart(2,`0`)}s`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,`0`)}m`}function bs(e=1e3){let[t,n]=(0,Z.useState)(()=>Date.now());return(0,Z.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function xs({ts:e}){let t=fs(e);return t===void 0?null:(0,Q.jsx)(`time`,{"data-slot":`message-time`,dateTime:e,title:ps(e),className:`text-[11px] leading-none text-soft-foreground`,children:t})}function Ss({startedAt:e,completedAt:t}){let n=fs(t);if(n===void 0)return null;let r=_s(e,t);return(0,Q.jsxs)(`div`,{"data-slot":`turn-time`,className:`flex items-center gap-1.5 px-0.5 text-[11px] leading-none text-soft-foreground`,children:[(0,Q.jsx)(`time`,{dateTime:t,title:ps(t),children:n}),r===void 0?null:(0,Q.jsxs)(`span`,{title:`Replied in ${r}`,children:[`· `,r]})]})}function Cs({ts:e}){let t=gs(e),n=ds(e);if(t===void 0||n===void 0)return null;let r=us.format(n);return(0,Q.jsxs)(`div`,{"data-slot":`day-separator`,role:`separator`,"aria-label":t===`Today`||t===`Yesterday`?`${t}, ${r}`:r,className:`flex items-center gap-3 py-1 text-[11px] font-medium text-soft-foreground`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`}),(0,Q.jsx)(`time`,{dateTime:hs(e),title:r,children:t}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`})]})}function ws({text:e,imageCount:t=0,images:n=[],ts:r,onEdit:i,onRemove:a,editLabel:o=`Edit message`,removeLabel:s=`Remove message`,draftRunId:c,draftSurface:l}){let u=t-n.length,[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(e),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(),y=Yt(c??``,l??``,{enabled:i!==void 0&&c!==void 0&&l!==void 0}),b=`${c??``} ${l??``}`,[x,S]=(0,Z.useState)(b);x!==b&&(S(b),f(!1),m(e),v(void 0)),(0,Z.useEffect)(()=>{d||!y.ready||!y.hasDraft||(m(y.text),v(void 0),f(!0))},[d,y.hasDraft,y.ready,y.text]);let C=e=>{m(e),y.setText(e)},w=()=>{m(e),v(void 0),f(!0)},T=async()=>{let t=p.trim();if(!t||t===e){y.clear(),f(!1);return}g(!0),v(void 0);try{await y.submit(()=>i?.(t)??Promise.resolve()),f(!1)}catch(e){v(e instanceof Error?e.message:`Could not save the message`)}finally{g(!1)}},E=()=>{y.clear(),f(!1)},D=async()=>{g(!0),v(void 0);try{await a?.(),y.clear()}catch(e){v(e instanceof Error?e.message:`Could not remove the message`)}finally{g(!1)}};return d?(0,Q.jsxs)(`div`,{"data-slot":`user-bubble`,"data-editing":`true`,className:`max-w-[78%] self-end rounded-2xl rounded-br-md bg-muted px-[15px] py-2.5 text-[13.5px] leading-[1.55] md:max-w-[70%]`,children:[(0,Q.jsx)(`textarea`,{autoFocus:!0,"aria-label":`Edit the message`,value:p,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.stopPropagation(),E()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),T())},className:`block max-h-[220px] min-h-[60px] w-full resize-none rounded-md bg-background px-2 py-1.5 text-[13.5px] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`}),(0,Q.jsxs)(`span`,{className:`mt-1.5 flex justify-end gap-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:E,disabled:h,className:`rounded-sm px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-background hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`,children:`Cancel`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void T(),disabled:h,className:`rounded-sm bg-primary px-2 py-1 text-xs font-semibold text-primary-foreground hover:brightness-[0.96] focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`,children:h?(0,Q.jsx)(cr,{className:`size-3.5 animate-spin`}):`Save`})]}),_?(0,Q.jsx)(`p`,{role:`alert`,className:`mt-1.5 text-xs text-danger`,children:_}):null]}):(0,Q.jsxs)(`div`,{"data-slot":`user-bubble`,className:`group max-w-[78%] min-w-0 self-end rounded-2xl rounded-br-md bg-muted px-[15px] py-2.5 text-[13.5px] leading-[1.55] md:max-w-[70%]`,children:[i||a?(0,Q.jsxs)(`span`,{"data-slot":`bubble-actions`,className:`mb-1 flex justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100`,children:[i?(0,Q.jsx)(`button`,{type:`button`,"aria-label":o,onClick:w,disabled:h,className:`rounded-sm p-1 text-soft-foreground hover:bg-background hover:text-foreground focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`,children:(0,Q.jsx)(li,{className:`size-3.5`})}):null,a?(0,Q.jsx)(`button`,{type:`button`,"aria-label":s,onClick:()=>void D(),disabled:h,className:`rounded-sm p-1 text-soft-foreground hover:bg-background hover:text-danger focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`,children:(0,Q.jsx)(Nn,{className:`size-3.5`})}):null]}):null,_?(0,Q.jsx)(`p`,{role:`alert`,className:`mb-1 text-xs text-danger`,children:_}):null,(0,Q.jsx)(Ts,{text:e}),n.length>0?(0,Q.jsx)(`span`,{"data-slot":`user-images`,className:`mt-2 flex flex-wrap items-center justify-end gap-1.5`,children:n.map(e=>he(e.split(`/`).pop()??``)?(0,Q.jsx)(Lr,{src:e,alt:`attached`,className:`max-h-40 max-w-[220px] rounded-md border border-border object-contain`},e):(0,Q.jsxs)(`a`,{href:e,download:!0,"data-slot":`user-file`,className:`inline-flex max-w-[220px] items-center gap-1.5 rounded-md border border-border bg-background/60 px-2 py-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(xn,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.split(`/`).pop()})]},e))}):null,u>0?(0,Q.jsxs)(`span`,{className:`mt-1 block text-xs text-soft-foreground`,children:[u,` image`,u>1?`s`:``,` attached`]}):null,r===void 0?null:(0,Q.jsx)(`span`,{className:`mt-1 flex justify-end`,children:(0,Q.jsx)(xs,{ts:r})})]})}function Ts({text:e}){let t=(0,Z.useMemo)(()=>Ga(e),[e]);return t?(0,Q.jsxs)(Q.Fragment,{children:[t.lead===``?null:(0,Q.jsx)(Ir,{breaks:!0,children:t.lead}),(0,Q.jsx)(po,{items:t.items})]}):(0,Q.jsx)(Ir,{breaks:!0,children:e})}function Es({text:e}){return(0,Q.jsx)(`div`,{"data-slot":`assistant-message`,className:`min-w-0 text-[15px] leading-[1.65]`,children:(0,Q.jsx)(Ir,{children:e})})}function Ds({note:e}){return(0,Q.jsxs)(`div`,{"data-slot":`note-line`,"data-tone":e.tone,className:q(`px-0.5 text-xs`,e.tone===`danger`?`text-danger`:`text-soft-foreground`),children:[e.tone===`danger`?`✗ `:`· `,e.text]})}var Os={claude:`Claude Code`,codex:`Codex`,junie:`Junie`,opencode:`OpenCode`,cursor:`Cursor`,pi:`pi`,copilot:`GitHub Copilot CLI`};function ks({incident:e}){if(e.profileId!==void 0)return(0,Q.jsx)(As,{incident:e,profileId:e.profileId});let t=Os[e.provider];return(0,Q.jsxs)(`div`,{role:`alert`,"data-slot":`provider-auth-required`,className:`rounded-md border border-danger/30 bg-danger/5 px-3.5 py-3`,children:[(0,Q.jsxs)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:[`This run needed `,t,` authorization`]}),(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Review `,t,` settings before retrying.`]}),(0,Q.jsx)(Se,{to:`/settings/agents#providers`,className:`mt-2 inline-flex text-xs font-medium text-foreground underline-offset-2 hover:underline`,children:`Open provider settings`})]})}function As({incident:e,profileId:t}){let n=V(),r=Os[e.provider];return(0,Q.jsxs)(`div`,{role:`alert`,"data-slot":`provider-auth-required`,"data-profile-id":t,className:`rounded-md border border-danger/30 bg-danger/5 px-3.5 py-3`,children:[(0,Q.jsxs)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:[`This run needed `,r,` account “`,n.data?.profiles.find(n=>n.id===t&&n.provider===e.provider)?.label??t,`” to be signed in`]}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Sign that account in again before retrying.`}),(0,Q.jsx)(be,{to:`/settings/global/accounts`,className:`mt-2 inline-flex text-xs font-medium text-foreground underline-offset-2 hover:underline`,children:`Open agent accounts`})]})}var js=new Set([`claude`,`opencode`,`cursor`]);function Ms({incident:e}){let t=Os[e.provider],[n,r]=(0,Z.useState)(null),i=U({mutationFn:()=>B(e.provider),onSuccess:()=>{r(null),Y(`Updating ${t} in a terminal. Continue the task once it finishes.`)},onError:e=>r({message:e.message,command:e instanceof S?e.command:void 0})}),a=async e=>{try{await navigator.clipboard.writeText(e),Y(`Command copied`)}catch{Y(`Could not copy the command`,{tone:`danger`})}};return(0,Q.jsxs)(`div`,{role:`alert`,"data-slot":`agent-update-required`,className:`rounded-md border border-danger/30 bg-danger/5 px-3.5 py-3`,children:[(0,Q.jsxs)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:[t,` needs an update`]}),js.has(e.provider)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Update it, then continue the task.`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,className:`mt-2`,disabled:i.isPending,onClick:()=>i.mutate(),children:[`Update `,t]})]}):(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Update it the way you installed it, then continue the task.`}),n?(0,Q.jsxs)(`div`,{"data-slot":`agent-update-manual`,className:`mt-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`p`,{children:n.message}),n.command?(0,Q.jsxs)(`div`,{className:`mt-1 flex items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-foreground`,children:n.command}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(n.command),children:`Copy`})]}):null]}):null]})}function Ns({text:e}){let t=(0,Z.useId)();if(e.trim()===``)return null;let n=e.split(`
19
+ `,1)[0]??``,r=n.length<e.length;return(0,Q.jsxs)(vr,{"data-slot":`reasoning`,className:`group/reasoning min-w-0`,children:[(0,Q.jsxs)(`div`,{id:t,className:`relative flex w-full items-center gap-1.5 rounded-md p-0.5 text-left text-[13px] text-soft-foreground hover:text-muted-foreground`,children:[(0,Q.jsx)(Vn,{"aria-hidden":!0,className:`size-3.5 shrink-0 transition-transform group-data-[state=open]/reasoning:rotate-90`}),(0,Q.jsx)(`span`,{className:`shrink-0`,children:`Thinking — `}),(0,Q.jsx)(`div`,{className:`min-w-0 truncate text-muted-foreground`,children:(0,Q.jsx)(Ir,{inline:!0,children:n})}),r?(0,Q.jsx)(`span`,{"aria-hidden":!0,children:`…`}):null,(0,Q.jsx)(_r,{"aria-labelledby":t,className:`absolute inset-0 rounded-md focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`})]}),(0,Q.jsx)(gr,{children:(0,Q.jsx)(`div`,{className:`px-6 py-1.5 text-[13px] leading-[1.6] text-soft-foreground`,children:(0,Q.jsx)(Ir,{children:e})})})]})}function Ps({since:e,lastActivityAt:t}={}){let n=bs(),r=vs(e,n),i=vs(t,n),a=fs(t);return(0,Q.jsxs)(`div`,{"data-slot":`working-indicator`,className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 py-1 text-[13px] text-soft-foreground`,children:[(0,Q.jsx)(cr,{role:`status`,"aria-label":`Working`,className:`size-3.5 shrink-0 animate-spin`}),(0,Q.jsx)(`span`,{className:`shimmer font-medium`,children:`Working…`}),r===void 0?null:(0,Q.jsx)(`span`,{"data-slot":`working-elapsed`,title:`Started ${ps(e)}`,className:`font-mono text-xs tabular-nums`,children:r}),i!==void 0&&a!==void 0?(0,Q.jsxs)(`span`,{"data-slot":`working-last-activity`,title:ps(t),className:`text-xs`,children:[`· last activity `,a,` (`,i,` ago)`]}):null]})}var Fs={read:ir,edit:li,delete:Nn,move:ai,search:Me,execute:rn,think:ri,fetch:Ye,task:jn,skill:bt,plan:oi,other:er},Is=e=>e.split(`
20
+ `).length;function Ls({text:e,streaming:t}){let[n,r]=(0,Z.useState)(!1),i=(0,Z.useRef)(null),a=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>{let e=i.current;t&&e&&a.current&&(e.scrollTop=e.scrollHeight)},[e,t]);let o=Is(e),s=!t&&!n&&o>12;return(0,Q.jsxs)(`div`,{"data-slot":`tool-output`,"data-clamped":s?`true`:void 0,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{ref:i,onScroll:t?e=>{a.current=Qo(e.currentTarget)}:void 0,className:q(`overflow-x-auto`,t&&`max-h-[216px] overflow-y-auto`,s&&`max-h-[216px] overflow-y-hidden`),children:(0,Q.jsx)(`pre`,{className:`px-4 py-3 font-mono text-xs leading-[1.7] whitespace-pre text-muted-foreground`,children:e})}),s?(0,Q.jsx)(`div`,{"data-slot":`tool-output-fade`,"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 bottom-0 h-14 bg-gradient-to-b from-transparent to-card-2`}):null]}),!t&&o>12?(0,Q.jsx)(`button`,{type:`button`,"data-slot":`tool-output-toggle`,onClick:()=>r(e=>!e),className:`block w-full border-t border-border/50 px-4 py-1.5 text-left text-[11px] font-medium text-soft-foreground hover:text-foreground`,children:n?`Show less`:`Show all ${o} lines`}):null]})}function Rs({diffs:e}){return(0,Q.jsx)(Q.Fragment,{children:e.map((e,t)=>(0,Q.jsxs)(`div`,{"data-slot":`diff-preview`,className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`border-b border-border/50 px-4 py-1.5 font-mono text-[11px] text-soft-foreground`,children:e.path}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto py-2 font-mono text-xs leading-[1.7] whitespace-pre`,children:e.unified===void 0?[...zs(e.oldText).map((e,t)=>(0,Q.jsxs)(`span`,{className:`block bg-diff-del px-4 text-muted-foreground`,children:[`- `,e]},`old-${t}`)),...zs(e.newText).map((e,t)=>(0,Q.jsxs)(`span`,{className:`block bg-diff-add px-4`,children:[`+ `,e]},`new-${t}`))]:e.unified.split(`
21
+ `).map((e,t)=>(0,Q.jsx)(Bs,{text:e},t))})]},`${e.path}:${t}`))})}function zs(e){return e==null||e===``?[]:e.replace(/\n$/,``).split(`
22
+ `)}function Bs({text:e}){return(0,Q.jsx)(`span`,{className:q(`block px-4`,e.startsWith(`+`)&&`bg-diff-add`,e.startsWith(`-`)&&`bg-diff-del text-muted-foreground`,e.startsWith(`@@`)&&`text-soft-foreground`),children:e})}function Vs(e){if(e.toolKind!==`execute`)return;let t=e.input,n=typeof t==`object`&&t&&`command`in t?t.command:void 0,r=typeof n==`string`?n:Array.isArray(n)&&n.every(e=>typeof e==`string`)?n.join(` `):Ho(e.title).detail;return r!==void 0&&r.trim()!==``?r:void 0}function Hs({command:e}){let[t,n]=(0,Z.useState)(!1);return(0,Q.jsx)(`button`,{type:`button`,"aria-label":t?`Copied`:`Copy command`,onClick:()=>{navigator.clipboard?.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)})},className:`mt-[3px] mr-1.5 shrink-0 rounded p-1 text-soft-foreground hover:bg-muted hover:text-foreground`,children:t?(0,Q.jsx)(Fn,{"aria-hidden":!0,className:`size-3.5`}):(0,Q.jsx)(We,{"aria-hidden":!0,className:`size-3.5`})})}function Us(e){return e.toolKind===`execute`&&e.status===`running`&&e.output!==void 0}function Ws({item:e,nested:t=[],cacheKey:n,renderNested:r}){let i=Ko(),[a,o]=(0,Z.useState)(()=>n===void 0?null:i?.get(n)??null),s=e=>{n!==void 0&&i?.set(n,e),o(e)},c=e.status===`running`||e.status===`pending`,l=Vs(e),{verb:u,detail:d}=Ho(e.title),f=l!==void 0&&(l!==d||l.includes(`
23
+ `)||l.length>80),p=l!==void 0&&f,m=f||e.output!==void 0&&e.output!==``||e.error!==void 0&&e.error!==``||e.diffs!==void 0&&e.diffs.length>0||t.length>0,h=m&&(a??Us(e)),g=h&&p?l:void 0,_=Fs[e.toolKind]??er;return(0,Q.jsxs)(vr,{"data-slot":`tool-card`,"data-status":e.status,"data-kind":e.toolKind,open:h,onOpenChange:s,className:q(`min-w-0 overflow-hidden rounded-md border bg-card`,e.status===`failed`?`border-danger/25`:`border-border`),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start`,children:[(0,Q.jsxs)(_r,{disabled:!m,className:q(`group flex min-h-[28px] w-full min-w-0 gap-1.5 px-2.5 py-0.5 text-left text-[13px] enabled:hover:bg-muted`,g===void 0?`items-center`:`items-start [&>svg]:mt-[7px] [&>span]:mt-[2px]`),children:[(0,Q.jsx)(Vn,{"aria-hidden":!0,className:q(`size-3 shrink-0 text-soft-foreground transition-transform group-data-[state=open]:rotate-90`,!m&&`invisible`)}),(0,Q.jsx)(_,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:q(`shrink-0 font-semibold`,c&&`shimmer`,e.status===`declined`&&`text-muted-foreground`),children:u}),g===void 0?d===void 0?null:(0,Q.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-muted-foreground`,children:d}):(0,Q.jsx)(`code`,{"data-slot":`tool-command`,className:`max-h-48 min-w-0 overflow-y-auto py-1 font-mono text-xs leading-[1.6] whitespace-pre-wrap break-all text-muted-foreground`,children:g}),(0,Q.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-2 pl-2`,children:[c?(0,Q.jsx)(cr,{role:`status`,"aria-label":`Running`,className:`size-3.5 animate-spin text-soft-foreground`}):null,e.status===`failed`?(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`failed`}):null,e.status===`declined`?(0,Q.jsx)(`span`,{className:`text-xs text-soft-foreground`,children:`declined`}):null,e.toolKind===`execute`&&typeof e.exitCode==`number`?(0,Q.jsx)(`span`,{"data-slot":`tool-exit`,className:q(`rounded-full px-2 py-px font-mono text-[10.5px] font-semibold`,e.exitCode===0?`bg-success/10 text-success`:`bg-danger/10 text-danger`),children:e.exitCode}):null]})]}),g===void 0?null:(0,Q.jsx)(Hs,{command:g})]}),(0,Q.jsx)(gr,{children:(0,Q.jsxs)(`div`,{className:`border-t border-border bg-card-2 empty:hidden`,children:[e.error!==void 0&&e.error!==``?(0,Q.jsx)(`div`,{"data-slot":`tool-error`,className:`px-4 py-3 font-mono text-xs leading-[1.7] whitespace-pre-wrap text-danger`,children:e.error}):null,e.diffs!==void 0&&e.diffs.length>0?(0,Q.jsx)(Rs,{diffs:e.diffs}):null,e.output!==void 0&&e.output!==``?(0,Q.jsx)(Ls,{text:e.output,streaming:c}):null,t.length>0?(0,Q.jsx)(`div`,{"data-slot":`tool-nested`,className:`flex flex-col gap-2 border-l-2 border-border py-2.5 pr-3 pl-3 ml-4 my-2`,children:r?.(t,n??e.id)}):null]})})]})}function Gs({group:e,scope:t}){return(0,Q.jsxs)(vr,{"data-slot":`ctx-group`,className:`min-w-0`,children:[(0,Q.jsxs)(_r,{className:`group flex h-[34px] w-full items-center gap-2 rounded-md px-2 -mx-2 text-left text-[13px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Vn,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-soft-foreground transition-transform group-data-[state=open]:rotate-90`}),e.label]}),(0,Q.jsx)(gr,{children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5 pt-1.5 pl-4`,children:e.tools.map(e=>(0,Q.jsx)(Ws,{item:e,cacheKey:t===void 0?void 0:`${t}:${e.id}`},e.id))})})]})}function Ks({count:e,children:t}){return(0,Q.jsxs)(vr,{"data-slot":`tool-streak`,className:`min-w-0`,children:[(0,Q.jsxs)(_r,{className:`group flex items-center gap-1.5 rounded-md p-0.5 text-left text-xs text-soft-foreground hover:text-muted-foreground`,children:[(0,Q.jsx)(Vn,{"aria-hidden":!0,className:`size-3.5 shrink-0 transition-transform group-data-[state=open]:rotate-90`}),Bo(e)]}),(0,Q.jsx)(gr,{children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 pt-2`,children:t})})]})}function qs({image:e}){return(0,Q.jsx)(Lr,{"data-slot":`thread-image`,src:e.url,alt:e.name??`image from the agent session`,className:`max-h-72 max-w-full self-start rounded-lg border border-border`})}var Js=120,Ys=e=>e!==`pending`&&e!==`running`,Xs=e=>e.kind===`tool`&&e.toolKind===`task`,Zs=e=>Xs(e)&&e.parentItemId===void 0,Qs=e=>(e.kind===`message`||e.kind===`reasoning`||e.kind===`tool`)&&!(e.kind===`tool`&&e.toolKind===`plan`);function $s(e,t){for(let n=0;n<e.length;n+=1)if(e[n].items.some(e=>Zs(e)&&t.has(e.id)))return n;return 0}function ec(e){let t=e.input;if(typeof t!=`object`||!t)return;let n=t;for(let e of[`subagent_type`,`subagentType`,`agent`]){let t=n[e];if(typeof t==`string`&&t.trim()!==``)return t.trim()}}function tc(e){if(e.kind===`tool`)return nc(e.title);if(e.kind===`message`||e.kind===`reasoning`){let t=e.text.split(`
24
+ `);for(let e=t.length-1;e>=0;--e){let n=t[e].trim();if(n!==``)return nc(n)}}}function nc(e){return e.length>Js?`${e.slice(0,Js-1).trimEnd()}…`:e}function rc(e,t=!1){let n=lc(e,e=>e.items.some(Zs));if(n===-1)return[];let r=e=>!t&&!Ys(e.status),i=[];for(let t=n-1;t>=0;--t){let n=e[t].items.filter(Zs);if(n.length!==0){if(!n.some(r))break;i.unshift(...n)}}let a=[...i,...e[n].items.filter(Zs)];if(n!==e.length-1&&!a.some(r))return[];let o=new Set(a.map(e=>e.id)),s=i.length>0?$s(e,o):n,c=new Map;for(let t=s;t<e.length;t+=1)for(let n of e[t].items){if(!Qs(n))continue;let e=n.parentItemId;if(e===void 0||!o.has(e))continue;let t=c.get(e);t?t.push(n):c.set(e,[n])}return a.map(e=>ac(e,c.get(e.id)??[],t))}function ic(e){let t=new Map;for(let n of e)for(let e of n.items){if(e.kind!==`tool`||e.toolKind!==`skill`||e.parentItemId!==void 0||e.status===`failed`||e.status===`declined`)continue;let n=Ho(e.title).detail??e.title;t.has(n)||t.set(n,{id:e.id,name:n})}return[...t.values()]}function ac(e,t,n){let r={id:e.id,title:Ho(e.title).detail??e.title,status:e.status,toolCalls:t.filter(e=>e.kind===`tool`).length},i=ec(e);i!==void 0&&(r.agentType=i),n&&!Ys(e.status)&&(r.stalled=!0);for(let e=t.length-1;e>=0;--e){let n=tc(t[e]);if(n!==void 0){r.activity=n;break}}return r}function oc(e){return{done:e.filter(e=>e.status===`completed`).length,total:e.length}}function sc(e){return e.activity??(e.stalled===!0?`never finished`:`starting…`)}function cc(e){return e.find(e=>!Ys(e.status))??e[0]}function lc(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function uc(e,t,n=!1){for(let r=e.length-1;r>=0;--r){let i=e[r].items.find(e=>e.id===t&&Zs(e));if(i!==void 0)return ac(i,dc(e,t),n)}}function dc(e,t){let n=e.findIndex(e=>e.items.some(e=>e.id===t&&Zs(e)));if(n===-1)return[];let r=[];for(let i=n;i<e.length;i+=1)for(let n of e[i].items)Qs(n)&&n.parentItemId===t&&n.id!==t&&r.push(n);return r}var fc=new Map,pc=!1;function mc({runId:e,agents:t,onSelect:n}){let[r,i]=(0,Z.useState)(()=>fc.get(e)??pc),a=t.every(e=>e.status!==`pending`&&e.status!==`running`),o=(0,Z.useRef)(a);if((0,Z.useEffect)(()=>{!o.current&&a&&i(t=>t&&(fc.set(e,!1),!1)),o.current=a},[a,e]),t.length===0)return null;let{done:s,total:c}=oc(t),l=cc(t);return(0,Q.jsxs)(`section`,{"data-slot":`agents-dock`,"data-state":r?`open`:`collapsed`,className:`min-w-0 overflow-hidden rounded-lg border border-border bg-card shadow-xs`,children:[(0,Q.jsx)(`div`,{"aria-hidden":!0,"data-slot":`grad-edge`,className:`h-[3px]`,style:{background:`var(--grad)`}}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(t=>(fc.set(e,!t),!t)),"aria-expanded":r,className:q(`flex w-full items-center gap-2 px-3.5 text-left text-[13px]`,r?`pt-2 pb-1.5`:`py-2`),children:[(0,Q.jsx)(jn,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-soft-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-semibold`,children:`Agents`}),(0,Q.jsxs)(`span`,{"data-slot":`agents-count`,className:`shrink-0 text-muted-foreground tabular-nums`,children:[`· `,s,`/`,c]}),!r&&l!==void 0?(0,Q.jsxs)(`span`,{"data-slot":`agents-current`,className:`min-w-0 truncate text-muted-foreground`,children:[`— `,sc(l)]}):null,(0,Q.jsx)(In,{"aria-hidden":!0,className:q(`ml-auto size-3.5 shrink-0 text-soft-foreground transition-transform`,!r&&`rotate-180`)})]}),r?(0,Q.jsx)(`ul`,{"data-slot":`agents-list`,className:`flex flex-col gap-[7px] px-3.5 pb-3`,children:t.map(e=>(0,Q.jsx)(hc,{agent:e,onSelect:n},e.id))}):null]})}function hc({agent:e,onSelect:t}){let n=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(gc,{status:e.status,stalled:e.stalled===!0}),(0,Q.jsx)(`span`,{className:`min-w-0 shrink truncate font-medium`,children:e.title}),e.agentType===void 0?null:(0,Q.jsx)(`span`,{"data-slot":`agent-type`,className:`shrink-0 rounded-full bg-muted px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:e.agentType}),(0,Q.jsx)(`span`,{"data-slot":`agent-activity`,className:`min-w-0 flex-1 truncate text-muted-foreground`,children:sc(e)}),(0,Q.jsxs)(`span`,{"data-slot":`agent-tools`,className:`shrink-0 text-muted-foreground tabular-nums`,children:[e.toolCalls,` `,e.toolCalls===1?`tool`:`tools`]})]});return(0,Q.jsx)(`li`,{"data-slot":`agent-item`,"data-status":e.status,className:`min-w-0 text-[13px]`,children:t?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),"aria-haspopup":`dialog`,className:`flex min-h-5 w-full min-w-0 items-center gap-2.5 rounded-sm text-left hover:bg-muted/50`,children:n}):(0,Q.jsx)(`div`,{className:`flex min-h-5 min-w-0 items-center gap-2.5`,children:n})})}function gc({status:e,stalled:t=!1}){return t?(0,Q.jsx)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,"data-stalled":`true`,className:`size-[15px] shrink-0 text-soft-foreground`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:`3 2.5`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`})}):e===`completed`?(0,Q.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 text-success`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,Q.jsx)(`path`,{d:`m8.5 12.2 2.4 2.4 4.6-5`})]}):e===`failed`||e===`declined`?(0,Q.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 text-danger`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,Q.jsx)(`path`,{d:`m9 9 6 6M15 9l-6 6`})]}):(0,Q.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 animate-pulse motion-reduce:animate-none`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,Q.jsx)(`circle`,{className:`stroke-pending`,cx:`12`,cy:`12`,r:`8.5`,strokeWidth:`2`}),(0,Q.jsx)(`path`,{className:`fill-pending`,d:`M12 3.5 A8.5 8.5 0 0 1 12 20.5 Z`})]})}var _c=new Map;function vc(){return typeof window.matchMedia!=`function`||window.matchMedia(`(min-width: 768px)`).matches}function yc(e){return{done:e.filter(e=>e.status===`completed`).length,total:e.filter(e=>e.status!==`cancelled`).length}}function bc(e){return e.find(e=>e.status===`in_progress`)??e.find(e=>e.status===`pending`)}function xc({runId:e,entries:t,settled:n=!1}){let[r,i]=(0,Z.useState)(()=>_c.get(e)??vc());if(t.length===0)return null;let{done:a,total:o}=yc(t),s=n?void 0:bc(t),c=n&&a<o;return(0,Q.jsxs)(`section`,{"data-slot":`plan-dock`,"data-state":r?`open`:`collapsed`,"data-settled":n?`true`:void 0,className:`min-w-0 overflow-hidden rounded-lg border border-border bg-card shadow-xs`,children:[(0,Q.jsx)(`div`,{"aria-hidden":!0,"data-slot":`grad-edge`,className:`h-0.5 md:h-[3px]`,style:{background:`var(--grad)`}}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(t=>(_c.set(e,!t),!t)),"aria-expanded":r,className:q(`flex w-full items-center gap-2 px-3.5 text-left text-[13px]`,r?`pt-2 pb-1.5`:`py-2`),children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-semibold`,children:`Plan`}),(0,Q.jsxs)(`span`,{"data-slot":`plan-count`,className:`shrink-0 text-muted-foreground tabular-nums`,children:[`· `,a,`/`,o]}),c?(0,Q.jsx)(`span`,{"data-slot":`plan-unfinished`,className:`shrink-0 text-soft-foreground`,children:`· left unfinished`}):null,!r&&s!==void 0?(0,Q.jsxs)(`span`,{"data-slot":`plan-current`,className:`min-w-0 truncate text-muted-foreground`,children:[`— `,s.activeForm??s.content]}):null,(0,Q.jsx)(In,{"aria-hidden":!0,className:q(`ml-auto size-3.5 shrink-0 text-soft-foreground transition-transform`,!r&&`rotate-180`)})]}),r?(0,Q.jsx)(`ul`,{"data-slot":`plan-list`,className:`flex flex-col gap-[7px] px-3.5 pb-3`,children:t.map((e,t)=>(0,Q.jsx)(Sc,{entry:e,settled:n},`${t}:${e.content}`))}):null]})}function Sc({entry:e,settled:t}){let n=t&&e.status===`in_progress`?`pending`:e.status;return(0,Q.jsxs)(`li`,{"data-slot":`plan-item`,"data-status":e.status,className:q(`flex min-h-5 min-w-0 items-center gap-2.5 text-[13px]`,n===`completed`&&`text-soft-foreground line-through`,n===`in_progress`&&`font-medium`,n===`pending`&&`text-muted-foreground`,n===`cancelled`&&`text-soft-foreground/70 line-through`),children:[(0,Q.jsx)(Cc,{status:n}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.content}),n===`in_progress`?(0,Q.jsx)(`span`,{"data-slot":`plan-tag`,className:`ml-auto shrink-0 rounded-full bg-muted px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:`in progress`}):null]})}function Cc({status:e}){return e===`cancelled`?(0,Q.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-soft-foreground/70`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,opacity:`.5`}),(0,Q.jsx)(`path`,{d:`m8.5 15.5 7-7`})]}):e===`completed`?(0,Q.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-success`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,Q.jsx)(`path`,{d:`m8.5 12.2 2.4 2.4 4.6-5`})]}):e===`in_progress`?(0,Q.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 animate-pulse motion-reduce:animate-none`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,Q.jsx)(`circle`,{className:`stroke-pending`,cx:`12`,cy:`12`,r:`8.5`,strokeWidth:`2`}),(0,Q.jsx)(`path`,{className:`fill-pending`,d:`M12 3.5 A8.5 8.5 0 0 1 12 20.5 Z`})]}):(0,Q.jsx)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-soft-foreground`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`})})}function wc({skills:e}){return e.length===0?null:(0,Q.jsxs)(`section`,{"data-slot":`skills-dock`,className:`flex min-w-0 items-center gap-2 overflow-hidden rounded-lg border border-border bg-card px-3.5 py-2 text-[13px] shadow-xs`,children:[(0,Q.jsx)(bt,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-soft-foreground`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-semibold`,children:e.length===1?`Skill`:`Skills`}),(0,Q.jsxs)(`span`,{"data-slot":`skills-names`,className:`min-w-0 truncate text-muted-foreground`,children:[`· `,e.map(e=>e.name).join(` · `)]})]})}function Tc(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null)return!1;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(!Tc(e[n],t[n]))return!1;return!0}if(!Ec(e)||!Ec(t))return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.hasOwn(t,r)||!Tc(e[r],t[r]))return!1;return!0}function Ec(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Dc(){return typeof CSS>`u`||typeof CSS.supports!=`function`||CSS.supports(`overflow-anchor`,`auto`)}function Oc(e,t={}){let{surface:n=`document`,onLoadOlder:r,onJumpToLatest:i,rowKeys:a=[]}=t,o=(0,Z.useRef)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(!0),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useCallback)(e=>{let t=o.current;if(!t)return;let n=m.current;n?n.scrollTo(e):t.scrollTop=e},[]),g=(0,Z.useCallback)(()=>{let e=o.current;e&&h(e.scrollHeight-e.clientHeight)},[h]),_=(0,Z.useCallback)(()=>{if(o.current){if(p.current!==e){p.current=e;let t=ns(e);t&&!t.atBottom?(d.current=!1,f.current=t.top):(d.current=!0,f.current=null)}f.current===null?d.current&&g():h(f.current)}},[e,h,g]),v=(0,Z.useCallback)(e=>{c(e),e&&(o.current=e.closest(n===`panel`?`[data-slot="transcript-viewport"]`:`[data-slot="main"]`),_())},[n,_]),y=(0,Z.useCallback)(()=>{d.current&&g()},[g]),b=(0,Z.useRef)(!1),x=(0,Z.useRef)(!1),S=(0,Z.useRef)(void 0),C=(0,Z.useRef)(!1),w=(0,Z.useRef)(!1),T=(0,Z.useRef)(!1),E=(0,Z.useRef)(void 0),D=(0,Z.useRef)(0),O=(0,Z.useRef)(a);O.current=a;let k=(0,Z.useCallback)(e=>[...e.querySelectorAll(`[data-slot="thread-row"][data-row-key]`)].map(e=>{let t=e.getBoundingClientRect();return{key:e.dataset.rowKey,top:t.top,bottom:t.bottom}}),[]),A=(0,Z.useCallback)(()=>{let e=o.current;if(!e||!r||b.current)return;b.current=!0;let t=e.scrollHeight,n=e.scrollTop,i=e.getBoundingClientRect().top,a=Xo(i,k(e));r().finally(()=>{requestAnimationFrame(()=>{let e=o.current;if(e&&!d.current){let r=n+Math.max(0,e.scrollHeight-t),i=e.getBoundingClientRect().top,o=a===void 0?-1:O.current.indexOf(a.key),s=m.current;s&&o>=0?s.scrollToIndex(o,{align:`start`,offset:-a.offset}):h(Zo(e.scrollTop,i,a,k(e),r))}b.current=!1})})},[k,r,h]);(0,Z.useEffect)(()=>()=>clearTimeout(S.current),[]);let ee=(0,Z.useCallback)(()=>{o.current&&(f.current=null,d.current=!0,(i?.()??Promise.resolve()).finally(()=>{requestAnimationFrame(()=>{let e=o.current;e?.scrollTo({top:e.scrollHeight-e.clientHeight,behavior:`smooth`})})}))},[i]);return(0,Z.useLayoutEffect)(()=>{!o.current||!s||_()},[s,_]),(0,Z.useEffect)(()=>{let t=o.current,n=s;if(!t||!n)return;let r=!Dc(),i=(e,t)=>{if(typeof document.elementsFromPoint==`function`){let n=document.elementsFromPoint(t.left+t.width/2,t.top+1).map(e=>e.closest(`[data-slot="thread-row"][data-row-key]`)).find(t=>t!==null&&e.contains(t));if(n){let e=n.getBoundingClientRect();return{key:n.dataset.rowKey,top:e.top,bottom:e.bottom}}return}return k(e).find(({bottom:e})=>e>t.top)},a=(e,t)=>{let n=typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(t):t.replace(/["\\]/g,`\\$&`),r=e.querySelector(`[data-slot="thread-row"][data-row-key="${n}"]`);if(!r)return;let i=r.getBoundingClientRect();return{key:t,top:i.top,bottom:i.bottom}},c=()=>{!r||d.current||f.current!==null||D.current===0&&(D.current=requestAnimationFrame(()=>{D.current=0;let e=o.current;if(!e||d.current)return;let t=e.getBoundingClientRect(),n=i(e,t);E.current=n===void 0?void 0:{key:n.key,offset:n.top-t.top}}))},l=()=>{let e=E.current;if(!r||e===void 0||m.current)return;let n=t.getBoundingClientRect().top,i=a(t,e.key),o=i===void 0?t.scrollTop:t.scrollTop+(i.top-n-e.offset);Math.abs(o-t.scrollTop)>=1&&h(o)},p=0,_=null,v=!1,y=t.scrollTop,b=()=>{f.current=null,d.current=!1,p=0},O=()=>{p=Date.now()},ee=e=>{if(e.deltaY<0){b();let e=!x.current;x.current=!0,clearTimeout(S.current),S.current=setTimeout(()=>{x.current=!1},180),e&&Yo(t)&&A()}else O()},j=e=>{[`ArrowUp`,`PageUp`,`Home`].includes(e.key)?(b(),!e.repeat&&Yo(t)&&A()):[`ArrowDown`,`PageDown`,`End`].includes(e.key)&&O()},te=()=>{v=!0,T.current=!1,y=t.scrollTop,Qo(t,80)||(b(),O())},M=()=>{v=!1},N=e=>{C.current=!1,w.current=!0,_=e.touches[0]?.clientY??null},P=()=>{w.current&&(w.current=!1,d.current&&f.current===null&&g())},F=e=>{let n=e.touches[0]?.clientY;n!==void 0&&(_!==null&&n>_+1?(b(),!C.current&&Yo(t)&&(C.current=!0,A())):_!==null&&n<_-1&&O(),_=n)},I=()=>{v&&!T.current&&t.scrollTop<y&&Yo(t)&&(T.current=!0,A()),y=t.scrollTop;let n=Qo(t,80);n&&f.current===null&&(d.current||Date.now()-p<2e3)&&(d.current=!0),u(!n),f.current===null&&ts(e,{top:t.scrollTop,atBottom:n}),c()};t.addEventListener(`scroll`,I,{passive:!0}),t.addEventListener(`wheel`,ee,{passive:!0}),t.addEventListener(`touchstart`,N,{passive:!0}),t.addEventListener(`touchmove`,F,{passive:!0}),window.addEventListener(`touchend`,P,{passive:!0}),window.addEventListener(`touchcancel`,P,{passive:!0}),t.addEventListener(`pointerdown`,te,{passive:!0}),window.addEventListener(`pointerup`,M,{passive:!0}),t.addEventListener(`keydown`,j);let L;return typeof ResizeObserver<`u`&&(L=new ResizeObserver(()=>{let e=f.current;if(e!==null){let n=t.scrollHeight-t.clientHeight;h(Math.min(e,n)),n>=e&&(f.current=null,c())}else d.current?w.current||g():l()}),L.observe(n)),c(),()=>{cancelAnimationFrame(D.current),D.current=0,E.current=void 0,t.removeEventListener(`scroll`,I),t.removeEventListener(`wheel`,ee),t.removeEventListener(`touchstart`,N),t.removeEventListener(`touchmove`,F),window.removeEventListener(`touchend`,P),window.removeEventListener(`touchcancel`,P),t.removeEventListener(`pointerdown`,te),window.removeEventListener(`pointerup`,M),t.removeEventListener(`keydown`,j),L?.disconnect()}},[e,s,A,h,g]),{attachContent:v,scrollElRef:o,virtualizerRef:m,pillVisible:l,jumpToLatest:ee,loadOlder:A,restickIfStuck:y}}function kc({runId:e,rows:t,mode:n,controls:r}){if(n===`virtual`)return(0,Q.jsx)(Ac,{runId:e,rows:t,controls:r});let i=Jo(Dc());return(0,Q.jsx)(`div`,{ref:r.attachContent,"data-slot":`thread-rows`,"data-virtualized":`false`,children:t.map(e=>(0,Q.jsx)(`div`,{"data-slot":`thread-row`,"data-row-key":e.key,className:i,children:e.node},e.key))})}function Ac({runId:e,rows:t,controls:n}){let r=(0,Z.useRef)(null),[i]=(0,Z.useState)(()=>as(e,t.length)),a=(0,Z.useRef)(t.length);a.current=t.length;let o=(0,Z.useRef)(null),s=(0,Z.useCallback)(t=>{n.virtualizerRef.current=t,t?o.current=t:o.current&&=(is(e,{rows:a.current,cache:o.current.cache}),null)},[e,n.virtualizerRef]),[c,l]=(0,Z.useState)(0);return(0,Z.useLayoutEffect)(()=>{let e=()=>{let e=r.current,t=n.scrollElRef.current;!e||!t||l(Math.max(0,Math.round(e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[n.scrollElRef]),(0,Q.jsx)(`div`,{ref:e=>{r.current=e,n.attachContent(e)},"data-slot":`thread-rows`,"data-virtualized":`true`,children:(0,Q.jsx)(Rr,{ref:s,scrollRef:n.scrollElRef,startMargin:c,...i===void 0?{}:{cache:i},children:t.map(e=>(0,Q.jsx)(`div`,{"data-slot":`thread-row`,"data-row-key":e.key,className:`flex w-full flex-col pb-2.5`,children:e.node},e.key))})})}function jc({onJump:e}){return(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`jump-to-latest`,onClick:e,className:`pointer-events-auto inline-flex min-h-8 items-center gap-1.5 rounded-full border border-border bg-background px-3.5 text-xs font-medium text-muted-foreground shadow-modal hover:text-foreground`,children:[(0,Q.jsx)(hn,{"aria-hidden":!0,className:`size-3.5`}),`Jump to latest`]})}function Mc(e,t){let n=[];(e.task||e.taskImages?.length)&&n.push({id:`task`,userMessageKey:`task`,userMessage:{text:e.task,images:e.taskImages??[],ts:e.createdAt},entries:[]});for(let t of e.queuedMessages??[])n.push({id:`queued:${t.id}`,userMessageKey:`queued:${t.id}`,userMessage:{text:t.text,images:t.images??[],ts:t.createdAt},inDaySequence:!1,entries:[]});for(let e of t.turns)n.push({id:e.id,userMessageKey:`${e.id}:user`,...e.userMessage===void 0?{}:{userMessage:{text:e.userMessage.text,imageCount:e.userMessage.imageCount,images:e.userMessage.images,...e.userMessage.ts===void 0?{}:{ts:e.userMessage.ts}}},...e.startedAt===void 0?{}:{startedAt:e.startedAt},...e.completed?.ts===void 0?{}:{completedAt:e.completed.ts},entries:e.items});return n}function Nc(e,t){return[{id:`agent:${e}`,entries:t}]}function Pc(e){if(e.inDaySequence!==!1)return e.userMessage?.ts??e.startedAt??e.completedAt}function Fc(e,t){let n=[],r;for(let t of e){let e=Pc(t),i=hs(e);i!==void 0&&e!==void 0&&(r===void 0||i>r)&&(r!==void 0&&n.push({key:`${t.id}:day-separator`,scope:t.id,content:{kind:`day-separator`,ts:e}}),r=i),t.userMessage!==void 0&&n.push({key:t.userMessageKey??`${t.id}:user`,scope:t.id,content:{kind:`user-message`,message:t.userMessage}});for(let e of Uo([...t.entries]))n.push({key:`${t.id}:${e.id}`,scope:t.id,content:{kind:`block`,block:e}});t.completedAt!==void 0&&n.push({key:`${t.id}:turn-time`,scope:t.id,content:{kind:`turn-time`,completedAt:t.completedAt,...t.startedAt===void 0?{}:{startedAt:t.startedAt}}})}return n}function Ic({runId:e,viewId:t,sections:n,mode:r,empty:i,renderAsk:a,messageActions:o,scrollControls:s,renderMode:c,rowModels:l}){let u=(0,Z.useMemo)(()=>l??Fc(n,e),[l,n,e]),d=Oc(`${e}:${t}`,{surface:r}),f=s??d,p=(0,Z.useMemo)(()=>u.map(t=>({key:t.key,node:(0,Q.jsx)(Rc,{runId:e,row:t,actions:o?.[t.key],renderAsk:a})})),[o,a,u,e]),m=c??$o(``,p.length),h=p.length===0?i??null:(0,Q.jsx)(kc,{runId:`${e}:${t}`,rows:p,mode:m,controls:f});return(0,Q.jsx)(qo,{runId:e,children:r===`panel`?(0,Q.jsxs)(`div`,{"data-slot":`transcript-viewport`,"aria-label":`Agent transcript`,role:`region`,tabIndex:0,className:`relative flex min-h-0 flex-1 flex-col overflow-y-auto [scrollbar-gutter:stable]`,children:[(0,Q.jsx)(`div`,{"data-slot":`subagent-stream`,className:`flex flex-col px-5 py-4`,children:h}),f.pillVisible?(0,Q.jsx)(`div`,{className:`pointer-events-none sticky inset-x-0 bottom-4 flex justify-center`,children:(0,Q.jsx)(jc,{onJump:f.jumpToLatest})}):null]}):h})}function Lc({runId:e,row:t,actions:n,renderAsk:r}){return zc(e,t,n,r)}var Rc=(0,Z.memo)(Lc,(e,t)=>e.runId===t.runId&&e.actions===t.actions&&e.renderAsk===t.renderAsk&&Tc(e.row,t.row));function zc(e,t,n,r){switch(t.content.kind){case`user-message`:return(0,Q.jsx)(Bc,{runId:e,message:t.content.message,actions:n});case`day-separator`:return(0,Q.jsx)(Cs,{ts:t.content.ts});case`turn-time`:return(0,Q.jsx)(Ss,{completedAt:t.content.completedAt,...t.content.startedAt===void 0?{}:{startedAt:t.content.startedAt}});case`block`:return(0,Q.jsx)(Vc,{block:t.content.block,scope:t.scope,renderAsk:r});default:return Wc(t.content)}}function Bc({runId:e,message:t,actions:n}){return(0,Q.jsx)(ws,{text:t.text,imageCount:t.imageCount,images:t.images,...t.ts===void 0?{}:{ts:t.ts},onEdit:n?.onEdit,onRemove:n?.onRemove,editLabel:n?.editLabel,removeLabel:n?.removeLabel,draftRunId:n?.draftSurface===void 0?void 0:e,draftSurface:n?.draftSurface})}var Vc=(0,Z.memo)(function e({block:t,scope:n,renderAsk:r}){switch(t.kind){case`entry`:return(0,Q.jsx)(Uc,{entry:t.entry,scope:n,renderAsk:r});case`tool-card`:return(0,Q.jsx)(Ws,{item:t.item,nested:t.children,cacheKey:`${n}:${t.id}`,renderNested:(e,t)=>(0,Q.jsx)(Hc,{entries:e,scope:t,renderAsk:r})});case`context-group`:return(0,Q.jsx)(Gs,{group:t,scope:n});case`streak`:return(0,Q.jsx)(Ks,{count:t.count,children:t.blocks.map(t=>(0,Q.jsx)(e,{block:t,scope:n,renderAsk:r},t.id))});default:return Wc(t)}},Gc);function Hc({entries:e,scope:t,renderAsk:n}){return Uo([...e]).map(e=>(0,Q.jsx)(Vc,{block:e,scope:t,renderAsk:n},e.id))}function Uc({entry:e,scope:t,renderAsk:n}){switch(e.kind){case`message`:return e.role===`assistant`?(0,Q.jsx)(Es,{text:e.text}):(0,Q.jsx)(ws,{text:e.text});case`reasoning`:return(0,Q.jsx)(Ns,{text:e.text});case`tool`:return(0,Q.jsx)(Ws,{item:e,cacheKey:`${t}:${e.id}`});case`note`:return(0,Q.jsx)(Ds,{note:e});case`image`:return(0,Q.jsx)(qs,{image:e});case`ask`:return n===void 0?(0,Q.jsx)(`div`,{"data-slot":`ask-card`,className:`rounded-lg border border-border bg-card px-4 py-3 text-sm`,children:`The agent asked a question. Open the main session to answer it.`}):n(e);case`provider-auth-required`:return(0,Q.jsx)(ks,{incident:e});case`agent-update-required`:return(0,Q.jsx)(Ms,{incident:e});default:return Wc(e)}}function Wc(e){throw Error(`Unhandled transcript variant: ${JSON.stringify(e)}`)}function Gc(e,t){return e.scope===t.scope&&qc(e.block,t.block)&&(!Kc(t.block)||e.renderAsk===t.renderAsk)}function Kc(e){return e.kind===`entry`?e.entry.kind===`ask`:e.kind===`tool-card`?e.children.some(e=>e.kind===`ask`):e.kind!==`context-group`&&e.blocks.some(Kc)}function qc(e,t){if(e.kind!==t.kind||e.id!==t.id)return!1;switch(t.kind){case`entry`:return Yc(e.kind===`entry`?e.entry:void 0,t.entry);case`tool-card`:return e.kind===`tool-card`&&al(e.item,t.item)&&Jc(e.children,t.children);case`context-group`:return e.kind===`context-group`&&e.files===t.files&&e.searches===t.searches&&e.label===t.label&&e.tools.length===t.tools.length&&e.tools.every((e,n)=>al(e,t.tools[n]));case`streak`:return e.kind===`streak`&&e.count===t.count&&e.blocks.length===t.blocks.length&&e.blocks.every((e,n)=>qc(e,t.blocks[n]));default:return!1}}function Jc(e,t){return e.length===t.length&&e.every((e,n)=>Yc(e,t[n]))}function Yc(e,t){if(e===void 0||e.kind!==t.kind||e.id!==t.id)return!1;switch(t.kind){case`message`:return e.kind===`message`&&il(e,t,Xc);case`reasoning`:return e.kind===`reasoning`&&il(e,t,Zc);case`tool`:return e.kind===`tool`&&al(e,t);case`note`:return e.kind===`note`&&il(e,t,Qc);case`image`:return e.kind===`image`&&il(e,t,$c);case`ask`:return e.kind===`ask`&&il(e,t,el);case`provider-auth-required`:return e.kind===`provider-auth-required`&&il(e,t,tl);case`agent-update-required`:return e.kind===`agent-update-required`&&il(e,t,nl);default:return!1}}var Xc={kind:!0,id:!0,role:!0,text:!0,phase:!0,parentItemId:!0},Zc={kind:!0,id:!0,text:!0,parentItemId:!0},Qc={kind:!0,id:!0,text:!0,tone:!0},$c={kind:!0,id:!0,url:!0,name:!0},el={kind:!0,id:!0,questions:!0,resolved:!0,answer:!0,fromWorkflow:!0},tl={kind:!0,id:!0,provider:!0,authFailureId:!0,profileId:!0},nl={kind:!0,id:!0,provider:!0},rl={kind:!0,id:!0,name:!0,toolKind:!0,title:!0,status:!0,input:!0,output:!0,error:!0,diffs:!0,locations:!0,exitCode:!0,parentItemId:!0};function il(e,t,n){return Object.keys(n).every(n=>e[n]===t[n])}function al(e,t){return il(e,t,rl)}function ol({runId:e,renderAsk:t,agent:n,entries:r,onClose:i}){return(0,Q.jsx)(Le,{open:n!==void 0,onOpenChange:e=>{e||i()},children:(0,Q.jsx)(Ie,{"data-slot":`subagent-sheet`,side:`right`,className:`flex min-h-0 w-full gap-0 p-0 sm:max-w-xl`,children:n===void 0?null:(0,Q.jsx)(sl,{runId:e,renderAsk:t,agent:n,entries:r})})})}function sl({runId:e,renderAsk:t,agent:n,entries:r}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Re,{className:`gap-1.5 border-b border-border px-5 py-4`,children:[(0,Q.jsxs)(ze,{className:`flex min-w-0 items-center gap-2 text-[15px]`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:n.title}),n.agentType===void 0?null:(0,Q.jsx)(`span`,{"data-slot":`agent-type`,className:`shrink-0 rounded-full bg-muted px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:n.agentType})]}),(0,Q.jsxs)(Pe,{"data-slot":`subagent-meta`,className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(cl,{status:n.status}),(0,Q.jsxs)(`span`,{className:`tabular-nums`,children:[n.toolCalls,` `,n.toolCalls===1?`tool call`:`tool calls`]})]})]}),(0,Q.jsx)(Ic,{runId:e,viewId:`agent:${n.id}`,sections:Nc(n.id,r),mode:`panel`,renderAsk:t,empty:(0,Q.jsx)(`div`,{"data-slot":`subagent-empty`,className:`py-2 text-[13px] text-muted-foreground`,children:`No attributed output — see the thread card for this agent's result.`})})]})}function cl({status:e}){let t=e===`completed`?`Completed`:e===`failed`?`Failed`:e===`declined`?`Declined`:e===`pending`?`Pending`:`Running`;return(0,Q.jsx)(`span`,{"data-slot":`subagent-status`,"data-status":e,className:q(`rounded-full px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.05em] uppercase`,e===`completed`&&`bg-success/15 text-success`,(e===`failed`||e===`declined`)&&`bg-danger/15 text-danger`,(e===`running`||e===`pending`)&&`bg-muted text-muted-foreground`),children:t})}function ll({run:e,diffComments:t}){return(0,Q.jsxs)(`section`,{"data-slot":`review-panel`,"aria-label":`Review the changes`,className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{"data-slot":`review-banner`,className:`flex items-center gap-2.5 rounded-md border border-violet/30 bg-violet/10 px-3.5 py-2.5`,children:[(0,Q.jsx)(tr,{className:`size-4 shrink-0 text-violet`,"aria-hidden":`true`}),(0,Q.jsxs)(`p`,{className:`min-w-0 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:`Review the changes before anything lands.`}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Read the diff, send notes back, draft a PR — or accept. Nothing merges on its own.`})]})]}),(0,Q.jsx)(Hr,{runId:e.id}),(0,Q.jsx)(ul,{run:e,diffComments:t})]})}function ul({run:e,diffComments:t}){let n=G(),r=(0,Z.useRef)(null),i=Yt(e.id,`review-notes`),a=i.text,o=i.setText,[s,c]=(0,Z.useState)(null),l=Ft(e.id),u=uo(e),d=Ea(e,(0,Z.useCallback)(t=>H(e.id,{text:t,runner:u.runnerOverride}),[e.id,u.runnerOverride]),{surface:`review`}),f=()=>n.invalidateQueries({queryKey:R.runs.all}),p=U({mutationFn:async e=>{if(!u.canContinue)return null;let n=async t=>{let n=`Review feedback:\n${no(e,t)}`;if(n.length>1e5)throw Error(`Too long with the diff comments attached — shorten the notes or remove some comments.`);return d(n,[])};return i.submit(()=>t?t.submit(n):n([]))},onSuccess:e=>{e!==null&&f()},onError:e=>Y(e.message,{tone:`danger`})}),m=Nt(e),h=U({mutationFn:()=>F(e.id),onSuccess:e=>{Y(`Draft PR created — ${e.url}`),f()},onError:e=>{e instanceof S&&e.manual!==void 0&&c(e.manual),Y(e.message,{tone:`danger`})}}),g=h.isPending||m.pending!==null,_=()=>m.byAgent?m.onAction(`create-draft-pr`):h.mutate(),v=t?.comments.length??0,y=()=>{let e=a.trim();if(e.length===0&&v===0){Y(`Write what to change first.`),r.current?.focus();return}p.mutate(e)};return(0,Q.jsxs)(`div`,{"data-slot":`review-actions`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Pn,{ref:r,"data-slot":`review-notes`,"aria-label":`Notes for the agent`,placeholder:`Notes for the agent — what should change?`,rows:2,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{dr({key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,repeat:e.repeat,isComposing:e.nativeEvent.isComposing})&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),y())},className:`min-h-[52px] text-[13px]`}),v>0?(0,Q.jsxs)(`p`,{"data-slot":`review-diff-comments`,className:`text-xs text-muted-foreground`,children:[`+ `,v,` `,v===1?`comment`:`comments`,` on the diff — sent back with these notes.`]}):null,u.canContinue?null:(0,Q.jsxs)(`p`,{id:`review-provider-guidance`,className:`flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:u.reason}),u.providerPending?null:(0,Q.jsx)(Se,{to:`/settings/agents#providers`,className:`font-medium text-foreground underline underline-offset-4`,children:`Configure providers`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(J,{"data-slot":`review-send-back`,variant:`outline`,size:`sm`,title:u.reason??`Send the notes back into the agent's session`,"aria-describedby":u.canContinue?void 0:`review-provider-guidance`,disabled:p.isPending||!u.canContinue,onClick:y,children:[(0,Q.jsx)(ii,{"aria-hidden":`true`}),`Send back`]}),me(e.pullRequestUrl)?(0,Q.jsx)(J,{asChild:!0,variant:`outline`,size:`sm`,children:(0,Q.jsxs)(`a`,{"data-slot":`pr-link`,href:e.pullRequestUrl,target:`_blank`,rel:`noopener noreferrer`,title:`The PR for this task is already open`,children:[(0,Q.jsx)(Xn,{"aria-hidden":`true`}),`PR ↗`]})}):(0,Q.jsxs)(J,{"data-slot":`review-draft-pr`,variant:`outline`,size:`sm`,title:m.byAgent?`Ask the agent to push the branch and open a draft PR`:`Push the branch and open a draft PR`,disabled:g,"aria-busy":g||void 0,onClick:_,children:[g?(0,Q.jsx)(cr,{"aria-hidden":`true`,className:`motion-safe:animate-spin`}):(0,Q.jsx)(or,{"aria-hidden":`true`}),g?rr[`create-draft-pr`]:`Draft PR`]}),(0,Q.jsxs)(J,{"data-slot":`review-accept`,variant:`contrast`,size:`sm`,className:`ml-auto`,title:pt(`review`),disabled:l.isPending,onClick:()=>l.mutate(),children:[(0,Q.jsx)(Fn,{"aria-hidden":`true`}),`Accept`]})]}),s===null?null:(0,Q.jsx)(dl,{command:s})]})}function dl({command:e}){return(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`review-manual`,title:`Copy the command`,onClick:()=>{navigator.clipboard.writeText(e).then(()=>Y(`Command copied to clipboard.`)).catch(()=>Y(`Run manually: ${e}`))},className:`flex w-full min-w-0 items-center gap-1.5 rounded-sm px-1 py-0.5 text-left font-mono text-[11px] text-soft-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(We,{className:`size-3 shrink-0`,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`truncate`,children:[`manual path: `,e]})]})}function fl(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}var pl=1500;function ml({status:e}){let t=(0,Z.useRef)(e),[n,r]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{let n=t.current;if(t.current=e,n!==`review`||e!==`done`||fl())return;r(!0);let i=setTimeout(()=>r(!1),pl);return()=>clearTimeout(i)},[e]),n?(0,Q.jsxs)(`div`,{"data-slot":`accept-celebration`,"aria-hidden":`true`,className:`pointer-events-none fixed inset-0 isolate z-40`,children:[(0,Q.jsx)(Pr,{}),(0,Q.jsx)(`div`,{className:`flex justify-center pt-24`,children:(0,Q.jsx)(`span`,{className:`rounded-full border border-violet/30 bg-violet/15 px-4 py-1.5 text-[13px] font-medium text-violet shadow-modal`,children:`✓ Changes accepted`})})]}):null}var hl=new Map,gl=(e,t)=>JSON.stringify([e,t.id,t.questions.map(e=>[e.header,e.question,e.options.map(e=>e.label)])]);function _l(e,t){return hl.get(gl(e,t))??{}}function vl(e,t,n){hl.set(gl(e,t),n)}function yl(e,t){hl.delete(gl(e,t))}function bl(e,t){return`${e.header}: ${t.join(`, `)}`}function xl({ask:e,run:t}){return(0,Z.useEffect)(()=>{e.resolved&&yl(t.id,e)},[e,t.id]),e.resolved?(0,Q.jsxs)(`div`,{"data-slot":`ask-card`,"data-resolved":`true`,className:`rounded-lg border border-border bg-card px-3.5 py-2.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`text-soft-foreground`,children:`Answered`}),e.answer?(0,Q.jsx)(`span`,{className:`ml-1.5 break-words whitespace-pre-line text-foreground`,children:e.answer}):null]}):(0,Q.jsx)(Sl,{ask:e,run:t})}function Sl({ask:e,run:t}){let n=ut(t),r=n.blockedBy!==void 0,i=e.questions,a=i.length===1&&i[0]?.multiSelect!==!0,[o,s]=(0,Z.useState)(()=>_l(t.id,e)),c=(n,r)=>s(i=>{let a={...i,[n]:r};return vl(t.id,e,a),a}),l=e=>(o[e]?.length??0)>0,u=i.every((e,t)=>l(t)),d=i.some((e,t)=>l(t))?i.filter((e,t)=>!l(t)).map(e=>e.header):[],f=()=>void n.send(i.map((e,t)=>bl(e,o[t]??[])).join(`
25
+ `)),p=n.mode===`resume`;return(0,Q.jsxs)(`div`,{"data-slot":`ask-card`,"data-resolved":`false`,"data-delivery":n.mode,className:`rounded-lg border border-primary/25 bg-primary/[0.04] px-4 pt-3.5 pb-3.5`,children:[(0,Q.jsx)(`div`,{className:`mb-2.5 flex items-center gap-2`,children:(0,Q.jsx)(`span`,{className:`text-xs font-medium text-primary`,children:e.fromWorkflow?`The workflow is asking`:`The agent is asking`})}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-4`,children:i.map((e,t)=>(0,Q.jsx)(Cl,{question:e,disabled:n.isPending||r,selected:o[t]??[],onSelect:i=>{r||(a?n.send(bl(e,i)):c(t,i))}},e.id??t))}),a?p?(0,Q.jsx)(`p`,{"data-slot":`ask-resume-hint`,className:`mt-3 text-[11.5px] text-soft-foreground`,children:`The session has ended — your answer reopens it and goes to the agent.`}):null:(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center gap-2.5`,children:[(0,Q.jsx)(J,{size:`sm`,disabled:n.isPending||r||!u,onClick:f,children:p?`Send answer & reopen`:`Send answer`}),(0,Q.jsx)(`span`,{"data-slot":p?`ask-resume-hint`:`ask-hint`,className:`text-[11.5px] text-soft-foreground`,children:p?`the session has ended — sending reopens it`:`${i.length>1?`answer each question`:`pick one or more`} — or type a reply below`})]}),!a&&d.length>0?(0,Q.jsxs)(`p`,{"data-slot":`ask-unanswered`,className:`mt-2 text-[11.5px] text-soft-foreground`,children:[`unanswered: `,d.join(`, `)]}):null,n.blockedBy===`provider`?(0,Q.jsxs)(`div`,{"data-slot":`ask-provider-gate`,className:`mt-3 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:n.reason}),(0,Q.jsx)(Se,{to:`/settings/agents#providers`,className:`font-medium text-foreground underline underline-offset-4`,children:`Configure providers`})]}):null,n.blockedBy===`no-session`?(0,Q.jsx)(`p`,{"data-slot":`ask-no-session`,className:`mt-3 text-xs text-muted-foreground`,children:n.reason}):null,n.error?(0,Q.jsx)(`p`,{"data-slot":`ask-error`,role:`alert`,className:`mt-3 text-xs text-danger`,children:n.error}):null]})}function Cl({question:e,disabled:t,selected:n,onSelect:r}){let i=e.multiSelect===!0,a=e=>{if(!i){r([e]);return}r(n.includes(e)?n.filter(t=>t!==e):[...n,e])};return(0,Q.jsxs)(`div`,{role:`group`,"aria-label":e.question,children:[(0,Q.jsxs)(`div`,{className:`mb-0.5 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded-md bg-primary px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary-foreground`,children:e.header}),i?(0,Q.jsx)(`span`,{className:`ml-auto text-[10.5px] text-soft-foreground`,children:`select all that apply`}):null]}),(0,Q.jsx)(`p`,{className:`mb-2.5 break-words text-sm font-semibold text-foreground`,children:e.question}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.options.map(e=>{let r=n.includes(e.label);return(0,Q.jsxs)(`button`,{type:`button`,disabled:t,"aria-pressed":r,onClick:()=>a(e.label),className:q(`flex w-full flex-col gap-0.5 rounded-md border px-3.5 py-2.5 text-left transition-colors`,`hover:border-primary/50 hover:bg-primary/[0.06] disabled:pointer-events-none disabled:opacity-50`,r?`border-primary/60 bg-primary/[0.06]`:`border-border bg-card`),children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-start gap-2 text-[13.5px] font-semibold text-foreground`,children:[i?(0,Q.jsx)(`span`,{"aria-hidden":!0,className:q(`flex size-4 shrink-0 items-center justify-center rounded border text-[10px]`,r?`border-primary bg-primary text-primary-foreground`:`border-soft-foreground`),children:r?`✓`:``}):null,(0,Q.jsx)(`span`,{className:`min-w-0 break-words`,children:e.label})]}),e.description?(0,Q.jsx)(`span`,{className:`min-w-0 break-words text-xs text-muted-foreground`,children:e.description}):null]},e.label)})})]})}var wl=/\b\d+\.\d+(?:\.\d+)?\+? or (?:newer|later|higher|above) is required\b|\brequires? (?:version |v)?\d+\.\d+(?:\.\d+)? or (?:newer|later|higher)\b/i;function Tl(e){return wl.test(e)}function El(e){for(let t=e.turns.length-1;t>=0;--t){let n=e.turns[t].planEntries;if(n!==void 0)return n}}function Dl(e){let t=[];for(let n of e.turns)for(let e of n.items)if(e.kind===`tool`){for(let n of e.locations??[])t.push(n.path);for(let n of e.diffs??[])t.push(n.path)}let n=[];for(let e=t.length-1;e>=0;--e)n.includes(t[e])||n.push(t[e]);return n}function Ol(e,t,n=!1){switch(e){case`waiting`:return{state:`waiting`};case`failed`:return n?{state:`closed`,tone:`dim`,label:`Session closed — waiting for your answer, which reopens it`}:{state:`closed`,tone:`danger`,label:t?`Session failed — ${t}`:`Session failed`};case`review`:return{state:`closed`,tone:`dim`,label:`Session closed — waiting for your review`};case`done`:case`cancelled`:return{state:`closed`,tone:`dim`,label:`Session closed`};default:return null}}function kl(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e){return typeof e==`string`?e:void 0}function Al(e){if(!(typeof e!=`string`||e===``))return Number.isFinite(new Date(e).getTime())?e:void 0}function jl(e){return e===`claude`||e===`codex`||e===`junie`||e===`opencode`||e===`cursor`||e===`pi`||e===`copilot`?e:void 0}var Ml=e=>kl(e)&&typeof e.header==`string`&&Array.isArray(e.options);function Nl(e,t){let n=e.replace(/\s*CEZ:DONE\s*$/,``).replace(/\s*CEZ:MONITORING\s*$/,``);return t&&(n=n.replace(/\s*CEZ:ASK[ \t]+\{[\s\S]*\}\s*$/,``)),n.includes(`CEZ:`)?n.split(`
26
+ `).filter(e=>!/^CEZ:(?:PR=\d+|ISSUE=\d+|TITLE=.+)\s*$/.test(e)).join(`
27
+ `):n}function Pl(e){let t=e=>Nl(e,!0).replace(/\s+/g,``),n=new Set,r=[];for(let{origin:i,entry:a}of e.entries)if(i===`v2`&&a.kind===`message`){let e=t(a.text);n.add(e),r.push(e)}if(r.length===0)return;n.add(r.join(``));let i=[],a={entries:[],texts:[]},o=()=>{if(a.entries.length>=2&&n.has(t(a.texts.join(``)))){a={entries:[],texts:[]};return}i.push(...a.entries),a={entries:[],texts:[]}};for(let t of e.entries)t.origin===`v1`&&t.entry.kind===`message`?(a.entries.push(t),a.texts.push(t.entry.text)):(o(),i.push(t));o(),e.entries=i}function Fl(e){if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}}var Il=e=>e.kind===`message`||e.kind===`reasoning`||e.kind===`tool`,Ll=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function Rl(e){if(!kl(e)||!Array.isArray(e.todos))return;let t=[];for(let n of e.todos){if(!kl(n)||typeof n.content!=`string`)return;t.push({content:n.content,status:Ll.has(n.status)?n.status:`pending`,...typeof n.activeForm==`string`?{activeForm:n.activeForm}:{}})}return t}function zl(e,t={}){let n=[],r=new Map,i,a=0,o,s,c=e=>{a+=1;let t={id:e===void 0?`turn-fallback-${a}`:`turn-seq-${e}`,entries:[],v2Items:!1};return n.push(t),t},l=()=>n.at(-1)??c(),u=jl(t.runner),d=new WeakSet,f=(e,t)=>{let n=l();u===void 0||d.has(n)||!Tl(e)||(d.add(n),n.entries.push({origin:`meta`,entry:{kind:`agent-update-required`,id:`${t}:update`,provider:u}}))},p=(e,t)=>Ve(e.stepId,t),m=(e,t,n)=>{let i={...t};if(!e.v2Items){e.v2Items=!0;for(let t of e.entries)t.origin===`v1`&&t.entry.kind===`tool`&&r.delete(t.entry.id);e.entries=e.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`tool`))}let a=r.get(n);if(a&&a.turn===e){a.entry.entry=i,r.set(n,a);return}let o={origin:`v2`,entry:i};e.entries.push(o),r.set(n,{turn:e,entry:o})};for(let t of e)switch(s=Al(t.ts)??s,t.type){case`user-message`:{let e=$(t.text)??``;o&&!o.resolved&&(o.resolved=!0,e!==``&&(o.answer=e),o=void 0);let n=c(t.seq),r=Al(t.ts);n.userMessage={text:e,imageCount:typeof t.imageCount==`number`?t.imageCount:0,images:Array.isArray(t.images)?t.images.filter(e=>typeof e==`string`):[],...r===void 0?{}:{ts:r}},r!==void 0&&(n.startedAt=r);break}case`turn.started`:{let e=$(t.turnId),r=n.at(-1),i=r&&r.turnId===void 0&&!r.v2Items?r:c(t.seq);i.turnId=e;let a=Al(t.ts);i.startedAt===void 0&&a!==void 0&&(i.startedAt=a);break}case`turn.completed`:{let e=$(t.turnId),r;for(let t=n.length-1;t>=0&&!r;--t)n[t].turnId===e&&(r=n[t]);let i=r??n.at(-1);if(i){let e=Al(t.ts);i.completed={stopReason:$(t.stopReason)??`end_turn`,...typeof t.costUsd==`number`?{costUsd:t.costUsd}:{},...e===void 0?{}:{ts:e}}}break}case`item.started`:case`item.updated`:case`item.completed`:{if(!kl(t.item))break;let e=t.item.kind,n=t.item.id;if(e!==`message`&&e!==`reasoning`&&e!==`tool`||typeof n!=`string`||n===``)break;let i=t.item,a=p(t,i.id);m(r.get(a)?.turn??l(),i,a);break}case`item.delta`:{let e=$(t.itemId)??``,n=r.get(p(t,e)),i=$(t.delta)??``;if(!n||i===``||!Il(n.entry.entry))break;let a=n.entry.entry;t.field===`output`&&a.kind===`tool`?a.output=(a.output??``)+i:t.field!==`output`&&a.kind!==`tool`&&(a.text+=i);break}case`text`:{let e=l(),n=$(t.text)??``;if(n===``)break;e.entries.push({origin:`v1`,entry:{kind:`message`,id:`v1:${t.seq}`,role:`assistant`,text:n}});break}case`tool-call`:{let e=l();if(e.v2Items)break;let n=$(t.tool)??`Tool`;if(Bl.has(n))break;let i=ni(n,t.input);if(i.toolKind===`plan`){let n=Rl(t.input);n!==void 0&&(e.planEntries=n)}let a={kind:`tool`,id:$(t.id)??`v1:${t.seq}`,name:n,toolKind:i.toolKind,title:i.title,status:`running`,input:t.input},o={origin:`v1`,entry:a};e.entries.push(o),r.set(a.id,{turn:e,entry:o});break}case`tool-result`:{let e=r.get($(t.toolCallId)??``);if(!e||e.turn.v2Items||e.entry.origin!==`v1`)break;let n=e.entry.entry;if(n.kind!==`tool`)break;n.status=`completed`,n.output=Fl(t.result);break}case`note`:case`lifecycle`:{let e=$(t.message)??``;if(e===``)break;let n=t.tone===`danger`?`danger`:`dim`;l().entries.push({origin:`meta`,entry:{kind:`note`,id:`v1:${t.seq}`,text:e,tone:n}});break}case`error`:{let e=$(t.message)??``;if(e===``)break;l().entries.push({origin:`meta`,entry:{kind:`note`,id:`v1:${t.seq}`,text:e,tone:`danger`}}),f(e,`v1:${t.seq}`);break}case`session.error`:{let e=$(t.message)??``;if(e===``)break;l().entries.push({origin:`meta`,entry:{kind:`note`,id:`v2:${t.seq}`,text:e,tone:`danger`}}),f(e,`v2:${t.seq}`);break}case`session.started`:u=jl(t.backend)??u;break;case`step-end`:{if(t.status!==`failed`)break;let e=$(t.error)?` — ${$(t.error)}`:``;l().entries.push({origin:`meta`,entry:{kind:`note`,id:`v1:${t.seq}`,text:`step ${$(t.stepId)??`?`} failed${e}`,tone:`danger`}});break}case`check-output`:{let e=$(t.command)??`check`,n=typeof t.exitCode==`number`?t.exitCode:-1,r={kind:`tool`,id:`v1:${t.seq}`,name:`check`,toolKind:`execute`,title:`Ran ${e}`,status:n===0?`completed`:`failed`,output:$(t.text)??``,exitCode:n};l().entries.push({origin:`meta`,entry:r});break}case`provider-auth-required`:{let e=jl(t.provider),n=$(t.authFailureId);if(e===void 0||n===void 0||n.length<1||n.length>128)break;let r=$(t.profileId);l().entries.push({origin:`meta`,entry:{kind:`provider-auth-required`,id:`v1:${t.seq}`,provider:e,authFailureId:n,...r!==void 0&&r.length<=128?{profileId:r}:{}}});break}case`image`:{let e=$(t.url);if(e===void 0)break;let n={kind:`image`,id:`v1:${t.seq}`,url:e},r=$(t.name);r!==void 0&&(n.name=r),l().entries.push({origin:`meta`,entry:n});break}case`plan.updated`:Array.isArray(t.entries)&&(l().planEntries=t.entries);break;case`session.ended`:i={reason:$(t.reason)??`end_turn`,...$(t.message)===void 0?{}:{message:$(t.message)}};break;case`ask.requested`:{let e=$(t.requestId);if(e===void 0||!Array.isArray(t.questions))break;let n=t.questions,r=n.every(Ml)?n:n.filter(Ml);if(r.length===0)break;let i={kind:`ask`,id:e,questions:r,resolved:!1,...t.source===`workflow`?{fromWorkflow:!0}:{}};l().entries.push({origin:`meta`,entry:i}),o=i;break}case`step-start`:case`token-usage`:case`cost`:case`turn-end`:case`done`:case`session`:break;default:break}for(let e of n){if(!e.v2Items)continue;let t=new Set;for(let{origin:n,entry:r}of e.entries)n===`v2`&&r.kind===`message`&&t.add(Nl(r.text,!0).trim());t.size!==0&&(e.entries=e.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`message`&&t.has(Nl(e.entry.text,!0).trim()))),Pl(e))}return{turns:n.map((e,r)=>{let i=e.entries.some(({entry:e})=>e.kind===`ask`),a=t.activeTurn===!0&&r===n.length-1;return{id:e.id,...e.turnId===void 0?{}:{turnId:e.turnId},...e.userMessage===void 0?{}:{userMessage:e.userMessage},...e.startedAt===void 0?{}:{startedAt:e.startedAt},...e.planEntries===void 0?{}:{planEntries:e.planEntries},...e.completed===void 0?{}:{completed:e.completed},items:e.entries.map(({entry:e})=>e.kind===`message`&&e.role===`assistant`?{...e,text:Nl(e.text,i||a)}:e)}}),...i===void 0?{}:{sessionEnded:i},...s===void 0?{}:{lastEventAt:s}}}var Bl=new Set([`subAgentActivity`,`collabAgentToolCall`,`collabToolCall`]);function Vl({run:e,thread:t,currentThread:n=t,history:r,onMarkedUnread:i,embedded:a=!1}){let o=Ol(e.status,e.error,h(e)),s=(0,Z.useCallback)(()=>i?.(e.id),[i,e.id]),c=El(n),u=l(e),d=c!==void 0&&c.length>0?yc(c):void 0,f=e.status===`running`||e.status===`waiting`,p=e.status===`queued`,m=fo(e),g=!f&&!p&&m.available,_=g&&m.canContinue,y=Ea(e,m.continueWith,{surface:null}),b=!!e.worktreeLifecycle?.activeOperationId,x=!f&&e.status!==`queued`,S=(0,Z.useMemo)(()=>rc(n.turns,x),[n.turns,x]),C=(0,Z.useMemo)(()=>ic(n.turns),[n.turns]),[w,T]=(0,Z.useState)(void 0),[E,D]=(0,Z.useState)(e.id);E!==e.id&&(D(e.id),T(void 0));let O=(0,Z.useMemo)(()=>w===void 0?void 0:uc(n.turns,w,x),[n.turns,w,x]),k=(0,Z.useMemo)(()=>w===void 0?[]:dc(n.turns,w),[n.turns,w]),A=Yt(e.id,`composer`),ee=so(e.id),{mutateAsync:j}=le(e.id),{mutateAsync:te}=se(e.id),{mutateAsync:M}=z(e.id),N=(0,Z.useMemo)(()=>p?{onEditTask:async e=>{await j({task:e})},onEditMessage:(e,t)=>te({msgId:e,message:{text:t}}).then(()=>void 0),onRemoveMessage:e=>M(e).then(()=>void 0)}:void 0,[p,j,te,M]),F=(0,Z.useMemo)(()=>Mc(e,t),[e,t]),I=(0,Z.useMemo)(()=>Fc(F,e.id),[F,e.id]),L=(0,Z.useCallback)(t=>(0,Q.jsx)(xl,{ask:t,run:e}),[e]),re=(0,Z.useMemo)(()=>{if(N===void 0)return;let t={task:{onEdit:N.onEditTask,editLabel:`Edit the prompt`,draftSurface:`task-prompt`}};for(let n of e.queuedMessages??[])t[`queued:${n.id}`]={onEdit:e=>N.onEditMessage(n.id,e),onRemove:()=>N.onRemoveMessage(n.id),draftSurface:`message:${n.id}`};return t},[N,e.queuedMessages]),ie=ne(e,v()),{search:R}=we(),B=$o(R,I.length),V=Oc(`${e.id}:main`,{onLoadOlder:r?.hasOlder?r.loadOlder:void 0,onJumpToLatest:r?.jumpToLatest,rowKeys:I.map(({key:e})=>e)});return je(V.restickIfStuck),(0,Q.jsxs)(`div`,{"data-route":`task-thread`,"data-run-id":e.id,className:`flex min-h-full flex-col`,children:[a?null:(0,Q.jsx)(Wt,{run:e,planTally:d,onMarkedUnread:s,continuationEngine:_?m.pills:void 0}),(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[var(--measure)] flex-1 flex-col gap-2.5 px-3 py-3 md:gap-3.5 md:px-6 md:py-5`,children:[e.worktreeLifecycle?(0,Q.jsx)(Tn,{worktreeId:e.worktreeLifecycle.worktreeId,operationId:e.worktreeLifecycle.activeOperationId,worktreePath:e.worktreePath,taskTitle:e.title??e.task}):null,r?(0,Q.jsx)(Kl,{hasOlder:r.hasOlder,loading:r.isFetchingOlder,error:r.olderError,fallback:r.fallback,retainedPages:r.retainedPages,onLoad:V.loadOlder}):null,(0,Q.jsx)(Ic,{runId:e.id,viewId:`main`,sections:F,mode:`document`,renderAsk:L,messageActions:re,scrollControls:V,renderMode:B,rowModels:I}),t.turns.length===0?e.status===`queued`?(0,Q.jsx)(Jl,{run:e}):(0,Q.jsx)(`p`,{"data-slot":`thread-empty`,className:`py-6 text-center text-xs text-soft-foreground`,children:`No session events yet.`}):null,e.status===`running`&&!b?(0,Q.jsx)(Ps,{since:ql(e,n),lastActivityAt:n.lastEventAt}):null,(0,Q.jsx)(Po,{run:e}),o&&o.state===`closed`?(0,Q.jsxs)(`div`,{"data-slot":`thread-footer`,"data-state":o.state,className:q(`mt-auto flex items-center gap-2 border-t border-border pt-3 text-xs`,o.tone===`danger`?`text-danger`:`text-soft-foreground`),children:[(0,Q.jsx)(Ul,{label:o.label,offerContinue:o.tone===`danger`&&!e.autoResumeAt,onContinue:g?()=>y(``,[]):void 0,blockedReason:_?void 0:m.providerPending?`Checking the agent provider…`:m.reason??`Connect an agent provider to continue.`}),me(P(e))?(0,Q.jsx)(`a`,{"data-slot":`pr-link`,href:P(e),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`PR ↗`}):null,me(ie)?(0,Q.jsx)(`a`,{"data-slot":`issue-link`,href:ie,target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`Issue ↗`}):null]}):null,e.status===`review`&&!b?(0,Q.jsx)(ll,{run:e,diffComments:ee}):null]}),(0,Q.jsx)(ml,{status:e.status}),(0,Q.jsx)(ol,{runId:e.id,renderAsk:L,agent:O,entries:k,onClose:()=>T(void 0)}),(0,Q.jsxs)(vo,{overlay:V.pillVisible?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-12 flex justify-center`,children:(0,Q.jsx)(jc,{onJump:V.jumpToLatest})}):null,children:[(0,Q.jsx)(mc,{runId:e.id,agents:S,onSelect:T},`agents:${e.id}`),(0,Q.jsx)(wc,{skills:C}),c!==void 0&&c.length>0?(0,Q.jsx)(xc,{runId:e.id,entries:c,settled:x},e.id):null,(0,Q.jsx)(No,{run:e}),!b&&u?(0,Q.jsxs)(`div`,{"data-slot":`budget-hint`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(jr,{tone:`pending`,pulse:!0}),`Budget reached — spent $`,u.spent.toFixed(2),` of $`,u.ceiling.toFixed(2),`; send a message to continue.`,e.status===`waiting`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsx)(Gl,{runId:e.id})]}):null]}):!b&&e.status===`waiting`?(0,Q.jsxs)(`div`,{"data-slot":`paused-hint`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(jr,{tone:`pending`,pulse:!0}),`The agent is paused, waiting for your reply`,(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsx)(Gl,{runId:e.id})]}):null,p?(0,Q.jsxs)(`div`,{"data-slot":`queued-hint`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(jr,{tone:`pending`}),`Messages you add now are folded into the prompt before the run starts.`]}):null,b?(0,Q.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,children:`Resolve the worktree operation above before continuing this task.`}):(0,Q.jsx)(_o,{run:e,draft:A,diffComments:ee,continueAction:m,getMentionCandidates:()=>Dl(t)})]})]})}var Hl=/— continue to /i;function Ul({label:e,offerContinue:t=!1,onContinue:n,blockedReason:r}){let i=n?Hl.exec(e):null;if(!n)return(0,Q.jsx)(`span`,{children:e});if(!i)return t?(0,Q.jsxs)(`span`,{children:[e,` `,(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),` `,(0,Q.jsx)(Wl,{onContinue:n,blockedReason:r})]}):(0,Q.jsx)(`span`,{children:e});let a=e.slice(0,i.index),o=e.slice(i.index+i[0].length);return(0,Q.jsxs)(`span`,{children:[a,`—`,` `,(0,Q.jsx)(Wl,{onContinue:n,blockedReason:r}),` to `,o]})}function Wl({onContinue:e,blockedReason:t}){let[n,r]=(0,Z.useState)(!1);return(0,Q.jsx)(`button`,{type:`button`,"data-slot":`footer-continue`,disabled:n||t!==void 0,title:t??`Reopen the session and pick up where it stopped`,onClick:()=>{r(!0),e().catch(e=>Y(e instanceof Error?e.message:String(e),{tone:`danger`})).finally(()=>r(!1))},className:`rounded-sm font-semibold underline underline-offset-2 hover:brightness-125 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none disabled:cursor-not-allowed disabled:no-underline disabled:opacity-60`,children:`Continue`})}function Gl({runId:e}){let t=Ft(e);return(0,Q.jsx)(`button`,{type:`button`,"data-slot":`end-session`,title:`Close the session — the task finishes (or goes to review if it changed files)`,disabled:t.isPending,onClick:()=>t.mutate(),className:`rounded-sm font-medium text-foreground underline-offset-2 hover:underline focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-60`,children:`End session`})}function Kl({hasOlder:e,loading:t,error:n,fallback:r,retainedPages:i,onLoad:a}){return r?(0,Q.jsx)(`p`,{"data-slot":`history-fallback`,className:`text-center text-xs text-soft-foreground`,role:`status`,children:`Progressive history is unavailable; showing the complete session.`}):!e&&!n?(0,Q.jsxs)(`div`,{"data-slot":`history-start`,className:`flex items-center gap-3 text-[11px] text-soft-foreground`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`}),`Start of session`,(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`})]}):(0,Q.jsxs)(`div`,{"data-slot":`history-boundary`,"data-retained-pages":i,"aria-busy":t,className:`flex min-h-8 items-center justify-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:t,className:`rounded-md px-3 py-1.5 font-medium hover:bg-muted disabled:cursor-wait`,children:t?`Loading 100 earlier items…`:n?`Couldn’t load earlier items · Retry`:`Load 100 earlier items`}),(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:t?`Loading earlier session history`:n||``})]})}function ql(e,t){let n=t.turns.at(-1);return n===void 0?e.startedAt:n.completed===void 0?n.startedAt??e.startedAt:n.completed.ts??e.startedAt}function Jl({run:e}){let t=it(W().data??[],e.id);return(0,Q.jsxs)(`div`,{"data-slot":`queued-state`,className:`flex flex-col items-center gap-1.5 py-10 text-center`,children:[(0,Q.jsx)(jr,{tone:`pending`,pulse:!0}),(0,Q.jsxs)(`p`,{className:`text-[13px] font-medium`,children:[`Waiting for a free agent slot`,t===void 0?``:` — #${t} in queue`]}),(0,Q.jsxs)(`p`,{className:`text-xs text-soft-foreground`,children:[e.workflow,` · starts automatically when a slot frees up`]})]})}var Yl=(0,Z.createContext)(null);function Xl(){return(0,Z.useContext)(Yl)}function Zl(e,t){let n=(0,Z.useRef)(null),[r,i]=(0,Z.useState)(null);return(0,Z.useLayoutEffect)(()=>{if(!e){i(null);return}let t=n.current?.closest(`[data-slot="panel"]`)??n.current?.closest(`[data-slot="main"]`);if(!t)return;let r=()=>{let e=t.getBoundingClientRect();i({top:e.top,left:e.left,width:e.width,height:e.height})};r();let a=new ResizeObserver(r);return a.observe(t),window.addEventListener(`resize`,r),()=>{a.disconnect(),window.removeEventListener(`resize`,r)}},[e]),(0,Z.useEffect)(()=>{if(!e)return;let n=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]`)||t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),{ref:n,covering:e&&r!==null,style:e&&r?r:void 0}}function Ql({className:e}){let t=Xl();return t?.maximized?(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`xs`,"data-action":`exit-full-view`,title:`Exit full view (Esc)`,onClick:t.toggle,className:q(`shrink-0 text-foreground`,e),children:[(0,Q.jsx)(si,{"aria-hidden":`true`}),`Exit full view`]}):null}var $l=[];function eu(e){return Array.isArray(e)?e.flatMap(e=>{let t=fe.safeParse(e);return t.success?[t.data]:[]}):[]}function tu(){let e=G(),t=x(),n=Z.useRef(0),r=Z.useRef(Promise.resolve()),a=t.data?.savedLayouts,o=Z.useMemo(()=>a?eu(a).filter(e=>!wt(e.name)&&e.columns.every(e=>Dt(e.view))):$l,[a]),s=Z.useCallback(t=>{let a=e.getQueryData(p.uiState);if(a===void 0)return;let o=t(eu(a.savedLayouts)).slice(0,50);e.setQueryData(p.uiState,{...a,savedLayouts:o});let s=++n.current,c=r.current.then(async()=>{let t=await i({savedLayouts:o},{keepalive:!0});s===n.current&&e.setQueryData(p.uiState,t)});r.current=c.catch(t=>{Y(t instanceof Error?t.message:String(t),{tone:`danger`}),s===n.current&&e.invalidateQueries({queryKey:p.uiState})})},[e]);return{saved:o,save:Z.useCallback(e=>s(t=>{let n={name:e.name,columns:e.columns.map(({view:e,width:t})=>({view:e,width:t}))},r=t.findIndex(t=>t.name===e.name);return r<0?[...t,n]:t.map((e,t)=>t===r?n:e)}),[s]),remove:Z.useCallback(e=>s(t=>t.filter(t=>t.name!==e)),[s])}}var nu=400,ru=1500,iu=2e3,au=3e4;function ou(e){let[t,n]=(0,Z.useState)(Bt),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),[s,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(0),f=(0,Z.useRef)(null),p=(0,Z.useRef)({taskId:e,state:null});p.current.taskId!==e&&(p.current={taskId:e,state:null},n(Bt()),i(!1),o(!1),l(!1),d(0)),(0,Z.useEffect)(()=>{let t=!1,r=null;f.current=null;let a=t=>{p.current={taskId:e,state:t},_.current=t,g.current={taskId:e,state:t},n(t),i(!0)},o=async n=>{let i;try{i=await c(e)}catch{if(t)return;n===0&&a(Bt()),l(!0),r=setTimeout(()=>void o(n+1),Math.min(au,iu*2**n));return}t||(f.current=e,m.current&&clearTimeout(m.current),m.current=null,l(!1),!(n>0&&i.layouts===null)&&(a(i.layouts===null?Bt():nn(i.layouts)),n>0&&d(e=>e+1)))};return o(0),()=>{t=!0,r&&clearTimeout(r)}},[e]);let m=(0,Z.useRef)(null),h=(0,Z.useRef)(0),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useCallback)((e,t,n=!1)=>{if(f.current!==e)return;_.current=t;let r=h.current+=1,i=t=>{r===h.current&&p.current.taskId===e&&o(t)},a=o=>{(n?K(e,t,{keepalive:n}):K(e,t)).then(()=>i(!1)).catch(e=>{if(r===h.current){if(e?.status===400)return i(!0);if(o>0){setTimeout(()=>{r===h.current&&a(o-1)},ru);return}i(!0)}})};a(1)},[]),y=(0,Z.useCallback)((e=!1)=>{let t=g.current;!t||t.state===_.current||(m.current&&clearTimeout(m.current),m.current=null,v(t.taskId,t.state,e))},[v]);(0,Z.useEffect)(()=>{if(!(!r||p.current.taskId!==e||t===p.current.state))return g.current={taskId:e,state:t},m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null,v(e,t)},nu),()=>{m.current&&clearTimeout(m.current),m.current=null}},[r,v,e,t,s]),(0,Z.useEffect)(()=>{let e=()=>y(!0);return window.addEventListener(`pagehide`,e),()=>{window.removeEventListener(`pagehide`,e),y()}},[y,e]);let b=(0,Z.useCallback)(e=>{n(t=>t.active?e(t,t.active):t)},[]);return{state:t,ready:r,saveFailed:a,loadFailed:s,replaced:u,layout:Tt(t),addLayout:(0,Z.useCallback)(e=>n(t=>zt(t,e)),[]),closeLayout:(0,Z.useCallback)(e=>n(t=>yt(t,e)),[]),selectLayout:(0,Z.useCallback)(e=>n(t=>ot(t,e)),[]),renameLayout:(0,Z.useCallback)((e,t)=>n(n=>an(n,e,t)),[]),applySaved:(0,Z.useCallback)(e=>n(t=>Gt(t,e)),[]),keepAs:(0,Z.useCallback)(e=>n(t=>Vt(t,e)),[]),addColumn:(0,Z.useCallback)(e=>b((t,n)=>Jt(t,n,e)),[b]),closeColumn:(0,Z.useCallback)(e=>b((t,n)=>jt(t,n,e)),[b]),setColumnView:(0,Z.useCallback)((e,t)=>b((n,r)=>en(n,r,e,t)),[b]),resizeColumns:(0,Z.useCallback)((e,t)=>b((n,r)=>xt(n,r,e,t)),[b]),moveColumn:(0,Z.useCallback)((e,t)=>b((n,r)=>At(n,r,e,t)),[b]),openDeepLink:(0,Z.useCallback)(e=>n(t=>vt(t,e)),[]),dropView:(0,Z.useCallback)((e,t,r)=>n(n=>St(n,e,t,r)),[]),setColumnBrowser:(0,Z.useCallback)((e,t)=>b((n,r)=>qe(n,r,e,t)),[b]),openInBrowser:(0,Z.useCallback)(e=>{let t=g.current?.state;return!t||Qt(t,e)===null?!1:(n(t=>Qt(t,e)??t),!0)},[]),openBeside:(0,Z.useCallback)(e=>{let t=g.current?.state??p.current.state;if(!t)return null;let r=kt(t,e);return r?(n(t=>kt(t,e)?.state??t),{name:r.name,index:r.index}):null},[])}}function su({view:e,columns:t,onDrop:n}){let[r,i]=(0,Z.useState)(null),a=t.length>=tt;return(0,Q.jsx)(`div`,{"data-slot":`view-drop-zones`,className:`absolute inset-0 z-30 flex gap-px bg-background/40 backdrop-blur-[1px]`,children:(t.length===0?[{width:100,zones:[{key:`only`,at:0,mode:`insert`,label:`Open ${Xe(e)} here`}]}]:t.map((t,n)=>{let r={key:`replace:${n}`,at:n,mode:`replace`,label:t.view===e?Xe(e):`Replace ${Xe(t.view)}`,hint:a?`${tt} columns is the limit`:void 0},i=a?[r]:[{key:`insert:${n}`,at:n,mode:`insert`,label:`Beside`,hint:`left`},r,{key:`insert:${n+1}:${n}`,at:n+1,mode:`insert`,label:`Beside`,hint:`right`}];return{width:t.width,zones:i}})).map((e,t)=>(0,Q.jsx)(`div`,{style:{flexBasis:`${e.width}%`},className:q(`grid min-w-0 grow gap-1.5 p-2.5`,e.zones.length===3?`grid-cols-[26%_1fr_26%]`:`grid-cols-1`),children:e.zones.map(e=>(0,Q.jsxs)(`div`,{"data-drop-zone":e.mode,onDragOver:t=>{t.dataTransfer.types.includes(`text/cez-view`)&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`,i(e.key))},onDragLeave:()=>i(t=>t===e.key?null:t),onDrop:t=>{let r=t.dataTransfer.getData(qr);Dt(r)&&(t.preventDefault(),n(r,e.at,e.mode))},className:q(`flex flex-col items-center justify-center rounded-lg border-[1.5px] border-dashed border-border bg-background/80 p-2 text-center text-xs font-medium text-muted-foreground transition-colors`,r===e.key&&`border-foreground/60 bg-muted text-foreground`),children:[e.label,e.hint?(0,Q.jsx)(`span`,{className:`text-[11px] font-normal opacity-80`,children:e.hint}):null]},e.key))},t))})}var cu=1024;function lu({columns:e,actions:t,renderView:n,headerExtras:r}){let i=He(cu),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(0),[c,l]=(0,Z.useState)(null),u=c===null?null:Math.min(c,e.length),d=e.length+(u===null?0:1)<tt,f=n=>{if(u===null)return;let r=u;l(null),t.addColumn(n),r<e.length&&t.moveColumn(e.length,r)},p=(n,r)=>(0,Q.jsx)(du,{index:n,column:r,count:e.length,actions:t});if(e.length===0)return(0,Q.jsx)(`div`,{"data-slot":`workspace-columns`,className:`flex min-h-0 flex-1 flex-col`,children:(0,Q.jsx)($e,{onPick:t.addColumn})});let m=e.length+(u===null?0:1),h=e=>u===null?e.width:100/m,g=(0,Q.jsxs)(`header`,{className:`flex h-8 shrink-0 items-center gap-1.5 border-b border-border/70 bg-background pl-4 pr-1.5 text-xs font-medium text-muted-foreground`,children:[(0,Q.jsx)(Mn,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`New window`}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close new window`,title:`Close`,onClick:()=>l(null),className:`text-soft-foreground`,children:(0,Q.jsx)(hr,{"aria-hidden":`true`,className:`size-3.5`})})]}),_=u===null?null:(0,Q.jsxs)(`div`,{"data-slot":`workspace-column`,"data-pending":``,className:`relative flex min-w-0 flex-col border-l border-border/70 first:border-l-0`,style:{width:`${100/m}%`},children:[g,(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,Q.jsx)($e,{scope:`window`,onPick:f})})]},`pending`);if(!i){let i=e.map((e,t)=>t);u!==null&&i.splice(u,0,`pending`);let a=Math.min(o,i.length-1),c=i[a],m=c===`pending`?null:e[c];return(0,Q.jsxs)(`div`,{"data-slot":`workspace-columns`,"data-narrow":``,className:`flex min-h-0 flex-1 flex-col`,children:[i.length>1?(0,Q.jsx)(kr,{value:String(a),onValueChange:e=>s(Number(e)),className:`shrink-0 gap-0`,children:(0,Q.jsx)(Or,{"aria-label":`Windows of this layout`,className:`grid w-full auto-cols-fr grid-flow-col gap-1 rounded-none border-b border-border bg-transparent px-3 py-1.5 group-data-[orientation=horizontal]/tabs:h-auto`,children:i.map((t,n)=>{let r=t===`pending`?Mn:Ge[e[t].view];return(0,Q.jsxs)(Dr,{value:String(n),className:`h-auto min-w-0 rounded-md border-0 px-2 py-1 text-xs data-[state=active]:bg-muted data-[state=active]:font-medium group-data-[variant=default]/tabs-list:data-[state=active]:shadow-none`,children:[(0,Q.jsx)(r,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:t===`pending`?`New window`:Xe(e[t].view)})]},n)})})}):null,m===null?(0,Q.jsxs)(Q.Fragment,{children:[g,(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,Q.jsx)($e,{scope:`window`,onPick:f})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(uu,{index:c,column:m,count:e.length,actions:t,menu:e.length>1?p(c,m):null,onSplit:()=>{l(c+1),s(c+1)},canSplit:d,grip:!1,extras:r?.(m.view,c)}),(0,Q.jsx)(`div`,{"data-slot":`main`,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:n(m.view,c,m)})]})]})}return(0,Q.jsxs)(`div`,{ref:a,"data-slot":`workspace-columns`,className:`flex min-h-0 flex-1 items-stretch`,children:[e.flatMap((i,o)=>[o===u?_:null,(0,Q.jsxs)(`div`,{"data-slot":`workspace-column`,"data-view":i.view,className:`relative flex min-w-0 flex-col border-l border-border/70 first:border-l-0`,style:{width:`${h(i)}%`},children:[o>0&&u===null?(0,Q.jsx)(fu,{index:o-1,width:e[o-1].width,pair:e[o-1].width+i.width,rowRef:a,onResize:t.resizeColumns}):null,(0,Q.jsx)(uu,{index:o,column:i,count:e.length,actions:t,menu:e.length>1?p(o,i):null,onSplit:()=>l(o+1),canSplit:d,trailing:o===e.length-1?(0,Q.jsx)(Ql,{className:`ml-1.5`}):null,extras:r?.(i.view,o)}),(0,Q.jsx)(`div`,{"data-slot":`main`,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(Yl.Provider,{value:null,children:n(i.view,o,i)})})]},o)]),u===e.length?_:null]})}function uu({index:e,column:t,count:n,actions:r,menu:i,trailing:a,onSplit:o,canSplit:s=!0,grip:c=!0,extras:l}){let[u,d]=(0,Z.useState)(!1),f=Ge[t.view],p=t=>{t.dataTransfer.setData(`text/cez-column`,String(e)),t.dataTransfer.effectAllowed=`move`};return(0,Q.jsxs)(`header`,{"data-slot":`workspace-column-header`,onDragOver:e=>{e.dataTransfer.types.includes(`text/cez-column`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,d(!0))},onDragLeave:()=>d(!1),onDrop:t=>{if(d(!1),!t.dataTransfer.types.includes(`text/cez-column`))return;let n=t.dataTransfer.getData(`text/cez-column`),i=Number(n);n===``||!Number.isInteger(i)||(t.preventDefault(),r.moveColumn(i,e))},className:q(`group/column flex h-8 shrink-0 items-center gap-0.5 border-b border-border/70 bg-background pl-4 pr-1.5`,u&&`bg-muted`),children:[n>1&&c?(0,Q.jsx)(`span`,{draggable:!0,onDragStart:p,title:`Drag to reorder`,className:`-ml-2 flex h-full shrink-0 cursor-grab items-center text-soft-foreground/70 active:cursor-grabbing`,children:(0,Q.jsx)(Sn,{"aria-hidden":`true`,className:`size-3.5`})}):null,n===1?null:(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)(Yn,{asChild:!0,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,"data-action":`change-view`,"aria-label":`${Xe(t.view)} — change view`,className:`-ml-1.5 h-6 gap-1.5 px-1.5 text-xs font-medium text-muted-foreground hover:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground`,children:[(0,Q.jsx)(f,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:Xe(t.view)}),(0,Q.jsx)(In,{"aria-hidden":`true`,className:`size-3 shrink-0 opacity-60`})]})}),(0,Q.jsxs)(qn,{align:`start`,className:`w-48`,children:[(0,Q.jsx)(Un,{children:`Change view`}),(0,Q.jsx)(dt,{onPick:t=>r.setColumnView(e,t),disabled:t.view})]})]}),(0,Q.jsx)(`span`,{draggable:n>1&&c,onDragStart:p,className:q(`h-full min-w-0 flex-1`,n>1&&c&&`cursor-grab active:cursor-grabbing`)}),l,o?(0,Q.jsx)(zn,{children:(0,Q.jsxs)(Bn,{children:[(0,Q.jsx)(Ln,{asChild:!0,children:(0,Q.jsx)(`span`,{className:`inline-flex`,children:(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-xs`,"data-action":`split-view`,"aria-label":`Split view`,disabled:!s,onClick:o,className:`text-soft-foreground hover:text-foreground`,children:(0,Q.jsx)(Mt,{"aria-hidden":`true`,className:`size-3.5`})})})}),(0,Q.jsx)(Rn,{side:`bottom`,children:s?`Split view (\\)`:`At most ${tt} windows`})]})}):null,i,n>1?(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${Xe(t.view)}`,title:`Close view`,onClick:()=>r.closeColumn(e),className:`text-soft-foreground`,children:(0,Q.jsx)(hr,{"aria-hidden":`true`,className:`size-3.5`})}):null,a]})}function du({index:e,column:t,count:n,actions:r}){return(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)(Yn,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon-sm`,className:`size-6 shrink-0 text-soft-foreground hover:text-foreground`,"aria-label":`Column menu ${Xe(t.view)}`,children:(0,Q.jsx)(at,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,Q.jsxs)(qn,{align:`end`,className:`w-52`,children:[n>1?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Gn,{disabled:e===0,onSelect:()=>r.moveColumn(e,e-1),children:[(0,Q.jsx)(gn,{"aria-hidden":`true`}),`Move left`]}),(0,Q.jsxs)(Gn,{disabled:e===n-1,onSelect:()=>r.moveColumn(e,e+1),children:[(0,Q.jsx)(yn,{"aria-hidden":`true`}),`Move right`]})]}):null,(0,Q.jsx)(Wn,{}),(0,Q.jsxs)(Gn,{onSelect:()=>r.closeColumn(e),children:[(0,Q.jsx)(hr,{"aria-hidden":`true`}),`Close view`]})]})]})}function fu({index:e,width:t,pair:n,rowRef:r,onResize:i}){let a=(0,Z.useRef)(null),o=e=>{e.button===0&&(a.current={x:e.clientX,width:t},e.currentTarget.setPointerCapture(e.pointerId),e.preventDefault(),e.currentTarget.focus())},s=n=>{let o=a.current,s=r.current;if(!o||!s)return;let c=s.getBoundingClientRect().width;c<=0||i(e,o.width+(n.clientX-o.x)/c*100-t)},c=e=>{a.current&&(a.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,Q.jsx)(`div`,{"data-slot":`column-divider`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize column ${e+1}`,"aria-valuenow":Math.round(t),"aria-valuemin":Math.round(Kt(n)),"aria-valuemax":Math.round(n-Kt(n)),tabIndex:0,onPointerDown:o,onPointerMove:s,onPointerUp:c,onPointerCancel:c,onKeyDown:t=>{let n=t.shiftKey?10:2,r=t.key===`ArrowLeft`?-n:t.key===`ArrowRight`?n:null;r!==null&&(t.preventDefault(),i(e,r))},title:`Drag to resize — arrow keys adjust precisely`,className:`absolute inset-y-0 -left-[5px] z-20 w-[9px] cursor-col-resize touch-none bg-transparent transition-colors hover:bg-violet/40 focus-visible:bg-violet/60 focus-visible:outline-none`})}var pu=(0,Z.lazy)(()=>ge(()=>import(`./terminal-drawer-CcPOjWwP.js`).then(e=>({default:e.TerminalDrawer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]))),mu=(0,Z.lazy)(()=>ge(()=>import(`./task-graph-BgHk8Y3v.js`).then(e=>({default:e.TaskGraphView})),__vite__mapDeps([20,1,2,3,4,5,21,22,23,8,24,25,26,14,27,28,29,9,10,30,31,11,32,33,34,35,15,36,37,38,39,40,12,13,41,42,17,43,44,45,6,7,46,47,48,49,16,50,51,52,53,54])));function hu({view:e}){let{id:t}=Ce(),n=D(t),r=(0,Z.useRef)(void 0);(0,Z.useEffect)(()=>{r.current!==t&&(r.current=void 0)},[t]);let i=(0,Z.useCallback)(e=>{r.current=e},[]),{mutate:a}=o();if((0,Z.useEffect)(()=>{n.data&&r.current!==n.data.id&&gt(n.data)&&a(n.data.id)},[a,n.data?.id,n.data?.status,n.data?.finishedAt,n.data?.seenAt,n.data?.archived,t]),n.isPending)return(0,Q.jsx)(gu,{view:e});if(n.isError){let e=n.error instanceof S&&n.error.status===404;return(0,Q.jsx)(`div`,{"data-route":`task-workspace`,className:`flex min-h-full flex-col`,children:(0,Q.jsx)(Fr,{icon:e?(0,Q.jsx)(mr,{}):(0,Q.jsx)(Ke,{}),tone:e?`neutral`:`danger`,title:e?`Task not found`:`Could not load this task`,subtitle:e?`No run has this id. It may have been deleted, or the link is from another machine.`:n.error.message,actions:(0,Q.jsx)(J,{asChild:!0,variant:`outline`,children:(0,Q.jsx)(Se,{to:`/`,children:`Back to tasks`})})})})}return(0,Q.jsx)(_u,{run:n.data,deepLinkView:e,onMarkedUnread:i})}function gu({view:e}){return e===`files`?(0,Q.jsx)(Rt,{tab:`files`}):e===`terminal`?(0,Q.jsx)(Rt,{tab:`terminal`}):e===`browser`?(0,Q.jsx)(Rt,{tab:`preview`}):e===`changes`||e===`commits`||e===`graph`?(0,Q.jsx)(Rt,{tab:`changes`}):(0,Q.jsx)(Dn,{})}function _u({run:e,deepLinkView:t,onMarkedUnread:n}){let r=ou(e.id),{openDeepLink:i,addLayout:a,closeLayout:o,selectLayout:s,setColumnBrowser:c,openInBrowser:l,applySaved:u,keepAs:d}=r,f=tu(),{save:p,remove:m}=f,h=r.state,g=(r.layout?.columns.length??0)>0,_=(0,Z.useCallback)(e=>{let t=ct(h,e);t&&(p(t),d(t.name))},[d,h,p]),v=te().data?.capabilities?.terminal===!0,y=(0,Z.useMemo)(()=>ht.filter(e=>e!==`terminal`||v),[v]),b=_e(),x=(0,Z.useRef)(null),S=(0,Z.useRef)(new Map),C=(0,Z.useRef)(e.id);C.current!==e.id&&(C.current=e.id,S.current=new Map,x.current=null),(0,Z.useEffect)(()=>{if(!r.ready)return;if(t){x.current?.runId!==e.id&&(x.current={runId:e.id,name:r.state.active});let n=S.current.get(t);n!==void 0&&r.state.layouts.some(e=>e.name===n)?s(n):i(t);return}let n=x.current;x.current=null,b===`POP`&&n&&n.runId===e.id&&n.name!==r.state.active&&s(n.name)},[t,r.ready,r.replaced,b,i,e.id,s]),(0,Z.useEffect)(()=>{if(!r.ready||!t||S.current.has(t))return;let e=r.layout;e&&e.columns.length===1&&e.columns[0]?.view===t&&S.current.set(t,e.name)},[t,r.layout,r.ready]);let w=(0,Z.useCallback)(()=>n(e.id),[n,e.id]),T=(0,Z.useMemo)(()=>rt.filter(t=>y.includes(t)&&(t!==`graph`||!!e.workflowDef)),[y,e.workflowDef]),E=r.ready?r.layout?Xt(r.layout):`session`:null,D=(0,Z.useMemo)(()=>r.state.layouts.filter(e=>Xt(e)===null),[r.state.layouts]),O=(0,Z.useCallback)(()=>a(),[a]),{hints:k,show:A}=Ze((0,Z.useMemo)(()=>lt(T),[T])),ee=ye(),[j,M]=(0,Z.useState)(null),N=(0,Z.useCallback)(e=>{setTimeout(()=>M(e),0)},[]),P=(0,Z.useCallback)(()=>M(null),[]),F=r.dropView,I=(0,Z.useRef)({runId:e.id,current:r.state.active,previous:null});I.current.runId===e.id?I.current.current!==r.state.active&&(I.current={runId:e.id,current:r.state.active,previous:I.current.current}):I.current={runId:e.id,current:r.state.active,previous:null};let L=(0,Z.useCallback)(e=>{if(E!==e)return null;let t=I.current.previous,n=t===null?void 0:r.state.layouts.find(e=>e.name===t);return n&&!(n.columns.length===1&&n.columns[0]?.view===e)?(s(n.name),n.columns.length):(i(e===`session`?`changes`:`session`),1)},[E,r.state.layouts,i,s]),ne=(0,Z.useCallback)((e,t,n)=>{if(M(null),n===`insert`&&L(e)!==null){F(e,t===0?0:tt,n);return}F(e,t,n)},[L,F]),re=(0,Z.useCallback)(e=>{let t=L(e)??r.layout?.columns.length??0;F(e,t,`insert`)},[L,F,r.layout?.columns.length]),ie=r.layout?.columns.length??0,R=E===null&&ie>1?r.closeColumn:void 0,[z,B]=(0,Z.useState)(()=>Mr(e.id)),V=(0,Z.useRef)(e.id);V.current!==e.id&&(V.current=e.id,B(Mr(e.id)));let H=(0,Z.useCallback)(t=>{B(n=>{let r={...n,...t};return Nr(e.id,r),r})},[e.id]),U=r.layout?.columns.some(e=>e.view===`terminal`)??!1,ae=xe(),oe=v&&z.open&&!U,[W,se]=(0,Z.useState)(!1),G=(0,Z.useRef)(e.id);G.current!==e.id&&(G.current=e.id,se(!1));let ce=(0,Z.useCallback)(()=>se(!1),[]),K=(0,Z.useCallback)(()=>se(e=>!e),[]),le=Zl(W,ce),ue=(0,Z.useMemo)(()=>({maximized:W,toggle:K}),[W,K]),de=z.open,fe=(0,Z.useCallback)(()=>{U||H({open:!de})},[de,U,H]),{closeColumn:pe}=r,me=r.layout?.columns,he=(0,Z.useCallback)(()=>{H({open:!0});let e=me?.findIndex(e=>e.view===`terminal`)??-1;e<0||(E!==null||me.length===1?i(`session`):pe(e))},[pe,E,i,me,H]),ge=(0,Z.useMemo)(()=>oe||U?[`terminal`]:[],[oe,U]),ve=(0,Z.useMemo)(()=>(0,Q.jsx)(Jr,{layouts:D,active:r.state.active,fixedViews:T,fixedActive:E,onViews:ge,onSelectFixed:i,onSelect:s,onClose:o,saved:f.saved,onApplySaved:u,onSaveCurrent:g?_:void 0,onDeleteSaved:m,notesHref:`/tasks/${e.id}/notes`,onViewDragStart:N,onViewDragEnd:P,onOpenBeside:re,onColumnDropClose:R,keyHints:k,showKeyHints:A}),[D,r.state.active,T,E,ge,i,s,o,f.saved,u,g,_,m,e.id,N,P,re,R,k,A]),Y=(0,Z.useMemo)(()=>(0,Q.jsx)(J,{variant:`ghost`,size:`icon-sm`,"data-action":`maximize-layout`,"aria-label":`Full view`,title:`Full view — hide everything but this layout (F)`,className:`text-muted-foreground`,onClick:K,children:(0,Q.jsx)($t,{"aria-hidden":`true`})}),[K]),be=(0,Z.useMemo)(()=>[...T.map(e=>({select:()=>i(e),active:E===e})),...D.map(e=>({select:()=>s(e.name),active:E===null&&e.name===r.state.active}))],[T,D,E,r.state.active,i,s]),Se=(0,Z.useMemo)(()=>[...ft(T).map(t=>t===`notes`?()=>ee(`/tasks/${e.id}/notes`):()=>i(t))],[T,i,ee,e.id]),Ce=(0,Z.useRef)({stripOrder:be,numbered:Se,toggleMaximized:K,terminalAllowed:v,toggleDrawer:fe});Ce.current={stripOrder:be,numbered:Se,toggleMaximized:K,terminalAllowed:v,toggleDrawer:fe},(0,Z.useEffect)(()=>{let e=e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.repeat||e.defaultPrevented||bn(e.target)||document.querySelector(`[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]`))return;let t=Ce.current,n=document.querySelector(yu),r=t.stripOrder.findIndex(e=>e.active),i=e=>{if(t.stripOrder.length===0)return;let n=(Math.max(r,0)+e+t.stripOrder.length)%t.stripOrder.length;t.stripOrder[n].select()};if(/^[1-9]$/.test(e.key)){let n=t.numbered[Number(e.key)-1];if(!n)return;n()}else if(e.key===`[`)i(-1);else if(e.key===`]`)i(1);else if(e.key===`f`||e.key===`F`)t.toggleMaximized();else if(e.key===`\\`){let e=n?.querySelectorAll(`[data-action="split-view"]:not(:disabled)`),t=e?.[e.length-1];if(!t)return;t.click()}else if(e.key===`/`){let e=n?.querySelector(`[data-slot="composer"] textarea, [data-slot="composer-input"]`);if(!e)return;e.focus()}else if(e.key==="`"){if(!t.terminalAllowed)return;t.toggleDrawer()}else return;e.preventDefault()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let we=so(e.id),[Te,Ee]=(0,Z.useState)(null),De=r.layout?.columns,Oe=(0,Z.useCallback)((e,t)=>{let n=De?.[e]?.view===`changes`,i=De?.filter(e=>e.view===`changes`).length===1;if(n&&i&&we.comments.length>0){Ee({index:e,view:t});return}r.setColumnView(e,t)},[De,we.comments.length,r.setColumnView]),ke=(0,Z.useMemo)(()=>({addColumn:E===null?r.addColumn:e=>F(e,ie,`insert`),closeColumn:r.closeColumn,setColumnView:Oe,resizeColumns:r.resizeColumns,moveColumn:r.moveColumn}),[E,F,ie,r.addColumn,r.closeColumn,Oe,r.resizeColumns,r.moveColumn]),Ae=r.openBeside,je=(0,Z.useCallback)(t=>{let n=Ae(t.view);n&&Gr(`${e.id}:${n.name}:${n.index}:${t.view}`,t.value)},[Ae,e.id]);(0,Z.useEffect)(()=>vn(e.id),[e.id]),(0,Z.useEffect)(()=>{if(!r.ready)return;let t=On(e.id);t&&je({view:`files`,value:t})},[r.ready,je,e.id]),(0,Z.useEffect)(()=>{let t=()=>document.querySelector(yu),n=()=>{let e=t()?.querySelectorAll(`[data-action="split-view"]:not(:disabled)`);return e?.[e.length-1]??null},a=()=>t()?.querySelector(`[data-slot="composer"] textarea, [data-slot="composer-input"]`)??null,o={runId:e.id,views:T,activeView:E,openView:i,openViewBeside:re,layouts:D.map(e=>({name:e.name,label:Lt(e.name),active:E===null&&e.name===r.state.active})),selectLayout:s,maximized:W,toggleMaximized:K,get splitView(){return n()?()=>n()?.click():null},terminal:{allowed:v,open:de,inColumn:U,toggle:fe,openInColumn:()=>{H({open:!1}),Ae(`terminal`)}},get focusComposer(){return a()?()=>a()?.focus():null},openFile:e=>je({view:`files`,value:e}),markedUnread:w};return kn(o),()=>_n(o)});let Me=r.state.active,Ne=De?.some(e=>e.view===`session`)?`session`:`changes`,Pe=Ia(e),{addDraft:Fe,discard:Ie,note:Le,marks:Re}=Pe,ze=(0,Z.useCallback)(e=>{Le(e)?.phase===`draft`&&Ie(e)},[Ie,Le]),Be=xu(e.id,r.layout?Me:null,r.state.layouts),Ve=(0,Z.useCallback)(e=>e===`terminal`&&v?(0,Q.jsx)(Jn,{label:`Move to bottom — under every view`,children:(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-xs`,"data-action":`terminal-to-drawer`,"aria-label":`Move to bottom`,onClick:he,className:`text-soft-foreground hover:text-foreground`,children:(0,Q.jsx)(tn,{"aria-hidden":`true`,className:`size-3.5`})})}):null,[he,v]),He=(0,Z.useCallback)((t,r,i,a)=>{switch(t){case`session`:return(0,Q.jsx)(wu,{run:e,onMarkedUnread:n,onOpenReference:je});case`changes`:return(0,Q.jsx)(yo,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:changes`},e.id);case`commits`:return(0,Q.jsx)(Kr,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:commits`});case`files`:return(0,Q.jsx)(Do,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:files`});case`graph`:return(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Cu,{title:`Loading graph…`}),children:(0,Q.jsx)(mu,{run:e,embedded:!0})});case`terminal`:return v?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Cu,{title:`Loading terminal…`}),children:(0,Q.jsx)(pu,{runId:e.id,height:0,onHeightChange:vu,onOpenInBrowser:l,fill:!0})}):(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(Zn,{}),tone:`neutral`,heading:`h2`,title:`Terminal disabled`,subtitle:`The terminal is off on this cockpit — it is off in hosted mode unless CEZ_TERMINAL=1.`});case`browser`:return(0,Q.jsx)(Li,{state:i.browser??It(),onChange:e=>c(r,e),onPickElement:Fe,designMarks:Re,onDesignEscape:ze,renderEmpty:v?t=>(0,Q.jsx)(ma,{runId:e.id,projectId:ae,onOpen:t,setup:e.worktreeLifecycle,onShowTerminal:U?void 0:()=>H({open:!0})}):void 0,renderDesignNote:({mark:t,close:n})=>{let r=Le(t);return r?(0,Q.jsx)(va,{note:r,run:e,notes:Pe,onClose:n}):null}})}},[Fe,Re,Pe,ze,Le,n,l,je,e,c,v,ae,U,H]);return(0,Q.jsxs)(`div`,{"data-route":`task-workspace`,"data-run-id":e.id,className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(Wt,{run:e,tab:Ne,onMarkedUnread:w,tabs:ve,headerActions:Y,wide:!0}),r.loadFailed?(0,Q.jsx)(`div`,{"data-slot":`layouts-unloaded`,role:`status`,className:`shrink-0 border-b border-border bg-muted/40 px-4 py-1.5 text-xs text-muted-foreground sm:px-6`,children:`This task's saved layouts could not be loaded yet — retrying. Changes made meanwhile are not saved.`}):null,r.saveFailed?(0,Q.jsx)(`div`,{"data-slot":`layouts-unsaved`,role:`status`,className:`shrink-0 border-b border-border bg-muted/40 px-4 py-1.5 text-xs text-muted-foreground sm:px-6`,children:`This layout could not be saved on this host — it keeps working in this tab, but will not come back after a refresh.`}):null,(0,Q.jsx)(on.Provider,{value:y,children:(0,Q.jsx)(Yl.Provider,{value:ue,children:(0,Q.jsxs)(`div`,{ref:le.ref,"data-slot":`workspace-stage`,"data-maximized":le.covering?``:void 0,style:le.style,className:q(`relative flex min-h-0 flex-1 flex-col`,le.covering&&`fixed z-40 overflow-hidden bg-background md:rounded-xl md:border md:border-border/70`),children:[r.ready?r.layout?Be.map(e=>(0,Q.jsx)(Su,{layout:e,active:e.name===Me,actions:ke,renderView:He,headerExtras:Ve},e.name)):(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(Mn,{}),tone:`neutral`,heading:`h2`,title:`No layouts`,subtitle:`You closed every layout of this task. Create a new one, or come back later — the task will open with a Chat layout.`,actions:(0,Q.jsx)(J,{variant:`outline`,onClick:O,children:`New layout`})}):(0,Q.jsx)(gu,{view:t}),j?(0,Q.jsx)(su,{view:j,columns:r.layout?.columns??[],onDrop:ne}):null,le.covering&&E!==null?(0,Q.jsx)(Ql,{className:`absolute top-2 right-3 z-20 bg-card shadow-sm`}):null]})})}),(0,Q.jsx)(Er,{open:Te!==null,onOpenChange:e=>!e&&Ee(null),children:(0,Q.jsxs)(xr,{children:[(0,Q.jsxs)(Tr,{children:[(0,Q.jsx)(br,{children:`You have an unsent comment`}),(0,Q.jsxs)(yr,{children:[we.comments.length===1?`One comment on the changes has not been sent yet.`:`${we.comments.length} comments on the changes have not been sent yet.`,` `,`This is the last column showing them.`]})]}),(0,Q.jsxs)(Cr,{children:[(0,Q.jsx)(wr,{children:`Go back`}),(0,Q.jsx)(Sr,{onClick:()=>{Te&&r.setColumnView(Te.index,Te.view),Ee(null)},children:`Change anyway`})]})]})}),oe?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(pu,{runId:e.id,height:z.height,onHeightChange:e=>H({height:e}),onClose:()=>H({open:!1}),onMoveToColumn:()=>{H({open:!1}),Ae(`terminal`)},onOpenInBrowser:l})}):null]})}var vu=()=>{},yu=`[data-slot="workspace-stage"] [data-slot="workspace-layout"][data-active]`;function bu(e){return e.columns.every(e=>e.view!==`terminal`&&e.view!==`browser`)}function xu(e,t,n){let[r,i]=(0,Z.useState)({runId:e,names:[]}),a=r.runId===e?r.names:[];return t!==null&&a[0]!==t&&i({runId:e,names:[t,...a.filter(e=>e!==t)].slice(0,5)}),n.filter(e=>e.name===t||a.includes(e.name)&&bu(e))}function Su({layout:e,active:t,actions:n,renderView:r,headerExtras:i}){let a=e.name,o=(0,Z.useCallback)((e,t,n)=>r(e,t,n,a),[r,a]);return(0,Q.jsx)(Z.Activity,{mode:t?`visible`:`hidden`,children:(0,Q.jsx)(`div`,{"data-slot":`workspace-layout`,"data-active":t?``:void 0,className:`flex min-h-0 flex-1 flex-col`,children:(0,Q.jsx)(lu,{columns:e.columns,actions:n,renderView:o,headerExtras:i})})})}function Cu({title:e}){return(0,Q.jsx)(Fr,{icon:(0,Q.jsx)(cr,{className:`motion-safe:animate-spin`}),tone:`neutral`,heading:`h2`,title:e})}function wu({run:e,onMarkedUnread:t,onOpenReference:n}){let r=Ci(e.id),i=(0,Z.useMemo)(()=>zl(r.visibleEvents,{activeTurn:e.status===`running`,runner:e.runner}),[r.visibleEvents,e.status,e.runner]),a=(0,Z.useMemo)(()=>zl(r.currentEvents,{activeTurn:e.status===`running`,runner:e.runner}),[r.currentEvents,e.status,e.runner]);if(Mo(e,r.visibleEvents),r.isPending)return(0,Q.jsx)(Dn,{});let o=t=>{let n=t.target instanceof Element?t.target.closest(`[data-streamdown="inline-code"]`):null;if(!(n instanceof HTMLElement)||n.closest(`[data-slot="user-message"]`))return null;let r=Tu(n.textContent??``,e.worktreePath??void 0);return r?{node:n,reference:r}:null};return(0,Q.jsx)(`div`,{className:`contents`,onPointerOver:e=>{let t=o(e);t&&!t.node.dataset.open&&(t.node.dataset.open=t.reference.view,t.node.title=t.reference.view===`files`?`Open in Files`:`Open in Commits`)},onClick:e=>{if(!n||window.getSelection()?.toString())return;let t=o(e);t&&n(t.reference)},children:(0,Q.jsx)(Vl,{run:e,thread:i,currentThread:a,history:r,onMarkedUnread:t,embedded:!0})})}function Tu(e,t){let n=e.trim();if(n.length<3||n.length>260||/\s/.test(n))return null;if(/^[0-9a-f]{7,40}$/.test(n)&&/[a-f]/.test(n)&&/[0-9]/.test(n))return{view:`commits`,value:n};let r=n.replace(/:\d+(?::\d+)?$/,``);return t&&r.startsWith(`${t}/`)&&(r=r.slice(t.length+1)),r.startsWith(`/`)||r.startsWith(`~`)||/^[a-z]+:\/\//i.test(r)||(r=r.replace(/^\.\//,``),r.startsWith(`..`))||!/^[\w@.+\-()[\]]+(?:\/[\w@.+\-()[\]]+)*\.[A-Za-z][A-Za-z0-9]{0,7}$/.test(r)||!r.includes(`/`)&&!/\.(?:tsx?|jsx?|mjs|cjs|json|md|mdx|css|scss|html|ya?ml|toml|py|rs|go|rb|java|kt|swift|sh|sql|lock|txt|env|svg|png|jpe?g)$/i.test(r)?null:{view:`files`,value:r}}export{hu as TaskWorkspaceRoute};
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{$i as r,Fi as i,Gr as a,Ur as o,Wr as s,aa as c,en as l,hr as u,j as d,wi as f}from"./queries-CI0EmEcH.js";import{F as p,r as m,t as h}from"./button-Clwd6u4_.js";import{i as g}from"./bundle-mjs-BT31bpU6.js";import{o as _}from"./host-usage-DjDYDU0A.js";import{f as v}from"./tooltip-B628Gs7C.js";import{a as y,c as b,g as x,i as S,n as C,r as w,t as T,u as E}from"./icon-tooltip-YXzUubMO.js";import{n as D,t as O}from"./terminal-F3ZJ5fI8.js";import{t as k}from"./loader-circle-D-ter0qP.js";import{n as A,t as ee}from"./square-8OFxLPoA.js";import{t as j}from"./plus-CBVm02wz.js";import{t as M}from"./x-DMIsmLBt.js";import{a as N,c as P,i as F,n as I,o as L,r as te,s as ne,t as re}from"./alert-dialog-DvPnvVvK.js";import{i as R,r as ie,t as z}from"./tabs-BUk8rSoE.js";import{t as B}from"./input-DIWTlsx6.js";import{t as V}from"./drawer-state-DasOAIpO.js";var H=p(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),U=e(t(),1),W=n(),G=3e3;function K({runId:e,onOpen:t}){let[n,r]=(0,U.useState)([]),[i,o]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t=!0,n=()=>{a(e).then(e=>{t&&r(e.urls)}).catch(()=>{})};n();let i=setInterval(n,G);return()=>{t=!1,clearInterval(i)}},[e]),n.length===0?null:(0,W.jsxs)(`div`,{"data-slot":`detected-urls`,className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border/70 px-3 py-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Detected addresses`}),n.map(e=>(0,W.jsxs)(`span`,{"data-slot":`detected-url`,"data-running":e.running===!0?``:void 0,className:`flex items-center gap-1.5 rounded-sm bg-muted/60 py-0.5 pr-0.5 pl-2 text-xs`,children:[(0,W.jsx)(x,{"aria-hidden":`true`,className:m(`size-2`,e.running===!0?`fill-success text-success`:e.running===!1?`fill-muted text-muted-foreground`:`text-soft-foreground`)}),(0,W.jsx)(`span`,{className:`font-mono`,children:e.url}),(0,W.jsx)(`span`,{className:`text-soft-foreground`,children:e.running===!0?`running`:e.running===!1?`not responding`:`…`}),(0,W.jsx)(h,{asChild:!0,variant:`ghost`,size:`xs`,className:`h-auto px-1.5 py-0.5 text-[length:inherit] hover:bg-background`,children:(0,W.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Open ${e.url} in Browser`,children:[(0,W.jsx)(D,{"aria-hidden":`true`,className:`size-3`}),(0,W.jsx)(`span`,{children:`Open in Browser`})]})}),(0,W.jsxs)(h,{type:`button`,variant:`ghost`,size:`xs`,"aria-label":`Open ${e.url} in Preview`,onClick:()=>o(!t(e.url)),className:`h-auto px-1.5 py-0.5 text-[length:inherit] hover:bg-background`,children:[(0,W.jsx)(H,{"aria-hidden":`true`,className:`size-3`}),(0,W.jsx)(`span`,{children:`Open Preview`})]})]},e.url)),i?(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No room to open it here — this layout has three columns, or its Preview is out of tabs.`}):null]})}function q({runId:e,onRun:t}){let[n,r]=(0,U.useState)([]),[i,a]=(0,U.useState)(``),o=(0,U.useCallback)(()=>{s(e).then(e=>r(e.commands)).catch(()=>{})},[e]);return(0,W.jsxs)(C,{onOpenChange:e=>e&&o(),children:[(0,W.jsx)(E,{asChild:!0,children:(0,W.jsxs)(h,{variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs text-muted-foreground`,children:[(0,W.jsx)(A,{"aria-hidden":`true`,className:`size-3`}),`Run`,(0,W.jsx)(v,{"aria-hidden":`true`,className:`size-3`})]})}),(0,W.jsxs)(w,{align:`end`,className:`max-h-80 w-80 overflow-y-auto`,children:[(0,W.jsx)(y,{children:`Project commands`}),n.length===0?(0,W.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-soft-foreground`,children:`No commands found in package.json or a Makefile. Type your own below.`}):n.map(e=>(0,W.jsxs)(S,{onSelect:()=>t(e.command),className:`flex-col items-start gap-0`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:e.command}),(0,W.jsxs)(`span`,{className:`text-[11px] text-soft-foreground`,children:[e.source,e.detail?` — ${e.detail}`:``]})]},`${e.source}:${e.command}`)),(0,W.jsx)(b,{}),(0,W.jsx)(y,{className:`font-normal text-soft-foreground`,children:`Custom command`}),(0,W.jsx)(`form`,{className:`px-2 pb-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();n!==``&&(a(``),t(n))},children:(0,W.jsx)(B,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:`e.g. npm run dev`,"aria-label":`Custom command`,spellCheck:!1,className:`h-8 px-2 font-mono text-xs shadow-none focus-visible:ring-0 md:text-xs`})})]})]})}var J=400,Y=`\r
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./react-runtime-CCIEwYL0.js";import{Fi as r,Gr as i,Qi as a,Ur as o,Wr as s,en as c,hr as l,ia as u,j as d,wi as f}from"./queries-Bn7zl9OU.js";import{F as p,r as m,t as h}from"./button-Clwd6u4_.js";import{i as g}from"./bundle-mjs-BT31bpU6.js";import{o as _}from"./host-usage-DnkXF0CT.js";import{f as v}from"./tooltip-B628Gs7C.js";import{a as y,c as b,g as x,i as S,n as C,r as w,t as T,u as E}from"./icon-tooltip-YXzUubMO.js";import{n as D,t as O}from"./terminal-F3ZJ5fI8.js";import{t as k}from"./loader-circle-D-ter0qP.js";import{n as A,t as ee}from"./square-8OFxLPoA.js";import{t as j}from"./plus-CBVm02wz.js";import{t as M}from"./x-DMIsmLBt.js";import{a as N,c as P,i as F,n as I,o as L,r as te,s as ne,t as re}from"./alert-dialog-DvPnvVvK.js";import{i as R,r as ie,t as z}from"./tabs-BUk8rSoE.js";import{t as B}from"./input-DIWTlsx6.js";import{t as V}from"./drawer-state-DasOAIpO.js";var H=p(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),U=e(t(),1),W=n(),G=3e3;function K({runId:e,onOpen:t}){let[n,r]=(0,U.useState)([]),[a,o]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t=!0,n=()=>{i(e).then(e=>{t&&r(e.urls)}).catch(()=>{})};n();let a=setInterval(n,G);return()=>{t=!1,clearInterval(a)}},[e]),n.length===0?null:(0,W.jsxs)(`div`,{"data-slot":`detected-urls`,className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-border/70 px-3 py-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Detected addresses`}),n.map(e=>(0,W.jsxs)(`span`,{"data-slot":`detected-url`,"data-running":e.running===!0?``:void 0,className:`flex items-center gap-1.5 rounded-sm bg-muted/60 py-0.5 pr-0.5 pl-2 text-xs`,children:[(0,W.jsx)(x,{"aria-hidden":`true`,className:m(`size-2`,e.running===!0?`fill-success text-success`:e.running===!1?`fill-muted text-muted-foreground`:`text-soft-foreground`)}),(0,W.jsx)(`span`,{className:`font-mono`,children:e.url}),(0,W.jsx)(`span`,{className:`text-soft-foreground`,children:e.running===!0?`running`:e.running===!1?`not responding`:`…`}),(0,W.jsx)(h,{asChild:!0,variant:`ghost`,size:`xs`,className:`h-auto px-1.5 py-0.5 text-[length:inherit] hover:bg-background`,children:(0,W.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Open ${e.url} in Browser`,children:[(0,W.jsx)(D,{"aria-hidden":`true`,className:`size-3`}),(0,W.jsx)(`span`,{children:`Open in Browser`})]})}),(0,W.jsxs)(h,{type:`button`,variant:`ghost`,size:`xs`,"aria-label":`Open ${e.url} in Preview`,onClick:()=>o(!t(e.url)),className:`h-auto px-1.5 py-0.5 text-[length:inherit] hover:bg-background`,children:[(0,W.jsx)(H,{"aria-hidden":`true`,className:`size-3`}),(0,W.jsx)(`span`,{children:`Open Preview`})]})]},e.url)),a?(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No room to open it here — this layout has three columns, or its Preview is out of tabs.`}):null]})}function q({runId:e,onRun:t}){let[n,r]=(0,U.useState)([]),[i,a]=(0,U.useState)(``),o=(0,U.useCallback)(()=>{s(e).then(e=>r(e.commands)).catch(()=>{})},[e]);return(0,W.jsxs)(C,{onOpenChange:e=>e&&o(),children:[(0,W.jsx)(E,{asChild:!0,children:(0,W.jsxs)(h,{variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs text-muted-foreground`,children:[(0,W.jsx)(A,{"aria-hidden":`true`,className:`size-3`}),`Run`,(0,W.jsx)(v,{"aria-hidden":`true`,className:`size-3`})]})}),(0,W.jsxs)(w,{align:`end`,className:`max-h-80 w-80 overflow-y-auto`,children:[(0,W.jsx)(y,{children:`Project commands`}),n.length===0?(0,W.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-soft-foreground`,children:`No commands found in package.json or a Makefile. Type your own below.`}):n.map(e=>(0,W.jsxs)(S,{onSelect:()=>t(e.command),className:`flex-col items-start gap-0`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:e.command}),(0,W.jsxs)(`span`,{className:`text-[11px] text-soft-foreground`,children:[e.source,e.detail?` — ${e.detail}`:``]})]},`${e.source}:${e.command}`)),(0,W.jsx)(b,{}),(0,W.jsx)(y,{className:`font-normal text-soft-foreground`,children:`Custom command`}),(0,W.jsx)(`form`,{className:`px-2 pb-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();n!==``&&(a(``),t(n))},children:(0,W.jsx)(B,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:`e.g. npm run dev`,"aria-label":`Custom command`,spellCheck:!1,className:`h-8 px-2 font-mono text-xs shadow-none focus-visible:ring-0 md:text-xs`})})]})]})}var J=400,Y=`\r
2
2
  [... earlier output fell out of the scrollback ...]\r
3
- `;function X(){let e=getComputedStyle(document.documentElement),t=t=>e.getPropertyValue(t).trim(),n=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`],r={};for(let e of n)r[e]=t(`--term-${e}`),r[`bright${e[0].toUpperCase()}${e.slice(1)}`]=t(`--term-bright-${e}`);return{background:t(`--card-2`),foreground:t(`--foreground`),cursor:t(`--primary-strong`),cursorAccent:t(`--card-2`),selectionBackground:t(`--term-selection`),...r}}function Z({runId:e,session:t,active:n,io:r}){let a=_(),o=(0,U.useRef)(null);o.current=r??{read:n=>f(e,t.id,n),write:n=>c(e,t.id,n),resize:(n,r)=>i(e,t.id,n,r)};let s=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.useRef)(null),p=(0,U.useRef)(null),h=(0,U.useRef)(null),v=(0,U.useRef)(0),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=s.current;if(!e)return;let t=!1,n;return(async()=>{let[{Terminal:r},{FitAddon:i}]=await Promise.all([g(()=>import(`./xterm-U4TA8lIC.js`),[]),g(()=>import(`./addon-fit-DIOBYJe3.js`),[])]);if(t)return;let a=new r({cursorBlink:!0,cursorStyle:`bar`,cursorWidth:2,fontSize:12.5,lineHeight:1.35,letterSpacing:0,fontFamily:`'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace`,theme:X(),scrollback:5e3}),s=new MutationObserver(()=>{a.options.theme=X()});s.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-accent`]}),d.current=s;let c=new i;a.loadAddon(c),a.open(e),u.current=a,p.current=()=>{e.clientHeight>0&&e.clientWidth>0&&c.fit()},h.current=()=>a.focus(),a.attachCustomKeyEventHandler(e=>{if(e.type!==`keydown`||!e.metaKey&&!e.ctrlKey)return!0;let t=e.key.toLowerCase();return e.metaKey||e.shiftKey?t===`c`&&a.hasSelection()?(navigator.clipboard?.writeText(a.getSelection()).catch(()=>{}),!1):t!==`v`:!0});let l=({cols:e,rows:t})=>{o.current.resize(e,t).catch(()=>{})};a.onResize(l),a.onData(e=>{o.current.write(e).catch(()=>{})}),p.current(),l({cols:a.cols,rows:a.rows}),b(!0);let f=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>p.current?.());f?.observe(e),n=()=>{f?.disconnect(),a.dispose()}})(),()=>{t=!0,d.current?.disconnect(),d.current=null,u.current=null,p.current=null,h.current=null,b(!1),n?.()}},[e,t.id]),(0,U.useEffect)(()=>{!n||!y||(p.current?.(),h.current?.())},[n,y]);let C=(0,U.useRef)(!1),w=(0,U.useRef)(!1),T=(0,U.useCallback)(async()=>{if(C.current){w.current=!0;return}C.current=!0;try{do{w.current=!1;let e=await o.current.read(v.current);v.current=e.cursor,e.truncated&&u.current?.write(Y),e.data&&u.current?.write(e.data)}while(w.current)}finally{C.current=!1}},[e,t.id]);return(0,U.useEffect)(()=>{if(!y||!n||a===void 0)return;let e=!0,r=()=>{e&&T().catch(()=>{})};r();let i=t.topic;if(i===null)return()=>{e=!1};if(a===`local`&&!x){let t=l(i,r,()=>S(!0));return()=>{e=!1,t()}}let o=setInterval(r,J);return()=>{e=!1,clearInterval(o)}},[n,T,y,t.topic,x,a]),(0,W.jsx)(`div`,{"data-slot":`terminal-screen`,"data-session":t.id,className:m(`absolute inset-0 overflow-hidden p-3`,n?`visible`:`invisible pointer-events-none`,t.exitCode!==null&&`opacity-60`),children:(0,W.jsx)(`div`,{ref:s,className:`size-full`})})}var ae=2e3;function Q({runId:e,height:t,onHeightChange:n,onClose:i,onMoveToColumn:a,onOpenInBrowser:s,fill:l=!1}){let[f,p]=(0,U.useState)([]),[g,_]=(0,U.useState)(null),[v,b]=(0,U.useState)(null),[x,D]=(0,U.useState)(!0),[A,R]=(0,U.useState)(null),B=d(),V=typeof window>`u`?`this host`:window.location.host,G=(B.data?.repo?.root??B.data?.repoRoot??``).split(/[\\/]/).filter(Boolean).pop()??`project`;(0,U.useEffect)(()=>{let t=!1;return D(!0),b(null),p([]),_(null),(async()=>{try{let n=await o(e);if(t)return;if(!n.available){b(n.reason??`The terminal is not available in this cockpit.`);return}Y(n.shells??[]);let r=n.sessions.filter(e=>e.exitCode===null),i=r.length>0?r:[await u(e,{})];if(t)return;p(i),_(i[0]?.id??null)}catch(e){t||b(e instanceof Error?e.message:String(e))}finally{t||D(!1)}})(),()=>{t=!0}},[e]),(0,U.useEffect)(()=>{if(v||x)return;let t=!0,n=setInterval(()=>{o(e).then(e=>{!t||!e.available||(p(e.sessions),_(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id??null))}).catch(()=>{})},ae);return()=>{t=!1,clearInterval(n)}},[e,x,v]);let[J,Y]=(0,U.useState)([]),X=(0,U.useCallback)(t=>{u(e,t?{shell:t}:{}).then(e=>{p(t=>[...t,e]),_(e.id)}).catch(e=>{b(e instanceof Error?e.message:String(e))})},[e]);(0,U.useEffect)(()=>{if(v)return;let e=e=>{!e.shiftKey||!(e.ctrlKey||e.metaKey)||e.code===`Backquote`&&(e.preventDefault(),X())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X,v]);let Q=(0,U.useCallback)(t=>{R(null),r(e,t.id).catch(()=>{}),p(e=>{let n=e.findIndex(e=>e.id===t.id),r=e.filter(e=>e.id!==t.id);return r.length===0?i?.():n>=0&&_(e=>e===t.id?r[Math.min(n,r.length-1)]?.id??null:e),r})},[i,e]),ce=(0,U.useCallback)(t=>{u(e,{}).then(async n=>{p(e=>[...e,n]),_(n.id),await c(e,n.id,`${t}\r`)}).catch(()=>{})},[e]),$=f.find(e=>e.id===g)??null;return(0,W.jsxs)(`section`,{"data-slot":`terminal-drawer`,"aria-label":`Terminal`,"data-fill":l?``:void 0,className:m(`relative flex flex-col bg-background`,l?`h-full min-h-0`:`shrink-0 border-t border-border shadow-[0_-12px_24px_-20px_rgb(var(--shadow-color)/0.35)]`),style:l?void 0:{height:`${t}px`},children:[l?null:(0,W.jsx)(se,{height:t,onHeightChange:n}),v?null:(0,W.jsx)(K,{runId:e,onOpen:s}),(0,W.jsxs)(`header`,{className:`flex h-10 shrink-0 items-center gap-1.5 pl-3 pr-2`,children:[(0,W.jsx)(O,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted-foreground`}),(0,W.jsx)(z,{value:g??``,onValueChange:_,className:`min-w-0 flex-1 gap-0`,children:(0,W.jsxs)(ie,{"aria-label":`Terminal tabs`,className:`flex w-full min-w-0 justify-start gap-0.5 overflow-x-auto rounded-none bg-transparent p-0 group-data-[orientation=horizontal]/tabs:h-auto`,children:[f.map(e=>(0,W.jsx)(oe,{session:e,active:e.id===g,onSelect:()=>_(e.id),onClose:()=>e.busy===!1?Q(e):R(e)},e.id)),v?null:J.length>1?(0,W.jsxs)(C,{children:[(0,W.jsx)(E,{asChild:!0,children:(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New terminal tab`,title:`New terminal tab — pick a shell`,className:`rounded`,children:(0,W.jsx)(j,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,W.jsxs)(w,{align:`start`,className:`w-56`,children:[(0,W.jsx)(y,{children:`New tab`}),J.map((e,t)=>(0,W.jsxs)(S,{"data-shell":e,onSelect:()=>X(e),children:[(0,W.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e}),t===0?(0,W.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-soft-foreground`,children:`default`}):null]},e))]})]}):(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New terminal tab`,title:`New terminal tab`,onClick:()=>X(),className:`rounded`,children:(0,W.jsx)(j,{"aria-hidden":`true`,className:`size-3.5`})})]})}),$?(0,W.jsx)(`span`,{className:`hidden max-w-[34%] shrink lg:block`,title:`${V} · ${G} · ${$.cwd}`,children:(0,W.jsxs)(`span`,{className:`block truncate text-[11px] text-soft-foreground`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:V}),` · `,G,` · `,$.cwd]})}):null,v?null:(0,W.jsx)(q,{runId:e,onRun:ce}),$?.busy===!0?(0,W.jsxs)(h,{variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs`,title:`Interrupt the command (Ctrl-C)`,onClick:()=>void c(e,$.id,``).catch(()=>{}),children:[(0,W.jsx)(ee,{"aria-hidden":`true`,className:`size-3`}),`Stop`]}):null,a?(0,W.jsx)(T,{label:`Move to column — beside the current view`,children:(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"data-action":`terminal-to-column`,"aria-label":`Move to column`,onClick:a,className:`rounded text-soft-foreground hover:text-foreground`,children:(0,W.jsx)(H,{"aria-hidden":`true`,className:`size-3.5`})})}):null,i?(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Hide terminal`,title:`Hide terminal — processes keep running`,onClick:i,className:`rounded`,children:(0,W.jsx)(M,{"aria-hidden":`true`,className:`size-3.5`})}):null]}),v?(0,W.jsx)(`p`,{"data-slot":`terminal-unavailable`,className:`px-3 py-4 text-xs text-soft-foreground`,children:v}):x?(0,W.jsxs)(`p`,{className:`flex items-center gap-2 px-3 py-4 text-xs text-soft-foreground`,children:[(0,W.jsx)(k,{"aria-hidden":`true`,className:`size-3.5 animate-spin`}),`Starting the shell…`]}):(0,W.jsx)(`div`,{"data-slot":`terminal-surface`,className:`relative mx-2 mb-2 min-h-0 flex-1 overflow-hidden rounded-lg border border-border/70 bg-card-2`,children:f.map(t=>(0,W.jsx)(Z,{runId:e,session:t,active:t.id===g},t.id))}),(0,W.jsx)(re,{open:A!==null,onOpenChange:e=>!e&&R(null),children:(0,W.jsxs)(F,{children:[(0,W.jsxs)(ne,{children:[(0,W.jsx)(P,{children:A?.busy===!0?`Something is running in this tab`:`Close this tab?`}),(0,W.jsx)(N,{children:A?.busy===!0?`“${A.label}” is still running. Closing the tab stops that process and everything it started.`:`This host cannot tell whether something is still running in this shell. Closing the tab stops the shell and everything it started.`})]}),(0,W.jsxs)(L,{children:[(0,W.jsx)(te,{children:`Cancel`}),(0,W.jsx)(I,{onClick:()=>A&&Q(A),children:`Close anyway`})]})]})})]})}function oe({session:e,active:t,onSelect:n,onClose:r}){return(0,W.jsxs)(`div`,{"data-slot":`terminal-tab`,"data-active":t?``:void 0,className:m(`group flex h-7 shrink-0 items-center rounded-md border border-transparent pl-2.5 pr-1 text-xs font-medium transition-colors`,t?`border-border/70 bg-card-2 text-foreground shadow-2xs`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[(0,W.jsx)(R,{value:e.id,onClick:n,title:e.exitCode===null?e.label:`${e.label} — exited (${e.exitCode})`,className:`inline-block h-auto max-w-40 flex-none truncate rounded-none border-0 p-0 text-xs font-medium text-inherit hover:text-inherit focus-visible:underline focus-visible:ring-0 focus-visible:outline-0 data-[state=active]:bg-transparent data-[state=active]:font-medium data-[state=active]:text-inherit group-data-[variant=default]/tabs-list:data-[state=active]:shadow-none`,children:e.label}),(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${e.label}`,onClick:r,className:m(`ml-1 size-4 rounded text-inherit opacity-0 transition-opacity hover:bg-background hover:text-inherit focus-visible:opacity-100 group-hover:opacity-100`,t&&`opacity-60`),children:(0,W.jsx)(M,{"aria-hidden":`true`,className:`size-3`})})]})}function se({height:e,onHeightChange:t}){let n=(0,U.useRef)(null),r=t=>{t.button===0&&(n.current={y:t.clientY,height:e},t.currentTarget.setPointerCapture(t.pointerId),t.preventDefault(),t.currentTarget.focus())},i=e=>{let r=n.current;r&&t(V(r.height-(e.clientY-r.y)))},a=e=>{n.current&&(n.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,W.jsx)(`div`,{"data-slot":`drawer-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize terminal`,"aria-valuenow":e,"aria-valuemin":120,"aria-valuemax":640,tabIndex:0,onPointerDown:r,onPointerMove:i,onPointerUp:a,onPointerCancel:a,onKeyDown:n=>{let r=n.shiftKey?64:16,i=n.key===`ArrowUp`?e+r:n.key===`ArrowDown`?e-r:n.key===`Home`?640:n.key===`End`?120:null;i!==null&&(n.preventDefault(),t(V(i)))},title:`Drag to resize — arrow keys adjust precisely`,className:`absolute inset-x-0 -top-[3px] z-20 h-[5px] cursor-row-resize touch-none bg-transparent transition-colors hover:bg-violet/40 focus-visible:bg-violet/60 focus-visible:outline-none`})}export{Q as TerminalDrawer};
3
+ `;function X(){let e=getComputedStyle(document.documentElement),t=t=>e.getPropertyValue(t).trim(),n=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`],r={};for(let e of n)r[e]=t(`--term-${e}`),r[`bright${e[0].toUpperCase()}${e.slice(1)}`]=t(`--term-bright-${e}`);return{background:t(`--card-2`),foreground:t(`--foreground`),cursor:t(`--primary-strong`),cursorAccent:t(`--card-2`),selectionBackground:t(`--term-selection`),...r}}function Z({runId:e,session:t,active:n,io:i}){let a=_(),o=(0,U.useRef)(null);o.current=i??{read:n=>f(e,t.id,n),write:n=>u(e,t.id,n),resize:(n,i)=>r(e,t.id,n,i)};let s=(0,U.useRef)(null),l=(0,U.useRef)(null),d=(0,U.useRef)(null),p=(0,U.useRef)(null),h=(0,U.useRef)(null),v=(0,U.useRef)(0),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=s.current;if(!e)return;let t=!1,n;return(async()=>{let[{Terminal:r},{FitAddon:i}]=await Promise.all([g(()=>import(`./xterm-U4TA8lIC.js`),[]),g(()=>import(`./addon-fit-DIOBYJe3.js`),[])]);if(t)return;let a=new r({cursorBlink:!0,cursorStyle:`bar`,cursorWidth:2,fontSize:12.5,lineHeight:1.35,letterSpacing:0,fontFamily:`'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace`,theme:X(),scrollback:5e3}),s=new MutationObserver(()=>{a.options.theme=X()});s.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-accent`]}),d.current=s;let c=new i;a.loadAddon(c),a.open(e),l.current=a,p.current=()=>{e.clientHeight>0&&e.clientWidth>0&&c.fit()},h.current=()=>a.focus(),a.attachCustomKeyEventHandler(e=>{if(e.type!==`keydown`||!e.metaKey&&!e.ctrlKey)return!0;let t=e.key.toLowerCase();return e.metaKey||e.shiftKey?t===`c`&&a.hasSelection()?(navigator.clipboard?.writeText(a.getSelection()).catch(()=>{}),!1):t!==`v`:!0});let u=({cols:e,rows:t})=>{o.current.resize(e,t).catch(()=>{})};a.onResize(u),a.onData(e=>{o.current.write(e).catch(()=>{})}),p.current(),u({cols:a.cols,rows:a.rows}),b(!0);let f=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>p.current?.());f?.observe(e),n=()=>{f?.disconnect(),a.dispose()}})(),()=>{t=!0,d.current?.disconnect(),d.current=null,l.current=null,p.current=null,h.current=null,b(!1),n?.()}},[e,t.id]),(0,U.useEffect)(()=>{!n||!y||(p.current?.(),h.current?.())},[n,y]);let C=(0,U.useRef)(!1),w=(0,U.useRef)(!1),T=(0,U.useCallback)(async()=>{if(C.current){w.current=!0;return}C.current=!0;try{do{w.current=!1;let e=await o.current.read(v.current);v.current=e.cursor,e.truncated&&l.current?.write(Y),e.data&&l.current?.write(e.data)}while(w.current)}finally{C.current=!1}},[e,t.id]);return(0,U.useEffect)(()=>{if(!y||!n||a===void 0)return;let e=!0,r=()=>{e&&T().catch(()=>{})};r();let i=t.topic;if(i===null)return()=>{e=!1};if(a===`local`&&!x){let t=c(i,r,()=>S(!0));return()=>{e=!1,t()}}let o=setInterval(r,J);return()=>{e=!1,clearInterval(o)}},[n,T,y,t.topic,x,a]),(0,W.jsx)(`div`,{"data-slot":`terminal-screen`,"data-session":t.id,className:m(`absolute inset-0 overflow-hidden p-3`,n?`visible`:`invisible pointer-events-none`,t.exitCode!==null&&`opacity-60`),children:(0,W.jsx)(`div`,{ref:s,className:`size-full`})})}var ae=2e3;function Q({runId:e,height:t,onHeightChange:n,onClose:r,onMoveToColumn:i,onOpenInBrowser:s,fill:c=!1}){let[f,p]=(0,U.useState)([]),[g,_]=(0,U.useState)(null),[v,b]=(0,U.useState)(null),[x,D]=(0,U.useState)(!0),[A,R]=(0,U.useState)(null),B=d(),V=typeof window>`u`?`this host`:window.location.host,G=(B.data?.repo?.root??B.data?.repoRoot??``).split(/[\\/]/).filter(Boolean).pop()??`project`;(0,U.useEffect)(()=>{let t=!1;return D(!0),b(null),p([]),_(null),(async()=>{try{let n=await o(e);if(t)return;if(!n.available){b(n.reason??`The terminal is not available in this cockpit.`);return}Y(n.shells??[]);let r=n.sessions.filter(e=>e.exitCode===null),i=r.length>0?r:[await l(e,{})];if(t)return;p(i),_(i[0]?.id??null)}catch(e){t||b(e instanceof Error?e.message:String(e))}finally{t||D(!1)}})(),()=>{t=!0}},[e]),(0,U.useEffect)(()=>{if(v||x)return;let t=!0,n=setInterval(()=>{o(e).then(e=>{!t||!e.available||(p(e.sessions),_(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id??null))}).catch(()=>{})},ae);return()=>{t=!1,clearInterval(n)}},[e,x,v]);let[J,Y]=(0,U.useState)([]),X=(0,U.useCallback)(t=>{l(e,t?{shell:t}:{}).then(e=>{p(t=>[...t,e]),_(e.id)}).catch(e=>{b(e instanceof Error?e.message:String(e))})},[e]);(0,U.useEffect)(()=>{if(v)return;let e=e=>{!e.shiftKey||!(e.ctrlKey||e.metaKey)||e.code===`Backquote`&&(e.preventDefault(),X())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X,v]);let Q=(0,U.useCallback)(t=>{R(null),a(e,t.id).catch(()=>{}),p(e=>{let n=e.findIndex(e=>e.id===t.id),i=e.filter(e=>e.id!==t.id);return i.length===0?r?.():n>=0&&_(e=>e===t.id?i[Math.min(n,i.length-1)]?.id??null:e),i})},[r,e]),ce=(0,U.useCallback)(t=>{l(e,{}).then(async n=>{p(e=>[...e,n]),_(n.id),await u(e,n.id,`${t}\r`)}).catch(()=>{})},[e]),$=f.find(e=>e.id===g)??null;return(0,W.jsxs)(`section`,{"data-slot":`terminal-drawer`,"aria-label":`Terminal`,"data-fill":c?``:void 0,className:m(`relative flex flex-col bg-background`,c?`h-full min-h-0`:`shrink-0 border-t border-border shadow-[0_-12px_24px_-20px_rgb(var(--shadow-color)/0.35)]`),style:c?void 0:{height:`${t}px`},children:[c?null:(0,W.jsx)(se,{height:t,onHeightChange:n}),v?null:(0,W.jsx)(K,{runId:e,onOpen:s}),(0,W.jsxs)(`header`,{className:`flex h-10 shrink-0 items-center gap-1.5 pl-3 pr-2`,children:[(0,W.jsx)(O,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted-foreground`}),(0,W.jsx)(z,{value:g??``,onValueChange:_,className:`min-w-0 flex-1 gap-0`,children:(0,W.jsxs)(ie,{"aria-label":`Terminal tabs`,className:`flex w-full min-w-0 justify-start gap-0.5 overflow-x-auto rounded-none bg-transparent p-0 group-data-[orientation=horizontal]/tabs:h-auto`,children:[f.map(e=>(0,W.jsx)(oe,{session:e,active:e.id===g,onSelect:()=>_(e.id),onClose:()=>e.busy===!1?Q(e):R(e)},e.id)),v?null:J.length>1?(0,W.jsxs)(C,{children:[(0,W.jsx)(E,{asChild:!0,children:(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New terminal tab`,title:`New terminal tab — pick a shell`,className:`rounded`,children:(0,W.jsx)(j,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,W.jsxs)(w,{align:`start`,className:`w-56`,children:[(0,W.jsx)(y,{children:`New tab`}),J.map((e,t)=>(0,W.jsxs)(S,{"data-shell":e,onSelect:()=>X(e),children:[(0,W.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e}),t===0?(0,W.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-soft-foreground`,children:`default`}):null]},e))]})]}):(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`New terminal tab`,title:`New terminal tab`,onClick:()=>X(),className:`rounded`,children:(0,W.jsx)(j,{"aria-hidden":`true`,className:`size-3.5`})})]})}),$?(0,W.jsx)(`span`,{className:`hidden max-w-[34%] shrink lg:block`,title:`${V} · ${G} · ${$.cwd}`,children:(0,W.jsxs)(`span`,{className:`block truncate text-[11px] text-soft-foreground`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:V}),` · `,G,` · `,$.cwd]})}):null,v?null:(0,W.jsx)(q,{runId:e,onRun:ce}),$?.busy===!0?(0,W.jsxs)(h,{variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs`,title:`Interrupt the command (Ctrl-C)`,onClick:()=>void u(e,$.id,``).catch(()=>{}),children:[(0,W.jsx)(ee,{"aria-hidden":`true`,className:`size-3`}),`Stop`]}):null,i?(0,W.jsx)(T,{label:`Move to column — beside the current view`,children:(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"data-action":`terminal-to-column`,"aria-label":`Move to column`,onClick:i,className:`rounded text-soft-foreground hover:text-foreground`,children:(0,W.jsx)(H,{"aria-hidden":`true`,className:`size-3.5`})})}):null,r?(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Hide terminal`,title:`Hide terminal — processes keep running`,onClick:r,className:`rounded`,children:(0,W.jsx)(M,{"aria-hidden":`true`,className:`size-3.5`})}):null]}),v?(0,W.jsx)(`p`,{"data-slot":`terminal-unavailable`,className:`px-3 py-4 text-xs text-soft-foreground`,children:v}):x?(0,W.jsxs)(`p`,{className:`flex items-center gap-2 px-3 py-4 text-xs text-soft-foreground`,children:[(0,W.jsx)(k,{"aria-hidden":`true`,className:`size-3.5 animate-spin`}),`Starting the shell…`]}):(0,W.jsx)(`div`,{"data-slot":`terminal-surface`,className:`relative mx-2 mb-2 min-h-0 flex-1 overflow-hidden rounded-lg border border-border/70 bg-card-2`,children:f.map(t=>(0,W.jsx)(Z,{runId:e,session:t,active:t.id===g},t.id))}),(0,W.jsx)(re,{open:A!==null,onOpenChange:e=>!e&&R(null),children:(0,W.jsxs)(F,{children:[(0,W.jsxs)(ne,{children:[(0,W.jsx)(P,{children:A?.busy===!0?`Something is running in this tab`:`Close this tab?`}),(0,W.jsx)(N,{children:A?.busy===!0?`“${A.label}” is still running. Closing the tab stops that process and everything it started.`:`This host cannot tell whether something is still running in this shell. Closing the tab stops the shell and everything it started.`})]}),(0,W.jsxs)(L,{children:[(0,W.jsx)(te,{children:`Cancel`}),(0,W.jsx)(I,{onClick:()=>A&&Q(A),children:`Close anyway`})]})]})})]})}function oe({session:e,active:t,onSelect:n,onClose:r}){return(0,W.jsxs)(`div`,{"data-slot":`terminal-tab`,"data-active":t?``:void 0,className:m(`group flex h-7 shrink-0 items-center rounded-md border border-transparent pl-2.5 pr-1 text-xs font-medium transition-colors`,t?`border-border/70 bg-card-2 text-foreground shadow-2xs`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[(0,W.jsx)(R,{value:e.id,onClick:n,title:e.exitCode===null?e.label:`${e.label} — exited (${e.exitCode})`,className:`inline-block h-auto max-w-40 flex-none truncate rounded-none border-0 p-0 text-xs font-medium text-inherit hover:text-inherit focus-visible:underline focus-visible:ring-0 focus-visible:outline-0 data-[state=active]:bg-transparent data-[state=active]:font-medium data-[state=active]:text-inherit group-data-[variant=default]/tabs-list:data-[state=active]:shadow-none`,children:e.label}),(0,W.jsx)(h,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${e.label}`,onClick:r,className:m(`ml-1 size-4 rounded text-inherit opacity-0 transition-opacity hover:bg-background hover:text-inherit focus-visible:opacity-100 group-hover:opacity-100`,t&&`opacity-60`),children:(0,W.jsx)(M,{"aria-hidden":`true`,className:`size-3`})})]})}function se({height:e,onHeightChange:t}){let n=(0,U.useRef)(null),r=t=>{t.button===0&&(n.current={y:t.clientY,height:e},t.currentTarget.setPointerCapture(t.pointerId),t.preventDefault(),t.currentTarget.focus())},i=e=>{let r=n.current;r&&t(V(r.height-(e.clientY-r.y)))},a=e=>{n.current&&(n.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,W.jsx)(`div`,{"data-slot":`drawer-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize terminal`,"aria-valuenow":e,"aria-valuemin":120,"aria-valuemax":640,tabIndex:0,onPointerDown:r,onPointerMove:i,onPointerUp:a,onPointerCancel:a,onKeyDown:n=>{let r=n.shiftKey?64:16,i=n.key===`ArrowUp`?e+r:n.key===`ArrowDown`?e-r:n.key===`Home`?640:n.key===`End`?120:null;i!==null&&(n.preventDefault(),t(V(i)))},title:`Drag to resize — arrow keys adjust precisely`,className:`absolute inset-x-0 -top-[3px] z-20 h-[5px] cursor-row-resize touch-none bg-transparent transition-colors hover:bg-violet/40 focus-visible:bg-violet/60 focus-visible:outline-none`})}export{Q as TerminalDrawer};