@edspencer/paddock 0.59.1 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/packages/server/dist/adoptable.d.ts +72 -3
- package/packages/server/dist/adoptable.js +231 -25
- package/packages/server/dist/herdctl.d.ts +80 -0
- package/packages/server/dist/herdctl.js +159 -0
- package/packages/server/dist/routes/chats.js +59 -3
- package/packages/server/dist/run-provenance.d.ts +11 -0
- package/packages/server/dist/run-provenance.js +18 -0
- package/packages/server/dist/ws-turn.d.ts +0 -13
- package/packages/server/dist/ws-turn.js +50 -0
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/{InstanceConfigPage-CAwSnyga.js → InstanceConfigPage-xn9Rvoah.js} +1 -1
- package/packages/web/dist/assets/{MarkdownRenderer-DpGpkMzG.js → MarkdownRenderer-DMONssKA.js} +1 -1
- package/packages/web/dist/assets/{ProjectRedirect-D1ipv4jr.js → ProjectRedirect-DHoWtvtY.js} +1 -1
- package/packages/web/dist/assets/ProjectView-BmSdUwY2.js +13 -0
- package/packages/web/dist/assets/{ProjectsGrid-Dwngb-m1.js → ProjectsGrid-CjfwpeFj.js} +1 -1
- package/packages/web/dist/assets/{arc-BZh6Z9_D.js → arc-DdFdbD-c.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-iCtJiW4k.js → architectureDiagram-3BPJPVTR-DC8UKtwV.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-BeI9Wi0h.js → blockDiagram-GPEHLZMM-DqFFe_5c.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-D_j2LKZ-.js → c4Diagram-AAUBKEIU-DbffFSM-.js} +1 -1
- package/packages/web/dist/assets/channel-QxsJGL6F.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-DRlfPROq.js → chunk-2J33WTMH-8PP2RHft.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-BMY66MLs.js → chunk-4BX2VUAB-Hag68B5N.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-BAQ92trf.js → chunk-55IACEB6-BXp_gQIa.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-Dxgb_nNN.js → chunk-727SXJPM-DlntjQux.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-D5cqv3Jv.js → chunk-AQP2D5EJ-BhI9KPrE.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-BOEqxzyA.js → chunk-FMBD7UC4-WhfORs2z.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-CkTZgv_W.js → chunk-ND2GUHAM-CIskmv20.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-DIr8TL7M.js → chunk-QZHKN3VN-CNOTpCW4.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-CI7p84hR.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-CI7p84hR.js +2 -0
- package/packages/web/dist/assets/{core-DyOZ2e1O.js → core-usOVRkLM.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-D8Muyf4o.js → cose-bilkent-S5V4N54A-CniuMIIW.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG-B_EUbUz6.js → dagre-BM42HDAG-5CteYfQY.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-DpAM0K6Q.js → diagram-2AECGRRQ-BIQjD2LA.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-Dhs9RMKk.js → diagram-5GNKFQAL-1vy3ErTt.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-LBeTHReu.js → diagram-KO2AKTUF-D45iqFk6.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-CxboRwue.js → diagram-LMA3HP47-DNktDktn.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-BK_P-OSi.js → diagram-OG6HWLK6-BQ9JgV70.js} +1 -1
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-CPSKRHI5.js → erDiagram-TEJ5UH35-oBasZ1uv.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-CbUumAP5.js → flowDiagram-I6XJVG4X-DxnJHMBS.js} +1 -1
- package/packages/web/dist/assets/{format-DDL0Q7H2.js → format-CIAat6sU.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-l-p25ckA.js → ganttDiagram-6RSMTGT7-CtJQ2m7z.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-i8kDIgga.js → gitGraphDiagram-PVQCEYII-5RPscwD_.js} +1 -1
- package/packages/web/dist/assets/index-B6etJCHf.css +1 -0
- package/packages/web/dist/assets/{index-DKDgTDXa.js → index-DtRblEY_.js} +4 -4
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-CbyLnHIe.js → infoDiagram-5YYISTIA-zQu3xkW4.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-C1_3z8-9.js → ishikawaDiagram-YF4QCWOH-ChoEjcdw.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-BzyAtQdy.js → journeyDiagram-JHISSGLW-DM2KWmDr.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-Fp2VVm-b.js → kanban-definition-UN3LZRKU-DWzTpYgh.js} +1 -1
- package/packages/web/dist/assets/{linear-6ZKEeWQ5.js → linear-Bpy9Aj-K.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-Dorg4Dl2.js → mermaid.core-D43x5bFb.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-Bk4Ax0bI.js → mindmap-definition-RKZ34NQL-BhceB-cv.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-DoTn5jHm.js → pieDiagram-4H26LBE5-BgcGlFFA.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-ClNmIKCj.js → quadrantDiagram-W4KKPZXB-ZRVaOoSp.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-DMF7i5KW.js → requirementDiagram-4Y6WPE33-2hHcJHBt.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-C-ALbVLg.js → sankeyDiagram-5OEKKPKP-KPUQ9Mu5.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-DsUxj8IQ.js → sequenceDiagram-3UESZ5HK-D4BXQSSM.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-OCZiRRsz.js → stateDiagram-AJRCARHV-DftS7dIo.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-CgBC1jpO.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-5ifjxa-s.js → timeline-definition-PNZ67QCA-C0OAxyWY.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-Bqvqpot5.js → vennDiagram-CIIHVFJN-C94fINN3.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-DwgnVd48.js → wardley-L42UT6IY-CbFrlwHE.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-F-VCH-oE.js → wardleyDiagram-YWT4CUSO-CHG2nndd.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-L4q6oV_7.js → xychartDiagram-2RQKCTM6-U9ESc19z.js} +1 -1
- package/packages/web/dist/index.html +2 -2
- package/packages/web/dist/sw.js +1 -1
- package/packages/web/dist/assets/ProjectView-BI1TtrOK.js +0 -13
- package/packages/web/dist/assets/channel-DszBVZgr.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DuGqlnbT.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DuGqlnbT.js +0 -2
- package/packages/web/dist/assets/index-CvGiQddO.css +0 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-BwcJspgG.js +0 -2
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-DpGpkMzG.js","assets/index-DKDgTDXa.js","assets/index-CvGiQddO.css","assets/format-DDL0Q7H2.js","assets/queued-LamEU0GH.js","assets/lastTab-CU1zsF0j.js","assets/core-DyOZ2e1O.js","assets/mermaid.core-Dorg4Dl2.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as n,b as L,l as be,j as e,w as Qs,A as ce,x as ws,F as $t,X as Be,c as Qe,y as Mt,L as Ds,z as ya,C as Qt,D as Ca,B as Je,P as at,E as Ns,S as Ps,s as Jt,_ as le,G as Sa,f as Xt,H as Ia,k as nt,W as Ta,I as Ae,J as rn,U as on,K as ps,O as Ls,Q as Rt,R as ys,t as Fs,V as ln,Y as cn,Z as dn,$ as un,a0 as Js,a1 as mn,a2 as pn,a3 as hn,a4 as xn,a5 as Xs,a6 as Zs,a7 as fn,a8 as kn,h as gn,a9 as bn,aa as jn,a as vn,m as wn,u as Nn,ab as yn,ac as Cn,ad as Sn,ae as In,af as ea,M as Tn,T as En,ag as Rn,g as $n,ah as Mn}from"./index-DKDgTDXa.js";import{i as _n,s as Dn,a as Pn,l as Ln,b as Fn,c as An,t as On,d as Un,f as Ea,e as Ra,g as $a,r as vt,h as Bn,j as Kt,C as qt,u as Vn,k as As,m as zn,S as Hn,P as Wn}from"./format-DDL0Q7H2.js";import{readQueued as Gn,readQueuedTs as Kn,writeQueued as qn,writeQueuedTs as Yn}from"./queued-LamEU0GH.js";import{t as tt,w as Qn,c as Jn}from"./lastTab-CU1zsF0j.js";const Xn=500,Zn=9e4,hs="paddock:cancel",ta="paddock:timeout";function er(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function tr(){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 a of t)if(typeof s.isTypeSupported!="function"||s.isTypeSupported(a.mimeType))return a;return{mimeType:"",ext:"webm"}}function sr({onText:t,timeoutMs:s=Zn}){const[a,r]=n.useState("idle"),[o,l]=n.useState(null),[i,c]=n.useState(null),[m]=n.useState(er),h=n.useRef(null),v=n.useRef(null),u=n.useRef([]),b=n.useRef("webm"),C=n.useRef(null),S=n.useRef(null),f=n.useRef(!0);n.useEffect(()=>{f.current=!0;let w=!1;return L.transcriptionStatus().then(O=>{w||l(O.available)}).catch(()=>{w||l(!1)}),()=>{var O;w=!0,f.current=!1,(O=S.current)==null||O.abort(hs),x()}},[]);const x=()=>{var w;(w=v.current)==null||w.getTracks().forEach(O=>O.stop()),v.current=null,h.current=null},T=n.useCallback(async()=>{if(!m||a==="recording"||a==="transcribing")return;c(null),C.current=null;let w;try{w=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(U){r("error"),c(or(U));return}v.current=w;const{mimeType:O,ext:y}=tr();b.current=y;const B=O?new MediaRecorder(w,{mimeType:O}):new MediaRecorder(w);u.current=[],B.ondataavailable=U=>{U.data&&U.data.size>0&&u.current.push(U.data)},B.onstop=()=>{x();const U=B.mimeType||O||"audio/webm",I=new Blob(u.current,{type:U});u.current=[],C.current=I,E(I)},h.current=B,B.start(),r("recording")},[m,a]),E=n.useCallback(async(w,O=!1)=>{if(w.size===0){C.current=null,f.current&&r("idle");return}f.current&&r("transcribing");const y=new AbortController;S.current=y;const B=setTimeout(()=>y.abort(ta),s);try{const U=await L.transcribe(w,`dictation.${b.current}`,y.signal);U.trim()&&t(U.trim()),C.current=null,f.current&&(c(null),r("idle"))}catch(U){if(y.signal.aborted&&y.signal.reason===hs){C.current=null,f.current&&(c(null),r("idle"));return}if(y.signal.aborted&&y.signal.reason===ta){f.current&&(r("error"),c("Transcription timed out — try again."));return}if(ar(U)&&!O)return await rr(Xn),E(w,!0);f.current&&(r("error"),c(nr(U)))}finally{clearTimeout(B),S.current===y&&(S.current=null)}},[t,s]),R=n.useCallback(()=>{var w;(w=S.current)==null||w.abort(hs)},[]),k=n.useCallback(()=>{const w=h.current;w&&w.state!=="inactive"&&w.stop()},[]),F=n.useCallback(()=>{a==="recording"?k():T()},[a,T,k]),$=n.useCallback(()=>{if(a==="recording"||a==="transcribing")return;const w=C.current;w?E(w):T()},[a,E,T]),P=n.useCallback(()=>{C.current=null,c(null),r("idle")},[]);return{state:a,available:o,supported:m,error:i,start:T,stop:k,toggle:F,retry:$,dismiss:P,cancel:R}}function ar(t){return t instanceof be?t.status>=500:!0}function nr(t){return t instanceof be?t.status>=500?t.message||"Transcription service error — try again.":t.status===400?t.message||"Didn't catch any audio — try again.":t.message||"Transcription failed.":"Couldn't reach the transcription service — check your connection and retry."}function rr(t){return new Promise(s=>setTimeout(s,t))}function or(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 lr({onText:t}){const{state:s,available:a,supported:r,error:o,toggle:l,retry:i,dismiss:c,cancel:m}=sr({onText:t});if(a!==!0)return null;const h=s==="recording",v=s==="transcribing",u=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-paddock-300 dark:text-paddock-700",children:e.jsx(Qs,{width:18,height:18})});const b=h?"Stop recording":v?"Transcribing… — click to cancel":u?"Transcription failed — click to record again":"Record a voice message",C=()=>{v?m():l()};return e.jsxs("div",{className:"relative flex items-center",children:[u&&o&&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-rose-300/70 bg-rose-50 px-2.5 py-1.5 text-xs text-rose-700 shadow-md dark:border-rose-900/70 dark:bg-rose-950 dark:text-rose-300",children:[e.jsx(ce,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:o}),e.jsx("button",{type:"button",onClick:i,className:"shrink-0 font-medium text-rose-700 underline underline-offset-2 hover:text-rose-900 dark:text-rose-200 dark:hover:text-rose-100",children:"Retry"}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Dismiss error",className:"shrink-0 text-rose-400 hover:text-rose-600 dark:hover:text-rose-200",children:"✕"})]}),e.jsxs("button",{type:"button",onClick:C,"aria-label":h?"Stop recording":v?"Cancel transcription":"Record a voice message","aria-pressed":h,title:b,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",h?"bg-rose-100 text-rose-600 dark:bg-rose-950/60 dark:text-rose-400":v?"cursor-pointer text-accent can-hover:hover:bg-rose-100 can-hover:hover:text-rose-600 dark:can-hover:hover:bg-rose-950/60 dark:can-hover:hover:text-rose-400":u?"bg-rose-100 text-rose-600 dark:bg-rose-950/60 dark:text-rose-400":"text-paddock-500 can-hover:hover:bg-paddock-100 can-hover:hover:text-paddock-700 dark:text-paddock-400 dark:can-hover:hover:bg-paddock-800 dark:can-hover:hover:text-paddock-200"].filter(Boolean).join(" "),children:[v?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(ir,{})}),e.jsx(ws,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):h?e.jsx(ws,{width:16,height:16}):e.jsx(Qs,{width:18,height:18}),h&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function ir(){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 Ma(t,s){return cr+(t??`new:${s}`)}function dr(t,s){try{const a=localStorage.getItem(Ma(t,s));return a&&a.length>0?a:null}catch{return null}}function Cs(t,s,a){try{localStorage.setItem(Ma(t,s),a)}catch{}}const ur="paddock:draft:";function _a(t,s){return ur+(t??`new:${s}`)}function mr(t,s){try{return localStorage.getItem(_a(t,s))??""}catch{return""}}function pr(t,s,a){try{const r=_a(t,s);a.length>0?localStorage.setItem(r,a):localStorage.removeItem(r)}catch{}}const sa="<paddock-attachments>",Ss="</paddock-attachments>",aa=`${Ss}
|
|
3
|
-
|
|
4
|
-
`;function Da(t){return`/api/chat-files/${encodeURIComponent(t)}`}function hr(t){const s=t.indexOf(sa);if(s===-1)return{attachments:[],text:t};const a=s+sa.length,r=t.indexOf(Ss,a);if(r===-1)return{attachments:[],text:t};const o=t.slice(a,r),l=[];for(const m of o.split(`
|
|
5
|
-
`)){const h=m.split(" ");if(h.length<3)continue;const[v,u,b]=h;!(v!=null&&v.trim())||!(b!=null&&b.trim())||l.push({id:v.trim(),kind:(u==null?void 0:u.trim())||"file",filename:b.trim()})}const i=t.slice(0,s),c=t.startsWith(aa,r)?t.slice(r+aa.length):t.slice(r+Ss.length).replace(/^\n+/,"");return{attachments:l,text:i+c}}function xr(t){const s=t.slice(t.lastIndexOf("/")+1),a=s.lastIndexOf(".");return a>0?s.slice(a).toLowerCase():""}function Pa(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 a=s/1024;return`${a<10?a.toFixed(1):Math.round(a)} MB`}function fr(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function kr(t,s,a){const r=(s??"").trim().toLowerCase(),o=xr(a??"");for(const l of t){const i=l.trim().toLowerCase();if(i){if(i==="*"||i==="*/*")return!0;if(i.includes("/")){if(!r)continue;const[c,m]=i.split("/",2),[h,v]=r.split("/",2);if((c==="*"||c===h)&&(m==="*"||m===v))return!0}else if(i.startsWith(".")){if(o&&o===i)return!0}else if(o&&o===`.${i}`)return!0}}return!1}function gr({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(br,{attachment:s},s.id))})}function br({attachment:t}){const s=Da(t.id);if(t.kind==="image")return e.jsx(vr,{src:s,filename:t.filename});const a=Pa(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-white px-3 py-2 text-left text-xs shadow-sm ring-1 ring-paddock-200/70 hover:ring-accent dark:bg-paddock-900 dark:ring-paddock-800",children:[e.jsx($t,{width:16,height:16,className:"shrink-0 text-paddock-400"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate font-medium text-ink dark:text-ink-dark",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-[10px] text-paddock-400",children:[t.kind,a?` · ${a}`:""]})]})]})}function jr({attachment:t,onRemove:s}){const a=Da(t.id),[r,o]=n.useState(!1),l=t.kind==="image"&&!r,i=Pa(t.size);return e.jsxs("span",{"data-testid":"attachment-tray-item",className:"group relative flex items-center gap-2 rounded-xl bg-white py-2 pl-2 pr-7 text-xs shadow-sm ring-1 ring-paddock-200/70 dark:bg-paddock-900 dark:ring-paddock-800",children:[l?e.jsx("img",{src:a,alt:t.filename,onError:()=>o(!0),className:"h-9 w-9 shrink-0 rounded-md object-cover"}):e.jsx($t,{width:16,height:16,className:"shrink-0 text-paddock-400"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"max-w-[10rem] truncate font-medium text-ink dark:text-ink-dark",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-[10px] text-paddock-400",children:[t.kind,i?` · ${i}`:""]})]}),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-paddock-400 hover:bg-paddock-100 hover:text-paddock-700 dark:hover:bg-paddock-800",children:e.jsx(Be,{width:12,height:12})})]})}function vr({src:t,filename:s}){const[a,r]=n.useState(!1),[o,l]=n.useState(!1);return o?e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-white px-3 py-2 text-xs text-rose-700 shadow-sm ring-1 ring-paddock-200/70 dark:bg-paddock-900 dark:text-rose-300 dark:ring-paddock-800",children:[e.jsx(ce,{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-paddock-200/70 hover:ring-accent dark:ring-paddock-800",children:e.jsx("img",{src:t,alt:s,onError:()=>l(!0),className:"h-24 w-24 object-cover"})}),a?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 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 wr(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 Nr({trigger:t,projectSlug:s}){const a=t.allowedTools??[],r=a.length===0,o=r?t.type==="schedule"?"runs as Claude (full tools)":"no tools — reasoning only":`${a.length} tool${a.length===1?"":"s"} granted`,l=t.type==="schedule"?Qe:Mt;return e.jsx("div",{"data-testid":"trigger-capability-banner",className:"sticky top-0 z-10 mb-4 rounded-xl border border-sky-300/70 bg-sky-50/95 px-3 py-2.5 text-sky-900 shadow-sm backdrop-blur dark:border-sky-500/40 dark:bg-sky-950/85 dark:text-sky-100",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-sky-500/15 text-sky-600 dark:text-sky-300",children:e.jsx(l,{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-sky-500/15 px-1.5 py-px text-[11px] font-medium uppercase tracking-wide text-sky-700 dark:text-sky-300",children:t.type}),e.jsx("span",{className:"font-mono text-[13px] text-sky-700 dark:text-sky-300",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-sky-500/15 px-1.5 py-px text-[11px] font-medium uppercase tracking-wide text-sky-700 dark:text-sky-300",children:"disabled"})]}),e.jsxs("p",{className:"mt-0.5 text-xs text-sky-800/90 dark:text-sky-200/80",children:["Fired by ",e.jsx("span",{className:"font-medium",children:wr(t)})," · ",o,". 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-sky-700 hover:underline dark:text-sky-300",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-sky-300/60 pl-3 dark:border-sky-500/30",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 font-medium",children:"Allowed tools"}),r?e.jsx("p",{className:"text-sky-800/80 dark:text-sky-200/70",children:t.type==="schedule"?"None declared — this schedule runs as Claude with its full toolset.":"None — this trigger can only read its prompt and respond (no file, shell, or MCP access)."}):e.jsx("ul",{className:"flex flex-wrap gap-1","data-testid":"trigger-allowed-tools",children:a.map(i=>e.jsx("li",{className:"rounded bg-sky-500/10 px-1.5 py-px font-mono text-[11px] text-sky-800 dark:bg-sky-400/10 dark:text-sky-200",children:i},i))})]}),e.jsxs("dl",{className:"grid grid-cols-[auto,1fr] gap-x-3 gap-y-0.5 text-sky-800/90 dark:text-sky-200/80",children:[t.permissionMode&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Permission mode"}),e.jsx("dd",{className:"font-mono text-[11px]",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-[11px]",children:t.model})]}),e.jsx("dt",{className:"font-medium",children:"Max turns"}),e.jsx("dd",{className:"font-mono text-[11px]",children:t.maxTurns}),e.jsx("dt",{className:"font-medium",children:"Agent"}),e.jsx("dd",{className:"truncate font-mono text-[11px]",children:t.agentName})]}),e.jsx(Ds,{to:`/projects/${encodeURIComponent(s)}/triggers`,className:"inline-flex items-center gap-1 font-medium text-sky-700 hover:underline dark:text-sky-300",title:"Manage this project's triggers",children:"Edit trigger →"})]})]})]})]})})}const yr=new Set(["paddock","paddock_manage"]);function Cr(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function Sr(t){if(!t.startsWith("mcp__"))return{isMcp:!1,server:"",isPaddock:!1,display:t,tool:t};const s=t.slice(5),a=s.indexOf("__"),r=a===-1?s:s.slice(0,a),o=a===-1?"":s.slice(a+2);return{isMcp:!0,server:r,isPaddock:yr.has(r),display:Cr(o||r),tool:o}}const na="mcp__paddock_manage__",Tt=(t,s)=>typeof t=="number"&&Number.isFinite(t)?t:s,ft=t=>{if(typeof t!="string")return;const s=t.trim();return s.length>0?s:void 0};function La(t,s=80){var r;const a=((r=t.split(`
|
|
6
|
-
`).find(o=>o.trim().length>0))==null?void 0:r.trim())??t.trim();return a.length>s?`${a.slice(0,s).trimEnd()}…`:a}function Fa(t,s){return t||(s?La(s):"untitled chat")}function Ir(t,s){if(!t.startsWith(na)||!s)return null;const a=t.slice(na.length);let r;try{r=JSON.parse(s)}catch{return null}if(!r||typeof r!="object")return null;switch(a){case"list_projects":{if(!Array.isArray(r.projects))return null;const o=r.projects;return{tool:a,count:Tt(r.count,o.length),projects:o}}case"list_chats":{if(!Array.isArray(r.chats))return null;const o=r.chats;return{tool:a,count:Tt(r.count,o.length),project:r.project??null,chats:o}}case"read_chat":{if(!Array.isArray(r.messages))return null;const o=r.messages;return{tool:a,project:String(r.project??""),sessionId:String(r.sessionId??""),total:Tt(r.total,o.length),returned:Tt(r.returned,o.length),messages:o}}case"create_chat":return r.sessionId?{tool:a,project:String(r.project??""),sessionId:String(r.sessionId),name:ft(r.name),prompt:ft(r.prompt)}:null;case"send_message":return r.sessionId?{tool:a,project:String(r.project??""),sessionId:String(r.sessionId),prompt:ft(r.prompt)}:null;case"fork_chat":return r.sessionId?{tool:a,project:String(r.project??""),sessionId:String(r.sessionId),from:ft(r.from),name:ft(r.name),prompt:ft(r.prompt)}:null;case"fork_chat_batch":{if(!Array.isArray(r.forks))return null;const o=r.forks;return{tool:a,count:Tt(r.count,o.length),source:String(r.source??""),forks:o}}default:return null}}function Tr(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 Fa(t.name,t.prompt);case"send_message":return t.prompt?La(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const Aa=n.createContext(null),Er=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,Is=t=>t.length>8?`${t.slice(0,8)}…`:t;function Et({project:t,sessionId:s,label:a}){return e.jsxs(Ds,{to:Er(t,s),className:"inline-flex items-center gap-1 rounded-md bg-accent/10 px-2 py-0.5 font-mono text-[11px] font-medium text-accent no-underline ring-1 ring-accent/20 transition-colors hover:bg-accent/20 dark:bg-accent/15",title:`Open ${s}`,children:[e.jsx(ya,{width:10,height:10,className:"shrink-0"}),a??Is(s)]})}const kt="border-t border-paddock-200/70 px-3 py-2.5 dark:border-paddock-800",gt="text-paddock-500 dark:text-paddock-400";function ra({children:t}){return e.jsx("span",{className:"rounded bg-paddock-200/70 px-1.5 py-0.5 text-[10px] font-medium text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300",children:t})}function oa({label:t,text:s}){return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-paddock-400",children:t}),e.jsx("div",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-paddock-100/70 px-2.5 py-1.5 text-[11.5px] leading-relaxed text-paddock-700 dark:bg-paddock-900/60 dark:text-paddock-300",children:s})]})}function Rr({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-emerald-500",title:"running"}):e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-paddock-300 dark:bg-paddock-700"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-paddock-700 dark:text-paddock-200",children:t.name||"(untitled)"}),e.jsx(Et,{project:t.project,sessionId:t.sessionId})]})}function $r({data:t}){const s=n.useContext(Aa)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:kt,children:e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.projects.map(a=>e.jsxs("li",{className:"flex items-center gap-1.5 rounded-md bg-paddock-100/70 px-2 py-1 dark:bg-paddock-900/60",children:[e.jsx("span",{className:"text-[11.5px] font-medium text-paddock-700 dark:text-paddock-200",children:a.name}),a.area&&e.jsx(ra,{children:a.area}),a.status&&a.status!=="active"&&e.jsx(ra,{children:a.status})]},a.slug))})});case"list_chats":return e.jsx("div",{className:kt,children:e.jsx("ul",{className:"max-h-72 divide-y divide-paddock-200/50 overflow-auto text-[11.5px] dark:divide-paddock-800/60",children:t.chats.map(a=>e.jsx(Rr,{chat:a},a.sessionId))})});case"read_chat":return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[11px]",children:[e.jsxs("span",{className:gt,children:[t.returned," of ",t.total," messages"]}),e.jsx(Et,{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((a,r)=>e.jsxs("li",{className:"text-[11.5px] leading-relaxed",children:[e.jsx("span",{className:`mr-1.5 font-mono text-[10px] font-semibold uppercase ${a.role==="assistant"?"text-accent":"text-paddock-400"}`,children:a.role}),e.jsx("span",{className:"whitespace-pre-wrap break-words text-paddock-700 dark:text-paddock-300",children:a.text})]},r))})]});case"create_chat":case"fork_chat":{const a=t.tool==="create_chat"?"Created chat":"Forked chat",r=Fa(t.name,t.prompt);return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-[11.5px]",children:[e.jsx("span",{className:gt,children:a}),e.jsx("span",{className:"font-medium text-paddock-800 dark:text-paddock-100",children:r}),e.jsxs("span",{className:gt,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${gt}`,children:["from ",Is(t.from)]}),e.jsx(Et,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(oa,{label:"Kickoff",text:t.prompt})]})}case"send_message":return e.jsxs("div",{className:kt,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-[11.5px]",children:[e.jsx("span",{className:gt,children:"Sent to"}),e.jsx("span",{className:"font-medium text-paddock-800 dark:text-paddock-100",children:t.project}),e.jsx(Et,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(oa,{label:"Message",text:t.prompt})]});case"fork_chat_batch":return e.jsxs("div",{className:kt,children:[e.jsx("div",{className:"mb-2 flex items-center gap-2 text-[11px]",children:e.jsxs("span",{className:gt,children:[t.count," ",t.count===1?"fork":"forks"," from ",Is(t.source)]})}),e.jsx("ol",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.forks.map((a,r)=>e.jsxs("li",{className:"flex items-start gap-2 rounded-md bg-paddock-100/60 px-2 py-1.5 dark:bg-paddock-900/50",children:[e.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-[10px] font-semibold text-paddock-400",children:r+1}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-[11.5px] leading-relaxed text-paddock-700 dark:text-paddock-300",children:a.prompt}),e.jsx(Et,{project:s,sessionId:a.sessionId})]},a.sessionId))})]})}}const Zt=new Set(["Task","Agent"]);function Mr(t,s){return Zt.has(t.toolName)&&s&&t.subagentDurationMs==null}const _r="mcp__paddock__send_file",Dr=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),Pr=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function Lr(t){return t.background||t.toolName==="Monitor"||Dr.has(t.toolName)?!0:Pr.test(t.output??"")}function Fr(t){switch(t){case"completed":return"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/60 dark:text-emerald-300";case"killed":case"timed out":return"bg-amber-100 text-amber-700 dark:bg-amber-950/60 dark:text-amber-300";case"running":case"persistent":return"bg-sky-100 text-sky-700 dark:bg-sky-950/60 dark:text-sky-300";default:return"bg-paddock-200/70 text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300"}}function Ar(t){switch(t){case"list_projects":return Ns;case"create_chat":return at;case"fork_chat":case"fork_chat_batch":return Je;case"send_message":return Ca;default:return Qt}}function Oa(t){if(t.toolName!==_r||!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?L.chatFileRawUrl(s.attachmentId):void 0}}function Or(t){return t==="+"?"bg-emerald-50 text-emerald-800 dark:bg-emerald-950/30 dark:text-emerald-300":t==="-"?"bg-rose-50 text-rose-800 dark:bg-rose-950/30 dark:text-rose-300":"text-paddock-600 dark:text-paddock-400"}function la(t){return t===void 0?"":String(t)}function Ur(t){switch(t){case"completed":case"done":return"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/60 dark:text-emerald-300";case"in_progress":return"bg-sky-100 text-sky-700 dark:bg-sky-950/60 dark:text-sky-300";case"blocked":case"failed":case"cancelled":return"bg-rose-100 text-rose-700 dark:bg-rose-950/60 dark:text-rose-300";default:return"bg-paddock-200/70 text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300"}}function Br(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 a=t.totalMatches??t.numFiles;a!==void 0&&s.push(`${a} match${a===1?"":"es"}`)}return s.length?(t.truncated?"≥":"")+s.join(" · "):null}function Vr(t){if(t.startLine===void 0||t.numLines===void 0)return null;const s=t.startLine+Math.max(0,t.numLines-1),a=t.totalLines!==void 0?` of ${t.totalLines}`:"";return`lines ${t.startLine}–${s}${a}`}let zr=0;const Ue=()=>`t${++zr}`;function Hr(t,s){t(a=>{const r=a[a.length-1];return r&&r.kind==="assistant"&&r.streaming?[...a.slice(0,-1),{...r,content:r.content+s}]:[...a,{kind:"assistant",id:Ue(),content:s,streaming:!0}]})}function Fe(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function ia(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 Wr(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const l=Oa(t.toolCall);return l?{kind:"file",id:s,file:l}:{kind:"tool",id:s,tool:t.toolCall}}if(t.role==="assistant")return{kind:"assistant",id:s,content:t.content,streaming:!1};if(_n(t.content))return{kind:"compact",id:s,summary:t.content};const a=Dn(t.content);if(a)return{kind:"command",id:s,command:a};if(Pn(t.content))return{kind:"commandOutput",id:s,content:Ln(t.content)??""};if(Fn(t.content))return{kind:"commandOutput",id:s,content:""};if(An(t.content))return{kind:"notification",id:s,summary:Un(t.content),status:On(t.content)};const{attachments:r,text:o}=hr(t.content);return{kind:"user",id:s,content:o,...t.sender?{sender:t.sender}:{},...r.length>0?{attachments:r}:{}}}function Yt(t){const s=new Map;return t.filter(a=>!a.bgConsumed).map(a=>{let r;if(a.uuid){const l=s.get(a.uuid)??0;s.set(a.uuid,l+1),r=l===0?a.uuid:`${a.uuid}#${l}`}else r=Ue();const o=Wr(a,r);return o.timestamp=a.timestamp,a.contextTokens!=null&&(o.contextTokens=a.contextTokens),o})}const Ua=n.createContext(null),Ba=n.createContext(!1),Os=n.createContext(null),Va=n.createContext(null),za=n.createContext(null),Us=n.createContext(null),Ha=n.createContext(null);function Gr({running:t,activity:s,onReveal:a}){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/30 bg-accent/[0.06] dark:bg-accent/10",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-[10px] 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 o=s.get(r.toolUseId);return e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>a(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(Ps,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-[11px] font-semibold text-paddock-700 dark:text-paddock-200",children:r.label}),r.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-[11px] text-paddock-500 dark:text-paddock-400",children:r.description}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-accent/90",title:o==null?void 0:o.latestStep,children:(o==null?void 0:o.latestStep)??"starting…"}),o!=null&&o.stepCount>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-[10px] tabular-nums text-paddock-400",children:[o.stepCount," step",o.stepCount===1?"":"s"]})]})},r.toolUseId)})})]})})}const Kr=2e3,qr=6;function Yr(t){const s=t.toolCall;if(!s)return null;const a=Zt.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,r=(s.description??s.inputSummary??"").trim();return r?`${a} ${r}`:a}function Qr(t){var r,o;if(t.length===0)return;const s=Date.parse(((r=t[0])==null?void 0:r.timestamp)??""),a=Date.parse(((o=t[t.length-1])==null?void 0:o.timestamp)??"");if(!(!Number.isFinite(s)||!Number.isFinite(a)||a<s))return a-s}function Jr(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function Xr(t,s,a){const[r,o]=n.useState(new Map),l=n.useRef(new Set),i=n.useRef(new Set),c=n.useRef(new Map),m=n.useRef(s);m.current=s;const h=n.useRef(a);h.current=a;const v=t.map(u=>u.toolUseId).sort().join(",");if(a)for(const u of t)i.current.add(u.toolUseId);return n.useEffect(()=>{const u=(v?v.split(","):[]).filter(f=>i.current.has(f));if(u.length===0||!m.current)return;let b=!1,C;const S=async()=>{const f=m.current;if(!f)return;const x=u.filter(E=>!l.current.has(E));if(x.length===0)return;const T=await Promise.all(x.map(E=>f(E).then(R=>({id:E,messages:R})).catch(()=>null)));b||(o(E=>{const R=new Map(E);for(const k of T){if(!k)continue;const F=Jr(k.messages),$=c.current.get(k.id),P=$&&$.sig===F?$.ticks+1:0;c.current.set(k.id,{sig:F,ticks:P});const w=!h.current&&P>=qr;w&&l.current.add(k.id);const O=k.messages.map(Yr).filter(y=>!!y);R.set(k.id,{latestStep:O[O.length-1],stepCount:O.length,messages:k.messages,elapsedMs:Qr(k.messages),running:!w})}return R}),b||(C=setTimeout(S,Kr)))};return S(),()=>{b=!0,C&&clearTimeout(C)}},[v,a]),r}function Zr(t){return n.useMemo(()=>{const s=[];for(const a of t){const r=a.kind==="tool"?a.tool:void 0;r!=null&&r.toolUseId&&Zt.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 eo({checked:t,available:s,onChange:a}){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-paddock-600 dark:text-paddock-300":"cursor-not-allowed text-paddock-400"}`,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=>a(r.target.checked),className:"h-3.5 w-3.5 rounded border-paddock-300 accent-accent focus:ring-accent/30 disabled:opacity-50 dark:border-paddock-600"}),e.jsx("span",{className:"font-medium",children:"Preload project context"}),e.jsx("span",{className:"hidden text-paddock-400 transition-opacity sm:inline",children:s?"(injects OVERVIEW.md + CHANGELOG.md)":"(no overview yet)"})]})}function to({models:t,model:s,onSelectModel:a,usage:r,sessionUsage:o,forkParent:l,onOpenForkParent:i}){return e.jsxs("div",{className:"mb-2 flex items-center gap-3 px-1 text-[11px] text-paddock-400",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-paddock-500 dark:text-paddock-400",children:"Model"}),e.jsxs("select",{value:s??"",onChange:c=>a(c.target.value),disabled:t.length===0,title:"Model for this chat (sent on every message; remembered per chat)",className:"rounded-md border border-paddock-300 bg-white px-1.5 py-0.5 text-[11px] text-paddock-700 outline-none focus:border-accent focus:ring-1 focus:ring-accent/20 disabled:opacity-50 dark:border-paddock-700 dark:bg-paddock-900 dark:text-paddock-200",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(so,{usage:r}),e.jsx(ao,{usage:o}),l&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(Je,{width:11,height:11,className:"shrink-0 text-paddock-400"}),e.jsx("span",{className:"shrink-0",children:"Fork of"}),e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(l.sessionId),title:`Open the chat this was forked from: ${l.name}`,className:"truncate font-medium text-accent underline-offset-2 hover:underline",children:l.name})]})]})}function so({usage:t}){if(!t||t.contextLimit<=0)return e.jsx("span",{className:"text-paddock-400",children:"context: —"});const s=Math.min(100,Math.max(0,t.contextTokens/t.contextLimit*100)),a=s>=80,r=Math.round(t.contextTokens/1e3),o=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-paddock-200 dark:bg-paddock-800",children:e.jsx("span",{className:`block h-full rounded-full transition-all ${a?"bg-amber-500":"bg-accent"}`,style:{width:`${s}%`}})}),e.jsxs("span",{className:a?"text-amber-600 dark:text-amber-400":void 0,children:[r,"k / ",o,"k (",Math.round(s),"%)"]})]})}function ao({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${Ea(t.costUsd)}`:Ra(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${$a(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const ca=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function no(){const[t,s]=n.useState(0);return n.useEffect(()=>{const a=setInterval(()=>s(r=>(r+1)%ca.length),2600);return()=>clearInterval(a)},[]),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-paddock-200 bg-paddock-100/70 px-3 py-1 text-xs text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/50 dark:text-paddock-400",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-accent","aria-hidden":"true"}),e.jsxs("span",{children:[ca[t],"…"]})]})})}function ro({text:t,onEdit:s,onClear:a}){const r=t.split(`
|
|
7
|
-
`,1)[0],o=t.length-r.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/30 bg-accent/[0.06] px-3 py-1.5 text-xs dark:border-accent/40 dark:bg-accent/10",children:[e.jsx(Qe,{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-paddock-600 dark:text-paddock-300",title:t,children:r}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-paddock-400 dark:text-paddock-500",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:s,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-paddock-600 hover:bg-paddock-200/70 dark:text-paddock-300 dark:hover:bg-paddock-800",children:[e.jsx(Jt,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:a,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-paddock-500 hover:bg-paddock-200/70 hover:text-rose-600 dark:text-paddock-400 dark:hover:bg-paddock-800",children:e.jsx(Be,{width:12,height:12})})]})]})})}function oo({state:t}){const s={open:{c:"bg-emerald-500",t:"connected"},connecting:{c:"bg-amber-500 animate-pulse",t:"connecting"},closed:{c:"bg-rose-500",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 lo=n.lazy(()=>le(()=>import("./MarkdownRenderer-DpGpkMzG.js"),__vite__mapDeps([0,1,2,3,4,5]))),_t=n.memo(function({children:s,mermaid:a=!1}){return e.jsx(n.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(lo,{mermaid:a,children:s})})}),io={tsx:"typescript",jsx:"javascript",html:"xml"};function co(t){if(!t)return;const s=t.toLowerCase();return io[s]??s}let xs=null;async function uo(){return xs||(xs=(async()=>{const{default:t}=await le(async()=>{const{default:$}=await import("./core-DyOZ2e1O.js");return{default:$}},__vite__mapDeps([6,1,2])),[s,a,r,o,l,i,c,m,h,v,u,b,C,S,f,x,T,E,R,k,F]=await Promise.all([le(()=>import("./typescript-C2FFdlUC.js"),[]),le(()=>import("./javascript-BKRaQes9.js"),[]),le(()=>import("./python-kSlZHhJb.js"),[]),le(()=>import("./ruby-7T4ktxyv.js"),[]),le(()=>import("./go-BPx_y7j8.js"),[]),le(()=>import("./rust-HC3MBUhY.js"),[]),le(()=>import("./java-B5VKqtH2.js"),[]),le(()=>import("./c-D2F1sQUL.js"),[]),le(()=>import("./cpp-Bm3ii6kY.js"),[]),le(()=>import("./csharp-BNpuYZMG.js"),[]),le(()=>import("./php-CRdd4dfS.js"),[]),le(()=>import("./swift-Dn8kKO_1.js"),[]),le(()=>import("./kotlin-Cw-eF_bm.js"),[]),le(()=>import("./bash-I8pq0VWm.js"),[]),le(()=>import("./sql-BC88IN-V.js"),[]),le(()=>import("./json-DIYVocXf.js"),[]),le(()=>import("./yaml-drsDnIKT.js"),[]),le(()=>import("./ini-B3BVgEsG.js"),[]),le(()=>import("./css-DazXZka4.js"),[]),le(()=>import("./scss-DZLA7YXz.js"),[]),le(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",a.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",o.default),t.registerLanguage("go",l.default),t.registerLanguage("rust",i.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",h.default),t.registerLanguage("csharp",v.default),t.registerLanguage("php",u.default),t.registerLanguage("swift",b.default),t.registerLanguage("kotlin",C.default),t.registerLanguage("bash",S.default),t.registerLanguage("sql",f.default),t.registerLanguage("json",x.default),t.registerLanguage("yaml",T.default),t.registerLanguage("toml",E.default),t.registerLanguage("css",R.default),t.registerLanguage("scss",k.default),t.registerLanguage("xml",F.default),t})()),xs}function mo({code:t,language:s}){const[a,r]=n.useState(null),o=co(s);n.useEffect(()=>{if(!o){r(null);return}let i=!1;return r(null),(async()=>{try{const c=await uo();if(i||!c.getLanguage(o))return;const{value:m}=c.highlight(t,{language:o});i||r(m)}catch{}})(),()=>{i=!0}},[t,o]);const l="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-[12.5px] leading-relaxed text-paddock-800 dark:text-paddock-200";return a!==null?e.jsx("pre",{className:l,children:e.jsx("code",{className:`hljs language-${o}`,dangerouslySetInnerHTML:{__html:a}})}):e.jsx("pre",{className:l,children:e.jsx("code",{children:t})})}let fs=null;function po(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function ho(){return fs||(fs=le(()=>import("./mermaid.core-Dorg4Dl2.js").then(t=>t.bm),__vite__mapDeps([7,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:po()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),fs}function xo({code:t}){const a="mmd-"+n.useId().replace(/[^a-zA-Z0-9-]/g,""),r=n.useRef(null),[o,l]=n.useState(null);return n.useEffect(()=>{let i=!1;return l(null),(async()=>{try{const c=await ho();await c.parse(t);const{svg:m,bindFunctions:h}=await c.render(a+"-svg",t);if(i||!r.current)return;r.current.innerHTML=m,h==null||h(r.current)}catch(c){if(i)return;l(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{i=!0}},[t,a]),o?e.jsxs("div",{className:"my-3 rounded-lg border border-amber-300/60 bg-amber-50 p-3 text-xs dark:border-amber-900/60 dark:bg-amber-950/40",children:[e.jsx("p",{className:"font-semibold text-amber-700 dark:text-amber-300",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-amber-600 dark:text-amber-400/90",children:o}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-paddock-100 p-2 font-mono text-[11.5px] text-paddock-700 dark:bg-paddock-950 dark:text-paddock-300",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-paddock-200 bg-white/60 p-3 dark:border-paddock-800 dark:bg-paddock-950/40"})}const fo="paddock:itemHeight:";function Bs(t){return fo+t}function da(t){try{const s=localStorage.getItem(Bs(t));if(s==null)return null;const a=Number(s);return Number.isFinite(a)&&a>0?a:null}catch{return null}}function ko(t,s){try{const a=Bs(t);Number.isFinite(s)&&s>0?localStorage.setItem(a,String(Math.round(s))):localStorage.removeItem(a)}catch{}}function go(t){try{localStorage.removeItem(Bs(t))}catch{}}function bo({itemId:t,children:s,defaultMaxHeight:a=360,minHeight:r=80}){const o=n.useRef(null),[l,i]=n.useState(0),[c,m]=n.useState(()=>da(t));n.useEffect(()=>{m(da(t))},[t]),n.useEffect(()=>{const C=o.current;if(!C)return;const S=()=>i(C.scrollHeight||0);if(S(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(S);return f.observe(C),()=>f.disconnect()},[s]);const h=l>0,v=h?l:Number.POSITIVE_INFINITY;let u=!1,b=0;return c!=null?(u=!0,b=Wa(c,r,v)):h&&l>a&&(u=!0,b=a),u?e.jsxs("div",{className:"group relative",style:{height:b},children:[e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsx("div",{ref:o,children:s})}),e.jsx(jo,{appliedHeight:b,onResize:C=>m(C),onCommit:C=>ko(t,C),onReset:()=>{go(t),m(null)},minHeight:r,maxHeight:v})]}):e.jsx("div",{ref:o,children:s})}function jo({appliedHeight:t,onResize:s,onCommit:a,onReset:r,minHeight:o,maxHeight:l}){const i=n.useRef(null),c=n.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:h=>{i.current={startY:h.clientY,startHeight:t},h.currentTarget.setPointerCapture(h.pointerId)},onPointerMove:h=>{if(!i.current)return;const v=ua(i.current.startHeight,h.clientY-i.current.startY,o,l);s(v)},onPointerUp:h=>{if(i.current){i.current=null;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}a(c.current)}},onDoubleClick:r,onKeyDown:h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){h.preventDefault();const v=h.key==="ArrowDown"?m:-m,u=ua(t,v,o,l);s(u),a(u)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-paddock-100 bg-paddock-50/40 opacity-60 transition hover:bg-paddock-100 hover:opacity-100 dark:border-paddock-800 dark:bg-paddock-900/40 dark:hover:bg-paddock-800",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-paddock-300 group-hover:bg-paddock-400 dark:bg-paddock-600 dark:group-hover:bg-paddock-500"})})}function ua(t,s,a,r){return Wa(t+s,a,r)}function Wa(t,s,a){return Math.min(Math.max(t,s),a)}function Ga({src:t,filename:s,message:a}){const[r,o]=n.useState(!1),[l,i]=n.useState(!1),c="repeating-conic-gradient(rgb(0 0 0 / 0.06) 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-rose-700 dark:text-rose-300",children:[e.jsx(ce,{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:()=>o(!0),onClick:()=>i(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),i(!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(Ka,{src:t,filename:s,onMaximize:()=>i(!0)}),l?e.jsx(vo,{src:t,filename:s,message:a,onClose:()=>i(!1)}):null]})}function Ka({src:t,filename:s,onMaximize:a}){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(wo,{})}),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(No,{})}),a?e.jsx("button",{type:"button",onClick:a,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(yo,{})}):null]})}function vo({src:t,filename:s,message:a,onClose:r}){const o=n.useRef(null);return n.useEffect(()=>{var c;const l=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",l);const i=document.body.style.overflow;return document.body.style.overflow="hidden",(c=o.current)==null||c.focus(),()=>{document.removeEventListener("keydown",l),document.body.style.overflow=i}},[r]),Sa.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-black/80 p-6",children:[e.jsx("button",{ref:o,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(Co,{})}),e.jsx("img",{src:t,alt:s,onClick:l=>l.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:l=>l.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),a?e.jsx("div",{className:"mt-1",children:a}):null]})]}),document.body)}function es({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 wo(){return e.jsxs(es,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function No(){return e.jsxs(es,{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 yo(){return e.jsx(es,{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 Co(){return e.jsx(es,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function So({file:t}){const[s,a]=n.useState(!0),r=Io(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-white shadow-sm ring-1 ring-paddock-200/70 dark:bg-paddock-900 dark:ring-paddock-800",children:[e.jsxs("button",{type:"button",onClick:()=>a(o=>!o),"aria-expanded":s,className:"flex w-full items-center gap-2 border-b border-paddock-200 bg-paddock-50/60 px-4 py-2 text-left text-[11px] text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/40",children:[e.jsx(_o,{open:s}),e.jsx(Ya,{}),e.jsx("span",{className:"font-mono text-paddock-600 dark:text-paddock-300",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-[10px] text-paddock-400",children:t.language??t.kind})]}),t.message?e.jsx("div",{className:"border-b border-paddock-100 px-4 py-2 text-xs text-paddock-500 dark:border-paddock-800 dark:text-paddock-400",children:t.message}):null,s?e.jsx(Eo,{file:t,itemId:r}):null]})})}function Io(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${To(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function To(t){let s=5381;for(let a=0;a<t.length;a++)s=(s<<5)+s+t.charCodeAt(a)|0;return(s>>>0).toString(36)}function Eo({file:t,itemId:s}){return t.kind==="image"?e.jsx(Ga,{src:t.rawUrl,filename:t.filename,message:t.message}):t.kind==="video"?e.jsx($o,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(Mo,{src:t.rawUrl,filename:t.filename}):t.source==="inline"?e.jsx(qa,{kind:t.kind,text:t.content??"",language:t.language,itemId:s}):e.jsx(Ro,{url:t.rawUrl,kind:t.kind,language:t.language,itemId:s})}function qa({kind:t,text:s,language:a,itemId:r}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:"min-h-[360px] w-full bg-white"}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(xo,{code:s})}):t==="markdown"?e.jsx(ks,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(_t,{mermaid:!0,children:s})})}):t==="code"?e.jsx(ks,{itemId:r,children:e.jsx(mo,{code:s,language:a})}):e.jsx(ks,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-[12.5px] leading-relaxed text-paddock-800 dark:text-paddock-200",children:s})})}function ks({itemId:t,children:s}){return t?e.jsx(bo,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function Ro({url:t,kind:s,language:a,itemId:r}){const[o,l]=n.useState(null);return n.useEffect(()=>{if(!t){l({error:!0});return}let i=!1;return l(null),fetch(t).then(c=>c.ok?c.text():Promise.reject(new Error(String(c.status)))).then(c=>!i&&l({text:c})).catch(()=>!i&&l({error:!0})),()=>{i=!0}},[t]),o===null?e.jsx("div",{className:"px-4 py-3 text-xs text-paddock-400",children:"Loading…"}):"error"in o?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-rose-700 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(qa,{kind:s,text:o.text,language:a,itemId:r})}function $o({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-paddock-950 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-paddock-200",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-rose-700 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function Mo({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-paddock-50 dark:bg-paddock-950",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-paddock-600 dark:text-paddock-300",children:[e.jsx(Ya,{}),e.jsx("span",{className:"font-mono text-paddock-700 dark:text-paddock-200",children:s}),e.jsx("span",{className:"text-xs text-paddock-500 dark:text-paddock-400",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-paddock-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-paddock-700",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-paddock-600 ring-1 ring-paddock-300 hover:bg-paddock-100 dark:text-paddock-300 dark:ring-paddock-700 dark:hover:bg-paddock-800",children:"Download"})]})]})}),e.jsx(Ka,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-rose-700 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function _o({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-paddock-400 transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function Ya(){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-paddock-400",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 Ts=n.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(Ao,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(gr,{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 px-4 py-2.5 text-sm text-white shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(So,{file:s.file}):s.kind==="tool"?e.jsx(Bo,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-paddock-100 px-2.5 py-0.5 font-mono text-xs text-ink-subtle ring-1 ring-paddock-200/70 dark:bg-paddock-900 dark:text-ink-dark/70 dark:ring-paddock-800",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(Lo,{content:s.content}):null:s.kind==="compact"?e.jsx(Fo,{summary:s.summary}):s.kind==="notice"?e.jsx(Uo,{notice:s.notice}):s.kind==="notification"?Bn(s.status)?e.jsx(Oo,{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-paddock-50 px-2.5 py-0.5 text-xs italic text-ink-subtle/80 ring-1 ring-paddock-200/60 dark:bg-paddock-950 dark:text-ink-dark/60 dark:ring-paddock-800/70",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-white px-4 py-2.5 text-ink shadow-sm ring-1 ring-paddock-200/70 dark:bg-paddock-900 dark:text-ink-dark dark:ring-paddock-800",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(_t,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Re,{})," ",e.jsx(Re,{delay:"150ms"})," ",e.jsx(Re,{delay:"300ms"})]})})})}),Do=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function Po({turn:t}){const s=n.useContext(Ha);if(!(!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&Do.test(t.id)))return e.jsx(Ts,{turn:t});const r=t.id.split("#")[0],o=t.contextTokens,l=s.contextLimit,i=o!=null&&l?Math.min(100,Math.round(o/l*100)):null,c="flex items-center rounded-full bg-canvas/95 shadow-sm ring-1 ring-paddock-200/70 backdrop-blur dark:bg-canvas-dark/95 dark:ring-paddock-800",m=`${c} h-6 w-6 justify-center text-ink-subtle dark:text-ink-dark/70 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-[11px] text-ink-subtle dark:text-ink-dark/70`,title:new Date(t.timestamp).toLocaleString(),children:[e.jsx("span",{children:vt(t.timestamp)}),o!=null?e.jsxs("span",{className:"text-ink-subtle/70 dark:text-ink-dark/50",title:"Context-window fill as of this message",children:["· ",Ra(o),i!=null?` · ${i}%`:""]}):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:`${m} hover:text-accent`,children:e.jsx(Je,{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:`${m} hover:text-rose-500`,children:e.jsx(Qe,{width:13,height:13})})]}),e.jsx(Ts,{turn:t})]})}function Re({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-paddock-400",style:{animationDelay:t}})}function Lo({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-paddock-50 px-4 py-2.5 text-ink shadow-sm ring-1 ring-paddock-200/70 dark:bg-paddock-950 dark:text-ink-dark dark:ring-paddock-800",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-[11px] italic text-ink-subtle/80 dark:text-ink-dark/60",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(_t,{children:t})]})})}function Fo({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-ink-subtle dark:text-ink-dark/60",children:[e.jsx("span",{className:"h-px flex-1 bg-paddock-200/70 dark:bg-paddock-800"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-paddock-200/70 dark:bg-paddock-800"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-paddock-50 px-3 py-2 text-xs text-ink-subtle ring-1 ring-paddock-200/70 dark:bg-paddock-950 dark:text-ink-dark/70 dark:ring-paddock-800",children:t})]})})}function Ao({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-[11px] italic text-ink-subtle/80 dark:text-ink-dark/60";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 a=((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(Ds,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${a} in ${t.project}`,children:a})]})]})}function Oo({summary:t}){const s=n.useContext(Us),a=!!(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-amber-300/70 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/50 dark:text-amber-200",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-[11px] text-amber-800/80 dark:text-amber-300/70",children:t})]})]}),a&&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:"rounded-md bg-amber-600 px-2.5 py-1 text-[11px] font-medium text-white shadow-sm transition hover:bg-amber-700 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-amber-700 dark:hover:bg-amber-600",children:r?"Continuing…":"Continue"})})]})})}function Uo({notice:t}){const s=n.useContext(Us),a=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),o=t.kind==="error",l=o?"border-rose-300/70 bg-rose-50 text-rose-900 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-200":"border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/50 dark:text-amber-200",i=o?"bg-rose-600 hover:bg-rose-700 dark:bg-rose-700 dark:hover:bg-rose-600":"bg-amber-600 hover:bg-amber-700 dark:bg-amber-700 dark:hover:bg-amber-600",c=o?"text-rose-800/80 dark:text-rose-300/70":"text-amber-800/80 dark:text-amber-300/70",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${l}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:o?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-[11px] ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),o&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-[11px] ${c}`,children:t.detail})]})]}),a&&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:`rounded-md px-2.5 py-1 text-[11px] font-medium text-white shadow-sm transition disabled:cursor-not-allowed disabled:opacity-50 ${i}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Bo({tool:t}){var p,A;const s=Sr(t.toolName),a=Ir(t.toolName,t.output),r=s.isPaddock?Ar(s.tool):null,o=a!=null&&(a.tool==="create_chat"||a.tool==="fork_chat"||a.tool==="send_message"||a.tool==="fork_chat_batch"),[l,i]=n.useState(o),c=n.useContext(za),m=n.useContext(Va),h=n.useRef(null),[v,u]=n.useState(!1),b=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;n.useEffect(()=>{var g;if(b==null)return;i(!0),(g=h.current)==null||g.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const X=setTimeout(()=>u(!1),3200);return()=>clearTimeout(X)},[b]);const C=n.useContext(Ba),S=n.useContext(Os),f=!!t.pending,x=Zt.has(t.toolName),T=t.toolUseId?S==null?void 0:S.get(t.toolUseId):void 0,E=x?Kt(t.subagentDurationMs??(T==null?void 0:T.elapsedMs)):Kt(t.durationMs),R=t.subagentCostUsd!=null?`~${Ea(t.subagentCostUsd)}`:null,k=!x&&Lr(t),F=t.monitorEvents??[],$=t.editDiff,P=!!$,w=t.toolName==="Read"?t.readInfo:void 0,O=w!=null&&w.isImage&&w.projectRelPath&&c?c(w.projectRelPath):null,y=t.toolName==="Bash"?t.bashDetails:void 0,B=t.searchInfo,U=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,I=t.toolName==="TaskCreate"?t.taskCreate:void 0,D=!!(y&&y.stderr),q=B?Br(B):null,H=w?Vr(w):null,Y=T!=null?T.running:Mr(t,C),Q=!!(x&&t.hasSubagent&&t.toolUseId),te=Y&&t.toolUseId?(p=S==null?void 0:S.get(t.toolUseId))==null?void 0:p.latestStep:void 0,ne=x?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,se=x?te??t.description:a?Tr(a):P?((A=$.filePath)==null?void 0:A.split("/").pop())??$.filePath:w?w.basename??w.filePath??t.inputSummary:I?I.subject:t.inputSummary,de=(w==null?void 0:w.filePath)??(I==null?void 0:I.description)??(te?t.description:void 0)??se??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:h,className:`w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-colors ${v?"subagent-reveal ":""}${t.isError?"border-rose-300/70 bg-rose-50/60 dark:border-rose-900/60 dark:bg-rose-950/30":x?"border-accent/40 bg-accent/[0.06] dark:border-accent/40 dark:bg-accent/10":k?"border-sky-300/50 bg-sky-50/40 dark:border-sky-900/50 dark:bg-sky-950/20":"border-paddock-200 bg-paddock-100/50 dark:border-paddock-800 dark:bg-paddock-900/40"}`,children:[e.jsxs("button",{type:"button",onClick:()=>i(X=>!X),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(Xt,{width:13,height:13,className:`shrink-0 text-paddock-400 transition-transform ${l?"rotate-90":""}`}),x?e.jsx(Ps,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-accent"}`}):k?e.jsx(Qe,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-sky-600 dark:text-sky-400"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-accent"}`}):P?e.jsx(Jt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):w?e.jsx($t,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):B?e.jsx(Ia,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):U||I?e.jsx(nt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):e.jsx(Ta,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-paddock-700 dark:text-paddock-200",children:ne}),x&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),k&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-sky-500/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-sky-700 dark:text-sky-300",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-accent",children:a&&"project"in a&&a.project?a.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-paddock-200/70 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300",children:"MCP"}),U?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-paddock-500 dark:text-paddock-400",children:[U.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",U.taskId]}),U.from&&U.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(ma,{status:U.from}),e.jsx("span",{className:"text-paddock-400",children:"→"}),e.jsx(ma,{status:U.to})]}):U.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:U.updatedFields.join(", ")})]}):se&&e.jsx("span",{className:`min-w-0 truncate font-mono ${te?"text-accent/90":"text-paddock-500 dark:text-paddock-400"}`,title:de,children:se}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-rose-200/70 px-1.5 py-0.5 text-[10px] font-semibold text-rose-700 dark:bg-rose-900/60 dark:text-rose-300",children:"error"}),f||Y?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/30 border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[k&&F.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-[10px] text-sky-600 dark:text-sky-400",children:[F.length," event",F.length===1?"":"s"]}),k&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-[10px] font-semibold ${Fr(t.taskStatus)}`,children:t.taskStatus}),P&&($.additions>0||$.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-[10px] font-semibold tabular-nums",children:[$.additions>0&&e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",$.additions]}),$.additions>0&&$.deletions>0&&" ",$.deletions>0&&e.jsxs("span",{className:"text-rose-600 dark:text-rose-400",children:["−",$.deletions]})]}),H&&e.jsx("span",{className:"whitespace-nowrap font-mono text-[10px] text-paddock-400 tabular-nums",children:H}),q&&e.jsx("span",{className:"whitespace-nowrap font-mono text-[10px] font-medium text-paddock-500 tabular-nums dark:text-paddock-400",children:q}),(y==null?void 0:y.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-paddock-200/70 px-1.5 py-0.5 font-mono text-[10px] text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300",children:y.gitHint}),(y==null?void 0:y.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-700 dark:bg-amber-950/60 dark:text-amber-300",children:"interrupted"}),(y==null?void 0:y.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-[10px] italic text-paddock-400",children:y.returnCodeInterpretation}),E&&e.jsx("span",{className:"text-paddock-400",children:E}),R&&e.jsx("span",{className:"text-paddock-400",children:R})]})]})]}),l&&(Q?e.jsx(Wo,{toolUseId:t.toolUseId,live:Y}):k&&F.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-sky-200/60 bg-sky-50/40 dark:border-sky-900/50 dark:bg-sky-950/20",children:F.map((X,g)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-sky-200/40 px-3 py-1.5 font-mono text-[11.5px] leading-relaxed text-paddock-700 last:border-b-0 dark:border-sky-900/40 dark:text-paddock-300",children:X},g))}):a?e.jsx($r,{data:a}):P?e.jsx(Vo,{diff:$}):O?e.jsx("div",{className:"border-t border-paddock-200/70 dark:border-paddock-800",children:e.jsx(Ga,{src:O,filename:(w==null?void 0:w.basename)??"image"})}):D?e.jsx(zo,{bash:y}):I&&I.description?e.jsx(Ho,{info:I}):e.jsxs("div",{className:"border-t border-paddock-200/70 dark:border-paddock-800",children:[k&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-paddock-200/70 bg-sky-50/50 px-3 py-2 text-[11.5px] font-medium text-paddock-700 dark:border-paddock-800 dark:bg-sky-950/20 dark:text-paddock-200",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-paddock-50/80 px-3 py-2 font-mono text-[11.5px] leading-relaxed text-paddock-700 dark:bg-paddock-950/60 dark:text-paddock-300",children:f?"Running…":t.output||"(no output)"})]}))]})})}function Vo({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-paddock-200/70 bg-paddock-50/80 font-mono text-[11.5px] leading-relaxed dark:border-paddock-800 dark:bg-paddock-950/60",children:[t.hunks.map((s,a)=>e.jsxs("div",{className:a>0?"border-t border-paddock-200/60 dark:border-paddock-800/60":"",children:[e.jsxs("div",{className:"bg-paddock-100/70 px-3 py-1 font-mono text-[10px] font-semibold text-sky-700/80 dark:bg-paddock-900/50 dark:text-sky-400/80",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,o)=>e.jsxs("div",{className:`flex ${Or(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular-nums opacity-40",children:la(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular-nums opacity-40",children:la(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||" "})]},o))]},a)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] italic text-paddock-400",children:"… diff truncated (see the file for the full change)"})]})}function ma({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-[10px] font-semibold ${Ur(t)}`,children:t})}function zo({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-paddock-200/70 dark:border-paddock-800",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-paddock-50/80 px-3 py-2 font-mono text-[11.5px] leading-relaxed text-paddock-700 dark:bg-paddock-950/60 dark:text-paddock-300",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-rose-200/50 bg-rose-50/50 px-3 py-2 font-mono text-[11.5px] leading-relaxed text-rose-700 first:border-t-0 dark:border-rose-900/40 dark:bg-rose-950/20 dark:text-rose-300",children:t.stderr})]})}function Ho({info:t}){return e.jsxs("div",{className:"border-t border-paddock-200/70 bg-paddock-50/80 px-3 py-2 dark:border-paddock-800 dark:bg-paddock-950/60",children:[t.subject&&e.jsx("div",{className:"text-[12px] font-semibold text-paddock-700 dark:text-paddock-200",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-[11.5px] leading-relaxed text-paddock-600 dark:text-paddock-400",children:t.description})]})}const pa=2e3;function Wo({toolUseId:t,live:s=!1}){var v,u;const a=n.useContext(Ua),[r,o]=n.useState(null),[l,i]=n.useState(!1),c=(u=(v=n.useContext(Os))==null?void 0:v.get(t))==null?void 0:u.messages;n.useEffect(()=>{o(null),i(!1)},[t]),n.useEffect(()=>{if(c)return;if(!a){i(!0);return}let b=!1,C;const S=()=>{a(t).then(f=>{b||(o(f),s&&(C=setTimeout(S,pa)))}).catch(()=>{b||(s?C=setTimeout(S,pa):i(!0))})};return S(),()=>{b=!0,C&&clearTimeout(C)}},[a,t,s,!!c]);const m=c??r,h=n.useMemo(()=>Yt(m??[]),[m]);return e.jsx("div",{className:"border-t border-paddock-200/70 bg-paddock-50/60 px-3 py-3 dark:border-paddock-800 dark:bg-paddock-950/40",children:l?e.jsx("div",{className:"text-[11.5px] text-rose-500",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-[11.5px] text-paddock-400",children:[e.jsx(Re,{})," ",e.jsx(Re,{delay:"150ms"})," ",e.jsx(Re,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):h.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-[11.5px] text-paddock-400",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Re,{})," ",e.jsx(Re,{delay:"150ms"})," ",e.jsx(Re,{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/30 pl-3",children:[h.map(b=>e.jsx(Ts,{turn:b},b.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-accent/80",children:[e.jsx(Re,{})," ",e.jsx(Re,{delay:"150ms"})," ",e.jsx(Re,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function Go(t){const{projectSlug:s,initialSessionId:a,loadHistory:r,onSessionEstablished:o,onSessionStarted:l,onTurnComplete:i,sessionRef:c,jobRef:m,pendingCancelRef:h,streamingRef:v,awaitingSessionRef:u,isNewSessionRef:b,startedNotifiedRef:C,establishedHereRef:S,modelRef:f,cancelledRef:x,noticeThisTurnRef:T,seenInjectionsRef:E,onQueuedFlushedRef:R,setTurns:k,setStreaming:F,setUsage:$,setSessionUsage:P,setError:w}=t;n.useEffect(()=>{const O=I=>{const D=c.current;return D?I.sessionId===D?!0:I.sessionId==null&&v.current:u.current},y=I=>{c.current=I,u.current=!1,U.setSessionId(I),b.current&&!C.current&&(C.current=!0,S.current=I,f.current&&Cs(I,s,f.current),l==null||l(I))},B=I=>{m.current=I,h.current&&(h.current=!1,Ae.cancel(I))},U=Ae.subscribe(s,c.current,{onResponse:(I,D)=>{O(D)&&(D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId),Hr(k,I))},onToolStart:(I,D)=>{O(D)&&(D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId),k(q=>I.toolUseId&&q.some(H=>H.kind==="tool"&&H.tool.toolUseId===I.toolUseId)?q:[...Fe(q),{kind:"tool",id:Ue(),tool:I}]))},onToolCall:(I,D)=>{if(!O(D))return;D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId);const q=Oa(I);k(H=>{if(I.toolUseId){const Q=H.findIndex(te=>te.kind==="tool"&&te.tool.toolUseId===I.toolUseId);if(Q!==-1){const te=H[Q].id,ne=H.slice();return ne[Q]=q?{kind:"file",id:te,file:q}:{kind:"tool",id:te,tool:I},ne}}const Y=q?{kind:"file",id:Ue(),file:q}:{kind:"tool",id:Ue(),tool:I};return[...Fe(H),Y]})},onMessageBoundary:I=>{O(I)&&(I.jobId&&B(I.jobId),k(D=>Fe(D)))},onComplete:I=>{if(O(I)){I.jobId&&B(I.jobId),v.current=!1,F(!1),k(D=>ia(Fe(D))),I.usage&&$(I.usage);{const D=I.sessionId??c.current;D&&L.chatContext(s,D).then(q=>P(q)).catch(()=>{})}if(I.sessionId){const D=b.current&&c.current!==I.sessionId;y(I.sessionId),(D||b.current)&&(b.current=!1,f.current&&Cs(I.sessionId,s,f.current),S.current=I.sessionId,o==null||o(I.sessionId))}!I.success&&I.error&&!T.current&&w(I.error);{const D=I.sessionId??c.current;i==null||i(D&&I.usage?{sessionId:D,usage:I.usage}:void 0)}x.current=!1}},onError:I=>{v.current&&(v.current=!1,F(!1),m.current=null,k(D=>ia(Fe(D))),w(I),x.current=!1)},onResync:()=>{const I=c.current;!I||!r||r(I).then(D=>k(Yt(D))).catch(()=>{})},onActive:({running:I,jobId:D})=>{I?(D&&B(D),v.current=!0,F(!0)):(v.current=!1,F(!1),m.current=null,k(q=>Fe(q)),x.current=!1,h.current=!1)},onQueuedFlushed:({text:I})=>{R.current(I)},onInjected:(I,D)=>{if(!O(D))return;D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId);const q=`${I.timestamp} ${I.content}`;E.current.has(q)||(E.current.add(q),k(H=>[...Fe(H),{kind:"user",id:Ue(),content:I.content,sender:I.sender}]))},onKilledTask:({summary:I,timestamp:D})=>{const q=`killed ${D}`;E.current.has(q)||(E.current.add(q),k(H=>[...Fe(H),{kind:"notification",id:Ue(),summary:I,status:"killed"}]))},onNotice:(I,D)=>{O(D)&&(T.current=!0,k(q=>[...Fe(q),{kind:"notice",id:Ue(),notice:I}]))}});return()=>{U.unsubscribe()}},[s,a,r,o,l,i])}const Ko="paddock:attachments:";function Qa(t,s){return Ko+(t??`new:${s}`)}function qo(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 a={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(a.size=s.size),a}function Yo(t,s){try{const a=localStorage.getItem(Qa(t,s));if(!a)return[];const r=JSON.parse(a);return Array.isArray(r)?r.map(qo).filter(o=>o!==null):[]}catch{return[]}}function Qo(t,s,a){try{const r=Qa(t,s);a.length>0?localStorage.setItem(r,JSON.stringify(a)):localStorage.removeItem(r)}catch{}}function Jo({projectSlug:t,initialSessionId:s,attachmentsDefault:a,projectAttachments:r,sessionRef:o,setError:l}){const[i,c]=n.useState(()=>Yo(s,t)),m=n.useRef([]);m.current=i;const[h,v]=n.useState(!1),[u,b]=n.useState(!1),C=n.useRef(null);n.useEffect(()=>{Qo(s,t,i)},[i,s,t]);const S=n.useMemo(()=>{const P=a??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},w=r??{};return{enabled:w.enabled??P.enabled,maxFileSizeMb:w.maxFileSizeMb??P.maxFileSizeMb,maxFilesPerMessage:w.maxFilesPerMessage??P.maxFilesPerMessage,allowedTypes:w.allowedTypes??P.allowedTypes}},[a,r]),f=S.enabled,x=n.useCallback(async P=>{if(!f||P.length===0)return;const w=S.maxFileSizeMb*1024*1024,O=S.maxFilesPerMessage-m.current.length;if(O<=0){l(`You can attach at most ${S.maxFilesPerMessage} files per message.`);return}const y=[];for(const B of P.slice(0,O)){if(!kr(S.allowedTypes,B.type,B.name)){l(`File type not allowed: ${B.name}`);continue}if(B.size>w){l(`File too large (max ${S.maxFileSizeMb} MB): ${B.name}`);continue}y.push(B)}if(P.length>O&&l(`You can attach at most ${S.maxFilesPerMessage} files per message.`),y.length!==0){v(!0);try{const{files:B}=await L.uploadAttachments(t,o.current??"new",y);c(U=>[...U,...B])}catch(B){l(B instanceof Error?B.message:"Upload failed.")}finally{v(!1)}}},[f,S,t]),T=n.useCallback(P=>{c(w=>w.filter(O=>O.id!==P))},[]),E=n.useCallback(P=>{var O;if(!f)return;const w=Array.from(((O=P.clipboardData)==null?void 0:O.files)??[]);w.length>0&&(P.preventDefault(),x(w))},[f,x]),R=n.useCallback(P=>{var w;f&&Array.from(((w=P.dataTransfer)==null?void 0:w.types)??[]).includes("Files")&&(P.preventDefault(),b(!0))},[f]),k=n.useCallback(P=>{P.currentTarget===P.target&&b(!1)},[]),F=n.useCallback(P=>{var O;if(!f)return;const w=Array.from(((O=P.dataTransfer)==null?void 0:O.files)??[]);w.length>0&&(P.preventDefault(),b(!1),x(w))},[f,x]),$=n.useCallback(P=>{const w=Array.from(P.target.files??[]);w.length>0&&x(w),P.target.value=""},[x]);return{attachments:i,attachRef:m,setAttachments:c,uploading:h,dragOver:u,fileInputRef:C,attachConfig:S,attachEnabled:f,addFiles:x,removeAttachment:T,onComposerPaste:E,onComposerDragOver:R,onComposerDragLeave:k,onComposerDrop:F,onPickFiles:$}}function Xo({projectSlug:t,initialSessionId:s,loadHistory:a,onSessionEstablished:r,onSessionStarted:o,onTurnComplete:l,preloadAvailable:i=!1,projectModel:c,projectModels:m,forkParent:h,onOpenForkParent:v,autoFocus:u,emptyHint:b,placeholder:C,trigger:S,projectRecovery:f,projectAttachments:x,onForkFromMessage:T,onRevertToMessage:E}){const[R,k]=n.useState([]),[F,$]=n.useState(()=>mr(s,t)),P=n.useRef(null),[w,O]=n.useState(!1),[y,B]=n.useState(!1),[U,I]=n.useState(null),[D,q]=n.useState(Ae.state),[H,Y]=n.useState(null),[Q,te]=n.useState(()=>Gn(s,t)),ne=n.useRef(Q),se=n.useRef(Kn(s,t)),de=n.useRef(!1),p=n.useRef(!1),[A,X]=n.useState(!0),g=!s,Z=n.useRef(!1),[re,$e]=n.useState([]),[me,ie]=n.useState(null),[Ce,Me]=n.useState(null),[fe,pe]=n.useState(null),[we,_e]=n.useState(null),[Ee,Se]=n.useState([]),[je,ee]=n.useState(0),[De,K]=n.useState(!1),ue=n.useRef(null),[Ie,Pe]=n.useState(null),[Ge,Oe]=n.useState(null),Xe=c??me,rt=n.useMemo(()=>m&&m.length>0?re.filter(j=>m.includes(j.id)):re,[re,m]),ve=n.useRef(s??null),N=n.useRef(null),J=n.useRef(!1),{attachments:ae,attachRef:z,setAttachments:Ne,uploading:Ve,dragOver:ot,fileInputRef:wt,attachConfig:lt,attachEnabled:Te,removeAttachment:ts,onComposerPaste:it,onComposerDragOver:ct,onComposerDragLeave:dt,onComposerDrop:Nt,onPickFiles:Dt}=Jo({projectSlug:t,initialSessionId:s,attachmentsDefault:we,projectAttachments:x,sessionRef:ve,setError:I}),he=n.useCallback(j=>ve.current?L.subagentMessages(t,ve.current,j):Promise.resolve([]),[t]),Ke=Zr(R),ut=Xr(Ke,he,w),Pt=n.useMemo(()=>Ke.filter(j=>{var M;return((M=ut.get(j.toolUseId))==null?void 0:M.running)??w}),[Ke,ut,w]),ss=n.useMemo(()=>t?j=>L.projectFileRawUrl(t,j):null,[t]),Ze=n.useRef(!s),qe=n.useRef(!1),mt=n.useRef(!1),Lt=n.useRef(!1),yt=n.useRef(null),pt=n.useRef(null),et=n.useRef(!0),as=n.useRef(new Set),Ct=n.useCallback(()=>{const j=pt.current;j&&(et.current=j.scrollHeight-j.scrollTop-j.clientHeight<80)},[]);n.useLayoutEffect(()=>{const j=pt.current;j&&et.current&&(j.scrollTop=j.scrollHeight)},[R]);const[ht,ns]=n.useState(null),Ft=n.useMemo(()=>({focused:ht,focus:j=>{et.current=!1,ns(M=>({toolUseId:j,nonce:((M==null?void 0:M.nonce)??0)+1}))}}),[ht]);n.useEffect(()=>Ae.onState(q),[]),n.useEffect(()=>{let j=!1;return L.getModels().then(M=>{j||($e(M.models),ie(M.defaultModel),pe(M.recoveryDefault),_e(M.attachmentsDefault))}).catch(()=>{}),()=>{j=!0}},[]),n.useEffect(()=>{let j=!1;return L.projectCommands(t).then(M=>{j||Se(M)}).catch(()=>{}),()=>{j=!0}},[t]);const ze=n.useMemo(()=>{if(!F.startsWith("/"))return null;const j=F.slice(1);return/\s/.test(j)?null:j},[F]),He=n.useMemo(()=>{if(ze===null)return[];const j=ze.toLowerCase();return Ee.filter(M=>M.name.toLowerCase().includes(j))},[ze,Ee]),At=ze!==null&&!De&&He.length>0;n.useEffect(()=>{ee(0)},[ze]),n.useEffect(()=>{K(!1)},[ze]);const St=n.useCallback(j=>{$(`/${j.name} `),requestAnimationFrame(()=>{var M;return(M=P.current)==null?void 0:M.focus()})},[]),It=n.useCallback(j=>{Me(j),ue.current=j,Cs(ve.current??s,t,j)},[t,s]);n.useEffect(()=>{if(s&&s===yt.current){Ze.current=!1;return}let j=!1;return ve.current=s??null,Ze.current=!s,N.current=null,qe.current=!1,mt.current=!1,Lt.current=!1,I(null),O(!1),s&&a?(B(!0),k([]),a(s).then(M=>{j||k(Yt(M))}).catch(()=>{j||I("Could not load this chat's history.")}).finally(()=>{j||B(!1)})):(k([]),B(!1)),s&&L.chatContext(t,s).then(M=>{j||!M||(Pe({inputTokens:M.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:M.contextTokens,contextLimit:M.contextLimit}),Oe(M))}).catch(()=>{}),()=>{j=!0}},[t,s,a]);const Ot=n.useCallback(async()=>{if(!(!s||!a)){try{const j=await a(s);k(Yt(j))}catch{I("Could not reload this chat's history.")}try{const j=await L.chatContext(t,s);j&&(Pe({inputTokens:j.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:j.contextTokens,contextLimit:j.contextLimit}),Oe(j))}catch{}}},[s,a,t]),Ut=n.useCallback(j=>{if(!E)return;const M=R.findIndex(Le=>Le.id.split("#")[0]===j),ye=M>=0&&R[M].kind==="user";let ke=M+1;if(ye){let Le=M-1;for(;Le>=0&&R[Le].kind!=="assistant";)Le--;ke=Le+1}else for(;ke<R.length&&(R[ke].kind==="tool"||R[ke].kind==="file");)ke++;const We=M>=0?R.slice(ke):[],ms=We.filter(Le=>Le.kind==="tool").length;Y({uuid:j,count:We.length,toolCount:ms,anchorIsUser:ye})},[E,R]),Bt=n.useCallback(async()=>{if(H){try{await(E==null?void 0:E(H.uuid)),await Ot()}catch{throw new Error("Could not revert this chat.")}Y(null)}},[H,E,Ot]),rs=n.useMemo(()=>T&&E?{onFork:T,onRevert:Ut,contextLimit:Ie==null?void 0:Ie.contextLimit}:null,[T,E,Ut,Ie==null?void 0:Ie.contextLimit]);n.useEffect(()=>{const M=dr(s,t)??Xe;M&&(Me(M),ue.current=M)},[t,s,Xe]),n.useEffect(()=>{s&&s===yt.current||(Pe(null),Oe(null))},[t,s]),n.useEffect(()=>{pr(s,t,F)},[F,s,t]),n.useEffect(()=>{qn(s,t,Q),Yn(s,t,Q?se.current:null)},[Q,s,t]),n.useEffect(()=>{s&&Ae.setQueued(t,s,Q,Q?se.current:null)},[Q,s,t,Ae]),n.useEffect(()=>{var j;(u||!s)&&((j=P.current)==null||j.focus())},[]);const Vt=n.useCallback(j=>{j&&(et.current=!0,k(M=>[...Fe(M),{kind:"user",id:Ue(),content:j}])),ne.current=null,se.current=null,te(null)},[]),zt=n.useRef(Vt);zt.current=Vt,Go({projectSlug:t,initialSessionId:s,loadHistory:a,onSessionEstablished:r,onSessionStarted:o,onTurnComplete:l,sessionRef:ve,jobRef:N,pendingCancelRef:J,streamingRef:qe,awaitingSessionRef:mt,isNewSessionRef:Ze,startedNotifiedRef:Lt,establishedHereRef:yt,modelRef:ue,cancelledRef:de,noticeThisTurnRef:p,seenInjectionsRef:as,onQueuedFlushedRef:zt,setTurns:k,setStreaming:O,setUsage:Pe,setSessionUsage:Oe,setError:I});const Ht=n.useCallback(j=>{I(null),et.current=!0;const M=j.startsWith("/")?[]:z.current;if(k(We=>[...Fe(We),{kind:"user",id:Ue(),content:j,...M.length>0?{attachments:M}:{}}]),M.length>0&&(Ne([]),z.current=[]),P.current&&(P.current.style.height="auto"),O(!0),qe.current=!0,p.current=!1,N.current=null,J.current=!1,ve.current===null&&(mt.current=!0),j.startsWith("/")){Z.current=!0,Ae.sendCommand(t,j,ve.current);return}const ke=Ze.current&&!Z.current&&A;Z.current=!0,Ae.send(t,j,ve.current,{preloadContext:ke,model:ue.current??void 0,attachments:M.map(We=>({id:We.id,filename:We.filename,kind:We.kind}))})},[t,A]),Wt=n.useCallback(()=>{const j=F.trim();if(!(!j&&z.current.length===0)){if(w){te(M=>{const ye=M?`${M}
|
|
8
|
-
${j}`:j;return ne.current=ye,M==null&&(se.current=Date.now()),ye}),$(""),P.current&&(P.current.style.height="auto");return}$(""),Ht(j)}},[F,w,Ht]),os=n.useCallback(()=>{const j=ne.current;j!=null&&(ne.current=null,se.current=null,te(null),$(M=>M.trim()?`${j}
|
|
9
|
-
${M}`:j),requestAnimationFrame(()=>{const M=P.current;M&&(M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,192)}px`,M.focus())}))},[]),ls=n.useCallback(()=>{ne.current=null,se.current=null,te(null)},[]),is=n.useCallback(()=>{de.current=!0,N.current?Ae.cancel(N.current):J.current=!0},[]),Gt=n.useCallback(()=>{const j=ve.current;j&&(qe.current||(O(!0),Ae.continueChat(t,j)))},[t]),cs=n.useMemo(()=>({enabled:(f==null?void 0:f.surfaceKilledTask)??(fe==null?void 0:fe.surfaceKilledTask)??!0,busy:w,onContinue:Gt}),[t,f,fe,w,Gt]),xt=j=>{if(At){if(j.key==="ArrowDown"){j.preventDefault(),ee(M=>(M+1)%He.length);return}if(j.key==="ArrowUp"){j.preventDefault(),ee(M=>(M-1+He.length)%He.length);return}if(j.key==="Tab"){j.preventDefault(),St(He[je]);return}if(j.key==="Enter"){const M=He[je];if(M&&M.name!==ze){j.preventDefault(),St(M);return}}if(j.key==="Escape"){j.preventDefault(),K(!0);return}}j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),Wt())},ds=n.useCallback(j=>{$(ye=>ye.trim()?`${ye.trimEnd()} ${j}`:j);const M=P.current;M&&requestAnimationFrame(()=>{M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,192)}px`,M.focus()})},[]),us=R.length===0&&!y;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:pt,onScroll:Ct,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:[S&&e.jsx(Nr,{trigger:S,projectSlug:t}),y&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"})]}),us&&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/10 text-accent",children:e.jsx(Ps,{width:22,height:22})}),e.jsx("p",{className:"max-w-sm text-sm text-paddock-500",children:b??"Start the conversation. Messages stream live from Claude and persist as a resumable session."})]}),e.jsx(Ua.Provider,{value:he,children:e.jsx(Ba.Provider,{value:w,children:e.jsx(Os.Provider,{value:ut,children:e.jsx(Va.Provider,{value:Ft,children:e.jsx(za.Provider,{value:ss,children:e.jsx(Aa.Provider,{value:t,children:e.jsx(Us.Provider,{value:cs,children:e.jsx(Ha.Provider,{value:rs,children:e.jsx("div",{className:"space-y-4",children:R.map(j=>e.jsx(Po,{turn:j},j.id))})})})})})})})})})]})}),e.jsx(Gr,{running:Pt,activity:ut,onReveal:Ft.focus}),w&&e.jsx(no,{}),U&&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-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:U})]})}),Q!=null&&e.jsx(ro,{text:Q,onEdit:os,onClear:ls}),e.jsx("div",{className:"border-t border-paddock-200 bg-canvas/80 backdrop-blur dark:border-paddock-800 dark:bg-canvas-dark/80",children:e.jsxs("div",{className:"pb-safe mx-auto w-full max-w-3xl px-4 pt-3",children:[g&&e.jsx(eo,{checked:A,available:i,onChange:X}),e.jsx(to,{models:rt,model:Ce,onSelectModel:It,usage:Ie,sessionUsage:Ge,forkParent:h,onOpenForkParent:v}),Te&&(ae.length>0||Ve)&&e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2","data-testid":"attachment-tray",children:[ae.map(j=>e.jsx(jr,{attachment:j,onRemove:ts},j.id)),Ve&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-paddock-50 px-3 py-2 text-xs text-paddock-500 ring-1 ring-paddock-200/70 dark:bg-paddock-950 dark:ring-paddock-800",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-paddock-300 border-t-accent"}),"Uploading…"]})]}),e.jsxs("div",{className:`relative flex items-end gap-2 rounded-2xl border bg-white p-2 shadow-sm focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/20 dark:bg-paddock-900 ${ot?"border-accent ring-2 ring-accent/30":"border-paddock-300 dark:border-paddock-700"}`,onDragOver:Te?ct:void 0,onDragLeave:Te?dt:void 0,onDrop:Te?Nt: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/10 text-sm font-medium text-accent",children:"Drop files to attach"}),At&&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:He.map((j,M)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${M===je?"bg-paddock-100 dark:bg-paddock-800":""}`,onMouseEnter:()=>ee(M),onMouseDown:ye=>{ye.preventDefault(),St(j)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",j.name]}),j.argumentHint&&e.jsx("span",{className:"shrink-0 text-paddock-400",children:j.argumentHint}),j.description&&e.jsx("span",{className:"ml-auto truncate text-paddock-500",children:j.description})]})},j.name))}),e.jsx("textarea",{ref:P,className:"max-h-48 min-h-[40px] flex-1 resize-none bg-transparent px-2 py-2 text-sm outline-none placeholder:text-paddock-400 dark:placeholder:text-paddock-600",rows:1,autoCapitalize:"sentences",value:F,placeholder:w?"Queue a message to send next…":C??"Message Claude…",onChange:j=>{$(j.target.value);const M=j.target;M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,192)}px`},onKeyDown:xt,onPaste:Te?it:void 0}),Te&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:wt,type:"file",multiple:!0,accept:fr(lt.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:Dt}),e.jsx("button",{type:"button",onClick:()=>{var j;return(j=wt.current)==null?void 0:j.click()},title:"Attach files","aria-label":"Attach files","data-testid":"attachment-button",className:"btn bg-transparent text-paddock-500 hover:bg-paddock-100 hover:text-paddock-700 dark:text-paddock-400 dark:hover:bg-paddock-800",children:e.jsx(rn,{width:16,height:16})})]}),e.jsx(lr,{onText:ds}),w?e.jsxs("button",{type:"button",onClick:is,title:"Stop generating","aria-label":"Stop",className:"btn bg-paddock-200 text-paddock-700 hover:bg-paddock-300 dark:bg-paddock-800 dark:text-paddock-200 dark:hover:bg-paddock-700",children:[e.jsx(ws,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}):e.jsxs("button",{type:"button",onClick:Wt,disabled:!F.trim()&&ae.length===0||Ve,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(Ca,{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-[11px] text-paddock-400",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(oo,{state:D})]})]})}),e.jsx(qt,{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-ink dark:text-ink-dark",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-ink dark:text-ink-dark",children:[H.toolCount," tool call",H.toolCount===1?"":"s"]}),"."]}):"."]}),H.toolCount>0&&e.jsxs("p",{className:"mt-3 rounded-lg bg-amber-50 px-3 py-2 text-amber-800 dark:bg-amber-950/40 dark:text-amber-200",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:Bt,onClose:()=>Y(null)})]})}function Zo(t){var r;const s=t.untracked?"??":(t.status||"").trim(),a=((r=s[0])==null?void 0:r.toUpperCase())??"";return t.untracked||a==="?"?{label:"??",cls:"bg-paddock-200/70 text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300"}:a==="A"?{label:"A",cls:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400"}:a==="D"?{label:"D",cls:"bg-rose-100 text-rose-700 dark:bg-rose-950/50 dark:text-rose-400"}:a==="R"?{label:"R",cls:"bg-violet-100 text-violet-700 dark:bg-violet-950/50 dark:text-violet-400"}:a==="M"?{label:"M",cls:"bg-amber-100 text-amber-700 dark:bg-amber-950/50 dark:text-amber-400"}:{label:a||s||"•",cls:"bg-paddock-200/70 text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300"}}function el({slug:t,status:s,onStatusChange:a,selectedFile:r,onSelectFile:o}){var X;const[l,i]=n.useState(null),[c,m]=n.useState(null),h=o!==void 0,v=h?r??null:c,u=n.useCallback(g=>{h?o==null||o(g):m(g)},[h,o]),[b,C]=n.useState(""),[S,f]=n.useState(!1),[x,T]=n.useState(!1),[E,R]=n.useState(null),[k,F]=n.useState(null),[$,P]=n.useState(new Set),w=s.files,O=w.length,y=w.filter(g=>!$.has(g.path)).map(g=>g.path),B=y.length,U=B===w.length&&w.length>0,I=n.useCallback(g=>{P(Z=>{const re=new Set(Z);return re.has(g)?re.delete(g):re.add(g),re})},[]),D=n.useCallback(()=>P(new Set),[]),q=n.useCallback(()=>P(new Set(w.map(g=>g.path))),[w]),H=n.useCallback(async()=>{const g=await L.gitInfo().catch(()=>null);g&&i(g)},[]);n.useEffect(()=>{H()},[H]);const Y=n.useCallback(async()=>{const g=await L.gitStatus(t).catch(()=>null);g&&a(g)},[t,a]),Q=v&&w.some(g=>g.path===v)?v:((X=w[0])==null?void 0:X.path)??null,te=w.find(g=>g.path===Q)??null,ne=n.useCallback(async()=>{const g=b.trim();if(!(!g||S||y.length===0)){f(!0),R(null),F(null);try{const Z=U?await L.gitCommit(t,g):await L.gitCommit(t,g,y);Z.committed?(C(""),P(new Set),F(Z.hash?`Committed ${Z.hash.slice(0,7)}`:"Committed"),await Y(),await H()):F(Z.error??"Nothing to commit")}catch(Z){R(Z instanceof be?Z.message:"Commit failed")}finally{f(!1)}}},[b,S,y,U,t,Y,H]),se=(l==null?void 0:l.ahead)??0,de=(l==null?void 0:l.configured)??!1,p=de&&se>0&&!x,A=n.useCallback(async()=>{if(p){T(!0),R(null),F(null);try{const g=await L.gitPush();g.pushed?(F("Pushed to remote"),await H()):R(g.error??"Push failed")}catch(g){R(g instanceof be?g.message:"Push failed")}finally{T(!1)}}},[p,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-paddock-200 px-4 py-2.5 dark:border-paddock-800",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-medium text-paddock-700 dark:text-paddock-200",children:[e.jsx(Je,{width:14,height:14,className:"text-paddock-400"}),s.branch??"—"]}),s.clean?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-paddock-400",children:[e.jsx(nt,{width:12,height:12}),"clean"]}):e.jsxs("span",{className:"rounded-md bg-amber-100 px-1.5 py-0.5 text-[11px] font-medium text-amber-700 dark:bg-amber-950/50 dark:text-amber-400",children:[O," uncommitted"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(ol,{info:l,onChanged:H}),e.jsxs("button",{type:"button",onClick:()=>void A(),disabled:!p,title:de?se>0?`Push ${se} commit${se===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx(on,{width:13,height:13}),x?"Pushing…":"Push",de&&se>0&&e.jsxs("span",{className:"text-[11px] font-semibold text-accent",children:["↑",se]})]})]})]}),(E||k)&&e.jsxs("div",{className:"px-4 pt-2",children:[E&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:E})]}),!E&&k&&e.jsx("p",{className:"text-xs text-paddock-500",children:k})]}),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-paddock-200 dark:border-paddock-800 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-[11px] text-paddock-400",children:[e.jsxs("span",{children:[B,"/",w.length," selected"]}),e.jsx("button",{type:"button",onClick:U?q:D,className:"rounded px-1 py-0.5 font-medium text-accent hover:bg-accent/10",title:U?"Deselect all files":"Select all files",children:U?"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-paddock-400",children:"No uncommitted changes. Files you author surface here for a checkpoint."}):w.map(g=>e.jsx(tl,{file:g,active:Q===g.path,selected:!$.has(g.path),onSelect:()=>u(g.path),onToggleSelect:()=>I(g.path)},g.path))}),e.jsxs("div",{className:"border-t border-paddock-200 p-3 dark:border-paddock-800",children:[e.jsx("textarea",{rows:2,value:b,placeholder:"Commit message…",onChange:g=>C(g.target.value),className:"max-h-40 min-h-[44px] w-full resize-none rounded-lg border border-paddock-300 bg-paddock-50 px-2.5 py-2 text-sm outline-none transition-colors placeholder:text-paddock-400 focus:border-accent focus:ring-2 focus:ring-accent/20 dark:border-paddock-700 dark:bg-paddock-950 dark:placeholder:text-paddock-600"}),e.jsxs("button",{type:"button",onClick:()=>void ne(),disabled:!b.trim()||S||B===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:w.length===0?"Nothing to commit":B===0?"Select at least one file to commit":U?"Commit all changed files":`Commit ${B} selected file${B===1?"":"s"}`,children:[e.jsx(nt,{width:13,height:13}),S?"Committing…":B>0&&!U?`Commit ${B} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(sl,{slug:t,file:te})})]})]})}function Vs({file:t}){if(t.binary)return e.jsx("span",{className:"text-paddock-400",children:"binary"});const{added:s,removed:a}=t;return s==null&&a==null?null:!s&&!a?e.jsx("span",{className:"text-paddock-400",children:"0"}):e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[s?e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",s]}):null,a?e.jsxs("span",{className:"text-rose-600 dark:text-rose-400",children:["−",a]}):null]})}function tl({file:t,active:s,selected:a,onSelect:r,onToggleSelect:o}){const l=Zo(t),i=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-paddock-200/80 dark:bg-paddock-800":"hover:bg-paddock-200/50 dark:hover:bg-paddock-800/50"}`,children:[e.jsx("input",{type:"checkbox",checked:a,onChange:o,"aria-label":`Stage ${t.path}`,title:a?"Included in commit — click to exclude":"Excluded — click to include",className:"h-3.5 w-3.5 shrink-0 cursor-pointer accent-accent"}),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-[10px] font-semibold ${l.cls}`,children:l.label}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-mono text-[12.5px] text-paddock-700 dark:text-paddock-200",children:t.path}),e.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-paddock-400",children:[e.jsx("span",{children:i}),e.jsx(Vs,{file:t})]})]})]})]})}function sl({slug:t,file:s}){const a=(s==null?void 0:s.path)??null,r=(s==null?void 0:s.untracked)??!1,[o,l]=n.useState(""),[i,c]=n.useState(!1),[m,h]=n.useState(null);if(n.useEffect(()=>{if(!a||r){l(""),h(null),c(!1);return}let u=!1;return c(!0),h(null),L.gitDiff(t,a).then(b=>{u||l(b)}).catch(b=>{u||h(b instanceof be?b.message:"Failed to load diff")}).finally(()=>{u||c(!1)}),()=>{u=!0}},[t,a,r]),!s)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-sm text-paddock-400",children:"Select a file to view its diff."});if(r)return e.jsx(rl,{slug:t,file:s});if(i)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-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"})]});if(m)return e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:m})]})});if(!o.trim())return e.jsxs("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm text-paddock-400",children:["No textual diff for this file",e.jsx("br",{}),"(e.g. a mode or binary change)."]});const v=o.split(`
|
|
10
|
-
`);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(al,{file:s}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-paddock-50/60 dark:bg-paddock-950/60",children:e.jsx("pre",{className:"min-w-full whitespace-pre px-4 py-3 font-mono text-[12px] leading-relaxed",children:v.map((u,b)=>e.jsx("div",{className:nl(u),children:u||" "},b))})})]})}function al({file:t}){return e.jsxs("div",{className:"flex items-center gap-2 border-b border-paddock-200 bg-paddock-50/60 px-4 py-2 text-[11px] text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/40",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-paddock-600 dark:text-paddock-300",children:t.path}),e.jsx(Vs,{file:t})]})}function nl(t){return t.startsWith("+++")||t.startsWith("---")||t.startsWith("diff ")||t.startsWith("index ")?"text-paddock-400":t.startsWith("@@")?"text-violet-600 dark:text-violet-400":t.startsWith("+")?"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400":t.startsWith("-")?"bg-rose-500/10 text-rose-700 dark:text-rose-400":"text-paddock-600 dark:text-paddock-300"}function rl({slug:t,file:s}){const a=s.path,[r,o]=n.useState(null),[l,i]=n.useState(!0),[c,m]=n.useState(null);n.useEffect(()=>{let v=!1;return i(!0),m(null),o(null),L.getProjectFile(t,a).then(u=>{v||o(u)}).catch(u=>{v||m(u instanceof be?u.message:"Failed to load file")}).finally(()=>{v||i(!1)}),()=>{v=!0}},[t,a]);const h=e.jsxs("div",{className:"flex items-center gap-2 border-b border-paddock-200 bg-paddock-50/60 px-4 py-2 text-[11px] text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/40",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-paddock-600 dark:text-paddock-300",children:a}),e.jsx(Vs,{file:s}),e.jsx("span",{className:"rounded bg-emerald-100 px-1.5 py-0.5 font-medium text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400",children:"new file · untracked"})]});return l?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"})]}):c||!r?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{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:[h,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:L.projectFileRawUrl(t,a),alt:a,className:"max-h-full max-w-full object-contain shadow-sm"})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[h,e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-paddock-50/60 dark:bg-paddock-950/60",children:e.jsx("pre",{className:"min-w-full whitespace-pre-wrap break-words border-l-2 border-emerald-500/40 px-4 py-3 font-mono text-[12px] leading-relaxed text-paddock-700 dark:text-paddock-200",children:r.content})})]})}function ol({info:t,onChanged:s}){const[a,r]=n.useState(!1),[o,l]=n.useState(null),[i,c]=n.useState(!1),[m,h]=n.useState(null),[v,u]=n.useState(!1),b=n.useRef(!1);n.useEffect(()=>(b.current=!1,()=>{b.current=!0}),[]);const C=t==null?void 0:t.github,S=n.useCallback(async()=>{r(!0),h(null);try{const x=await L.githubConnect();l({userCode:x.userCode,verificationUri:x.verificationUri}),c(!0),b.current=!1;const T=Date.now()+x.expiresIn*1e3;let E=Math.max(1,x.interval)*1e3;const R=async()=>{if(!b.current){if(Date.now()>=T){c(!1),l(null),h("The code expired before authorization. Try again.");return}try{const k=await L.githubPoll(x.deviceCode);if(b.current)return;if(k.status==="authorized"){c(!1),l(null),await s();return}if(k.status==="error"){c(!1),l(null),h(k.error??"Authorization failed.");return}k.status==="slow_down"&&(E+=5e3),window.setTimeout(()=>void R(),E)}catch(k){if(b.current)return;c(!1),l(null),h(k instanceof be?k.message:"Polling failed.")}}};window.setTimeout(()=>void R(),E)}catch(x){h(x instanceof be?x.message:"Could not start the GitHub connection.")}finally{r(!1)}},[s]),f=n.useCallback(async()=>{u(!0);try{await L.githubDisconnect(),await s()}catch{}finally{u(!1)}},[s]);return C?C.configured?C.connected?e.jsxs("span",{className:"inline-flex items-center gap-2 text-[11px] text-paddock-500",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400",children:[e.jsx(ps,{width:13,height:13}),"@",C.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void f(),disabled:v,className:"btn-subtle px-2 py-1 text-[11px]",title:"Disconnect GitHub",children:v?"…":"Disconnect"})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[o?e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5 text-[11px] text-paddock-500",children:[e.jsx("span",{className:"text-paddock-500",children:"Enter"}),e.jsx("code",{className:"rounded bg-paddock-200/80 px-1.5 py-0.5 font-mono text-[12px] font-semibold tracking-widest text-paddock-800 dark:bg-paddock-800 dark:text-paddock-100",children:o.userCode}),e.jsx("span",{className:"text-paddock-500",children:"at"}),e.jsxs("a",{href:o.verificationUri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-accent underline underline-offset-2 hover:text-accent-600",children:[e.jsx(ya,{width:11,height:11}),"github.com"]}),i&&e.jsx("span",{className:"text-paddock-400",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void S(),disabled:a,className:"btn-ghost py-1.5 text-xs",title:"Authorize paddock to push to GitHub on your behalf (device flow).",children:[e.jsx(ps,{width:13,height:13}),a?"Starting…":"Connect GitHub"]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-rose-600 dark:text-rose-400",children:[e.jsx(ce,{width:12,height:12}),m]})]}):e.jsxs("span",{className:"hidden items-center gap-1.5 text-[11px] text-paddock-400 sm:inline-flex",title:"Set PADDOCK_GITHUB_CLIENT_ID on the server to enable in-app GitHub auth.",children:[e.jsx(ps,{width:13,height:13}),"GitHub not configured"]}):null}function ll(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(Qe,{width:12,height:12}),cls:"bg-amber-100 text-amber-700 dark:bg-amber-950/50 dark:text-amber-400"}:t==="spawned"?{label:"Spawned",icon:e.jsx(Je,{width:12,height:12}),cls:"bg-violet-100 text-violet-700 dark:bg-violet-950/50 dark:text-violet-400"}:t==="adopted"?{label:"Imported",icon:e.jsx(Ls,{width:12,height:12}),cls:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400"}:{label:"You",icon:e.jsx(Qt,{width:12,height:12}),cls:"bg-paddock-200/70 text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300"}}function il(t){switch(t){case"completed":return{label:"completed",cls:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400"};case"failed":return{label:"failed",cls:"bg-rose-100 text-rose-700 dark:bg-rose-950/50 dark:text-rose-400"};case"running":return{label:"running",cls:"bg-sky-100 text-sky-700 dark:bg-sky-950/50 dark:text-sky-400"};case"cancelled":return{label:"cancelled",cls:"bg-paddock-200/70 text-paddock-500 dark:bg-paddock-800 dark:text-paddock-400"};case"pending":return{label:"pending",cls:"bg-amber-100 text-amber-700 dark:bg-amber-950/50 dark:text-amber-400"};default:return{label:t,cls:"bg-paddock-200/70 text-paddock-500 dark:bg-paddock-800 dark:text-paddock-400"}}}function cl(t){if(t.durationSeconds!=null)return Kt(t.durationSeconds*1e3)??"—";if(t.status==="running"){const s=Date.parse(t.startedAt);if(Number.isFinite(s))return`${Kt(Date.now()-s)??"—"}…`}return"—"}function gs(t){return t.origin!=="human"&&t.origin!=="adopted"}function dl(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"?"imported from the Claude Code CLI":"you"}function ul({run:t,title:s,onOpen:a}){var c,m;const r=ll(t.origin),o=il(t.status),l=t.sessionId!=null,i=((c=t.prompt)==null?void 0:c.trim())||((m=t.summary)==null?void 0:m.trim())||s;return e.jsxs("button",{type:"button",onClick:l?a:void 0,disabled:!l,"data-run-origin":t.origin,"data-run-new":t.isNew?"true":void 0,className:`flex w-full items-start gap-3 border-t border-paddock-200 px-4 py-3 text-left first:border-t-0 dark:border-paddock-800 ${l?"hover:bg-paddock-100/70 dark:hover:bg-paddock-900/40":"cursor-default"} ${t.isNew?"bg-accent/[0.06]":""}`,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"})}),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-[11px] 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-[11px] font-medium ${o.cls}`,children:o.label})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-ink dark:text-ink-dark",children:i}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-paddock-500 dark:text-paddock-400",children:dl(t)})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-0.5 text-xs text-paddock-500 dark:text-paddock-400",children:[e.jsx("span",{title:new Date(t.startedAt).toLocaleString(),children:vt(t.startedAt)}),e.jsx("span",{className:"font-mono",children:cl(t)}),e.jsx("span",{className:"font-mono text-paddock-400 dark:text-paddock-600",title:"Per-run cost is coming soon",children:"—"})]})]})}function ml({slug:t,state:s,chats:a,onOpenChat:r}){const{data:o,loading:l,error:i,refresh:c,markSeen:m}=s,[h,v]=n.useState("unattended");n.useEffect(()=>{m()},[t]);const u=n.useMemo(()=>{const x=new Map;for(const T of a)x.set(T.sessionId,T.name);return T=>T&&x.get(T)||(T?T.slice(0,8):"unknown chat")},[a]),b=(o==null?void 0:o.runs)??[],C=n.useMemo(()=>b.filter(gs).length,[b]),S=n.useMemo(()=>h==="unattended"?b.filter(gs):b,[b,h]),f=n.useMemo(()=>b.filter(x=>x.isNew&&gs(x)).length,[b]);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-paddock-200 px-4 py-3 dark:border-paddock-800",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-ink dark:text-ink-dark",children:"Run history"}),e.jsx("button",{type:"button",onClick:()=>void c(),className:"text-xs text-paddock-500 hover:text-paddock-700 dark:text-paddock-400 dark:hover:text-paddock-200",children:"Refresh"})]}),e.jsxs("div",{className:"inline-flex overflow-hidden rounded-lg border border-paddock-200 text-xs dark:border-paddock-800",children:[e.jsxs(ha,{active:h==="unattended",onClick:()=>v("unattended"),children:["Unattended",C>0?` (${C})`:""]}),e.jsx(ha,{active:h==="all",onClick:()=>v("all"),children:"All"})]})]}),f>0&&e.jsxs("div",{"data-since-last-visit":f,className:"border-b border-accent/30 bg-accent/[0.08] px-4 py-2 text-sm text-ink dark:text-ink-dark",children:[e.jsxs("span",{className:"font-medium",children:[f," new ",f===1?"run":"runs"]})," ","ran while you were away."]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:i?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-rose-600 dark:text-rose-400",children:i}):l&&b.length===0?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-paddock-500 dark:text-paddock-400",children:"Loading run history…"}):S.length===0?e.jsx(pl,{filter:h,hasAny:b.length>0}):e.jsx("div",{children:S.map(x=>e.jsx(ul,{run:x,title:u(x.sessionId),onOpen:()=>x.sessionId&&r(x.sessionId)},x.jobId))})})]})}function ha({active:t,onClick:s,children:a}){return e.jsx("button",{type:"button",onClick:s,className:`px-2.5 py-1 font-medium transition-colors ${t?"bg-accent/15 text-accent-700 dark:text-accent":"text-paddock-500 hover:text-paddock-700 dark:text-paddock-400 dark:hover:text-paddock-200"}`,children:a})}function pl({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-ink dark:text-ink-dark",children:t==="unattended"?"No unattended runs yet":"No runs yet"}),e.jsx("p",{className:"mx-auto mt-1 max-w-sm text-xs text-paddock-500 dark:text-paddock-400",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 hl(t){const[s,a]=n.useState(null),[r,o]=n.useState(!0),[l,i]=n.useState(null),[c,m]=n.useState(!1),h=n.useCallback(async()=>{o(!0),m(!1);try{const b=await L.projectRuns(t);a(b),i(null)}catch(b){i(b instanceof Error?b.message:"Failed to load run history")}finally{o(!1)}},[t]);n.useEffect(()=>{h()},[h]);const v=n.useCallback(async()=>{m(!0),await L.markRunsSeen(t).catch(()=>{})},[t]),u=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:r,error:l,newUnattended:u,refresh:h,markSeen:v}}function xl({slug:t,name:s}){const[a,r]=n.useState(null),[o,l]=n.useState(null),[i,c]=n.useState(!0);return n.useEffect(()=>{let m=!1;return c(!0),l(null),r(null),L.getProjectFile(t,s).then(h=>{m||r(h)}).catch(h=>{m||l(h instanceof Error?h.message:"Failed to load file")}).finally(()=>{m||c(!1)}),()=>{m=!0}},[t,s]),i?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-4 w-1/3 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-paddock-200/70 dark:bg-paddock-800/70"})]}):o||!a?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:o??"File not found."})]})}):a.kind==="image"?e.jsx(kl,{slug:t,name:a.name}):a.kind==="html"?e.jsx(fl,{name:a.name,content:a.content}):a.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-paddock-200 bg-paddock-50 p-4 font-mono text-[12.5px] leading-relaxed text-paddock-800 dark:border-paddock-800 dark:bg-paddock-950 dark:text-paddock-200",children:a.content})}):e.jsx("article",{className:"prose-doc mx-auto max-w-3xl px-6 py-6",children:e.jsx(_t,{mermaid:!0,children:a.content})})}function fl({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-paddock-200 bg-paddock-50/60 px-4 py-2 text-[11px] text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/40",children:[e.jsx(gl,{}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-paddock-600 dark:text-paddock-300",children:t})," renders in a sandboxed frame (scripts allowed, isolated from the app)."]})]}),e.jsx("iframe",{title:t,sandbox:"allow-scripts",srcDoc:s,className:"min-h-[480px] w-full flex-1 bg-white"})]})}function kl({slug:t,name:s}){const[a,r]=n.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-paddock-200 bg-paddock-50/60 px-4 py-2 text-[11px] text-paddock-500 dark:border-paddock-800 dark:bg-paddock-900/40",children:e.jsx("span",{className:"font-mono text-paddock-600 dark:text-paddock-300",children:s})}),e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",style:{background:"repeating-conic-gradient(rgb(0 0 0 / 0.06) 0% 25%, transparent 0% 50%) 50% / 20px 20px"},children:a?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:L.projectFileRawUrl(t,s),alt:s,onError:()=>r(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function gl(){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-paddock-400",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"})})}function bl({project:t,path:s,onNavigate:a,onTogglePin:r}){const o=t.slug,[l,i]=n.useState(null),[c,m]=n.useState(!1),[h,v]=n.useState(null),[u,b]=n.useState(!0);n.useEffect(()=>{let x=!1;return b(!0),v(null),i(null),m(!1),L.listProjectDir(o,s).then(T=>{x||(T.kind==="file"?m(!0):i(T))}).catch(T=>{x||v(T instanceof Error?T.message:"Failed to load files")}).finally(()=>{x||b(!1)}),()=>{x=!0}},[o,s]);const C=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",S=e.jsx(jl,{path:s,isFile:c,onNavigate:a});if(u)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[S,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(x=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-paddock-200/60 dark:bg-paddock-800/60"},x))})]})});if(h)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:[S,e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-300/60 bg-rose-50 px-3 py-2 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/50 dark:text-rose-300",children:[e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:h})]})]})});if(c){const x=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-paddock-200 px-4 py-2 dark:border-paddock-800",children:[e.jsx("div",{className:"min-w-0 flex-1",children:S}),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 ${x?"bg-accent/10 text-accent":"text-paddock-500 hover:bg-paddock-200/60 dark:hover:bg-paddock-800/60"}`,title:x?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(Rt,{width:13,height:13}),x?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(xl,{slug:o,name:s})})]})}const f=(l==null?void 0:l.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:[S,f.length===0&&s===""?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-paddock-400",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-paddock-200 dark:border-paddock-800",children:[s!==""&&e.jsxs("button",{onClick:()=>a(C),className:"flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-paddock-100/70 dark:hover:bg-paddock-900/40",children:[e.jsx(Ns,{width:15,height:15,className:"shrink-0 text-paddock-400"}),e.jsx("span",{className:"font-mono text-sm text-paddock-500",children:".."})]}),f.length===0&&s!==""&&e.jsx("div",{className:"px-3 py-2.5 text-sm italic text-paddock-400",children:"This folder is empty."}),f.map((x,T)=>{const E=s?`${s}/${x.name}`:x.name,R=x.kind==="dir",k=t.pinned.includes(E),F=!R,$=T>0||s!==""?"border-t border-paddock-200 dark:border-paddock-800":"";return e.jsxs("div",{className:`group/file flex items-center gap-2 px-3 py-2.5 transition-colors hover:bg-paddock-100/70 dark:hover:bg-paddock-900/40 ${$}`,children:[e.jsxs("button",{onClick:()=>a(E),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[R?e.jsx(Ns,{width:15,height:15,className:"shrink-0 text-accent/80"}):e.jsx($t,{width:15,height:15,className:"shrink-0 text-paddock-400"}),e.jsx("span",{className:`truncate font-mono text-sm ${R?"font-medium text-paddock-700 dark:text-paddock-200":"text-paddock-700 dark:text-paddock-200"}`,children:x.name}),R&&e.jsx(Xt,{width:14,height:14,className:"ml-auto shrink-0 text-paddock-300 dark:text-paddock-600"})]}),F&&e.jsxs("button",{type:"button","aria-label":k?`Unpin ${x.name}`:`Pin ${x.name}`,title:k?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>r(E),className:`flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[11px] font-medium transition ${k?"bg-accent/10 text-accent":"text-paddock-400 opacity-0 hover:bg-paddock-200/70 hover:text-paddock-700 focus:opacity-100 group-hover/file:opacity-100 dark:hover:bg-paddock-800"}`,children:[e.jsx(Rt,{width:12,height:12}),k?"Pinned":"Pin"]})]},x.name)})]})]})})}function jl({path:t,isFile:s,onNavigate:a}){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(xa,{label:"Files",isLast:r.length===0,onClick:()=>a("")}),r.map((o,l)=>{const i=l===r.length-1,c=r.slice(0,l+1).join("/");return e.jsxs("span",{className:"flex items-center gap-x-1",children:[e.jsx(Xt,{width:13,height:13,className:"shrink-0 text-paddock-300 dark:text-paddock-600"}),e.jsx(xa,{label:o,isLast:i,mono:!0,muted:i&&s,onClick:()=>a(c)})]},c)})]})}function xa({label:t,isLast:s,mono:a,muted:r,onClick:o}){const l=a?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${l} font-medium ${r?"text-paddock-500 dark:text-paddock-400":"text-ink dark:text-ink-dark"}`,children:t}):e.jsx("button",{type:"button",onClick:o,className:`${l} rounded text-paddock-500 transition-colors hover:text-accent`,children:t})}const vl=["idea","active","paused","blocked","done","abandoned"];function bs(t,s,a){const r={};return t!==""&&(r.overviewMaxTokens=Number(t)),s!==""&&(r.changelogMaxTokens=Number(s)),a!==""&&(r.claudeMaxTokens=Number(a)),Object.keys(r).length>0?r:null}const fa=[{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)"}];function bt({title:t,description:s,children:a}){return e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wide text-paddock-500",children:t}),s&&e.jsx("p",{className:"mb-3 mt-0.5 text-[13px] text-paddock-500",children:s}),e.jsx("div",{className:`card ${s?"":"mt-2"}`,children:a})]})}function xe({children:t}){return e.jsx("p",{className:"mt-1 text-[12px] leading-snug text-paddock-500",children:t})}function ka({children:t}){return e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-[12px] leading-snug text-amber-600 dark:text-amber-400",children:[e.jsx(ce,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t})]})}function jt({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-[11px] font-semibold uppercase tracking-wide text-paddock-400",children:t}),e.jsx("dd",{className:"mt-0.5 text-sm text-paddock-700 dark:text-paddock-300",children:s})]})}function wl({project:t,onSaved:s}){const[a,r]=n.useState(""),[o,l]=n.useState(!1),[i,c]=n.useState(!1),[m,h]=n.useState(null);if(n.useEffect(()=>{r(""),l(!1),h(null)},[t.slug,t.repoBacked]),t.repoBacked)return e.jsx(bt,{title:"Repository backing",description:"This project is backed by an external git repo — Claude works in a checkout of it.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3",children:[e.jsx(jt,{label:"Repository",value:e.jsx("span",{className:"break-all font-mono text-[13px]",children:t.repo})}),e.jsx(jt,{label:"Working directory",value:e.jsx("span",{className:"break-all font-mono text-[13px]",children:t.workingDir})})]})});const v=a.trim(),u=v.length>0&&!Nl(v),b=async()=>{if(!(!v||u)){c(!0),h(null);try{const C=await L.promoteProject(t.slug,v);s(C),l(!1),r("")}catch(C){h(C instanceof be?C.message:"Failed to promote project")}finally{c(!1)}}};return e.jsxs(bt,{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-[13px]",value:a,onChange:C=>{r(C.target.value),l(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":u,"aria-label":"Git repository URL"}),u?e.jsx(xe,{children:e.jsx("span",{className:"text-rose-600 dark:text-rose-400",children:"That doesn’t look like a git URL (https://, git@…, ssh://, git://)."})}):e.jsxs(xe,{children:["Paddock clones this repo into a nested checkout and points Claude at it. The repo’s own ",e.jsx("code",{children:"CLAUDE.md"})," and git tooling take over."]})]}),m&&e.jsx("p",{className:"mt-3 rounded-lg bg-rose-50 px-3 py-2 text-sm text-rose-600 dark:bg-rose-950/40 dark:text-rose-300",children:m}),o?e.jsxs("div",{className:"mt-4 rounded-lg border border-amber-300 bg-amber-50 p-3 dark:border-amber-800/60 dark:bg-amber-950/30",children:[e.jsxs("p",{className:"flex items-start gap-1.5 text-[13px] leading-snug text-amber-700 dark:text-amber-300",children:[e.jsx(ce,{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:v}),", 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:i,onClick:b,children:i?"Promoting…":"Yes, promote"}),e.jsx("button",{type:"button",className:"btn-subtle",disabled:i,onClick:()=>l(!1),children:"Cancel"})]})]}):e.jsx("button",{type:"button",className:"btn-primary mt-4",disabled:i||!v||u,onClick:()=>l(!0),children:"Promote to repo-backed…"})]})}function Nl(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}function yl({project:t,onSaved:s}){var Xe,rt,ve;const[a,r]=n.useState(t.name),[o,l]=n.useState(t.summary),[i,c]=n.useState(t.domain.join(", ")),[m,h]=n.useState(t.group??""),[v,u]=n.useState(t.status),[b,C]=n.useState(t.visibility),[S,f]=n.useState(t.links??[]),[x,T]=n.useState(t.model),[E,R]=n.useState(t.models??[]),[k,F]=n.useState(t.permissionMode),[$,P]=n.useState(String(t.maxTurns)),[w,O]=n.useState(t.docker),[y,B]=n.useState(t.driveMode??""),[U,I]=n.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[D,q]=n.useState(((Xe=t.curation)==null?void 0:Xe.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[H,Y]=n.useState(((rt=t.curation)==null?void 0:rt.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[Q,te]=n.useState(((ve=t.curation)==null?void 0:ve.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[ne,se]=n.useState([]),[de,p]=n.useState("batch"),[A,X]=n.useState(1),[g,Z]=n.useState({overviewMaxTokens:2e3,changelogMaxTokens:8e3,claudeMaxTokens:6e3}),[re,$e]=n.useState(!1),[me,ie]=n.useState(null),[Ce,Me]=n.useState(0);n.useEffect(()=>{var N,J,ae;r(t.name),l(t.summary),c(t.domain.join(", ")),h(t.group??""),u(t.status),C(t.visibility),f(t.links??[]),T(t.model),R(t.models??[]),F(t.permissionMode),P(String(t.maxTurns)),O(t.docker),B(t.driveMode??""),I(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),q(((N=t.curation)==null?void 0:N.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),Y(((J=t.curation)==null?void 0:J.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),te(((ae=t.curation)==null?void 0:ae.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),ie(null)},[t]),n.useEffect(()=>{let N=!1;return L.getModels().then(J=>{N||(se(J.models),p(J.driveModeDefault),X(J.maxSpawnDepthDefault),Z(J.curationDefault))}).catch(()=>{}),()=>{N=!0}},[]);const fe=n.useMemo(()=>S.map(N=>({label:N.label.trim(),url:N.url.trim()})).filter(N=>N.url.length>0),[S]),pe=n.useMemo(()=>i.split(",").map(N=>N.trim()).filter(Boolean),[i]),we=n.useMemo(()=>({name:a.trim(),status:v,group:m,summary:o.trim(),domain:pe,visibility:b,links:fe,model:x,models:E.length>0?E:null,permissionMode:k,maxTurns:Number($),docker:w,driveMode:y===""?null:y,maxSpawnDepth:U===""?null:Number(U),curation:bs(D,H,Q)}),[a,v,m,o,pe,b,fe,x,E,k,$,w,y,U,D,H,Q]),_e=n.useMemo(()=>{var J,ae,z;const N={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(Ne=>({label:Ne.label,url:Ne.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:bs(((J=t.curation)==null?void 0:J.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ae=t.curation)==null?void 0:ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((z=t.curation)==null?void 0:z.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify(we)!==JSON.stringify(N)},[we,t]),Ee=we.name.length===0,Se=Number($),je=!Number.isInteger(Se)||Se<1||Se>1e3,ee=Number(U),De=U!==""&&(!Number.isInteger(ee)||ee<0||ee>8),K=N=>N!==""&&(!Number.isInteger(Number(N))||Number(N)<1),ue=K(D)||K(H)||K(Q),Ie=async N=>{if(N.preventDefault(),!(Ee||je||De||ue)){$e(!0),ie(null);try{const J=await L.updateProject(t.slug,we);s(J),Me(ae=>ae+1)}catch(J){ie(J instanceof be?J.message:"Failed to save changes")}finally{$e(!1)}}},Pe=de==="session"?"Session":"Batch",Ge=E.length>0?ne.filter(N=>E.includes(N.id)):ne,Oe=(N,J)=>R(ae=>J?[...ae.filter(z=>z!==N),N]:ae.filter(z=>z!==N));return e.jsxs("form",{onSubmit:Ie,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-paddock-200 bg-canvas/80 px-4 py-2.5 backdrop-blur dark:border-paddock-800 dark:bg-paddock-900/60 sm:px-6",children:[e.jsx("span",{className:"text-sm font-medium text-paddock-700 dark:text-paddock-200",children:"Settings"}),_e&&!re&&e.jsx("span",{className:"text-[12px] text-amber-600 dark:text-amber-400",children:"Unsaved changes"}),Ce>0&&!_e&&!re&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[12px] text-emerald-600 dark:text-emerald-400",children:[e.jsx(nt,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:re||!_e||Ee||je||De||ue,children:re?"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:[me&&e.jsx("p",{className:"mb-4 rounded-lg bg-rose-50 px-3 py-2 text-sm text-rose-600 dark:bg-rose-950/40 dark:text-rose-300",children:me}),e.jsxs(bt,{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:a,onChange:N=>r(N.target.value),placeholder:"Display name","aria-invalid":Ee}),Ee&&e.jsx(xe,{children:"Name can’t be empty."})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary"}),e.jsx("input",{className:"input",value:o,onChange:N=>l(N.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:v,onChange:N=>u(N.target.value),children:vl.map(N=>e.jsx("option",{value:N,className:"capitalize",children:N},N))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:m,onChange:N=>h(N.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),ys.map(N=>e.jsx("option",{value:N.slug,children:N.label},N.slug)),m&&!ys.some(N=>N.slug===m)&&e.jsx("option",{value:m,children:m})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Visibility"}),e.jsxs("select",{className:"input capitalize",value:b,onChange:N=>C(N.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:i,onChange:N=>c(N.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),S.length===0&&e.jsx("p",{className:"mb-2 text-[12px] italic text-paddock-400",children:"No links yet."}),e.jsx("div",{className:"space-y-2",children:S.map((N,J)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:N.label,onChange:ae=>f(z=>z.map((Ne,Ve)=>Ve===J?{...Ne,label:ae.target.value}:Ne)),placeholder:"Label","aria-label":`Link ${J+1} label`}),e.jsx("input",{className:"input flex-1",value:N.url,onChange:ae=>f(z=>z.map((Ne,Ve)=>Ve===J?{...Ne,url:ae.target.value}:Ne)),placeholder:"https://…","aria-label":`Link ${J+1} URL`}),e.jsx("button",{type:"button",onClick:()=>f(ae=>ae.filter((z,Ne)=>Ne!==J)),"aria-label":`Remove link ${J+1}`,title:"Remove link",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-paddock-400 transition hover:bg-rose-100 hover:text-rose-600 dark:hover:bg-rose-950/60 dark:hover:text-rose-400",children:e.jsx(Fs,{width:14,height:14})})]},J))}),e.jsxs("button",{type:"button",onClick:()=>f(N=>[...N,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(at,{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-paddock-200 pt-4 sm:grid-cols-3 dark:border-paddock-800",children:[e.jsx(jt,{label:"Slug",value:e.jsx("span",{className:"font-mono",children:t.slug})}),e.jsx(jt,{label:"Started",value:t.started})]})]}),e.jsx(bt,{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:x,onChange:N=>T(N.target.value),children:[!Ge.some(N=>N.id===x)&&e.jsx("option",{value:x,children:x}),Ge.map(N=>e.jsx("option",{value:N.id,children:N.label},N.id))]})]}),e.jsx(xe,{children:"Larger context windows (Opus/Fable/Sonnet: 1M; Haiku: 200K) fit longer chats."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsxs("select",{className:"input",value:k,onChange:N=>F(N.target.value),children:[!fa.some(N=>N.value===k)&&e.jsx("option",{value:k,children:k}),fa.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value))]})]}),k==="bypassPermissions"?e.jsx(ka,{children:"Claude runs every tool without asking — it can edit files and run commands unprompted."}):e.jsx(xe,{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:$,onChange:N=>P(N.target.value),"aria-invalid":je})]}),je?e.jsx(xe,{children:e.jsx("span",{className:"text-rose-600 dark:text-rose-400",children:"Must be a whole number 1–1000."})}):e.jsx(xe,{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-accent",checked:w,onChange:N=>O(N.target.checked)}),e.jsx("span",{className:"text-sm text-paddock-700 dark:text-paddock-200",children:"Run Claude in a Docker sandbox"})]}),w?e.jsx(ka,{children:"Requires a working Docker daemon on the box, or Claude won’t start."}):e.jsx(xe,{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-[12px] italic text-paddock-400",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(N=>{const J=E.length===0||E.includes(N.id);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 text-sm text-paddock-700 dark:text-paddock-200",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-accent",checked:J,onChange:ae=>{E.length===0?R(ae.target.checked?[]:ne.filter(z=>z.id!==N.id).map(z=>z.id)):Oe(N.id,ae.target.checked)},"aria-label":N.label}),e.jsx("span",{children:N.label})]},N.id)})}),E.length===0?e.jsx(xe,{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(xe,{children:["Restricting this project's picker to ",E.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:y,onChange:N=>B(N.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",Pe,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),y===""?e.jsxs(xe,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-paddock-700 dark:text-paddock-200",children:Pe}),". ",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(xe,{children:["Overriding the global default."," ",e.jsx("button",{type:"button",onClick:()=>B(""),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:U,onChange:N=>I(N.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",A,")"]}),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"})]})]}),U===""?e.jsxs(xe,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-paddock-700 dark:text-paddock-200",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(xe,{children:["Overriding the instance default."," ",e.jsx("button",{type:"button",onClick:()=>I(""),className:"font-medium text-accent hover:underline",children:"Reset to instance default"}),"."]})]})]})}),e.jsxs(bt,{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 (${g.overviewMaxTokens})`,value:D,onChange:N=>q(N.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 (${g.changelogMaxTokens})`,value:H,onChange:N=>Y(N.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 (${g.claudeMaxTokens})`,value:Q,onChange:N=>te(N.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),ue?e.jsx(xe,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):bs(D,H,Q)?e.jsxs(xe,{children:["Overriding the instance defaults (",g.overviewMaxTokens,"/",g.changelogMaxTokens,"/",g.claudeMaxTokens,") for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{q(""),Y(""),te("")},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."]}):e.jsxs(xe,{children:["Inheriting the instance defaults:"," ",e.jsxs("span",{className:"font-medium text-paddock-700 dark:text-paddock-200",children:[g.overviewMaxTokens,"/",g.changelogMaxTokens,"/",g.claudeMaxTokens]})," ","tokens (OVERVIEW/CHANGELOG/CLAUDE). Lower a budget to shrink the context this project injects into every chat."]})]}),e.jsx(wl,{project:t,onSaved:s}),e.jsx(bt,{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(jt,{label:"Overview",value:t.hasOverview?e.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400",children:[e.jsx(nt,{width:12,height:12})," OVERVIEW.md written by a sweep"]}):e.jsx("span",{className:"text-paddock-400",children:"No OVERVIEW.md yet"})}),e.jsx(jt,{label:"Pinned files",value:t.pinned.length>0?e.jsx("span",{className:"flex flex-wrap gap-1.5",children:t.pinned.map(N=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-paddock-100 px-1.5 py-0.5 font-mono text-[12px] text-paddock-700 dark:bg-paddock-900 dark:text-paddock-300",children:[e.jsx(Rt,{width:11,height:11,className:"text-accent"}),N]},N))}):e.jsx("span",{className:"text-paddock-400",children:"None — pin files from the Files tab"})})]})})]})})]})}const Cl=/^[A-Za-z0-9._-]+$/,Sl={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},Il={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},Tl=[{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)"}],El={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},Rl=["read","write","web","orchestration","browser"];function $l(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 Ml(t){const s=t.trigger,a=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:a.promptFile?"file":"inline",prompt:a.prompt??"",promptFile:a.promptFile??"",resumeSession:a.session==="resume",allowedTools:new Set(a.tools??[]),permissionMode:a.permissionMode??"",model:a.model??"",maxTurns:a.maxTurns!=null?String(a.maxTurns):"",maxSpawnDepth:a.maxSpawnDepth!=null?String(a.maxSpawnDepth):"",enabled:t.enabled===!0}}function _l(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 a={session:t.resumeSession?"resume":"new",tools:[...t.allowedTools]};t.promptMode==="file"?a.promptFile=t.promptFile.trim():a.prompt=t.prompt,t.permissionMode&&(a.permissionMode=t.permissionMode),t.model.trim()&&(a.model=t.model.trim());const r=Number(t.maxTurns);t.maxTurns.trim()&&Number.isFinite(r)&&r>0&&(a.maxTurns=Math.floor(r));const o=Number(t.maxSpawnDepth);return t.maxSpawnDepth.trim()&&Number.isFinite(o)&&o>=0&&(a.maxSpawnDepth=Math.floor(o)),{trigger:s,run:a,enabled:t.enabled}}function Dl(t){const s=t.run.tools??[];return s.length===0?t.trigger.type==="schedule"?"Claude's tools":"Tool-less":`${s.length} tool${s.length===1?"":"s"}`}function ga(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function Pl(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function Ll({project:t}){const s=t.slug,[a,r]=n.useState([]),[o,l]=n.useState([]),[i,c]=n.useState(["onArchive","afterTurn"]),[m,h]=n.useState(["schedule","event","webhook"]),[v,u]=n.useState(!0),[b,C]=n.useState(null),[S,f]=n.useState(null),[x,T]=n.useState(null),[E,R]=n.useState(null),[k,F]=n.useState(null),[$,P]=n.useState({}),w=n.useCallback(async()=>{u(!0);try{const p=await L.listTriggers(s);r(p.triggers),l(p.grantableTools),p.events.length>0&&c(p.events),p.triggerTypes.length>0&&h(p.triggerTypes),C(null)}catch(p){C(p instanceof be?p.message:"Failed to load triggers")}finally{u(!1)}},[s]),O=n.useCallback(async()=>{try{const p=await L.triggerRuntime(s);P(Object.fromEntries(p.runtime.map(A=>[A.name,A])))}catch{}},[s]);n.useEffect(()=>{w()},[w]),n.useEffect(()=>{O();const p=setInterval(()=>{document.visibilityState==="visible"&&O()},1e4);return()=>clearInterval(p)},[O]),n.useEffect(()=>{if(!S)return;const p=setTimeout(()=>f(null),4e3);return()=>clearTimeout(p)},[S]);const y=x==null?void 0:x.draft,B=n.useMemo(()=>x!=null&&x.isNew?a.some(p=>p.name===(y==null?void 0:y.name.trim())):!1,[x,y,a]),U=!!y&&(!Cl.test(y.name.trim())||y.name.trim().length>64),I=!!y&&(y.type==="schedule"?y.expr.trim().length===0:y.type==="webhook"?y.path.trim().length===0:!1),D=!!y&&(y.promptMode==="file"?y.promptFile.trim().length===0||!y.promptFile.trim().toLowerCase().endsWith(".md"):y.prompt.trim().length===0),q=!!y&&y.type==="webhook",H=U||B||I||D||q,Y=p=>T(A=>A&&{...A,draft:{...A.draft,...p}}),Q=p=>T(A=>{if(!A)return A;const X=new Set(A.draft.allowedTools);return X.has(p)?X.delete(p):X.add(p),{...A,draft:{...A.draft,allowedTools:X}}}),te=async()=>{if(!x||H)return;const p=x.draft.name.trim();R(p);try{await L.putTrigger(s,p,_l(x.draft)),T(null),f(`Saved “${p}”.`),await w()}catch(A){C(A instanceof be?A.message:"Failed to save trigger")}finally{R(null)}},ne=async p=>{R(p.name);try{const A=await L.putTrigger(s,p.name,{trigger:p.trigger,run:p.run,enabled:!p.enabled});r(X=>X.map(g=>g.name===p.name?A:g))}catch(A){C(A instanceof be?A.message:"Failed to update trigger")}finally{R(null)}},se=async()=>{const p=k;if(p){R(p.name);try{await L.deleteTrigger(s,p.name),r(A=>A.filter(X=>X.name!==p.name)),f(`Deleted “${p.name}”.`),F(null)}catch(A){throw new Error(A instanceof be?A.message:"Failed to delete trigger")}finally{R(null)}}},de=async p=>{R(p.name);try{await L.runTrigger(s,p.name),f(`Ran “${p.name}” — a new chat is starting.`),await O()}catch(A){C(A instanceof be?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-paddock-500",children:[e.jsx(Mt,{width:14,height:14}),"Triggers"]}),e.jsxs("p",{className:"mb-3 mt-0.5 text-[13px] text-paddock-500",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:[b&&e.jsx("p",{className:"mb-3 rounded-lg bg-rose-50 px-3 py-2 text-sm text-rose-600 dark:bg-rose-950/40 dark:text-rose-300",children:b}),S&&e.jsx("p",{className:"mb-3 rounded-lg bg-emerald-50 px-3 py-2 text-sm text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-300",children:S}),v?e.jsx("p",{className:"py-4 text-center text-sm text-paddock-400",children:"Loading triggers…"}):a.length===0?e.jsx("p",{className:"py-4 text-center text-sm italic text-paddock-400",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-paddock-200 text-left text-[11px] font-semibold uppercase tracking-wide text-paddock-400 dark:border-paddock-800",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:a.map(p=>{var X;const A=$[p.name];return e.jsxs("tr",{"data-trigger":p.name,className:"border-b border-paddock-100 last:border-0 dark:border-paddock-800/60",children:[e.jsxs("td",{className:"px-2 py-2.5 align-top",children:[e.jsx("span",{className:"font-medium text-paddock-800 dark:text-paddock-100",children:p.name}),p.run.promptFile?e.jsx("span",{className:"mt-0.5 block font-mono text-[11px] text-paddock-400",title:"Prompt read from this file at fire time",children:p.run.promptFile}):p.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-[11px] text-paddock-400",children:p.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Fl,{type:p.trigger.type})}),e.jsx("td",{className:"px-2 py-2.5 align-top font-mono text-[12px] text-paddock-600 dark:text-paddock-300",children:Pl(p.trigger)}),e.jsxs("td",{className:"px-2 py-2.5 align-top text-[12px] text-paddock-600 dark:text-paddock-300",children:[e.jsx("span",{title:((X=p.run.tools)==null?void 0:X.join(", "))||"No tools granted",children:Dl(p)}),p.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-[11px] text-paddock-400",children:p.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":p.name,children:e.jsx(Ul,{rt:A})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":p.name,children:e.jsx(Bl,{rt:A,trigger:p})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Al,{enabled:p.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:()=>de(p),disabled:E===p.name||ga(p),title:ga(p)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${p.name} now`,"data-testid":`run-trigger-${p.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-accent transition hover:bg-accent/10 disabled:opacity-40",children:e.jsx(ln,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ne(p),disabled:E===p.name,className:"rounded-md px-1.5 py-1 text-[12px] font-medium text-paddock-500 transition hover:bg-paddock-200/60 disabled:opacity-40 dark:hover:bg-paddock-800/60",title:p.enabled?"Disable":"Enable",children:p.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>T({isNew:!1,draft:Ml(p)}),disabled:E===p.name,title:"Edit","aria-label":`Edit ${p.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-paddock-500 transition hover:bg-paddock-200/60 disabled:opacity-40 dark:hover:bg-paddock-800/60",children:e.jsx(Jt,{width:14,height:14})}),e.jsx("button",{type:"button",onClick:()=>F(p),disabled:E===p.name,title:"Delete","aria-label":`Delete ${p.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-paddock-400 transition hover:bg-rose-100 hover:text-rose-600 disabled:opacity-40 dark:hover:bg-rose-950/60 dark:hover:text-rose-400",children:e.jsx(Fs,{width:14,height:14})})]})})]},p.name)})})]})}),!x&&e.jsxs("button",{type:"button",onClick:()=>T({isNew:!0,draft:$l(m[0]??"schedule",i[0]??"onArchive")}),className:"btn-subtle mt-3 gap-1.5 px-2 py-1 text-xs","data-testid":"add-trigger",children:[e.jsx(at,{width:13,height:13}),"Add trigger"]}),x&&y&&e.jsxs("div",{className:"mt-4 rounded-xl border border-paddock-200 bg-paddock-50/60 p-4 dark:border-paddock-800 dark:bg-paddock-950/40","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-paddock-700 dark:text-paddock-200",children:x.isNew?"New trigger":`Edit “${y.name}”`}),e.jsx("button",{type:"button",onClick:()=>T(null),"aria-label":"Cancel",className:"flex h-7 w-7 items-center justify-center rounded-md text-paddock-400 hover:bg-paddock-200/60 dark:hover:bg-paddock-800/60",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:y.name,onChange:p=>Y({name:p.target.value}),placeholder:"daily-manager",disabled:!x.isNew,"aria-invalid":U||B,"data-testid":"trigger-name"}),x.isNew&&B?e.jsx("p",{className:"mt-1 text-[12px] text-rose-500",children:"A trigger with that name exists."}):x.isNew&&y.name.trim()&&U?e.jsxs("p",{className:"mt-1 text-[12px] text-rose-500",children:["Letters, numbers, ",e.jsx("code",{children:". _ -"})," only (max 64)."]}):!x.isNew&&e.jsx("p",{className:"mt-1 text-[12px] text-paddock-400",children:"Rename by deleting and recreating."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Type"}),e.jsx("select",{className:"input",value:y.type,onChange:p=>Y({type:p.target.value}),"data-testid":"trigger-type",children:m.map(p=>e.jsx("option",{value:p,children:Il[p]??p},p))})]}),y.type==="schedule"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Timer"}),e.jsxs("select",{className:"input",value:y.scheduleKind,onChange:p=>Y({scheduleKind:p.target.value,expr:""}),"data-testid":"trigger-schedule-kind",children:[e.jsx("option",{value:"interval",children:"Interval (every N)"}),e.jsx("option",{value:"cron",children:"Cron"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:y.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:y.expr,onChange:p=>Y({expr:p.target.value}),placeholder:y.scheduleKind==="cron"?"0 9 * * *":"30m","aria-invalid":I,"data-testid":"trigger-expr"}),e.jsx("p",{className:"mt-1 text-[12px] text-paddock-400",children:y.scheduleKind==="cron"?"5-field cron (or @daily / @hourly), host-local time.":"A duration like 30m, 1h, or 6h."})]})]}),y.type==="event"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Event"}),e.jsx("select",{className:"input",value:y.event,onChange:p=>Y({event:p.target.value}),"data-testid":"trigger-event",children:i.map(p=>e.jsx("option",{value:p,children:Sl[p]??p},p))})]}),y.type==="webhook"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Path"}),e.jsx("input",{className:"input font-mono",value:y.path,onChange:p=>Y({path:p.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),q&&e.jsxs("p",{className:"col-span-2 flex items-start gap-1.5 text-[12px] leading-snug text-amber-600 dark:text-amber-400",children:[e.jsx(ce,{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-[13px]",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-accent",checked:y.promptMode==="inline",onChange:()=>Y({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-accent",checked:y.promptMode==="file",onChange:()=>Y({promptMode:"file"})}),"Prompt file"]})]}),y.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:y.prompt,onChange:p=>Y({prompt:p.target.value}),placeholder:"What should this trigger do when it fires?","aria-invalid":D,"data-testid":"trigger-prompt"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input font-mono",value:y.promptFile,onChange:p=>Y({promptFile:p.target.value}),placeholder:"daily-manager.md","aria-invalid":D,"data-testid":"trigger-prompt-file"}),e.jsxs("p",{className:"mt-1 text-[12px] text-paddock-400",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-[12px] text-paddock-400",children:["The trigger agent can use exactly the tools you check here — nothing else. Leave all unchecked for a tool-less trigger that only thinks and returns text",y.type==="schedule"?" (a schedule with no tools runs as Claude with its full toolset).":"."]}),e.jsx("div",{className:"space-y-3","data-testid":"trigger-tools",children:Rl.filter(p=>o.some(A=>A.group===p)).map(p=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-[11px] font-semibold uppercase tracking-wide text-paddock-400",children:El[p]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:o.filter(A=>A.group===p).map(A=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-md px-1.5 py-1 text-[13px] hover:bg-paddock-100/60 dark:hover:bg-paddock-800/40",title:A.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-accent",checked:y.allowedTools.has(A.name),onChange:()=>Q(A.name),"data-tool":A.name}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono text-[12px] font-medium text-paddock-700 dark:text-paddock-200",children:A.name}),e.jsx("span",{className:"block text-[11px] leading-snug text-paddock-400",children:A.description})]})]},A.name))})]},p))}),y.allowedTools.has("Bash")&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-[12px] leading-snug text-amber-600 dark:text-amber-400",children:[e.jsx(ce,{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-accent",checked:y.resumeSession,onChange:p=>Y({resumeSession:p.target.checked}),"data-testid":"trigger-session"}),e.jsx("span",{className:"text-paddock-700 dark:text-paddock-200",children:"Accrete into one session"})]}),e.jsx("span",{className:"text-[12px] text-paddock-400",children:y.resumeSession?"One long-lived chat that accretes across fires.":"A fresh chat each fire."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsx("select",{className:"input",value:y.permissionMode,onChange:p=>Y({permissionMode:p.target.value}),"data-testid":"trigger-permission-mode",children:Tl.map(p=>e.jsx("option",{value:p.value,children:p.label},p.value))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,step:1,className:"input",value:y.maxTurns,onChange:p=>Y({maxTurns:p.target.value}),placeholder:"30","data-testid":"trigger-max-turns"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsx("input",{className:"input",value:y.model,onChange:p=>Y({model:p.target.value}),placeholder:"Workspace default","data-testid":"trigger-model"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsx("input",{type:"number",min:0,step:1,className:"input",value:y.maxSpawnDepth,onChange:p=>Y({maxSpawnDepth:p.target.value}),placeholder:"Inherit","data-testid":"trigger-max-spawn-depth"}),e.jsx("p",{className:"mt-1 text-[12px] text-paddock-400",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-accent",checked:y.enabled,onChange:p=>Y({enabled:p.target.checked}),"data-testid":"trigger-enabled"}),e.jsx("span",{className:"text-paddock-700 dark:text-paddock-200",children:"Enabled (fires on its trigger)"})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:te,disabled:H||E===y.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:E===y.name.trim()?"Saving…":x.isNew?"Create trigger":"Save"}),e.jsx("button",{type:"button",onClick:()=>T(null),className:"btn-ghost",children:"Cancel"})]})]})]})]})}),e.jsx(qt,{open:k!==null,title:"Delete trigger?",confirmLabel:"Delete trigger",message:k&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-ink dark:text-ink-dark",children:k.name})," ","will be removed from this project. This can't be undone."]}),onConfirm:se,onClose:()=>F(null)})]})}function Fl({type:t}){const s={schedule:"bg-violet-100 text-violet-700 dark:bg-violet-950/50 dark:text-violet-300",event:"bg-sky-100 text-sky-700 dark:bg-sky-950/50 dark:text-sky-300",webhook:"bg-paddock-200 text-paddock-500 dark:bg-paddock-800 dark:text-paddock-400"},a=t==="schedule"?Qe:Mt;return e.jsxs("span",{"data-trigger-type":t,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium capitalize ${s[t]}`,children:[e.jsx(a,{width:11,height:11}),t]})}function Al({enabled:t,running:s}){return s?e.jsxs("span",{"data-trigger-status":"running",className:"inline-flex items-center gap-1 rounded-full bg-amber-100 px-2 py-0.5 text-[11px] font-medium text-amber-700 dark:bg-amber-950/50 dark:text-amber-300",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-amber-500"}),"Running"]}):e.jsx("span",{"data-trigger-status":t?"enabled":"disabled",className:`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium ${t?"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300":"bg-paddock-200 text-paddock-500 dark:bg-paddock-800 dark:text-paddock-400"}`,children:t?"Enabled":"Disabled"})}function Ol(t){return t==="completed"?"bg-emerald-500":t==="failed"||t==="cancelled"?"bg-rose-500":t==="running"||t==="pending"?"bg-amber-500":"bg-paddock-400"}function Ul({rt:t}){const s=t==null?void 0:t.lastRun;if(!s)return e.jsx("span",{className:"text-[12px] text-paddock-400",children:"—"});const a=s.startedAt,r=[a?new Date(a).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-[12px] text-paddock-600 dark:text-paddock-300",title:r,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Ol(s.status)}`}),s.status==="running"?"Running…":vt(a)]})}function Bl({rt:t,trigger:s}){const a=s.trigger.type;if(a==="event")return e.jsx("span",{className:"text-[12px] text-paddock-400",children:"on event"});if(a==="webhook")return e.jsx("span",{className:"text-[12px] text-paddock-400",children:"on webhook"});const r=t==null?void 0:t.nextRunAt;return r?e.jsx("span",{className:"text-[12px] text-paddock-600 dark:text-paddock-300",title:new Date(r).toLocaleString(),children:Vn(r)}):e.jsx("span",{className:"text-[12px] text-paddock-400",children:"—"})}function Vl({open:t,chatName:s,onClose:a,onFork:r}){const o=`Fork of ${s}`,[l,i]=n.useState(o),c=n.useRef(null);if(n.useEffect(()=>{if(t){i(o);const h=c.current;h&&(h.focus(),h.select())}},[t,s]),As(t,a),!t)return null;const m=h=>{h.preventDefault(),r(l.trim()||o)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:a,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-paddock-200 bg-white p-6 shadow-2xl dark:border-paddock-800 dark:bg-paddock-900",onClick:h=>h.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:"Fork chat"}),e.jsx("button",{type:"button",onClick:a,className:"rounded-lg p-1 text-paddock-400 hover:bg-paddock-100 hover:text-paddock-600 dark:hover:bg-paddock-800","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-paddock-500",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:l,onChange:h=>i(h.target.value),placeholder:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:a,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:"Fork"})]})]})})}function zl({open:t,chatName:s,resetName:a,onClose:r,onRename:o}){const[l,i]=n.useState(s),c=n.useRef(null);if(n.useEffect(()=>{if(!t)return;i(s);const u=c.current;u&&(u.focus(),u.select())},[t,s]),As(t,r),!t)return null;const m=l.trim(),h=m==="",v=u=>{u.preventDefault(),o(h?null:m)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:r,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-paddock-200 bg-white p-6 shadow-2xl dark:border-paddock-800 dark:bg-paddock-900",onClick:u=>u.stopPropagation(),onSubmit:v,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-paddock-400 hover:bg-paddock-100 hover:text-paddock-600 dark:hover:bg-paddock-800","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-paddock-500",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:l,onChange:u=>i(u.target.value),placeholder:a||"Chat name"})]}),e.jsx("p",{className:"mb-5 text-xs text-paddock-400","data-testid":"rename-hint",children:h?e.jsxs(e.Fragment,{children:["Clearing the name resets it to",a?e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"font-medium text-paddock-500 dark:text-paddock-300",children:a}),"."]}):" 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:h?"Reset name":"Rename"})]})]})})}function Hl({open:t,slug:s,sessionId:a,defaultName:r,onClose:o,onPromoted:l}){const[i,c]=n.useState(r??""),[m,h]=n.useState(""),[v,u]=n.useState(""),[b,C]=n.useState(""),[S,f]=n.useState(!1),[x,T]=n.useState(null);if(n.useEffect(()=>{t&&(c(r??""),h(""),u(""),C(""),T(null))},[t,r]),As(t&&!S,o),!t)return null;const E=async R=>{if(R.preventDefault(),!!i.trim()){f(!0),T(null);try{const{project:k,promoted:F}=await L.promoteChat(s,a,{name:i.trim(),group:b||void 0,summary:m.trim()||void 0,domain:v.split(",").map($=>$.trim()).filter(Boolean)});l(k,F)}catch(k){T(k instanceof be?k.message:"Failed to promote chat")}finally{f(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:()=>!S&&o(),children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-paddock-200 bg-white p-6 shadow-2xl dark:border-paddock-800 dark:bg-paddock-900",onClick:R=>R.stopPropagation(),onSubmit:E,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:o,className:"rounded-lg p-1 text-paddock-400 hover:bg-paddock-100 hover:text-paddock-600 dark:hover:bg-paddock-800","aria-label":"Close",children:e.jsx(Be,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-paddock-500",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:i,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:m,onChange:R=>h(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:b,onChange:R=>C(R.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),ys.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:v,onChange:R=>u(R.target.value),placeholder:"home, plumbing"})]}),x&&e.jsx("p",{className:"mb-4 rounded-lg bg-rose-50 px-3 py-2 text-sm text-rose-600 dark:bg-rose-950/40 dark:text-rose-300",children:x}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:o,disabled:S,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:S||!i.trim(),children:S?"Promoting…":"Promote to project"})]})]})})}const Ja="paddock:fork:";function Wl(t){if(!t)return null;try{const s=localStorage.getItem(Ja+t);if(!s)return null;const a=JSON.parse(s);return a&&typeof a.sessionId=="string"&&typeof a.name=="string"?a:null}catch{return null}}function ba(t,s){try{localStorage.setItem(Ja+t,JSON.stringify(s))}catch{}}function Es(t){const s=Date.parse(t.chat.updatedAt??"")||0;return t.children.reduce((a,r)=>Math.max(a,Es(r)),s)}function zs(t){for(const s of t)zs(s.children);t.sort((s,a)=>!!s.chat.starred!=!!a.chat.starred?s.chat.starred?-1:1:Es(a)-Es(s))}function Xa(t,s){let a=0;for(const r of t)r.depth=s,r.descendantCount=Xa(r.children,s+1),a+=1+r.descendantCount;return a}function Gl(t){var r;const s=new Map;for(const o of t)s.set(o.sessionId,{chat:o,children:[],depth:0,descendantCount:0});const a=[];for(const o of s.values()){const l=(r=o.chat.parent)==null?void 0:r.sessionId,i=l?s.get(l):void 0;if(!i||i===o||ql(o,i,s)){a.push(o);continue}i.children.push(o)}return zs(a),Xa(a,0),a}function Kl(t){const s=t.map(a=>({chat:a,children:[],depth:0,descendantCount:0}));return zs(s),s}function ql(t,s,a){var l;const r=new Set([t.chat.sessionId]);let o=s;for(;o;){if(r.has(o.chat.sessionId))return!0;r.add(o.chat.sessionId);const i=(l=o.chat.parent)==null?void 0:l.sessionId;o=i?a.get(i):void 0}return!1}function Rs(t){return t.reduce((s,a)=>s+1+Rs(a.children),0)}function Yl(t){const s=[t.chat.sessionId],a=r=>{for(const o of r)s.push(o.chat.sessionId),a(o.children)};return a(t.children),s}function Ql(t,s){var i;const a=new Map;for(const c of t){const m=(i=c.parent)==null?void 0:i.sessionId;if(!m)continue;const h=a.get(m);h?h.push(c.sessionId):a.set(m,[c.sessionId])}const r=[],o=new Set([s]),l=[s];for(;l.length;)for(const c of a.get(l.pop())??[])o.has(c)||(o.add(c),r.push(c),l.push(c));return r}function ja(t,s){const a=[],r=o=>{for(const l of o)a.push(l),s.has(l.chat.sessionId)||r(l.children)};return r(t),a}function Jl(t,s){var o;const a=new Map(t.map(l=>[l.sessionId,l])),r=new Set;for(const l of s){let i=l;const c=new Set;for(;i&&!c.has(i.sessionId);){c.add(i.sessionId),r.add(i.sessionId);const m=(o=i.parent)==null?void 0:o.sessionId;i=m?a.get(m):void 0}}return t.filter(l=>r.has(l.sessionId))}const $s="paddock:chatsCollapsed:";function Xl(t){try{const s=localStorage.getItem($s+t);if(!s)return new Set;const a=JSON.parse(s);return Array.isArray(a)?new Set(a.filter(r=>typeof r=="string")):new Set}catch{return new Set}}function Zl(t,s){try{s.size===0?localStorage.removeItem($s+t):localStorage.setItem($s+t,JSON.stringify([...s]))}catch{}}const Za="paddock:chatView:nested",en="paddock:chatView:runningOnly";function tn(t,s){try{const a=localStorage.getItem(t);return a==="1"?!0:a==="0"?!1:s}catch{return s}}function sn(t,s,a){try{s===a?localStorage.removeItem(t):localStorage.setItem(t,s?"1":"0")}catch{}}function ei(){return tn(Za,!0)}function ti(t){sn(Za,t,!0)}function si(){return tn(en,!1)}function ai(t){sn(en,t,!1)}function ni(){const[t,s]=n.useState(ei),[a,r]=n.useState(si),o=n.useCallback(i=>{s(i),ti(i)},[]),l=n.useCallback(i=>{r(i),ai(i)},[]);return n.useMemo(()=>({nested:t,setNested:o,runningOnly:a,setRunningOnly:l}),[t,o,a,l])}function st({active:t,onClick:s,children:a}){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-ink dark:text-ink-dark":"border-transparent text-paddock-500 hover:text-paddock-700 dark:hover:text-paddock-300"}`,children:a})}function ri({file:t,active:s,onSelect:a,onUnpin:r}){const o=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:a,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-ink dark:text-ink-dark":"text-paddock-500 hover:text-paddock-700 dark:hover:text-paddock-300"}`,children:[e.jsx(Rt,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"max-w-[10rem] truncate",children:o})]}),e.jsx("button",{type:"button","aria-label":`Unpin ${t}`,title:`Unpin ${t}`,onClick:l=>{l.stopPropagation(),r()},className:"flex h-5 w-5 items-center justify-center rounded text-paddock-400 opacity-60 transition hover:bg-paddock-200/70 hover:text-paddock-700 focus:opacity-100 group-hover/pin:opacity-100 dark:hover:bg-paddock-800",children:e.jsx(Be,{width:12,height:12})})]})}function oi({project:t,running:s,unread:a,attentionLoading:r,attentionError:o,changelog:l,overview:i,files:c,onOpenChat:m,onNewChat:h,onOpenFile:v,onOpenFiles:u}){const b=c.slice(0,6);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:[e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(js,{label:"Running",count:s.length}),e.jsxs("button",{onClick:h,className:"btn-subtle -mr-1 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(at,{width:13,height:13}),"New chat"]})]}),o?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm text-rose-600 dark:text-rose-400",children:o})}):e.jsx(va,{chats:s,workspaceSlug:t.slug,loading:r,empty:"Nothing running right now.",onOpenChat:m,kind:"running"})]}),!o&&e.jsxs("section",{className:"mb-8",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between",children:e.jsx(js,{label:"Unread",count:a.length})}),e.jsx(va,{chats:a,workspaceSlug:t.slug,loading:r,empty:"No unread replies. All caught up.",onOpenChat:m,kind:"unread"})]}),v&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(js,{label:"Files",count:c.length}),c.length>b.length&&e.jsx("button",{onClick:u,className:"btn-subtle -mr-1 px-2 py-1 text-xs",children:"View all"})]}),b.length===0?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-paddock-400",children:"No files yet. Files Claude writes appear here."})}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-paddock-200 dark:border-paddock-800",children:b.map((C,S)=>e.jsxs("button",{onClick:()=>v(C),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-paddock-100/70 dark:hover:bg-paddock-900/40 ${S>0?"border-t border-paddock-200 dark:border-paddock-800":""}`,children:[e.jsx($t,{width:15,height:15,className:"shrink-0 text-paddock-400"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-paddock-700 dark:text-paddock-200",children:C}),t.pinned.includes(C)&&e.jsx(Rt,{width:12,height:12,className:"shrink-0 text-accent"})]},C))})]}),e.jsx(wa,{id:`${t.slug}:overview`,title:"OVERVIEW.md",body:i,emptyLabel:"No OVERVIEW.md yet."},`${t.slug}:overview`),e.jsx(wa,{id:`${t.slug}:changelog`,title:"CHANGELOG.md",body:l,emptyLabel:"No CHANGELOG.md yet."},`${t.slug}:changelog`),e.jsxs("p",{className:"mt-6 text-[11px] text-paddock-400",children:["Project directory: ",e.jsx("span",{className:"font-mono",children:t.dir})]})]})})}function js({label:t,count:s}){return e.jsxs("h3",{className:"text-sm font-semibold uppercase tracking-wide text-paddock-500",children:[t,s>0&&e.jsx("span",{className:"ml-1.5 text-paddock-400",children:s})]})}function va({chats:t,workspaceSlug:s,loading:a,empty:r,onOpenChat:o,kind:l}){return a&&t.length===0?e.jsx("div",{className:"h-[52px] animate-pulse rounded-2xl border border-paddock-200 bg-white/60 dark:border-paddock-800 dark:bg-paddock-900/50","aria-busy":"true"}):t.length===0?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-paddock-400",children:r})}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-paddock-200 dark:border-paddock-800","data-testid":`home-${l}-chats`,children:t.map((i,c)=>e.jsxs("button",{onClick:()=>o(i.sessionId,i.projectSlug),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-paddock-100/70 dark:hover:bg-paddock-900/40 ${c>0?"border-t border-paddock-200 dark:border-paddock-800":""}`,children:[l==="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"}):e.jsx("span",{title:"Unread reply","aria-label":"unread",className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:i.name}),i.projectSlug!==s&&e.jsx("span",{className:"shrink-0 truncate rounded-md bg-paddock-100 px-1.5 py-0.5 text-[11px] text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300",children:i.projectName}),e.jsx("span",{className:"shrink-0 text-[11px] text-paddock-400",children:vt(l==="unread"?i.lastTurnCompletedAt??i.updatedAt:i.updatedAt)})]},`${i.projectSlug}:${i.sessionId}`))})}function wa({id:t,title:s,body:a,emptyLabel:r}){const[o,l]=li(t),i=!o,c=a.trim().length>0;return e.jsxs("section",{className:"mb-8",children:[e.jsxs("button",{type:"button",onClick:l,"aria-expanded":i,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-paddock-100/60 dark:hover:bg-paddock-800/40",children:[e.jsx(Xt,{width:14,height:14,className:`shrink-0 text-paddock-400 transition-transform ${i?"rotate-90":""}`}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wide text-paddock-500",children:s})]}),i&&e.jsx("div",{className:"card",children:c?e.jsx(_t,{children:a}):e.jsx("p",{className:"text-sm italic text-paddock-400",children:r})})]})}function li(t){const s=`paddock:home-collapsed:${t}`,[a,r]=n.useState(()=>{try{return localStorage.getItem(s)==="1"}catch{return!1}});return[a,()=>r(l=>{const i=!l;try{localStorage.setItem(s,i?"1":"0")}catch{}return i})]}const Ms=8,_s=2*Math.PI*Ms,ii=.25*_s;function Na({tokens:t,limit:s,usage:a,size:r=14,working:o=!1}){const l=t!=null&&s!=null&&s>0;if(!l&&!o)return null;const i=l?Math.min(100,Math.max(0,t/s*100)):0,c=l&&i>=80,m=l?i/100*_s:ii,h=l?Math.round(t/1e3):0,v=l?Math.round(s/1e3):0,u=a?`
|
|
12
|
-
Session so far: ${$a(a)}`:"",b=o?l?`Streaming a response… — context window ${Math.round(i)}% full (${t.toLocaleString()} / ${s.toLocaleString()} tokens)`:"Streaming a response…":`Context window ${Math.round(i)}% full as of the last completed turn (${t.toLocaleString()} / ${s.toLocaleString()} tokens)${u}`,C=o?l?`Streaming a response… (context ${Math.round(i)}% full)`:"Streaming a response…":`Context ${Math.round(i)}% full (${h}k of ${v}k tokens)`;return e.jsx("span",{className:"inline-flex shrink-0 items-center",title:b,"aria-label":C,children:e.jsxs("svg",{width:r,height:r,viewBox:"0 0 20 20",className:o?"spin-eco":"-rotate-90",role:"img","aria-hidden":"true",children:[e.jsx("circle",{cx:"10",cy:"10",r:Ms,fill:"none",strokeWidth:"3",className:"stroke-paddock-200 dark:stroke-paddock-700"}),e.jsx("circle",{cx:"10",cy:"10",r:Ms,fill:"none",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:`${m} ${_s}`,className:c?"stroke-amber-500":"stroke-accent"})]})})}function ci({provenance:t,hookName:s,className:a=""}){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":"Imported chat",title:"Imported — this chat came from your Claude Code CLI history",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-emerald-600 dark:text-emerald-400 ${a}`,children:e.jsx(Ls,{width:12,height:12})});if(r==="hook"){const i=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:i,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-sky-600 dark:text-sky-400 ${a}`,children:e.jsx(Mt,{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-amber-600 dark:text-amber-400 ${a}`,children:e.jsx(Qe,{width:12,height:12})});const o=(t==null?void 0:t.depth)??0,l=o>1?` (${o} levels deep)`:"";return e.jsx("span",{"data-provenance":"spawned","aria-label":"Spawned chat",title:`Spawned — another chat created this one${l}`,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-violet-600 dark:text-violet-400 ${a}`,children:e.jsx(Je,{width:12,height:12})})}function ge({content:t,children:s,delayMs:a=250,className:r=""}){const o=n.useId(),l=n.useRef(null),i=n.useRef(null),c=n.useRef(null),[m,h]=n.useState(null),v=()=>{c.current&&clearTimeout(c.current),c.current=null},u=n.useCallback(()=>{v(),h(null)},[]),b=n.useCallback(()=>{var T;const f=(T=l.current)==null?void 0:T.getBoundingClientRect();if(!f)return;const x=f.top<56;h({x:f.left+f.width/2,y:x?f.bottom+6:f.top-6,below:x})},[]);n.useEffect(()=>v,[]),n.useEffect(()=>{if(!m)return;const f=x=>{x.key==="Escape"&&u()};return window.addEventListener("keydown",f),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("keydown",f),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[m,u]),n.useLayoutEffect(()=>{if(!m||!i.current)return;const f=i.current.offsetWidth;if(!f)return;const x=8+f/2,T=window.innerWidth-8-f/2,E=Math.min(Math.max(m.x,x),Math.max(x,T));E!==m.x&&h({...m,x:E})},[m]);const C=n.Children.only(s),S=n.isValidElement(C)?n.cloneElement(C,{"aria-describedby":m?o:void 0}):C;return e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:l,className:`inline-flex ${r}`,onPointerEnter:f=>{f.pointerType!=="touch"&&(v(),c.current=setTimeout(b,a))},onPointerLeave:u,onPointerDown:u,onFocusCapture:b,onBlurCapture:u,children:S}),m&&Sa.createPortal(e.jsx("div",{ref:i,id:o,role:"tooltip",style:{position:"fixed",left:m.x,top:m.y,transform:`translate(-50%, ${m.below?"0":"-100%"})`},className:"pointer-events-none z-[70] max-w-[15rem] animate-fade-in rounded-lg bg-paddock-900 px-2 py-1 text-[11px] leading-snug text-white shadow-lg dark:bg-paddock-100 dark:text-paddock-900",children:t}),document.body)]})}function di({activeTotal:t,shownCount:s,searching:a,runningCount:r,runningOnly:o,setRunningOnly:l}){const i=a?`${s}/${t}`:`${t}`,c=a?`${s} of ${t} chats shown`:`${t} chats`;return r===0&&!o?e.jsx("span",{className:"text-[11px] text-paddock-400",title:c,children:i}):e.jsxs("span",{role:"group","aria-label":"Chat count and running filter",className:"flex items-stretch overflow-hidden rounded-full border border-paddock-300/70 text-[11px] leading-none dark:border-paddock-700",children:[e.jsx(ge,{content:o?"Show all chats":c,className:"items-stretch",children:e.jsx("button",{type:"button",onClick:()=>l(!1),"aria-pressed":!o,"aria-label":o?`Show all ${t} chats`:`${t} chats`,className:`h-full px-1.5 py-0.5 transition-colors ${o?"text-paddock-400 hover:bg-paddock-200/70 hover:text-paddock-700 dark:hover:bg-paddock-700 dark:hover:text-paddock-100":"bg-paddock-200/70 font-medium text-paddock-600 dark:bg-paddock-800 dark:text-paddock-200"}`,children:i})}),e.jsx(ge,{content:o?"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:()=>l(!o),"aria-pressed":o,"aria-label":`Show only running chats (${r} running)`,className:`flex h-full items-center gap-1 border-l border-paddock-300/70 px-1.5 py-0.5 transition-colors dark:border-paddock-700 ${o?"bg-accent font-semibold text-white":"font-medium text-accent hover:bg-accent/10"}`,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 ui({nested:t,setNested:s,runningOnly:a}){const r=t?"Switch to a flat chat list":"Switch to a nested chat list";return e.jsx(ge,{content:a?"Running-only view is always flat":r,children:e.jsx("button",{type:"button",onClick:()=>s(!t),disabled:a,"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(cn,{width:16,height:16,className:"mx-auto"}):e.jsx(dn,{width:16,height:16,className:"mx-auto"})})})}function vs(t){return`${t} nested chat${t===1?"":"s"}`}const mi=4,pi=new Set;function hi({chatList:t,sessionsOpen:s,setSessionsOpen:a,chatSearch:r,setChatSearch:o,searching:l,newChat:i,view:c,activeSession:m,pendingChat:h,chats:v,fallbackChat:u,visibleChats:b,activeChats:C,archivedChats:S,activeTotal:f,runningCount:x,viewPrefs:T,archivedOpen:E,setArchivedOpen:R,collapsedChats:k,toggleChatCollapsed:F,openChat:$,unread:P,usageBySession:w,runningSessions:O,setForkingChat:y,setPromotingChat:B,renameChat:U,archiveChat:I,requestDeleteChat:D,starChat:q,toggleUnread:H,detachChat:Y,adoptableCount:Q,importing:te,importChats:ne}){const se=l?pi:k,de=C.some(g=>g.children.length>0)||S.some(g=>g.children.length>0),p=Rs(C),A=Rs(S),X=(g,Z)=>{var Se,je,ee,De;const re=(Z==null?void 0:Z.depth)??0,$e=(Z==null?void 0:Z.children.length)??0,me=(Z==null?void 0:Z.descendantCount)??0,ie=P.has(g.sessionId),Ce=se.has(g.sessionId),Me=!!Z&&me>0,fe=K=>Me&&K.shiftKey?Yl(Z):[g.sessionId],pe=me+1,we=(K,ue)=>Me?e.jsxs(e.Fragment,{children:[K," · ",e.jsx("span",{className:"font-semibold",children:"Shift-click"})," to ",ue]}):K,_e=(K,ue)=>Me?`${K} (Shift-click to ${ue})`:K,Ee=6+(re>0?1:0)+(B?1:0);return e.jsxs("div",{className:`group/chat chat-row chat-row--actions-${Ee} relative mb-0.5 flex rounded-lg transition-colors ${m===g.sessionId&&c==="chat"?"bg-paddock-200/80 dark:bg-paddock-800":"hover:bg-paddock-200/50 dark:hover:bg-paddock-800/50"}`,children:[Array.from({length:Math.min(re,mi)},(K,ue)=>e.jsx("div",{"aria-hidden":"true",className:"w-3 shrink-0 border-l border-paddock-300/60 dark:border-paddock-700/60"},ue)),de&&e.jsx("div",{className:"flex w-4 shrink-0 items-start justify-center pt-2.5",children:$e>0&&e.jsx(ge,{content:Ce?`Show ${vs(me)}`:"Hide nested chats",children:e.jsx("button",{type:"button","aria-label":`${Ce?"Expand":"Collapse"} ${me} chat${me===1?"":"s"} under ${g.name}`,"aria-expanded":!Ce,onClick:K=>{K.stopPropagation(),F(g.sessionId)},className:"flex h-4 w-4 items-center justify-center rounded text-paddock-400 transition hover:bg-paddock-300/60 hover:text-paddock-700 dark:hover:bg-paddock-700 dark:hover:text-paddock-100",children:e.jsx(Js,{width:11,height:11,className:`transition-transform ${Ce?"-rotate-90":""}`})})})}),e.jsxs("button",{type:"button",onClick:()=>$(g.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 ${de?"pl-1":"pl-2.5"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-1.5",children:[ie&&e.jsx(ge,{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"})}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${ie?"font-semibold":"font-medium"}`,children:g.name}),Ce&&me>0&&e.jsx(ge,{content:`${vs(me)} hidden`,className:"shrink-0",children:e.jsx("span",{className:"shrink-0 rounded-full bg-paddock-300/70 px-1.5 text-[10px] font-medium leading-4 text-paddock-600 dark:bg-paddock-700 dark:text-paddock-300",children:me})}),!(re>0&&((Se=g.provenance)==null?void 0:Se.origin)==="spawned")&&e.jsx(ci,{provenance:g.provenance,hookName:(je=g.trigger)==null?void 0:je.name}),e.jsx(Na,{tokens:((ee=w[g.sessionId])==null?void 0:ee.contextTokens)??g.contextTokens,limit:((De=w[g.sessionId])==null?void 0:De.contextLimit)??g.contextLimit,usage:zn(w[g.sessionId]??g),working:O.has(g.sessionId)})]}),e.jsx("span",{className:"chat-row-time text-[11px] text-paddock-400",children:vt(g.updatedAt)})]}),e.jsxs("div",{className:"absolute bottom-1 right-1.5 flex items-center gap-0.5",children:[re>0&&e.jsx(ge,{content:me>0?`Detach from parent — move this chat and its ${vs(me)} to the top level`:"Detach from parent — move this chat to the top level",children:e.jsx("button",{type:"button","aria-label":`Detach chat ${g.name} from its parent`,onClick:K=>{K.stopPropagation(),Y(g)},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-paddock-200 hover:text-accent focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-paddock-700 dark:hover:text-accent",children:e.jsx(mn,{width:13,height:13})})}),e.jsx(ge,{content:"Fork chat — branch a new chat from this one's context",children:e.jsx("button",{type:"button","aria-label":`Fork chat ${g.name}`,onClick:K=>{K.stopPropagation(),y(g)},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-paddock-200 hover:text-accent focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-paddock-700 dark:hover:text-accent",children:e.jsx(Je,{width:13,height:13})})}),B&&e.jsx(ge,{content:"Promote into a new project — give this chat a home of its own",children:e.jsx("button",{type:"button","aria-label":`Promote chat ${g.name} into a project`,onClick:K=>{K.stopPropagation(),B(g)},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-paddock-200 hover:text-accent focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-paddock-700 dark:hover:text-accent",children:e.jsx(at,{width:13,height:13})})}),e.jsx(ge,{content:"Rename chat",children:e.jsx("button",{type:"button","aria-label":`Rename chat ${g.name}`,onClick:K=>{K.stopPropagation(),U(g)},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-paddock-200 hover:text-paddock-700 focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-paddock-700 dark:hover:text-paddock-100",children:e.jsx(Jt,{width:13,height:13})})}),e.jsx(ge,{content:we(g.archived?"Unarchive chat":"Archive chat — file it away without deleting",g.archived?`unarchive all ${pe}`:`archive all ${pe}`),children:e.jsx("button",{type:"button","aria-label":_e(`${g.archived?"Unarchive":"Archive"} chat ${g.name}`,g.archived?`unarchive all ${pe}`:`archive all ${pe}`),onClick:K=>{K.stopPropagation(),I(g,fe(K))},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-paddock-200 hover:text-accent dark:hover:bg-paddock-700 dark:hover:text-accent ${g.archived?"text-accent opacity-100":"text-paddock-400 opacity-0"}`,children:e.jsx(pn,{width:13,height:13})})}),e.jsx(ge,{content:we("Delete chat",`delete all ${pe}`),children:e.jsx("button",{type:"button","aria-label":_e(`Delete chat ${g.name}`,`delete all ${pe}`),onClick:K=>{K.stopPropagation(),D(g,fe(K))},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-rose-100 hover:text-rose-600 focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-rose-950/60 dark:hover:text-rose-400",children:e.jsx(Fs,{width:13,height:13})})}),e.jsx(ge,{content:we(ie?"Mark as read":"Mark as unread — resurface it later",ie?`mark all ${pe} read`:`mark all ${pe} unread`),children:e.jsx("button",{type:"button","aria-label":_e(`Mark chat ${g.name} ${ie?"read":"unread"}`,ie?`mark all ${pe} read`:`mark all ${pe} unread`),"aria-pressed":ie,onClick:K=>{K.stopPropagation(),H(g,fe(K))},className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 opacity-0 transition hover:bg-paddock-200 hover:text-accent focus:opacity-100 group-hover/chat:opacity-100 dark:hover:bg-paddock-700 dark:hover:text-accent",children:e.jsx(hn,{width:13,height:13,open:!ie})})}),e.jsx(ge,{content:g.starred?"Unstar chat":"Star chat — pin it to the top of the list",children:e.jsx("button",{type:"button","aria-label":`${g.starred?"Unstar":"Star"} chat ${g.name}`,"aria-pressed":!!g.starred,onClick:K=>{K.stopPropagation(),q(g)},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-paddock-200 hover:text-amber-500 dark:hover:bg-paddock-700 dark:hover:text-amber-400 ${g.starred?"text-amber-400 opacity-100":"text-paddock-400 opacity-0"}`,children:e.jsx(xn,{width:13,height:13,fill:g.starred?"currentColor":"none"})})})]})]},g.sessionId)};return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"fixed inset-0 z-20 bg-black/40 lg:hidden","aria-hidden":"true",onClick:()=>a(!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-paddock-200 bg-canvas shadow-2xl transition-transform duration-200 ease-out dark:border-paddock-800 dark:bg-paddock-900 lg:relative lg:z-auto lg:max-w-none lg:translate-x-0 lg:bg-white/40 lg:shadow-none dark:lg:bg-paddock-900/20 ${s?"translate-x-0":"-translate-x-full"}`,children:[t.isDesktop&&e.jsx(un,{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(Ia,{width:15,height:15,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-paddock-400"}),e.jsx("input",{type:"text",value:r,onChange:g=>o(g.target.value),placeholder:"Search","aria-label":"Search chats",className:`input py-1.5 pl-8 ${l?"pr-8":"pr-2"}`}),l&&e.jsx(ge,{content:"Clear search",className:"absolute right-1.5 top-1/2 -translate-y-1/2",children:e.jsx("button",{type:"button",onClick:()=>o(""),"aria-label":"Clear search",className:"flex h-6 w-6 items-center justify-center rounded-md text-paddock-400 transition hover:bg-paddock-200 hover:text-paddock-700 dark:hover:bg-paddock-700 dark:hover:text-paddock-100",children:e.jsx(Be,{width:13,height:13})})})]}),e.jsx(ui,{nested:T.nested,setNested:T.setNested,runningOnly:T.runningOnly}),e.jsx(ge,{content:"New chat",children:e.jsx("button",{type:"button",className:"btn-primary h-9 w-9 shrink-0 p-0",onClick:i,"aria-label":"New Chat",children:e.jsx(at,{width:16,height:16})})}),e.jsx("button",{type:"button",onClick:()=>a(!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:[Q>0&&e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("button",{type:"button",onClick:ne,disabled:te,"aria-label":`Import ${Q} native Claude Code chat${Q===1?"":"s"} into this workspace`,className:"btn-ghost w-full justify-start py-1.5 text-xs",children:[e.jsx(Ls,{width:13,height:13,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:te?"Importing…":`Import ${Q} native chat${Q===1?"":"s"}`})]})}),e.jsxs("div",{className:"mb-1 flex items-center justify-between pr-3",children:[e.jsx("span",{className:"section-label",children:"Chats"}),(f>0||T.runningOnly)&&e.jsx(di,{activeTotal:f,shownCount:p,searching:l,runningCount:x,runningOnly:T.runningOnly,setRunningOnly:T.setRunningOnly})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:[m===null&&c==="chat"&&!h&&e.jsxs("div",{className:"mb-0.5 flex items-center gap-1.5 rounded-lg bg-paddock-200/80 px-2.5 py-2 text-sm dark:bg-paddock-800",children:[e.jsx(Qt,{width:13,height:13,className:"text-paddock-500"}),e.jsx("span",{className:"font-medium italic text-paddock-600 dark:text-paddock-300",children:"New chat…"})]}),h&&!v.some(g=>g.sessionId===h)&&e.jsx("div",{className:`group/chat relative mb-0.5 rounded-lg transition-colors ${m===h&&c==="chat"?"bg-paddock-200/80 dark:bg-paddock-800":"hover:bg-paddock-200/50 dark:hover:bg-paddock-800/50"}`,children:e.jsxs("button",{onClick:()=>$(h),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-paddock-600 dark:text-paddock-300",children:"New chat…"}),e.jsx(Na,{working:!0})]})}),u&&X(u),v.length===0&&!u&&e.jsx("p",{className:"px-2 py-2 text-sm text-paddock-500",children:"No saved chats yet. Send a message to start one."}),v.length>0&&T.runningOnly&&x===0&&e.jsxs("p",{className:"px-2 py-2 text-sm text-paddock-500",children:["No chats are running."," ",e.jsx("button",{type:"button",onClick:()=>T.setRunningOnly(!1),className:"text-accent underline underline-offset-2 hover:no-underline",children:"Show all chats"})]}),v.length>0&&(!T.runningOnly||x>0)&&l&&b.length===0&&!u&&e.jsxs("p",{className:"px-2 py-2 text-sm text-paddock-500",children:["No chats match “",r.trim(),"”."]}),v.length>0&&!T.runningOnly&&!l&&C.length===0&&!u&&e.jsx("p",{className:"px-2 py-2 text-sm text-paddock-500",children:"No active chats — see Archived below."}),ja(C,se).map(g=>X(g.chat,g))]}),S.length>0&&e.jsxs("div",{className:`flex flex-col border-t border-paddock-200 dark:border-paddock-800 ${E?"min-h-0 flex-1":"shrink-0"}`,children:[e.jsxs("button",{type:"button",onClick:()=>R(g=>!g),"aria-expanded":E,className:"flex w-full items-center gap-1.5 px-3 py-2 text-left text-xs font-medium uppercase tracking-wide text-paddock-500 transition-colors hover:bg-paddock-200/40 dark:text-paddock-400 dark:hover:bg-paddock-800/40",children:[e.jsx(Js,{width:14,height:14,className:`shrink-0 transition-transform ${E?"":"-rotate-90"}`}),e.jsx("span",{children:"Archived"}),e.jsx("span",{className:"ml-auto rounded-full bg-paddock-200 px-1.5 py-0.5 text-[10px] font-semibold normal-case text-paddock-600 dark:bg-paddock-800 dark:text-paddock-300",children:A})]}),E&&e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:ja(S,se).map(g=>X(g.chat,g))})]})]})]})]})}function xi({slug:t,chats:s,view:a,activeSession:r,runningSessions:o,onSeen:l,onManySeen:i}){const[c,m]=n.useState(new Set),[h,v]=n.useState(0),u=n.useCallback(f=>{const x=Date.now(),T=Xs(f,x);L.markChatSeen(t,f,x).catch(()=>{Zs(f,T,x),v(E=>E+1)}),l==null||l(f),m(E=>{if(!E.has(f))return E;const R=new Set(E);return R.delete(f),R}),v(E=>E+1)},[t,l]),b=n.useCallback(f=>{if(f.length<=1){f[0]&&u(f[0]);return}const x=Date.now(),T=f.map(k=>[k,Xs(k,x)]),E=f.filter(k=>c.has(k)),R=i==null?void 0:i(f);m(k=>{if(!E.length)return k;const F=new Set(k);for(const $ of E)F.delete($);return F}),v(k=>k+1),L.markChatsUnread(t,f,!1).catch(()=>{for(const[k,F]of T)Zs(k,F,x);E.length&&m(k=>{const F=new Set(k);for(const $ of E)F.add($);return F}),R==null||R(),v(k=>k+1)})},[t,i,u,c]);n.useEffect(()=>{for(const f of s)fn(f.sessionId,f.lastSeen);v(f=>f+1)},[s]);const C=n.useMemo(()=>{const f=new Set;for(const x of s){if(a==="chat"&&x.sessionId===r)continue;if(x.unread||c.has(x.sessionId)){f.add(x.sessionId);continue}const T=x.lastTurnCompletedAt?Date.parse(x.lastTurnCompletedAt):NaN;Number.isFinite(T)&&T>kn(x.sessionId)&&f.add(x.sessionId)}return f},[s,a,r,c,h]);n.useEffect(()=>{a==="chat"&&r&&u(r)},[a,r,u]);const S=n.useRef(new Set);return n.useEffect(()=>{const f=S.current;for(const x of f)o.has(x)||(a==="chat"&&x===r?u(x):m(T=>T.has(x)?T:new Set(T).add(x)));S.current=o},[o,a,r,u]),{markSeen:u,markManySeen:b,unread:C}}const fi=250,ki=2500,gi=3e4;function bi(t,s){const[a,r]=n.useState([]),[o,l]=n.useState([]),[i,c]=n.useState(!0),[m,h]=n.useState(null),v=n.useRef(0),u=n.useCallback(async()=>{const S=++v.current;try{const f=await L.attentionChats(t);if(S!==v.current)return;r(f.running),l(f.unread),h(null)}catch(f){if(S!==v.current)return;h(f instanceof Error?f.message:"Failed to load chats")}finally{S===v.current&&c(!1)}},[t]),b=n.useRef(u);b.current=u;const C=n.useRef(!1);return n.useEffect(()=>{C.current=!1,r([]),l([]),c(!0),u()},[t,u]),n.useEffect(()=>{if(!C.current){C.current=!0;return}const S=setTimeout(()=>void b.current(),fi),f=setTimeout(()=>void b.current(),ki);return()=>{clearTimeout(S),clearTimeout(f)}},[s]),n.useEffect(()=>{const S=()=>{document.visibilityState==="visible"&&b.current()},f=setInterval(S,gi);return document.addEventListener("visibilitychange",S),()=>{clearInterval(f),document.removeEventListener("visibilitychange",S)}},[]),{running:a,unread:o,loading:i,error:m,refresh:()=>void u()}}function ji({message:t,tone:s="success",onDismiss:a,durationMs:r=6e3}){if(n.useEffect(()=>{if(t===null||r<=0)return;const l=setTimeout(a,r);return()=>clearTimeout(l)},[t,r,a]),t===null)return null;const o=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 ${o?"border-rose-300/60 bg-rose-50 text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/80 dark:text-rose-300":"border-paddock-200 bg-canvas text-paddock-700 dark:border-paddock-700 dark:bg-paddock-800 dark:text-paddock-100"}`,children:[o?e.jsx(ce,{width:16,height:16,className:"mt-0.5 shrink-0"}):e.jsx(nt,{width:16,height:16,className:"mt-0.5 shrink-0 text-emerald-500"}),e.jsx("span",{className:"break-words",children:t}),e.jsx("button",{type:"button",onClick:a,"aria-label":"Dismiss notification",className:"-mr-1 ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded transition hover:bg-black/5 dark:hover:bg-white/10",children:e.jsx(Be,{width:12,height:12})})]})})}function an({adopted:t,skipped:s}){const a=t.length;if(a===0&&s.length===0)return"Nothing to import — no native chats were found.";const r=a===0?"Imported nothing":`Imported ${a} chat${a===1?"":"s"}`;if(s.length===0)return r;const o=[...new Set(s.map(i=>i.reason).filter(Boolean))],l=o.length===1?` (${o[0]})`:"";return`${r} — skipped ${s.length}${l}`}function vi({root:t=!1}={}){var Ws,Gs,Ks,qs,Ys;const s=gn(),a=t?bn:s.slug??"",r=ea(a),o=jn(),l=vn(),i=wn(),c=(i==null?void 0:i.openNav)??(()=>{}),{refresh:m,upsert:h,remove:v}=Nn(),u=yn(o.pathname,r),b=u==="chat"?s.sessionId:void 0,C=u==="files"?Cn(o.pathname,r):"",S=u==="changes"&&s.file?decodeURIComponent(s.file):void 0,f=n.useRef({counter:0,session:b??null}),x=n.useRef(!1);f.current.session!==(b??null)&&((Ws=o.state)!=null&&Ws.established||(f.current.counter+=1),f.current.session=b??null);const[T,E]=n.useState(0),R=`${f.current.counter}:${T}`,[k,F]=n.useState(null),[$,P]=n.useState([]),[w,O]=n.useState({}),[y,B]=n.useState(""),[U,I]=n.useState(null),[D,q]=n.useState(new Set);n.useEffect(()=>Ae.onActiveSessions(q),[]);const[H,Y]=n.useState(""),[Q,te]=n.useState(""),[ne,se]=n.useState([]),[de,p]=n.useState(null),[A,X]=n.useState(0),[g,Z]=n.useState(!1),[re,$e]=n.useState(null),me=n.useCallback(()=>$e(null),[]),[ie,Ce]=n.useState(null),Me=hl(a),fe=Me.newUnattended,[pe,we]=n.useState(!1),[_e,Ee]=n.useState(!1),[Se,je]=n.useState(null),[ee,De]=n.useState(null),[K,ue]=n.useState(null),[Ie,Pe]=n.useState(null),[Ge,Oe]=n.useState(!1),[Xe,rt]=n.useState(()=>Xl(a)),ve=n.useCallback(d=>{rt(_=>{const V=new Set(_);return V.has(d)?V.delete(d):V.add(d),Zl(a,V),V})},[a]),N=ni(),J=Sn(Mn),ae=n.useRef(null),z=b??null,Ne=n.useCallback(d=>P(_=>_.map(V=>V.sessionId===d&&V.unread?{...V,unread:!1}:V)),[]),Ve=n.useCallback(d=>{const _=new Set(d),V=$.filter(G=>_.has(G.sessionId)&&G.unread).map(G=>G.sessionId);if(!V.length)return()=>{};P(G=>G.map(oe=>_.has(oe.sessionId)&&oe.unread?{...oe,unread:!1}:oe));const W=new Set(V);return()=>P(G=>G.map(oe=>W.has(oe.sessionId)?{...oe,unread:!0}:oe))},[$]),{unread:ot,markManySeen:wt}=xi({slug:a,chats:$,view:u,activeSession:z,runningSessions:D,onSeen:Ne,onManySeen:Ve}),lt=bi(a,D),Te=n.useMemo(()=>{const d=N.runningOnly?$.filter(W=>D.has(W.sessionId)||W.sessionId===z):$,_=y.trim().toLowerCase();if(!_)return d;const V=d.filter(W=>{var G;return W.name.toLowerCase().includes(_)||(((G=W.preview)==null?void 0:G.toLowerCase().includes(_))??!1)});return N.runningOnly?V:Jl($,V)},[$,y,N.runningOnly,D,z]),ts=y.trim().length>0,it=n.useCallback(async()=>{const d=await L.gitStatus(a).catch(()=>null);Ce(d&&d.repo?d:null)},[a]),ct=n.useCallback(async()=>{const d=await L.chatUsage(a).catch(()=>null);d&&O(_=>({..._,...d}))},[a]),dt=n.useCallback(async()=>{const d=await L.chatUsage(a,"archived").catch(()=>null);d&&O(_=>({..._,...d}))},[a]),Nt=n.useRef(!1),Dt=n.useCallback(async()=>{p(null);try{const d=await L.getProjectDetail(a);F(d.project),P(d.chats),Y(d.changelog),te(d.overview??"");const _=await L.listProjectFiles(a).catch(()=>[]);se(_)}catch(d){p(d instanceof Error?d.message:"Failed to load project")}it(),ct()},[a,it,ct]);n.useEffect(()=>{F(null),Ce(null),O({}),Nt.current=!1,Dt()},[a,Dt]),n.useEffect(()=>{Ge&&(Nt.current=!0,dt())},[Ge,dt]),n.useEffect(()=>{if(t)return;const d=u==="home"?tt({view:"home"}):u==="settings"?tt({view:"settings"}):u==="history"?tt({view:"history"}):u==="triggers"?tt({view:"triggers"}):u==="chat"?tt({view:"chat",sessionId:b}):u==="changes"?tt({view:"changes",file:S}):tt({view:"files",path:C||void 0});Qn(a,d)},[t,a,u,b,C,S]);const he=n.useCallback(async()=>{const d=await L.listProjectChats(a).catch(()=>null);d&&P(d)},[a]),Ke=n.useCallback(async()=>{const d=await L.getAdoptableChats(a).catch(()=>null);X((d==null?void 0:d.count)??0)},[a]),ut=n.useCallback(async()=>{if(!g){Z(!0);try{const d=await L.adoptChats(a);await he(),await Ke(),$e({message:an(d),tone:d.adopted.length===0&&d.skipped.length>0?"error":"success"})}catch(d){$e({message:d instanceof Error?d.message:"Failed to import native chats",tone:"error"})}finally{Z(!1)}}},[g,a,he,Ke]);n.useEffect(()=>{X(0),$e(null),Ke()},[Ke]);const Pt=n.useCallback(async()=>{const d=await L.getProjectDetail(a).catch(()=>null);d&&(F(d.project),P(d.chats),Y(d.changelog),te(d.overview??""));const _=await L.listProjectFiles(a).catch(()=>null);_&&se(_),it(),ct(),Nt.current&&dt()},[a,it,ct,dt]),ss=n.useCallback(d=>L.projectChatMessages(a,d),[a]);n.useEffect(()=>{we(!1)},[u,b,C,S]);const Ze=n.useCallback(()=>l(In(r)),[l,r]),qe=n.useCallback(()=>l(`${r}/chat`),[l,r]),mt=n.useCallback(()=>l(`${r}/files`),[l,r]),Lt=n.useCallback(()=>l(`${r}/changes`),[l,r]),yt=n.useCallback(()=>l(`${r}/history`),[l,r]),pt=n.useCallback(()=>l(`${r}/settings`),[l,r]),et=n.useCallback(()=>l(`${r}/triggers`),[l,r]),as=n.useCallback(d=>l(d?`${r}/changes/${encodeURIComponent(d)}`:`${r}/changes`),[l,r]);n.useEffect(()=>{o.pathname.startsWith(`${r}/hooks`)&&l(`${r}/triggers`,{replace:!0})},[o.pathname,l,r]);const Ct=n.useCallback(()=>{E(d=>d+1),qe()},[qe]),ht=n.useCallback(d=>l(`${r}/chat/${encodeURIComponent(d)}`),[l,r]),ns=n.useCallback((d,_)=>l(`${ea(_)}/chat/${encodeURIComponent(d)}`),[l]),Ft=n.useCallback(async(d,_)=>{let V;try{V=await L.forkChat(a,d.sessionId,_)}catch(W){p(W instanceof Error?W.message:"Failed to fork chat");return}ba(V,{sessionId:d.sessionId,name:d.name}),await he(),l(`${r}/chat/${encodeURIComponent(V)}`,{state:{justForked:!0}})},[l,r,a,he]),ze=n.useCallback(async d=>{if(!z||x.current)return;x.current=!0;const _=$.find(G=>G.sessionId===z),V=_?`Fork of ${_.name}`:void 0;let W;try{W=await L.forkChat(a,z,V,d)}catch(G){p(G instanceof Error?G.message:"Failed to fork chat"),x.current=!1;return}_&&ba(W,{sessionId:_.sessionId,name:_.name}),await he(),l(`${r}/chat/${encodeURIComponent(W)}`,{state:{justForked:!0}}),x.current=!1},[z,$,l,r,a,he]),He=n.useCallback(async d=>{if(z){try{await L.revertChat(a,z,d)}catch(_){throw p(_ instanceof Error?_.message:"Failed to revert chat"),_}await he()}},[z,a,he]),At=Wl(b),St=((Gs=o.state)==null?void 0:Gs.justForked)===!0,It=n.useCallback(d=>l(d?`${r}/files/${d.split("/").map(encodeURIComponent).join("/")}`:`${r}/files`),[l,r]),Ot=n.useCallback(d=>{I(d),he(),m(),b||l(`${r}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[he,m,b,l,r]),Ut=n.useCallback(d=>{he(),m(),b||l(`${r}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[he,m,b,l,r]);n.useEffect(()=>{U&&$.some(d=>d.sessionId===U)&&I(null)},[$,U]);const Bt=n.useRef(new Set);n.useEffect(()=>{let d=!1;for(const _ of D)Bt.current.has(_)||(Bt.current.add(_),$.some(V=>V.sessionId===_)||(d=!0));d&&he()},[D,$,he]);const rs=n.useCallback(d=>{d&&O(_=>({..._,[d.sessionId]:d.usage})),Pt(),m()},[Pt,m]),Vt=n.useCallback(async d=>{if(!k)return;const _=k.pinned.includes(d)?await L.unpinFile(a,d):await L.pinFile(a,d);F(_),h(_)},[k,a,h]),zt=n.useCallback(async d=>{const _=await L.unpinFile(a,d);F(_),h(_),C===d&&l(`${r}/files`,{replace:!0})},[a,r,h,C,l]),Ht=n.useCallback(async()=>{if(!ee)return;const{ids:d}=ee;let _;if(d.length===1)await L.deleteProjectChat(a,d[0]),_=d;else{const W=await L.deleteProjectChats(a,d);_=W.removed,W.failed.length&&p(`Deleted ${W.removed.length} of ${d.length} chats — ${W.failed.length} could not be removed.`)}const V=new Set(_);P(W=>W.filter(G=>!V.has(G.sessionId))),z&&V.has(z)&&l(`${r}/chat`,{replace:!0}),De(null)},[ee,a,r,z,l]),Wt=n.useCallback((d,_)=>{const V=$.filter(oe=>!!oe.archived==!!d.archived),W=new Set(_),G=Ql(V,d.sessionId).filter(oe=>!W.has(oe)).length;De({chat:d,ids:_,orphanCount:G})},[$]),os=n.useCallback(async(d,_)=>{await L.renameProjectChat(a,d.sessionId,_),P(V=>V.map(W=>W.sessionId===d.sessionId?{...W,name:_||W.preview||W.sessionId.slice(0,8)}:W))},[a]),ls=n.useCallback(async(d,_)=>{const V=!d.archived,W=new Set(_);P(G=>G.map(oe=>W.has(oe.sessionId)?{...oe,archived:V}:oe)),V&&Oe(!0);try{_.length===1?await L.archiveProjectChat(a,_[0],V):await L.archiveProjectChats(a,_,V)}catch(G){P(oe=>oe.map(Ye=>W.has(Ye.sessionId)?{...Ye,archived:d.archived}:Ye)),p(G instanceof Error?G.message:"Failed to archive chat")}},[a]),is=n.useCallback(async d=>{const _=d.parent;if(_){P(V=>V.map(W=>W.sessionId===d.sessionId?{...W,parent:void 0}:W));try{await L.detachProjectChat(a,d.sessionId,!0)}catch(V){P(W=>W.map(G=>G.sessionId===d.sessionId?{...G,parent:_}:G)),p(V instanceof Error?V.message:"Failed to detach chat")}}},[a]),Gt=n.useCallback(async d=>{const _=!d.starred;P(V=>V.map(W=>W.sessionId===d.sessionId?{...W,starred:_}:W));try{await L.starProjectChat(a,d.sessionId,_)}catch(V){P(W=>W.map(G=>G.sessionId===d.sessionId?{...G,starred:d.starred}:G)),p(V instanceof Error?V.message:"Failed to star chat")}},[a]),cs=n.useCallback(async(d,_)=>{if(ot.has(d.sessionId)){wt(_);return}const V=new Set(_),W=new Map($.filter(G=>V.has(G.sessionId)).map(G=>[G.sessionId,G.unread]));P(G=>G.map(oe=>V.has(oe.sessionId)?{...oe,unread:!0}:oe));try{_.length===1?await L.markChatUnread(a,_[0],!0):await L.markChatsUnread(a,_,!0)}catch(G){P(oe=>oe.map(Ye=>V.has(Ye.sessionId)?{...Ye,unread:W.get(Ye.sessionId)}:Ye)),p(G instanceof Error?G.message:"Failed to mark chat unread")}},[ot,wt,a,$]),xt=n.useCallback(d=>N.runningOnly||!N.nested?Kl(d):Gl(d),[N.runningOnly,N.nested]),ds=n.useMemo(()=>xt(N.runningOnly?Te:Te.filter(d=>!d.archived)),[Te,xt,N.runningOnly]),us=n.useMemo(()=>N.runningOnly?[]:xt(Te.filter(d=>d.archived)),[Te,xt,N.runningOnly]),j=$.filter(d=>!d.archived).length,M=n.useMemo(()=>$.filter(d=>D.has(d.sessionId)).length,[$,D]),ye=$.some(d=>d.archived&&d.sessionId===z),ke=n.useRef(null);n.useEffect(()=>{var _;const d=$.find(V=>V.sessionId===z);d?ke.current=d:((_=ke.current)==null?void 0:_.sessionId)!==z&&(ke.current=null)},[$,z]);const ms=!!z&&u==="chat"&&U!==z&&!$.some(d=>d.sessionId===z)?((Ks=ke.current)==null?void 0:Ks.sessionId)===z?ke.current:{sessionId:z,workingDirectory:"",name:"Current chat",updatedAt:"",resumable:!0}:null;if(n.useEffect(()=>{ye&&ae.current!==z&&(ae.current=z,Oe(!0))},[ye,z]),de)return e.jsx("div",{className:"p-8",children:e.jsx("div",{className:"rounded-lg border border-rose-300/60 bg-rose-50 px-4 py-3 text-sm text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/40 dark:text-rose-300",children:de})});if(!k)return e.jsx("div",{className:"p-8 text-sm text-paddock-500",children:"Loading project…"});const Le=k.pinned,Hs=u==="files"&&C&&Le.includes(C)?C:null,nn=u==="files"&&!Hs;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("header",{className:"pt-safe border-b border-paddock-200 px-3 pb-2.5 dark:border-paddock-800 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(Tn,{width:20,height:20})}),e.jsxs("button",{type:"button",onClick:()=>we(!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(Qt,{width:16,height:16}),e.jsx("span",{className:"hidden sm:inline",children:"Chats"}),$.length>0&&e.jsx("span",{className:"text-[11px] text-paddock-400",children:$.length})]}),e.jsx("h1",{className:"min-w-0 text-lg font-semibold tracking-tight lg:text-xl",children:e.jsx("button",{type:"button",onClick:Ze,title:"Project home",className:"block max-w-full truncate rounded transition-colors hover:text-accent",children:k.name})}),e.jsx(Hn,{status:k.status}),k.domain.map(d=>e.jsx(En,{tag:d,className:"hidden lg:inline-flex"},d)),k.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-emerald-100 px-1.5 py-0.5 text-[11px] font-medium text-emerald-700 lg:inline-flex dark:bg-emerald-950/50 dark:text-emerald-400",children:[e.jsx(nt,{width:11,height:11}),"Overview"]}),k.repoBacked&&e.jsxs("a",{href:Rn(k.repo),target:"_blank",rel:"noreferrer",title:`Repo-backed project — Claude works in a clone of ${k.repo}`,className:"hidden items-center gap-1 rounded-md bg-sky-100 px-1.5 py-0.5 text-[11px] font-medium text-sky-700 lg:inline-flex dark:bg-sky-950/50 dark:text-sky-400",children:[e.jsx(Je,{width:11,height:11}),"Repo"]}),e.jsxs("span",{className:"ml-auto hidden items-center gap-1 text-xs text-paddock-400 lg:inline-flex",children:[e.jsx(Qe,{width:12,height:12}),"updated ",vt(k.updated)]}),e.jsx("button",{type:"button",onClick:Ct,"aria-label":"New chat",title:"New chat",className:"btn-subtle ml-auto shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(at,{width:16,height:16})}),e.jsx(Wn,{onEdit:pt,onDelete:t?void 0:()=>Ee(!0),size:18})]}),k.summary&&e.jsx("p",{className:"mt-1.5 hidden text-sm text-paddock-600 lg:block dark:text-paddock-400",children:k.summary})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx(hi,{chatList:J,sessionsOpen:pe,setSessionsOpen:we,chatSearch:y,setChatSearch:B,searching:ts,newChat:Ct,view:u,activeSession:z,pendingChat:U,chats:$,fallbackChat:ms,visibleChats:Te,activeChats:ds,archivedChats:us,activeTotal:j,runningCount:M,viewPrefs:N,archivedOpen:Ge,setArchivedOpen:Oe,collapsedChats:Xe,toggleChatCollapsed:ve,openChat:ht,unread:ot,usageBySession:w,runningSessions:D,setForkingChat:ue,setPromotingChat:t?Pe:void 0,renameChat:je,archiveChat:ls,requestDeleteChat:Wt,starChat:Gt,toggleUnread:cs,detachChat:is,adoptableCount:A,importing:g,importChats:()=>void ut()}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:`border-b border-paddock-200 dark:border-paddock-800 ${u==="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(st,{active:u==="home",onClick:Ze,children:"Home"}),e.jsx(st,{active:u==="chat",onClick:qe,children:"Chat"}),e.jsx(st,{active:nn,onClick:mt,children:"Files"}),ie&&e.jsx(st,{active:u==="changes",onClick:Lt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Changes",ie.files.length>0&&e.jsx("span",{title:`${ie.files.length} uncommitted change${ie.files.length===1?"":"s"}`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-amber-100 px-1 text-[10px] font-semibold text-amber-700 dark:bg-amber-950/50 dark:text-amber-400",children:ie.files.length})]})}),e.jsx(st,{active:u==="history",onClick:yt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["History",fe>0&&e.jsx("span",{title:`${fe} new unattended run${fe===1?"":"s"} since your last visit`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-accent/15 px-1 text-[10px] font-semibold text-accent-700 dark:text-accent",children:fe})]})}),e.jsx(st,{active:u==="settings",onClick:pt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ta,{width:13,height:13}),"Settings"]})}),e.jsx(st,{active:u==="triggers",onClick:et,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Mt,{width:13,height:13}),"Triggers"]})}),Le.map(d=>e.jsx(ri,{file:d,active:Hs===d,onSelect:()=>It(d),onUnpin:()=>void zt(d)},d))]})}),u==="changes"&&ie&&e.jsx(el,{slug:k.slug,status:ie,onStatusChange:d=>Ce(d.repo?d:null),selectedFile:S??null,onSelectFile:as}),u==="history"&&e.jsx(ml,{slug:k.slug,state:Me,chats:$,onOpenChat:ht}),u==="settings"&&e.jsx(yl,{project:k,onSaved:d=>{F(d),h(d)}}),u==="triggers"&&e.jsx(Ll,{project:k}),u==="home"&&e.jsx(oi,{project:k,running:lt.running,unread:lt.unread,attentionLoading:lt.loading,attentionError:lt.error,changelog:H,overview:Q,files:ne,onOpenChat:ns,onNewChat:Ct,onOpenFile:It,onOpenFiles:mt}),u==="chat"&&e.jsx(Xo,{projectSlug:k.slug,initialSessionId:z??void 0,loadHistory:ss,onSessionEstablished:Ut,onSessionStarted:Ot,onTurnComplete:rs,preloadAvailable:k.hasOverview,projectModel:k.model,projectModels:k.models,projectRecovery:k.recovery,projectAttachments:k.attachments,forkParent:At??void 0,onOpenForkParent:ht,onForkFromMessage:ze,onRevertToMessage:He,autoFocus:St,trigger:(Ys=$.find(d=>d.sessionId===z)??(((qs=ke.current)==null?void 0:qs.sessionId)===z?ke.current:null))==null?void 0:Ys.trigger},R),u==="files"&&e.jsx(bl,{project:k,path:C,onNavigate:It,onTogglePin:Vt},C)]})]}),e.jsx(qt,{open:_e,title:"Delete project?",message:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-ink dark:text-ink-dark",children:k.name})," and all its chats and files will be permanently removed. This cannot be undone."]}),confirmLabel:"Delete project",onConfirm:async()=>{await L.deleteProject(k.slug),v(k.slug),Jn(k.slug),l($n())},onClose:()=>Ee(!1)}),e.jsx(qt,{open:ee!==null,title:ee&&ee.ids.length>1?`Delete ${ee.ids.length} chats?`:"Delete chat?",message:ee&&e.jsxs(e.Fragment,{children:[ee.ids.length>1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-ink dark:text-ink-dark",children:ee.chat.name})," ","and its ",ee.ids.length-1," nested chat",ee.ids.length-1===1?"":"s"," will be permanently removed — their transcripts too."]}):"This chat's transcript will be permanently removed.",ee.orphanCount>0&&e.jsxs(e.Fragment,{children:[" ","Its ",ee.orphanCount," other nested chat",ee.orphanCount===1?"":"s"," will be kept and moved to the top level."]})," ","This cannot be undone."]}),confirmLabel:ee&&ee.ids.length>1?`Delete ${ee.ids.length} chats`:"Delete chat",onConfirm:Ht,onClose:()=>De(null)}),Ie&&e.jsx(Hl,{open:!0,slug:a,sessionId:Ie.sessionId,defaultName:Ie.name,onClose:()=>Pe(null),onPromoted:d=>{Pe(null),h(d),l(`/projects/${d.slug}/chat`)}}),Se&&e.jsx(zl,{open:!0,chatName:Se.name,resetName:Se.preview,onClose:()=>je(null),onRename:d=>{const _=Se;je(null),os(_,d)}}),K&&e.jsx(Vl,{open:!0,chatName:K.name,onClose:()=>ue(null),onFork:d=>{const _=K;ue(null),Ft(_,d)}}),e.jsx(ji,{message:(re==null?void 0:re.message)??null,tone:re==null?void 0:re.tone,onDismiss:me})]})}const Si=Object.freeze(Object.defineProperty({__proto__:null,ProjectView:vi,importSummary:an},Symbol.toStringTag,{value:"Module"}));export{xo as M,Si as P};
|
|
13
|
-
|