@edspencer/paddock 0.75.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/server/dist/instance-config.js +2 -2
- package/packages/server/dist/routes/chats.d.ts +17 -0
- package/packages/server/dist/routes/chats.js +32 -4
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/{DeleteProjectDialog-BVjEiE8h.js → DeleteProjectDialog-cHTdNUlT.js} +1 -1
- package/packages/web/dist/assets/DiscoverPage-DzR0ltxH.js +2 -0
- package/packages/web/dist/assets/DiscoverView-CiTYHesP.js +2 -0
- package/packages/web/dist/assets/InstanceConfigPage-C9cJA3mw.js +2 -0
- package/packages/web/dist/assets/{MarkdownRenderer-A5ROjF2W.js → MarkdownRenderer-5uaTbABu.js} +2 -2
- package/packages/web/dist/assets/{ProjectRedirect-CNQm3371.js → ProjectRedirect-BscldZqe.js} +1 -1
- package/packages/web/dist/assets/ProjectView-Bj95W0f4.js +13 -0
- package/packages/web/dist/assets/ProjectsGrid-BYgv4KBI.js +2 -0
- package/packages/web/dist/assets/RootHome-2SxtceM_.js +2 -0
- package/packages/web/dist/assets/{Surfaces-CF0yyXrm.js → Surfaces-B__G3SGB.js} +1 -1
- package/packages/web/dist/assets/{arc-DrUfzi6A.js → arc-DeEeXqHG.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-BYqov1Zc.js → architectureDiagram-3BPJPVTR-DAEVJcxx.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DmMOVO_f.js → blockDiagram-GPEHLZMM-BDsc1L6N.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-Czfa53Zk.js → c4Diagram-AAUBKEIU-BRAkt0wF.js} +1 -1
- package/packages/web/dist/assets/channel-xkQ7S92i.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-C0V1Q1vH.js → chunk-2J33WTMH-CbWDgMLI.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-DnjnNYey.js → chunk-4BX2VUAB-BcEZCLPu.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-BcFZPZvh.js → chunk-55IACEB6-DCqQh6q8.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-D3f-Sjzp.js → chunk-727SXJPM-JweiY_B4.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-DQHhDP9y.js → chunk-AQP2D5EJ-BYrqLbEv.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-Dj5WjiyS.js → chunk-FMBD7UC4-dJDuyJ2V.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-Bl7cQ3SB.js → chunk-ND2GUHAM-DsJrI4kA.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-C7SPUOKr.js → chunk-QZHKN3VN-D6xgEpXd.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-C1trK71k.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-C1trK71k.js +2 -0
- package/packages/web/dist/assets/{core-DD3lQR7a.js → core-afW9-UwG.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-DsUrPBsx.js → cose-bilkent-S5V4N54A-BhZOj7HZ.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG--oW-opUg.js → dagre-BM42HDAG-DCfvbRPP.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-PBABAEds.js → diagram-2AECGRRQ-Ci0M1D7l.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-DHgapxzA.js → diagram-5GNKFQAL-BZ6SW1yc.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-BlAviCxX.js → diagram-KO2AKTUF-B4-cJTIk.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-CY6_XHw1.js → diagram-LMA3HP47-B2OF1ipy.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-6kwM_03D.js → diagram-OG6HWLK6-D70TzZwD.js} +1 -1
- package/packages/web/dist/assets/documentTitle-Wl8Djqre.js +2 -0
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-bh-0n04U.js → erDiagram-TEJ5UH35-CDTl1U_L.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-BVkoiXeP.js → flowDiagram-I6XJVG4X-BpuTkLzx.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-DnfAgVxK.js → ganttDiagram-6RSMTGT7-zfON_pzp.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-BLyvLMXz.js → gitGraphDiagram-PVQCEYII-CXJlr4Aa.js} +1 -1
- package/packages/web/dist/assets/index-BPqHA_fy.js +71 -0
- package/packages/web/dist/assets/index-Uc957im9.css +1 -0
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-D6B9ugJD.js → infoDiagram-5YYISTIA-1K1LG6E2.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-CZ7CzKek.js → ishikawaDiagram-YF4QCWOH-srZJnYw8.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-C7XkLc9i.js → journeyDiagram-JHISSGLW-3E_CsMIN.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-B1IONnOY.js → kanban-definition-UN3LZRKU-BUPFeskA.js} +1 -1
- package/packages/web/dist/assets/{linear-Evefwzlv.js → linear-CS75OsJ4.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-DFz_RqY2.js → mermaid.core-AX6KCjdW.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-DCHEHB1t.js → mindmap-definition-RKZ34NQL-CvtTMpsJ.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-CAgAPCtd.js → pieDiagram-4H26LBE5-DyWKFZLR.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-Qx0hVImF.js → quadrantDiagram-W4KKPZXB-DlLXpUjd.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-Cag9Mvg9.js → requirementDiagram-4Y6WPE33-DuF2w7X7.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-DCdGTeQa.js → sankeyDiagram-5OEKKPKP-jQdUQ_IA.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-Dwpsy94j.js → sequenceDiagram-3UESZ5HK-4RN9tEo0.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-aGMHRRAE.js → stateDiagram-AJRCARHV-CkknRhAq.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-1UhTuOCG.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-BzPnsQmY.js → timeline-definition-PNZ67QCA-CtDo_Km4.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-CZ1fY8y7.js → vennDiagram-CIIHVFJN-BtHweUMq.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-C41nLzIr.js → wardley-L42UT6IY-C_OWlnET.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-CoUrc0lU.js → wardleyDiagram-YWT4CUSO-CI_iXYGs.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-DCOTYBX6.js → xychartDiagram-2RQKCTM6-zPP4izdU.js} +1 -1
- package/packages/web/dist/index.html +2 -2
- package/packages/web/dist/sw.js +1 -1
- package/packages/web/dist/assets/DiscoverPage-Pqr0B6n7.js +0 -2
- package/packages/web/dist/assets/DiscoverView-BWfSBjLX.js +0 -2
- package/packages/web/dist/assets/InstanceConfigPage-ClXUufoD.js +0 -2
- package/packages/web/dist/assets/ProjectView-BdzJ3aKK.js +0 -13
- package/packages/web/dist/assets/ProjectsGrid-DR1fmWxh.js +0 -2
- package/packages/web/dist/assets/RootHome-CTLglUiz.js +0 -2
- package/packages/web/dist/assets/channel-CEHEe3UY.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-CeAhIB_Q.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-CeAhIB_Q.js +0 -2
- package/packages/web/dist/assets/index-CQsrBw44.js +0 -71
- package/packages/web/dist/assets/index-LM9Ga0Wn.css +0 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-DhdrFtkn.js +0 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-5uaTbABu.js","assets/index-BPqHA_fy.js","assets/index-Uc957im9.css","assets/queued-CagZVfWU.js","assets/DeleteProjectDialog-cHTdNUlT.js","assets/lastTab-CU1zsF0j.js","assets/Surfaces-B__G3SGB.js","assets/DiscoverView-CiTYHesP.js","assets/documentTitle-Wl8Djqre.js","assets/core-afW9-UwG.js","assets/mermaid.core-AX6KCjdW.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as a,a as B,Z as je,j as e,a9 as $n,A as ge,aa as Gs,ab as Qt,X as Oe,n as Je,ac as Mt,L as rn,ad as ma,C as Yt,ae as fa,B as ft,i as rt,a4 as qs,af as wr,ag as vr,ah as yr,ai as kr,aj as Nr,ak as Cr,al as Sr,am as Tr,t as At,a7 as Qs,an as In,S as Xt,ao as $r,I as fs,a5 as Jt,ap as xa,P as bs,aq as ga,ar as pa,as as ba,at as ce,W as It,au as Ir,av as Ps,aw as ja,ax as Er,p as Et,ay as wa,az as xs,Q as va,aA as ya,aB as be,aC as Rr,aD as Mr,aE as _s,aF as gs,aG as ka,T as js,aH as Ys,aI as Ar,aJ as Dr,a1 as Pr,c as $t,aK as pe,aL as _r,aM as Lr,aN as Fr,aO as Or,aP as Ur,aQ as Br,aR as Vr,aS as En,aT as Rn,aU as zr,aV as Hr,aW as Wr,e as ws,aX as Kr,aY as Gr,aZ as qr,a_ as Na,d as Ca,a$ as Qr,u as Yr,R as Xr,b0 as Jr,h as Zr,a0 as ei,b1 as ti,b2 as si,b3 as ni,O as ai,b4 as ri,l as ii,b5 as oi}from"./index-BPqHA_fy.js";import{readQueued as li,readQueuedId as ci,readQueuedAttachments as di,writeQueued as ui,writeQueuedId as hi,writeQueuedAttachments as mi,newQueuedId as fi}from"./queued-CagZVfWU.js";import{C as on,d as xi,D as gi}from"./DeleteProjectDialog-cHTdNUlT.js";import{S as mt,C as pi,E as Sa}from"./Surfaces-B__G3SGB.js";import{t as dt,w as bi}from"./lastTab-CU1zsF0j.js";import{D as ji}from"./DiscoverView-CiTYHesP.js";import{u as wi}from"./documentTitle-Wl8Djqre.js";const vi=500,yi=9e4,Ls="paddock:cancel",Mn="paddock:timeout";function ki(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function Ni(){const t=[{mimeType:"audio/webm;codecs=opus",ext:"webm"},{mimeType:"audio/webm",ext:"webm"},{mimeType:"audio/ogg;codecs=opus",ext:"ogg"},{mimeType:"audio/mp4",ext:"mp4"}],s=window.MediaRecorder;for(const n of t)if(typeof s.isTypeSupported!="function"||s.isTypeSupported(n.mimeType))return n;return{mimeType:"",ext:"webm"}}function Ci({onText:t,timeoutMs:s=yi}){const[n,r]=a.useState("idle"),[i,o]=a.useState(null),[l,c]=a.useState(null),[m]=a.useState(ki),u=a.useRef(null),b=a.useRef(null),f=a.useRef([]),h=a.useRef("webm"),j=a.useRef(null),x=a.useRef(null),N=a.useRef(!0);a.useEffect(()=>{N.current=!0;let y=!1;return B.transcriptionStatus().then(T=>{y||o(T.available)}).catch(()=>{y||o(!1)}),()=>{var T;y=!0,N.current=!1,(T=x.current)==null||T.abort(Ls),d()}},[]);const d=()=>{var y;(y=b.current)==null||y.getTracks().forEach(T=>T.stop()),b.current=null,u.current=null},g=a.useCallback(async()=>{if(!m||n==="recording"||n==="transcribing")return;c(null),j.current=null;let y;try{y=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(O){r("error"),c(Ii(O));return}b.current=y;const{mimeType:T,ext:w}=Ni();h.current=w;const F=T?new MediaRecorder(y,{mimeType:T}):new MediaRecorder(y);f.current=[],F.ondataavailable=O=>{O.data&&O.data.size>0&&f.current.push(O.data)},F.onstop=()=>{d();const O=F.mimeType||T||"audio/webm",z=new Blob(f.current,{type:O});f.current=[],j.current=z,D(z)},u.current=F,F.start(),r("recording")},[m,n]),D=a.useCallback(async(y,T=!1)=>{if(y.size===0){j.current=null,N.current&&r("idle");return}N.current&&r("transcribing");const w=new AbortController;x.current=w;const F=setTimeout(()=>w.abort(Mn),s);try{const O=await B.transcribe(y,`dictation.${h.current}`,w.signal);O.trim()&&t(O.trim()),j.current=null,N.current&&(c(null),r("idle"))}catch(O){if(w.signal.aborted&&w.signal.reason===Ls){j.current=null,N.current&&(c(null),r("idle"));return}if(w.signal.aborted&&w.signal.reason===Mn){N.current&&(r("error"),c("Transcription timed out — try again."));return}if(Si(O)&&!T)return await $i(vi),D(y,!0);N.current&&(r("error"),c(Ti(O)))}finally{clearTimeout(F),x.current===w&&(x.current=null)}},[t,s]),$=a.useCallback(()=>{var y;(y=x.current)==null||y.abort(Ls)},[]),I=a.useCallback(()=>{const y=u.current;y&&y.state!=="inactive"&&y.stop()},[]),C=a.useCallback(()=>{n==="recording"?I():g()},[n,g,I]),S=a.useCallback(()=>{if(n==="recording"||n==="transcribing")return;const y=j.current;y?D(y):g()},[n,D,g]),M=a.useCallback(()=>{j.current=null,c(null),r("idle")},[]);return{state:n,available:i,supported:m,error:l,start:g,stop:I,toggle:C,retry:S,dismiss:M,cancel:$}}function Si(t){return t instanceof je?t.status>=500:!0}function Ti(t){return t instanceof je?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 $i(t){return new Promise(s=>setTimeout(s,t))}function Ii(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 Ei({onText:t}){const{state:s,available:n,supported:r,error:i,toggle:o,retry:l,dismiss:c,cancel:m}=Ci({onText:t});if(n!==!0)return null;const u=s==="recording",b=s==="transcribing",f=s==="error";if(!r)return e.jsx("button",{type:"button",disabled:!0,"aria-label":"Voice dictation unavailable",title:"Voice dictation needs a secure context (HTTPS or localhost). It's blocked over plain HTTP.",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-fg-subtle",children:e.jsx($n,{width:18,height:18})});const h=u?"Stop recording":b?"Transcribing… — click to cancel":f?"Transcription failed — click to record again":"Record a voice message",j=()=>{b?m():o()};return e.jsxs("div",{className:"relative flex items-center",children:[f&&i&&e.jsxs("div",{role:"alert",className:"absolute bottom-full right-0 z-10 mb-2 flex max-w-[240px] items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-2.5 py-1.5 text-xs text-danger shadow-md",children:[e.jsx(ge,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:i}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 font-medium text-danger underline underline-offset-2 hover:opacity-80",children:"Retry"}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Dismiss error",className:"shrink-0 text-danger/70 hover:text-danger",children:"✕"})]}),e.jsxs("button",{type:"button",onClick:j,"aria-label":u?"Stop recording":b?"Cancel transcription":"Record a voice message","aria-pressed":u,title:h,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",u?"bg-danger-soft text-danger":b?"cursor-pointer text-accent can-hover:hover:bg-danger-soft can-hover:hover:text-danger":f?"bg-danger-soft text-danger":"text-fg-muted can-hover:hover:bg-surface-hover can-hover:hover:text-fg"].filter(Boolean).join(" "),children:[b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(Ri,{})}),e.jsx(Gs,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):u?e.jsx(Gs,{width:16,height:16}):e.jsx($n,{width:18,height:18}),u&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function Ri(){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 Mi="paddock:chatModel:";function Ta(t,s){return Mi+(t??`new:${s}`)}function Ai(t,s){try{const n=localStorage.getItem(Ta(t,s));return n&&n.length>0?n:null}catch{return null}}function Xs(t,s,n){try{localStorage.setItem(Ta(t,s),n)}catch{}}const Di="paddock:draft:";function $a(t,s){return Di+(t??`new:${s}`)}function Pi(t,s){try{return localStorage.getItem($a(t,s))??""}catch{return""}}function _i(t,s,n){try{const r=$a(t,s);n.length>0?localStorage.setItem(r,n):localStorage.removeItem(r)}catch{}}const An="<paddock-attachments>",Js="</paddock-attachments>",Dn=`${Js}
|
|
3
|
+
|
|
4
|
+
`;function Ia(t){return`/api/chat-files/${encodeURIComponent(t)}`}function Li(t){const s=t.indexOf(An);if(s===-1)return{attachments:[],text:t};const n=s+An.length,r=t.indexOf(Js,n);if(r===-1)return{attachments:[],text:t};const i=t.slice(n,r),o=[];for(const m of i.split(`
|
|
5
|
+
`)){const u=m.split(" ");if(u.length<3)continue;const[b,f,h]=u;!(b!=null&&b.trim())||!(h!=null&&h.trim())||o.push({id:b.trim(),kind:(f==null?void 0:f.trim())||"file",filename:h.trim()})}const l=t.slice(0,s),c=t.startsWith(Dn,r)?t.slice(r+Dn.length):t.slice(r+Js.length).replace(/^\n+/,"");return{attachments:o,text:l+c}}function Fi(t){const s=t.slice(t.lastIndexOf("/")+1),n=s.lastIndexOf(".");return n>0?s.slice(n).toLowerCase():""}function Ea(t){if(t===void 0||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const s=t/1024;if(s<1024)return`${s<10?s.toFixed(1):Math.round(s)} KB`;const n=s/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function Oi(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function Ui(t,s,n){const r=(s??"").trim().toLowerCase(),i=Fi(n??"");for(const o of t){const l=o.trim().toLowerCase();if(l){if(l==="*"||l==="*/*")return!0;if(l.includes("/")){if(!r)continue;const[c,m]=l.split("/",2),[u,b]=r.split("/",2);if((c==="*"||c===u)&&(m==="*"||m===b))return!0}else if(l.startsWith(".")){if(i&&i===l)return!0}else if(i&&i===`.${l}`)return!0}}return!1}function Bi({attachments:t}){return t.length===0?null:e.jsx("div",{className:"mb-1 flex flex-wrap justify-end gap-2","data-testid":"message-attachments",children:t.map(s=>e.jsx(Vi,{attachment:s},s.id))})}function Vi({attachment:t}){const s=Ia(t.id);if(t.kind==="image")return e.jsx(Hi,{src:s,filename:t.filename});const n=Ea(t.size);return e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",title:t.filename,"data-testid":"attachment-chip",className:"flex max-w-[14rem] items-center gap-2 rounded-xl bg-surface-raised px-3 py-2 text-left text-xs shadow-sm ring-1 ring-edge hover:ring-accent",children:[e.jsx(Qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,n?` · ${n}`:""]})]})]})}function zi({attachment:t,onRemove:s}){const n=Ia(t.id),[r,i]=a.useState(!1),o=t.kind==="image"&&!r,l=Ea(t.size);return e.jsxs("span",{"data-testid":"attachment-tray-item",className:"group relative flex items-center gap-2 rounded-xl bg-surface-raised py-2 pl-2 pr-7 text-xs shadow-sm ring-1 ring-edge",children:[o?e.jsx("img",{src:n,alt:t.filename,onError:()=>i(!0),className:"h-9 w-9 shrink-0 rounded-md object-cover"}):e.jsx(Qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"max-w-[10rem] truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,l?` · ${l}`:""]})]}),e.jsx("button",{type:"button",onClick:()=>s(t.id),"aria-label":`Remove ${t.filename}`,title:"Remove","data-testid":"attachment-remove",className:"absolute right-1 top-1 rounded-full p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg",children:e.jsx(Oe,{width:12,height:12})})]})}function Hi({src:t,filename:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(!1);return i?e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-raised px-3 py-2 text-xs text-danger shadow-sm ring-1 ring-edge",children:[e.jsx(ge,{width:14,height:14}),s]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>r(!0),title:s,"data-testid":"attachment-thumb",className:"block overflow-hidden rounded-xl ring-1 ring-edge hover:ring-accent",children:e.jsx("img",{src:t,alt:s,onError:()=>o(!0),className:"h-24 w-24 object-cover"})}),n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4",onClick:()=>r(!1),role:"dialog","aria-label":s,children:e.jsx("img",{src:t,alt:s,className:"max-h-full max-w-full rounded-lg object-contain shadow-2xl"})}):null]})}function Wi(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 Ki({trigger:t,projectSlug:s}){const n=t.allowedTools??[],r=n.length===0,i=r?t.type==="schedule"?"runs as Claude (full tools)":"no tools declared":`${n.length} tool${n.length===1?"":"s"} granted`,o=t.type==="schedule"?Je:Mt;return e.jsx("div",{"data-testid":"trigger-capability-banner",className:"sticky top-0 z-10 mb-4 rounded-xl border border-info-edge bg-info-soft/95 px-3 py-2.5 text-info shadow-sm backdrop-blur",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{"aria-hidden":!0,className:"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-lg bg-info-solid/15 text-info",children:e.jsx(o,{width:15,height:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm",children:[e.jsx("span",{className:"font-semibold",children:"Trigger agent"}),e.jsx("span",{"data-trigger-type":t.type,className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:t.type}),e.jsx("span",{className:"font-mono text-sm text-info",children:t.name}),!t.enabled&&e.jsx("span",{title:"This trigger is currently disabled — it won't fire again until re-enabled. This chat is one of its past runs.",className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:"disabled"})]}),e.jsxs("p",{className:"mt-0.5 text-xs text-info",children:["Fired by ",e.jsx("span",{className:"font-medium",children:Wi(t)})," · ",i,". A reply you type here runs at this trigger's capability, not Claude's."]}),e.jsxs("details",{className:"group mt-1.5 text-xs",children:[e.jsxs("summary",{className:"inline-flex cursor-pointer select-none items-center gap-1 text-info hover:underline",children:[e.jsx("span",{className:"transition group-open:rotate-90","aria-hidden":!0,children:"▸"}),"Capabilities"]}),e.jsxs("div",{className:"mt-2 space-y-2 border-l-2 border-info-edge pl-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 font-medium",children:"Allowed tools"}),r?e.jsx("p",{className:"text-info",children:t.type==="schedule"?"None declared — this schedule runs as Claude with its full toolset.":"None declared. An empty list is not a restriction: no allow-list is passed to the runtime, so this agent falls back to Claude's default tools. Its prompt and max turns are the real bounds."}):e.jsx("ul",{className:"flex flex-wrap gap-1","data-testid":"trigger-allowed-tools",children:n.map(l=>e.jsx("li",{className:"rounded bg-info-solid/10 px-1.5 py-px font-mono text-2xs text-info",children:l},l))})]}),e.jsxs("dl",{className:"grid grid-cols-[auto,1fr] gap-x-3 gap-y-0.5 text-info",children:[t.permissionMode&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Permission mode"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.permissionMode})]}),t.model&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Model"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.model})]}),e.jsx("dt",{className:"font-medium",children:"Max turns"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.maxTurns}),e.jsx("dt",{className:"font-medium",children:"Agent"}),e.jsx("dd",{className:"truncate font-mono text-2xs",children:t.agentName})]}),e.jsx(rn,{to:`/projects/${encodeURIComponent(s)}/triggers`,className:"inline-flex items-center gap-1 font-medium text-info hover:underline",title:"Manage this project's triggers",children:"Edit trigger →"})]})]})]})]})})}const Gi=new Set(["paddock","paddock_manage"]);function qi(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function Qi(t){if(!t.startsWith("mcp__"))return{isMcp:!1,server:"",isPaddock:!1,display:t,tool:t};const s=t.slice(5),n=s.indexOf("__"),r=n===-1?s:s.slice(0,n),i=n===-1?"":s.slice(n+2);return{isMcp:!0,server:r,isPaddock:Gi.has(r),display:qi(i||r),tool:i}}const Pn="mcp__paddock_manage__",Wt=(t,s)=>typeof t=="number"&&Number.isFinite(t)?t:s,Nt=t=>{if(typeof t!="string")return;const s=t.trim();return s.length>0?s:void 0};function Ra(t,s=80){var r;const n=((r=t.split(`
|
|
6
|
+
`).find(i=>i.trim().length>0))==null?void 0:r.trim())??t.trim();return n.length>s?`${n.slice(0,s).trimEnd()}…`:n}function Ma(t,s){return t||(s?Ra(s):"untitled chat")}function Yi(t,s){if(!t.startsWith(Pn)||!s)return null;const n=t.slice(Pn.length);let r;try{r=JSON.parse(s)}catch{return null}if(!r||typeof r!="object")return null;switch(n){case"list_projects":{if(!Array.isArray(r.projects))return null;const i=r.projects;return{tool:n,count:Wt(r.count,i.length),projects:i}}case"list_chats":{if(!Array.isArray(r.chats))return null;const i=r.chats;return{tool:n,count:Wt(r.count,i.length),project:r.project??null,chats:i}}case"read_chat":{if(!Array.isArray(r.messages))return null;const i=r.messages;return{tool:n,project:String(r.project??""),sessionId:String(r.sessionId??""),total:Wt(r.total,i.length),returned:Wt(r.returned,i.length),messages:i}}case"create_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),name:Nt(r.name),prompt:Nt(r.prompt)}:null;case"send_message":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),prompt:Nt(r.prompt)}:null;case"fork_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),from:Nt(r.from),name:Nt(r.name),prompt:Nt(r.prompt)}:null;case"fork_chat_batch":{if(!Array.isArray(r.forks))return null;const i=r.forks;return{tool:n,count:Wt(r.count,i.length),source:String(r.source??""),forks:i}}default:return null}}function Xi(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 Ma(t.name,t.prompt);case"send_message":return t.prompt?Ra(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const Aa=a.createContext(null),Ji=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,Zs=t=>t.length>8?`${t.slice(0,8)}…`:t;function Gt({project:t,sessionId:s,label:n}){return e.jsxs(rn,{to:Ji(t,s),className:"inline-flex items-center gap-1 rounded-md bg-accent-soft px-2 py-0.5 font-mono text-2xs font-medium text-accent no-underline ring-1 ring-accent/20 transition-colors hover:bg-accent/20",title:`Open ${s}`,children:[e.jsx(ma,{width:10,height:10,className:"shrink-0"}),n??Zs(s)]})}const Ct="border-t border-edge px-3 py-2.5",St="text-fg-muted";function _n({children:t}){return e.jsx("span",{className:"rounded bg-surface-active px-1.5 py-0.5 text-3xs font-medium text-fg-muted",children:t})}function Ln({label:t,text:s}){return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"mb-1 text-3xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("div",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-surface-sunken px-2.5 py-1.5 text-2xs leading-relaxed text-fg-muted",children:s})]})}function Zi({chat:t}){return e.jsxs("li",{className:"flex items-center gap-2 py-1",children:[t.running?e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-success-solid",title:"running"}):e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-edge-strong"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg",children:t.name||"(untitled)"}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId})]})}function eo({data:t}){const s=a.useContext(Aa)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:Ct,children:e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.projects.map(n=>e.jsxs("li",{className:"flex items-center gap-1.5 rounded-md bg-surface-sunken px-2 py-1",children:[e.jsx("span",{className:"text-2xs font-medium text-fg",children:n.name}),n.area&&e.jsx(_n,{children:n.area}),n.status&&n.status!=="active"&&e.jsx(_n,{children:n.status})]},n.slug))})});case"list_chats":return e.jsx("div",{className:Ct,children:e.jsx("ul",{className:"max-h-72 divide-y divide-edge-subtle overflow-auto text-2xs",children:t.chats.map(n=>e.jsx(Zi,{chat:n},n.sessionId))})});case"read_chat":return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:[e.jsxs("span",{className:St,children:[t.returned," of ",t.total," messages"]}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),e.jsx("ul",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.messages.map((n,r)=>e.jsxs("li",{className:"text-2xs leading-relaxed",children:[e.jsx("span",{className:`mr-1.5 font-mono text-3xs font-semibold uppercase ${n.role==="assistant"?"text-accent":"text-fg-subtle"}`,children:n.role}),e.jsx("span",{className:"whitespace-pre-wrap break-words text-fg-muted",children:n.text})]},r))})]});case"create_chat":case"fork_chat":{const n=t.tool==="create_chat"?"Created chat":"Forked chat",r=Ma(t.name,t.prompt);return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:St,children:n}),e.jsx("span",{className:"font-medium text-fg",children:r}),e.jsxs("span",{className:St,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${St}`,children:["from ",Zs(t.from)]}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(Ln,{label:"Kickoff",text:t.prompt})]})}case"send_message":return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:St,children:"Sent to"}),e.jsx("span",{className:"font-medium text-fg",children:t.project}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(Ln,{label:"Message",text:t.prompt})]});case"fork_chat_batch":return e.jsxs("div",{className:Ct,children:[e.jsx("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:e.jsxs("span",{className:St,children:[t.count," ",t.count===1?"fork":"forks"," from ",Zs(t.source)]})}),e.jsx("ol",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.forks.map((n,r)=>e.jsxs("li",{className:"flex items-start gap-2 rounded-md bg-surface-sunken px-2 py-1.5",children:[e.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-3xs font-semibold text-fg-subtle",children:r+1}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:n.prompt}),e.jsx(Gt,{project:s,sessionId:n.sessionId})]},n.sessionId))})]})}}const vs=new Set(["Task","Agent"]);function to(t,s){return vs.has(t.toolName)&&s&&t.subagentDurationMs==null}const so="mcp__paddock__send_file",no=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),ao=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function ro(t){return t.background||t.toolName==="Monitor"||no.has(t.toolName)?!0:ao.test(t.output??"")}function io(t){switch(t){case"completed":return"bg-success-soft text-success";case"killed":case"timed out":return"bg-warn-soft text-warn";case"running":case"persistent":return"bg-info-soft text-info";default:return"bg-surface-active text-fg-muted"}}function oo(t){switch(t){case"list_projects":return qs;case"create_chat":return rt;case"fork_chat":case"fork_chat_batch":return ft;case"send_message":return fa;default:return Yt}}function Da(t){if(t.toolName!==so||!t.output)return null;let s;try{s=JSON.parse(t.output)}catch{return null}return!s||s.paddockSendFile!==1||typeof s.filename!="string"?null:{filename:s.filename,kind:s.kind,language:s.language,message:s.message,source:s.source,content:s.source==="inline"?s.content:void 0,rawUrl:s.source==="file"&&s.attachmentId?B.chatFileRawUrl(s.attachmentId):void 0}}function lo(t){return t==="+"?"bg-success-soft text-success":t==="-"?"bg-danger-soft text-danger":"text-fg-muted"}function Fn(t){return t===void 0?"":String(t)}function co(t){switch(t){case"completed":case"done":return"bg-success-soft text-success";case"in_progress":return"bg-info-soft text-info";case"blocked":case"failed":case"cancelled":return"bg-danger-soft text-danger";default:return"bg-surface-active text-fg-muted"}}function uo(t){const s=[];if(t.kind==="grep")t.numLines!==void 0&&s.push(`${t.numLines} line${t.numLines===1?"":"s"}`),t.numFiles!==void 0&&s.push(`${t.numFiles} file${t.numFiles===1?"":"s"}`);else{const n=t.totalMatches??t.numFiles;n!==void 0&&s.push(`${n} match${n===1?"":"es"}`)}return s.length?(t.truncated?"≥":"")+s.join(" · "):null}function ho(t){if(t.startLine===void 0||t.numLines===void 0)return null;const s=t.startLine+Math.max(0,t.numLines-1),n=t.totalLines!==void 0?` of ${t.totalLines}`:"";return`lines ${t.startLine}–${s}${n}`}let mo=0;const Xe=()=>`t${++mo}`;function fo(t,s){t(n=>{const r=n[n.length-1];return r&&r.kind==="assistant"&&r.streaming?[...n.slice(0,-1),{...r,content:r.content+s}]:[...n,{kind:"assistant",id:Xe(),content:s,streaming:!0}]})}function Fe(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function On(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 xo(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const o=Da(t.toolCall);return o?{kind:"file",id:s,file:o}:{kind:"tool",id:s,tool:t.toolCall}}if(t.role==="assistant")return{kind:"assistant",id:s,content:t.content,streaming:!1};if(wr(t.content))return{kind:"compact",id:s,summary:t.content};const n=vr(t.content);if(n)return{kind:"command",id:s,command:n};if(yr(t.content))return{kind:"commandOutput",id:s,content:kr(t.content)??""};if(Nr(t.content))return{kind:"commandOutput",id:s,content:""};if(Cr(t.content))return{kind:"notification",id:s,summary:Tr(t.content),status:Sr(t.content)};const{attachments:r,text:i}=Li(t.content);return{kind:"user",id:s,content:i,...t.sender?{sender:t.sender}:{},...r.length>0?{attachments:r}:{}}}const go="/compact";function po(t){return t.kind==="commandOutput"&&t.content===""}function bo(t){if(!t.some(n=>n.kind==="compact"))return t;const s=[];for(let n=0;n<t.length;n++){const r=t[n];if(r.kind!=="compact"){s.push(r);continue}let i=n+1;for(;i<t.length&&po(t[i]);)i++;const o=t[i];(o==null?void 0:o.kind)==="command"&&o.command===go?(s.push(...t.slice(n+1,i+1),r),n=i):s.push(r)}return s}function Tt(t){const s=new Map,n=t.filter(r=>!r.bgConsumed).map(r=>{let i;if(r.uuid){const l=s.get(r.uuid)??0;s.set(r.uuid,l+1),i=l===0?r.uuid:`${r.uuid}#${l}`}else i=Xe();const o=xo(r,i);return o.timestamp=r.timestamp,r.contextTokens!=null&&(o.contextTokens=r.contextTokens),o});return bo(n)}function Un(t){switch(t.kind){case"user":return`user:${t.content}`;case"command":return`command:${t.command}`;case"commandOutput":return`commandOutput:${t.content}`;case"compact":return`compact:${t.summary}`;case"notification":return`notification:${t.status??""}:${t.summary}`;case"notice":return`notice:${t.notice.kind}`;case"file":return`file:${t.file.filename}:${t.file.source}`;default:return`${t.kind}:${t.id}`}}function Fs(t,s){if(s.length===0)return t;if(t.length===0)return s;const n=[...t],r=new Map,i=new Map,o=[];n.forEach((l,c)=>{l.kind==="tool"&&l.tool.toolUseId?r.set(l.tool.toolUseId,c):l.kind==="assistant"?o.push(c):i.set(Un(l),c)});for(const l of s){if(l.kind==="tool"&&l.tool.toolUseId){const m=r.get(l.tool.toolUseId);if(m===void 0){r.set(l.tool.toolUseId,n.length),n.push(l);continue}const u=n[m];if(u.kind!=="tool")continue;n[m]={...u,tool:{...u.tool,...l.tool,pending:l.tool.pending===!0}};continue}if(l.kind==="assistant"){const m=o.find(b=>{const f=n[b];return f.kind==="assistant"&&(f.content===l.content||f.content.startsWith(l.content)||l.content.startsWith(f.content))});if(m===void 0){o.push(n.length),n.push(l);continue}const u=n[m];if(u.kind!=="assistant")continue;l.content.length>u.content.length&&(n[m]={...u,content:l.content,streaming:l.streaming});continue}const c=Un(l);i.has(c)||(i.set(c,n.length),n.push(l))}return n}const Pa=a.createContext(null),_a=a.createContext(!1),ln=a.createContext(null),La=a.createContext(null),Fa=a.createContext(null),cn=a.createContext(null),Oa=a.createContext(null),Ua=a.createContext(null),Bn=4;function jo(t){const[,s]=a.useState(0);a.useEffect(()=>{if(!t)return;const n=setInterval(()=>s(r=>r+1),1e3);return()=>clearInterval(n)},[t])}const ht=t=>t.role??t.type;function wo({role:t}){const s="shrink-0 text-info";return t==="shell"?e.jsx(Jt,{width:12,height:12,className:s}):t==="workflow"?e.jsx(xa,{width:12,height:12,className:s}):t==="subagent"?e.jsx(Xt,{width:12,height:12,className:"shrink-0 text-accent"}):e.jsx(Je,{width:12,height:12,className:s})}function Os(t){const s=ht(t);return s==="subagent"?t.agentType??"sub-agent":s==="workflow"?t.workflowName??"workflow":s==="monitor"?t.tool??"monitor":s}function Ba(t,s){var r,i;if(ht(t)!=="shell")return;const n=(r=t.command)==null?void 0:r.trim();if(n)return n;if(t.toolUseId)return((i=s==null?void 0:s.get(t.toolUseId))==null?void 0:i.trim())||void 0}function Vn(t,s){const n=Ba(t,s);return n||(ht(t)==="shell"?t.description:t.lastToolName?t.lastToolName:t.description)}const Va={subagent:"sub-agent",shell:"shell",monitor:"monitor",workflow:"workflow",task:"task"};function cs(t,s){const n=Va[t];return n?`${s} ${n}${s===1?"":"s"}`:`${s} ${t}`}const vo=t=>t==="subagent";function zn({taskId:t,label:s,stopping:n,failed:r,onStop:i}){return!i||!t?null:e.jsx("button",{type:"button",onClick:i,disabled:n,"data-testid":"running-task-cancel","data-stop-state":r?"failed":n?"stopping":"idle",title:r?`Could not stop: ${r}`:`Stop ${s}`,"aria-label":r?`Retry stopping ${s}`:`Stop ${s}`,className:`mr-1.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors disabled:opacity-40 ${r?"text-danger can-hover:hover:bg-danger-soft":"text-fg-subtle can-hover:hover:bg-danger-soft can-hover:hover:text-danger"}`,children:e.jsx(Oe,{width:12,height:12})})}function yo({running:t,activity:s,tasks:n,commands:r,onReveal:i,onCancel:o,stopping:l,stopFailed:c}){var L;const m=new Set(t.map(v=>v.toolUseId)),u=n.filter(v=>!v.skipTranscript),b=u.filter(v=>!(v.toolUseId!=null&&m.has(v.toolUseId))),f=new Map(u.filter(v=>v.toolUseId!=null).map(v=>[v.toolUseId,v])),h=t.length+b.length,[j,x]=a.useState(()=>h>Bn),N=a.useRef(h===0);a.useLayoutEffect(()=>{h===0?N.current=!0:N.current&&(N.current=!1,x(h>Bn))},[h]);const d=a.useId(),[g,D]=a.useState(null);if(a.useEffect(()=>{h===0&&D(null)},[h]),jo(h>0),h===0)return null;const $=new Map;t.length&&$.set("subagent",t.length);for(const v of b){const A=ht(v);$.set(A,($.get(A)??0)+1)}const I=[...$.entries()].sort((v,A)=>A[1]-v[1]),C=I.length===1&&Va[I[0][0]]?I[0][0]:null,S=C?`${cs(C,h)} running`:`${h} ${h===1?"thing":"things"} running`,M=b.reduce((v,A)=>v==null||A.startedAt>v.startedAt?A:v,null),y=t.length?t[t.length-1]:null,T=I.length>1?I.map(([v,A])=>cs(v,A)).join(" · "):M?Vn(M,r)||S:y?((L=s.get(y.toolUseId))==null?void 0:L.latestStep)??y.label:S,w=b.reduce((v,A)=>v==null||A.startedAt<v?A.startedAt:v,null),F=j?At:Qs,O=u.filter(v=>v.stoppable!==!1&&!(l!=null&&l.has(v.id))).map(v=>v.id),z=(v,A,W)=>{if(!(!o||!v))return()=>{if(!vo(A))return o(v);D({taskIds:[v],title:`Stop ${W}?`,body:"This sub-agent and everything it started will be stopped. Work already in progress is lost, and it cannot be resumed from where it got to.",confirmLabel:"Stop sub-agent"})}},J=()=>{const v=u.filter(A=>O.includes(A.id)&&ht(A)==="subagent").length;D({taskIds:O,title:"Stop all running work?",body:`${cs("task",O.length)} will be stopped`+(v>0?`, including ${cs("subagent",v)} and everything they started.`:".")+" Work already in progress is lost.",confirmLabel:"Stop all"})};return e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4","data-testid":"running-work",children:[e.jsxs("div",{className:"mb-2 overflow-hidden rounded-lg border border-accent-edge bg-accent-soft",children:[e.jsxs("div",{className:"flex items-center border-b border-accent/20",children:[e.jsxs("button",{type:"button",onClick:()=>x(v=>!v),"aria-expanded":!j,"aria-controls":d,"data-testid":"running-work-toggle",title:j?"Show each running item":"Collapse to a summary",className:"flex min-w-0 flex-1 items-center gap-1.5 px-3 py-1.5 text-left transition-colors can-hover:hover:bg-accent/10 focus-visible:focus-ring",children:[e.jsx("span",{className:"h-2.5 w-2.5 shrink-0 animate-spin rounded-full border-2 border-accent/30 border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 truncate text-3xs font-semibold uppercase tracking-wide text-accent",children:S}),e.jsx(F,{width:12,height:12,"aria-hidden":"true",className:"ml-auto shrink-0 text-accent/70"})]}),o&&h>1&&O.length>0&&e.jsx("button",{type:"button",onClick:J,"data-testid":"running-work-stop-all",title:"Stop every running task",className:"shrink-0 px-3 py-1.5 text-3xs font-semibold uppercase tracking-wide text-fg-subtle transition-colors can-hover:hover:text-danger focus-visible:focus-ring",children:"Stop all"})]}),j?e.jsxs("div",{id:d,className:"flex items-center gap-2 px-3 py-1.5","data-testid":"running-work-summary",children:[e.jsx(Je,{width:12,height:12,"aria-hidden":"true",className:"shrink-0 text-info"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-2xs text-info",title:T,children:T}),w!=null&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:["oldest ",In(Date.now()-w)]})]}):e.jsxs("ul",{id:d,className:"divide-y divide-accent/15",children:[t.map(v=>{const A=s.get(v.toolUseId),W=f.get(v.toolUseId),Q=W&&W.stoppable!==!1?W.id:void 0,ie=Q!=null&&(l==null?void 0:l.has(Q))===!0,K=Q!=null?c==null?void 0:c.get(Q):void 0,q=z(Q,"subagent",v.label);return e.jsxs("li",{className:"flex items-center",children:[e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>i(v.toolUseId),title:"Show this sub-agent in the transcript",className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors can-hover:hover:bg-accent/10 ${q?"pr-1":"pr-3"} ${ie?"opacity-50":""}`,children:[e.jsx(Xt,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:v.label}),v.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted",children:v.description}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${K?"text-danger":"text-accent/90"}`,title:K??(A==null?void 0:A.latestStep),children:K?"can't stop":ie?"stopping…":(A==null?void 0:A.latestStep)??"starting…"}),A!=null&&A.stepCount>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[A.stepCount," step",A.stepCount===1?"":"s"]})]}),e.jsx(zn,{taskId:Q,label:v.label,stopping:ie,failed:K,onStop:q})]},v.toolUseId)}),b.map(v=>{const A=Vn(v,r),W=Ba(v,r)?v.description.trim():"",Q=v.toolUseId,ie=Q?"button":"div",K=(l==null?void 0:l.has(v.id))===!0,q=c==null?void 0:c.get(v.id),k=v.stoppable!==!1?v.id:void 0,U=z(k,ht(v),Os(v));return e.jsxs("li",{className:"flex items-center",children:[e.jsxs(ie,{...Q?{type:"button",onClick:()=>i(Q),title:"Show this task in the transcript"}:{},"data-testid":"running-task-row","data-task-type":v.type,className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors ${U?"pr-1":"pr-3"} ${Q?"can-hover:hover:bg-accent/10":""} ${K?"opacity-50":""}`,children:[e.jsx(wo,{role:ht(v)}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:Os(v)}),W&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted","data-testid":"running-task-intent",children:W}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${q?"text-danger":"text-info"}`,"data-testid":"running-task-detail",title:q??A,children:q?"can't stop":K?"stopping…":A||"starting…"}),v.toolUses!=null&&v.toolUses>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[v.toolUses," step",v.toolUses===1?"":"s"]}),e.jsx("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle","data-testid":"running-task-elapsed",children:In(Date.now()-v.startedAt)})]}),e.jsx(zn,{taskId:k,label:Os(v),stopping:K,failed:q,onStop:U})]},v.id)})]})]}),e.jsx($r,{open:g!=null,onClose:()=>D(null),role:"alertdialog",size:"sm",title:(g==null?void 0:g.title)??"",description:g==null?void 0:g.body,footer:e.jsxs(e.Fragment,{children:[e.jsx(fs,{variant:"ghost",onClick:()=>D(null),children:"Keep running"}),e.jsx(fs,{variant:"danger","data-testid":"running-work-confirm-stop",onClick:()=>{const v=(g==null?void 0:g.taskIds)??[];D(null),v.forEach(A=>o==null?void 0:o(A))},children:(g==null?void 0:g.confirmLabel)??"Stop"})]})})]})}const ko=2e3,No=6,za=new Set;function Co(t){const s=t.toolCall;if(!s)return null;const n=vs.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,r=(s.description??s.inputSummary??"").trim();return r?`${n} ${r}`:n}function So(t){var r,i;if(t.length===0)return;const s=Date.parse(((r=t[0])==null?void 0:r.timestamp)??""),n=Date.parse(((i=t[t.length-1])==null?void 0:i.timestamp)??"");if(!(!Number.isFinite(s)||!Number.isFinite(n)||n<s))return n-s}function To(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function $o(t,s,n,r=za){const[i,o]=a.useState(new Map),l=a.useRef(new Set),c=a.useRef(new Map),m=a.useRef(s);m.current=s;const u=a.useRef(n);u.current=n;const b=t.map(h=>h.toolUseId).sort().join(","),f=[...r].sort().join(",");return a.useEffect(()=>{const h=f?f.split(","):[];if(h.length!==0){for(const j of h)l.current.add(j);o(j=>{let x=null;for(const N of h){const d=j.get(N);d&&!d.running||(x??(x=new Map(j)),x.set(N,{...d,stepCount:(d==null?void 0:d.stepCount)??0,running:!1}))}return x??j})}},[f]),a.useEffect(()=>{const h=b?b.split(","):[];if(h.length===0||!m.current)return;let j=!1,x;const N=async()=>{const d=m.current;if(!d)return;const g=h.filter($=>!l.current.has($));if(g.length===0)return;const D=await Promise.all(g.map($=>d($).then(I=>({id:$,messages:I})).catch(()=>null)));j||(o($=>{const I=new Map($);for(const C of D){if(!C||l.current.has(C.id))continue;const S=To(C.messages),M=c.current.get(C.id),y=M&&M.sig===S?M.ticks+1:0;c.current.set(C.id,{sig:S,ticks:y});const T=!u.current&&y>=No;T&&l.current.add(C.id);const w=C.messages.map(Co).filter(F=>!!F);I.set(C.id,{latestStep:w[w.length-1],stepCount:w.length,messages:C.messages,elapsedMs:So(C.messages),running:!T})}return I}),j||(x=setTimeout(N,ko)))};return N(),()=>{j=!0,x&&clearTimeout(x)}},[b]),i}function Io(t){const[s,n]=a.useState(za),r=a.useRef(new Set),i=t.map(o=>o.toolUseId).filter(o=>!!o).sort().join(",");return a.useEffect(()=>{const o=new Set(i?i.split(","):[]);for(const l of o)r.current.add(l);n(l=>{let c=null;for(const m of r.current)o.has(m)||l.has(m)||(c??(c=new Set(l)),c.add(m));return c??l})},[i]),s}function Eo(t){return a.useMemo(()=>{const s=[];for(const n of t){const r=n.kind==="tool"?n.tool:void 0;r!=null&&r.toolUseId&&vs.has(r.toolName)&&r.hasSubagent&&r.subagentDurationMs==null&&s.push({toolUseId:r.toolUseId,label:r.subagentType??r.toolName,description:r.description})}return s},[t])}function Ro(t){return a.useMemo(()=>{var n;const s=new Map;for(const r of t){const i=r.kind==="tool"?r.tool:void 0;if(!(i!=null&&i.toolUseId)||i.toolName!=="Bash"&&i.toolName!=="bash")continue;const o=(n=i.inputSummary)==null?void 0:n.trim();o&&s.set(i.toolUseId,o)}return s},[t])}function Mo({checked:t,available:s,onChange:n}){return e.jsxs("label",{className:`group mb-2 inline-flex w-fit items-center gap-2 rounded-lg px-1 py-0.5 text-xs ${s?"cursor-pointer text-fg-muted":"cursor-not-allowed text-fg-subtle"}`,title:s?"Inject this project's curated OVERVIEW.md (current state) and CHANGELOG.md (history) as context on the first message of this new chat, so the agent starts already knowing the project's state and narrative.":"No project overview yet — a sweep writes OVERVIEW.md after some activity. The agent will still see the project's files.",children:[e.jsx("input",{type:"checkbox",checked:t,disabled:!s,onChange:r=>n(r.target.checked),className:"h-3.5 w-3.5 rounded border-edge-strong accent-[var(--accent-solid)] focus:ring-accent/30 disabled:opacity-50"}),e.jsx("span",{className:"font-medium",children:"Preload project context"}),e.jsx("span",{className:"hidden text-fg-subtle transition-opacity sm:inline",children:s?"(injects OVERVIEW.md + CHANGELOG.md)":"(no overview yet)"})]})}function Ao({models:t,model:s,onSelectModel:n,usage:r,sessionUsage:i,forkParent:o,onOpenForkParent:l}){return e.jsxs("div",{className:"mb-2 flex items-center gap-3 px-1 text-2xs text-fg-subtle",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-fg-muted",children:"Model"}),e.jsxs("select",{value:s??"",onChange:c=>n(c.target.value),disabled:t.length===0,title:"Model for this chat (sent on every message; remembered per chat)",className:"rounded-md border border-edge-strong bg-surface-raised px-1.5 py-0.5 text-2xs text-fg-muted outline-none focus:border-accent focus:ring-1 focus:ring-accent/20 disabled:opacity-50",children:[s&&!t.some(c=>c.id===s)&&e.jsx("option",{value:s,children:s}),t.map(c=>e.jsx("option",{value:c.id,children:c.label},c.id))]})]}),e.jsx(Do,{usage:r}),e.jsx(Po,{usage:i}),o&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(ft,{width:11,height:11,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"shrink-0",children:"Fork of"}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(o.sessionId),title:`Open the chat this was forked from: ${o.name}`,className:"truncate font-medium text-accent underline-offset-2 hover:underline",children:o.name})]})]})}function Do({usage:t}){if(!t||t.contextLimit<=0)return e.jsx("span",{className:"text-fg-subtle",children:"context: —"});const s=Math.min(100,Math.max(0,t.contextTokens/t.contextLimit*100)),n=s>=80,r=Math.round(t.contextTokens/1e3),i=Math.round(t.contextLimit/1e3);return e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",title:`Context window used as of the last completed turn (${t.contextTokens.toLocaleString()} / ${t.contextLimit.toLocaleString()} tokens)`,children:[e.jsx("span",{className:"h-1 w-20 overflow-hidden rounded-full bg-surface-active",children:e.jsx("span",{className:`motion-base block h-full rounded-full transition-[width,background-color] ${n?"bg-warn-solid":"bg-accent-solid"}`,style:{width:`${s}%`}})}),e.jsxs("span",{className:n?"text-warn":void 0,children:[r,"k / ",i,"k (",Math.round(s),"%)"]})]})}function Po({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${ga(t.costUsd)}`:pa(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${ba(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const Hn=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function _o(){const[t,s]=a.useState(0);return a.useEffect(()=>{const n=setInterval(()=>s(r=>(r+1)%Hn.length),2600);return()=>clearInterval(n)},[]),e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-edge bg-surface-active px-3 py-1 text-xs text-fg-muted",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-accent-solid","aria-hidden":"true"}),e.jsxs("span",{children:[Hn[t],"…"]})]})})}function Lo({text:t,attachments:s=[],onEdit:n,onClear:r}){const i=t.split(`
|
|
7
|
+
`,1)[0],o=t.length-i.length;return e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-accent-edge bg-accent-soft px-3 py-1.5 text-xs",children:[e.jsx(Je,{width:13,height:13,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 font-semibold uppercase tracking-wide text-accent",children:"queued"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-muted",title:t||s.map(l=>l.filename).join(", "),children:i||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),i&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(l=>l.filename).join(", "),children:["📎 ",s.length]}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:n,title:"Edit this message (cancels the pending auto-send)",className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active",children:[e.jsx(bs,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:r,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-fg-muted hover:bg-surface-active hover:text-danger",children:e.jsx(Oe,{width:12,height:12})})]})]})})}function Fo({state:t}){const s={open:{c:"bg-success-solid",t:"connected"},connecting:{c:"bg-warn-solid animate-pulse",t:"connecting"},closed:{c:"bg-danger-solid",t:"offline"}}[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${s.c}`}),s.t]})}const Oo=a.lazy(()=>ce(()=>import("./MarkdownRenderer-5uaTbABu.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Zt=a.memo(function({children:s,mermaid:n=!1}){return e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(Oo,{mermaid:n,children:s})})}),Uo=new Set(["markdown","code","text","html","mermaid"]);function us(t){return Uo.has(t)}function Ha(t){const s=t.source==="file"&&us(t.kind)?t.rawUrl:void 0,[n,r]=a.useState(null);return a.useEffect(()=>{if(t.source!=="file"||!us(t.kind))return;if(!s){r({error:!0});return}let i=!1;return r(null),fetch(s).then(o=>o.ok?o.text():Promise.reject(new Error(String(o.status)))).then(o=>!i&&r({text:o})).catch(()=>!i&&r({error:!0})),()=>{i=!0}},[s,t.source,t.kind]),us(t.kind)?t.source==="inline"?{text:t.content??""}:n:null}const Bo={markdown:"text/markdown",html:"text/html"},hs="flex items-center px-2.5 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg focus-visible:focus-ring disabled:pointer-events-none disabled:opacity-40";function Vo({file:t,text:s}){return e.jsxs(e.Fragment,{children:[us(t.kind)?e.jsx(zo,{filename:t.filename,text:s}):null,t.kind==="image"||t.kind==="pdf"?null:e.jsx(Ho,{file:t,failed:s!==null&&"error"in s})]})}function zo({filename:t,text:s}){const[n,r]=a.useState("idle");a.useEffect(()=>{if(n==="idle")return;const c=setTimeout(()=>r("idle"),1600);return()=>clearTimeout(c)},[n]);const i=s!==null&&"text"in s,o=()=>{if(!i)return;const c=navigator.clipboard;if(!c){r("failed");return}c.writeText(s.text).then(()=>r("copied"),()=>r("failed"))},l=n==="copied"?"Copied":n==="failed"?"Couldn't copy":s===null?"Loading…":"error"in s?"Couldn't load this file":"Copy source";return e.jsxs("button",{type:"button",onClick:o,disabled:!i,"aria-label":`Copy ${t}`,title:l,className:hs,children:[n==="copied"?e.jsx(It,{width:13,height:13,className:"text-success"}):n==="failed"?e.jsx(ge,{width:13,height:13,className:"text-danger"}):e.jsx(Ir,{width:13,height:13}),e.jsx("span",{className:"sr-only",role:"status",children:n==="copied"?"Copied":n==="failed"?"Couldn't copy":""})]})}function Ho({file:t,failed:s}){const n=`Download ${t.filename}`;if(t.source==="file")return t.rawUrl?s?e.jsx("button",{type:"button",disabled:!0,"aria-label":n,title:"Couldn't load this file",className:hs,children:e.jsx(Ps,{width:13,height:13})}):e.jsx("a",{href:t.rawUrl,download:t.filename,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})}):null;const r=()=>{const i=`${Bo[t.kind]??"text/plain"};charset=utf-8`,o=URL.createObjectURL(new Blob([t.content??""],{type:i})),l=document.createElement("a");l.href=o,l.download=t.filename,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3)};return e.jsx("button",{type:"button",onClick:r,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})})}const Wo={tsx:"typescript",jsx:"javascript",html:"xml"};function Ko(t){if(!t)return;const s=t.toLowerCase();return Wo[s]??s}let Us=null;async function Go(){return Us||(Us=(async()=>{const{default:t}=await ce(async()=>{const{default:S}=await import("./core-afW9-UwG.js");return{default:S}},__vite__mapDeps([9,1,2])),[s,n,r,i,o,l,c,m,u,b,f,h,j,x,N,d,g,D,$,I,C]=await Promise.all([ce(()=>import("./typescript-C2FFdlUC.js"),[]),ce(()=>import("./javascript-BKRaQes9.js"),[]),ce(()=>import("./python-kSlZHhJb.js"),[]),ce(()=>import("./ruby-7T4ktxyv.js"),[]),ce(()=>import("./go-BPx_y7j8.js"),[]),ce(()=>import("./rust-HC3MBUhY.js"),[]),ce(()=>import("./java-B5VKqtH2.js"),[]),ce(()=>import("./c-D2F1sQUL.js"),[]),ce(()=>import("./cpp-Bm3ii6kY.js"),[]),ce(()=>import("./csharp-BNpuYZMG.js"),[]),ce(()=>import("./php-CRdd4dfS.js"),[]),ce(()=>import("./swift-Dn8kKO_1.js"),[]),ce(()=>import("./kotlin-Cw-eF_bm.js"),[]),ce(()=>import("./bash-I8pq0VWm.js"),[]),ce(()=>import("./sql-BC88IN-V.js"),[]),ce(()=>import("./json-DIYVocXf.js"),[]),ce(()=>import("./yaml-drsDnIKT.js"),[]),ce(()=>import("./ini-B3BVgEsG.js"),[]),ce(()=>import("./css-DazXZka4.js"),[]),ce(()=>import("./scss-DZLA7YXz.js"),[]),ce(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",i.default),t.registerLanguage("go",o.default),t.registerLanguage("rust",l.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",u.default),t.registerLanguage("csharp",b.default),t.registerLanguage("php",f.default),t.registerLanguage("swift",h.default),t.registerLanguage("kotlin",j.default),t.registerLanguage("bash",x.default),t.registerLanguage("sql",N.default),t.registerLanguage("json",d.default),t.registerLanguage("yaml",g.default),t.registerLanguage("toml",D.default),t.registerLanguage("css",$.default),t.registerLanguage("scss",I.default),t.registerLanguage("xml",C.default),t})()),Us}function qo({code:t,language:s}){const[n,r]=a.useState(null),i=Ko(s);a.useEffect(()=>{if(!i){r(null);return}let l=!1;return r(null),(async()=>{try{const c=await Go();if(l||!c.getLanguage(i))return;const{value:m}=c.highlight(t,{language:i});l||r(m)}catch{}})(),()=>{l=!0}},[t,i]);const o="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg";return n!==null?e.jsx("pre",{className:o,children:e.jsx("code",{className:`hljs language-${i}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:o,children:e.jsx("code",{children:t})})}let Bs=null;function Qo(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function Yo(){return Bs||(Bs=ce(()=>import("./mermaid.core-AX6KCjdW.js").then(t=>t.bm),__vite__mapDeps([10,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:Qo()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),Bs}function Xo({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[i,o]=a.useState(null);return a.useEffect(()=>{let l=!1;return o(null),(async()=>{try{const c=await Yo();await c.parse(t);const{svg:m,bindFunctions:u}=await c.render(n+"-svg",t);if(l||!r.current)return;r.current.innerHTML=m,u==null||u(r.current)}catch(c){if(l)return;o(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{l=!0}},[t,n]),i?e.jsxs("div",{className:"my-3 rounded-lg border border-warn-edge bg-warn-soft p-3 text-xs",children:[e.jsx("p",{className:"font-semibold text-warn",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-warn",children:i}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-surface-sunken p-2 font-mono text-2xs text-fg-muted",children:t})]}):e.jsx("div",{ref:r,"data-testid":"mermaid",className:"mermaid-host my-3 flex justify-center overflow-x-auto rounded-lg border border-edge bg-surface-raised p-3"})}const Jo="paddock:itemHeight:";function dn(t){return Jo+t}function Wn(t){try{const s=localStorage.getItem(dn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function Zo(t,s){try{const n=dn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function el(t){try{localStorage.removeItem(dn(t))}catch{}}function tl({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const i=a.useRef(null),[o,l]=a.useState(0),[c,m]=a.useState(()=>Wn(t));a.useEffect(()=>{m(Wn(t))},[t]),a.useEffect(()=>{if(!i.current)return;const j=()=>{var N;return l(((N=i.current)==null?void 0:N.scrollHeight)||0)};if(j(),typeof ResizeObserver>"u")return;const x=new ResizeObserver(j);return x.observe(i.current),()=>x.disconnect()},[s]);const u=o>0,b=u?o:Number.POSITIVE_INFINITY;let f=!1,h=0;return c!=null?(f=!0,h=Wa(c,r,b)):u&&o>n&&(f=!0,h=n),e.jsxs("div",{className:f?"group relative":void 0,style:f?{height:h}:void 0,children:[e.jsx("div",{className:f?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:i,children:s})}),f?e.jsx(sl,{appliedHeight:h,onResize:j=>m(j),onCommit:j=>Zo(t,j),onReset:()=>{el(t),m(null)},minHeight:r,maxHeight:b}):null]})}function sl({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:i,maxHeight:o}){const l=a.useRef(null),c=a.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:u=>{l.current={startY:u.clientY,startHeight:t},u.currentTarget.setPointerCapture(u.pointerId)},onPointerMove:u=>{if(!l.current)return;const b=Kn(l.current.startHeight,u.clientY-l.current.startY,i,o);s(b)},onPointerUp:u=>{if(l.current){l.current=null;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const b=u.key==="ArrowDown"?m:-m,f=Kn(t,b,i,o);s(f),n(f)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-edge-subtle bg-surface-sunken opacity-60 transition hover:bg-surface-hover hover:opacity-100",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-edge-strong group-hover:bg-fg-subtle"})})}function Kn(t,s,n,r){return Wa(t+s,n,r)}function Wa(t,s,n){return Math.min(Math.max(t,s),n)}function Ka({src:t,filename:s,message:n,onMaximize:r}){const[i,o]=a.useState(!1),[l,c]=a.useState(!1),m=r??(()=>c(!0)),u="repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||i?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsxs("div",{className:"group relative flex items-center justify-center overflow-auto p-4",style:{background:u},children:[e.jsx("img",{src:t,alt:s,onError:()=>o(!0),onClick:m,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m())},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(Ga,{src:t,filename:s,onMaximize:m}),l?e.jsx(nl,{src:t,filename:s,message:n,onClose:()=>c(!1)}):null]})}function Ga({src:t,filename:s,onMaximize:n}){const r="pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/55 text-white shadow-sm transition-colors hover:bg-black/75 focus-visible:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{className:"pointer-events-none absolute bottom-2 right-2 z-10 flex items-center gap-1.5 opacity-100 transition-opacity can-hover:opacity-0 can-hover:group-hover:opacity-100 can-hover:group-focus-within:opacity-100",children:[e.jsx("a",{href:t,download:s,className:r,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(al,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:r,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx(rl,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(il,{})}):null]})}function nl({src:t,filename:s,message:n,onClose:r}){const i=a.useRef(null);return a.useEffect(()=>{var c;const o=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",o);const l=document.body.style.overflow;return document.body.style.overflow="hidden",(c=i.current)==null||c.focus(),()=>{document.removeEventListener("keydown",o),document.body.style.overflow=l}},[r]),ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:r,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-4 bg-overlay-strong p-6",children:[e.jsx("button",{ref:i,type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",children:e.jsx(ol,{})}),e.jsx("img",{src:t,alt:s,onClick:o=>o.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:o=>o.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),n?e.jsx("div",{className:"mt-1",children:n}):null]})]}),document.body)}function ys({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 al(){return e.jsxs(ys,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function rl(){return e.jsxs(ys,{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 il(){return e.jsx(ys,{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 ol(){return e.jsx(ys,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function un({src:t,filename:s,className:n="h-[600px] w-full"}){return t?e.jsxs("div",{className:`group relative ${n}`,children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-full w-full bg-surface-sunken",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-fg-muted",children:[e.jsx(Qt,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-fg",children:s}),e.jsx("span",{className:"text-xs text-fg-muted",children:"This browser can’t show the PDF inline."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:"rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-surface motion-fast transition-colors hover:bg-fg-muted",children:"Open in new tab"}),e.jsx("a",{href:t,download:s,className:"rounded-md px-3 py-1.5 text-xs font-medium text-fg-muted ring-1 ring-edge-strong hover:bg-surface-hover",children:"Download"})]})]})}),e.jsx(Ga,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function ll({file:t,turnId:s}){const[n,r]=a.useState(!0),i=a.useContext(Ua),o=i&&s?()=>i.open(s,t):void 0,l=ps(t),c=Ha(t);return e.jsx("div",{className:"flex animate-fade-in justify-start","data-sent-file-turn":s,children:e.jsxs("div",{className:"w-full max-w-[92%] overflow-hidden rounded-2xl rounded-bl-md bg-surface-raised shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"flex items-stretch border-b border-edge bg-surface-sunken text-2xs text-fg-muted",children:[e.jsxs("button",{type:"button",onClick:()=>r(m=>!m),"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 px-4 py-2 text-left",children:[e.jsx(hl,{open:n}),e.jsx(ml,{}),e.jsx("span",{className:"truncate font-mono text-fg-muted",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-3xs text-fg-subtle",children:t.language??t.kind})]}),e.jsx(Vo,{file:t,text:c}),o?e.jsx("button",{type:"button",onClick:o,"aria-label":`Maximize ${t.filename}`,title:"Maximize",className:"flex items-center px-3 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg",children:e.jsx(fl,{})}):null]}),t.message?e.jsx("div",{className:"border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted",children:t.message}):null,n?e.jsx(qa,{file:t,itemId:l,onMaximize:o,text:c}):null]})})}function ps(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${cl(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function cl(t){let s=5381;for(let n=0;n<t.length;n++)s=(s<<5)+s+t.charCodeAt(n)|0;return(s>>>0).toString(36)}function qa({file:t,itemId:s,onMaximize:n,fill:r=!1,text:i}){return t.kind==="image"?e.jsx(Ka,{src:t.rawUrl,filename:t.filename,message:t.message,onMaximize:n}):t.kind==="video"?e.jsx(ul,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(un,{src:t.rawUrl,filename:t.filename,className:r?"h-full w-full":void 0}):t.source==="inline"?e.jsx(Qa,{kind:t.kind,text:t.content??"",language:t.language,itemId:s,fill:r}):i!==void 0?e.jsx(Ya,{state:i,kind:t.kind,language:t.language,itemId:s,fill:r}):e.jsx(dl,{file:t,itemId:s,fill:r})}function Qa({kind:t,text:s,language:n,itemId:r,fill:i=!1}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:`html-preview w-full ${i?"h-full":"min-h-[360px]"}`}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(Xo,{code:s})}):t==="markdown"?e.jsx(Vs,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Zt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(Vs,{itemId:r,children:e.jsx(qo,{code:s,language:n})}):e.jsx(Vs,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg",children:s})})}function Vs({itemId:t,children:s}){return t?e.jsx(tl,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function dl({file:t,itemId:s,fill:n}){const r=Ha(t);return e.jsx(Ya,{state:r,kind:t.kind,language:t.language,itemId:s,fill:n})}function Ya({state:t,kind:s,language:n,itemId:r,fill:i}){return t===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in t?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Qa,{kind:s,text:t.text,language:n,itemId:r,fill:i})}function ul({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-surface-sunken p-4",children:e.jsx("video",{src:t,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[480px] w-full rounded-sm shadow-sm",children:e.jsxs("p",{className:"p-4 text-sm text-fg-muted",children:["Your browser can’t play this video."," ",e.jsxs("a",{href:t,download:s,className:"underline",children:["Download ",s]})]})})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function hl({open:t}){return e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-subtle transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function ml(){return e.jsxs("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("path",{d:"M14 2v6h6"})]})}function fl(){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",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"})})}const hn=a.memo(function({turn:s}){return s.kind==="user"?e.jsxs("div",{className:"flex animate-fade-in flex-col items-end",children:[s.sender?e.jsx(wl,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(Bi,{attachments:s.attachments}):null,s.content?e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-accent-solid px-4 py-2.5 text-sm text-accent-fg shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(ll,{file:s.file,turnId:s.id}):s.kind==="tool"?e.jsx(kl,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-surface-active px-2.5 py-0.5 font-mono text-xs text-fg-muted ring-1 ring-edge",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(bl,{content:s.content}):null:s.kind==="compact"?e.jsx(jl,{summary:s.summary}):s.kind==="notice"?e.jsx(yl,{notice:s.notice}):s.kind==="notification"?Er(s.status)?e.jsx(vl,{summary:s.summary}):e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"max-w-[85%] truncate rounded-full bg-surface-sunken px-2.5 py-0.5 text-xs italic text-fg-muted ring-1 ring-edge",title:s.summary,children:s.summary})}):e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsx("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-raised px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(Zt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"})]})})})}),xl=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function gl({turn:t}){const s=a.useContext(Oa);return!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&xl.test(t.id)?e.jsx(pl,{turn:t,actions:s}):e.jsx(hn,{turn:t})}function pl({turn:t,actions:s}){var g;const n=t.id.split("#")[0],r=t.id===n,i=s.linkTo(n),o=a.useRef(null),[l,c]=a.useState(!1),[m,u]=a.useState(!1),b=r&&((g=s.focused)==null?void 0:g.uuid)===n?s.focused.nonce:null;a.useEffect(()=>{var $;if(b==null)return;($=o.current)==null||$.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const D=setTimeout(()=>u(!1),3200);return()=>clearTimeout(D)},[b]),a.useEffect(()=>{if(!l)return;const D=setTimeout(()=>c(!1),1600);return()=>clearTimeout(D)},[l]);const f=D=>{var $;D.metaKey||D.ctrlKey||D.shiftKey||D.altKey||D.button!==0||(D.preventDefault(),($=navigator.clipboard)==null||$.writeText(i).then(()=>c(!0)).catch(()=>c(!1)))},h=t.contextTokens,j=s.contextLimit,x=h!=null&&j?Math.min(100,Math.round(h/j*100)):null,N="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",d=`${N} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{ref:o,id:r?wa(n):void 0,className:`group relative rounded-lg ${m?"reveal-flash":""}`,children:[e.jsxs("div",{className:"pointer-events-none absolute -top-3 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",children:[e.jsx("a",{href:i,onClick:f,title:`Copy a link to this message · ${new Date(t.timestamp).toLocaleString()}`,"aria-label":`Copy a link to this message (${Et(t.timestamp)})`,className:`${N} gap-1 px-2 py-0.5 text-2xs text-fg-muted transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:l?e.jsx("span",{className:"text-accent",children:"Link copied"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:Et(t.timestamp)}),h!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",pa(h),x!=null?` · ${x}%`:""]}):null]})}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${d} hover:text-accent`,children:e.jsx(ft,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${d} hover:text-danger`,children:e.jsx(Je,{width:13,height:13})})]}),e.jsx(hn,{turn:t})]})}function Me({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function bl({content:t}){return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-sunken px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-2xs italic text-fg-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(Zt,{children:t})]})})}function jl({summary:t}){return e.jsx("div",{className:"animate-fade-in py-1",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 text-xs text-fg-muted",children:[e.jsx("span",{className:"h-px flex-1 bg-edge"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-edge"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:t})]})})}function wl({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-2xs italic text-fg-muted";if(t.kind==="schedule")return e.jsxs("div",{className:s,"data-sender":"schedule",children:[e.jsx("span",{"aria-hidden":!0,children:"⏰"}),e.jsxs("span",{children:["scheduled by ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="hook")return e.jsxs("div",{className:s,"data-sender":"hook",children:[e.jsx("span",{"aria-hidden":!0,children:"⚡"}),e.jsxs("span",{children:["triggered by hook ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="recovery")return e.jsxs("div",{className:s,"data-sender":"recovery",children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:"continued after a background task was terminated"})]});if(t.kind==="agent")return e.jsxs("div",{className:s,"data-sender":"agent",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsx("span",{children:"sent by an agent"})]});const n=((r=t.name)==null?void 0:r.trim())||t.sessionId.slice(0,8);return e.jsxs("div",{className:s,"data-sender":"chat",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsxs("span",{children:["sent by"," ",e.jsx(rn,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${n} in ${t.project}`,children:n})]})]})}function vl({summary:t}){const s=a.useContext(cn),n=!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy);return e.jsx("div",{className:"flex animate-fade-in justify-center","data-recovery":"killed-task",children:e.jsxs("div",{className:"flex max-w-[90%] flex-col gap-1.5 rounded-lg border border-warn-edge bg-warn-soft px-3 py-2 text-xs text-warn",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:"⚠"}),e.jsxs("span",{className:"leading-snug",children:["A background task was terminated at the turn boundary — Claude is idle and will not continue on its own.",e.jsx("span",{className:"mt-0.5 block text-2xs text-warn",children:t})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-recovery-action":"continue",className:"motion-fast rounded-md bg-warn-solid px-2.5 py-1 text-2xs font-medium text-warn-fg shadow-sm transition-[filter,box-shadow,opacity] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50",children:r?"Continuing…":"Continue"})})]})})}function yl({notice:t}){const s=a.useContext(cn),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),i=t.kind==="error",o=i?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",l=i?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=i?"text-danger":"text-warn",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${o}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:i?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-2xs ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),i&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-2xs ${c}`,children:t.detail})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-notice-action":"retry",className:`motion-fast rounded-md px-2.5 py-1 text-2xs font-medium shadow-sm transition-[filter,box-shadow,opacity] disabled:cursor-not-allowed disabled:opacity-50 ${l}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function kl({tool:t}){var k,U;const s=Qi(t.toolName),n=Yi(t.toolName,t.output),r=s.isPaddock?oo(s.tool):null,i=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[o,l]=a.useState(i),c=a.useContext(Fa),m=a.useContext(La),u=a.useRef(null),[b,f]=a.useState(!1),h=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;a.useEffect(()=>{var E;if(h==null)return;l(!0),(E=u.current)==null||E.scrollIntoView({behavior:"smooth",block:"center"}),f(!0);const Z=setTimeout(()=>f(!1),3200);return()=>clearTimeout(Z)},[h]);const j=a.useContext(_a),x=a.useContext(ln),N=!!t.pending,d=vs.has(t.toolName),g=t.toolUseId?x==null?void 0:x.get(t.toolUseId):void 0,D=d?xs(t.subagentDurationMs??(g==null?void 0:g.elapsedMs)):xs(t.durationMs),$=t.subagentCostUsd!=null?`~${ga(t.subagentCostUsd)}`:null,I=!d&&ro(t),C=t.monitorEvents??[],S=t.editDiff,M=!!S,y=t.toolName==="Read"?t.readInfo:void 0,T=y!=null&&y.isImage&&y.projectRelPath&&c?c(y.projectRelPath):null,w=t.toolName==="Bash"?t.bashDetails:void 0,F=t.searchInfo,O=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,z=t.toolName==="TaskCreate"?t.taskCreate:void 0,J=!!(w&&w.stderr),L=F?uo(F):null,v=y?ho(y):null,A=g!=null?g.running:to(t,j),W=!!(d&&t.hasSubagent&&t.toolUseId),Q=A&&t.toolUseId?(k=x==null?void 0:x.get(t.toolUseId))==null?void 0:k.latestStep:void 0,ie=d?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,K=d?Q??t.description:n?Xi(n):M?((U=S.filePath)==null?void 0:U.split("/").pop())??S.filePath:y?y.basename??y.filePath??t.inputSummary:z?z.subject:t.inputSummary,q=(y==null?void 0:y.filePath)??(z==null?void 0:z.description)??(Q?t.description:void 0)??K??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:u,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${b?"reveal-flash ":""}${t.isError?"border-danger-edge bg-danger-soft":d?"border-accent-edge bg-accent-soft":I?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>l(Z=>!Z),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(At,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${o?"rotate-90":""}`}),d?e.jsx(Xt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):I?e.jsx(Je,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-info"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):M?e.jsx(bs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):y?e.jsx(Qt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):F?e.jsx(va,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):O||z?e.jsx(It,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(ya,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-fg",children:ie}),d&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),I&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-info-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-info",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:n&&"project"in n&&n.project?n.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-fg-muted",children:"MCP"}),O?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[O.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",O.taskId]}),O.from&&O.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Gn,{status:O.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(Gn,{status:O.to})]}):O.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:O.updatedFields.join(", ")})]}):K&&e.jsx("span",{className:`min-w-0 truncate font-mono ${Q?"text-accent":"text-fg-muted"}`,title:q,children:K}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-danger-soft px-1.5 py-0.5 text-3xs font-semibold text-danger",children:"error"}),N||A?e.jsxs("span",{className:"flex items-center gap-1.5 text-accent",title:"Sub-agent is running",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-accent-edge border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-3xs font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[I&&C.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[C.length," event",C.length===1?"":"s"]}),I&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${io(t.taskStatus)}`,children:t.taskStatus}),M&&(S.additions>0||S.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[S.additions>0&&e.jsxs("span",{className:"text-success",children:["+",S.additions]}),S.additions>0&&S.deletions>0&&" ",S.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",S.deletions]})]}),v&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:v}),L&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:L}),(w==null?void 0:w.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 font-mono text-3xs text-fg-muted",children:w.gitHint}),(w==null?void 0:w.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-warn-soft px-1.5 py-0.5 text-3xs font-semibold text-warn",children:"interrupted"}),(w==null?void 0:w.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:w.returnCodeInterpretation}),D&&e.jsx("span",{className:"text-fg-subtle tabular",children:D}),$&&e.jsx("span",{className:"text-fg-subtle tabular",children:$})]})]})]}),o&&(W?e.jsx(Tl,{toolUseId:t.toolUseId,live:A}):I&&C.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:C.map((Z,E)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-info-edge px-3 py-1.5 font-mono text-2xs leading-relaxed text-fg-muted last:border-b-0",children:Z},E))}):n?e.jsx(eo,{data:n}):M?e.jsx(Nl,{diff:S}):T?e.jsx("div",{className:"border-t border-edge",children:e.jsx(Ka,{src:T,filename:(y==null?void 0:y.basename)??"image"})}):J?e.jsx(Cl,{bash:w}):z&&z.description?e.jsx(Sl,{info:z}):e.jsxs("div",{className:"border-t border-edge",children:[I&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-edge bg-info-soft px-3 py-2 text-2xs font-medium text-fg",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:N?"Running…":t.output||"(no output)"})]}))]})})}function Nl({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-edge bg-surface-sunken font-mono text-2xs leading-relaxed",children:[t.hunks.map((s,n)=>e.jsxs("div",{className:n>0?"border-t border-edge":"",children:[e.jsxs("div",{className:"bg-surface-active px-3 py-1 font-mono text-3xs font-semibold text-lineage",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,i)=>e.jsxs("div",{className:`flex ${lo(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:r.t===" "?"":r.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:r.text||" "})]},i))]},n)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-2xs italic text-fg-subtle",children:"… diff truncated (see the file for the full change)"})]})}function Gn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${co(t)}`,children:t})}function Cl({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-edge",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-danger-edge bg-danger-soft px-3 py-2 font-mono text-2xs leading-relaxed text-danger first:border-t-0",children:t.stderr})]})}function Sl({info:t}){return e.jsxs("div",{className:"border-t border-edge bg-surface-sunken px-3 py-2",children:[t.subject&&e.jsx("div",{className:"text-xs font-semibold text-fg",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:t.description})]})}const qn=2e3;function Tl({toolUseId:t,live:s=!1}){var b,f;const n=a.useContext(Pa),[r,i]=a.useState(null),[o,l]=a.useState(!1),c=(f=(b=a.useContext(ln))==null?void 0:b.get(t))==null?void 0:f.messages;a.useEffect(()=>{i(null),l(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){l(!0);return}let h=!1,j;const x=()=>{n(t).then(N=>{h||(i(N),s&&(j=setTimeout(x,qn)))}).catch(()=>{h||(s?j=setTimeout(x,qn):l(!0))})};return x(),()=>{h=!0,j&&clearTimeout(j)}},[n,t,s,!!c]);const m=c??r,u=a.useMemo(()=>Tt(m??[]),[m]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:o?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):u.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"waiting for sub-agent steps…"})]}):e.jsx("span",{children:"(no recorded steps)"})}):e.jsxs("div",{className:"space-y-3 border-l-2 border-accent-edge pl-3",children:[u.map(h=>e.jsx(hn,{turn:h},h.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function $l(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:i,onSessionStarted:o,onTurnComplete:l,sessionRef:c,jobRef:m,pendingCancelRef:u,streamingRef:b,awaitingSessionRef:f,isNewSessionRef:h,startedNotifiedRef:j,establishedHereRef:x,modelRef:N,cancelledRef:d,noticeThisTurnRef:g,seenInjectionsRef:D,onQueuedFlushedRef:$,onQueuedStateRef:I,onQueuedReturnedRef:C,setTurns:S,setStreaming:M,setUsage:y,setSessionUsage:T,setError:w}=t;a.useEffect(()=>{const F=L=>{const v=c.current;return v?L.sessionId===v?!0:L.sessionId==null&&b.current:f.current},O=L=>{c.current=L,f.current=!1,J.setSessionId(L),h.current&&!j.current&&(j.current=!0,x.current=L,N.current&&Xs(L,s,N.current),o==null||o(L))},z=L=>{m.current=L,u.current&&(u.current=!1,be.cancel(L))},J=be.subscribe(s,c.current,{onResponse:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),fo(S,L))},onToolStart:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),S(A=>L.toolUseId&&A.some(W=>W.kind==="tool"&&W.tool.toolUseId===L.toolUseId)?A:[...Fe(A),{kind:"tool",id:Xe(),tool:L}]))},onToolCall:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=Da(L);S(W=>{if(L.toolUseId){const ie=W.findIndex(K=>K.kind==="tool"&&K.tool.toolUseId===L.toolUseId);if(ie!==-1){const K=W[ie].id,q=W.slice();return q[ie]=A?{kind:"file",id:K,file:A}:{kind:"tool",id:K,tool:L},q}}const Q=A?{kind:"file",id:Xe(),file:A}:{kind:"tool",id:Xe(),tool:L};return[...Fe(W),Q]})},onMessageBoundary:L=>{F(L)&&(L.jobId&&z(L.jobId),S(v=>Fe(v)))},onComplete:L=>{if(F(L)){L.jobId&&z(L.jobId),b.current=!1,M(!1),S(v=>On(Fe(v))),L.usage&&y(L.usage);{const v=L.sessionId??c.current;v&&B.chatContext(s,v).then(A=>T(A)).catch(()=>{})}if(L.sessionId){const v=h.current&&c.current!==L.sessionId;O(L.sessionId),(v||h.current)&&(h.current=!1,N.current&&Xs(L.sessionId,s,N.current),x.current=L.sessionId,i==null||i(L.sessionId))}!L.success&&L.error&&!g.current&&w(L.error);{const v=L.sessionId??c.current;l==null||l(v&&L.usage?{sessionId:v,usage:L.usage}:void 0)}d.current=!1}},onError:L=>{b.current&&(b.current=!1,M(!1),m.current=null,S(v=>On(Fe(v))),w(L),d.current=!1)},onResync:()=>{const L=c.current;!L||!r||r(L).then(({messages:v})=>S(Tt(v))).catch(()=>{})},onActive:({turnRunning:L,jobId:v})=>{L?(v&&z(v),b.current=!0,M(!0)):(b.current=!1,M(!1),m.current=null,S(A=>Fe(A)),d.current=!1,u.current=!1)},onQueuedFlushed:({text:L,attachments:v})=>{$.current(L,v)},onQueuedState:({text:L,qid:v,reason:A,attachments:W})=>{I.current(L,v,A,W)},onQueuedReturned:({text:L,attachments:v})=>{C.current(L,v)},onInjected:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=`${L.timestamp} ${L.content}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"user",id:Xe(),content:L.content,sender:L.sender}]))},onKilledTask:({summary:L,timestamp:v})=>{const A=`killed ${v}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"notification",id:Xe(),summary:L,status:"killed"}]))},onNotice:(L,v)=>{F(v)&&(g.current=!0,S(A=>[...Fe(A),{kind:"notice",id:Xe(),notice:L}]))}});return()=>{J.unsubscribe()}},[s,n,r,i,o,l])}function Il({turns:t,omitted:s,loadEarlier:n,reveal:r}){const i=a.useMemo(()=>t.flatMap(S=>S.kind==="file"?[{id:S.id,file:S.file}]:[]),[t]),o=a.useRef(i);o.current=i;const[l,c]=a.useState(null),[m,u]=a.useState("idle"),[b,f]=a.useState(!1),[h,j]=a.useState(null),x=a.useMemo(()=>{if(!l||l.single)return-1;const S=i.findIndex(y=>y.id===l.id);if(S!==-1)return S;const M=ps(l.file);return i.findIndex(y=>ps(y.file)===M)},[i,l]);a.useEffect(()=>{l&&!l.single&&x===-1&&c(null)},[l,x]);const N=a.useCallback(S=>{const M=o.current[S];M&&(c({id:M.id,file:M.file,single:!1}),u("idle"),j(y=>({id:M.id,nonce:((y==null?void 0:y.nonce)??0)+1})))},[]);a.useEffect(()=>{h&&r(h.id)},[h,r]);const d=s>0&&!!n,g=a.useCallback(()=>{if(!(!l||l.single)){if(x>0)return N(x-1);x!==0||!d||m==="loading"||(u("loading"),n().then(()=>f(!0)).catch(()=>u("error")))}},[l,x,N,d,m,n]);a.useEffect(()=>{b&&(f(!1),x>0?N(x-1):u("none"))},[b,x,N]);const D=a.useCallback(()=>{l&&!l.single&&x<i.length-1&&N(x+1)},[l,x,i.length,N]),$=a.useCallback(()=>{c(null),u("idle")},[]),I=a.useMemo(()=>({open:(S,M)=>{const y=!o.current.some(T=>T.id===S);c({id:S,file:M,single:y}),u("idle")}}),[]),C=l?{file:x===-1?l.file:i[x].file,position:x===-1?null:{index:x,total:i.length},canPrev:x>0||x===0&&d,canNext:x!==-1&&x<i.length-1,earlier:x===0?d&&m==="idle"?"withheld":m:"idle",onPrev:g,onNext:D,onClose:$}:null;return{context:I,viewer:C}}const El={idle:null,withheld:"Earlier messages aren’t loaded — ← loads them",loading:"Loading earlier messages…",none:"No earlier files in this chat",error:"Couldn’t load earlier messages — ← to retry"};function Rl({file:t,position:s,canPrev:n,canNext:r,earlier:i,onPrev:o,onNext:l,onClose:c}){const m=a.useRef(null),u=a.useRef({onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r});u.current={onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r},a.useEffect(()=>{var N;const h=d=>{const g=u.current;if(d.key==="Escape")return g.onClose();d.key!=="ArrowLeft"&&d.key!=="ArrowRight"||d.altKey||d.ctrlKey||d.metaKey||d.shiftKey||Al(d.target)||(d.preventDefault(),d.key==="ArrowLeft"&&g.canPrev&&g.onPrev(),d.key==="ArrowRight"&&g.canNext&&g.onNext())};document.addEventListener("keydown",h);const j=document.body.style.overflow;document.body.style.overflow="hidden";const x=document.activeElement;return(N=m.current)==null||N.focus(),()=>{var d;document.removeEventListener("keydown",h),document.body.style.overflow=j,(d=x==null?void 0:x.focus)==null||d.call(x,{preventScroll:!0})}},[]);const b=El[i],f=h=>h.stopPropagation();return ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t.filename,onClick:c,className:"fixed inset-0 z-50 flex flex-col gap-3 bg-overlay-strong p-3 backdrop-blur-sm sm:p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-white/90",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-white/80",onClick:f,children:t.filename}),s?e.jsxs("span",{className:"shrink-0 tabular-nums text-xs text-white/60","aria-live":"polite",children:[s.index+1," / ",s.total]}):null,b?e.jsx("span",{className:"min-w-0 truncate text-xs text-white/60",role:"status",children:b}):null,e.jsx("button",{ref:m,type:"button",onClick:c,"aria-label":"Close",title:"Close (Esc)",className:`${Xa} ml-auto h-9 w-9 shrink-0`,children:e.jsx(Ja,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 items-center gap-2 sm:gap-3",children:[s?e.jsx(Qn,{side:"left",disabled:!n,onClick:o}):null,e.jsx("div",{className:"flex h-full min-w-0 flex-1 items-center justify-center",children:e.jsx(Ml,{file:t},ps(t))}),s?e.jsx(Qn,{side:"right",disabled:!r,onClick:l}):null]}),t.message?e.jsx("div",{onClick:f,className:"mx-auto max-w-3xl text-center text-sm text-white/90",children:t.message}):null]}),document.body)}function Ml({file:t}){const s=r=>r.stopPropagation();if(t.kind==="image"&&t.rawUrl)return e.jsx("img",{src:t.rawUrl,alt:t.filename,onClick:s,className:"max-h-full max-w-full object-contain"});if(t.kind==="video"&&t.rawUrl)return e.jsx("video",{src:t.rawUrl,controls:!0,playsInline:!0,preload:"metadata",onClick:s,className:"h-full w-full object-contain"});const n=t.kind==="pdf"||t.kind==="html";return e.jsx("div",{onClick:s,className:`w-full overflow-auto rounded-lg bg-surface-raised shadow-lg ring-1 ring-edge ${n?"h-full max-w-6xl":"max-h-full max-w-4xl"}`,children:e.jsx(qa,{file:t,fill:!0})})}const Xa="flex 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";function Qn({side:t,disabled:s,onClick:n}){const r=t==="left"?"Previous file":"Next file";return e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),n()},disabled:s,"aria-label":r,title:`${r} (${t==="left"?"←":"→"})`,className:`${Xa} h-10 w-10 shrink-0 disabled:pointer-events-none disabled:opacity-30`,children:e.jsx(Ja,{children:e.jsx("path",{d:t==="left"?"M15 18l-6-6 6-6":"M9 18l6-6-6-6"})})})}function Al(t){return t instanceof HTMLElement?t.isContentEditable?!0:["INPUT","TEXTAREA","SELECT","VIDEO","AUDIO"].includes(t.tagName):!1}function Ja({children:t}){return e.jsx("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}const Za="paddock:attachments:",er="paddock:newchat-instance:";function Dl(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function Pl(t){try{const s=er+t,n=sessionStorage.getItem(s);if(n)return n;const r=Dl();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${Za}new:${t}`)}catch{}return r}catch{return"shared"}}function _l(t){try{localStorage.removeItem(qt(null,t))}catch{}try{sessionStorage.removeItem(er+t)}catch{}}function qt(t,s){return Za+(t??`new:${s}:${Pl(s)}`)}function Ll(t){if(!t||typeof t!="object")return null;const s=t;if(typeof s.id!="string"||!s.id||typeof s.filename!="string"||!s.filename)return null;const n={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(n.size=s.size),n}function Fl(t,s){try{const n=localStorage.getItem(qt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(Ll).filter(i=>i!==null):[]}catch{return[]}}function Ol(t,s,n){try{const r=qt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:i,setError:o}){const[l,c]=a.useState(()=>Fl(s,t)),m=a.useRef([]);m.current=l;const[u,b]=a.useState(!1),[f,h]=a.useState(!1),j=a.useRef(null);a.useEffect(()=>{Ol(s,t,l)},[l,s,t]);const x=a.useRef(null);a.useEffect(()=>{if(!s){x.current=qt(null,t);return}const T=x.current;if(x.current=null,!(!T||T===qt(s,t)))try{localStorage.removeItem(T)}catch{}},[s,t]);const N=a.useMemo(()=>{const T=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},w=r??{};return{enabled:w.enabled??T.enabled,maxFileSizeMb:w.maxFileSizeMb??T.maxFileSizeMb,maxFilesPerMessage:w.maxFilesPerMessage??T.maxFilesPerMessage,allowedTypes:w.allowedTypes??T.allowedTypes}},[n,r]),d=N.enabled,g=a.useCallback(async T=>{if(!d||T.length===0)return;const w=N.maxFileSizeMb*1024*1024,F=N.maxFilesPerMessage-m.current.length;if(F<=0){o(`You can attach at most ${N.maxFilesPerMessage} files per message.`);return}const O=[];for(const z of T.slice(0,F)){if(!Ui(N.allowedTypes,z.type,z.name)){o(`File type not allowed: ${z.name}`);continue}if(z.size>w){o(`File too large (max ${N.maxFileSizeMb} MB): ${z.name}`);continue}O.push(z)}if(T.length>F&&o(`You can attach at most ${N.maxFilesPerMessage} files per message.`),O.length!==0){b(!0);try{const{files:z}=await B.uploadAttachments(t,i.current??"new",O);c(J=>[...J,...z])}catch(z){o(z instanceof Error?z.message:"Upload failed.")}finally{b(!1)}}},[d,N,t]),D=a.useCallback(T=>{c(w=>w.filter(F=>F.id!==T))},[]),$=a.useCallback(()=>{c([])},[]),I=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.clipboardData)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),g(w))},[d,g]),C=a.useCallback(T=>{var w;d&&Array.from(((w=T.dataTransfer)==null?void 0:w.types)??[]).includes("Files")&&(T.preventDefault(),h(!0))},[d]),S=a.useCallback(T=>{T.currentTarget===T.target&&h(!1)},[]),M=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.dataTransfer)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),h(!1),g(w))},[d,g]),y=a.useCallback(T=>{const w=Array.from(T.target.files??[]);w.length>0&&g(w),T.target.value=""},[g]);return{attachments:l,attachRef:m,setAttachments:c,uploading:u,dragOver:f,fileInputRef:j,attachConfig:N,attachEnabled:d,addFiles:g,removeAttachment:D,clearAttachments:$,onComposerPaste:I,onComposerDragOver:C,onComposerDragLeave:S,onComposerDrop:M,onPickFiles:y}}const Bl=15e3,Vl="no response — try again";function zl({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,preloadAvailable:l=!1,projectModel:c,projectModels:m,forkParent:u,onOpenForkParent:b,autoFocus:f,emptyHint:h,placeholder:j,trigger:x,projectRecovery:N,projectAttachments:d,onForkFromMessage:g,onRevertToMessage:D,onMessageLink:$,focusMessageUuid:I}){const[C,S]=a.useState([]),[M,y]=a.useState(0),[T,w]=a.useState(()=>Pi(s,t)),F=a.useRef(null),[O,z]=a.useState(!1),[J,L]=a.useState(!1),[v,A]=a.useState(null),[W,Q]=a.useState(null),[ie,K]=a.useState(be.state),[q,k]=a.useState(null),[U,Z]=a.useState(()=>li(s,t)),E=a.useRef(U),H=a.useRef(ci(s,t)),[de,we]=a.useState(()=>di(s,t)),le=a.useRef(de);le.current=de;const he=U!=null||de.length>0,ke=a.useRef(!1),Ue=a.useRef(!1),[Ae,re]=a.useState(!0),Be=!s,ve=a.useRef(!1),[Te,se]=a.useState([]),[Ve,De]=a.useState(null),[$e,X]=a.useState(null),[me,Ie]=a.useState(null),[Dt,Ze]=a.useState(null),[ze,et]=a.useState([]),[He,We]=a.useState(0),[Ne,P]=a.useState(!1),ee=a.useRef(null),[ae,ue]=a.useState(null),[ye,Ke]=a.useState(null),Pt=c??Ve,_t=a.useMemo(()=>m&&m.length>0?Te.filter(p=>m.includes(p.id)):Te,[Te,m]),Ee=a.useRef(s??null),it=a.useRef(null),Lt=a.useRef(!1),{attachments:Pe,attachRef:tt,setAttachments:ot,uploading:lt,dragOver:es,fileInputRef:Ft,attachConfig:Ot,attachEnabled:st,removeAttachment:ks,clearAttachments:Ns,onComposerPaste:Cs,onComposerDragOver:Ss,onComposerDragLeave:Ts,onComposerDrop:$s,onPickFiles:Is}=Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:Dt,projectAttachments:d,sessionRef:Ee,setError:A}),xt=a.useRef(null),ts=a.useRef(Pe.length);a.useEffect(()=>{const p=Pe.length>ts.current;ts.current=Pe.length,p&&xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)},[Pe.length]);const ss=a.useCallback(p=>Ee.current?B.subagentMessages(t,Ee.current,p):Promise.resolve([]),[t]),Ut=Eo(C),[ct,ns]=a.useState([]);a.useEffect(()=>{const p=s??null;if(!p){ns([]);return}return be.onBackgroundWork(p,ns)},[s]);const Bt=Io(ct),gt=$o(Ut,ss,O,Bt),[as,pt]=a.useState(new Set),[Es,bt]=a.useState(new Map),nt=a.useRef(new Map),at=a.useCallback(p=>{const R=nt.current.get(p);R!==void 0&&(clearTimeout(R),nt.current.delete(p))},[]);a.useEffect(()=>{const p=nt.current;return()=>{for(const R of p.values())clearTimeout(R);p.clear()}},[]),a.useEffect(()=>{const p=s??null;if(p)return be.onStopTaskResult(p,({taskId:R,outcome:G,message:V})=>{G!=="stopping"&&(at(R),pt(Y=>{if(!Y.has(R))return Y;const fe=new Set(Y);return fe.delete(R),fe}),G==="error"&&bt(Y=>new Map(Y).set(R,V||"the runtime refused the stop")))})},[s,at]);const Rs=a.useCallback(p=>{const R=s??null;if(!R)return;let G=!1;pt(V=>V.has(p)?(G=!0,V):new Set(V).add(p)),!G&&(bt(V=>{if(!V.has(p))return V;const Y=new Map(V);return Y.delete(p),Y}),at(p),nt.current.set(p,setTimeout(()=>{nt.current.delete(p),pt(V=>{if(!V.has(p))return V;const Y=new Set(V);return Y.delete(p),Y}),bt(V=>new Map(V).set(p,Vl))},Bl)),be.stopTask(R,p))},[s,at]);a.useEffect(()=>{const p=new Set(ct.map(R=>R.id));for(const R of[...nt.current.keys()])p.has(R)||at(R);pt(R=>{const G=new Set([...R].filter(V=>p.has(V)));return G.size===R.size?R:G}),bt(R=>{const G=new Map([...R].filter(([V])=>p.has(V)));return G.size===R.size?R:G})},[ct,at]);const jt=Ro(C),Ms=a.useMemo(()=>Ut.filter(p=>{var R;return!Bt.has(p.toolUseId)&&(((R=gt.get(p.toolUseId))==null?void 0:R.running)??O)}),[Ut,gt,O,Bt]),As=a.useMemo(()=>t?p=>B.projectFileRawUrl(t,p):null,[t]),wt=a.useRef(!s),vt=a.useRef(!1),yt=a.useRef(!1),_e=a.useRef(!1),rs=a.useRef(null),kt=a.useRef(null),Ge=a.useRef(!0),is=a.useRef(new Set),xn=a.useCallback(()=>{const p=kt.current;p&&(Ge.current=p.scrollHeight-p.scrollTop-p.clientHeight<80)},[]);a.useLayoutEffect(()=>{const p=kt.current;p&&Ge.current&&(p.scrollTop=p.scrollHeight)},[C]);const[Vt,os]=a.useState(null),zt=a.useMemo(()=>({focused:Vt,focus:p=>{Ge.current=!1,os(R=>({toolUseId:p,nonce:((R==null?void 0:R.nonce)??0)+1}))}}),[Vt]);a.useEffect(()=>be.onState(K),[]),a.useEffect(()=>{let p=!1;return B.getModels().then(R=>{p||(se(R.models),De(R.defaultModel),Ie(R.recoveryDefault),Ze(R.attachmentsDefault))}).catch(()=>{}),()=>{p=!0}},[]),a.useEffect(()=>{let p=!1;return B.projectCommands(t).then(R=>{p||et(R)}).catch(()=>{}),()=>{p=!0}},[t]);const qe=a.useMemo(()=>{if(!T.startsWith("/"))return null;const p=T.slice(1);return/\s/.test(p)?null:p},[T]),Qe=a.useMemo(()=>{if(qe===null)return[];const p=qe.toLowerCase();return ze.filter(R=>R.name.toLowerCase().includes(p))},[qe,ze]),Ht=qe!==null&&!Ne&&Qe.length>0;a.useEffect(()=>{We(0)},[qe]),a.useEffect(()=>{P(!1)},[qe]);const _=a.useCallback(p=>{w(`/${p.name} `),requestAnimationFrame(()=>{var R;return(R=F.current)==null?void 0:R.focus()})},[]),te=a.useCallback(p=>{X(p),ee.current=p,Xs(Ee.current??s,t,p)},[t,s]);a.useEffect(()=>{if(s&&s===rs.current){wt.current=!1;return}let p=!1;return Ee.current=s??null,wt.current=!s,it.current=null,vt.current=!1,yt.current=!1,_e.current=!1,A(null),z(!1),s&&n?(L(!0),S([]),n(s).then(({messages:R,total:G,truncated:V})=>{p||(y(V?G-R.length:0),S(Y=>Fs(Tt(R),Y)))}).catch(()=>{p||A("Could not load this chat's history.")}).finally(()=>{p||L(!1)})):(S([]),L(!1)),s&&B.chatContext(t,s).then(R=>{p||!R||(ue({inputTokens:R.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:R.contextTokens,contextLimit:R.contextLimit}),Ke(R))}).catch(()=>{}),()=>{p=!0}},[t,s,n]);const oe=a.useCallback(async()=>{if(!(!s||!n)){try{const{messages:p,total:R,truncated:G}=await n(s);S(Tt(p)),y(G?R-p.length:0)}catch{A("Could not reload this chat's history.")}try{const p=await B.chatContext(t,s);p&&(ue({inputTokens:p.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:p.contextTokens,contextLimit:p.contextLimit}),Ke(p))}catch{}}},[s,n,t]),Ye=a.useCallback(p=>{if(!D)return;const R=C.findIndex(Se=>Se.id.split("#")[0]===p),G=R>=0&&C[R].kind==="user";let V=R+1;if(G){let Se=R-1;for(;Se>=0&&C[Se].kind!=="assistant";)Se--;V=Se+1}else for(;V<C.length&&(C[V].kind==="tool"||C[V].kind==="file");)V++;const Y=R>=0?C.slice(V):[],fe=Y.filter(Se=>Se.kind==="tool").length;k({uuid:p,count:Y.length,toolCount:fe,anchorIsUser:G})},[D,C]),Ce=a.useCallback(async()=>{if(q){try{await(D==null?void 0:D(q.uuid)),await oe()}catch{throw new Error("Could not revert this chat.")}k(null)}},[q,D,oe]),[Le,or]=a.useState(null),gn=a.useRef(null);a.useEffect(()=>{if(!I||J||C.length===0)return;const p=`${s??""}:${I}`;if(gn.current===p)return;gn.current=p;const R=V=>V.some(Y=>Y.id.split("#")[0]===I),G=()=>{Ge.current=!1,or(V=>({uuid:I,nonce:((V==null?void 0:V.nonce)??0)+1}))};if(R(C)){G();return}if(M>0&&n){let V=!1;return n(s??"",0).then(({messages:Y})=>{if(V)return;const fe=Tt(Y);if(!R(fe)){Q("That link points at a message that isn't in this chat any more.");return}S(Se=>Fs(fe,Se)),y(0),G()}).catch(()=>{V||Q("Could not load the rest of this chat's history.")}),()=>{V=!0}}Q("That link points at a message that isn't in this chat any more.")},[I,J,C,s,M,n]);const lr=a.useCallback(async()=>{if(!s||!n)return;const{messages:p}=await n(s,0);S(R=>Fs(Tt(p),R)),y(0)},[s,n]),cr=a.useCallback(p=>{var G;const R=Array.from(((G=kt.current)==null?void 0:G.querySelectorAll("[data-sent-file-turn]"))??[]).find(V=>V.dataset.sentFileTurn===p);R&&(Ge.current=!1,R.scrollIntoView({behavior:"smooth",block:"center"}))},[]),Ds=Il({turns:C,omitted:M,loadEarlier:s&&n?lr:void 0,reveal:cr}),pn=a.useCallback(p=>($==null?void 0:$(p))??`${window.location.origin}${window.location.pathname}#${wa(p)}`,[$]),dr=a.useMemo(()=>g&&D?{onFork:g,onRevert:Ye,contextLimit:ae==null?void 0:ae.contextLimit,linkTo:pn,focused:Le}:null,[g,D,Ye,ae==null?void 0:ae.contextLimit,pn,Le]);a.useEffect(()=>{const R=Ai(s,t)??Pt;R&&(X(R),ee.current=R)},[t,s,Pt]),a.useEffect(()=>{s&&s===rs.current||(ue(null),Ke(null))},[t,s]),a.useEffect(()=>{_i(s,t,T)},[T,s,t]),a.useEffect(()=>{if(W==null)return;const p=setTimeout(()=>Q(null),8e3);return()=>clearTimeout(p)},[W]),a.useEffect(()=>{ui(s,t,U),hi(s,t,he?H.current:null),mi(s,t,de)},[U,de,he,s,t]),a.useEffect(()=>{s&&be.setQueued(t,s,U,he?H.current:null,de)},[U,de,he,s,t,be]),a.useEffect(()=>{var p;(f||!s)&&((p=F.current)==null||p.focus())},[]);const bn=a.useCallback((p,R)=>{const G=R??[];(p||G.length>0)&&(Ge.current=!0,S(V=>[...Fe(V),{kind:"user",id:Xe(),content:p??"",...G.length>0?{attachments:G}:{}}])),E.current=null,H.current=null,Z(null),we([])},[]),jn=a.useCallback((p,R,G,V)=>{R&&(H.current=R);const Y=p&&p.length>0?p:null,fe=V??[];G==="returned"&&(E.current!=null||le.current.length)&&Q("Stopped — the queued message went back to the composer that stopped the turn.");const Se=fe.length===le.current.length&&fe.every((br,jr)=>{var Tn;return br.id===((Tn=le.current[jr])==null?void 0:Tn.id)});E.current===Y&&Se||(E.current=Y,Y===null&&fe.length===0&&(H.current=null),Z(Y),Se||we(fe))},[]),wn=a.useRef(jn);wn.current=jn;const ls=a.useCallback((p,R)=>{E.current=null,H.current=null,Z(null);const G=R??le.current;G.length>0&&ot(V=>{const Y=new Set(V.map(fe=>fe.id));return[...V,...G.filter(fe=>!Y.has(fe.id))]}),we([]),w(V=>V.trim()?`${p}
|
|
8
|
+
${V}`:p),requestAnimationFrame(()=>{const V=F.current;V&&(V.style.height="auto",V.style.height=`${Math.min(V.scrollHeight,192)}px`,V.focus())})},[ot]),vn=a.useCallback((p,R)=>ls(p,R),[ls]),yn=a.useRef(vn);yn.current=vn;const kn=a.useRef(bn);kn.current=bn,$l({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,sessionRef:Ee,jobRef:it,pendingCancelRef:Lt,streamingRef:vt,awaitingSessionRef:yt,isNewSessionRef:wt,startedNotifiedRef:_e,establishedHereRef:rs,modelRef:ee,cancelledRef:ke,noticeThisTurnRef:Ue,seenInjectionsRef:is,onQueuedFlushedRef:kn,onQueuedStateRef:wn,onQueuedReturnedRef:yn,setTurns:S,setStreaming:z,setUsage:ue,setSessionUsage:Ke,setError:A});const Nn=a.useCallback(p=>{A(null),Ge.current=!0;const R=p.startsWith("/")?[]:tt.current;if(S(Y=>[...Fe(Y),{kind:"user",id:Xe(),content:p,...R.length>0?{attachments:R}:{}}]),R.length>0&&(ot([]),tt.current=[]),F.current&&(F.current.style.height="auto"),z(!0),vt.current=!0,Ue.current=!1,it.current=null,Lt.current=!1,Ee.current===null&&(yt.current=!0),p.startsWith("/")){ve.current=!0,be.sendCommand(t,p,Ee.current);return}const V=wt.current&&!ve.current&&Ae;ve.current=!0,be.send(t,p,Ee.current,{preloadContext:V,model:ee.current??void 0,attachments:R.map(Y=>({id:Y.id,filename:Y.filename,kind:Y.kind}))})},[t,Ae]),Cn=a.useCallback(()=>{const p=T.trim();if(!(!p&&tt.current.length===0)){if(O){const G=(E.current??p).startsWith("/")?[]:tt.current;G.length>0&&(we(V=>{const Y=new Set(V.map(fe=>fe.id));return[...V,...G.filter(fe=>!Y.has(fe.id))]}),ot([]),tt.current=[]),Z(V=>{const Y=p?V?`${V}
|
|
9
|
+
${p}`:p:V;return E.current=Y,(V==null||H.current==null)&&(H.current=fi()),Y}),w(""),F.current&&(F.current.style.height="auto");return}w(""),Nn(p)}},[T,O,Nn,tt,ot]),ur=a.useCallback(()=>{const p=E.current;p==null&&le.current.length===0||ls(p??"")},[ls]),hr=a.useCallback(()=>{E.current=null,H.current=null,Z(null),we([])},[]),mr=a.useCallback(()=>{ke.current=!0,it.current?be.cancel(it.current):Lt.current=!0},[]),Sn=a.useCallback(()=>{const p=Ee.current;p&&(vt.current||(z(!0),be.continueChat(t,p)))},[t]),fr=a.useMemo(()=>({enabled:(N==null?void 0:N.surfaceKilledTask)??(me==null?void 0:me.surfaceKilledTask)??!0,busy:O,onContinue:Sn}),[t,N,me,O,Sn]),xr=p=>{if(Ht){if(p.key==="ArrowDown"){p.preventDefault(),We(R=>(R+1)%Qe.length);return}if(p.key==="ArrowUp"){p.preventDefault(),We(R=>(R-1+Qe.length)%Qe.length);return}if(p.key==="Tab"){p.preventDefault(),_(Qe[He]);return}if(p.key==="Enter"){const R=Qe[He];if(R&&R.name!==qe){p.preventDefault(),_(R);return}}if(p.key==="Escape"){p.preventDefault(),P(!0);return}}p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),Cn())},gr=a.useCallback(p=>{w(G=>G.trim()?`${G.trimEnd()} ${p}`:p);const R=F.current;R&&requestAnimationFrame(()=>{R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`,R.focus()})},[]),pr=C.length===0&&!J;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:kt,onScroll:xn,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:[x&&e.jsx(Ki,{trigger:x,projectSlug:t}),J&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}),pr&&e.jsxs("div",{className:"mt-16 flex flex-col items-center text-center",children:[e.jsx("div",{className:"mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-accent-soft text-accent",children:e.jsx(Xt,{width:22,height:22})}),e.jsx("p",{className:"max-w-sm text-sm text-fg-subtle",children:h??"Start the conversation. Messages stream live from Claude and persist as a resumable session."})]}),M>0&&!J&&e.jsxs("p",{className:"pb-4 text-center text-2xs text-fg-subtle",children:[M.toLocaleString()," earlier"," ",M===1?"message is":"messages are"," not shown. They are still saved — reopening this chat always shows the most recent messages first."]}),e.jsx(Ua.Provider,{value:Ds.context,children:e.jsx(Pa.Provider,{value:ss,children:e.jsx(_a.Provider,{value:O,children:e.jsx(ln.Provider,{value:gt,children:e.jsx(La.Provider,{value:zt,children:e.jsx(Fa.Provider,{value:As,children:e.jsx(Aa.Provider,{value:t,children:e.jsx(cn.Provider,{value:fr,children:e.jsx(Oa.Provider,{value:dr,children:e.jsx("div",{className:"space-y-4",children:C.map(p=>e.jsx(gl,{turn:p},p.id))})})})})})})})})})}),Ds.viewer?e.jsx(Rl,{...Ds.viewer}):null]})}),O&&e.jsx(_o,{}),e.jsx(yo,{running:Ms,activity:gt,tasks:ct,commands:jt,onReveal:zt.focus,onCancel:s?Rs:void 0,stopping:as,stopFailed:Es}),v&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:v})]})}),W&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-edge bg-surface-hover px-3 py-2 text-sm text-fg-muted",children:[e.jsx(Je,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:W})]})}),he&&e.jsx(Lo,{text:U??"",attachments:de,onEdit:ur,onClear:hr}),e.jsx("div",{className:"border-t border-edge bg-surface/80 backdrop-blur",children:e.jsxs("div",{className:"pb-safe mx-auto w-full max-w-3xl px-4 pt-3",children:[Be&&e.jsx(Mo,{checked:Ae,available:l,onChange:re}),e.jsx(Ao,{models:_t,model:$e,onSelectModel:te,usage:ae,sessionUsage:ye,forkParent:u,onOpenForkParent:b}),st&&(Pe.length>0||lt)&&e.jsxs("div",{className:"mb-2",children:[Pe.length>1&&e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2 px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{"data-testid":"attachment-tray-count",children:[Pe.length," files attached"]}),e.jsx("button",{type:"button",onClick:Ns,"data-testid":"attachment-tray-clear",title:"Unstage every file from this message",className:"rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active hover:text-danger",children:"Clear all"})]}),e.jsxs("div",{ref:xt,className:"flex max-h-[min(9rem,28vh)] flex-wrap gap-2 overflow-y-auto overscroll-contain","data-testid":"attachment-tray",children:[Pe.map(p=>e.jsx(zi,{attachment:p,onRemove:ks},p.id)),lt&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),"Uploading…"]})]})]}),e.jsxs("div",{className:`relative flex items-end gap-2 rounded-2xl border bg-surface-raised p-2 shadow-sm focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/20 ${es?"border-accent ring-2 ring-accent/30":"border-edge-strong"}`,onDragOver:st?Ss:void 0,onDragLeave:st?Ts:void 0,onDrop:st?$s:void 0,children:[es&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-accent-soft text-sm font-medium text-accent",children:"Drop files to attach"}),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:Qe.map((p,R)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${R===He?"bg-surface-selected":""}`,onMouseEnter:()=>We(R),onMouseDown:G=>{G.preventDefault(),_(p)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",p.name]}),p.argumentHint&&e.jsx("span",{className:"shrink-0 text-fg-subtle",children:p.argumentHint}),p.description&&e.jsx("span",{className:"ml-auto truncate text-fg-muted",children:p.description})]})},p.name))}),e.jsx("textarea",{ref:F,className:"max-h-48 min-h-[40px] flex-1 resize-none bg-transparent px-2 py-2 text-sm outline-none",rows:1,autoCapitalize:"sentences",value:T,placeholder:O?"Queue a message to send next…":j??"Message Claude…",onChange:p=>{w(p.target.value);const R=p.target;R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`},onKeyDown:xr,onPaste:st?Cs:void 0}),st&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:Ft,type:"file",multiple:!0,accept:Oi(Ot.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:Is}),e.jsx("button",{type:"button",onClick:()=>{var p;return(p=Ft.current)==null?void 0:p.click()},title:"Attach files","aria-label":"Attach files","data-testid":"attachment-button",className:"btn bg-transparent text-fg-muted hover:bg-surface-hover hover:text-fg",children:e.jsx(Rr,{width:16,height:16})})]}),e.jsx(Ei,{onText:gr}),O?e.jsxs("button",{type:"button",onClick:mr,title:"Stop generating","aria-label":"Stop",className:"btn bg-surface-active text-fg-muted hover:bg-surface-selected",children:[e.jsx(Gs,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}):e.jsxs("button",{type:"button",onClick:Cn,disabled:!T.trim()&&Pe.length===0||lt,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(fa,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Send"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[e.jsx("kbd",{className:"font-sans",children:"Enter"})," to ",O?"queue":"send"," ·"," ",e.jsx("kbd",{className:"font-sans",children:"Shift+Enter"})," for newline"]}),e.jsx(Fo,{state:ie})]})]})}),e.jsx(on,{open:q!==null,wide:!0,dismissOnBackdrop:!1,title:"Revert this chat back to here?",confirmLabel:"Revert chat",message:q&&e.jsxs(e.Fragment,{children:[q.anchorIsUser&&e.jsx("p",{className:"mb-2",children:"This rewinds to the assistant's previous reply."}),e.jsxs("p",{children:[e.jsxs("span",{className:"font-medium text-fg",children:[q.count," message",q.count===1?"":"s"]})," ","will be removed",q.toolCount>0?e.jsxs(e.Fragment,{children:[", including"," ",e.jsxs("span",{className:"font-medium text-fg",children:[q.toolCount," tool call",q.toolCount===1?"":"s"]}),"."]}):"."]}),q.toolCount>0&&e.jsxs("p",{className:"mt-3 rounded-lg bg-warn-soft px-3 py-2 text-warn",children:[e.jsx("span",{className:"font-medium",children:"Those actions are not undone."})," Files written, PRs opened and messages sent stay as they are — only the conversation is rewound."]}),e.jsx("p",{className:"mt-3",children:"The removed messages are backed up, and this chat keeps its id."})]}),onConfirm:Ce,onClose:()=>k(null)})]})}function Hl(t){var r;const s=t.untracked?"??":(t.status||"").trim(),n=((r=s[0])==null?void 0:r.toUpperCase())??"";return t.untracked||n==="?"?{label:"??",cls:"bg-surface-active text-fg-muted"}:n==="A"?{label:"A",cls:"bg-success-soft text-success"}:n==="D"?{label:"D",cls:"bg-danger-soft text-danger"}:n==="R"?{label:"R",cls:"bg-lineage-soft text-lineage"}:n==="M"?{label:"M",cls:"bg-warn-soft text-warn"}:{label:n||s||"•",cls:"bg-surface-active text-fg-muted"}}function Wl({slug:t,status:s,onStatusChange:n,selectedFile:r,onSelectFile:i}){var Z;const[o,l]=a.useState(null),[c,m]=a.useState(null),u=i!==void 0,b=u?r??null:c,f=a.useCallback(E=>{u?i==null||i(E):m(E)},[u,i]),[h,j]=a.useState(""),[x,N]=a.useState(!1),[d,g]=a.useState(!1),[D,$]=a.useState(null),[I,C]=a.useState(null),[S,M]=a.useState(new Set),y=s.files,T=y.length,w=y.filter(E=>!S.has(E.path)).map(E=>E.path),F=w.length,O=F===y.length&&y.length>0,z=a.useCallback(E=>{M(H=>{const de=new Set(H);return de.has(E)?de.delete(E):de.add(E),de})},[]),J=a.useCallback(()=>M(new Set),[]),L=a.useCallback(()=>M(new Set(y.map(E=>E.path))),[y]),v=a.useCallback(async()=>{const E=await B.gitProjectInfo(t).catch(()=>null);E&&l(E)},[t]);a.useEffect(()=>{v()},[v]);const A=a.useCallback(async()=>{const E=await B.gitStatus(t).catch(()=>null);E&&n(E)},[t,n]),W=b&&y.some(E=>E.path===b)?b:((Z=y[0])==null?void 0:Z.path)??null,Q=y.find(E=>E.path===W)??null,ie=a.useCallback(async()=>{const E=h.trim();if(!(!E||x||w.length===0)){N(!0),$(null),C(null);try{const H=O?await B.gitCommit(t,E):await B.gitCommit(t,E,w);H.committed?(j(""),M(new Set),C(H.hash?`Committed ${H.hash.slice(0,7)}`:"Committed"),await A(),await v()):C(H.error??"Nothing to commit")}catch(H){$(H instanceof je?H.message:"Commit failed")}finally{N(!1)}}},[h,x,w,O,t,A,v]),K=(o==null?void 0:o.ahead)??0,q=(o==null?void 0:o.configured)??!1,k=q&&K>0&&!d,U=a.useCallback(async()=>{if(k){g(!0),$(null),C(null);try{const E=await B.gitPush(t);E.pushed?(C("Pushed to remote"),await v()):$(E.error??"Push failed")}catch(E){$(E instanceof je?E.message:"Push failed")}finally{g(!1)}}},[k,v,t]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-edge px-4 py-2.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-medium text-fg-muted",children:[e.jsx(ft,{width:14,height:14,className:"text-fg-subtle"}),s.branch??"—"]}),s.clean?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-fg-subtle",children:[e.jsx(It,{width:12,height:12}),"clean"]}):e.jsxs("span",{className:"rounded-md bg-warn-soft px-1.5 py-0.5 text-2xs font-medium text-warn",children:[T," uncommitted"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(Xl,{info:o,onChanged:v}),e.jsxs("button",{type:"button",onClick:()=>void U(),disabled:!k,title:q?K>0?`Push ${K} commit${K===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx(Mr,{width:13,height:13}),d?"Pushing…":"Push",q&&K>0&&e.jsxs("span",{className:"text-2xs font-semibold text-accent",children:["↑",K]})]})]})]}),(D||I)&&e.jsxs("div",{className:"px-4 pt-2",children:[D&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:D})]}),!D&&I&&e.jsx("p",{className:"text-xs text-fg-muted",children:I})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("div",{className:"flex w-full shrink-0 flex-col border-b border-edge lg:w-72 lg:border-b-0 lg:border-r",children:[e.jsxs("div",{className:"mb-1 mt-3 flex items-center justify-between gap-2 px-3",children:[e.jsx("span",{className:"section-label px-0",children:"Changed files"}),y.length>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[F,"/",y.length," selected"]}),e.jsx("button",{type:"button",onClick:O?L:J,className:"rounded px-1 py-0.5 font-medium text-accent hover:bg-accent/10",title:O?"Deselect all files":"Select all files",children:O?"None":"All"})]})]}),e.jsx("div",{className:"max-h-[35vh] overflow-y-auto px-2 pb-2 lg:max-h-none lg:flex-1",children:y.length===0?e.jsx("p",{className:"px-2 py-2 text-sm italic text-fg-subtle",children:"No uncommitted changes. Files you author surface here for a checkpoint."}):y.map(E=>e.jsx(Kl,{file:E,active:W===E.path,selected:!S.has(E.path),onSelect:()=>f(E.path),onToggleSelect:()=>z(E.path)},E.path))}),e.jsxs("div",{className:"border-t border-edge p-3",children:[e.jsx("textarea",{rows:2,value:h,placeholder:"Commit message…",onChange:E=>j(E.target.value),className:"max-h-40 min-h-[44px] w-full resize-none rounded-lg border border-edge-strong bg-surface-sunken px-2.5 py-2 text-sm text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20"}),e.jsxs("button",{type:"button",onClick:()=>void ie(),disabled:!h.trim()||x||F===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:y.length===0?"Nothing to commit":F===0?"Select at least one file to commit":O?"Commit all changed files":`Commit ${F} selected file${F===1?"":"s"}`,children:[e.jsx(It,{width:13,height:13}),x?"Committing…":F>0&&!O?`Commit ${F} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(Gl,{slug:t,file:Q})})]})]})}function mn({file:t}){if(t.binary)return e.jsx("span",{className:"text-fg-subtle",children:"binary"});const{added:s,removed:n}=t;return s==null&&n==null?null:!s&&!n?e.jsx("span",{className:"text-fg-subtle",children:"0"}):e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono tabular",children:[s?e.jsxs("span",{className:"text-success",children:["+",s]}):null,n?e.jsxs("span",{className:"text-danger",children:["−",n]}):null]})}function Kl({file:t,active:s,selected:n,onSelect:r,onToggleSelect:i}){const o=Hl(t),l=t.untracked?"untracked":t.staged?"staged":"unstaged";return e.jsxs("div",{className:`mb-0.5 flex items-center gap-2 rounded-lg pl-2 pr-2.5 transition-colors ${s?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[e.jsx("input",{type:"checkbox",checked:n,onChange:i,"aria-label":`Stage ${t.path}`,title:n?"Included in commit — click to exclude":"Excluded — click to include",className:"h-3.5 w-3.5 shrink-0 cursor-pointer accent-[var(--accent-solid)]"}),e.jsxs("button",{type:"button",onClick:r,title:t.path,className:"flex min-w-0 flex-1 items-center gap-2 py-2 text-left text-sm",children:[e.jsx("span",{className:`inline-flex h-5 w-6 shrink-0 items-center justify-center rounded font-mono text-3xs font-semibold ${o.cls}`,children:o.label}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-mono text-xs text-fg-muted",children:t.path}),e.jsxs("span",{className:"flex items-center gap-2 text-3xs text-fg-subtle",children:[e.jsx("span",{children:l}),e.jsx(mn,{file:t})]})]})]})]})}function Gl({slug:t,file:s}){const n=(s==null?void 0:s.path)??null,r=(s==null?void 0:s.untracked)??!1,[i,o]=a.useState(""),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{if(!n||r){o(""),u(null),c(!1);return}let f=!1;return c(!0),u(null),B.gitDiff(t,n).then(h=>{f||o(h)}).catch(h=>{f||u(h instanceof je?h.message:"Failed to load diff")}).finally(()=>{f||c(!1)}),()=>{f=!0}},[t,n,r]),!s)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-sm text-fg-subtle",children:"Select a file to view its diff."});if(r)return e.jsx(Yl,{slug:t,file:s});if(l)return e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]});if(m)return e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:m})]})});if(!i.trim())return e.jsxs("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm text-fg-subtle",children:["No textual diff for this file",e.jsx("br",{}),"(e.g. a mode or binary change)."]});const b=i.split(`
|
|
10
|
+
`);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(ql,{file:s}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre px-4 py-3 font-mono text-xs leading-relaxed",children:b.map((f,h)=>e.jsx("div",{className:Ql(f),children:f||" "},h))})})]})}function ql({file:t}){return e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:t.path}),e.jsx(mn,{file:t})]})}function Ql(t){return t.startsWith("+++")||t.startsWith("---")||t.startsWith("diff ")||t.startsWith("index ")?"text-fg-subtle":t.startsWith("@@")?"text-lineage":t.startsWith("+")?"bg-success-soft text-success":t.startsWith("-")?"bg-danger-soft text-danger":"text-fg-muted"}function Yl({slug:t,file:s}){const n=s.path,[r,i]=a.useState(null),[o,l]=a.useState(!0),[c,m]=a.useState(null);a.useEffect(()=>{let b=!1;return l(!0),m(null),i(null),B.gitUntrackedFile(t,n).then(f=>{b||i(f)}).catch(f=>{b||m(f instanceof je?f.message:"Failed to load file")}).finally(()=>{b||l(!1)}),()=>{b=!0}},[t,n]);const u=e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:n}),e.jsx(mn,{file:s}),e.jsx("span",{className:"rounded bg-success-soft px-1.5 py-0.5 font-medium text-success",children:"new file · untracked"})]});return o?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]}):c||!r?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:c??"File not found."})]})}):r.kind==="image"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:B.gitUntrackedFileRawUrl(t,n),alt:n,className:"max-h-full max-w-full object-contain shadow-sm"})})]}):r.kind==="pdf"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(un,{src:B.gitUntrackedFileRawUrl(t,n),filename:n,className:"h-full min-h-[480px] w-full"})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre-wrap break-words border-l-2 border-success-edge px-4 py-3 font-mono text-xs leading-relaxed text-fg-muted",children:r.content})})]})}function Xl({info:t,onChanged:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(null),[l,c]=a.useState(!1),[m,u]=a.useState(null),[b,f]=a.useState(!1),h=a.useRef(!1);a.useEffect(()=>(h.current=!1,()=>{h.current=!0}),[]);const j=t==null?void 0:t.github,x=a.useCallback(async()=>{r(!0),u(null);try{const d=await B.githubConnect();o({userCode:d.userCode,verificationUri:d.verificationUri}),c(!0),h.current=!1;const g=Date.now()+d.expiresIn*1e3;let D=Math.max(1,d.interval)*1e3;const $=async()=>{if(!h.current){if(Date.now()>=g){c(!1),o(null),u("The code expired before authorization. Try again.");return}try{const I=await B.githubPoll(d.deviceCode);if(h.current)return;if(I.status==="authorized"){c(!1),o(null),await s();return}if(I.status==="error"){c(!1),o(null),u(I.error??"Authorization failed.");return}I.status==="slow_down"&&(D+=5e3),window.setTimeout(()=>void $(),D)}catch(I){if(h.current)return;c(!1),o(null),u(I instanceof je?I.message:"Polling failed.")}}};window.setTimeout(()=>void $(),D)}catch(d){u(d instanceof je?d.message:"Could not start the GitHub connection.")}finally{r(!1)}},[s]),N=a.useCallback(async()=>{f(!0);try{await B.githubDisconnect(),await s()}catch{}finally{f(!1)}},[s]);return j?j.configured?j.connected?e.jsxs("span",{className:"inline-flex items-center gap-2 text-2xs text-fg-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(_s,{width:13,height:13}),"@",j.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void N(),disabled:b,className:"btn-subtle px-2 py-1 text-2xs",title:"Disconnect GitHub",children:b?"…":"Disconnect"})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[i?e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5 text-2xs text-fg-muted",children:[e.jsx("span",{className:"text-fg-muted",children:"Enter"}),e.jsx("code",{className:"rounded bg-surface-active px-1.5 py-0.5 font-mono text-xs font-semibold tracking-widest text-fg",children:i.userCode}),e.jsx("span",{className:"text-fg-muted",children:"at"}),e.jsxs("a",{href:i.verificationUri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-accent underline underline-offset-2 hover:text-accent-solid-hover",children:[e.jsx(ma,{width:11,height:11}),"github.com"]}),l&&e.jsx("span",{className:"text-fg-subtle",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void x(),disabled:n,className:"btn-ghost py-1.5 text-xs",title:"Authorize paddock to push to GitHub on your behalf (device flow).",children:[e.jsx(_s,{width:13,height:13}),n?"Starting…":"Connect GitHub"]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-danger",children:[e.jsx(ge,{width:12,height:12}),m]})]}):e.jsxs("span",{className:"hidden items-center gap-1.5 text-2xs text-fg-subtle sm:inline-flex",title:"Set PADDOCK_GITHUB_CLIENT_ID on the server to enable in-app GitHub auth.",children:[e.jsx(_s,{width:13,height:13}),"GitHub not configured"]}):null}function Jl(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(Je,{width:12,height:12}),cls:"bg-warn-soft text-warn"}:t==="spawned"?{label:"Spawned",icon:e.jsx(ft,{width:12,height:12}),cls:"bg-lineage-soft text-lineage"}:t==="adopted"?{label:"Adopted",icon:e.jsx(Jt,{width:12,height:12}),cls:"bg-success-soft text-success"}:{label:"You",icon:e.jsx(Yt,{width:12,height:12}),cls:"bg-surface-active text-fg-muted"}}function Zl(t){switch(t){case"completed":return{label:"completed",cls:"bg-success-soft text-success"};case"failed":return{label:"failed",cls:"bg-danger-soft text-danger"};case"running":return{label:"running",cls:"bg-info-soft text-info"};case"cancelled":return{label:"cancelled",cls:"bg-surface-active text-fg-muted"};case"pending":return{label:"pending",cls:"bg-warn-soft text-warn"};default:return{label:t,cls:"bg-surface-active text-fg-muted"}}}function ec(t){if(t.durationSeconds!=null)return xs(t.durationSeconds*1e3)??"—";if(t.status==="running"){const s=Date.parse(t.startedAt);if(Number.isFinite(s))return`${xs(Date.now()-s)??"—"}…`}return"—"}function zs(t){return t.origin!=="human"&&t.origin!=="adopted"}function tc(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 sc({run:t,title:s,onOpen:n}){var c,m;const r=Jl(t.origin),i=Zl(t.status),o=t.sessionId!=null,l=((c=t.prompt)==null?void 0:c.trim())||((m=t.summary)==null?void 0:m.trim())||s;return e.jsxs("button",{type:"button",onClick:o?n:void 0,disabled:!o,"data-run-origin":t.origin,"data-run-new":t.isNew?"true":void 0,className:`flex w-full items-start gap-3 border-t border-edge px-4 py-3 text-left first:border-t-0 ${o?"hover:bg-surface-hover":"cursor-default"} ${t.isNew?"bg-accent-soft":""}`,children:[e.jsx("span",{className:"mt-1.5 w-1.5 shrink-0",children:t.isNew&&e.jsx("span",{"data-run-unread":"true","aria-label":"New since your last visit",title:"Ran while you were away",className:"block h-1.5 w-1.5 rounded-full bg-accent-solid"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-2xs font-medium ${r.cls}`,children:[r.icon,r.label]}),e.jsx("span",{className:`inline-flex items-center rounded px-1.5 py-0.5 text-2xs font-medium ${i.cls}`,children:i.label})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-fg",children:l}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-fg-muted",children:tc(t)})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-0.5 text-xs text-fg-muted",children:[e.jsx("span",{title:new Date(t.startedAt).toLocaleString(),children:Et(t.startedAt)}),e.jsx("span",{className:"font-mono tabular",children:ec(t)}),e.jsx("span",{className:"font-mono text-fg-subtle",title:"Per-run cost is coming soon",children:"—"})]})]})}function nc({slug:t,state:s,chats:n,onOpenChat:r}){const{data:i,loading:o,error:l,refresh:c,markSeen:m}=s,[u,b]=a.useState("unattended");a.useEffect(()=>{m()},[t]);const f=a.useMemo(()=>{const d=new Map;for(const g of n)d.set(g.sessionId,g.name);return g=>g&&d.get(g)||(g?g.slice(0,8):"unknown chat")},[n]),h=(i==null?void 0:i.runs)??[],j=a.useMemo(()=>h.filter(zs).length,[h]),x=a.useMemo(()=>u==="unattended"?h.filter(zs):h,[h,u]),N=a.useMemo(()=>h.filter(d=>d.isNew&&zs(d)).length,[h]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-edge px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Run history"}),e.jsx("button",{type:"button",onClick:()=>void c(),className:"text-xs text-fg-muted hover:text-fg",children:"Refresh"})]}),e.jsxs("div",{className:"inline-flex overflow-hidden rounded-lg border border-edge text-xs",children:[e.jsxs(Yn,{active:u==="unattended",onClick:()=>b("unattended"),children:["Unattended",j>0?` (${j})`:""]}),e.jsx(Yn,{active:u==="all",onClick:()=>b("all"),children:"All"})]})]}),N>0&&e.jsxs("div",{"data-since-last-visit":N,className:"border-b border-accent-edge bg-accent-soft px-4 py-2 text-sm text-fg",children:[e.jsxs("span",{className:"font-medium",children:[N," new ",N===1?"run":"runs"]})," ","ran while you were away."]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:l?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-danger",children:l}):o&&h.length===0?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-fg-muted",children:"Loading run history…"}):x.length===0?e.jsx(ac,{filter:u,hasAny:h.length>0}):e.jsx("div",{children:x.map(d=>e.jsx(sc,{run:d,title:f(d.sessionId),onOpen:()=>d.sessionId&&r(d.sessionId)},d.jobId))})})]})}function Yn({active:t,onClick:s,children:n}){return e.jsx("button",{type:"button",onClick:s,className:`motion-fast px-2.5 py-1 font-medium transition-colors ${t?"bg-accent-soft text-accent":"text-fg-muted hover:text-fg"}`,children:n})}function ac({filter:t,hasAny:s}){return e.jsxs("div",{className:"px-4 py-12 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-fg",children:t==="unattended"?"No unattended runs yet":"No runs yet"}),e.jsx("p",{className:"mx-auto mt-1 max-w-sm text-xs text-fg-muted",children:t==="unattended"?s?"Scheduled and spawned runs will show up here. Switch to All to see your own runs.":"Scheduled and spawned runs — the ones that happen while you're not watching — will show up here.":"Runs appear here once Claude starts finishing turns."})]})}function rc(t){const[s,n]=a.useState(null),[r,i]=a.useState(!0),[o,l]=a.useState(null),[c,m]=a.useState(!1),u=a.useCallback(async()=>{i(!0),m(!1);try{const h=await B.projectRuns(t);n(h),l(null)}catch(h){l(h instanceof Error?h.message:"Failed to load run history")}finally{i(!1)}},[t]);a.useEffect(()=>{u()},[u]);const b=a.useCallback(async()=>{m(!0),await B.markRunsSeen(t).catch(()=>{})},[t]),f=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:r,error:o,newUnattended:f,refresh:u,markSeen:b}}function ic({slug:t,name:s}){const[n,r]=a.useState(null),[i,o]=a.useState(null),[l,c]=a.useState(!0);return a.useEffect(()=>{let m=!1;return c(!0),o(null),r(null),B.getProjectFile(t,s).then(u=>{m||r(u)}).catch(u=>{m||o(u instanceof Error?u.message:"Failed to load file")}).finally(()=>{m||c(!1)}),()=>{m=!0}},[t,s]),l?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-4 w-1/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}):i||!n?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:i??"File not found."})]})}):n.kind==="image"?e.jsx(lc,{slug:t,name:n.name}):n.kind==="pdf"?e.jsx(cc,{slug:t,name:n.name}):n.kind==="html"?e.jsx(oc,{name:n.name,content:n.content}):n.kind==="text"?e.jsx("div",{className:"overflow-auto p-6",children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-lg border border-edge bg-surface-sunken p-4 font-mono text-xs leading-relaxed text-fg",children:n.content})}):e.jsx("article",{className:"prose-doc mx-auto max-w-3xl px-6 py-6",children:e.jsx(Zt,{mermaid:!0,children:n.content})})}function oc({name:t,content:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx(dc,{}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-fg-muted",children:t})," renders in a sandboxed frame (scripts allowed, isolated from the app)."]})]}),e.jsx("iframe",{title:t,sandbox:"allow-scripts",srcDoc:s,className:"html-preview min-h-[480px] w-full flex-1"})]})}function lc({slug:t,name:s}){const[n,r]=a.useState(!1);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",style:{background:"repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px"},children:n?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:B.projectFileRawUrl(t,s),alt:s,onError:()=>r(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function cc({slug:t,name:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(un,{src:B.projectFileRawUrl(t,s),filename:s,className:"h-full min-h-[480px] w-full"})})]})}function dc(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"})})}function uc({project:t,path:s,onNavigate:n,onTogglePin:r}){const i=t.slug,[o,l]=a.useState(null),[c,m]=a.useState(!1),[u,b]=a.useState(null),[f,h]=a.useState(!0);a.useEffect(()=>{let d=!1;return h(!0),b(null),l(null),m(!1),B.listProjectDir(i,s).then(g=>{d||(g.kind==="file"?m(!0):l(g))}).catch(g=>{d||b(g instanceof Error?g.message:"Failed to load files")}).finally(()=>{d||h(!1)}),()=>{d=!0}},[i,s]);const j=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",x=e.jsx(hc,{path:s,isFile:c,onNavigate:n});if(f)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:[x,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(d=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},d))})]})});if(u)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[x,e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(ge,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:u})]})]})});if(c){const d=t.pinned.includes(s);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge px-4 py-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:x}),e.jsxs("button",{onClick:()=>r(s),className:`ml-auto inline-flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors ${d?"bg-accent/10 text-accent":"text-fg-muted hover:bg-surface-hover"}`,title:d?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(gs,{width:13,height:13}),d?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(ic,{slug:i,name:s})})]})}const N=(o==null?void 0:o.entries)??[];return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[x,N.length===0&&s===""?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-fg-subtle",children:"No files yet. Files Claude writes (and sweep-curated OVERVIEW.md) will appear here."})}):e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-edge",children:[s!==""&&e.jsxs("button",{onClick:()=>n(j),className:"flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover",children:[e.jsx(qs,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-sm text-fg-muted",children:".."})]}),N.length===0&&s!==""&&e.jsx("div",{className:"px-3 py-2.5 text-sm italic text-fg-subtle",children:"This folder is empty."}),N.map((d,g)=>{const D=s?`${s}/${d.name}`:d.name,$=d.kind==="dir",I=t.pinned.includes(D),C=!$,S=g>0||s!==""?"border-t border-edge":"";return e.jsxs("div",{className:`group/file flex items-center gap-2 px-3 py-2.5 transition-colors hover:bg-surface-hover ${S}`,children:[e.jsxs("button",{onClick:()=>n(D),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[$?e.jsx(qs,{width:15,height:15,className:"shrink-0 text-accent/80"}):e.jsx(Qt,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:`truncate font-mono text-sm ${$?"font-medium text-fg":"text-fg"}`,children:d.name}),$&&e.jsx(At,{width:14,height:14,className:"ml-auto shrink-0 text-fg-subtle"})]}),C&&e.jsxs("button",{type:"button","aria-label":I?`Unpin ${d.name}`:`Pin ${d.name}`,title:I?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>r(D),className:`flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-2xs font-medium transition ${I?"bg-accent/10 text-accent":"text-fg-subtle opacity-0 hover:bg-surface-active hover:text-fg-muted focus:opacity-100 group-hover/file:opacity-100"}`,children:[e.jsx(gs,{width:12,height:12}),I?"Pinned":"Pin"]})]},d.name)})]})]})})}function hc({path:t,isFile:s,onNavigate:n}){const r=t?t.split("/"):[];return e.jsxs("nav",{"aria-label":"File path",className:"mb-3 flex flex-wrap items-center gap-x-1 gap-y-0.5 text-sm",children:[e.jsx(Xn,{label:"Files",isLast:r.length===0,onClick:()=>n("")}),r.map((i,o)=>{const l=o===r.length-1,c=r.slice(0,o+1).join("/");return e.jsxs("span",{className:"flex items-center gap-x-1",children:[e.jsx(At,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx(Xn,{label:i,isLast:l,mono:!0,muted:l&&s,onClick:()=>n(c)})]},c)})]})}function Xn({label:t,isLast:s,mono:n,muted:r,onClick:i}){const o=n?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${o} font-medium ${r?"text-fg-muted":"text-fg"}`,children:t}):e.jsx("button",{type:"button",onClick:i,className:`${o} rounded text-fg-muted transition-colors hover:text-accent`,children:t})}function xe({children:t}){return e.jsx("p",{className:"mt-1 text-xs leading-snug text-fg-muted",children:t})}function Jn({children:t}){return e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t})]})}function Rt({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("dd",{className:"mt-0.5 text-sm text-fg-muted",children:s})]})}function mc({project:t,onDeleted:s}){const[n,r]=a.useState(!1);if(ka(t.slug))return null;const i=xi(t);return e.jsxs(mt,{title:"Danger zone",description:i?"Deleting unlinks this project: Paddock’s notes, settings and chats go, and the directory it works in is left untouched.":"Deleting removes this project’s directory — its notes, settings, chats and files.",children:[e.jsxs("button",{type:"button",className:"btn btn-danger gap-1.5",onClick:()=>r(!0),children:[e.jsx(js,{width:14,height:14}),"Delete project…"]}),n&&e.jsx(gi,{project:t,open:!0,onClose:()=>r(!1),onDeleted:s})]})}function fc({project:t}){return e.jsx(mt,{title:"Derived",description:"Read-only state Claude and sweeps maintain.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3 sm:grid-cols-2",children:[e.jsx(Rt,{label:"Overview",value:t.hasOverview?e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(It,{width:12,height:12})," OVERVIEW.md written by a sweep"]}):e.jsx("span",{className:"text-fg-subtle",children:"No OVERVIEW.md yet"})}),e.jsx(Rt,{label:"Pinned files",value:t.pinned.length>0?e.jsx("span",{className:"flex flex-wrap gap-1.5",children:t.pinned.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-surface-active px-1.5 py-0.5 font-mono text-xs text-fg-muted",children:[e.jsx(gs,{width:11,height:11,className:"text-accent"}),s]},s))}):e.jsx("span",{className:"text-fg-subtle",children:"None — pin files from the Files tab"})})]})})}function xc({project:t,onSaved:s}){const[n,r]=a.useState(""),[i,o]=a.useState(!1),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{r(""),o(!1),u(null)},[t.slug,t.managed]),!t.managed||t.path)return e.jsx(mt,{title:"Backing",description:t.managed?"Claude works in the directory below, and Paddock curates this project's notes there.":"Claude works in the directory below. Paddock does not write project files into it — its notes stay in the project's own folder.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3",children:[t.repo&&e.jsx(Rt,{label:t.path?"Repository (recorded)":"Repository",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.repo})}),e.jsx(Rt,{label:"Working directory",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.workingDir})})]})});const b=n.trim(),f=b.length>0&&!gc(b),h=async()=>{if(!(!b||f)){c(!0),u(null);try{const j=await B.promoteProject(t.slug,b);s(j),o(!1),r("")}catch(j){u(j instanceof je?j.message:"Failed to promote project")}finally{c(!1)}}};return e.jsxs(mt,{title:"Repository backing",description:"Notebook project. Promote it to repo-backed to work directly in an external git repo — keeping all of this project's chats and notes.",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Git repository URL"}),e.jsx("input",{className:"input font-mono text-sm",value:n,onChange:j=>{r(j.target.value),o(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":f,"aria-label":"Git repository URL"}),f?e.jsx(xe,{children:e.jsx("span",{className:"text-danger",children:"That doesn’t look like a git URL (https://, git@…, ssh://, git://)."})}):e.jsxs(xe,{children:["Paddock clones this repo into a nested checkout and points Claude at it. The repo’s own ",e.jsx("code",{children:"CLAUDE.md"})," and git tooling take over."]})]}),m&&e.jsx("p",{className:"mt-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:m}),i?e.jsxs("div",{className:"mt-4 rounded-lg border border-warn-edge bg-warn-soft p-3",children:[e.jsxs("p",{className:"flex items-start gap-1.5 text-sm leading-snug text-warn",children:[e.jsx(ge,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["Promote ",e.jsx("span",{className:"font-semibold",children:t.name})," to repo-backed? This clones ",e.jsx("span",{className:"break-all font-mono",children:b}),", moves Claude into that checkout, and stops curating this project’s ",e.jsx("code",{children:"CLAUDE.md"})," (the repo’s own takes over). Your ",e.jsx("span",{className:"font-medium",children:"chats and notes are kept"}),". This is ",e.jsx("span",{className:"font-medium",children:"one-way"}),"."]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"btn-primary",disabled:l,onClick:h,children:l?"Promoting…":"Yes, promote"}),e.jsx("button",{type:"button",className:"btn-subtle",disabled:l,onClick:()=>o(!1),children:"Cancel"})]})]}):e.jsx("button",{type:"button",className:"btn-primary mt-4",disabled:l||!b||f,onClick:()=>o(!0),children:"Promote to repo-backed…"})]})}function gc(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}const pc=["idea","active","paused","blocked","done","abandoned"];function Hs(t,s,n){const r={};return t!==""&&(r.overviewMaxTokens=Number(t)),s!==""&&(r.changelogMaxTokens=Number(s)),n!==""&&(r.claudeMaxTokens=Number(n)),Object.keys(r).length>0?r:null}const Zn=[{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)"}],Kt="loading…";function bc({project:t,onSaved:s,onDeleted:n}){var He,We,Ne;const[r,i]=a.useState(t.name),[o,l]=a.useState(t.summary),[c,m]=a.useState(t.domain.join(", ")),[u,b]=a.useState(t.group??""),[f,h]=a.useState(t.status),[j,x]=a.useState(t.visibility),[N,d]=a.useState(t.links??[]),[g,D]=a.useState(t.model),[$,I]=a.useState(t.models??[]),[C,S]=a.useState(t.permissionMode),[M,y]=a.useState(String(t.maxTurns)),[T,w]=a.useState(t.docker),[F,O]=a.useState(t.driveMode??""),[z,J]=a.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[L,v]=a.useState(((He=t.curation)==null?void 0:He.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[A,W]=a.useState(((We=t.curation)==null?void 0:We.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[Q,ie]=a.useState(((Ne=t.curation)==null?void 0:Ne.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[K,q]=a.useState([]),[k,U]=a.useState(null),[Z,E]=a.useState(null),[H,de]=a.useState(null),[we,le]=a.useState(!1),[he,ke]=a.useState(null),[Ue,Ae]=a.useState(0);a.useEffect(()=>{var P,ee,ae;i(t.name),l(t.summary),m(t.domain.join(", ")),b(t.group??""),h(t.status),x(t.visibility),d(t.links??[]),D(t.model),I(t.models??[]),S(t.permissionMode),y(String(t.maxTurns)),w(t.docker),O(t.driveMode??""),J(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),v(((P=t.curation)==null?void 0:P.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),W(((ee=t.curation)==null?void 0:ee.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),ie(((ae=t.curation)==null?void 0:ae.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),ke(null)},[t]),a.useEffect(()=>{let P=!1;return B.getModels().then(ee=>{P||(q(ee.models),U(ee.driveModeDefault),E(ee.maxSpawnDepthDefault),de(ee.curationDefault))}).catch(()=>{}),()=>{P=!0}},[]);const re=a.useMemo(()=>N.map(P=>({label:P.label.trim(),url:P.url.trim()})).filter(P=>P.url.length>0),[N]),Be=a.useMemo(()=>c.split(",").map(P=>P.trim()).filter(Boolean),[c]),ve=a.useMemo(()=>({name:r.trim(),status:f,group:u,summary:o.trim(),domain:Be,visibility:j,links:re,model:g,models:$.length>0?$:null,permissionMode:C,maxTurns:Number(M),docker:T,driveMode:F===""?null:F,maxSpawnDepth:z===""?null:Number(z),curation:Hs(L,A,Q)}),[r,f,u,o,Be,j,re,g,$,C,M,T,F,z,L,A,Q]),Te=a.useMemo(()=>{var ee,ae,ue;const P={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(ye=>({label:ye.label,url:ye.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:Hs(((ee=t.curation)==null?void 0:ee.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ae=t.curation)==null?void 0:ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((ue=t.curation)==null?void 0:ue.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify(ve)!==JSON.stringify(P)},[ve,t]),se=ve.name.length===0,Ve=Number(M),De=!Number.isInteger(Ve)||Ve<1||Ve>1e3,$e=Number(z),X=z!==""&&(!Number.isInteger($e)||$e<0||$e>8),me=P=>P!==""&&(!Number.isInteger(Number(P))||Number(P)<1),Ie=me(L)||me(A)||me(Q),Dt=async P=>{if(P.preventDefault(),!(se||De||X||Ie)){le(!0),ke(null);try{const ee=await B.updateProject(t.slug,ve);s(ee),Ae(ae=>ae+1)}catch(ee){ke(ee instanceof je?ee.message:"Failed to save changes")}finally{le(!1)}}},Ze=k===null?Kt:k==="session"?"Session":"Batch",ze=$.length>0?K.filter(P=>$.includes(P.id)):K,et=(P,ee)=>I(ae=>ee?[...ae.filter(ue=>ue!==P),P]:ae.filter(ue=>ue!==P));return e.jsxs("form",{onSubmit:Dt,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-edge bg-surface/80 px-4 py-2.5 backdrop-blur sm:px-6",children:[e.jsx("span",{className:"text-sm font-medium text-fg-muted",children:"Settings"}),Te&&!we&&e.jsx("span",{className:"text-xs text-warn",children:"Unsaved changes"}),Ue>0&&!Te&&!we&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-success",children:[e.jsx(It,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:we||!Te||se||De||X||Ie,children:we?"Saving…":"Save changes"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[he&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:he}),e.jsxs(mt,{title:"Identity & metadata",description:"How this project is named, grouped, and described across the app.",children:[e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",value:r,onChange:P=>i(P.target.value),placeholder:"Display name","aria-invalid":se}),se&&e.jsx(xe,{children:"Name can’t be empty."})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary"}),e.jsx("input",{className:"input",value:o,onChange:P=>l(P.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:f,onChange:P=>h(P.target.value),children:pc.map(P=>e.jsx("option",{value:P,className:"capitalize",children:P},P))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:u,onChange:P=>b(P.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Ys.map(P=>e.jsx("option",{value:P.slug,children:P.label},P.slug)),u&&!Ys.some(P=>P.slug===u)&&e.jsx("option",{value:u,children:u})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Visibility"}),e.jsxs("select",{className:"input capitalize",value:j,onChange:P=>x(P.target.value),children:[e.jsx("option",{value:"public",children:"Public"}),e.jsx("option",{value:"private",children:"Private"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:c,onChange:P=>m(P.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),N.length===0&&e.jsx("p",{className:"mb-2 text-xs italic text-fg-subtle",children:"No links yet."}),e.jsx("div",{className:"space-y-2",children:N.map((P,ee)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:P.label,onChange:ae=>d(ue=>ue.map((ye,Ke)=>Ke===ee?{...ye,label:ae.target.value}:ye)),placeholder:"Label","aria-label":`Link ${ee+1} label`}),e.jsx("input",{className:"input flex-1",value:P.url,onChange:ae=>d(ue=>ue.map((ye,Ke)=>Ke===ee?{...ye,url:ae.target.value}:ye)),placeholder:"https://…","aria-label":`Link ${ee+1} URL`}),e.jsx("button",{type:"button",onClick:()=>d(ae=>ae.filter((ue,ye)=>ye!==ee)),"aria-label":`Remove link ${ee+1}`,title:"Remove link",className:"motion-fast flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-fg-subtle transition-[color,background-color,border-color,box-shadow,transform] hover:bg-danger-soft hover:text-danger",children:e.jsx(js,{width:14,height:14})})]},ee))}),e.jsxs("button",{type:"button",onClick:()=>d(P=>[...P,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(rt,{width:13,height:13}),"Add link"]})]}),e.jsxs("dl",{className:"mt-4 grid grid-cols-2 gap-x-4 gap-y-3 border-t border-edge pt-4 sm:grid-cols-3",children:[e.jsx(Rt,{label:"Slug",value:ka(t.slug)?e.jsx("span",{className:"italic text-fg-subtle",title:"The root workspace has no slug",children:"(root)"}):e.jsx("span",{className:"font-mono",children:t.slug})}),e.jsx(Rt,{label:"Started",value:t.started})]})]}),e.jsx(mt,{title:"Claude",description:"How Claude runs in this workspace. Changes take effect on the next turn.",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-4",children:[e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsxs("select",{className:"input",value:g,onChange:P=>D(P.target.value),children:[!ze.some(P=>P.id===g)&&e.jsx("option",{value:g,children:g}),ze.map(P=>e.jsx("option",{value:P.id,children:P.label},P.id))]})]}),e.jsx(xe,{children:"Larger context windows (Opus/Fable/Sonnet: 1M; Haiku: 200K) fit longer chats."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsxs("select",{className:"input",value:C,onChange:P=>S(P.target.value),children:[!Zn.some(P=>P.value===C)&&e.jsx("option",{value:C,children:C}),Zn.map(P=>e.jsx("option",{value:P.value,children:P.label},P.value))]})]}),C==="bypassPermissions"?e.jsx(Jn,{children:"Claude runs every tool without asking — it can edit files and run commands unprompted."}):e.jsx(xe,{children:"How much Claude asks before acting."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,max:1e3,step:1,className:"input",value:M,onChange:P=>y(P.target.value),"aria-invalid":De})]}),De?e.jsx(xe,{children:e.jsx("span",{className:"text-danger",children:"Must be a whole number 1–1000."})}):e.jsx(xe,{children:"Upper bound on agent turns in a single run."})]}),e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Docker sandbox"}),e.jsxs("label",{className:"mt-1 flex cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:T,onChange:P=>w(P.target.checked)}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Run Claude in a Docker sandbox"})]}),T?e.jsx(Jn,{children:"Requires a working Docker daemon on the box, or Claude won’t start."}):e.jsx(xe,{children:"Isolate Claude's tool calls in a container."})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Offered models"}),K.length===0?e.jsx("p",{className:"mt-1 text-xs italic text-fg-subtle",children:"Loading the instance model list…"}):e.jsx("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-1.5",children:K.map(P=>{const ee=$.length===0||$.includes(P.id);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 text-sm text-fg-muted",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:ee,onChange:ae=>{$.length===0?I(ae.target.checked?[]:K.filter(ue=>ue.id!==P.id).map(ue=>ue.id)):et(P.id,ae.target.checked)},"aria-label":P.label}),e.jsx("span",{children:P.label})]},P.id)})}),$.length===0?e.jsx(xe,{children:"Offering all instance models. Uncheck any to restrict this project's picker to a subset; the model default above is then constrained to it."}):e.jsxs(xe,{children:["Restricting this project's picker to ",$.length," of ",K.length," ","instance models."," ",e.jsx("button",{type:"button",onClick:()=>I([]),className:"font-medium text-accent hover:underline",children:"Offer all instance models"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Drive mode"}),e.jsxs("select",{className:"input",value:F,onChange:P=>O(P.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",Ze,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),F===""&&k===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the box-wide drive-mode default…"})}):F===""?e.jsxs(xe,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Ze}),". ",e.jsx("span",{className:"font-medium",children:"Session"})," enables cross-turn autonomy (ScheduleWakeup / ",e.jsx("code",{children:"/loop"}),"); ",e.jsx("span",{className:"font-medium",children:"Batch"})," ","is the legacy one-shot path."]}):e.jsxs(xe,{children:["Overriding the global default."," ",e.jsx("button",{type:"button",onClick:()=>O(""),className:"font-medium text-accent hover:underline",children:"Reset to global default"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsxs("select",{className:"input",value:z,onChange:P=>J(P.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",Z??Kt,")"]}),e.jsx("option",{value:"0",children:"0 — no spawned children get tools"}),e.jsx("option",{value:"1",children:"1 — children can report back (grandchildren can't)"}),e.jsx("option",{value:"2",children:"2"}),e.jsx("option",{value:"3",children:"3"}),e.jsx("option",{value:"4",children:"4"})]})]}),z===""&&Z===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance max-spawn-depth default…"})}):z===""?e.jsxs(xe,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Z}),". A chat spawned via ",e.jsx("code",{children:"create_chat"}),"/",e.jsx("code",{children:"fork_chat"})," gets the self-management tools (so it can ",e.jsx("code",{children:"send_message"})," back to its parent and spawn its own) only while its depth stays within this bound."," ",e.jsx("span",{className:"font-medium",children:"0"})," disables spawned tooling entirely."]}):e.jsxs(xe,{children:["Overriding the instance default."," ",e.jsx("button",{type:"button",onClick:()=>J(""),className:"font-medium text-accent hover:underline",children:"Reset to instance default"}),"."]})]})]})}),e.jsxs(mt,{title:"Curation budgets",description:"Per-file token limits the post-turn sweeper keeps this project's OVERVIEW.md, CHANGELOG.md and CLAUDE.md under. Leave a field blank to inherit the instance default.",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"OVERVIEW.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.overviewMaxTokens)??Kt})`,value:L,onChange:P=>v(P.target.value),"aria-label":"OVERVIEW.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CHANGELOG.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.changelogMaxTokens)??Kt})`,value:A,onChange:P=>W(P.target.value),"aria-label":"CHANGELOG.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CLAUDE.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.claudeMaxTokens)??Kt})`,value:Q,onChange:P=>ie(P.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),Ie?e.jsx(xe,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):Hs(L,A,Q)?e.jsxs(xe,{children:["Overriding the instance defaults",H&&e.jsxs(e.Fragment,{children:[" ","(",H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens,")"]})," ","for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{v(""),W(""),ie("")},className:"font-medium text-accent hover:underline",children:"Reset all to instance defaults"}),". Repo-backed projects never have their CLAUDE.md curated, so that budget is moot for them."]}):H===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance curation budgets…"})}):e.jsxs(xe,{children:["Inheriting the instance defaults:"," ",e.jsxs("span",{className:"tabular font-medium text-fg",children:[H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens]})," ","tokens (OVERVIEW/CHANGELOG/CLAUDE). Lower a budget to shrink the context this project injects into every chat."]})]}),e.jsx(xc,{project:t,onSaved:s}),e.jsx(fc,{project:t}),e.jsx(mc,{project:t,onDeleted:n})]})})]})}const jc=/^[A-Za-z0-9._-]+$/,wc={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},vc={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},yc=[{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)"}],kc={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},Nc=["read","write","web","orchestration","browser"];function Cc(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 Sc(t){const s=t.trigger,n=t.run;return{name:t.name,type:s.type,scheduleKind:s.type==="schedule"&&s.interval!==void 0?"interval":"cron",expr:s.type==="schedule"?s.cron!==void 0?s.cron:s.interval??"":"",event:s.type==="event"?s.on:"onArchive",path:s.type==="webhook"?s.path:"",promptMode:n.promptFile?"file":"inline",prompt:n.prompt??"",promptFile:n.promptFile??"",resumeSession:n.session==="resume",allowedTools:new Set(n.tools??[]),permissionMode:n.permissionMode??"",model:n.model??"",maxTurns:n.maxTurns!=null?String(n.maxTurns):"",maxSpawnDepth:n.maxSpawnDepth!=null?String(n.maxSpawnDepth):"",enabled:t.enabled===!0}}function Tc(t){let s;t.type==="event"?s={type:"event",on:t.event}:t.type==="webhook"?s={type:"webhook",path:t.path.trim()}:s=t.scheduleKind==="cron"?{type:"schedule",cron:t.expr.trim()}:{type:"schedule",interval:t.expr.trim()};const n={session:t.resumeSession?"resume":"new",tools:[...t.allowedTools]};t.promptMode==="file"?n.promptFile=t.promptFile.trim():n.prompt=t.prompt,t.permissionMode&&(n.permissionMode=t.permissionMode),t.model.trim()&&(n.model=t.model.trim());const r=Number(t.maxTurns);t.maxTurns.trim()&&Number.isFinite(r)&&r>0&&(n.maxTurns=Math.floor(r));const i=Number(t.maxSpawnDepth);return t.maxSpawnDepth.trim()&&Number.isFinite(i)&&i>=0&&(n.maxSpawnDepth=Math.floor(i)),{trigger:s,run:n,enabled:t.enabled}}function $c(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 ea(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function Ic(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function Ec({project:t}){const s=t.slug,[n,r]=a.useState([]),[i,o]=a.useState([]),[l,c]=a.useState(["onArchive","afterTurn"]),[m,u]=a.useState(["schedule","event","webhook"]),[b,f]=a.useState(!0),[h,j]=a.useState(null),[x,N]=a.useState(null),[d,g]=a.useState(null),[D,$]=a.useState(null),[I,C]=a.useState(null),[S,M]=a.useState({}),y=a.useCallback(async()=>{f(!0);try{const k=await B.listTriggers(s);r(k.triggers),o(k.grantableTools),k.events.length>0&&c(k.events),k.triggerTypes.length>0&&u(k.triggerTypes),j(null)}catch(k){j(k instanceof je?k.message:"Failed to load triggers")}finally{f(!1)}},[s]),T=a.useCallback(async()=>{try{const k=await B.triggerRuntime(s);M(Object.fromEntries(k.runtime.map(U=>[U.name,U])))}catch{}},[s]);a.useEffect(()=>{y()},[y]),a.useEffect(()=>{T();const k=setInterval(()=>{document.visibilityState==="visible"&&T()},1e4);return()=>clearInterval(k)},[T]),a.useEffect(()=>{if(!x)return;const k=setTimeout(()=>N(null),4e3);return()=>clearTimeout(k)},[x]);const w=d==null?void 0:d.draft,F=a.useMemo(()=>d!=null&&d.isNew?n.some(k=>k.name===(w==null?void 0:w.name.trim())):!1,[d,w,n]),O=!!w&&(!jc.test(w.name.trim())||w.name.trim().length>64),z=!!w&&(w.type==="schedule"?w.expr.trim().length===0:w.type==="webhook"?w.path.trim().length===0:!1),J=!!w&&(w.promptMode==="file"?w.promptFile.trim().length===0||!w.promptFile.trim().toLowerCase().endsWith(".md"):w.prompt.trim().length===0),L=!!w&&w.type==="webhook",v=O||F||z||J||L,A=k=>g(U=>U&&{...U,draft:{...U.draft,...k}}),W=k=>g(U=>{if(!U)return U;const Z=new Set(U.draft.allowedTools);return Z.has(k)?Z.delete(k):Z.add(k),{...U,draft:{...U.draft,allowedTools:Z}}}),Q=async()=>{if(!d||v)return;const k=d.draft.name.trim();$(k);try{await B.putTrigger(s,k,Tc(d.draft)),g(null),N(`Saved “${k}”.`),await y()}catch(U){j(U instanceof je?U.message:"Failed to save trigger")}finally{$(null)}},ie=async k=>{$(k.name);try{const U=await B.putTrigger(s,k.name,{trigger:k.trigger,run:k.run,enabled:!k.enabled});r(Z=>Z.map(E=>E.name===k.name?U:E))}catch(U){j(U instanceof je?U.message:"Failed to update trigger")}finally{$(null)}},K=async()=>{const k=I;if(k){$(k.name);try{await B.deleteTrigger(s,k.name),r(U=>U.filter(Z=>Z.name!==k.name)),N(`Deleted “${k.name}”.`),C(null)}catch(U){throw new Error(U instanceof je?U.message:"Failed to delete trigger")}finally{$(null)}}},q=async k=>{$(k.name);try{await B.runTrigger(s,k.name),N(`Ran “${k.name}” — a new chat is starting.`),await T()}catch(U){j(U instanceof je?U.message:"Failed to run trigger")}finally{$(null)}};return e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain","data-testid":"triggers-pane",children:[e.jsx("div",{className:"mx-auto max-w-3xl px-6 py-6",children:e.jsxs("section",{className:"mb-6",children:[e.jsxs("h3",{className:"flex items-center gap-1.5 text-sm font-semibold uppercase tracking-wide text-fg-muted",children:[e.jsx(Mt,{width:14,height:14}),"Triggers"]}),e.jsxs("p",{className:"mb-3 mt-0.5 text-sm text-fg-muted",children:["A trigger runs an agent turn when something happens — a"," ",e.jsx("span",{className:"font-medium",children:"schedule"})," (a cron/interval fires), an"," ",e.jsx("span",{className:"font-medium",children:"event"})," (a lifecycle event like a chat being archived), or a ",e.jsx("span",{className:"font-medium",children:"webhook"})," (reserved). Each trigger's granted tools ",e.jsx("em",{children:"are"})," its capability. New triggers are created disabled; enable one when you’re ready for it to fire."]}),e.jsxs("div",{className:"card",children:[h&&e.jsx("p",{className:"mb-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:h}),x&&e.jsx("p",{className:"mb-3 rounded-lg bg-success-soft px-3 py-2 text-sm text-success",children:x}),b?e.jsx("p",{className:"py-4 text-center text-sm text-fg-subtle",children:"Loading triggers…"}):n.length===0?e.jsx("p",{className:"py-4 text-center text-sm italic text-fg-subtle",children:"No triggers yet."}):e.jsx("div",{className:"-mx-1 overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[54rem] border-collapse text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-edge text-left text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:[e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Trigger"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Type"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"When"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Capability"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Last run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Next run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Status"}),e.jsx("th",{className:"px-2 py-2 text-right font-semibold",children:"Actions"})]})}),e.jsx("tbody",{children:n.map(k=>{var Z;const U=S[k.name];return e.jsxs("tr",{"data-trigger":k.name,className:"border-b border-edge-subtle last:border-0",children:[e.jsxs("td",{className:"px-2 py-2.5 align-top",children:[e.jsx("span",{className:"font-medium text-fg",children:k.name}),k.run.promptFile?e.jsx("span",{className:"mt-0.5 block font-mono text-2xs text-fg-subtle",title:"Prompt read from this file at fire time",children:k.run.promptFile}):k.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-2xs text-fg-subtle",children:k.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Rc,{type:k.trigger.type})}),e.jsx("td",{className:"px-2 py-2.5 align-top font-mono text-xs text-fg-muted",children:Ic(k.trigger)}),e.jsxs("td",{className:"px-2 py-2.5 align-top text-xs text-fg-muted",children:[e.jsx("span",{title:((Z=k.run.tools)==null?void 0:Z.join(", "))||"No tools declared — an empty list is not enforced as a deny-all",children:$c(k)}),k.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-2xs text-fg-subtle",children:k.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":k.name,children:e.jsx(Dc,{rt:U})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":k.name,children:e.jsx(Pc,{rt:U,trigger:k})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Mc,{enabled:k.enabled===!0,running:(U==null?void 0:U.running)===!0})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>q(k),disabled:D===k.name||ea(k),title:ea(k)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${k.name} now`,"data-testid":`run-trigger-${k.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-accent transition hover:bg-accent-soft disabled:opacity-40",children:e.jsx(Ar,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ie(k),disabled:D===k.name,className:"rounded-md px-1.5 py-1 text-xs font-medium text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",title:k.enabled?"Disable":"Enable",children:k.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>g({isNew:!1,draft:Sc(k)}),disabled:D===k.name,title:"Edit","aria-label":`Edit ${k.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",children:e.jsx(bs,{width:14,height:14})}),e.jsx("button",{type:"button",onClick:()=>C(k),disabled:D===k.name,title:"Delete","aria-label":`Delete ${k.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle transition hover:bg-danger-soft hover:text-danger disabled:opacity-40",children:e.jsx(js,{width:14,height:14})})]})})]},k.name)})})]})}),!d&&e.jsxs("button",{type:"button",onClick:()=>g({isNew:!0,draft:Cc(m[0]??"schedule",l[0]??"onArchive")}),className:"btn-subtle mt-3 gap-1.5 px-2 py-1 text-xs","data-testid":"add-trigger",children:[e.jsx(rt,{width:13,height:13}),"Add trigger"]}),d&&w&&e.jsxs("div",{className:"mt-4 rounded-xl border border-edge bg-surface-sunken p-4","data-testid":"trigger-editor",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:d.isNew?"New trigger":`Edit “${w.name}”`}),e.jsx("button",{type:"button",onClick:()=>g(null),"aria-label":"Cancel",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle hover:bg-surface-hover",children:e.jsx(Oe,{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:w.name,onChange:k=>A({name:k.target.value}),placeholder:"daily-manager",disabled:!d.isNew,"aria-invalid":O||F,"data-testid":"trigger-name"}),d.isNew&&F?e.jsx("p",{className:"mt-1 text-xs text-danger",children:"A trigger with that name exists."}):d.isNew&&w.name.trim()&&O?e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Letters, numbers, ",e.jsx("code",{children:". _ -"})," only (max 64)."]}):!d.isNew&&e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Rename by deleting and recreating."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Type"}),e.jsx("select",{className:"input",value:w.type,onChange:k=>A({type:k.target.value}),"data-testid":"trigger-type",children:m.map(k=>e.jsx("option",{value:k,children:vc[k]??k},k))})]}),w.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:w.scheduleKind,onChange:k=>A({scheduleKind:k.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:w.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:w.expr,onChange:k=>A({expr:k.target.value}),placeholder:w.scheduleKind==="cron"?"0 9 * * *":"30m","aria-invalid":z,"data-testid":"trigger-expr"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:w.scheduleKind==="cron"?"5-field cron (or @daily / @hourly), host-local time.":"A duration like 30m, 1h, or 6h."})]})]}),w.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:w.event,onChange:k=>A({event:k.target.value}),"data-testid":"trigger-event",children:l.map(k=>e.jsx("option",{value:k,children:wc[k]??k},k))})]}),w.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:w.path,onChange:k=>A({path:k.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),L&&e.jsxs("p",{className:"col-span-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{"data-testid":"trigger-webhook-reserved",children:["Webhook triggers are ",e.jsx("strong",{children:"reserved"})," — the inbound HTTP ingress isn’t built yet, so a webhook trigger can’t be created here. The shape is shown for reference."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Prompt"}),e.jsxs("div",{className:"mb-2 flex gap-3 text-sm",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:w.promptMode==="inline",onChange:()=>A({promptMode:"inline"})}),"Inline text"]}),e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:w.promptMode==="file",onChange:()=>A({promptMode:"file"})}),"Prompt file"]})]}),w.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:w.prompt,onChange:k=>A({prompt:k.target.value}),placeholder:"What should this trigger do when it fires?","aria-invalid":J,"data-testid":"trigger-prompt"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input font-mono",value:w.promptFile,onChange:k=>A({promptFile:k.target.value}),placeholder:"daily-manager.md","aria-invalid":J,"data-testid":"trigger-prompt-file"}),e.jsxs("p",{className:"mt-1 text-xs text-fg-subtle",children:["A ",e.jsx("code",{children:".md"})," file under ",e.jsx("code",{children:".paddock/triggers/"}),", read fresh each fire (git-tracked, Claude-editable)."]})]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Tools"}),e.jsxs("p",{className:"mb-2 text-xs text-fg-subtle",children:["The trigger agent can use exactly the tools you check here — nothing else.",w.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:Nc.filter(k=>i.some(U=>U.group===k)).map(k=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:kc[k]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:i.filter(U=>U.group===k).map(U=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-md px-1.5 py-1 text-sm hover:bg-surface-hover",title:U.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:w.allowedTools.has(U.name),onChange:()=>W(U.name),"data-tool":U.name}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-fg",children:U.name}),e.jsx("span",{className:"block text-2xs leading-snug text-fg-subtle",children:U.description})]})]},U.name))})]},k))}),w.allowedTools.has("Bash")&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(ge,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[e.jsx("code",{children:"Bash"})," lets this trigger run arbitrary shell commands in the project working dir. Grant it only when the trigger genuinely needs it."]})]})]}),e.jsxs("div",{className:"col-span-2 flex flex-wrap items-center gap-x-6 gap-y-2",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:w.resumeSession,onChange:k=>A({resumeSession:k.target.checked}),"data-testid":"trigger-session"}),e.jsx("span",{className:"text-fg",children:"Accrete into one session"})]}),e.jsx("span",{className:"text-xs text-fg-subtle",children:w.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:w.permissionMode,onChange:k=>A({permissionMode:k.target.value}),"data-testid":"trigger-permission-mode",children:yc.map(k=>e.jsx("option",{value:k.value,children:k.label},k.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:w.maxTurns,onChange:k=>A({maxTurns:k.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:w.model,onChange:k=>A({model:k.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:w.maxSpawnDepth,onChange:k=>A({maxSpawnDepth:k.target.value}),placeholder:"Inherit","data-testid":"trigger-max-spawn-depth"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"0 = may not spawn children."})]}),e.jsxs("label",{className:"col-span-2 inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:w.enabled,onChange:k=>A({enabled:k.target.checked}),"data-testid":"trigger-enabled"}),e.jsx("span",{className:"text-fg",children:"Enabled (fires on its trigger)"})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Q,disabled:v||D===w.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:D===w.name.trim()?"Saving…":d.isNew?"Create trigger":"Save"}),e.jsx("button",{type:"button",onClick:()=>g(null),className:"btn-ghost",children:"Cancel"})]})]})]})]})}),e.jsx(on,{open:I!==null,title:"Delete trigger?",confirmLabel:"Delete trigger",message:I&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:I.name})," ","will be removed from this project. This can't be undone."]}),onConfirm:K,onClose:()=>C(null)})]})}function Rc({type:t}){const s={schedule:"bg-lineage-soft text-lineage",event:"bg-info-soft text-info",webhook:"bg-surface-active text-fg-muted"},n=t==="schedule"?Je:Mt;return e.jsxs("span",{"data-trigger-type":t,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-2xs font-medium capitalize ${s[t]}`,children:[e.jsx(n,{width:11,height:11}),t]})}function Mc({enabled:t,running:s}){return s?e.jsxs("span",{"data-trigger-status":"running",className:"inline-flex items-center gap-1 rounded-full bg-warn-soft px-2 py-0.5 text-2xs font-medium text-warn",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-warn-solid"}),"Running"]}):e.jsx("span",{"data-trigger-status":t?"enabled":"disabled",className:`inline-flex items-center rounded-full px-2 py-0.5 text-2xs font-medium ${t?"bg-success-soft text-success":"bg-surface-active text-fg-muted"}`,children:t?"Enabled":"Disabled"})}function Ac(t){return t==="completed"?"bg-success-solid":t==="failed"||t==="cancelled"?"bg-danger-solid":t==="running"||t==="pending"?"bg-warn-solid":"bg-fg-subtle"}function Dc({rt:t}){const s=t==null?void 0:t.lastRun;if(!s)return e.jsx("span",{className:"text-xs text-fg-subtle",children:"—"});const n=s.startedAt,r=[n?new Date(n).toLocaleString():null,`status: ${s.status}${s.exitReason?` (${s.exitReason})`:""}`,s.summary??null].filter(Boolean).join(`
|
|
11
|
+
`);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-fg-muted",title:r,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Ac(s.status)}`}),s.status==="running"?"Running…":Et(n)]})}function Pc({rt:t,trigger:s}){const n=s.trigger.type;if(n==="event")return e.jsx("span",{className:"text-xs text-fg-subtle",children:"on event"});if(n==="webhook")return e.jsx("span",{className:"text-xs text-fg-subtle",children:"on webhook"});const r=t==null?void 0:t.nextRunAt;return r?e.jsx("span",{className:"text-xs text-fg-muted",title:new Date(r).toLocaleString(),children:Dr(r)}):e.jsx("span",{className:"text-xs text-fg-subtle",children:"—"})}const tr="paddock:fork:";function _c(t){if(!t)return null;try{const s=localStorage.getItem(tr+t);if(!s)return null;const n=JSON.parse(s);return n&&typeof n.sessionId=="string"&&typeof n.name=="string"?n:null}catch{return null}}function Lc(t,s){try{localStorage.setItem(tr+t,JSON.stringify(s))}catch{}}function en(t){const s=Date.parse(t.chat.updatedAt??"")||0;return t.children.reduce((n,r)=>Math.max(n,en(r)),s)}function fn(t){for(const s of t)fn(s.children);t.sort((s,n)=>!!s.chat.starred!=!!n.chat.starred?s.chat.starred?-1:1:en(n)-en(s))}function sr(t,s){let n=0;for(const r of t)r.depth=s,r.descendantCount=sr(r.children,s+1),n+=1+r.descendantCount;return n}function Fc(t){var r;const s=new Map;for(const i of t)s.set(i.sessionId,{chat:i,children:[],depth:0,descendantCount:0});const n=[];for(const i of s.values()){const o=(r=i.chat.parent)==null?void 0:r.sessionId,l=o?s.get(o):void 0;if(!l||l===i||Uc(i,l,s)){n.push(i);continue}l.children.push(i)}return fn(n),sr(n,0),n}function Oc(t){const s=t.map(n=>({chat:n,children:[],depth:0,descendantCount:0}));return fn(s),s}function Uc(t,s,n){var o;const r=new Set([t.chat.sessionId]);let i=s;for(;i;){if(r.has(i.chat.sessionId))return!0;r.add(i.chat.sessionId);const l=(o=i.chat.parent)==null?void 0:o.sessionId;i=l?n.get(l):void 0}return!1}function tn(t){return t.reduce((s,n)=>s+1+tn(n.children),0)}function Bc(t){const s=[t.chat.sessionId],n=r=>{for(const i of r)s.push(i.chat.sessionId),n(i.children)};return n(t.children),s}function Vc(t,s){var l;const n=new Map;for(const c of t){const m=(l=c.parent)==null?void 0:l.sessionId;if(!m)continue;const u=n.get(m);u?u.push(c.sessionId):n.set(m,[c.sessionId])}const r=[],i=new Set([s]),o=[s];for(;o.length;)for(const c of n.get(o.pop())??[])i.has(c)||(i.add(c),r.push(c),o.push(c));return r}function ta(t,s){const n=[],r=i=>{for(const o of i)n.push(o),s.has(o.chat.sessionId)||r(o.children)};return r(t),n}function zc(t,s){var i;const n=new Map(t.map(o=>[o.sessionId,o])),r=new Set;for(const o of s){let l=o;const c=new Set;for(;l&&!c.has(l.sessionId);){c.add(l.sessionId),r.add(l.sessionId);const m=(i=l.parent)==null?void 0:i.sessionId;l=m?n.get(m):void 0}}return t.filter(o=>r.has(o.sessionId))}const sn="paddock:chatsCollapsed:";function Hc(t){try{const s=localStorage.getItem(sn+t);if(!s)return new Set;const n=JSON.parse(s);return Array.isArray(n)?new Set(n.filter(r=>typeof r=="string")):new Set}catch{return new Set}}function Wc(t,s){try{s.size===0?localStorage.removeItem(sn+t):localStorage.setItem(sn+t,JSON.stringify([...s]))}catch{}}const nr="paddock:chatView:nested",ar="paddock:chatView:runningOnly";function rr(t,s){try{const n=localStorage.getItem(t);return n==="1"?!0:n==="0"?!1:s}catch{return s}}function ir(t,s,n){try{s===n?localStorage.removeItem(t):localStorage.setItem(t,s?"1":"0")}catch{}}function Kc(){return rr(nr,!0)}function Gc(t){ir(nr,t,!0)}function qc(){return rr(ar,!1)}function Qc(t){ir(ar,t,!1)}function Yc(){const[t,s]=a.useState(Kc),[n,r]=a.useState(qc),i=a.useCallback(l=>{s(l),Gc(l)},[]),o=a.useCallback(l=>{r(l),Qc(l)},[]);return a.useMemo(()=>({nested:t,setNested:i,runningOnly:n,setRunningOnly:o}),[t,i,n,o])}function ut({active:t,onClick:s,children:n}){return e.jsx("button",{onClick:s,className:`whitespace-nowrap border-b-2 px-3 py-2.5 text-sm font-medium transition-colors ${t?"border-accent text-fg":"border-transparent text-fg-muted hover:text-fg"}`,children:n})}function Xc({file:t,active:s,onSelect:n,onUnpin:r}){const i=t.includes("/")?t.slice(t.lastIndexOf("/")+1):t;return e.jsxs("div",{className:`group/pin flex items-center gap-1 border-b-2 pr-1 transition-colors ${s?"border-accent":"border-transparent"}`,children:[e.jsxs("button",{onClick:n,title:t,"aria-label":`Open ${t} tab`,role:"tab","aria-selected":s,className:`flex items-center gap-1.5 py-2.5 pl-3 pr-1 text-sm font-medium transition-colors ${s?"text-fg":"text-fg-muted hover:text-fg"}`,children:[e.jsx(gs,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"max-w-[10rem] truncate",children:i})]}),e.jsx("button",{type:"button","aria-label":`Unpin ${t}`,title:`Unpin ${t}`,onClick:o=>{o.stopPropagation(),r()},className:"flex h-5 w-5 items-center justify-center rounded text-fg-subtle opacity-60 transition hover:bg-surface-active hover:text-fg focus:opacity-100 group-hover/pin:opacity-100",children:e.jsx(Oe,{width:12,height:12})})]})}function sa({placement:t,view:s,filesTabActive:n,gitStatus:r,newRunCount:i,pinned:o,activePinnedFile:l,goHome:c,goChat:m,goFiles:u,goChanges:b,goHistory:f,goSettings:h,goTriggers:j,goToFilesPath:x,unpinTab:N}){const d=e.jsxs("div",{"data-testid":"workspace-tabs",className:`-mb-px flex items-center gap-1 overflow-x-auto ${t==="header"?"min-w-0 flex-1 self-end":"px-4"}`,children:[e.jsx(ut,{active:s==="home",onClick:c,children:"Home"}),e.jsx(ut,{active:s==="chat",onClick:m,children:"Chat"}),e.jsx(ut,{active:n,onClick:u,children:"Files"}),r&&e.jsx(ut,{active:s==="changes",onClick:b,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Changes",r.files.length>0&&e.jsx("span",{title:`${r.files.length} uncommitted change${r.files.length===1?"":"s"}`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-warn-soft px-1 text-3xs font-semibold text-warn",children:r.files.length})]})}),e.jsx(ut,{active:s==="history",onClick:f,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["History",i>0&&e.jsx("span",{title:`${i} new unattended run${i===1?"":"s"} since your last visit`,className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-accent-soft px-1 text-3xs font-semibold text-accent",children:i})]})}),e.jsx(ut,{active:s==="settings",onClick:h,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ya,{width:13,height:13}),"Settings"]})}),e.jsx(ut,{active:s==="triggers",onClick:j,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Mt,{width:13,height:13}),"Triggers"]})}),o.map(g=>e.jsx(Xc,{file:g,active:l===g,onSelect:()=>x(g),onUnpin:()=>void N(g)},g))]});return t==="header"?d:e.jsx("div",{className:`border-b border-edge ${s==="chat"?"hidden":"block"}`,children:d})}function Jc({name:t,onHome:s,openNav:n,onShowChats:r,chatCount:i,onNewChat:o,tabs:l}){return e.jsx("header",{className:`pt-safe border-b border-edge px-3 sm:px-6 ${l?"":"pb-2.5"}`,children:e.jsxs("div",{className:`flex items-center ${l?"gap-6":"gap-2"}`,children:[e.jsx("button",{type:"button",onClick:n,className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden","aria-label":"Open menu",children:e.jsx(Pr,{width:20,height:20})}),e.jsxs("button",{type:"button",onClick:r,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(Yt,{width:16,height:16}),e.jsx("span",{className:"hidden sm:inline",children:"Chats"}),i>0&&e.jsx("span",{className:"text-2xs text-fg-subtle",children:i})]}),e.jsx("h1",{className:"min-w-0 text-lg font-semibold tracking-tight lg:max-w-xs lg:shrink-0 lg:text-xl xl:max-w-sm",children:e.jsx("button",{type:"button",onClick:s,title:`${t} — project home`,className:"block max-w-full truncate rounded transition-colors hover:text-accent",children:t})}),l,e.jsx("button",{type:"button",onClick:o,"aria-label":"New chat",title:"New chat",className:"btn-subtle ml-auto shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(rt,{width:16,height:16})})]})})}function Zc({index:t,count:s,backLabel:n,nextLabel:r,onBack:i,onNext:o,clamped:l=!1,itemNoun:c}){return s<=1?null:e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"font-mono tabular text-2xs text-fg-subtle","aria-hidden":"true",children:[t+1,"/",s]}),e.jsxs("span",{className:"sr-only",role:"status",children:[c," ",t+1," of ",s]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(na,{label:n,back:!0,disabled:l&&t===0,onClick:i}),e.jsx(na,{label:r,disabled:l&&t===s-1,onClick:o})]})]})}function na({label:t,back:s=!1,disabled:n=!1,onClick:r}){return e.jsx("button",{type:"button",onClick:r,disabled:n,"aria-label":t,title:t,className:"focus-visible:focus-ring rounded-md p-1 text-fg-subtle transition-colors disabled:opacity-30 can-hover:hover:enabled:bg-surface-hover can-hover:hover:enabled:text-fg",children:e.jsx(At,{width:14,height:14,className:s?"rotate-180":""})})}function aa({label:t,icon:s,entries:n,itemNoun:r,testId:i,random:o=Math.random,className:l}){const[c]=a.useState(()=>n.length===0?0:Math.min(Math.floor(o()*n.length),n.length-1)),[m,u]=a.useState(c);if(n.length===0)return null;const b=Math.min(m,n.length-1),f=n[b];if(f===void 0)return null;const h=j=>{u(x=>(Math.min(x,n.length-1)+j+n.length)%n.length)};return e.jsxs(pi,{className:$t("flex flex-col",l),"data-testid":i,children:[e.jsxs("div",{className:"mb-3 flex items-center gap-1.5 text-xs font-semibold text-fg-muted",children:[e.jsx(s,{width:13,height:13}),t]}),e.jsxs("div",{className:"min-w-0 flex-1",children:["version"in f&&e.jsxs("span",{className:"mb-1 inline-block rounded-md bg-surface-active px-1.5 py-0.5 font-mono tabular text-2xs text-fg-muted",children:["v",f.version]}),e.jsx("h4",{className:"text-sm font-semibold text-fg",children:f.title}),e.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:f.body}),f.href!==void 0&&f.href!==""&&e.jsx("a",{href:f.href,target:"_blank",rel:"noreferrer",className:"focus-visible:focus-ring mt-2 inline-block rounded-md text-xs text-accent can-hover:hover:underline",children:"Read more →"})]},f.id),e.jsx(Zc,{index:b,count:n.length,backLabel:`Previous ${t} entry`,nextLabel:`Next ${t} entry`,onBack:()=>h(-1),onNext:()=>h(1),itemNoun:r})]})}const ne="https://paddock.edspencer.net",ra=[{id:"paste-a-screenshot-into-the-composer",title:"Paste a screenshot straight into the composer",body:"Ctrl+V or Cmd+V with the composer focused attaches whatever is on your clipboard, and dragging files onto it works too. A message with an attachment can be sent with no text at all.",href:`${ne}/using/sending-files-and-images/#three-ways-to-attach`},{id:"queue-a-message-mid-turn",title:"Type while Claude is still working",body:"A message typed during a turn is queued on the server and sent the moment that turn finishes, so it survives a reload and a closed tab. Pressing Stop hands it back to the composer rather than sending it.",href:`${ne}/using/working-in-chats/#type-while-a-turn-is-running-the-queue`},{id:"link-to-a-single-message",title:"Deep-link to one message in a chat",body:"Hover any settled message and click the small time and context chip: it copies a link to that exact message. Opening it loads the chat, scrolls to the message and flashes it.",href:`${ne}/using/working-in-chats/#hover-a-message-time-context-link-fork-and-rewind`},{id:"revert-rewinds-the-transcript",title:"Revert rewinds the chat, not the world",body:"Reverting a conversation back to a message removes the tail of the transcript, but files written, commits pushed and messages sent are not undone. The discarded tail is backed up rather than destroyed.",href:`${ne}/using/working-in-chats/#hover-a-message-time-context-link-fork-and-rewind`},{id:"your-first-message-names-the-chat",title:"Your first message names the chat",body:"The chat list shows your opening prompt in full, not a summary, so a chat is as findable later as that first line is descriptive. You can rename it afterwards from the row's hover actions.",href:`${ne}/using/working-in-chats/#start-a-chat`},{id:"shift-click-a-chat-family",title:"Shift-click acts on a whole family",body:"When a chat has spawned or forked children nested beneath it, Shift-clicking archive, delete or mark-read on its row applies to the whole subtree instead of just that one chat. The tooltip tells you how many it would hit.",href:`${ne}/using/working-in-chats/#nested-chats--a-fan-out-reads-as-a-tree`},{id:"close-the-laptop-mid-turn",title:"You can close the laptop mid-turn",body:"The turn keeps running on the server, and when you reconnect the client replays the frames you missed rather than restarting the stream. If you were away long enough for the buffer to age out, it re-reads the transcript instead.",href:`${ne}/using/working-in-chats/#resume-from-anywhere`},{id:"drafts-are-per-browser",title:"Drafts stay in the browser that typed them",body:"An unsent draft is kept per chat in local storage, so it is still there tomorrow — but it never follows you to another device. Read state, stars and archiving are server-side and do follow you.",href:`${ne}/using/working-in-chats/#the-composer`},{id:"search-reaches-archived-chats",title:"Chat search reaches archived chats",body:"The Search chats box filters on both name and first-message preview, and it looks inside the Archived section too. A match pulls its parent rows into view as scaffolding, and your folded state comes back when you clear the box.",href:`${ne}/using/working-in-chats/#search`},{id:"pin-a-file-as-a-tab",title:"Pin any file as a project tab",body:"From the Files tab you can pin a file at any depth, and it becomes a tab in the project header with its own URL. Nested pins show just the basename — hover for the full path.",href:`${ne}/using/reading-claudes-work/#pin-a-file-as-a-tab--at-any-depth`},{id:"commit-only-some-files",title:"Commit only some of the changes",body:"The Changes tab gives every changed file a checkbox, so you can commit a subset instead of everything at once. The projects grid also flags each project's uncommitted-file count before you open it.",href:`${ne}/using/reading-claudes-work/#review-and-commit-the-changes-tab`},{id:"ask-claude-to-send-a-file",title:"Ask Claude to send you a file",body:"Every turn can render a file inline in the chat — a chart, a screenshot, a generated report — rather than telling you a path you would have to go and open. Just ask for the file itself.",href:`${ne}/guides/agent-capabilities/#reach-where-an-agent-can-go`},{id:"curated-notes-is-the-only-managed-section",title:"CLAUDE.md has a section Paddock owns",body:"In a managed project the automatic curator rewrites only the body under the ## Curated notes heading. Everything you write above that heading is preserved verbatim, sweep after sweep.",href:`${ne}/concepts/sweeper/#what-it-produces`},{id:"the-sweeper-rewrites-whole-files",title:"OVERVIEW.md and CHANGELOG.md get rewritten",body:"Curation is a full-file rewrite, not an append, so hand edits to those two files can be reworded or dropped on the next sweep. Anything you want kept permanently belongs above the curated heading in CLAUDE.md, or in a file nothing curates.",href:`${ne}/concepts/sweeper/#what-it-produces`},{id:"steer-the-curator-with-a-file",title:"Steer the curator with one file",body:`Drop a .paddock/hooks/sweep.md into a project and its contents are appended to the curator's prompt every sweep — "always keep a Glossary section", say. It is git-tracked, has no UI, and changes only how the notes are written.`,href:`${ne}/using/automating-with-hooks/#steer-the-built-in-curator`},{id:"preload-context-is-a-composer-toggle",title:"Preload project context is on the composer",body:"The switch that feeds a project's curated OVERVIEW.md and CHANGELOG.md into a chat lives on the composer, not in Settings, and it only acts on the first turn of a new chat. On a brand-new project it sits disabled until the curator has written something.",href:`${ne}/using/creating-and-organizing-projects/#preload-project-context-in-the-composer-not-settings`},{id:"saving-settings-freezes-four-fields",title:"Saving Settings pins four fields",body:"The first save on a project's Settings tab writes model, permission mode, max turns and Docker into its project.yaml as concrete values, so they stop tracking the instance default. Drive mode, max spawn depth, offered models and the curation budgets keep inheriting.",href:`${ne}/using/creating-and-organizing-projects/#tune-the-agent-the-settings-tab`},{id:"a-projects-directory-is-permanent",title:"A project's directory can never move",body:"The working directory is baked into the path of every transcript, so it is fixed at creation and there is no re-point later. Moving the directory on disk strands that project's chat history.",href:`${ne}/concepts/projects/#axis-2--where-the-content-lives`},{id:"areas-are-not-a-fixed-list",title:"Areas are not a fixed list",body:"The Settings dropdown offers Homelab, House, Side Projects and Unsorted, but the field is a free-form string: set group: in a project's project.yaml to invent your own and the dropdown offers it from then on.",href:`${ne}/using/creating-and-organizing-projects/#organize-projects-into-areas`},{id:"new-triggers-start-disabled",title:"A new trigger is saved disabled",body:'Writing a schedule or an event hook never arms it — every trigger is created with enabled false and fires nothing until you flip it. "I created it and it never ran" is almost always this.',href:`${ne}/using/scheduling-recurring-work/#add-a-schedule-from-the-triggers-tab`},{id:"run-a-trigger-on-demand",title:"Fire a trigger now to test it",body:"Running a trigger by hand goes down the same path a real firing takes and works even while the trigger is still disabled. You never have to wait until 9am to find out whether the prompt was any good.",href:`${ne}/reference/schedules/#the-trigger-schema-schedule`},{id:"an-empty-tool-list-means-every-tool",title:"A schedule with no tool list gets everything",body:`Leaving a schedule's tool allow-list empty reads like "no tools" and means the opposite: the firing runs as the project's own agent with the full toolset, Bash included. Naming even one tool moves it onto its own scoped agent.`,href:`${ne}/guides/agent-capabilities/#scoped-agents-triggers-and-hooks`},{id:"trigger-prompts-can-live-in-git",title:"A trigger's prompt can live in git",body:"Instead of pasting text into the form, point a trigger at a .md file under the project's .paddock/triggers/ directory. It is read fresh on every firing, so a long runbook prompt can evolve in version control.",href:`${ne}/using/automating-with-hooks/#create-an-onarchive-hook`},{id:"accrete-into-one-session",title:"A schedule can remember its last run",body:'By default each firing starts a fresh chat. Turn on "accrete into one session" and every firing resumes the same chat instead, which is how a recurring job builds up context rather than starting from nothing each time.',href:`${ne}/concepts/schedules/#fresh-chat-vs-one-accreting-session`},{id:"your-user-claude-md-is-not-loaded",title:"Your own CLAUDE.md is not loaded",body:"By default Paddock borrows only your Claude Code login — your ~/.claude/CLAUDE.md, agents, commands and plugins are deliberately left out. Set claude.instructions: host in paddock.config.yaml to bring them in.",href:`${ne}/guides/what-paddock-touches/#turning-sharing-on`},{id:"host-claude-hooks-do-not-run",title:"Your Claude Code hooks do not run here",body:"Hooks configured in your own ~/.claude/settings.json are not executed inside Paddock turns unless you set claude.hooks: host. The rest of that file still applies either way.",href:`${ne}/configuration/config-file/#hooks`},{id:"declare-mcp-servers-to-paddock",title:"MCP servers must be declared to Paddock",body:"Running claude mcp add inside the instance attaches a server that can never be called: agents carry an explicit tool allow-list, and a server Paddock did not attach itself is refused silently. Declare it in the top-level mcpServers: block instead.",href:`${ne}/configuration/config-file/#mcpservers--the-servers-this-instance-declares-itself`},{id:"config-saves-need-a-restart",title:"Config is frozen at boot",body:"Instance config is resolved once at startup, so a save on the Config screen takes effect at the next restart rather than immediately. A field pinned by an environment variable renders read-only and names the variable that wins.",href:`${ne}/configuration/instance-settings/#2-an-environment-variable-wins-and-the-screen-tells-you`},{id:"dictation-is-one-variable-away",title:"Dictation is one variable away",body:"Set PADDOCK_WHISPER_ENDPOINT to a Whisper-compatible endpoint and a microphone button appears in the composer — nothing else needs configuring. Nothing in the UI hints the feature exists until it is set.",href:`${ne}/configuration/environment/#voice-dictation-whisper`},{id:"themes-are-per-browser",title:"Themes are yours, not the instance's",body:"Config → Appearance offers four themes and an accent picker that re-solves any colour you choose for readable contrast, and the choice is stored per browser. Two people on one instance can see completely different Paddocks.",href:`${ne}/configuration/appearance/#scope-per-browser-not-per-instance`},{id:"a-project-is-not-a-sandbox",title:"A project is not a security boundary",body:"Project agents have Bash and no confinement, so one can read and edit another project's files and notes. If two bodies of work need different trust levels, that means two Paddock instances, not two projects.",href:`${ne}/guides/agent-capabilities/#reach-where-an-agent-can-go`},{id:"root-chats-reach-every-project",title:"A root chat can reach every project",body:"Chats started from Home run with the whole projects directory as their working directory, which is both the point and a real step up in reach. Worth remembering before handing one a broad instruction.",href:`${ne}/using/working-in-chats/#project-chats-vs-root-chats`}],Re="https://paddock.edspencer.net/whats-new/",ia=[{id:"0-72-posture-profiles",version:"0.72",title:"One key for the whole posture",body:"One profile key — paranoid, balanced or yolo — sets an instance's security posture across the Claude sharing modes, spawn depth and capability toggles, without touching your port, bind address or auth.",href:`${Re}#072--one-key-for-the-whole-posture`},{id:"0-71-2-service-control",version:"0.71.2",title:"Service control",body:"An installed Paddock service restarts after any stop rather than only after a crash, and paddock service gained start, stop and restart, which wait for the URL to answer before claiming success.",href:`${Re}#0712--service-control`},{id:"0-71-1-front-door",version:"0.71.1",title:"The front door",body:"The root workspace's Home is the front door: Discovery sits inline while the instance is empty, and What's New and Tips cards each show one entry chosen at random.",href:`${Re}#0711--the-front-door`},{id:"0-71-0-stop-one-thing",version:"0.71.0",title:"Stop one thing, not everything",body:"Every row in the running-work bar has a ✕, and a Stop all appears once more than one thing is running — so a session with fifteen stray shells no longer has to be reaped whole.",href:`${Re}#0710--stop-one-thing-not-everything`},{id:"0-70-1-linked-directories",version:"0.70.1",title:"Linked directories, all the way through",body:"The Changes tab, the file browser and the Push button act on a linked project's own directory rather than on the backing store, so untracked files render and Push pushes the right repository.",href:`${Re}#0701--linked-directories-all-the-way-through`},{id:"0-70-inline-code",version:"0.70",title:"Inline code you can see",body:"Inline code in a chat message has its background back after a token change closed the contrast against the card underneath it to 1.04:1, and blockquotes have their colour again.",href:`${Re}#070--inline-code-you-can-see`},{id:"0-69-background-work",version:"0.69",title:"Background work you can see",body:"A bar above the composer names every background task still running, what it is doing and how long it has been going — and a chat with live work no longer reports itself idle.",href:`${Re}#069--background-work-you-can-see`},{id:"0-68-discover",version:"0.68",title:"Discover, and --here is gone",body:"Discover reads your Claude Code history and offers the directories you have actually been working in as projects, importing a directory without writing anything into it.",href:`${Re}#068--discover-and---here-is-gone`},{id:"0-67-themes-and-fleet-readout",version:"0.67",title:"A design system, four themes, and the fleet readout",body:"Four themes and an accent picker that solves any colour you pick for contrast, in Config under Appearance, plus a live strip above every screen saying what the fleet is doing.",href:`${Re}#067--a-design-system-four-themes-and-the-fleet-readout`},{id:"0-66-2-nothing-goes-missing",version:"0.66.2",title:"Nothing you typed goes missing",body:"Five ways work could quietly vanish are fixed: a file staged mid-turn no longer rides your next message, and reloading during a turn no longer discards the reply.",href:`${Re}#0662--nothing-you-typed-goes-missing`},{id:"0-66-1-queued-messages",version:"0.66.1",title:"Queued messages",body:"A message typed while a turn is running is held reliably, drains however that turn ends, merges rather than overwrites across two tabs, and comes back to the composer if you press Stop.",href:`${Re}#0661--queued-messages`},{id:"0-66-0-config-screen-and-port",version:"0.66.0",title:"Config screen, and a new default port",body:"The instance Config screen gained a section rail, a Modified-only lens and a filter that matches environment variable names — and the default port moved from 4000 to 7233.",href:`${Re}#0660--config-screen-and-a-new-default-port`}];function ed({project:t,root:s=!1,instanceEmpty:n=!1,onInstanceRecheck:r,running:i,unread:o,recent:l,attentionLoading:c,attentionError:m,changelog:u,overview:b,onOpenChat:f,onNewChat:h}){const j=!m&&!c&&i.length===0&&o.length===0&&l.length===0,x=s,N=s?n:!1,d=[ia.length,ra.length].filter(D=>D>0).length,g=N===!1;return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:$t("mx-auto px-6 py-6",x?"max-w-6xl":"max-w-3xl"),children:[N===!0&&e.jsx("section",{className:"mb-8","data-testid":"home-first-run",children:e.jsx(ji,{firstRun:!0,embedded:!0,onLeave:r,onStartChat:h})}),t.summary&&e.jsx("p",{className:"mb-6 text-sm text-fg-muted","data-testid":"home-summary",children:t.summary}),x&&d>0&&e.jsxs("div",{className:$t("mb-8 grid gap-4",d===2?"xl:grid-cols-2":""),children:[e.jsx(aa,{label:"What's New",icon:Mt,entries:ia,itemNoun:"Entry",testId:"home-whats-new"}),e.jsx(aa,{label:"Tips",icon:Xt,entries:ra,itemNoun:"Tip",testId:"home-tips-panel"})]}),g&&(m?e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(la,{label:"Running & Recent"}),e.jsx(oa,{onNewChat:h})]}),e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm text-danger",children:m})})]}):j?e.jsx("section",{className:"mb-8",children:e.jsx(Sa,{variant:"panel",icon:e.jsx(Yt,{width:22,height:22}),title:"No chats yet",body:"Nothing is running and nothing has happened here yet. Start a chat and it will appear here the moment it wants you.",action:e.jsx(fs,{variant:"primary",icon:e.jsx(rt,{width:14,height:14}),onClick:h,children:"New chat"})})}):e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[e.jsx(la,{label:"Running & Recent",detail:[i.length>0?`${i.length} running`:null,o.length>0?`${o.length} unread`:null]}),e.jsx(oa,{onNewChat:h})]}),e.jsx(td,{running:i,recent:l,unread:o,workspaceSlug:t.slug,loading:c,onOpenChat:f})]})),e.jsxs("div",{className:"grid items-start gap-x-6 xl:grid-cols-2",children:[e.jsx(da,{id:`${t.slug}:overview`,title:"OVERVIEW.md",body:b,emptyTitle:"No OVERVIEW.md yet",emptyBody:"The sweeper writes this after a chat — what this workspace is, and where the work has got to."},`${t.slug}:overview`),e.jsx(da,{id:`${t.slug}:changelog`,title:"CHANGELOG.md",body:u,emptyTitle:"No CHANGELOG.md yet",emptyBody:"The sweeper writes this after a chat — a running log of what actually changed."},`${t.slug}:changelog`)]}),e.jsxs("p",{className:"mt-6 text-2xs text-fg-subtle",children:["Project directory: ",e.jsx("span",{className:"font-mono",children:t.dir})]})]})})}function oa({onNewChat:t}){return e.jsx(fs,{variant:"subtle",size:"sm",className:"-mr-1 shrink-0 whitespace-nowrap",icon:e.jsx(rt,{width:13,height:13}),onClick:t,children:"New chat"})}function la({label:t,detail:s=[]}){const n=s.filter(r=>!!r);return e.jsxs("h3",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 text-sm font-semibold uppercase tracking-wide text-fg-muted",children:[e.jsx("span",{className:"whitespace-nowrap",children:t}),n.length>0&&e.jsx("span",{className:"whitespace-nowrap font-normal normal-case tracking-normal text-fg-subtle",children:n.join(" · ")})]})}const ca=10;function ds(t){const s=Date.parse(t.updatedAt??""),n=Date.parse(t.lastTurnCompletedAt??"");return Math.max(Number.isFinite(s)?s:0,Number.isFinite(n)?n:0)}function td({running:t,recent:s,unread:n,workspaceSlug:r,loading:i,onOpenChat:o}){const[l,c]=a.useState(!1),m=d=>`${d.projectSlug}:${d.sessionId}`,u=new Set(n.map(m)),b=new Set(s.map(m)),f=[...s,...n.filter(d=>!b.has(m(d)))].sort((d,g)=>ds(g)-ds(d));if(i&&t.length===0&&f.length===0)return e.jsx("div",{className:"h-[52px] animate-pulse rounded-2xl border border-edge bg-surface-raised","aria-busy":"true"});const h=[...t].sort((d,g)=>(be.turnStartedAt(d.sessionId)??1/0)-(be.turnStartedAt(g.sessionId)??1/0)),j=l?f:f.slice(0,ca),x=f.length-j.length,N=[...h.map(d=>({chat:d,state:"running"})),...j.map(d=>({chat:d,state:u.has(m(d))?"unread":"read"}))];return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-edge","data-testid":"home-attention-chats",children:[N.map(({chat:d,state:g},D)=>e.jsxs("button",{"data-state":g,onClick:()=>o(d.sessionId,d.projectSlug),className:$t("flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover",D>0&&"border-t border-edge"),children:[g==="running"?e.jsx("span",{title:"Streaming a response…","aria-label":"running",className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-accent-solid"}):g==="unread"?e.jsx("span",{title:"Unread reply","aria-label":"unread",className:"h-1.5 w-1.5 shrink-0 rounded-full bg-warn-solid"}):e.jsx("span",{className:"h-1.5 w-1.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:$t("min-w-0 flex-1 truncate text-sm",g==="read"?"text-fg-muted":"font-medium text-fg"),children:d.name}),d.projectSlug!==r&&e.jsx("span",{className:"shrink-0 truncate rounded-md bg-surface-active px-1.5 py-0.5 text-2xs text-fg-muted",children:d.projectName}),e.jsx("span",{className:$t("w-16 shrink-0 text-right text-2xs",g==="running"?"font-medium text-accent":"text-fg-subtle"),children:g==="running"?"running":ds(d)>0?Et(new Date(ds(d)).toISOString()):""})]},m(d))),(x>0||l)&&f.length>ca&&e.jsx("button",{type:"button",onClick:()=>c(d=>!d),className:"flex w-full items-center justify-center border-t border-edge px-3 py-2 text-2xs font-medium text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg",children:l?"Show fewer":`Show ${x} more`})]})}function da({id:t,title:s,body:n,emptyTitle:r,emptyBody:i}){const[o,l]=sd(t),c=!o,m=n.trim().length>0;return e.jsxs("section",{className:"mb-8",children:[e.jsxs("button",{type:"button",onClick:l,"aria-expanded":c,className:"mb-2 -ml-1 flex w-full items-center gap-1.5 rounded-lg px-1 py-1 text-left transition-colors hover:bg-surface-hover",children:[e.jsx(At,{width:14,height:14,className:`shrink-0 text-fg-subtle transition-transform ${c?"rotate-90":""}`}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wide text-fg-muted",children:s})]}),c&&(m?e.jsx("div",{className:"card",children:e.jsx(Zt,{children:n})}):e.jsx(Sa,{title:r,body:i}))]})}function sd(t){const s=`paddock:home-collapsed:${t}`,[n,r]=a.useState(()=>{try{return localStorage.getItem(s)==="1"}catch{return!1}});return[n,()=>r(o=>{const l=!o;try{localStorage.setItem(s,l?"1":"0")}catch{}return l})]}const nn=8,an=2*Math.PI*nn,nd=.25*an;function ua({tokens:t,limit:s,usage:n,size:r=14,working:i=!1}){const o=t!=null&&s!=null&&s>0;if(!o&&!i)return null;const l=o?Math.min(100,Math.max(0,t/s*100)):0,c=o&&l>=80,m=o?l/100*an:nd,u=o?Math.round(t/1e3):0,b=o?Math.round(s/1e3):0,f=n?`
|
|
12
|
+
Session so far: ${ba(n)}`:"",h=i?o?`Streaming a response… — context window ${Math.round(l)}% full (${t.toLocaleString()} / ${s.toLocaleString()} tokens)`:"Streaming a response…":`Context window ${Math.round(l)}% full as of the last completed turn (${t.toLocaleString()} / ${s.toLocaleString()} tokens)${f}`,j=i?o?`Streaming a response… (context ${Math.round(l)}% full)`:"Streaming a response…":`Context ${Math.round(l)}% full (${u}k of ${b}k tokens)`;return e.jsx("span",{className:"inline-flex shrink-0 items-center",title:h,"aria-label":j,children:e.jsxs("svg",{width:r,height:r,viewBox:"0 0 20 20",className:i?"spin-eco":"-rotate-90",role:"img","aria-hidden":"true",children:[e.jsx("circle",{cx:"10",cy:"10",r:nn,fill:"none",strokeWidth:"3",className:"stroke-edge"}),e.jsx("circle",{cx:"10",cy:"10",r:nn,fill:"none",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:`${m} ${an}`,className:c?"stroke-[var(--warn-solid)]":"stroke-[var(--accent-solid)]"})]})})}function ad({provenance:t,hookName:s,className:n=""}){const r=t==null?void 0:t.origin;if(r!=="scheduled"&&r!=="spawned"&&r!=="hook"&&r!=="adopted")return null;if(r==="adopted")return e.jsx("span",{"data-provenance":"adopted","aria-label":"Adopted chat",title:"Adopted — this chat came from your Claude Code CLI history",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-success ${n}`,children:e.jsx(Jt,{width:12,height:12})});if(r==="hook"){const l=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:l,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-info ${n}`,children:e.jsx(Mt,{width:12,height:12})})}if(r==="scheduled")return e.jsx("span",{"data-provenance":"scheduled","aria-label":"Scheduled chat",title:"Scheduled — a schedule started this chat",className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-warn ${n}`,children:e.jsx(Je,{width:12,height:12})});const i=(t==null?void 0:t.depth)??0,o=i>1?` (${i} levels deep)`:"";return e.jsx("span",{"data-provenance":"spawned","aria-label":"Spawned chat",title:`Spawned — another chat created this one${o}`,className:`flex h-4 w-4 shrink-0 items-center justify-center rounded text-lineage ${n}`,children:e.jsx(ft,{width:12,height:12})})}function rd({activeTotal:t,shownCount:s,searching:n,runningCount:r,runningOnly:i,setRunningOnly:o}){const l=n?`${s}/${t}`:`${t}`,c=n?`${s} of ${t} chats shown`:`${t} chats`;return r===0&&!i?e.jsx("span",{className:"text-2xs text-fg-subtle",title:c,children:l}):e.jsxs("span",{role:"group","aria-label":"Chat count and running filter",className:"flex items-stretch overflow-hidden rounded-full border border-edge-strong text-2xs leading-none",children:[e.jsx(pe,{content:i?"Show all chats":c,className:"items-stretch",children:e.jsx("button",{type:"button",onClick:()=>o(!1),"aria-pressed":!i,"aria-label":i?`Show all ${t} chats`:`${t} chats`,className:`h-full px-1.5 py-0.5 transition-colors ${i?"text-fg-subtle hover:bg-surface-hover hover:text-fg":"bg-surface-active font-medium text-fg-muted"}`,children:l})}),e.jsx(pe,{content:i?"Showing only running chats — click to show all":`Show only the ${r} chat${r===1?"":"s"} running now`,className:"items-stretch",children:e.jsxs("button",{type:"button",onClick:()=>o(!i),"aria-pressed":i,"aria-label":`Show only running chats (${r} running)`,className:`flex h-full items-center gap-1 border-l border-edge-strong px-1.5 py-0.5 transition-colors ${i?"bg-accent-solid font-semibold text-accent-fg":"font-medium text-accent hover:bg-accent-soft"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`h-2.5 w-2.5 rounded-full border-[1.5px] border-current ${r>0?"spin-eco border-t-transparent":"opacity-60"}`}),r]})})]})}function id({nested:t,setNested:s,runningOnly:n}){const r=t?"Switch to a flat chat list":"Switch to a nested chat list";return e.jsx(pe,{content:n?"Running-only view is always flat":r,children:e.jsx("button",{type:"button",onClick:()=>s(!t),disabled:n,"aria-label":r,"aria-pressed":t,className:"btn-subtle h-9 w-9 shrink-0 p-0 disabled:cursor-not-allowed disabled:opacity-40",children:t?e.jsx(_r,{width:16,height:16,className:"mx-auto"}):e.jsx(xa,{width:16,height:16,className:"mx-auto"})})})}function Ws(t){return`${t} nested chat${t===1?"":"s"}`}const od=4,ld=new Set;function cd({chatList:t,sessionsOpen:s,setSessionsOpen:n,chatSearch:r,setChatSearch:i,searching:o,newChat:l,view:c,activeSession:m,pendingChat:u,chats:b,fallbackChat:f,visibleChats:h,activeChats:j,archivedChats:x,activeTotal:N,runningCount:d,viewPrefs:g,archivedOpen:D,setArchivedOpen:$,collapsedChats:I,toggleChatCollapsed:C,openChat:S,unread:M,usageBySession:y,runningSessions:T,onForkChat:w,setPromotingChat:F,renameChat:O,archiveChat:z,requestDeleteChat:J,starChat:L,toggleUnread:v,detachChat:A,adoptableCount:W,adopting:Q,adoptChats:ie}){const K=o?ld:I,q=j.some(E=>E.children.length>0)||x.some(E=>E.children.length>0),k=tn(j),U=tn(x),Z=(E,H)=>{var se,Ve,De,$e;const de=(H==null?void 0:H.depth)??0,we=(H==null?void 0:H.children.length)??0,le=(H==null?void 0:H.descendantCount)??0,he=M.has(E.sessionId),ke=K.has(E.sessionId),Ue=!!H&&le>0,Ae=X=>Ue&&X.shiftKey?Bc(H):[E.sessionId],re=le+1,Be=(X,me)=>Ue?e.jsxs(e.Fragment,{children:[X," · ",e.jsx("span",{className:"font-semibold",children:"Shift-click"})," to ",me]}):X,ve=(X,me)=>Ue?`${X} (Shift-click to ${me})`:X,Te=6+(de>0?1:0)+(F?1:0);return e.jsxs("div",{className:`group/chat chat-row chat-row--actions-${Te} relative mb-0.5 flex rounded-lg transition-colors ${m===E.sessionId&&c==="chat"?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[Array.from({length:Math.min(de,od)},(X,me)=>e.jsx("div",{"aria-hidden":"true",className:"w-3 shrink-0 border-l border-edge"},me)),q&&e.jsx("div",{className:"flex w-4 shrink-0 items-start justify-center pt-2.5",children:we>0&&e.jsx(pe,{content:ke?`Show ${Ws(le)}`:"Hide nested chats",children:e.jsx("button",{type:"button","aria-label":`${ke?"Expand":"Collapse"} ${le} chat${le===1?"":"s"} under ${E.name}`,"aria-expanded":!ke,onClick:X=>{X.stopPropagation(),C(E.sessionId)},className:"flex h-4 w-4 items-center justify-center rounded text-fg-subtle transition hover:bg-surface-active hover:text-fg",children:e.jsx(Qs,{width:11,height:11,className:`transition-transform ${ke?"-rotate-90":""}`})})})}),e.jsxs("button",{type:"button",onClick:()=>S(E.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 ${q?"pl-1":"pl-2.5"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-1.5",children:[he&&e.jsx(pe,{content:"New reply you haven't read yet",className:"shrink-0",children:e.jsx("span",{"data-unread":"true","aria-label":"Unread reply",className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent-solid"})}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${he?"font-semibold":"font-medium"}`,children:E.name}),ke&&le>0&&e.jsx(pe,{content:`${Ws(le)} hidden`,className:"shrink-0",children:e.jsx("span",{className:"shrink-0 rounded-full bg-surface-active px-1.5 text-3xs font-medium leading-4 text-fg-muted",children:le})}),!(de>0&&((se=E.provenance)==null?void 0:se.origin)==="spawned")&&e.jsx(ad,{provenance:E.provenance,hookName:(Ve=E.trigger)==null?void 0:Ve.name}),e.jsx(ua,{tokens:((De=y[E.sessionId])==null?void 0:De.contextTokens)??E.contextTokens,limit:(($e=y[E.sessionId])==null?void 0:$e.contextLimit)??E.contextLimit,usage:Fr(y[E.sessionId]??E),working:T.has(E.sessionId)})]}),e.jsx("span",{className:"chat-row-time text-2xs leading-5 text-fg-subtle",children:Et(E.updatedAt)})]}),e.jsxs("div",{className:"absolute bottom-1 right-1.5 flex items-center gap-0.5",children:[de>0&&e.jsx(pe,{content:le>0?`Detach from parent — move this chat and its ${Ws(le)} to the top level`:"Detach from parent — move this chat to the top level",children:e.jsx("button",{type:"button","aria-label":`Detach chat ${E.name} from its parent`,onClick:X=>{X.stopPropagation(),A(E)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Or,{width:13,height:13})})}),e.jsx(pe,{content:"Fork chat — branch a new chat from this one's context",children:e.jsx("button",{type:"button","aria-label":`Fork chat ${E.name}`,onClick:X=>{X.stopPropagation(),w(E)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(ft,{width:13,height:13})})}),F&&e.jsx(pe,{content:"Promote into a new project — give this chat a home of its own",children:e.jsx("button",{type:"button","aria-label":`Promote chat ${E.name} into a project`,onClick:X=>{X.stopPropagation(),F(E)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(rt,{width:13,height:13})})}),e.jsx(pe,{content:"Rename chat",children:e.jsx("button",{type:"button","aria-label":`Rename chat ${E.name}`,onClick:X=>{X.stopPropagation(),O(E)},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-fg focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(bs,{width:13,height:13})})}),e.jsx(pe,{content:Be(E.archived?"Unarchive chat":"Archive chat — file it away without deleting",E.archived?`unarchive all ${re}`:`archive all ${re}`),children:e.jsx("button",{type:"button","aria-label":ve(`${E.archived?"Unarchive":"Archive"} chat ${E.name}`,E.archived?`unarchive all ${re}`:`archive all ${re}`),onClick:X=>{X.stopPropagation(),z(E,Ae(X))},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-surface-active hover:text-accent ${E.archived?"text-accent opacity-100":"text-fg-subtle opacity-0"}`,children:e.jsx(Ur,{width:13,height:13})})}),e.jsx(pe,{content:Be("Delete chat",`delete all ${re}`),children:e.jsx("button",{type:"button","aria-label":ve(`Delete chat ${E.name}`,`delete all ${re}`),onClick:X=>{X.stopPropagation(),J(E,Ae(X))},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-danger-soft hover:text-danger focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(js,{width:13,height:13})})}),e.jsx(pe,{content:Be(he?"Mark as read":"Mark as unread — resurface it later",he?`mark all ${re} read`:`mark all ${re} unread`),children:e.jsx("button",{type:"button","aria-label":ve(`Mark chat ${E.name} ${he?"read":"unread"}`,he?`mark all ${re} read`:`mark all ${re} unread`),"aria-pressed":he,onClick:X=>{X.stopPropagation(),v(E,Ae(X))},className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle opacity-0 transition hover:bg-surface-active hover:text-accent focus:opacity-100 group-hover/chat:opacity-100",children:e.jsx(Br,{width:13,height:13,open:!he})})}),e.jsx(pe,{content:E.starred?"Unstar chat":"Star chat — pin it to the top of the list",children:e.jsx("button",{type:"button","aria-label":`${E.starred?"Unstar":"Star"} chat ${E.name}`,"aria-pressed":!!E.starred,onClick:X=>{X.stopPropagation(),L(E)},className:`flex h-6 w-6 items-center justify-center rounded-md transition focus:opacity-100 group-hover/chat:opacity-100 hover:bg-surface-active hover:text-warn ${E.starred?"text-warn opacity-100":"text-fg-subtle opacity-0"}`,children:e.jsx(Vr,{width:13,height:13,fill:E.starred?"currentColor":"none"})})})]})]},E.sessionId)};return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"fixed inset-0 z-20 bg-overlay lg:hidden","aria-hidden":"true",onClick:()=>n(!1)}),e.jsxs("div",{style:t.style,className:`fixed inset-y-0 left-0 z-30 flex w-64 max-w-[80%] shrink-0 flex-col border-r border-edge bg-surface-raised shadow-2xl transition-transform duration-200 ease-out lg:relative lg:z-auto lg:max-w-none lg:translate-x-0 lg:bg-surface-raised/40 lg:shadow-none ${s?"translate-x-0":"-translate-x-full"}`,children:[t.isDesktop&&e.jsx(Lr,{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(va,{width:15,height:15,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-subtle"}),e.jsx("input",{type:"text",value:r,onChange:E=>i(E.target.value),placeholder:"Search","aria-label":"Search chats",className:`input py-1.5 pl-8 ${o?"pr-8":"pr-2"}`}),o&&e.jsx(pe,{content:"Clear search",className:"absolute right-1.5 top-1/2 -translate-y-1/2",children:e.jsx("button",{type:"button",onClick:()=>i(""),"aria-label":"Clear search",className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-subtle transition hover:bg-surface-active hover:text-fg",children:e.jsx(Oe,{width:13,height:13})})})]}),e.jsx(id,{nested:g.nested,setNested:g.setNested,runningOnly:g.runningOnly}),e.jsx(pe,{content:"New chat",children:e.jsx("button",{type:"button",className:"btn-primary h-9 w-9 shrink-0 p-0",onClick:l,"aria-label":"New Chat",children:e.jsx(rt,{width:16,height:16})})}),e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close chats",className:"btn-subtle shrink-0 px-2 py-2 lg:hidden",children:e.jsx(Oe,{width:16,height:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[W>0&&e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("button",{type:"button",onClick:ie,disabled:Q,"aria-label":`Adopt ${W} native Claude Code chat${W===1?"":"s"} into this workspace`,"aria-haspopup":"dialog",className:"btn-ghost w-full justify-start py-1.5 text-xs",children:[e.jsx(Jt,{width:13,height:13,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Q?"Adopting…":`Adopt ${W} native chat${W===1?"":"s"}…`})]})}),e.jsxs("div",{className:"mb-1 flex items-center justify-between pr-3",children:[e.jsx("span",{className:"section-label",children:"Chats"}),(N>0||g.runningOnly)&&e.jsx(rd,{activeTotal:N,shownCount:k,searching:o,runningCount:d,runningOnly:g.runningOnly,setRunningOnly:g.setRunningOnly})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:[m===null&&c==="chat"&&!u&&e.jsxs("div",{className:"mb-0.5 flex items-center gap-1.5 rounded-lg bg-surface-selected px-2.5 py-2 text-sm",children:[e.jsx(Yt,{width:13,height:13,className:"text-fg-muted"}),e.jsx("span",{className:"font-medium italic text-fg-muted",children:"New chat…"})]}),u&&!b.some(E=>E.sessionId===u)&&e.jsx("div",{className:`group/chat relative mb-0.5 rounded-lg transition-colors ${m===u&&c==="chat"?"bg-surface-selected":"hover:bg-surface-hover"}`,children:e.jsxs("button",{onClick:()=>S(u),className:"flex w-full items-center gap-1.5 rounded-lg px-2.5 py-2 text-left text-sm",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-medium italic text-fg-muted",children:"New chat…"}),e.jsx(ua,{working:!0})]})}),f&&Z(f),b.length===0&&!f&&e.jsx("p",{className:"px-2 py-2 text-sm text-fg-muted",children:"No saved chats yet. Send a message to start one."}),b.length>0&&g.runningOnly&&d===0&&e.jsxs("p",{className:"px-2 py-2 text-sm text-fg-muted",children:["No chats are running."," ",e.jsx("button",{type:"button",onClick:()=>g.setRunningOnly(!1),className:"text-accent underline underline-offset-2 hover:no-underline",children:"Show all chats"})]}),b.length>0&&(!g.runningOnly||d>0)&&o&&h.length===0&&!f&&e.jsxs("p",{className:"px-2 py-2 text-sm text-fg-muted",children:["No chats match “",r.trim(),"”."]}),b.length>0&&!g.runningOnly&&!o&&j.length===0&&!f&&e.jsx("p",{className:"px-2 py-2 text-sm text-fg-muted",children:"No active chats — see Archived below."}),ta(j,K).map(E=>Z(E.chat,E))]}),x.length>0&&e.jsxs("div",{className:`flex flex-col border-t border-edge ${D?"min-h-0 flex-1":"shrink-0"}`,children:[e.jsxs("button",{type:"button",onClick:()=>$(E=>!E),"aria-expanded":D,className:"flex w-full items-center gap-1.5 px-3 py-2 text-left text-xs font-medium uppercase tracking-wide text-fg-muted transition-colors hover:bg-surface-hover",children:[e.jsx(Qs,{width:14,height:14,className:`shrink-0 transition-transform ${D?"":"-rotate-90"}`}),e.jsx("span",{children:"Archived"}),e.jsx("span",{className:"ml-auto rounded-full bg-surface-active px-1.5 py-0.5 text-3xs font-semibold normal-case text-fg-muted",children:U})]}),D&&e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-2",children:ta(x,K).map(E=>Z(E.chat,E))})]})]})]})]})}function ms(t=document){return t.visibilityState==="hidden"}function dd(t){return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)}const ud=()=>!ms(),hd=()=>!0;function md(){return a.useSyncExternalStore(dd,ud,hd)}function fd({slug:t,chats:s,view:n,activeSession:r,runningSessions:i,onSeen:o,onManySeen:l}){const[c,m]=a.useState(new Set),[u,b]=a.useState(0),[f,h]=a.useState(null),j=md(),x=a.useCallback(($,I)=>{const C=Date.now(),S=(I==null?void 0:I.keepUnread)===!0,M=En($,C),y=S?{keepUnread:!0}:void 0;B.markChatSeen(t,$,C,y).catch(()=>{Rn($,M,C),b(T=>T+1)}),S||o==null||o($),S||h(T=>(T==null?void 0:T.id)===$?null:T),m(T=>{if(!T.has($))return T;const w=new Set(T);return w.delete($),w}),b(T=>T+1)},[t,o]),N=a.useCallback($=>{if($.length<=1){$[0]&&x($[0]);return}const I=Date.now(),C=$.map(y=>[y,En(y,I)]),S=$.filter(y=>c.has(y)),M=l==null?void 0:l($);m(y=>{if(!S.length)return y;const T=new Set(y);for(const w of S)T.delete(w);return T}),b(y=>y+1),B.markChatsUnread(t,$,!1).catch(()=>{for(const[y,T]of C)Rn(y,T,I);S.length&&m(y=>{const T=new Set(y);for(const w of S)T.add(w);return T}),M==null||M(),b(y=>y+1)})},[t,l,x,c]);a.useEffect(()=>{for(const $ of s)zr($.sessionId,$.lastSeen);b($=>$+1)},[s]);const d=a.useMemo(()=>{const $=new Set;for(const I of s){if(n==="chat"&&I.sessionId===r&&(f==null?void 0:f.id)!==I.sessionId)continue;if(I.unread||c.has(I.sessionId)){$.add(I.sessionId);continue}const C=I.lastTurnCompletedAt?Date.parse(I.lastTurnCompletedAt):NaN;Number.isFinite(C)&&C>Hr(I.sessionId)&&$.add(I.sessionId)}return $},[s,n,r,c,u,f]),g=a.useCallback(($,I)=>{h(C=>(C==null?void 0:C.id)===$?C.keepUnread&&!I?{id:$,keepUnread:I}:C:{id:$,keepUnread:I})},[]);a.useEffect(()=>{n!=="chat"||!r||(ms()?g(r,!1):x(r))},[n,r,x,g]),a.useLayoutEffect(()=>{if(!f)return;const $=n==="chat"&&f.id===r;$&&ms()||(h(I=>I===f?null:I),$&&x(f.id,f.keepUnread?{keepUnread:!0}:void 0))},[f,j,n,r,x]);const D=a.useRef(new Set);return a.useEffect(()=>{const $=D.current;for(const I of $)i.has(I)||(n==="chat"&&I===r&&ms()?(m(C=>C.has(I)?C:new Set(C).add(I)),g(I,!0)):n==="chat"&&I===r?x(I,{keepUnread:!0}):m(C=>C.has(I)?C:new Set(C).add(I)));D.current=i},[i,n,r,x,g]),{markSeen:x,markManySeen:N,unread:d}}const xd=250,gd=2500,pd=3e4;function bd(t,s){const[n,r]=a.useState([]),[i,o]=a.useState([]),[l,c]=a.useState([]),[m,u]=a.useState(!0),[b,f]=a.useState(null),h=a.useRef(0),j=a.useCallback(async()=>{const d=++h.current;try{const g=await B.attentionChats(t);if(d!==h.current)return;r(g.running),o(g.unread),c(g.recent??[]),f(null)}catch(g){if(d!==h.current)return;f(g instanceof Error?g.message:"Failed to load chats")}finally{d===h.current&&u(!1)}},[t]),x=a.useRef(j);x.current=j;const N=a.useRef(!1);return a.useEffect(()=>{N.current=!1,r([]),o([]),c([]),u(!0),j()},[t,j]),a.useEffect(()=>{if(!N.current){N.current=!0;return}const d=setTimeout(()=>void x.current(),xd),g=setTimeout(()=>void x.current(),gd);return()=>{clearTimeout(d),clearTimeout(g)}},[s]),a.useEffect(()=>{const d=()=>{document.visibilityState==="visible"&&x.current()},g=setInterval(d,pd);return document.addEventListener("visibilitychange",d),()=>{clearInterval(g),document.removeEventListener("visibilitychange",d)}},[]),{running:n,unread:i,recent:l,loading:m,error:b,refresh:()=>void j()}}function jd({adopted:t,skipped:s}){const n=t.length;if(n===0&&s.length===0)return"Nothing to adopt — no native chats were found.";const r=n===0?"Adopted nothing":`Adopted ${n} chat${n===1?"":"s"}`;if(s.length===0)return r;const i=[...new Set(s.map(l=>l.reason).filter(Boolean))],o=i.length===1?` (${i[0]})`:"";return`${r} — skipped ${s.length}${o}`}function wd(t,s){const[n,r]=a.useState(0),[i,o]=a.useState(!1),[l,c]=a.useState(null),[m,u]=a.useState(!1),[b,f]=a.useState(null),h=a.useCallback(()=>f(null),[]),j=a.useCallback(async()=>{const d=await B.getAdoptableChats(t).catch(()=>null);r((d==null?void 0:d.count)??0),c(d)},[t]),x=a.useCallback(async d=>{f(null);try{const g=await B.unadoptChats(t,{sessionIds:d});await s(),await j(),f(g.released.length>0?{message:`Removed ${g.released.length} adopted chat${g.released.length===1?"":"s"}.`,tone:"success"}:{message:"Nothing left to undo.",tone:"error"})}catch(g){f({message:g instanceof Error?g.message:"Failed to undo the adoption",tone:"error"})}},[t,s,j]),N=a.useCallback(async d=>{if(!i){o(!0);try{const g=await B.adoptChats(t,{sessionIds:d});u(!1),await s(),await j();const D=g.adopted.length===0&&g.skipped.length>0;f({message:jd(g),tone:D?"error":"success",action:g.adopted.length>0?{label:"Undo",onAct:()=>void x(g.adopted)}:void 0})}catch(g){f({message:g instanceof Error?g.message:"Failed to adopt native chats",tone:"error"})}finally{o(!1)}}},[i,t,s,j,x]);return a.useEffect(()=>{r(0),c(null),u(!1),f(null),j()},[j]),{adoptableCount:n,adopting:i,adoptable:l,adoptOpen:m,setAdoptOpen:u,confirmAdopt:N,toast:b,dismissToast:h}}function vd({slug:t,base:s,activeSession:n,navigate:r,chats:i,setChats:o,setLoadErr:l,setArchivedOpen:c,unread:m,markManySeen:u}){const[b,f]=a.useState(null),[h,j]=a.useState(null),x=a.useCallback(async()=>{if(!h)return;const{ids:C}=h;let S;if(C.length===1)await B.deleteProjectChat(t,C[0]),S=C;else{const y=await B.deleteProjectChats(t,C);S=y.removed,y.failed.length&&l(`Deleted ${y.removed.length} of ${C.length} chats — ${y.failed.length} could not be removed.`)}const M=new Set(S);Wr(S),o(y=>y.filter(T=>!M.has(T.sessionId))),n&&M.has(n)&&r(`${s}/chat`,{replace:!0}),j(null)},[h,t,s,n,r]),N=a.useCallback((C,S)=>{const M=i.filter(w=>!!w.archived==!!C.archived),y=new Set(S),T=Vc(M,C.sessionId).filter(w=>!y.has(w)).length;j({chat:C,ids:S,orphanCount:T})},[i]),d=a.useCallback(async(C,S)=>{await B.renameProjectChat(t,C.sessionId,S),o(M=>M.map(y=>y.sessionId===C.sessionId?{...y,name:S||y.preview||y.sessionId.slice(0,8)}:y))},[t]),g=a.useCallback(async(C,S)=>{const M=!C.archived,y=new Set(S);o(T=>T.map(w=>y.has(w.sessionId)?{...w,archived:M}:w)),M&&c(!0);try{S.length===1?await B.archiveProjectChat(t,S[0],M):await B.archiveProjectChats(t,S,M)}catch(T){o(w=>w.map(F=>y.has(F.sessionId)?{...F,archived:C.archived}:F)),l(T instanceof Error?T.message:"Failed to archive chat")}},[t]),D=a.useCallback(async C=>{const S=C.parent;if(S){o(M=>M.map(y=>y.sessionId===C.sessionId?{...y,parent:void 0}:y));try{await B.detachProjectChat(t,C.sessionId,!0)}catch(M){o(y=>y.map(T=>T.sessionId===C.sessionId?{...T,parent:S}:T)),l(M instanceof Error?M.message:"Failed to detach chat")}}},[t]),$=a.useCallback(async C=>{const S=!C.starred;o(M=>M.map(y=>y.sessionId===C.sessionId?{...y,starred:S}:y));try{await B.starProjectChat(t,C.sessionId,S)}catch(M){o(y=>y.map(T=>T.sessionId===C.sessionId?{...T,starred:C.starred}:T)),l(M instanceof Error?M.message:"Failed to star chat")}},[t]),I=a.useCallback(async(C,S)=>{if(m.has(C.sessionId)){u(S);return}const M=new Set(S),y=new Map(i.filter(T=>M.has(T.sessionId)).map(T=>[T.sessionId,T.unread]));o(T=>T.map(w=>M.has(w.sessionId)?{...w,unread:!0}:w));try{S.length===1?await B.markChatUnread(t,S[0],!0):await B.markChatsUnread(t,S,!0)}catch(T){o(w=>w.map(F=>M.has(F.sessionId)?{...F,unread:y.get(F.sessionId)}:F)),l(T instanceof Error?T.message:"Failed to mark chat unread")}},[m,u,t,i]);return{deletingChat:h,setDeletingChat:j,confirmDeleteChat:x,requestDeleteChat:N,renamingChat:b,setRenamingChat:f,commitRename:d,archiveChat:g,detachChat:D,starChat:$,toggleUnread:I}}function yd({open:t,chatName:s,onClose:n,onFork:r}){const i=`Fork of ${s}`,[o,l]=a.useState(i),c=a.useRef(null);if(a.useEffect(()=>{if(t){l(i);const u=c.current;u&&(u.focus(),u.select(),u.scrollLeft=0)}},[t,s]),ws(t,n),!t)return null;const m=u=>{u.preventDefault(),r(o.trim()||i)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:n,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:u=>u.stopPropagation(),onSubmit:m,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Fork chat"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Oe,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Branches a new chat from this one — the parent's full history comes along and stays resumable. Name the fork, then continue it independently."}),e.jsxs("label",{className:"mb-5 block",children:[e.jsx("span",{className:"field-label",children:"Fork name"}),e.jsx("input",{ref:c,autoFocus:!0,className:"input",value:o,onChange:u=>l(u.target.value),placeholder:i})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:n,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:"Fork"})]})]})})}function kd({open:t,chatName:s,resetName:n,onClose:r,onRename:i}){const[o,l]=a.useState(s),c=a.useRef(null);if(a.useEffect(()=>{if(!t)return;l(s);const f=c.current;f&&(f.focus(),f.select())},[t,s]),ws(t,r),!t)return null;const m=o.trim(),u=m==="",b=f=>{f.preventDefault(),i(u?null:m)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:r,children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:f=>f.stopPropagation(),onSubmit:b,role:"dialog","aria-modal":"true","aria-label":"Rename chat",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Rename chat"}),e.jsx("button",{type:"button",onClick:r,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Oe,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Renaming only changes how this chat is labelled in the sidebar — the transcript, its id, and its history are untouched."}),e.jsxs("label",{className:"mb-2 block",children:[e.jsx("span",{className:"field-label",children:"Chat name"}),e.jsx("input",{ref:c,autoFocus:!0,className:"input",value:o,onChange:f=>l(f.target.value),placeholder:n||"Chat name"})]}),e.jsx("p",{className:"mb-5 text-xs text-fg-subtle","data-testid":"rename-hint",children:u?e.jsxs(e.Fragment,{children:["Clearing the name resets it to",n?e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"font-medium text-fg-muted",children:n}),"."]}):" the chat's generated name."]}):"Clear the box to reset it to the generated name."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:r,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",children:u?"Reset name":"Rename"})]})]})})}function Nd({open:t,slug:s,sessionId:n,defaultName:r,onClose:i,onPromoted:o}){const[l,c]=a.useState(r??""),[m,u]=a.useState(""),[b,f]=a.useState(""),[h,j]=a.useState(""),[x,N]=a.useState(!1),[d,g]=a.useState(null);if(a.useEffect(()=>{t&&(c(r??""),u(""),f(""),j(""),g(null))},[t,r]),ws(t&&!x,i),!t)return null;const D=async $=>{if($.preventDefault(),!!l.trim()){N(!0),g(null);try{const{project:I,promoted:C}=await B.promoteChat(s,n,{name:l.trim(),group:h||void 0,summary:m.trim()||void 0,domain:b.split(",").map(S=>S.trim()).filter(Boolean)});o(I,C)}catch(I){g(I instanceof je?I.message:"Failed to promote chat")}finally{N(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!x&&i(),children:e.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:$=>$.stopPropagation(),onSubmit:D,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:i,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Oe,{width:18,height:18})})]}),e.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:"Creates a project and moves this chat into it — its history comes along and stays resumable."}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Project name"}),e.jsx("input",{autoFocus:!0,className:"input",value:l,onChange:$=>c($.target.value),placeholder:"Garage Water Heater Replacement"})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary (optional)"}),e.jsx("input",{className:"input",value:m,onChange:$=>u($.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:h,onChange:$=>j($.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Ys.map($=>e.jsx("option",{value:$.slug,children:$.label},$.slug))]})]}),e.jsxs("label",{className:"mb-5 block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:b,onChange:$=>f($.target.value),placeholder:"home, plumbing"})]}),d&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:i,disabled:x,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:x||!l.trim(),children:x?"Promoting…":"Promote to project"})]})]})})}function Cd({open:t,adoptable:s,busy:n,onClose:r,onAdopt:i}){const[o,l]=a.useState(new Set),c=a.useMemo(()=>((s==null?void 0:s.sources)??[]).map(j=>({sourceCwd:j.sourceCwd,sessions:j.sessions??j.sessionIds.map(x=>({sessionId:x}))})),[s]),m=a.useMemo(()=>c.flatMap(j=>j.sessions.map(x=>x.sessionId)),[c]),u=m.join(",");if(a.useEffect(()=>{t&&l(new Set(m))},[t,u]),ws(t&&!n,r),!t)return null;const b=j=>{l(x=>{const N=new Set(x);return N.delete(j)||N.add(j),N})},f=(j,x)=>{l(N=>{const d=new Set(N);for(const g of j)x?d.add(g):d.delete(g);return d})},h=o.size;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!n&&r(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Adopt native Claude Code chats",className:"flex max-h-[80vh] w-full max-w-2xl animate-scale-in flex-col rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick: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(Jt,{width:16,height:16}),"Adopt native chats"]}),e.jsx("button",{type:"button",onClick:r,disabled:n,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:e.jsx(Oe,{width:18,height:18})})]}),e.jsxs("p",{className:"mb-4 text-sm text-fg-muted",children:["These Claude Code sessions were run in a terminal and aren't visible here yet. Adopting them lists them here — your own ",e.jsx("code",{children:"~/.claude"})," history is never moved or deleted."]}),e.jsxs("div",{className:"-mx-1 flex-1 overflow-y-auto px-1",children:[c.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-fg-muted",children:"Nothing left to adopt."}),c.map(j=>{const x=j.sessions.map(d=>d.sessionId),N=x.every(d=>o.has(d));return e.jsxs("section",{className:"mb-4 last:mb-0",children:[e.jsxs("header",{className:"mb-1 flex items-baseline justify-between gap-2",children:[e.jsx("code",{className:"min-w-0 break-all text-xs text-fg-muted",children:j.sourceCwd}),e.jsx("button",{type:"button",onClick:()=>f(x,!N),className:"shrink-0 text-xs text-fg-muted underline underline-offset-2 hover:text-fg",children:N?"Deselect all":"Select all"})]}),e.jsx("ul",{className:"space-y-1",children:j.sessions.map(d=>e.jsx("li",{children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-lg border border-edge px-3 py-2 transition hover:bg-surface-hover",children:[e.jsx("input",{type:"checkbox",className:"mt-1 shrink-0",checked:o.has(d.sessionId),onChange:()=>b(d.sessionId)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",children:Sd(d)}),d.mtime!==void 0&&e.jsxs("span",{className:"mt-0.5 block text-xs text-fg-muted tabular",children:[Td(d.mtime)," · ",$d(d.sizeBytes)]})]})]})},d.sessionId))})]},j.sourceCwd)})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 border-t border-edge pt-4",children:[e.jsxs("span",{className:"text-sm text-fg-muted",children:[h," of ",m.length," selected"]}),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("button",{type:"button",className:"btn-ghost",onClick:r,disabled:n,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn-primary",disabled:n||h===0,onClick:()=>i([...o]),children:n?"Adopting…":`Adopt ${h} chat${h===1?"":"s"}`})]})]})]})})}function Sd(t){var r,i;const s=(r=t.autoName)==null?void 0:r.trim();if(s!==void 0&&s!=="")return s;const n=(i=t.preview)==null?void 0:i.trim();return n!==void 0&&n!==""?n:t.sessionId}function Td(t){const s=new Date(t);return Number.isNaN(s.getTime())?"unknown date":s.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function $d(t){return t<1024?`${t} B`:t<1024*1024?`${Math.round(t/1024)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Id({actions:t,adoption:s,slug:n,upsert:r,navigate:i,promotingChat:o,setPromotingChat:l,forkRequest:c,setForkRequest:m,commitFork:u}){const{deletingChat:b,setDeletingChat:f,confirmDeleteChat:h,renamingChat:j,setRenamingChat:x,commitRename:N}=t,{adoptOpen:d,adoptable:g,adopting:D,setAdoptOpen:$,confirmAdopt:I,toast:C,dismissToast:S}=s;return e.jsxs(e.Fragment,{children:[e.jsx(on,{open:b!==null,title:b&&b.ids.length>1?`Delete ${b.ids.length} chats?`:"Delete chat?",message:b&&e.jsxs(e.Fragment,{children:[b.ids.length>1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:b.chat.name})," ","and its ",b.ids.length-1," nested chat",b.ids.length-1===1?"":"s"," will be permanently removed — their transcripts too."]}):"This chat's transcript will be permanently removed.",b.orphanCount>0&&e.jsxs(e.Fragment,{children:[" ","Its ",b.orphanCount," other nested chat",b.orphanCount===1?"":"s"," will be kept and moved to the top level."]})," ","This cannot be undone."]}),confirmLabel:b&&b.ids.length>1?`Delete ${b.ids.length} chats`:"Delete chat",onConfirm:h,onClose:()=>f(null)}),o&&e.jsx(Nd,{open:!0,slug:n,sessionId:o.sessionId,defaultName:o.name,onClose:()=>l(null),onPromoted:M=>{l(null),r(M),i(`/projects/${M.slug}/chat`)}}),j&&e.jsx(kd,{open:!0,chatName:j.name,resetName:j.preview,onClose:()=>x(null),onRename:M=>{const y=j;x(null),N(y,M)}}),c&&e.jsx(yd,{open:!0,chatName:c.chat.name,onClose:()=>m(null),onFork:M=>{const{chat:y,fromUuid:T}=c;m(null),u(y,M,T)}}),e.jsx(Cd,{open:d,adoptable:g,busy:D,onClose:()=>$(!1),onAdopt:M=>void I(M)}),e.jsx(Kr,{message:(C==null?void 0:C.message)??null,tone:C==null?void 0:C.tone,onDismiss:S,action:C==null?void 0:C.action,durationMs:C!=null&&C.action?12e3:void 0})]})}function Ed({slug:t,base:s,activeSession:n,chats:r,navigate:i,refreshChats:o,setLoadErr:l}){const c=a.useRef(!1),[m,u]=a.useState(null),b=a.useCallback(async(N,d,g)=>{if(c.current)return;c.current=!0;let D;try{D=await B.forkChat(t,N.sessionId,d,g)}catch($){l($ instanceof Error?$.message:"Failed to fork chat"),c.current=!1;return}Lc(D,{sessionId:N.sessionId,name:N.name}),await o(),i(`${s}/chat/${encodeURIComponent(D)}`,{state:{justForked:!0}}),c.current=!1},[i,s,t,o]),f=a.useCallback(N=>u({chat:N}),[]),h=a.useCallback(N=>{if(!n)return;const d=r.find(g=>g.sessionId===n)??{sessionId:n,workingDirectory:"",name:"Current chat",updatedAt:"",resumable:!0};u({chat:d,fromUuid:N})},[n,r]),j=a.useCallback(async N=>{if(n){try{await B.revertChat(t,n,N)}catch(d){throw l(d instanceof Error?d.message:"Failed to revert chat"),d}await o()}},[n,t,o]),x=a.useCallback(N=>n?`${window.location.origin}${Gr(s,n,N)}`:window.location.href,[s,n]);return{forkRequest:m,setForkRequest:u,commitFork:b,requestFork:f,requestForkFromMessage:h,revertToMessage:j,messageLink:x}}function Rd(t,s,n){const r={pathname:n},i=a.useCallback(()=>s(qr(t)),[s,t]),o=a.useCallback(()=>s(`${t}/chat`),[s,t]),l=a.useCallback(()=>s(`${t}/files`),[s,t]),c=a.useCallback(()=>s(`${t}/changes`),[s,t]),m=a.useCallback(()=>s(`${t}/history`),[s,t]),u=a.useCallback(()=>s(`${t}/settings`),[s,t]),b=a.useCallback(()=>s(`${t}/triggers`),[s,t]),f=a.useCallback(N=>s(N?`${t}/changes/${encodeURIComponent(N)}`:`${t}/changes`),[s,t]);a.useEffect(()=>{r.pathname.startsWith(`${t}/hooks`)&&s(`${t}/triggers`,{replace:!0})},[r.pathname,s,t]);const h=a.useCallback(N=>s(`${t}/chat/${encodeURIComponent(N)}`),[s,t]),j=a.useCallback((N,d)=>s(`${Na(d)}/chat/${encodeURIComponent(N)}`),[s]),x=a.useCallback(N=>s(N?`${t}/files/${N.split("/").map(encodeURIComponent).join("/")}`:`${t}/files`),[s,t]);return{goHome:i,goChat:o,goFiles:l,goChanges:c,goHistory:m,goSettings:u,goTriggers:b,openChangeFile:f,openChat:h,openChatIn:j,goToFilesPath:x}}const Ks={files:"Files",changes:"Changes",history:"History",settings:"Settings",triggers:"Triggers"};function ha(t){if(!t)return"";const s=t.split("/").filter(Boolean);return s[s.length-1]??""}function Md(t){const{activeSession:s,activeChat:n,pendingChat:r,loaded:i}=t;return s===null?"New chat":n?n.name.trim()?n.name:"Chat":r===s?"New chat":i?"Chat":null}function Ad(t){const{view:s,root:n}=t,r=n?"":t.workspaceName;switch(s){case"home":return[r];case"chat":return[Md(t),r];case"files":return[ha(t.filesSubpath),Ks.files,r];case"changes":return[ha(t.changeFile),Ks.changes,r];default:return[Ks[s],r]}}function Dd(t){const{view:s,root:n,slug:r,activeSession:i,unread:o}=t;return s==="chat"&&i?{kind:"chat",sessionId:i,unread:(o==null?void 0:o.has(i))??!1}:n&&s==="home"?{kind:"instance"}:{kind:"workspace",key:r}}function Pd(t){var j;const{projects:s,rootWorkspace:n}=Ca(),{root:r,slug:i,chats:o,lastActiveChat:l,activeSession:c}=t,m=((j=t.project)==null?void 0:j.slug)===i?t.project:null,u=r?n:s.find(x=>x.slug===i),b=(m==null?void 0:m.name)??(u==null?void 0:u.name)??i,f=o.find(x=>x.sessionId===c)??((l==null?void 0:l.sessionId)===c?l:null),h=Qr(Dd(t));wi(Ad({...t,workspaceName:b,activeChat:f,loaded:m!==null}),{prefix:h})}function _d({root:t=!1,instanceEmpty:s=!1,onInstanceRecheck:n}={}){var os,zt,qe,Qe,Ht;const r=Yr(),i=t?Xr:r.slug??"",o=Na(i),l=Jr(),c=Zr(),m=ei(),u=(m==null?void 0:m.openNav)??(()=>{}),{refresh:b,upsert:f}=Ca(),h=ti(l.pathname,o),j=h==="chat"?r.sessionId:void 0,x=h==="files"?si(l.pathname,o):"",N=h==="changes"&&r.file?decodeURIComponent(r.file):void 0,d=a.useRef({counter:0,session:j??null});d.current.session!==(j??null)&&((os=l.state)!=null&&os.established||(d.current.counter+=1),d.current.session=j??null);const[g,D]=a.useState(0),$=`${d.current.counter}:${g}`,[I,C]=a.useState(null),[S,M]=a.useState([]),[y,T]=a.useState({}),[w,F]=a.useState(""),[O,z]=a.useState(null),[J,L]=a.useState(new Set);a.useEffect(()=>be.onActiveSessions(L),[]);const[v,A]=a.useState(""),[W,Q]=a.useState(""),[ie,K]=a.useState(null),[q,k]=a.useState(null),U=rc(i),Z=U.newUnattended,[E,H]=a.useState(!1),[de,we]=a.useState(null),[le,he]=a.useState(!1),[ke,Ue]=a.useState(()=>Hc(i)),Ae=a.useCallback(_=>{Ue(te=>{const oe=new Set(te);return oe.has(_)?oe.delete(_):oe.add(_),Wc(i,oe),oe})},[i]),re=Yc(),Be=ni(oi),ve=ai("(min-width: 1024px)"),Te=a.useRef(null),se=j??null,Ve=a.useCallback(_=>M(te=>te.map(oe=>oe.sessionId===_&&oe.unread?{...oe,unread:!1}:oe)),[]),De=a.useCallback(_=>{const te=new Set(_),oe=S.filter(Ce=>te.has(Ce.sessionId)&&Ce.unread).map(Ce=>Ce.sessionId);if(!oe.length)return()=>{};M(Ce=>Ce.map(Le=>te.has(Le.sessionId)&&Le.unread?{...Le,unread:!1}:Le));const Ye=new Set(oe);return()=>M(Ce=>Ce.map(Le=>Ye.has(Le.sessionId)?{...Le,unread:!0}:Le))},[S]),{unread:$e,markManySeen:X}=fd({slug:i,chats:S,view:h,activeSession:se,runningSessions:J,onSeen:Ve,onManySeen:De}),me=bd(i,J),Ie=a.useMemo(()=>{const _=re.runningOnly?S.filter(Ye=>J.has(Ye.sessionId)||Ye.sessionId===se):S,te=w.trim().toLowerCase();if(!te)return _;const oe=_.filter(Ye=>{var Ce;return Ye.name.toLowerCase().includes(te)||(((Ce=Ye.preview)==null?void 0:Ce.toLowerCase().includes(te))??!1)});return re.runningOnly?oe:zc(S,oe)},[S,w,re.runningOnly,J,se]),Dt=w.trim().length>0,Ze=a.useCallback(async()=>{const _=await B.gitStatus(i).catch(()=>null);k(_&&_.repo?_:null)},[i]),ze=a.useCallback(async()=>{const _=await B.chatUsage(i).catch(()=>null);_&&T(te=>({...te,..._}))},[i]),et=a.useCallback(async()=>{const _=await B.chatUsage(i,"archived").catch(()=>null);_&&T(te=>({...te,..._}))},[i]),He=a.useRef(!1),We=a.useCallback(async()=>{K(null);try{const _=await B.getProjectDetail(i);C(_.project),M(_.chats),A(_.changelog),Q(_.overview??"")}catch(_){K(_ instanceof Error?_.message:"Failed to load project")}Ze(),ze()},[i,Ze,ze]);a.useEffect(()=>{C(null),k(null),T({}),He.current=!1,We()},[i,We]),a.useEffect(()=>{le&&(He.current=!0,et())},[le,et]),a.useEffect(()=>{if(t)return;const _=h==="home"?dt({view:"home"}):h==="settings"?dt({view:"settings"}):h==="history"?dt({view:"history"}):h==="triggers"?dt({view:"triggers"}):h==="chat"?dt({view:"chat",sessionId:j}):h==="changes"?dt({view:"changes",file:N}):dt({view:"files",path:x||void 0});bi(i,_)},[t,i,h,j,x,N]);const Ne=a.useCallback(async()=>{const _=await B.listProjectChats(i).catch(()=>null);_&&M(_)},[i]),P=wd(i,Ne),{adoptableCount:ee,adopting:ae,setAdoptOpen:ue}=P,ye=a.useCallback(async()=>{const _=await B.getProjectDetail(i).catch(()=>null);_&&(C(_.project),M(_.chats),A(_.changelog),Q(_.overview??"")),Ze(),ze(),He.current&&et()},[i,Ze,ze,et]),Ke=a.useCallback(async(_,te)=>{const oe=te??(await B.uiConfig()).transcriptRenderLimit;return B.projectChatMessages(i,_,oe)},[i]);a.useEffect(()=>{H(!1)},[h,j,x,N]);const{goHome:Pt,goChat:_t,goFiles:Ee,goChanges:it,goHistory:Lt,goSettings:Pe,goTriggers:tt,openChangeFile:ot,openChat:lt,openChatIn:es,goToFilesPath:Ft}=Rd(o,c,l.pathname),Ot=a.useCallback(()=>{D(_=>_+1),_l(i),_t()},[_t,i]),{forkRequest:st,setForkRequest:ks,commitFork:Ns,requestFork:Cs,requestForkFromMessage:Ss,revertToMessage:Ts,messageLink:$s}=Ed({slug:i,base:o,activeSession:se,chats:S,navigate:c,refreshChats:Ne,setLoadErr:K}),Is=ri(l.hash),xt=_c(j),ts=((zt=l.state)==null?void 0:zt.justForked)===!0,ss=a.useCallback(_=>{z(_),Ne(),b(),j||c(`${o}/chat/${encodeURIComponent(_)}`,{replace:!0,state:{established:!0}})},[Ne,b,j,c,o]),Ut=a.useCallback(_=>{Ne(),b(),j||c(`${o}/chat/${encodeURIComponent(_)}`,{replace:!0,state:{established:!0}})},[Ne,b,j,c,o]);a.useEffect(()=>{O&&S.some(_=>_.sessionId===O)&&z(null)},[S,O]);const ct=a.useRef(new Set);a.useEffect(()=>{let _=!1;for(const te of J)ct.current.has(te)||(ct.current.add(te),S.some(oe=>oe.sessionId===te)||(_=!0));_&&Ne()},[J,S,Ne]);const ns=a.useCallback(_=>{_&&T(te=>({...te,[_.sessionId]:_.usage})),ye(),b()},[ye,b]),Bt=a.useCallback(async _=>{if(!I)return;const te=I.pinned.includes(_)?await B.unpinFile(i,_):await B.pinFile(i,_);C(te),f(te)},[I,i,f]),gt=a.useCallback(async _=>{const te=await B.unpinFile(i,_);C(te),f(te),x===_&&c(`${o}/files`,{replace:!0})},[i,o,f,x,c]),as=vd({slug:i,base:o,activeSession:se,navigate:c,chats:S,setChats:M,setLoadErr:K,setArchivedOpen:he,unread:$e,markManySeen:X}),{requestDeleteChat:pt,setRenamingChat:Es,archiveChat:bt,detachChat:nt,starChat:at,toggleUnread:Rs}=as,jt=a.useCallback(_=>re.runningOnly||!re.nested?Oc(_):Fc(_),[re.runningOnly,re.nested]),Ms=a.useMemo(()=>jt(re.runningOnly?Ie:Ie.filter(_=>!_.archived)),[Ie,jt,re.runningOnly]),As=a.useMemo(()=>re.runningOnly?[]:jt(Ie.filter(_=>_.archived)),[Ie,jt,re.runningOnly]),wt=S.filter(_=>!_.archived).length,vt=a.useMemo(()=>S.filter(_=>J.has(_.sessionId)).length,[S,J]),yt=S.some(_=>_.archived&&_.sessionId===se),_e=a.useRef(null);a.useEffect(()=>{var te;const _=S.find(oe=>oe.sessionId===se);_?_e.current=_:((te=_e.current)==null?void 0:te.sessionId)!==se&&(_e.current=null)},[S,se]);const kt=!!se&&h==="chat"&&O!==se&&!S.some(_=>_.sessionId===se)?((qe=_e.current)==null?void 0:qe.sessionId)===se?_e.current:{sessionId:se,workingDirectory:"",name:"Current chat",updatedAt:"",resumable:!0}:null;if(Pd({root:t,slug:i,project:I,chats:S,lastActiveChat:_e.current,view:h,activeSession:se,pendingChat:O,filesSubpath:x,changeFile:N,unread:$e}),a.useEffect(()=>{yt&&Te.current!==se&&(Te.current=se,he(!0))},[yt,se]),ie)return e.jsx("div",{className:"p-8",children:e.jsx("div",{className:"rounded-lg border border-danger-edge bg-danger-soft px-4 py-3 text-sm text-danger",children:ie})});if(!I)return e.jsx("div",{className:"p-8 text-sm text-fg-muted",children:"Loading project…"});const Ge=I.pinned,is=h==="files"&&x&&Ge.includes(x)?x:null,Vt={view:h,filesTabActive:h==="files"&&!is,gitStatus:q,newRunCount:Z,pinned:Ge,activePinnedFile:is,goHome:Pt,goChat:_t,goFiles:Ee,goChanges:it,goHistory:Lt,goSettings:Pe,goTriggers:tt,goToFilesPath:Ft,unpinTab:gt};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(Jc,{name:I.name,onHome:Pt,openNav:u,onShowChats:()=>H(!0),chatCount:S.length,onNewChat:Ot,tabs:ve?e.jsx(sa,{placement:"header",...Vt}):void 0}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx(cd,{chatList:Be,sessionsOpen:E,setSessionsOpen:H,chatSearch:w,setChatSearch:F,searching:Dt,newChat:Ot,view:h,activeSession:se,pendingChat:O,chats:S,fallbackChat:kt,visibleChats:Ie,activeChats:Ms,archivedChats:As,activeTotal:wt,runningCount:vt,viewPrefs:re,archivedOpen:le,setArchivedOpen:he,collapsedChats:ke,toggleChatCollapsed:Ae,openChat:lt,unread:$e,usageBySession:y,runningSessions:J,onForkChat:Cs,setPromotingChat:t?we:void 0,renameChat:Es,archiveChat:bt,requestDeleteChat:pt,starChat:at,toggleUnread:Rs,detachChat:nt,adoptableCount:ee,adopting:ae,adoptChats:()=>ue(!0)}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[!ve&&e.jsx(sa,{placement:"column",...Vt}),h==="changes"&&q&&e.jsx(Wl,{slug:I.slug,status:q,onStatusChange:_=>k(_.repo?_:null),selectedFile:N??null,onSelectFile:ot}),h==="history"&&e.jsx(nc,{slug:I.slug,state:U,chats:S,onOpenChat:lt}),h==="settings"&&e.jsx(bc,{project:I,onSaved:_=>{C(_),f(_)},onDeleted:()=>c(ii())}),h==="triggers"&&e.jsx(Ec,{project:I}),h==="home"&&e.jsx(ed,{project:I,root:t,instanceEmpty:t?s:!1,onInstanceRecheck:n,running:me.running,unread:me.unread,recent:me.recent,attentionLoading:me.loading,attentionError:me.error,changelog:v,overview:W,onOpenChat:es,onNewChat:Ot}),h==="chat"&&e.jsx(zl,{projectSlug:I.slug,initialSessionId:se??void 0,loadHistory:Ke,onSessionEstablished:Ut,onSessionStarted:ss,onTurnComplete:ns,preloadAvailable:I.hasOverview,projectModel:I.model,projectModels:I.models,projectRecovery:I.recovery,projectAttachments:I.attachments,forkParent:xt??void 0,onOpenForkParent:lt,onForkFromMessage:Ss,onRevertToMessage:Ts,onMessageLink:$s,focusMessageUuid:Is,autoFocus:ts,trigger:(Ht=S.find(_=>_.sessionId===se)??(((Qe=_e.current)==null?void 0:Qe.sessionId)===se?_e.current:null))==null?void 0:Ht.trigger},$),h==="files"&&e.jsx(uc,{project:I,path:x,onNavigate:Ft,onTogglePin:Bt},x)]})]}),e.jsx(Id,{actions:as,adoption:P,slug:i,upsert:f,navigate:c,promotingChat:de,setPromotingChat:we,forkRequest:st,setForkRequest:ks,commitFork:Ns})]})}const Hd=Object.freeze(Object.defineProperty({__proto__:null,ProjectView:_d},Symbol.toStringTag,{value:"Module"}));export{Xo as M,_d as P,Hd as a};
|
|
13
|
+
|