@edspencer/paddock 0.65.0 → 0.66.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/README.md +3 -3
- package/package.json +1 -1
- package/packages/server/dist/cli/args.d.ts +4 -4
- package/packages/server/dist/cli/args.js +5 -5
- package/packages/server/dist/cli/paddock.js +1 -1
- package/packages/server/dist/config.d.ts +7 -0
- package/packages/server/dist/config.js +9 -1
- package/packages/server/dist/herdctl.d.ts +89 -0
- package/packages/server/dist/herdctl.js +169 -2
- package/packages/server/dist/instance-config.js +12 -1
- package/packages/server/dist/projects.d.ts +11 -0
- package/packages/server/dist/projects.js +40 -2
- package/packages/server/dist/routes/chats.js +77 -6
- package/packages/server/dist/routes/projects.js +22 -2
- package/packages/server/dist/schema-version.d.ts +111 -0
- package/packages/server/dist/schema-version.js +142 -0
- package/packages/server/dist/subagents.d.ts +65 -0
- package/packages/server/dist/subagents.js +159 -19
- package/packages/server/dist/tooldetails.d.ts +10 -4
- package/packages/server/dist/tooldetails.js +23 -6
- package/packages/server/dist/trusted-proxy.js +1 -1
- package/packages/server/dist/turn-interlock.d.ts +101 -0
- package/packages/server/dist/turn-interlock.js +76 -0
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/InstanceConfigPage-DBrwtZjx.js +2 -0
- package/packages/web/dist/assets/{MarkdownRenderer-Ri1LwAUN.js → MarkdownRenderer-Bn6VPBdL.js} +1 -1
- package/packages/web/dist/assets/{ProjectRedirect-Dze5H8Xy.js → ProjectRedirect-CQmDBtd-.js} +1 -1
- package/packages/web/dist/assets/ProjectView-BVKu9oIg.js +13 -0
- package/packages/web/dist/assets/{ProjectsGrid-BidsM7ah.js → ProjectsGrid-BW56zqke.js} +1 -1
- package/packages/web/dist/assets/{arc-eQ3ryE9c.js → arc-CGy6WkLl.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-Dc6Tj2Ai.js → architectureDiagram-3BPJPVTR-DJH1WIxY.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DBX5pma_.js → blockDiagram-GPEHLZMM-Cufb_pvX.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-CnWrtTpa.js → c4Diagram-AAUBKEIU-glqeg1Ky.js} +1 -1
- package/packages/web/dist/assets/channel-C4kPYn_d.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-2qmLvtsr.js → chunk-2J33WTMH-SOFTHYgh.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-Dn-LUDMV.js → chunk-4BX2VUAB-DFxFAiG8.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-DB0augUY.js → chunk-55IACEB6-CEEDxZVG.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-BPQQM0i8.js → chunk-727SXJPM--3eiptsh.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-DOhfwA-x.js → chunk-AQP2D5EJ-DIHIugCo.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-CatHHdFD.js → chunk-FMBD7UC4-BmxWZl5c.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-B645aAlG.js → chunk-ND2GUHAM-hMHtJs_I.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-D1fAaPSZ.js → chunk-QZHKN3VN-CRnnasyy.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DCg6gTVh.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DCg6gTVh.js +2 -0
- package/packages/web/dist/assets/{core-B4t7D8Om.js → core-CGW2CVAY.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BLdKDAwa.js → cose-bilkent-S5V4N54A-kcl9qSfK.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG-CbTbTVKv.js → dagre-BM42HDAG-BiLsFx1W.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-CorSS29_.js → diagram-2AECGRRQ-BcIpoY66.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-PLKivts0.js → diagram-5GNKFQAL-BK5p5kJa.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-CUSIBacZ.js → diagram-KO2AKTUF-BmJYalCP.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-CZ69mAZs.js → diagram-LMA3HP47-BHs0SWEM.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-Cmf042Rh.js → diagram-OG6HWLK6-CSs8hie4.js} +1 -1
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-DyIKGj6e.js → erDiagram-TEJ5UH35-4qd_Td27.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-B79pLdLD.js → flowDiagram-I6XJVG4X-CstUgr7V.js} +1 -1
- package/packages/web/dist/assets/{format-C5nhFL8q.js → format-B_kAvAW3.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-BFTR_oNA.js → ganttDiagram-6RSMTGT7-DTn9OuIc.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-DdGUlJxS.js → gitGraphDiagram-PVQCEYII-E_bCor2O.js} +1 -1
- package/packages/web/dist/assets/{index-DVSsta3B.js → index-B-QAOq9a.js} +2 -2
- package/packages/web/dist/assets/index-B3K5nsLe.css +1 -0
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-B80FyUOy.js → infoDiagram-5YYISTIA-foRUrIOQ.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-_wRlphn9.js → ishikawaDiagram-YF4QCWOH-CTON8v5t.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-qu4yvjW8.js → journeyDiagram-JHISSGLW-D-qwGjr7.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-D2DEUp2-.js → kanban-definition-UN3LZRKU-5l4y83rE.js} +1 -1
- package/packages/web/dist/assets/{linear-D-CLRUEW.js → linear-B1GiUWpI.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-DdihBJl4.js → mermaid.core-btQIOU6d.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-BEh_TDBf.js → mindmap-definition-RKZ34NQL-DduczfMv.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-BbrmLVaZ.js → pieDiagram-4H26LBE5-D86uGusc.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-DfVuygAv.js → quadrantDiagram-W4KKPZXB-Bo5EW3MZ.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-BHp2QpZt.js → requirementDiagram-4Y6WPE33-C9aZJK93.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-D2G6lRMY.js → sankeyDiagram-5OEKKPKP-b__W6SAJ.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-Dj-jzR-c.js → sequenceDiagram-3UESZ5HK-Lr4Df8kX.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-C5D6bT13.js → stateDiagram-AJRCARHV-R0XxGxD5.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-i2pZN-iR.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-DE4gGjhP.js → timeline-definition-PNZ67QCA-D42Je9LW.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-C9QNrl92.js → vennDiagram-CIIHVFJN-KCu14-QB.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-U2fSGy-d.js → wardley-L42UT6IY-Cfir3V9o.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-B9RhObdH.js → wardleyDiagram-YWT4CUSO-BkXjbTXu.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-BnlPrtQ9.js → xychartDiagram-2RQKCTM6-BVT60Pln.js} +1 -1
- package/packages/web/dist/index.html +2 -2
- package/packages/web/dist/sw.js +1 -1
- package/packages/web/dist/assets/InstanceConfigPage-DcprTH2W.js +0 -2
- package/packages/web/dist/assets/ProjectView-PrA8purE.js +0 -13
- package/packages/web/dist/assets/channel-B4sED4OP.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-BlVeHFir.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-BlVeHFir.js +0 -2
- package/packages/web/dist/assets/index-B6etJCHf.css +0 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-C8NDOqTq.js +0 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-Bn6VPBdL.js","assets/index-B-QAOq9a.js","assets/index-B3K5nsLe.css","assets/format-B_kAvAW3.js","assets/queued-LamEU0GH.js","assets/lastTab-CU1zsF0j.js","assets/core-CGW2CVAY.js","assets/mermaid.core-btQIOU6d.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r,b as A,n as Ne,j as e,y as ea,A as xe,z as Ss,F as _t,X as Le,c as at,D as Dt,L as Fs,E as Ea,C as Qt,G as Ta,B as Ye,P as ct,H as Is,S as Os,v as Jt,_ as le,I as Ra,f as Xt,l as $a,m as dt,W as Ma,J as Pe,K as un,U as pn,O as ks,Q as Zt,R as Mt,V as Es,w as Us,Y as mn,Z as hn,$ as xn,a0 as fn,a1 as ta,a2 as kn,a3 as gn,a4 as bn,a5 as jn,a6 as sa,a7 as aa,a8 as vn,a9 as wn,h as Nn,aa as yn,ab as Cn,a as Sn,p as In,u as En,ac as Tn,ad as Rn,ae as $n,af as Mn,ag as na,M as _n,T as Dn,ah as Pn,g as Ln,ai as An}from"./index-B-QAOq9a.js";import{i as Fn,s as On,a as Un,l as Bn,b as Vn,c as zn,t as Hn,d as Gn,f as _a,e as Da,g as Pa,r as vt,h as Wn,j as Kt,C as qt,u as Kn,k as es,m as qn,S as Yn,P as Qn}from"./format-B_kAvAW3.js";import{readQueued as Jn,readQueuedTs as Xn,writeQueued as Zn,writeQueuedTs as er}from"./queued-LamEU0GH.js";import{t as lt,w as tr,c as sr}from"./lastTab-CU1zsF0j.js";const ar=500,nr=9e4,gs="paddock:cancel",ra="paddock:timeout";function rr(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function or(){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 lr({onText:t,timeoutMs:s=nr}){const[a,n]=r.useState("idle"),[o,l]=r.useState(null),[i,c]=r.useState(null),[p]=r.useState(rr),x=r.useRef(null),w=r.useRef(null),u=r.useRef([]),b=r.useRef("webm"),j=r.useRef(null),C=r.useRef(null),f=r.useRef(!0);r.useEffect(()=>{f.current=!0;let N=!1;return A.transcriptionStatus().then(O=>{N||l(O.available)}).catch(()=>{N||l(!1)}),()=>{var O;N=!0,f.current=!1,(O=C.current)==null||O.abort(gs),m()}},[]);const m=()=>{var N;(N=w.current)==null||N.getTracks().forEach(O=>O.stop()),w.current=null,x.current=null},T=r.useCallback(async()=>{if(!p||a==="recording"||a==="transcribing")return;c(null),j.current=null;let N;try{N=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(U){n("error"),c(ur(U));return}w.current=N;const{mimeType:O,ext:y}=or();b.current=y;const B=O?new MediaRecorder(N,{mimeType:O}):new MediaRecorder(N);u.current=[],B.ondataavailable=U=>{U.data&&U.data.size>0&&u.current.push(U.data)},B.onstop=()=>{m();const U=B.mimeType||O||"audio/webm",I=new Blob(u.current,{type:U});u.current=[],j.current=I,$(I)},x.current=B,B.start(),n("recording")},[p,a]),$=r.useCallback(async(N,O=!1)=>{if(N.size===0){j.current=null,f.current&&n("idle");return}f.current&&n("transcribing");const y=new AbortController;C.current=y;const B=setTimeout(()=>y.abort(ra),s);try{const U=await A.transcribe(N,`dictation.${b.current}`,y.signal);U.trim()&&t(U.trim()),j.current=null,f.current&&(c(null),n("idle"))}catch(U){if(y.signal.aborted&&y.signal.reason===gs){j.current=null,f.current&&(c(null),n("idle"));return}if(y.signal.aborted&&y.signal.reason===ra){f.current&&(n("error"),c("Transcription timed out — try again."));return}if(ir(U)&&!O)return await dr(ar),$(N,!0);f.current&&(n("error"),c(cr(U)))}finally{clearTimeout(B),C.current===y&&(C.current=null)}},[t,s]),M=r.useCallback(()=>{var N;(N=C.current)==null||N.abort(gs)},[]),k=r.useCallback(()=>{const N=x.current;N&&N.state!=="inactive"&&N.stop()},[]),L=r.useCallback(()=>{a==="recording"?k():T()},[a,T,k]),R=r.useCallback(()=>{if(a==="recording"||a==="transcribing")return;const N=j.current;N?$(N):T()},[a,$,T]),P=r.useCallback(()=>{j.current=null,c(null),n("idle")},[]);return{state:a,available:o,supported:p,error:i,start:T,stop:k,toggle:L,retry:R,dismiss:P,cancel:M}}function ir(t){return t instanceof Ne?t.status>=500:!0}function cr(t){return t instanceof Ne?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 dr(t){return new Promise(s=>setTimeout(s,t))}function ur(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 pr({onText:t}){const{state:s,available:a,supported:n,error:o,toggle:l,retry:i,dismiss:c,cancel:p}=lr({onText:t});if(a!==!0)return null;const x=s==="recording",w=s==="transcribing",u=s==="error";if(!n)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(ea,{width:18,height:18})});const b=x?"Stop recording":w?"Transcribing… — click to cancel":u?"Transcription failed — click to record again":"Record a voice message",j=()=>{w?p():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(xe,{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:j,"aria-label":x?"Stop recording":w?"Cancel transcription":"Record a voice message","aria-pressed":x,title:b,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",x?"bg-rose-100 text-rose-600 dark:bg-rose-950/60 dark:text-rose-400":w?"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:[w?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(mr,{})}),e.jsx(Ss,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):x?e.jsx(Ss,{width:16,height:16}):e.jsx(ea,{width:18,height:18}),x&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function mr(){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 hr="paddock:chatModel:";function La(t,s){return hr+(t??`new:${s}`)}function xr(t,s){try{const a=localStorage.getItem(La(t,s));return a&&a.length>0?a:null}catch{return null}}function Ts(t,s,a){try{localStorage.setItem(La(t,s),a)}catch{}}const fr="paddock:draft:";function Aa(t,s){return fr+(t??`new:${s}`)}function kr(t,s){try{return localStorage.getItem(Aa(t,s))??""}catch{return""}}function gr(t,s,a){try{const n=Aa(t,s);a.length>0?localStorage.setItem(n,a):localStorage.removeItem(n)}catch{}}const oa="<paddock-attachments>",Rs="</paddock-attachments>",la=`${Rs}
|
|
3
|
+
|
|
4
|
+
`;function Fa(t){return`/api/chat-files/${encodeURIComponent(t)}`}function br(t){const s=t.indexOf(oa);if(s===-1)return{attachments:[],text:t};const a=s+oa.length,n=t.indexOf(Rs,a);if(n===-1)return{attachments:[],text:t};const o=t.slice(a,n),l=[];for(const p of o.split(`
|
|
5
|
+
`)){const x=p.split(" ");if(x.length<3)continue;const[w,u,b]=x;!(w!=null&&w.trim())||!(b!=null&&b.trim())||l.push({id:w.trim(),kind:(u==null?void 0:u.trim())||"file",filename:b.trim()})}const i=t.slice(0,s),c=t.startsWith(la,n)?t.slice(n+la.length):t.slice(n+Rs.length).replace(/^\n+/,"");return{attachments:l,text:i+c}}function jr(t){const s=t.slice(t.lastIndexOf("/")+1),a=s.lastIndexOf(".");return a>0?s.slice(a).toLowerCase():""}function Oa(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 vr(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function wr(t,s,a){const n=(s??"").trim().toLowerCase(),o=jr(a??"");for(const l of t){const i=l.trim().toLowerCase();if(i){if(i==="*"||i==="*/*")return!0;if(i.includes("/")){if(!n)continue;const[c,p]=i.split("/",2),[x,w]=n.split("/",2);if((c==="*"||c===x)&&(p==="*"||p===w))return!0}else if(i.startsWith(".")){if(o&&o===i)return!0}else if(o&&o===`.${i}`)return!0}}return!1}function Nr({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(yr,{attachment:s},s.id))})}function yr({attachment:t}){const s=Fa(t.id);if(t.kind==="image")return e.jsx(Sr,{src:s,filename:t.filename});const a=Oa(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 Cr({attachment:t,onRemove:s}){const a=Fa(t.id),[n,o]=r.useState(!1),l=t.kind==="image"&&!n,i=Oa(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(Le,{width:12,height:12})})]})}function Sr({src:t,filename:s}){const[a,n]=r.useState(!1),[o,l]=r.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(xe,{width:14,height:14}),s]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>n(!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:()=>n(!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 Ir(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 Er({trigger:t,projectSlug:s}){const a=t.allowedTools??[],n=a.length===0,o=n?t.type==="schedule"?"runs as Claude (full tools)":"no tools declared":`${a.length} tool${a.length===1?"":"s"} granted`,l=t.type==="schedule"?at:Dt;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:Ir(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"}),n?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 declared. An empty list is not a restriction: no allow-list is passed to the runtime, so this agent falls back to Claude's default tools. Its prompt and max turns are the real bounds."}):e.jsx("ul",{className:"flex flex-wrap gap-1","data-testid":"trigger-allowed-tools",children: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(Fs,{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 Tr=new Set(["paddock","paddock_manage"]);function Rr(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function $r(t){if(!t.startsWith("mcp__"))return{isMcp:!1,server:"",isPaddock:!1,display:t,tool:t};const s=t.slice(5),a=s.indexOf("__"),n=a===-1?s:s.slice(0,a),o=a===-1?"":s.slice(a+2);return{isMcp:!0,server:n,isPaddock:Tr.has(n),display:Rr(o||n),tool:o}}const ia="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 Ua(t,s=80){var n;const a=((n=t.split(`
|
|
6
|
+
`).find(o=>o.trim().length>0))==null?void 0:n.trim())??t.trim();return a.length>s?`${a.slice(0,s).trimEnd()}…`:a}function Ba(t,s){return t||(s?Ua(s):"untitled chat")}function Mr(t,s){if(!t.startsWith(ia)||!s)return null;const a=t.slice(ia.length);let n;try{n=JSON.parse(s)}catch{return null}if(!n||typeof n!="object")return null;switch(a){case"list_projects":{if(!Array.isArray(n.projects))return null;const o=n.projects;return{tool:a,count:Tt(n.count,o.length),projects:o}}case"list_chats":{if(!Array.isArray(n.chats))return null;const o=n.chats;return{tool:a,count:Tt(n.count,o.length),project:n.project??null,chats:o}}case"read_chat":{if(!Array.isArray(n.messages))return null;const o=n.messages;return{tool:a,project:String(n.project??""),sessionId:String(n.sessionId??""),total:Tt(n.total,o.length),returned:Tt(n.returned,o.length),messages:o}}case"create_chat":return n.sessionId?{tool:a,project:String(n.project??""),sessionId:String(n.sessionId),name:ft(n.name),prompt:ft(n.prompt)}:null;case"send_message":return n.sessionId?{tool:a,project:String(n.project??""),sessionId:String(n.sessionId),prompt:ft(n.prompt)}:null;case"fork_chat":return n.sessionId?{tool:a,project:String(n.project??""),sessionId:String(n.sessionId),from:ft(n.from),name:ft(n.name),prompt:ft(n.prompt)}:null;case"fork_chat_batch":{if(!Array.isArray(n.forks))return null;const o=n.forks;return{tool:a,count:Tt(n.count,o.length),source:String(n.source??""),forks:o}}default:return null}}function _r(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 Ba(t.name,t.prompt);case"send_message":return t.prompt?Ua(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const Va=r.createContext(null),Dr=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,$s=t=>t.length>8?`${t.slice(0,8)}…`:t;function $t({project:t,sessionId:s,label:a}){return e.jsxs(Fs,{to:Dr(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(Ea,{width:10,height:10,className:"shrink-0"}),a??$s(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 ca({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 da({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 Pr({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($t,{project:t.project,sessionId:t.sessionId})]})}function Lr({data:t}){const s=r.useContext(Va)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:kt,children:e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.projects.map(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(ca,{children:a.area}),a.status&&a.status!=="active"&&e.jsx(ca,{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(Pr,{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($t,{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,n)=>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})]},n))})]});case"create_chat":case"fork_chat":{const a=t.tool==="create_chat"?"Created chat":"Forked chat",n=Ba(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:n}),e.jsxs("span",{className:gt,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${gt}`,children:["from ",$s(t.from)]}),e.jsx($t,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(da,{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($t,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(da,{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 ",$s(t.source)]})}),e.jsx("ol",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.forks.map((a,n)=>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:n+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($t,{project:s,sessionId:a.sessionId})]},a.sessionId))})]})}}const ts=new Set(["Task","Agent"]);function Ar(t,s){return ts.has(t.toolName)&&s&&t.subagentDurationMs==null}const Fr="mcp__paddock__send_file",Or=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),Ur=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function Br(t){return t.background||t.toolName==="Monitor"||Or.has(t.toolName)?!0:Ur.test(t.output??"")}function Vr(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 zr(t){switch(t){case"list_projects":return Is;case"create_chat":return ct;case"fork_chat":case"fork_chat_batch":return Ye;case"send_message":return Ta;default:return Qt}}function za(t){if(t.toolName!==Fr||!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?A.chatFileRawUrl(s.attachmentId):void 0}}function Hr(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 ua(t){return t===void 0?"":String(t)}function Gr(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 Wr(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 Kr(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 qr=0;const ze=()=>`t${++qr}`;function Yr(t,s){t(a=>{const n=a[a.length-1];return n&&n.kind==="assistant"&&n.streaming?[...a.slice(0,-1),{...n,content:n.content+s}]:[...a,{kind:"assistant",id:ze(),content:s,streaming:!0}]})}function De(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function pa(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 Qr(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const l=za(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(Fn(t.content))return{kind:"compact",id:s,summary:t.content};const a=On(t.content);if(a)return{kind:"command",id:s,command:a};if(Un(t.content))return{kind:"commandOutput",id:s,content:Bn(t.content)??""};if(Vn(t.content))return{kind:"commandOutput",id:s,content:""};if(zn(t.content))return{kind:"notification",id:s,summary:Gn(t.content),status:Hn(t.content)};const{attachments:n,text:o}=br(t.content);return{kind:"user",id:s,content:o,...t.sender?{sender:t.sender}:{},...n.length>0?{attachments:n}:{}}}const Jr="/compact";function Xr(t){return t.kind==="commandOutput"&&t.content===""}function Zr(t){if(!t.some(a=>a.kind==="compact"))return t;const s=[];for(let a=0;a<t.length;a++){const n=t[a];if(n.kind!=="compact"){s.push(n);continue}let o=a+1;for(;o<t.length&&Xr(t[o]);)o++;const l=t[o];(l==null?void 0:l.kind)==="command"&&l.command===Jr?(s.push(...t.slice(a+1,o+1),n),a=o):s.push(n)}return s}function Yt(t){const s=new Map,a=t.filter(n=>!n.bgConsumed).map(n=>{let o;if(n.uuid){const i=s.get(n.uuid)??0;s.set(n.uuid,i+1),o=i===0?n.uuid:`${n.uuid}#${i}`}else o=ze();const l=Qr(n,o);return l.timestamp=n.timestamp,n.contextTokens!=null&&(l.contextTokens=n.contextTokens),l});return Zr(a)}const Ha=r.createContext(null),Ga=r.createContext(!1),Bs=r.createContext(null),Wa=r.createContext(null),Ka=r.createContext(null),Vs=r.createContext(null),qa=r.createContext(null);function eo({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(n=>{const o=s.get(n.toolUseId);return e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>a(n.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(Os,{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:n.label}),n.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-[11px] text-paddock-500 dark:text-paddock-400",children:n.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"]})]})},n.toolUseId)})})]})})}const to=2e3,so=6;function ao(t){const s=t.toolCall;if(!s)return null;const a=ts.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,n=(s.description??s.inputSummary??"").trim();return n?`${a} ${n}`:a}function no(t){var n,o;if(t.length===0)return;const s=Date.parse(((n=t[0])==null?void 0:n.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 ro(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function oo(t,s,a){const[n,o]=r.useState(new Map),l=r.useRef(new Set),i=r.useRef(new Set),c=r.useRef(new Map),p=r.useRef(s);p.current=s;const x=r.useRef(a);x.current=a;const w=t.map(u=>u.toolUseId).sort().join(",");if(a)for(const u of t)i.current.add(u.toolUseId);return r.useEffect(()=>{const u=(w?w.split(","):[]).filter(f=>i.current.has(f));if(u.length===0||!p.current)return;let b=!1,j;const C=async()=>{const f=p.current;if(!f)return;const m=u.filter($=>!l.current.has($));if(m.length===0)return;const T=await Promise.all(m.map($=>f($).then(M=>({id:$,messages:M})).catch(()=>null)));b||(o($=>{const M=new Map($);for(const k of T){if(!k)continue;const L=ro(k.messages),R=c.current.get(k.id),P=R&&R.sig===L?R.ticks+1:0;c.current.set(k.id,{sig:L,ticks:P});const N=!x.current&&P>=so;N&&l.current.add(k.id);const O=k.messages.map(ao).filter(y=>!!y);M.set(k.id,{latestStep:O[O.length-1],stepCount:O.length,messages:k.messages,elapsedMs:no(k.messages),running:!N})}return M}),b||(j=setTimeout(C,to)))};return C(),()=>{b=!0,j&&clearTimeout(j)}},[w,a]),n}function lo(t){return r.useMemo(()=>{const s=[];for(const a of t){const n=a.kind==="tool"?a.tool:void 0;n!=null&&n.toolUseId&&ts.has(n.toolName)&&n.hasSubagent&&n.subagentDurationMs==null&&s.push({toolUseId:n.toolUseId,label:n.subagentType??n.toolName,description:n.description})}return s},[t])}function io({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:n=>a(n.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 co({models:t,model:s,onSelectModel:a,usage:n,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(uo,{usage:n}),e.jsx(po,{usage:o}),l&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(Ye,{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 uo({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,n=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:[n,"k / ",o,"k (",Math.round(s),"%)"]})]})}function po({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${_a(t.costUsd)}`:Da(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${Pa(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const ma=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function mo(){const[t,s]=r.useState(0);return r.useEffect(()=>{const a=setInterval(()=>s(n=>(n+1)%ma.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:[ma[t],"…"]})]})})}function ho({text:t,onEdit:s,onClear:a}){const n=t.split(`
|
|
7
|
+
`,1)[0],o=t.length-n.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(at,{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:n}),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(Le,{width:12,height:12})})]})]})})}function xo({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 fo=r.lazy(()=>le(()=>import("./MarkdownRenderer-Bn6VPBdL.js"),__vite__mapDeps([0,1,2,3,4,5]))),Pt=r.memo(function({children:s,mermaid:a=!1}){return e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(fo,{mermaid:a,children:s})})}),ko={tsx:"typescript",jsx:"javascript",html:"xml"};function go(t){if(!t)return;const s=t.toLowerCase();return ko[s]??s}let bs=null;async function bo(){return bs||(bs=(async()=>{const{default:t}=await le(async()=>{const{default:R}=await import("./core-CGW2CVAY.js");return{default:R}},__vite__mapDeps([6,1,2])),[s,a,n,o,l,i,c,p,x,w,u,b,j,C,f,m,T,$,M,k,L]=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",n.default),t.registerLanguage("ruby",o.default),t.registerLanguage("go",l.default),t.registerLanguage("rust",i.default),t.registerLanguage("java",c.default),t.registerLanguage("c",p.default),t.registerLanguage("cpp",x.default),t.registerLanguage("csharp",w.default),t.registerLanguage("php",u.default),t.registerLanguage("swift",b.default),t.registerLanguage("kotlin",j.default),t.registerLanguage("bash",C.default),t.registerLanguage("sql",f.default),t.registerLanguage("json",m.default),t.registerLanguage("yaml",T.default),t.registerLanguage("toml",$.default),t.registerLanguage("css",M.default),t.registerLanguage("scss",k.default),t.registerLanguage("xml",L.default),t})()),bs}function jo({code:t,language:s}){const[a,n]=r.useState(null),o=go(s);r.useEffect(()=>{if(!o){n(null);return}let i=!1;return n(null),(async()=>{try{const c=await bo();if(i||!c.getLanguage(o))return;const{value:p}=c.highlight(t,{language:o});i||n(p)}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 js=null;function vo(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function wo(){return js||(js=le(()=>import("./mermaid.core-btQIOU6d.js").then(t=>t.bm),__vite__mapDeps([7,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:vo()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),js}function No({code:t}){const a="mmd-"+r.useId().replace(/[^a-zA-Z0-9-]/g,""),n=r.useRef(null),[o,l]=r.useState(null);return r.useEffect(()=>{let i=!1;return l(null),(async()=>{try{const c=await wo();await c.parse(t);const{svg:p,bindFunctions:x}=await c.render(a+"-svg",t);if(i||!n.current)return;n.current.innerHTML=p,x==null||x(n.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:n,"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 yo="paddock:itemHeight:";function zs(t){return yo+t}function ha(t){try{const s=localStorage.getItem(zs(t));if(s==null)return null;const a=Number(s);return Number.isFinite(a)&&a>0?a:null}catch{return null}}function Co(t,s){try{const a=zs(t);Number.isFinite(s)&&s>0?localStorage.setItem(a,String(Math.round(s))):localStorage.removeItem(a)}catch{}}function So(t){try{localStorage.removeItem(zs(t))}catch{}}function Io({itemId:t,children:s,defaultMaxHeight:a=360,minHeight:n=80}){const o=r.useRef(null),[l,i]=r.useState(0),[c,p]=r.useState(()=>ha(t));r.useEffect(()=>{p(ha(t))},[t]),r.useEffect(()=>{if(!o.current)return;const j=()=>{var f;return i(((f=o.current)==null?void 0:f.scrollHeight)||0)};if(j(),typeof ResizeObserver>"u")return;const C=new ResizeObserver(j);return C.observe(o.current),()=>C.disconnect()},[s]);const x=l>0,w=x?l:Number.POSITIVE_INFINITY;let u=!1,b=0;return c!=null?(u=!0,b=Ya(c,n,w)):x&&l>a&&(u=!0,b=a),e.jsxs("div",{className:u?"group relative":void 0,style:u?{height:b}:void 0,children:[e.jsx("div",{className:u?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:o,children:s})}),u?e.jsx(Eo,{appliedHeight:b,onResize:j=>p(j),onCommit:j=>Co(t,j),onReset:()=>{So(t),p(null)},minHeight:n,maxHeight:w}):null]})}function Eo({appliedHeight:t,onResize:s,onCommit:a,onReset:n,minHeight:o,maxHeight:l}){const i=r.useRef(null),c=r.useRef(t);c.current=t;const p=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:x=>{i.current={startY:x.clientY,startHeight:t},x.currentTarget.setPointerCapture(x.pointerId)},onPointerMove:x=>{if(!i.current)return;const w=xa(i.current.startHeight,x.clientY-i.current.startY,o,l);s(w)},onPointerUp:x=>{if(i.current){i.current=null;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}a(c.current)}},onDoubleClick:n,onKeyDown:x=>{if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault();const w=x.key==="ArrowDown"?p:-p,u=xa(t,w,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 xa(t,s,a,n){return Ya(t+s,a,n)}function Ya(t,s,a){return Math.min(Math.max(t,s),a)}function Qa({src:t,filename:s,message:a}){const[n,o]=r.useState(!1),[l,i]=r.useState(!1),c="repeating-conic-gradient(rgb(0 0 0 / 0.06) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||n?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(xe,{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:p=>{(p.key==="Enter"||p.key===" ")&&(p.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(Ja,{src:t,filename:s,onMaximize:()=>i(!0)}),l?e.jsx(To,{src:t,filename:s,message:a,onClose:()=>i(!1)}):null]})}function Ja({src:t,filename:s,onMaximize:a}){const n="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:n,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(Ro,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:n,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx($o,{})}),a?e.jsx("button",{type:"button",onClick:a,className:n,"aria-label":"Maximize",title:"Maximize",children:e.jsx(Mo,{})}):null]})}function To({src:t,filename:s,message:a,onClose:n}){const o=r.useRef(null);return r.useEffect(()=>{var c;const l=p=>{p.key==="Escape"&&n()};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}},[n]),Ra.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:n,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:n,"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(_o,{})}),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 ss({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 Ro(){return e.jsxs(ss,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function $o(){return e.jsxs(ss,{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 Mo(){return e.jsx(ss,{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 _o(){return e.jsx(ss,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function Do({file:t}){const[s,a]=r.useState(!0),n=Po(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(Bo,{open:s}),e.jsx(Za,{}),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(Ao,{file:t,itemId:n}):null]})})}function Po(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${Lo(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function Lo(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 Ao({file:t,itemId:s}){return t.kind==="image"?e.jsx(Qa,{src:t.rawUrl,filename:t.filename,message:t.message}):t.kind==="video"?e.jsx(Oo,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(Uo,{src:t.rawUrl,filename:t.filename}):t.source==="inline"?e.jsx(Xa,{kind:t.kind,text:t.content??"",language:t.language,itemId:s}):e.jsx(Fo,{url:t.rawUrl,kind:t.kind,language:t.language,itemId:s})}function Xa({kind:t,text:s,language:a,itemId:n}){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(No,{code:s})}):t==="markdown"?e.jsx(vs,{itemId:n,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Pt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(vs,{itemId:n,children:e.jsx(jo,{code:s,language:a})}):e.jsx(vs,{itemId:n,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 vs({itemId:t,children:s}){return t?e.jsx(Io,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function Fo({url:t,kind:s,language:a,itemId:n}){const[o,l]=r.useState(null);return r.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(xe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Xa,{kind:s,text:o.text,language:a,itemId:n})}function Oo({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(xe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function Uo({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(Za,{}),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(Ja,{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(xe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function Bo({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 Za(){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 Ms=r.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(Wo,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(Nr,{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(Do,{file:s.file}):s.kind==="tool"?e.jsx(Yo,{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(Ho,{content:s.content}):null:s.kind==="compact"?e.jsx(Go,{summary:s.summary}):s.kind==="notice"?e.jsx(qo,{notice:s.notice}):s.kind==="notification"?Wn(s.status)?e.jsx(Ko,{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(Pt,{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"})]})})})}),Vo=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function zo({turn:t}){const s=r.useContext(qa);if(!(!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&Vo.test(t.id)))return e.jsx(Ms,{turn:t});const n=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",p=`${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:["· ",Da(o),i!=null?` · ${i}%`:""]}):null]}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${p} hover:text-accent`,children:e.jsx(Ye,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${p} hover:text-rose-500`,children:e.jsx(at,{width:13,height:13})})]}),e.jsx(Ms,{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 Ho({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(Pt,{children:t})]})})}function Go({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 Wo({sender:t}){var n;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=((n=t.name)==null?void 0:n.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(Fs,{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 Ko({summary:t}){const s=r.useContext(Vs),a=!!(s!=null&&s.enabled),n=!!(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:n,"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:n?"Continuing…":"Continue"})})]})})}function qo({notice:t}){const s=r.useContext(Vs),a=t.retryable&&!!(s!=null&&s.enabled),n=!!(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",p=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:[p,"."]})," ",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:n,"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:n?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Yo({tool:t}){var h,F;const s=$r(t.toolName),a=Mr(t.toolName,t.output),n=s.isPaddock?zr(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]=r.useState(o),c=r.useContext(Ka),p=r.useContext(Wa),x=r.useRef(null),[w,u]=r.useState(!1),b=p!=null&&p.focused&&p.focused.toolUseId===t.toolUseId?p.focused.nonce:null;r.useEffect(()=>{var g;if(b==null)return;i(!0),(g=x.current)==null||g.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const X=setTimeout(()=>u(!1),3200);return()=>clearTimeout(X)},[b]);const j=r.useContext(Ga),C=r.useContext(Bs),f=!!t.pending,m=ts.has(t.toolName),T=t.toolUseId?C==null?void 0:C.get(t.toolUseId):void 0,$=m?Kt(t.subagentDurationMs??(T==null?void 0:T.elapsedMs)):Kt(t.durationMs),M=t.subagentCostUsd!=null?`~${_a(t.subagentCostUsd)}`:null,k=!m&&Br(t),L=t.monitorEvents??[],R=t.editDiff,P=!!R,N=t.toolName==="Read"?t.readInfo:void 0,O=N!=null&&N.isImage&&N.projectRelPath&&c?c(N.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),K=B?Wr(B):null,z=N?Kr(N):null,q=T!=null?T.running:Ar(t,j),Y=!!(m&&t.hasSubagent&&t.toolUseId),ee=q&&t.toolUseId?(h=C==null?void 0:C.get(t.toolUseId))==null?void 0:h.latestStep:void 0,ae=m?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,te=m?ee??t.description:a?_r(a):P?((F=R.filePath)==null?void 0:F.split("/").pop())??R.filePath:N?N.basename??N.filePath??t.inputSummary:I?I.subject:t.inputSummary,ue=(N==null?void 0:N.filePath)??(I==null?void 0:I.description)??(ee?t.description:void 0)??te??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:x,className:`w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-colors ${w?"subagent-reveal ":""}${t.isError?"border-rose-300/70 bg-rose-50/60 dark:border-rose-900/60 dark:bg-rose-950/30":m?"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":""}`}),m?e.jsx(Os,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-accent"}`}):k?e.jsx(at,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-sky-600 dark:text-sky-400"}`}):n?e.jsx(n,{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"}`}):N?e.jsx(_t,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):B?e.jsx($a,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):U||I?e.jsx(dt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-rose-500":"text-paddock-500"}`}):e.jsx(Ma,{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:ae}),m&&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(fa,{status:U.from}),e.jsx("span",{className:"text-paddock-400",children:"→"}),e.jsx(fa,{status:U.to})]}):U.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:U.updatedFields.join(", ")})]}):te&&e.jsx("span",{className:`min-w-0 truncate font-mono ${ee?"text-accent/90":"text-paddock-500 dark:text-paddock-400"}`,title:ue,children:te}),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||q?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&&L.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-[10px] text-sky-600 dark:text-sky-400",children:[L.length," event",L.length===1?"":"s"]}),k&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-[10px] font-semibold ${Vr(t.taskStatus)}`,children:t.taskStatus}),P&&(R.additions>0||R.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-[10px] font-semibold tabular-nums",children:[R.additions>0&&e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",R.additions]}),R.additions>0&&R.deletions>0&&" ",R.deletions>0&&e.jsxs("span",{className:"text-rose-600 dark:text-rose-400",children:["−",R.deletions]})]}),z&&e.jsx("span",{className:"whitespace-nowrap font-mono text-[10px] text-paddock-400 tabular-nums",children:z}),K&&e.jsx("span",{className:"whitespace-nowrap font-mono text-[10px] font-medium text-paddock-500 tabular-nums dark:text-paddock-400",children:K}),(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.jsx("span",{className:"text-paddock-400",children:$}),M&&e.jsx("span",{className:"text-paddock-400",children:M})]})]})]}),l&&(Y?e.jsx(Zo,{toolUseId:t.toolUseId,live:q}):k&&L.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:L.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(Lr,{data:a}):P?e.jsx(Qo,{diff:R}):O?e.jsx("div",{className:"border-t border-paddock-200/70 dark:border-paddock-800",children:e.jsx(Qa,{src:O,filename:(N==null?void 0:N.basename)??"image"})}):D?e.jsx(Jo,{bash:y}):I&&I.description?e.jsx(Xo,{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 Qo({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((n,o)=>e.jsxs("div",{className:`flex ${Hr(n.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular-nums opacity-40",children:ua(n.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular-nums opacity-40",children:ua(n.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:n.t===" "?"":n.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:n.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 fa({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-[10px] font-semibold ${Gr(t)}`,children:t})}function Jo({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 Xo({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 ka=2e3;function Zo({toolUseId:t,live:s=!1}){var w,u;const a=r.useContext(Ha),[n,o]=r.useState(null),[l,i]=r.useState(!1),c=(u=(w=r.useContext(Bs))==null?void 0:w.get(t))==null?void 0:u.messages;r.useEffect(()=>{o(null),i(!1)},[t]),r.useEffect(()=>{if(c)return;if(!a){i(!0);return}let b=!1,j;const C=()=>{a(t).then(f=>{b||(o(f),s&&(j=setTimeout(C,ka)))}).catch(()=>{b||(s?j=setTimeout(C,ka):i(!0))})};return C(),()=>{b=!0,j&&clearTimeout(j)}},[a,t,s,!!c]);const p=c??n,x=r.useMemo(()=>Yt(p??[]),[p]);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"}):p==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…"})]}):x.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:[x.map(b=>e.jsx(Ms,{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 el(t){const{projectSlug:s,initialSessionId:a,loadHistory:n,onSessionEstablished:o,onSessionStarted:l,onTurnComplete:i,sessionRef:c,jobRef:p,pendingCancelRef:x,streamingRef:w,awaitingSessionRef:u,isNewSessionRef:b,startedNotifiedRef:j,establishedHereRef:C,modelRef:f,cancelledRef:m,noticeThisTurnRef:T,seenInjectionsRef:$,onQueuedFlushedRef:M,setTurns:k,setStreaming:L,setUsage:R,setSessionUsage:P,setError:N}=t;r.useEffect(()=>{const O=I=>{const D=c.current;return D?I.sessionId===D?!0:I.sessionId==null&&w.current:u.current},y=I=>{c.current=I,u.current=!1,U.setSessionId(I),b.current&&!j.current&&(j.current=!0,C.current=I,f.current&&Ts(I,s,f.current),l==null||l(I))},B=I=>{p.current=I,x.current&&(x.current=!1,Pe.cancel(I))},U=Pe.subscribe(s,c.current,{onResponse:(I,D)=>{O(D)&&(D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId),Yr(k,I))},onToolStart:(I,D)=>{O(D)&&(D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId),k(K=>I.toolUseId&&K.some(z=>z.kind==="tool"&&z.tool.toolUseId===I.toolUseId)?K:[...De(K),{kind:"tool",id:ze(),tool:I}]))},onToolCall:(I,D)=>{if(!O(D))return;D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId);const K=za(I);k(z=>{if(I.toolUseId){const Y=z.findIndex(ee=>ee.kind==="tool"&&ee.tool.toolUseId===I.toolUseId);if(Y!==-1){const ee=z[Y].id,ae=z.slice();return ae[Y]=K?{kind:"file",id:ee,file:K}:{kind:"tool",id:ee,tool:I},ae}}const q=K?{kind:"file",id:ze(),file:K}:{kind:"tool",id:ze(),tool:I};return[...De(z),q]})},onMessageBoundary:I=>{O(I)&&(I.jobId&&B(I.jobId),k(D=>De(D)))},onComplete:I=>{if(O(I)){I.jobId&&B(I.jobId),w.current=!1,L(!1),k(D=>pa(De(D))),I.usage&&R(I.usage);{const D=I.sessionId??c.current;D&&A.chatContext(s,D).then(K=>P(K)).catch(()=>{})}if(I.sessionId){const D=b.current&&c.current!==I.sessionId;y(I.sessionId),(D||b.current)&&(b.current=!1,f.current&&Ts(I.sessionId,s,f.current),C.current=I.sessionId,o==null||o(I.sessionId))}!I.success&&I.error&&!T.current&&N(I.error);{const D=I.sessionId??c.current;i==null||i(D&&I.usage?{sessionId:D,usage:I.usage}:void 0)}m.current=!1}},onError:I=>{w.current&&(w.current=!1,L(!1),p.current=null,k(D=>pa(De(D))),N(I),m.current=!1)},onResync:()=>{const I=c.current;!I||!n||n(I).then(D=>k(Yt(D))).catch(()=>{})},onActive:({running:I,jobId:D})=>{I?(D&&B(D),w.current=!0,L(!0)):(w.current=!1,L(!1),p.current=null,k(K=>De(K)),m.current=!1,x.current=!1)},onQueuedFlushed:({text:I})=>{M.current(I)},onInjected:(I,D)=>{if(!O(D))return;D.jobId&&B(D.jobId),D.sessionId&&y(D.sessionId);const K=`${I.timestamp} ${I.content}`;$.current.has(K)||($.current.add(K),k(z=>[...De(z),{kind:"user",id:ze(),content:I.content,sender:I.sender}]))},onKilledTask:({summary:I,timestamp:D})=>{const K=`killed ${D}`;$.current.has(K)||($.current.add(K),k(z=>[...De(z),{kind:"notification",id:ze(),summary:I,status:"killed"}]))},onNotice:(I,D)=>{O(D)&&(T.current=!0,k(K=>[...De(K),{kind:"notice",id:ze(),notice:I}]))}});return()=>{U.unsubscribe()}},[s,a,n,o,l,i])}const tl="paddock:attachments:";function en(t,s){return tl+(t??`new:${s}`)}function sl(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 al(t,s){try{const a=localStorage.getItem(en(t,s));if(!a)return[];const n=JSON.parse(a);return Array.isArray(n)?n.map(sl).filter(o=>o!==null):[]}catch{return[]}}function nl(t,s,a){try{const n=en(t,s);a.length>0?localStorage.setItem(n,JSON.stringify(a)):localStorage.removeItem(n)}catch{}}function rl({projectSlug:t,initialSessionId:s,attachmentsDefault:a,projectAttachments:n,sessionRef:o,setError:l}){const[i,c]=r.useState(()=>al(s,t)),p=r.useRef([]);p.current=i;const[x,w]=r.useState(!1),[u,b]=r.useState(!1),j=r.useRef(null);r.useEffect(()=>{nl(s,t,i)},[i,s,t]);const C=r.useMemo(()=>{const P=a??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},N=n??{};return{enabled:N.enabled??P.enabled,maxFileSizeMb:N.maxFileSizeMb??P.maxFileSizeMb,maxFilesPerMessage:N.maxFilesPerMessage??P.maxFilesPerMessage,allowedTypes:N.allowedTypes??P.allowedTypes}},[a,n]),f=C.enabled,m=r.useCallback(async P=>{if(!f||P.length===0)return;const N=C.maxFileSizeMb*1024*1024,O=C.maxFilesPerMessage-p.current.length;if(O<=0){l(`You can attach at most ${C.maxFilesPerMessage} files per message.`);return}const y=[];for(const B of P.slice(0,O)){if(!wr(C.allowedTypes,B.type,B.name)){l(`File type not allowed: ${B.name}`);continue}if(B.size>N){l(`File too large (max ${C.maxFileSizeMb} MB): ${B.name}`);continue}y.push(B)}if(P.length>O&&l(`You can attach at most ${C.maxFilesPerMessage} files per message.`),y.length!==0){w(!0);try{const{files:B}=await A.uploadAttachments(t,o.current??"new",y);c(U=>[...U,...B])}catch(B){l(B instanceof Error?B.message:"Upload failed.")}finally{w(!1)}}},[f,C,t]),T=r.useCallback(P=>{c(N=>N.filter(O=>O.id!==P))},[]),$=r.useCallback(P=>{var O;if(!f)return;const N=Array.from(((O=P.clipboardData)==null?void 0:O.files)??[]);N.length>0&&(P.preventDefault(),m(N))},[f,m]),M=r.useCallback(P=>{var N;f&&Array.from(((N=P.dataTransfer)==null?void 0:N.types)??[]).includes("Files")&&(P.preventDefault(),b(!0))},[f]),k=r.useCallback(P=>{P.currentTarget===P.target&&b(!1)},[]),L=r.useCallback(P=>{var O;if(!f)return;const N=Array.from(((O=P.dataTransfer)==null?void 0:O.files)??[]);N.length>0&&(P.preventDefault(),b(!1),m(N))},[f,m]),R=r.useCallback(P=>{const N=Array.from(P.target.files??[]);N.length>0&&m(N),P.target.value=""},[m]);return{attachments:i,attachRef:p,setAttachments:c,uploading:x,dragOver:u,fileInputRef:j,attachConfig:C,attachEnabled:f,addFiles:m,removeAttachment:T,onComposerPaste:$,onComposerDragOver:M,onComposerDragLeave:k,onComposerDrop:L,onPickFiles:R}}function ol({projectSlug:t,initialSessionId:s,loadHistory:a,onSessionEstablished:n,onSessionStarted:o,onTurnComplete:l,preloadAvailable:i=!1,projectModel:c,projectModels:p,forkParent:x,onOpenForkParent:w,autoFocus:u,emptyHint:b,placeholder:j,trigger:C,projectRecovery:f,projectAttachments:m,onForkFromMessage:T,onRevertToMessage:$}){const[M,k]=r.useState([]),[L,R]=r.useState(()=>kr(s,t)),P=r.useRef(null),[N,O]=r.useState(!1),[y,B]=r.useState(!1),[U,I]=r.useState(null),[D,K]=r.useState(Pe.state),[z,q]=r.useState(null),[Y,ee]=r.useState(()=>Jn(s,t)),ae=r.useRef(Y),te=r.useRef(Xn(s,t)),ue=r.useRef(!1),h=r.useRef(!1),[F,X]=r.useState(!0),g=!s,Z=r.useRef(!1),[pe,He]=r.useState([]),[ge,he]=r.useState(null),[ce,je]=r.useState(null),[Ie,ie]=r.useState(null),[Ce,Te]=r.useState(null),[Se,Ae]=r.useState([]),[ye,Ee]=r.useState(0),[Fe,W]=r.useState(!1),fe=r.useRef(null),[se,$e]=r.useState(null),[Qe,Oe]=r.useState(null),Ge=c??ge,Je=r.useMemo(()=>p&&p.length>0?pe.filter(v=>p.includes(v.id)):pe,[pe,p]),be=r.useRef(s??null),S=r.useRef(null),Q=r.useRef(!1),{attachments:ne,attachRef:de,setAttachments:re,uploading:We,dragOver:wt,fileInputRef:J,attachConfig:as,attachEnabled:Xe,removeAttachment:Nt,onComposerPaste:Lt,onComposerDragOver:ut,onComposerDragLeave:Ze,onComposerDrop:ns,onPickFiles:pt}=rl({projectSlug:t,initialSessionId:s,attachmentsDefault:Ce,projectAttachments:m,sessionRef:be,setError:I}),nt=r.useCallback(v=>be.current?A.subagentMessages(t,be.current,v):Promise.resolve([]),[t]),et=lo(M),tt=oo(et,nt,N),At=r.useMemo(()=>et.filter(v=>{var _;return((_=tt.get(v.toolUseId))==null?void 0:_.running)??N}),[et,tt,N]),ke=r.useMemo(()=>t?v=>A.projectFileRawUrl(t,v):null,[t]),Me=r.useRef(!s),rt=r.useRef(!1),yt=r.useRef(!1),Ct=r.useRef(!1),St=r.useRef(null),mt=r.useRef(null),Ke=r.useRef(!0),Ft=r.useRef(new Set),rs=r.useCallback(()=>{const v=mt.current;v&&(Ke.current=v.scrollHeight-v.scrollTop-v.clientHeight<80)},[]);r.useLayoutEffect(()=>{const v=mt.current;v&&Ke.current&&(v.scrollTop=v.scrollHeight)},[M]);const[Ot,Ut]=r.useState(null),Bt=r.useMemo(()=>({focused:Ot,focus:v=>{Ke.current=!1,Ut(_=>({toolUseId:v,nonce:((_==null?void 0:_.nonce)??0)+1}))}}),[Ot]);r.useEffect(()=>Pe.onState(K),[]),r.useEffect(()=>{let v=!1;return A.getModels().then(_=>{v||(He(_.models),he(_.defaultModel),ie(_.recoveryDefault),Te(_.attachmentsDefault))}).catch(()=>{}),()=>{v=!0}},[]),r.useEffect(()=>{let v=!1;return A.projectCommands(t).then(_=>{v||Ae(_)}).catch(()=>{}),()=>{v=!0}},[t]);const qe=r.useMemo(()=>{if(!L.startsWith("/"))return null;const v=L.slice(1);return/\s/.test(v)?null:v},[L]),_e=r.useMemo(()=>{if(qe===null)return[];const v=qe.toLowerCase();return Se.filter(_=>_.name.toLowerCase().includes(v))},[qe,Se]),ht=qe!==null&&!Fe&&_e.length>0;r.useEffect(()=>{Ee(0)},[qe]),r.useEffect(()=>{W(!1)},[qe]);const It=r.useCallback(v=>{R(`/${v.name} `),requestAnimationFrame(()=>{var _;return(_=P.current)==null?void 0:_.focus()})},[]),os=r.useCallback(v=>{je(v),fe.current=v,Ts(be.current??s,t,v)},[t,s]);r.useEffect(()=>{if(s&&s===St.current){Me.current=!1;return}let v=!1;return be.current=s??null,Me.current=!s,S.current=null,rt.current=!1,yt.current=!1,Ct.current=!1,I(null),O(!1),s&&a?(B(!0),k([]),a(s).then(_=>{v||k(Yt(_))}).catch(()=>{v||I("Could not load this chat's history.")}).finally(()=>{v||B(!1)})):(k([]),B(!1)),s&&A.chatContext(t,s).then(_=>{v||!_||($e({inputTokens:_.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:_.contextTokens,contextLimit:_.contextLimit}),Oe(_))}).catch(()=>{}),()=>{v=!0}},[t,s,a]);const Vt=r.useCallback(async()=>{if(!(!s||!a)){try{const v=await a(s);k(Yt(v))}catch{I("Could not reload this chat's history.")}try{const v=await A.chatContext(t,s);v&&($e({inputTokens:v.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:v.contextTokens,contextLimit:v.contextLimit}),Oe(v))}catch{}}},[s,a,t]),zt=r.useCallback(v=>{if(!$)return;const _=M.findIndex(Ve=>Ve.id.split("#")[0]===v),ve=_>=0&&M[_].kind==="user";let Ue=_+1;if(ve){let Ve=_-1;for(;Ve>=0&&M[Ve].kind!=="assistant";)Ve--;Ue=Ve+1}else for(;Ue<M.length&&(M[Ue].kind==="tool"||M[Ue].kind==="file");)Ue++;const Be=_>=0?M.slice(Ue):[],fs=Be.filter(Ve=>Ve.kind==="tool").length;q({uuid:v,count:Be.length,toolCount:fs,anchorIsUser:ve})},[$,M]),ls=r.useCallback(async()=>{if(z){try{await($==null?void 0:$(z.uuid)),await Vt()}catch{throw new Error("Could not revert this chat.")}q(null)}},[z,$,Vt]),is=r.useMemo(()=>T&&$?{onFork:T,onRevert:zt,contextLimit:se==null?void 0:se.contextLimit}:null,[T,$,zt,se==null?void 0:se.contextLimit]);r.useEffect(()=>{const _=xr(s,t)??Ge;_&&(je(_),fe.current=_)},[t,s,Ge]),r.useEffect(()=>{s&&s===St.current||($e(null),Oe(null))},[t,s]),r.useEffect(()=>{gr(s,t,L)},[L,s,t]),r.useEffect(()=>{Zn(s,t,Y),er(s,t,Y?te.current:null)},[Y,s,t]),r.useEffect(()=>{s&&Pe.setQueued(t,s,Y,Y?te.current:null)},[Y,s,t,Pe]),r.useEffect(()=>{var v;(u||!s)&&((v=P.current)==null||v.focus())},[]);const xt=r.useCallback(v=>{v&&(Ke.current=!0,k(_=>[...De(_),{kind:"user",id:ze(),content:v}])),ae.current=null,te.current=null,ee(null)},[]),Ht=r.useRef(xt);Ht.current=xt,el({projectSlug:t,initialSessionId:s,loadHistory:a,onSessionEstablished:n,onSessionStarted:o,onTurnComplete:l,sessionRef:be,jobRef:S,pendingCancelRef:Q,streamingRef:rt,awaitingSessionRef:yt,isNewSessionRef:Me,startedNotifiedRef:Ct,establishedHereRef:St,modelRef:fe,cancelledRef:ue,noticeThisTurnRef:h,seenInjectionsRef:Ft,onQueuedFlushedRef:Ht,setTurns:k,setStreaming:O,setUsage:$e,setSessionUsage:Oe,setError:I});const Gt=r.useCallback(v=>{I(null),Ke.current=!0;const _=v.startsWith("/")?[]:de.current;if(k(Be=>[...De(Be),{kind:"user",id:ze(),content:v,..._.length>0?{attachments:_}:{}}]),_.length>0&&(re([]),de.current=[]),P.current&&(P.current.style.height="auto"),O(!0),rt.current=!0,h.current=!1,S.current=null,Q.current=!1,be.current===null&&(yt.current=!0),v.startsWith("/")){Z.current=!0,Pe.sendCommand(t,v,be.current);return}const Ue=Me.current&&!Z.current&&F;Z.current=!0,Pe.send(t,v,be.current,{preloadContext:Ue,model:fe.current??void 0,attachments:_.map(Be=>({id:Be.id,filename:Be.filename,kind:Be.kind}))})},[t,F]),Et=r.useCallback(()=>{const v=L.trim();if(!(!v&&de.current.length===0)){if(N){ee(_=>{const ve=_?`${_}
|
|
8
|
+
${v}`:v;return ae.current=ve,_==null&&(te.current=Date.now()),ve}),R(""),P.current&&(P.current.style.height="auto");return}R(""),Gt(v)}},[L,N,Gt]),cs=r.useCallback(()=>{const v=ae.current;v!=null&&(ae.current=null,te.current=null,ee(null),R(_=>_.trim()?`${v}
|
|
9
|
+
${_}`:v),requestAnimationFrame(()=>{const _=P.current;_&&(_.style.height="auto",_.style.height=`${Math.min(_.scrollHeight,192)}px`,_.focus())}))},[]),ds=r.useCallback(()=>{ae.current=null,te.current=null,ee(null)},[]),us=r.useCallback(()=>{ue.current=!0,S.current?Pe.cancel(S.current):Q.current=!0},[]),Wt=r.useCallback(()=>{const v=be.current;v&&(rt.current||(O(!0),Pe.continueChat(t,v)))},[t]),ps=r.useMemo(()=>({enabled:(f==null?void 0:f.surfaceKilledTask)??(Ie==null?void 0:Ie.surfaceKilledTask)??!0,busy:N,onContinue:Wt}),[t,f,Ie,N,Wt]),ms=v=>{if(ht){if(v.key==="ArrowDown"){v.preventDefault(),Ee(_=>(_+1)%_e.length);return}if(v.key==="ArrowUp"){v.preventDefault(),Ee(_=>(_-1+_e.length)%_e.length);return}if(v.key==="Tab"){v.preventDefault(),It(_e[ye]);return}if(v.key==="Enter"){const _=_e[ye];if(_&&_.name!==qe){v.preventDefault(),It(_);return}}if(v.key==="Escape"){v.preventDefault(),W(!0);return}}v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),Et())},hs=r.useCallback(v=>{R(ve=>ve.trim()?`${ve.trimEnd()} ${v}`:v);const _=P.current;_&&requestAnimationFrame(()=>{_.style.height="auto",_.style.height=`${Math.min(_.scrollHeight,192)}px`,_.focus()})},[]),xs=M.length===0&&!y;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:mt,onScroll:rs,className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4 py-6",children:[C&&e.jsx(Er,{trigger:C,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"})]}),xs&&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(Os,{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(Ha.Provider,{value:nt,children:e.jsx(Ga.Provider,{value:N,children:e.jsx(Bs.Provider,{value:tt,children:e.jsx(Wa.Provider,{value:Bt,children:e.jsx(Ka.Provider,{value:ke,children:e.jsx(Va.Provider,{value:t,children:e.jsx(Vs.Provider,{value:ps,children:e.jsx(qa.Provider,{value:is,children:e.jsx("div",{className:"space-y-4",children:M.map(v=>e.jsx(zo,{turn:v},v.id))})})})})})})})})})]})}),e.jsx(eo,{running:At,activity:tt,onReveal:Bt.focus}),N&&e.jsx(mo,{}),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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:U})]})}),Y!=null&&e.jsx(ho,{text:Y,onEdit:cs,onClear:ds}),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(io,{checked:F,available:i,onChange:X}),e.jsx(co,{models:Je,model:ce,onSelectModel:os,usage:se,sessionUsage:Qe,forkParent:x,onOpenForkParent:w}),Xe&&(ne.length>0||We)&&e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2","data-testid":"attachment-tray",children:[ne.map(v=>e.jsx(Cr,{attachment:v,onRemove:Nt},v.id)),We&&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 ${wt?"border-accent ring-2 ring-accent/30":"border-paddock-300 dark:border-paddock-700"}`,onDragOver:Xe?ut:void 0,onDragLeave:Xe?Ze:void 0,onDrop:Xe?ns:void 0,children:[wt&&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"}),ht&&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:_e.map((v,_)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${_===ye?"bg-paddock-100 dark:bg-paddock-800":""}`,onMouseEnter:()=>Ee(_),onMouseDown:ve=>{ve.preventDefault(),It(v)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",v.name]}),v.argumentHint&&e.jsx("span",{className:"shrink-0 text-paddock-400",children:v.argumentHint}),v.description&&e.jsx("span",{className:"ml-auto truncate text-paddock-500",children:v.description})]})},v.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:L,placeholder:N?"Queue a message to send next…":j??"Message Claude…",onChange:v=>{R(v.target.value);const _=v.target;_.style.height="auto",_.style.height=`${Math.min(_.scrollHeight,192)}px`},onKeyDown:ms,onPaste:Xe?Lt:void 0}),Xe&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:J,type:"file",multiple:!0,accept:vr(as.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:pt}),e.jsx("button",{type:"button",onClick:()=>{var v;return(v=J.current)==null?void 0:v.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(un,{width:16,height:16})})]}),e.jsx(pr,{onText:hs}),N?e.jsxs("button",{type:"button",onClick:us,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(Ss,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}):e.jsxs("button",{type:"button",onClick:Et,disabled:!L.trim()&&ne.length===0||We,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(Ta,{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 ",N?"queue":"send"," ·"," ",e.jsx("kbd",{className:"font-sans",children:"Shift+Enter"})," for newline"]}),e.jsx(xo,{state:D})]})]})}),e.jsx(qt,{open:z!==null,wide:!0,dismissOnBackdrop:!1,title:"Revert this chat back to here?",confirmLabel:"Revert chat",message:z&&e.jsxs(e.Fragment,{children:[z.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:[z.count," message",z.count===1?"":"s"]})," ","will be removed",z.toolCount>0?e.jsxs(e.Fragment,{children:[", including"," ",e.jsxs("span",{className:"font-medium text-ink dark:text-ink-dark",children:[z.toolCount," tool call",z.toolCount===1?"":"s"]}),"."]}):"."]}),z.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:ls,onClose:()=>q(null)})]})}function ll(t){var n;const s=t.untracked?"??":(t.status||"").trim(),a=((n=s[0])==null?void 0:n.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 il({slug:t,status:s,onStatusChange:a,selectedFile:n,onSelectFile:o}){var X;const[l,i]=r.useState(null),[c,p]=r.useState(null),x=o!==void 0,w=x?n??null:c,u=r.useCallback(g=>{x?o==null||o(g):p(g)},[x,o]),[b,j]=r.useState(""),[C,f]=r.useState(!1),[m,T]=r.useState(!1),[$,M]=r.useState(null),[k,L]=r.useState(null),[R,P]=r.useState(new Set),N=s.files,O=N.length,y=N.filter(g=>!R.has(g.path)).map(g=>g.path),B=y.length,U=B===N.length&&N.length>0,I=r.useCallback(g=>{P(Z=>{const pe=new Set(Z);return pe.has(g)?pe.delete(g):pe.add(g),pe})},[]),D=r.useCallback(()=>P(new Set),[]),K=r.useCallback(()=>P(new Set(N.map(g=>g.path))),[N]),z=r.useCallback(async()=>{const g=await A.gitInfo().catch(()=>null);g&&i(g)},[]);r.useEffect(()=>{z()},[z]);const q=r.useCallback(async()=>{const g=await A.gitStatus(t).catch(()=>null);g&&a(g)},[t,a]),Y=w&&N.some(g=>g.path===w)?w:((X=N[0])==null?void 0:X.path)??null,ee=N.find(g=>g.path===Y)??null,ae=r.useCallback(async()=>{const g=b.trim();if(!(!g||C||y.length===0)){f(!0),M(null),L(null);try{const Z=U?await A.gitCommit(t,g):await A.gitCommit(t,g,y);Z.committed?(j(""),P(new Set),L(Z.hash?`Committed ${Z.hash.slice(0,7)}`:"Committed"),await q(),await z()):L(Z.error??"Nothing to commit")}catch(Z){M(Z instanceof Ne?Z.message:"Commit failed")}finally{f(!1)}}},[b,C,y,U,t,q,z]),te=(l==null?void 0:l.ahead)??0,ue=(l==null?void 0:l.configured)??!1,h=ue&&te>0&&!m,F=r.useCallback(async()=>{if(h){T(!0),M(null),L(null);try{const g=await A.gitPush();g.pushed?(L("Pushed to remote"),await z()):M(g.error??"Push failed")}catch(g){M(g instanceof Ne?g.message:"Push failed")}finally{T(!1)}}},[h,z]);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(Ye,{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(dt,{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(hl,{info:l,onChanged:z}),e.jsxs("button",{type:"button",onClick:()=>void F(),disabled:!h,title:ue?te>0?`Push ${te} commit${te===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx(pn,{width:13,height:13}),m?"Pushing…":"Push",ue&&te>0&&e.jsxs("span",{className:"text-[11px] font-semibold text-accent",children:["↑",te]})]})]})]}),($||k)&&e.jsxs("div",{className:"px-4 pt-2",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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:$})]}),!$&&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"}),N.length>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-paddock-400",children:[e.jsxs("span",{children:[B,"/",N.length," selected"]}),e.jsx("button",{type:"button",onClick:U?K: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:N.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."}):N.map(g=>e.jsx(cl,{file:g,active:Y===g.path,selected:!R.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=>j(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 ae(),disabled:!b.trim()||C||B===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:N.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(dt,{width:13,height:13}),C?"Committing…":B>0&&!U?`Commit ${B} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(dl,{slug:t,file:ee})})]})]})}function Hs({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 cl({file:t,active:s,selected:a,onSelect:n,onToggleSelect:o}){const l=ll(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:n,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(Hs,{file:t})]})]})]})]})}function dl({slug:t,file:s}){const a=(s==null?void 0:s.path)??null,n=(s==null?void 0:s.untracked)??!1,[o,l]=r.useState(""),[i,c]=r.useState(!1),[p,x]=r.useState(null);if(r.useEffect(()=>{if(!a||n){l(""),x(null),c(!1);return}let u=!1;return c(!0),x(null),A.gitDiff(t,a).then(b=>{u||l(b)}).catch(b=>{u||x(b instanceof Ne?b.message:"Failed to load diff")}).finally(()=>{u||c(!1)}),()=>{u=!0}},[t,a,n]),!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(n)return e.jsx(ml,{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(p)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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:p})]})});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 w=o.split(`
|
|
10
|
+
`);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(ul,{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:w.map((u,b)=>e.jsx("div",{className:pl(u),children:u||" "},b))})})]})}function ul({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(Hs,{file:t})]})}function pl(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 ml({slug:t,file:s}){const a=s.path,[n,o]=r.useState(null),[l,i]=r.useState(!0),[c,p]=r.useState(null);r.useEffect(()=>{let w=!1;return i(!0),p(null),o(null),A.getProjectFile(t,a).then(u=>{w||o(u)}).catch(u=>{w||p(u instanceof Ne?u.message:"Failed to load file")}).finally(()=>{w||i(!1)}),()=>{w=!0}},[t,a]);const x=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(Hs,{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||!n?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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:c??"File not found."})]})}):n.kind==="image"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[x,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:A.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:[x,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:n.content})})]})}function hl({info:t,onChanged:s}){const[a,n]=r.useState(!1),[o,l]=r.useState(null),[i,c]=r.useState(!1),[p,x]=r.useState(null),[w,u]=r.useState(!1),b=r.useRef(!1);r.useEffect(()=>(b.current=!1,()=>{b.current=!0}),[]);const j=t==null?void 0:t.github,C=r.useCallback(async()=>{n(!0),x(null);try{const m=await A.githubConnect();l({userCode:m.userCode,verificationUri:m.verificationUri}),c(!0),b.current=!1;const T=Date.now()+m.expiresIn*1e3;let $=Math.max(1,m.interval)*1e3;const M=async()=>{if(!b.current){if(Date.now()>=T){c(!1),l(null),x("The code expired before authorization. Try again.");return}try{const k=await A.githubPoll(m.deviceCode);if(b.current)return;if(k.status==="authorized"){c(!1),l(null),await s();return}if(k.status==="error"){c(!1),l(null),x(k.error??"Authorization failed.");return}k.status==="slow_down"&&($+=5e3),window.setTimeout(()=>void M(),$)}catch(k){if(b.current)return;c(!1),l(null),x(k instanceof Ne?k.message:"Polling failed.")}}};window.setTimeout(()=>void M(),$)}catch(m){x(m instanceof Ne?m.message:"Could not start the GitHub connection.")}finally{n(!1)}},[s]),f=r.useCallback(async()=>{u(!0);try{await A.githubDisconnect(),await s()}catch{}finally{u(!1)}},[s]);return j?j.configured?j.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(ks,{width:13,height:13}),"@",j.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void f(),disabled:w,className:"btn-subtle px-2 py-1 text-[11px]",title:"Disconnect GitHub",children:w?"…":"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(Ea,{width:11,height:11}),"github.com"]}),i&&e.jsx("span",{className:"text-paddock-400",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void C(),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(ks,{width:13,height:13}),a?"Starting…":"Connect GitHub"]}),p&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-rose-600 dark:text-rose-400",children:[e.jsx(xe,{width:12,height:12}),p]})]}):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(ks,{width:13,height:13}),"GitHub not configured"]}):null}function xl(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(at,{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(Ye,{width:12,height:12}),cls:"bg-violet-100 text-violet-700 dark:bg-violet-950/50 dark:text-violet-400"}:t==="adopted"?{label:"Adopted",icon:e.jsx(Zt,{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 fl(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 kl(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 ws(t){return t.origin!=="human"&&t.origin!=="adopted"}function gl(t){return t.origin==="scheduled"?t.schedule?`schedule · ${t.schedule}`:"schedule":t.origin==="spawned"?t.depth>1?`spawned · ${t.depth} levels deep`:"spawned by another chat":t.origin==="adopted"?"adopted from the Claude Code CLI":"you"}function bl({run:t,title:s,onOpen:a}){var c,p;const n=xl(t.origin),o=fl(t.status),l=t.sessionId!=null,i=((c=t.prompt)==null?void 0:c.trim())||((p=t.summary)==null?void 0:p.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 ${n.cls}`,children:[n.icon,n.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:gl(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:kl(t)}),e.jsx("span",{className:"font-mono text-paddock-400 dark:text-paddock-600",title:"Per-run cost is coming soon",children:"—"})]})]})}function jl({slug:t,state:s,chats:a,onOpenChat:n}){const{data:o,loading:l,error:i,refresh:c,markSeen:p}=s,[x,w]=r.useState("unattended");r.useEffect(()=>{p()},[t]);const u=r.useMemo(()=>{const m=new Map;for(const T of a)m.set(T.sessionId,T.name);return T=>T&&m.get(T)||(T?T.slice(0,8):"unknown chat")},[a]),b=(o==null?void 0:o.runs)??[],j=r.useMemo(()=>b.filter(ws).length,[b]),C=r.useMemo(()=>x==="unattended"?b.filter(ws):b,[b,x]),f=r.useMemo(()=>b.filter(m=>m.isNew&&ws(m)).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(ga,{active:x==="unattended",onClick:()=>w("unattended"),children:["Unattended",j>0?` (${j})`:""]}),e.jsx(ga,{active:x==="all",onClick:()=>w("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…"}):C.length===0?e.jsx(vl,{filter:x,hasAny:b.length>0}):e.jsx("div",{children:C.map(m=>e.jsx(bl,{run:m,title:u(m.sessionId),onOpen:()=>m.sessionId&&n(m.sessionId)},m.jobId))})})]})}function ga({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 vl({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 wl(t){const[s,a]=r.useState(null),[n,o]=r.useState(!0),[l,i]=r.useState(null),[c,p]=r.useState(!1),x=r.useCallback(async()=>{o(!0),p(!1);try{const b=await A.projectRuns(t);a(b),i(null)}catch(b){i(b instanceof Error?b.message:"Failed to load run history")}finally{o(!1)}},[t]);r.useEffect(()=>{x()},[x]);const w=r.useCallback(async()=>{p(!0),await A.markRunsSeen(t).catch(()=>{})},[t]),u=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:n,error:l,newUnattended:u,refresh:x,markSeen:w}}function Nl({slug:t,name:s}){const[a,n]=r.useState(null),[o,l]=r.useState(null),[i,c]=r.useState(!0);return r.useEffect(()=>{let p=!1;return c(!0),l(null),n(null),A.getProjectFile(t,s).then(x=>{p||n(x)}).catch(x=>{p||l(x instanceof Error?x.message:"Failed to load file")}).finally(()=>{p||c(!1)}),()=>{p=!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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:o??"File not found."})]})}):a.kind==="image"?e.jsx(Cl,{slug:t,name:a.name}):a.kind==="html"?e.jsx(yl,{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(Pt,{mermaid:!0,children:a.content})})}function yl({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(Sl,{}),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 Cl({slug:t,name:s}){const[a,n]=r.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(xe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:A.projectFileRawUrl(t,s),alt:s,onError:()=>n(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function Sl(){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 Il({project:t,path:s,onNavigate:a,onTogglePin:n}){const o=t.slug,[l,i]=r.useState(null),[c,p]=r.useState(!1),[x,w]=r.useState(null),[u,b]=r.useState(!0);r.useEffect(()=>{let m=!1;return b(!0),w(null),i(null),p(!1),A.listProjectDir(o,s).then(T=>{m||(T.kind==="file"?p(!0):i(T))}).catch(T=>{m||w(T instanceof Error?T.message:"Failed to load files")}).finally(()=>{m||b(!1)}),()=>{m=!0}},[o,s]);const j=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",C=e.jsx(El,{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:[C,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(m=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-paddock-200/60 dark:bg-paddock-800/60"},m))})]})});if(x)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[C,e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-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(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:x})]})]})});if(c){const m=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:C}),e.jsxs("button",{onClick:()=>n(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 ${m?"bg-accent/10 text-accent":"text-paddock-500 hover:bg-paddock-200/60 dark:hover:bg-paddock-800/60"}`,title:m?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(Mt,{width:13,height:13}),m?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(Nl,{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:[C,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(j),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(Is,{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((m,T)=>{const $=s?`${s}/${m.name}`:m.name,M=m.kind==="dir",k=t.pinned.includes($),L=!M,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 ${R}`,children:[e.jsxs("button",{onClick:()=>a($),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[M?e.jsx(Is,{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 ${M?"font-medium text-paddock-700 dark:text-paddock-200":"text-paddock-700 dark:text-paddock-200"}`,children:m.name}),M&&e.jsx(Xt,{width:14,height:14,className:"ml-auto shrink-0 text-paddock-300 dark:text-paddock-600"})]}),L&&e.jsxs("button",{type:"button","aria-label":k?`Unpin ${m.name}`:`Pin ${m.name}`,title:k?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>n($),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(Mt,{width:12,height:12}),k?"Pinned":"Pin"]})]},m.name)})]})]})})}function El({path:t,isFile:s,onNavigate:a}){const n=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(ba,{label:"Files",isLast:n.length===0,onClick:()=>a("")}),n.map((o,l)=>{const i=l===n.length-1,c=n.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(ba,{label:o,isLast:i,mono:!0,muted:i&&s,onClick:()=>a(c)})]},c)})]})}function ba({label:t,isLast:s,mono:a,muted:n,onClick:o}){const l=a?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${l} font-medium ${n?"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 Tl=["idea","active","paused","blocked","done","abandoned"];function Ns(t,s,a){const n={};return t!==""&&(n.overviewMaxTokens=Number(t)),s!==""&&(n.changelogMaxTokens=Number(s)),a!==""&&(n.claudeMaxTokens=Number(a)),Object.keys(n).length>0?n:null}const ja=[{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)"}],Rt="loading…";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 me({children:t}){return e.jsx("p",{className:"mt-1 text-[12px] leading-snug text-paddock-500",children:t})}function va({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(xe,{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 Rl({project:t,onSaved:s}){const[a,n]=r.useState(""),[o,l]=r.useState(!1),[i,c]=r.useState(!1),[p,x]=r.useState(null);if(r.useEffect(()=>{n(""),l(!1),x(null)},[t.slug,t.managed]),!t.managed||t.path)return e.jsx(bt,{title:"Backing",description:t.managed?"Claude works in the directory below, and Paddock curates this project's notes there.":"Claude works in the directory below. Paddock does not write project files into it — its notes stay in the project's own folder.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3",children:[t.repo&&e.jsx(jt,{label:t.path?"Repository (recorded)":"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 w=a.trim(),u=w.length>0&&!$l(w),b=async()=>{if(!(!w||u)){c(!0),x(null);try{const j=await A.promoteProject(t.slug,w);s(j),l(!1),n("")}catch(j){x(j instanceof Ne?j.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:j=>{n(j.target.value),l(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":u,"aria-label":"Git repository URL"}),u?e.jsx(me,{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(me,{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."]})]}),p&&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:p}),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(xe,{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:w}),", 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||!w||u,onClick:()=>l(!0),children:"Promote to repo-backed…"})]})}function $l(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}function Ml({project:t,onSaved:s}){var Ge,Je,be;const[a,n]=r.useState(t.name),[o,l]=r.useState(t.summary),[i,c]=r.useState(t.domain.join(", ")),[p,x]=r.useState(t.group??""),[w,u]=r.useState(t.status),[b,j]=r.useState(t.visibility),[C,f]=r.useState(t.links??[]),[m,T]=r.useState(t.model),[$,M]=r.useState(t.models??[]),[k,L]=r.useState(t.permissionMode),[R,P]=r.useState(String(t.maxTurns)),[N,O]=r.useState(t.docker),[y,B]=r.useState(t.driveMode??""),[U,I]=r.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[D,K]=r.useState(((Ge=t.curation)==null?void 0:Ge.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[z,q]=r.useState(((Je=t.curation)==null?void 0:Je.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[Y,ee]=r.useState(((be=t.curation)==null?void 0:be.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[ae,te]=r.useState([]),[ue,h]=r.useState(null),[F,X]=r.useState(null),[g,Z]=r.useState(null),[pe,He]=r.useState(!1),[ge,he]=r.useState(null),[ce,je]=r.useState(0);r.useEffect(()=>{var S,Q,ne;n(t.name),l(t.summary),c(t.domain.join(", ")),x(t.group??""),u(t.status),j(t.visibility),f(t.links??[]),T(t.model),M(t.models??[]),L(t.permissionMode),P(String(t.maxTurns)),O(t.docker),B(t.driveMode??""),I(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),K(((S=t.curation)==null?void 0:S.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),q(((Q=t.curation)==null?void 0:Q.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),ee(((ne=t.curation)==null?void 0:ne.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),he(null)},[t]),r.useEffect(()=>{let S=!1;return A.getModels().then(Q=>{S||(te(Q.models),h(Q.driveModeDefault),X(Q.maxSpawnDepthDefault),Z(Q.curationDefault))}).catch(()=>{}),()=>{S=!0}},[]);const Ie=r.useMemo(()=>C.map(S=>({label:S.label.trim(),url:S.url.trim()})).filter(S=>S.url.length>0),[C]),ie=r.useMemo(()=>i.split(",").map(S=>S.trim()).filter(Boolean),[i]),Ce=r.useMemo(()=>({name:a.trim(),status:w,group:p,summary:o.trim(),domain:ie,visibility:b,links:Ie,model:m,models:$.length>0?$:null,permissionMode:k,maxTurns:Number(R),docker:N,driveMode:y===""?null:y,maxSpawnDepth:U===""?null:Number(U),curation:Ns(D,z,Y)}),[a,w,p,o,ie,b,Ie,m,$,k,R,N,y,U,D,z,Y]),Te=r.useMemo(()=>{var Q,ne,de;const S={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(re=>({label:re.label,url:re.url})),model:t.model,models:t.models&&t.models.length>0?t.models:null,permissionMode:t.permissionMode,maxTurns:t.maxTurns,docker:t.docker,driveMode:t.driveMode??null,maxSpawnDepth:t.maxSpawnDepth??null,curation:Ns(((Q=t.curation)==null?void 0:Q.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ne=t.curation)==null?void 0:ne.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((de=t.curation)==null?void 0:de.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify(Ce)!==JSON.stringify(S)},[Ce,t]),Se=Ce.name.length===0,Ae=Number(R),ye=!Number.isInteger(Ae)||Ae<1||Ae>1e3,Ee=Number(U),Fe=U!==""&&(!Number.isInteger(Ee)||Ee<0||Ee>8),W=S=>S!==""&&(!Number.isInteger(Number(S))||Number(S)<1),fe=W(D)||W(z)||W(Y),se=async S=>{if(S.preventDefault(),!(Se||ye||Fe||fe)){He(!0),he(null);try{const Q=await A.updateProject(t.slug,Ce);s(Q),je(ne=>ne+1)}catch(Q){he(Q instanceof Ne?Q.message:"Failed to save changes")}finally{He(!1)}}},$e=ue===null?Rt:ue==="session"?"Session":"Batch",Qe=$.length>0?ae.filter(S=>$.includes(S.id)):ae,Oe=(S,Q)=>M(ne=>Q?[...ne.filter(de=>de!==S),S]:ne.filter(de=>de!==S));return e.jsxs("form",{onSubmit:se,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"}),Te&&!pe&&e.jsx("span",{className:"text-[12px] text-amber-600 dark:text-amber-400",children:"Unsaved changes"}),ce>0&&!Te&&!pe&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[12px] text-emerald-600 dark:text-emerald-400",children:[e.jsx(dt,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:pe||!Te||Se||ye||Fe||fe,children:pe?"Saving…":"Save changes"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[ge&&e.jsx("p",{className:"mb-4 rounded-lg bg-rose-50 px-3 py-2 text-sm text-rose-600 dark:bg-rose-950/40 dark:text-rose-300",children:ge}),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:S=>n(S.target.value),placeholder:"Display name","aria-invalid":Se}),Se&&e.jsx(me,{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:S=>l(S.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:w,onChange:S=>u(S.target.value),children:Tl.map(S=>e.jsx("option",{value:S,className:"capitalize",children:S},S))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:p,onChange:S=>x(S.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Es.map(S=>e.jsx("option",{value:S.slug,children:S.label},S.slug)),p&&!Es.some(S=>S.slug===p)&&e.jsx("option",{value:p,children:p})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Visibility"}),e.jsxs("select",{className:"input capitalize",value:b,onChange:S=>j(S.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:S=>c(S.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),C.length===0&&e.jsx("p",{className:"mb-2 text-[12px] italic text-paddock-400",children:"No links yet."}),e.jsx("div",{className:"space-y-2",children:C.map((S,Q)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:S.label,onChange:ne=>f(de=>de.map((re,We)=>We===Q?{...re,label:ne.target.value}:re)),placeholder:"Label","aria-label":`Link ${Q+1} label`}),e.jsx("input",{className:"input flex-1",value:S.url,onChange:ne=>f(de=>de.map((re,We)=>We===Q?{...re,url:ne.target.value}:re)),placeholder:"https://…","aria-label":`Link ${Q+1} URL`}),e.jsx("button",{type:"button",onClick:()=>f(ne=>ne.filter((de,re)=>re!==Q)),"aria-label":`Remove link ${Q+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(Us,{width:14,height:14})})]},Q))}),e.jsxs("button",{type:"button",onClick:()=>f(S=>[...S,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(ct,{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:m,onChange:S=>T(S.target.value),children:[!Qe.some(S=>S.id===m)&&e.jsx("option",{value:m,children:m}),Qe.map(S=>e.jsx("option",{value:S.id,children:S.label},S.id))]})]}),e.jsx(me,{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:S=>L(S.target.value),children:[!ja.some(S=>S.value===k)&&e.jsx("option",{value:k,children:k}),ja.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))]})]}),k==="bypassPermissions"?e.jsx(va,{children:"Claude runs every tool without asking — it can edit files and run commands unprompted."}):e.jsx(me,{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:R,onChange:S=>P(S.target.value),"aria-invalid":ye})]}),ye?e.jsx(me,{children:e.jsx("span",{className:"text-rose-600 dark:text-rose-400",children:"Must be a whole number 1–1000."})}):e.jsx(me,{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:N,onChange:S=>O(S.target.checked)}),e.jsx("span",{className:"text-sm text-paddock-700 dark:text-paddock-200",children:"Run Claude in a Docker sandbox"})]}),N?e.jsx(va,{children:"Requires a working Docker daemon on the box, or Claude won’t start."}):e.jsx(me,{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"}),ae.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:ae.map(S=>{const Q=$.length===0||$.includes(S.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:Q,onChange:ne=>{$.length===0?M(ne.target.checked?[]:ae.filter(de=>de.id!==S.id).map(de=>de.id)):Oe(S.id,ne.target.checked)},"aria-label":S.label}),e.jsx("span",{children:S.label})]},S.id)})}),$.length===0?e.jsx(me,{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(me,{children:["Restricting this project's picker to ",$.length," of ",ae.length," ","instance models."," ",e.jsx("button",{type:"button",onClick:()=>M([]),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:S=>B(S.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",$e,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),y===""&&ue===null?e.jsx(me,{children:e.jsx("span",{className:"italic text-paddock-400",children:"Loading the box-wide drive-mode default…"})}):y===""?e.jsxs(me,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-paddock-700 dark:text-paddock-200",children:$e}),". ",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(me,{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:S=>I(S.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",F??Rt,")"]}),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===""&&F===null?e.jsx(me,{children:e.jsx("span",{className:"italic text-paddock-400",children:"Loading the instance max-spawn-depth default…"})}):U===""?e.jsxs(me,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-paddock-700 dark:text-paddock-200",children:F}),". 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(me,{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==null?void 0:g.overviewMaxTokens)??Rt})`,value:D,onChange:S=>K(S.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==null?void 0:g.changelogMaxTokens)??Rt})`,value:z,onChange:S=>q(S.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==null?void 0:g.claudeMaxTokens)??Rt})`,value:Y,onChange:S=>ee(S.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),fe?e.jsx(me,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):Ns(D,z,Y)?e.jsxs(me,{children:["Overriding the instance defaults",g&&e.jsxs(e.Fragment,{children:[" ","(",g.overviewMaxTokens,"/",g.changelogMaxTokens,"/",g.claudeMaxTokens,")"]})," ","for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{K(""),q(""),ee("")},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."]}):g===null?e.jsx(me,{children:e.jsx("span",{className:"italic text-paddock-400",children:"Loading the instance curation budgets…"})}):e.jsxs(me,{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(Rl,{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(dt,{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(S=>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(Mt,{width:11,height:11,className:"text-accent"}),S]},S))}):e.jsx("span",{className:"text-paddock-400",children:"None — pin files from the Files tab"})})]})})]})})]})}const _l=/^[A-Za-z0-9._-]+$/,Dl={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},Pl={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},Ll=[{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)"}],Al={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},Fl=["read","write","web","orchestration","browser"];function Ol(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 Ul(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 Bl(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 n=Number(t.maxTurns);t.maxTurns.trim()&&Number.isFinite(n)&&n>0&&(a.maxTurns=Math.floor(n));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 Vl(t){const s=t.run.tools??[];return s.length===0?t.trigger.type==="schedule"?"Claude's tools":"No tools":`${s.length} tool${s.length===1?"":"s"}`}function wa(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function zl(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function Hl({project:t}){const s=t.slug,[a,n]=r.useState([]),[o,l]=r.useState([]),[i,c]=r.useState(["onArchive","afterTurn"]),[p,x]=r.useState(["schedule","event","webhook"]),[w,u]=r.useState(!0),[b,j]=r.useState(null),[C,f]=r.useState(null),[m,T]=r.useState(null),[$,M]=r.useState(null),[k,L]=r.useState(null),[R,P]=r.useState({}),N=r.useCallback(async()=>{u(!0);try{const h=await A.listTriggers(s);n(h.triggers),l(h.grantableTools),h.events.length>0&&c(h.events),h.triggerTypes.length>0&&x(h.triggerTypes),j(null)}catch(h){j(h instanceof Ne?h.message:"Failed to load triggers")}finally{u(!1)}},[s]),O=r.useCallback(async()=>{try{const h=await A.triggerRuntime(s);P(Object.fromEntries(h.runtime.map(F=>[F.name,F])))}catch{}},[s]);r.useEffect(()=>{N()},[N]),r.useEffect(()=>{O();const h=setInterval(()=>{document.visibilityState==="visible"&&O()},1e4);return()=>clearInterval(h)},[O]),r.useEffect(()=>{if(!C)return;const h=setTimeout(()=>f(null),4e3);return()=>clearTimeout(h)},[C]);const y=m==null?void 0:m.draft,B=r.useMemo(()=>m!=null&&m.isNew?a.some(h=>h.name===(y==null?void 0:y.name.trim())):!1,[m,y,a]),U=!!y&&(!_l.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),K=!!y&&y.type==="webhook",z=U||B||I||D||K,q=h=>T(F=>F&&{...F,draft:{...F.draft,...h}}),Y=h=>T(F=>{if(!F)return F;const X=new Set(F.draft.allowedTools);return X.has(h)?X.delete(h):X.add(h),{...F,draft:{...F.draft,allowedTools:X}}}),ee=async()=>{if(!m||z)return;const h=m.draft.name.trim();M(h);try{await A.putTrigger(s,h,Bl(m.draft)),T(null),f(`Saved “${h}”.`),await N()}catch(F){j(F instanceof Ne?F.message:"Failed to save trigger")}finally{M(null)}},ae=async h=>{M(h.name);try{const F=await A.putTrigger(s,h.name,{trigger:h.trigger,run:h.run,enabled:!h.enabled});n(X=>X.map(g=>g.name===h.name?F:g))}catch(F){j(F instanceof Ne?F.message:"Failed to update trigger")}finally{M(null)}},te=async()=>{const h=k;if(h){M(h.name);try{await A.deleteTrigger(s,h.name),n(F=>F.filter(X=>X.name!==h.name)),f(`Deleted “${h.name}”.`),L(null)}catch(F){throw new Error(F instanceof Ne?F.message:"Failed to delete trigger")}finally{M(null)}}},ue=async h=>{M(h.name);try{await A.runTrigger(s,h.name),f(`Ran “${h.name}” — a new chat is starting.`),await O()}catch(F){j(F instanceof Ne?F.message:"Failed to run trigger")}finally{M(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(Dt,{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}),C&&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:C}),w?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(h=>{var X;const F=R[h.name];return e.jsxs("tr",{"data-trigger":h.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:h.name}),h.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:h.run.promptFile}):h.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-[11px] text-paddock-400",children:h.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Gl,{type:h.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:zl(h.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=h.run.tools)==null?void 0:X.join(", "))||"No tools declared — an empty list is not enforced as a deny-all",children:Vl(h)}),h.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-[11px] text-paddock-400",children:h.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":h.name,children:e.jsx(ql,{rt:F})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":h.name,children:e.jsx(Yl,{rt:F,trigger:h})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Wl,{enabled:h.enabled===!0,running:(F==null?void 0:F.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:()=>ue(h),disabled:$===h.name||wa(h),title:wa(h)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${h.name} now`,"data-testid":`run-trigger-${h.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-accent transition hover:bg-accent/10 disabled:opacity-40",children:e.jsx(mn,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ae(h),disabled:$===h.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:h.enabled?"Disable":"Enable",children:h.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>T({isNew:!1,draft:Ul(h)}),disabled:$===h.name,title:"Edit","aria-label":`Edit ${h.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:()=>L(h),disabled:$===h.name,title:"Delete","aria-label":`Delete ${h.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(Us,{width:14,height:14})})]})})]},h.name)})})]})}),!m&&e.jsxs("button",{type:"button",onClick:()=>T({isNew:!0,draft:Ol(p[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(ct,{width:13,height:13}),"Add trigger"]}),m&&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:m.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(Le,{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:h=>q({name:h.target.value}),placeholder:"daily-manager",disabled:!m.isNew,"aria-invalid":U||B,"data-testid":"trigger-name"}),m.isNew&&B?e.jsx("p",{className:"mt-1 text-[12px] text-rose-500",children:"A trigger with that name exists."}):m.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)."]}):!m.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:h=>q({type:h.target.value}),"data-testid":"trigger-type",children:p.map(h=>e.jsx("option",{value:h,children:Pl[h]??h},h))})]}),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:h=>q({scheduleKind:h.target.value,expr:""}),"data-testid":"trigger-schedule-kind",children:[e.jsx("option",{value:"interval",children:"Interval (every N)"}),e.jsx("option",{value:"cron",children:"Cron"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:y.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:y.expr,onChange:h=>q({expr:h.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:h=>q({event:h.target.value}),"data-testid":"trigger-event",children:i.map(h=>e.jsx("option",{value:h,children:Dl[h]??h},h))})]}),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:h=>q({path:h.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),K&&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(xe,{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:()=>q({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:()=>q({promptMode:"file"})}),"Prompt file"]})]}),y.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:y.prompt,onChange:h=>q({prompt:h.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:h=>q({promptFile:h.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.",y.type==="schedule"?" Leave all unchecked and the schedule runs as Claude with its full toolset.":" Leaving all unchecked declares no tools, but is not a deny-all: an empty list is not passed to the runtime, so the agent falls back to Claude's default tools."]}),e.jsx("div",{className:"space-y-3","data-testid":"trigger-tools",children:Fl.filter(h=>o.some(F=>F.group===h)).map(h=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-[11px] font-semibold uppercase tracking-wide text-paddock-400",children:Al[h]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:o.filter(F=>F.group===h).map(F=>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:F.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-accent",checked:y.allowedTools.has(F.name),onChange:()=>Y(F.name),"data-tool":F.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:F.name}),e.jsx("span",{className:"block text-[11px] leading-snug text-paddock-400",children:F.description})]})]},F.name))})]},h))}),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(xe,{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:h=>q({resumeSession:h.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:h=>q({permissionMode:h.target.value}),"data-testid":"trigger-permission-mode",children:Ll.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,step:1,className:"input",value:y.maxTurns,onChange:h=>q({maxTurns:h.target.value}),placeholder:"30","data-testid":"trigger-max-turns"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsx("input",{className:"input",value:y.model,onChange:h=>q({model:h.target.value}),placeholder:"Workspace default","data-testid":"trigger-model"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsx("input",{type:"number",min:0,step:1,className:"input",value:y.maxSpawnDepth,onChange:h=>q({maxSpawnDepth:h.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:h=>q({enabled:h.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:ee,disabled:z||$===y.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:$===y.name.trim()?"Saving…":m.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:te,onClose:()=>L(null)})]})}function Gl({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"?at:Dt;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 Wl({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 Kl(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 ql({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,n=[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:n,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Kl(s.status)}`}),s.status==="running"?"Running…":vt(a)]})}function Yl({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 n=t==null?void 0:t.nextRunAt;return n?e.jsx("span",{className:"text-[12px] text-paddock-600 dark:text-paddock-300",title:new Date(n).toLocaleString(),children:Kn(n)}):e.jsx("span",{className:"text-[12px] text-paddock-400",children:"—"})}function Ql({open:t,chatName:s,onClose:a,onFork:n}){const o=`Fork of ${s}`,[l,i]=r.useState(o),c=r.useRef(null);if(r.useEffect(()=>{if(t){i(o);const x=c.current;x&&(x.focus(),x.select())}},[t,s]),es(t,a),!t)return null;const p=x=>{x.preventDefault(),n(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:x=>x.stopPropagation(),onSubmit:p,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(Le,{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:x=>i(x.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 Jl({open:t,chatName:s,resetName:a,onClose:n,onRename:o}){const[l,i]=r.useState(s),c=r.useRef(null);if(r.useEffect(()=>{if(!t)return;i(s);const u=c.current;u&&(u.focus(),u.select())},[t,s]),es(t,n),!t)return null;const p=l.trim(),x=p==="",w=u=>{u.preventDefault(),o(x?null:p)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:n,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:w,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:n,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(Le,{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:x?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:n,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:x?"Reset name":"Rename"})]})]})})}function Xl({open:t,slug:s,sessionId:a,defaultName:n,onClose:o,onPromoted:l}){const[i,c]=r.useState(n??""),[p,x]=r.useState(""),[w,u]=r.useState(""),[b,j]=r.useState(""),[C,f]=r.useState(!1),[m,T]=r.useState(null);if(r.useEffect(()=>{t&&(c(n??""),x(""),u(""),j(""),T(null))},[t,n]),es(t&&!C,o),!t)return null;const $=async M=>{if(M.preventDefault(),!!i.trim()){f(!0),T(null);try{const{project:k,promoted:L}=await A.promoteChat(s,a,{name:i.trim(),group:b||void 0,summary:p.trim()||void 0,domain:w.split(",").map(R=>R.trim()).filter(Boolean)});l(k,L)}catch(k){T(k instanceof Ne?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:()=>!C&&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:M=>M.stopPropagation(),onSubmit:$,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(Le,{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:M=>c(M.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:p,onChange:M=>x(M.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:M=>j(M.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Es.map(M=>e.jsx("option",{value:M.slug,children:M.label},M.slug))]})]}),e.jsxs("label",{className:"mb-5 block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:w,onChange:M=>u(M.target.value),placeholder:"home, plumbing"})]}),m&&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:m}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:o,disabled:C,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:C||!i.trim(),children:C?"Promoting…":"Promote to project"})]})]})})}function Zl({open:t,adoptable:s,busy:a,onClose:n,onAdopt:o}){const[l,i]=r.useState(new Set),c=r.useMemo(()=>((s==null?void 0:s.sources)??[]).map(j=>({sourceCwd:j.sourceCwd,sessions:j.sessions??j.sessionIds.map(C=>({sessionId:C}))})),[s]),p=r.useMemo(()=>c.flatMap(j=>j.sessions.map(C=>C.sessionId)),[c]),x=p.join(",");if(r.useEffect(()=>{t&&i(new Set(p))},[t,x]),es(t&&!a,n),!t)return null;const w=j=>{i(C=>{const f=new Set(C);return f.delete(j)||f.add(j),f})},u=(j,C)=>{i(f=>{const m=new Set(f);for(const T of j)C?m.add(T):m.delete(T);return m})},b=l.size;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&&n(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Adopt native Claude Code chats",className:"flex max-h-[80vh] w-full max-w-2xl animate-scale-in flex-col rounded-2xl border border-paddock-200 bg-white p-6 shadow-2xl dark:border-paddock-800 dark:bg-paddock-900",onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-lg font-semibold",children:[e.jsx(Zt,{width:16,height:16}),"Adopt native chats"]}),e.jsx("button",{type:"button",onClick:n,disabled: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(Le,{width:18,height:18})})]}),e.jsxs("p",{className:"mb-4 text-sm text-paddock-500",children:["These Claude Code sessions were run in a terminal and aren't visible here yet. Adopting them lists them here — your own ",e.jsx("code",{children:"~/.claude"})," history is never moved or deleted."]}),e.jsxs("div",{className:"-mx-1 flex-1 overflow-y-auto px-1",children:[c.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-paddock-500",children:"Nothing left to adopt."}),c.map(j=>{const C=j.sessions.map(m=>m.sessionId),f=C.every(m=>l.has(m));return e.jsxs("section",{className:"mb-4 last:mb-0",children:[e.jsxs("header",{className:"mb-1 flex items-baseline justify-between gap-2",children:[e.jsx("code",{className:"min-w-0 break-all text-xs text-paddock-500",children:j.sourceCwd}),e.jsx("button",{type:"button",onClick:()=>u(C,!f),className:"shrink-0 text-xs text-paddock-500 underline underline-offset-2 hover:text-paddock-700 dark:hover:text-paddock-300",children:f?"Deselect all":"Select all"})]}),e.jsx("ul",{className:"space-y-1",children:j.sessions.map(m=>e.jsx("li",{children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-lg border border-paddock-200 px-3 py-2 transition hover:bg-paddock-50 dark:border-paddock-800 dark:hover:bg-paddock-800/50",children:[e.jsx("input",{type:"checkbox",className:"mt-1 shrink-0",checked:l.has(m.sessionId),onChange:()=>w(m.sessionId)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",children:ei(m)}),m.mtime!==void 0&&e.jsxs("span",{className:"mt-0.5 block text-xs text-paddock-500",children:[ti(m.mtime)," · ",si(m.sizeBytes)]})]})]})},m.sessionId))})]},j.sourceCwd)})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 border-t border-paddock-200 pt-4 dark:border-paddock-800",children:[e.jsxs("span",{className:"text-sm text-paddock-500",children:[b," of ",p.length," selected"]}),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:n,disabled:a,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn-primary",disabled:a||b===0,onClick:()=>o([...l]),children:a?"Adopting…":`Adopt ${b} chat${b===1?"":"s"}`})]})]})]})})}function ei(t){var n,o;const s=(n=t.autoName)==null?void 0:n.trim();if(s!==void 0&&s!=="")return s;const a=(o=t.preview)==null?void 0:o.trim();return a!==void 0&&a!==""?a:t.sessionId}function ti(t){const s=new Date(t);return Number.isNaN(s.getTime())?"unknown date":s.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function si(t){return t<1024?`${t} B`:t<1024*1024?`${Math.round(t/1024)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}const tn="paddock:fork:";function ai(t){if(!t)return null;try{const s=localStorage.getItem(tn+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 Na(t,s){try{localStorage.setItem(tn+t,JSON.stringify(s))}catch{}}function _s(t){const s=Date.parse(t.chat.updatedAt??"")||0;return t.children.reduce((a,n)=>Math.max(a,_s(n)),s)}function Gs(t){for(const s of t)Gs(s.children);t.sort((s,a)=>!!s.chat.starred!=!!a.chat.starred?s.chat.starred?-1:1:_s(a)-_s(s))}function sn(t,s){let a=0;for(const n of t)n.depth=s,n.descendantCount=sn(n.children,s+1),a+=1+n.descendantCount;return a}function ni(t){var n;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=(n=o.chat.parent)==null?void 0:n.sessionId,i=l?s.get(l):void 0;if(!i||i===o||oi(o,i,s)){a.push(o);continue}i.children.push(o)}return Gs(a),sn(a,0),a}function ri(t){const s=t.map(a=>({chat:a,children:[],depth:0,descendantCount:0}));return Gs(s),s}function oi(t,s,a){var l;const n=new Set([t.chat.sessionId]);let o=s;for(;o;){if(n.has(o.chat.sessionId))return!0;n.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 Ds(t){return t.reduce((s,a)=>s+1+Ds(a.children),0)}function li(t){const s=[t.chat.sessionId],a=n=>{for(const o of n)s.push(o.chat.sessionId),a(o.children)};return a(t.children),s}function ii(t,s){var i;const a=new Map;for(const c of t){const p=(i=c.parent)==null?void 0:i.sessionId;if(!p)continue;const x=a.get(p);x?x.push(c.sessionId):a.set(p,[c.sessionId])}const n=[],o=new Set([s]),l=[s];for(;l.length;)for(const c of a.get(l.pop())??[])o.has(c)||(o.add(c),n.push(c),l.push(c));return n}function ya(t,s){const a=[],n=o=>{for(const l of o)a.push(l),s.has(l.chat.sessionId)||n(l.children)};return n(t),a}function ci(t,s){var o;const a=new Map(t.map(l=>[l.sessionId,l])),n=new Set;for(const l of s){let i=l;const c=new Set;for(;i&&!c.has(i.sessionId);){c.add(i.sessionId),n.add(i.sessionId);const p=(o=i.parent)==null?void 0:o.sessionId;i=p?a.get(p):void 0}}return t.filter(l=>n.has(l.sessionId))}const Ps="paddock:chatsCollapsed:";function di(t){try{const s=localStorage.getItem(Ps+t);if(!s)return new Set;const a=JSON.parse(s);return Array.isArray(a)?new Set(a.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function ui(t,s){try{s.size===0?localStorage.removeItem(Ps+t):localStorage.setItem(Ps+t,JSON.stringify([...s]))}catch{}}const an="paddock:chatView:nested",nn="paddock:chatView:runningOnly";function rn(t,s){try{const a=localStorage.getItem(t);return a==="1"?!0:a==="0"?!1:s}catch{return s}}function on(t,s,a){try{s===a?localStorage.removeItem(t):localStorage.setItem(t,s?"1":"0")}catch{}}function pi(){return rn(an,!0)}function mi(t){on(an,t,!0)}function hi(){return rn(nn,!1)}function xi(t){on(nn,t,!1)}function fi(){const[t,s]=r.useState(pi),[a,n]=r.useState(hi),o=r.useCallback(i=>{s(i),mi(i)},[]),l=r.useCallback(i=>{n(i),xi(i)},[]);return r.useMemo(()=>({nested:t,setNested:o,runningOnly:a,setRunningOnly:l}),[t,o,a,l])}function it({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 ki({file:t,active:s,onSelect:a,onUnpin:n}){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(Mt,{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(),n()},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(Le,{width:12,height:12})})]})}function gi({project:t,running:s,unread:a,attentionLoading:n,attentionError:o,changelog:l,overview:i,files:c,onOpenChat:p,onNewChat:x,onOpenFile:w,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(ys,{label:"Running",count:s.length}),e.jsxs("button",{onClick:x,className:"btn-subtle -mr-1 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(ct,{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(Ca,{chats:s,workspaceSlug:t.slug,loading:n,empty:"Nothing running right now.",onOpenChat:p,kind:"running"})]}),!o&&e.jsxs("section",{className:"mb-8",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between",children:e.jsx(ys,{label:"Unread",count:a.length})}),e.jsx(Ca,{chats:a,workspaceSlug:t.slug,loading:n,empty:"No unread replies. All caught up.",onOpenChat:p,kind:"unread"})]}),w&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(ys,{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((j,C)=>e.jsxs("button",{onClick:()=>w(j),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:[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:j}),t.pinned.includes(j)&&e.jsx(Mt,{width:12,height:12,className:"shrink-0 text-accent"})]},j))})]}),e.jsx(Sa,{id:`${t.slug}:overview`,title:"OVERVIEW.md",body:i,emptyLabel:"No OVERVIEW.md yet."},`${t.slug}:overview`),e.jsx(Sa,{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 ys({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 Ca({chats:t,workspaceSlug:s,loading:a,empty:n,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:n})}):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 Sa({id:t,title:s,body:a,emptyLabel:n}){const[o,l]=bi(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(Pt,{children:a}):e.jsx("p",{className:"text-sm italic text-paddock-400",children:n})})]})}function bi(t){const s=`paddock:home-collapsed:${t}`,[a,n]=r.useState(()=>{try{return localStorage.getItem(s)==="1"}catch{return!1}});return[a,()=>n(l=>{const i=!l;try{localStorage.setItem(s,i?"1":"0")}catch{}return i})]}const Ls=8,As=2*Math.PI*Ls,ji=.25*As;function Ia({tokens:t,limit:s,usage:a,size:n=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,p=l?i/100*As:ji,x=l?Math.round(t/1e3):0,w=l?Math.round(s/1e3):0,u=a?`
|
|
12
|
+
Session so far: ${Pa(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}`,j=o?l?`Streaming a response… (context ${Math.round(i)}% full)`:"Streaming a response…":`Context ${Math.round(i)}% full (${x}k of ${w}k tokens)`;return e.jsx("span",{className:"inline-flex shrink-0 items-center",title:b,"aria-label":j,children:e.jsxs("svg",{width:n,height:n,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:Ls,fill:"none",strokeWidth:"3",className:"stroke-paddock-200 dark:stroke-paddock-700"}),e.jsx("circle",{cx:"10",cy:"10",r:Ls,fill:"none",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:`${p} ${As}`,className:c?"stroke-amber-500":"stroke-accent"})]})})}function vi({provenance:t,hookName:s,className:a=""}){const n=t==null?void 0:t.origin;if(n!=="scheduled"&&n!=="spawned"&&n!=="hook"&&n!=="adopted")return null;if(n==="adopted")return e.jsx("span",{"data-provenance":"adopted","aria-label":"Adopted chat",title:"Adopted — this chat came from your Claude Code CLI history",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-emerald-600 dark:text-emerald-400 ${a}`,children:e.jsx(Zt,{width:12,height:12})});if(n==="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(Dt,{width:12,height:12})})}if(n==="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(at,{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(Ye,{width:12,height:12})})}function we({content:t,children:s,delayMs:a=250,className:n=""}){const o=r.useId(),l=r.useRef(null),i=r.useRef(null),c=r.useRef(null),[p,x]=r.useState(null),w=()=>{c.current&&clearTimeout(c.current),c.current=null},u=r.useCallback(()=>{w(),x(null)},[]),b=r.useCallback(()=>{var T;const f=(T=l.current)==null?void 0:T.getBoundingClientRect();if(!f)return;const m=f.top<56;x({x:f.left+f.width/2,y:m?f.bottom+6:f.top-6,below:m})},[]);r.useEffect(()=>w,[]),r.useEffect(()=>{if(!p)return;const f=m=>{m.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)}},[p,u]),r.useLayoutEffect(()=>{if(!p||!i.current)return;const f=i.current.offsetWidth;if(!f)return;const m=8+f/2,T=window.innerWidth-8-f/2,$=Math.min(Math.max(p.x,m),Math.max(m,T));$!==p.x&&x({...p,x:$})},[p]);const j=r.Children.only(s),C=r.isValidElement(j)?r.cloneElement(j,{"aria-describedby":p?o:void 0}):j;return e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:l,className:`inline-flex ${n}`,onPointerEnter:f=>{f.pointerType!=="touch"&&(w(),c.current=setTimeout(b,a))},onPointerLeave:u,onPointerDown:u,onFocusCapture:b,onBlurCapture:u,children:C}),p&&Ra.createPortal(e.jsx("div",{ref:i,id:o,role:"tooltip",style:{position:"fixed",left:p.x,top:p.y,transform:`translate(-50%, ${p.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 wi({activeTotal:t,shownCount:s,searching:a,runningCount:n,runningOnly:o,setRunningOnly:l}){const i=a?`${s}/${t}`:`${t}`,c=a?`${s} of ${t} chats shown`:`${t} chats`;return n===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(we,{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(we,{content:o?"Showing only running chats — click to show all":`Show only the ${n} chat${n===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 (${n} 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 ${n>0?"spin-eco border-t-transparent":"opacity-60"}`}),n]})})]})}function Ni({nested:t,setNested:s,runningOnly:a}){const n=t?"Switch to a flat chat list":"Switch to a nested chat list";return e.jsx(we,{content:a?"Running-only view is always flat":n,children:e.jsx("button",{type:"button",onClick:()=>s(!t),disabled:a,"aria-label":n,"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(hn,{width:16,height:16,className:"mx-auto"}):e.jsx(xn,{width:16,height:16,className:"mx-auto"})})})}function Cs(t){return`${t} nested chat${t===1?"":"s"}`}const yi=4,Ci=new Set;function Si({chatList:t,sessionsOpen:s,setSessionsOpen:a,chatSearch:n,setChatSearch:o,searching:l,newChat:i,view:c,activeSession:p,pendingChat:x,chats:w,fallbackChat:u,visibleChats:b,activeChats:j,archivedChats:C,activeTotal:f,runningCount:m,viewPrefs:T,archivedOpen:$,setArchivedOpen:M,collapsedChats:k,toggleChatCollapsed:L,openChat:R,unread:P,usageBySession:N,runningSessions:O,setForkingChat:y,setPromotingChat:B,renameChat:U,archiveChat:I,requestDeleteChat:D,starChat:K,toggleUnread:z,detachChat:q,adoptableCount:Y,adopting:ee,adoptChats:ae}){const te=l?Ci:k,ue=j.some(g=>g.children.length>0)||C.some(g=>g.children.length>0),h=Ds(j),F=Ds(C),X=(g,Z)=>{var Ae,ye,Ee,Fe;const pe=(Z==null?void 0:Z.depth)??0,He=(Z==null?void 0:Z.children.length)??0,ge=(Z==null?void 0:Z.descendantCount)??0,he=P.has(g.sessionId),ce=te.has(g.sessionId),je=!!Z&&ge>0,Ie=W=>je&&W.shiftKey?li(Z):[g.sessionId],ie=ge+1,Ce=(W,fe)=>je?e.jsxs(e.Fragment,{children:[W," · ",e.jsx("span",{className:"font-semibold",children:"Shift-click"})," to ",fe]}):W,Te=(W,fe)=>je?`${W} (Shift-click to ${fe})`:W,Se=6+(pe>0?1:0)+(B?1:0);return e.jsxs("div",{className:`group/chat chat-row chat-row--actions-${Se} relative mb-0.5 flex rounded-lg transition-colors ${p===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(pe,yi)},(W,fe)=>e.jsx("div",{"aria-hidden":"true",className:"w-3 shrink-0 border-l border-paddock-300/60 dark:border-paddock-700/60"},fe)),ue&&e.jsx("div",{className:"flex w-4 shrink-0 items-start justify-center pt-2.5",children:He>0&&e.jsx(we,{content:ce?`Show ${Cs(ge)}`:"Hide nested chats",children:e.jsx("button",{type:"button","aria-label":`${ce?"Expand":"Collapse"} ${ge} chat${ge===1?"":"s"} under ${g.name}`,"aria-expanded":!ce,onClick:W=>{W.stopPropagation(),L(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(ta,{width:11,height:11,className:`transition-transform ${ce?"-rotate-90":""}`})})})}),e.jsxs("button",{type:"button",onClick:()=>R(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 ${ue?"pl-1":"pl-2.5"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-1.5",children:[he&&e.jsx(we,{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 ${he?"font-semibold":"font-medium"}`,children:g.name}),ce&&ge>0&&e.jsx(we,{content:`${Cs(ge)} 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:ge})}),!(pe>0&&((Ae=g.provenance)==null?void 0:Ae.origin)==="spawned")&&e.jsx(vi,{provenance:g.provenance,hookName:(ye=g.trigger)==null?void 0:ye.name}),e.jsx(Ia,{tokens:((Ee=N[g.sessionId])==null?void 0:Ee.contextTokens)??g.contextTokens,limit:((Fe=N[g.sessionId])==null?void 0:Fe.contextLimit)??g.contextLimit,usage:qn(N[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:[pe>0&&e.jsx(we,{content:ge>0?`Detach from parent — move this chat and its ${Cs(ge)} to the top level`:"Detach from parent — move this chat to the top level",children:e.jsx("button",{type:"button","aria-label":`Detach chat ${g.name} from its parent`,onClick:W=>{W.stopPropagation(),q(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(kn,{width:13,height:13})})}),e.jsx(we,{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:W=>{W.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(Ye,{width:13,height:13})})}),B&&e.jsx(we,{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:W=>{W.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(ct,{width:13,height:13})})}),e.jsx(we,{content:"Rename chat",children:e.jsx("button",{type:"button","aria-label":`Rename chat ${g.name}`,onClick:W=>{W.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(we,{content:Ce(g.archived?"Unarchive chat":"Archive chat — file it away without deleting",g.archived?`unarchive all ${ie}`:`archive all ${ie}`),children:e.jsx("button",{type:"button","aria-label":Te(`${g.archived?"Unarchive":"Archive"} chat ${g.name}`,g.archived?`unarchive all ${ie}`:`archive all ${ie}`),onClick:W=>{W.stopPropagation(),I(g,Ie(W))},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(gn,{width:13,height:13})})}),e.jsx(we,{content:Ce("Delete chat",`delete all ${ie}`),children:e.jsx("button",{type:"button","aria-label":Te(`Delete chat ${g.name}`,`delete all ${ie}`),onClick:W=>{W.stopPropagation(),D(g,Ie(W))},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(Us,{width:13,height:13})})}),e.jsx(we,{content:Ce(he?"Mark as read":"Mark as unread — resurface it later",he?`mark all ${ie} read`:`mark all ${ie} unread`),children:e.jsx("button",{type:"button","aria-label":Te(`Mark chat ${g.name} ${he?"read":"unread"}`,he?`mark all ${ie} read`:`mark all ${ie} unread`),"aria-pressed":he,onClick:W=>{W.stopPropagation(),z(g,Ie(W))},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(bn,{width:13,height:13,open:!he})})}),e.jsx(we,{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:W=>{W.stopPropagation(),K(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(jn,{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(fn,{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($a,{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:n,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(we,{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(Le,{width:13,height:13})})})]}),e.jsx(Ni,{nested:T.nested,setNested:T.setNested,runningOnly:T.runningOnly}),e.jsx(we,{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(ct,{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(Le,{width:16,height:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[Y>0&&e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("button",{type:"button",onClick:ae,disabled:ee,"aria-label":`Adopt ${Y} native Claude Code chat${Y===1?"":"s"} into this workspace`,"aria-haspopup":"dialog",className:"btn-ghost w-full justify-start py-1.5 text-xs",children:[e.jsx(Zt,{width:13,height:13,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ee?"Adopting…":`Adopt ${Y} native chat${Y===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(wi,{activeTotal:f,shownCount:h,searching:l,runningCount:m,runningOnly:T.runningOnly,setRunningOnly:T.setRunningOnly})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:[p===null&&c==="chat"&&!x&&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…"})]}),x&&!w.some(g=>g.sessionId===x)&&e.jsx("div",{className:`group/chat relative mb-0.5 rounded-lg transition-colors ${p===x&&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:()=>R(x),className:"flex w-full items-center gap-1.5 rounded-lg px-2.5 py-2 text-left text-sm",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-medium italic text-paddock-600 dark:text-paddock-300",children:"New chat…"}),e.jsx(Ia,{working:!0})]})}),u&&X(u),w.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."}),w.length>0&&T.runningOnly&&m===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"})]}),w.length>0&&(!T.runningOnly||m>0)&&l&&b.length===0&&!u&&e.jsxs("p",{className:"px-2 py-2 text-sm text-paddock-500",children:["No chats match “",n.trim(),"”."]}),w.length>0&&!T.runningOnly&&!l&&j.length===0&&!u&&e.jsx("p",{className:"px-2 py-2 text-sm text-paddock-500",children:"No active chats — see Archived below."}),ya(j,te).map(g=>X(g.chat,g))]}),C.length>0&&e.jsxs("div",{className:`flex flex-col border-t border-paddock-200 dark:border-paddock-800 ${$?"min-h-0 flex-1":"shrink-0"}`,children:[e.jsxs("button",{type:"button",onClick:()=>M(g=>!g),"aria-expanded":$,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(ta,{width:14,height:14,className:`shrink-0 transition-transform ${$?"":"-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:F})]}),$&&e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:ya(C,te).map(g=>X(g.chat,g))})]})]})]})]})}function Ii({slug:t,chats:s,view:a,activeSession:n,runningSessions:o,onSeen:l,onManySeen:i}){const[c,p]=r.useState(new Set),[x,w]=r.useState(0),u=r.useCallback((f,m)=>{const T=Date.now(),$=(m==null?void 0:m.keepUnread)===!0,M=sa(f,T),k=$?{keepUnread:!0}:void 0;A.markChatSeen(t,f,T,k).catch(()=>{aa(f,M,T),w(L=>L+1)}),$||l==null||l(f),p(L=>{if(!L.has(f))return L;const R=new Set(L);return R.delete(f),R}),w(L=>L+1)},[t,l]),b=r.useCallback(f=>{if(f.length<=1){f[0]&&u(f[0]);return}const m=Date.now(),T=f.map(k=>[k,sa(k,m)]),$=f.filter(k=>c.has(k)),M=i==null?void 0:i(f);p(k=>{if(!$.length)return k;const L=new Set(k);for(const R of $)L.delete(R);return L}),w(k=>k+1),A.markChatsUnread(t,f,!1).catch(()=>{for(const[k,L]of T)aa(k,L,m);$.length&&p(k=>{const L=new Set(k);for(const R of $)L.add(R);return L}),M==null||M(),w(k=>k+1)})},[t,i,u,c]);r.useEffect(()=>{for(const f of s)vn(f.sessionId,f.lastSeen);w(f=>f+1)},[s]);const j=r.useMemo(()=>{const f=new Set;for(const m of s){if(a==="chat"&&m.sessionId===n)continue;if(m.unread||c.has(m.sessionId)){f.add(m.sessionId);continue}const T=m.lastTurnCompletedAt?Date.parse(m.lastTurnCompletedAt):NaN;Number.isFinite(T)&&T>wn(m.sessionId)&&f.add(m.sessionId)}return f},[s,a,n,c,x]);r.useEffect(()=>{a==="chat"&&n&&u(n)},[a,n,u]);const C=r.useRef(new Set);return r.useEffect(()=>{const f=C.current;for(const m of f)o.has(m)||(a==="chat"&&m===n?u(m,{keepUnread:!0}):p(T=>T.has(m)?T:new Set(T).add(m)));C.current=o},[o,a,n,u]),{markSeen:u,markManySeen:b,unread:j}}const Ei=250,Ti=2500,Ri=3e4;function $i(t,s){const[a,n]=r.useState([]),[o,l]=r.useState([]),[i,c]=r.useState(!0),[p,x]=r.useState(null),w=r.useRef(0),u=r.useCallback(async()=>{const C=++w.current;try{const f=await A.attentionChats(t);if(C!==w.current)return;n(f.running),l(f.unread),x(null)}catch(f){if(C!==w.current)return;x(f instanceof Error?f.message:"Failed to load chats")}finally{C===w.current&&c(!1)}},[t]),b=r.useRef(u);b.current=u;const j=r.useRef(!1);return r.useEffect(()=>{j.current=!1,n([]),l([]),c(!0),u()},[t,u]),r.useEffect(()=>{if(!j.current){j.current=!0;return}const C=setTimeout(()=>void b.current(),Ei),f=setTimeout(()=>void b.current(),Ti);return()=>{clearTimeout(C),clearTimeout(f)}},[s]),r.useEffect(()=>{const C=()=>{document.visibilityState==="visible"&&b.current()},f=setInterval(C,Ri);return document.addEventListener("visibilitychange",C),()=>{clearInterval(f),document.removeEventListener("visibilitychange",C)}},[]),{running:a,unread:o,loading:i,error:p,refresh:()=>void u()}}function Mi({message:t,tone:s="success",onDismiss:a,durationMs:n=6e3,action:o}){if(r.useEffect(()=>{if(t===null||n<=0)return;const i=setTimeout(a,n);return()=>clearTimeout(i)},[t,n,a]),t===null)return null;const l=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 ${l?"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:[l?e.jsx(xe,{width:16,height:16,className:"mt-0.5 shrink-0"}):e.jsx(dt,{width:16,height:16,className:"mt-0.5 shrink-0 text-emerald-500"}),e.jsx("span",{className:"break-words",children:t}),o&&e.jsx("button",{type:"button",onClick:o.onAct,className:"ml-1 shrink-0 font-medium underline underline-offset-2 transition hover:opacity-80",children:o.label}),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(Le,{width:12,height:12})})]})})}function ln({adopted:t,skipped:s}){const a=t.length;if(a===0&&s.length===0)return"Nothing to adopt — no native chats were found.";const n=a===0?"Adopted nothing":`Adopted ${a} chat${a===1?"":"s"}`;if(s.length===0)return n;const o=[...new Set(s.map(i=>i.reason).filter(Boolean))],l=o.length===1?` (${o[0]})`:"";return`${n} — skipped ${s.length}${l}`}function _i({root:t=!1}={}){var Ys,Qs,Js,Xs,Zs;const s=Nn(),a=t?yn:s.slug??"",n=na(a),o=Cn(),l=Sn(),i=In(),c=(i==null?void 0:i.openNav)??(()=>{}),{refresh:p,upsert:x,remove:w}=En(),u=Tn(o.pathname,n),b=u==="chat"?s.sessionId:void 0,j=u==="files"?Rn(o.pathname,n):"",C=u==="changes"&&s.file?decodeURIComponent(s.file):void 0,f=r.useRef({counter:0,session:b??null}),m=r.useRef(!1);f.current.session!==(b??null)&&((Ys=o.state)!=null&&Ys.established||(f.current.counter+=1),f.current.session=b??null);const[T,$]=r.useState(0),M=`${f.current.counter}:${T}`,[k,L]=r.useState(null),[R,P]=r.useState([]),[N,O]=r.useState({}),[y,B]=r.useState(""),[U,I]=r.useState(null),[D,K]=r.useState(new Set);r.useEffect(()=>Pe.onActiveSessions(K),[]);const[z,q]=r.useState(""),[Y,ee]=r.useState(""),[ae,te]=r.useState([]),[ue,h]=r.useState(null),[F,X]=r.useState(0),[g,Z]=r.useState(!1),[pe,He]=r.useState(null),[ge,he]=r.useState(!1),[ce,je]=r.useState(null),Ie=r.useCallback(()=>je(null),[]),[ie,Ce]=r.useState(null),Te=wl(a),Se=Te.newUnattended,[Ae,ye]=r.useState(!1),[Ee,Fe]=r.useState(!1),[W,fe]=r.useState(null),[se,$e]=r.useState(null),[Qe,Oe]=r.useState(null),[Ge,Je]=r.useState(null),[be,S]=r.useState(!1),[Q,ne]=r.useState(()=>di(a)),de=r.useCallback(d=>{ne(E=>{const V=new Set(E);return V.has(d)?V.delete(d):V.add(d),ui(a,V),V})},[a]),re=fi(),We=$n(An),wt=r.useRef(null),J=b??null,as=r.useCallback(d=>P(E=>E.map(V=>V.sessionId===d&&V.unread?{...V,unread:!1}:V)),[]),Xe=r.useCallback(d=>{const E=new Set(d),V=R.filter(G=>E.has(G.sessionId)&&G.unread).map(G=>G.sessionId);if(!V.length)return()=>{};P(G=>G.map(oe=>E.has(oe.sessionId)&&oe.unread?{...oe,unread:!1}:oe));const H=new Set(V);return()=>P(G=>G.map(oe=>H.has(oe.sessionId)?{...oe,unread:!0}:oe))},[R]),{unread:Nt,markManySeen:Lt}=Ii({slug:a,chats:R,view:u,activeSession:J,runningSessions:D,onSeen:as,onManySeen:Xe}),ut=$i(a,D),Ze=r.useMemo(()=>{const d=re.runningOnly?R.filter(H=>D.has(H.sessionId)||H.sessionId===J):R,E=y.trim().toLowerCase();if(!E)return d;const V=d.filter(H=>{var G;return H.name.toLowerCase().includes(E)||(((G=H.preview)==null?void 0:G.toLowerCase().includes(E))??!1)});return re.runningOnly?V:ci(R,V)},[R,y,re.runningOnly,D,J]),ns=y.trim().length>0,pt=r.useCallback(async()=>{const d=await A.gitStatus(a).catch(()=>null);Ce(d&&d.repo?d:null)},[a]),nt=r.useCallback(async()=>{const d=await A.chatUsage(a).catch(()=>null);d&&O(E=>({...E,...d}))},[a]),et=r.useCallback(async()=>{const d=await A.chatUsage(a,"archived").catch(()=>null);d&&O(E=>({...E,...d}))},[a]),tt=r.useRef(!1),At=r.useCallback(async()=>{h(null);try{const d=await A.getProjectDetail(a);L(d.project),P(d.chats),q(d.changelog),ee(d.overview??"");const E=await A.listProjectFiles(a).catch(()=>[]);te(E)}catch(d){h(d instanceof Error?d.message:"Failed to load project")}pt(),nt()},[a,pt,nt]);r.useEffect(()=>{L(null),Ce(null),O({}),tt.current=!1,At()},[a,At]),r.useEffect(()=>{be&&(tt.current=!0,et())},[be,et]),r.useEffect(()=>{if(t)return;const d=u==="home"?lt({view:"home"}):u==="settings"?lt({view:"settings"}):u==="history"?lt({view:"history"}):u==="triggers"?lt({view:"triggers"}):u==="chat"?lt({view:"chat",sessionId:b}):u==="changes"?lt({view:"changes",file:C}):lt({view:"files",path:j||void 0});tr(a,d)},[t,a,u,b,j,C]);const ke=r.useCallback(async()=>{const d=await A.listProjectChats(a).catch(()=>null);d&&P(d)},[a]),Me=r.useCallback(async()=>{const d=await A.getAdoptableChats(a).catch(()=>null);X((d==null?void 0:d.count)??0),He(d)},[a]),rt=r.useCallback(async d=>{je(null);try{const E=await A.unadoptChats(a,{sessionIds:d});await ke(),await Me(),je(E.released.length>0?{message:`Removed ${E.released.length} adopted chat${E.released.length===1?"":"s"}.`,tone:"success"}:{message:"Nothing left to undo.",tone:"error"})}catch(E){je({message:E instanceof Error?E.message:"Failed to undo the adoption",tone:"error"})}},[a,ke,Me]),yt=r.useCallback(async d=>{if(!g){Z(!0);try{const E=await A.adoptChats(a,{sessionIds:d});he(!1),await ke(),await Me();const V=E.adopted.length===0&&E.skipped.length>0;je({message:ln(E),tone:V?"error":"success",action:E.adopted.length>0?{label:"Undo",onAct:()=>void rt(E.adopted)}:void 0})}catch(E){je({message:E instanceof Error?E.message:"Failed to adopt native chats",tone:"error"})}finally{Z(!1)}}},[g,a,ke,Me,rt]);r.useEffect(()=>{X(0),He(null),he(!1),je(null),Me()},[Me]);const Ct=r.useCallback(async()=>{const d=await A.getProjectDetail(a).catch(()=>null);d&&(L(d.project),P(d.chats),q(d.changelog),ee(d.overview??""));const E=await A.listProjectFiles(a).catch(()=>null);E&&te(E),pt(),nt(),tt.current&&et()},[a,pt,nt,et]),St=r.useCallback(d=>A.projectChatMessages(a,d),[a]);r.useEffect(()=>{ye(!1)},[u,b,j,C]);const mt=r.useCallback(()=>l(Mn(n)),[l,n]),Ke=r.useCallback(()=>l(`${n}/chat`),[l,n]),Ft=r.useCallback(()=>l(`${n}/files`),[l,n]),rs=r.useCallback(()=>l(`${n}/changes`),[l,n]),Ot=r.useCallback(()=>l(`${n}/history`),[l,n]),Ut=r.useCallback(()=>l(`${n}/settings`),[l,n]),Bt=r.useCallback(()=>l(`${n}/triggers`),[l,n]),qe=r.useCallback(d=>l(d?`${n}/changes/${encodeURIComponent(d)}`:`${n}/changes`),[l,n]);r.useEffect(()=>{o.pathname.startsWith(`${n}/hooks`)&&l(`${n}/triggers`,{replace:!0})},[o.pathname,l,n]);const _e=r.useCallback(()=>{$(d=>d+1),Ke()},[Ke]),ht=r.useCallback(d=>l(`${n}/chat/${encodeURIComponent(d)}`),[l,n]),It=r.useCallback((d,E)=>l(`${na(E)}/chat/${encodeURIComponent(d)}`),[l]),os=r.useCallback(async(d,E)=>{let V;try{V=await A.forkChat(a,d.sessionId,E)}catch(H){h(H instanceof Error?H.message:"Failed to fork chat");return}Na(V,{sessionId:d.sessionId,name:d.name}),await ke(),l(`${n}/chat/${encodeURIComponent(V)}`,{state:{justForked:!0}})},[l,n,a,ke]),Vt=r.useCallback(async d=>{if(!J||m.current)return;m.current=!0;const E=R.find(G=>G.sessionId===J),V=E?`Fork of ${E.name}`:void 0;let H;try{H=await A.forkChat(a,J,V,d)}catch(G){h(G instanceof Error?G.message:"Failed to fork chat"),m.current=!1;return}E&&Na(H,{sessionId:E.sessionId,name:E.name}),await ke(),l(`${n}/chat/${encodeURIComponent(H)}`,{state:{justForked:!0}}),m.current=!1},[J,R,l,n,a,ke]),zt=r.useCallback(async d=>{if(J){try{await A.revertChat(a,J,d)}catch(E){throw h(E instanceof Error?E.message:"Failed to revert chat"),E}await ke()}},[J,a,ke]),ls=ai(b),is=((Qs=o.state)==null?void 0:Qs.justForked)===!0,xt=r.useCallback(d=>l(d?`${n}/files/${d.split("/").map(encodeURIComponent).join("/")}`:`${n}/files`),[l,n]),Ht=r.useCallback(d=>{I(d),ke(),p(),b||l(`${n}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[ke,p,b,l,n]),Gt=r.useCallback(d=>{ke(),p(),b||l(`${n}/chat/${encodeURIComponent(d)}`,{replace:!0,state:{established:!0}})},[ke,p,b,l,n]);r.useEffect(()=>{U&&R.some(d=>d.sessionId===U)&&I(null)},[R,U]);const Et=r.useRef(new Set);r.useEffect(()=>{let d=!1;for(const E of D)Et.current.has(E)||(Et.current.add(E),R.some(V=>V.sessionId===E)||(d=!0));d&&ke()},[D,R,ke]);const cs=r.useCallback(d=>{d&&O(E=>({...E,[d.sessionId]:d.usage})),Ct(),p()},[Ct,p]),ds=r.useCallback(async d=>{if(!k)return;const E=k.pinned.includes(d)?await A.unpinFile(a,d):await A.pinFile(a,d);L(E),x(E)},[k,a,x]),us=r.useCallback(async d=>{const E=await A.unpinFile(a,d);L(E),x(E),j===d&&l(`${n}/files`,{replace:!0})},[a,n,x,j,l]),Wt=r.useCallback(async()=>{if(!se)return;const{ids:d}=se;let E;if(d.length===1)await A.deleteProjectChat(a,d[0]),E=d;else{const H=await A.deleteProjectChats(a,d);E=H.removed,H.failed.length&&h(`Deleted ${H.removed.length} of ${d.length} chats — ${H.failed.length} could not be removed.`)}const V=new Set(E);P(H=>H.filter(G=>!V.has(G.sessionId))),J&&V.has(J)&&l(`${n}/chat`,{replace:!0}),$e(null)},[se,a,n,J,l]),ps=r.useCallback((d,E)=>{const V=R.filter(oe=>!!oe.archived==!!d.archived),H=new Set(E),G=ii(V,d.sessionId).filter(oe=>!H.has(oe)).length;$e({chat:d,ids:E,orphanCount:G})},[R]),ms=r.useCallback(async(d,E)=>{await A.renameProjectChat(a,d.sessionId,E),P(V=>V.map(H=>H.sessionId===d.sessionId?{...H,name:E||H.preview||H.sessionId.slice(0,8)}:H))},[a]),hs=r.useCallback(async(d,E)=>{const V=!d.archived,H=new Set(E);P(G=>G.map(oe=>H.has(oe.sessionId)?{...oe,archived:V}:oe)),V&&S(!0);try{E.length===1?await A.archiveProjectChat(a,E[0],V):await A.archiveProjectChats(a,E,V)}catch(G){P(oe=>oe.map(st=>H.has(st.sessionId)?{...st,archived:d.archived}:st)),h(G instanceof Error?G.message:"Failed to archive chat")}},[a]),xs=r.useCallback(async d=>{const E=d.parent;if(E){P(V=>V.map(H=>H.sessionId===d.sessionId?{...H,parent:void 0}:H));try{await A.detachProjectChat(a,d.sessionId,!0)}catch(V){P(H=>H.map(G=>G.sessionId===d.sessionId?{...G,parent:E}:G)),h(V instanceof Error?V.message:"Failed to detach chat")}}},[a]),v=r.useCallback(async d=>{const E=!d.starred;P(V=>V.map(H=>H.sessionId===d.sessionId?{...H,starred:E}:H));try{await A.starProjectChat(a,d.sessionId,E)}catch(V){P(H=>H.map(G=>G.sessionId===d.sessionId?{...G,starred:d.starred}:G)),h(V instanceof Error?V.message:"Failed to star chat")}},[a]),_=r.useCallback(async(d,E)=>{if(Nt.has(d.sessionId)){Lt(E);return}const V=new Set(E),H=new Map(R.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{E.length===1?await A.markChatUnread(a,E[0],!0):await A.markChatsUnread(a,E,!0)}catch(G){P(oe=>oe.map(st=>V.has(st.sessionId)?{...st,unread:H.get(st.sessionId)}:st)),h(G instanceof Error?G.message:"Failed to mark chat unread")}},[Nt,Lt,a,R]),ve=r.useCallback(d=>re.runningOnly||!re.nested?ri(d):ni(d),[re.runningOnly,re.nested]),Ue=r.useMemo(()=>ve(re.runningOnly?Ze:Ze.filter(d=>!d.archived)),[Ze,ve,re.runningOnly]),Be=r.useMemo(()=>re.runningOnly?[]:ve(Ze.filter(d=>d.archived)),[Ze,ve,re.runningOnly]),fs=R.filter(d=>!d.archived).length,Ve=r.useMemo(()=>R.filter(d=>D.has(d.sessionId)).length,[R,D]),Ws=R.some(d=>d.archived&&d.sessionId===J),ot=r.useRef(null);r.useEffect(()=>{var E;const d=R.find(V=>V.sessionId===J);d?ot.current=d:((E=ot.current)==null?void 0:E.sessionId)!==J&&(ot.current=null)},[R,J]);const cn=!!J&&u==="chat"&&U!==J&&!R.some(d=>d.sessionId===J)?((Js=ot.current)==null?void 0:Js.sessionId)===J?ot.current:{sessionId:J,workingDirectory:"",name:"Current chat",updatedAt:"",resumable:!0}:null;if(r.useEffect(()=>{Ws&&wt.current!==J&&(wt.current=J,S(!0))},[Ws,J]),ue)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:ue})});if(!k)return e.jsx("div",{className:"p-8 text-sm text-paddock-500",children:"Loading project…"});const Ks=k.pinned,qs=u==="files"&&j&&Ks.includes(j)?j:null,dn=u==="files"&&!qs;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(_n,{width:20,height:20})}),e.jsxs("button",{type:"button",onClick:()=>ye(!0),className:"btn-subtle shrink-0 gap-1.5 px-2 py-1.5 lg:-ml-2 lg:hidden","aria-label":"Show chats",children:[e.jsx(Qt,{width:16,height:16}),e.jsx("span",{className:"hidden sm:inline",children:"Chats"}),R.length>0&&e.jsx("span",{className:"text-[11px] text-paddock-400",children:R.length})]}),e.jsx("h1",{className:"min-w-0 text-lg font-semibold tracking-tight lg:text-xl",children:e.jsx("button",{type:"button",onClick:mt,title:"Project home",className:"block max-w-full truncate rounded transition-colors hover:text-accent",children:k.name})}),e.jsx(Yn,{status:k.status}),k.domain.map(d=>e.jsx(Dn,{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(dt,{width:11,height:11}),"Overview"]}),!k.managed&&k.repo&&e.jsxs("a",{href:Pn(k.repo),target:"_blank",rel:"noreferrer",title:k.path?`Claude works in ${k.path}, a checkout of ${k.repo}`:`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(Ye,{width:11,height:11}),"Repo"]}),!k.managed&&!k.repo&&k.path&&e.jsxs("span",{title:`Claude works in ${k.path}. Paddock writes no project files there.`,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(Ye,{width:11,height:11}),"Linked"]}),e.jsxs("span",{className:"ml-auto hidden items-center gap-1 text-xs text-paddock-400 lg:inline-flex",children:[e.jsx(at,{width:12,height:12}),"updated ",vt(k.updated)]}),e.jsx("button",{type:"button",onClick:_e,"aria-label":"New chat",title:"New chat",className:"btn-subtle ml-auto shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(ct,{width:16,height:16})}),e.jsx(Qn,{onEdit:Ut,onDelete:t?void 0:()=>Fe(!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(Si,{chatList:We,sessionsOpen:Ae,setSessionsOpen:ye,chatSearch:y,setChatSearch:B,searching:ns,newChat:_e,view:u,activeSession:J,pendingChat:U,chats:R,fallbackChat:cn,visibleChats:Ze,activeChats:Ue,archivedChats:Be,activeTotal:fs,runningCount:Ve,viewPrefs:re,archivedOpen:be,setArchivedOpen:S,collapsedChats:Q,toggleChatCollapsed:de,openChat:ht,unread:Nt,usageBySession:N,runningSessions:D,setForkingChat:Oe,setPromotingChat:t?Je:void 0,renameChat:fe,archiveChat:hs,requestDeleteChat:ps,starChat:v,toggleUnread:_,detachChat:xs,adoptableCount:F,adopting:g,adoptChats:()=>he(!0)}),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(it,{active:u==="home",onClick:mt,children:"Home"}),e.jsx(it,{active:u==="chat",onClick:Ke,children:"Chat"}),e.jsx(it,{active:dn,onClick:Ft,children:"Files"}),ie&&e.jsx(it,{active:u==="changes",onClick:rs,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(it,{active:u==="history",onClick:Ot,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["History",Se>0&&e.jsx("span",{title:`${Se} new unattended run${Se===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:Se})]})}),e.jsx(it,{active:u==="settings",onClick:Ut,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ma,{width:13,height:13}),"Settings"]})}),e.jsx(it,{active:u==="triggers",onClick:Bt,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Dt,{width:13,height:13}),"Triggers"]})}),Ks.map(d=>e.jsx(ki,{file:d,active:qs===d,onSelect:()=>xt(d),onUnpin:()=>void us(d)},d))]})}),u==="changes"&&ie&&e.jsx(il,{slug:k.slug,status:ie,onStatusChange:d=>Ce(d.repo?d:null),selectedFile:C??null,onSelectFile:qe}),u==="history"&&e.jsx(jl,{slug:k.slug,state:Te,chats:R,onOpenChat:ht}),u==="settings"&&e.jsx(Ml,{project:k,onSaved:d=>{L(d),x(d)}}),u==="triggers"&&e.jsx(Hl,{project:k}),u==="home"&&e.jsx(gi,{project:k,running:ut.running,unread:ut.unread,attentionLoading:ut.loading,attentionError:ut.error,changelog:z,overview:Y,files:ae,onOpenChat:It,onNewChat:_e,onOpenFile:xt,onOpenFiles:Ft}),u==="chat"&&e.jsx(ol,{projectSlug:k.slug,initialSessionId:J??void 0,loadHistory:St,onSessionEstablished:Gt,onSessionStarted:Ht,onTurnComplete:cs,preloadAvailable:k.hasOverview,projectModel:k.model,projectModels:k.models,projectRecovery:k.recovery,projectAttachments:k.attachments,forkParent:ls??void 0,onOpenForkParent:ht,onForkFromMessage:Vt,onRevertToMessage:zt,autoFocus:is,trigger:(Zs=R.find(d=>d.sessionId===J)??(((Xs=ot.current)==null?void 0:Xs.sessionId)===J?ot.current:null))==null?void 0:Zs.trigger},M),u==="files"&&e.jsx(Il,{project:k,path:j,onNavigate:xt,onTogglePin:ds},j)]})]}),e.jsx(qt,{open:Ee,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 A.deleteProject(k.slug),w(k.slug),sr(k.slug),l(Ln())},onClose:()=>Fe(!1)}),e.jsx(qt,{open:se!==null,title:se&&se.ids.length>1?`Delete ${se.ids.length} chats?`:"Delete chat?",message:se&&e.jsxs(e.Fragment,{children:[se.ids.length>1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-ink dark:text-ink-dark",children:se.chat.name})," ","and its ",se.ids.length-1," nested chat",se.ids.length-1===1?"":"s"," will be permanently removed — their transcripts too."]}):"This chat's transcript will be permanently removed.",se.orphanCount>0&&e.jsxs(e.Fragment,{children:[" ","Its ",se.orphanCount," other nested chat",se.orphanCount===1?"":"s"," will be kept and moved to the top level."]})," ","This cannot be undone."]}),confirmLabel:se&&se.ids.length>1?`Delete ${se.ids.length} chats`:"Delete chat",onConfirm:Wt,onClose:()=>$e(null)}),Ge&&e.jsx(Xl,{open:!0,slug:a,sessionId:Ge.sessionId,defaultName:Ge.name,onClose:()=>Je(null),onPromoted:d=>{Je(null),x(d),l(`/projects/${d.slug}/chat`)}}),W&&e.jsx(Jl,{open:!0,chatName:W.name,resetName:W.preview,onClose:()=>fe(null),onRename:d=>{const E=W;fe(null),ms(E,d)}}),Qe&&e.jsx(Ql,{open:!0,chatName:Qe.name,onClose:()=>Oe(null),onFork:d=>{const E=Qe;Oe(null),os(E,d)}}),e.jsx(Zl,{open:ge,adoptable:pe,busy:g,onClose:()=>he(!1),onAdopt:d=>void yt(d)}),e.jsx(Mi,{message:(ce==null?void 0:ce.message)??null,tone:ce==null?void 0:ce.tone,onDismiss:Ie,action:ce==null?void 0:ce.action,durationMs:ce!=null&&ce.action?12e3:void 0})]})}const Oi=Object.freeze(Object.defineProperty({__proto__:null,ProjectView:_i,adoptSummary:ln},Symbol.toStringTag,{value:"Module"}));export{No as M,Oi as P};
|
|
13
|
+
|