@edspencer/paddock 0.68.1 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/package.json +1 -1
  2. package/packages/server/dist/agent-errors.js +7 -1
  3. package/packages/server/dist/background-live.d.ts +124 -0
  4. package/packages/server/dist/background-live.js +226 -0
  5. package/packages/server/dist/cli/paddock.js +12 -7
  6. package/packages/server/dist/config.d.ts +7 -5
  7. package/packages/server/dist/config.js +0 -1
  8. package/packages/server/dist/instance-config.js +1 -2
  9. package/packages/server/dist/recovery-config.d.ts +0 -6
  10. package/packages/server/dist/recovery-config.js +0 -4
  11. package/packages/server/dist/ws-protocol.d.ts +61 -1
  12. package/packages/server/dist/ws-turn.d.ts +2 -0
  13. package/packages/server/dist/ws-turn.js +17 -1
  14. package/packages/server/dist/ws.js +72 -13
  15. package/packages/server/package.json +1 -1
  16. package/packages/web/dist/assets/{Chip-NMeHUE94.js → Chip-C8a-t439.js} +1 -1
  17. package/packages/web/dist/assets/DiscoverPage-C1khyCvD.js +2 -0
  18. package/packages/web/dist/assets/{DiscoverView-Bt4FUTjB.js → DiscoverView-DS_Z9xKH.js} +1 -1
  19. package/packages/web/dist/assets/{InstanceConfigPage-DIQJtIYC.js → InstanceConfigPage-B1ei1FDo.js} +1 -1
  20. package/packages/web/dist/assets/{MarkdownRenderer-BVMZB_mP.js → MarkdownRenderer-DCj_ZwVG.js} +1 -1
  21. package/packages/web/dist/assets/{ProjectMenu-D9Nsqjxy.js → ProjectMenu-B7dGZSFB.js} +1 -1
  22. package/packages/web/dist/assets/{ProjectRedirect-B8rJ9qqe.js → ProjectRedirect-bstvMvM9.js} +1 -1
  23. package/packages/web/dist/assets/ProjectView-iuiUIoIl.js +13 -0
  24. package/packages/web/dist/assets/{ProjectsGrid-CDqvd4bj.js → ProjectsGrid-DKvySDUQ.js} +1 -1
  25. package/packages/web/dist/assets/{RootHome-CmiJG9wb.js → RootHome-CD_37qb-.js} +1 -1
  26. package/packages/web/dist/assets/{Surfaces-c410wTbw.js → Surfaces-1dBayrsj.js} +1 -1
  27. package/packages/web/dist/assets/{arc-DN2jEPE9.js → arc-BJPb3ViJ.js} +1 -1
  28. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-BLMFd81z.js → architectureDiagram-3BPJPVTR-PkLOC5wV.js} +1 -1
  29. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-BweEECqE.js → blockDiagram-GPEHLZMM-IPduhNH-.js} +1 -1
  30. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-DpN_9YFO.js → c4Diagram-AAUBKEIU-dKTYV1Vq.js} +1 -1
  31. package/packages/web/dist/assets/channel-BhrgMiqg.js +2 -0
  32. package/packages/web/dist/assets/{chunk-2J33WTMH-BxWEBoli.js → chunk-2J33WTMH-B5C6geyg.js} +1 -1
  33. package/packages/web/dist/assets/{chunk-4BX2VUAB-C5nkcPRR.js → chunk-4BX2VUAB-1BRhFRhF.js} +1 -1
  34. package/packages/web/dist/assets/{chunk-55IACEB6-B8P3CNX8.js → chunk-55IACEB6-DNv-sTiI.js} +1 -1
  35. package/packages/web/dist/assets/{chunk-727SXJPM-D3yuzl-m.js → chunk-727SXJPM-CWezuVkx.js} +1 -1
  36. package/packages/web/dist/assets/{chunk-AQP2D5EJ-CzWxcEIw.js → chunk-AQP2D5EJ-Bt4yEQnu.js} +1 -1
  37. package/packages/web/dist/assets/{chunk-FMBD7UC4-CCB91otB.js → chunk-FMBD7UC4-lb_8q4JY.js} +1 -1
  38. package/packages/web/dist/assets/{chunk-ND2GUHAM-BymMfuY4.js → chunk-ND2GUHAM-DOwgGlQ_.js} +1 -1
  39. package/packages/web/dist/assets/{chunk-QZHKN3VN-CezHuNcf.js → chunk-QZHKN3VN-BanKpY4q.js} +1 -1
  40. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-Ho1IMdjg.js +2 -0
  41. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-Ho1IMdjg.js +2 -0
  42. package/packages/web/dist/assets/{core-LjceHm3Z.js → core-CAsyoNAa.js} +1 -1
  43. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BWhmWR_V.js → cose-bilkent-S5V4N54A-sVaVkwMI.js} +1 -1
  44. package/packages/web/dist/assets/{dagre-BM42HDAG-BTXWnJYV.js → dagre-BM42HDAG-C9pKHSMo.js} +1 -1
  45. package/packages/web/dist/assets/{diagram-2AECGRRQ-BY2LZdf0.js → diagram-2AECGRRQ-CHdrmCfX.js} +1 -1
  46. package/packages/web/dist/assets/{diagram-5GNKFQAL-BZ78Imy8.js → diagram-5GNKFQAL-4UTa2Dfa.js} +1 -1
  47. package/packages/web/dist/assets/{diagram-KO2AKTUF-BV4Ax_0D.js → diagram-KO2AKTUF-NidpfVwW.js} +1 -1
  48. package/packages/web/dist/assets/{diagram-LMA3HP47-1kcTal-d.js → diagram-LMA3HP47-ictQj03T.js} +1 -1
  49. package/packages/web/dist/assets/{diagram-OG6HWLK6-CX3RfHlO.js → diagram-OG6HWLK6-B7dTLMHC.js} +1 -1
  50. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-BBS46D95.js → erDiagram-TEJ5UH35-C2QYYzJ8.js} +1 -1
  51. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-CpPHahLZ.js → flowDiagram-I6XJVG4X-D2rcjSZ9.js} +1 -1
  52. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-CxL_QCuL.js → ganttDiagram-6RSMTGT7-BQcXTYzg.js} +1 -1
  53. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-BeTkPHaG.js → gitGraphDiagram-PVQCEYII-DwB2Vqxa.js} +1 -1
  54. package/packages/web/dist/assets/index-BNzTD4hA.css +1 -0
  55. package/packages/web/dist/assets/{index-DjhUG9sA.js → index-BeuEs7dL.js} +14 -14
  56. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-CiMnl36I.js → infoDiagram-5YYISTIA-BoK4Mawg.js} +1 -1
  57. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-CjASKQeF.js → ishikawaDiagram-YF4QCWOH-DPP9svhg.js} +1 -1
  58. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-BZzehSqh.js → journeyDiagram-JHISSGLW-TrggodYk.js} +1 -1
  59. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-Cn-l0UIy.js → kanban-definition-UN3LZRKU-Bh69hRSR.js} +1 -1
  60. package/packages/web/dist/assets/{linear-DyELsH8s.js → linear-C1iYMpBz.js} +1 -1
  61. package/packages/web/dist/assets/{mermaid.core-C1adXzqy.js → mermaid.core-BZDABcuq.js} +4 -4
  62. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-DP6iSaA_.js → mindmap-definition-RKZ34NQL-DTJON3dS.js} +1 -1
  63. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-DHpN8Fse.js → pieDiagram-4H26LBE5-BxtFV74I.js} +1 -1
  64. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-DAfc21Kd.js → quadrantDiagram-W4KKPZXB-D2Ar8kmO.js} +1 -1
  65. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-X3FfIiGh.js → requirementDiagram-4Y6WPE33-DiLSfeSQ.js} +1 -1
  66. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-Ch319LBM.js → sankeyDiagram-5OEKKPKP-D_CRQc7j.js} +1 -1
  67. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-CAyajDJc.js → sequenceDiagram-3UESZ5HK-DjtfcRNV.js} +1 -1
  68. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-C1G4309_.js → stateDiagram-AJRCARHV-CzEtmYLV.js} +1 -1
  69. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-pM8fIOir.js +2 -0
  70. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-Bj5ihSj4.js → timeline-definition-PNZ67QCA-DXKspEG3.js} +1 -1
  71. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-WIZuVHvV.js → vennDiagram-CIIHVFJN-B_tXRMHH.js} +1 -1
  72. package/packages/web/dist/assets/{wardley-L42UT6IY-CwRQf2fI.js → wardley-L42UT6IY-DNaNoaJm.js} +1 -1
  73. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-Bug_Zcav.js → wardleyDiagram-YWT4CUSO-BuVDpC8s.js} +1 -1
  74. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-Cw5xgfwo.js → xychartDiagram-2RQKCTM6-Cqtew2PA.js} +1 -1
  75. package/packages/web/dist/index.html +2 -2
  76. package/packages/web/dist/sw.js +1 -1
  77. package/packages/web/dist/assets/DiscoverPage-LY0CRBVz.js +0 -2
  78. package/packages/web/dist/assets/ProjectView-D-21ULHU.js +0 -13
  79. package/packages/web/dist/assets/channel-B_SiD-tA.js +0 -2
  80. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-Detq0lSJ.js +0 -2
  81. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-Detq0lSJ.js +0 -2
  82. package/packages/web/dist/assets/index-DYccdR9x.css +0 -1
  83. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-C0-BEM28.js +0 -2
