@edspencer/paddock 0.74.3 → 0.74.4

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 (69) hide show
  1. package/package.json +2 -2
  2. package/packages/server/dist/claude-mcp.js +23 -25
  3. package/packages/server/dist/mcp-servers.d.ts +5 -4
  4. package/packages/server/dist/mcp-servers.js +38 -40
  5. package/packages/server/package.json +1 -1
  6. package/packages/web/dist/assets/{DeleteProjectDialog-q-V59YiP.js → DeleteProjectDialog-BdoW_R7V.js} +1 -1
  7. package/packages/web/dist/assets/DiscoverPage-DvTIPCrH.js +2 -0
  8. package/packages/web/dist/assets/{DiscoverView-CDqEPbLw.js → DiscoverView-CMj7eSnF.js} +1 -1
  9. package/packages/web/dist/assets/{InstanceConfigPage-CLu6YmDA.js → InstanceConfigPage-DKNwaVYI.js} +1 -1
  10. package/packages/web/dist/assets/{MarkdownRenderer-D-7rJ2MA.js → MarkdownRenderer-B_3lLjnB.js} +1 -1
  11. package/packages/web/dist/assets/{ProjectRedirect-0rVEh-WX.js → ProjectRedirect-nDbXztYC.js} +1 -1
  12. package/packages/web/dist/assets/{ProjectView-C1ezKZtq.js → ProjectView-PRsm7vOY.js} +3 -3
  13. package/packages/web/dist/assets/{ProjectsGrid-BjFdqjV3.js → ProjectsGrid-CYJi1Kqr.js} +1 -1
  14. package/packages/web/dist/assets/{RootHome-DTZbSsti.js → RootHome-CheYnmEv.js} +1 -1
  15. package/packages/web/dist/assets/{Surfaces-ebMLXoSK.js → Surfaces-CM8msreu.js} +1 -1
  16. package/packages/web/dist/assets/{arc-CxgFwaSO.js → arc-nqaX3m3G.js} +1 -1
  17. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-DQRs6fUO.js → architectureDiagram-3BPJPVTR-d4br01sb.js} +1 -1
  18. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-CKtBGIVx.js → blockDiagram-GPEHLZMM-VodC7YkS.js} +1 -1
  19. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-CiHinbCH.js → c4Diagram-AAUBKEIU-B6sPwmLi.js} +1 -1
  20. package/packages/web/dist/assets/channel-BNVT7JiH.js +2 -0
  21. package/packages/web/dist/assets/{chunk-2J33WTMH-DROWEdGz.js → chunk-2J33WTMH-JtaEkPQC.js} +1 -1
  22. package/packages/web/dist/assets/{chunk-4BX2VUAB-VWuPhDDm.js → chunk-4BX2VUAB-DE9kQ9zL.js} +1 -1
  23. package/packages/web/dist/assets/{chunk-55IACEB6-B3U9YNx_.js → chunk-55IACEB6-BtIMASB5.js} +1 -1
  24. package/packages/web/dist/assets/{chunk-727SXJPM-CIX50fRQ.js → chunk-727SXJPM-DLXUGkUZ.js} +1 -1
  25. package/packages/web/dist/assets/{chunk-AQP2D5EJ-D0FIIi3O.js → chunk-AQP2D5EJ-DH3jIkKd.js} +1 -1
  26. package/packages/web/dist/assets/{chunk-FMBD7UC4-CPh-a6PK.js → chunk-FMBD7UC4-BW5BAMeu.js} +1 -1
  27. package/packages/web/dist/assets/{chunk-ND2GUHAM-Dgvl3GVf.js → chunk-ND2GUHAM-CXeIOy_-.js} +1 -1
  28. package/packages/web/dist/assets/{chunk-QZHKN3VN--6FFIyTd.js → chunk-QZHKN3VN-N6ikFvm3.js} +1 -1
  29. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DM2u-qH7.js +2 -0
  30. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DM2u-qH7.js +2 -0
  31. package/packages/web/dist/assets/{core-DmcZcbit.js → core-DvlNQV3i.js} +1 -1
  32. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-CrkuZMpE.js → cose-bilkent-S5V4N54A-D-uP2JUg.js} +1 -1
  33. package/packages/web/dist/assets/{dagre-BM42HDAG-DLViqa6a.js → dagre-BM42HDAG-DcwT03nn.js} +1 -1
  34. package/packages/web/dist/assets/{diagram-2AECGRRQ-DDACz4xS.js → diagram-2AECGRRQ-CYWOuBDA.js} +1 -1
  35. package/packages/web/dist/assets/{diagram-5GNKFQAL-7M-qCrgM.js → diagram-5GNKFQAL-CchX8M-M.js} +1 -1
  36. package/packages/web/dist/assets/{diagram-KO2AKTUF-ORCh-W__.js → diagram-KO2AKTUF-C6gfE_3Y.js} +1 -1
  37. package/packages/web/dist/assets/{diagram-LMA3HP47-DB-BMVHo.js → diagram-LMA3HP47-C0nHp4dK.js} +1 -1
  38. package/packages/web/dist/assets/{diagram-OG6HWLK6-DvnaOyG_.js → diagram-OG6HWLK6-B2XnqQMm.js} +1 -1
  39. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-Bv0gzd7A.js → erDiagram-TEJ5UH35-EvAsmPUY.js} +1 -1
  40. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-ClGD26se.js → flowDiagram-I6XJVG4X-Crx1NVyQ.js} +1 -1
  41. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-DVYtc_Dd.js → ganttDiagram-6RSMTGT7-DXO1N4y2.js} +1 -1
  42. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-Bf6vf5_U.js → gitGraphDiagram-PVQCEYII-DI0uWhPj.js} +1 -1
  43. package/packages/web/dist/assets/{index-DKbCTgvS.js → index-CrFWN6gV.js} +2 -2
  44. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-BsUWhgeg.js → infoDiagram-5YYISTIA-C7T6BR2W.js} +1 -1
  45. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-CQGtjMds.js → ishikawaDiagram-YF4QCWOH-DIMWecJU.js} +1 -1
  46. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-B58R6W2A.js → journeyDiagram-JHISSGLW-Cw6l_Uvr.js} +1 -1
  47. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-J6QoqrIV.js → kanban-definition-UN3LZRKU-DS5FEgkP.js} +1 -1
  48. package/packages/web/dist/assets/{linear-D82_ZH34.js → linear-CO826BKf.js} +1 -1
  49. package/packages/web/dist/assets/{mermaid.core-DAaQ0A8U.js → mermaid.core-DmLiTJQf.js} +4 -4
  50. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-BoF58K9i.js → mindmap-definition-RKZ34NQL-BH7zKJ_V.js} +1 -1
  51. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-DQlDoISX.js → pieDiagram-4H26LBE5-CKvmGBhy.js} +1 -1
  52. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-wpX7tARX.js → quadrantDiagram-W4KKPZXB-BlrwN_-b.js} +1 -1
  53. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-CsHb872v.js → requirementDiagram-4Y6WPE33-XnkdTwhc.js} +1 -1
  54. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-Kd81146T.js → sankeyDiagram-5OEKKPKP-D8w8tvFt.js} +1 -1
  55. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-BPVBxFck.js → sequenceDiagram-3UESZ5HK-DSBhXBpD.js} +1 -1
  56. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-B3BWA7Zr.js → stateDiagram-AJRCARHV-Wx2j6w7O.js} +1 -1
  57. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-D0EQr0L1.js +2 -0
  58. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-CPV-ctE2.js → timeline-definition-PNZ67QCA-BzMDqPxS.js} +1 -1
  59. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-aHIEBP1W.js → vennDiagram-CIIHVFJN-C_qyX4Ca.js} +1 -1
  60. package/packages/web/dist/assets/{wardley-L42UT6IY-KTdxdz1j.js → wardley-L42UT6IY-D7JC0ZSP.js} +1 -1
  61. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-CYVKS1aU.js → wardleyDiagram-YWT4CUSO-hePAdnbK.js} +1 -1
  62. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-znmQf9g2.js → xychartDiagram-2RQKCTM6-CxiZbMIc.js} +1 -1
  63. package/packages/web/dist/index.html +1 -1
  64. package/packages/web/dist/sw.js +1 -1
  65. package/packages/web/dist/assets/DiscoverPage-Ytc7flhQ.js +0 -2
  66. package/packages/web/dist/assets/channel-Brnda8TU.js +0 -2
  67. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-B5WekHqh.js +0 -2
  68. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-B5WekHqh.js +0 -2
  69. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-moMhbA1I.js +0 -2
