@open-mercato/cezar 0.18.0 → 0.19.0-pr1815.4229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/automations/automation-cli.js +12 -6
  2. package/dist/automations/automation-cli.js.map +1 -1
  3. package/dist/automations/prompts.js +3 -1
  4. package/dist/automations/prompts.js.map +1 -1
  5. package/dist/automations/schedule-runner.js +18 -4
  6. package/dist/automations/schedule-runner.js.map +1 -1
  7. package/dist/automations/store.js +9 -2
  8. package/dist/automations/store.js.map +1 -1
  9. package/dist/automations/templates.js +1 -0
  10. package/dist/automations/templates.js.map +1 -1
  11. package/dist/automations/types.d.ts +28 -0
  12. package/dist/automations/types.js +6 -2
  13. package/dist/automations/types.js.map +1 -1
  14. package/dist/contract/automation-schedule.d.ts +28 -0
  15. package/dist/contract/automations.d.ts +126 -0
  16. package/dist/contract/github.d.ts +56 -0
  17. package/dist/contract/index.js +63 -0
  18. package/dist/contract/workspace.d.ts +18 -0
  19. package/dist/server/forge/github-issue-metadata.d.ts +6 -0
  20. package/dist/server/forge/github-issue-metadata.js +66 -0
  21. package/dist/server/forge/github-issue-metadata.js.map +1 -0
  22. package/dist/server/forge/github.d.ts +1 -1
  23. package/dist/server/forge/github.js +38 -4
  24. package/dist/server/forge/github.js.map +1 -1
  25. package/dist/server/forge/types.d.ts +2 -17
  26. package/dist/server/server.d.ts +320 -36
  27. package/dist/server/server.js +21 -20
  28. package/dist/server/server.js.map +1 -1
  29. package/dist/workflows/run.js +7 -0
  30. package/dist/workflows/run.js.map +1 -1
  31. package/package.json +3 -3
  32. package/web/dist/assets/{agent-task-pickers-DbNIzx20.js → agent-task-pickers-_i7QNEVz.js} +1 -1
  33. package/web/dist/assets/{alert-dialog-4Kna6Hd7.js → alert-dialog-BZU09BVw.js} +1 -1
  34. package/web/dist/assets/arrow-down-BQxdXW9w.js +1 -0
  35. package/web/dist/assets/arrow-left-CvmEanh8.js +1 -0
  36. package/web/dist/assets/automation-format-CEBKDGz8.js +1 -0
  37. package/web/dist/assets/automations-route-Cg1sWvtN.js +1 -0
  38. package/web/dist/assets/button-BvYDiOkd.js +100 -0
  39. package/web/dist/assets/{centered-state-D-wDs7Y1.js → centered-state-Bpq40Y_t.js} +1 -1
  40. package/web/dist/assets/check-DC3eAaS2.js +1 -0
  41. package/web/dist/assets/chevron-left-BW4WDtiS.js +1 -0
  42. package/web/dist/assets/chevron-right-DuM1UAhq.js +1 -0
  43. package/web/dist/assets/circle-check-DiPv45P_.js +1 -0
  44. package/web/dist/assets/{clipboard-DQGL_gUp.js → clipboard-7kWKIj7k.js} +1 -1
  45. package/web/dist/assets/{collapsible-D7qsttC5.js → collapsible-OE3rGS50.js} +1 -1
  46. package/web/dist/assets/{commit-list-DTMGEn0-.js → commit-list-DalU6p3i.js} +1 -1
  47. package/web/dist/assets/{compare-variants-DqlkpLFs.js → compare-variants-CuCfgtyG.js} +1 -1
  48. package/web/dist/assets/dashboard-BYBop-ZJ.js +44 -0
  49. package/web/dist/assets/{diff-DY-_mmb0.js → diff-DfTKq2z2.js} +2 -2
  50. package/web/dist/assets/{diff-view-oTEcZZ_O.js → diff-view-Du2463vL.js} +1 -1
  51. package/web/dist/assets/{download-BBtWFvsh.js → download-_KH0gJo8.js} +1 -1
  52. package/web/dist/assets/facet-filter-BSS2vFA8.js +5 -0
  53. package/web/dist/assets/{file-CbWEaOku.js → file-d2ABwdSR.js} +1 -1
  54. package/web/dist/assets/file-preview-BURiO97x.js +2 -0
  55. package/web/dist/assets/{git-pull-request-draft-Dwhm6Vhn.js → git-pull-request-draft-DIdbQZ0O.js} +1 -1
  56. package/web/dist/assets/git-tab-loading-8Y0ID8J2.js +1 -0
  57. package/web/dist/assets/{git-toolbar-C3vpZJaZ.js → git-toolbar-CSrf6Ux9.js} +1 -1
  58. package/web/dist/assets/github-DQ8J0EYw.js +1 -0
  59. package/web/dist/assets/{host-usage-CI_ZlJQu.js → host-usage-EK6T4fAW.js} +1 -1
  60. package/web/dist/assets/{icon-tooltip-CgAWLDxo.js → icon-tooltip-nRvCJxOH.js} +1 -1
  61. package/web/dist/assets/index-BVPhzJ3k.js +31 -0
  62. package/web/dist/assets/index-HmrjUHlJ.css +2 -0
  63. package/web/dist/assets/{input-Br4NQpZK.js → input-90eli0Uk.js} +1 -1
  64. package/web/dist/assets/{layout-cards-fdJa2H62.js → layout-cards-n-2Pwe6c.js} +1 -1
  65. package/web/dist/assets/{lib-w_5wfsBF.js → lib-C4vuyY62.js} +1 -1
  66. package/web/dist/assets/loader-circle-DAforPX2.js +1 -0
  67. package/web/dist/assets/{markdown-G3dvGJao.js → markdown-BBnagS_c.js} +1 -1
  68. package/web/dist/assets/{markdown-BfZORc0a.js → markdown-DLB6o6YD.js} +1 -1
  69. package/web/dist/assets/{message-square-Dl-ol3uz.js → message-square-WCEmfkiD.js} +1 -1
  70. package/web/dist/assets/plus-BJEPAJjW.js +1 -0
  71. package/web/dist/assets/{project-router-DgQSavhI.js → project-router-7DKoABD3.js} +1 -1
  72. package/web/dist/assets/queries-DsfjHsrp.js +1 -0
  73. package/web/dist/assets/{reference-chip-BxUGeHDa.js → reference-chip-frnxjI-K.js} +1 -1
  74. package/web/dist/assets/repo-git-DVREyQYa.js +1 -0
  75. package/web/dist/assets/{run-diff-CqXLVaDj.js → run-diff-CmqQmGTJ.js} +1 -1
  76. package/web/dist/assets/{save-ByUa-aAl.js → save-CCb1fwTJ.js} +1 -1
  77. package/web/dist/assets/{scroll-within-Dexi68h1.js → scroll-within-CNcaqKGp.js} +1 -1
  78. package/web/dist/assets/{search-x-CLuL49ms.js → search-x-Cm22V3TC.js} +1 -1
  79. package/web/dist/assets/{settings-2-BvalJGW-.js → settings-2-CWK1otJs.js} +1 -1
  80. package/web/dist/assets/skills-B0OolFqS.js +1 -0
  81. package/web/dist/assets/{square-FwRsgrg-.js → square-B-gfdc5r.js} +1 -1
  82. package/web/dist/assets/{tabs-nC1VLjcX.js → tabs-D3hCl7A6.js} +1 -1
  83. package/web/dist/assets/{tag-CteJEZQp.js → tag-C5TeSwBA.js} +1 -1
  84. package/web/dist/assets/{task-commits-CYcqwz-f.js → task-commits-DIrIWA6g.js} +1 -1
  85. package/web/dist/assets/{task-graph-CJfTnzUp.js → task-graph-Diq4xAP_.js} +1 -1
  86. package/web/dist/assets/{task-notes-DxH2q3Hr.js → task-notes-DnIcoZgS.js} +1 -1
  87. package/web/dist/assets/task-workspace-DhUBQLGl.js +29 -0
  88. package/web/dist/assets/{terminal-aoRx5eKS.js → terminal-BIKtPgmL.js} +1 -1
  89. package/web/dist/assets/{terminal-drawer-CuGVJS-l.js → terminal-drawer-f0Tw3yHw.js} +2 -2
  90. package/web/dist/assets/{textarea-X_NVmVlZ.js → textarea-D6BGJB7j.js} +1 -1
  91. package/web/dist/assets/{token-metrics-CdH7TbLP.js → token-metrics-CMdTXREP.js} +1 -1
  92. package/web/dist/assets/{tooltip-C2bzSwbQ.js → tooltip-Bb7ddw0_.js} +1 -1
  93. package/web/dist/assets/{tracker-BYs-vq6-.js → tracker-BDiIqG2R.js} +2 -2
  94. package/web/dist/assets/{triangle-alert-BdMPm9Jb.js → triangle-alert-BhQYv6Is.js} +1 -1
  95. package/web/dist/assets/{upload-DrvICo_K.js → upload-Crivm77f.js} +1 -1
  96. package/web/dist/assets/{use-now-Byfm730u.js → use-now-BW1HO2p_.js} +1 -1
  97. package/web/dist/assets/{use-submit-shortcut-B41NLqM4.js → use-submit-shortcut-oBvmLiAo.js} +1 -1
  98. package/web/dist/assets/{workflow-graph-ppdi5xyK.js → workflow-graph-DJLPSGD3.js} +3 -3
  99. package/web/dist/assets/{worktree-lifecycle-operation-CvU6xu3u.js → worktree-lifecycle-operation-DL-RTic4.js} +2 -2
  100. package/web/dist/index.html +39 -39
  101. package/dist/telemetry-service.json +0 -1
  102. package/web/dist/assets/arrow-left-B1Ed0tpu.js +0 -1
  103. package/web/dist/assets/automation-format-CXffJGqm.js +0 -1
  104. package/web/dist/assets/automations-route-ruFF7d59.js +0 -1
  105. package/web/dist/assets/button-wdWSPx_B.js +0 -100
  106. package/web/dist/assets/check-DvAMBXJe.js +0 -1
  107. package/web/dist/assets/chevron-left-Dqb1lvgZ.js +0 -1
  108. package/web/dist/assets/chevron-right-DDQuVTY1.js +0 -1
  109. package/web/dist/assets/circle-check-BiVc-j8x.js +0 -1
  110. package/web/dist/assets/dashboard-BX4228zB.js +0 -44
  111. package/web/dist/assets/facet-filter-B_AsFqFx.js +0 -5
  112. package/web/dist/assets/file-preview-DEKEA-Hk.js +0 -2
  113. package/web/dist/assets/git-tab-loading-w5Ne43J6.js +0 -1
  114. package/web/dist/assets/github-Hshin4wG.js +0 -1
  115. package/web/dist/assets/index-CQ1cB3qE.css +0 -2
  116. package/web/dist/assets/index-D-pGbO9R.js +0 -31
  117. package/web/dist/assets/loader-circle-CwT0JWiv.js +0 -1
  118. package/web/dist/assets/plus-BwQyZgNP.js +0 -1
  119. package/web/dist/assets/queries-BTgOLNTK.js +0 -1
  120. package/web/dist/assets/repo-git-B47L82oV.js +0 -1
  121. package/web/dist/assets/skills-Bu12y3Zp.js +0 -1
  122. package/web/dist/assets/task-workspace-7NHIdOyT.js +0 -29