@@ -1,13 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-BVMZB_mP.js","assets/index-DjhUG9sA.js","assets/index-DYccdR9x.css","assets/ProjectMenu-D9Nsqjxy.js","assets/queued-CagZVfWU.js","assets/Surfaces-c410wTbw.js","assets/lastTab-CU1zsF0j.js","assets/core-LjceHm3Z.js","assets/mermaid.core-C1adXzqy.js"])))=>i.map(i=>d[i]);
2
- import{r as a,b as F,G as Ie,j as e,Y as rn,D as je,Z as Fs,_ as Vt,X as Be,c as et,$ as zt,L as Ys,a0 as Ln,C as Ht,a1 as An,B as Ze,P as lt,J as Os,a2 as ba,a3 as ja,a4 as va,a5 as wa,a6 as Na,a7 as ya,a8 as ka,a9 as Ca,S as Js,U as xs,aa as Fn,ab as On,ac as Un,ad as oe,ae as Bn,d as It,af as Sa,ag as ds,h as fs,E as Vn,F as pt,ah as zn,ai as Ue,aj as Ia,ak as $a,al as Rs,K as ps,am as Ut,an as Us,V as Xs,ao as Ea,ap as Ra,aq as Ta,ar as Ma,as as _a,O as ln,at as Da,au as Pa,av as La,aw as Aa,ax as Fa,ay as on,az as cn,aA as Oa,aB as Ua,i as Ba,R as Va,aC as za,a as Ha,H as Wa,u as Ga,aD as Ka,aE as Qa,aF as qa,aG as Ya,aH as dn,aI as Ja,M as Xa,T as Za,aJ as er,g as tr,aK as sr}from"./index-DjhUG9sA.js";import{C as us,u as gs,S as nr,P as ar}from"./ProjectMenu-D9Nsqjxy.js";import{readQueued as rr,readQueuedId as lr,readQueuedAttachments as ir,writeQueued as or,writeQueuedId as cr,writeQueuedAttachments as dr,newQueuedId as ur}from"./queued-CagZVfWU.js";import{S as Ct,E as ms,B as Hn}from"./Surfaces-c410wTbw.js";import{t as xt,w as mr,c as hr}from"./lastTab-CU1zsF0j.js";const xr=500,fr=9e4,Ts="paddock:cancel",un="paddock:timeout";function pr(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function gr(){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 br({onText:t,timeoutMs:s=fr}){const[n,r]=a.useState("idle"),[l,i]=a.useState(null),[o,c]=a.useState(null),[u]=a.useState(pr),x=a.useRef(null),N=a.useRef(null),m=a.useRef([]),j=a.useRef("webm"),y=a.useRef(null),C=a.useRef(null),g=a.useRef(!0);a.useEffect(()=>{g.current=!0;let w=!1;return F.transcriptionStatus().then(O=>{w||i(O.available)}).catch(()=>{w||i(!1)}),()=>{var O;w=!0,g.current=!1,(O=C.current)==null||O.abort(Ts),f()}},[]);const f=()=>{var w;(w=N.current)==null||w.getTracks().forEach(O=>O.stop()),N.current=null,x.current=null},S=a.useCallback(async()=>{if(!u||n==="recording"||n==="transcribing")return;c(null),y.current=null;let w;try{w=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(P){r("error"),c(Nr(P));return}N.current=w;const{mimeType:O,ext:k}=gr();j.current=k;const z=O?new MediaRecorder(w,{mimeType:O}):new MediaRecorder(w);m.current=[],z.ondataavailable=P=>{P.data&&P.data.size>0&&m.current.push(P.data)},z.onstop=()=>{f();const P=z.mimeType||O||"audio/webm",G=new Blob(m.current,{type:P});m.current=[],y.current=G,M(G)},x.current=z,z.start(),r("recording")},[u,n]),M=a.useCallback(async(w,O=!1)=>{if(w.size===0){y.current=null,g.current&&r("idle");return}g.current&&r("transcribing");const k=new AbortController;C.current=k;const z=setTimeout(()=>k.abort(un),s);try{const P=await F.transcribe(w,`dictation.${j.current}`,k.signal);P.trim()&&t(P.trim()),y.current=null,g.current&&(c(null),r("idle"))}catch(P){if(k.signal.aborted&&k.signal.reason===Ts){y.current=null,g.current&&(c(null),r("idle"));return}if(k.signal.aborted&&k.signal.reason===un){g.current&&(r("error"),c("Transcription timed out — try again."));return}if(jr(P)&&!O)return await wr(xr),M(w,!0);g.current&&(r("error"),c(vr(P)))}finally{clearTimeout(z),C.current===k&&(C.current=null)}},[t,s]),R=a.useCallback(()=>{var w;(w=C.current)==null||w.abort(Ts)},[]),v=a.useCallback(()=>{const w=x.current;w&&w.state!=="inactive"&&w.stop()},[]),L=a.useCallback(()=>{n==="recording"?v():S()},[n,S,v]),E=a.useCallback(()=>{if(n==="recording"||n==="transcribing")return;const w=y.current;w?M(w):S()},[n,M,S]),B=a.useCallback(()=>{y.current=null,c(null),r("idle")},[]);return{state:n,available:l,supported:u,error:o,start:S,stop:v,toggle:L,retry:E,dismiss:B,cancel:R}}function jr(t){return t instanceof Ie?t.status>=500:!0}function vr(t){return t instanceof Ie?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 wr(t){return new Promise(s=>setTimeout(s,t))}function Nr(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 yr({onText:t}){const{state:s,available:n,supported:r,error:l,toggle:i,retry:o,dismiss:c,cancel:u}=br({onText:t});if(n!==!0)return null;const x=s==="recording",N=s==="transcribing",m=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(rn,{width:18,height:18})});const j=x?"Stop recording":N?"Transcribing… — click to cancel":m?"Transcription failed — click to record again":"Record a voice message",y=()=>{N?u():i()};return e.jsxs("div",{className:"relative flex items-center",children:[m&&l&&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(je,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:l}),e.jsx("button",{type:"button",onClick:o,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:y,"aria-label":x?"Stop recording":N?"Cancel transcription":"Record a voice message","aria-pressed":x,title:j,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",x?"bg-danger-soft text-danger":N?"cursor-pointer text-accent can-hover:hover:bg-danger-soft can-hover:hover:text-danger":m?"bg-danger-soft text-danger":"text-fg-muted can-hover:hover:bg-surface-hover can-hover:hover:text-fg"].filter(Boolean).join(" "),children:[N?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(kr,{})}),e.jsx(Fs,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):x?e.jsx(Fs,{width:16,height:16}):e.jsx(rn,{width:18,height:18}),x&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function kr(){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 Cr="paddock:chatModel:";function Wn(t,s){return Cr+(t??`new:${s}`)}function Sr(t,s){try{const n=localStorage.getItem(Wn(t,s));return n&&n.length>0?n:null}catch{return null}}function Bs(t,s,n){try{localStorage.setItem(Wn(t,s),n)}catch{}}const Ir="paddock:draft:";function Gn(t,s){return Ir+(t??`new:${s}`)}function $r(t,s){try{return localStorage.getItem(Gn(t,s))??""}catch{return""}}function Er(t,s,n){try{const r=Gn(t,s);n.length>0?localStorage.setItem(r,n):localStorage.removeItem(r)}catch{}}const mn="<paddock-attachments>",Vs="</paddock-attachments>",hn=`${Vs}
3
-
4
- `;function Kn(t){return`/api/chat-files/${encodeURIComponent(t)}`}function Rr(t){const s=t.indexOf(mn);if(s===-1)return{attachments:[],text:t};const n=s+mn.length,r=t.indexOf(Vs,n);if(r===-1)return{attachments:[],text:t};const l=t.slice(n,r),i=[];for(const u of l.split(`
5
- `)){const x=u.split(" ");if(x.length<3)continue;const[N,m,j]=x;!(N!=null&&N.trim())||!(j!=null&&j.trim())||i.push({id:N.trim(),kind:(m==null?void 0:m.trim())||"file",filename:j.trim()})}const o=t.slice(0,s),c=t.startsWith(hn,r)?t.slice(r+hn.length):t.slice(r+Vs.length).replace(/^\n+/,"");return{attachments:i,text:o+c}}function Tr(t){const s=t.slice(t.lastIndexOf("/")+1),n=s.lastIndexOf(".");return n>0?s.slice(n).toLowerCase():""}function Qn(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 Mr(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function _r(t,s,n){const r=(s??"").trim().toLowerCase(),l=Tr(n??"");for(const i of t){const o=i.trim().toLowerCase();if(o){if(o==="*"||o==="*/*")return!0;if(o.includes("/")){if(!r)continue;const[c,u]=o.split("/",2),[x,N]=r.split("/",2);if((c==="*"||c===x)&&(u==="*"||u===N))return!0}else if(o.startsWith(".")){if(l&&l===o)return!0}else if(l&&l===`.${o}`)return!0}}return!1}function Dr({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(Pr,{attachment:s},s.id))})}function Pr({attachment:t}){const s=Kn(t.id);if(t.kind==="image")return e.jsx(Ar,{src:s,filename:t.filename});const n=Qn(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(Vt,{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 Lr({attachment:t,onRemove:s}){const n=Kn(t.id),[r,l]=a.useState(!1),i=t.kind==="image"&&!r,o=Qn(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:[i?e.jsx("img",{src:n,alt:t.filename,onError:()=>l(!0),className:"h-9 w-9 shrink-0 rounded-md object-cover"}):e.jsx(Vt,{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,o?` · ${o}`:""]})]}),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(Be,{width:12,height:12})})]})}function Ar({src:t,filename:s}){const[n,r]=a.useState(!1),[l,i]=a.useState(!1);return l?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(je,{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:()=>i(!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 Fr(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 Or({trigger:t,projectSlug:s}){const n=t.allowedTools??[],r=n.length===0,l=r?t.type==="schedule"?"runs as Claude (full tools)":"no tools declared":`${n.length} tool${n.length===1?"":"s"} granted`,i=t.type==="schedule"?et:zt;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(i,{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:Fr(t)})," · ",l,". 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(o=>e.jsx("li",{className:"rounded bg-info-solid/10 px-1.5 py-px font-mono text-2xs text-info",children:o},o))})]}),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(Ys,{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 Ur=new Set(["paddock","paddock_manage"]);function Br(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function Vr(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),l=n===-1?"":s.slice(n+2);return{isMcp:!0,server:r,isPaddock:Ur.has(r),display:Br(l||r),tool:l}}const xn="mcp__paddock_manage__",At=(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 qn(t,s=80){var r;const n=((r=t.split(`
6
- `).find(l=>l.trim().length>0))==null?void 0:r.trim())??t.trim();return n.length>s?`${n.slice(0,s).trimEnd()}…`:n}function Yn(t,s){return t||(s?qn(s):"untitled chat")}function zr(t,s){if(!t.startsWith(xn)||!s)return null;const n=t.slice(xn.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 l=r.projects;return{tool:n,count:At(r.count,l.length),projects:l}}case"list_chats":{if(!Array.isArray(r.chats))return null;const l=r.chats;return{tool:n,count:At(r.count,l.length),project:r.project??null,chats:l}}case"read_chat":{if(!Array.isArray(r.messages))return null;const l=r.messages;return{tool:n,project:String(r.project??""),sessionId:String(r.sessionId??""),total:At(r.total,l.length),returned:At(r.returned,l.length),messages:l}}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 l=r.forks;return{tool:n,count:At(r.count,l.length),source:String(r.source??""),forks:l}}default:return null}}function Hr(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 Yn(t.name,t.prompt);case"send_message":return t.prompt?qn(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const Jn=a.createContext(null),Wr=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,zs=t=>t.length>8?`${t.slice(0,8)}…`:t;function Ot({project:t,sessionId:s,label:n}){return e.jsxs(Ys,{to:Wr(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(Ln,{width:10,height:10,className:"shrink-0"}),n??zs(s)]})}const yt="border-t border-edge px-3 py-2.5",kt="text-fg-muted";function fn({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 pn({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 Gr({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(Ot,{project:t.project,sessionId:t.sessionId})]})}function Kr({data:t}){const s=a.useContext(Jn)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:yt,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(fn,{children:n.area}),n.status&&n.status!=="active"&&e.jsx(fn,{children:n.status})]},n.slug))})});case"list_chats":return e.jsx("div",{className:yt,children:e.jsx("ul",{className:"max-h-72 divide-y divide-edge-subtle overflow-auto text-2xs",children:t.chats.map(n=>e.jsx(Gr,{chat:n},n.sessionId))})});case"read_chat":return e.jsxs("div",{className:yt,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:[e.jsxs("span",{className:kt,children:[t.returned," of ",t.total," messages"]}),e.jsx(Ot,{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=Yn(t.name,t.prompt);return e.jsxs("div",{className:yt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:kt,children:n}),e.jsx("span",{className:"font-medium text-fg",children:r}),e.jsxs("span",{className:kt,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${kt}`,children:["from ",zs(t.from)]}),e.jsx(Ot,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(pn,{label:"Kickoff",text:t.prompt})]})}case"send_message":return e.jsxs("div",{className:yt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:kt,children:"Sent to"}),e.jsx("span",{className:"font-medium text-fg",children:t.project}),e.jsx(Ot,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(pn,{label:"Message",text:t.prompt})]});case"fork_chat_batch":return e.jsxs("div",{className:yt,children:[e.jsx("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:e.jsxs("span",{className:kt,children:[t.count," ",t.count===1?"fork":"forks"," from ",zs(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(Ot,{project:s,sessionId:n.sessionId})]},n.sessionId))})]})}}const bs=new Set(["Task","Agent"]);function Qr(t,s){return bs.has(t.toolName)&&s&&t.subagentDurationMs==null}const qr="mcp__paddock__send_file",Yr=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),Jr=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function Xr(t){return t.background||t.toolName==="Monitor"||Yr.has(t.toolName)?!0:Jr.test(t.output??"")}function Zr(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 el(t){switch(t){case"list_projects":return Os;case"create_chat":return lt;case"fork_chat":case"fork_chat_batch":return Ze;case"send_message":return An;default:return Ht}}function Xn(t){if(t.toolName!==qr||!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?F.chatFileRawUrl(s.attachmentId):void 0}}function tl(t){return t==="+"?"bg-success-soft text-success":t==="-"?"bg-danger-soft text-danger":"text-fg-muted"}function gn(t){return t===void 0?"":String(t)}function sl(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 nl(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 al(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 rl=0;const Ge=()=>`t${++rl}`;function ll(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:Ge(),content:s,streaming:!0}]})}function Oe(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function bn(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 il(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const i=Xn(t.toolCall);return i?{kind:"file",id:s,file:i}:{kind:"tool",id:s,tool:t.toolCall}}if(t.role==="assistant")return{kind:"assistant",id:s,content:t.content,streaming:!1};if(ba(t.content))return{kind:"compact",id:s,summary:t.content};const n=ja(t.content);if(n)return{kind:"command",id:s,command:n};if(va(t.content))return{kind:"commandOutput",id:s,content:wa(t.content)??""};if(Na(t.content))return{kind:"commandOutput",id:s,content:""};if(ya(t.content))return{kind:"notification",id:s,summary:Ca(t.content),status:ka(t.content)};const{attachments:r,text:l}=Rr(t.content);return{kind:"user",id:s,content:l,...t.sender?{sender:t.sender}:{},...r.length>0?{attachments:r}:{}}}const ol="/compact";function cl(t){return t.kind==="commandOutput"&&t.content===""}function dl(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 l=n+1;for(;l<t.length&&cl(t[l]);)l++;const i=t[l];(i==null?void 0:i.kind)==="command"&&i.command===ol?(s.push(...t.slice(n+1,l+1),r),n=l):s.push(r)}return s}function hs(t){const s=new Map,n=t.filter(r=>!r.bgConsumed).map(r=>{let l;if(r.uuid){const o=s.get(r.uuid)??0;s.set(r.uuid,o+1),l=o===0?r.uuid:`${r.uuid}#${o}`}else l=Ge();const i=il(r,l);return i.timestamp=r.timestamp,r.contextTokens!=null&&(i.contextTokens=r.contextTokens),i});return dl(n)}function jn(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 ul(t,s){if(s.length===0)return t;if(t.length===0)return s;const n=[...t],r=new Map,l=new Map,i=[];n.forEach((o,c)=>{o.kind==="tool"&&o.tool.toolUseId?r.set(o.tool.toolUseId,c):o.kind==="assistant"?i.push(c):l.set(jn(o),c)});for(const o of s){if(o.kind==="tool"&&o.tool.toolUseId){const u=r.get(o.tool.toolUseId);if(u===void 0){r.set(o.tool.toolUseId,n.length),n.push(o);continue}const x=n[u];if(x.kind!=="tool")continue;n[u]={...x,tool:{...x.tool,...o.tool,pending:o.tool.pending===!0}};continue}if(o.kind==="assistant"){const u=i.find(N=>{const m=n[N];return m.kind==="assistant"&&(m.content===o.content||m.content.startsWith(o.content)||o.content.startsWith(m.content))});if(u===void 0){i.push(n.length),n.push(o);continue}const x=n[u];if(x.kind!=="assistant")continue;o.content.length>x.content.length&&(n[u]={...x,content:o.content,streaming:o.streaming});continue}const c=jn(o);l.has(c)||(l.set(c,n.length),n.push(o))}return n}const Zn=a.createContext(null),ea=a.createContext(!1),Zs=a.createContext(null),ta=a.createContext(null),sa=a.createContext(null),en=a.createContext(null),na=a.createContext(null);function ml({running:t,activity:s,onReveal:n}){return t.length===0?null:e.jsx("div",{className:"mx-auto w-full max-w-3xl px-4","data-testid":"running-subagents",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 gap-1.5 border-b border-accent/20 px-3 py-1.5",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.jsxs("span",{className:"text-3xs font-semibold uppercase tracking-wide text-accent",children:[t.length," sub-agent",t.length===1?"":"s"," running"]})]}),e.jsx("ul",{className:"divide-y divide-accent/15",children:t.map(r=>{const l=s.get(r.toolUseId);return e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>n(r.toolUseId),title:"Show this sub-agent in the transcript",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-accent/10",children:[e.jsx(Js,{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:r.label}),r.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted",children:r.description}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-2xs text-accent/90",title:l==null?void 0:l.latestStep,children:(l==null?void 0:l.latestStep)??"starting…"}),l!=null&&l.stepCount>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[l.stepCount," step",l.stepCount===1?"":"s"]})]})},r.toolUseId)})})]})})}const hl=2e3,xl=6;function fl(t){const s=t.toolCall;if(!s)return null;const n=bs.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,r=(s.description??s.inputSummary??"").trim();return r?`${n} ${r}`:n}function pl(t){var r,l;if(t.length===0)return;const s=Date.parse(((r=t[0])==null?void 0:r.timestamp)??""),n=Date.parse(((l=t[t.length-1])==null?void 0:l.timestamp)??"");if(!(!Number.isFinite(s)||!Number.isFinite(n)||n<s))return n-s}function gl(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function bl(t,s,n){const[r,l]=a.useState(new Map),i=a.useRef(new Set),o=a.useRef(new Map),c=a.useRef(s);c.current=s;const u=a.useRef(n);u.current=n;const x=t.map(N=>N.toolUseId).sort().join(",");return a.useEffect(()=>{const N=x?x.split(","):[];if(N.length===0||!c.current)return;let m=!1,j;const y=async()=>{const C=c.current;if(!C)return;const g=N.filter(S=>!i.current.has(S));if(g.length===0)return;const f=await Promise.all(g.map(S=>C(S).then(M=>({id:S,messages:M})).catch(()=>null)));m||(l(S=>{const M=new Map(S);for(const R of f){if(!R)continue;const v=gl(R.messages),L=o.current.get(R.id),E=L&&L.sig===v?L.ticks+1:0;o.current.set(R.id,{sig:v,ticks:E});const B=!u.current&&E>=xl;B&&i.current.add(R.id);const w=R.messages.map(fl).filter(O=>!!O);M.set(R.id,{latestStep:w[w.length-1],stepCount:w.length,messages:R.messages,elapsedMs:pl(R.messages),running:!B})}return M}),m||(j=setTimeout(y,hl)))};return y(),()=>{m=!0,j&&clearTimeout(j)}},[x]),r}function jl(t){return a.useMemo(()=>{const s=[];for(const n of t){const r=n.kind==="tool"?n.tool:void 0;r!=null&&r.toolUseId&&bs.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 vl({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 wl({models:t,model:s,onSelectModel:n,usage:r,sessionUsage:l,forkParent:i,onOpenForkParent:o}){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(Nl,{usage:r}),e.jsx(yl,{usage:l}),i&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(Ze,{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:()=>o==null?void 0:o(i.sessionId),title:`Open the chat this was forked from: ${i.name}`,className:"truncate font-medium text-accent underline-offset-2 hover:underline",children:i.name})]})]})}function Nl({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),l=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 / ",l,"k (",Math.round(s),"%)"]})]})}function yl({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${Fn(t.costUsd)}`:On(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${Un(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const vn=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function kl(){const[t,s]=a.useState(0);return a.useEffect(()=>{const n=setInterval(()=>s(r=>(r+1)%vn.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:[vn[t],"…"]})]})})}function Cl({text:t,attachments:s=[],onEdit:n,onClear:r}){const l=t.split(`
7
- `,1)[0],i=t.length-l.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(et,{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(o=>o.filename).join(", "),children:l||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),l&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(o=>o.filename).join(", "),children:["📎 ",s.length]}),i>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${i} more character${i===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",i," character",i===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(xs,{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(Be,{width:12,height:12})})]})]})})}function Sl({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 Il=a.lazy(()=>oe(()=>import("./MarkdownRenderer-BVMZB_mP.js"),__vite__mapDeps([0,1,2,3,4,5,6]))),Wt=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(Il,{mermaid:n,children:s})})}),$l={tsx:"typescript",jsx:"javascript",html:"xml"};function El(t){if(!t)return;const s=t.toLowerCase();return $l[s]??s}let Ms=null;async function Rl(){return Ms||(Ms=(async()=>{const{default:t}=await oe(async()=>{const{default:E}=await import("./core-LjceHm3Z.js");return{default:E}},__vite__mapDeps([7,1,2])),[s,n,r,l,i,o,c,u,x,N,m,j,y,C,g,f,S,M,R,v,L]=await Promise.all([oe(()=>import("./typescript-C2FFdlUC.js"),[]),oe(()=>import("./javascript-BKRaQes9.js"),[]),oe(()=>import("./python-kSlZHhJb.js"),[]),oe(()=>import("./ruby-7T4ktxyv.js"),[]),oe(()=>import("./go-BPx_y7j8.js"),[]),oe(()=>import("./rust-HC3MBUhY.js"),[]),oe(()=>import("./java-B5VKqtH2.js"),[]),oe(()=>import("./c-D2F1sQUL.js"),[]),oe(()=>import("./cpp-Bm3ii6kY.js"),[]),oe(()=>import("./csharp-BNpuYZMG.js"),[]),oe(()=>import("./php-CRdd4dfS.js"),[]),oe(()=>import("./swift-Dn8kKO_1.js"),[]),oe(()=>import("./kotlin-Cw-eF_bm.js"),[]),oe(()=>import("./bash-I8pq0VWm.js"),[]),oe(()=>import("./sql-BC88IN-V.js"),[]),oe(()=>import("./json-DIYVocXf.js"),[]),oe(()=>import("./yaml-drsDnIKT.js"),[]),oe(()=>import("./ini-B3BVgEsG.js"),[]),oe(()=>import("./css-DazXZka4.js"),[]),oe(()=>import("./scss-DZLA7YXz.js"),[]),oe(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",l.default),t.registerLanguage("go",i.default),t.registerLanguage("rust",o.default),t.registerLanguage("java",c.default),t.registerLanguage("c",u.default),t.registerLanguage("cpp",x.default),t.registerLanguage("csharp",N.default),t.registerLanguage("php",m.default),t.registerLanguage("swift",j.default),t.registerLanguage("kotlin",y.default),t.registerLanguage("bash",C.default),t.registerLanguage("sql",g.default),t.registerLanguage("json",f.default),t.registerLanguage("yaml",S.default),t.registerLanguage("toml",M.default),t.registerLanguage("css",R.default),t.registerLanguage("scss",v.default),t.registerLanguage("xml",L.default),t})()),Ms}function Tl({code:t,language:s}){const[n,r]=a.useState(null),l=El(s);a.useEffect(()=>{if(!l){r(null);return}let o=!1;return r(null),(async()=>{try{const c=await Rl();if(o||!c.getLanguage(l))return;const{value:u}=c.highlight(t,{language:l});o||r(u)}catch{}})(),()=>{o=!0}},[t,l]);const i="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:i,children:e.jsx("code",{className:`hljs language-${l}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:i,children:e.jsx("code",{children:t})})}let _s=null;function Ml(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function _l(){return _s||(_s=oe(()=>import("./mermaid.core-C1adXzqy.js").then(t=>t.bm),__vite__mapDeps([8,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:Ml()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),_s}function Dl({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[l,i]=a.useState(null);return a.useEffect(()=>{let o=!1;return i(null),(async()=>{try{const c=await _l();await c.parse(t);const{svg:u,bindFunctions:x}=await c.render(n+"-svg",t);if(o||!r.current)return;r.current.innerHTML=u,x==null||x(r.current)}catch(c){if(o)return;i(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{o=!0}},[t,n]),l?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:l}),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 Pl="paddock:itemHeight:";function tn(t){return Pl+t}function wn(t){try{const s=localStorage.getItem(tn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function Ll(t,s){try{const n=tn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function Al(t){try{localStorage.removeItem(tn(t))}catch{}}function Fl({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const l=a.useRef(null),[i,o]=a.useState(0),[c,u]=a.useState(()=>wn(t));a.useEffect(()=>{u(wn(t))},[t]),a.useEffect(()=>{if(!l.current)return;const y=()=>{var g;return o(((g=l.current)==null?void 0:g.scrollHeight)||0)};if(y(),typeof ResizeObserver>"u")return;const C=new ResizeObserver(y);return C.observe(l.current),()=>C.disconnect()},[s]);const x=i>0,N=x?i:Number.POSITIVE_INFINITY;let m=!1,j=0;return c!=null?(m=!0,j=aa(c,r,N)):x&&i>n&&(m=!0,j=n),e.jsxs("div",{className:m?"group relative":void 0,style:m?{height:j}:void 0,children:[e.jsx("div",{className:m?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:l,children:s})}),m?e.jsx(Ol,{appliedHeight:j,onResize:y=>u(y),onCommit:y=>Ll(t,y),onReset:()=>{Al(t),u(null)},minHeight:r,maxHeight:N}):null]})}function Ol({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:l,maxHeight:i}){const o=a.useRef(null),c=a.useRef(t);c.current=t;const u=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:x=>{o.current={startY:x.clientY,startHeight:t},x.currentTarget.setPointerCapture(x.pointerId)},onPointerMove:x=>{if(!o.current)return;const N=Nn(o.current.startHeight,x.clientY-o.current.startY,l,i);s(N)},onPointerUp:x=>{if(o.current){o.current=null;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:x=>{if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault();const N=x.key==="ArrowDown"?u:-u,m=Nn(t,N,l,i);s(m),n(m)}},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 Nn(t,s,n,r){return aa(t+s,n,r)}function aa(t,s,n){return Math.min(Math.max(t,s),n)}function ra({src:t,filename:s,message:n}){const[r,l]=a.useState(!1),[i,o]=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(je,{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:()=>l(!0),onClick:()=>o(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),o(!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(la,{src:t,filename:s,onMaximize:()=>o(!0)}),i?e.jsx(Ul,{src:t,filename:s,message:n,onClose:()=>o(!1)}):null]})}function la({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(Bl,{})}),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(Vl,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(zl,{})}):null]})}function Ul({src:t,filename:s,message:n,onClose:r}){const l=a.useRef(null);return a.useEffect(()=>{var c;const i=u=>{u.key==="Escape"&&r()};document.addEventListener("keydown",i);const o=document.body.style.overflow;return document.body.style.overflow="hidden",(c=l.current)==null||c.focus(),()=>{document.removeEventListener("keydown",i),document.body.style.overflow=o}},[r]),Bn.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:l,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(Hl,{})}),e.jsx("img",{src:t,alt:s,onClick:i=>i.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:i=>i.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 js({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 Bl(){return e.jsxs(js,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function Vl(){return e.jsxs(js,{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 zl(){return e.jsx(js,{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 Hl(){return e.jsx(js,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function Wl({file:t}){const[s,n]=a.useState(!0),r=Gl(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(l=>!l),"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(Xl,{open:s}),e.jsx(oa,{}),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(Ql,{file:t,itemId:r}):null]})})}function Gl(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${Kl(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function Kl(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 Ql({file:t,itemId:s}){return t.kind==="image"?e.jsx(ra,{src:t.rawUrl,filename:t.filename,message:t.message}):t.kind==="video"?e.jsx(Yl,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(Jl,{src:t.rawUrl,filename:t.filename}):t.source==="inline"?e.jsx(ia,{kind:t.kind,text:t.content??"",language:t.language,itemId:s}):e.jsx(ql,{url:t.rawUrl,kind:t.kind,language:t.language,itemId:s})}function ia({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(Dl,{code:s})}):t==="markdown"?e.jsx(Ds,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Wt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(Ds,{itemId:r,children:e.jsx(Tl,{code:s,language:n})}):e.jsx(Ds,{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 Ds({itemId:t,children:s}){return t?e.jsx(Fl,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function ql({url:t,kind:s,language:n,itemId:r}){const[l,i]=a.useState(null);return a.useEffect(()=>{if(!t){i({error:!0});return}let o=!1;return i(null),fetch(t).then(c=>c.ok?c.text():Promise.reject(new Error(String(c.status)))).then(c=>!o&&i({text:c})).catch(()=>!o&&i({error:!0})),()=>{o=!0}},[t]),l===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in l?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(je,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(ia,{kind:s,text:l.text,language:n,itemId:r})}function Yl({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(je,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function Jl({src:t,filename:s}){return t?e.jsxs("div",{className:"group relative",children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-[600px] 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(oa,{}),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(la,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(je,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function Xl({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 oa(){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 Hs=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(ni,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(Dr,{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(Wl,{file:s.file}):s.kind==="tool"?e.jsx(li,{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(ti,{content:s.content}):null:s.kind==="compact"?e.jsx(si,{summary:s.summary}):s.kind==="notice"?e.jsx(ri,{notice:s.notice}):s.kind==="notification"?Sa(s.status)?e.jsx(ai,{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(Wt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(De,{})," ",e.jsx(De,{delay:"150ms"})," ",e.jsx(De,{delay:"300ms"})]})})})}),Zl=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function ei({turn:t}){const s=a.useContext(na);if(!(!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&Zl.test(t.id)))return e.jsx(Hs,{turn:t});const r=t.id.split("#")[0],l=t.contextTokens,i=s.contextLimit,o=l!=null&&i?Math.min(100,Math.round(l/i*100)):null,c="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",u=`${c} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{className:"group relative",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.jsxs("span",{className:`${c} gap-1 px-2 py-0.5 text-2xs text-fg-muted`,title:new Date(t.timestamp).toLocaleString(),children:[e.jsx("span",{children:It(t.timestamp)}),l!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",On(l),o!=null?` · ${o}%`:""]}):null]}),e.jsx("button",{type:"button",onClick:()=>s.onFork(r),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${u} hover:text-accent`,children:e.jsx(Ze,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(r),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${u} hover:text-danger`,children:e.jsx(et,{width:13,height:13})})]}),e.jsx(Hs,{turn:t})]})}function De({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function ti({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(Wt,{children:t})]})})}function si({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 ni({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(Ys,{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 ai({summary:t}){const s=a.useContext(en),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 ri({notice:t}){const s=a.useContext(en),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),l=t.kind==="error",i=l?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",o=l?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=l?"text-danger":"text-warn",u=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 ${i}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:l?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[u,"."]})," ",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."]}),l&&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 ${o}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function li({tool:t}){var h,A;const s=Vr(t.toolName),n=zr(t.toolName,t.output),r=s.isPaddock?el(s.tool):null,l=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[i,o]=a.useState(l),c=a.useContext(sa),u=a.useContext(ta),x=a.useRef(null),[N,m]=a.useState(!1),j=u!=null&&u.focused&&u.focused.toolUseId===t.toolUseId?u.focused.nonce:null;a.useEffect(()=>{var p;if(j==null)return;o(!0),(p=x.current)==null||p.scrollIntoView({behavior:"smooth",block:"center"}),m(!0);const q=setTimeout(()=>m(!1),3200);return()=>clearTimeout(q)},[j]);const y=a.useContext(ea),C=a.useContext(Zs),g=!!t.pending,f=bs.has(t.toolName),S=t.toolUseId?C==null?void 0:C.get(t.toolUseId):void 0,M=f?ds(t.subagentDurationMs??(S==null?void 0:S.elapsedMs)):ds(t.durationMs),R=t.subagentCostUsd!=null?`~${Fn(t.subagentCostUsd)}`:null,v=!f&&Xr(t),L=t.monitorEvents??[],E=t.editDiff,B=!!E,w=t.toolName==="Read"?t.readInfo:void 0,O=w!=null&&w.isImage&&w.projectRelPath&&c?c(w.projectRelPath):null,k=t.toolName==="Bash"?t.bashDetails:void 0,z=t.searchInfo,P=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,G=t.toolName==="TaskCreate"?t.taskCreate:void 0,J=!!(k&&k.stderr),T=z?nl(z):null,_=w?al(w):null,U=S!=null?S.running:Qr(t,y),H=!!(f&&t.hasSubagent&&t.toolUseId),ce=U&&t.toolUseId?(h=C==null?void 0:C.get(t.toolUseId))==null?void 0:h.latestStep:void 0,ne=f?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,X=f?ce??t.description:n?Hr(n):B?((A=E.filePath)==null?void 0:A.split("/").pop())??E.filePath:w?w.basename??w.filePath??t.inputSummary:G?G.subject:t.inputSummary,se=(w==null?void 0:w.filePath)??(G==null?void 0:G.description)??(ce?t.description:void 0)??X??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:x,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${N?"subagent-reveal ":""}${t.isError?"border-danger-edge bg-danger-soft":f?"border-accent-edge bg-accent-soft":v?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>o(q=>!q),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(fs,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${i?"rotate-90":""}`}),f?e.jsx(Js,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):v?e.jsx(et,{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"}`}):B?e.jsx(xs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):w?e.jsx(Vt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):z?e.jsx(Vn,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):P||G?e.jsx(pt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(zn,{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:ne}),f&&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"}),v&&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"}),P?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[P.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",P.taskId]}),P.from&&P.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(yn,{status:P.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(yn,{status:P.to})]}):P.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:P.updatedFields.join(", ")})]}):X&&e.jsx("span",{className:`min-w-0 truncate font-mono ${ce?"text-accent":"text-fg-muted"}`,title:se,children:X}),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"}),g||U?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:[v&&L.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[L.length," event",L.length===1?"":"s"]}),v&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${Zr(t.taskStatus)}`,children:t.taskStatus}),B&&(E.additions>0||E.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[E.additions>0&&e.jsxs("span",{className:"text-success",children:["+",E.additions]}),E.additions>0&&E.deletions>0&&" ",E.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",E.deletions]})]}),_&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:_}),T&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:T}),(k==null?void 0:k.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:k.gitHint}),(k==null?void 0:k.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"}),(k==null?void 0:k.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:k.returnCodeInterpretation}),M&&e.jsx("span",{className:"text-fg-subtle tabular",children:M}),R&&e.jsx("span",{className:"text-fg-subtle tabular",children:R})]})]})]}),i&&(H?e.jsx(di,{toolUseId:t.toolUseId,live:U}):v&&L.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:L.map((q,p)=>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:q},p))}):n?e.jsx(Kr,{data:n}):B?e.jsx(ii,{diff:E}):O?e.jsx("div",{className:"border-t border-edge",children:e.jsx(ra,{src:O,filename:(w==null?void 0:w.basename)??"image"})}):J?e.jsx(oi,{bash:k}):G&&G.description?e.jsx(ci,{info:G}):e.jsxs("div",{className:"border-t border-edge",children:[v&&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:g?"Running…":t.output||"(no output)"})]}))]})})}function ii({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,l)=>e.jsxs("div",{className:`flex ${tl(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:gn(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:gn(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||" "})]},l))]},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 yn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${sl(t)}`,children:t})}function oi({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 ci({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 kn=2e3;function di({toolUseId:t,live:s=!1}){var N,m;const n=a.useContext(Zn),[r,l]=a.useState(null),[i,o]=a.useState(!1),c=(m=(N=a.useContext(Zs))==null?void 0:N.get(t))==null?void 0:m.messages;a.useEffect(()=>{l(null),o(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){o(!0);return}let j=!1,y;const C=()=>{n(t).then(g=>{j||(l(g),s&&(y=setTimeout(C,kn)))}).catch(()=>{j||(s?y=setTimeout(C,kn):o(!0))})};return C(),()=>{j=!0,y&&clearTimeout(y)}},[n,t,s,!!c]);const u=c??r,x=a.useMemo(()=>hs(u??[]),[u]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:i?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):u==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(De,{})," ",e.jsx(De,{delay:"150ms"})," ",e.jsx(De,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):x.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(De,{})," ",e.jsx(De,{delay:"150ms"})," ",e.jsx(De,{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:[x.map(j=>e.jsx(Hs,{turn:j},j.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(De,{})," ",e.jsx(De,{delay:"150ms"})," ",e.jsx(De,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function ui(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:l,onSessionStarted:i,onTurnComplete:o,sessionRef:c,jobRef:u,pendingCancelRef:x,streamingRef:N,awaitingSessionRef:m,isNewSessionRef:j,startedNotifiedRef:y,establishedHereRef:C,modelRef:g,cancelledRef:f,noticeThisTurnRef:S,seenInjectionsRef:M,onQueuedFlushedRef:R,onQueuedStateRef:v,onQueuedReturnedRef:L,setTurns:E,setStreaming:B,setUsage:w,setSessionUsage:O,setError:k}=t;a.useEffect(()=>{const z=T=>{const _=c.current;return _?T.sessionId===_?!0:T.sessionId==null&&N.current:m.current},P=T=>{c.current=T,m.current=!1,J.setSessionId(T),j.current&&!y.current&&(y.current=!0,C.current=T,g.current&&Bs(T,s,g.current),i==null||i(T))},G=T=>{u.current=T,x.current&&(x.current=!1,Ue.cancel(T))},J=Ue.subscribe(s,c.current,{onResponse:(T,_)=>{z(_)&&(_.jobId&&G(_.jobId),_.sessionId&&P(_.sessionId),ll(E,T))},onToolStart:(T,_)=>{z(_)&&(_.jobId&&G(_.jobId),_.sessionId&&P(_.sessionId),E(U=>T.toolUseId&&U.some(H=>H.kind==="tool"&&H.tool.toolUseId===T.toolUseId)?U:[...Oe(U),{kind:"tool",id:Ge(),tool:T}]))},onToolCall:(T,_)=>{if(!z(_))return;_.jobId&&G(_.jobId),_.sessionId&&P(_.sessionId);const U=Xn(T);E(H=>{if(T.toolUseId){const ne=H.findIndex(X=>X.kind==="tool"&&X.tool.toolUseId===T.toolUseId);if(ne!==-1){const X=H[ne].id,se=H.slice();return se[ne]=U?{kind:"file",id:X,file:U}:{kind:"tool",id:X,tool:T},se}}const ce=U?{kind:"file",id:Ge(),file:U}:{kind:"tool",id:Ge(),tool:T};return[...Oe(H),ce]})},onMessageBoundary:T=>{z(T)&&(T.jobId&&G(T.jobId),E(_=>Oe(_)))},onComplete:T=>{if(z(T)){T.jobId&&G(T.jobId),N.current=!1,B(!1),E(_=>bn(Oe(_))),T.usage&&w(T.usage);{const _=T.sessionId??c.current;_&&F.chatContext(s,_).then(U=>O(U)).catch(()=>{})}if(T.sessionId){const _=j.current&&c.current!==T.sessionId;P(T.sessionId),(_||j.current)&&(j.current=!1,g.current&&Bs(T.sessionId,s,g.current),C.current=T.sessionId,l==null||l(T.sessionId))}!T.success&&T.error&&!S.current&&k(T.error);{const _=T.sessionId??c.current;o==null||o(_&&T.usage?{sessionId:_,usage:T.usage}:void 0)}f.current=!1}},onError:T=>{N.current&&(N.current=!1,B(!1),u.current=null,E(_=>bn(Oe(_))),k(T),f.current=!1)},onResync:()=>{const T=c.current;!T||!r||r(T).then(_=>E(hs(_))).catch(()=>{})},onActive:({running:T,jobId:_})=>{T?(_&&G(_),N.current=!0,B(!0)):(N.current=!1,B(!1),u.current=null,E(U=>Oe(U)),f.current=!1,x.current=!1)},onQueuedFlushed:({text:T,attachments:_})=>{R.current(T,_)},onQueuedState:({text:T,qid:_,reason:U,attachments:H})=>{v.current(T,_,U,H)},onQueuedReturned:({text:T,attachments:_})=>{L.current(T,_)},onInjected:(T,_)=>{if(!z(_))return;_.jobId&&G(_.jobId),_.sessionId&&P(_.sessionId);const U=`${T.timestamp} ${T.content}`;M.current.has(U)||(M.current.add(U),E(H=>[...Oe(H),{kind:"user",id:Ge(),content:T.content,sender:T.sender}]))},onKilledTask:({summary:T,timestamp:_})=>{const U=`killed ${_}`;M.current.has(U)||(M.current.add(U),E(H=>[...Oe(H),{kind:"notification",id:Ge(),summary:T,status:"killed"}]))},onNotice:(T,_)=>{z(_)&&(S.current=!0,E(U=>[...Oe(U),{kind:"notice",id:Ge(),notice:T}]))}});return()=>{J.unsubscribe()}},[s,n,r,l,i,o])}const ca="paddock:attachments:",da="paddock:newchat-instance:";function mi(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function hi(t){try{const s=da+t,n=sessionStorage.getItem(s);if(n)return n;const r=mi();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${ca}new:${t}`)}catch{}return r}catch{return"shared"}}function xi(t){try{localStorage.removeItem(Bt(null,t))}catch{}try{sessionStorage.removeItem(da+t)}catch{}}function Bt(t,s){return ca+(t??`new:${s}:${hi(s)}`)}function fi(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 pi(t,s){try{const n=localStorage.getItem(Bt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(fi).filter(l=>l!==null):[]}catch{return[]}}function gi(t,s,n){try{const r=Bt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function bi({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:l,setError:i}){const[o,c]=a.useState(()=>pi(s,t)),u=a.useRef([]);u.current=o;const[x,N]=a.useState(!1),[m,j]=a.useState(!1),y=a.useRef(null);a.useEffect(()=>{gi(s,t,o)},[o,s,t]);const C=a.useRef(null);a.useEffect(()=>{if(!s){C.current=Bt(null,t);return}const w=C.current;if(C.current=null,!(!w||w===Bt(s,t)))try{localStorage.removeItem(w)}catch{}},[s,t]);const g=a.useMemo(()=>{const w=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},O=r??{};return{enabled:O.enabled??w.enabled,maxFileSizeMb:O.maxFileSizeMb??w.maxFileSizeMb,maxFilesPerMessage:O.maxFilesPerMessage??w.maxFilesPerMessage,allowedTypes:O.allowedTypes??w.allowedTypes}},[n,r]),f=g.enabled,S=a.useCallback(async w=>{if(!f||w.length===0)return;const O=g.maxFileSizeMb*1024*1024,k=g.maxFilesPerMessage-u.current.length;if(k<=0){i(`You can attach at most ${g.maxFilesPerMessage} files per message.`);return}const z=[];for(const P of w.slice(0,k)){if(!_r(g.allowedTypes,P.type,P.name)){i(`File type not allowed: ${P.name}`);continue}if(P.size>O){i(`File too large (max ${g.maxFileSizeMb} MB): ${P.name}`);continue}z.push(P)}if(w.length>k&&i(`You can attach at most ${g.maxFilesPerMessage} files per message.`),z.length!==0){N(!0);try{const{files:P}=await F.uploadAttachments(t,l.current??"new",z);c(G=>[...G,...P])}catch(P){i(P instanceof Error?P.message:"Upload failed.")}finally{N(!1)}}},[f,g,t]),M=a.useCallback(w=>{c(O=>O.filter(k=>k.id!==w))},[]),R=a.useCallback(w=>{var k;if(!f)return;const O=Array.from(((k=w.clipboardData)==null?void 0:k.files)??[]);O.length>0&&(w.preventDefault(),S(O))},[f,S]),v=a.useCallback(w=>{var O;f&&Array.from(((O=w.dataTransfer)==null?void 0:O.types)??[]).includes("Files")&&(w.preventDefault(),j(!0))},[f]),L=a.useCallback(w=>{w.currentTarget===w.target&&j(!1)},[]),E=a.useCallback(w=>{var k;if(!f)return;const O=Array.from(((k=w.dataTransfer)==null?void 0:k.files)??[]);O.length>0&&(w.preventDefault(),j(!1),S(O))},[f,S]),B=a.useCallback(w=>{const O=Array.from(w.target.files??[]);O.length>0&&S(O),w.target.value=""},[S]);return{attachments:o,attachRef:u,setAttachments:c,uploading:x,dragOver:m,fileInputRef:y,attachConfig:g,attachEnabled:f,addFiles:S,removeAttachment:M,onComposerPaste:R,onComposerDragOver:v,onComposerDragLeave:L,onComposerDrop:E,onPickFiles:B}}function ji({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:l,onTurnComplete:i,preloadAvailable:o=!1,projectModel:c,projectModels:u,forkParent:x,onOpenForkParent:N,autoFocus:m,emptyHint:j,placeholder:y,trigger:C,projectRecovery:g,projectAttachments:f,onForkFromMessage:S,onRevertToMessage:M}){const[R,v]=a.useState([]),[L,E]=a.useState(()=>$r(s,t)),B=a.useRef(null),[w,O]=a.useState(!1),[k,z]=a.useState(!1),[P,G]=a.useState(null),[J,T]=a.useState(null),[_,U]=a.useState(Ue.state),[H,ce]=a.useState(null),[ne,X]=a.useState(()=>rr(s,t)),se=a.useRef(ne),h=a.useRef(lr(s,t)),[A,q]=a.useState(()=>ir(s,t)),p=a.useRef(A);p.current=A;const ee=ne!=null||A.length>0,pe=a.useRef(!1),Ve=a.useRef(!1),[ge,be]=a.useState(!0),me=!s,we=a.useRef(!1),[Me,de]=a.useState([]),[$e,_e]=a.useState(null),[Te,Pe]=a.useState(null),[ye,ze]=a.useState(null),[He,Q]=a.useState(null),[ke,he]=a.useState([]),[We,Le]=a.useState(0),[it,Ke]=a.useState(!1),Ae=a.useRef(null),[Ee,I]=a.useState(null),[te,ae]=a.useState(null),xe=c??$e,re=a.useMemo(()=>u&&u.length>0?Me.filter(b=>u.includes(b.id)):Me,[Me,u]),Ce=a.useRef(s??null),tt=a.useRef(null),Z=a.useRef(!1),{attachments:$t,attachRef:st,setAttachments:Qe,uploading:gt,dragOver:ot,fileInputRef:qe,attachConfig:vs,attachEnabled:Fe,removeAttachment:bt,onComposerPaste:jt,onComposerDragOver:Et,onComposerDragLeave:Gt,onComposerDrop:ve,onPickFiles:nt}=bi({projectSlug:t,initialSessionId:s,attachmentsDefault:He,projectAttachments:f,sessionRef:Ce,setError:G}),Rt=a.useCallback(b=>Ce.current?F.subagentMessages(t,Ce.current,b):Promise.resolve([]),[t]),Tt=jl(R),ct=bl(Tt,Rt,w),ws=a.useMemo(()=>Tt.filter(b=>{var D;return((D=ct.get(b.toolUseId))==null?void 0:D.running)??w}),[Tt,ct,w]),Kt=a.useMemo(()=>t?b=>F.projectFileRawUrl(t,b):null,[t]),at=a.useRef(!s),dt=a.useRef(!1),Mt=a.useRef(!1),Qt=a.useRef(!1),vt=a.useRef(null),_t=a.useRef(null),ut=a.useRef(!0),Dt=a.useRef(new Set),Pt=a.useCallback(()=>{const b=_t.current;b&&(ut.current=b.scrollHeight-b.scrollTop-b.clientHeight<80)},[]);a.useLayoutEffect(()=>{const b=_t.current;b&&ut.current&&(b.scrollTop=b.scrollHeight)},[R]);const[qt,Ns]=a.useState(null),Yt=a.useMemo(()=>({focused:qt,focus:b=>{ut.current=!1,Ns(D=>({toolUseId:b,nonce:((D==null?void 0:D.nonce)??0)+1}))}}),[qt]);a.useEffect(()=>Ue.onState(U),[]),a.useEffect(()=>{let b=!1;return F.getModels().then(D=>{b||(de(D.models),_e(D.defaultModel),ze(D.recoveryDefault),Q(D.attachmentsDefault))}).catch(()=>{}),()=>{b=!0}},[]),a.useEffect(()=>{let b=!1;return F.projectCommands(t).then(D=>{b||he(D)}).catch(()=>{}),()=>{b=!0}},[t]);const Ye=a.useMemo(()=>{if(!L.startsWith("/"))return null;const b=L.slice(1);return/\s/.test(b)?null:b},[L]),Je=a.useMemo(()=>{if(Ye===null)return[];const b=Ye.toLowerCase();return ke.filter(D=>D.name.toLowerCase().includes(b))},[Ye,ke]),Jt=Ye!==null&&!it&&Je.length>0;a.useEffect(()=>{Le(0)},[Ye]),a.useEffect(()=>{Ke(!1)},[Ye]);const mt=a.useCallback(b=>{E(`/${b.name} `),requestAnimationFrame(()=>{var D;return(D=B.current)==null?void 0:D.focus()})},[]),ys=a.useCallback(b=>{Pe(b),Ae.current=b,Bs(Ce.current??s,t,b)},[t,s]);a.useEffect(()=>{if(s&&s===vt.current){at.current=!1;return}let b=!1;return Ce.current=s??null,at.current=!s,tt.current=null,dt.current=!1,Mt.current=!1,Qt.current=!1,G(null),O(!1),s&&n?(z(!0),v([]),n(s).then(D=>{b||v(le=>ul(hs(D),le))}).catch(()=>{b||G("Could not load this chat's history.")}).finally(()=>{b||z(!1)})):(v([]),z(!1)),s&&F.chatContext(t,s).then(D=>{b||!D||(I({inputTokens:D.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:D.contextTokens,contextLimit:D.contextLimit}),ae(D))}).catch(()=>{}),()=>{b=!0}},[t,s,n]);const Xt=a.useCallback(async()=>{if(!(!s||!n)){try{const b=await n(s);v(hs(b))}catch{G("Could not reload this chat's history.")}try{const b=await F.chatContext(t,s);b&&(I({inputTokens:b.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:b.contextTokens,contextLimit:b.contextLimit}),ae(b))}catch{}}},[s,n,t]),Lt=a.useCallback(b=>{if(!M)return;const D=R.findIndex(Re=>Re.id.split("#")[0]===b),le=D>=0&&R[D].kind==="user";let Y=D+1;if(le){let Re=D-1;for(;Re>=0&&R[Re].kind!=="assistant";)Re--;Y=Re+1}else for(;Y<R.length&&(R[Y].kind==="tool"||R[Y].kind==="file");)Y++;const ue=D>=0?R.slice(Y):[],Ne=ue.filter(Re=>Re.kind==="tool").length;ce({uuid:b,count:ue.length,toolCount:Ne,anchorIsUser:le})},[M,R]),ks=a.useCallback(async()=>{if(H){try{await(M==null?void 0:M(H.uuid)),await Xt()}catch{throw new Error("Could not revert this chat.")}ce(null)}},[H,M,Xt]),Cs=a.useMemo(()=>S&&M?{onFork:S,onRevert:Lt,contextLimit:Ee==null?void 0:Ee.contextLimit}:null,[S,M,Lt,Ee==null?void 0:Ee.contextLimit]);a.useEffect(()=>{const D=Sr(s,t)??xe;D&&(Pe(D),Ae.current=D)},[t,s,xe]),a.useEffect(()=>{s&&s===vt.current||(I(null),ae(null))},[t,s]),a.useEffect(()=>{Er(s,t,L)},[L,s,t]),a.useEffect(()=>{if(J==null)return;const b=setTimeout(()=>T(null),8e3);return()=>clearTimeout(b)},[J]),a.useEffect(()=>{or(s,t,ne),cr(s,t,ee?h.current:null),dr(s,t,A)},[ne,A,ee,s,t]),a.useEffect(()=>{s&&Ue.setQueued(t,s,ne,ee?h.current:null,A)},[ne,A,ee,s,t,Ue]),a.useEffect(()=>{var b;(m||!s)&&((b=B.current)==null||b.focus())},[]);const Zt=a.useCallback((b,D)=>{const le=D??[];(b||le.length>0)&&(ut.current=!0,v(Y=>[...Oe(Y),{kind:"user",id:Ge(),content:b??"",...le.length>0?{attachments:le}:{}}])),se.current=null,h.current=null,X(null),q([])},[]),es=a.useCallback((b,D,le,Y)=>{D&&(h.current=D);const ue=b&&b.length>0?b:null,Ne=Y??[];le==="returned"&&(se.current!=null||p.current.length)&&T("Stopped — the queued message went back to the composer that stopped the turn.");const Re=Ne.length===p.current.length&&Ne.every((os,d)=>{var $;return os.id===(($=p.current[d])==null?void 0:$.id)});se.current===ue&&Re||(se.current=ue,ue===null&&Ne.length===0&&(h.current=null),X(ue),Re||q(Ne))},[]),ts=a.useRef(es);ts.current=es;const wt=a.useCallback((b,D)=>{se.current=null,h.current=null,X(null);const le=D??p.current;le.length>0&&Qe(Y=>{const ue=new Set(Y.map(Ne=>Ne.id));return[...Y,...le.filter(Ne=>!ue.has(Ne.id))]}),q([]),E(Y=>Y.trim()?`${b}
8
- ${Y}`:b),requestAnimationFrame(()=>{const Y=B.current;Y&&(Y.style.height="auto",Y.style.height=`${Math.min(Y.scrollHeight,192)}px`,Y.focus())})},[Qe]),ss=a.useCallback((b,D)=>wt(b,D),[wt]),ns=a.useRef(ss);ns.current=ss;const as=a.useRef(Zt);as.current=Zt,ui({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:l,onTurnComplete:i,sessionRef:Ce,jobRef:tt,pendingCancelRef:Z,streamingRef:dt,awaitingSessionRef:Mt,isNewSessionRef:at,startedNotifiedRef:Qt,establishedHereRef:vt,modelRef:Ae,cancelledRef:pe,noticeThisTurnRef:Ve,seenInjectionsRef:Dt,onQueuedFlushedRef:as,onQueuedStateRef:ts,onQueuedReturnedRef:ns,setTurns:v,setStreaming:O,setUsage:I,setSessionUsage:ae,setError:G});const rs=a.useCallback(b=>{G(null),ut.current=!0;const D=b.startsWith("/")?[]:st.current;if(v(ue=>[...Oe(ue),{kind:"user",id:Ge(),content:b,...D.length>0?{attachments:D}:{}}]),D.length>0&&(Qe([]),st.current=[]),B.current&&(B.current.style.height="auto"),O(!0),dt.current=!0,Ve.current=!1,tt.current=null,Z.current=!1,Ce.current===null&&(Mt.current=!0),b.startsWith("/")){we.current=!0,Ue.sendCommand(t,b,Ce.current);return}const Y=at.current&&!we.current&&ge;we.current=!0,Ue.send(t,b,Ce.current,{preloadContext:Y,model:Ae.current??void 0,attachments:D.map(ue=>({id:ue.id,filename:ue.filename,kind:ue.kind}))})},[t,ge]),ht=a.useCallback(()=>{const b=L.trim();if(!(!b&&st.current.length===0)){if(w){const le=(se.current??b).startsWith("/")?[]:st.current;le.length>0&&(q(Y=>{const ue=new Set(Y.map(Ne=>Ne.id));return[...Y,...le.filter(Ne=>!ue.has(Ne.id))]}),Qe([]),st.current=[]),X(Y=>{const ue=b?Y?`${Y}
9
- ${b}`:b:Y;return se.current=ue,(Y==null||h.current==null)&&(h.current=ur()),ue}),E(""),B.current&&(B.current.style.height="auto");return}E(""),rs(b)}},[L,w,rs,st,Qe]),Ss=a.useCallback(()=>{const b=se.current;b==null&&p.current.length===0||wt(b??"")},[wt]),Is=a.useCallback(()=>{se.current=null,h.current=null,X(null),q([])},[]),$s=a.useCallback(()=>{pe.current=!0,tt.current?Ue.cancel(tt.current):Z.current=!0},[]),ls=a.useCallback(()=>{const b=Ce.current;b&&(dt.current||(O(!0),Ue.continueChat(t,b)))},[t]),is=a.useMemo(()=>({enabled:(g==null?void 0:g.surfaceKilledTask)??(ye==null?void 0:ye.surfaceKilledTask)??!0,busy:w,onContinue:ls}),[t,g,ye,w,ls]),Xe=b=>{if(Jt){if(b.key==="ArrowDown"){b.preventDefault(),Le(D=>(D+1)%Je.length);return}if(b.key==="ArrowUp"){b.preventDefault(),Le(D=>(D-1+Je.length)%Je.length);return}if(b.key==="Tab"){b.preventDefault(),mt(Je[We]);return}if(b.key==="Enter"){const D=Je[We];if(D&&D.name!==Ye){b.preventDefault(),mt(D);return}}if(b.key==="Escape"){b.preventDefault(),Ke(!0);return}}b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),ht())},an=a.useCallback(b=>{E(le=>le.trim()?`${le.trimEnd()} ${b}`:b);const D=B.current;D&&requestAnimationFrame(()=>{D.style.height="auto",D.style.height=`${Math.min(D.scrollHeight,192)}px`,D.focus()})},[]),Es=R.length===0&&!k;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:_t,onScroll:Pt,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:[C&&e.jsx(Or,{trigger:C,projectSlug:t}),k&&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"})]}),Es&&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(Js,{width:22,height:22})}),e.jsx("p",{className:"max-w-sm text-sm text-fg-subtle",children:j??"Start the conversation. Messages stream live from Claude and persist as a resumable session."})]}),e.jsx(Zn.Provider,{value:Rt,children:e.jsx(ea.Provider,{value:w,children:e.jsx(Zs.Provider,{value:ct,children:e.jsx(ta.Provider,{value:Yt,children:e.jsx(sa.Provider,{value:Kt,children:e.jsx(Jn.Provider,{value:t,children:e.jsx(en.Provider,{value:is,children:e.jsx(na.Provider,{value:Cs,children:e.jsx("div",{className:"space-y-4",children:R.map(b=>e.jsx(ei,{turn:b},b.id))})})})})})})})})})]})}),e.jsx(ml,{running:ws,activity:ct,onReveal:Yt.focus}),w&&e.jsx(kl,{}),P&&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(je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:P})]})}),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-edge bg-surface-hover px-3 py-2 text-sm text-fg-muted",children:[e.jsx(et,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:J})]})}),ee&&e.jsx(Cl,{text:ne??"",attachments:A,onEdit:Ss,onClear:Is}),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:[me&&e.jsx(vl,{checked:ge,available:o,onChange:be}),e.jsx(wl,{models:re,model:Te,onSelectModel:ys,usage:Ee,sessionUsage:te,forkParent:x,onOpenForkParent:N}),Fe&&($t.length>0||gt)&&e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2","data-testid":"attachment-tray",children:[$t.map(b=>e.jsx(Lr,{attachment:b,onRemove:bt},b.id)),gt&&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 ${ot?"border-accent ring-2 ring-accent/30":"border-edge-strong"}`,onDragOver:Fe?Et:void 0,onDragLeave:Fe?Gt:void 0,onDrop:Fe?ve:void 0,children:[ot&&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"}),Jt&&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:Je.map((b,D)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${D===We?"bg-surface-selected":""}`,onMouseEnter:()=>Le(D),onMouseDown:le=>{le.preventDefault(),mt(b)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",b.name]}),b.argumentHint&&e.jsx("span",{className:"shrink-0 text-fg-subtle",children:b.argumentHint}),b.description&&e.jsx("span",{className:"ml-auto truncate text-fg-muted",children:b.description})]})},b.name))}),e.jsx("textarea",{ref:B,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:L,placeholder:w?"Queue a message to send next…":y??"Message Claude…",onChange:b=>{E(b.target.value);const D=b.target;D.style.height="auto",D.style.height=`${Math.min(D.scrollHeight,192)}px`},onKeyDown:Xe,onPaste:Fe?jt:void 0}),Fe&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:qe,type:"file",multiple:!0,accept:Mr(vs.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:nt}),e.jsx("button",{type:"button",onClick:()=>{var b;return(b=qe.current)==null?void 0:b.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(Ia,{width:16,height:16})})]}),e.jsx(yr,{onText:an}),w?e.jsxs("button",{type:"button",onClick:$s,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:ht,disabled:!L.trim()&&$t.length===0||gt,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(An,{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 ",w?"queue":"send"," ·"," ",e.jsx("kbd",{className:"font-sans",children:"Shift+Enter"})," for newline"]}),e.jsx(Sl,{state:_})]})]})}),e.jsx(us,{open:H!==null,wide:!0,dismissOnBackdrop:!1,title:"Revert this chat back to here?",confirmLabel:"Revert chat",message:H&&e.jsxs(e.Fragment,{children:[H.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:[H.count," message",H.count===1?"":"s"]})," ","will be removed",H.toolCount>0?e.jsxs(e.Fragment,{children:[", including"," ",e.jsxs("span",{className:"font-medium text-fg",children:[H.toolCount," tool call",H.toolCount===1?"":"s"]}),"."]}):"."]}),H.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:ks,onClose:()=>ce(null)})]})}function vi(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 wi({slug:t,status:s,onStatusChange:n,selectedFile:r,onSelectFile:l}){var q;const[i,o]=a.useState(null),[c,u]=a.useState(null),x=l!==void 0,N=x?r??null:c,m=a.useCallback(p=>{x?l==null||l(p):u(p)},[x,l]),[j,y]=a.useState(""),[C,g]=a.useState(!1),[f,S]=a.useState(!1),[M,R]=a.useState(null),[v,L]=a.useState(null),[E,B]=a.useState(new Set),w=s.files,O=w.length,k=w.filter(p=>!E.has(p.path)).map(p=>p.path),z=k.length,P=z===w.length&&w.length>0,G=a.useCallback(p=>{B(ee=>{const pe=new Set(ee);return pe.has(p)?pe.delete(p):pe.add(p),pe})},[]),J=a.useCallback(()=>B(new Set),[]),T=a.useCallback(()=>B(new Set(w.map(p=>p.path))),[w]),_=a.useCallback(async()=>{const p=await F.gitInfo().catch(()=>null);p&&o(p)},[]);a.useEffect(()=>{_()},[_]);const U=a.useCallback(async()=>{const p=await F.gitStatus(t).catch(()=>null);p&&n(p)},[t,n]),H=N&&w.some(p=>p.path===N)?N:((q=w[0])==null?void 0:q.path)??null,ce=w.find(p=>p.path===H)??null,ne=a.useCallback(async()=>{const p=j.trim();if(!(!p||C||k.length===0)){g(!0),R(null),L(null);try{const ee=P?await F.gitCommit(t,p):await F.gitCommit(t,p,k);ee.committed?(y(""),B(new Set),L(ee.hash?`Committed ${ee.hash.slice(0,7)}`:"Committed"),await U(),await _()):L(ee.error??"Nothing to commit")}catch(ee){R(ee instanceof Ie?ee.message:"Commit failed")}finally{g(!1)}}},[j,C,k,P,t,U,_]),X=(i==null?void 0:i.ahead)??0,se=(i==null?void 0:i.configured)??!1,h=se&&X>0&&!f,A=a.useCallback(async()=>{if(h){S(!0),R(null),L(null);try{const p=await F.gitPush();p.pushed?(L("Pushed to remote"),await _()):R(p.error??"Push failed")}catch(p){R(p instanceof Ie?p.message:"Push failed")}finally{S(!1)}}},[h,_]);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(Ze,{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(pt,{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:[O," uncommitted"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(Ii,{info:i,onChanged:_}),e.jsxs("button",{type:"button",onClick:()=>void A(),disabled:!h,title:se?X>0?`Push ${X} commit${X===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx($a,{width:13,height:13}),f?"Pushing…":"Push",se&&X>0&&e.jsxs("span",{className:"text-2xs font-semibold text-accent",children:["↑",X]})]})]})]}),(M||v)&&e.jsxs("div",{className:"px-4 pt-2",children:[M&&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(je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:M})]}),!M&&v&&e.jsx("p",{className:"text-xs text-fg-muted",children:v})]}),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"}),w.length>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[z,"/",w.length," selected"]}),e.jsx("button",{type:"button",onClick:P?T:J,className:"rounded px-1 py-0.5 font-medium text-accent hover:bg-accent/10",title:P?"Deselect all files":"Select all files",children:P?"None":"All"})]})]}),e.jsx("div",{className:"max-h-[35vh] overflow-y-auto px-2 pb-2 lg:max-h-none lg:flex-1",children:w.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."}):w.map(p=>e.jsx(Ni,{file:p,active:H===p.path,selected:!E.has(p.path),onSelect:()=>m(p.path),onToggleSelect:()=>G(p.path)},p.path))}),e.jsxs("div",{className:"border-t border-edge p-3",children:[e.jsx("textarea",{rows:2,value:j,placeholder:"Commit message…",onChange:p=>y(p.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 ne(),disabled:!j.trim()||C||z===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:w.length===0?"Nothing to commit":z===0?"Select at least one file to commit":P?"Commit all changed files":`Commit ${z} selected file${z===1?"":"s"}`,children:[e.jsx(pt,{width:13,height:13}),C?"Committing…":z>0&&!P?`Commit ${z} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(yi,{slug:t,file:ce})})]})]})}function sn({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 Ni({file:t,active:s,selected:n,onSelect:r,onToggleSelect:l}){const i=vi(t),o=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:l,"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 ${i.cls}`,children:i.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:o}),e.jsx(sn,{file:t})]})]})]})]})}function yi({slug:t,file:s}){const n=(s==null?void 0:s.path)??null,r=(s==null?void 0:s.untracked)??!1,[l,i]=a.useState(""),[o,c]=a.useState(!1),[u,x]=a.useState(null);if(a.useEffect(()=>{if(!n||r){i(""),x(null),c(!1);return}let m=!1;return c(!0),x(null),F.gitDiff(t,n).then(j=>{m||i(j)}).catch(j=>{m||x(j instanceof Ie?j.message:"Failed to load diff")}).finally(()=>{m||c(!1)}),()=>{m=!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(Si,{slug:t,file:s});if(o)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(u)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(je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:u})]})});if(!l.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 N=l.split(`
10
- `);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(ki,{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:N.map((m,j)=>e.jsx("div",{className:Ci(m),children:m||" "},j))})})]})}function ki({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(sn,{file:t})]})}function Ci(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 Si({slug:t,file:s}){const n=s.path,[r,l]=a.useState(null),[i,o]=a.useState(!0),[c,u]=a.useState(null);a.useEffect(()=>{let N=!1;return o(!0),u(null),l(null),F.getProjectFile(t,n).then(m=>{N||l(m)}).catch(m=>{N||u(m instanceof Ie?m.message:"Failed to load file")}).finally(()=>{N||o(!1)}),()=>{N=!0}},[t,n]);const x=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(sn,{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 i?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(je,{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:[x,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:F.projectFileRawUrl(t,n),alt:n,className:"max-h-full max-w-full object-contain shadow-sm"})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[x,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 Ii({info:t,onChanged:s}){const[n,r]=a.useState(!1),[l,i]=a.useState(null),[o,c]=a.useState(!1),[u,x]=a.useState(null),[N,m]=a.useState(!1),j=a.useRef(!1);a.useEffect(()=>(j.current=!1,()=>{j.current=!0}),[]);const y=t==null?void 0:t.github,C=a.useCallback(async()=>{r(!0),x(null);try{const f=await F.githubConnect();i({userCode:f.userCode,verificationUri:f.verificationUri}),c(!0),j.current=!1;const S=Date.now()+f.expiresIn*1e3;let M=Math.max(1,f.interval)*1e3;const R=async()=>{if(!j.current){if(Date.now()>=S){c(!1),i(null),x("The code expired before authorization. Try again.");return}try{const v=await F.githubPoll(f.deviceCode);if(j.current)return;if(v.status==="authorized"){c(!1),i(null),await s();return}if(v.status==="error"){c(!1),i(null),x(v.error??"Authorization failed.");return}v.status==="slow_down"&&(M+=5e3),window.setTimeout(()=>void R(),M)}catch(v){if(j.current)return;c(!1),i(null),x(v instanceof Ie?v.message:"Polling failed.")}}};window.setTimeout(()=>void R(),M)}catch(f){x(f instanceof Ie?f.message:"Could not start the GitHub connection.")}finally{r(!1)}},[s]),g=a.useCallback(async()=>{m(!0);try{await F.githubDisconnect(),await s()}catch{}finally{m(!1)}},[s]);return y?y.configured?y.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(Rs,{width:13,height:13}),"@",y.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void g(),disabled:N,className:"btn-subtle px-2 py-1 text-2xs",title:"Disconnect GitHub",children:N?"…":"Disconnect"})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[l?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:l.userCode}),e.jsx("span",{className:"text-fg-muted",children:"at"}),e.jsxs("a",{href:l.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(Ln,{width:11,height:11}),"github.com"]}),o&&e.jsx("span",{className:"text-fg-subtle",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void C(),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(Rs,{width:13,height:13}),n?"Starting…":"Connect GitHub"]}),u&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-danger",children:[e.jsx(je,{width:12,height:12}),u]})]}):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(Rs,{width:13,height:13}),"GitHub not configured"]}):null}function $i(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(et,{width:12,height:12}),cls:"bg-warn-soft text-warn"}:t==="spawned"?{label:"Spawned",icon:e.jsx(Ze,{width:12,height:12}),cls:"bg-lineage-soft text-lineage"}:t==="adopted"?{label:"Adopted",icon:e.jsx(ps,{width:12,height:12}),cls:"bg-success-soft text-success"}:{label:"You",icon:e.jsx(Ht,{width:12,height:12}),cls:"bg-surface-active text-fg-muted"}}function Ei(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 Ri(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 Ps(t){return t.origin!=="human"&&t.origin!=="adopted"}function Ti(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 Mi({run:t,title:s,onOpen:n}){var c,u;const r=$i(t.origin),l=Ei(t.status),i=t.sessionId!=null,o=((c=t.prompt)==null?void 0:c.trim())||((u=t.summary)==null?void 0:u.trim())||s;return e.jsxs("button",{type:"button",onClick:i?n:void 0,disabled:!i,"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 ${i?"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 ${l.cls}`,children:l.label})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-fg",children:o}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-fg-muted",children:Ti(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:It(t.startedAt)}),e.jsx("span",{className:"font-mono tabular",children:Ri(t)}),e.jsx("span",{className:"font-mono text-fg-subtle",title:"Per-run cost is coming soon",children:"—"})]})]})}function _i({slug:t,state:s,chats:n,onOpenChat:r}){const{data:l,loading:i,error:o,refresh:c,markSeen:u}=s,[x,N]=a.useState("unattended");a.useEffect(()=>{u()},[t]);const m=a.useMemo(()=>{const f=new Map;for(const S of n)f.set(S.sessionId,S.name);return S=>S&&f.get(S)||(S?S.slice(0,8):"unknown chat")},[n]),j=(l==null?void 0:l.runs)??[],y=a.useMemo(()=>j.filter(Ps).length,[j]),C=a.useMemo(()=>x==="unattended"?j.filter(Ps):j,[j,x]),g=a.useMemo(()=>j.filter(f=>f.isNew&&Ps(f)).length,[j]);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(Cn,{active:x==="unattended",onClick:()=>N("unattended"),children:["Unattended",y>0?` (${y})`:""]}),e.jsx(Cn,{active:x==="all",onClick:()=>N("all"),children:"All"})]})]}),g>0&&e.jsxs("div",{"data-since-last-visit":g,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:[g," new ",g===1?"run":"runs"]})," ","ran while you were away."]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:o?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-danger",children:o}):i&&j.length===0?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-fg-muted",children:"Loading run history…"}):C.length===0?e.jsx(Di,{filter:x,hasAny:j.length>0}):e.jsx("div",{children:C.map(f=>e.jsx(Mi,{run:f,title:m(f.sessionId),onOpen:()=>f.sessionId&&r(f.sessionId)},f.jobId))})})]})}function Cn({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 Di({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 Pi(t){const[s,n]=a.useState(null),[r,l]=a.useState(!0),[i,o]=a.useState(null),[c,u]=a.useState(!1),x=a.useCallback(async()=>{l(!0),u(!1);try{const j=await F.projectRuns(t);n(j),o(null)}catch(j){o(j instanceof Error?j.message:"Failed to load run history")}finally{l(!1)}},[t]);a.useEffect(()=>{x()},[x]);const N=a.useCallback(async()=>{u(!0),await F.markRunsSeen(t).catch(()=>{})},[t]),m=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:r,error:i,newUnattended:m,refresh:x,markSeen:N}}function Li({slug:t,name:s}){const[n,r]=a.useState(null),[l,i]=a.useState(null),[o,c]=a.useState(!0);return a.useEffect(()=>{let u=!1;return c(!0),i(null),r(null),F.getProjectFile(t,s).then(x=>{u||r(x)}).catch(x=>{u||i(x instanceof Error?x.message:"Failed to load file")}).finally(()=>{u||c(!1)}),()=>{u=!0}},[t,s]),o?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"})]}):l||!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(je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:l??"File not found."})]})}):n.kind==="image"?e.jsx(Fi,{slug:t,name:n.name}):n.kind==="html"?e.jsx(Ai,{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(Wt,{mermaid:!0,children:n.content})})}function Ai({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(Oi,{}),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 Fi({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(je,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:F.projectFileRawUrl(t,s),alt:s,onError:()=>r(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function Oi(){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 Ui({project:t,path:s,onNavigate:n,onTogglePin:r}){const l=t.slug,[i,o]=a.useState(null),[c,u]=a.useState(!1),[x,N]=a.useState(null),[m,j]=a.useState(!0);a.useEffect(()=>{let f=!1;return j(!0),N(null),o(null),u(!1),F.listProjectDir(l,s).then(S=>{f||(S.kind==="file"?u(!0):o(S))}).catch(S=>{f||N(S instanceof Error?S.message:"Failed to load files")}).finally(()=>{f||j(!1)}),()=>{f=!0}},[l,s]);const y=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",C=e.jsx(Bi,{path:s,isFile:c,onNavigate:n});if(m)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:[C,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(f=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},f))})]})});if(x)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:[C,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(je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:x})]})]})});if(c){const f=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:C}),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 ${f?"bg-accent/10 text-accent":"text-fg-muted hover:bg-surface-hover"}`,title:f?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(Ut,{width:13,height:13}),f?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(Li,{slug:l,name:s})})]})}const g=(i==null?void 0:i.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:[C,g.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(y),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:".."})]}),g.length===0&&s!==""&&e.jsx("div",{className:"px-3 py-2.5 text-sm italic text-fg-subtle",children:"This folder is empty."}),g.map((f,S)=>{const M=s?`${s}/${f.name}`:f.name,R=f.kind==="dir",v=t.pinned.includes(M),L=!R,E=S>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 ${E}`,children:[e.jsxs("button",{onClick:()=>n(M),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[R?e.jsx(Os,{width:15,height:15,className:"shrink-0 text-accent/80"}):e.jsx(Vt,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:`truncate font-mono text-sm ${R?"font-medium text-fg":"text-fg"}`,children:f.name}),R&&e.jsx(fs,{width:14,height:14,className:"ml-auto shrink-0 text-fg-subtle"})]}),L&&e.jsxs("button",{type:"button","aria-label":v?`Unpin ${f.name}`:`Pin ${f.name}`,title:v?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>r(M),className:`flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-2xs font-medium transition ${v?"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(Ut,{width:12,height:12}),v?"Pinned":"Pin"]})]},f.name)})]})]})})}function Bi({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(Sn,{label:"Files",isLast:r.length===0,onClick:()=>n("")}),r.map((l,i)=>{const o=i===r.length-1,c=r.slice(0,i+1).join("/");return e.jsxs("span",{className:"flex items-center gap-x-1",children:[e.jsx(fs,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx(Sn,{label:l,isLast:o,mono:!0,muted:o&&s,onClick:()=>n(c)})]},c)})]})}function Sn({label:t,isLast:s,mono:n,muted:r,onClick:l}){const i=n?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${i} font-medium ${r?"text-fg-muted":"text-fg"}`,children:t}):e.jsx("button",{type:"button",onClick:l,className:`${i} rounded text-fg-muted transition-colors hover:text-accent`,children:t})}const Vi=["idea","active","paused","blocked","done","abandoned"];function Ls(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 In=[{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)"}],Ft="loading…";function fe({children:t}){return e.jsx("p",{className:"mt-1 text-xs leading-snug text-fg-muted",children:t})}function $n({children:t}){return e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(je,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t})]})}function St({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 zi({project:t,onSaved:s}){const[n,r]=a.useState(""),[l,i]=a.useState(!1),[o,c]=a.useState(!1),[u,x]=a.useState(null);if(a.useEffect(()=>{r(""),i(!1),x(null)},[t.slug,t.managed]),!t.managed||t.path)return e.jsx(Ct,{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(St,{label:t.path?"Repository (recorded)":"Repository",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.repo})}),e.jsx(St,{label:"Working directory",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.workingDir})})]})});const N=n.trim(),m=N.length>0&&!Hi(N),j=async()=>{if(!(!N||m)){c(!0),x(null);try{const y=await F.promoteProject(t.slug,N);s(y),i(!1),r("")}catch(y){x(y instanceof Ie?y.message:"Failed to promote project")}finally{c(!1)}}};return e.jsxs(Ct,{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:y=>{r(y.target.value),i(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":m,"aria-label":"Git repository URL"}),m?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."]})]}),u&&e.jsx("p",{className:"mt-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:u}),l?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(je,{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:N}),", 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:o,onClick:j,children:o?"Promoting…":"Yes, promote"}),e.jsx("button",{type:"button",className:"btn-subtle",disabled:o,onClick:()=>i(!1),children:"Cancel"})]})]}):e.jsx("button",{type:"button",className:"btn-primary mt-4",disabled:o||!N||m,onClick:()=>i(!0),children:"Promote to repo-backed…"})]})}function Hi(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}function Wi({project:t,onSaved:s}){var Ke,Ae,Ee;const[n,r]=a.useState(t.name),[l,i]=a.useState(t.summary),[o,c]=a.useState(t.domain.join(", ")),[u,x]=a.useState(t.group??""),[N,m]=a.useState(t.status),[j,y]=a.useState(t.visibility),[C,g]=a.useState(t.links??[]),[f,S]=a.useState(t.model),[M,R]=a.useState(t.models??[]),[v,L]=a.useState(t.permissionMode),[E,B]=a.useState(String(t.maxTurns)),[w,O]=a.useState(t.docker),[k,z]=a.useState(t.driveMode??""),[P,G]=a.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[J,T]=a.useState(((Ke=t.curation)==null?void 0:Ke.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[_,U]=a.useState(((Ae=t.curation)==null?void 0:Ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[H,ce]=a.useState(((Ee=t.curation)==null?void 0:Ee.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[ne,X]=a.useState([]),[se,h]=a.useState(null),[A,q]=a.useState(null),[p,ee]=a.useState(null),[pe,Ve]=a.useState(!1),[ge,be]=a.useState(null),[me,we]=a.useState(0);a.useEffect(()=>{var I,te,ae;r(t.name),i(t.summary),c(t.domain.join(", ")),x(t.group??""),m(t.status),y(t.visibility),g(t.links??[]),S(t.model),R(t.models??[]),L(t.permissionMode),B(String(t.maxTurns)),O(t.docker),z(t.driveMode??""),G(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),T(((I=t.curation)==null?void 0:I.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),U(((te=t.curation)==null?void 0:te.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),ce(((ae=t.curation)==null?void 0:ae.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),be(null)},[t]),a.useEffect(()=>{let I=!1;return F.getModels().then(te=>{I||(X(te.models),h(te.driveModeDefault),q(te.maxSpawnDepthDefault),ee(te.curationDefault))}).catch(()=>{}),()=>{I=!0}},[]);const Me=a.useMemo(()=>C.map(I=>({label:I.label.trim(),url:I.url.trim()})).filter(I=>I.url.length>0),[C]),de=a.useMemo(()=>o.split(",").map(I=>I.trim()).filter(Boolean),[o]),$e=a.useMemo(()=>({name:n.trim(),status:N,group:u,summary:l.trim(),domain:de,visibility:j,links:Me,model:f,models:M.length>0?M:null,permissionMode:v,maxTurns:Number(E),docker:w,driveMode:k===""?null:k,maxSpawnDepth:P===""?null:Number(P),curation:Ls(J,_,H)}),[n,N,u,l,de,j,Me,f,M,v,E,w,k,P,J,_,H]),_e=a.useMemo(()=>{var te,ae,xe;const I={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(re=>({label:re.label,url:re.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:Ls(((te=t.curation)==null?void 0:te.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ae=t.curation)==null?void 0:ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((xe=t.curation)==null?void 0:xe.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify($e)!==JSON.stringify(I)},[$e,t]),Te=$e.name.length===0,Pe=Number(E),ye=!Number.isInteger(Pe)||Pe<1||Pe>1e3,ze=Number(P),He=P!==""&&(!Number.isInteger(ze)||ze<0||ze>8),Q=I=>I!==""&&(!Number.isInteger(Number(I))||Number(I)<1),ke=Q(J)||Q(_)||Q(H),he=async I=>{if(I.preventDefault(),!(Te||ye||He||ke)){Ve(!0),be(null);try{const te=await F.updateProject(t.slug,$e);s(te),we(ae=>ae+1)}catch(te){be(te instanceof Ie?te.message:"Failed to save changes")}finally{Ve(!1)}}},We=se===null?Ft:se==="session"?"Session":"Batch",Le=M.length>0?ne.filter(I=>M.includes(I.id)):ne,it=(I,te)=>R(ae=>te?[...ae.filter(xe=>xe!==I),I]:ae.filter(xe=>xe!==I));return e.jsxs("form",{onSubmit:he,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&&!pe&&e.jsx("span",{className:"text-xs text-warn",children:"Unsaved changes"}),me>0&&!_e&&!pe&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-success",children:[e.jsx(pt,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:pe||!_e||Te||ye||He||ke,children:pe?"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:[ge&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:ge}),e.jsxs(Ct,{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:n,onChange:I=>r(I.target.value),placeholder:"Display name","aria-invalid":Te}),Te&&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:l,onChange:I=>i(I.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:N,onChange:I=>m(I.target.value),children:Vi.map(I=>e.jsx("option",{value:I,className:"capitalize",children:I},I))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:u,onChange:I=>x(I.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Us.map(I=>e.jsx("option",{value:I.slug,children:I.label},I.slug)),u&&!Us.some(I=>I.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:j,onChange:I=>y(I.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:o,onChange:I=>c(I.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),C.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:C.map((I,te)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:I.label,onChange:ae=>g(xe=>xe.map((re,Ce)=>Ce===te?{...re,label:ae.target.value}:re)),placeholder:"Label","aria-label":`Link ${te+1} label`}),e.jsx("input",{className:"input flex-1",value:I.url,onChange:ae=>g(xe=>xe.map((re,Ce)=>Ce===te?{...re,url:ae.target.value}:re)),placeholder:"https://…","aria-label":`Link ${te+1} URL`}),e.jsx("button",{type:"button",onClick:()=>g(ae=>ae.filter((xe,re)=>re!==te)),"aria-label":`Remove link ${te+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(Xs,{width:14,height:14})})]},te))}),e.jsxs("button",{type:"button",onClick:()=>g(I=>[...I,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(lt,{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(St,{label:"Slug",value:e.jsx("span",{className:"font-mono",children:t.slug})}),e.jsx(St,{label:"Started",value:t.started})]})]}),e.jsx(Ct,{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:f,onChange:I=>S(I.target.value),children:[!Le.some(I=>I.id===f)&&e.jsx("option",{value:f,children:f}),Le.map(I=>e.jsx("option",{value:I.id,children:I.label},I.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:v,onChange:I=>L(I.target.value),children:[!In.some(I=>I.value===v)&&e.jsx("option",{value:v,children:v}),In.map(I=>e.jsx("option",{value:I.value,children:I.label},I.value))]})]}),v==="bypassPermissions"?e.jsx($n,{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:E,onChange:I=>B(I.target.value),"aria-invalid":ye})]}),ye?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:w,onChange:I=>O(I.target.checked)}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Run Claude in a Docker sandbox"})]}),w?e.jsx($n,{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"}),ne.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:ne.map(I=>{const te=M.length===0||M.includes(I.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:te,onChange:ae=>{M.length===0?R(ae.target.checked?[]:ne.filter(xe=>xe.id!==I.id).map(xe=>xe.id)):it(I.id,ae.target.checked)},"aria-label":I.label}),e.jsx("span",{children:I.label})]},I.id)})}),M.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 ",M.length," of ",ne.length," ","instance models."," ",e.jsx("button",{type:"button",onClick:()=>R([]),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:k,onChange:I=>z(I.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",We,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),k===""&&se===null?e.jsx(fe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the box-wide drive-mode default…"})}):k===""?e.jsxs(fe,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-fg",children:We}),". ",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:()=>z(""),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:P,onChange:I=>G(I.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",A??Ft,")"]}),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"})]})]}),P===""&&A===null?e.jsx(fe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance max-spawn-depth default…"})}):P===""?e.jsxs(fe,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-fg",children:A}),". 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:()=>G(""),className:"font-medium text-accent hover:underline",children:"Reset to instance default"}),"."]})]})]})}),e.jsxs(Ct,{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 (${(p==null?void 0:p.overviewMaxTokens)??Ft})`,value:J,onChange:I=>T(I.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 (${(p==null?void 0:p.changelogMaxTokens)??Ft})`,value:_,onChange:I=>U(I.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 (${(p==null?void 0:p.claudeMaxTokens)??Ft})`,value:H,onChange:I=>ce(I.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),ke?e.jsx(fe,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):Ls(J,_,H)?e.jsxs(fe,{children:["Overriding the instance defaults",p&&e.jsxs(e.Fragment,{children:[" ","(",p.overviewMaxTokens,"/",p.changelogMaxTokens,"/",p.claudeMaxTokens,")"]})," ","for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{T(""),U(""),ce("")},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."]}):p===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:[p.overviewMaxTokens,"/",p.changelogMaxTokens,"/",p.claudeMaxTokens]})," ","tokens (OVERVIEW/CHANGELOG/CLAUDE). Lower a budget to shrink the context this project injects into every chat."]})]}),e.jsx(zi,{project:t,onSaved:s}),e.jsx(Ct,{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(St,{label:"Overview",value:t.hasOverview?e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(pt,{width:12,height:12})," OVERVIEW.md written by a sweep"]}):e.jsx("span",{className:"text-fg-subtle",children:"No OVERVIEW.md yet"})}),e.jsx(St,{label:"Pinned files",value:t.pinned.length>0?e.jsx("span",{className:"flex flex-wrap gap-1.5",children:t.pinned.map(I=>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(Ut,{width:11,height:11,className:"text-accent"}),I]},I))}):e.jsx("span",{className:"text-fg-subtle",children:"None — pin files from the Files tab"})})]})})]})})]})}const Gi=/^[A-Za-z0-9._-]+$/,Ki={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},Qi={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},qi=[{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)"}],Yi={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},Ji=["read","write","web","orchestration","browser"];function Xi(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 Zi(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 eo(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 l=Number(t.maxSpawnDepth);return t.maxSpawnDepth.trim()&&Number.isFinite(l)&&l>=0&&(n.maxSpawnDepth=Math.floor(l)),{trigger:s,run:n,enabled:t.enabled}}function to(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 En(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function so(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function no({project:t}){const s=t.slug,[n,r]=a.useState([]),[l,i]=a.useState([]),[o,c]=a.useState(["onArchive","afterTurn"]),[u,x]=a.useState(["schedule","event","webhook"]),[N,m]=a.useState(!0),[j,y]=a.useState(null),[C,g]=a.useState(null),[f,S]=a.useState(null),[M,R]=a.useState(null),[v,L]=a.useState(null),[E,B]=a.useState({}),w=a.useCallback(async()=>{m(!0);try{const h=await F.listTriggers(s);r(h.triggers),i(h.grantableTools),h.events.length>0&&c(h.events),h.triggerTypes.length>0&&x(h.triggerTypes),y(null)}catch(h){y(h instanceof Ie?h.message:"Failed to load triggers")}finally{m(!1)}},[s]),O=a.useCallback(async()=>{try{const h=await F.triggerRuntime(s);B(Object.fromEntries(h.runtime.map(A=>[A.name,A])))}catch{}},[s]);a.useEffect(()=>{w()},[w]),a.useEffect(()=>{O();const h=setInterval(()=>{document.visibilityState==="visible"&&O()},1e4);return()=>clearInterval(h)},[O]),a.useEffect(()=>{if(!C)return;const h=setTimeout(()=>g(null),4e3);return()=>clearTimeout(h)},[C]);const k=f==null?void 0:f.draft,z=a.useMemo(()=>f!=null&&f.isNew?n.some(h=>h.name===(k==null?void 0:k.name.trim())):!1,[f,k,n]),P=!!k&&(!Gi.test(k.name.trim())||k.name.trim().length>64),G=!!k&&(k.type==="schedule"?k.expr.trim().length===0:k.type==="webhook"?k.path.trim().length===0:!1),J=!!k&&(k.promptMode==="file"?k.promptFile.trim().length===0||!k.promptFile.trim().toLowerCase().endsWith(".md"):k.prompt.trim().length===0),T=!!k&&k.type==="webhook",_=P||z||G||J||T,U=h=>S(A=>A&&{...A,draft:{...A.draft,...h}}),H=h=>S(A=>{if(!A)return A;const q=new Set(A.draft.allowedTools);return q.has(h)?q.delete(h):q.add(h),{...A,draft:{...A.draft,allowedTools:q}}}),ce=async()=>{if(!f||_)return;const h=f.draft.name.trim();R(h);try{await F.putTrigger(s,h,eo(f.draft)),S(null),g(`Saved “${h}”.`),await w()}catch(A){y(A instanceof Ie?A.message:"Failed to save trigger")}finally{R(null)}},ne=async h=>{R(h.name);try{const A=await F.putTrigger(s,h.name,{trigger:h.trigger,run:h.run,enabled:!h.enabled});r(q=>q.map(p=>p.name===h.name?A:p))}catch(A){y(A instanceof Ie?A.message:"Failed to update trigger")}finally{R(null)}},X=async()=>{const h=v;if(h){R(h.name);try{await F.deleteTrigger(s,h.name),r(A=>A.filter(q=>q.name!==h.name)),g(`Deleted “${h.name}”.`),L(null)}catch(A){throw new Error(A instanceof Ie?A.message:"Failed to delete trigger")}finally{R(null)}}},se=async h=>{R(h.name);try{await F.runTrigger(s,h.name),g(`Ran “${h.name}” — a new chat is starting.`),await O()}catch(A){y(A instanceof Ie?A.message:"Failed to run trigger")}finally{R(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(zt,{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:[j&&e.jsx("p",{className:"mb-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:j}),C&&e.jsx("p",{className:"mb-3 rounded-lg bg-success-soft px-3 py-2 text-sm text-success",children:C}),N?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(h=>{var q;const A=E[h.name];return e.jsxs("tr",{"data-trigger":h.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:h.name}),h.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:h.run.promptFile}):h.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-2xs text-fg-subtle",children:h.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(ao,{type:h.trigger.type})}),e.jsx("td",{className:"px-2 py-2.5 align-top font-mono text-xs text-fg-muted",children:so(h.trigger)}),e.jsxs("td",{className:"px-2 py-2.5 align-top text-xs text-fg-muted",children:[e.jsx("span",{title:((q=h.run.tools)==null?void 0:q.join(", "))||"No tools declared — an empty list is not enforced as a deny-all",children:to(h)}),h.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-2xs text-fg-subtle",children:h.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":h.name,children:e.jsx(io,{rt:A})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":h.name,children:e.jsx(oo,{rt:A,trigger:h})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(ro,{enabled:h.enabled===!0,running:(A==null?void 0:A.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:()=>se(h),disabled:M===h.name||En(h),title:En(h)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${h.name} now`,"data-testid":`run-trigger-${h.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(Ea,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ne(h),disabled:M===h.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:h.enabled?"Disable":"Enable",children:h.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>S({isNew:!1,draft:Zi(h)}),disabled:M===h.name,title:"Edit","aria-label":`Edit ${h.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(xs,{width:14,height:14})}),e.jsx("button",{type:"button",onClick:()=>L(h),disabled:M===h.name,title:"Delete","aria-label":`Delete ${h.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(Xs,{width:14,height:14})})]})})]},h.name)})})]})}),!f&&e.jsxs("button",{type:"button",onClick:()=>S({isNew:!0,draft:Xi(u[0]??"schedule",o[0]??"onArchive")}),className:"btn-subtle mt-3 gap-1.5 px-2 py-1 text-xs","data-testid":"add-trigger",children:[e.jsx(lt,{width:13,height:13}),"Add trigger"]}),f&&k&&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:f.isNew?"New trigger":`Edit “${k.name}”`}),e.jsx("button",{type:"button",onClick:()=>S(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(Be,{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:k.name,onChange:h=>U({name:h.target.value}),placeholder:"daily-manager",disabled:!f.isNew,"aria-invalid":P||z,"data-testid":"trigger-name"}),f.isNew&&z?e.jsx("p",{className:"mt-1 text-xs text-danger",children:"A trigger with that name exists."}):f.isNew&&k.name.trim()&&P?e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Letters, numbers, ",e.jsx("code",{children:". _ -"})," only (max 64)."]}):!f.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:k.type,onChange:h=>U({type:h.target.value}),"data-testid":"trigger-type",children:u.map(h=>e.jsx("option",{value:h,children:Qi[h]??h},h))})]}),k.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:k.scheduleKind,onChange:h=>U({scheduleKind:h.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:k.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:k.expr,onChange:h=>U({expr:h.target.value}),placeholder:k.scheduleKind==="cron"?"0 9 * * *":"30m","aria-invalid":G,"data-testid":"trigger-expr"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:k.scheduleKind==="cron"?"5-field cron (or @daily / @hourly), host-local time.":"A duration like 30m, 1h, or 6h."})]})]}),k.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:k.event,onChange:h=>U({event:h.target.value}),"data-testid":"trigger-event",children:o.map(h=>e.jsx("option",{value:h,children:Ki[h]??h},h))})]}),k.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:k.path,onChange:h=>U({path:h.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),T&&e.jsxs("p",{className:"col-span-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(je,{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:k.promptMode==="inline",onChange:()=>U({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:k.promptMode==="file",onChange:()=>U({promptMode:"file"})}),"Prompt file"]})]}),k.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:k.prompt,onChange:h=>U({prompt:h.target.value}),placeholder:"What should this trigger do when it fires?","aria-invalid":J,"data-testid":"trigger-prompt"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input font-mono",value:k.promptFile,onChange:h=>U({promptFile:h.target.value}),placeholder:"daily-manager.md","aria-invalid":J,"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.",k.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:Ji.filter(h=>l.some(A=>A.group===h)).map(h=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:Yi[h]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:l.filter(A=>A.group===h).map(A=>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:A.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:k.allowedTools.has(A.name),onChange:()=>H(A.name),"data-tool":A.name}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-fg",children:A.name}),e.jsx("span",{className:"block text-2xs leading-snug text-fg-subtle",children:A.description})]})]},A.name))})]},h))}),k.allowedTools.has("Bash")&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(je,{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:k.resumeSession,onChange:h=>U({resumeSession:h.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:k.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:k.permissionMode,onChange:h=>U({permissionMode:h.target.value}),"data-testid":"trigger-permission-mode",children:qi.map(h=>e.jsx("option",{value:h.value,children:h.label},h.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:k.maxTurns,onChange:h=>U({maxTurns:h.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:k.model,onChange:h=>U({model:h.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:k.maxSpawnDepth,onChange:h=>U({maxSpawnDepth:h.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:k.enabled,onChange:h=>U({enabled:h.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:ce,disabled:_||M===k.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:M===k.name.trim()?"Saving…":f.isNew?"Create trigger":"Save"}),e.jsx("button",{type:"button",onClick:()=>S(null),className:"btn-ghost",children:"Cancel"})]})]})]})]})}),e.jsx(us,{open:v!==null,title:"Delete trigger?",confirmLabel:"Delete trigger",message:v&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:v.name})," ","will be removed from this project. This can't be undone."]}),onConfirm:X,onClose:()=>L(null)})]})}function ao({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"?et:zt;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 ro({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 lo(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 io({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(`
11
- `);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-fg-muted",title:r,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${lo(s.status)}`}),s.status==="running"?"Running…":It(n)]})}function oo({rt:t,trigger:s}){const n=s.trigger.type;if(n==="event")return e.jsx("span",{className:"text-xs text-fg-subtle",children:"on event"});if(n==="webhook")return e.jsx("span",{className:"text-xs text-fg-subtle",children:"on webhook"});const r=t==null?void 0:t.nextRunAt;return r?e.jsx("span",{className:"text-xs text-fg-muted",title:new Date(r).toLocaleString(),children:Ra(r)}):e.jsx("span",{className:"text-xs text-fg-subtle",children:"—"})}function co({open:t,chatName:s,onClose:n,onFork:r}){const l=`Fork of ${s}`,[i,o]=a.useState(l),c=a.useRef(null);if(a.useEffect(()=>{if(t){o(l);const x=c.current;x&&(x.focus(),x.select())}},[t,s]),gs(t,n),!t)return null;const u=x=>{x.preventDefault(),r(i.trim()||l)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:n,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:x=>x.stopPropagation(),onSubmit:u,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Fork chat"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Branches a new chat from this one — the parent's full history comes along and stays resumable. Name the fork, then continue it independently."}),e.jsxs("label",{className:"mb-5 block",children:[e.jsx("span",{className:"field-label",children:"Fork name"}),e.jsx("input",{ref:c,autoFocus:!0,className:"input",value:i,onChange:x=>o(x.target.value),placeholder:l})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:n,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:"Fork"})]})]})})}function uo({open:t,chatName:s,resetName:n,onClose:r,onRename:l}){const[i,o]=a.useState(s),c=a.useRef(null);if(a.useEffect(()=>{if(!t)return;o(s);const m=c.current;m&&(m.focus(),m.select())},[t,s]),gs(t,r),!t)return null;const u=i.trim(),x=u==="",N=m=>{m.preventDefault(),l(x?null:u)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:r,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:m=>m.stopPropagation(),onSubmit:N,role:"dialog","aria-modal":"true","aria-label":"Rename chat",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Rename chat"}),e.jsx("button",{type:"button",onClick:r,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Renaming only changes how this chat is labelled in the sidebar — the transcript, its id, and its history are untouched."}),e.jsxs("label",{className:"mb-2 block",children:[e.jsx("span",{className:"field-label",children:"Chat name"}),e.jsx("input",{ref:c,autoFocus:!0,className:"input",value:i,onChange:m=>o(m.target.value),placeholder:n||"Chat name"})]}),e.jsx("p",{className:"mb-5 text-xs text-fg-subtle","data-testid":"rename-hint",children:x?e.jsxs(e.Fragment,{children:["Clearing the name resets it to",n?e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"font-medium text-fg-muted",children:n}),"."]}):" the chat's generated name."]}):"Clear the box to reset it to the generated name."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:r,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:x?"Reset name":"Rename"})]})]})})}function mo({open:t,slug:s,sessionId:n,defaultName:r,onClose:l,onPromoted:i}){const[o,c]=a.useState(r??""),[u,x]=a.useState(""),[N,m]=a.useState(""),[j,y]=a.useState(""),[C,g]=a.useState(!1),[f,S]=a.useState(null);if(a.useEffect(()=>{t&&(c(r??""),x(""),m(""),y(""),S(null))},[t,r]),gs(t&&!C,l),!t)return null;const M=async R=>{if(R.preventDefault(),!!o.trim()){g(!0),S(null);try{const{project:v,promoted:L}=await F.promoteChat(s,n,{name:o.trim(),group:j||void 0,summary:u.trim()||void 0,domain:N.split(",").map(E=>E.trim()).filter(Boolean)});i(v,L)}catch(v){S(v instanceof Ie?v.message:"Failed to promote chat")}finally{g(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!C&&l(),children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:R=>R.stopPropagation(),onSubmit:M,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Promote to project"}),e.jsx("button",{type:"button",onClick:l,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Creates a project and moves this chat into it — its history comes along and stays resumable."}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Project name"}),e.jsx("input",{autoFocus:!0,className:"input",value:o,onChange:R=>c(R.target.value),placeholder:"Garage Water Heater Replacement"})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary (optional)"}),e.jsx("input",{className:"input",value:u,onChange:R=>x(R.target.value),placeholder:"One line on what this project is about"})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:j,onChange:R=>y(R.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Us.map(R=>e.jsx("option",{value:R.slug,children:R.label},R.slug))]})]}),e.jsxs("label",{className:"mb-5 block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:N,onChange:R=>m(R.target.value),placeholder:"home, plumbing"})]}),f&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:l,disabled:C,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:C||!o.trim(),children:C?"Promoting…":"Promote to project"})]})]})})}function ho({open:t,adoptable:s,busy:n,onClose:r,onAdopt:l}){const[i,o]=a.useState(new Set),c=a.useMemo(()=>((s==null?void 0:s.sources)??[]).map(y=>({sourceCwd:y.sourceCwd,sessions:y.sessions??y.sessionIds.map(C=>({sessionId:C}))})),[s]),u=a.useMemo(()=>c.flatMap(y=>y.sessions.map(C=>C.sessionId)),[c]),x=u.join(",");if(a.useEffect(()=>{t&&o(new Set(u))},[t,x]),gs(t&&!n,r),!t)return null;const N=y=>{o(C=>{const g=new Set(C);return g.delete(y)||g.add(y),g})},m=(y,C)=>{o(g=>{const f=new Set(g);for(const S of y)C?f.add(S):f.delete(S);return f})},j=i.size;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!n&&r(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Adopt native Claude Code chats",className:"flex max-h-[80vh] w-full max-w-2xl animate-scale-in flex-col rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-lg font-semibold",children:[e.jsx(ps,{width:16,height:16}),"Adopt native chats"]}),e.jsx("button",{type:"button",onClick:r,disabled:n,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsxs("p",{className:"mb-4 text-sm text-fg-muted",children:["These Claude Code sessions were run in a terminal and aren't visible here yet. Adopting them lists them here — your own ",e.jsx("code",{children:"~/.claude"})," history is never moved or deleted."]}),e.jsxs("div",{className:"-mx-1 flex-1 overflow-y-auto px-1",children:[c.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-fg-muted",children:"Nothing left to adopt."}),c.map(y=>{const C=y.sessions.map(f=>f.sessionId),g=C.every(f=>i.has(f));return e.jsxs("section",{className:"mb-4 last:mb-0",children:[e.jsxs("header",{className:"mb-1 flex items-baseline justify-between gap-2",children:[e.jsx("code",{className:"min-w-0 break-all text-xs text-fg-muted",children:y.sourceCwd}),e.jsx("button",{type:"button",onClick:()=>m(C,!g),className:"shrink-0 text-xs text-fg-muted underline underline-offset-2 hover:text-fg",children:g?"Deselect all":"Select all"})]}),e.jsx("ul",{className:"space-y-1",children:y.sessions.map(f=>e.jsx("li",{children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-lg border border-edge px-3 py-2 transition hover:bg-surface-hover",children:[e.jsx("input",{type:"checkbox",className:"mt-1 shrink-0",checked:i.has(f.sessionId),onChange:()=>N(f.sessionId)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",children:xo(f)}),f.mtime!==void 0&&e.jsxs("span",{className:"mt-0.5 block text-xs text-fg-muted tabular",children:[fo(f.mtime)," · ",po(f.sizeBytes)]})]})]})},f.sessionId))})]},y.sourceCwd)})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 border-t border-edge pt-4",children:[e.jsxs("span",{className:"text-sm text-fg-muted",children:[j," of ",u.length," selected"]}),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:r,disabled:n,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn-primary",disabled:n||j===0,onClick:()=>l([...i]),children:n?"Adopting…":`Adopt ${j} chat${j===1?"":"s"}`})]})]})]})})}function xo(t){var r,l;const s=(r=t.autoName)==null?void 0:r.trim();if(s!==void 0&&s!=="")return s;const n=(l=t.preview)==null?void 0:l.trim();return n!==void 0&&n!==""?n:t.sessionId}function fo(t){const s=new Date(t);return Number.isNaN(s.getTime())?"unknown date":s.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function po(t){return t<1024?`${t} B`:t<1024*1024?`${Math.round(t/1024)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}const ua="paddock:fork:";function go(t){if(!t)return null;try{const s=localStorage.getItem(ua+t);if(!s)return null;const n=JSON.parse(s);return n&&typeof n.sessionId=="string"&&typeof n.name=="string"?n:null}catch{return null}}function Rn(t,s){try{localStorage.setItem(ua+t,JSON.stringify(s))}catch{}}function Ws(t){const s=Date.parse(t.chat.updatedAt??"")||0;return t.children.reduce((n,r)=>Math.max(n,Ws(r)),s)}function nn(t){for(const s of t)nn(s.children);t.sort((s,n)=>!!s.chat.starred!=!!n.chat.starred?s.chat.starred?-1:1:Ws(n)-Ws(s))}function ma(t,s){let n=0;for(const r of t)r.depth=s,r.descendantCount=ma(r.children,s+1),n+=1+r.descendantCount;return n}function bo(t){var r;const s=new Map;for(const l of t)s.set(l.sessionId,{chat:l,children:[],depth:0,descendantCount:0});const n=[];for(const l of s.values()){const i=(r=l.chat.parent)==null?void 0:r.sessionId,o=i?s.get(i):void 0;if(!o||o===l||vo(l,o,s)){n.push(l);continue}o.children.push(l)}return nn(n),ma(n,0),n}function jo(t){const s=t.map(n=>({chat:n,children:[],depth:0,descendantCount:0}));return nn(s),s}function vo(t,s,n){var i;const r=new Set([t.chat.sessionId]);let l=s;for(;l;){if(r.has(l.chat.sessionId))return!0;r.add(l.chat.sessionId);const o=(i=l.chat.parent)==null?void 0:i.sessionId;l=o?n.get(o):void 0}return!1}function Gs(t){return t.reduce((s,n)=>s+1+Gs(n.children),0)}function wo(t){const s=[t.chat.sessionId],n=r=>{for(const l of r)s.push(l.chat.sessionId),n(l.children)};return n(t.children),s}function No(t,s){var o;const n=new Map;for(const c of t){const u=(o=c.parent)==null?void 0:o.sessionId;if(!u)continue;const x=n.get(u);x?x.push(c.sessionId):n.set(u,[c.sessionId])}const r=[],l=new Set([s]),i=[s];for(;i.length;)for(const c of n.get(i.pop())??[])l.has(c)||(l.add(c),r.push(c),i.push(c));return r}function Tn(t,s){const n=[],r=l=>{for(const i of l)n.push(i),s.has(i.chat.sessionId)||r(i.children)};return r(t),n}function yo(t,s){var l;const n=new Map(t.map(i=>[i.sessionId,i])),r=new Set;for(const i of s){let o=i;const c=new Set;for(;o&&!c.has(o.sessionId);){c.add(o.sessionId),r.add(o.sessionId);const u=(l=o.parent)==null?void 0:l.sessionId;o=u?n.get(u):void 0}}return t.filter(i=>r.has(i.sessionId))}const Ks="paddock:chatsCollapsed:";function ko(t){try{const s=localStorage.getItem(Ks+t);if(!s)return new Set;const n=JSON.parse(s);return Array.isArray(n)?new Set(n.filter(r=>typeof r=="string")):new Set}catch{return new Set}}function Co(t,s){try{s.size===0?localStorage.removeItem(Ks+t):localStorage.setItem(Ks+t,JSON.stringify([...s]))}catch{}}const ha="paddock:chatView:nested",xa="paddock:chatView:runningOnly";function fa(t,s){try{const n=localStorage.getItem(t);return n==="1"?!0:n==="0"?!1:s}catch{return s}}function pa(t,s,n){try{s===n?localStorage.removeItem(t):localStorage.setItem(t,s?"1":"0")}catch{}}function So(){return fa(ha,!0)}function Io(t){pa(ha,t,!0)}function $o(){return fa(xa,!1)}function Eo(t){pa(xa,t,!1)}function Ro(){const[t,s]=a.useState(So),[n,r]=a.useState($o),l=a.useCallback(o=>{s(o),Io(o)},[]),i=a.useCallback(o=>{r(o),Eo(o)},[]);return a.useMemo(()=>({nested:t,setNested:l,runningOnly:n,setRunningOnly:i}),[t,l,n,i])}function ft({active:t,onClick:s,children:n}){return e.jsx("button",{onClick:s,className:`whitespace-nowrap border-b-2 px-3 py-2.5 text-sm font-medium transition-colors ${t?"border-accent text-fg":"border-transparent text-fg-muted hover:text-fg"}`,children:n})}function To({file:t,active:s,onSelect:n,onUnpin:r}){const l=t.includes("/")?t.slice(t.lastIndexOf("/")+1):t;return e.jsxs("div",{className:`group/pin flex items-center gap-1 border-b-2 pr-1 transition-colors ${s?"border-accent":"border-transparent"}`,children:[e.jsxs("button",{onClick:n,title:t,"aria-label":`Open ${t} tab`,role:"tab","aria-selected":s,className:`flex items-center gap-1.5 py-2.5 pl-3 pr-1 text-sm font-medium transition-colors ${s?"text-fg":"text-fg-muted hover:text-fg"}`,children:[e.jsx(Ut,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"max-w-[10rem] truncate",children:l})]}),e.jsx("button",{type:"button","aria-label":`Unpin ${t}`,title:`Unpin ${t}`,onClick:i=>{i.stopPropagation(),r()},className:"flex h-5 w-5 items-center justify-center rounded text-fg-subtle opacity-60 transition hover:bg-surface-active hover:text-fg focus:opacity-100 group-hover/pin:opacity-100",children:e.jsx(Be,{width:12,height:12})})]})}function Mo({project:t,running:s,unread:n,attentionLoading:r,attentionError:l,changelog:i,overview:o,files:c,onOpenChat:u,onNewChat:x,onOpenFile:N,onOpenFiles:m}){const j=c.slice(0,6),y=!l&&!r&&s.length===0&&n.length===0;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:[l?e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(cs,{label:"Running",count:s.length}),e.jsx(Mn,{onNewChat:x})]}),e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm text-danger",children:l})})]}):y?e.jsx("section",{className:"mb-8",children:e.jsx(ms,{variant:"panel",icon:e.jsx(Ht,{width:22,height:22}),title:"All caught up",body:"Nothing is running and there are no unread replies. Start a chat and it will appear here the moment it wants you.",action:e.jsx(Hn,{variant:"primary",icon:e.jsx(lt,{width:14,height:14}),onClick:x,children:"New chat"})})}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(cs,{label:"Running",count:s.length}),e.jsx(Mn,{onNewChat:x})]}),e.jsx(_n,{chats:s,workspaceSlug:t.slug,loading:r,empty:"Nothing running right now.",onOpenChat:u,kind:"running"})]}),e.jsxs("section",{className:"mb-8",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between",children:e.jsx(cs,{label:"Unread",count:n.length})}),e.jsx(_n,{chats:n,workspaceSlug:t.slug,loading:r,empty:"No unread replies. All caught up.",onOpenChat:u,kind:"unread"})]})]}),N&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(cs,{label:"Files",count:c.length}),c.length>j.length&&e.jsx("button",{onClick:m,className:"btn-subtle -mr-1 px-2 py-1 text-xs",children:"View all"})]}),j.length===0?e.jsx(ms,{title:"No files yet",body:"Anything Claude writes in this project shows up here, newest first."}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-edge",children:j.map((C,g)=>e.jsxs("button",{onClick:()=>N(C),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover ${g>0?"border-t border-edge":""}`,children:[e.jsx(Vt,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-fg",children:C}),t.pinned.includes(C)&&e.jsx(Ut,{width:12,height:12,className:"shrink-0 text-accent"})]},C))})]}),e.jsx(Dn,{id:`${t.slug}:overview`,title:"OVERVIEW.md",body:o,emptyTitle:"No OVERVIEW.md yet",emptyBody:"The sweeper writes this after a chat — what this workspace is, and where the work has got to."},`${t.slug}:overview`),e.jsx(Dn,{id:`${t.slug}:changelog`,title:"CHANGELOG.md",body:i,emptyTitle:"No CHANGELOG.md yet",emptyBody:"The sweeper writes this after a chat — a running log of what actually changed."},`${t.slug}:changelog`),e.jsxs("p",{className:"mt-6 text-2xs text-fg-subtle",children:["Project directory: ",e.jsx("span",{className:"font-mono",children:t.dir})]})]})})}function Mn({onNewChat:t}){return e.jsx(Hn,{variant:"subtle",size:"sm",className:"-mr-1",icon:e.jsx(lt,{width:13,height:13}),onClick:t,children:"New chat"})}function cs({label:t,count:s}){return e.jsxs("h3",{className:"text-sm font-semibold uppercase tracking-wide text-fg-muted",children:[t,s>0&&e.jsx("span",{className:"ml-1.5 text-fg-subtle",children:s})]})}function _n({chats:t,workspaceSlug:s,loading:n,empty:r,onOpenChat:l,kind:i}){return n&&t.length===0?e.jsx("div",{className:"h-[52px] animate-pulse rounded-2xl border border-edge bg-surface-raised","aria-busy":"true"}):t.length===0?e.jsx(ms,{title:r}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-edge","data-testid":`home-${i}-chats`,children:t.map((o,c)=>e.jsxs("button",{onClick:()=>l(o.sessionId,o.projectSlug),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover ${c>0?"border-t border-edge":""}`,children:[i==="running"?e.jsx("span",{title:"Streaming a response…","aria-label":"streaming",className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-accent-solid"}):e.jsx("span",{title:"Unread reply","aria-label":"unread",className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent-solid"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:o.name}),o.projectSlug!==s&&e.jsx("span",{className:"shrink-0 truncate rounded-md bg-surface-active px-1.5 py-0.5 text-2xs text-fg-muted",children:o.projectName}),e.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:It(i==="unread"?o.lastTurnCompletedAt??o.updatedAt:o.updatedAt)})]},`${o.projectSlug}:${o.sessionId}`))})}function Dn({id:t,title:s,body:n,emptyTitle:r,emptyBody:l}){const[i,o]=_o(t),c=!i,u=n.trim().length>0;return e.jsxs("section",{className:"mb-8",children:[e.jsxs("button",{type:"button",onClick:o,"aria-expanded":c,className:"mb-2 -ml-1 flex w-full items-center gap-1.5 rounded-lg px-1 py-1 text-left transition-colors hover:bg-surface-hover",children:[e.jsx(fs,{width:14,height:14,className:`shrink-0 text-fg-subtle transition-transform ${c?"rotate-90":""}`}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wide text-fg-muted",children:s})]}),c&&(u?e.jsx("div",{className:"card",children:e.jsx(Wt,{children:n})}):e.jsx(ms,{title:r,body:l}))]})}function _o(t){const s=`paddock:home-collapsed:${t}`,[n,r]=a.useState(()=>{try{return localStorage.getItem(s)==="1"}catch{return!1}});return[n,()=>r(i=>{const o=!i;try{localStorage.setItem(s,o?"1":"0")}catch{}return o})]}const Qs=8,qs=2*Math.PI*Qs,Do=.25*qs;function Pn({tokens:t,limit:s,usage:n,size:r=14,working:l=!1}){const i=t!=null&&s!=null&&s>0;if(!i&&!l)return null;const o=i?Math.min(100,Math.max(0,t/s*100)):0,c=i&&o>=80,u=i?o/100*qs:Do,x=i?Math.round(t/1e3):0,N=i?Math.round(s/1e3):0,m=n?`
12
- Session so far: ${Un(n)}`:"",j=l?i?`Streaming a response… — context window ${Math.round(o)}% full (${t.toLocaleString()} / ${s.toLocaleString()} tokens)`:"Streaming a response…":`Context window ${Math.round(o)}% full as of the last completed turn (${t.toLocaleString()} / ${s.toLocaleString()} tokens)${m}`,y=l?i?`Streaming a response… (context ${Math.round(o)}% full)`:"Streaming a response…":`Context ${Math.round(o)}% full (${x}k of ${N}k tokens)`;return e.jsx("span",{className:"inline-flex shrink-0 items-center",title:j,"aria-label":y,children:e.jsxs("svg",{width:r,height:r,viewBox:"0 0 20 20",className:l?"spin-eco":"-rotate-90",role:"img","aria-hidden":"true",children:[e.jsx("circle",{cx:"10",cy:"10",r:Qs,fill:"none",strokeWidth:"3",className:"stroke-edge"}),e.jsx("circle",{cx:"10",cy:"10",r:Qs,fill:"none",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:`${u} ${qs}`,className:c?"stroke-[var(--warn-solid)]":"stroke-[var(--accent-solid)]"})]})})}function Po({provenance:t,hookName:s,className:n=""}){const r=t==null?void 0:t.origin;if(r!=="scheduled"&&r!=="spawned"&&r!=="hook"&&r!=="adopted")return null;if(r==="adopted")return e.jsx("span",{"data-provenance":"adopted","aria-label":"Adopted chat",title:"Adopted — this chat came from your Claude Code CLI history",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-success ${n}`,children:e.jsx(ps,{width:12,height:12})});if(r==="hook"){const o=s?`Hook — the “${s}” event hook fired this chat`:"Hook — an event hook fired this chat";return e.jsx("span",{"data-provenance":"hook","aria-label":"Hook chat",title:o,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-info ${n}`,children:e.jsx(zt,{width:12,height:12})})}if(r==="scheduled")return e.jsx("span",{"data-provenance":"scheduled","aria-label":"Scheduled chat",title:"Scheduled — a schedule started this chat",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-warn ${n}`,children:e.jsx(et,{width:12,height:12})});const l=(t==null?void 0:t.depth)??0,i=l>1?` (${l} levels deep)`:"";return e.jsx("span",{"data-provenance":"spawned","aria-label":"Spawned chat",title:`Spawned — another chat created this one${i}`,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-lineage ${n}`,children:e.jsx(Ze,{width:12,height:12})})}function Se({content:t,children:s,delayMs:n=250,className:r=""}){const l=a.useId(),i=a.useRef(null),o=a.useRef(null),c=a.useRef(null),[u,x]=a.useState(null),N=()=>{c.current&&clearTimeout(c.current),c.current=null},m=a.useCallback(()=>{N(),x(null)},[]),j=a.useCallback(()=>{var S;const g=(S=i.current)==null?void 0:S.getBoundingClientRect();if(!g)return;const f=g.top<56;x({x:g.left+g.width/2,y:f?g.bottom+6:g.top-6,below:f})},[]);a.useEffect(()=>N,[]),a.useEffect(()=>{if(!u)return;const g=f=>{f.key==="Escape"&&m()};return window.addEventListener("keydown",g),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("keydown",g),window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[u,m]),a.useLayoutEffect(()=>{if(!u||!o.current)return;const g=o.current.offsetWidth;if(!g)return;const f=8+g/2,S=window.innerWidth-8-g/2,M=Math.min(Math.max(u.x,f),Math.max(f,S));M!==u.x&&x({...u,x:M})},[u]);const y=a.Children.only(s),C=a.isValidElement(y)?a.cloneElement(y,{"aria-describedby":u?l:void 0}):y;return e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:i,className:`inline-flex ${r}`,onPointerEnter:g=>{g.pointerType!=="touch"&&(N(),c.current=setTimeout(j,n))},onPointerLeave:m,onPointerDown:m,onFocusCapture:j,onBlurCapture:m,children:C}),u&&Bn.createPortal(e.jsx("div",{ref:o,id:l,role:"tooltip",style:{position:"fixed",left:u.x,top:u.y,transform:`translate(-50%, ${u.below?"0":"-100%"})`},className:"pointer-events-none z-[70] max-w-[15rem] animate-fade-in rounded-lg bg-fg px-2 py-1 text-2xs leading-snug text-surface shadow-lg",children:t}),document.body)]})}function Lo({activeTotal:t,shownCount:s,searching:n,runningCount:r,runningOnly:l,setRunningOnly:i}){const o=n?`${s}/${t}`:`${t}`,c=n?`${s} of ${t} chats shown`:`${t} chats`;return r===0&&!l?e.jsx("span",{className:"text-2xs text-fg-subtle",title:c,children:o}):e.jsxs("span",{role:"group","aria-label":"Chat count and running filter",className:"flex items-stretch overflow-hidden rounded-full border border-edge-strong text-2xs leading-none",children:[e.jsx(Se,{content:l?"Show all chats":c,className:"items-stretch",children:e.jsx("button",{type:"button",onClick:()=>i(!1),"aria-pressed":!l,"aria-label":l?`Show all ${t} chats`:`${t} chats`,className:`h-full px-1.5 py-0.5 transition-colors ${l?"text-fg-subtle hover:bg-surface-hover hover:text-fg":"bg-surface-active font-medium text-fg-muted"}`,children:o})}),e.jsx(Se,{content:l?"Showing only running chats — click to show all":`Show only the ${r} chat${r===1?"":"s"} running now`,className:"items-stretch",children:e.jsxs("button",{type:"button",onClick:()=>i(!l),"aria-pressed":l,"aria-label":`Show only running chats (${r} running)`,className:`flex h-full items-center gap-1 border-l border-edge-strong px-1.5 py-0.5 transition-colors ${l?"bg-accent-solid font-semibold text-accent-fg":"font-medium text-accent hover:bg-accent-soft"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`h-2.5 w-2.5 rounded-full border-[1.5px] border-current ${r>0?"spin-eco border-t-transparent":"opacity-60"}`}),r]})})]})}function Ao({nested:t,setNested:s,runningOnly:n}){const r=t?"Switch to a flat chat list":"Switch to a nested chat list";return e.jsx(Se,{content:n?"Running-only view is always flat":r,children:e.jsx("button",{type:"button",onClick:()=>s(!t),disabled:n,"aria-label":r,"aria-pressed":t,className:"btn-subtle h-9 w-9 shrink-0 p-0 disabled:cursor-not-allowed disabled:opacity-40",children:t?e.jsx(Ta,{width:16,height:16,className:"mx-auto"}):e.jsx(Ma,{width:16,height:16,className:"mx-auto"})})})}function As(t){return`${t} nested chat${t===1?"":"s"}`}const Fo=4,Oo=new Set;function Uo({chatList:t,sessionsOpen:s,setSessionsOpen:n,chatSearch:r,setChatSearch:l,searching:i,newChat:o,view:c,activeSession:u,pendingChat:x,chats:N,fallbackChat:m,visibleChats:j,activeChats:y,archivedChats:C,activeTotal:g,runningCount:f,viewPrefs:S,archivedOpen:M,setArchivedOpen:R,collapsedChats:v,toggleChatCollapsed:L,openChat:E,unread:B,usageBySession:w,runningSessions:O,setForkingChat:k,setPromotingChat:z,renameChat:P,archiveChat:G,requestDeleteChat:J,starChat:T,toggleUnread:_,detachChat:U,adoptableCount:H,adopting:ce,adoptChats:ne}){const X=i?Oo:v,se=y.some(p=>p.children.length>0)||C.some(p=>p.children.length>0),h=Gs(y),A=Gs(C),q=(p,ee)=>{var Pe,ye,ze,He;const pe=(ee==null?void 0:ee.depth)??0,Ve=(ee==null?void 0:ee.children.length)??0,ge=(ee==null?void 0:ee.descendantCount)??0,be=B.has(p.sessionId),me=X.has(p.sessionId),we=!!ee&&ge>0,Me=Q=>we&&Q.shiftKey?wo(ee):[p.sessionId],de=ge+1,$e=(Q,ke)=>we?e.jsxs(e.Fragment,{children:[Q," · ",e.jsx("span",{className:"font-semibold",children:"Shift-click"})," to ",ke]}):Q,_e=(Q,ke)=>we?`${Q} (Shift-click to ${ke})`:Q,Te=6+(pe>0?1:0)+(z?1:0);return e.jsxs("div",{className:`group/chat chat-row chat-row--actions-${Te} relative mb-0.5 flex rounded-lg transition-colors ${u===p.sessionId&&c==="chat"?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[Array.from({length:Math.min(pe,Fo)},(Q,ke)=>e.jsx("div",{"aria-hidden":"true",className:"w-3 shrink-0 border-l border-edge"},ke)),se&&e.jsx("div",{className:"flex w-4 shrink-0 items-start justify-center pt-2.5",children:Ve>0&&e.jsx(Se,{content:me?`Show ${As(ge)}`:"Hide nested chats",children:e.jsx("button",{type:"button","aria-label":`${me?"Expand":"Collapse"} ${ge} chat${ge===1?"":"s"} under ${p.name}`,"aria-expanded":!me,onClick:Q=>{Q.stopPropagation(),L(p.sessionId)},className:"flex h-4 w-4 items-center justify-center rounded text-fg-subtle transition hover:bg-surface-active hover:text-fg",children:e.jsx(ln,{width:11,height:11,className:`transition-transform ${me?"-rotate-90":""}`})})})}),e.jsxs("button",{type:"button",onClick:()=>E(p.sessionId),className:`flex min-w-0 flex-1 flex-col items-start gap-0.5 rounded-lg py-2 pr-2.5 text-left text-sm ${se?"pl-1":"pl-2.5"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-1.5",children:[be&&e.jsx(Se,{content:"New reply you haven't read yet",className:"shrink-0",children:e.jsx("span",{"data-unread":"true","aria-label":"Unread reply",className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent-solid"})}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${be?"font-semibold":"font-medium"}`,children:p.name}),me&&ge>0&&e.jsx(Se,{content:`${As(ge)} hidden`,className:"shrink-0",children:e.jsx("span",{className:"shrink-0 rounded-full bg-surface-active px-1.5 text-3xs font-medium leading-4 text-fg-muted",children:ge})}),!(pe>0&&((Pe=p.provenance)==null?void 0:Pe.origin)==="spawned")&&e.jsx(Po,{provenance:p.provenance,hookName:(ye=p.trigger)==null?void 0:ye.name}),e.jsx(Pn,{tokens:((ze=w[p.sessionId])==null?void 0:ze.contextTokens)??p.contextTokens,limit:((He=w[p.sessionId])==null?void 0:He.contextLimit)??p.contextLimit,usage:Da(w[p.sessionId]??p),working:O.has(p.sessionId)})]}),e.jsx("span",{className:"chat-row-time text-2xs leading-5 text-fg-subtle",children:It(p.updatedAt)})]}),e.jsxs("div",{className:"absolute bottom-1 right-1.5 flex items-center gap-0.5",children:[pe>0&&e.jsx(Se,{content:ge>0?`Detach from parent — move this chat and its ${As(ge)} to the top level`:"Detach from parent — move this chat to the top level",children:e.jsx("button",{type:"button","aria-label":`Detach chat ${p.name} from its parent`,onClick:Q=>{Q.stopPropagation(),U(p)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Pa,{width:13,height:13})})}),e.jsx(Se,{content:"Fork chat — branch a new chat from this one's context",children:e.jsx("button",{type:"button","aria-label":`Fork chat ${p.name}`,onClick:Q=>{Q.stopPropagation(),k(p)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Ze,{width:13,height:13})})}),z&&e.jsx(Se,{content:"Promote into a new project — give this chat a home of its own",children:e.jsx("button",{type:"button","aria-label":`Promote chat ${p.name} into a project`,onClick:Q=>{Q.stopPropagation(),z(p)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(lt,{width:13,height:13})})}),e.jsx(Se,{content:"Rename chat",children:e.jsx("button",{type:"button","aria-label":`Rename chat ${p.name}`,onClick:Q=>{Q.stopPropagation(),P(p)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-fg focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(xs,{width:13,height:13})})}),e.jsx(Se,{content:$e(p.archived?"Unarchive chat":"Archive chat — file it away without deleting",p.archived?`unarchive all ${de}`:`archive all ${de}`),children:e.jsx("button",{type:"button","aria-label":_e(`${p.archived?"Unarchive":"Archive"} chat ${p.name}`,p.archived?`unarchive all ${de}`:`archive all ${de}`),onClick:Q=>{Q.stopPropagation(),G(p,Me(Q))},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-surface-active hover:text-accent ${p.archived?"text-accent opacity-100":"text-fg-subtle opacity-0"}`,children:e.jsx(La,{width:13,height:13})})}),e.jsx(Se,{content:$e("Delete chat",`delete all ${de}`),children:e.jsx("button",{type:"button","aria-label":_e(`Delete chat ${p.name}`,`delete all ${de}`),onClick:Q=>{Q.stopPropagation(),J(p,Me(Q))},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-danger-soft hover:text-danger focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Xs,{width:13,height:13})})}),e.jsx(Se,{content:$e(be?"Mark as read":"Mark as unread — resurface it later",be?`mark all ${de} read`:`mark all ${de} unread`),children:e.jsx("button",{type:"button","aria-label":_e(`Mark chat ${p.name} ${be?"read":"unread"}`,be?`mark all ${de} read`:`mark all ${de} unread`),"aria-pressed":be,onClick:Q=>{Q.stopPropagation(),_(p,Me(Q))},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Aa,{width:13,height:13,open:!be})})}),e.jsx(Se,{content:p.starred?"Unstar chat":"Star chat — pin it to the top of the list",children:e.jsx("button",{type:"button","aria-label":`${p.starred?"Unstar":"Star"} chat ${p.name}`,"aria-pressed":!!p.starred,onClick:Q=>{Q.stopPropagation(),T(p)},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-surface-active hover:text-warn ${p.starred?"text-warn opacity-100":"text-fg-subtle opacity-0"}`,children:e.jsx(Fa,{width:13,height:13,fill:p.starred?"currentColor":"none"})})})]})]},p.sessionId)};return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"fixed inset-0 z-20 bg-overlay lg:hidden","aria-hidden":"true",onClick:()=>n(!1)}),e.jsxs("div",{style:t.style,className:`fixed inset-y-0 left-0 z-30 flex w-64 max-w-[80%] shrink-0 flex-col border-r border-edge bg-surface-raised shadow-2xl transition-transform duration-200 ease-out lg:relative lg:z-auto lg:max-w-none lg:translate-x-0 lg:bg-surface-raised/40 lg:shadow-none ${s?"translate-x-0":"-translate-x-full"}`,children:[t.isDesktop&&e.jsx(_a,{spec:t.spec,width:t.width,onPreview:t.preview,onCommit:t.commit,onReset:t.reset,label:"Resize chat list"}),e.jsxs("div",{className:"flex items-center gap-2 p-3",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(Vn,{width:15,height:15,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-subtle"}),e.jsx("input",{type:"text",value:r,onChange:p=>l(p.target.value),placeholder:"Search","aria-label":"Search chats",className:`input py-1.5 pl-8 ${i?"pr-8":"pr-2"}`}),i&&e.jsx(Se,{content:"Clear search",className:"absolute right-1.5 top-1/2 -translate-y-1/2",children:e.jsx("button",{type:"button",onClick:()=>l(""),"aria-label":"Clear search",className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle transition hover:bg-surface-active hover:text-fg",children:e.jsx(Be,{width:13,height:13})})})]}),e.jsx(Ao,{nested:S.nested,setNested:S.setNested,runningOnly:S.runningOnly}),e.jsx(Se,{content:"New chat",children:e.jsx("button",{type:"button",className:"btn-primary h-9 w-9 shrink-0 p-0",onClick:o,"aria-label":"New Chat",children:e.jsx(lt,{width:16,height:16})})}),e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close chats",className:"btn-subtle shrink-0 px-2 py-2 lg:hidden",children:e.jsx(Be,{width:16,height:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[H>0&&e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("button",{type:"button",onClick:ne,disabled:ce,"aria-label":`Adopt ${H} native Claude Code chat${H===1?"":"s"} into this workspace`,"aria-haspopup":"dialog",className:"btn-ghost w-full justify-start py-1.5 text-xs",children:[e.jsx(ps,{width:13,height:13,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ce?"Adopting…":`Adopt ${H} native chat${H===1?"":"s"}…`})]})}),e.jsxs("div",{className:"mb-1 flex items-center justify-between pr-3",children:[e.jsx("span",{className:"section-label",children:"Chats"}),(g>0||S.runningOnly)&&e.jsx(Lo,{activeTotal:g,shownCount:h,searching:i,runningCount:f,runningOnly:S.runningOnly,setRunningOnly:S.setRunningOnly})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:[u===null&&c==="chat"&&!x&&e.jsxs("div",{className:"mb-0.5 flex items-center gap-1.5 rounded-lg bg-surface-selected px-2.5 py-2 text-sm",children:[e.jsx(Ht,{width:13,height:13,className:"text-fg-muted"}),e.jsx("span",{className:"font-medium italic text-fg-muted",children:"New chat…"})]}),x&&!N.some(p=>p.sessionId===x)&&e.jsx("div",{className:`group/chat relative mb-0.5 rounded-lg transition-colors ${u===x&&c==="chat"?"bg-surface-selected":"hover:bg-surface-hover"}`,children:e.jsxs("button",{onClick:()=>E(x),className:"flex w-full items-center gap-1.5 rounded-lg px-2.5 py-2 text-left text-sm",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-medium italic text-fg-muted",children:"New chat…"}),e.jsx(Pn,{working:!0})]})}),m&&q(m),N.length===0&&!m&&e.jsx("p",{className:"px-2 py-2 text-sm text-fg-muted",children:"No saved chats yet. Send a message to start one."}),N.length>0&&S.runningOnly&&f===0&&e.jsxs("p",{className:"px-2 py-2 text-sm text-fg-muted",children:["No chats are running."," ",e.jsx("button",{type:"button",onClick:()=>S.setRunningOnly(!1),className:"text-accent underline underline-offset-2 hover:no-underline",children:"Show all chats"})]}),N.length>0&&(!S.runningOnly||f>0)&&i&&j.length===0&&!m&&e.jsxs("p",{className:"px-2 py-2 text-sm text-fg-muted",children:["No chats match “",r.trim(),"”."]}),N.length>0&&!S.runningOnly&&!i&&y.length===0&&!m&&e.jsx("p",{className:"px-2 py-2 text-sm text-fg-muted",children:"No active chats — see Archived below."}),Tn(y,X).map(p=>q(p.chat,p))]}),C.length>0&&e.jsxs("div",{className:`flex flex-col border-t border-edge ${M?"min-h-0 flex-1":"shrink-0"}`,children:[e.jsxs("button",{type:"button",onClick:()=>R(p=>!p),"aria-expanded":M,className:"flex w-full items-center gap-1.5 px-3 py-2 text-left text-xs font-medium uppercase tracking-wide text-fg-muted transition-colors hover:bg-surface-hover",children:[e.jsx(ln,{width:14,height:14,className:`shrink-0 transition-transform ${M?"":"-rotate-90"}`}),e.jsx("span",{children:"Archived"}),e.jsx("span",{className:"ml-auto rounded-full bg-surface-active px-1.5 py-0.5 text-3xs font-semibold normal-case text-fg-muted",children:A})]}),M&&e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:Tn(C,X).map(p=>q(p.chat,p))})]})]})]})]})}function Bo({slug:t,chats:s,view:n,activeSession:r,runningSessions:l,onSeen:i,onManySeen:o}){const[c,u]=a.useState(new Set),[x,N]=a.useState(0),m=a.useCallback((g,f)=>{const S=Date.now(),M=(f==null?void 0:f.keepUnread)===!0,R=on(g,S),v=M?{keepUnread:!0}:void 0;F.markChatSeen(t,g,S,v).catch(()=>{cn(g,R,S),N(L=>L+1)}),M||i==null||i(g),u(L=>{if(!L.has(g))return L;const E=new Set(L);return E.delete(g),E}),N(L=>L+1)},[t,i]),j=a.useCallback(g=>{if(g.length<=1){g[0]&&m(g[0]);return}const f=Date.now(),S=g.map(v=>[v,on(v,f)]),M=g.filter(v=>c.has(v)),R=o==null?void 0:o(g);u(v=>{if(!M.length)return v;const L=new Set(v);for(const E of M)L.delete(E);return L}),N(v=>v+1),F.markChatsUnread(t,g,!1).catch(()=>{for(const[v,L]of S)cn(v,L,f);M.length&&u(v=>{const L=new Set(v);for(const E of M)L.add(E);return L}),R==null||R(),N(v=>v+1)})},[t,o,m,c]);a.useEffect(()=>{for(const g of s)Oa(g.sessionId,g.lastSeen);N(g=>g+1)},[s]);const y=a.useMemo(()=>{const g=new Set;for(const f of s){if(n==="chat"&&f.sessionId===r)continue;if(f.unread||c.has(f.sessionId)){g.add(f.sessionId);continue}const S=f.lastTurnCompletedAt?Date.parse(f.lastTurnCompletedAt):NaN;Number.isFinite(S)&&S>Ua(f.sessionId)&&g.add(f.sessionId)}return g},[s,n,r,c,x]);a.useEffect(()=>{n==="chat"&&r&&m(r)},[n,r,m]);const C=a.useRef(new Set);return a.useEffect(()=>{const g=C.current;for(const f of g)l.has(f)||(n==="chat"&&f===r?m(f,{keepUnread:!0}):u(S=>S.has(f)?S:new Set(S).add(f)));C.current=l},[l,n,r,m]),{markSeen:m,markManySeen:j,unread:y}}const Vo=250,zo=2500,Ho=3e4;function Wo(t,s){const[n,r]=a.useState([]),[l,i]=a.useState([]),[o,c]=a.useState(!0),[u,x]=a.useState(null),N=a.useRef(0),m=a.useCallback(async()=>{const C=++N.current;try{const g=await F.attentionChats(t);if(C!==N.current)return;r(g.running),i(g.unread),x(null)}catch(g){if(C!==N.current)return;x(g instanceof Error?g.message:"Failed to load chats")}finally{C===N.current&&c(!1)}},[t]),j=a.useRef(m);j.current=m;const y=a.useRef(!1);return a.useEffect(()=>{y.current=!1,r([]),i([]),c(!0),m()},[t,m]),a.useEffect(()=>{if(!y.current){y.current=!0;return}const C=setTimeout(()=>void j.current(),Vo),g=setTimeout(()=>void j.current(),zo);return()=>{clearTimeout(C),clearTimeout(g)}},[s]),a.useEffect(()=>{const C=()=>{document.visibilityState==="visible"&&j.current()},g=setInterval(C,Ho);return document.addEventListener("visibilitychange",C),()=>{clearInterval(g),document.removeEventListener("visibilitychange",C)}},[]),{running:n,unread:l,loading:o,error:u,refresh:()=>void m()}}function Go({message:t,tone:s="success",onDismiss:n,durationMs:r=6e3,action:l}){if(a.useEffect(()=>{if(t===null||r<=0)return;const o=setTimeout(n,r);return()=>clearTimeout(o)},[t,r,n]),t===null)return null;const i=s==="error";return e.jsx("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 bottom-4 z-50 flex justify-center px-4",children:e.jsxs("div",{className:`pointer-events-auto flex max-w-md items-start gap-2 rounded-lg border px-3 py-2 text-sm shadow-lg ${i?"border-danger-edge bg-danger-soft text-danger":"border-edge bg-surface-raised text-fg"}`,children:[i?e.jsx(je,{width:16,height:16,className:"mt-0.5 shrink-0"}):e.jsx(pt,{width:16,height:16,className:"mt-0.5 shrink-0 text-success-solid"}),e.jsx("span",{className:"break-words",children:t}),l&&e.jsx("button",{type:"button",onClick:l.onAct,className:"ml-1 shrink-0 font-medium underline underline-offset-2 transition hover:opacity-80",children:l.label}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Dismiss notification",className:"-mr-1 ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded transition hover:bg-surface-hover",children:e.jsx(Be,{width:12,height:12})})]})})}function ga({adopted:t,skipped:s}){const n=t.length;if(n===0&&s.length===0)return"Nothing to adopt — no native chats were found.";const r=n===0?"Adopted nothing":`Adopted ${n} chat${n===1?"":"s"}`;if(s.length===0)return r;const l=[...new Set(s.map(o=>o.reason).filter(Boolean))],i=l.length===1?` (${l[0]})`:"";return`${r} — skipped ${s.length}${i}`}function Ko({root:t=!1}={}){var Y,ue,Ne,Re,os;const s=Ba(),n=t?Va:s.slug??"",r=dn(n),l=za(),i=Ha(),o=Wa(),c=(o==null?void 0:o.openNav)??(()=>{}),{refresh:u,upsert:x,remove:N}=Ga(),m=Ka(l.pathname,r),j=m==="chat"?s.sessionId:void 0,y=m==="files"?Qa(l.pathname,r):"",C=m==="changes"&&s.file?decodeURIComponent(s.file):void 0,g=a.useRef({counter:0,session:j??null}),f=a.useRef(!1);g.current.session!==(j??null)&&((Y=l.state)!=null&&Y.established||(g.current.counter+=1),g.current.session=j??null);const[S,M]=a.useState(0),R=`${g.current.counter}:${S}`,[v,L]=a.useState(null),[E,B]=a.useState([]),[w,O]=a.useState({}),[k,z]=a.useState(""),[P,G]=a.useState(null),[J,T]=a.useState(new Set);a.useEffect(()=>Ue.onActiveSessions(T),[]);const[_,U]=a.useState(""),[H,ce]=a.useState(""),[ne,X]=a.useState([]),[se,h]=a.useState(null),[A,q]=a.useState(0),[p,ee]=a.useState(!1),[pe,Ve]=a.useState(null),[ge,be]=a.useState(!1),[me,we]=a.useState(null),Me=a.useCallback(()=>we(null),[]),[de,$e]=a.useState(null),_e=Pi(n),Te=_e.newUnattended,[Pe,ye]=a.useState(!1),[ze,He]=a.useState(!1),[Q,ke]=a.useState(null),[he,We]=a.useState(null),[Le,it]=a.useState(null),[Ke,Ae]=a.useState(null),[Ee,I]=a.useState(!1),[te,ae]=a.useState(()=>ko(n)),xe=a.useCallback(d=>{ae($=>{const V=new Set($);return V.has(d)?V.delete(d):V.add(d),Co(n,V),V})},[n]),re=Ro(),Ce=qa(sr),tt=a.useRef(null),Z=j??null,$t=a.useCallback(d=>B($=>$.map(V=>V.sessionId===d&&V.unread?{...V,unread:!1}:V)),[]),st=a.useCallback(d=>{const $=new Set(d),V=E.filter(K=>$.has(K.sessionId)&&K.unread).map(K=>K.sessionId);if(!V.length)return()=>{};B(K=>K.map(ie=>$.has(ie.sessionId)&&ie.unread?{...ie,unread:!1}:ie));const W=new Set(V);return()=>B(K=>K.map(ie=>W.has(ie.sessionId)?{...ie,unread:!0}:ie))},[E]),{unread:Qe,markManySeen:gt}=Bo({slug:n,chats:E,view:m,activeSession:Z,runningSessions:J,onSeen:$t,onManySeen:st}),ot=Wo(n,J),qe=a.useMemo(()=>{const d=re.runningOnly?E.filter(W=>J.has(W.sessionId)||W.sessionId===Z):E,$=k.trim().toLowerCase();if(!$)return d;const V=d.filter(W=>{var K;return W.name.toLowerCase().includes($)||(((K=W.preview)==null?void 0:K.toLowerCase().includes($))??!1)});return re.runningOnly?V:yo(E,V)},[E,k,re.runningOnly,J,Z]),vs=k.trim().length>0,Fe=a.useCallback(async()=>{const d=await F.gitStatus(n).catch(()=>null);$e(d&&d.repo?d:null)},[n]),bt=a.useCallback(async()=>{const d=await F.chatUsage(n).catch(()=>null);d&&O($=>({...$,...d}))},[n]),jt=a.useCallback(async()=>{const d=await F.chatUsage(n,"archived").catch(()=>null);d&&O($=>({...$,...d}))},[n]),Et=a.useRef(!1),Gt=a.useCallback(async()=>{h(null);try{const d=await F.getProjectDetail(n);L(d.project),B(d.chats),U(d.changelog),ce(d.overview??"");const $=await F.listProjectFiles(n).catch(()=>[]);X($)}catch(d){h(d instanceof Error?d.message:"Failed to load project")}Fe(),bt()},[n,Fe,bt]);a.useEffect(()=>{L(null),$e(null),O({}),Et.current=!1,Gt()},[n,Gt]),a.useEffect(()=>{Ee&&(Et.current=!0,jt())},[Ee,jt]),a.useEffect(()=>{if(t)return;const d=m==="home"?xt({view:"home"}):m==="settings"?xt({view:"settings"}):m==="history"?xt({view:"history"}):m==="triggers"?xt({view:"triggers"}):m==="chat"?xt({view:"chat",sessionId:j}):m==="changes"?xt({view:"changes",file:C}):xt({view:"files",path:y||void 0});mr(n,d)},[t,n,m,j,y,C]);const ve=a.useCallback(async()=>{const d=await F.listProjectChats(n).catch(()=>null);d&&B(d)},[n]),nt=a.useCallback(async()=>{const d=await F.getAdoptableChats(n).catch(()=>null);q((d==null?void 0:d.count)??0),Ve(d)},[n]),Rt=a.useCallback(async d=>{we(null);try{const $=await F.unadoptChats(n,{sessionIds:d});await ve(),await nt(),we($.released.length>0?{message:`Removed ${$.released.length} adopted chat${$.released.length===1?"":"s"}.`,tone:"success"}:{message:"Nothing left to undo.",tone:"error"})}catch($){we({message:$ instanceof Error?$.message:"Failed to undo the adoption",tone:"error"})}},[n,ve,nt]),Tt=a.useCallback(async d=>{if(!p){ee(!0);try{const $=await F.adoptChats(n,{sessionIds:d});be(!1),await ve(),await nt();const V=$.adopted.length===0&&$.skipped.length>0;we({message:ga($),tone:V?"error":"success",action:$.adopted.length>0?{label:"Undo",onAct:()=>void Rt($.adopted)}:void 0})}catch($){we({message:$ instanceof Error?$.message:"Failed to adopt native chats",tone:"error"})}finally{ee(!1)}}},[p,n,ve,nt,Rt]);a.useEffect(()=>{q(0),Ve(null),be(!1),we(null),nt()},[nt]);const ct=a.useCallback(async()=>{const d=await F.getProjectDetail(n).catch(()=>null);d&&(L(d.project),B(d.chats),U(d.changelog),ce(d.overview??""));const $=await F.listProjectFiles(n).catch(()=>null);$&&X($),Fe(),bt(),Et.current&&jt()},[n,Fe,bt,jt]),ws=a.useCallback(d=>F.projectChatMessages(n,d),[n]);a.useEffect(()=>{ye(!1)},[m,j,y,C]);const Kt=a.useCallback(()=>i(Ya(r)),[i,r]),at=a.useCallback(()=>i(`${r}/chat`),[i,r]),dt=a.useCallback(()=>i(`${r}/files`),[i,r]),Mt=a.useCallback(()=>i(`${r}/changes`),[i,r]),Qt=a.useCallback(()=>i(`${r}/history`),[i,r]),vt=a.useCallback(()=>i(`${r}/settings`),[i,r]),_t=a.useCallback(()=>i(`${r}/triggers`),[i,r]),ut=a.useCallback(d=>i(d?`${r}/changes/${encodeURIComponent(d)}`:`${r}/changes`),[i,r]);a.useEffect(()=>{l.pathname.startsWith(`${r}/hooks`)&&i(`${r}/triggers`,{replace:!0})},[l.pathname,i,r]);const Dt=a.useCallback(()=>{M(d=>d+1),xi(n),at()},[at,n]),Pt=a.useCallback(d=>i(`${r}/chat/${encodeURIComponent(d)}`),[i,r]),qt=a.useCallback((d,$)=>i(`${dn($)}/chat/${encodeURIComponent(d)}`),[i]),Ns=a.useCallback(async(d,$)=>{let V;try{V=await F.forkChat(n,d.sessionId,$)}catch(W){h(W instanceof Error?W.message:"Failed to fork chat");return}Rn(V,{sessionId:d.sessionId,name:d.name}),await ve(),i(`${r}/chat/${encodeURIComponent(V)}`,{state:{justForked:!0}})},[i,r,n,ve]),Yt=a.useCallback(async d=>{if(!Z||f.current)return;f.current=!0;const $=E.find(K=>K.sessionId===Z),V=$?`Fork of ${$.name}`:void 0;let W;try{W=await F.forkChat(n,Z,V,d)}catch(K){h(K instanceof Error?K.message:"Failed to fork chat"),f.current=!1;return}$&&Rn(W,{sessionId:$.sessionId,name:$.name}),await ve(),i(`${r}/chat/${encodeURIComponent(W)}`,{state:{justForked:!0}}),f.current=!1},[Z,E,i,r,n,ve]),Ye=a.useCallback(async d=>{if(Z){try{await F.revertChat(n,Z,d)}catch($){throw h($ instanceof Error?$.message:"Failed to revert chat"),$}await ve()}},[Z,n,ve]),Je=go(j),Jt=((ue=l.state)==null?void 0:ue.justForked)===!0,mt=a.useCallback(d=>i(d?`${r}/files/${d.split("/").map(encodeURIComponent).join("/")}`:`${r}/files`),[i,r]),ys=a.useCallback(d=>{G(d),ve(),u(),j||i(`${r}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[ve,u,j,i,r]),Xt=a.useCallback(d=>{ve(),u(),j||i(`${r}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[ve,u,j,i,r]);a.useEffect(()=>{P&&E.some(d=>d.sessionId===P)&&G(null)},[E,P]);const Lt=a.useRef(new Set);a.useEffect(()=>{let d=!1;for(const $ of J)Lt.current.has($)||(Lt.current.add($),E.some(V=>V.sessionId===$)||(d=!0));d&&ve()},[J,E,ve]);const ks=a.useCallback(d=>{d&&O($=>({...$,[d.sessionId]:d.usage})),ct(),u()},[ct,u]),Cs=a.useCallback(async d=>{if(!v)return;const $=v.pinned.includes(d)?await F.unpinFile(n,d):await F.pinFile(n,d);L($),x($)},[v,n,x]),Zt=a.useCallback(async d=>{const $=await F.unpinFile(n,d);L($),x($),y===d&&i(`${r}/files`,{replace:!0})},[n,r,x,y,i]),es=a.useCallback(async()=>{if(!he)return;const{ids:d}=he;let $;if(d.length===1)await F.deleteProjectChat(n,d[0]),$=d;else{const W=await F.deleteProjectChats(n,d);$=W.removed,W.failed.length&&h(`Deleted ${W.removed.length} of ${d.length} chats — ${W.failed.length} could not be removed.`)}const V=new Set($);Ja($),B(W=>W.filter(K=>!V.has(K.sessionId))),Z&&V.has(Z)&&i(`${r}/chat`,{replace:!0}),We(null)},[he,n,r,Z,i]),ts=a.useCallback((d,$)=>{const V=E.filter(ie=>!!ie.archived==!!d.archived),W=new Set($),K=No(V,d.sessionId).filter(ie=>!W.has(ie)).length;We({chat:d,ids:$,orphanCount:K})},[E]),wt=a.useCallback(async(d,$)=>{await F.renameProjectChat(n,d.sessionId,$),B(V=>V.map(W=>W.sessionId===d.sessionId?{...W,name:$||W.preview||W.sessionId.slice(0,8)}:W))},[n]),ss=a.useCallback(async(d,$)=>{const V=!d.archived,W=new Set($);B(K=>K.map(ie=>W.has(ie.sessionId)?{...ie,archived:V}:ie)),V&&I(!0);try{$.length===1?await F.archiveProjectChat(n,$[0],V):await F.archiveProjectChats(n,$,V)}catch(K){B(ie=>ie.map(rt=>W.has(rt.sessionId)?{...rt,archived:d.archived}:rt)),h(K instanceof Error?K.message:"Failed to archive chat")}},[n]),ns=a.useCallback(async d=>{const $=d.parent;if($){B(V=>V.map(W=>W.sessionId===d.sessionId?{...W,parent:void 0}:W));try{await F.detachProjectChat(n,d.sessionId,!0)}catch(V){B(W=>W.map(K=>K.sessionId===d.sessionId?{...K,parent:$}:K)),h(V instanceof Error?V.message:"Failed to detach chat")}}},[n]),as=a.useCallback(async d=>{const $=!d.starred;B(V=>V.map(W=>W.sessionId===d.sessionId?{...W,starred:$}:W));try{await F.starProjectChat(n,d.sessionId,$)}catch(V){B(W=>W.map(K=>K.sessionId===d.sessionId?{...K,starred:d.starred}:K)),h(V instanceof Error?V.message:"Failed to star chat")}},[n]),rs=a.useCallback(async(d,$)=>{if(Qe.has(d.sessionId)){gt($);return}const V=new Set($),W=new Map(E.filter(K=>V.has(K.sessionId)).map(K=>[K.sessionId,K.unread]));B(K=>K.map(ie=>V.has(ie.sessionId)?{...ie,unread:!0}:ie));try{$.length===1?await F.markChatUnread(n,$[0],!0):await F.markChatsUnread(n,$,!0)}catch(K){B(ie=>ie.map(rt=>V.has(rt.sessionId)?{...rt,unread:W.get(rt.sessionId)}:rt)),h(K instanceof Error?K.message:"Failed to mark chat unread")}},[Qe,gt,n,E]),ht=a.useCallback(d=>re.runningOnly||!re.nested?jo(d):bo(d),[re.runningOnly,re.nested]),Ss=a.useMemo(()=>ht(re.runningOnly?qe:qe.filter(d=>!d.archived)),[qe,ht,re.runningOnly]),Is=a.useMemo(()=>re.runningOnly?[]:ht(qe.filter(d=>d.archived)),[qe,ht,re.runningOnly]),$s=E.filter(d=>!d.archived).length,ls=a.useMemo(()=>E.filter(d=>J.has(d.sessionId)).length,[E,J]),is=E.some(d=>d.archived&&d.sessionId===Z),Xe=a.useRef(null);a.useEffect(()=>{var $;const d=E.find(V=>V.sessionId===Z);d?Xe.current=d:(($=Xe.current)==null?void 0:$.sessionId)!==Z&&(Xe.current=null)},[E,Z]);const Es=!!Z&&m==="chat"&&P!==Z&&!E.some(d=>d.sessionId===Z)?((Ne=Xe.current)==null?void 0:Ne.sessionId)===Z?Xe.current:{sessionId:Z,workingDirectory:"",name:"Current chat",updatedAt:"",resumable:!0}:null;if(a.useEffect(()=>{is&&tt.current!==Z&&(tt.current=Z,I(!0))},[is,Z]),se)return e.jsx("div",{className:"p-8",children:e.jsx("div",{className:"rounded-lg border border-danger-edge bg-danger-soft px-4 py-3 text-sm text-danger",children:se})});if(!v)return e.jsx("div",{className:"p-8 text-sm text-fg-muted",children:"Loading project…"});const b=v.pinned,D=m==="files"&&y&&b.includes(y)?y:null,le=m==="files"&&!D;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("header",{className:"pt-safe border-b border-edge px-3 pb-2.5 sm:px-6 lg:py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 lg:flex-wrap lg:gap-3",children:[e.jsx("button",{type:"button",onClick:c,className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden","aria-label":"Open menu",children:e.jsx(Xa,{width:20,height:20})}),e.jsxs("button",{type:"button",onClick:()=>ye(!0),className:"btn-subtle shrink-0 gap-1.5 px-2 py-1.5 lg:-ml-2 lg:hidden","aria-label":"Show chats",children:[e.jsx(Ht,{width:16,height:16}),e.jsx("span",{className:"hidden sm:inline",children:"Chats"}),E.length>0&&e.jsx("span",{className:"text-2xs text-fg-subtle",children:E.length})]}),e.jsx("h1",{className:"min-w-0 text-lg font-semibold tracking-tight lg:text-xl",children:e.jsx("button",{type:"button",onClick:Kt,title:"Project home",className:"block max-w-full truncate rounded transition-colors hover:text-accent",children:v.name})}),e.jsx(nr,{status:v.status}),v.domain.map(d=>e.jsx(Za,{tag:d,className:"hidden lg:inline-flex"},d)),v.hasOverview&&e.jsxs("span",{title:"A sweep has curated an OVERVIEW.md for this project. New chats can preload it as context.",className:"hidden items-center gap-1 rounded-md bg-success-soft px-1.5 py-0.5 text-2xs font-medium text-success lg:inline-flex",children:[e.jsx(pt,{width:11,height:11}),"Overview"]}),!v.managed&&v.repo&&e.jsxs("a",{href:er(v.repo),target:"_blank",rel:"noreferrer",title:v.path?`Claude works in ${v.path}, a checkout of ${v.repo}`:`Claude works in a clone of ${v.repo}`,className:"hidden items-center gap-1 rounded-md bg-info-soft px-1.5 py-0.5 text-2xs font-medium text-info lg:inline-flex",children:[e.jsx(Ze,{width:11,height:11}),"Repo"]}),!v.managed&&!v.repo&&v.path&&e.jsxs("span",{title:`Claude works in ${v.path}. Paddock writes no project files there.`,className:"hidden items-center gap-1 rounded-md bg-info-soft px-1.5 py-0.5 text-2xs font-medium text-info lg:inline-flex",children:[e.jsx(Ze,{width:11,height:11}),"Linked"]}),e.jsxs("span",{className:"ml-auto hidden items-center gap-1 text-xs text-fg-subtle lg:inline-flex",children:[e.jsx(et,{width:12,height:12}),"updated ",It(v.updated)]}),e.jsx("button",{type:"button",onClick:Dt,"aria-label":"New chat",title:"New chat",className:"btn-subtle ml-auto shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(lt,{width:16,height:16})}),e.jsx(ar,{onEdit:vt,onDelete:t?void 0:()=>He(!0),size:18})]}),v.summary&&e.jsx("p",{className:"mt-1.5 hidden text-sm text-fg-muted lg:block",children:v.summary})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx(Uo,{chatList:Ce,sessionsOpen:Pe,setSessionsOpen:ye,chatSearch:k,setChatSearch:z,searching:vs,newChat:Dt,view:m,activeSession:Z,pendingChat:P,chats:E,fallbackChat:Es,visibleChats:qe,activeChats:Ss,archivedChats:Is,activeTotal:$s,runningCount:ls,viewPrefs:re,archivedOpen:Ee,setArchivedOpen:I,collapsedChats:te,toggleChatCollapsed:xe,openChat:Pt,unread:Qe,usageBySession:w,runningSessions:J,setForkingChat:it,setPromotingChat:t?Ae:void 0,renameChat:ke,archiveChat:ss,requestDeleteChat:ts,starChat:as,toggleUnread:rs,detachChat:ns,adoptableCount:A,adopting:p,adoptChats:()=>be(!0)}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:`border-b border-edge ${m==="chat"?"hidden lg:block":"block"}`,children:e.jsxs("div",{className:"-mb-px flex items-center gap-1 overflow-x-auto px-4",children:[e.jsx(ft,{active:m==="home",onClick:Kt,children:"Home"}),e.jsx(ft,{active:m==="chat",onClick:at,children:"Chat"}),e.jsx(ft,{active:le,onClick:dt,children:"Files"}),de&&e.jsx(ft,{active:m==="changes",onClick:Mt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Changes",de.files.length>0&&e.jsx("span",{title:`${de.files.length} uncommitted change${de.files.length===1?"":"s"}`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-warn-soft px-1 text-3xs font-semibold text-warn",children:de.files.length})]})}),e.jsx(ft,{active:m==="history",onClick:Qt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["History",Te>0&&e.jsx("span",{title:`${Te} new unattended run${Te===1?"":"s"} since your last visit`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-accent-soft px-1 text-3xs font-semibold text-accent",children:Te})]})}),e.jsx(ft,{active:m==="settings",onClick:vt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(zn,{width:13,height:13}),"Settings"]})}),e.jsx(ft,{active:m==="triggers",onClick:_t,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(zt,{width:13,height:13}),"Triggers"]})}),b.map(d=>e.jsx(To,{file:d,active:D===d,onSelect:()=>mt(d),onUnpin:()=>void Zt(d)},d))]})}),m==="changes"&&de&&e.jsx(wi,{slug:v.slug,status:de,onStatusChange:d=>$e(d.repo?d:null),selectedFile:C??null,onSelectFile:ut}),m==="history"&&e.jsx(_i,{slug:v.slug,state:_e,chats:E,onOpenChat:Pt}),m==="settings"&&e.jsx(Wi,{project:v,onSaved:d=>{L(d),x(d)}}),m==="triggers"&&e.jsx(no,{project:v}),m==="home"&&e.jsx(Mo,{project:v,running:ot.running,unread:ot.unread,attentionLoading:ot.loading,attentionError:ot.error,changelog:_,overview:H,files:ne,onOpenChat:qt,onNewChat:Dt,onOpenFile:mt,onOpenFiles:dt}),m==="chat"&&e.jsx(ji,{projectSlug:v.slug,initialSessionId:Z??void 0,loadHistory:ws,onSessionEstablished:Xt,onSessionStarted:ys,onTurnComplete:ks,preloadAvailable:v.hasOverview,projectModel:v.model,projectModels:v.models,projectRecovery:v.recovery,projectAttachments:v.attachments,forkParent:Je??void 0,onOpenForkParent:Pt,onForkFromMessage:Yt,onRevertToMessage:Ye,autoFocus:Jt,trigger:(os=E.find(d=>d.sessionId===Z)??(((Re=Xe.current)==null?void 0:Re.sessionId)===Z?Xe.current:null))==null?void 0:os.trigger},R),m==="files"&&e.jsx(Ui,{project:v,path:y,onNavigate:mt,onTogglePin:Cs},y)]})]}),e.jsx(us,{open:ze,title:"Delete project?",message:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:v.name})," and all its chats and files will be permanently removed. This cannot be undone."]}),confirmLabel:"Delete project",onConfirm:async()=>{await F.deleteProject(v.slug),N(v.slug),hr(v.slug),i(tr())},onClose:()=>He(!1)}),e.jsx(us,{open:he!==null,title:he&&he.ids.length>1?`Delete ${he.ids.length} chats?`:"Delete chat?",message:he&&e.jsxs(e.Fragment,{children:[he.ids.length>1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:he.chat.name})," ","and its ",he.ids.length-1," nested chat",he.ids.length-1===1?"":"s"," will be permanently removed — their transcripts too."]}):"This chat's transcript will be permanently removed.",he.orphanCount>0&&e.jsxs(e.Fragment,{children:[" ","Its ",he.orphanCount," other nested chat",he.orphanCount===1?"":"s"," will be kept and moved to the top level."]})," ","This cannot be undone."]}),confirmLabel:he&&he.ids.length>1?`Delete ${he.ids.length} chats`:"Delete chat",onConfirm:es,onClose:()=>We(null)}),Ke&&e.jsx(mo,{open:!0,slug:n,sessionId:Ke.sessionId,defaultName:Ke.name,onClose:()=>Ae(null),onPromoted:d=>{Ae(null),x(d),i(`/projects/${d.slug}/chat`)}}),Q&&e.jsx(uo,{open:!0,chatName:Q.name,resetName:Q.preview,onClose:()=>ke(null),onRename:d=>{const $=Q;ke(null),wt($,d)}}),Le&&e.jsx(co,{open:!0,chatName:Le.name,onClose:()=>it(null),onFork:d=>{const $=Le;it(null),Ns($,d)}}),e.jsx(ho,{open:ge,adoptable:pe,busy:p,onClose:()=>be(!1),onAdopt:d=>void Tt(d)}),e.jsx(Go,{message:(me==null?void 0:me.message)??null,tone:me==null?void 0:me.tone,onDismiss:Me,action:me==null?void 0:me.action,durationMs:me!=null&&me.action?12e3:void 0})]})}const Zo=Object.freeze(Object.defineProperty({__proto__:null,ProjectView:Ko,adoptSummary:ga},Symbol.toStringTag,{value:"Module"}));export{Dl as M,Ko as P,Zo as a};
13
-