@@ -1,10 +1,10 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-D-7rJ2MA.js","assets/index-DKbCTgvS.js","assets/index-ClOpntF7.css","assets/queued-CagZVfWU.js","assets/DeleteProjectDialog-q-V59YiP.js","assets/lastTab-CU1zsF0j.js","assets/Surfaces-ebMLXoSK.js","assets/DiscoverView-CDqEPbLw.js","assets/core-DmcZcbit.js","assets/mermaid.core-DAaQ0A8U.js"])))=>i.map(i=>d[i]);
2
- import{r as a,a as B,W as be,j as e,a7 as vn,A as ge,a8 as Fs,a9 as qt,X as Fe,l as Je,aa as Tt,L as Js,ab as aa,C as Qt,ac as ra,B as ft,f as rt,a2 as Os,ad as er,ae as tr,af as sr,ag as nr,ah as ar,ai as rr,aj as ir,ak as or,q as It,a5 as Us,al as yn,S as Yt,am as lr,G as cs,a3 as Jt,an as ia,P as hs,ao as oa,ap as la,aq as ca,ar as ce,as as cr,at as dr,m as St,au as da,av as ds,K as ua,U as Gt,aw as ha,ax as Ne,ay as ur,az as hr,aA as Ts,aB as us,aC as ma,T as ms,aD as Bs,aE as mr,aF as fr,$ as xr,c as Vs,aG as pe,aH as gr,aI as pr,aJ as br,aK as jr,aL as wr,aM as vr,aN as yr,aO as Nn,aP as kn,aQ as Nr,aR as kr,aS as Cr,d as fs,aT as Sr,aU as $r,aV as Tr,aW as fa,u as Ir,R as Rr,aX as Er,e as Mr,_ as Ar,b as Dr,aY as Pr,aZ as _r,a_ as Lr,J as Fr,a$ as Or,i as Ur,b0 as Br}from"./index-DKbCTgvS.js";import{readQueued as Vr,readQueuedId as zr,readQueuedAttachments as Hr,writeQueued as Wr,writeQueuedId as Gr,writeQueuedAttachments as Kr,newQueuedId as qr}from"./queued-CagZVfWU.js";import{C as Xs,d as Qr,D as Yr}from"./DeleteProjectDialog-q-V59YiP.js";import{S as mt,C as Jr,E as Zs}from"./Surfaces-ebMLXoSK.js";import{t as dt,w as Xr}from"./lastTab-CU1zsF0j.js";import{D as Zr}from"./DiscoverView-CDqEPbLw.js";const ei=500,ti=9e4,Is="paddock:cancel",Cn="paddock:timeout";function si(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function ni(){const t=[{mimeType:"audio/webm;codecs=opus",ext:"webm"},{mimeType:"audio/webm",ext:"webm"},{mimeType:"audio/ogg;codecs=opus",ext:"ogg"},{mimeType:"audio/mp4",ext:"mp4"}],s=window.MediaRecorder;for(const n of t)if(typeof s.isTypeSupported!="function"||s.isTypeSupported(n.mimeType))return n;return{mimeType:"",ext:"webm"}}function ai({onText:t,timeoutMs:s=ti}){const[n,r]=a.useState("idle"),[i,o]=a.useState(null),[l,c]=a.useState(null),[m]=a.useState(si),u=a.useRef(null),p=a.useRef(null),g=a.useRef([]),h=a.useRef("webm"),b=a.useRef(null),N=a.useRef(null),f=a.useRef(!0);a.useEffect(()=>{f.current=!0;let $=!1;return B.transcriptionStatus().then(T=>{$||o(T.available)}).catch(()=>{$||o(!1)}),()=>{var T;$=!0,f.current=!1,(T=N.current)==null||T.abort(Is),d()}},[]);const d=()=>{var $;($=p.current)==null||$.getTracks().forEach(T=>T.stop()),p.current=null,u.current=null},v=a.useCallback(async()=>{if(!m||n==="recording"||n==="transcribing")return;c(null),b.current=null;let $;try{$=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(O){r("error"),c(li(O));return}p.current=$;const{mimeType:T,ext:y}=ni();h.current=y;const F=T?new MediaRecorder($,{mimeType:T}):new MediaRecorder($);g.current=[],F.ondataavailable=O=>{O.data&&O.data.size>0&&g.current.push(O.data)},F.onstop=()=>{d();const O=F.mimeType||T||"audio/webm",z=new Blob(g.current,{type:O});g.current=[],b.current=z,P(z)},u.current=F,F.start(),r("recording")},[m,n]),P=a.useCallback(async($,T=!1)=>{if($.size===0){b.current=null,f.current&&r("idle");return}f.current&&r("transcribing");const y=new AbortController;N.current=y;const F=setTimeout(()=>y.abort(Cn),s);try{const O=await B.transcribe($,`dictation.${h.current}`,y.signal);O.trim()&&t(O.trim()),b.current=null,f.current&&(c(null),r("idle"))}catch(O){if(y.signal.aborted&&y.signal.reason===Is){b.current=null,f.current&&(c(null),r("idle"));return}if(y.signal.aborted&&y.signal.reason===Cn){f.current&&(r("error"),c("Transcription timed out — try again."));return}if(ri(O)&&!T)return await oi(ei),P($,!0);f.current&&(r("error"),c(ii(O)))}finally{clearTimeout(F),N.current===y&&(N.current=null)}},[t,s]),E=a.useCallback(()=>{var $;($=N.current)==null||$.abort(Is)},[]),I=a.useCallback(()=>{const $=u.current;$&&$.state!=="inactive"&&$.stop()},[]),k=a.useCallback(()=>{n==="recording"?I():v()},[n,v,I]),S=a.useCallback(()=>{if(n==="recording"||n==="transcribing")return;const $=b.current;$?P($):v()},[n,P,v]),L=a.useCallback(()=>{b.current=null,c(null),r("idle")},[]);return{state:n,available:i,supported:m,error:l,start:v,stop:I,toggle:k,retry:S,dismiss:L,cancel:E}}function ri(t){return t instanceof be?t.status>=500:!0}function ii(t){return t instanceof be?t.status>=500?t.message||"Transcription service error — try again.":t.status===400?t.message||"Didn't catch any audio — try again.":t.message||"Transcription failed.":"Couldn't reach the transcription service — check your connection and retry."}function oi(t){return new Promise(s=>setTimeout(s,t))}function li(t){switch(t==null?void 0:t.name){case"NotAllowedError":case"SecurityError":return"Microphone permission denied.";case"NotFoundError":case"DevicesNotFoundError":return"No microphone found.";case"NotReadableError":return"Microphone is already in use.";default:return t instanceof Error?t.message:"Could not access the microphone."}}function ci({onText:t}){const{state:s,available:n,supported:r,error:i,toggle:o,retry:l,dismiss:c,cancel:m}=ai({onText:t});if(n!==!0)return null;const u=s==="recording",p=s==="transcribing",g=s==="error";if(!r)return e.jsx("button",{type:"button",disabled:!0,"aria-label":"Voice dictation unavailable",title:"Voice dictation needs a secure context (HTTPS or localhost). It's blocked over plain HTTP.",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-fg-subtle",children:e.jsx(vn,{width:18,height:18})});const h=u?"Stop recording":p?"Transcribing… — click to cancel":g?"Transcription failed — click to record again":"Record a voice message",b=()=>{p?m():o()};return e.jsxs("div",{className:"relative flex items-center",children:[g&&i&&e.jsxs("div",{role:"alert",className:"absolute bottom-full right-0 z-10 mb-2 flex max-w-[240px] items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-2.5 py-1.5 text-xs text-danger shadow-md",children:[e.jsx(ge,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:i}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 font-medium text-danger underline underline-offset-2 hover:opacity-80",children:"Retry"}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Dismiss error",className:"shrink-0 text-danger/70 hover:text-danger",children:"✕"})]}),e.jsxs("button",{type:"button",onClick:b,"aria-label":u?"Stop recording":p?"Cancel transcription":"Record a voice message","aria-pressed":u,title:h,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",u?"bg-danger-soft text-danger":p?"cursor-pointer text-accent can-hover:hover:bg-danger-soft can-hover:hover:text-danger":g?"bg-danger-soft text-danger":"text-fg-muted can-hover:hover:bg-surface-hover can-hover:hover:text-fg"].filter(Boolean).join(" "),children:[p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(di,{})}),e.jsx(Fs,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):u?e.jsx(Fs,{width:16,height:16}):e.jsx(vn,{width:18,height:18}),u&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function di(){return e.jsx("span",{className:"h-[18px] w-[18px] animate-spin rounded-full border-2 border-accent/25 border-t-accent",role:"status","aria-label":"Transcribing"})}const ui="paddock:chatModel:";function xa(t,s){return ui+(t??`new:${s}`)}function hi(t,s){try{const n=localStorage.getItem(xa(t,s));return n&&n.length>0?n:null}catch{return null}}function zs(t,s,n){try{localStorage.setItem(xa(t,s),n)}catch{}}const mi="paddock:draft:";function ga(t,s){return mi+(t??`new:${s}`)}function fi(t,s){try{return localStorage.getItem(ga(t,s))??""}catch{return""}}function xi(t,s,n){try{const r=ga(t,s);n.length>0?localStorage.setItem(r,n):localStorage.removeItem(r)}catch{}}const Sn="<paddock-attachments>",Hs="</paddock-attachments>",$n=`${Hs}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-B_3lLjnB.js","assets/index-CrFWN6gV.js","assets/index-ClOpntF7.css","assets/queued-CagZVfWU.js","assets/DeleteProjectDialog-BdoW_R7V.js","assets/lastTab-CU1zsF0j.js","assets/Surfaces-CM8msreu.js","assets/DiscoverView-CMj7eSnF.js","assets/core-DvlNQV3i.js","assets/mermaid.core-DmLiTJQf.js"])))=>i.map(i=>d[i]);
2
+ import{r as a,a as B,W as be,j as e,a7 as vn,A as ge,a8 as Fs,a9 as qt,X as Fe,l as Je,aa as Tt,L as Js,ab as aa,C as Qt,ac as ra,B as ft,f as rt,a2 as Os,ad as er,ae as tr,af as sr,ag as nr,ah as ar,ai as rr,aj as ir,ak as or,q as It,a5 as Us,al as yn,S as Yt,am as lr,G as cs,a3 as Jt,an as ia,P as hs,ao as oa,ap as la,aq as ca,ar as ce,as as cr,at as dr,m as St,au as da,av as ds,K as ua,U as Gt,aw as ha,ax as Ne,ay as ur,az as hr,aA as Ts,aB as us,aC as ma,T as ms,aD as Bs,aE as mr,aF as fr,$ as xr,c as Vs,aG as pe,aH as gr,aI as pr,aJ as br,aK as jr,aL as wr,aM as vr,aN as yr,aO as Nn,aP as kn,aQ as Nr,aR as kr,aS as Cr,d as fs,aT as Sr,aU as $r,aV as Tr,aW as fa,u as Ir,R as Rr,aX as Er,e as Mr,_ as Ar,b as Dr,aY as Pr,aZ as _r,a_ as Lr,J as Fr,a$ as Or,i as Ur,b0 as Br}from"./index-CrFWN6gV.js";import{readQueued as Vr,readQueuedId as zr,readQueuedAttachments as Hr,writeQueued as Wr,writeQueuedId as Gr,writeQueuedAttachments as Kr,newQueuedId as qr}from"./queued-CagZVfWU.js";import{C as Xs,d as Qr,D as Yr}from"./DeleteProjectDialog-BdoW_R7V.js";import{S as mt,C as Jr,E as Zs}from"./Surfaces-CM8msreu.js";import{t as dt,w as Xr}from"./lastTab-CU1zsF0j.js";import{D as Zr}from"./DiscoverView-CMj7eSnF.js";const ei=500,ti=9e4,Is="paddock:cancel",Cn="paddock:timeout";function si(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function ni(){const t=[{mimeType:"audio/webm;codecs=opus",ext:"webm"},{mimeType:"audio/webm",ext:"webm"},{mimeType:"audio/ogg;codecs=opus",ext:"ogg"},{mimeType:"audio/mp4",ext:"mp4"}],s=window.MediaRecorder;for(const n of t)if(typeof s.isTypeSupported!="function"||s.isTypeSupported(n.mimeType))return n;return{mimeType:"",ext:"webm"}}function ai({onText:t,timeoutMs:s=ti}){const[n,r]=a.useState("idle"),[i,o]=a.useState(null),[l,c]=a.useState(null),[m]=a.useState(si),u=a.useRef(null),p=a.useRef(null),g=a.useRef([]),h=a.useRef("webm"),b=a.useRef(null),N=a.useRef(null),f=a.useRef(!0);a.useEffect(()=>{f.current=!0;let $=!1;return B.transcriptionStatus().then(T=>{$||o(T.available)}).catch(()=>{$||o(!1)}),()=>{var T;$=!0,f.current=!1,(T=N.current)==null||T.abort(Is),d()}},[]);const d=()=>{var $;($=p.current)==null||$.getTracks().forEach(T=>T.stop()),p.current=null,u.current=null},v=a.useCallback(async()=>{if(!m||n==="recording"||n==="transcribing")return;c(null),b.current=null;let $;try{$=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(O){r("error"),c(li(O));return}p.current=$;const{mimeType:T,ext:y}=ni();h.current=y;const F=T?new MediaRecorder($,{mimeType:T}):new MediaRecorder($);g.current=[],F.ondataavailable=O=>{O.data&&O.data.size>0&&g.current.push(O.data)},F.onstop=()=>{d();const O=F.mimeType||T||"audio/webm",z=new Blob(g.current,{type:O});g.current=[],b.current=z,P(z)},u.current=F,F.start(),r("recording")},[m,n]),P=a.useCallback(async($,T=!1)=>{if($.size===0){b.current=null,f.current&&r("idle");return}f.current&&r("transcribing");const y=new AbortController;N.current=y;const F=setTimeout(()=>y.abort(Cn),s);try{const O=await B.transcribe($,`dictation.${h.current}`,y.signal);O.trim()&&t(O.trim()),b.current=null,f.current&&(c(null),r("idle"))}catch(O){if(y.signal.aborted&&y.signal.reason===Is){b.current=null,f.current&&(c(null),r("idle"));return}if(y.signal.aborted&&y.signal.reason===Cn){f.current&&(r("error"),c("Transcription timed out — try again."));return}if(ri(O)&&!T)return await oi(ei),P($,!0);f.current&&(r("error"),c(ii(O)))}finally{clearTimeout(F),N.current===y&&(N.current=null)}},[t,s]),E=a.useCallback(()=>{var $;($=N.current)==null||$.abort(Is)},[]),I=a.useCallback(()=>{const $=u.current;$&&$.state!=="inactive"&&$.stop()},[]),k=a.useCallback(()=>{n==="recording"?I():v()},[n,v,I]),S=a.useCallback(()=>{if(n==="recording"||n==="transcribing")return;const $=b.current;$?P($):v()},[n,P,v]),L=a.useCallback(()=>{b.current=null,c(null),r("idle")},[]);return{state:n,available:i,supported:m,error:l,start:v,stop:I,toggle:k,retry:S,dismiss:L,cancel:E}}function ri(t){return t instanceof be?t.status>=500:!0}function ii(t){return t instanceof be?t.status>=500?t.message||"Transcription service error — try again.":t.status===400?t.message||"Didn't catch any audio — try again.":t.message||"Transcription failed.":"Couldn't reach the transcription service — check your connection and retry."}function oi(t){return new Promise(s=>setTimeout(s,t))}function li(t){switch(t==null?void 0:t.name){case"NotAllowedError":case"SecurityError":return"Microphone permission denied.";case"NotFoundError":case"DevicesNotFoundError":return"No microphone found.";case"NotReadableError":return"Microphone is already in use.";default:return t instanceof Error?t.message:"Could not access the microphone."}}function ci({onText:t}){const{state:s,available:n,supported:r,error:i,toggle:o,retry:l,dismiss:c,cancel:m}=ai({onText:t});if(n!==!0)return null;const u=s==="recording",p=s==="transcribing",g=s==="error";if(!r)return e.jsx("button",{type:"button",disabled:!0,"aria-label":"Voice dictation unavailable",title:"Voice dictation needs a secure context (HTTPS or localhost). It's blocked over plain HTTP.",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-fg-subtle",children:e.jsx(vn,{width:18,height:18})});const h=u?"Stop recording":p?"Transcribing… — click to cancel":g?"Transcription failed — click to record again":"Record a voice message",b=()=>{p?m():o()};return e.jsxs("div",{className:"relative flex items-center",children:[g&&i&&e.jsxs("div",{role:"alert",className:"absolute bottom-full right-0 z-10 mb-2 flex max-w-[240px] items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-2.5 py-1.5 text-xs text-danger shadow-md",children:[e.jsx(ge,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:i}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 font-medium text-danger underline underline-offset-2 hover:opacity-80",children:"Retry"}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Dismiss error",className:"shrink-0 text-danger/70 hover:text-danger",children:"✕"})]}),e.jsxs("button",{type:"button",onClick:b,"aria-label":u?"Stop recording":p?"Cancel transcription":"Record a voice message","aria-pressed":u,title:h,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",u?"bg-danger-soft text-danger":p?"cursor-pointer text-accent can-hover:hover:bg-danger-soft can-hover:hover:text-danger":g?"bg-danger-soft text-danger":"text-fg-muted can-hover:hover:bg-surface-hover can-hover:hover:text-fg"].filter(Boolean).join(" "),children:[p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(di,{})}),e.jsx(Fs,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):u?e.jsx(Fs,{width:16,height:16}):e.jsx(vn,{width:18,height:18}),u&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function di(){return e.jsx("span",{className:"h-[18px] w-[18px] animate-spin rounded-full border-2 border-accent/25 border-t-accent",role:"status","aria-label":"Transcribing"})}const ui="paddock:chatModel:";function xa(t,s){return ui+(t??`new:${s}`)}function hi(t,s){try{const n=localStorage.getItem(xa(t,s));return n&&n.length>0?n:null}catch{return null}}function zs(t,s,n){try{localStorage.setItem(xa(t,s),n)}catch{}}const mi="paddock:draft:";function ga(t,s){return mi+(t??`new:${s}`)}function fi(t,s){try{return localStorage.getItem(ga(t,s))??""}catch{return""}}function xi(t,s,n){try{const r=ga(t,s);n.length>0?localStorage.setItem(r,n):localStorage.removeItem(r)}catch{}}const Sn="<paddock-attachments>",Hs="</paddock-attachments>",$n=`${Hs}
3
3
 
4
4
  `;function pa(t){return`/api/chat-files/${encodeURIComponent(t)}`}function gi(t){const s=t.indexOf(Sn);if(s===-1)return{attachments:[],text:t};const n=s+Sn.length,r=t.indexOf(Hs,n);if(r===-1)return{attachments:[],text:t};const i=t.slice(n,r),o=[];for(const m of i.split(`
5
5
  `)){const u=m.split(" ");if(u.length<3)continue;const[p,g,h]=u;!(p!=null&&p.trim())||!(h!=null&&h.trim())||o.push({id:p.trim(),kind:(g==null?void 0:g.trim())||"file",filename:h.trim()})}const l=t.slice(0,s),c=t.startsWith($n,r)?t.slice(r+$n.length):t.slice(r+Hs.length).replace(/^\n+/,"");return{attachments:o,text:l+c}}function pi(t){const s=t.slice(t.lastIndexOf("/")+1),n=s.lastIndexOf(".");return n>0?s.slice(n).toLowerCase():""}function ba(t){if(t===void 0||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const s=t/1024;if(s<1024)return`${s<10?s.toFixed(1):Math.round(s)} KB`;const n=s/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function bi(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function ji(t,s,n){const r=(s??"").trim().toLowerCase(),i=pi(n??"");for(const o of t){const l=o.trim().toLowerCase();if(l){if(l==="*"||l==="*/*")return!0;if(l.includes("/")){if(!r)continue;const[c,m]=l.split("/",2),[u,p]=r.split("/",2);if((c==="*"||c===u)&&(m==="*"||m===p))return!0}else if(l.startsWith(".")){if(i&&i===l)return!0}else if(i&&i===`.${l}`)return!0}}return!1}function wi({attachments:t}){return t.length===0?null:e.jsx("div",{className:"mb-1 flex flex-wrap justify-end gap-2","data-testid":"message-attachments",children:t.map(s=>e.jsx(vi,{attachment:s},s.id))})}function vi({attachment:t}){const s=pa(t.id);if(t.kind==="image")return e.jsx(Ni,{src:s,filename:t.filename});const n=ba(t.size);return e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",title:t.filename,"data-testid":"attachment-chip",className:"flex max-w-[14rem] items-center gap-2 rounded-xl bg-surface-raised px-3 py-2 text-left text-xs shadow-sm ring-1 ring-edge hover:ring-accent",children:[e.jsx(qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,n?` · ${n}`:""]})]})]})}function yi({attachment:t,onRemove:s}){const n=pa(t.id),[r,i]=a.useState(!1),o=t.kind==="image"&&!r,l=ba(t.size);return e.jsxs("span",{"data-testid":"attachment-tray-item",className:"group relative flex items-center gap-2 rounded-xl bg-surface-raised py-2 pl-2 pr-7 text-xs shadow-sm ring-1 ring-edge",children:[o?e.jsx("img",{src:n,alt:t.filename,onError:()=>i(!0),className:"h-9 w-9 shrink-0 rounded-md object-cover"}):e.jsx(qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"max-w-[10rem] truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,l?` · ${l}`:""]})]}),e.jsx("button",{type:"button",onClick:()=>s(t.id),"aria-label":`Remove ${t.filename}`,title:"Remove","data-testid":"attachment-remove",className:"absolute right-1 top-1 rounded-full p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg",children:e.jsx(Fe,{width:12,height:12})})]})}function Ni({src:t,filename:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(!1);return i?e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-raised px-3 py-2 text-xs text-danger shadow-sm ring-1 ring-edge",children:[e.jsx(ge,{width:14,height:14}),s]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>r(!0),title:s,"data-testid":"attachment-thumb",className:"block overflow-hidden rounded-xl ring-1 ring-edge hover:ring-accent",children:e.jsx("img",{src:t,alt:s,onError:()=>o(!0),className:"h-24 w-24 object-cover"})}),n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4",onClick:()=>r(!1),role:"dialog","aria-label":s,children:e.jsx("img",{src:t,alt:s,className:"max-h-full max-w-full rounded-lg object-contain shadow-2xl"})}):null]})}function ki(t){if(t.type==="event")return`the ${t.event} event`;if(t.type==="webhook")return`a webhook (${t.path??"reserved"})`;const s=t.cron??t.interval??"";return`a ${t.cron!==void 0?"cron":"interval"} schedule (${s})`}function Ci({trigger:t,projectSlug:s}){const n=t.allowedTools??[],r=n.length===0,i=r?t.type==="schedule"?"runs as Claude (full tools)":"no tools declared":`${n.length} tool${n.length===1?"":"s"} granted`,o=t.type==="schedule"?Je:Tt;return e.jsx("div",{"data-testid":"trigger-capability-banner",className:"sticky top-0 z-10 mb-4 rounded-xl border border-info-edge bg-info-soft/95 px-3 py-2.5 text-info shadow-sm backdrop-blur",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{"aria-hidden":!0,className:"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-lg bg-info-solid/15 text-info",children:e.jsx(o,{width:15,height:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm",children:[e.jsx("span",{className:"font-semibold",children:"Trigger agent"}),e.jsx("span",{"data-trigger-type":t.type,className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:t.type}),e.jsx("span",{className:"font-mono text-sm text-info",children:t.name}),!t.enabled&&e.jsx("span",{title:"This trigger is currently disabled — it won't fire again until re-enabled. This chat is one of its past runs.",className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:"disabled"})]}),e.jsxs("p",{className:"mt-0.5 text-xs text-info",children:["Fired by ",e.jsx("span",{className:"font-medium",children:ki(t)})," · ",i,". A reply you type here runs at this trigger's capability, not Claude's."]}),e.jsxs("details",{className:"group mt-1.5 text-xs",children:[e.jsxs("summary",{className:"inline-flex cursor-pointer select-none items-center gap-1 text-info hover:underline",children:[e.jsx("span",{className:"transition group-open:rotate-90","aria-hidden":!0,children:"▸"}),"Capabilities"]}),e.jsxs("div",{className:"mt-2 space-y-2 border-l-2 border-info-edge pl-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 font-medium",children:"Allowed tools"}),r?e.jsx("p",{className:"text-info",children:t.type==="schedule"?"None declared — this schedule runs as Claude with its full toolset.":"None declared. An empty list is not a restriction: no allow-list is passed to the runtime, so this agent falls back to Claude's default tools. Its prompt and max turns are the real bounds."}):e.jsx("ul",{className:"flex flex-wrap gap-1","data-testid":"trigger-allowed-tools",children:n.map(l=>e.jsx("li",{className:"rounded bg-info-solid/10 px-1.5 py-px font-mono text-2xs text-info",children:l},l))})]}),e.jsxs("dl",{className:"grid grid-cols-[auto,1fr] gap-x-3 gap-y-0.5 text-info",children:[t.permissionMode&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Permission mode"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.permissionMode})]}),t.model&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Model"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.model})]}),e.jsx("dt",{className:"font-medium",children:"Max turns"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.maxTurns}),e.jsx("dt",{className:"font-medium",children:"Agent"}),e.jsx("dd",{className:"truncate font-mono text-2xs",children:t.agentName})]}),e.jsx(Js,{to:`/projects/${encodeURIComponent(s)}/triggers`,className:"inline-flex items-center gap-1 font-medium text-info hover:underline",title:"Manage this project's triggers",children:"Edit trigger →"})]})]})]})]})})}const Si=new Set(["paddock","paddock_manage"]);function $i(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function Ti(t){if(!t.startsWith("mcp__"))return{isMcp:!1,server:"",isPaddock:!1,display:t,tool:t};const s=t.slice(5),n=s.indexOf("__"),r=n===-1?s:s.slice(0,n),i=n===-1?"":s.slice(n+2);return{isMcp:!0,server:r,isPaddock:Si.has(r),display:$i(i||r),tool:i}}const Tn="mcp__paddock_manage__",Vt=(t,s)=>typeof t=="number"&&Number.isFinite(t)?t:s,Nt=t=>{if(typeof t!="string")return;const s=t.trim();return s.length>0?s:void 0};function ja(t,s=80){var r;const n=((r=t.split(`
6
6
  `).find(i=>i.trim().length>0))==null?void 0:r.trim())??t.trim();return n.length>s?`${n.slice(0,s).trimEnd()}…`:n}function wa(t,s){return t||(s?ja(s):"untitled chat")}function Ii(t,s){if(!t.startsWith(Tn)||!s)return null;const n=t.slice(Tn.length);let r;try{r=JSON.parse(s)}catch{return null}if(!r||typeof r!="object")return null;switch(n){case"list_projects":{if(!Array.isArray(r.projects))return null;const i=r.projects;return{tool:n,count:Vt(r.count,i.length),projects:i}}case"list_chats":{if(!Array.isArray(r.chats))return null;const i=r.chats;return{tool:n,count:Vt(r.count,i.length),project:r.project??null,chats:i}}case"read_chat":{if(!Array.isArray(r.messages))return null;const i=r.messages;return{tool:n,project:String(r.project??""),sessionId:String(r.sessionId??""),total:Vt(r.total,i.length),returned:Vt(r.returned,i.length),messages:i}}case"create_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),name:Nt(r.name),prompt:Nt(r.prompt)}:null;case"send_message":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),prompt:Nt(r.prompt)}:null;case"fork_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),from:Nt(r.from),name:Nt(r.name),prompt:Nt(r.prompt)}:null;case"fork_chat_batch":{if(!Array.isArray(r.forks))return null;const i=r.forks;return{tool:n,count:Vt(r.count,i.length),source:String(r.source??""),forks:i}}default:return null}}function Ri(t){switch(t.tool){case"list_projects":return`${t.count} ${t.count===1?"project":"projects"}`;case"list_chats":return`${t.count} ${t.count===1?"chat":"chats"}`+(t.project?` in ${t.project}`:" across all projects");case"read_chat":return`${t.project} · ${t.returned}/${t.total} messages`;case"create_chat":case"fork_chat":return wa(t.name,t.prompt);case"send_message":return t.prompt?ja(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const va=a.createContext(null),Ei=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,Ws=t=>t.length>8?`${t.slice(0,8)}…`:t;function Ht({project:t,sessionId:s,label:n}){return e.jsxs(Js,{to:Ei(t,s),className:"inline-flex items-center gap-1 rounded-md bg-accent-soft px-2 py-0.5 font-mono text-2xs font-medium text-accent no-underline ring-1 ring-accent/20 transition-colors hover:bg-accent/20",title:`Open ${s}`,children:[e.jsx(aa,{width:10,height:10,className:"shrink-0"}),n??Ws(s)]})}const kt="border-t border-edge px-3 py-2.5",Ct="text-fg-muted";function In({children:t}){return e.jsx("span",{className:"rounded bg-surface-active px-1.5 py-0.5 text-3xs font-medium text-fg-muted",children:t})}function Rn({label:t,text:s}){return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"mb-1 text-3xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("div",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-surface-sunken px-2.5 py-1.5 text-2xs leading-relaxed text-fg-muted",children:s})]})}function Mi({chat:t}){return e.jsxs("li",{className:"flex items-center gap-2 py-1",children:[t.running?e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-success-solid",title:"running"}):e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-edge-strong"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg",children:t.name||"(untitled)"}),e.jsx(Ht,{project:t.project,sessionId:t.sessionId})]})}function Ai({data:t}){const s=a.useContext(va)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:kt,children:e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.projects.map(n=>e.jsxs("li",{className:"flex items-center gap-1.5 rounded-md bg-surface-sunken px-2 py-1",children:[e.jsx("span",{className:"text-2xs font-medium text-fg",children:n.name}),n.area&&e.jsx(In,{children:n.area}),n.status&&n.status!=="active"&&e.jsx(In,{children:n.status})]},n.slug))})});case"list_chats":return e.jsx("div",{className:kt,children:e.jsx("ul",{className:"max-h-72 divide-y divide-edge-subtle overflow-auto text-2xs",children:t.chats.map(n=>e.jsx(Mi,{chat:n},n.sessionId))})});case"read_chat":return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:[e.jsxs("span",{className:Ct,children:[t.returned," of ",t.total," messages"]}),e.jsx(Ht,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),e.jsx("ul",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.messages.map((n,r)=>e.jsxs("li",{className:"text-2xs leading-relaxed",children:[e.jsx("span",{className:`mr-1.5 font-mono text-3xs font-semibold uppercase ${n.role==="assistant"?"text-accent":"text-fg-subtle"}`,children:n.role}),e.jsx("span",{className:"whitespace-pre-wrap break-words text-fg-muted",children:n.text})]},r))})]});case"create_chat":case"fork_chat":{const n=t.tool==="create_chat"?"Created chat":"Forked chat",r=wa(t.name,t.prompt);return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:Ct,children:n}),e.jsx("span",{className:"font-medium text-fg",children:r}),e.jsxs("span",{className:Ct,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${Ct}`,children:["from ",Ws(t.from)]}),e.jsx(Ht,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(Rn,{label:"Kickoff",text:t.prompt})]})}case"send_message":return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:Ct,children:"Sent to"}),e.jsx("span",{className:"font-medium text-fg",children:t.project}),e.jsx(Ht,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(Rn,{label:"Message",text:t.prompt})]});case"fork_chat_batch":return e.jsxs("div",{className:kt,children:[e.jsx("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:e.jsxs("span",{className:Ct,children:[t.count," ",t.count===1?"fork":"forks"," from ",Ws(t.source)]})}),e.jsx("ol",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.forks.map((n,r)=>e.jsxs("li",{className:"flex items-start gap-2 rounded-md bg-surface-sunken px-2 py-1.5",children:[e.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-3xs font-semibold text-fg-subtle",children:r+1}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:n.prompt}),e.jsx(Ht,{project:s,sessionId:n.sessionId})]},n.sessionId))})]})}}const xs=new Set(["Task","Agent"]);function Di(t,s){return xs.has(t.toolName)&&s&&t.subagentDurationMs==null}const Pi="mcp__paddock__send_file",_i=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),Li=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function Fi(t){return t.background||t.toolName==="Monitor"||_i.has(t.toolName)?!0:Li.test(t.output??"")}function Oi(t){switch(t){case"completed":return"bg-success-soft text-success";case"killed":case"timed out":return"bg-warn-soft text-warn";case"running":case"persistent":return"bg-info-soft text-info";default:return"bg-surface-active text-fg-muted"}}function Ui(t){switch(t){case"list_projects":return Os;case"create_chat":return rt;case"fork_chat":case"fork_chat_batch":return ft;case"send_message":return ra;default:return Qt}}function ya(t){if(t.toolName!==Pi||!t.output)return null;let s;try{s=JSON.parse(t.output)}catch{return null}return!s||s.paddockSendFile!==1||typeof s.filename!="string"?null:{filename:s.filename,kind:s.kind,language:s.language,message:s.message,source:s.source,content:s.source==="inline"?s.content:void 0,rawUrl:s.source==="file"&&s.attachmentId?B.chatFileRawUrl(s.attachmentId):void 0}}function Bi(t){return t==="+"?"bg-success-soft text-success":t==="-"?"bg-danger-soft text-danger":"text-fg-muted"}function En(t){return t===void 0?"":String(t)}function Vi(t){switch(t){case"completed":case"done":return"bg-success-soft text-success";case"in_progress":return"bg-info-soft text-info";case"blocked":case"failed":case"cancelled":return"bg-danger-soft text-danger";default:return"bg-surface-active text-fg-muted"}}function zi(t){const s=[];if(t.kind==="grep")t.numLines!==void 0&&s.push(`${t.numLines} line${t.numLines===1?"":"s"}`),t.numFiles!==void 0&&s.push(`${t.numFiles} file${t.numFiles===1?"":"s"}`);else{const n=t.totalMatches??t.numFiles;n!==void 0&&s.push(`${n} match${n===1?"":"es"}`)}return s.length?(t.truncated?"≥":"")+s.join(" · "):null}function Hi(t){if(t.startLine===void 0||t.numLines===void 0)return null;const s=t.startLine+Math.max(0,t.numLines-1),n=t.totalLines!==void 0?` of ${t.totalLines}`:"";return`lines ${t.startLine}–${s}${n}`}let Wi=0;const Ye=()=>`t${++Wi}`;function Gi(t,s){t(n=>{const r=n[n.length-1];return r&&r.kind==="assistant"&&r.streaming?[...n.slice(0,-1),{...r,content:r.content+s}]:[...n,{kind:"assistant",id:Ye(),content:s,streaming:!0}]})}function Le(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function Mn(t){return t.some(s=>s.kind==="tool"&&s.tool.pending)?t.map(s=>s.kind==="tool"&&s.tool.pending?{...s,tool:{...s.tool,pending:!1}}:s):t}function Ki(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const o=ya(t.toolCall);return o?{kind:"file",id:s,file:o}:{kind:"tool",id:s,tool:t.toolCall}}if(t.role==="assistant")return{kind:"assistant",id:s,content:t.content,streaming:!1};if(er(t.content))return{kind:"compact",id:s,summary:t.content};const n=tr(t.content);if(n)return{kind:"command",id:s,command:n};if(sr(t.content))return{kind:"commandOutput",id:s,content:nr(t.content)??""};if(ar(t.content))return{kind:"commandOutput",id:s,content:""};if(rr(t.content))return{kind:"notification",id:s,summary:or(t.content),status:ir(t.content)};const{attachments:r,text:i}=gi(t.content);return{kind:"user",id:s,content:i,...t.sender?{sender:t.sender}:{},...r.length>0?{attachments:r}:{}}}const qi="/compact";function Qi(t){return t.kind==="commandOutput"&&t.content===""}function Yi(t){if(!t.some(n=>n.kind==="compact"))return t;const s=[];for(let n=0;n<t.length;n++){const r=t[n];if(r.kind!=="compact"){s.push(r);continue}let i=n+1;for(;i<t.length&&Qi(t[i]);)i++;const o=t[i];(o==null?void 0:o.kind)==="command"&&o.command===qi?(s.push(...t.slice(n+1,i+1),r),n=i):s.push(r)}return s}function Wt(t){const s=new Map,n=t.filter(r=>!r.bgConsumed).map(r=>{let i;if(r.uuid){const l=s.get(r.uuid)??0;s.set(r.uuid,l+1),i=l===0?r.uuid:`${r.uuid}#${l}`}else i=Ye();const o=Ki(r,i);return o.timestamp=r.timestamp,r.contextTokens!=null&&(o.contextTokens=r.contextTokens),o});return Yi(n)}function An(t){switch(t.kind){case"user":return`user:${t.content}`;case"command":return`command:${t.command}`;case"commandOutput":return`commandOutput:${t.content}`;case"compact":return`compact:${t.summary}`;case"notification":return`notification:${t.status??""}:${t.summary}`;case"notice":return`notice:${t.notice.kind}`;case"file":return`file:${t.file.filename}:${t.file.source}`;default:return`${t.kind}:${t.id}`}}function Dn(t,s){if(s.length===0)return t;if(t.length===0)return s;const n=[...t],r=new Map,i=new Map,o=[];n.forEach((l,c)=>{l.kind==="tool"&&l.tool.toolUseId?r.set(l.tool.toolUseId,c):l.kind==="assistant"?o.push(c):i.set(An(l),c)});for(const l of s){if(l.kind==="tool"&&l.tool.toolUseId){const m=r.get(l.tool.toolUseId);if(m===void 0){r.set(l.tool.toolUseId,n.length),n.push(l);continue}const u=n[m];if(u.kind!=="tool")continue;n[m]={...u,tool:{...u.tool,...l.tool,pending:l.tool.pending===!0}};continue}if(l.kind==="assistant"){const m=o.find(p=>{const g=n[p];return g.kind==="assistant"&&(g.content===l.content||g.content.startsWith(l.content)||l.content.startsWith(g.content))});if(m===void 0){o.push(n.length),n.push(l);continue}const u=n[m];if(u.kind!=="assistant")continue;l.content.length>u.content.length&&(n[m]={...u,content:l.content,streaming:l.streaming});continue}const c=An(l);i.has(c)||(i.set(c,n.length),n.push(l))}return n}const Na=a.createContext(null),ka=a.createContext(!1),en=a.createContext(null),Ca=a.createContext(null),Sa=a.createContext(null),tn=a.createContext(null),$a=a.createContext(null),Pn=4;function Ji(t){const[,s]=a.useState(0);a.useEffect(()=>{if(!t)return;const n=setInterval(()=>s(r=>r+1),1e3);return()=>clearInterval(n)},[t])}const ht=t=>t.role??t.type;function Xi({role:t}){const s="shrink-0 text-info";return t==="shell"?e.jsx(Jt,{width:12,height:12,className:s}):t==="workflow"?e.jsx(ia,{width:12,height:12,className:s}):t==="subagent"?e.jsx(Yt,{width:12,height:12,className:"shrink-0 text-accent"}):e.jsx(Je,{width:12,height:12,className:s})}function Rs(t){const s=ht(t);return s==="subagent"?t.agentType??"sub-agent":s==="workflow"?t.workflowName??"workflow":s==="monitor"?t.tool??"monitor":s}function Ta(t,s){var r,i;if(ht(t)!=="shell")return;const n=(r=t.command)==null?void 0:r.trim();if(n)return n;if(t.toolUseId)return((i=s==null?void 0:s.get(t.toolUseId))==null?void 0:i.trim())||void 0}function _n(t,s){const n=Ta(t,s);return n||(ht(t)==="shell"?t.description:t.lastToolName?t.lastToolName:t.description)}const Ia={subagent:"sub-agent",shell:"shell",monitor:"monitor",workflow:"workflow",task:"task"};function ls(t,s){const n=Ia[t];return n?`${s} ${n}${s===1?"":"s"}`:`${s} ${t}`}const Zi=t=>t==="subagent";function Ln({taskId:t,label:s,stopping:n,failed:r,onStop:i}){return!i||!t?null:e.jsx("button",{type:"button",onClick:i,disabled:n,"data-testid":"running-task-cancel","data-stop-state":r?"failed":n?"stopping":"idle",title:r?`Could not stop: ${r}`:`Stop ${s}`,"aria-label":r?`Retry stopping ${s}`:`Stop ${s}`,className:`mr-1.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors disabled:opacity-40 ${r?"text-danger can-hover:hover:bg-danger-soft":"text-fg-subtle can-hover:hover:bg-danger-soft can-hover:hover:text-danger"}`,children:e.jsx(Fe,{width:12,height:12})})}function eo({running:t,activity:s,tasks:n,commands:r,onReveal:i,onCancel:o,stopping:l,stopFailed:c}){var _;const m=new Set(t.map(j=>j.toolUseId)),u=n.filter(j=>!j.skipTranscript),p=u.filter(j=>!(j.toolUseId!=null&&m.has(j.toolUseId))),g=new Map(u.filter(j=>j.toolUseId!=null).map(j=>[j.toolUseId,j])),h=t.length+p.length,[b,N]=a.useState(()=>h>Pn),f=a.useRef(h===0);a.useLayoutEffect(()=>{h===0?f.current=!0:f.current&&(f.current=!1,N(h>Pn))},[h]);const d=a.useId(),[v,P]=a.useState(null);if(a.useEffect(()=>{h===0&&P(null)},[h]),Ji(h>0),h===0)return null;const E=new Map;t.length&&E.set("subagent",t.length);for(const j of p){const M=ht(j);E.set(M,(E.get(M)??0)+1)}const I=[...E.entries()].sort((j,M)=>M[1]-j[1]),k=I.length===1&&Ia[I[0][0]]?I[0][0]:null,S=k?`${ls(k,h)} running`:`${h} ${h===1?"thing":"things"} running`,L=p.reduce((j,M)=>j==null||M.startedAt>j.startedAt?M:j,null),$=t.length?t[t.length-1]:null,T=I.length>1?I.map(([j,M])=>ls(j,M)).join(" · "):L?_n(L,r)||S:$?((_=s.get($.toolUseId))==null?void 0:_.latestStep)??$.label:S,y=p.reduce((j,M)=>j==null||M.startedAt<j?M.startedAt:j,null),F=b?It:Us,O=u.filter(j=>j.stoppable!==!1&&!(l!=null&&l.has(j.id))).map(j=>j.id),z=(j,M,W)=>{if(!(!o||!j))return()=>{if(!Zi(M))return o(j);P({taskIds:[j],title:`Stop ${W}?`,body:"This sub-agent and everything it started will be stopped. Work already in progress is lost, and it cannot be resumed from where it got to.",confirmLabel:"Stop sub-agent"})}},X=()=>{const j=u.filter(M=>O.includes(M.id)&&ht(M)==="subagent").length;P({taskIds:O,title:"Stop all running work?",body:`${ls("task",O.length)} will be stopped`+(j>0?`, including ${ls("subagent",j)} and everything they started.`:".")+" Work already in progress is lost.",confirmLabel:"Stop all"})};return e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4","data-testid":"running-work",children:[e.jsxs("div",{className:"mb-2 overflow-hidden rounded-lg border border-accent-edge bg-accent-soft",children:[e.jsxs("div",{className:"flex items-center border-b border-accent/20",children:[e.jsxs("button",{type:"button",onClick:()=>N(j=>!j),"aria-expanded":!b,"aria-controls":d,"data-testid":"running-work-toggle",title:b?"Show each running item":"Collapse to a summary",className:"flex min-w-0 flex-1 items-center gap-1.5 px-3 py-1.5 text-left transition-colors can-hover:hover:bg-accent/10 focus-visible:focus-ring",children:[e.jsx("span",{className:"h-2.5 w-2.5 shrink-0 animate-spin rounded-full border-2 border-accent/30 border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 truncate text-3xs font-semibold uppercase tracking-wide text-accent",children:S}),e.jsx(F,{width:12,height:12,"aria-hidden":"true",className:"ml-auto shrink-0 text-accent/70"})]}),o&&h>1&&O.length>0&&e.jsx("button",{type:"button",onClick:X,"data-testid":"running-work-stop-all",title:"Stop every running task",className:"shrink-0 px-3 py-1.5 text-3xs font-semibold uppercase tracking-wide text-fg-subtle transition-colors can-hover:hover:text-danger focus-visible:focus-ring",children:"Stop all"})]}),b?e.jsxs("div",{id:d,className:"flex items-center gap-2 px-3 py-1.5","data-testid":"running-work-summary",children:[e.jsx(Je,{width:12,height:12,"aria-hidden":"true",className:"shrink-0 text-info"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-2xs text-info",title:T,children:T}),y!=null&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:["oldest ",yn(Date.now()-y)]})]}):e.jsxs("ul",{id:d,className:"divide-y divide-accent/15",children:[t.map(j=>{const M=s.get(j.toolUseId),W=g.get(j.toolUseId),q=W&&W.stoppable!==!1?W.id:void 0,ie=q!=null&&(l==null?void 0:l.has(q))===!0,G=q!=null?c==null?void 0:c.get(q):void 0,K=z(q,"subagent",j.label);return e.jsxs("li",{className:"flex items-center",children:[e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>i(j.toolUseId),title:"Show this sub-agent in the transcript",className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors can-hover:hover:bg-accent/10 ${K?"pr-1":"pr-3"} ${ie?"opacity-50":""}`,children:[e.jsx(Yt,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:j.label}),j.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted",children:j.description}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${G?"text-danger":"text-accent/90"}`,title:G??(M==null?void 0:M.latestStep),children:G?"can't stop":ie?"stopping…":(M==null?void 0:M.latestStep)??"starting…"}),M!=null&&M.stepCount>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[M.stepCount," step",M.stepCount===1?"":"s"]})]}),e.jsx(Ln,{taskId:q,label:j.label,stopping:ie,failed:G,onStop:K})]},j.toolUseId)}),p.map(j=>{const M=_n(j,r),W=Ta(j,r)?j.description.trim():"",q=j.toolUseId,ie=q?"button":"div",G=(l==null?void 0:l.has(j.id))===!0,K=c==null?void 0:c.get(j.id),w=j.stoppable!==!1?j.id:void 0,U=z(w,ht(j),Rs(j));return e.jsxs("li",{className:"flex items-center",children:[e.jsxs(ie,{...q?{type:"button",onClick:()=>i(q),title:"Show this task in the transcript"}:{},"data-testid":"running-task-row","data-task-type":j.type,className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors ${U?"pr-1":"pr-3"} ${q?"can-hover:hover:bg-accent/10":""} ${G?"opacity-50":""}`,children:[e.jsx(Xi,{role:ht(j)}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:Rs(j)}),W&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted","data-testid":"running-task-intent",children:W}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${K?"text-danger":"text-info"}`,"data-testid":"running-task-detail",title:K??M,children:K?"can't stop":G?"stopping…":M||"starting…"}),j.toolUses!=null&&j.toolUses>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[j.toolUses," step",j.toolUses===1?"":"s"]}),e.jsx("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle","data-testid":"running-task-elapsed",children:yn(Date.now()-j.startedAt)})]}),e.jsx(Ln,{taskId:w,label:Rs(j),stopping:G,failed:K,onStop:U})]},j.id)})]})]}),e.jsx(lr,{open:v!=null,onClose:()=>P(null),role:"alertdialog",size:"sm",title:(v==null?void 0:v.title)??"",description:v==null?void 0:v.body,footer:e.jsxs(e.Fragment,{children:[e.jsx(cs,{variant:"ghost",onClick:()=>P(null),children:"Keep running"}),e.jsx(cs,{variant:"danger","data-testid":"running-work-confirm-stop",onClick:()=>{const j=(v==null?void 0:v.taskIds)??[];P(null),j.forEach(M=>o==null?void 0:o(M))},children:(v==null?void 0:v.confirmLabel)??"Stop"})]})})]})}const to=2e3,so=6,Ra=new Set;function no(t){const s=t.toolCall;if(!s)return null;const n=xs.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,r=(s.description??s.inputSummary??"").trim();return r?`${n} ${r}`:n}function ao(t){var r,i;if(t.length===0)return;const s=Date.parse(((r=t[0])==null?void 0:r.timestamp)??""),n=Date.parse(((i=t[t.length-1])==null?void 0:i.timestamp)??"");if(!(!Number.isFinite(s)||!Number.isFinite(n)||n<s))return n-s}function ro(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function io(t,s,n,r=Ra){const[i,o]=a.useState(new Map),l=a.useRef(new Set),c=a.useRef(new Map),m=a.useRef(s);m.current=s;const u=a.useRef(n);u.current=n;const p=t.map(h=>h.toolUseId).sort().join(","),g=[...r].sort().join(",");return a.useEffect(()=>{const h=g?g.split(","):[];if(h.length!==0){for(const b of h)l.current.add(b);o(b=>{let N=null;for(const f of h){const d=b.get(f);d&&!d.running||(N??(N=new Map(b)),N.set(f,{...d,stepCount:(d==null?void 0:d.stepCount)??0,running:!1}))}return N??b})}},[g]),a.useEffect(()=>{const h=p?p.split(","):[];if(h.length===0||!m.current)return;let b=!1,N;const f=async()=>{const d=m.current;if(!d)return;const v=h.filter(E=>!l.current.has(E));if(v.length===0)return;const P=await Promise.all(v.map(E=>d(E).then(I=>({id:E,messages:I})).catch(()=>null)));b||(o(E=>{const I=new Map(E);for(const k of P){if(!k||l.current.has(k.id))continue;const S=ro(k.messages),L=c.current.get(k.id),$=L&&L.sig===S?L.ticks+1:0;c.current.set(k.id,{sig:S,ticks:$});const T=!u.current&&$>=so;T&&l.current.add(k.id);const y=k.messages.map(no).filter(F=>!!F);I.set(k.id,{latestStep:y[y.length-1],stepCount:y.length,messages:k.messages,elapsedMs:ao(k.messages),running:!T})}return I}),b||(N=setTimeout(f,to)))};return f(),()=>{b=!0,N&&clearTimeout(N)}},[p]),i}function oo(t){const[s,n]=a.useState(Ra),r=a.useRef(new Set),i=t.map(o=>o.toolUseId).filter(o=>!!o).sort().join(",");return a.useEffect(()=>{const o=new Set(i?i.split(","):[]);for(const l of o)r.current.add(l);n(l=>{let c=null;for(const m of r.current)o.has(m)||l.has(m)||(c??(c=new Set(l)),c.add(m));return c??l})},[i]),s}function lo(t){return a.useMemo(()=>{const s=[];for(const n of t){const r=n.kind==="tool"?n.tool:void 0;r!=null&&r.toolUseId&&xs.has(r.toolName)&&r.hasSubagent&&r.subagentDurationMs==null&&s.push({toolUseId:r.toolUseId,label:r.subagentType??r.toolName,description:r.description})}return s},[t])}function co(t){return a.useMemo(()=>{var n;const s=new Map;for(const r of t){const i=r.kind==="tool"?r.tool:void 0;if(!(i!=null&&i.toolUseId)||i.toolName!=="Bash"&&i.toolName!=="bash")continue;const o=(n=i.inputSummary)==null?void 0:n.trim();o&&s.set(i.toolUseId,o)}return s},[t])}function uo({checked:t,available:s,onChange:n}){return e.jsxs("label",{className:`group mb-2 inline-flex w-fit items-center gap-2 rounded-lg px-1 py-0.5 text-xs ${s?"cursor-pointer text-fg-muted":"cursor-not-allowed text-fg-subtle"}`,title:s?"Inject this project's curated OVERVIEW.md (current state) and CHANGELOG.md (history) as context on the first message of this new chat, so the agent starts already knowing the project's state and narrative.":"No project overview yet — a sweep writes OVERVIEW.md after some activity. The agent will still see the project's files.",children:[e.jsx("input",{type:"checkbox",checked:t,disabled:!s,onChange:r=>n(r.target.checked),className:"h-3.5 w-3.5 rounded border-edge-strong accent-[var(--accent-solid)] focus:ring-accent/30 disabled:opacity-50"}),e.jsx("span",{className:"font-medium",children:"Preload project context"}),e.jsx("span",{className:"hidden text-fg-subtle transition-opacity sm:inline",children:s?"(injects OVERVIEW.md + CHANGELOG.md)":"(no overview yet)"})]})}function ho({models:t,model:s,onSelectModel:n,usage:r,sessionUsage:i,forkParent:o,onOpenForkParent:l}){return e.jsxs("div",{className:"mb-2 flex items-center gap-3 px-1 text-2xs text-fg-subtle",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-fg-muted",children:"Model"}),e.jsxs("select",{value:s??"",onChange:c=>n(c.target.value),disabled:t.length===0,title:"Model for this chat (sent on every message; remembered per chat)",className:"rounded-md border border-edge-strong bg-surface-raised px-1.5 py-0.5 text-2xs text-fg-muted outline-none focus:border-accent focus:ring-1 focus:ring-accent/20 disabled:opacity-50",children:[s&&!t.some(c=>c.id===s)&&e.jsx("option",{value:s,children:s}),t.map(c=>e.jsx("option",{value:c.id,children:c.label},c.id))]})]}),e.jsx(mo,{usage:r}),e.jsx(fo,{usage:i}),o&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(ft,{width:11,height:11,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"shrink-0",children:"Fork of"}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(o.sessionId),title:`Open the chat this was forked from: ${o.name}`,className:"truncate font-medium text-accent underline-offset-2 hover:underline",children:o.name})]})]})}function mo({usage:t}){if(!t||t.contextLimit<=0)return e.jsx("span",{className:"text-fg-subtle",children:"context: —"});const s=Math.min(100,Math.max(0,t.contextTokens/t.contextLimit*100)),n=s>=80,r=Math.round(t.contextTokens/1e3),i=Math.round(t.contextLimit/1e3);return e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",title:`Context window used as of the last completed turn (${t.contextTokens.toLocaleString()} / ${t.contextLimit.toLocaleString()} tokens)`,children:[e.jsx("span",{className:"h-1 w-20 overflow-hidden rounded-full bg-surface-active",children:e.jsx("span",{className:`motion-base block h-full rounded-full transition-[width,background-color] ${n?"bg-warn-solid":"bg-accent-solid"}`,style:{width:`${s}%`}})}),e.jsxs("span",{className:n?"text-warn":void 0,children:[r,"k / ",i,"k (",Math.round(s),"%)"]})]})}function fo({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${oa(t.costUsd)}`:la(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${ca(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const Fn=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function xo(){const[t,s]=a.useState(0);return a.useEffect(()=>{const n=setInterval(()=>s(r=>(r+1)%Fn.length),2600);return()=>clearInterval(n)},[]),e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-edge bg-surface-active px-3 py-1 text-xs text-fg-muted",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-accent-solid","aria-hidden":"true"}),e.jsxs("span",{children:[Fn[t],"…"]})]})})}function go({text:t,attachments:s=[],onEdit:n,onClear:r}){const i=t.split(`
7
- `,1)[0],o=t.length-i.length;return e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-accent-edge bg-accent-soft px-3 py-1.5 text-xs",children:[e.jsx(Je,{width:13,height:13,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 font-semibold uppercase tracking-wide text-accent",children:"queued"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-muted",title:t||s.map(l=>l.filename).join(", "),children:i||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),i&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(l=>l.filename).join(", "),children:["📎 ",s.length]}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:n,title:"Edit this message (cancels the pending auto-send)",className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active",children:[e.jsx(hs,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:r,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-fg-muted hover:bg-surface-active hover:text-danger",children:e.jsx(Fe,{width:12,height:12})})]})]})})}function po({state:t}){const s={open:{c:"bg-success-solid",t:"connected"},connecting:{c:"bg-warn-solid animate-pulse",t:"connecting"},closed:{c:"bg-danger-solid",t:"offline"}}[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${s.c}`}),s.t]})}const bo=a.lazy(()=>ce(()=>import("./MarkdownRenderer-D-7rJ2MA.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]))),Xt=a.memo(function({children:s,mermaid:n=!1}){return e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(bo,{mermaid:n,children:s})})}),jo={tsx:"typescript",jsx:"javascript",html:"xml"};function wo(t){if(!t)return;const s=t.toLowerCase();return jo[s]??s}let Es=null;async function vo(){return Es||(Es=(async()=>{const{default:t}=await ce(async()=>{const{default:S}=await import("./core-DmcZcbit.js");return{default:S}},__vite__mapDeps([8,1,2])),[s,n,r,i,o,l,c,m,u,p,g,h,b,N,f,d,v,P,E,I,k]=await Promise.all([ce(()=>import("./typescript-C2FFdlUC.js"),[]),ce(()=>import("./javascript-BKRaQes9.js"),[]),ce(()=>import("./python-kSlZHhJb.js"),[]),ce(()=>import("./ruby-7T4ktxyv.js"),[]),ce(()=>import("./go-BPx_y7j8.js"),[]),ce(()=>import("./rust-HC3MBUhY.js"),[]),ce(()=>import("./java-B5VKqtH2.js"),[]),ce(()=>import("./c-D2F1sQUL.js"),[]),ce(()=>import("./cpp-Bm3ii6kY.js"),[]),ce(()=>import("./csharp-BNpuYZMG.js"),[]),ce(()=>import("./php-CRdd4dfS.js"),[]),ce(()=>import("./swift-Dn8kKO_1.js"),[]),ce(()=>import("./kotlin-Cw-eF_bm.js"),[]),ce(()=>import("./bash-I8pq0VWm.js"),[]),ce(()=>import("./sql-BC88IN-V.js"),[]),ce(()=>import("./json-DIYVocXf.js"),[]),ce(()=>import("./yaml-drsDnIKT.js"),[]),ce(()=>import("./ini-B3BVgEsG.js"),[]),ce(()=>import("./css-DazXZka4.js"),[]),ce(()=>import("./scss-DZLA7YXz.js"),[]),ce(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",i.default),t.registerLanguage("go",o.default),t.registerLanguage("rust",l.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",u.default),t.registerLanguage("csharp",p.default),t.registerLanguage("php",g.default),t.registerLanguage("swift",h.default),t.registerLanguage("kotlin",b.default),t.registerLanguage("bash",N.default),t.registerLanguage("sql",f.default),t.registerLanguage("json",d.default),t.registerLanguage("yaml",v.default),t.registerLanguage("toml",P.default),t.registerLanguage("css",E.default),t.registerLanguage("scss",I.default),t.registerLanguage("xml",k.default),t})()),Es}function yo({code:t,language:s}){const[n,r]=a.useState(null),i=wo(s);a.useEffect(()=>{if(!i){r(null);return}let l=!1;return r(null),(async()=>{try{const c=await vo();if(l||!c.getLanguage(i))return;const{value:m}=c.highlight(t,{language:i});l||r(m)}catch{}})(),()=>{l=!0}},[t,i]);const o="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg";return n!==null?e.jsx("pre",{className:o,children:e.jsx("code",{className:`hljs language-${i}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:o,children:e.jsx("code",{children:t})})}let Ms=null;function No(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function ko(){return Ms||(Ms=ce(()=>import("./mermaid.core-DAaQ0A8U.js").then(t=>t.bm),__vite__mapDeps([9,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:No()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),Ms}function Co({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[i,o]=a.useState(null);return a.useEffect(()=>{let l=!1;return o(null),(async()=>{try{const c=await ko();await c.parse(t);const{svg:m,bindFunctions:u}=await c.render(n+"-svg",t);if(l||!r.current)return;r.current.innerHTML=m,u==null||u(r.current)}catch(c){if(l)return;o(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{l=!0}},[t,n]),i?e.jsxs("div",{className:"my-3 rounded-lg border border-warn-edge bg-warn-soft p-3 text-xs",children:[e.jsx("p",{className:"font-semibold text-warn",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-warn",children:i}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-surface-sunken p-2 font-mono text-2xs text-fg-muted",children:t})]}):e.jsx("div",{ref:r,"data-testid":"mermaid",className:"mermaid-host my-3 flex justify-center overflow-x-auto rounded-lg border border-edge bg-surface-raised p-3"})}const So="paddock:itemHeight:";function sn(t){return So+t}function On(t){try{const s=localStorage.getItem(sn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function $o(t,s){try{const n=sn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function To(t){try{localStorage.removeItem(sn(t))}catch{}}function Io({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const i=a.useRef(null),[o,l]=a.useState(0),[c,m]=a.useState(()=>On(t));a.useEffect(()=>{m(On(t))},[t]),a.useEffect(()=>{if(!i.current)return;const b=()=>{var f;return l(((f=i.current)==null?void 0:f.scrollHeight)||0)};if(b(),typeof ResizeObserver>"u")return;const N=new ResizeObserver(b);return N.observe(i.current),()=>N.disconnect()},[s]);const u=o>0,p=u?o:Number.POSITIVE_INFINITY;let g=!1,h=0;return c!=null?(g=!0,h=Ea(c,r,p)):u&&o>n&&(g=!0,h=n),e.jsxs("div",{className:g?"group relative":void 0,style:g?{height:h}:void 0,children:[e.jsx("div",{className:g?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:i,children:s})}),g?e.jsx(Ro,{appliedHeight:h,onResize:b=>m(b),onCommit:b=>$o(t,b),onReset:()=>{To(t),m(null)},minHeight:r,maxHeight:p}):null]})}function Ro({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:i,maxHeight:o}){const l=a.useRef(null),c=a.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:u=>{l.current={startY:u.clientY,startHeight:t},u.currentTarget.setPointerCapture(u.pointerId)},onPointerMove:u=>{if(!l.current)return;const p=Un(l.current.startHeight,u.clientY-l.current.startY,i,o);s(p)},onPointerUp:u=>{if(l.current){l.current=null;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const p=u.key==="ArrowDown"?m:-m,g=Un(t,p,i,o);s(g),n(g)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-edge-subtle bg-surface-sunken opacity-60 transition hover:bg-surface-hover hover:opacity-100",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-edge-strong group-hover:bg-fg-subtle"})})}function Un(t,s,n,r){return Ea(t+s,n,r)}function Ea(t,s,n){return Math.min(Math.max(t,s),n)}function Ma({src:t,filename:s,message:n}){const[r,i]=a.useState(!1),[o,l]=a.useState(!1),c="repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||r?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsxs("div",{className:"group relative flex items-center justify-center overflow-auto p-4",style:{background:c},children:[e.jsx("img",{src:t,alt:s,onError:()=>i(!0),onClick:()=>l(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),l(!0))},role:"button",tabIndex:0,"aria-label":`Open ${s} full screen`,className:"max-h-[480px] max-w-full cursor-zoom-in object-contain shadow-sm"}),e.jsx(Aa,{src:t,filename:s,onMaximize:()=>l(!0)}),o?e.jsx(Eo,{src:t,filename:s,message:n,onClose:()=>l(!1)}):null]})}function Aa({src:t,filename:s,onMaximize:n}){const r="pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/55 text-white shadow-sm transition-colors hover:bg-black/75 focus-visible:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{className:"pointer-events-none absolute bottom-2 right-2 z-10 flex items-center gap-1.5 opacity-100 transition-opacity can-hover:opacity-0 can-hover:group-hover:opacity-100 can-hover:group-focus-within:opacity-100",children:[e.jsx("a",{href:t,download:s,className:r,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(Mo,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:r,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx(Ao,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(Do,{})}):null]})}function Eo({src:t,filename:s,message:n,onClose:r}){const i=a.useRef(null);return a.useEffect(()=>{var c;const o=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",o);const l=document.body.style.overflow;return document.body.style.overflow="hidden",(c=i.current)==null||c.focus(),()=>{document.removeEventListener("keydown",o),document.body.style.overflow=l}},[r]),cr.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:r,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-4 bg-overlay-strong p-6",children:[e.jsx("button",{ref:i,type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",children:e.jsx(Po,{})}),e.jsx("img",{src:t,alt:s,onClick:o=>o.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:o=>o.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),n?e.jsx("div",{className:"mt-1",children:n}):null]})]}),document.body)}function gs({children:t}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}function Mo(){return e.jsxs(gs,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function Ao(){return e.jsxs(gs,{children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function Do(){return e.jsx(gs,{children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}function Po(){return e.jsx(gs,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function nn({src:t,filename:s,className:n="h-[600px] w-full"}){return t?e.jsxs("div",{className:`group relative ${n}`,children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-full w-full bg-surface-sunken",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-fg-muted",children:[e.jsx(qt,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-fg",children:s}),e.jsx("span",{className:"text-xs text-fg-muted",children:"This browser can’t show the PDF inline."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:"rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-surface motion-fast transition-colors hover:bg-fg-muted",children:"Open in new tab"}),e.jsx("a",{href:t,download:s,className:"rounded-md px-3 py-1.5 text-xs font-medium text-fg-muted ring-1 ring-edge-strong hover:bg-surface-hover",children:"Download"})]})]})}),e.jsx(Aa,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function _o({file:t}){const[s,n]=a.useState(!0),r=Lo(t);return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"w-full max-w-[92%] overflow-hidden rounded-2xl rounded-bl-md bg-surface-raised shadow-sm ring-1 ring-edge",children:[e.jsxs("button",{type:"button",onClick:()=>n(i=>!i),"aria-expanded":s,className:"flex w-full items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-left text-2xs text-fg-muted",children:[e.jsx(Vo,{open:s}),e.jsx(zo,{}),e.jsx("span",{className:"font-mono text-fg-muted",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-3xs text-fg-subtle",children:t.language??t.kind})]}),t.message?e.jsx("div",{className:"border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted",children:t.message}):null,s?e.jsx(Oo,{file:t,itemId:r}):null]})})}function Lo(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${Fo(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function Fo(t){let s=5381;for(let n=0;n<t.length;n++)s=(s<<5)+s+t.charCodeAt(n)|0;return(s>>>0).toString(36)}function Oo({file:t,itemId:s}){return t.kind==="image"?e.jsx(Ma,{src:t.rawUrl,filename:t.filename,message:t.message}):t.kind==="video"?e.jsx(Bo,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(nn,{src:t.rawUrl,filename:t.filename}):t.source==="inline"?e.jsx(Da,{kind:t.kind,text:t.content??"",language:t.language,itemId:s}):e.jsx(Uo,{url:t.rawUrl,kind:t.kind,language:t.language,itemId:s})}function Da({kind:t,text:s,language:n,itemId:r}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:"html-preview min-h-[360px] w-full"}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(Co,{code:s})}):t==="markdown"?e.jsx(As,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Xt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(As,{itemId:r,children:e.jsx(yo,{code:s,language:n})}):e.jsx(As,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg",children:s})})}function As({itemId:t,children:s}){return t?e.jsx(Io,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function Uo({url:t,kind:s,language:n,itemId:r}){const[i,o]=a.useState(null);return a.useEffect(()=>{if(!t){o({error:!0});return}let l=!1;return o(null),fetch(t).then(c=>c.ok?c.text():Promise.reject(new Error(String(c.status)))).then(c=>!l&&o({text:c})).catch(()=>!l&&o({error:!0})),()=>{l=!0}},[t]),i===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in i?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Da,{kind:s,text:i.text,language:n,itemId:r})}function Bo({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-surface-sunken p-4",children:e.jsx("video",{src:t,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[480px] w-full rounded-sm shadow-sm",children:e.jsxs("p",{className:"p-4 text-sm text-fg-muted",children:["Your browser can’t play this video."," ",e.jsxs("a",{href:t,download:s,className:"underline",children:["Download ",s]})]})})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function Vo({open:t}){return e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-subtle transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function zo(){return e.jsxs("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("path",{d:"M14 2v6h6"})]})}const an=a.memo(function({turn:s}){return s.kind==="user"?e.jsxs("div",{className:"flex animate-fade-in flex-col items-end",children:[s.sender?e.jsx(Qo,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(wi,{attachments:s.attachments}):null,s.content?e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-accent-solid px-4 py-2.5 text-sm text-accent-fg shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(_o,{file:s.file}):s.kind==="tool"?e.jsx(Xo,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-surface-active px-2.5 py-0.5 font-mono text-xs text-fg-muted ring-1 ring-edge",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(Ko,{content:s.content}):null:s.kind==="compact"?e.jsx(qo,{summary:s.summary}):s.kind==="notice"?e.jsx(Jo,{notice:s.notice}):s.kind==="notification"?dr(s.status)?e.jsx(Yo,{summary:s.summary}):e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"max-w-[85%] truncate rounded-full bg-surface-sunken px-2.5 py-0.5 text-xs italic text-fg-muted ring-1 ring-edge",title:s.summary,children:s.summary})}):e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsx("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-raised px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(Xt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"})]})})})}),Ho=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function Wo({turn:t}){const s=a.useContext($a);return!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&Ho.test(t.id)?e.jsx(Go,{turn:t,actions:s}):e.jsx(an,{turn:t})}function Go({turn:t,actions:s}){var v;const n=t.id.split("#")[0],r=t.id===n,i=s.linkTo(n),o=a.useRef(null),[l,c]=a.useState(!1),[m,u]=a.useState(!1),p=r&&((v=s.focused)==null?void 0:v.uuid)===n?s.focused.nonce:null;a.useEffect(()=>{var E;if(p==null)return;(E=o.current)==null||E.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const P=setTimeout(()=>u(!1),3200);return()=>clearTimeout(P)},[p]),a.useEffect(()=>{if(!l)return;const P=setTimeout(()=>c(!1),1600);return()=>clearTimeout(P)},[l]);const g=P=>{var E;P.metaKey||P.ctrlKey||P.shiftKey||P.altKey||P.button!==0||(P.preventDefault(),(E=navigator.clipboard)==null||E.writeText(i).then(()=>c(!0)).catch(()=>c(!1)))},h=t.contextTokens,b=s.contextLimit,N=h!=null&&b?Math.min(100,Math.round(h/b*100)):null,f="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",d=`${f} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{ref:o,id:r?da(n):void 0,className:`group relative rounded-lg ${m?"reveal-flash":""}`,children:[e.jsxs("div",{className:"pointer-events-none absolute -top-3 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",children:[e.jsx("a",{href:i,onClick:g,title:`Copy a link to this message · ${new Date(t.timestamp).toLocaleString()}`,"aria-label":`Copy a link to this message (${St(t.timestamp)})`,className:`${f} gap-1 px-2 py-0.5 text-2xs text-fg-muted transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:l?e.jsx("span",{className:"text-accent",children:"Link copied"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:St(t.timestamp)}),h!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",la(h),N!=null?` · ${N}%`:""]}):null]})}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${d} hover:text-accent`,children:e.jsx(ft,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${d} hover:text-danger`,children:e.jsx(Je,{width:13,height:13})})]}),e.jsx(an,{turn:t})]})}function Ee({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function Ko({content:t}){return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-sunken px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-2xs italic text-fg-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(Xt,{children:t})]})})}function qo({summary:t}){return e.jsx("div",{className:"animate-fade-in py-1",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 text-xs text-fg-muted",children:[e.jsx("span",{className:"h-px flex-1 bg-edge"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-edge"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:t})]})})}function Qo({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-2xs italic text-fg-muted";if(t.kind==="schedule")return e.jsxs("div",{className:s,"data-sender":"schedule",children:[e.jsx("span",{"aria-hidden":!0,children:"⏰"}),e.jsxs("span",{children:["scheduled by ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="hook")return e.jsxs("div",{className:s,"data-sender":"hook",children:[e.jsx("span",{"aria-hidden":!0,children:"⚡"}),e.jsxs("span",{children:["triggered by hook ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="recovery")return e.jsxs("div",{className:s,"data-sender":"recovery",children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:"continued after a background task was terminated"})]});if(t.kind==="agent")return e.jsxs("div",{className:s,"data-sender":"agent",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsx("span",{children:"sent by an agent"})]});const n=((r=t.name)==null?void 0:r.trim())||t.sessionId.slice(0,8);return e.jsxs("div",{className:s,"data-sender":"chat",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsxs("span",{children:["sent by"," ",e.jsx(Js,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${n} in ${t.project}`,children:n})]})]})}function Yo({summary:t}){const s=a.useContext(tn),n=!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy);return e.jsx("div",{className:"flex animate-fade-in justify-center","data-recovery":"killed-task",children:e.jsxs("div",{className:"flex max-w-[90%] flex-col gap-1.5 rounded-lg border border-warn-edge bg-warn-soft px-3 py-2 text-xs text-warn",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:"⚠"}),e.jsxs("span",{className:"leading-snug",children:["A background task was terminated at the turn boundary — Claude is idle and will not continue on its own.",e.jsx("span",{className:"mt-0.5 block text-2xs text-warn",children:t})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-recovery-action":"continue",className:"motion-fast rounded-md bg-warn-solid px-2.5 py-1 text-2xs font-medium text-warn-fg shadow-sm transition-[filter,box-shadow,opacity] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50",children:r?"Continuing…":"Continue"})})]})})}function Jo({notice:t}){const s=a.useContext(tn),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),i=t.kind==="error",o=i?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",l=i?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=i?"text-danger":"text-warn",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${o}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:i?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-2xs ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),i&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-2xs ${c}`,children:t.detail})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-notice-action":"retry",className:`motion-fast rounded-md px-2.5 py-1 text-2xs font-medium shadow-sm transition-[filter,box-shadow,opacity] disabled:cursor-not-allowed disabled:opacity-50 ${l}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Xo({tool:t}){var w,U;const s=Ti(t.toolName),n=Ii(t.toolName,t.output),r=s.isPaddock?Ui(s.tool):null,i=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[o,l]=a.useState(i),c=a.useContext(Sa),m=a.useContext(Ca),u=a.useRef(null),[p,g]=a.useState(!1),h=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;a.useEffect(()=>{var C;if(h==null)return;l(!0),(C=u.current)==null||C.scrollIntoView({behavior:"smooth",block:"center"}),g(!0);const Z=setTimeout(()=>g(!1),3200);return()=>clearTimeout(Z)},[h]);const b=a.useContext(ka),N=a.useContext(en),f=!!t.pending,d=xs.has(t.toolName),v=t.toolUseId?N==null?void 0:N.get(t.toolUseId):void 0,P=d?ds(t.subagentDurationMs??(v==null?void 0:v.elapsedMs)):ds(t.durationMs),E=t.subagentCostUsd!=null?`~${oa(t.subagentCostUsd)}`:null,I=!d&&Fi(t),k=t.monitorEvents??[],S=t.editDiff,L=!!S,$=t.toolName==="Read"?t.readInfo:void 0,T=$!=null&&$.isImage&&$.projectRelPath&&c?c($.projectRelPath):null,y=t.toolName==="Bash"?t.bashDetails:void 0,F=t.searchInfo,O=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,z=t.toolName==="TaskCreate"?t.taskCreate:void 0,X=!!(y&&y.stderr),_=F?zi(F):null,j=$?Hi($):null,M=v!=null?v.running:Di(t,b),W=!!(d&&t.hasSubagent&&t.toolUseId),q=M&&t.toolUseId?(w=N==null?void 0:N.get(t.toolUseId))==null?void 0:w.latestStep:void 0,ie=d?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,G=d?q??t.description:n?Ri(n):L?((U=S.filePath)==null?void 0:U.split("/").pop())??S.filePath:$?$.basename??$.filePath??t.inputSummary:z?z.subject:t.inputSummary,K=($==null?void 0:$.filePath)??(z==null?void 0:z.description)??(q?t.description:void 0)??G??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:u,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${p?"reveal-flash ":""}${t.isError?"border-danger-edge bg-danger-soft":d?"border-accent-edge bg-accent-soft":I?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>l(Z=>!Z),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(It,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${o?"rotate-90":""}`}),d?e.jsx(Yt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):I?e.jsx(Je,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-info"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):L?e.jsx(hs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):$?e.jsx(qt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):F?e.jsx(ua,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):O||z?e.jsx(Gt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(ha,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-fg",children:ie}),d&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),I&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-info-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-info",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:n&&"project"in n&&n.project?n.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-fg-muted",children:"MCP"}),O?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[O.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",O.taskId]}),O.from&&O.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Bn,{status:O.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(Bn,{status:O.to})]}):O.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:O.updatedFields.join(", ")})]}):G&&e.jsx("span",{className:`min-w-0 truncate font-mono ${q?"text-accent":"text-fg-muted"}`,title:K,children:G}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-danger-soft px-1.5 py-0.5 text-3xs font-semibold text-danger",children:"error"}),f||M?e.jsxs("span",{className:"flex items-center gap-1.5 text-accent",title:"Sub-agent is running",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-accent-edge border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-3xs font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[I&&k.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[k.length," event",k.length===1?"":"s"]}),I&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${Oi(t.taskStatus)}`,children:t.taskStatus}),L&&(S.additions>0||S.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[S.additions>0&&e.jsxs("span",{className:"text-success",children:["+",S.additions]}),S.additions>0&&S.deletions>0&&" ",S.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",S.deletions]})]}),j&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:j}),_&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:_}),(y==null?void 0:y.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 font-mono text-3xs text-fg-muted",children:y.gitHint}),(y==null?void 0:y.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-warn-soft px-1.5 py-0.5 text-3xs font-semibold text-warn",children:"interrupted"}),(y==null?void 0:y.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:y.returnCodeInterpretation}),P&&e.jsx("span",{className:"text-fg-subtle tabular",children:P}),E&&e.jsx("span",{className:"text-fg-subtle tabular",children:E})]})]})]}),o&&(W?e.jsx(sl,{toolUseId:t.toolUseId,live:M}):I&&k.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:k.map((Z,C)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-info-edge px-3 py-1.5 font-mono text-2xs leading-relaxed text-fg-muted last:border-b-0",children:Z},C))}):n?e.jsx(Ai,{data:n}):L?e.jsx(Zo,{diff:S}):T?e.jsx("div",{className:"border-t border-edge",children:e.jsx(Ma,{src:T,filename:($==null?void 0:$.basename)??"image"})}):X?e.jsx(el,{bash:y}):z&&z.description?e.jsx(tl,{info:z}):e.jsxs("div",{className:"border-t border-edge",children:[I&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-edge bg-info-soft px-3 py-2 text-2xs font-medium text-fg",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:f?"Running…":t.output||"(no output)"})]}))]})})}function Zo({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-edge bg-surface-sunken font-mono text-2xs leading-relaxed",children:[t.hunks.map((s,n)=>e.jsxs("div",{className:n>0?"border-t border-edge":"",children:[e.jsxs("div",{className:"bg-surface-active px-3 py-1 font-mono text-3xs font-semibold text-lineage",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,i)=>e.jsxs("div",{className:`flex ${Bi(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:En(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:En(r.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:r.t===" "?"":r.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:r.text||" "})]},i))]},n)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-2xs italic text-fg-subtle",children:"… diff truncated (see the file for the full change)"})]})}function Bn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${Vi(t)}`,children:t})}function el({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-edge",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-danger-edge bg-danger-soft px-3 py-2 font-mono text-2xs leading-relaxed text-danger first:border-t-0",children:t.stderr})]})}function tl({info:t}){return e.jsxs("div",{className:"border-t border-edge bg-surface-sunken px-3 py-2",children:[t.subject&&e.jsx("div",{className:"text-xs font-semibold text-fg",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:t.description})]})}const Vn=2e3;function sl({toolUseId:t,live:s=!1}){var p,g;const n=a.useContext(Na),[r,i]=a.useState(null),[o,l]=a.useState(!1),c=(g=(p=a.useContext(en))==null?void 0:p.get(t))==null?void 0:g.messages;a.useEffect(()=>{i(null),l(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){l(!0);return}let h=!1,b;const N=()=>{n(t).then(f=>{h||(i(f),s&&(b=setTimeout(N,Vn)))}).catch(()=>{h||(s?b=setTimeout(N,Vn):l(!0))})};return N(),()=>{h=!0,b&&clearTimeout(b)}},[n,t,s,!!c]);const m=c??r,u=a.useMemo(()=>Wt(m??[]),[m]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:o?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):u.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"waiting for sub-agent steps…"})]}):e.jsx("span",{children:"(no recorded steps)"})}):e.jsxs("div",{className:"space-y-3 border-l-2 border-accent-edge pl-3",children:[u.map(h=>e.jsx(an,{turn:h},h.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function nl(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:i,onSessionStarted:o,onTurnComplete:l,sessionRef:c,jobRef:m,pendingCancelRef:u,streamingRef:p,awaitingSessionRef:g,isNewSessionRef:h,startedNotifiedRef:b,establishedHereRef:N,modelRef:f,cancelledRef:d,noticeThisTurnRef:v,seenInjectionsRef:P,onQueuedFlushedRef:E,onQueuedStateRef:I,onQueuedReturnedRef:k,setTurns:S,setStreaming:L,setUsage:$,setSessionUsage:T,setError:y}=t;a.useEffect(()=>{const F=_=>{const j=c.current;return j?_.sessionId===j?!0:_.sessionId==null&&p.current:g.current},O=_=>{c.current=_,g.current=!1,X.setSessionId(_),h.current&&!b.current&&(b.current=!0,N.current=_,f.current&&zs(_,s,f.current),o==null||o(_))},z=_=>{m.current=_,u.current&&(u.current=!1,Ne.cancel(_))},X=Ne.subscribe(s,c.current,{onResponse:(_,j)=>{F(j)&&(j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId),Gi(S,_))},onToolStart:(_,j)=>{F(j)&&(j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId),S(M=>_.toolUseId&&M.some(W=>W.kind==="tool"&&W.tool.toolUseId===_.toolUseId)?M:[...Le(M),{kind:"tool",id:Ye(),tool:_}]))},onToolCall:(_,j)=>{if(!F(j))return;j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId);const M=ya(_);S(W=>{if(_.toolUseId){const ie=W.findIndex(G=>G.kind==="tool"&&G.tool.toolUseId===_.toolUseId);if(ie!==-1){const G=W[ie].id,K=W.slice();return K[ie]=M?{kind:"file",id:G,file:M}:{kind:"tool",id:G,tool:_},K}}const q=M?{kind:"file",id:Ye(),file:M}:{kind:"tool",id:Ye(),tool:_};return[...Le(W),q]})},onMessageBoundary:_=>{F(_)&&(_.jobId&&z(_.jobId),S(j=>Le(j)))},onComplete:_=>{if(F(_)){_.jobId&&z(_.jobId),p.current=!1,L(!1),S(j=>Mn(Le(j))),_.usage&&$(_.usage);{const j=_.sessionId??c.current;j&&B.chatContext(s,j).then(M=>T(M)).catch(()=>{})}if(_.sessionId){const j=h.current&&c.current!==_.sessionId;O(_.sessionId),(j||h.current)&&(h.current=!1,f.current&&zs(_.sessionId,s,f.current),N.current=_.sessionId,i==null||i(_.sessionId))}!_.success&&_.error&&!v.current&&y(_.error);{const j=_.sessionId??c.current;l==null||l(j&&_.usage?{sessionId:j,usage:_.usage}:void 0)}d.current=!1}},onError:_=>{p.current&&(p.current=!1,L(!1),m.current=null,S(j=>Mn(Le(j))),y(_),d.current=!1)},onResync:()=>{const _=c.current;!_||!r||r(_).then(({messages:j})=>S(Wt(j))).catch(()=>{})},onActive:({turnRunning:_,jobId:j})=>{_?(j&&z(j),p.current=!0,L(!0)):(p.current=!1,L(!1),m.current=null,S(M=>Le(M)),d.current=!1,u.current=!1)},onQueuedFlushed:({text:_,attachments:j})=>{E.current(_,j)},onQueuedState:({text:_,qid:j,reason:M,attachments:W})=>{I.current(_,j,M,W)},onQueuedReturned:({text:_,attachments:j})=>{k.current(_,j)},onInjected:(_,j)=>{if(!F(j))return;j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId);const M=`${_.timestamp} ${_.content}`;P.current.has(M)||(P.current.add(M),S(W=>[...Le(W),{kind:"user",id:Ye(),content:_.content,sender:_.sender}]))},onKilledTask:({summary:_,timestamp:j})=>{const M=`killed ${j}`;P.current.has(M)||(P.current.add(M),S(W=>[...Le(W),{kind:"notification",id:Ye(),summary:_,status:"killed"}]))},onNotice:(_,j)=>{F(j)&&(v.current=!0,S(M=>[...Le(M),{kind:"notice",id:Ye(),notice:_}]))}});return()=>{X.unsubscribe()}},[s,n,r,i,o,l])}const Pa="paddock:attachments:",_a="paddock:newchat-instance:";function al(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function rl(t){try{const s=_a+t,n=sessionStorage.getItem(s);if(n)return n;const r=al();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${Pa}new:${t}`)}catch{}return r}catch{return"shared"}}function il(t){try{localStorage.removeItem(Kt(null,t))}catch{}try{sessionStorage.removeItem(_a+t)}catch{}}function Kt(t,s){return Pa+(t??`new:${s}:${rl(s)}`)}function ol(t){if(!t||typeof t!="object")return null;const s=t;if(typeof s.id!="string"||!s.id||typeof s.filename!="string"||!s.filename)return null;const n={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(n.size=s.size),n}function ll(t,s){try{const n=localStorage.getItem(Kt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(ol).filter(i=>i!==null):[]}catch{return[]}}function cl(t,s,n){try{const r=Kt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function dl({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:i,setError:o}){const[l,c]=a.useState(()=>ll(s,t)),m=a.useRef([]);m.current=l;const[u,p]=a.useState(!1),[g,h]=a.useState(!1),b=a.useRef(null);a.useEffect(()=>{cl(s,t,l)},[l,s,t]);const N=a.useRef(null);a.useEffect(()=>{if(!s){N.current=Kt(null,t);return}const T=N.current;if(N.current=null,!(!T||T===Kt(s,t)))try{localStorage.removeItem(T)}catch{}},[s,t]);const f=a.useMemo(()=>{const T=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},y=r??{};return{enabled:y.enabled??T.enabled,maxFileSizeMb:y.maxFileSizeMb??T.maxFileSizeMb,maxFilesPerMessage:y.maxFilesPerMessage??T.maxFilesPerMessage,allowedTypes:y.allowedTypes??T.allowedTypes}},[n,r]),d=f.enabled,v=a.useCallback(async T=>{if(!d||T.length===0)return;const y=f.maxFileSizeMb*1024*1024,F=f.maxFilesPerMessage-m.current.length;if(F<=0){o(`You can attach at most ${f.maxFilesPerMessage} files per message.`);return}const O=[];for(const z of T.slice(0,F)){if(!ji(f.allowedTypes,z.type,z.name)){o(`File type not allowed: ${z.name}`);continue}if(z.size>y){o(`File too large (max ${f.maxFileSizeMb} MB): ${z.name}`);continue}O.push(z)}if(T.length>F&&o(`You can attach at most ${f.maxFilesPerMessage} files per message.`),O.length!==0){p(!0);try{const{files:z}=await B.uploadAttachments(t,i.current??"new",O);c(X=>[...X,...z])}catch(z){o(z instanceof Error?z.message:"Upload failed.")}finally{p(!1)}}},[d,f,t]),P=a.useCallback(T=>{c(y=>y.filter(F=>F.id!==T))},[]),E=a.useCallback(()=>{c([])},[]),I=a.useCallback(T=>{var F;if(!d)return;const y=Array.from(((F=T.clipboardData)==null?void 0:F.files)??[]);y.length>0&&(T.preventDefault(),v(y))},[d,v]),k=a.useCallback(T=>{var y;d&&Array.from(((y=T.dataTransfer)==null?void 0:y.types)??[]).includes("Files")&&(T.preventDefault(),h(!0))},[d]),S=a.useCallback(T=>{T.currentTarget===T.target&&h(!1)},[]),L=a.useCallback(T=>{var F;if(!d)return;const y=Array.from(((F=T.dataTransfer)==null?void 0:F.files)??[]);y.length>0&&(T.preventDefault(),h(!1),v(y))},[d,v]),$=a.useCallback(T=>{const y=Array.from(T.target.files??[]);y.length>0&&v(y),T.target.value=""},[v]);return{attachments:l,attachRef:m,setAttachments:c,uploading:u,dragOver:g,fileInputRef:b,attachConfig:f,attachEnabled:d,addFiles:v,removeAttachment:P,clearAttachments:E,onComposerPaste:I,onComposerDragOver:k,onComposerDragLeave:S,onComposerDrop:L,onPickFiles:$}}const ul=15e3,hl="no response — try again";function ml({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,preloadAvailable:l=!1,projectModel:c,projectModels:m,forkParent:u,onOpenForkParent:p,autoFocus:g,emptyHint:h,placeholder:b,trigger:N,projectRecovery:f,projectAttachments:d,onForkFromMessage:v,onRevertToMessage:P,onMessageLink:E,focusMessageUuid:I}){const[k,S]=a.useState([]),[L,$]=a.useState(0),[T,y]=a.useState(()=>fi(s,t)),F=a.useRef(null),[O,z]=a.useState(!1),[X,_]=a.useState(!1),[j,M]=a.useState(null),[W,q]=a.useState(null),[ie,G]=a.useState(Ne.state),[K,w]=a.useState(null),[U,Z]=a.useState(()=>Vr(s,t)),C=a.useRef(U),H=a.useRef(zr(s,t)),[de,je]=a.useState(()=>Hr(s,t)),le=a.useRef(de);le.current=de;const he=U!=null||de.length>0,ye=a.useRef(!1),Oe=a.useRef(!1),[Me,re]=a.useState(!0),Ue=!s,we=a.useRef(!1),[$e,ne]=a.useState([]),[Be,Ae]=a.useState(null),[De,J]=a.useState(null),[xe,Te]=a.useState(null),[Rt,Xe]=a.useState(null),[Ve,et]=a.useState([]),[ze,He]=a.useState(0),[ke,A]=a.useState(!1),ee=a.useRef(null),[ae,ue]=a.useState(null),[ve,We]=a.useState(null),Et=c??Be,Mt=a.useMemo(()=>m&&m.length>0?$e.filter(x=>m.includes(x.id)):$e,[$e,m]),Ie=a.useRef(s??null),it=a.useRef(null),At=a.useRef(!1),{attachments:Pe,attachRef:tt,setAttachments:ot,uploading:lt,dragOver:Zt,fileInputRef:Dt,attachConfig:Pt,attachEnabled:st,removeAttachment:ps,clearAttachments:bs,onComposerPaste:js,onComposerDragOver:ws,onComposerDragLeave:vs,onComposerDrop:ys,onPickFiles:Ns}=dl({projectSlug:t,initialSessionId:s,attachmentsDefault:Rt,projectAttachments:d,sessionRef:Ie,setError:M}),xt=a.useRef(null),es=a.useRef(Pe.length);a.useEffect(()=>{const x=Pe.length>es.current;es.current=Pe.length,x&&xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)},[Pe.length]);const ts=a.useCallback(x=>Ie.current?B.subagentMessages(t,Ie.current,x):Promise.resolve([]),[t]),_t=lo(k),[ct,ss]=a.useState([]);a.useEffect(()=>{const x=s??null;if(!x){ss([]);return}return Ne.onBackgroundWork(x,ss)},[s]);const Lt=oo(ct),gt=io(_t,ts,O,Lt),[ns,pt]=a.useState(new Set),[ks,bt]=a.useState(new Map),nt=a.useRef(new Map),at=a.useCallback(x=>{const R=nt.current.get(x);R!==void 0&&(clearTimeout(R),nt.current.delete(x))},[]);a.useEffect(()=>{const x=nt.current;return()=>{for(const R of x.values())clearTimeout(R);x.clear()}},[]),a.useEffect(()=>{const x=s??null;if(x)return Ne.onStopTaskResult(x,({taskId:R,outcome:Q,message:V})=>{Q!=="stopping"&&(at(R),pt(Y=>{if(!Y.has(R))return Y;const me=new Set(Y);return me.delete(R),me}),Q==="error"&&bt(Y=>new Map(Y).set(R,V||"the runtime refused the stop")))})},[s,at]);const Cs=a.useCallback(x=>{const R=s??null;if(!R)return;let Q=!1;pt(V=>V.has(x)?(Q=!0,V):new Set(V).add(x)),!Q&&(bt(V=>{if(!V.has(x))return V;const Y=new Map(V);return Y.delete(x),Y}),at(x),nt.current.set(x,setTimeout(()=>{nt.current.delete(x),pt(V=>{if(!V.has(x))return V;const Y=new Set(V);return Y.delete(x),Y}),bt(V=>new Map(V).set(x,hl))},ul)),Ne.stopTask(R,x))},[s,at]);a.useEffect(()=>{const x=new Set(ct.map(R=>R.id));for(const R of[...nt.current.keys()])x.has(R)||at(R);pt(R=>{const Q=new Set([...R].filter(V=>x.has(V)));return Q.size===R.size?R:Q}),bt(R=>{const Q=new Map([...R].filter(([V])=>x.has(V)));return Q.size===R.size?R:Q})},[ct,at]);const jt=co(k),Ss=a.useMemo(()=>_t.filter(x=>{var R;return!Lt.has(x.toolUseId)&&(((R=gt.get(x.toolUseId))==null?void 0:R.running)??O)}),[_t,gt,O,Lt]),$s=a.useMemo(()=>t?x=>B.projectFileRawUrl(t,x):null,[t]),wt=a.useRef(!s),vt=a.useRef(!1),yt=a.useRef(!1),Ge=a.useRef(!1),as=a.useRef(null),Ft=a.useRef(null),Ze=a.useRef(!0),rs=a.useRef(new Set),ln=a.useCallback(()=>{const x=Ft.current;x&&(Ze.current=x.scrollHeight-x.scrollTop-x.clientHeight<80)},[]);a.useLayoutEffect(()=>{const x=Ft.current;x&&Ze.current&&(x.scrollTop=x.scrollHeight)},[k]);const[Ot,is]=a.useState(null),Ut=a.useMemo(()=>({focused:Ot,focus:x=>{Ze.current=!1,is(R=>({toolUseId:x,nonce:((R==null?void 0:R.nonce)??0)+1}))}}),[Ot]);a.useEffect(()=>Ne.onState(G),[]),a.useEffect(()=>{let x=!1;return B.getModels().then(R=>{x||(ne(R.models),Ae(R.defaultModel),Te(R.recoveryDefault),Xe(R.attachmentsDefault))}).catch(()=>{}),()=>{x=!0}},[]),a.useEffect(()=>{let x=!1;return B.projectCommands(t).then(R=>{x||et(R)}).catch(()=>{}),()=>{x=!0}},[t]);const Ke=a.useMemo(()=>{if(!T.startsWith("/"))return null;const x=T.slice(1);return/\s/.test(x)?null:x},[T]),qe=a.useMemo(()=>{if(Ke===null)return[];const x=Ke.toLowerCase();return Ve.filter(R=>R.name.toLowerCase().includes(x))},[Ke,Ve]),Bt=Ke!==null&&!ke&&qe.length>0;a.useEffect(()=>{He(0)},[Ke]),a.useEffect(()=>{A(!1)},[Ke]);const D=a.useCallback(x=>{y(`/${x.name} `),requestAnimationFrame(()=>{var R;return(R=F.current)==null?void 0:R.focus()})},[]),te=a.useCallback(x=>{J(x),ee.current=x,zs(Ie.current??s,t,x)},[t,s]);a.useEffect(()=>{if(s&&s===as.current){wt.current=!1;return}let x=!1;return Ie.current=s??null,wt.current=!s,it.current=null,vt.current=!1,yt.current=!1,Ge.current=!1,M(null),z(!1),s&&n?(_(!0),S([]),n(s).then(({messages:R,total:Q,truncated:V})=>{x||($(V?Q-R.length:0),S(Y=>Dn(Wt(R),Y)))}).catch(()=>{x||M("Could not load this chat's history.")}).finally(()=>{x||_(!1)})):(S([]),_(!1)),s&&B.chatContext(t,s).then(R=>{x||!R||(ue({inputTokens:R.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:R.contextTokens,contextLimit:R.contextLimit}),We(R))}).catch(()=>{}),()=>{x=!0}},[t,s,n]);const oe=a.useCallback(async()=>{if(!(!s||!n)){try{const{messages:x,total:R,truncated:Q}=await n(s);S(Wt(x)),$(Q?R-x.length:0)}catch{M("Could not reload this chat's history.")}try{const x=await B.chatContext(t,s);x&&(ue({inputTokens:x.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:x.contextTokens,contextLimit:x.contextLimit}),We(x))}catch{}}},[s,n,t]),Qe=a.useCallback(x=>{if(!P)return;const R=k.findIndex(Se=>Se.id.split("#")[0]===x),Q=R>=0&&k[R].kind==="user";let V=R+1;if(Q){let Se=R-1;for(;Se>=0&&k[Se].kind!=="assistant";)Se--;V=Se+1}else for(;V<k.length&&(k[V].kind==="tool"||k[V].kind==="file");)V++;const Y=R>=0?k.slice(V):[],me=Y.filter(Se=>Se.kind==="tool").length;w({uuid:x,count:Y.length,toolCount:me,anchorIsUser:Q})},[P,k]),Ce=a.useCallback(async()=>{if(K){try{await(P==null?void 0:P(K.uuid)),await oe()}catch{throw new Error("Could not revert this chat.")}w(null)}},[K,P,oe]),[_e,za]=a.useState(null),cn=a.useRef(null);a.useEffect(()=>{if(!I||X||k.length===0)return;const x=`${s??""}:${I}`;if(cn.current===x)return;cn.current=x;const R=V=>V.some(Y=>Y.id.split("#")[0]===I),Q=()=>{Ze.current=!1,za(V=>({uuid:I,nonce:((V==null?void 0:V.nonce)??0)+1}))};if(R(k)){Q();return}if(L>0&&n){let V=!1;return n(s??"",0).then(({messages:Y})=>{if(V)return;const me=Wt(Y);if(!R(me)){q("That link points at a message that isn't in this chat any more.");return}S(Se=>Dn(me,Se)),$(0),Q()}).catch(()=>{V||q("Could not load the rest of this chat's history.")}),()=>{V=!0}}q("That link points at a message that isn't in this chat any more.")},[I,X,k,s,L,n]);const dn=a.useCallback(x=>(E==null?void 0:E(x))??`${window.location.origin}${window.location.pathname}#${da(x)}`,[E]),Ha=a.useMemo(()=>v&&P?{onFork:v,onRevert:Qe,contextLimit:ae==null?void 0:ae.contextLimit,linkTo:dn,focused:_e}:null,[v,P,Qe,ae==null?void 0:ae.contextLimit,dn,_e]);a.useEffect(()=>{const R=hi(s,t)??Et;R&&(J(R),ee.current=R)},[t,s,Et]),a.useEffect(()=>{s&&s===as.current||(ue(null),We(null))},[t,s]),a.useEffect(()=>{xi(s,t,T)},[T,s,t]),a.useEffect(()=>{if(W==null)return;const x=setTimeout(()=>q(null),8e3);return()=>clearTimeout(x)},[W]),a.useEffect(()=>{Wr(s,t,U),Gr(s,t,he?H.current:null),Kr(s,t,de)},[U,de,he,s,t]),a.useEffect(()=>{s&&Ne.setQueued(t,s,U,he?H.current:null,de)},[U,de,he,s,t,Ne]),a.useEffect(()=>{var x;(g||!s)&&((x=F.current)==null||x.focus())},[]);const un=a.useCallback((x,R)=>{const Q=R??[];(x||Q.length>0)&&(Ze.current=!0,S(V=>[...Le(V),{kind:"user",id:Ye(),content:x??"",...Q.length>0?{attachments:Q}:{}}])),C.current=null,H.current=null,Z(null),je([])},[]),hn=a.useCallback((x,R,Q,V)=>{R&&(H.current=R);const Y=x&&x.length>0?x:null,me=V??[];Q==="returned"&&(C.current!=null||le.current.length)&&q("Stopped — the queued message went back to the composer that stopped the turn.");const Se=me.length===le.current.length&&me.every((Xa,Za)=>{var wn;return Xa.id===((wn=le.current[Za])==null?void 0:wn.id)});C.current===Y&&Se||(C.current=Y,Y===null&&me.length===0&&(H.current=null),Z(Y),Se||je(me))},[]),mn=a.useRef(hn);mn.current=hn;const os=a.useCallback((x,R)=>{C.current=null,H.current=null,Z(null);const Q=R??le.current;Q.length>0&&ot(V=>{const Y=new Set(V.map(me=>me.id));return[...V,...Q.filter(me=>!Y.has(me.id))]}),je([]),y(V=>V.trim()?`${x}
7
+ `,1)[0],o=t.length-i.length;return e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-accent-edge bg-accent-soft px-3 py-1.5 text-xs",children:[e.jsx(Je,{width:13,height:13,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 font-semibold uppercase tracking-wide text-accent",children:"queued"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-muted",title:t||s.map(l=>l.filename).join(", "),children:i||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),i&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(l=>l.filename).join(", "),children:["📎 ",s.length]}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:n,title:"Edit this message (cancels the pending auto-send)",className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active",children:[e.jsx(hs,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:r,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-fg-muted hover:bg-surface-active hover:text-danger",children:e.jsx(Fe,{width:12,height:12})})]})]})})}function po({state:t}){const s={open:{c:"bg-success-solid",t:"connected"},connecting:{c:"bg-warn-solid animate-pulse",t:"connecting"},closed:{c:"bg-danger-solid",t:"offline"}}[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${s.c}`}),s.t]})}const bo=a.lazy(()=>ce(()=>import("./MarkdownRenderer-B_3lLjnB.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]))),Xt=a.memo(function({children:s,mermaid:n=!1}){return e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(bo,{mermaid:n,children:s})})}),jo={tsx:"typescript",jsx:"javascript",html:"xml"};function wo(t){if(!t)return;const s=t.toLowerCase();return jo[s]??s}let Es=null;async function vo(){return Es||(Es=(async()=>{const{default:t}=await ce(async()=>{const{default:S}=await import("./core-DvlNQV3i.js");return{default:S}},__vite__mapDeps([8,1,2])),[s,n,r,i,o,l,c,m,u,p,g,h,b,N,f,d,v,P,E,I,k]=await Promise.all([ce(()=>import("./typescript-C2FFdlUC.js"),[]),ce(()=>import("./javascript-BKRaQes9.js"),[]),ce(()=>import("./python-kSlZHhJb.js"),[]),ce(()=>import("./ruby-7T4ktxyv.js"),[]),ce(()=>import("./go-BPx_y7j8.js"),[]),ce(()=>import("./rust-HC3MBUhY.js"),[]),ce(()=>import("./java-B5VKqtH2.js"),[]),ce(()=>import("./c-D2F1sQUL.js"),[]),ce(()=>import("./cpp-Bm3ii6kY.js"),[]),ce(()=>import("./csharp-BNpuYZMG.js"),[]),ce(()=>import("./php-CRdd4dfS.js"),[]),ce(()=>import("./swift-Dn8kKO_1.js"),[]),ce(()=>import("./kotlin-Cw-eF_bm.js"),[]),ce(()=>import("./bash-I8pq0VWm.js"),[]),ce(()=>import("./sql-BC88IN-V.js"),[]),ce(()=>import("./json-DIYVocXf.js"),[]),ce(()=>import("./yaml-drsDnIKT.js"),[]),ce(()=>import("./ini-B3BVgEsG.js"),[]),ce(()=>import("./css-DazXZka4.js"),[]),ce(()=>import("./scss-DZLA7YXz.js"),[]),ce(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",i.default),t.registerLanguage("go",o.default),t.registerLanguage("rust",l.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",u.default),t.registerLanguage("csharp",p.default),t.registerLanguage("php",g.default),t.registerLanguage("swift",h.default),t.registerLanguage("kotlin",b.default),t.registerLanguage("bash",N.default),t.registerLanguage("sql",f.default),t.registerLanguage("json",d.default),t.registerLanguage("yaml",v.default),t.registerLanguage("toml",P.default),t.registerLanguage("css",E.default),t.registerLanguage("scss",I.default),t.registerLanguage("xml",k.default),t})()),Es}function yo({code:t,language:s}){const[n,r]=a.useState(null),i=wo(s);a.useEffect(()=>{if(!i){r(null);return}let l=!1;return r(null),(async()=>{try{const c=await vo();if(l||!c.getLanguage(i))return;const{value:m}=c.highlight(t,{language:i});l||r(m)}catch{}})(),()=>{l=!0}},[t,i]);const o="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg";return n!==null?e.jsx("pre",{className:o,children:e.jsx("code",{className:`hljs language-${i}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:o,children:e.jsx("code",{children:t})})}let Ms=null;function No(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function ko(){return Ms||(Ms=ce(()=>import("./mermaid.core-DmLiTJQf.js").then(t=>t.bm),__vite__mapDeps([9,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:No()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),Ms}function Co({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[i,o]=a.useState(null);return a.useEffect(()=>{let l=!1;return o(null),(async()=>{try{const c=await ko();await c.parse(t);const{svg:m,bindFunctions:u}=await c.render(n+"-svg",t);if(l||!r.current)return;r.current.innerHTML=m,u==null||u(r.current)}catch(c){if(l)return;o(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{l=!0}},[t,n]),i?e.jsxs("div",{className:"my-3 rounded-lg border border-warn-edge bg-warn-soft p-3 text-xs",children:[e.jsx("p",{className:"font-semibold text-warn",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-warn",children:i}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-surface-sunken p-2 font-mono text-2xs text-fg-muted",children:t})]}):e.jsx("div",{ref:r,"data-testid":"mermaid",className:"mermaid-host my-3 flex justify-center overflow-x-auto rounded-lg border border-edge bg-surface-raised p-3"})}const So="paddock:itemHeight:";function sn(t){return So+t}function On(t){try{const s=localStorage.getItem(sn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function $o(t,s){try{const n=sn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function To(t){try{localStorage.removeItem(sn(t))}catch{}}function Io({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const i=a.useRef(null),[o,l]=a.useState(0),[c,m]=a.useState(()=>On(t));a.useEffect(()=>{m(On(t))},[t]),a.useEffect(()=>{if(!i.current)return;const b=()=>{var f;return l(((f=i.current)==null?void 0:f.scrollHeight)||0)};if(b(),typeof ResizeObserver>"u")return;const N=new ResizeObserver(b);return N.observe(i.current),()=>N.disconnect()},[s]);const u=o>0,p=u?o:Number.POSITIVE_INFINITY;let g=!1,h=0;return c!=null?(g=!0,h=Ea(c,r,p)):u&&o>n&&(g=!0,h=n),e.jsxs("div",{className:g?"group relative":void 0,style:g?{height:h}:void 0,children:[e.jsx("div",{className:g?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:i,children:s})}),g?e.jsx(Ro,{appliedHeight:h,onResize:b=>m(b),onCommit:b=>$o(t,b),onReset:()=>{To(t),m(null)},minHeight:r,maxHeight:p}):null]})}function Ro({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:i,maxHeight:o}){const l=a.useRef(null),c=a.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:u=>{l.current={startY:u.clientY,startHeight:t},u.currentTarget.setPointerCapture(u.pointerId)},onPointerMove:u=>{if(!l.current)return;const p=Un(l.current.startHeight,u.clientY-l.current.startY,i,o);s(p)},onPointerUp:u=>{if(l.current){l.current=null;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const p=u.key==="ArrowDown"?m:-m,g=Un(t,p,i,o);s(g),n(g)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-edge-subtle bg-surface-sunken opacity-60 transition hover:bg-surface-hover hover:opacity-100",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-edge-strong group-hover:bg-fg-subtle"})})}function Un(t,s,n,r){return Ea(t+s,n,r)}function Ea(t,s,n){return Math.min(Math.max(t,s),n)}function Ma({src:t,filename:s,message:n}){const[r,i]=a.useState(!1),[o,l]=a.useState(!1),c="repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||r?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsxs("div",{className:"group relative flex items-center justify-center overflow-auto p-4",style:{background:c},children:[e.jsx("img",{src:t,alt:s,onError:()=>i(!0),onClick:()=>l(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),l(!0))},role:"button",tabIndex:0,"aria-label":`Open ${s} full screen`,className:"max-h-[480px] max-w-full cursor-zoom-in object-contain shadow-sm"}),e.jsx(Aa,{src:t,filename:s,onMaximize:()=>l(!0)}),o?e.jsx(Eo,{src:t,filename:s,message:n,onClose:()=>l(!1)}):null]})}function Aa({src:t,filename:s,onMaximize:n}){const r="pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/55 text-white shadow-sm transition-colors hover:bg-black/75 focus-visible:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{className:"pointer-events-none absolute bottom-2 right-2 z-10 flex items-center gap-1.5 opacity-100 transition-opacity can-hover:opacity-0 can-hover:group-hover:opacity-100 can-hover:group-focus-within:opacity-100",children:[e.jsx("a",{href:t,download:s,className:r,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(Mo,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:r,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx(Ao,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(Do,{})}):null]})}function Eo({src:t,filename:s,message:n,onClose:r}){const i=a.useRef(null);return a.useEffect(()=>{var c;const o=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",o);const l=document.body.style.overflow;return document.body.style.overflow="hidden",(c=i.current)==null||c.focus(),()=>{document.removeEventListener("keydown",o),document.body.style.overflow=l}},[r]),cr.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:r,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-4 bg-overlay-strong p-6",children:[e.jsx("button",{ref:i,type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",children:e.jsx(Po,{})}),e.jsx("img",{src:t,alt:s,onClick:o=>o.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:o=>o.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),n?e.jsx("div",{className:"mt-1",children:n}):null]})]}),document.body)}function gs({children:t}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}function Mo(){return e.jsxs(gs,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function Ao(){return e.jsxs(gs,{children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function Do(){return e.jsx(gs,{children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}function Po(){return e.jsx(gs,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function nn({src:t,filename:s,className:n="h-[600px] w-full"}){return t?e.jsxs("div",{className:`group relative ${n}`,children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-full w-full bg-surface-sunken",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-fg-muted",children:[e.jsx(qt,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-fg",children:s}),e.jsx("span",{className:"text-xs text-fg-muted",children:"This browser can’t show the PDF inline."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:"rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-surface motion-fast transition-colors hover:bg-fg-muted",children:"Open in new tab"}),e.jsx("a",{href:t,download:s,className:"rounded-md px-3 py-1.5 text-xs font-medium text-fg-muted ring-1 ring-edge-strong hover:bg-surface-hover",children:"Download"})]})]})}),e.jsx(Aa,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function _o({file:t}){const[s,n]=a.useState(!0),r=Lo(t);return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"w-full max-w-[92%] overflow-hidden rounded-2xl rounded-bl-md bg-surface-raised shadow-sm ring-1 ring-edge",children:[e.jsxs("button",{type:"button",onClick:()=>n(i=>!i),"aria-expanded":s,className:"flex w-full items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-left text-2xs text-fg-muted",children:[e.jsx(Vo,{open:s}),e.jsx(zo,{}),e.jsx("span",{className:"font-mono text-fg-muted",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-3xs text-fg-subtle",children:t.language??t.kind})]}),t.message?e.jsx("div",{className:"border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted",children:t.message}):null,s?e.jsx(Oo,{file:t,itemId:r}):null]})})}function Lo(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${Fo(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function Fo(t){let s=5381;for(let n=0;n<t.length;n++)s=(s<<5)+s+t.charCodeAt(n)|0;return(s>>>0).toString(36)}function Oo({file:t,itemId:s}){return t.kind==="image"?e.jsx(Ma,{src:t.rawUrl,filename:t.filename,message:t.message}):t.kind==="video"?e.jsx(Bo,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(nn,{src:t.rawUrl,filename:t.filename}):t.source==="inline"?e.jsx(Da,{kind:t.kind,text:t.content??"",language:t.language,itemId:s}):e.jsx(Uo,{url:t.rawUrl,kind:t.kind,language:t.language,itemId:s})}function Da({kind:t,text:s,language:n,itemId:r}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:"html-preview min-h-[360px] w-full"}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(Co,{code:s})}):t==="markdown"?e.jsx(As,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Xt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(As,{itemId:r,children:e.jsx(yo,{code:s,language:n})}):e.jsx(As,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg",children:s})})}function As({itemId:t,children:s}){return t?e.jsx(Io,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function Uo({url:t,kind:s,language:n,itemId:r}){const[i,o]=a.useState(null);return a.useEffect(()=>{if(!t){o({error:!0});return}let l=!1;return o(null),fetch(t).then(c=>c.ok?c.text():Promise.reject(new Error(String(c.status)))).then(c=>!l&&o({text:c})).catch(()=>!l&&o({error:!0})),()=>{l=!0}},[t]),i===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in i?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Da,{kind:s,text:i.text,language:n,itemId:r})}function Bo({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-surface-sunken p-4",children:e.jsx("video",{src:t,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[480px] w-full rounded-sm shadow-sm",children:e.jsxs("p",{className:"p-4 text-sm text-fg-muted",children:["Your browser can’t play this video."," ",e.jsxs("a",{href:t,download:s,className:"underline",children:["Download ",s]})]})})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function Vo({open:t}){return e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-subtle transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function zo(){return e.jsxs("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("path",{d:"M14 2v6h6"})]})}const an=a.memo(function({turn:s}){return s.kind==="user"?e.jsxs("div",{className:"flex animate-fade-in flex-col items-end",children:[s.sender?e.jsx(Qo,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(wi,{attachments:s.attachments}):null,s.content?e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-accent-solid px-4 py-2.5 text-sm text-accent-fg shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(_o,{file:s.file}):s.kind==="tool"?e.jsx(Xo,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-surface-active px-2.5 py-0.5 font-mono text-xs text-fg-muted ring-1 ring-edge",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(Ko,{content:s.content}):null:s.kind==="compact"?e.jsx(qo,{summary:s.summary}):s.kind==="notice"?e.jsx(Jo,{notice:s.notice}):s.kind==="notification"?dr(s.status)?e.jsx(Yo,{summary:s.summary}):e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"max-w-[85%] truncate rounded-full bg-surface-sunken px-2.5 py-0.5 text-xs italic text-fg-muted ring-1 ring-edge",title:s.summary,children:s.summary})}):e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsx("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-raised px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(Xt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"})]})})})}),Ho=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function Wo({turn:t}){const s=a.useContext($a);return!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&Ho.test(t.id)?e.jsx(Go,{turn:t,actions:s}):e.jsx(an,{turn:t})}function Go({turn:t,actions:s}){var v;const n=t.id.split("#")[0],r=t.id===n,i=s.linkTo(n),o=a.useRef(null),[l,c]=a.useState(!1),[m,u]=a.useState(!1),p=r&&((v=s.focused)==null?void 0:v.uuid)===n?s.focused.nonce:null;a.useEffect(()=>{var E;if(p==null)return;(E=o.current)==null||E.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const P=setTimeout(()=>u(!1),3200);return()=>clearTimeout(P)},[p]),a.useEffect(()=>{if(!l)return;const P=setTimeout(()=>c(!1),1600);return()=>clearTimeout(P)},[l]);const g=P=>{var E;P.metaKey||P.ctrlKey||P.shiftKey||P.altKey||P.button!==0||(P.preventDefault(),(E=navigator.clipboard)==null||E.writeText(i).then(()=>c(!0)).catch(()=>c(!1)))},h=t.contextTokens,b=s.contextLimit,N=h!=null&&b?Math.min(100,Math.round(h/b*100)):null,f="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",d=`${f} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{ref:o,id:r?da(n):void 0,className:`group relative rounded-lg ${m?"reveal-flash":""}`,children:[e.jsxs("div",{className:"pointer-events-none absolute -top-3 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",children:[e.jsx("a",{href:i,onClick:g,title:`Copy a link to this message · ${new Date(t.timestamp).toLocaleString()}`,"aria-label":`Copy a link to this message (${St(t.timestamp)})`,className:`${f} gap-1 px-2 py-0.5 text-2xs text-fg-muted transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:l?e.jsx("span",{className:"text-accent",children:"Link copied"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:St(t.timestamp)}),h!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",la(h),N!=null?` · ${N}%`:""]}):null]})}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${d} hover:text-accent`,children:e.jsx(ft,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${d} hover:text-danger`,children:e.jsx(Je,{width:13,height:13})})]}),e.jsx(an,{turn:t})]})}function Ee({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function Ko({content:t}){return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-sunken px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-2xs italic text-fg-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(Xt,{children:t})]})})}function qo({summary:t}){return e.jsx("div",{className:"animate-fade-in py-1",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 text-xs text-fg-muted",children:[e.jsx("span",{className:"h-px flex-1 bg-edge"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-edge"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:t})]})})}function Qo({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-2xs italic text-fg-muted";if(t.kind==="schedule")return e.jsxs("div",{className:s,"data-sender":"schedule",children:[e.jsx("span",{"aria-hidden":!0,children:"⏰"}),e.jsxs("span",{children:["scheduled by ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="hook")return e.jsxs("div",{className:s,"data-sender":"hook",children:[e.jsx("span",{"aria-hidden":!0,children:"⚡"}),e.jsxs("span",{children:["triggered by hook ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="recovery")return e.jsxs("div",{className:s,"data-sender":"recovery",children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:"continued after a background task was terminated"})]});if(t.kind==="agent")return e.jsxs("div",{className:s,"data-sender":"agent",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsx("span",{children:"sent by an agent"})]});const n=((r=t.name)==null?void 0:r.trim())||t.sessionId.slice(0,8);return e.jsxs("div",{className:s,"data-sender":"chat",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsxs("span",{children:["sent by"," ",e.jsx(Js,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${n} in ${t.project}`,children:n})]})]})}function Yo({summary:t}){const s=a.useContext(tn),n=!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy);return e.jsx("div",{className:"flex animate-fade-in justify-center","data-recovery":"killed-task",children:e.jsxs("div",{className:"flex max-w-[90%] flex-col gap-1.5 rounded-lg border border-warn-edge bg-warn-soft px-3 py-2 text-xs text-warn",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:"⚠"}),e.jsxs("span",{className:"leading-snug",children:["A background task was terminated at the turn boundary — Claude is idle and will not continue on its own.",e.jsx("span",{className:"mt-0.5 block text-2xs text-warn",children:t})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-recovery-action":"continue",className:"motion-fast rounded-md bg-warn-solid px-2.5 py-1 text-2xs font-medium text-warn-fg shadow-sm transition-[filter,box-shadow,opacity] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50",children:r?"Continuing…":"Continue"})})]})})}function Jo({notice:t}){const s=a.useContext(tn),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),i=t.kind==="error",o=i?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",l=i?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=i?"text-danger":"text-warn",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${o}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:i?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-2xs ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),i&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-2xs ${c}`,children:t.detail})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-notice-action":"retry",className:`motion-fast rounded-md px-2.5 py-1 text-2xs font-medium shadow-sm transition-[filter,box-shadow,opacity] disabled:cursor-not-allowed disabled:opacity-50 ${l}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Xo({tool:t}){var w,U;const s=Ti(t.toolName),n=Ii(t.toolName,t.output),r=s.isPaddock?Ui(s.tool):null,i=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[o,l]=a.useState(i),c=a.useContext(Sa),m=a.useContext(Ca),u=a.useRef(null),[p,g]=a.useState(!1),h=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;a.useEffect(()=>{var C;if(h==null)return;l(!0),(C=u.current)==null||C.scrollIntoView({behavior:"smooth",block:"center"}),g(!0);const Z=setTimeout(()=>g(!1),3200);return()=>clearTimeout(Z)},[h]);const b=a.useContext(ka),N=a.useContext(en),f=!!t.pending,d=xs.has(t.toolName),v=t.toolUseId?N==null?void 0:N.get(t.toolUseId):void 0,P=d?ds(t.subagentDurationMs??(v==null?void 0:v.elapsedMs)):ds(t.durationMs),E=t.subagentCostUsd!=null?`~${oa(t.subagentCostUsd)}`:null,I=!d&&Fi(t),k=t.monitorEvents??[],S=t.editDiff,L=!!S,$=t.toolName==="Read"?t.readInfo:void 0,T=$!=null&&$.isImage&&$.projectRelPath&&c?c($.projectRelPath):null,y=t.toolName==="Bash"?t.bashDetails:void 0,F=t.searchInfo,O=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,z=t.toolName==="TaskCreate"?t.taskCreate:void 0,X=!!(y&&y.stderr),_=F?zi(F):null,j=$?Hi($):null,M=v!=null?v.running:Di(t,b),W=!!(d&&t.hasSubagent&&t.toolUseId),q=M&&t.toolUseId?(w=N==null?void 0:N.get(t.toolUseId))==null?void 0:w.latestStep:void 0,ie=d?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,G=d?q??t.description:n?Ri(n):L?((U=S.filePath)==null?void 0:U.split("/").pop())??S.filePath:$?$.basename??$.filePath??t.inputSummary:z?z.subject:t.inputSummary,K=($==null?void 0:$.filePath)??(z==null?void 0:z.description)??(q?t.description:void 0)??G??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:u,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${p?"reveal-flash ":""}${t.isError?"border-danger-edge bg-danger-soft":d?"border-accent-edge bg-accent-soft":I?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>l(Z=>!Z),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(It,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${o?"rotate-90":""}`}),d?e.jsx(Yt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):I?e.jsx(Je,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-info"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):L?e.jsx(hs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):$?e.jsx(qt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):F?e.jsx(ua,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):O||z?e.jsx(Gt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(ha,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-fg",children:ie}),d&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),I&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-info-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-info",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:n&&"project"in n&&n.project?n.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-fg-muted",children:"MCP"}),O?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[O.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",O.taskId]}),O.from&&O.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Bn,{status:O.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(Bn,{status:O.to})]}):O.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:O.updatedFields.join(", ")})]}):G&&e.jsx("span",{className:`min-w-0 truncate font-mono ${q?"text-accent":"text-fg-muted"}`,title:K,children:G}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-danger-soft px-1.5 py-0.5 text-3xs font-semibold text-danger",children:"error"}),f||M?e.jsxs("span",{className:"flex items-center gap-1.5 text-accent",title:"Sub-agent is running",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-accent-edge border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-3xs font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[I&&k.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[k.length," event",k.length===1?"":"s"]}),I&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${Oi(t.taskStatus)}`,children:t.taskStatus}),L&&(S.additions>0||S.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[S.additions>0&&e.jsxs("span",{className:"text-success",children:["+",S.additions]}),S.additions>0&&S.deletions>0&&" ",S.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",S.deletions]})]}),j&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:j}),_&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:_}),(y==null?void 0:y.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 font-mono text-3xs text-fg-muted",children:y.gitHint}),(y==null?void 0:y.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-warn-soft px-1.5 py-0.5 text-3xs font-semibold text-warn",children:"interrupted"}),(y==null?void 0:y.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:y.returnCodeInterpretation}),P&&e.jsx("span",{className:"text-fg-subtle tabular",children:P}),E&&e.jsx("span",{className:"text-fg-subtle tabular",children:E})]})]})]}),o&&(W?e.jsx(sl,{toolUseId:t.toolUseId,live:M}):I&&k.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:k.map((Z,C)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-info-edge px-3 py-1.5 font-mono text-2xs leading-relaxed text-fg-muted last:border-b-0",children:Z},C))}):n?e.jsx(Ai,{data:n}):L?e.jsx(Zo,{diff:S}):T?e.jsx("div",{className:"border-t border-edge",children:e.jsx(Ma,{src:T,filename:($==null?void 0:$.basename)??"image"})}):X?e.jsx(el,{bash:y}):z&&z.description?e.jsx(tl,{info:z}):e.jsxs("div",{className:"border-t border-edge",children:[I&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-edge bg-info-soft px-3 py-2 text-2xs font-medium text-fg",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:f?"Running…":t.output||"(no output)"})]}))]})})}function Zo({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-edge bg-surface-sunken font-mono text-2xs leading-relaxed",children:[t.hunks.map((s,n)=>e.jsxs("div",{className:n>0?"border-t border-edge":"",children:[e.jsxs("div",{className:"bg-surface-active px-3 py-1 font-mono text-3xs font-semibold text-lineage",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,i)=>e.jsxs("div",{className:`flex ${Bi(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:En(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:En(r.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:r.t===" "?"":r.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:r.text||" "})]},i))]},n)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-2xs italic text-fg-subtle",children:"… diff truncated (see the file for the full change)"})]})}function Bn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${Vi(t)}`,children:t})}function el({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-edge",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-danger-edge bg-danger-soft px-3 py-2 font-mono text-2xs leading-relaxed text-danger first:border-t-0",children:t.stderr})]})}function tl({info:t}){return e.jsxs("div",{className:"border-t border-edge bg-surface-sunken px-3 py-2",children:[t.subject&&e.jsx("div",{className:"text-xs font-semibold text-fg",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:t.description})]})}const Vn=2e3;function sl({toolUseId:t,live:s=!1}){var p,g;const n=a.useContext(Na),[r,i]=a.useState(null),[o,l]=a.useState(!1),c=(g=(p=a.useContext(en))==null?void 0:p.get(t))==null?void 0:g.messages;a.useEffect(()=>{i(null),l(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){l(!0);return}let h=!1,b;const N=()=>{n(t).then(f=>{h||(i(f),s&&(b=setTimeout(N,Vn)))}).catch(()=>{h||(s?b=setTimeout(N,Vn):l(!0))})};return N(),()=>{h=!0,b&&clearTimeout(b)}},[n,t,s,!!c]);const m=c??r,u=a.useMemo(()=>Wt(m??[]),[m]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:o?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):u.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"waiting for sub-agent steps…"})]}):e.jsx("span",{children:"(no recorded steps)"})}):e.jsxs("div",{className:"space-y-3 border-l-2 border-accent-edge pl-3",children:[u.map(h=>e.jsx(an,{turn:h},h.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(Ee,{})," ",e.jsx(Ee,{delay:"150ms"})," ",e.jsx(Ee,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function nl(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:i,onSessionStarted:o,onTurnComplete:l,sessionRef:c,jobRef:m,pendingCancelRef:u,streamingRef:p,awaitingSessionRef:g,isNewSessionRef:h,startedNotifiedRef:b,establishedHereRef:N,modelRef:f,cancelledRef:d,noticeThisTurnRef:v,seenInjectionsRef:P,onQueuedFlushedRef:E,onQueuedStateRef:I,onQueuedReturnedRef:k,setTurns:S,setStreaming:L,setUsage:$,setSessionUsage:T,setError:y}=t;a.useEffect(()=>{const F=_=>{const j=c.current;return j?_.sessionId===j?!0:_.sessionId==null&&p.current:g.current},O=_=>{c.current=_,g.current=!1,X.setSessionId(_),h.current&&!b.current&&(b.current=!0,N.current=_,f.current&&zs(_,s,f.current),o==null||o(_))},z=_=>{m.current=_,u.current&&(u.current=!1,Ne.cancel(_))},X=Ne.subscribe(s,c.current,{onResponse:(_,j)=>{F(j)&&(j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId),Gi(S,_))},onToolStart:(_,j)=>{F(j)&&(j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId),S(M=>_.toolUseId&&M.some(W=>W.kind==="tool"&&W.tool.toolUseId===_.toolUseId)?M:[...Le(M),{kind:"tool",id:Ye(),tool:_}]))},onToolCall:(_,j)=>{if(!F(j))return;j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId);const M=ya(_);S(W=>{if(_.toolUseId){const ie=W.findIndex(G=>G.kind==="tool"&&G.tool.toolUseId===_.toolUseId);if(ie!==-1){const G=W[ie].id,K=W.slice();return K[ie]=M?{kind:"file",id:G,file:M}:{kind:"tool",id:G,tool:_},K}}const q=M?{kind:"file",id:Ye(),file:M}:{kind:"tool",id:Ye(),tool:_};return[...Le(W),q]})},onMessageBoundary:_=>{F(_)&&(_.jobId&&z(_.jobId),S(j=>Le(j)))},onComplete:_=>{if(F(_)){_.jobId&&z(_.jobId),p.current=!1,L(!1),S(j=>Mn(Le(j))),_.usage&&$(_.usage);{const j=_.sessionId??c.current;j&&B.chatContext(s,j).then(M=>T(M)).catch(()=>{})}if(_.sessionId){const j=h.current&&c.current!==_.sessionId;O(_.sessionId),(j||h.current)&&(h.current=!1,f.current&&zs(_.sessionId,s,f.current),N.current=_.sessionId,i==null||i(_.sessionId))}!_.success&&_.error&&!v.current&&y(_.error);{const j=_.sessionId??c.current;l==null||l(j&&_.usage?{sessionId:j,usage:_.usage}:void 0)}d.current=!1}},onError:_=>{p.current&&(p.current=!1,L(!1),m.current=null,S(j=>Mn(Le(j))),y(_),d.current=!1)},onResync:()=>{const _=c.current;!_||!r||r(_).then(({messages:j})=>S(Wt(j))).catch(()=>{})},onActive:({turnRunning:_,jobId:j})=>{_?(j&&z(j),p.current=!0,L(!0)):(p.current=!1,L(!1),m.current=null,S(M=>Le(M)),d.current=!1,u.current=!1)},onQueuedFlushed:({text:_,attachments:j})=>{E.current(_,j)},onQueuedState:({text:_,qid:j,reason:M,attachments:W})=>{I.current(_,j,M,W)},onQueuedReturned:({text:_,attachments:j})=>{k.current(_,j)},onInjected:(_,j)=>{if(!F(j))return;j.jobId&&z(j.jobId),j.sessionId&&O(j.sessionId);const M=`${_.timestamp} ${_.content}`;P.current.has(M)||(P.current.add(M),S(W=>[...Le(W),{kind:"user",id:Ye(),content:_.content,sender:_.sender}]))},onKilledTask:({summary:_,timestamp:j})=>{const M=`killed ${j}`;P.current.has(M)||(P.current.add(M),S(W=>[...Le(W),{kind:"notification",id:Ye(),summary:_,status:"killed"}]))},onNotice:(_,j)=>{F(j)&&(v.current=!0,S(M=>[...Le(M),{kind:"notice",id:Ye(),notice:_}]))}});return()=>{X.unsubscribe()}},[s,n,r,i,o,l])}const Pa="paddock:attachments:",_a="paddock:newchat-instance:";function al(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function rl(t){try{const s=_a+t,n=sessionStorage.getItem(s);if(n)return n;const r=al();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${Pa}new:${t}`)}catch{}return r}catch{return"shared"}}function il(t){try{localStorage.removeItem(Kt(null,t))}catch{}try{sessionStorage.removeItem(_a+t)}catch{}}function Kt(t,s){return Pa+(t??`new:${s}:${rl(s)}`)}function ol(t){if(!t||typeof t!="object")return null;const s=t;if(typeof s.id!="string"||!s.id||typeof s.filename!="string"||!s.filename)return null;const n={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(n.size=s.size),n}function ll(t,s){try{const n=localStorage.getItem(Kt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(ol).filter(i=>i!==null):[]}catch{return[]}}function cl(t,s,n){try{const r=Kt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function dl({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:i,setError:o}){const[l,c]=a.useState(()=>ll(s,t)),m=a.useRef([]);m.current=l;const[u,p]=a.useState(!1),[g,h]=a.useState(!1),b=a.useRef(null);a.useEffect(()=>{cl(s,t,l)},[l,s,t]);const N=a.useRef(null);a.useEffect(()=>{if(!s){N.current=Kt(null,t);return}const T=N.current;if(N.current=null,!(!T||T===Kt(s,t)))try{localStorage.removeItem(T)}catch{}},[s,t]);const f=a.useMemo(()=>{const T=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},y=r??{};return{enabled:y.enabled??T.enabled,maxFileSizeMb:y.maxFileSizeMb??T.maxFileSizeMb,maxFilesPerMessage:y.maxFilesPerMessage??T.maxFilesPerMessage,allowedTypes:y.allowedTypes??T.allowedTypes}},[n,r]),d=f.enabled,v=a.useCallback(async T=>{if(!d||T.length===0)return;const y=f.maxFileSizeMb*1024*1024,F=f.maxFilesPerMessage-m.current.length;if(F<=0){o(`You can attach at most ${f.maxFilesPerMessage} files per message.`);return}const O=[];for(const z of T.slice(0,F)){if(!ji(f.allowedTypes,z.type,z.name)){o(`File type not allowed: ${z.name}`);continue}if(z.size>y){o(`File too large (max ${f.maxFileSizeMb} MB): ${z.name}`);continue}O.push(z)}if(T.length>F&&o(`You can attach at most ${f.maxFilesPerMessage} files per message.`),O.length!==0){p(!0);try{const{files:z}=await B.uploadAttachments(t,i.current??"new",O);c(X=>[...X,...z])}catch(z){o(z instanceof Error?z.message:"Upload failed.")}finally{p(!1)}}},[d,f,t]),P=a.useCallback(T=>{c(y=>y.filter(F=>F.id!==T))},[]),E=a.useCallback(()=>{c([])},[]),I=a.useCallback(T=>{var F;if(!d)return;const y=Array.from(((F=T.clipboardData)==null?void 0:F.files)??[]);y.length>0&&(T.preventDefault(),v(y))},[d,v]),k=a.useCallback(T=>{var y;d&&Array.from(((y=T.dataTransfer)==null?void 0:y.types)??[]).includes("Files")&&(T.preventDefault(),h(!0))},[d]),S=a.useCallback(T=>{T.currentTarget===T.target&&h(!1)},[]),L=a.useCallback(T=>{var F;if(!d)return;const y=Array.from(((F=T.dataTransfer)==null?void 0:F.files)??[]);y.length>0&&(T.preventDefault(),h(!1),v(y))},[d,v]),$=a.useCallback(T=>{const y=Array.from(T.target.files??[]);y.length>0&&v(y),T.target.value=""},[v]);return{attachments:l,attachRef:m,setAttachments:c,uploading:u,dragOver:g,fileInputRef:b,attachConfig:f,attachEnabled:d,addFiles:v,removeAttachment:P,clearAttachments:E,onComposerPaste:I,onComposerDragOver:k,onComposerDragLeave:S,onComposerDrop:L,onPickFiles:$}}const ul=15e3,hl="no response — try again";function ml({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,preloadAvailable:l=!1,projectModel:c,projectModels:m,forkParent:u,onOpenForkParent:p,autoFocus:g,emptyHint:h,placeholder:b,trigger:N,projectRecovery:f,projectAttachments:d,onForkFromMessage:v,onRevertToMessage:P,onMessageLink:E,focusMessageUuid:I}){const[k,S]=a.useState([]),[L,$]=a.useState(0),[T,y]=a.useState(()=>fi(s,t)),F=a.useRef(null),[O,z]=a.useState(!1),[X,_]=a.useState(!1),[j,M]=a.useState(null),[W,q]=a.useState(null),[ie,G]=a.useState(Ne.state),[K,w]=a.useState(null),[U,Z]=a.useState(()=>Vr(s,t)),C=a.useRef(U),H=a.useRef(zr(s,t)),[de,je]=a.useState(()=>Hr(s,t)),le=a.useRef(de);le.current=de;const he=U!=null||de.length>0,ye=a.useRef(!1),Oe=a.useRef(!1),[Me,re]=a.useState(!0),Ue=!s,we=a.useRef(!1),[$e,ne]=a.useState([]),[Be,Ae]=a.useState(null),[De,J]=a.useState(null),[xe,Te]=a.useState(null),[Rt,Xe]=a.useState(null),[Ve,et]=a.useState([]),[ze,He]=a.useState(0),[ke,A]=a.useState(!1),ee=a.useRef(null),[ae,ue]=a.useState(null),[ve,We]=a.useState(null),Et=c??Be,Mt=a.useMemo(()=>m&&m.length>0?$e.filter(x=>m.includes(x.id)):$e,[$e,m]),Ie=a.useRef(s??null),it=a.useRef(null),At=a.useRef(!1),{attachments:Pe,attachRef:tt,setAttachments:ot,uploading:lt,dragOver:Zt,fileInputRef:Dt,attachConfig:Pt,attachEnabled:st,removeAttachment:ps,clearAttachments:bs,onComposerPaste:js,onComposerDragOver:ws,onComposerDragLeave:vs,onComposerDrop:ys,onPickFiles:Ns}=dl({projectSlug:t,initialSessionId:s,attachmentsDefault:Rt,projectAttachments:d,sessionRef:Ie,setError:M}),xt=a.useRef(null),es=a.useRef(Pe.length);a.useEffect(()=>{const x=Pe.length>es.current;es.current=Pe.length,x&&xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)},[Pe.length]);const ts=a.useCallback(x=>Ie.current?B.subagentMessages(t,Ie.current,x):Promise.resolve([]),[t]),_t=lo(k),[ct,ss]=a.useState([]);a.useEffect(()=>{const x=s??null;if(!x){ss([]);return}return Ne.onBackgroundWork(x,ss)},[s]);const Lt=oo(ct),gt=io(_t,ts,O,Lt),[ns,pt]=a.useState(new Set),[ks,bt]=a.useState(new Map),nt=a.useRef(new Map),at=a.useCallback(x=>{const R=nt.current.get(x);R!==void 0&&(clearTimeout(R),nt.current.delete(x))},[]);a.useEffect(()=>{const x=nt.current;return()=>{for(const R of x.values())clearTimeout(R);x.clear()}},[]),a.useEffect(()=>{const x=s??null;if(x)return Ne.onStopTaskResult(x,({taskId:R,outcome:Q,message:V})=>{Q!=="stopping"&&(at(R),pt(Y=>{if(!Y.has(R))return Y;const me=new Set(Y);return me.delete(R),me}),Q==="error"&&bt(Y=>new Map(Y).set(R,V||"the runtime refused the stop")))})},[s,at]);const Cs=a.useCallback(x=>{const R=s??null;if(!R)return;let Q=!1;pt(V=>V.has(x)?(Q=!0,V):new Set(V).add(x)),!Q&&(bt(V=>{if(!V.has(x))return V;const Y=new Map(V);return Y.delete(x),Y}),at(x),nt.current.set(x,setTimeout(()=>{nt.current.delete(x),pt(V=>{if(!V.has(x))return V;const Y=new Set(V);return Y.delete(x),Y}),bt(V=>new Map(V).set(x,hl))},ul)),Ne.stopTask(R,x))},[s,at]);a.useEffect(()=>{const x=new Set(ct.map(R=>R.id));for(const R of[...nt.current.keys()])x.has(R)||at(R);pt(R=>{const Q=new Set([...R].filter(V=>x.has(V)));return Q.size===R.size?R:Q}),bt(R=>{const Q=new Map([...R].filter(([V])=>x.has(V)));return Q.size===R.size?R:Q})},[ct,at]);const jt=co(k),Ss=a.useMemo(()=>_t.filter(x=>{var R;return!Lt.has(x.toolUseId)&&(((R=gt.get(x.toolUseId))==null?void 0:R.running)??O)}),[_t,gt,O,Lt]),$s=a.useMemo(()=>t?x=>B.projectFileRawUrl(t,x):null,[t]),wt=a.useRef(!s),vt=a.useRef(!1),yt=a.useRef(!1),Ge=a.useRef(!1),as=a.useRef(null),Ft=a.useRef(null),Ze=a.useRef(!0),rs=a.useRef(new Set),ln=a.useCallback(()=>{const x=Ft.current;x&&(Ze.current=x.scrollHeight-x.scrollTop-x.clientHeight<80)},[]);a.useLayoutEffect(()=>{const x=Ft.current;x&&Ze.current&&(x.scrollTop=x.scrollHeight)},[k]);const[Ot,is]=a.useState(null),Ut=a.useMemo(()=>({focused:Ot,focus:x=>{Ze.current=!1,is(R=>({toolUseId:x,nonce:((R==null?void 0:R.nonce)??0)+1}))}}),[Ot]);a.useEffect(()=>Ne.onState(G),[]),a.useEffect(()=>{let x=!1;return B.getModels().then(R=>{x||(ne(R.models),Ae(R.defaultModel),Te(R.recoveryDefault),Xe(R.attachmentsDefault))}).catch(()=>{}),()=>{x=!0}},[]),a.useEffect(()=>{let x=!1;return B.projectCommands(t).then(R=>{x||et(R)}).catch(()=>{}),()=>{x=!0}},[t]);const Ke=a.useMemo(()=>{if(!T.startsWith("/"))return null;const x=T.slice(1);return/\s/.test(x)?null:x},[T]),qe=a.useMemo(()=>{if(Ke===null)return[];const x=Ke.toLowerCase();return Ve.filter(R=>R.name.toLowerCase().includes(x))},[Ke,Ve]),Bt=Ke!==null&&!ke&&qe.length>0;a.useEffect(()=>{He(0)},[Ke]),a.useEffect(()=>{A(!1)},[Ke]);const D=a.useCallback(x=>{y(`/${x.name} `),requestAnimationFrame(()=>{var R;return(R=F.current)==null?void 0:R.focus()})},[]),te=a.useCallback(x=>{J(x),ee.current=x,zs(Ie.current??s,t,x)},[t,s]);a.useEffect(()=>{if(s&&s===as.current){wt.current=!1;return}let x=!1;return Ie.current=s??null,wt.current=!s,it.current=null,vt.current=!1,yt.current=!1,Ge.current=!1,M(null),z(!1),s&&n?(_(!0),S([]),n(s).then(({messages:R,total:Q,truncated:V})=>{x||($(V?Q-R.length:0),S(Y=>Dn(Wt(R),Y)))}).catch(()=>{x||M("Could not load this chat's history.")}).finally(()=>{x||_(!1)})):(S([]),_(!1)),s&&B.chatContext(t,s).then(R=>{x||!R||(ue({inputTokens:R.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:R.contextTokens,contextLimit:R.contextLimit}),We(R))}).catch(()=>{}),()=>{x=!0}},[t,s,n]);const oe=a.useCallback(async()=>{if(!(!s||!n)){try{const{messages:x,total:R,truncated:Q}=await n(s);S(Wt(x)),$(Q?R-x.length:0)}catch{M("Could not reload this chat's history.")}try{const x=await B.chatContext(t,s);x&&(ue({inputTokens:x.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:x.contextTokens,contextLimit:x.contextLimit}),We(x))}catch{}}},[s,n,t]),Qe=a.useCallback(x=>{if(!P)return;const R=k.findIndex(Se=>Se.id.split("#")[0]===x),Q=R>=0&&k[R].kind==="user";let V=R+1;if(Q){let Se=R-1;for(;Se>=0&&k[Se].kind!=="assistant";)Se--;V=Se+1}else for(;V<k.length&&(k[V].kind==="tool"||k[V].kind==="file");)V++;const Y=R>=0?k.slice(V):[],me=Y.filter(Se=>Se.kind==="tool").length;w({uuid:x,count:Y.length,toolCount:me,anchorIsUser:Q})},[P,k]),Ce=a.useCallback(async()=>{if(K){try{await(P==null?void 0:P(K.uuid)),await oe()}catch{throw new Error("Could not revert this chat.")}w(null)}},[K,P,oe]),[_e,za]=a.useState(null),cn=a.useRef(null);a.useEffect(()=>{if(!I||X||k.length===0)return;const x=`${s??""}:${I}`;if(cn.current===x)return;cn.current=x;const R=V=>V.some(Y=>Y.id.split("#")[0]===I),Q=()=>{Ze.current=!1,za(V=>({uuid:I,nonce:((V==null?void 0:V.nonce)??0)+1}))};if(R(k)){Q();return}if(L>0&&n){let V=!1;return n(s??"",0).then(({messages:Y})=>{if(V)return;const me=Wt(Y);if(!R(me)){q("That link points at a message that isn't in this chat any more.");return}S(Se=>Dn(me,Se)),$(0),Q()}).catch(()=>{V||q("Could not load the rest of this chat's history.")}),()=>{V=!0}}q("That link points at a message that isn't in this chat any more.")},[I,X,k,s,L,n]);const dn=a.useCallback(x=>(E==null?void 0:E(x))??`${window.location.origin}${window.location.pathname}#${da(x)}`,[E]),Ha=a.useMemo(()=>v&&P?{onFork:v,onRevert:Qe,contextLimit:ae==null?void 0:ae.contextLimit,linkTo:dn,focused:_e}:null,[v,P,Qe,ae==null?void 0:ae.contextLimit,dn,_e]);a.useEffect(()=>{const R=hi(s,t)??Et;R&&(J(R),ee.current=R)},[t,s,Et]),a.useEffect(()=>{s&&s===as.current||(ue(null),We(null))},[t,s]),a.useEffect(()=>{xi(s,t,T)},[T,s,t]),a.useEffect(()=>{if(W==null)return;const x=setTimeout(()=>q(null),8e3);return()=>clearTimeout(x)},[W]),a.useEffect(()=>{Wr(s,t,U),Gr(s,t,he?H.current:null),Kr(s,t,de)},[U,de,he,s,t]),a.useEffect(()=>{s&&Ne.setQueued(t,s,U,he?H.current:null,de)},[U,de,he,s,t,Ne]),a.useEffect(()=>{var x;(g||!s)&&((x=F.current)==null||x.focus())},[]);const un=a.useCallback((x,R)=>{const Q=R??[];(x||Q.length>0)&&(Ze.current=!0,S(V=>[...Le(V),{kind:"user",id:Ye(),content:x??"",...Q.length>0?{attachments:Q}:{}}])),C.current=null,H.current=null,Z(null),je([])},[]),hn=a.useCallback((x,R,Q,V)=>{R&&(H.current=R);const Y=x&&x.length>0?x:null,me=V??[];Q==="returned"&&(C.current!=null||le.current.length)&&q("Stopped — the queued message went back to the composer that stopped the turn.");const Se=me.length===le.current.length&&me.every((Xa,Za)=>{var wn;return Xa.id===((wn=le.current[Za])==null?void 0:wn.id)});C.current===Y&&Se||(C.current=Y,Y===null&&me.length===0&&(H.current=null),Z(Y),Se||je(me))},[]),mn=a.useRef(hn);mn.current=hn;const os=a.useCallback((x,R)=>{C.current=null,H.current=null,Z(null);const Q=R??le.current;Q.length>0&&ot(V=>{const Y=new Set(V.map(me=>me.id));return[...V,...Q.filter(me=>!Y.has(me.id))]}),je([]),y(V=>V.trim()?`${x}
8
8
  ${V}`:x),requestAnimationFrame(()=>{const V=F.current;V&&(V.style.height="auto",V.style.height=`${Math.min(V.scrollHeight,192)}px`,V.focus())})},[ot]),fn=a.useCallback((x,R)=>os(x,R),[os]),xn=a.useRef(fn);xn.current=fn;const gn=a.useRef(un);gn.current=un,nl({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,sessionRef:Ie,jobRef:it,pendingCancelRef:At,streamingRef:vt,awaitingSessionRef:yt,isNewSessionRef:wt,startedNotifiedRef:Ge,establishedHereRef:as,modelRef:ee,cancelledRef:ye,noticeThisTurnRef:Oe,seenInjectionsRef:rs,onQueuedFlushedRef:gn,onQueuedStateRef:mn,onQueuedReturnedRef:xn,setTurns:S,setStreaming:z,setUsage:ue,setSessionUsage:We,setError:M});const pn=a.useCallback(x=>{M(null),Ze.current=!0;const R=x.startsWith("/")?[]:tt.current;if(S(Y=>[...Le(Y),{kind:"user",id:Ye(),content:x,...R.length>0?{attachments:R}:{}}]),R.length>0&&(ot([]),tt.current=[]),F.current&&(F.current.style.height="auto"),z(!0),vt.current=!0,Oe.current=!1,it.current=null,At.current=!1,Ie.current===null&&(yt.current=!0),x.startsWith("/")){we.current=!0,Ne.sendCommand(t,x,Ie.current);return}const V=wt.current&&!we.current&&Me;we.current=!0,Ne.send(t,x,Ie.current,{preloadContext:V,model:ee.current??void 0,attachments:R.map(Y=>({id:Y.id,filename:Y.filename,kind:Y.kind}))})},[t,Me]),bn=a.useCallback(()=>{const x=T.trim();if(!(!x&&tt.current.length===0)){if(O){const Q=(C.current??x).startsWith("/")?[]:tt.current;Q.length>0&&(je(V=>{const Y=new Set(V.map(me=>me.id));return[...V,...Q.filter(me=>!Y.has(me.id))]}),ot([]),tt.current=[]),Z(V=>{const Y=x?V?`${V}
9
9
  ${x}`:x:V;return C.current=Y,(V==null||H.current==null)&&(H.current=qr()),Y}),y(""),F.current&&(F.current.style.height="auto");return}y(""),pn(x)}},[T,O,pn,tt,ot]),Wa=a.useCallback(()=>{const x=C.current;x==null&&le.current.length===0||os(x??"")},[os]),Ga=a.useCallback(()=>{C.current=null,H.current=null,Z(null),je([])},[]),Ka=a.useCallback(()=>{ye.current=!0,it.current?Ne.cancel(it.current):At.current=!0},[]),jn=a.useCallback(()=>{const x=Ie.current;x&&(vt.current||(z(!0),Ne.continueChat(t,x)))},[t]),qa=a.useMemo(()=>({enabled:(f==null?void 0:f.surfaceKilledTask)??(xe==null?void 0:xe.surfaceKilledTask)??!0,busy:O,onContinue:jn}),[t,f,xe,O,jn]),Qa=x=>{if(Bt){if(x.key==="ArrowDown"){x.preventDefault(),He(R=>(R+1)%qe.length);return}if(x.key==="ArrowUp"){x.preventDefault(),He(R=>(R-1+qe.length)%qe.length);return}if(x.key==="Tab"){x.preventDefault(),D(qe[ze]);return}if(x.key==="Enter"){const R=qe[ze];if(R&&R.name!==Ke){x.preventDefault(),D(R);return}}if(x.key==="Escape"){x.preventDefault(),A(!0);return}}x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),bn())},Ya=a.useCallback(x=>{y(Q=>Q.trim()?`${Q.trimEnd()} ${x}`:x);const R=F.current;R&&requestAnimationFrame(()=>{R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`,R.focus()})},[]),Ja=k.length===0&&!X;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:Ft,onScroll:ln,className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4 py-6",children:[N&&e.jsx(Ci,{trigger:N,projectSlug:t}),X&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}),Ja&&e.jsxs("div",{className:"mt-16 flex flex-col items-center text-center",children:[e.jsx("div",{className:"mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-accent-soft text-accent",children:e.jsx(Yt,{width:22,height:22})}),e.jsx("p",{className:"max-w-sm text-sm text-fg-subtle",children:h??"Start the conversation. Messages stream live from Claude and persist as a resumable session."})]}),L>0&&!X&&e.jsxs("p",{className:"pb-4 text-center text-2xs text-fg-subtle",children:[L.toLocaleString()," earlier"," ",L===1?"message is":"messages are"," not shown. They are still saved — reopening this chat always shows the most recent messages first."]}),e.jsx(Na.Provider,{value:ts,children:e.jsx(ka.Provider,{value:O,children:e.jsx(en.Provider,{value:gt,children:e.jsx(Ca.Provider,{value:Ut,children:e.jsx(Sa.Provider,{value:$s,children:e.jsx(va.Provider,{value:t,children:e.jsx(tn.Provider,{value:qa,children:e.jsx($a.Provider,{value:Ha,children:e.jsx("div",{className:"space-y-4",children:k.map(x=>e.jsx(Wo,{turn:x},x.id))})})})})})})})})})]})}),O&&e.jsx(xo,{}),e.jsx(eo,{running:Ss,activity:gt,tasks:ct,commands:jt,onReveal:Ut.focus,onCancel:s?Cs:void 0,stopping:ns,stopFailed:ks}),j&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:j})]})}),W&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-edge bg-surface-hover px-3 py-2 text-sm text-fg-muted",children:[e.jsx(Je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:W})]})}),he&&e.jsx(go,{text:U??"",attachments:de,onEdit:Wa,onClear:Ga}),e.jsx("div",{className:"border-t border-edge bg-surface/80 backdrop-blur",children:e.jsxs("div",{className:"pb-safe mx-auto w-full max-w-3xl px-4 pt-3",children:[Ue&&e.jsx(uo,{checked:Me,available:l,onChange:re}),e.jsx(ho,{models:Mt,model:De,onSelectModel:te,usage:ae,sessionUsage:ve,forkParent:u,onOpenForkParent:p}),st&&(Pe.length>0||lt)&&e.jsxs("div",{className:"mb-2",children:[Pe.length>1&&e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2 px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{"data-testid":"attachment-tray-count",children:[Pe.length," files attached"]}),e.jsx("button",{type:"button",onClick:bs,"data-testid":"attachment-tray-clear",title:"Unstage every file from this message",className:"rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active hover:text-danger",children:"Clear all"})]}),e.jsxs("div",{ref:xt,className:"flex max-h-[min(9rem,28vh)] flex-wrap gap-2 overflow-y-auto overscroll-contain","data-testid":"attachment-tray",children:[Pe.map(x=>e.jsx(yi,{attachment:x,onRemove:ps},x.id)),lt&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),"Uploading…"]})]})]}),e.jsxs("div",{className:`relative flex items-end gap-2 rounded-2xl border bg-surface-raised p-2 shadow-sm focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/20 ${Zt?"border-accent ring-2 ring-accent/30":"border-edge-strong"}`,onDragOver:st?ws:void 0,onDragLeave:st?vs:void 0,onDrop:st?ys:void 0,children:[Zt&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-accent-soft text-sm font-medium text-accent",children:"Drop files to attach"}),Bt&&e.jsx("div",{className:"menu bottom-full left-0 mb-2 max-h-64 w-full overflow-y-auto",role:"menu","aria-label":"Slash commands",children:qe.map((x,R)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${R===ze?"bg-surface-selected":""}`,onMouseEnter:()=>He(R),onMouseDown:Q=>{Q.preventDefault(),D(x)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",x.name]}),x.argumentHint&&e.jsx("span",{className:"shrink-0 text-fg-subtle",children:x.argumentHint}),x.description&&e.jsx("span",{className:"ml-auto truncate text-fg-muted",children:x.description})]})},x.name))}),e.jsx("textarea",{ref:F,className:"max-h-48 min-h-[40px] flex-1 resize-none bg-transparent px-2 py-2 text-sm outline-none",rows:1,autoCapitalize:"sentences",value:T,placeholder:O?"Queue a message to send next…":b??"Message Claude…",onChange:x=>{y(x.target.value);const R=x.target;R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`},onKeyDown:Qa,onPaste:st?js:void 0}),st&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:Dt,type:"file",multiple:!0,accept:bi(Pt.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:Ns}),e.jsx("button",{type:"button",onClick:()=>{var x;return(x=Dt.current)==null?void 0:x.click()},title:"Attach files","aria-label":"Attach files","data-testid":"attachment-button",className:"btn bg-transparent text-fg-muted hover:bg-surface-hover hover:text-fg",children:e.jsx(ur,{width:16,height:16})})]}),e.jsx(ci,{onText:Ya}),O?e.jsxs("button",{type:"button",onClick:Ka,title:"Stop generating","aria-label":"Stop",className:"btn bg-surface-active text-fg-muted hover:bg-surface-selected",children:[e.jsx(Fs,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}):e.jsxs("button",{type:"button",onClick:bn,disabled:!T.trim()&&Pe.length===0||lt,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(ra,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Send"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[e.jsx("kbd",{className:"font-sans",children:"Enter"})," to ",O?"queue":"send"," ·"," ",e.jsx("kbd",{className:"font-sans",children:"Shift+Enter"})," for newline"]}),e.jsx(po,{state:ie})]})]})}),e.jsx(Xs,{open:K!==null,wide:!0,dismissOnBackdrop:!1,title:"Revert this chat back to here?",confirmLabel:"Revert chat",message:K&&e.jsxs(e.Fragment,{children:[K.anchorIsUser&&e.jsx("p",{className:"mb-2",children:"This rewinds to the assistant's previous reply."}),e.jsxs("p",{children:[e.jsxs("span",{className:"font-medium text-fg",children:[K.count," message",K.count===1?"":"s"]})," ","will be removed",K.toolCount>0?e.jsxs(e.Fragment,{children:[", including"," ",e.jsxs("span",{className:"font-medium text-fg",children:[K.toolCount," tool call",K.toolCount===1?"":"s"]}),"."]}):"."]}),K.toolCount>0&&e.jsxs("p",{className:"mt-3 rounded-lg bg-warn-soft px-3 py-2 text-warn",children:[e.jsx("span",{className:"font-medium",children:"Those actions are not undone."})," Files written, PRs opened and messages sent stay as they are — only the conversation is rewound."]}),e.jsx("p",{className:"mt-3",children:"The removed messages are backed up, and this chat keeps its id."})]}),onConfirm:Ce,onClose:()=>w(null)})]})}function fl(t){var r;const s=t.untracked?"??":(t.status||"").trim(),n=((r=s[0])==null?void 0:r.toUpperCase())??"";return t.untracked||n==="?"?{label:"??",cls:"bg-surface-active text-fg-muted"}:n==="A"?{label:"A",cls:"bg-success-soft text-success"}:n==="D"?{label:"D",cls:"bg-danger-soft text-danger"}:n==="R"?{label:"R",cls:"bg-lineage-soft text-lineage"}:n==="M"?{label:"M",cls:"bg-warn-soft text-warn"}:{label:n||s||"•",cls:"bg-surface-active text-fg-muted"}}function xl({slug:t,status:s,onStatusChange:n,selectedFile:r,onSelectFile:i}){var Z;const[o,l]=a.useState(null),[c,m]=a.useState(null),u=i!==void 0,p=u?r??null:c,g=a.useCallback(C=>{u?i==null||i(C):m(C)},[u,i]),[h,b]=a.useState(""),[N,f]=a.useState(!1),[d,v]=a.useState(!1),[P,E]=a.useState(null),[I,k]=a.useState(null),[S,L]=a.useState(new Set),$=s.files,T=$.length,y=$.filter(C=>!S.has(C.path)).map(C=>C.path),F=y.length,O=F===$.length&&$.length>0,z=a.useCallback(C=>{L(H=>{const de=new Set(H);return de.has(C)?de.delete(C):de.add(C),de})},[]),X=a.useCallback(()=>L(new Set),[]),_=a.useCallback(()=>L(new Set($.map(C=>C.path))),[$]),j=a.useCallback(async()=>{const C=await B.gitProjectInfo(t).catch(()=>null);C&&l(C)},[t]);a.useEffect(()=>{j()},[j]);const M=a.useCallback(async()=>{const C=await B.gitStatus(t).catch(()=>null);C&&n(C)},[t,n]),W=p&&$.some(C=>C.path===p)?p:((Z=$[0])==null?void 0:Z.path)??null,q=$.find(C=>C.path===W)??null,ie=a.useCallback(async()=>{const C=h.trim();if(!(!C||N||y.length===0)){f(!0),E(null),k(null);try{const H=O?await B.gitCommit(t,C):await B.gitCommit(t,C,y);H.committed?(b(""),L(new Set),k(H.hash?`Committed ${H.hash.slice(0,7)}`:"Committed"),await M(),await j()):k(H.error??"Nothing to commit")}catch(H){E(H instanceof be?H.message:"Commit failed")}finally{f(!1)}}},[h,N,y,O,t,M,j]),G=(o==null?void 0:o.ahead)??0,K=(o==null?void 0:o.configured)??!1,w=K&&G>0&&!d,U=a.useCallback(async()=>{if(w){v(!0),E(null),k(null);try{const C=await B.gitPush(t);C.pushed?(k("Pushed to remote"),await j()):E(C.error??"Push failed")}catch(C){E(C instanceof be?C.message:"Push failed")}finally{v(!1)}}},[w,j,t]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-edge px-4 py-2.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-medium text-fg-muted",children:[e.jsx(ft,{width:14,height:14,className:"text-fg-subtle"}),s.branch??"—"]}),s.clean?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-fg-subtle",children:[e.jsx(Gt,{width:12,height:12}),"clean"]}):e.jsxs("span",{className:"rounded-md bg-warn-soft px-1.5 py-0.5 text-2xs font-medium text-warn",children:[T," uncommitted"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(vl,{info:o,onChanged:j}),e.jsxs("button",{type:"button",onClick:()=>void U(),disabled:!w,title:K?G>0?`Push ${G} commit${G===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx(hr,{width:13,height:13}),d?"Pushing…":"Push",K&&G>0&&e.jsxs("span",{className:"text-2xs font-semibold text-accent",children:["↑",G]})]})]})]}),(P||I)&&e.jsxs("div",{className:"px-4 pt-2",children:[P&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:P})]}),!P&&I&&e.jsx("p",{className:"text-xs text-fg-muted",children:I})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("div",{className:"flex w-full shrink-0 flex-col border-b border-edge lg:w-72 lg:border-b-0 lg:border-r",children:[e.jsxs("div",{className:"mb-1 mt-3 flex items-center justify-between gap-2 px-3",children:[e.jsx("span",{className:"section-label px-0",children:"Changed files"}),$.length>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[F,"/",$.length," selected"]}),e.jsx("button",{type:"button",onClick:O?_:X,className:"rounded px-1 py-0.5 font-medium text-accent hover:bg-accent/10",title:O?"Deselect all files":"Select all files",children:O?"None":"All"})]})]}),e.jsx("div",{className:"max-h-[35vh] overflow-y-auto px-2 pb-2 lg:max-h-none lg:flex-1",children:$.length===0?e.jsx("p",{className:"px-2 py-2 text-sm italic text-fg-subtle",children:"No uncommitted changes. Files you author surface here for a checkpoint."}):$.map(C=>e.jsx(gl,{file:C,active:W===C.path,selected:!S.has(C.path),onSelect:()=>g(C.path),onToggleSelect:()=>z(C.path)},C.path))}),e.jsxs("div",{className:"border-t border-edge p-3",children:[e.jsx("textarea",{rows:2,value:h,placeholder:"Commit message…",onChange:C=>b(C.target.value),className:"max-h-40 min-h-[44px] w-full resize-none rounded-lg border border-edge-strong bg-surface-sunken px-2.5 py-2 text-sm text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20"}),e.jsxs("button",{type:"button",onClick:()=>void ie(),disabled:!h.trim()||N||F===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:$.length===0?"Nothing to commit":F===0?"Select at least one file to commit":O?"Commit all changed files":`Commit ${F} selected file${F===1?"":"s"}`,children:[e.jsx(Gt,{width:13,height:13}),N?"Committing…":F>0&&!O?`Commit ${F} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(pl,{slug:t,file:q})})]})]})}function rn({file:t}){if(t.binary)return e.jsx("span",{className:"text-fg-subtle",children:"binary"});const{added:s,removed:n}=t;return s==null&&n==null?null:!s&&!n?e.jsx("span",{className:"text-fg-subtle",children:"0"}):e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono tabular",children:[s?e.jsxs("span",{className:"text-success",children:["+",s]}):null,n?e.jsxs("span",{className:"text-danger",children:["−",n]}):null]})}function gl({file:t,active:s,selected:n,onSelect:r,onToggleSelect:i}){const o=fl(t),l=t.untracked?"untracked":t.staged?"staged":"unstaged";return e.jsxs("div",{className:`mb-0.5 flex items-center gap-2 rounded-lg pl-2 pr-2.5 transition-colors ${s?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[e.jsx("input",{type:"checkbox",checked:n,onChange:i,"aria-label":`Stage ${t.path}`,title:n?"Included in commit — click to exclude":"Excluded — click to include",className:"h-3.5 w-3.5 shrink-0 cursor-pointer accent-[var(--accent-solid)]"}),e.jsxs("button",{type:"button",onClick:r,title:t.path,className:"flex min-w-0 flex-1 items-center gap-2 py-2 text-left text-sm",children:[e.jsx("span",{className:`inline-flex h-5 w-6 shrink-0 items-center justify-center rounded font-mono text-3xs font-semibold ${o.cls}`,children:o.label}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-mono text-xs text-fg-muted",children:t.path}),e.jsxs("span",{className:"flex items-center gap-2 text-3xs text-fg-subtle",children:[e.jsx("span",{children:l}),e.jsx(rn,{file:t})]})]})]})]})}function pl({slug:t,file:s}){const n=(s==null?void 0:s.path)??null,r=(s==null?void 0:s.untracked)??!1,[i,o]=a.useState(""),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{if(!n||r){o(""),u(null),c(!1);return}let g=!1;return c(!0),u(null),B.gitDiff(t,n).then(h=>{g||o(h)}).catch(h=>{g||u(h instanceof be?h.message:"Failed to load diff")}).finally(()=>{g||c(!1)}),()=>{g=!0}},[t,n,r]),!s)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-sm text-fg-subtle",children:"Select a file to view its diff."});if(r)return e.jsx(wl,{slug:t,file:s});if(l)return e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]});if(m)return e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:m})]})});if(!i.trim())return e.jsxs("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm text-fg-subtle",children:["No textual diff for this file",e.jsx("br",{}),"(e.g. a mode or binary change)."]});const p=i.split(`
10
10
  `);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(bl,{file:s}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre px-4 py-3 font-mono text-xs leading-relaxed",children:p.map((g,h)=>e.jsx("div",{className:jl(g),children:g||" "},h))})})]})}function bl({file:t}){return e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:t.path}),e.jsx(rn,{file:t})]})}function jl(t){return t.startsWith("+++")||t.startsWith("---")||t.startsWith("diff ")||t.startsWith("index ")?"text-fg-subtle":t.startsWith("@@")?"text-lineage":t.startsWith("+")?"bg-success-soft text-success":t.startsWith("-")?"bg-danger-soft text-danger":"text-fg-muted"}function wl({slug:t,file:s}){const n=s.path,[r,i]=a.useState(null),[o,l]=a.useState(!0),[c,m]=a.useState(null);a.useEffect(()=>{let p=!1;return l(!0),m(null),i(null),B.gitUntrackedFile(t,n).then(g=>{p||i(g)}).catch(g=>{p||m(g instanceof be?g.message:"Failed to load file")}).finally(()=>{p||l(!1)}),()=>{p=!0}},[t,n]);const u=e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:n}),e.jsx(rn,{file:s}),e.jsx("span",{className:"rounded bg-success-soft px-1.5 py-0.5 font-medium text-success",children:"new file · untracked"})]});return o?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]}):c||!r?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:c??"File not found."})]})}):r.kind==="image"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:B.gitUntrackedFileRawUrl(t,n),alt:n,className:"max-h-full max-w-full object-contain shadow-sm"})})]}):r.kind==="pdf"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(nn,{src:B.gitUntrackedFileRawUrl(t,n),filename:n,className:"h-full min-h-[480px] w-full"})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre-wrap break-words border-l-2 border-success-edge px-4 py-3 font-mono text-xs leading-relaxed text-fg-muted",children:r.content})})]})}function vl({info:t,onChanged:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(null),[l,c]=a.useState(!1),[m,u]=a.useState(null),[p,g]=a.useState(!1),h=a.useRef(!1);a.useEffect(()=>(h.current=!1,()=>{h.current=!0}),[]);const b=t==null?void 0:t.github,N=a.useCallback(async()=>{r(!0),u(null);try{const d=await B.githubConnect();o({userCode:d.userCode,verificationUri:d.verificationUri}),c(!0),h.current=!1;const v=Date.now()+d.expiresIn*1e3;let P=Math.max(1,d.interval)*1e3;const E=async()=>{if(!h.current){if(Date.now()>=v){c(!1),o(null),u("The code expired before authorization. Try again.");return}try{const I=await B.githubPoll(d.deviceCode);if(h.current)return;if(I.status==="authorized"){c(!1),o(null),await s();return}if(I.status==="error"){c(!1),o(null),u(I.error??"Authorization failed.");return}I.status==="slow_down"&&(P+=5e3),window.setTimeout(()=>void E(),P)}catch(I){if(h.current)return;c(!1),o(null),u(I instanceof be?I.message:"Polling failed.")}}};window.setTimeout(()=>void E(),P)}catch(d){u(d instanceof be?d.message:"Could not start the GitHub connection.")}finally{r(!1)}},[s]),f=a.useCallback(async()=>{g(!0);try{await B.githubDisconnect(),await s()}catch{}finally{g(!1)}},[s]);return b?b.configured?b.connected?e.jsxs("span",{className:"inline-flex items-center gap-2 text-2xs text-fg-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(Ts,{width:13,height:13}),"@",b.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void f(),disabled:p,className:"btn-subtle px-2 py-1 text-2xs",title:"Disconnect GitHub",children:p?"…":"Disconnect"})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[i?e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5 text-2xs text-fg-muted",children:[e.jsx("span",{className:"text-fg-muted",children:"Enter"}),e.jsx("code",{className:"rounded bg-surface-active px-1.5 py-0.5 font-mono text-xs font-semibold tracking-widest text-fg",children:i.userCode}),e.jsx("span",{className:"text-fg-muted",children:"at"}),e.jsxs("a",{href:i.verificationUri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-accent underline underline-offset-2 hover:text-accent-solid-hover",children:[e.jsx(aa,{width:11,height:11}),"github.com"]}),l&&e.jsx("span",{className:"text-fg-subtle",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void N(),disabled:n,className:"btn-ghost py-1.5 text-xs",title:"Authorize paddock to push to GitHub on your behalf (device flow).",children:[e.jsx(Ts,{width:13,height:13}),n?"Starting…":"Connect GitHub"]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-danger",children:[e.jsx(ge,{width:12,height:12}),m]})]}):e.jsxs("span",{className:"hidden items-center gap-1.5 text-2xs text-fg-subtle sm:inline-flex",title:"Set PADDOCK_GITHUB_CLIENT_ID on the server to enable in-app GitHub auth.",children:[e.jsx(Ts,{width:13,height:13}),"GitHub not configured"]}):null}function yl(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(Je,{width:12,height:12}),cls:"bg-warn-soft text-warn"}:t==="spawned"?{label:"Spawned",icon:e.jsx(ft,{width:12,height:12}),cls:"bg-lineage-soft text-lineage"}:t==="adopted"?{label:"Adopted",icon:e.jsx(Jt,{width:12,height:12}),cls:"bg-success-soft text-success"}:{label:"You",icon:e.jsx(Qt,{width:12,height:12}),cls:"bg-surface-active text-fg-muted"}}function Nl(t){switch(t){case"completed":return{label:"completed",cls:"bg-success-soft text-success"};case"failed":return{label:"failed",cls:"bg-danger-soft text-danger"};case"running":return{label:"running",cls:"bg-info-soft text-info"};case"cancelled":return{label:"cancelled",cls:"bg-surface-active text-fg-muted"};case"pending":return{label:"pending",cls:"bg-warn-soft text-warn"};default:return{label:t,cls:"bg-surface-active text-fg-muted"}}}function kl(t){if(t.durationSeconds!=null)return ds(t.durationSeconds*1e3)??"—";if(t.status==="running"){const s=Date.parse(t.startedAt);if(Number.isFinite(s))return`${ds(Date.now()-s)??"—"}…`}return"—"}function Ds(t){return t.origin!=="human"&&t.origin!=="adopted"}function Cl(t){return t.origin==="scheduled"?t.schedule?`schedule · ${t.schedule}`:"schedule":t.origin==="spawned"?t.depth>1?`spawned · ${t.depth} levels deep`:"spawned by another chat":t.origin==="adopted"?"adopted from the Claude Code CLI":"you"}function Sl({run:t,title:s,onOpen:n}){var c,m;const r=yl(t.origin),i=Nl(t.status),o=t.sessionId!=null,l=((c=t.prompt)==null?void 0:c.trim())||((m=t.summary)==null?void 0:m.trim())||s;return e.jsxs("button",{type:"button",onClick:o?n:void 0,disabled:!o,"data-run-origin":t.origin,"data-run-new":t.isNew?"true":void 0,className:`flex w-full items-start gap-3 border-t border-edge px-4 py-3 text-left first:border-t-0 ${o?"hover:bg-surface-hover":"cursor-default"} ${t.isNew?"bg-accent-soft":""}`,children:[e.jsx("span",{className:"mt-1.5 w-1.5 shrink-0",children:t.isNew&&e.jsx("span",{"data-run-unread":"true","aria-label":"New since your last visit",title:"Ran while you were away",className:"block h-1.5 w-1.5 rounded-full bg-accent-solid"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-2xs font-medium ${r.cls}`,children:[r.icon,r.label]}),e.jsx("span",{className:`inline-flex items-center rounded px-1.5 py-0.5 text-2xs font-medium ${i.cls}`,children:i.label})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-fg",children:l}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-fg-muted",children:Cl(t)})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-0.5 text-xs text-fg-muted",children:[e.jsx("span",{title:new Date(t.startedAt).toLocaleString(),children:St(t.startedAt)}),e.jsx("span",{className:"font-mono tabular",children:kl(t)}),e.jsx("span",{className:"font-mono text-fg-subtle",title:"Per-run cost is coming soon",children:"—"})]})]})}function $l({slug:t,state:s,chats:n,onOpenChat:r}){const{data:i,loading:o,error:l,refresh:c,markSeen:m}=s,[u,p]=a.useState("unattended");a.useEffect(()=>{m()},[t]);const g=a.useMemo(()=>{const d=new Map;for(const v of n)d.set(v.sessionId,v.name);return v=>v&&d.get(v)||(v?v.slice(0,8):"unknown chat")},[n]),h=(i==null?void 0:i.runs)??[],b=a.useMemo(()=>h.filter(Ds).length,[h]),N=a.useMemo(()=>u==="unattended"?h.filter(Ds):h,[h,u]),f=a.useMemo(()=>h.filter(d=>d.isNew&&Ds(d)).length,[h]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-edge px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Run history"}),e.jsx("button",{type:"button",onClick:()=>void c(),className:"text-xs text-fg-muted hover:text-fg",children:"Refresh"})]}),e.jsxs("div",{className:"inline-flex overflow-hidden rounded-lg border border-edge text-xs",children:[e.jsxs(zn,{active:u==="unattended",onClick:()=>p("unattended"),children:["Unattended",b>0?` (${b})`:""]}),e.jsx(zn,{active:u==="all",onClick:()=>p("all"),children:"All"})]})]}),f>0&&e.jsxs("div",{"data-since-last-visit":f,className:"border-b border-accent-edge bg-accent-soft px-4 py-2 text-sm text-fg",children:[e.jsxs("span",{className:"font-medium",children:[f," new ",f===1?"run":"runs"]})," ","ran while you were away."]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:l?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-danger",children:l}):o&&h.length===0?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-fg-muted",children:"Loading run history…"}):N.length===0?e.jsx(Tl,{filter:u,hasAny:h.length>0}):e.jsx("div",{children:N.map(d=>e.jsx(Sl,{run:d,title:g(d.sessionId),onOpen:()=>d.sessionId&&r(d.sessionId)},d.jobId))})})]})}function zn({active:t,onClick:s,children:n}){return e.jsx("button",{type:"button",onClick:s,className:`motion-fast px-2.5 py-1 font-medium transition-colors ${t?"bg-accent-soft text-accent":"text-fg-muted hover:text-fg"}`,children:n})}function Tl({filter:t,hasAny:s}){return e.jsxs("div",{className:"px-4 py-12 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-fg",children:t==="unattended"?"No unattended runs yet":"No runs yet"}),e.jsx("p",{className:"mx-auto mt-1 max-w-sm text-xs text-fg-muted",children:t==="unattended"?s?"Scheduled and spawned runs will show up here. Switch to All to see your own runs.":"Scheduled and spawned runs — the ones that happen while you're not watching — will show up here.":"Runs appear here once Claude starts finishing turns."})]})}function Il(t){const[s,n]=a.useState(null),[r,i]=a.useState(!0),[o,l]=a.useState(null),[c,m]=a.useState(!1),u=a.useCallback(async()=>{i(!0),m(!1);try{const h=await B.projectRuns(t);n(h),l(null)}catch(h){l(h instanceof Error?h.message:"Failed to load run history")}finally{i(!1)}},[t]);a.useEffect(()=>{u()},[u]);const p=a.useCallback(async()=>{m(!0),await B.markRunsSeen(t).catch(()=>{})},[t]),g=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:r,error:o,newUnattended:g,refresh:u,markSeen:p}}function Rl({slug:t,name:s}){const[n,r]=a.useState(null),[i,o]=a.useState(null),[l,c]=a.useState(!0);return a.useEffect(()=>{let m=!1;return c(!0),o(null),r(null),B.getProjectFile(t,s).then(u=>{m||r(u)}).catch(u=>{m||o(u instanceof Error?u.message:"Failed to load file")}).finally(()=>{m||c(!1)}),()=>{m=!0}},[t,s]),l?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-4 w-1/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}):i||!n?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:i??"File not found."})]})}):n.kind==="image"?e.jsx(Ml,{slug:t,name:n.name}):n.kind==="pdf"?e.jsx(Al,{slug:t,name:n.name}):n.kind==="html"?e.jsx(El,{name:n.name,content:n.content}):n.kind==="text"?e.jsx("div",{className:"overflow-auto p-6",children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-lg border border-edge bg-surface-sunken p-4 font-mono text-xs leading-relaxed text-fg",children:n.content})}):e.jsx("article",{className:"prose-doc mx-auto max-w-3xl px-6 py-6",children:e.jsx(Xt,{mermaid:!0,children:n.content})})}function El({name:t,content:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx(Dl,{}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-fg-muted",children:t})," renders in a sandboxed frame (scripts allowed, isolated from the app)."]})]}),e.jsx("iframe",{title:t,sandbox:"allow-scripts",srcDoc:s,className:"html-preview min-h-[480px] w-full flex-1"})]})}function Ml({slug:t,name:s}){const[n,r]=a.useState(!1);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",style:{background:"repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px"},children:n?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:B.projectFileRawUrl(t,s),alt:s,onError:()=>r(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function Al({slug:t,name:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(nn,{src:B.projectFileRawUrl(t,s),filename:s,className:"h-full min-h-[480px] w-full"})})]})}function Dl(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"})})}function Pl({project:t,path:s,onNavigate:n,onTogglePin:r}){const i=t.slug,[o,l]=a.useState(null),[c,m]=a.useState(!1),[u,p]=a.useState(null),[g,h]=a.useState(!0);a.useEffect(()=>{let d=!1;return h(!0),p(null),l(null),m(!1),B.listProjectDir(i,s).then(v=>{d||(v.kind==="file"?m(!0):l(v))}).catch(v=>{d||p(v instanceof Error?v.message:"Failed to load files")}).finally(()=>{d||h(!1)}),()=>{d=!0}},[i,s]);const b=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",N=e.jsx(_l,{path:s,isFile:c,onNavigate:n});if(g)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[N,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(d=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},d))})]})});if(u)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[N,e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:u})]})]})});if(c){const d=t.pinned.includes(s);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge px-4 py-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:N}),e.jsxs("button",{onClick:()=>r(s),className:`ml-auto inline-flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors ${d?"bg-accent/10 text-accent":"text-fg-muted hover:bg-surface-hover"}`,title:d?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(us,{width:13,height:13}),d?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(Rl,{slug:i,name:s})})]})}const f=(o==null?void 0:o.entries)??[];return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[N,f.length===0&&s===""?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-fg-subtle",children:"No files yet. Files Claude writes (and sweep-curated OVERVIEW.md) will appear here."})}):e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-edge",children:[s!==""&&e.jsxs("button",{onClick:()=>n(b),className:"flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover",children:[e.jsx(Os,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-sm text-fg-muted",children:".."})]}),f.length===0&&s!==""&&e.jsx("div",{className:"px-3 py-2.5 text-sm italic text-fg-subtle",children:"This folder is empty."}),f.map((d,v)=>{const P=s?`${s}/${d.name}`:d.name,E=d.kind==="dir",I=t.pinned.includes(P),k=!E,S=v>0||s!==""?"border-t border-edge":"";return e.jsxs("div",{className:`group/file flex items-center gap-2 px-3 py-2.5 transition-colors hover:bg-surface-hover ${S}`,children:[e.jsxs("button",{onClick:()=>n(P),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[E?e.jsx(Os,{width:15,height:15,className:"shrink-0 text-accent/80"}):e.jsx(qt,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:`truncate font-mono text-sm ${E?"font-medium text-fg":"text-fg"}`,children:d.name}),E&&e.jsx(It,{width:14,height:14,className:"ml-auto shrink-0 text-fg-subtle"})]}),k&&e.jsxs("button",{type:"button","aria-label":I?`Unpin ${d.name}`:`Pin ${d.name}`,title:I?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>r(P),className:`flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-2xs font-medium transition ${I?"bg-accent/10 text-accent":"text-fg-subtle opacity-0 hover:bg-surface-active hover:text-fg-muted focus:opacity-100 group-hover/file:opacity-100"}`,children:[e.jsx(us,{width:12,height:12}),I?"Pinned":"Pin"]})]},d.name)})]})]})})}function _l({path:t,isFile:s,onNavigate:n}){const r=t?t.split("/"):[];return e.jsxs("nav",{"aria-label":"File path",className:"mb-3 flex flex-wrap items-center gap-x-1 gap-y-0.5 text-sm",children:[e.jsx(Hn,{label:"Files",isLast:r.length===0,onClick:()=>n("")}),r.map((i,o)=>{const l=o===r.length-1,c=r.slice(0,o+1).join("/");return e.jsxs("span",{className:"flex items-center gap-x-1",children:[e.jsx(It,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx(Hn,{label:i,isLast:l,mono:!0,muted:l&&s,onClick:()=>n(c)})]},c)})]})}function Hn({label:t,isLast:s,mono:n,muted:r,onClick:i}){const o=n?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${o} font-medium ${r?"text-fg-muted":"text-fg"}`,children:t}):e.jsx("button",{type:"button",onClick:i,className:`${o} rounded text-fg-muted transition-colors hover:text-accent`,children:t})}function fe({children:t}){return e.jsx("p",{className:"mt-1 text-xs leading-snug text-fg-muted",children:t})}function Wn({children:t}){return e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t})]})}function $t({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("dd",{className:"mt-0.5 text-sm text-fg-muted",children:s})]})}function Ll({project:t,onDeleted:s}){const[n,r]=a.useState(!1);if(ma(t.slug))return null;const i=Qr(t);return e.jsxs(mt,{title:"Danger zone",description:i?"Deleting unlinks this project: Paddock’s notes, settings and chats go, and the directory it works in is left untouched.":"Deleting removes this project’s directory — its notes, settings, chats and files.",children:[e.jsxs("button",{type:"button",className:"btn btn-danger gap-1.5",onClick:()=>r(!0),children:[e.jsx(ms,{width:14,height:14}),"Delete project…"]}),n&&e.jsx(Yr,{project:t,open:!0,onClose:()=>r(!1),onDeleted:s})]})}function Fl({project:t}){return e.jsx(mt,{title:"Derived",description:"Read-only state Claude and sweeps maintain.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3 sm:grid-cols-2",children:[e.jsx($t,{label:"Overview",value:t.hasOverview?e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(Gt,{width:12,height:12})," OVERVIEW.md written by a sweep"]}):e.jsx("span",{className:"text-fg-subtle",children:"No OVERVIEW.md yet"})}),e.jsx($t,{label:"Pinned files",value:t.pinned.length>0?e.jsx("span",{className:"flex flex-wrap gap-1.5",children:t.pinned.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-surface-active px-1.5 py-0.5 font-mono text-xs text-fg-muted",children:[e.jsx(us,{width:11,height:11,className:"text-accent"}),s]},s))}):e.jsx("span",{className:"text-fg-subtle",children:"None — pin files from the Files tab"})})]})})}function Ol({project:t,onSaved:s}){const[n,r]=a.useState(""),[i,o]=a.useState(!1),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{r(""),o(!1),u(null)},[t.slug,t.managed]),!t.managed||t.path)return e.jsx(mt,{title:"Backing",description:t.managed?"Claude works in the directory below, and Paddock curates this project's notes there.":"Claude works in the directory below. Paddock does not write project files into it — its notes stay in the project's own folder.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3",children:[t.repo&&e.jsx($t,{label:t.path?"Repository (recorded)":"Repository",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.repo})}),e.jsx($t,{label:"Working directory",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.workingDir})})]})});const p=n.trim(),g=p.length>0&&!Ul(p),h=async()=>{if(!(!p||g)){c(!0),u(null);try{const b=await B.promoteProject(t.slug,p);s(b),o(!1),r("")}catch(b){u(b instanceof be?b.message:"Failed to promote project")}finally{c(!1)}}};return e.jsxs(mt,{title:"Repository backing",description:"Notebook project. Promote it to repo-backed to work directly in an external git repo — keeping all of this project's chats and notes.",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Git repository URL"}),e.jsx("input",{className:"input font-mono text-sm",value:n,onChange:b=>{r(b.target.value),o(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":g,"aria-label":"Git repository URL"}),g?e.jsx(fe,{children:e.jsx("span",{className:"text-danger",children:"That doesn’t look like a git URL (https://, git@…, ssh://, git://)."})}):e.jsxs(fe,{children:["Paddock clones this repo into a nested checkout and points Claude at it. The repo’s own ",e.jsx("code",{children:"CLAUDE.md"})," and git tooling take over."]})]}),m&&e.jsx("p",{className:"mt-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:m}),i?e.jsxs("div",{className:"mt-4 rounded-lg border border-warn-edge bg-warn-soft p-3",children:[e.jsxs("p",{className:"flex items-start gap-1.5 text-sm leading-snug text-warn",children:[e.jsx(ge,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["Promote ",e.jsx("span",{className:"font-semibold",children:t.name})," to repo-backed? This clones ",e.jsx("span",{className:"break-all font-mono",children:p}),", moves Claude into that checkout, and stops curating this project’s ",e.jsx("code",{children:"CLAUDE.md"})," (the repo’s own takes over). Your ",e.jsx("span",{className:"font-medium",children:"chats and notes are kept"}),". This is ",e.jsx("span",{className:"font-medium",children:"one-way"}),"."]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"btn-primary",disabled:l,onClick:h,children:l?"Promoting…":"Yes, promote"}),e.jsx("button",{type:"button",className:"btn-subtle",disabled:l,onClick:()=>o(!1),children:"Cancel"})]})]}):e.jsx("button",{type:"button",className:"btn-primary mt-4",disabled:l||!p||g,onClick:()=>o(!0),children:"Promote to repo-backed…"})]})}function Ul(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}const Bl=["idea","active","paused","blocked","done","abandoned"];function Ps(t,s,n){const r={};return t!==""&&(r.overviewMaxTokens=Number(t)),s!==""&&(r.changelogMaxTokens=Number(s)),n!==""&&(r.claudeMaxTokens=Number(n)),Object.keys(r).length>0?r:null}const Gn=[{value:"default",label:"Default (ask each time)"},{value:"acceptEdits",label:"Accept edits"},{value:"plan",label:"Plan only"},{value:"bypassPermissions",label:"Bypass all (use with care)"}],zt="loading…";function Vl({project:t,onSaved:s,onDeleted:n}){var ze,He,ke;const[r,i]=a.useState(t.name),[o,l]=a.useState(t.summary),[c,m]=a.useState(t.domain.join(", ")),[u,p]=a.useState(t.group??""),[g,h]=a.useState(t.status),[b,N]=a.useState(t.visibility),[f,d]=a.useState(t.links??[]),[v,P]=a.useState(t.model),[E,I]=a.useState(t.models??[]),[k,S]=a.useState(t.permissionMode),[L,$]=a.useState(String(t.maxTurns)),[T,y]=a.useState(t.docker),[F,O]=a.useState(t.driveMode??""),[z,X]=a.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[_,j]=a.useState(((ze=t.curation)==null?void 0:ze.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[M,W]=a.useState(((He=t.curation)==null?void 0:He.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[q,ie]=a.useState(((ke=t.curation)==null?void 0:ke.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[G,K]=a.useState([]),[w,U]=a.useState(null),[Z,C]=a.useState(null),[H,de]=a.useState(null),[je,le]=a.useState(!1),[he,ye]=a.useState(null),[Oe,Me]=a.useState(0);a.useEffect(()=>{var A,ee,ae;i(t.name),l(t.summary),m(t.domain.join(", ")),p(t.group??""),h(t.status),N(t.visibility),d(t.links??[]),P(t.model),I(t.models??[]),S(t.permissionMode),$(String(t.maxTurns)),y(t.docker),O(t.driveMode??""),X(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),j(((A=t.curation)==null?void 0:A.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),W(((ee=t.curation)==null?void 0:ee.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),ie(((ae=t.curation)==null?void 0:ae.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),ye(null)},[t]),a.useEffect(()=>{let A=!1;return B.getModels().then(ee=>{A||(K(ee.models),U(ee.driveModeDefault),C(ee.maxSpawnDepthDefault),de(ee.curationDefault))}).catch(()=>{}),()=>{A=!0}},[]);const re=a.useMemo(()=>f.map(A=>({label:A.label.trim(),url:A.url.trim()})).filter(A=>A.url.length>0),[f]),Ue=a.useMemo(()=>c.split(",").map(A=>A.trim()).filter(Boolean),[c]),we=a.useMemo(()=>({name:r.trim(),status:g,group:u,summary:o.trim(),domain:Ue,visibility:b,links:re,model:v,models:E.length>0?E:null,permissionMode:k,maxTurns:Number(L),docker:T,driveMode:F===""?null:F,maxSpawnDepth:z===""?null:Number(z),curation:Ps(_,M,q)}),[r,g,u,o,Ue,b,re,v,E,k,L,T,F,z,_,M,q]),$e=a.useMemo(()=>{var ee,ae,ue;const A={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(ve=>({label:ve.label,url:ve.url})),model:t.model,models:t.models&&t.models.length>0?t.models:null,permissionMode:t.permissionMode,maxTurns:t.maxTurns,docker:t.docker,driveMode:t.driveMode??null,maxSpawnDepth:t.maxSpawnDepth??null,curation:Ps(((ee=t.curation)==null?void 0:ee.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ae=t.curation)==null?void 0:ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((ue=t.curation)==null?void 0:ue.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify(we)!==JSON.stringify(A)},[we,t]),ne=we.name.length===0,Be=Number(L),Ae=!Number.isInteger(Be)||Be<1||Be>1e3,De=Number(z),J=z!==""&&(!Number.isInteger(De)||De<0||De>8),xe=A=>A!==""&&(!Number.isInteger(Number(A))||Number(A)<1),Te=xe(_)||xe(M)||xe(q),Rt=async A=>{if(A.preventDefault(),!(ne||Ae||J||Te)){le(!0),ye(null);try{const ee=await B.updateProject(t.slug,we);s(ee),Me(ae=>ae+1)}catch(ee){ye(ee instanceof be?ee.message:"Failed to save changes")}finally{le(!1)}}},Xe=w===null?zt:w==="session"?"Session":"Batch",Ve=E.length>0?G.filter(A=>E.includes(A.id)):G,et=(A,ee)=>I(ae=>ee?[...ae.filter(ue=>ue!==A),A]:ae.filter(ue=>ue!==A));return e.jsxs("form",{onSubmit:Rt,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-edge bg-surface/80 px-4 py-2.5 backdrop-blur sm:px-6",children:[e.jsx("span",{className:"text-sm font-medium text-fg-muted",children:"Settings"}),$e&&!je&&e.jsx("span",{className:"text-xs text-warn",children:"Unsaved changes"}),Oe>0&&!$e&&!je&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-success",children:[e.jsx(Gt,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:je||!$e||ne||Ae||J||Te,children:je?"Saving…":"Save changes"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[he&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:he}),e.jsxs(mt,{title:"Identity & metadata",description:"How this project is named, grouped, and described across the app.",children:[e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",value:r,onChange:A=>i(A.target.value),placeholder:"Display name","aria-invalid":ne}),ne&&e.jsx(fe,{children:"Name can’t be empty."})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary"}),e.jsx("input",{className:"input",value:o,onChange:A=>l(A.target.value),placeholder:"One line on what this project is about"})]}),e.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Status"}),e.jsx("select",{className:"input capitalize",value:g,onChange:A=>h(A.target.value),children:Bl.map(A=>e.jsx("option",{value:A,className:"capitalize",children:A},A))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:u,onChange:A=>p(A.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Bs.map(A=>e.jsx("option",{value:A.slug,children:A.label},A.slug)),u&&!Bs.some(A=>A.slug===u)&&e.jsx("option",{value:u,children:u})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Visibility"}),e.jsxs("select",{className:"input capitalize",value:b,onChange:A=>N(A.target.value),children:[e.jsx("option",{value:"public",children:"Public"}),e.jsx("option",{value:"private",children:"Private"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:c,onChange:A=>m(A.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),f.length===0&&e.jsx("p",{className:"mb-2 text-xs italic text-fg-subtle",children:"No links yet."}),e.jsx("div",{className:"space-y-2",children:f.map((A,ee)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:A.label,onChange:ae=>d(ue=>ue.map((ve,We)=>We===ee?{...ve,label:ae.target.value}:ve)),placeholder:"Label","aria-label":`Link ${ee+1} label`}),e.jsx("input",{className:"input flex-1",value:A.url,onChange:ae=>d(ue=>ue.map((ve,We)=>We===ee?{...ve,url:ae.target.value}:ve)),placeholder:"https://…","aria-label":`Link ${ee+1} URL`}),e.jsx("button",{type:"button",onClick:()=>d(ae=>ae.filter((ue,ve)=>ve!==ee)),"aria-label":`Remove link ${ee+1}`,title:"Remove link",className:"motion-fast flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-fg-subtle transition-[color,background-color,border-color,box-shadow,transform] hover:bg-danger-soft hover:text-danger",children:e.jsx(ms,{width:14,height:14})})]},ee))}),e.jsxs("button",{type:"button",onClick:()=>d(A=>[...A,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(rt,{width:13,height:13}),"Add link"]})]}),e.jsxs("dl",{className:"mt-4 grid grid-cols-2 gap-x-4 gap-y-3 border-t border-edge pt-4 sm:grid-cols-3",children:[e.jsx($t,{label:"Slug",value:ma(t.slug)?e.jsx("span",{className:"italic text-fg-subtle",title:"The root workspace has no slug",children:"(root)"}):e.jsx("span",{className:"font-mono",children:t.slug})}),e.jsx($t,{label:"Started",value:t.started})]})]}),e.jsx(mt,{title:"Claude",description:"How Claude runs in this workspace. Changes take effect on the next turn.",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-4",children:[e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsxs("select",{className:"input",value:v,onChange:A=>P(A.target.value),children:[!Ve.some(A=>A.id===v)&&e.jsx("option",{value:v,children:v}),Ve.map(A=>e.jsx("option",{value:A.id,children:A.label},A.id))]})]}),e.jsx(fe,{children:"Larger context windows (Opus/Fable/Sonnet: 1M; Haiku: 200K) fit longer chats."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsxs("select",{className:"input",value:k,onChange:A=>S(A.target.value),children:[!Gn.some(A=>A.value===k)&&e.jsx("option",{value:k,children:k}),Gn.map(A=>e.jsx("option",{value:A.value,children:A.label},A.value))]})]}),k==="bypassPermissions"?e.jsx(Wn,{children:"Claude runs every tool without asking — it can edit files and run commands unprompted."}):e.jsx(fe,{children:"How much Claude asks before acting."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,max:1e3,step:1,className:"input",value:L,onChange:A=>$(A.target.value),"aria-invalid":Ae})]}),Ae?e.jsx(fe,{children:e.jsx("span",{className:"text-danger",children:"Must be a whole number 1–1000."})}):e.jsx(fe,{children:"Upper bound on agent turns in a single run."})]}),e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Docker sandbox"}),e.jsxs("label",{className:"mt-1 flex cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:T,onChange:A=>y(A.target.checked)}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Run Claude in a Docker sandbox"})]}),T?e.jsx(Wn,{children:"Requires a working Docker daemon on the box, or Claude won’t start."}):e.jsx(fe,{children:"Isolate Claude's tool calls in a container."})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Offered models"}),G.length===0?e.jsx("p",{className:"mt-1 text-xs italic text-fg-subtle",children:"Loading the instance model list…"}):e.jsx("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-1.5",children:G.map(A=>{const ee=E.length===0||E.includes(A.id);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 text-sm text-fg-muted",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:ee,onChange:ae=>{E.length===0?I(ae.target.checked?[]:G.filter(ue=>ue.id!==A.id).map(ue=>ue.id)):et(A.id,ae.target.checked)},"aria-label":A.label}),e.jsx("span",{children:A.label})]},A.id)})}),E.length===0?e.jsx(fe,{children:"Offering all instance models. Uncheck any to restrict this project's picker to a subset; the model default above is then constrained to it."}):e.jsxs(fe,{children:["Restricting this project's picker to ",E.length," of ",G.length," ","instance models."," ",e.jsx("button",{type:"button",onClick:()=>I([]),className:"font-medium text-accent hover:underline",children:"Offer all instance models"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Drive mode"}),e.jsxs("select",{className:"input",value:F,onChange:A=>O(A.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",Xe,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),F===""&&w===null?e.jsx(fe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the box-wide drive-mode default…"})}):F===""?e.jsxs(fe,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Xe}),". ",e.jsx("span",{className:"font-medium",children:"Session"})," enables cross-turn autonomy (ScheduleWakeup / ",e.jsx("code",{children:"/loop"}),"); ",e.jsx("span",{className:"font-medium",children:"Batch"})," ","is the legacy one-shot path."]}):e.jsxs(fe,{children:["Overriding the global default."," ",e.jsx("button",{type:"button",onClick:()=>O(""),className:"font-medium text-accent hover:underline",children:"Reset to global default"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsxs("select",{className:"input",value:z,onChange:A=>X(A.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",Z??zt,")"]}),e.jsx("option",{value:"0",children:"0 — no spawned children get tools"}),e.jsx("option",{value:"1",children:"1 — children can report back (grandchildren can't)"}),e.jsx("option",{value:"2",children:"2"}),e.jsx("option",{value:"3",children:"3"}),e.jsx("option",{value:"4",children:"4"})]})]}),z===""&&Z===null?e.jsx(fe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance max-spawn-depth default…"})}):z===""?e.jsxs(fe,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Z}),". A chat spawned via ",e.jsx("code",{children:"create_chat"}),"/",e.jsx("code",{children:"fork_chat"})," gets the self-management tools (so it can ",e.jsx("code",{children:"send_message"})," back to its parent and spawn its own) only while its depth stays within this bound."," ",e.jsx("span",{className:"font-medium",children:"0"})," disables spawned tooling entirely."]}):e.jsxs(fe,{children:["Overriding the instance default."," ",e.jsx("button",{type:"button",onClick:()=>X(""),className:"font-medium text-accent hover:underline",children:"Reset to instance default"}),"."]})]})]})}),e.jsxs(mt,{title:"Curation budgets",description:"Per-file token limits the post-turn sweeper keeps this project's OVERVIEW.md, CHANGELOG.md and CLAUDE.md under. Leave a field blank to inherit the instance default.",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"OVERVIEW.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.overviewMaxTokens)??zt})`,value:_,onChange:A=>j(A.target.value),"aria-label":"OVERVIEW.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CHANGELOG.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.changelogMaxTokens)??zt})`,value:M,onChange:A=>W(A.target.value),"aria-label":"CHANGELOG.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CLAUDE.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.claudeMaxTokens)??zt})`,value:q,onChange:A=>ie(A.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),Te?e.jsx(fe,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):Ps(_,M,q)?e.jsxs(fe,{children:["Overriding the instance defaults",H&&e.jsxs(e.Fragment,{children:[" ","(",H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens,")"]})," ","for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{j(""),W(""),ie("")},className:"font-medium text-accent hover:underline",children:"Reset all to instance defaults"}),". Repo-backed projects never have their CLAUDE.md curated, so that budget is moot for them."]}):H===null?e.jsx(fe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance curation budgets…"})}):e.jsxs(fe,{children:["Inheriting the instance defaults:"," ",e.jsxs("span",{className:"tabular font-medium text-fg",children:[H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens]})," ","tokens (OVERVIEW/CHANGELOG/CLAUDE). Lower a budget to shrink the context this project injects into every chat."]})]}),e.jsx(Ol,{project:t,onSaved:s}),e.jsx(Fl,{project:t}),e.jsx(Ll,{project:t,onDeleted:n})]})})]})}const zl=/^[A-Za-z0-9._-]+$/,Hl={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},Wl={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},Gl=[{value:"",label:"Default (fleet default)"},{value:"acceptEdits",label:"Accept edits"},{value:"plan",label:"Plan only"},{value:"default",label:"Ask each time"},{value:"bypassPermissions",label:"Bypass all (use with care)"}],Kl={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},ql=["read","write","web","orchestration","browser"];function Ql(t,s){return{name:"",type:t,scheduleKind:"interval",expr:"",event:s,path:"",promptMode:"inline",prompt:"",promptFile:"",resumeSession:!1,allowedTools:new Set,permissionMode:"",model:"",maxTurns:"",maxSpawnDepth:"",enabled:!1}}function Yl(t){const s=t.trigger,n=t.run;return{name:t.name,type:s.type,scheduleKind:s.type==="schedule"&&s.interval!==void 0?"interval":"cron",expr:s.type==="schedule"?s.cron!==void 0?s.cron:s.interval??"":"",event:s.type==="event"?s.on:"onArchive",path:s.type==="webhook"?s.path:"",promptMode:n.promptFile?"file":"inline",prompt:n.prompt??"",promptFile:n.promptFile??"",resumeSession:n.session==="resume",allowedTools:new Set(n.tools??[]),permissionMode:n.permissionMode??"",model:n.model??"",maxTurns:n.maxTurns!=null?String(n.maxTurns):"",maxSpawnDepth:n.maxSpawnDepth!=null?String(n.maxSpawnDepth):"",enabled:t.enabled===!0}}function Jl(t){let s;t.type==="event"?s={type:"event",on:t.event}:t.type==="webhook"?s={type:"webhook",path:t.path.trim()}:s=t.scheduleKind==="cron"?{type:"schedule",cron:t.expr.trim()}:{type:"schedule",interval:t.expr.trim()};const n={session:t.resumeSession?"resume":"new",tools:[...t.allowedTools]};t.promptMode==="file"?n.promptFile=t.promptFile.trim():n.prompt=t.prompt,t.permissionMode&&(n.permissionMode=t.permissionMode),t.model.trim()&&(n.model=t.model.trim());const r=Number(t.maxTurns);t.maxTurns.trim()&&Number.isFinite(r)&&r>0&&(n.maxTurns=Math.floor(r));const i=Number(t.maxSpawnDepth);return t.maxSpawnDepth.trim()&&Number.isFinite(i)&&i>=0&&(n.maxSpawnDepth=Math.floor(i)),{trigger:s,run:n,enabled:t.enabled}}function Xl(t){const s=t.run.tools??[];return s.length===0?t.trigger.type==="schedule"?"Claude's tools":"No tools":`${s.length} tool${s.length===1?"":"s"}`}function Kn(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function Zl(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function ec({project:t}){const s=t.slug,[n,r]=a.useState([]),[i,o]=a.useState([]),[l,c]=a.useState(["onArchive","afterTurn"]),[m,u]=a.useState(["schedule","event","webhook"]),[p,g]=a.useState(!0),[h,b]=a.useState(null),[N,f]=a.useState(null),[d,v]=a.useState(null),[P,E]=a.useState(null),[I,k]=a.useState(null),[S,L]=a.useState({}),$=a.useCallback(async()=>{g(!0);try{const w=await B.listTriggers(s);r(w.triggers),o(w.grantableTools),w.events.length>0&&c(w.events),w.triggerTypes.length>0&&u(w.triggerTypes),b(null)}catch(w){b(w instanceof be?w.message:"Failed to load triggers")}finally{g(!1)}},[s]),T=a.useCallback(async()=>{try{const w=await B.triggerRuntime(s);L(Object.fromEntries(w.runtime.map(U=>[U.name,U])))}catch{}},[s]);a.useEffect(()=>{$()},[$]),a.useEffect(()=>{T();const w=setInterval(()=>{document.visibilityState==="visible"&&T()},1e4);return()=>clearInterval(w)},[T]),a.useEffect(()=>{if(!N)return;const w=setTimeout(()=>f(null),4e3);return()=>clearTimeout(w)},[N]);const y=d==null?void 0:d.draft,F=a.useMemo(()=>d!=null&&d.isNew?n.some(w=>w.name===(y==null?void 0:y.name.trim())):!1,[d,y,n]),O=!!y&&(!zl.test(y.name.trim())||y.name.trim().length>64),z=!!y&&(y.type==="schedule"?y.expr.trim().length===0:y.type==="webhook"?y.path.trim().length===0:!1),X=!!y&&(y.promptMode==="file"?y.promptFile.trim().length===0||!y.promptFile.trim().toLowerCase().endsWith(".md"):y.prompt.trim().length===0),_=!!y&&y.type==="webhook",j=O||F||z||X||_,M=w=>v(U=>U&&{...U,draft:{...U.draft,...w}}),W=w=>v(U=>{if(!U)return U;const Z=new Set(U.draft.allowedTools);return Z.has(w)?Z.delete(w):Z.add(w),{...U,draft:{...U.draft,allowedTools:Z}}}),q=async()=>{if(!d||j)return;const w=d.draft.name.trim();E(w);try{await B.putTrigger(s,w,Jl(d.draft)),v(null),f(`Saved “${w}”.`),await $()}catch(U){b(U instanceof be?U.message:"Failed to save trigger")}finally{E(null)}},ie=async w=>{E(w.name);try{const U=await B.putTrigger(s,w.name,{trigger:w.trigger,run:w.run,enabled:!w.enabled});r(Z=>Z.map(C=>C.name===w.name?U:C))}catch(U){b(U instanceof be?U.message:"Failed to update trigger")}finally{E(null)}},G=async()=>{const w=I;if(w){E(w.name);try{await B.deleteTrigger(s,w.name),r(U=>U.filter(Z=>Z.name!==w.name)),f(`Deleted “${w.name}”.`),k(null)}catch(U){throw new Error(U instanceof be?U.message:"Failed to delete trigger")}finally{E(null)}}},K=async w=>{E(w.name);try{await B.runTrigger(s,w.name),f(`Ran “${w.name}” — a new chat is starting.`),await T()}catch(U){b(U instanceof be?U.message:"Failed to run trigger")}finally{E(null)}};return e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain","data-testid":"triggers-pane",children:[e.jsx("div",{className:"mx-auto max-w-3xl px-6 py-6",children:e.jsxs("section",{className:"mb-6",children:[e.jsxs("h3",{className:"flex items-center gap-1.5 text-sm font-semibold uppercase tracking-wide text-fg-muted",children:[e.jsx(Tt,{width:14,height:14}),"Triggers"]}),e.jsxs("p",{className:"mb-3 mt-0.5 text-sm text-fg-muted",children:["A trigger runs an agent turn when something happens — a"," ",e.jsx("span",{className:"font-medium",children:"schedule"})," (a cron/interval fires), an"," ",e.jsx("span",{className:"font-medium",children:"event"})," (a lifecycle event like a chat being archived), or a ",e.jsx("span",{className:"font-medium",children:"webhook"})," (reserved). Each trigger's granted tools ",e.jsx("em",{children:"are"})," its capability. New triggers are created disabled; enable one when you’re ready for it to fire."]}),e.jsxs("div",{className:"card",children:[h&&e.jsx("p",{className:"mb-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:h}),N&&e.jsx("p",{className:"mb-3 rounded-lg bg-success-soft px-3 py-2 text-sm text-success",children:N}),p?e.jsx("p",{className:"py-4 text-center text-sm text-fg-subtle",children:"Loading triggers…"}):n.length===0?e.jsx("p",{className:"py-4 text-center text-sm italic text-fg-subtle",children:"No triggers yet."}):e.jsx("div",{className:"-mx-1 overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[54rem] border-collapse text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-edge text-left text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:[e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Trigger"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Type"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"When"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Capability"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Last run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Next run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Status"}),e.jsx("th",{className:"px-2 py-2 text-right font-semibold",children:"Actions"})]})}),e.jsx("tbody",{children:n.map(w=>{var Z;const U=S[w.name];return e.jsxs("tr",{"data-trigger":w.name,className:"border-b border-edge-subtle last:border-0",children:[e.jsxs("td",{className:"px-2 py-2.5 align-top",children:[e.jsx("span",{className:"font-medium text-fg",children:w.name}),w.run.promptFile?e.jsx("span",{className:"mt-0.5 block font-mono text-2xs text-fg-subtle",title:"Prompt read from this file at fire time",children:w.run.promptFile}):w.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-2xs text-fg-subtle",children:w.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(tc,{type:w.trigger.type})}),e.jsx("td",{className:"px-2 py-2.5 align-top font-mono text-xs text-fg-muted",children:Zl(w.trigger)}),e.jsxs("td",{className:"px-2 py-2.5 align-top text-xs text-fg-muted",children:[e.jsx("span",{title:((Z=w.run.tools)==null?void 0:Z.join(", "))||"No tools declared — an empty list is not enforced as a deny-all",children:Xl(w)}),w.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-2xs text-fg-subtle",children:w.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":w.name,children:e.jsx(ac,{rt:U})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":w.name,children:e.jsx(rc,{rt:U,trigger:w})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(sc,{enabled:w.enabled===!0,running:(U==null?void 0:U.running)===!0})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>K(w),disabled:P===w.name||Kn(w),title:Kn(w)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${w.name} now`,"data-testid":`run-trigger-${w.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-accent transition hover:bg-accent-soft disabled:opacity-40",children:e.jsx(mr,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ie(w),disabled:P===w.name,className:"rounded-md px-1.5 py-1 text-xs font-medium text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",title:w.enabled?"Disable":"Enable",children:w.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>v({isNew:!1,draft:Yl(w)}),disabled:P===w.name,title:"Edit","aria-label":`Edit ${w.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",children:e.jsx(hs,{width:14,height:14})}),e.jsx("button",{type:"button",onClick:()=>k(w),disabled:P===w.name,title:"Delete","aria-label":`Delete ${w.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle transition hover:bg-danger-soft hover:text-danger disabled:opacity-40",children:e.jsx(ms,{width:14,height:14})})]})})]},w.name)})})]})}),!d&&e.jsxs("button",{type:"button",onClick:()=>v({isNew:!0,draft:Ql(m[0]??"schedule",l[0]??"onArchive")}),className:"btn-subtle mt-3 gap-1.5 px-2 py-1 text-xs","data-testid":"add-trigger",children:[e.jsx(rt,{width:13,height:13}),"Add trigger"]}),d&&y&&e.jsxs("div",{className:"mt-4 rounded-xl border border-edge bg-surface-sunken p-4","data-testid":"trigger-editor",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:d.isNew?"New trigger":`Edit “${y.name}”`}),e.jsx("button",{type:"button",onClick:()=>v(null),"aria-label":"Cancel",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle hover:bg-surface-hover",children:e.jsx(Fe,{width:14,height:14})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",value:y.name,onChange:w=>M({name:w.target.value}),placeholder:"daily-manager",disabled:!d.isNew,"aria-invalid":O||F,"data-testid":"trigger-name"}),d.isNew&&F?e.jsx("p",{className:"mt-1 text-xs text-danger",children:"A trigger with that name exists."}):d.isNew&&y.name.trim()&&O?e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Letters, numbers, ",e.jsx("code",{children:". _ -"})," only (max 64)."]}):!d.isNew&&e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Rename by deleting and recreating."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Type"}),e.jsx("select",{className:"input",value:y.type,onChange:w=>M({type:w.target.value}),"data-testid":"trigger-type",children:m.map(w=>e.jsx("option",{value:w,children:Wl[w]??w},w))})]}),y.type==="schedule"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Timer"}),e.jsxs("select",{className:"input",value:y.scheduleKind,onChange:w=>M({scheduleKind:w.target.value,expr:""}),"data-testid":"trigger-schedule-kind",children:[e.jsx("option",{value:"interval",children:"Interval (every N)"}),e.jsx("option",{value:"cron",children:"Cron"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:y.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:y.expr,onChange:w=>M({expr:w.target.value}),placeholder:y.scheduleKind==="cron"?"0 9 * * *":"30m","aria-invalid":z,"data-testid":"trigger-expr"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:y.scheduleKind==="cron"?"5-field cron (or @daily / @hourly), host-local time.":"A duration like 30m, 1h, or 6h."})]})]}),y.type==="event"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Event"}),e.jsx("select",{className:"input",value:y.event,onChange:w=>M({event:w.target.value}),"data-testid":"trigger-event",children:l.map(w=>e.jsx("option",{value:w,children:Hl[w]??w},w))})]}),y.type==="webhook"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Path"}),e.jsx("input",{className:"input font-mono",value:y.path,onChange:w=>M({path:w.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),_&&e.jsxs("p",{className:"col-span-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{"data-testid":"trigger-webhook-reserved",children:["Webhook triggers are ",e.jsx("strong",{children:"reserved"})," — the inbound HTTP ingress isn’t built yet, so a webhook trigger can’t be created here. The shape is shown for reference."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Prompt"}),e.jsxs("div",{className:"mb-2 flex gap-3 text-sm",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:y.promptMode==="inline",onChange:()=>M({promptMode:"inline"})}),"Inline text"]}),e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:y.promptMode==="file",onChange:()=>M({promptMode:"file"})}),"Prompt file"]})]}),y.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:y.prompt,onChange:w=>M({prompt:w.target.value}),placeholder:"What should this trigger do when it fires?","aria-invalid":X,"data-testid":"trigger-prompt"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input font-mono",value:y.promptFile,onChange:w=>M({promptFile:w.target.value}),placeholder:"daily-manager.md","aria-invalid":X,"data-testid":"trigger-prompt-file"}),e.jsxs("p",{className:"mt-1 text-xs text-fg-subtle",children:["A ",e.jsx("code",{children:".md"})," file under ",e.jsx("code",{children:".paddock/triggers/"}),", read fresh each fire (git-tracked, Claude-editable)."]})]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Tools"}),e.jsxs("p",{className:"mb-2 text-xs text-fg-subtle",children:["The trigger agent can use exactly the tools you check here — nothing else.",y.type==="schedule"?" Leave all unchecked and the schedule runs as Claude with its full toolset.":" Leaving all unchecked declares no tools, but is not a deny-all: an empty list is not passed to the runtime, so the agent falls back to Claude's default tools."]}),e.jsx("div",{className:"space-y-3","data-testid":"trigger-tools",children:ql.filter(w=>i.some(U=>U.group===w)).map(w=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:Kl[w]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:i.filter(U=>U.group===w).map(U=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-md px-1.5 py-1 text-sm hover:bg-surface-hover",title:U.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:y.allowedTools.has(U.name),onChange:()=>W(U.name),"data-tool":U.name}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-fg",children:U.name}),e.jsx("span",{className:"block text-2xs leading-snug text-fg-subtle",children:U.description})]})]},U.name))})]},w))}),y.allowedTools.has("Bash")&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[e.jsx("code",{children:"Bash"})," lets this trigger run arbitrary shell commands in the project working dir. Grant it only when the trigger genuinely needs it."]})]})]}),e.jsxs("div",{className:"col-span-2 flex flex-wrap items-center gap-x-6 gap-y-2",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:y.resumeSession,onChange:w=>M({resumeSession:w.target.checked}),"data-testid":"trigger-session"}),e.jsx("span",{className:"text-fg",children:"Accrete into one session"})]}),e.jsx("span",{className:"text-xs text-fg-subtle",children:y.resumeSession?"One long-lived chat that accretes across fires.":"A fresh chat each fire."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsx("select",{className:"input",value:y.permissionMode,onChange:w=>M({permissionMode:w.target.value}),"data-testid":"trigger-permission-mode",children:Gl.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,step:1,className:"input",value:y.maxTurns,onChange:w=>M({maxTurns:w.target.value}),placeholder:"30","data-testid":"trigger-max-turns"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsx("input",{className:"input",value:y.model,onChange:w=>M({model:w.target.value}),placeholder:"Workspace default","data-testid":"trigger-model"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsx("input",{type:"number",min:0,step:1,className:"input",value:y.maxSpawnDepth,onChange:w=>M({maxSpawnDepth:w.target.value}),placeholder:"Inherit","data-testid":"trigger-max-spawn-depth"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"0 = may not spawn children."})]}),e.jsxs("label",{className:"col-span-2 inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:y.enabled,onChange:w=>M({enabled:w.target.checked}),"data-testid":"trigger-enabled"}),e.jsx("span",{className:"text-fg",children:"Enabled (fires on its trigger)"})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:q,disabled:j||P===y.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:P===y.name.trim()?"Saving…":d.isNew?"Create trigger":"Save"}),e.jsx("button",{type:"button",onClick:()=>v(null),className:"btn-ghost",children:"Cancel"})]})]})]})]})}),e.jsx(Xs,{open:I!==null,title:"Delete trigger?",confirmLabel:"Delete trigger",message:I&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:I.name})," ","will be removed from this project. This can't be undone."]}),onConfirm:G,onClose:()=>k(null)})]})}function tc({type:t}){const s={schedule:"bg-lineage-soft text-lineage",event:"bg-info-soft text-info",webhook:"bg-surface-active text-fg-muted"},n=t==="schedule"?Je:Tt;return e.jsxs("span",{"data-trigger-type":t,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-2xs font-medium capitalize ${s[t]}`,children:[e.jsx(n,{width:11,height:11}),t]})}function sc({enabled:t,running:s}){return s?e.jsxs("span",{"data-trigger-status":"running",className:"inline-flex items-center gap-1 rounded-full bg-warn-soft px-2 py-0.5 text-2xs font-medium text-warn",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-warn-solid"}),"Running"]}):e.jsx("span",{"data-trigger-status":t?"enabled":"disabled",className:`inline-flex items-center rounded-full px-2 py-0.5 text-2xs font-medium ${t?"bg-success-soft text-success":"bg-surface-active text-fg-muted"}`,children:t?"Enabled":"Disabled"})}function nc(t){return t==="completed"?"bg-success-solid":t==="failed"||t==="cancelled"?"bg-danger-solid":t==="running"||t==="pending"?"bg-warn-solid":"bg-fg-subtle"}function ac({rt:t}){const s=t==null?void 0:t.lastRun;if(!s)return e.jsx("span",{className:"text-xs text-fg-subtle",children:"—"});const n=s.startedAt,r=[n?new Date(n).toLocaleString():null,`status: ${s.status}${s.exitReason?` (${s.exitReason})`:""}`,s.summary??null].filter(Boolean).join(`