@@ -1,29 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-drawer-CuGVJS-l.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-runtime-CCIEwYL0.js","assets/queries-BTgOLNTK.js","assets/button-wdWSPx_B.js","assets/bundle-mjs-rHxsej31.js","assets/preload-helper-Czpn1I53.js","assets/host-usage-CI_ZlJQu.js","assets/use-desktop-BNN3U2y9.js","assets/tooltip-C2bzSwbQ.js","assets/icon-tooltip-CgAWLDxo.js","assets/terminal-aoRx5eKS.js","assets/loader-circle-CwT0JWiv.js","assets/square-FwRsgrg-.js","assets/plus-BwQyZgNP.js","assets/clipboard-DQGL_gUp.js","assets/alert-dialog-4Kna6Hd7.js","assets/tabs-nC1VLjcX.js","assets/input-Br4NQpZK.js","assets/drawer-state-DasOAIpO.js","assets/terminal-drawer-BrP-ENHg.css","assets/task-graph-CJfTnzUp.js","assets/project-router-DgQSavhI.js","assets/git-tab-loading-w5Ne43J6.js","assets/reference-chip-BxUGeHDa.js","assets/circle-check-BiVc-j8x.js","assets/triangle-alert-BdMPm9Jb.js","assets/git-pull-request-draft-Dwhm6Vhn.js","assets/token-metrics-CdH7TbLP.js","assets/textarea-X_NVmVlZ.js","assets/check-DvAMBXJe.js","assets/git-toolbar-C3vpZJaZ.js","assets/upload-DrvICo_K.js","assets/lib-w_5wfsBF.js","assets/use-submit-shortcut-B41NLqM4.js","assets/search-x-CLuL49ms.js","assets/collapsible-D7qsttC5.js","assets/centered-state-D-wDs7Y1.js","assets/workflow-graph-ppdi5xyK.js","assets/download-BBtWFvsh.js","assets/settings-2-BvalJGW-.js","assets/message-square-Dl-ol3uz.js","assets/save-ByUa-aAl.js","assets/tag-CteJEZQp.js","assets/index-D-pGbO9R.js","assets/facet-filter-B_AsFqFx.js","assets/use-now-Byfm730u.js","assets/arrow-left-B1Ed0tpu.js","assets/worktree-lifecycle-operation-CvU6xu3u.js","assets/file-CbWEaOku.js","assets/chevron-right-DDQuVTY1.js","assets/markdown-G3dvGJao.js","assets/chunk-BO2N2NFS-Bde6epwZ.js","assets/lib-BxQXEXDF.js","assets/index-CQ1cB3qE.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{$r as r,Ai as i,Bn as a,Dt as o,Fa as s,Ft as c,Hn as l,J as u,Jr as d,L as f,Lt as p,M as m,Ma as h,Na as g,Oa as _,Ot as v,Pi as y,Qn as b,Qr as x,Sa as S,Sr as C,St as w,U as T,V as E,Xr as D,Yi as O,Yr as k,Zr as A,_a as j,_n as ee,_t as M,a as N,b as P,ca as F,cr as I,ei as L,en as R,er as te,gi as ne,gr as z,gt as re,h as ie,ia as B,ja as V,ki as H,mi as ae,nn as oe,ot as U,pa as se,qr as ce,r as W,ri as le,st as G,tr as ue,u as de,vn as fe,x as K,xr as pe,xt as me}from"./queries-BTgOLNTK.js";import{Et as he,F as ge,Ft as _e,V as ve,i as ye,r as q,t as J}from"./button-wdWSPx_B.js";import{t as be}from"./preload-helper-Czpn1I53.js";import{C as xe,T as Se,c as Ce,f as Y,m as we,s as Te,t as Ee,w as De,x as Oe}from"./project-router-DgQSavhI.js";import{_ as ke,f as Ae,g as je,h as Me,m as Ne,p as Pe,s as Fe,v as Ie,y as Le}from"./reference-chip-BxUGeHDa.js";import{a as Re,b as ze,i as Be,n as Ve,o as He,s as Ue,x as We,y as Ge}from"./use-now-Byfm730u.js";import{t as Ke}from"./use-desktop-BNN3U2y9.js";import{$ as qe,$t as Je,An as Ye,Bt as Xe,Ct as Ze,Dn as Qe,Dt as $e,E as et,En as tt,Et as nt,G as rt,Gt as it,H as at,In as ot,J as st,Jt as ct,K as lt,Kt as ut,Ln as dt,M as ft,Mn as pt,Nt as mt,O as ht,Ot as gt,Pn as _t,Q as vt,R as yt,St as bt,Tn as xt,Tt as St,U as Ct,V as wt,W as Tt,X as Et,Xt as Dt,Y as Ot,Yt as kt,_ as At,_t as jt,at as Mt,bt as Nt,ct as Pt,dt as Ft,ft as It,g as Lt,gt as Rt,hn as zt,ht as Bt,it as Vt,j as Ht,kn as Ut,l as Wt,lt as Gt,mn as Kt,mt as qt,n as Jt,nt as Yt,ot as Xt,pn as Zt,pt as Qt,q as $t,qt as en,r as tn,rn as nn,rt as rn,st as an,u as on,ut as sn,v as cn,vt as ln,wt as un,xt as dn,yt as fn}from"./git-tab-loading-w5Ne43J6.js";import{c as pn,d as mn,f as hn,i as gn,l as _n,n as vn,o as yn,p as bn,r as xn,s as Sn,t as Cn,u as wn}from"./file-preview-DEKEA-Hk.js";import{t as Tn}from"./arrow-left-B1Ed0tpu.js";import{A as En,C as Dn,J as On,K as kn,O as An,T as jn,Y as Mn,g as Nn,i as Pn,m as Fn,n as In,p as Ln,q as Rn,r as zn,x as Bn}from"./worktree-lifecycle-operation-CvU6xu3u.js";import{t as Vn}from"./file-CbWEaOku.js";import{a as Hn,i as Un,r as Wn,t as Gn}from"./textarea-X_NVmVlZ.js";import{t as Kn}from"./check-DvAMBXJe.js";import{f as qn,i as Jn,n as Yn,r as Xn,t as Zn}from"./tooltip-C2bzSwbQ.js";import{t as Qn}from"./chevron-right-DDQuVTY1.js";import{t as $n}from"./circle-check-BiVc-j8x.js";import{a as er,c as tr,i as nr,n as rr,r as ir,t as ar,u as or}from"./icon-tooltip-CgAWLDxo.js";import{n as sr,t as cr}from"./terminal-aoRx5eKS.js";import{a as lr,h as ur,m as dr,p as fr,r as pr,u as mr}from"./git-toolbar-C3vpZJaZ.js";import{n as hr}from"./upload-DrvICo_K.js";import{n as gr,t as _r}from"./triangle-alert-BdMPm9Jb.js";import{t as vr}from"./loader-circle-CwT0JWiv.js";import{t as yr}from"./message-square-Dl-ol3uz.js";import{r as br,t as xr}from"./use-submit-shortcut-B41NLqM4.js";import{n as Sr}from"./square-FwRsgrg-.js";import{t as Cr}from"./plus-BwQyZgNP.js";import{t as wr}from"./search-x-CLuL49ms.js";import{n as Tr,t as Er}from"./clipboard-DQGL_gUp.js";import{n as Dr,r as Or,t as kr}from"./collapsible-D7qsttC5.js";import{a as Ar,c as jr,i as Mr,n as Nr,o as Pr,r as Fr,s as Ir,t as Lr}from"./alert-dialog-4Kna6Hd7.js";import{i as Rr,r as zr,t as Br}from"./tabs-nC1VLjcX.js";import{t as Vr}from"./input-Br4NQpZK.js";import{i as Hr}from"./token-metrics-CdH7TbLP.js";import{t as Ur}from"./lib-w_5wfsBF.js";import{n as Wr,r as Gr}from"./drawer-state-DasOAIpO.js";import{n as Kr,t as qr}from"./centered-state-D-wDs7Y1.js";import{t as Jr}from"./markdown-G3dvGJao.js";import{t as Yr}from"./markdown-BfZORc0a.js";import{a as Xr}from"./scroll-within-Dexi68h1.js";import{n as Zr,t as Qr}from"./types-BTlmexWF.js";import{t as $r}from"./run-diff-CqXLVaDj.js";import{t as ei}from"./diff-DY-_mmb0.js";import{i as ti,r as ni,t as ri}from"./task-commits-CYcqwz-f.js";import{n as ii,r as ai,t as oi}from"./layout-cards-fdJa2H62.js";var si=120;function ci(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function li(e){let t=e.replace(/\s+/g,` `).trim();return t.length>si?`${t.slice(0,si-1)}…`:t}function X(e,...t){if(ci(e))for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim()!==``)return li(t)}}function ui(e){if(!ci(e))return;let t=e.command;if(typeof t==`string`&&t.trim()!==``)return li(t);if(Array.isArray(t)){let e=t.filter(e=>typeof e==`string`);if(e.length>0)return li(e.join(` `))}}function di(e){if(!ci(e)||!Array.isArray(e.changes))return[];let t=[];for(let n of e.changes)ci(n)&&typeof n.path==`string`&&n.path.trim()!==``&&t.push(n.path);return t}function fi(e){return X(e,`description`,`query`,`url`,`filePath`,`file_path`,`path`,`pattern`,`name`)}function pi(e,t){return t?`${e} ${t}`:e}function mi(e,t){let n=typeof e==`string`?e.toLowerCase():``;switch(n){case`bash`:case`commandexecution`:return{toolKind:`execute`,title:pi(`Ran`,ui(t)),subtitle:X(t,`description`)};case`edit`:case`multiedit`:return{toolKind:`edit`,title:pi(`Edit`,X(t,`file_path`,`filePath`,`path`))};case`write`:return{toolKind:`edit`,title:pi(`Write`,X(t,`file_path`,`filePath`,`path`))};case`notebookedit`:return{toolKind:`edit`,title:pi(`Edit`,X(t,`notebook_path`,`notebookPath`,`file_path`,`filePath`,`path`))};case`filechange`:{let e=di(t);return{toolKind:`edit`,title:pi(`Edit`,e.length===1?e[0]:e.length>1?`${e.length} files`:void 0)}}case`read`:return{toolKind:`read`,title:pi(`Read`,X(t,`file_path`,`filePath`,`path`))};case`imageview`:return{toolKind:`read`,title:pi(`View image`,X(t,`path`))};case`glob`:case`grep`:return{toolKind:`search`,title:pi(`Search`,X(t,`pattern`,`query`)),subtitle:X(t,`path`)};case`webfetch`:return{toolKind:`fetch`,title:pi(`Fetch`,X(t,`url`))};case`websearch`:return{toolKind:`fetch`,title:pi(`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:fi(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()!==``?li(e):`Tool`,subtitle:fi(t)}}var hi=ge(`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`}]]),gi=ge(`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`}]]),_i=ge(`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`}]]),vi=ge(`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`}]]),yi=ge(`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`}]]),bi=ge(`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`}]]),xi=ge(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Si=ge(`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 Ci(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 wi=5,Ti=120,Ei=200,Di=5e3,Oi=15e3,ki=[];function Ai(...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 ji(e){let t=-1/0;for(let n of e){if(n.seq<=t)return!1;t=n.seq}return!0}function Mi(e){for(let t=e.length-1;t>=0;--t)if(e[t].newerCursor===void 0)return e[t]}function Ni(...e){if(!e.every(ji))return Ai(...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 Pi(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=Ge(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(Ge(e)??``);return t!==void 0&&t>e.seq}).map(({seq:e})=>e)}function Fi(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 Ai(e,t);r=n.seq}return e.length===0||t[0].seq>n?[...e,...t]:Ni(e,t)}function Ii(e){let t=ve(),n=s(),r=[`run-history`,t,e],i=[`run-history-context`,t,e],a=[`run-history-tail`,t,e],o=V({queryKey:r,enabled:e!==void 0,initialPageParam:void 0,queryFn:({pageParam:t,signal:n})=>k(e,t,{signal:n}),getPreviousPageParam:e=>e.olderCursor,getNextPageParam:e=>e.newerCursor,maxPages:wi,retry:1}),c=g({queryKey:i,enabled:e!==void 0,queryFn:({signal:t})=>D(e,{signal:t}),retry:1}),l=o.isError&&o.data===void 0&&!o.isFetchPreviousPageError&&!o.isFetchNextPageError&&!o.isRefetchError,u=c.isError&&c.data===void 0&&!c.isRefetchError,d=o.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()),_=(0,Z.useRef)(0);m.current.key!==p&&(m.current={key:p,fallbackLatched:!1},h.current=Promise.resolve(),_.current+=1,f.current=void 0),(l||u)&&(m.current.fallbackLatched=!0);let v=m.current.fallbackLatched,y=(0,Z.useCallback)(e=>{let t=h.current,n;return h.current=new Promise(e=>{n=e}),t.then(e).finally(n)},[]),x=Mi(d),S=d.length>0?n.getQueryData(a):void 0;x&&(!f.current||x.asOfSeq>=f.current.asOfSeq)?f.current=x:S&&(!f.current||S.asOfSeq>=f.current.asOfSeq)&&(f.current=S);let C=f.current??x??S??(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 i=_.current,o=new AbortController,s;try{let c=await Promise.race([k(e,void 0,{signal:o.signal}),new Promise((e,t)=>{s=setTimeout(()=>{o.abort(),t(Error(`history compaction timed out`))},Oi)})]);if(m.current.key!==p||_.current!==i)return!1;let l=n.getQueryData(r),u=Mi(l?.pages??[]),d=n.getQueryData(a);if(Math.max(u?.asOfSeq??-1/0,d?.asOfSeq??-1/0,f.current?.asOfSeq??-1/0)>=c.asOfSeq)return!1;let h=l?(()=>{let e=[...l.pages],t=[...l.pageParams],n=u?e.indexOf(u):-1;for(n>=0?(e[n]=c,t[n]=void 0):(e.push(c),t.push(void 0));e.length>wi;)e.shift(),t.shift();return{pages:e,pageParams:t}})():{pages:[c],pageParams:[void 0]};return n.setQueryData(r,h),n.setQueryData(a,c),f.current=c,Pi(t,h.pages.flatMap(e=>e.events),c.asOfSeq)}catch{return!1}finally{clearTimeout(s),o.abort(),w.current===p&&(w.current=void 0)}},[r,p,n,e,a]),E=(0,Z.useCallback)(e=>{let t=W.runs.detail(e.id);n.getQueryData(t)!==void 0&&n.setQueryData(t,t=>t===void 0?e:b(t,e))},[n]),O=We(C&&!v?e:void 0,C?{cursor:C.liveCursor,afterSeq:C.asOfSeq,compactWhenOver:Di,compactAt:Ei,onCompact:T,onRun:E}:{onRun:E}),A=We(v?e:void 0,{onRun:E}),j=Ci(O,Ti,e),ee=Ci(A,Ti,e),M=(0,Z.useRef)({runId:void 0,scope:t,events:[]});(M.current.runId!==e||M.current.scope!==t)&&(M.current={runId:e,scope:t,events:[]}),v||(M.current.events=j);let N=v?M.current.events:ki,P=(0,Z.useMemo)(()=>{let e=d.map(e=>e.events);return C!==void 0&&!d.includes(C)&&e.push(C.events),Ai(...e)},[C,d]);(0,Z.useEffect)(()=>{let e=Mi(d);e&&n.setQueryData(a,e)},[d,n,e,t]);let F=(0,Z.useMemo)(()=>v?Ni(P,N,ee):Fi(P,j),[v,ee,N,j,P]),I=(0,Z.useMemo)(()=>{if(v)return F;let e=c.data?.contextEvents??[],t=c.data?.asOfSeq??0;return Ni(e,F.filter(({seq:e})=>e>t),j.filter(({seq:e})=>e<=t))},[c.data,v,j,F]),L=(0,Z.useCallback)(async()=>{let e=p,t=_.current,i=Mi(n.getQueryData(r)?.pages??[]);i&&n.setQueryData(a,i);try{await y(()=>o.fetchPreviousPage())}finally{if(m.current.key!==e||_.current!==t)return;let i=f.current;if(!i)return;n.setQueryData(r,e=>{if(!e)return e;let t=Mi(e.pages),n=t?e.pages.indexOf(t):-1;if(n<0||e.pages[n].asOfSeq>=i.asOfSeq)return e;let r=[...e.pages];return r[n]=i,{...e,pages:r}})}},[y,o.fetchPreviousPage,r,n,a]),R=(0,Z.useCallback)(async()=>{_.current+=1,h.current=Promise.resolve();let e=e=>f.current??Mi(e)??n.getQueryData(a),t=n.getQueryData(r);if(!e(t?.pages??[])){f.current=void 0,n.removeQueries({queryKey:a,exact:!0}),n.resetQueries({queryKey:r,exact:!0});return}if(t?.pages.length===1&&t.pages[0]===e(t.pages)&&!o.isFetchingPreviousPage)return;await n.cancelQueries({queryKey:r,exact:!0});let i=e(n.getQueryData(r)?.pages??[]);i&&(n.setQueryData(r,{pages:[i],pageParams:[void 0]}),n.setQueryData(a,i),f.current=i)},[o.isFetchingPreviousPage,r,n,a]);return{visibleEvents:F,currentEvents:I,isPending:!v&&o.isPending,contextPending:!v&&c.isPending,fallback:v,hasOlder:!v&&!!o.hasPreviousPage,isFetchingOlder:o.isFetchingPreviousPage,olderError:o.isFetchPreviousPageError?o.error instanceof Error?o.error.message:`Could not load earlier items`:void 0,loadOlder:L,jumpToLatest:R,retainedPages:d.length}}var Li=`design-picks`,Ri=(e,t)=>typeof e==`string`?e.slice(0,t):``,zi=e=>typeof e==`number`&&Number.isFinite(e)?Math.round(e):0;function Bi(e){if(typeof e!=`object`||!e)return null;let t=e,n=Ri(t.selector,400),r=Ri(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:Ri(t.url,2e3),selector:n,tag:r,text:Ri(t.text,200),html:Ri(t.html,1600),styles:o,rect:{x:zi(i.x),y:zi(i.y),width:zi(i.width),height:zi(i.height)},viewport:{width:zi(a.width),height:zi(a.height)},components:Array.isArray(t.components)?t.components.filter(e=>typeof e==`string`).slice(0,6).map(e=>e.slice(0,80)):[],source:Ri(t.source,300),...typeof t.mark==`string`&&/^[a-z0-9-]{1,24}$/.test(t.mark)?{mark:t.mark}:{}}}function Vi(e){let t=e.selector.split(` > `).at(-1)??e.tag;return e.components[0]?`${e.components[0]} · ${t}`:t}var Hi=`Elements selected in the app preview:`;function Ui(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 Wi=e=>e.split(`
3
- `).map(e=>e===``?``:` ${e}`).join(`
4
- `);function Gi(e){return e.length===0?``:`${Hi}\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${Wi(Ui(e.html,`html`))}`}).join(`
6
-
7
- `)}`}function Ki(e,t){let n=Gi(t);if(n===``)return e;let r=e.trim()===``?n:`${e}\n\n${n}`;if(r.length>1e5)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(),qi=12e3,Ji=/^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[?::1\]?|.+\.local)$/i;function Yi({state:e,onChange:t,onPickElement:n,designMarks:r,renderDesignNote:i,onDesignEscape:a,designTray:o,renderEmpty:s}){let c=e.tabs.length>0?e.tabs:[``],l=Math.min(e.active,c.length-1),u=c[l]??``,[d,f]=(0,Z.useState)(u),[p,h]=(0,Z.useState)(u===``?`idle`:`loading`),[g,_]=(0,Z.useState)(0),[v,y]=(0,Z.useState)(u),b=m(),x=(0,Z.useRef)(null),[S,C]=(0,Z.useState)({}),w=S[l]??ia(u),T=w.position>0,E=w.position>=0&&w.position<w.stack.length-1,[D,O]=(0,Z.useState)(null),k=(0,Z.useRef)(0),A=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{if(x.current&&x.current.index===l&&x.current.url===u){x.current=null;return}x.current=null,f(u),y(u),h(u===``?`idle`:`loading`),A.current&&_(e=>e+1),A.current=!0},[l,u]);let j=b.data?.capabilities?.localHandoff??!0,[ee,M]=(0,Z.useState)(()=>new Set),N=v!==``&&!j&&ga(v)&&!ee.has(fa(v)??``),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(null),[R,te]=(0,Z.useState)(!1),ne=(0,Z.useRef)(null),z=(0,Z.useRef)(null),re=n!==void 0,ie=re&&(b.data?.capabilities?.designMode??!1),B=ie?null:b.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)`,V=ca(v),H=ie&&P&&V!==null,oe=(0,Z.useRef)(()=>!1);oe.current=()=>!ie||V===null?!1:(P||Zt(`shortcut`),F(e=>!e),!0),(0,Z.useEffect)(()=>{if(!re)return;let e=e=>{e.repeat||e.defaultPrevented||!Zi(e)||document.querySelector(`[role="dialog"]:not([data-slot="browser-design-note"]), [role="alertdialog"]`)||oe.current()&&e.preventDefault()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[re]);let U=I!==null&&I.upstream===V?I.origin:null,se=H&&U===null,ce=(0,Z.useCallback)(e=>U!==null&&V!==null?U+e.slice(V.length):e,[U,V]),W=ce(v),le=`${ua(W)}#${g}`,G=D??v;(0,Z.useEffect)(()=>{O(null),k.current=0},[le]),(0,Z.useEffect)(()=>{if(!H||V===null)return;let e=!1;return ae({target:V,parentOrigin:window.location.origin}).then(t=>{e||L({upstream:V,origin:t.origin})}).catch(t=>{e||(F(!1),Y(t instanceof Error&&t.message?t.message:`Design Mode could not start.`,{tone:`danger`}))}),()=>{e=!0}},[H,g,V]),(0,Z.useEffect)(()=>te(!1),[le]),(0,Z.useEffect)(()=>{!R||U===null||ne.current?.contentWindow?.postMessage({source:`cezar-design-host`,type:`set-active`,active:H},U)},[H,U,R]);let ue=i!==void 0,[de,fe]=(0,Z.useState)(!1),[K,pe]=(0,Z.useState)(null),[me,he]=(0,Z.useState)({}),[ge,_e]=(0,Z.useState)(!1),ve=(0,Z.useRef)(null),ye=(0,Z.useRef)(null),[be,xe]=(0,Z.useState)(null),Se=(0,Z.useCallback)(()=>fe(!1),[]),Ce=r??$i,we=K!==null&&Ce.some(e=>e.key===K),Te=ue&&ie&&de&&we,Ee=K===null?void 0:me[K],De=ue&&U!==null&&ge?Ce.filter(e=>e.draft&&!(e.key in me)):$i,Oe=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{we?Oe.current=K:de&&Oe.current===K&&fe(!1)},[K,we,de]),(0,Z.useEffect)(()=>{he({}),_e(!1)},[le]),(0,Z.useLayoutEffect)(()=>{if(!Te)return;let e=ve.current,t=ye.current;!e||!t||xe(ra(Ee,{width:e.clientWidth,height:e.clientHeight},{width:t.offsetWidth,height:t.offsetHeight}))},[K,Ee,Te]);let ke=be!==null;(0,Z.useEffect)(()=>{Te&&ke&&ye.current?.querySelector(`textarea`)?.focus()},[K,Te,ke]);let Ae=JSON.stringify(Ce.map(({key:e,n:t,selector:n,path:r})=>({key:e,n:t,selector:n,path:r}))),je=(0,Z.useCallback)(()=>{U!==null&&ne.current?.contentWindow?.postMessage({source:`cezar-design-host`,type:`set-marks`,marks:JSON.parse(Ae)},U)},[Ae,U]);(0,Z.useEffect)(()=>{R&&je()},[R,je]);let Me=(0,Z.useRef)(null);Me.current=Te?K:null,(0,Z.useEffect)(()=>{if(U===null)return;let e=e=>{if(e.origin!==U||e.source!==ne.current?.contentWindow)return;let t=e.data;if(!(typeof t!=`object`||!t||t.source!==`cezar-design`)){if(t.type===`ready`)te(!0);else if(t.type===`toggle`)F(!1);else if(t.type===`cancel`)Me.current===null?F(!1):(a?.(Me.current),fe(!1));else if(t.type===`mark-clicked`&&typeof t.key==`string`)pe(t.key),fe(!0);else if(t.type===`rects`)he(ea(t.rects)),_e(!0);else if(t.type===`picked`){let e=Bi(t.element);if(!e||!n?.(e)){je();return}if(!ue){Y(`Element picked.`);return}let r=e.mark;r!==void 0&&he(t=>({...t,[r]:e.rect})),pe(r??null),fe(!0)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ue,U,a,n,je]);let Ne=(0,Z.useCallback)(()=>{P||L(null)},[P]);(0,Z.useEffect)(()=>{if(p!==`loading`||v===``||N)return;let e=setTimeout(()=>h(`failed`),qi);return()=>clearTimeout(e)},[N,g,p,v]);let Pe=(0,Z.useCallback)(n=>{c[l]===n||n.length>vt||(x.current={index:l,url:n},t({...e,tabs:c.map((e,t)=>t===l?n:e)}))},[l,t,e,c]),Fe=(0,Z.useCallback)(e=>{if(p===`idle`&&!N&&e!==G&&da(G,e)){O(null),y(e),f(e),e===v&&ne.current&&(ne.current.src=ce(e)),Pe(e);return}Ne(),O(null),y(e),f(e),h(`loading`),_(e=>e+1)},[ce,Pe,N,Ne,G,p,v]),Ie=(0,Z.useCallback)(e=>{let t=sa(e);t!==null&&(C(e=>{let n=e[l]??ia(u),r=n.stack.slice(0,n.position+1);if(r[r.length-1]===t)return e;let i=[...r,t].slice(-aa);return{...e,[l]:{stack:i,position:i.length-1}}}),Fe(t))},[l,u,Fe]),Le=(0,Z.useCallback)(e=>{let t=w.position+e,n=w.stack[t];n!==void 0&&(C(e=>({...e,[l]:{stack:w.stack,position:t}})),Fe(n))},[l,w.position,w.stack,Fe]),Re=(0,Z.useCallback)(()=>{v!==``&&(k.current+=1,h(`idle`),Pe(G))},[Pe,G,v]),ze=(0,Z.useCallback)((e,t)=>{O(e),f(t=>t===G||document.activeElement!==z.current?e:t),C(n=>{let r=n[l]??ia(u);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`&&k.current>0||r.position<0){let t=[...r.stack.slice(0,r.position+1),e].slice(-aa);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,[l]:i}}),p===`idle`&&Pe(e)},[l,u,Pe,G,p]),Be=fa(W);(0,Z.useEffect)(()=>{if(Be===null)return;let e=e=>{if(e.origin!==Be||e.source!==ne.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=pa(t.url,Be,U===null?null:V);n!==null&&ze(n,typeof t.how==`string`?t.how:`replace`)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ze,Be,U,V]);let Ve=(0,Z.useCallback)(()=>{c.length>=Ot||t({tabs:[...c,``],active:c.length})},[t,c]),He=(0,Z.useCallback)(e=>{let n=c.filter((t,n)=>n!==e);if(n.length===0){t(Ft()),C({});return}t({tabs:n,active:e<l?l-1:Math.min(l,n.length-1)}),C(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})},[l,t,c]);return(0,Q.jsxs)(`div`,{"data-slot":`browser-view`,className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(Br,{value:String(l),onValueChange:n=>t({...e,active:Number(n)}),className:`shrink-0 gap-0`,children:(0,Q.jsxs)(zr,{"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:[c.map((n,r)=>(0,Q.jsxs)(`div`,{"data-slot":`browser-tab`,"data-active":r===l?``:void 0,className:q(`group flex h-6 shrink-0 items-center rounded-sm pl-2 pr-0.5 text-xs font-medium`,r===l?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:[(0,Q.jsx)(Rr,{value:String(r),onClick:()=>{r!==l&&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:oa(n)}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Close tab ${oa(n)}`,onClick:()=>He(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===l&&`opacity-60`),children:(0,Q.jsx)(Tr,{"aria-hidden":`true`,className:`size-3`})})]},r)),c.length<Ot?(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`New tab`,title:`New tab`,onClick:Ve,className:`size-6 rounded`,children:(0,Q.jsx)(Cr,{"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)(Qi,{label:`Back`,disabled:!T,onClick:()=>Le(-1),icon:(0,Q.jsx)(Tn,{"aria-hidden":`true`,className:`size-3.5`})}),(0,Q.jsx)(Qi,{label:`Forward`,disabled:!E,onClick:()=>Le(1),icon:(0,Q.jsx)(Mn,{"aria-hidden":`true`,className:`size-3.5`})}),(0,Q.jsx)(Qi,{label:`Reload`,onClick:()=>{v!==``&&(Ne(),O(null),y(G),f(G),h(`loading`),_(e=>e+1))},icon:(0,Q.jsx)(bi,{"aria-hidden":`true`,className:q(`size-3.5`,p===`loading`&&`animate-spin`)})}),(0,Q.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),Ie(d)},children:(0,Q.jsx)(Vr,{ref:z,value:d,onChange:e=>f(e.target.value),placeholder:`Enter an address, e.g. http://localhost:3000`,"aria-label":`Address`,spellCheck:!1,className:`h-8 text-ui focus-visible:ring-ring/30 md:text-ui`})}),re?(0,Q.jsxs)(J,{type:`button`,"data-slot":`browser-design-toggle`,variant:H?`primary`:`outline`,size:`sm`,"aria-pressed":H,disabled:B!==null||V===null,title:B??(V===null?`Design Mode works on local http:// addresses`:H?`Stop selecting elements (${Xe(Xi)} or Esc)`:`Click an element of the page to send it to the agent (${Xe(Xi)})`),onClick:()=>{P||Zt(`button`),F(e=>!e)},className:`ml-1 disabled:opacity-40`,children:[(0,Q.jsx)(wn,{"aria-hidden":`true`,className:`size-3.5`}),`Design Mode`,(0,Q.jsx)(`kbd`,{"data-slot":`browser-design-key`,"aria-hidden":`true`,className:`ml-0.5 rounded border border-current/25 px-1 font-sans text-micro leading-4 opacity-70`,children:Xe(Xi)})]}):null]}),(0,Q.jsxs)(`div`,{ref:ve,className:`relative min-h-0 flex-1`,children:[N?(0,Q.jsx)(qr,{icon:(0,Q.jsx)(_r,{}),tone:`neutral`,heading:`h2`,title:`This address points at the machine you are sitting at`,subtitle:`This cockpit runs remotely, so a local address opens on your computer rather than on the task's host. Forward the port from your computer first:`,children:(0,Q.jsx)(ha,{url:v,onTunneled:()=>{let e=fa(v);e&&M(t=>new Set(t).add(e))}})}):v===``&&s?s(Ie):v===``?(0,Q.jsx)(qr,{icon:(0,Q.jsx)(pt,{}),tone:`neutral`,heading:`h2`,title:`Empty tab`,subtitle:j?`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.`:`Enter the address of the task's app, e.g. http://localhost:3000. This cockpit runs remotely: start the app in the task's terminal (on a hosted cockpit it needs CEZ_TERMINAL=1), and cezar shows the SSH command that forwards its port to you.`}):(0,Q.jsxs)(Q.Fragment,{children:[p===`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,De.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:De.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:()=>{pe(e.key),fe(!0)},className:`max-w-48`,children:(0,Q.jsxs)(`span`,{className:`truncate`,children:[`Draft · `,e.label]})},e.key))}):null,ie&&o?(0,Q.jsx)(`div`,{className:`absolute right-3 bottom-3 z-10`,children:o}):null,H&&p===`idle`&&!Te&&De.length===0&&!o?(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:ue?`Click an element to write a note about it · Esc to stop`:`Click an element to pick it · Esc to stop`}):null,se?null:(0,Q.jsx)(`iframe`,{ref:ne,src:W,title:`Preview`,onLoad:Re,sandbox:`allow-same-origin allow-scripts allow-forms allow-modals allow-popups`,allow:``,referrerPolicy:`no-referrer`,className:q(`size-full border-0`,p===`loading`&&`invisible`)},le),p===`loading`?(0,Q.jsx)(`p`,{className:`absolute inset-0 grid place-items-center text-xs text-soft-foreground`,children:`Loading…`}):null]}),Te?(0,Q.jsx)(`div`,{ref:ye,"data-slot":`browser-design-note`,role:`dialog`,"aria-label":`Note about the selected elements`,style:be?{left:be.left,top:be.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:Se})}):null]})]})}var Xi=`Alt+D`;function Zi(e){return(e.code?e.code===`KeyD`:e.key===`d`||e.key===`D`)&&e.altKey&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey}function Qi({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 $i=[];function ea(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 ta=10,na=8;function ra(e,t,n){let r=Math.max(na,t.width-n.width-na),i=Math.max(na,t.height-n.height-na);if(!e)return{left:r,top:i};let a=(e,t)=>Math.min(Math.max(e,na),t),o=e.y+e.height+ta,s=e.y-ta-n.height,c=o+n.height+na<=t.height?o:s>=na?s:o;return{left:a(e.x,r),top:a(c,i)}}function ia(e){return e===``?{stack:[],position:-1}:{stack:[e],position:0}}var aa=50;function oa(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 sa(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 ca(e){if(e===``)return null;try{let t=new URL(e);return t.protocol!==`http:`||!la.test(t.hostname)?null:t.origin}catch{return null}}var la=/^(localhost|127\.0\.0\.1|\[::1\])$/i;function ua(e){let t=e.indexOf(`#`);return t===-1?e:e.slice(0,t)}function da(e,t){return e!==``&&t.includes(`#`)&&ua(e)===ua(t)}function fa(e){try{let t=new URL(e).origin;return t===`null`?null:t}catch{return null}}function pa(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 sa((n??t)+i)}function ma(e,t){try{let n=new URL(e),r=n.port||(n.protocol===`https:`?`443`:`80`);return`ssh -N -L ${r}:localhost:${r} ${t||`<host>`}`}catch{return null}}function ha({url:e,onTunneled:t}){let n=ma(e,window.location.hostname);return n?(0,Q.jsxs)(`div`,{"data-slot":`browser-tunnel`,className:`flex w-full flex-col items-center gap-3`,children:[(0,Q.jsx)(`code`,{className:`w-full rounded-md border border-border bg-muted px-3 py-2 font-mono text-xs break-all text-foreground select-all`,children:n}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{navigator.clipboard?.writeText(n).then(()=>Y(`Copied the SSH command.`),()=>Y(`Could not copy — select the command instead.`,{tone:`danger`}))},children:`Copy command`}),(0,Q.jsx)(J,{type:`button`,size:`sm`,"data-action":`browser-tunnel-open`,onClick:t,children:`The tunnel is open — show it here`}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,asChild:!0,children:(0,Q.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,children:`Open in a new tab`})})]})]}):null}function ga(e){try{return Ji.test(new URL(e).hostname)}catch{return!1}}var _a=5,va=[{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 ya({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)([``]),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),g=e=>{let t=e??n;l(t.services.length>0?[...t.services]:[``]),d(t.url??``)};(0,Z.useEffect)(()=>{if(!e)return;p(null);let t=!1;return le().then(e=>{if(t)return;a(e);let n=e.personal?`personal`:`project`;s(n),g(e[n])}).catch(e=>!t&&p(e instanceof Error?e.message:String(e))),()=>{t=!0}},[e]);let _=async e=>{h(!0),p(null);try{a(await B({scope:o,recipe:e})),r(),t(!1)}catch(e){p(e instanceof Error?e.message:String(e))}finally{h(!1)}},v=c.map(e=>e.trim()).filter(Boolean),y=u.trim(),b=y!==``&&!/^https?:\/\/\S+$/.test(y);return(0,Q.jsx)(Ae,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Pe,{className:`sm:max-w-lg`,children:[(0,Q.jsxs)(je,{children:[(0,Q.jsx)(ke,{children:`Start recipe`}),(0,Q.jsx)(Ne,{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:va.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),g(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)(Vr,{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)(Tr,{"aria-hidden":`true`})})]},t)),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`xs`,className:`self-start text-muted-foreground`,disabled:c.length>=_a,onClick:()=>l(e=>[...e,``]),children:[(0,Q.jsx)(Cr,{"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)(Vr,{value:u,onChange:e=>d(e.target.value),placeholder:`http://localhost:5173 — empty: the first address a service prints`,"aria-label":`Address to show`,"aria-invalid":b,spellCheck:!1,className:`h-8 font-mono text-xs md:text-xs`}),b?(0,Q.jsx)(`span`,{className:`text-danger`,children:`Start it with http:// or https://`}):null]}),f?(0,Q.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:f}):null]}),(0,Q.jsxs)(Me,{className:`gap-2 sm:justify-between`,children:[i?.[o]?(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,disabled:m,onClick:()=>void _(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:m||v.length===0||b,onClick:()=>void _({services:v,...y?{url:y}:{}}),children:`Save`})]})]})]})})}var ba=1e3,xa=12e4,Sa=6e5,Ca=[`dev`,`start`,`serve`,`preview`,`run`],wa=e=>`cez:preview-run:${e??`default`}`;function Ta(e){try{return window.localStorage.getItem(wa(e))}catch{return null}}function Ea(e,t){try{window.localStorage.setItem(wa(e),t)}catch{}}function Da(e){for(let t of Ca){let n=e.find(e=>RegExp(`^(npm run|make) ${t}$`).test(e.command));if(n)return n.command}return null}function Oa(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 ka(e,t,n){let r=e.filter(e=>Date.parse(e.lastSeenAt)>=t&&e.running!==!1);return n?r.some(e=>Oa(e.url,n))?n:null:(r.find(e=>e.running===!0)??r[0])?.url??null}function Aa({runId:e,projectId:t,onOpen:n,onShowTerminal:i,setup:a}){let o=a?.phase===`setup`&&a.needsAttention,s=a?.phase===`setup`&&!a.needsAttention&&a.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)(()=>Ta(t)),[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)({kind:`idle`}),[b,S]=(0,Z.useState)(!1),w=(0,Z.useCallback)(()=>{let t=!1;return r(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 s=()=>E.current===o,c=e=>D.current.push(setTimeout(e,ba)),l={services:a,...r.url?{url:r.url}:{}};i.remember&&a[0]&&(Ea(t,a[0]),h(a[0]));let f=async t=>{let n=await x(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},p=async()=>{y({kind:`starting`,plan:l});let t=Date.now()-1e3,r=[];for(let t of a){let n=await C(e,{});if(!s())return;r.push(n.id),await j(e,n.id,`${t}\r`)}let i=async()=>{if(!s())return;if(Date.now()-t>xa){y({kind:`no-address`,plan:l});return}let o=await L(e).catch(()=>null);if(!s())return;let u=o?ka(o.urls,t,l.url):null;if(u){E.current=null,n(u);return}let d=await f(r);if(s()){if(d){y({kind:`exited`,command:a[d.index],code:d.code});return}c(()=>void i())}};await i()};(async()=>{if(!u)return p();y({kind:`installing`,install:u,plan:l});let t=Date.now(),n=await C(e,{});if(!s())return;await j(e,n.id,`${u} && exit 0 || exit 1\r`);let r=async()=>{if(!s())return;if(Date.now()-t>Sa){y({kind:`no-address`,plan:l});return}let e=await f([n.id]);if(s()){if(!e)return c(()=>void r());if(e.code!==0){y({kind:`exited`,command:u,code:e.code});return}d(null),await p()}};c(()=>void r())})().catch(()=>{s()&&y({kind:`failed`})})},[u,n,t,e]),k=(c??[]).filter(e=>f!==null||e.command!==T),A=i?(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:[(0,Q.jsx)(cr,{"aria-hidden":`true`}),`Show terminal`]}):null,ee=(0,Q.jsx)(ya,{open:b,onOpenChange:S,suggestion:f?{services:f.services,...f.url?{url:f.url}:{}}:{services:T?[T]:[``]},onSaved:w});if(v.kind===`installing`||v.kind===`starting`){let e=v.plan.services.join(` · `);return(0,Q.jsx)(ja,{icon:(0,Q.jsx)(vr,{"aria-hidden":`true`,className:`size-5 motion-safe:animate-spin`}),title:v.kind===`installing`?`Installing dependencies (${v.install})`:`Starting ${e}`,subtitle:v.kind===`installing`?`This worktree has no dependencies yet. ${e} starts as soon as they are installed.`:`Running in ${v.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${v.plan.url?` at ${v.plan.url}`:``}.`,children:A})}let M=v.kind===`exited`?`${v.command} exited with code ${v.code} before the app was up.`:v.kind===`no-address`?`${v.plan.services.join(` · `)} is still running, but ${v.plan.url?`nothing answered at ${v.plan.url}`:`printed no address`} yet. Enter it above, or check the terminal.`:v.kind===`failed`?`Could not open a terminal for this task.`:null,N=(0,Q.jsxs)(rr,{children:[(0,Q.jsx)(or,{asChild:!0,children:(0,Q.jsxs)(J,{type:`button`,variant:f||T?`outline`:`primary`,size:`sm`,"data-action":`run-app-other`,disabled:s,children:[f||T?`Other command`:`Choose a command`,(0,Q.jsx)(qn,{"aria-hidden":`true`})]})}),(0,Q.jsxs)(ir,{align:`center`,className:`max-h-80 w-80 overflow-y-auto`,children:[(0,Q.jsx)(er,{children:`Project commands`}),k.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.`}):k.map(e=>(0,Q.jsxs)(nr,{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-meta text-soft-foreground`,children:[e.source,e.detail?` — ${e.detail}`:``]})]},`${e.source}:${e.command}`)),(0,Q.jsx)(tr,{}),(0,Q.jsx)(er,{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}),_(``)},children:(0,Q.jsx)(Vr,{value:g,onChange:e=>_(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=s?`This worktree's setup scripts are still running. Start the app when they finish.`:o?`This worktree's setup needs attention — retry it from the task's Chat, or start the app anyway.`:null;return(0,Q.jsxs)(ja,{icon:(0,Q.jsx)(Sr,{"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:s,onClick:()=>O(f),children:[(0,Q.jsx)(Sr,{"aria-hidden":`true`}),`Start app`]}):T?(0,Q.jsxs)(J,{type:`button`,size:`sm`,"data-action":`run-app`,disabled:s,onClick:()=>O({services:[T]},{remember:!0}),children:[(0,Q.jsx)(Sr,{"aria-hidden":`true`}),`Run `,(0,Q.jsx)(`code`,{className:`font-mono text-label`,children:T})]}):null,N,M?A:null]}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`xs`,"data-action":`edit-start-app`,className:`text-muted-foreground`,onClick:()=>S(!0),children:[(0,Q.jsx)(br,{"aria-hidden":`true`}),f?`Edit start recipe`:`Save a start recipe for this project`]}),ee]})}function ja({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 Ma={running:{label:`In progress`,tone:`pending`,pulse:!0},asking:{label:`Agent is waiting for your answer`,tone:`violet`},done:{label:`Done`,tone:`success`}};function Na({note:e,notes:t,onClose:n}){let r=e.phase===`draft`,i=e.text.trim()===``,a=r&&!e.added,o=()=>{a&&t.discard(e.key),n()},s=()=>{t.discard(e.key),n()},c=()=>{if(e.added)return n();i||(t.markAdded(e.key),n())},l=r?null:Ma[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)(yr,{"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-meta font-medium text-foreground`,title:e.pick.selector,children:Vi(e.pick)}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-6`,"aria-label":a?`Discard note`:`Close`,title:a?`Discard this note and deselect the element (Esc)`:`Close (Esc)`,onClick:o,children:(0,Q.jsx)(Tr,{"aria-hidden":`true`})})]}),l?(0,Q.jsxs)(`p`,{"data-slot":`design-note-status`,className:`flex items-center gap-1.5 text-soft-foreground`,children:[(0,Q.jsx)(Hr,{tone:l.tone,pulse:l.pulse??!1}),l.label]}):null,r?(0,Q.jsx)(Gn,{value:e.text,onChange:n=>t.setText(e.key,n.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),o()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),c())},placeholder:`What should change here?`,readOnly:e.sending===!0,"aria-label":`Note for the agent`,autoFocus:!0,rows:3,className:`min-h-16 resize-none text-ui md:text-ui`}):(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-ui break-words whitespace-pre-wrap text-foreground`,children:e.text}),r?(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[e.added?(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`text-soft-foreground hover:text-danger`,disabled:e.sending===!0,onClick:s,children:[(0,Q.jsx)(Wn,{"aria-hidden":`true`}),`Delete`]}):(0,Q.jsx)(`span`,{}),(0,Q.jsx)(J,{type:`button`,size:`sm`,disabled:!e.added&&i,title:e.added?`Done (Ctrl/⌘+Enter)`:`Add note (Ctrl/⌘+Enter)`,onClick:c,children:e.added?`Done`:`Add note`})]}):null]})}function Pa({notes:e}){let t=e.sending;if(e.ready===0&&!t)return null;let n=async()=>{if(!t)try{await e.sendAll()}catch(e){Y(e instanceof Error&&e.message?e.message:`Could not send the notes.`,{tone:`danger`})}};return(0,Q.jsxs)(`div`,{"data-slot":`design-notes-tray`,className:`flex items-center gap-2 rounded-xl border border-border bg-background/95 py-1.5 pr-1.5 pl-3 text-xs shadow-lg`,children:[(0,Q.jsx)(yr,{"aria-hidden":`true`,className:`size-3.5 text-soft-foreground`}),(0,Q.jsxs)(`span`,{className:`text-foreground`,children:[e.ready,` `,e.ready===1?`note`:`notes`]}),(0,Q.jsxs)(J,{type:`button`,size:`sm`,disabled:t,onClick:()=>void n(),children:[(0,Q.jsx)(xi,{"aria-hidden":`true`}),t?`Sending…`:`Send to agent`]})]})}function Fa(e){return e===`running`||e===`waiting`||e===`queued`?`live`:`continue`}var Ia=[250,500,1e3,1e3,2e3,2e3,3e3],La=e=>new Promise(t=>setTimeout(t,e));function Ra(e){return e instanceof te&&e.status===409&&e.message===`session closed`}var za=`the agent is not taking messages right now — your message is back in the composer; send it again once the task settles`;function Ba(e){return Ra(e)?new te(409,za,{cause:e}):e}function Va(e){return e instanceof te&&e.status===409&&e.message===`run is still active`}function Ha(e,t){return e===`live`?Ra(t):Va(t)}var Ua=e=>e.steps.filter(e=>e.id.startsWith(`continue-`)).length;function Wa(e,t,n={}){let{wait:r=La,surface:i=`existing_session`}=n,a=s(),{mutateAsync:o}=c(e.id),l=Ua(e);return(0,Z.useCallback)(async(n,s)=>{let c=S(),u=async e=>{let r=await(e===`live`?o({text:n,images:s}):t(n,s,c));return i&&zt(i),r},d=()=>a.fetchQuery({...N(e.id),staleTime:0}),f=Fa(e.status),p;try{return await u(f)}catch(e){p=e}for(let e=0;f===`continue`&&p instanceof te&&p.status===0;e+=1){let t=ue[e];if(t===void 0)throw p;await r(t);let n=await d().catch(()=>void 0);if(!n||Fa(n.status)!==`continue`||Ua(n)!==l)throw p;try{return await u(`continue`)}catch(e){p=e}}if(!(p instanceof te)||p.status!==409)throw p;let m=p;for(let e=0;;e+=1){let t;try{t=await d()}catch{throw Ba(m)}let i=Fa(t.status);if(i===f){let t=Ha(f,m)?Ia[e]:void 0;if(t===void 0)throw Ba(m);await r(t);try{return await u(f)}catch(e){if(!Ha(f,e))throw e;m=e;continue}}if(i===`live`&&n.trim()===``&&s.length===0)return;if(i===`continue`&&en(t)===void 0)throw Ba(m);return await u(i)}},[t,l,a,e.id,e.status,o,i,r])}var Ga=2e4,Ka=new Map;function qa(e){let t=Ka.get(e);return t||(t={drafts:void 0,sent:[],counter:0,listeners:new Set,chain:Promise.resolve(),timer:void 0,version:0,inFlight:null},Ka.set(e,t)),t}function Ja(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=Bi(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,Ga):``,...t.added===!0?{added:!0}:{}})}return n}var Ya=e=>e.length===0?``:JSON.stringify(e.map(e=>({pick:e.pick,text:e.text,...e.added?{added:!0}:{}}))),Xa=e=>{try{return new URL(e).pathname}catch{return}};function Za(e){return Ki(e.text.trim(),[{...e.pick,id:e.key}])}function Qa(e){if(e.length===1)return Za(e[0]);let t=e.map((e,t)=>`## Note ${t+1}\n\n${Za(e)}`).join(`
8
-
9
- `);if(t.length>1e5)throw Error(`Too long with ${e.length} notes — send fewer at once.`);return t}function $a(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)>eo)&&(a={...a,phase:t.asking?`asking`:`done`})),a!==e&&(i=!0),a}),o=a.filter(e=>e.phase===`running`||e.phase===`asking`),s=Math.max(...o.map(e=>e.deliveredAt??0));return o.some(e=>(e.deliveredAt??0)<s)&&(a=a.map(e=>o.includes(e)&&(e.deliveredAt??0)<s?{...e,phase:`done`}:e),i=!0),i?a:e}var eo=15e3;function to(e){let t=e.id,n=qa(t),r=me(t),i=r.data?.surfaces?.[Li]?.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=Ja(typeof i==`string`?i:``),a())},[r.isSuccess,a,n,i]);let o=(0,Z.useCallback)(e=>{clearTimeout(n.timer),n.timer=setTimeout(()=>{let e=Ya(n.drafts??[]);e.length>1e5||(n.chain=n.chain.catch(()=>{}).then(()=>H(t,Li,{text:e,images:[]})).catch(()=>{}))},e)},[t,n]),s=Wa(e,(0,Z.useCallback)((e,n,r)=>z(t,{text:e,idempotencyKey:r}),[t]),{surface:null}),c=(0,Z.useRef)(s);c.current=s;let l=e.status===`waiting`&&e.askParked===!0;(0,Z.useEffect)(()=>{let t=$a(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.inFlight?.has(e)||!n.drafts?.some(t=>t.key===e)||(n.drafts=n.drafts.map(n=>n.key===e?{...n,text:t.slice(0,Ga)}:n),a(),o(500))},[o,a,n]),f=(0,Z.useCallback)(e=>{n.drafts?.some(t=>t.key===e&&!t.added)&&(n.drafts=n.drafts.map(t=>t.key===e?{...t,added:!0}:t),a(),o(0))},[o,a,n]),p=(0,Z.useCallback)(e=>{n.inFlight?.has(e)||!n.drafts?.some(t=>t.key===e)||(n.drafts=n.drafts.filter(t=>t.key!==e),a(),o(0))},[o,a,n]),m=(0,Z.useCallback)(async()=>{if(n.inFlight!==null)return;let e=(n.drafts??[]).filter(e=>e.text.trim()!==``);if(e.length===0)return;let t=Qa(e),r=new Set(e.map(e=>e.key));n.inFlight=r,a();try{await c.current(t,[])}finally{n.inFlight=null,a()}let i=Date.now();n.sent=[...n.sent,...e.map(e=>({key:e.key,pick:e.pick,text:e.text.trim(),number:++n.counter,sawRunning:!1,phase:`running`,deliveredAt:i}))],n.drafts=(n.drafts??[]).filter(e=>!r.has(e.key)),a(),o(0)},[o,a,n]),h=(0,Z.useMemo)(()=>[...(n.drafts??[]).map(e=>({...e,phase:`draft`,...n.inFlight?.has(e.key)?{sending:!0}:{}})),...n.sent],[n,n.version]);return{notes:h,marks:(0,Z.useMemo)(()=>h.map(e=>e.phase===`draft`?{key:e.key,selector:e.pick.selector,path:Xa(e.pick.url),label:Vi(e.pick),draft:!0}:{key:e.key,n:e.number,label:Vi(e.pick),draft:!1}),[h]),note:(0,Z.useCallback)(e=>h.find(t=>t.key===e),[h]),addDraft:u,setText:d,markAdded:f,discard:p,ready:h.filter(e=>e.phase===`draft`&&e.text.trim()!==``).length,sending:n.inFlight!==null,sendAll:m}}var no=`diff-comments`;function ro(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}:{},...io(t.start)?{start:{side:t.start.side,line:t.start.line}}:{}})}return n}function io(e){if(typeof e!=`object`||!e)return!1;let t=e;return(t.side===`old`||t.side===`new`)&&typeof t.line==`number`}function ao(e){return Zr(e,e.start)}function oo(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 so=`Review comments on the diff:`;function co(e){return e.length===0?``:`${so}\n\n${oo(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?go(e):t}:\n\n${vo(_o(e.excerpt))}\n\n${vo(e.body)}`}).join(`
10
-
11
- `)}`}var lo=/^- `([^`]+)` (.+):$/;function uo(e){let t=e.indexOf(`${so}\n\n`);if(t===-1||t>0&&e[t-1]!==`
12
- `)return;let n=e.slice(0,t).trim(),r=e.slice(t+28+2).split(`
13
- `),i=[],a=0;for(;a<r.length;){let e=lo.exec(r[a]??``);if(!e){if((r[a]??``).trim()===``){a++;continue}return}a++;let t=[];for(;a<r.length&&!lo.test(r[a]??``);)t.push((r[a]??``).replace(/^ {2}/,``)),a++;i.push(fo(e[1],e[2],t))}return i.length>0?{lead:n,items:i}:void 0}function fo(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(`
14
- `),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(`
15
- `)}return{path:r??e,label:t,...i?{line:Number(i[1])}:{},side:a,excerpt:s,body:o.join(`
16
- `).trim()}}function po(e,t){let n=co(t);return n===``?e:e.trim()===``?n:`${e}\n\n${n}`}function mo(e){return/^\/([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s|$)/.exec(e.trimStart())?.[1]}function ho(e,t){let n=mo(e);return n===void 0||(t?.includes(n)??!1)}function go(e){let t=e.side===`old`||e.start?.side===`old`,n=e.oldPath&&t?` (removed lines numbered in \`${e.oldPath}\`)`:``;return`\`${e.path}\` ${ao(e)}${n}`}function _o(e){let t=Math.max(0,...(e.match(/`+/g)??[]).map(e=>e.length)),n="`".repeat(Math.max(3,t+1));return`${n}\n${xo(e).split(`
17
- `).map(e=>e.trimEnd()).join(`
18
- `)}\n${n}`}function vo(e){return e.split(`
19
- `).map(e=>` ${e}`).join(`
20
- `)}var yo=1e3;function bo(e,t=200){let n=xo(e);return n.length<=t?n:`${n.slice(0,t)}…`}function xo(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``).replace(/\s+$/,``)}function So(e,t){let n=po(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 Co(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}var wo=new WeakMap;function To(e){let t=wo.get(e);return t||(t={lists:new Map,listeners:new Map,chains:new Map,removed:new Map,base:new Map,pending:new Map},wo.set(e,t)),t}var Eo=[];function Do(e){let t=s(),n=To(t),r=me(e===``?void 0:e),i=r.data?.surfaces?.[no]?.text,a=(0,Z.useMemo)(()=>ro(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=ko(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:W.runs.drafts(e)})};return window.addEventListener(`focus`,n),document.addEventListener(`visibilitychange`,n),()=>{window.removeEventListener(`focus`,n),document.removeEventListener(`visibilitychange`,n)}},[t,e]);let c=o??(r.isSuccess?a:Eo),l=(0,Z.useCallback)(()=>n.lists.get(e)??a,[e,a,n]),u=(0,Z.useCallback)(r=>{n.lists.set(e,r),n.listeners.get(e)?.forEach(e=>e());let i=Oo(r);t.setQueryData(W.runs.drafts(e),e=>{let t={...e?.surfaces??{}};return i===``?delete t[no]:t[no]={text:i,images:[],updatedAt:new Date().toISOString()},{surfaces:t}})},[t,e,n]),d=(0,Z.useCallback)((t,r=[])=>{if(Oo(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)}u(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 ce(e)).surfaces?.[no]?.text;i=ko(r,ro(typeof t==`string`?t:``),n.base.get(e)??[],n.removed.get(e))}catch{}i!==r&&u(i);let a=Oo(i);a.length>1e5||(await H(e,no,{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},[u,e,n]),f=(0,Z.useCallback)(e=>d([...l(),{...e,body:e.body.slice(0,Qr),excerpt:bo(e.excerpt,e.start?yo:200),id:Co()}]),[l,d]),p=(0,Z.useCallback)((e,t)=>d(l().map(n=>n.id===e?{...n,body:t.slice(0,Qr)}:n)),[l,d]),m=(0,Z.useCallback)(e=>void d(l().filter(t=>t.id!==e),[e]),[l,d]),h=(0,Z.useCallback)(()=>void d([],l().map(e=>e.id)),[l,d]),g=(0,Z.useCallback)(async e=>{let t=l(),n=await e(t);if(t.length>0){let e=new Map(t.map(e=>[e.id,e.body])),n=l();d(n.filter(t=>e.get(t.id)!==t.body),n.filter(t=>e.get(t.id)===t.body).map(e=>e.id))}return n},[l,d]);return{ready:o!==void 0||r.isSuccess,comments:c,add:f,update:p,remove:m,clear:h,submit:g}}function Oo(e){return e.length===0?``:JSON.stringify(e)}function ko(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 Ao(e,t=null){let n=u(),r=_(n.data),i=e.runner??`claude`,a=ft(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 jo(e){let t=s(),n=kt(e).continueRun,r=ie(),[i,a]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),f=Ao(e,i),{runners:p,canContinue:m,currentRunner:g,runner:_}=f,v=o(_,n),y=r.data?.modelsLocked===!0,b=_!==g,x=!y&&!b&&e.model?{...r.data?.defaultModels,[_]:e.model}:r.data?.defaultModels,S=y?null:c,C=ht(_,v.data,[S,x?.[_]]),w=Ht(S,_,x,v.data),{accounts:T,repoAccount:E}=Fn(),D=[...e.steps].reverse().find(e=>e.profileId)?.profileId??e.agentProfile??`default`,O=b?E:{...E,[g]:D},k=T.some(e=>e.provider===_&&e.id===u)?u:null,A=h({mutationFn:({text:t,images:n,idempotencyKey:r})=>m?z(e.id,{text:t.trim()?t:void 0,images:n.length?n:void 0,runner:f.runnerOverride,model:!y&&c!==null?w:void 0,agentProfile:k??void 0,idempotencyKey:r}):Promise.reject(Error(f.reason??`Connect an agent provider to continue.`)),onSuccess:()=>t.invalidateQueries({queryKey:W.runs.all})});return{available:n,canContinue:m,reason:f.reason,providerPending:f.providerPending,pills:(0,Q.jsxs)(`div`,{"data-slot":`follow-up-engine`,className:`flex flex-wrap items-center gap-1.5`,children:[p.length>1||p.some(e=>Ln(T,e))?(0,Q.jsx)(cn,{runners:p,value:_,accounts:T,account:k,repoAccount:O,onPick:(e,t)=>{d(t),e!==_&&(a(e),l(null))}}):null,(0,Q.jsx)(At,{slot:`follow-up-model-pill`,ariaLabel:`Model`,label:C.find(e=>e.id===w)?.label??`auto`,value:w,readOnly:y,disabledHint:`Model selection is locked to native coding-agent settings.`,onPick:e=>l(e),options:C.map(e=>({value:e.id,label:e.label,desc:e.desc})),status:et(_,v.data,v.isError)})]}),continueWith:(e,t,n)=>A.mutateAsync({text:e,images:t,idempotencyKey:n})}}function Mo({items:e}){let{id:t}=De();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-label 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-label`,children:[(0,Q.jsx)(Vn,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground`}),t?(0,Q.jsx)(Ee,{to:No(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-label 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 No(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 Po(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 Fo({runId:e,comments:t,onRemove:n,onOpen:r}){return t.length===0?null:(0,Q.jsx)(Xn,{delayDuration:300,children:oo(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=ao(t);return(0,Q.jsxs)(Zn,{children:[(0,Q.jsx)(Jn,{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)(Vn,{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)(Ee,{to:No(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)(Tr,{"aria-hidden":`true`,className:`size-3.5`})})]})}),(0,Q.jsx)(Yn,{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-meta 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 Io({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=Wa(e,r.continueWith),f=n.comments.length>0,m=p(f),h=(0,Z.useMemo)(()=>Array.isArray(m.data)?m.data.map(e=>e.name):void 0,[m.data]),g=nn(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)(Ee,{to:`/settings/agents#providers`,className:`text-xs font-medium text-foreground underline underline-offset-4`,children:`Configure providers`}):null,(0,Q.jsx)(Lt,{run:e})]}),S=yt(e),C=e.status===`running`||e.status===`queued`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Pn,{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(()=>f&&!ho(e,h)?(Y(`Diff comments kept — /${mo(e)} is a command, so they go with your next message.`),d(e,r)):n.submit(async t=>d(So(e,t),r)))}finally{a?.(!1)}},draftItems:f?(0,Q.jsx)(Fo,{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||f,sendAriaLabel:u?`Continue`:`Send`,sendShortcut:`↵`,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 Lo({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 Ro({run:e,embedded:t=!1,stateKey:n}){let r=m();G();let i=M(e.id,Dt(e.status)),a=Ke(),[o,c]=(0,Z.useState)(`unified`),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),[p,g]=ti(n,null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),[y,b]=pn(),x=Sn(y),S=Do(e.id),{add:C}=S,w=(0,Z.useCallback)(e=>{let t=C(e);return t&&Kt(e.start?`multi_line`:`single_line`),t},[C]),T=S.comments.length,E=on(e.id,`composer`),[D,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1);T>0&&!A&&j(!0),A&&T===0&&!E.hasDraft&&!D&&j(!1);let ee=T>0||D||A&&E.hasDraft,[N,P]=(0,Z.useState)(0),F=(0,Z.useCallback)(e=>{if(!e){P(0);return}if(P(e.offsetHeight),typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>P(e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),I=(0,Z.useMemo)(()=>{let e=new Map;for(let t of S.comments)e.set(t.path,(e.get(t.path)??0)+1);return e},[S.comments]);s();let L=h({mutationFn:t=>ne(e.id,t),onError:e=>Y(e.message,{tone:`danger`})}),R=i.isError&&i.error instanceof te&&i.error.status===409,z=i.data?.files??Bo,re=i.data?.baseSha,ie=(0,Z.useDeferredValue)(z,Bo),B=ie!==z,V=!i.isPending&&!i.isError&&z.length>0,H=(0,Z.useMemo)(()=>gn(z),[z]),ae=(0,Z.useMemo)(()=>z.some(Yr),[z]),oe=a?o:`unified`,U=!a||l,se=(0,Z.useCallback)(e=>{let t=_.current;`side`in e&&t?.reveal?t.reveal(e):t?.scrollToPath(e.path)},[]),[ce,W]=(0,Z.useState)(null),le=(0,Z.useCallback)(e=>{_.current&&!B?se(e):W(e)},[B,se]);(0,Z.useEffect)(()=>{if(ce===null||B)return;let e=0,t=setInterval(()=>{!_.current&&++e<40||(clearInterval(t),se(ce),W(null))},75);return()=>clearInterval(t)},[B,se,ce]);let ue=e=>{g(e),le({path:e})},de=(0,Z.useCallback)(e=>{g(e.path),le(e)},[le,g]),[fe]=Se(),K=(0,Z.useMemo)(()=>Po(fe),[fe]),pe=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!K||!V||B)return;let e=fe.toString();if(pe.current===e)return;let t=0,n=setInterval(()=>{!_.current&&++t<40||(clearInterval(n),pe.current=e,de(K))},75);return()=>clearInterval(n)},[B,V,de,fe,K]),(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)(tn,{run:e,tab:`changes`}),(0,Q.jsx)(lr,{branch:e.branch,stat:i.data?.stat,mode:oe,wrap:U,preview:d,onModeChange:c,onWrapChange:u,onPreviewChange:ae?f: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)(qr,{icon:R?(0,Q.jsx)(dr,{}):(0,Q.jsx)(hr,{}),tone:R?`neutral`:`danger`,heading:`h2`,title:R?`No changes to show`:`Could not load the changes`,subtitle:i.error.message}):z.length===0?(0,Q.jsx)(qr,{icon:(0,Q.jsx)(dr,{}),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":`${ee?N:0}px`},children:[(0,Q.jsx)(`aside`,{ref:v,"data-slot":`changes-tree-pane`,style:x.style,className:q(`hidden w-60 max-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`,x.className),children:(0,Q.jsx)(_n,{root:H,selected:p,onSelect:ue,commentCounts:I})}),(0,Q.jsx)(yn,{paneRef:v,width:y,onWidthChange:b,className:q(`hidden`,t?`md:@xl:block`:`md:block`)}),(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:ie.length===0?(0,Q.jsxs)(`p`,{"data-slot":`diff-rendering`,className:`px-1 pt-4 text-xs text-soft-foreground`,children:[`Rendering `,z.length.toLocaleString(),` `,z.length===1?`file`:`files`,`…`]}):(0,Q.jsx)(ei,{files:ie,viewRef:_,mode:oe,wrap:U,preview:a&&ae&&d,loadFileText:t=>Vo(e.id,t),imageSrc:t=>O(e.id,t),oldImageSrc:re?t=>O(e.id,t,re):void 0,onOpenInApp:r.data?.capabilities.localHandoff?e=>L.mutate(e):void 0,comments:S.comments,onAddComment:S.ready?w:void 0,onEditComment:S.update,onRemoveComment:S.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)})]}),ee?(0,Q.jsx)(Lo,{ref:F,floating:!0,className:`mt-auto`,style:{marginTop:V&&N?-N:void 0},children:(0,Q.jsx)(zo,{run:e,draft:E,diffComments:S,onSendingChange:k,onOpenComment:e=>de({path:e.path,side:e.side,line:e.line,commentId:e.id}),getMentionCandidates:()=>z.map(e=>e.path)})}):null]})}function zo(e){let t=jo(e.run);return Fe(),(0,Q.jsx)(Io,{...e,continueAction:t})}var Bo=[];async function Vo(e,t){try{let n=await d(e,t);return n.type!==`file`||n.binary||n.tooLarge?null:n.content??null}catch{return null}}function Ho({runId:e,selected:t,onSelect:n}){return(0,Q.jsx)(`nav`,{"data-slot":`files-tree`,"aria-label":`Worktree files`,className:`min-w-0 text-ui`,children:(0,Q.jsx)(`ul`,{className:`flex flex-col gap-px`,children:(0,Q.jsx)(Uo,{runId:e,path:``,depth:0,selected:t,onSelect:n})})})}function Uo({runId:e,path:t,depth:n,selected:r,onSelect:i}){let a=w(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)(Wo,{runId:e,name:a.name,path:t===``?a.name:`${t}/${a.name}`,depth:n,selected:r,onSelect:i},a.name):(0,Q.jsx)(Go,{name:a.name,path:t===``?a.name:`${t}/${a.name}`,size:a.size,depth:n,selected:r,onSelect:i},a.name))}):null}function Wo({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)(Qn,{"aria-hidden":`true`,className:q(`size-3.5 shrink-0 transition-transform`,o&&`rotate-90`)}),(0,Q.jsx)(fr,{"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)(Uo,{runId:e,path:n,depth:r+1,selected:i,onSelect:a})}):null]})}function Go({name:e,path:t,size:n,depth:r,selected:i,onSelect:a}){let o=i===t,s=xn(t)?mn:Vn;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-meta tabular-nums text-soft-foreground`,children:vn(n)})]})})}function Ko({run:e,embedded:t=!1,stateKey:n}){let r=w(e.id,``),[i,a]=ti(n,null),o=Ke(),s=(0,Z.useRef)(null),[c,l]=pn(),u=Sn(c),d=r.isError&&r.error instanceof te&&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)(tn,{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)(qr,{icon:d?(0,Q.jsx)(hn,{}):(0,Q.jsx)(_r,{}),tone:d?`neutral`:`danger`,heading:`h2`,title:d?`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`,{ref:s,"data-slot":`files-tree-pane`,style:u.style,className:q(`w-full shrink-0 md:max-w-[60%] 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`,u.className),children:(0,Q.jsx)(Ho,{runId:e.id,selected:i,onSelect:a})}),(0,Q.jsx)(yn,{paneRef:s,width:c,onWidthChange:l,className:`hidden md:block`}),(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)(Cn,{source:{kind:`run`,runId:e.id},path:i,className:`min-w-0`})})})]})]})}var qo=2e3;function Jo(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 Yo(e){let{lastEnd:t,lastStart:n}=Jo(e);return t>n?t:0}function Xo(e){let{lastEnd:t,lastStart:n}=Jo(e);return n>t?n:0}function Zo(e,t){let n=s(),r=(0,Z.useMemo)(()=>Yo(t),[t]),i=(0,Z.useMemo)(()=>Xo(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:W.runs.detail(a)}),n.invalidateQueries({queryKey:W.runs.list()})},qo);return()=>clearTimeout(e)},[r,i,a,o,n])}function Qo({run:e}){let t=s(),n=h({mutationFn:()=>I(e.id),onSuccess:()=>{t.invalidateQueries({queryKey:W.runs.detail(e.id)}),t.invalidateQueries({queryKey:W.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)(Hr,{tone:`pending`,pulse:!0}),(0,Q.jsxs)(`span`,{children:[e.autoResumeReason===`transient`?`Temporary provider failure — this task retries automatically at`:`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)(we,{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 $o(e){let t=s();return h({mutationFn:()=>F(e),onSuccess:()=>t.invalidateQueries({queryKey:W.runs.all}),onError:e=>Y(e.message,{tone:`danger`})})}function es({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)(ts,{run:e})}function ts({run:e}){let t=!!P().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)(Ee,{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)($n,{className:`mt-0.5 size-5 shrink-0 text-success`,"aria-hidden":!0}):(0,Q.jsx)(Le,{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 ns=e=>e.kind===`tool`,rs=e=>(e.toolKind===`read`||e.toolKind===`search`)&&e.status===`completed`,is=(e,t,n)=>`${e} ${e===1?t:n}`;function as(e,t){let n=[];return e>0&&n.push(is(e,`file`,`files`)),t>0&&n.push(is(t,`search`,`searches`)),`Explored ${n.join(` · `)}`}function os(e){return`${e} earlier tool call${e===1?``:`s`}`}var ss=[`Web search`,`Ran`,`Edit`,`Write`,`Read`,`Search`,`Fetch`,`Task:`,`Skill:`];function cs(e){for(let t of ss)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 ls(e){let t=e.filter(e=>!(e.kind===`tool`&&e.toolKind===`plan`)&&!(e.kind===`reasoning`&&e.text.trim()===``)),n=new Set(t.filter(ns).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:as(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)ns(e)&&rs(e)&&!r.has(e.id)?o.push(e):(s(),ns(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 us=new Map,ds=(0,Z.createContext)(null);function fs(){return(0,Z.useContext)(ds)}function ps({runId:e,children:t}){let n=(0,Z.useMemo)(()=>({get:t=>us.get(e)?.get(t),set:(t,n)=>{let r=us.get(e)??new Map;r.set(t,n),us.set(e,r)}}),[e]);return(0,Q.jsx)(ds.Provider,{value:n,children:t})}function ms(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 hs(e){return e.scrollTop<Math.max(600,e.clientHeight)}function gs(e,t){let n=t.find(({bottom:t})=>t>e);return n===void 0?void 0:{key:n.key,offset:n.top-e}}function _s(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 vs(e,t=24){return e.scrollHeight-e.scrollTop-e.clientHeight<t}function ys(e,t){let n=new URLSearchParams(e).get(`thread`);return n===`flat`||n===`virtual`?n:t>300?`virtual`:`flat`}var bs=new Map;function xs(e,t){bs.set(e,t)}function Ss(e){return bs.get(e)}var Cs=new Map;function ws(e,t){Cs.set(e,t)}function Ts(e,t){let n=Cs.get(e);return n!==void 0&&n.rows===t?n.cache:void 0}var Es=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}),Ds=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`medium`}),Os=new Intl.DateTimeFormat(void 0,{weekday:`short`,month:`short`,day:`numeric`}),ks=new Intl.DateTimeFormat(void 0,{weekday:`short`,year:`numeric`,month:`short`,day:`numeric`}),As=new Intl.DateTimeFormat(void 0,{dateStyle:`full`});function js(e){if(typeof e!=`string`||e===``)return;let t=new Date(e);return Number.isFinite(t.getTime())?t:void 0}function Ms(e){let t=js(e);return t===void 0?void 0:Es.format(t)}function Ns(e){let t=js(e);return t===void 0?void 0:Ds.format(t)}var Ps=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;function Fs(e){let t=js(e);return t===void 0?void 0:Ps(t)}function Is(e,t=new Date){let n=js(e);if(n===void 0)return;let r=Ps(n);return r===Ps(t)?`Today`:r===Ps(new Date(t.getFullYear(),t.getMonth(),t.getDate()-1))?`Yesterday`:(n.getFullYear()===t.getFullYear()?Os:ks).format(n)}function Ls(e,t){let n=js(e),r=js(t);if(!(n===void 0||r===void 0))return zs(Math.round((r.getTime()-n.getTime())/1e3))}function Rs(e,t){let n=js(e);if(n!==void 0)return zs(Math.floor((t-n.getTime())/1e3))}function zs(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 Vs({ts:e}){let t=Ms(e);return t===void 0?null:(0,Q.jsx)(`time`,{"data-slot":`message-time`,dateTime:e,title:Ns(e),className:`text-meta leading-none text-soft-foreground`,children:t})}function Hs({startedAt:e,completedAt:t}){let n=Ms(t);if(n===void 0)return null;let r=Ls(e,t);return(0,Q.jsxs)(`div`,{"data-slot":`turn-time`,className:`flex items-center gap-1.5 px-0.5 text-meta leading-none text-soft-foreground`,children:[(0,Q.jsx)(`time`,{dateTime:t,title:Ns(t),children:n}),r===void 0?null:(0,Q.jsxs)(`span`,{title:`Replied in ${r}`,children:[`· `,r]})]})}function Us({ts:e}){let t=Is(e),n=js(e);if(t===void 0||n===void 0)return null;let r=As.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-meta 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:Fs(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=on(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-ui 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-ui 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)(vr,{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-ui 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)(Si,{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)(Wn,{className:`size-3.5`})}):null]}):null,_?(0,Q.jsx)(`p`,{role:`alert`,className:`mb-1 text-xs text-danger`,children:_}):null,(0,Q.jsx)(Gs,{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=>_e(e.split(`/`).pop()??``)?(0,Q.jsx)(Xr,{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)(kn,{"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)(Vs,{ts:r})})]})}function Gs({text:e}){let t=(0,Z.useMemo)(()=>uo(e),[e]);return t?(0,Q.jsxs)(Q.Fragment,{children:[t.lead===``?null:(0,Q.jsx)(Jr,{breaks:!0,children:t.lead}),(0,Q.jsx)(Mo,{items:t.items})]}):(0,Q.jsx)(Jr,{breaks:!0,children:e})}function Ks({text:e}){return(0,Q.jsx)(`div`,{"data-slot":`assistant-message`,className:`min-w-0 text-lead leading-[1.65]`,children:(0,Q.jsx)(Jr,{children:e})})}function qs({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 Js={claude:`Claude Code`,codex:`Codex`,junie:`Junie`,opencode:`OpenCode`,cursor:`Cursor`,pi:`pi`,copilot:`GitHub Copilot CLI`};function Ys({incident:e}){if(e.profileId!==void 0)return(0,Q.jsx)(Xs,{incident:e,profileId:e.profileId});let t=Js[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-ui 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)(Ee,{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 Xs({incident:e,profileId:t}){let n=de(),r=Js[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-ui 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)(we,{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 Zs=new Set([`claude`,`opencode`,`cursor`]);function Qs({incident:e}){let t=Js[e.provider],[n,r]=(0,Z.useState)(null),i=h({mutationFn:()=>se(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 te?e.command:void 0})}),a=async e=>{try{await Er(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-ui font-semibold text-foreground`,children:[t,` needs an update`]}),Zs.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 $s({text:e}){let t=(0,Z.useId)();if(e.trim()===``)return null;let n=e.split(`
21
- `,1)[0]??``,r=n.length<e.length;return(0,Q.jsxs)(kr,{"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-ui text-soft-foreground hover:text-muted-foreground`,children:[(0,Q.jsx)(Qn,{"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)(Jr,{inline:!0,children:n})}),r?(0,Q.jsx)(`span`,{"aria-hidden":!0,children:`…`}):null,(0,Q.jsx)(Or,{"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)(Dr,{children:(0,Q.jsx)(`div`,{className:`px-6 py-1.5 text-ui leading-[1.6] text-soft-foreground`,children:(0,Q.jsx)(Jr,{children:e})})})]})}function ec({since:e,lastActivityAt:t}={}){let n=Bs(),r=Rs(e,n),i=Rs(t,n),a=Ms(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-ui text-soft-foreground`,children:[(0,Q.jsx)(vr,{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 ${Ns(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:Ns(t),className:`text-xs`,children:[`· last activity `,a,` (`,i,` ago)`]}):null]})}var tc={read:On,edit:Si,delete:Wn,move:_i,search:Ie,execute:xt,think:hi,fetch:pt,task:Hn,skill:tt,plan:vi,other:mr},nc=e=>e.split(`
22
- `).length;function rc({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=nc(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=vs(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-meta font-medium text-soft-foreground hover:text-foreground`,children:n?`Show less`:`Show all ${o} lines`}):null]})}function ic({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-meta 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?[...ac(e.oldText).map((e,t)=>(0,Q.jsxs)(`span`,{className:`block bg-diff-del px-4 text-muted-foreground`,children:[`- `,e]},`old-${t}`)),...ac(e.newText).map((e,t)=>(0,Q.jsxs)(`span`,{className:`block bg-diff-add px-4`,children:[`+ `,e]},`new-${t}`))]:e.unified.split(`
23
- `).map((e,t)=>(0,Q.jsx)(oc,{text:e},t))})]},`${e.path}:${t}`))})}function ac(e){return e==null||e===``?[]:e.replace(/\n$/,``).split(`
24
- `)}function oc({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 sc(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(` `):cs(e.title).detail;return r!==void 0&&r.trim()!==``?r:void 0}function cc({command:e}){let[t,n]=(0,Z.useState)(!1);return(0,Q.jsx)(`button`,{type:`button`,"aria-label":t?`Copied`:`Copy command`,onClick:()=>{Er(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}).catch(()=>Y(`Copy failed — select the command to copy it.`,{tone:`danger`}))},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)(Kn,{"aria-hidden":!0,className:`size-3.5`}):(0,Q.jsx)(ot,{"aria-hidden":!0,className:`size-3.5`})})}function lc(e){return e.toolKind===`execute`&&e.status===`running`&&e.output!==void 0}function uc({item:e,nested:t=[],cacheKey:n,renderNested:r}){let i=fs(),[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=sc(e),{verb:u,detail:d}=cs(e.title),f=l!==void 0&&(l!==d||l.includes(`
25
- `)||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??lc(e)),g=h&&p?l:void 0,_=tc[e.toolKind]??mr;return(0,Q.jsxs)(kr,{"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)(Or,{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-ui enabled:hover:bg-muted`,g===void 0?`items-center`:`items-start [&>svg]:mt-[7px] [&>span]:mt-[2px]`),children:[(0,Q.jsx)(Qn,{"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)(vr,{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-micro 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)(cc,{command:g})]}),(0,Q.jsx)(Dr,{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)(ic,{diffs:e.diffs}):null,e.output!==void 0&&e.output!==``?(0,Q.jsx)(rc,{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 dc({group:e,scope:t}){return(0,Q.jsxs)(kr,{"data-slot":`ctx-group`,className:`min-w-0`,children:[(0,Q.jsxs)(Or,{className:`group flex h-[34px] w-full items-center gap-2 rounded-md px-2 -mx-2 text-left text-ui font-medium text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Qn,{"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)(Dr,{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)(uc,{item:e,cacheKey:t===void 0?void 0:`${t}:${e.id}`},e.id))})})]})}function fc({count:e,children:t}){return(0,Q.jsxs)(kr,{"data-slot":`tool-streak`,className:`min-w-0`,children:[(0,Q.jsxs)(Or,{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)(Qn,{"aria-hidden":!0,className:`size-3.5 shrink-0 transition-transform group-data-[state=open]:rotate-90`}),os(e)]}),(0,Q.jsx)(Dr,{children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 pt-2`,children:t})})]})}function pc({image:e}){return(0,Q.jsx)(Xr,{"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 mc=120,hc=e=>e!==`pending`&&e!==`running`,gc=e=>e.kind===`tool`&&e.toolKind===`task`,_c=e=>gc(e)&&e.parentItemId===void 0,vc=e=>(e.kind===`message`||e.kind===`reasoning`||e.kind===`tool`)&&!(e.kind===`tool`&&e.toolKind===`plan`);function yc(e,t){for(let n=0;n<e.length;n+=1)if(e[n].items.some(e=>_c(e)&&t.has(e.id)))return n;return 0}function bc(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 xc(e){if(e.kind===`tool`)return Sc(e.title);if(e.kind===`message`||e.kind===`reasoning`){let t=e.text.split(`
26
- `);for(let e=t.length-1;e>=0;--e){let n=t[e].trim();if(n!==``)return Sc(n)}}}function Sc(e){return e.length>mc?`${e.slice(0,mc-1).trimEnd()}…`:e}function Cc(e,t=!1){let n=kc(e,e=>e.items.some(_c));if(n===-1)return[];let r=e=>!t&&!hc(e.status),i=[];for(let t=n-1;t>=0;--t){let n=e[t].items.filter(_c);if(n.length!==0){if(!n.some(r))break;i.unshift(...n)}}let a=[...i,...e[n].items.filter(_c)];if(n!==e.length-1&&!a.some(r))return[];let o=new Set(a.map(e=>e.id)),s=i.length>0?yc(e,o):n,c=new Map;for(let t=s;t<e.length;t+=1)for(let n of e[t].items){if(!vc(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=>Tc(e,c.get(e.id)??[],t))}function wc(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=cs(e.title).detail??e.title;t.has(n)||t.set(n,{id:e.id,name:n})}return[...t.values()]}function Tc(e,t,n){let r={id:e.id,title:cs(e.title).detail??e.title,status:e.status,toolCalls:t.filter(e=>e.kind===`tool`).length},i=bc(e);i!==void 0&&(r.agentType=i),n&&!hc(e.status)&&(r.stalled=!0);for(let e=t.length-1;e>=0;--e){let n=xc(t[e]);if(n!==void 0){r.activity=n;break}}return r}function Ec(e){return{done:e.filter(e=>e.status===`completed`).length,total:e.length}}function Dc(e){return e.activity??(e.stalled===!0?`never finished`:`starting…`)}function Oc(e){return e.find(e=>!hc(e.status))??e[0]}function kc(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function Ac(e,t,n=!1){for(let r=e.length-1;r>=0;--r){let i=e[r].items.find(e=>e.id===t&&_c(e));if(i!==void 0)return Tc(i,jc(e,t),n)}}function jc(e,t){let n=e.findIndex(e=>e.items.some(e=>e.id===t&&_c(e)));if(n===-1)return[];let r=[];for(let i=n;i<e.length;i+=1)for(let n of e[i].items)vc(n)&&n.parentItemId===t&&n.id!==t&&r.push(n);return r}var Mc=new Map,Nc=!1;function Pc({runId:e,agents:t,onSelect:n}){let[r,i]=(0,Z.useState)(()=>Mc.get(e)??Nc),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&&(Mc.set(e,!1),!1)),o.current=a},[a,e]),t.length===0)return null;let{done:s,total:c}=Ec(t),l=Oc(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=>(Mc.set(e,!t),!t)),"aria-expanded":r,className:q(`flex w-full items-center gap-2 px-3.5 text-left text-ui`,r?`pt-2 pb-1.5`:`py-2`),children:[(0,Q.jsx)(Hn,{"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:[`— `,Dc(l)]}):null,(0,Q.jsx)(qn,{"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)(Fc,{agent:e,onSelect:n},e.id))}):null]})}function Fc({agent:e,onSelect:t}){let n=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ic,{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 eyebrow text-muted-foreground`,children:e.agentType}),(0,Q.jsx)(`span`,{"data-slot":`agent-activity`,className:`min-w-0 flex-1 truncate text-muted-foreground`,children:Dc(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-ui`,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 Ic({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 Lc=new Map;function Rc(){return typeof window.matchMedia!=`function`||window.matchMedia(`(min-width: 768px)`).matches}function zc(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 Vc({runId:e,entries:t,settled:n=!1}){let[r,i]=(0,Z.useState)(()=>Lc.get(e)??Rc());if(t.length===0)return null;let{done:a,total:o}=zc(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=>(Lc.set(e,!t),!t)),"aria-expanded":r,className:q(`flex w-full items-center gap-2 px-3.5 text-left text-ui`,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)(qn,{"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)(Hc,{entry:e,settled:n},`${t}:${e.content}`))}):null]})}function Hc({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-ui`,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)(Uc,{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 eyebrow text-muted-foreground`,children:`in progress`}):null]})}function Uc({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-ui shadow-xs`,children:[(0,Q.jsx)(tt,{"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 Gc(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(!Gc(e[n],t[n]))return!1;return!0}if(!Kc(e)||!Kc(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)||!Gc(e[r],t[r]))return!1;return!0}function Kc(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function qc(){return typeof CSS>`u`||typeof CSS.supports!=`function`||CSS.supports(`overflow-anchor`,`auto`)}function Jc(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=Ss(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=gs(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(_s(e.scrollTop,i,a,k(e),r))}b.current=!1})})},[k,r,h]);(0,Z.useEffect)(()=>()=>clearTimeout(S.current),[]);let j=(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=!qc(),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()},j=e=>{if(e.deltaY<0){b();let e=!x.current;x.current=!0,clearTimeout(S.current),S.current=setTimeout(()=>{x.current=!1},180),e&&hs(t)&&A()}else O()},ee=e=>{[`ArrowUp`,`PageUp`,`Home`].includes(e.key)?(b(),!e.repeat&&hs(t)&&A()):[`ArrowDown`,`PageDown`,`End`].includes(e.key)&&O()},M=()=>{v=!0,T.current=!1,y=t.scrollTop,vs(t,80)||(b(),O())},N=()=>{v=!1},P=e=>{C.current=!1,w.current=!0,_=e.touches[0]?.clientY??null},F=()=>{w.current&&(w.current=!1,d.current&&f.current===null&&g())},I=e=>{let n=e.touches[0]?.clientY;n!==void 0&&(_!==null&&n>_+1?(b(),!C.current&&hs(t)&&(C.current=!0,A())):_!==null&&n<_-1&&O(),_=n)},L=()=>{v&&!T.current&&t.scrollTop<y&&hs(t)&&(T.current=!0,A()),y=t.scrollTop;let n=vs(t,80);n&&f.current===null&&(d.current||Date.now()-p<2e3)&&(d.current=!0),u(!n),f.current===null&&xs(e,{top:t.scrollTop,atBottom:n}),c()};t.addEventListener(`scroll`,L,{passive:!0}),t.addEventListener(`wheel`,j,{passive:!0}),t.addEventListener(`touchstart`,P,{passive:!0}),t.addEventListener(`touchmove`,I,{passive:!0}),window.addEventListener(`touchend`,F,{passive:!0}),window.addEventListener(`touchcancel`,F,{passive:!0}),t.addEventListener(`pointerdown`,M,{passive:!0}),window.addEventListener(`pointerup`,N,{passive:!0}),t.addEventListener(`keydown`,ee);let R;return typeof ResizeObserver<`u`&&(R=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()}),R.observe(n)),c(),()=>{cancelAnimationFrame(D.current),D.current=0,E.current=void 0,t.removeEventListener(`scroll`,L),t.removeEventListener(`wheel`,j),t.removeEventListener(`touchstart`,P),t.removeEventListener(`touchmove`,I),window.removeEventListener(`touchend`,F),window.removeEventListener(`touchcancel`,F),t.removeEventListener(`pointerdown`,M),window.removeEventListener(`pointerup`,N),t.removeEventListener(`keydown`,ee),R?.disconnect()}},[e,s,A,h,g]),{attachContent:v,scrollElRef:o,virtualizerRef:m,pillVisible:l,jumpToLatest:j,loadOlder:A,restickIfStuck:y}}function Yc({runId:e,rows:t,mode:n,controls:r}){if(n===`virtual`)return(0,Q.jsx)(Xc,{runId:e,rows:t,controls:r});let i=ms(qc());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 Xc({runId:e,rows:t,controls:n}){let r=(0,Z.useRef)(null),[i]=(0,Z.useState)(()=>Ts(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&&=(ws(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)(Ur,{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 Zc({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)(bn,{"aria-hidden":!0,className:`size-3.5`}),`Jump to latest`]})}function Qc(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 $c(e,t){return[{id:`agent:${e}`,entries:t}]}function el(e){if(e.inDaySequence!==!1)return e.userMessage?.ts??e.startedAt??e.completedAt}function tl(e,t){let n=[],r;for(let t of e){let e=el(t),i=Fs(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 ls([...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 nl({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??tl(n,e),[l,n,e]),d=Jc(`${e}:${t}`,{surface:r}),f=s??d,p=(0,Z.useMemo)(()=>u.map(t=>({key:t.key,node:(0,Q.jsx)(il,{runId:e,row:t,actions:o?.[t.key],renderAsk:a})})),[o,a,u,e]),m=c??ys(``,p.length),h=p.length===0?i??null:(0,Q.jsx)(Yc,{runId:`${e}:${t}`,rows:p,mode:m,controls:f});return(0,Q.jsx)(ps,{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)(Zc,{onJump:f.jumpToLatest})}):null]}):h})}function rl({runId:e,row:t,actions:n,renderAsk:r}){return al(e,t,n,r)}var il=(0,Z.memo)(rl,(e,t)=>e.runId===t.runId&&e.actions===t.actions&&e.renderAsk===t.renderAsk&&Gc(e.row,t.row));function al(e,t,n,r){switch(t.content.kind){case`user-message`:return(0,Q.jsx)(ol,{runId:e,message:t.content.message,actions:n});case`day-separator`:return(0,Q.jsx)(Us,{ts:t.content.ts});case`turn-time`:return(0,Q.jsx)(Hs,{completedAt:t.content.completedAt,...t.content.startedAt===void 0?{}:{startedAt:t.content.startedAt}});case`block`:return(0,Q.jsx)(sl,{block:t.content.block,scope:t.scope,renderAsk:r});default:return ul(t.content)}}function ol({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 sl=(0,Z.memo)(function e({block:t,scope:n,renderAsk:r}){switch(t.kind){case`entry`:return(0,Q.jsx)(ll,{entry:t.entry,scope:n,renderAsk:r});case`tool-card`:return(0,Q.jsx)(uc,{item:t.item,nested:t.children,cacheKey:`${n}:${t.id}`,renderNested:(e,t)=>(0,Q.jsx)(cl,{entries:e,scope:t,renderAsk:r})});case`context-group`:return(0,Q.jsx)(dc,{group:t,scope:n});case`streak`:return(0,Q.jsx)(fc,{count:t.count,children:t.blocks.map(t=>(0,Q.jsx)(e,{block:t,scope:n,renderAsk:r},t.id))});default:return ul(t)}},dl);function cl({entries:e,scope:t,renderAsk:n}){return ls([...e]).map(e=>(0,Q.jsx)(sl,{block:e,scope:t,renderAsk:n},e.id))}function ll({entry:e,scope:t,renderAsk:n}){switch(e.kind){case`message`:return e.role===`assistant`?(0,Q.jsx)(Ks,{text:e.text}):(0,Q.jsx)(Ws,{text:e.text});case`reasoning`:return(0,Q.jsx)($s,{text:e.text});case`tool`:return(0,Q.jsx)(uc,{item:e,cacheKey:`${t}:${e.id}`});case`note`:return(0,Q.jsx)(qs,{note:e});case`image`:return(0,Q.jsx)(pc,{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)(Ys,{incident:e});case`agent-update-required`:return(0,Q.jsx)(Qs,{incident:e});default:return ul(e)}}function ul(e){throw Error(`Unhandled transcript variant: ${JSON.stringify(e)}`)}function dl(e,t){return e.scope===t.scope&&pl(e.block,t.block)&&(!fl(t.block)||e.renderAsk===t.renderAsk)}function fl(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(fl)}function pl(e,t){if(e.kind!==t.kind||e.id!==t.id)return!1;switch(t.kind){case`entry`:return hl(e.kind===`entry`?e.entry:void 0,t.entry);case`tool-card`:return e.kind===`tool-card`&&Tl(e.item,t.item)&&ml(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)=>Tl(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)=>pl(e,t.blocks[n]));default:return!1}}function ml(e,t){return e.length===t.length&&e.every((e,n)=>hl(e,t[n]))}function hl(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`&&wl(e,t,gl);case`reasoning`:return e.kind===`reasoning`&&wl(e,t,_l);case`tool`:return e.kind===`tool`&&Tl(e,t);case`note`:return e.kind===`note`&&wl(e,t,vl);case`image`:return e.kind===`image`&&wl(e,t,yl);case`ask`:return e.kind===`ask`&&wl(e,t,bl);case`provider-auth-required`:return e.kind===`provider-auth-required`&&wl(e,t,xl);case`agent-update-required`:return e.kind===`agent-update-required`&&wl(e,t,Sl);default:return!1}}var gl={kind:!0,id:!0,role:!0,text:!0,phase:!0,parentItemId:!0},_l={kind:!0,id:!0,text:!0,parentItemId:!0},vl={kind:!0,id:!0,text:!0,tone:!0},yl={kind:!0,id:!0,url:!0,name:!0},bl={kind:!0,id:!0,questions:!0,resolved:!0,answer:!0,fromWorkflow:!0},xl={kind:!0,id:!0,provider:!0,authFailureId:!0,profileId:!0},Sl={kind:!0,id:!0,provider:!0},Cl={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 wl(e,t,n){return Object.keys(n).every(n=>e[n]===t[n])}function Tl(e,t){return wl(e,t,Cl)}function El({runId:e,renderAsk:t,agent:n,entries:r,onClose:i}){return(0,Q.jsx)(Ve,{open:n!==void 0,onOpenChange:e=>{e||i()},children:(0,Q.jsx)(Be,{"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)(Dl,{runId:e,renderAsk:t,agent:n,entries:r})})})}function Dl({runId:e,renderAsk:t,agent:n,entries:r}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(He,{className:`gap-1.5 border-b border-border px-5 py-4`,children:[(0,Q.jsxs)(Ue,{className:`flex min-w-0 items-center gap-2 text-lead`,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 eyebrow text-muted-foreground`,children:n.agentType})]}),(0,Q.jsxs)(Re,{"data-slot":`subagent-meta`,className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(Ol,{status:n.status}),(0,Q.jsxs)(`span`,{className:`tabular-nums`,children:[n.toolCalls,` `,n.toolCalls===1?`tool call`:`tool calls`]})]})]}),(0,Q.jsx)(nl,{runId:e,viewId:`agent:${n.id}`,sections:$c(n.id,r),mode:`panel`,renderAsk:t,empty:(0,Q.jsx)(`div`,{"data-slot":`subagent-empty`,className:`py-2 text-ui text-muted-foreground`,children:`No attributed output — see the thread card for this agent's result.`})})]})}function Ol({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 eyebrow`,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 kl({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)(ur,{className:`size-4 shrink-0 text-violet`,"aria-hidden":`true`}),(0,Q.jsxs)(`p`,{className:`min-w-0 text-ui`,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)($r,{runId:e.id}),(0,Q.jsx)(Al,{run:e,diffComments:t})]})}function Al({run:e,diffComments:t}){let n=s(),r=(0,Z.useRef)(null),i=on(e.id,`review-notes`),a=i.text,o=i.setText,[c,l]=(0,Z.useState)(null),u=Wt(e.id),d=Ao(e),f=Wa(e,(0,Z.useCallback)((t,n,r)=>z(e.id,{text:t,runner:d.runnerOverride,idempotencyKey:r}),[e.id,d.runnerOverride]),{surface:`review`}),p=()=>n.invalidateQueries({queryKey:W.runs.all}),m=h({mutationFn:async e=>{if(!d.canContinue)return null;let n=async t=>{let n=`Review feedback:\n${So(e,t)}`;if(n.length>1e5)throw Error(`Too long with the diff comments attached — shorten the notes or remove some comments.`);return f(n,[])};return i.submit(()=>t?t.submit(n):n([]))},onSuccess:e=>{e!==null&&p()},onError:e=>Y(e.message,{tone:`danger`})}),g=mt(e),_=h({mutationFn:()=>pe(e.id),onSuccess:e=>{Y(`Draft PR created — ${e.url}`),p()},onError:e=>{e instanceof te&&e.manual!==void 0&&l(e.manual),Y(e.message,{tone:`danger`})}}),v=_.isPending||g.pending!==null,y=()=>g.byAgent?g.onAction(`create-draft-pr`):_.mutate(),b=t?.comments.length??0,x=()=>{let e=a.trim();if(e.length===0&&b===0){Y(`Write what to change first.`),r.current?.focus();return}m.mutate(e)};return(0,Q.jsxs)(`div`,{"data-slot":`review-actions`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Gn,{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=>{xr({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(),x())},className:`min-h-[52px] text-ui`}),b>0?(0,Q.jsxs)(`p`,{"data-slot":`review-diff-comments`,className:`text-xs text-muted-foreground`,children:[`+ `,b,` `,b===1?`comment`:`comments`,` on the diff — sent back with these notes.`]}):null,d.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:d.reason}),d.providerPending?null:(0,Q.jsx)(Ee,{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:d.reason??`Send the notes back into the agent's session`,"aria-describedby":d.canContinue?void 0:`review-provider-guidance`,disabled:m.isPending||!d.canContinue,onClick:x,children:[(0,Q.jsx)(gi,{"aria-hidden":`true`}),`Send back`]}),ye(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)(sr,{"aria-hidden":`true`}),`PR ↗`]})}):(0,Q.jsxs)(J,{"data-slot":`review-draft-pr`,variant:`outline`,size:`sm`,title:g.byAgent?`Ask the agent to push the branch and open a draft PR`:`Push the branch and open a draft PR`,disabled:v,"aria-busy":v||void 0,onClick:y,children:[v?(0,Q.jsx)(vr,{"aria-hidden":`true`,className:`motion-safe:animate-spin`}):(0,Q.jsx)(gr,{"aria-hidden":`true`}),v?pr[`create-draft-pr`]:`Draft PR`]}),(0,Q.jsxs)(J,{"data-slot":`review-accept`,variant:`contrast`,size:`sm`,className:`ml-auto`,title:ut(`review`),disabled:u.isPending,onClick:()=>u.mutate(),children:[(0,Q.jsx)(Kn,{"aria-hidden":`true`}),`Accept`]})]}),c===null?null:(0,Q.jsx)(jl,{command:c})]})}function jl({command:e}){return(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`review-manual`,title:`Copy the command`,onClick:()=>{Er(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-meta text-soft-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(ot,{className:`size-3 shrink-0`,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`truncate`,children:[`manual path: `,e]})]})}function Ml(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}var Nl=1500;function Pl({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`||Ml())return;r(!0);let i=setTimeout(()=>r(!1),Nl);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)(Kr,{}),(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-ui font-medium text-violet shadow-modal`,children:`✓ Changes accepted`})})]}):null}var Fl=new Map,Il=(e,t)=>JSON.stringify([e,t.id,t.questions.map(e=>[e.header,e.question,e.options.map(e=>e.label)])]);function Ll(e,t){return Fl.get(Il(e,t))??{}}function Rl(e,t,n){Fl.set(Il(e,t),n)}function zl(e,t){Fl.delete(Il(e,t))}var Bl=`I need more information to answer this — please explain the context and ask again.`,Vl={labels:[]},Hl=e=>e.other?.trim().replace(/\s+/g,` `)??``,Ul=e=>e.moreInfo===!0||e.labels.length>0||Hl(e)!==``;function Wl(e,t){if(t.moreInfo)return`${e.header}: ${Bl}`;let n=Hl(t);return`${e.header}: ${[...t.labels,...n?[n]:[]].join(`, `)}`}function Gl({ask:e,run:t}){return(0,Z.useEffect)(()=>{e.resolved&&zl(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)(Kl,{ask:e,run:t})}function Kl({ask:e,run:t}){let n=it(t),r=n.blockedBy!==void 0,i=e.questions,a=i.length===1&&i[0]?.multiSelect!==!0,[o,s]=(0,Z.useState)(()=>Ll(t.id,e)),c=(n,r)=>s(i=>{let a={...i,[n]:r};return Rl(t.id,e,a),a}),l=e=>o[e]??Vl,u=e=>Ul(l(e)),d=i.every((e,t)=>u(t)),f=i.some((e,t)=>u(t))?i.filter((e,t)=>!u(t)).map(e=>e.header):[],p=()=>void n.send(i.map((e,t)=>Wl(e,l(t))).join(`
27
- `)),m=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)(ql,{question:e,disabled:n.isPending||r,oneTap:a,answer:l(t),onChange:e=>{r||c(t,e)},onSubmit:t=>{!r&&Ul(t)&&n.send(Wl(e,t))}},e.id??t))}),a?m?(0,Q.jsx)(`p`,{"data-slot":`ask-resume-hint`,className:`mt-3 text-meta 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||!d,onClick:p,children:m?`Send answer & reopen`:`Send answer`}),(0,Q.jsx)(`span`,{"data-slot":m?`ask-resume-hint`:`ask-hint`,className:`text-meta text-soft-foreground`,children:m?`the session has ended — sending reopens it`:`${i.length>1?`answer each question`:`pick one or more`} — or type a reply below`})]}),!a&&f.length>0?(0,Q.jsxs)(`p`,{"data-slot":`ask-unanswered`,className:`mt-2 text-meta text-soft-foreground`,children:[`unanswered: `,f.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)(Ee,{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 ql({question:e,disabled:t,oneTap:n,answer:r,onChange:i,onSubmit:a}){let o=e.multiSelect===!0,s=r.other!==void 0,c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{l&&(c.current?.focus(),u(!1))},[l]);let d=e=>n?a(e):i(e),f=e=>{if(!o){d({labels:[e]});return}i({labels:r.labels.includes(e)?r.labels.filter(t=>t!==e):[...r.labels,e],...s?{other:r.other}:{}})};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 eyebrow text-primary-foreground`,children:e.header}),o?(0,Q.jsx)(`span`,{className:`ml-auto text-micro 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.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.options.map(e=>(0,Q.jsx)(Jl,{label:e.label,description:e.description,checkbox:o,selected:r.labels.includes(e.label),disabled:t,onClick:()=>f(e.label)},e.label)),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(Yl,{slot:`ask-other`,selected:s,disabled:t,onClick:()=>{if(s){i({labels:r.labels});return}i({labels:o?r.labels:[],other:``}),u(!0)},children:`Other…`}),(0,Q.jsx)(Yl,{slot:`ask-more-info`,selected:r.moreInfo===!0,disabled:t,onClick:()=>r.moreInfo?i(Vl):d({labels:[],moreInfo:!0}),children:`Need more info`})]}),s?(0,Q.jsxs)(`div`,{"data-slot":`ask-other-input`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Gn,{ref:c,rows:2,"aria-label":`Your own answer: ${e.question}`,placeholder:`Type your own answer`,value:r.other,disabled:t,onChange:e=>i({...r,other:e.target.value}),onKeyDown:e=>{n&&e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),a(r))}}),n?(0,Q.jsx)(`div`,{children:(0,Q.jsx)(J,{size:`sm`,disabled:t||!Ul(r),onClick:()=>a(r),children:`Send answer`})}):null]}):null]})]})}function Jl({label:e,description:t,checkbox:n,selected:r,disabled:i,onClick:a}){return(0,Q.jsxs)(`button`,{type:`button`,disabled:i,"aria-pressed":r,onClick:a,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-ui font-semibold text-foreground`,children:[n?(0,Q.jsx)(`span`,{"aria-hidden":!0,className:q(`flex size-4 shrink-0 items-center justify-center rounded border text-micro`,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})]}),t?(0,Q.jsx)(`span`,{className:`min-w-0 break-words text-xs text-muted-foreground`,children:t}):null]})}function Yl({slot:e,selected:t,disabled:n,onClick:r,children:i}){return(0,Q.jsx)(`button`,{type:`button`,"data-slot":e,disabled:n,"aria-pressed":t,onClick:r,className:q(`rounded-md border border-dashed px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors`,`hover:border-primary/50 hover:bg-primary/[0.06] hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,t?`border-primary/60 bg-primary/[0.06] text-foreground`:`border-border bg-card`),children:i})}var Xl=/\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 Zl(e){return Xl.test(e)}function Ql(e){for(let t=e.turns.length-1;t>=0;--t){let n=e.turns[t].planEntries;if(n!==void 0)return n}}function $l(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 eu(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 tu(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e){return typeof e==`string`?e:void 0}function nu(e){if(!(typeof e!=`string`||e===``))return Number.isFinite(new Date(e).getTime())?e:void 0}function ru(e){return e===`claude`||e===`codex`||e===`junie`||e===`opencode`||e===`cursor`||e===`pi`||e===`copilot`?e:void 0}var iu=e=>tu(e)&&typeof e.header==`string`&&Array.isArray(e.options);function au(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(`
28
- `).filter(e=>!/^CEZ:(?:PR=\d+|ISSUE=\d+|TITLE=.+)\s*$/.test(e)).join(`
29
- `):n}function ou(e){let t=e=>au(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 su(e){if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}}var cu=e=>e.kind===`message`||e.kind===`reasoning`||e.kind===`tool`,lu=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function uu(e){if(!tu(e)||!Array.isArray(e.todos))return;let t=[];for(let n of e.todos){if(!tu(n)||typeof n.content!=`string`)return;t.push({content:n.content,status:lu.has(n.status)?n.status:`pending`,...typeof n.activeForm==`string`?{activeForm:n.activeForm}:{}})}return t}function du(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=ru(t.runner),d=new WeakSet,f=(e,t)=>{let n=l();u===void 0||d.has(n)||!Zl(e)||(d.add(n),n.entries.push({origin:`meta`,entry:{kind:`agent-update-required`,id:`${t}:update`,provider:u}}))},p=(e,t)=>ze(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=nu(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=nu(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=nu(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=nu(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(!tu(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===``||!cu(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(fu.has(n))break;let i=mi(n,t.input);if(i.toolKind===`plan`){let n=uu(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=su(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=ru(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=ru(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(iu)?n:n.filter(iu);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(au(r.text,!0).trim());t.size!==0&&(e.entries=e.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`message`&&t.has(au(e.entry.text,!0).trim()))),ou(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:au(e.text,i||a)}:e)}}),...i===void 0?{}:{sessionEnded:i},...s===void 0?{}:{lastEventAt:s}}}var fu=new Set([`subAgentActivity`,`collabAgentToolCall`,`collabToolCall`]);function pu({run:e,thread:t,currentThread:n=t,history:r,onMarkedUnread:i,embedded:o=!1}){let s=eu(e.status,e.error,l(e)),c=(0,Z.useCallback)(()=>i?.(e.id),[i,e.id]),u=Ql(n),d=a(e),f=u!==void 0&&u.length>0?zc(u):void 0,p=e.status===`running`||e.status===`waiting`,m=e.status===`queued`,h=jo(e),g=!p&&!m&&h.available,_=g&&h.canContinue,v=Wa(e,h.continueWith,{surface:null}),y=!!e.worktreeLifecycle?.activeOperationId,b=!p&&e.status!==`queued`,x=(0,Z.useMemo)(()=>Cc(n.turns,b),[n.turns,b]),S=(0,Z.useMemo)(()=>wc(n.turns),[n.turns]),[C,w]=(0,Z.useState)(void 0),[D,O]=(0,Z.useState)(e.id);D!==e.id&&(O(e.id),w(void 0));let k=(0,Z.useMemo)(()=>C===void 0?void 0:Ac(n.turns,C,b),[n.turns,C,b]),A=(0,Z.useMemo)(()=>C===void 0?[]:jc(n.turns,C),[n.turns,C]),j=on(e.id,`composer`),M=Do(e.id),{mutateAsync:N}=E(e.id),{mutateAsync:P}=K(e.id),{mutateAsync:F}=U(e.id),I=(0,Z.useMemo)(()=>m?{onEditTask:async e=>{await N({task:e})},onEditMessage:(e,t)=>P({msgId:e,message:{text:t}}).then(()=>void 0),onRemoveMessage:e=>F(e).then(()=>void 0)}:void 0,[m,N,P,F]),L=(0,Z.useMemo)(()=>Qc(e,t),[e,t]),R=(0,Z.useMemo)(()=>tl(L,e.id),[L,e.id]),te=(0,Z.useCallback)(t=>(0,Q.jsx)(Gl,{ask:t,run:e}),[e]),ne=(0,Z.useMemo)(()=>{if(I===void 0)return;let t={task:{onEdit:I.onEditTask,editLabel:`Edit the prompt`,draftSurface:`task-prompt`}};for(let n of e.queuedMessages??[])t[`queued:${n.id}`]={onEdit:e=>I.onEditMessage(n.id,e),onRemove:()=>I.onRemoveMessage(n.id),draftSurface:`message:${n.id}`};return t},[I,e.queuedMessages]),z=ee(e,T()),{search:re}=Oe(),ie=ys(re,R.length),B=Jc(`${e.id}:main`,{onLoadOlder:r?.hasOlder?r.loadOlder:void 0,onJumpToLatest:r?.jumpToLatest,rowKeys:R.map(({key:e})=>e)});return Fe(B.restickIfStuck),(0,Q.jsxs)(`div`,{"data-route":`task-thread`,"data-run-id":e.id,className:`flex min-h-full flex-col`,children:[o?null:(0,Q.jsx)(tn,{run:e,planTally:f,onMarkedUnread:c,continuationEngine:_?h.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)(In,{worktreeId:e.worktreeLifecycle.worktreeId,operationId:e.worktreeLifecycle.activeOperationId,worktreePath:e.worktreePath,taskTitle:e.title??e.task}):null,r?(0,Q.jsx)(vu,{hasOlder:r.hasOlder,loading:r.isFetchingOlder,error:r.olderError,fallback:r.fallback,retainedPages:r.retainedPages,onLoad:B.loadOlder}):null,(0,Q.jsx)(nl,{runId:e.id,viewId:`main`,sections:L,mode:`document`,renderAsk:te,messageActions:ne,scrollControls:B,renderMode:ie,rowModels:R}),t.turns.length===0?e.status===`queued`?(0,Q.jsx)(bu,{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`&&!y?(0,Q.jsx)(ec,{since:yu(e,n),lastActivityAt:n.lastEventAt}):null,(0,Q.jsx)(es,{run:e}),s&&s.state===`closed`?(0,Q.jsxs)(`div`,{"data-slot":`thread-footer`,"data-state":s.state,className:q(`mt-auto flex items-center gap-2 border-t border-border pt-3 text-xs`,s.tone===`danger`?`text-danger`:`text-soft-foreground`),children:[(0,Q.jsx)(hu,{label:s.label,offerContinue:s.tone===`danger`&&!e.autoResumeAt,onContinue:g?()=>v(``,[]):void 0,blockedReason:_?void 0:h.providerPending?`Checking the agent provider…`:h.reason??`Connect an agent provider to continue.`}),ye(fe(e))?(0,Q.jsx)(`a`,{"data-slot":`pr-link`,href:fe(e),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`PR ↗`}):null,ye(z)?(0,Q.jsx)(`a`,{"data-slot":`issue-link`,href:z,target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`Issue ↗`}):null]}):null,e.status===`review`&&!y&&e.worktree!==!1?(0,Q.jsx)(kl,{run:e,diffComments:M}):null]}),(0,Q.jsx)(Pl,{status:e.status}),(0,Q.jsx)(El,{runId:e.id,renderAsk:te,agent:k,entries:A,onClose:()=>w(void 0)}),(0,Q.jsxs)(Lo,{overlay:B.pillVisible?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-12 flex justify-center`,children:(0,Q.jsx)(Zc,{onJump:B.jumpToLatest})}):null,children:[(0,Q.jsx)(Pc,{runId:e.id,agents:x,onSelect:w},`agents:${e.id}`),(0,Q.jsx)(Wc,{skills:S}),u!==void 0&&u.length>0?(0,Q.jsx)(Vc,{runId:e.id,entries:u,settled:b},e.id):null,(0,Q.jsx)(Qo,{run:e}),!y&&d?(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)(Hr,{tone:`pending`,pulse:!0}),`Budget reached — spent $`,d.spent.toFixed(2),` of $`,d.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)(_u,{runId:e.id})]}):null]}):!y&&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)(Hr,{tone:`pending`,pulse:!0}),`The agent is paused, waiting for your reply`,(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsx)(_u,{runId:e.id})]}):null,m?(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)(Hr,{tone:`pending`}),`Messages you add now are folded into the prompt before the run starts.`]}):null,y?(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)(Io,{run:e,draft:j,diffComments:M,continueAction:h,getMentionCandidates:()=>$l(t)})]})]})}var mu=/— continue to /i;function hu({label:e,offerContinue:t=!1,onContinue:n,blockedReason:r}){let i=n?mu.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)(gu,{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)(gu,{onContinue:n,blockedReason:r}),` to `,o]})}function gu({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 _u({runId:e}){let t=Wt(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 vu({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-meta 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 yu(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 bu({run:e}){let t=ct(v().data??[],e.id),n=$o(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)(Hr,{tone:`pending`,pulse:!0}),(0,Q.jsx)(`p`,{className:`text-ui font-medium`,children:Nn(e.queueWaitReason)??`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,` · `,e.queueWaitReason?`starts automatically when the account and a slot are available`:`starts automatically when a slot frees up`]}),!e.queueWaitReason&&(0,Q.jsx)(J,{"data-slot":`start-now`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:n.isPending||n.isSuccess,onClick:()=>n.mutate(),title:`Start this task now, over the parallel-task limit`,children:`Start now`})]})}var xu=(0,Z.createContext)(null);function Su(){return(0,Z.useContext)(xu)}function Cu(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 wu({className:e}){let t=Su();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)(yi,{"aria-hidden":`true`}),`Exit full view`]}):null}var Tu=[];function Eu(e){return Array.isArray(e)?e.flatMap(e=>{let t=he.safeParse(e);return t.success?[t.data]:[]}):[]}function Du(){let e=s(),t=R(),n=Z.useRef(0),r=Z.useRef(Promise.resolve()),i=t.data?.savedLayouts,a=Z.useMemo(()=>i?Eu(i).filter(e=>!Qt(e.name)&&e.columns.every(e=>qt(e.view))):Tu,[i]),o=Z.useCallback(t=>{let i=e.getQueryData(oe.uiState);if(i===void 0)return;let a=t(Eu(i.savedLayouts)).slice(0,50);e.setQueryData(oe.uiState,{...i,savedLayouts:a});let o=++n.current,s=r.current.then(async()=>{let t=await y({savedLayouts:a},{keepalive:!0});o===n.current&&e.setQueryData(oe.uiState,t)});r.current=s.catch(t=>{Y(t instanceof Error?t.message:String(t),{tone:`danger`}),o===n.current&&e.invalidateQueries({queryKey:oe.uiState})})},[e]);return{saved:a,save:Z.useCallback(e=>o(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)}),[o]),remove:Z.useCallback(e=>o(t=>t.filter(t=>t.name!==e)),[o])}}var Ou=400,ku=1500,Au=2e3,ju=3e4;function Mu(e){let[t,n]=(0,Z.useState)(Pt),[r,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),[c,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(Pt()),a(!1),s(!1),l(!1),d(0)),(0,Z.useEffect)(()=>{let t=!1,r=null;f.current=null;let i=t=>{p.current={taskId:e,state:t},_.current=t,g.current={taskId:e,state:t},n(t),a(!0)},o=async n=>{let a;try{a=await A(e)}catch{if(t)return;n===0&&i(Pt()),l(!0),r=setTimeout(()=>void o(n+1),Math.min(ju,Au*2**n));return}t||(f.current=e,m.current&&clearTimeout(m.current),m.current=null,l(!1),!(n>0&&a.layouts===null)&&(i(a.layouts===null?Pt():Ze(a.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,a=t=>{r===h.current&&p.current.taskId===e&&s(t)},o=s=>{(n?i(e,t,{keepalive:n}):i(e,t)).then(()=>a(!1)).catch(e=>{if(r===h.current){if(e?.status===400)return a(!0);if(s>0){setTimeout(()=>{r===h.current&&o(s-1)},ku);return}a(!0)}})};o(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)},Ou),()=>{m.current&&clearTimeout(m.current),m.current=null}},[r,v,e,t,c]),(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:o,loadFailed:c,replaced:u,layout:Yt(t),addLayout:(0,Z.useCallback)(e=>n(t=>Vt(t,e)),[]),closeLayout:(0,Z.useCallback)(e=>n(t=>an(t,e)),[]),selectLayout:(0,Z.useCallback)(e=>n(t=>un(t,e)),[]),renameLayout:(0,Z.useCallback)((e,t)=>n(n=>dn(n,e,t)),[]),applySaved:(0,Z.useCallback)(e=>n(t=>Mt(t,e)),[]),keepAs:(0,Z.useCallback)(e=>n(t=>Bt(t,e)),[]),addColumn:(0,Z.useCallback)(e=>b((t,n)=>rn(t,n,e)),[b]),closeColumn:(0,Z.useCallback)(e=>b((t,n)=>Xt(t,n,e)),[b]),setColumnView:(0,Z.useCallback)((e,t)=>b((n,r)=>nt(n,r,e,t)),[b]),resizeColumns:(0,Z.useCallback)((e,t)=>b((n,r)=>bt(n,r,e,t)),[b]),moveColumn:(0,Z.useCallback)((e,t)=>b((n,r)=>jt(n,r,e,t)),[b]),openDeepLink:(0,Z.useCallback)(e=>n(t=>fn(t,e)),[]),dropView:(0,Z.useCallback)((e,t,r)=>n(n=>sn(n,e,t,r)),[]),setColumnBrowser:(0,Z.useCallback)((e,t)=>b((n,r)=>St(n,r,e,t)),[b]),openInBrowser:(0,Z.useCallback)(e=>{let t=g.current?.state;return!t||Nt(t,e)===null?!1:(n(t=>Nt(t,e)??t),!0)},[]),openBeside:(0,Z.useCallback)(e=>{let t=g.current?.state??p.current.state;if(!t)return null;let r=ln(t,e);return r?(n(t=>ln(t,e)?.state??t),{name:r.name,index:r.index}):null},[])}}function Nu({view:e,columns:t,onDrop:n}){let r=t.length>=Et;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 ${gt(e)} here`}]}]:t.map((t,n)=>{let i={key:`replace:${n}`,at:n,mode:`replace`,label:t.view===e?gt(e):`Replace ${gt(t.view)}`,hint:r?`${Et} columns is the limit`:void 0},a=r?[i]:[{key:`insert:${n}`,at:n,mode:`insert`,label:`Beside`,hint:`left`},i,{key:`insert:${n+1}:${n}`,at:n+1,mode:`insert`,label:`Beside`,hint:`right`}];return{width:t.width,zones:a}})).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.jsx)(Pu,{zone:e,onDrop:n},e.key))},t))})}function Pu({zone:e,onDrop:t}){let{over:n,reset:r,handlers:i}=ai(e=>e.dataTransfer.types.includes(ii));return(0,Q.jsxs)(`div`,{"data-drop-zone":e.mode,...i,onDragOver:e=>{e.dataTransfer.types.includes(`text/cez-view`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:n=>{r();let i=n.dataTransfer.getData(ii);qt(i)&&(n.preventDefault(),t(i,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`,n&&`border-foreground/60 bg-muted text-foreground`),children:[e.label,e.hint?(0,Q.jsx)(`span`,{className:`text-meta font-normal opacity-80`,children:e.hint}):null]})}var Fu=1024;function Iu({columns:e,actions:t,renderView:n,headerExtras:r}){let i=Ke(Fu),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)<Et,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)(Ru,{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)(Tt,{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)(Un,{"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)(Tr,{"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)(Tt,{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)(Br,{value:String(a),onValueChange:e=>s(Number(e)),className:`shrink-0 gap-0`,children:(0,Q.jsx)(zr,{"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`?Un:at[e[t].view];return(0,Q.jsxs)(Rr,{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`:gt(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)(Tt,{scope:`window`,onPick:f})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Lu,{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)(zu,{index:o-1,width:e[o-1].width,pair:e[o-1].width+i.width,rowRef:a,onResize:t.resizeColumns}):null,(0,Q.jsx)(Lu,{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)(wu,{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)(xu.Provider,{value:null,children:n(i.view,o,i)})})]},o)]),u===e.length?_:null]})}function Lu({index:e,column:t,count:n,actions:r,menu:i,trailing:a,onSplit:o,canSplit:s=!0,grip:c=!0,extras:l}){let{over:u,reset:d,handlers:f}=ai(e=>e.dataTransfer.types.includes(`text/cez-column`)),p=at[t.view],m=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`)},...f,onDrop:t=>{if(d(),!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:m,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)(Rn,{"aria-hidden":`true`,className:`size-3.5`})}):null,n===1?null:(0,Q.jsxs)(rr,{children:[(0,Q.jsx)(or,{asChild:!0,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,"data-action":`change-view`,"aria-label":`${gt(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)(p,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:gt(t.view)}),(0,Q.jsx)(qn,{"aria-hidden":`true`,className:`size-3 shrink-0 opacity-60`})]})}),(0,Q.jsxs)(ir,{align:`start`,className:`w-48`,children:[(0,Q.jsx)(er,{children:`Change view`}),(0,Q.jsx)(Ct,{onPick:t=>r.setColumnView(e,t),disabled:t.view})]})]}),(0,Q.jsx)(`span`,{draggable:n>1&&c,onDragStart:m,className:q(`h-full min-w-0 flex-1`,n>1&&c&&`cursor-grab active:cursor-grabbing`)}),l,o?(0,Q.jsx)(Xn,{children:(0,Q.jsxs)(Zn,{children:[(0,Q.jsx)(Jn,{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)(dt,{"aria-hidden":`true`,className:`size-3.5`})})})}),(0,Q.jsx)(Yn,{side:`bottom`,children:s?`Split view (\\)`:`At most ${Et} windows`})]})}):null,i,n>1?(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${gt(t.view)}`,title:`Close view`,onClick:()=>r.closeColumn(e),className:`text-soft-foreground`,children:(0,Q.jsx)(Tr,{"aria-hidden":`true`,className:`size-3.5`})}):null,a]})}function Ru({index:e,column:t,count:n,actions:r}){return(0,Q.jsxs)(rr,{children:[(0,Q.jsx)(or,{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 ${gt(t.view)}`,children:(0,Q.jsx)(_t,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,Q.jsxs)(ir,{align:`end`,className:`w-52`,children:[n>1?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(nr,{disabled:e===0,onSelect:()=>r.moveColumn(e,e-1),children:[(0,Q.jsx)(Tn,{"aria-hidden":`true`}),`Move left`]}),(0,Q.jsxs)(nr,{disabled:e===n-1,onSelect:()=>r.moveColumn(e,e+1),children:[(0,Q.jsx)(Mn,{"aria-hidden":`true`}),`Move right`]})]}):null,(0,Q.jsx)(tr,{}),(0,Q.jsxs)(nr,{onSelect:()=>r.closeColumn(e),children:[(0,Q.jsx)(Tr,{"aria-hidden":`true`}),`Close view`]})]})]})}function zu({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(Gt(n)),"aria-valuemax":Math.round(n-Gt(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 Bu=(0,Z.lazy)(()=>be(()=>import(`./terminal-drawer-CuGVJS-l.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,20]))),Vu=(0,Z.lazy)(()=>be(()=>import(`./task-graph-CJfTnzUp.js`).then(e=>({default:e.TaskGraphView})),__vite__mapDeps([21,1,2,3,4,5,22,6,23,24,9,25,26,27,15,28,29,30,10,11,31,32,12,33,34,35,36,16,37,38,39,40,41,13,14,42,43,18,44,45,46,7,8,47,48,49,50,17,51,52,53,54,55])));function Hu({view:e}){let{id:t}=De(),n=re(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}=f();if((0,Z.useEffect)(()=>{n.data&&r.current!==n.data.id&&Je(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)(Uu,{view:e});if(n.isError){let e=n.error instanceof te&&n.error.status===404;return(0,Q.jsx)(`div`,{"data-route":`task-workspace`,className:`flex min-h-full flex-col`,children:(0,Q.jsx)(qr,{icon:e?(0,Q.jsx)(wr,{}):(0,Q.jsx)(Ut,{}),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)(Ee,{to:`/`,children:`Back to tasks`})})})})}return(0,Q.jsx)(Wu,{run:n.data,deepLinkView:e,onMarkedUnread:i})}function Uu({view:e}){return e===`files`?(0,Q.jsx)(Jt,{tab:`files`}):e===`terminal`?(0,Q.jsx)(Jt,{tab:`terminal`}):e===`browser`?(0,Q.jsx)(Jt,{tab:`preview`}):e===`changes`||e===`commits`||e===`graph`?(0,Q.jsx)(Jt,{tab:`changes`}):(0,Q.jsx)(zn,{})}function Wu({run:e,deepLinkView:t,onMarkedUnread:n}){let r=Mu(e.id),{openDeepLink:i,addLayout:a,closeLayout:o,selectLayout:s,setColumnBrowser:c,openInBrowser:l,applySaved:u,keepAs:d}=r,f=Du(),{save:p,remove:h}=f,g=r.state,_=(r.layout?.columns.length??0)>0,v=(0,Z.useCallback)(e=>{let t=$e(g,e);t&&(p(t),d(t.name))},[d,g,p]),y=m().data?.capabilities?.terminal===!0,b=(0,Z.useMemo)(()=>qe.filter(e=>e!==`terminal`||y),[y]),x=xe(),S=(0,Z.useRef)(null),C=(0,Z.useRef)(new Map),w=(0,Z.useRef)(e.id);w.current!==e.id&&(w.current=e.id,C.current=new Map,S.current=null),(0,Z.useEffect)(()=>{if(!r.ready)return;if(t){S.current?.runId!==e.id&&(S.current={runId:e.id,name:r.state.active});let n=C.current.get(t);n!==void 0&&r.state.layouts.some(e=>e.name===n)?s(n):i(t);return}let n=S.current;S.current=null,x===`POP`&&n&&n.runId===e.id&&n.name!==r.state.active&&s(n.name)},[t,r.ready,r.replaced,x,i,e.id,s]),(0,Z.useEffect)(()=>{if(!r.ready||!t||C.current.has(t))return;let e=r.layout;e&&e.columns.length===1&&e.columns[0]?.view===t&&C.current.set(t,e.name)},[t,r.layout,r.ready]);let T=(0,Z.useCallback)(()=>n(e.id),[n,e.id]),E=(0,Z.useMemo)(()=>st.filter(t=>b.includes(t)&&(t!==`graph`||!!e.workflowDef)),[b,e.workflowDef]),D=r.ready?r.layout?It(r.layout):`session`:null,O=(0,Z.useMemo)(()=>r.state.layouts.filter(e=>It(e)===null),[r.state.layouts]),k=(0,Z.useCallback)(()=>a(),[a]),{hints:A,show:j}=$t((0,Z.useMemo)(()=>rt(E),[E])),ee=Ce(),[M,N]=(0,Z.useState)(null),P=(0,Z.useCallback)(e=>{setTimeout(()=>N(e),0)},[]),F=(0,Z.useCallback)(()=>N(null),[]),I=r.dropView,L=(0,Z.useRef)({runId:e.id,current:r.state.active,previous:null});L.current.runId===e.id?L.current.current!==r.state.active&&(L.current={runId:e.id,current:r.state.active,previous:L.current.current}):L.current={runId:e.id,current:r.state.active,previous:null};let R=(0,Z.useCallback)(e=>{if(D!==e)return null;let t=L.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)},[D,r.state.layouts,i,s]),te=(0,Z.useCallback)((e,t,n)=>{if(N(null),n===`insert`&&R(e)!==null){I(e,t===0?0:Et,n);return}I(e,t,n)},[R,I]),ne=(0,Z.useCallback)(e=>{let t=R(e)??r.layout?.columns.length??0;I(e,t,`insert`)},[R,I,r.layout?.columns.length]),z=r.layout?.columns.length??0,re=D===null&&z>1?r.closeColumn:void 0,[ie,B]=(0,Z.useState)(()=>Wr(e.id)),V=(0,Z.useRef)(e.id);V.current!==e.id&&(V.current=e.id,B(Wr(e.id)));let H=(0,Z.useCallback)(t=>{B(n=>{let r={...n,...t};return Gr(e.id,r),r})},[e.id]),ae=r.layout?.columns.some(e=>e.view===`terminal`)??!1,oe=Te(),U=y&&ie.open&&!ae,[se,ce]=(0,Z.useState)(!1),W=(0,Z.useRef)(e.id);W.current!==e.id&&(W.current=e.id,ce(!1));let le=(0,Z.useCallback)(()=>ce(!1),[]),G=(0,Z.useCallback)(()=>ce(e=>!e),[]),ue=Cu(se,le),de=(0,Z.useMemo)(()=>({maximized:se,toggle:G}),[se,G]),fe=ie.open,K=(0,Z.useCallback)(()=>{ae||H({open:!fe})},[fe,ae,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||(D!==null||me.length===1?i(`session`):pe(e))},[pe,D,i,me,H]),ge=(0,Z.useMemo)(()=>U||ae?[`terminal`]:[],[U,ae]),_e=(0,Z.useMemo)(()=>(0,Q.jsx)(oi,{layouts:O,active:r.state.active,fixedViews:E,fixedActive:D,onViews:ge,onSelectFixed:i,onSelect:s,onClose:o,saved:f.saved,onApplySaved:u,onSaveCurrent:_?v:void 0,onDeleteSaved:h,notesHref:`/tasks/${e.id}/notes`,onViewDragStart:P,onViewDragEnd:F,onOpenBeside:ne,onColumnDropClose:re,keyHints:A,showKeyHints:j}),[O,r.state.active,E,D,ge,i,s,o,f.saved,u,_,v,h,e.id,P,F,ne,re,A,j]),ve=(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:G,children:(0,Q.jsx)(Ye,{"aria-hidden":`true`})}),[G]),ye=(0,Z.useMemo)(()=>[...E.map(e=>({select:()=>i(e),active:D===e})),...O.map(e=>({select:()=>s(e.name),active:D===null&&e.name===r.state.active}))],[E,O,D,r.state.active,i,s]),be=(0,Z.useMemo)(()=>[...lt(E).map(t=>t===`notes`?()=>ee(`/tasks/${e.id}/notes`):()=>i(t))],[E,i,ee,e.id]),Se=(0,Z.useRef)({stripOrder:ye,numbered:be,toggleMaximized:G,terminalAllowed:y,toggleDrawer:K});Se.current={stripOrder:ye,numbered:be,toggleMaximized:G,terminalAllowed:y,toggleDrawer:K},(0,Z.useEffect)(()=>{let e=e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.repeat||e.defaultPrevented||En(e.target)||document.querySelector(`[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]`))return;let t=Se.current,n=document.querySelector(Ku),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 Y=Do(e.id),[we,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&&Y.comments.length>0){Ee({index:e,view:t});return}r.setColumnView(e,t)},[De,Y.comments.length,r.setColumnView]),ke=(0,Z.useMemo)(()=>({addColumn:D===null?r.addColumn:e=>I(e,z,`insert`),closeColumn:r.closeColumn,setColumnView:Oe,resizeColumns:r.resizeColumns,moveColumn:r.moveColumn}),[D,I,z,r.addColumn,r.closeColumn,Oe,r.resizeColumns,r.moveColumn]),Ae=r.openBeside,je=(0,Z.useCallback)(t=>{let n=Ae(t.view);n&&ni(`${e.id}:${n.name}:${n.index}:${t.view}`,t.value)},[Ae,e.id]);(0,Z.useEffect)(()=>An(e.id),[e.id]),(0,Z.useEffect)(()=>{if(!r.ready)return;let t=Dn(e.id);t&&je({view:`files`,value:t})},[r.ready,je,e.id]),(0,Z.useEffect)(()=>{let t=()=>document.querySelector(Ku),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:E,activeView:D,openView:i,openViewBeside:ne,layouts:O.map(e=>({name:e.name,label:Rt(e.name),active:D===null&&e.name===r.state.active})),selectLayout:s,maximized:se,toggleMaximized:G,get splitView(){return n()?()=>n()?.click():null},terminal:{allowed:y,open:fe,inColumn:ae,toggle:K,openInColumn:()=>{H({open:!1}),Ae(`terminal`)}},get focusComposer(){return a()?()=>a()?.focus():null},openFile:e=>je({view:`files`,value:e}),markedUnread:T};return Bn(o),()=>jn(o)});let Me=r.state.active,Ne=De?.some(e=>e.view===`session`)?`session`:`changes`,Pe=to(e),{addDraft:Fe,discard:Ie,note:Le,marks:Re}=Pe,ze=(0,Z.useCallback)(e=>{let t=Le(e);t?.phase===`draft`&&!t.added&&Ie(e)},[Ie,Le]),Be=Ju(e.id,r.layout?Me:null,r.state.layouts),Ve=(0,Z.useCallback)(e=>e===`terminal`&&y?(0,Q.jsx)(ar,{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)(Qe,{"aria-hidden":`true`,className:`size-3.5`})})}):null,[he,y]),He=(0,Z.useCallback)((t,r,i,a)=>{switch(t){case`session`:return(0,Q.jsx)(Zu,{run:e,onMarkedUnread:n,onOpenReference:je});case`changes`:return(0,Q.jsx)(Ro,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:changes`},e.id);case`commits`:return(0,Q.jsx)(ri,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:commits`});case`files`:return(0,Q.jsx)(Ko,{run:e,embedded:!0,stateKey:`${e.id}:${a}:${r}:files`});case`graph`:return(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xu,{title:`Loading graph…`}),children:(0,Q.jsx)(Vu,{run:e,embedded:!0})});case`terminal`:return y?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xu,{title:`Loading terminal…`}),children:(0,Q.jsx)(Bu,{runId:e.id,height:0,onHeightChange:Gu,onOpenInBrowser:l,fill:!0})}):(0,Q.jsx)(qr,{icon:(0,Q.jsx)(cr,{}),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)(Yi,{state:i.browser??Ft(),onChange:e=>c(r,e),onPickElement:Fe,designMarks:Re,onDesignEscape:ze,designTray:Pe.ready>0||Pe.sending?(0,Q.jsx)(Pa,{notes:Pe}):null,renderEmpty:y?t=>(0,Q.jsx)(Aa,{runId:e.id,projectId:oe,onOpen:t,setup:e.worktreeLifecycle,onShowTerminal:ae?void 0:()=>H({open:!0})}):void 0,renderDesignNote:({mark:e,close:t})=>{let n=Le(e);return n?(0,Q.jsx)(Na,{note:n,notes:Pe,onClose:t}):null}})}},[Fe,Re,Pe,ze,Le,n,l,je,e,c,y,oe,ae,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)(tn,{run:e,tab:Ne,onMarkedUnread:T,tabs:_e,headerActions:ve,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)(wt.Provider,{value:b,children:(0,Q.jsx)(xu.Provider,{value:de,children:(0,Q.jsxs)(`div`,{ref:ue.ref,"data-slot":`workspace-stage`,"data-maximized":ue.covering?``:void 0,style:ue.style,className:q(`relative flex min-h-0 flex-1 flex-col`,ue.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)(Yu,{layout:e,active:e.name===Me,actions:ke,renderView:He,headerExtras:Ve},e.name)):(0,Q.jsx)(qr,{icon:(0,Q.jsx)(Un,{}),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:k,children:`New layout`})}):(0,Q.jsx)(Uu,{view:t}),M?(0,Q.jsx)(Nu,{view:M,columns:r.layout?.columns??[],onDrop:te}):null,ue.covering&&D!==null?(0,Q.jsx)(wu,{className:`absolute top-2 right-3 z-20 bg-card shadow-sm`}):null]})})}),(0,Q.jsx)(Lr,{open:we!==null,onOpenChange:e=>!e&&Ee(null),children:(0,Q.jsxs)(Mr,{children:[(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(jr,{children:`You have an unsent comment`}),(0,Q.jsxs)(Ar,{children:[Y.comments.length===1?`One comment on the changes has not been sent yet.`:`${Y.comments.length} comments on the changes have not been sent yet.`,` `,`This is the last column showing them.`]})]}),(0,Q.jsxs)(Pr,{children:[(0,Q.jsx)(Fr,{children:`Go back`}),(0,Q.jsx)(Nr,{onClick:()=>{we&&r.setColumnView(we.index,we.view),Ee(null)},children:`Change anyway`})]})]})}),U?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Bu,{runId:e.id,height:ie.height,onHeightChange:e=>H({height:e}),onClose:()=>H({open:!1}),onMoveToColumn:()=>{H({open:!1}),Ae(`terminal`)},onOpenInBrowser:l})}):null]})}var Gu=()=>{},Ku=`[data-slot="workspace-stage"] [data-slot="workspace-layout"][data-active]`;function qu(e){return e.columns.every(e=>e.view!==`terminal`&&e.view!==`browser`)}function Ju(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)&&qu(e))}function Yu({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)(Iu,{columns:e.columns,actions:n,renderView:o,headerExtras:i})})})}function Xu({title:e}){return(0,Q.jsx)(qr,{icon:(0,Q.jsx)(vr,{className:`motion-safe:animate-spin`}),tone:`neutral`,heading:`h2`,title:e})}function Zu({run:e,onMarkedUnread:t,onOpenReference:n}){let r=Ii(e.id),i=(0,Z.useMemo)(()=>du(r.visibleEvents,{activeTurn:e.status===`running`,runner:e.runner}),[r.visibleEvents,e.status,e.runner]),a=(0,Z.useMemo)(()=>du(r.currentEvents,{activeTurn:e.status===`running`,runner:e.runner}),[r.currentEvents,e.status,e.runner]);if(Zo(e,r.visibleEvents),r.isPending)return(0,Q.jsx)(zn,{});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=Qu(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)(pu,{run:e,thread:i,currentThread:a,history:r,onMarkedUnread:t,embedded:!0})})}function Qu(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};