@edspencer/paddock 0.77.0 → 0.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/package.json +1 -1
  2. package/packages/server/dist/app.js +8 -1
  3. package/packages/server/dist/browser-gpu.d.ts +31 -0
  4. package/packages/server/dist/browser-gpu.js +63 -0
  5. package/packages/server/dist/herdctl-agent-config.d.ts +8 -2
  6. package/packages/server/dist/herdctl-agent-config.js +10 -4
  7. package/packages/server/dist/herdctl-agent-names.d.ts +8 -1
  8. package/packages/server/dist/herdctl-agent-names.js +12 -7
  9. package/packages/server/dist/herdctl.d.ts +6 -1
  10. package/packages/server/dist/herdctl.js +9 -3
  11. package/packages/server/package.json +1 -1
  12. package/packages/web/dist/assets/{DeleteProjectDialog-cHTdNUlT.js → DeleteProjectDialog-Bt_5z1b7.js} +1 -1
  13. package/packages/web/dist/assets/DiscoverPage-LE2yFc0F.js +2 -0
  14. package/packages/web/dist/assets/{DiscoverView-CiTYHesP.js → DiscoverView-C_VQec3o.js} +1 -1
  15. package/packages/web/dist/assets/{InstanceConfigPage-C9cJA3mw.js → InstanceConfigPage-bpZrpumd.js} +1 -1
  16. package/packages/web/dist/assets/{MarkdownRenderer-5uaTbABu.js → MarkdownRenderer-DmYpvXqr.js} +1 -1
  17. package/packages/web/dist/assets/{ProjectRedirect-BscldZqe.js → ProjectRedirect-CWAQx9Uc.js} +1 -1
  18. package/packages/web/dist/assets/{ProjectView-Bj95W0f4.js → ProjectView-JuOCBGKC.js} +3 -3
  19. package/packages/web/dist/assets/{ProjectsGrid-BYgv4KBI.js → ProjectsGrid-BihtN69c.js} +1 -1
  20. package/packages/web/dist/assets/{RootHome-2SxtceM_.js → RootHome-Bw3ZuHAb.js} +1 -1
  21. package/packages/web/dist/assets/{Surfaces-B__G3SGB.js → Surfaces-iO74d5OF.js} +1 -1
  22. package/packages/web/dist/assets/{arc-DeEeXqHG.js → arc-DTuVdQA0.js} +1 -1
  23. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-DAEVJcxx.js → architectureDiagram-3BPJPVTR-O9NSGqRe.js} +1 -1
  24. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-BDsc1L6N.js → blockDiagram-GPEHLZMM-CDvwKA_y.js} +1 -1
  25. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-BRAkt0wF.js → c4Diagram-AAUBKEIU-pNQuZhoW.js} +1 -1
  26. package/packages/web/dist/assets/channel-DF_bH_eP.js +2 -0
  27. package/packages/web/dist/assets/{chunk-2J33WTMH-CbWDgMLI.js → chunk-2J33WTMH-C11djcYQ.js} +1 -1
  28. package/packages/web/dist/assets/{chunk-4BX2VUAB-BcEZCLPu.js → chunk-4BX2VUAB-Dw2AiJPG.js} +1 -1
  29. package/packages/web/dist/assets/{chunk-55IACEB6-DCqQh6q8.js → chunk-55IACEB6-DNkrrGDk.js} +1 -1
  30. package/packages/web/dist/assets/{chunk-727SXJPM-JweiY_B4.js → chunk-727SXJPM-Cfe5G8_L.js} +1 -1
  31. package/packages/web/dist/assets/{chunk-AQP2D5EJ-BYrqLbEv.js → chunk-AQP2D5EJ-CygyZWVK.js} +1 -1
  32. package/packages/web/dist/assets/{chunk-FMBD7UC4-dJDuyJ2V.js → chunk-FMBD7UC4-DCqy7Cyl.js} +1 -1
  33. package/packages/web/dist/assets/{chunk-ND2GUHAM-DsJrI4kA.js → chunk-ND2GUHAM-DY-Tt8Fl.js} +1 -1
  34. package/packages/web/dist/assets/{chunk-QZHKN3VN-D6xgEpXd.js → chunk-QZHKN3VN-Vfq6pHq6.js} +1 -1
  35. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-CUAj9ybC.js +2 -0
  36. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-CUAj9ybC.js +2 -0
  37. package/packages/web/dist/assets/{core-afW9-UwG.js → core-EsYWo_BG.js} +1 -1
  38. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BhZOj7HZ.js → cose-bilkent-S5V4N54A-Dp85AcO4.js} +1 -1
  39. package/packages/web/dist/assets/{dagre-BM42HDAG-DCfvbRPP.js → dagre-BM42HDAG-CRckd_YA.js} +1 -1
  40. package/packages/web/dist/assets/{diagram-2AECGRRQ-Ci0M1D7l.js → diagram-2AECGRRQ-JoJSPnwR.js} +1 -1
  41. package/packages/web/dist/assets/{diagram-5GNKFQAL-BZ6SW1yc.js → diagram-5GNKFQAL-Bson74dI.js} +1 -1
  42. package/packages/web/dist/assets/{diagram-KO2AKTUF-B4-cJTIk.js → diagram-KO2AKTUF-BNliER8l.js} +1 -1
  43. package/packages/web/dist/assets/{diagram-LMA3HP47-B2OF1ipy.js → diagram-LMA3HP47-CGoQ3_PH.js} +1 -1
  44. package/packages/web/dist/assets/{diagram-OG6HWLK6-D70TzZwD.js → diagram-OG6HWLK6-DCdEm5k7.js} +1 -1
  45. package/packages/web/dist/assets/{documentTitle-Wl8Djqre.js → documentTitle-CXH5hpbS.js} +1 -1
  46. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-CDTl1U_L.js → erDiagram-TEJ5UH35-BdasaK8s.js} +1 -1
  47. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-BpuTkLzx.js → flowDiagram-I6XJVG4X-B4JuMupx.js} +1 -1
  48. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-zfON_pzp.js → ganttDiagram-6RSMTGT7-hJbdicJt.js} +1 -1
  49. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-CXJlr4Aa.js → gitGraphDiagram-PVQCEYII-pXZI1Zkh.js} +1 -1
  50. package/packages/web/dist/assets/{index-BPqHA_fy.js → index-4_u0mfSb.js} +2 -2
  51. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-1K1LG6E2.js → infoDiagram-5YYISTIA-BvJMTOeK.js} +1 -1
  52. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-srZJnYw8.js → ishikawaDiagram-YF4QCWOH-B77zOzN-.js} +1 -1
  53. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-3E_CsMIN.js → journeyDiagram-JHISSGLW-V313L7-8.js} +1 -1
  54. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-BUPFeskA.js → kanban-definition-UN3LZRKU-zu-Sih2h.js} +1 -1
  55. package/packages/web/dist/assets/{linear-CS75OsJ4.js → linear-vmWftBq6.js} +1 -1
  56. package/packages/web/dist/assets/{mermaid.core-AX6KCjdW.js → mermaid.core-Da_mwYBC.js} +4 -4
  57. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-CvtTMpsJ.js → mindmap-definition-RKZ34NQL-6sExeRgQ.js} +1 -1
  58. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-DyWKFZLR.js → pieDiagram-4H26LBE5-LjXeW1Vb.js} +1 -1
  59. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-DlLXpUjd.js → quadrantDiagram-W4KKPZXB-mm7l4NBx.js} +1 -1
  60. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-DuF2w7X7.js → requirementDiagram-4Y6WPE33-BnEmeDZs.js} +1 -1
  61. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-jQdUQ_IA.js → sankeyDiagram-5OEKKPKP-APXzF57J.js} +1 -1
  62. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-4RN9tEo0.js → sequenceDiagram-3UESZ5HK-DpjqNsed.js} +1 -1
  63. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-CkknRhAq.js → stateDiagram-AJRCARHV-DhUpQhRh.js} +1 -1
  64. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-D6jKC77W.js +2 -0
  65. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-CtDo_Km4.js → timeline-definition-PNZ67QCA-wXCQTCZf.js} +1 -1
  66. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-BtHweUMq.js → vennDiagram-CIIHVFJN-B6nxo-jj.js} +1 -1
  67. package/packages/web/dist/assets/{wardley-L42UT6IY-C_OWlnET.js → wardley-L42UT6IY-BeRZDa-K.js} +1 -1
  68. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-CI_iXYGs.js → wardleyDiagram-YWT4CUSO-BFBQl8LE.js} +1 -1
  69. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-zPP4izdU.js → xychartDiagram-2RQKCTM6-BwZGu1gQ.js} +1 -1
  70. package/packages/web/dist/index.html +1 -1
  71. package/packages/web/dist/sw.js +1 -1
  72. package/packages/web/dist/assets/DiscoverPage-DzR0ltxH.js +0 -2
  73. package/packages/web/dist/assets/channel-xkQ7S92i.js +0 -2
  74. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-C1trK71k.js +0 -2
  75. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-C1trK71k.js +0 -2
  76. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-1UhTuOCG.js +0 -2
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectsGrid-BYgv4KBI.js","assets/DeleteProjectDialog-cHTdNUlT.js","assets/lastTab-CU1zsF0j.js","assets/documentTitle-Wl8Djqre.js","assets/ProjectView-Bj95W0f4.js","assets/queued-CagZVfWU.js","assets/Surfaces-B__G3SGB.js","assets/DiscoverView-CiTYHesP.js","assets/ProjectRedirect-BscldZqe.js","assets/InstanceConfigPage-C9cJA3mw.js","assets/DiscoverPage-DzR0ltxH.js","assets/RootHome-2SxtceM_.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectsGrid-BihtN69c.js","assets/DeleteProjectDialog-Bt_5z1b7.js","assets/lastTab-CU1zsF0j.js","assets/documentTitle-CXH5hpbS.js","assets/ProjectView-JuOCBGKC.js","assets/queued-CagZVfWU.js","assets/Surfaces-iO74d5OF.js","assets/DiscoverView-C_VQec3o.js","assets/ProjectRedirect-CWAQx9Uc.js","assets/InstanceConfigPage-bpZrpumd.js","assets/DiscoverPage-LE2yFc0F.js","assets/RootHome-Bw3ZuHAb.js"])))=>i.map(i=>d[i]);
2
2
  function lf(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const o in r)if(o!=="default"&&!(o in e)){const s=Object.getOwnPropertyDescriptor(r,o);s&&Object.defineProperty(e,o,s.get?s:{enumerable:!0,get:()=>r[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const s of o)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(o){const s={};return o.integrity&&(s.integrity=o.integrity),o.referrerPolicy&&(s.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?s.credentials="include":o.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(o){if(o.ep)return;o.ep=!0;const s=n(o);fetch(o.href,s)}})();const Bm="modulepreload",Wm=function(e){return"/"+e},ac={},Zt=function(t,n,r){let o=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),a=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));o=Promise.allSettled(n.map(u=>{if(u=Wm(u),u in ac)return;ac[u]=!0;const c=u.endsWith(".css"),d=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${d}`))return;const f=document.createElement("link");if(f.rel=c?"stylesheet":Bm,c||(f.as="script"),f.crossOrigin="",f.href=u,a&&f.setAttribute("nonce",a),document.head.appendChild(f),c)return new Promise((p,S)=>{f.addEventListener("load",p),f.addEventListener("error",()=>S(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(i){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=i,window.dispatchEvent(a),!a.defaultPrevented)throw i}return o.then(i=>{for(const a of i||[])a.status==="rejected"&&s(a.reason);return t().catch(s)})};var cS=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function uf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var cf={exports:{}},wi={},df={exports:{}},te={};/**
3
3
  * @license React
4
4
  * react.production.min.js
@@ -67,5 +67,5 @@ Error generating stack: `+s.message+`
67
67
  * LICENSE.md file in the root directory of this source tree.
68
68
  *
69
69
  * @license MIT
70
- */function Kr(){return Kr=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Kr.apply(this,arguments)}function zp(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function D0(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function O0(e,t){return e.button===0&&(!t||t==="_self")&&!D0(e)}const $0=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],A0=["aria-current","caseSensitive","className","end","style","to","unstable_viewTransition","children"],z0="6";try{window.__reactRouterVersion=z0}catch{}function F0(e,t){return Gy({basename:void 0,future:Kr({},void 0,{v7_prependBasename:!0}),history:yy({window:void 0}),hydrationData:U0(),routes:e,mapRouteProperties:I0,unstable_dataStrategy:void 0,unstable_patchRoutesOnNavigation:void 0,window:void 0}).initialize()}function U0(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Kr({},t,{errors:B0(t.errors)})),t}function B0(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,o]of t)if(o&&o.__type==="RouteErrorResponse")n[r]=new mi(o.status,o.statusText,o.data,o.internal===!0);else if(o&&o.__type==="Error"){if(o.__subType){let s=window[o.__subType];if(typeof s=="function")try{let i=new s(o.message);i.stack="",n[r]=i}catch{}}if(n[r]==null){let s=new Error(o.message);s.stack="",n[r]=s}}else n[r]=o;return n}const Fp=x.createContext({isTransitioning:!1}),W0=x.createContext(new Map),H0="startTransition",Md=sg[H0],V0="flushSync",_d=vy[V0];function K0(e){Md?Md(e):e()}function fo(e){_d?_d(e):e()}class Q0{constructor(){this.status="pending",this.promise=new Promise((t,n)=>{this.resolve=r=>{this.status==="pending"&&(this.status="resolved",t(r))},this.reject=r=>{this.status==="pending"&&(this.status="rejected",n(r))}})}}function G0(e){let{fallbackElement:t,router:n,future:r}=e,[o,s]=x.useState(n.state),[i,a]=x.useState(),[u,c]=x.useState({isTransitioning:!1}),[d,f]=x.useState(),[p,S]=x.useState(),[k,g]=x.useState(),C=x.useRef(new Map),{v7_startTransition:m}=r||{},h=x.useCallback(y=>{m?K0(y):y()},[m]),v=x.useCallback((y,D)=>{let{deletedFetchers:b,unstable_flushSync:B,unstable_viewTransitionOpts:ee}=D;b.forEach(fe=>C.current.delete(fe)),y.fetchers.forEach((fe,st)=>{fe.data!==void 0&&C.current.set(st,fe.data)});let ce=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!ee||ce){B?fo(()=>s(y)):h(()=>s(y));return}if(B){fo(()=>{p&&(d&&d.resolve(),p.skipTransition()),c({isTransitioning:!0,flushSync:!0,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation})});let fe=n.window.document.startViewTransition(()=>{fo(()=>s(y))});fe.finished.finally(()=>{fo(()=>{f(void 0),S(void 0),a(void 0),c({isTransitioning:!1})})}),fo(()=>S(fe));return}p?(d&&d.resolve(),p.skipTransition(),g({state:y,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation})):(a(y),c({isTransitioning:!0,flushSync:!1,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation}))},[n.window,p,d,C,h]);x.useLayoutEffect(()=>n.subscribe(v),[n,v]),x.useEffect(()=>{u.isTransitioning&&!u.flushSync&&f(new Q0)},[u]),x.useEffect(()=>{if(d&&i&&n.window){let y=i,D=d.promise,b=n.window.document.startViewTransition(async()=>{h(()=>s(y)),await D});b.finished.finally(()=>{f(void 0),S(void 0),a(void 0),c({isTransitioning:!1})}),S(b)}},[h,i,d,n.window]),x.useEffect(()=>{d&&i&&o.location.key===i.location.key&&d.resolve()},[d,p,o.location,i]),x.useEffect(()=>{!u.isTransitioning&&k&&(a(k.state),c({isTransitioning:!0,flushSync:!1,currentLocation:k.currentLocation,nextLocation:k.nextLocation}),g(void 0))},[u.isTransitioning,k]),x.useEffect(()=>{},[]);let E=x.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:y=>n.navigate(y),push:(y,D,b)=>n.navigate(y,{state:D,preventScrollReset:b==null?void 0:b.preventScrollReset}),replace:(y,D,b)=>n.navigate(y,{replace:!0,state:D,preventScrollReset:b==null?void 0:b.preventScrollReset})}),[n]),T=n.basename||"/",R=x.useMemo(()=>({router:n,navigator:E,static:!1,basename:T}),[n,E,T]),M=x.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return x.createElement(x.Fragment,null,x.createElement(qo.Provider,{value:R},x.createElement(Lu.Provider,{value:o},x.createElement(W0.Provider,{value:C.current},x.createElement(Fp.Provider,{value:u},x.createElement(_0,{basename:T,location:o.location,navigationType:o.historyAction,navigator:E,future:M},o.initialized||n.future.v7_partialHydration?x.createElement(Y0,{routes:n.routes,future:n.future,state:o}):t))))),null)}const Y0=x.memo(J0);function J0(e){let{routes:t,future:n,state:r}=e;return S0(t,void 0,r,n)}const X0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Z0=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ts=x.forwardRef(function(t,n){let{onClick:r,relative:o,reloadDocument:s,replace:i,state:a,target:u,to:c,preventScrollReset:d,unstable_viewTransition:f}=t,p=zp(t,$0),{basename:S}=x.useContext(cn),k,g=!1;if(typeof c=="string"&&Z0.test(c)&&(k=c,X0))try{let v=new URL(window.location.href),E=c.startsWith("//")?new URL(v.protocol+c):new URL(c),T=ln(E.pathname,S);E.origin===v.origin&&T!=null?c=T+E.search+E.hash:g=!0}catch{}let C=v0(c,{relative:o}),m=ex(c,{replace:i,state:a,target:u,preventScrollReset:d,relative:o,unstable_viewTransition:f});function h(v){r&&r(v),v.defaultPrevented||m(v)}return x.createElement("a",Kr({},p,{href:k||C,onClick:g||s?r:h,ref:n,target:u}))}),yn=x.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:o=!1,className:s="",end:i=!1,style:a,to:u,unstable_viewTransition:c,children:d}=t,f=zp(t,A0),p=Fi(u,{relative:f.relative}),S=cr(),k=x.useContext(Lu),{navigator:g,basename:C}=x.useContext(cn),m=k!=null&&tx(p)&&c===!0,h=g.encodeLocation?g.encodeLocation(p).pathname:p.pathname,v=S.pathname,E=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;o||(v=v.toLowerCase(),E=E?E.toLowerCase():null,h=h.toLowerCase()),E&&C&&(E=ln(E,C)||E);const T=h!=="/"&&h.endsWith("/")?h.length-1:h.length;let R=v===h||!i&&v.startsWith(h)&&v.charAt(T)==="/",M=E!=null&&(E===h||!i&&E.startsWith(h)&&E.charAt(h.length)==="/"),y={isActive:R,isPending:M,isTransitioning:m},D=R?r:void 0,b;typeof s=="function"?b=s(y):b=[s,R?"active":null,M?"pending":null,m?"transitioning":null].filter(Boolean).join(" ");let B=typeof a=="function"?a(y):a;return x.createElement(ts,Kr({},f,{"aria-current":D,className:b,ref:n,style:B,to:u,unstable_viewTransition:c}),typeof d=="function"?d(y):d)});var Nl;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Nl||(Nl={}));var Id;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Id||(Id={}));function q0(e){let t=x.useContext(qo);return t||q(!1),t}function ex(e,t){let{target:n,replace:r,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a}=t===void 0?{}:t,u=es(),c=cr(),d=Fi(e,{relative:i});return x.useCallback(f=>{if(O0(f,n)){f.preventDefault();let p=r!==void 0?r:ir(c)===ir(d);u(e,{replace:p,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a})}},[c,u,d,r,o,n,e,s,i,a])}function tx(e,t){t===void 0&&(t={});let n=x.useContext(Fp);n==null&&q(!1);let{basename:r}=q0(Nl.useViewTransitionState),o=Fi(e,{relative:t.relative});if(!n.isTransitioning)return!1;let s=ln(n.currentLocation.pathname,r)||n.currentLocation.pathname,i=ln(n.nextLocation.pathname,r)||n.nextLocation.pathname;return pi(o.pathname,i)!=null||pi(o.pathname,s)!=null}const _u="";function Iu(e){return e===_u}function K(e){return Iu(e)?"/api/root":`/api/projects/${encodeURIComponent(e)}`}function Up(e){return Iu(e)?"":`/projects/${e}`}function hS(e){return e===""?"/":`${e}/home`}function nx(){return"/projects"}function pS(e,t){const n=e.startsWith(t)?e.slice(t.length):e;return n.startsWith("/files")?"files":n.startsWith("/changes")?"changes":n.startsWith("/history")?"history":n.startsWith("/settings")?"settings":n.startsWith("/triggers")||n.startsWith("/hooks")?"triggers":n.startsWith("/home")?"home":n.startsWith("/chat")?"chat":t===""?"home":"chat"}function mS(e,t){const n=`${t}/files`;if(!e.startsWith(n))return"";const r=e.slice(n.length).replace(/^\//,"");return r?r.split("/").filter(Boolean).map(o=>{try{return decodeURIComponent(o)}catch{return o}}).join("/"):""}function rx(e){return`m-${e}`}function gS(e,t,n){return`${e}/chat/${encodeURIComponent(t)}#${rx(n)}`}function vS(e){var t;return(t=/^#?m-([0-9a-fA-F][0-9a-fA-F-]{7,})$/.exec(e))==null?void 0:t[1]}const Gn="";async function U(e,t){const n=await fetch(`${Gn}${e}`,{headers:{"content-type":"application/json",...(t==null?void 0:t.headers)??{}},...t});if(!n.ok){let r=n.statusText,o,s;try{s=await n.json();const i=s;i.error&&(r=i.error),typeof i.code=="string"&&(o=i.code)}catch{}throw new $n(r,n.status,o,s)}return await n.json()}async function ox(e,t){const n=await fetch(`${Gn}${e}`,t);if(!n.ok){let r=n.statusText;try{const o=JSON.parse(await n.text());o.error&&(r=o.error)}catch{}throw new $n(r,n.status)}return n.text()}class $n extends Error{constructor(t,n,r,o){super(t),this.status=n,this.code=r,this.body=o,this.name="ApiError"}}const Dd={transcriptRenderLimit:500};let Od=null;const ar={async me(){return U("/api/me")},async markChatSeen(e,t,n,r){const o=`${K(e)}/chats/${encodeURIComponent(t)}/seen`;await U(o,{method:"POST",body:JSON.stringify({...n!==void 0?{when:n}:{},...r!=null&&r.keepUnread?{keepUnread:!0}:{}})})},async markChatUnread(e,t,n){const r=`${K(e)}/chats/${encodeURIComponent(t)}/unread`;await U(r,{method:"POST",body:JSON.stringify({unread:n})})},async projectRuns(e,t){const n=t!==void 0?`?limit=${encodeURIComponent(t)}`:"";return U(`${K(e)}/runs${n}`)},async markRunsSeen(e,t){await U(`${K(e)}/runs/seen`,{method:"POST",body:JSON.stringify(t!==void 0?{when:t}:{})})},async getModels(){return U("/api/models")},async getInstanceConfig(){return U("/api/instance-config")},async updateInstanceConfig(e,t){return U("/api/instance-config",{method:"PUT",body:JSON.stringify(t===void 0?{patch:e}:{patch:e,expectedVersion:t})})},async uploadAttachments(e,t,n){const r=new FormData;for(const s of n)r.append("files",s,s.name);const o=await fetch(`${Gn}${K(e)}/chats/${encodeURIComponent(t)}/upload`,{method:"POST",body:r});if(!o.ok){let s=o.statusText;try{const i=await o.json();i.error&&(s=i.error)}catch{}throw new $n(s,o.status)}return await o.json()},async projectCommands(e){const{commands:t}=await U(`${K(e)}/commands`);return t},async listProjects(){const{projects:e,root:t}=await U("/api/projects");return{projects:e,root:t??null}},async getProjectDetail(e){return U(`${K(e)}`)},async attentionChats(e){const t=await U(`${K(e)}/chats/attention`);return{running:t.running??[],unread:t.unread??[],recent:t.recent??[]}},async createProject(e){const{project:t}=await U("/api/projects",{method:"POST",body:JSON.stringify(e)});return t},async updateProject(e,t){const{project:n}=await U(`${K(e)}`,{method:"PATCH",body:JSON.stringify(t)});return n},async promoteProject(e,t){const{project:n}=await U(`${K(e)}/promote`,{method:"POST",body:JSON.stringify({repo:t})});return n},async deleteProject(e){await U(`${K(e)}`,{method:"DELETE"})},async deleteProjectChat(e,t){await U(`${K(e)}/chats/${encodeURIComponent(t)}`,{method:"DELETE"})},async renameProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({name:n})})},async archiveProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/archive`,{method:"POST",body:JSON.stringify({archived:n})})},async starProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/star`,{method:"POST",body:JSON.stringify({starred:n})})},async archiveProjectChats(e,t,n){await U(`${K(e)}/chats/batch/archive`,{method:"POST",body:JSON.stringify({sessionIds:t,archived:n})})},async markChatsUnread(e,t,n){await U(`${K(e)}/chats/batch/unread`,{method:"POST",body:JSON.stringify({sessionIds:t,unread:n})})},async deleteProjectChats(e,t){const n=await U(`${K(e)}/chats/batch/delete`,{method:"POST",body:JSON.stringify({sessionIds:t})});return{removed:n.removed??[],failed:n.failed??[]}},async detachProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/detach`,{method:"POST",body:JSON.stringify({detached:n})})},async promoteChat(e,t,n){return U(`${K(e)}/chats/${encodeURIComponent(t)}/promote`,{method:"POST",body:JSON.stringify(n)})},async forkChat(e,t,n,r){const{sessionId:o}=await U(`${K(e)}/chats/${encodeURIComponent(t)}/fork`,{method:"POST",body:JSON.stringify({name:n,fromUuid:r})});return o},async revertChat(e,t,n){const{removed:r}=await U(`${K(e)}/chats/${encodeURIComponent(t)}/revert`,{method:"POST",body:JSON.stringify({uuid:n})});return r},async listProjectDir(e,t=""){const n=t?`?path=${encodeURIComponent(t)}`:"";return U(`${K(e)}/files${n}`)},async listProjectFiles(e){const{entries:t}=await this.listProjectDir(e);return t.filter(n=>n.kind==="file").map(n=>n.name)},async getProjectFile(e,t){return U(`${K(e)}/files/${encodeURIComponent(t)}`)},projectFileRawUrl(e,t){return`${Gn}${K(e)}/files/${encodeURIComponent(t)}?raw=1`},chatFileRawUrl(e){return`${Gn}/api/chat-files/${encodeURIComponent(e)}`},async pinFile(e,t){const{project:n}=await U(`${K(e)}/pins`,{method:"PUT",body:JSON.stringify({file:t})});return n},async unpinFile(e,t){const{project:n}=await U(`${K(e)}/pins/${encodeURIComponent(t)}`,{method:"DELETE"});return n},async listProjectChats(e){const{chats:t}=await U(`${K(e)}/chats`);return t},async getAdoptableChats(e){return U(`${K(e)}/adoptable-chats`)},async adoptChats(e,t){return U(`${K(e)}/adopt-chats`,{method:"POST",body:JSON.stringify(t??{})})},async unadoptChats(e,t){return U(`${K(e)}/unadopt-chats`,{method:"POST",body:JSON.stringify(t??{})})},async chatUsage(e,t){const n=t?`?scope=${t}`:"",{usage:r}=await U(`${K(e)}/chats/usage${n}`);return r},uiConfig(){return Od??(Od=ar.getModels().then(e=>e.uiDefault??Dd).catch(()=>Dd)),Od},async projectChatMessages(e,t,n=0){const r=n>0?`?limit=${n}`:"",o=await U(`${K(e)}/chats/${encodeURIComponent(t)}/messages${r}`);return{messages:o.messages,total:o.total??o.messages.length,truncated:o.truncated??!1}},async subagentMessages(e,t,n){const r=`${K(e)}/chats/${encodeURIComponent(t)}`,{messages:o}=await U(`${r}/subagents/${encodeURIComponent(n)}/messages`);return o},async chatContext(e,t){const n=`${K(e)}/chats/${encodeURIComponent(t)}/context`,{usage:r}=await U(n);return r},async listTriggers(e){return U(`${K(e)}/triggers`)},async putTrigger(e,t,n){const{trigger:r}=await U(`${K(e)}/triggers/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)});return r},async deleteTrigger(e,t){await U(`${K(e)}/triggers/${encodeURIComponent(t)}`,{method:"DELETE"})},async triggerRuntime(e){return U(`${K(e)}/triggers/runtime`)},async runTrigger(e,t){const{sessionId:n}=await U(`${K(e)}/triggers/${encodeURIComponent(t)}/run`,{method:"POST",body:"{}"});return n},async gitInfo(){return U("/api/git")},async gitStatus(e){return U(`${K(e)}/git/status`)},async gitDiff(e,t){const n=t?`?file=${encodeURIComponent(t)}`:"";return ox(`${K(e)}/git/diff${n}`)},async gitCommit(e,t,n){return U(`${K(e)}/git/commit`,{method:"POST",body:JSON.stringify(n?{message:t,files:n}:{message:t})})},async gitProjectInfo(e){return U(`${K(e)}/git/remote`)},async gitPush(e){return U(`${K(e)}/git/push`,{method:"POST"})},async gitUntrackedFile(e,t){return U(`${K(e)}/git/file?path=${encodeURIComponent(t)}`)},gitUntrackedFileRawUrl(e,t){return`${Gn}${K(e)}/git/file?path=${encodeURIComponent(t)}&raw=1`},async githubConnect(){return U("/api/git/github/connect",{method:"POST"})},async githubPoll(e){return U("/api/git/github/poll",{method:"POST",body:JSON.stringify({deviceCode:e})})},async githubDisconnect(){await U("/api/git/github/disconnect",{method:"POST"})},async discover(e){const t=new URLSearchParams;e!=null&&e.includeNonGit&&t.set("includeNonGit","1"),e!=null&&e.includeOutsideHome&&t.set("includeOutsideHome","1");const n=t.toString();return U(`/api/discover${n?`?${n}`:""}`)},async discoverSessions(e){return U(`/api/discover/sessions?dir=${encodeURIComponent(e)}`)},async transcriptionStatus(){return U("/api/transcription")},async transcribe(e,t="dictation.webm",n){const r=new FormData;r.append("file",e,t);const o=await fetch(`${Gn}/api/transcribe`,{method:"POST",body:r,signal:n});if(!o.ok){let i=o.statusText;try{const a=await o.json();a.error&&(i=a.error)}catch{}throw new $n(i,o.status)}const{text:s}=await o.json();return s},async transcriptsMigration(){return U("/api/transcripts/migration")},async transcriptsMigrationChats(e){const t=e===void 0?"":`?slug=${encodeURIComponent(e)}`;return U(`/api/transcripts/migration/chats${t}`)},async runTranscriptsMigration(e){return U("/api/transcripts/migration",{method:"POST",body:JSON.stringify(e)})}},Bp=x.createContext(null);function sx({children:e}){const[t,n]=x.useState([]),[r,o]=x.useState(null),[s,i]=x.useState(!0),[a,u]=x.useState(null),c=x.useRef(!1),d=x.useCallback(async()=>{c.current||i(!0),u(null);try{const{projects:k,root:g}=await ar.listProjects();c.current=!0,n(k),g&&o(g)}catch(k){u(k instanceof Error?k.message:"Failed to load projects")}finally{i(!1)}},[]),f=x.useCallback(k=>{if(Iu(k.slug)){o(k);return}n(g=>[k,...g.filter(C=>C.slug!==k.slug)])},[]),p=x.useCallback(k=>{n(g=>g.filter(C=>C.slug!==k))},[]);x.useEffect(()=>{d()},[d]);const S=x.useMemo(()=>({projects:t,rootWorkspace:r,loading:s,error:a,refresh:d,upsert:f,remove:p}),[t,r,s,a,d,f,p]);return l.jsx(Bp.Provider,{value:S,children:e})}function Wp(){const e=x.useContext(Bp);if(!e)throw new Error("useProjects must be used within ProjectsProvider");return e}const ix="paddock:theme";function ax(){return typeof document<"u"&&document.documentElement.classList.contains("dark")}function lx(){const[e,t]=x.useState(ax),n=x.useCallback(()=>{t(r=>{const o=!r;document.documentElement.classList.toggle("dark",o);try{localStorage.setItem(ix,o?"dark":"light")}catch{}return o})},[]);return{dark:e,toggle:n}}const An={name:"Paddock",logo:"🐎",accent:"#c2603c"},ux={running:"#f97316",unread:"#22c55e"},cx={enabled:!1,path:"/open-api"};function Hp(){const e=globalThis.__PADDOCK_CONFIG__;return{...An,...(e==null?void 0:e.brand)??{}}}function dx(){const e=globalThis.__PADDOCK_CONFIG__;return{...cx,...(e==null?void 0:e.openapi)??{}}}function Vp(e){return/^(https?:\/\/|\/)/i.test(e.trim())}const Du=e=>e<0?0:e>1?1:e;function Ou(e){return e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055}function It(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function $u({L:e,a:t,b:n}){const r=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s]}function Cl(e,t,n){const r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),o=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),s=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return{L:.2104542553*r+.793617785*o-.0040720468*s,a:1.9779984951*r-2.428592205*o+.4505937099*s,b:.0259040371*r+.7827717662*o-.808675766*s}}function Qr(e,t,n,r=1){const o=n*Math.PI/180,s=$u({L:e,a:t*Math.cos(o),b:t*Math.sin(o)}),[i,a,u]=s.map(c=>Du(Ou(c)));return{r:i,g:a,b:u,a:r}}function $d(e,t,n){const r=n*Math.PI/180;return $u({L:e,a:t*Math.cos(r),b:t*Math.sin(r)}).map(Ou).every(o=>o>=-.0015&&o<=1.0015)}function Gt({r:e,g:t,b:n}){const r=o=>Math.round(Du(o)*255).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`}function et({r:e,g:t,b:n}){const[r,o,s]=[e,t,n].map(It);return .2126*r+.7152*o+.0722*s}function fx(e,t){if(e.a>=1)return e;const n=e.a;return{r:e.r*n+t.r*(1-n),g:e.g*n+t.g*(1-n),b:e.b*n+t.b*(1-n),a:1}}function We(e,t){const n=et(fx(e,t)),r=et(t),[o,s]=n>r?[n,r]:[r,n];return(o+.05)/(s+.05)}const Ad={white:{r:1,g:1,b:1,a:1},black:{r:0,g:0,b:0,a:1},transparent:{r:0,g:0,b:0,a:0}};function ja(e){const t=[];let n=0,r="";for(const o of e)o==="("?n++:o===")"&&n--,o===","&&n===0?(t.push(r.trim()),r=""):r+=o;return r.trim()&&t.push(r.trim()),t}function mr(e,t){return!e.startsWith(`${t}(`)||!e.endsWith(")")?null:e.slice(t.length+1,-1)}function gn(e){const t=e.endsWith("%")?Number(e.slice(0,-1))/100:Number(e);if(!Number.isFinite(t))throw new Error(`not a number: ${e}`);return t}function Cn(e,t,n=0){if(n>24)throw new Error(`var() cycle resolving ${e}`);const r=e.trim();if(Ad[r])return Ad[r];if(r.startsWith("#")){let u=r.slice(1);if(u.length===3&&(u=[...u].map(d=>d+d).join("")),u.length!==6)throw new Error(`bad hex: ${r}`);const c=parseInt(u,16);return{r:(c>>16&255)/255,g:(c>>8&255)/255,b:(c&255)/255,a:1}}const o=mr(r,"var");if(o!==null){const[u,...c]=ja(o),d=t[u]??c.join(",");if(!d)throw new Error(`undefined custom property: ${u}`);return Cn(d,t,n+1)}const s=mr(r,"oklch");if(s!==null){const[u,c]=s.split("/"),d=u.trim().split(/\s+/);if(d.length!==3)throw new Error(`bad oklch(): ${r}`);return Qr(gn(d[0]),gn(d[1]),gn(d[2]),c?gn(c.trim()):1)}const i=mr(r,"rgb")??mr(r,"rgba");if(i!==null){const u=i.trim(),c=mr(u,"var");if(c!==null){const[S]=ja(c),k=t[S];if(!k)throw new Error(`undefined custom property: ${S}`);return Cn(`rgb(${k})`,t,n+1)}const[d,f]=u.split("/"),p=d.trim().split(/[\s,]+/);if(p.length<3)throw new Error(`bad rgb(): ${r}`);return{r:gn(p[0])/255,g:gn(p[1])/255,b:gn(p[2])/255,a:f?gn(f.trim()):1}}const a=mr(r,"color-mix");if(a!==null){const[u,c,d]=ja(a),f=u.trim();if(f!=="in oklab"&&f!=="in srgb")throw new Error(`only \`in oklab\` and \`in srgb\` color-mix are supported, got: ${u}`);const p=zd(c),S=zd(d);let k=p.pct,g=S.pct;k===null&&g===null?(k=.5,g=.5):k===null?k=1-g:g===null&&(g=1-k);const C=k+g,m=k/C,h=Cn(p.color,t,n+1),v=Cn(S.color,t,n+1);return f==="in srgb"?hx(h,v,m):px(h,v,m)}throw new Error(`unsupported colour value: ${r}`)}function zd(e){const t=/\s+(-?[\d.]+)%$/.exec(e.trim());return t?{color:e.trim().slice(0,t.index).trim(),pct:Number(t[1])/100}:{color:e.trim(),pct:null}}function hx(e,t,n){return{r:e.r*n+t.r*(1-n),g:e.g*n+t.g*(1-n),b:e.b*n+t.b*(1-n),a:e.a*n+t.a*(1-n)}}function px(e,t,n){const r=Cl(It(e.r),It(e.g),It(e.b)),o=Cl(It(t.r),It(t.g),It(t.b)),s={L:r.L*n+o.L*(1-n),a:r.a*n+o.a*(1-n),b:r.b*n+o.b*(1-n)},[i,a,u]=$u(s).map(c=>Du(Ou(c)));return{r:i,g:a,b:u,a:e.a*n+t.a*(1-n)}}function tn({r:e,g:t,b:n}){const{L:r,a:o,b:s}=Cl(It(e),It(t),It(n)),i=Math.hypot(o,s),a=i<1e-6?0:(Math.atan2(s,o)*180/Math.PI+360)%360;return{L:r,C:i,H:a}}const mx=[[.47,.17,25],[.5,.122,55],[.555,.112,90],[.48,.12,125],[.545,.15,150],[.44,.077,185],[.555,.098,215],[.545,.15,252],[.44,.17,282],[.58,.16,308],[.48,.17,338],[.58,.16,5]],ns=Object.freeze(mx.map(([e,t,n])=>Gt(Qr(e,t,n)))),Fd=ns.map(e=>{const{L:t,C:n,H:r}=tn(Cn(e,{})),o=r*Math.PI/180;return{L:t,a:n*Math.cos(o),b:n*Math.sin(o)}});function gx(e,t){const n=Fd[e],r=Fd[t];return Math.hypot(n.L-r.L,n.a-r.a,n.b-r.b)}function vx(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function Kp(e){return vx(e.trim())%ns.length}function Au(e){return ns[Kp(e)]}const Ui=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function zu(e){return!e||Ui(e,An.accent)}function yx(e){return Ui(e.name,An.name)&&e.logo.trim()===An.logo&&zu(e.accent)}function Fu(e){try{return Cn(e,{})}catch{return null}}function xx(e){return!zu(e.accent)&&Fu(e.accent)?e.accent.trim():Ui(e.name,An.name)?An.accent:Au(e.name)}function wx(e){return!zu(e.accent)&&Fu(e.accent)||Ui(e.name,An.name)?null:Au(e.name)}function Uu(e,t=4.5){const n=Fu(e);return n?We({r:1,g:1,b:1,a:1},n)>=t?"white":"black":"white"}const Pl={small:16,large:32},Sx=.22,kx=.76,Ud='"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, -apple-system, "Segoe UI", sans-serif';function Qp(e,t){const n=t*Sx;e.beginPath(),e.moveTo(n,0),e.lineTo(t-n,0),e.quadraticCurveTo(t,0,t,n),e.lineTo(t,t-n),e.quadraticCurveTo(t,t,t-n,t),e.lineTo(n,t),e.quadraticCurveTo(0,t,0,t-n),e.lineTo(0,n),e.quadraticCurveTo(0,0,n,0),e.closePath()}function jx(e,t,n){Qp(e,t),e.fillStyle=n,e.fill()}function Bd(e,t){const n=e.measureText(t),r=n.actualBoundingBoxLeft??0,o=n.actualBoundingBoxRight??n.width,s=n.actualBoundingBoxAscent??0,i=n.actualBoundingBoxDescent??0;return{left:r,ascent:s,w:r+o,h:s+i}}function Ex(e,t,n,r){const o=t*kx;let s=o;e.font=`600 ${s}px ${Ud}`;let i=Bd(e,n);const a=Math.max(i.w,i.h);a>0&&(s=s*o/a,e.font=`600 ${s}px ${Ud}`,i=Bd(e,n)),e.fillStyle=r,e.textAlign="left",e.textBaseline="alphabetic",e.fillText(n,(t-i.w)/2+i.left,(t-i.h)/2+i.ascent)}function Nx(e,t,n){const r=n.naturalWidth||n.width||t,o=n.naturalHeight||n.height||t,s=Math.max(t/r,t/o),i=r*s,a=o*s;e.save(),Qp(e,t),e.clip(),e.drawImage(n,(t-i)/2,(t-a)/2,i,a),e.restore()}function Cx(e,t){const{content:n,size:r}=t;"glyph"in n?Ex(e,r,n.glyph,t.foreground??"white"):"image"in n?Nx(e,r,n.image):e.drawImage(n.icon,0,0,r,r)}const Px=.22,Tx=.07;function bx(e,t,n){const r=t*Px,o=t-r;e.save(),e.globalCompositeOperation="destination-out",e.beginPath(),e.arc(o,o,r+t*Tx,0,Math.PI*2),e.fill(),e.restore(),e.beginPath(),e.arc(o,o,r,0,Math.PI*2),e.fillStyle=n,e.fill()}function Tl(e){try{const n=(e.doc??document).createElement("canvas");n.width=e.size,n.height=e.size;const r=n.getContext("2d");if(!r)return null;"icon"in e.content||jx(r,e.size,e.color),Cx(r,e),e.dot&&bx(r,e.size,e.dot);const o=n.toDataURL("image/png");return o.startsWith("data:image/png")?o:null}catch{return null}}const Dr="data-paddock-default-href",bl="data-paddock-default-type",vi="data-paddock-favicon";function Gp(e){return Array.from(e.head.querySelectorAll('link[rel~="icon"]'))}function Rx(e,t=document){let n=Gp(t);if(n.length===0){const r=t.createElement("link");r.rel="icon",r.setAttribute(vi,""),t.head.appendChild(r),n=[r]}for(const r of n){!r.hasAttribute(Dr)&&!r.hasAttribute(vi)&&(r.setAttribute(Dr,r.getAttribute("href")??""),r.setAttribute(bl,r.getAttribute("type")??""));const o=r.getAttribute("sizes")==="16x16"?e.small:e.large;r.getAttribute("href")!==o&&r.setAttribute("href",o),e.type?r.setAttribute("type",e.type):r.removeAttribute("type")}}function Wd(e=document){for(const t of Gp(e)){if(t.hasAttribute(vi)){t.remove();continue}if(!t.hasAttribute(Dr))continue;t.setAttribute("href",t.getAttribute(Dr)??"");const n=t.getAttribute(bl);n?t.setAttribute("type",n):t.removeAttribute("type"),t.removeAttribute(Dr),t.removeAttribute(bl)}}function Lx(e=document){const t=e.head.querySelector('link[rel~="icon"][sizes="32x32"]')??e.head.querySelector('link[rel~="icon"][type="image/png"]');return!t||t.hasAttribute(vi)?null:t.getAttribute(Dr)??t.getAttribute("href")}function Rl(e,t){return new Promise((n,r)=>{const o=new Image;t&&(o.crossOrigin="anonymous"),o.onload=()=>n(o),o.onerror=()=>r(new Error(`favicon: could not load ${e}`)),o.src=e})}function Hd(e,t,n){const r=Uu(t,3),o=Tl({content:e,color:t,foreground:r,dot:n,size:Pl.large}),s=o&&Tl({content:e,color:t,foreground:r,dot:n,size:Pl.small});return o&&s?{large:o,small:s,type:"image/png"}:null}function Mx(e){return(Array.from(e.trim())[0]??"P").toUpperCase()}function _x(e,t){if(yx(e))return t({kind:"shipped"}),()=>{};const n=xx(e),r=e.logo.trim(),o={glyph:Mx(e.name)};if(!Vp(r))return t({kind:"chip",content:{glyph:r},color:n}),()=>{};let s=!1;const i=u=>{s||t(u)},a=()=>Rl(r,!1).then(()=>i({kind:"raw",src:r}),()=>i({kind:"chip",content:o,color:n}));return Rl(r,!0).then(u=>{s||(Tl({content:{image:u},color:n,size:Pl.small})?i({kind:"chip",content:{image:u},color:n}):a())},a),()=>{s=!0}}function Ix(e,t,n){const r=t?ux[t]:void 0;switch(e.kind){case"shipped":return r?n().then(o=>o?Hd({icon:o},"transparent",r):null):null;case"chip":return Hd(e.content,e.color,r);case"raw":return{small:e.src,large:e.src}}}function Dx(e,t=null){const{name:n,logo:r,accent:o}=e,[s,i]=x.useState(null),a=x.useRef(new WeakMap),u=x.useRef(null);x.useEffect(()=>_x({name:n,logo:r,accent:o},i),[n,r,o]),x.useEffect(()=>{if(!s)return;const c=t??"none";let d=a.current.get(s);d||a.current.set(s,d=new Map);const f=g=>{g?Rx(g):Wd()};if(d.has(c)){f(d.get(c)??null);return}const S=Ix(s,t,()=>{if(!u.current){const g=Lx(),C=g?Rl(g,!1).catch(()=>(u.current===C&&(u.current=null),null)):Promise.resolve(null);u.current=C}return u.current});if(!(S instanceof Promise)){d.set(c,S),f(S);return}let k=!1;return S.then(g=>{g&&d.set(c,g),k||f(g)}),()=>{k=!0}},[s,t]),x.useEffect(()=>()=>Wd(),[])}const Yp={running:!1,unread:0,kind:"none"};function Ox(e,{active:t,finished:n,hiddenSince:r}){if(!e)return Yp;if(e.kind==="chat"){const a=t.has(e.sessionId);return{kind:"chat",running:a,unread:!a&&e.unread?1:0}}const o=a=>e.kind==="instance"||a===e.key;let s=!1;for(const a of t.values())o(a)&&(s=!0);let i=0;if(r!==null)for(const a of n)a.at>r&&o(a.projectSlug)&&(i+=1);return{kind:e.kind,running:s,unread:i}}function $x(e){let t=e.running?"● ":"";return e.unread>0&&(t+=e.kind==="chat"?"✓ ":`(${e.unread}) `),t}function Ax(e){return e.running?"running":e.unread>0?"unread":null}function Ws(e){return e?e.kind==="chat"?`chat:${e.sessionId}:${e.unread?1:0}`:e.kind==="workspace"?`ws:${e.key}`:"instance":"none"}const Jp=x.createContext({status:Yp,scopeKey:"none",setScope:()=>{}});function yS(e){const{status:t,scopeKey:n,setScope:r}=x.useContext(Jp),o=Ws(e),s=x.useMemo(()=>e,[o]);return x.useEffect(()=>{r(s)},[s,r]),x.useEffect(()=>()=>r(null),[r]),n===o?$x(t):""}function zx(){const[e,t]=x.useState(()=>typeof document<"u"&&document.visibilityState==="hidden"?Date.now():null);return x.useEffect(()=>{const n=()=>t(r=>document.visibilityState==="hidden"?r??Date.now():null);return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Fx(e){const[t,n]=x.useState(null),r=x.useCallback(u=>{n(c=>Ws(c)===Ws(u)?c:u)},[]),o=zx(),s=Ox(t,{...e,hiddenSince:o}),i=Ws(t),a=`${i}|${s.kind}|${s.running?1:0}|${s.unread}`;return x.useMemo(()=>({status:s,scopeKey:i,setScope:r}),[a,r])}const Bu=[{slug:"homelab",label:"Homelab",blurb:"Servers, networking, self-hosted services."},{slug:"house",label:"House",blurb:"Physical home systems — water, climate, power, garden."},{slug:"side-projects",label:"Side Projects",blurb:"Apps and ideas of your own."}],Vd="",Xp=new Map(Bu.map(e=>[e.slug,e]));function Ux(e){if(!e)return"Unsorted";const t=Xp.get(e);return t?t.label:e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function xS(e){var t;return(t=Xp.get(e))==null?void 0:t.blurb}function Bx(e){const t=new Set(e),n=[];for(const o of Bu)t.has(o.slug)&&(n.push(o.slug),t.delete(o.slug));const r=t.delete(Vd);return n.push(...[...t].sort()),r&&n.push(Vd),n}const Zp=25e3,qp=1e4,Wx=Zp+qp+5e3,Hx=500,Vx=1e4;class Kx{constructor(){this.ws=null,this.outbox=[],this.subs=new Map,this.pingTimer=null,this.pongTimer=null,this.awaitingPong=!1,this.lastPongAt=0,this.reconnectTimer=null,this.reconnectAttempts=0,this.manualClose=!1,this.stateListeners=new Set,this._state="closed",this.activeSessions=new Map,this.activeStartedAt=new Map,this.backgroundTasks=new Map,this.backgroundListeners=new Set,this.stopTaskListeners=new Set,this.activeListeners=new Set,this.activeInfoListeners=new Set,this.knownSessions=new Set;const n=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`;if(this.url=`${n.replace(/^http/,"ws")}/ws`,typeof window<"u"){const r=()=>this.ensureLive();window.addEventListener("online",r),window.addEventListener("focus",r),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&this.ensureLive()})}}get state(){return this._state}onState(t){return this.stateListeners.add(t),t(this._state),()=>this.stateListeners.delete(t)}setState(t){if(this._state!==t){this._state=t;for(const n of this.stateListeners)n(t)}}onActiveSessions(t){return this.activeListeners.add(t),t(new Set(this.activeSessions.keys())),this.connect(),()=>this.activeListeners.delete(t)}onActiveInfos(t){return this.activeInfoListeners.add(t),t(new Map(this.activeSessions)),this.connect(),()=>this.activeInfoListeners.delete(t)}turnStartedAt(t){return this.activeStartedAt.get(t)??null}backgroundWork(t){return this.backgroundTasks.get(t)??[]}onBackgroundWork(t,n){const r=(o,s)=>{o===t&&n(s)};return this.backgroundListeners.add(r),n(this.backgroundWork(t)),this.connect(),()=>this.backgroundListeners.delete(r)}setActive(t,n,r,o){const s=this.activeSessions.has(t);if(n?(this.activeSessions.set(t,r),o!=null&&!this.activeStartedAt.has(t)&&this.activeStartedAt.set(t,o)):(this.activeSessions.delete(t),this.activeStartedAt.delete(t)),this.activeSessions.has(t)!==s){const i=new Set(this.activeSessions.keys());for(const u of this.activeListeners)u(i);const a=new Map(this.activeSessions);for(const u of this.activeInfoListeners)u(a)}}subscribe(t,n,r){const o=Symbol("chat-sub"),s={projectSlug:t,sessionId:n,handlers:r,lastSeq:-1,turnActive:!1};return this.subs.set(o,s),this.connect(),n&&this.attachSession(s,!1),{setSessionId:i=>{const a=this.subs.get(o);a&&(a.sessionId=i,i&&this.attachSession(a,!1))},unsubscribe:()=>{this.subs.delete(o)}}}attachSession(t,n){t.sessionId&&(this.knownSessions.add(t.sessionId),this.transmit(JSON.stringify({type:"chat:subscribe",payload:{projectSlug:t.projectSlug,sessionId:t.sessionId,wantReplay:n,lastSeq:t.lastSeq}})))}send(t,n,r,o){const s={projectSlug:t,sessionId:r,message:n};o!=null&&o.preloadContext&&(s.preloadContext=!0),o!=null&&o.model&&(s.model=o.model),o!=null&&o.attachments&&o.attachments.length>0&&(s.attachments=o.attachments),this.markTurnStart(t,r),this.transmit(JSON.stringify({type:"chat:send",payload:s}))}setQueued(t,n,r,o,s){const i={projectSlug:t,sessionId:n,text:r,qid:o};s&&s.length>0&&(i.attachments=s.map(a=>({id:a.id,filename:a.filename,kind:a.kind}))),this.transmit(JSON.stringify({type:"chat:set_queue",payload:i}))}markTurnStart(t,n){for(const r of this.subs.values())r.projectSlug===t&&r.sessionId===n&&(r.lastSeq=-1,r.turnActive=!0)}sendCommand(t,n,r){this.markTurnStart(t,r),this.transmit(JSON.stringify({type:"chat:command",payload:{projectSlug:t,sessionId:r,command:n}}))}cancel(t){this.transmit(JSON.stringify({type:"chat:cancel",payload:{jobId:t}}))}stopTask(t,n){this.transmit(JSON.stringify({type:"chat:stop_task",payload:{sessionId:t,taskId:n}}))}onStopTaskResult(t,n){const r=(o,s)=>{o===t&&n(s)};return this.stopTaskListeners.add(r),()=>this.stopTaskListeners.delete(r)}continueChat(t,n){this.markTurnStart(t,n),this.transmit(JSON.stringify({type:"chat:continue",payload:{projectSlug:t,sessionId:n}}))}transmit(t){this.isLive()?this.ws.send(t):(this.outbox.push(t),this.ensureLive())}isLive(){var t;return((t=this.ws)==null?void 0:t.readyState)!==WebSocket.OPEN?!1:Date.now()-this.lastPongAt<Wx}wantsSocket(){return this.subs.size>0||this.activeListeners.size>0||this.activeInfoListeners.size>0}ensureLive(){var n;if(!this.wantsSocket())return;const t=(n=this.ws)==null?void 0:n.readyState;t===WebSocket.OPEN?this.sendPing():t!==WebSocket.CONNECTING&&(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectAttempts=0,this.connect())}flushOutbox(){var n;if(((n=this.ws)==null?void 0:n.readyState)!==WebSocket.OPEN||this.outbox.length===0)return;const t=this.outbox;this.outbox=[];for(const r of t)this.ws.send(r)}connect(){if(this.manualClose=!1,this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))return;this.setState("connecting");let t;try{t=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.ws=t,t.onopen=()=>{this.reconnectAttempts=0,this.awaitingPong=!1,this.lastPongAt=Date.now(),this.setState("open"),this.flushOutbox();for(const n of this.subs.values())n.sessionId&&this.attachSession(n,n.turnActive);this.startPing()},t.onclose=()=>{this.stopPing(),this.setState("closed"),this.manualClose||this.scheduleReconnect()},t.onerror=()=>{t.close()},t.onmessage=n=>this.dispatch(n.data)}startPing(){this.stopPing(),this.pingTimer=setInterval(()=>this.sendPing(),Zp)}sendPing(){var t;if(!(((t=this.ws)==null?void 0:t.readyState)!==WebSocket.OPEN||this.awaitingPong)){this.awaitingPong=!0;try{this.ws.send(JSON.stringify({type:"ping"}))}catch{this.awaitingPong=!1,this.ws.close();return}this.pongTimer=setTimeout(()=>{var n;this.pongTimer=null,this.awaitingPong&&((n=this.ws)==null||n.close())},qp)}}stopPing(){this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.pongTimer&&clearTimeout(this.pongTimer),this.pongTimer=null,this.awaitingPong=!1}scheduleReconnect(){if(this.reconnectTimer)return;const t=Math.min(Vx,Hx*2**this.reconnectAttempts);this.reconnectAttempts+=1,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},t)}route(t,n){const r=[...this.subs.values()].filter(s=>s.projectSlug===t);if(r.length===0)return;if(n){const s=r.find(i=>i.sessionId===n);if(s)return s;if(this.knownSessions.has(n))return}const o=r.find(s=>s.sessionId===null);if(o)return o;if(n===null&&r.length===1)return r[0]}dispatch(t){var c,d,f,p,S,k,g,C,m,h,v,E,T,R,M,y,D,b,B,ee,ce,fe,st,Ze,St,I,z,Q;let n;try{n=JSON.parse(t)}catch{return}if(n.type==="pong"){this.awaitingPong=!1,this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null),this.lastPongAt=Date.now(),this.flushOutbox();return}if(n.type==="chat:stop_task_result"){const{sessionId:O,taskId:Y,outcome:se,message:X}=n.payload;if(O&&Y&&se)for(const Ee of this.stopTaskListeners)Ee(O,{taskId:Y,outcome:se,message:X});return}const r=n.payload.projectSlug;if(r==null)return;if(n.type==="chat:error"){const O=this.route(r,null);(d=O==null?void 0:(c=O.handlers).onError)==null||d.call(c,n.payload.error);return}if(n.type==="chat:resync"){const O=this.route(r,n.payload.sessionId);(p=O==null?void 0:(f=O.handlers).onResync)==null||p.call(f);return}if(n.type==="chat:background"){const{sessionId:O,tasks:Y}=n.payload;if(O){const se=Array.isArray(Y)?Y:[];se.length===0?this.backgroundTasks.delete(O):this.backgroundTasks.set(O,se);for(const X of this.backgroundListeners)X(O,se)}return}if(n.type==="chat:active"){this.setActive(n.payload.sessionId,n.payload.running,r,n.payload.startedAt);for(const O of this.subs.values())O.projectSlug===r&&O.sessionId===n.payload.sessionId&&((k=(S=O.handlers).onActive)==null||k.call(S,{running:n.payload.running,turnRunning:n.payload.turnRunning??n.payload.running,jobId:n.payload.jobId}));return}if(n.type==="chat:queued_flushed"){const{sessionId:O,text:Y,attachments:se}=n.payload;if(O){Zt(async()=>{const{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{X(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((C=(g=X.handlers).onQueuedFlushed)==null||C.call(g,{text:Y,attachments:se}))}return}if(n.type==="chat:queued_state"){const{sessionId:O,text:Y,qid:se,reason:X,attachments:Ee}=n.payload;if(O){const ie=Y&&Y.length>0?Y:null,ze=Ee??[],Ft=ie!==null||ze.length>0;Zt(async()=>{const{writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr}=await import("./queued-CagZVfWU.js");return{writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr}},[]).then(({writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr})=>{Ut(O,r,ie),dn(O,r,Ft?se??null:null),Zr(O,r,ze)});for(const Ut of this.subs.values())Ut.projectSlug===r&&Ut.sessionId===O&&((h=(m=Ut.handlers).onQueuedState)==null||h.call(m,{text:ie,attachments:ze,qid:se,reason:X}))}return}if(n.type==="chat:queued_returned"){const{sessionId:O,text:Y,attachments:se}=n.payload;if(O&&typeof Y=="string"){Zt(async()=>{const{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{X(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((E=(v=X.handlers).onQueuedReturned)==null||E.call(v,{text:Y,attachments:se}))}return}if(n.type==="chat:killed_task"){const{sessionId:O,summary:Y,timestamp:se}=n.payload;if(O)for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((R=(T=X.handlers).onKilledTask)==null||R.call(T,{summary:Y??"",timestamp:se??""}));return}const{sessionId:o,jobId:s}=n.payload,i=this.route(r,o);if(!i)return;const a={sessionId:o,jobId:s},u=n.payload.seq;switch(typeof u=="number"&&u>i.lastSeq&&(i.lastSeq=u),i.turnActive=n.type!=="chat:complete",n.type){case"chat:response":(y=(M=i.handlers).onResponse)==null||y.call(M,n.payload.chunk,a);break;case"chat:tool_call":(b=(D=i.handlers).onToolCall)==null||b.call(D,{toolName:n.payload.toolName,inputSummary:n.payload.inputSummary,output:n.payload.output,isError:n.payload.isError,durationMs:n.payload.durationMs,toolUseId:n.payload.toolUseId,subagentType:n.payload.subagentType,description:n.payload.description,hasSubagent:n.payload.hasSubagent},a);break;case"chat:tool_start":(ee=(B=i.handlers).onToolStart)==null||ee.call(B,{toolName:n.payload.toolName,inputSummary:n.payload.inputSummary,toolUseId:n.payload.toolUseId,output:"",isError:!1,pending:!0,subagentType:n.payload.subagentType,description:n.payload.description,hasSubagent:n.payload.hasSubagent},a);break;case"chat:message_boundary":(fe=(ce=i.handlers).onMessageBoundary)==null||fe.call(ce,a);break;case"chat:injected":(Ze=(st=i.handlers).onInjected)==null||Ze.call(st,{sender:n.payload.sender,content:n.payload.content,timestamp:n.payload.timestamp},a);break;case"chat:notice":(I=(St=i.handlers).onNotice)==null||I.call(St,n.payload.notice,a);break;case"chat:complete":(Q=(z=i.handlers).onComplete)==null||Q.call(z,{...a,success:n.payload.success,error:n.payload.error,model:n.payload.model,usage:n.payload.usage});break}}}const Wu=new Kx,nn=new Map,Ll="paddock:lastSeen-changed";function Hu(e){try{window.dispatchEvent(new CustomEvent(Ll,{detail:{sessionId:e}}))}catch{}}function Qx(e){return nn.get(e)??0}function Gx(e,t){!t||!Number.isFinite(t)||t<=(nn.get(e)??0)||(nn.set(e,t),Hu(e))}function wS(e,t=Date.now()){const n=nn.get(e)??0;return t<=n||(nn.set(e,t),Hu(e)),n}function SS(e,t,n){nn.get(e)===n&&(t?nn.set(e,t):nn.delete(e),Hu(e))}const Ml="paddock:chats-gone";function kS(e){if(e.length!==0){for(const t of e)nn.delete(t);try{window.dispatchEvent(new CustomEvent(Ml,{detail:{sessionIds:e}}))}catch{}}}function Yx({tag:e,className:t=""}){const n=es();return l.jsx("button",{type:"button",onClick:r=>{r.preventDefault(),r.stopPropagation(),n(`/tags/${encodeURIComponent(e)}`)},title:`Show projects tagged ${e}`,className:`tag relative z-10 transition-colors hover:bg-surface-selected ${t}`,children:e})}const Jx=/^\d{4}-\d{2}-\d{2}$/;function yi(e){if(!e)return"";if(Jx.test(e)){const[u,c,d]=e.split("-").map(Number),f=new Date(u,c-1,d);if(Number.isNaN(f.getTime()))return e;const p=new Date,S=new Date(p.getFullYear(),p.getMonth(),p.getDate()),k=Math.round((S.getTime()-f.getTime())/864e5);return k<=0?"today":k===1?"yesterday":k<7?`${k}d ago`:k<35?`${Math.round(k/7)}w ago`:k<365?`${Math.round(k/30)}mo ago`:`${Math.round(k/365)}y ago`}const t=new Date(e).getTime();if(Number.isNaN(t))return e;const n=Math.round((Date.now()-t)/1e3);if(n<45)return"just now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const o=Math.round(r/60);if(o<24)return`${o}h ago`;const s=Math.round(o/24);if(s<7)return`${s}d ago`;const i=Math.round(s/7);if(i<5)return`${i}w ago`;const a=Math.round(s/30);return a<12?`${a}mo ago`:`${Math.round(s/365)}y ago`}function jS(e){if(!e)return"";const t=new Date(e).getTime();if(Number.isNaN(t))return e;const n=Math.round((t-Date.now())/1e3);if(n<=30)return"now";const r=Math.round(n/60);if(r<60)return`in ${r}m`;const o=Math.round(r/60);if(o<24)return`in ${o}h`;const s=Math.round(o/24);if(s<7)return`in ${s}d`;const i=Math.round(s/7);if(i<5)return`in ${i}w`;const a=Math.round(s/30);return a<12?`in ${a}mo`:`in ${Math.round(s/365)}y`}function Ea(e){return!Number.isFinite(e)||e<0?"0":e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:2)}M`:e>=1e3?`${Math.round(e/1e3)}K`:`${Math.round(e)}`}function Xx(e){return!Number.isFinite(e)||e<=0?"$0.00":e<.01?"<$0.01":`$${e.toFixed(2)}`}function ES(e){if(!(!e||e.totalTokens==null))return{inputTokens:e.inputTokens??0,outputTokens:e.outputTokens??0,cacheReadTokens:e.cacheReadTokens??0,cacheCreationTokens:e.cacheCreationTokens??0,totalTokens:e.totalTokens,costUsd:e.costUsd??null}}function NS(e){const t=e.inputTokens+e.cacheReadTokens+e.cacheCreationTokens,n=`${Ea(e.totalTokens)} tokens · ${Ea(t)} in / ${Ea(e.outputTokens)} out`;return e.costUsd==null?n:`${n} · ~${Xx(e.costUsd)} at API rates`}function CS(e){if(e==null||Number.isNaN(e))return null;if(e<1e3)return`${Math.round(e)}ms`;const t=e/1e3;if(t<10)return`${t.toFixed(1)}s`;if(t<60)return`${Math.round(t)}s`;const n=Math.floor(t/60),r=Math.round(t%60);return r?`${n}m ${r}s`:`${n}m`}const Zx="This session is being continued from a previous conversation";function PS(e){return e.trimStart().startsWith(Zx)}function TS(e){const t=/^\s*<command-name>([^<]*)<\/command-name>/.exec(e);if(!t)return null;const n=t[1].trim();return n.length>0?n:null}function bS(e){return e.trimStart().startsWith("<local-command-caveat>")}function RS(e){const t=/^\s*<local-command-stdout>([\s\S]*)<\/local-command-stdout>\s*$/.exec(e);if(!t)return null;const n=t[1].trim();return n.length>0?n:null}function LS(e){return/^\s*<local-command-stdout>[\s\S]*<\/local-command-stdout>\s*$/.test(e)}function MS(e){return e.trimStart().startsWith("<task-notification>")}function _S(e){var r;const t=/<summary>([\s\S]*?)<\/summary>/.exec(e),n=(r=t==null?void 0:t[1])==null?void 0:r.trim();return n&&n.length>0?n:"Background agent updated"}function IS(e){var r;const t=/<status>([\s\S]*?)<\/status>/.exec(e),n=(r=t==null?void 0:t[1])==null?void 0:r.trim().toLowerCase();return n&&n.length>0?n:null}function DS(e){return e==="killed"||e==="stopped"}function qx(e){const t=Math.max(0,Math.floor(e/1e3)),n=t%60,r=Math.floor(t/60)%60,o=Math.floor(t/3600),s=String(n).padStart(2,"0");return o>0?`${o}:${String(r).padStart(2,"0")}:${s}`:`${r}:${s}`}const _l="paddock:transcriptsMigration:dismissed";function e1(){try{return localStorage.getItem(_l)==="1"}catch{return!1}}function Kd(e){try{e?localStorage.setItem(_l,"1"):localStorage.removeItem(_l)}catch{}}let xo=null;function t1(){if(!xo)try{xo=ar.transcriptsMigration().catch(()=>null)}catch{xo=Promise.resolve(null)}return xo}function n1(){xo=null}function em(){const[e,t]=x.useState(null),[n,r]=x.useState(e1);x.useEffect(()=>{let s=!0;return t1().then(i=>{!s||!i||(t(i),i&&!i.eligible&&(Kd(!1),r(!1)))}),()=>{s=!1}},[]);const o=x.useCallback(()=>{Kd(!0),r(!0)},[]);return{probe:e,showBanner:(e==null?void 0:e.eligible)===!0&&!n,showInConfig:e!=null&&e.mode==="own"&&(e.eligible||e.reason==="profile-paranoid"),dismiss:o}}function Bi(e){return((e==null?void 0:e.projects)??[]).flatMap(t=>t.chats)}function r1(e){return new Set(Bi(e).filter(t=>t.defaultSelected).map(t=>t.sessionId))}function o1(e,t){const n=e.chats.length,r=e.chats.reduce((o,s)=>o+(t.has(s.sessionId)?1:0),0);return{selected:r,total:n,all:n>0&&r===n,some:r>0&&r<n}}function s1(e,t,n){const r=new Set(e);for(const o of t.chats)n?r.add(o.sessionId):r.delete(o.sessionId);return r}function i1(e,t){return t?new Set(Bi(e).map(n=>n.sessionId)):new Set}function a1(e,t){const n=new Set(e);return n.delete(t)||n.add(t),n}function l1(e,t){const n=Bi(e).map(r=>r.sessionId);return{sessionIds:n.filter(r=>t.has(r)),plannedSessionIds:n,expectedVersion:e.configVersion}}function u1(e){const t=(e==null?void 0:e.totals.identical)??0,n=((e==null?void 0:e.projects)??[]).reduce((o,s)=>o+s.projectExtras.length,0),r=(e==null?void 0:e.sweepers.chats)??0;return{identical:t,projectExtras:n,sweeperChats:r,total:t+n+r}}function tm(e){return e?e.projects.length===0&&e.sweepers.stores===0:!1}function nm(e){return!e.ok||e.failed.length>0?"partial":e.alreadyMigrated?"already":e.migrated.length===0&&e.preserved.length===0?"nothing":"done"}function c1(e){const t=new Map;for(const n of e){const r=t.get(n.slug);r?r.push(n):t.set(n.slug,[n])}return[...t.entries()].map(([n,r])=>({slug:n,items:r}))}const d1={new:{label:"New",hint:"Not in ~/.claude yet. Moving it in loses nothing."},"fast-forward":{label:"Fast-forward",hint:"One copy is just a longer version of the other. Lossless either way."},diverged:{label:"Diverged",hint:"Both copies have messages the other does not. Ticking keeps Paddock's copy in ~/.claude; the other is kept too, in the preserve folder."},unknown:{label:"Not compared",hint:"Paddock ran out of scan budget before it could compare these two copies, so it has not assumed they are safe to merge."}};function xi(e){return d1[e]??{label:String(e),hint:"This Paddock build does not recognise this state, so it is shown as the server described it."}}function Qd(e){const t=e.indexOf("/.claude/");return t===-1?e:`~${e.slice(t)}`}function f1(e,t){return t==="all"?!0:t==="needs-decision"?!e.defaultSelected:e.state===t}function Ye(...e){return e.filter(Boolean).join(" ")}const h1={primary:"bg-accent-solid text-accent-fg shadow-xs hover:bg-accent-solid-hover active:scale-[0.98]",ghost:"bg-surface-active text-fg hover:bg-surface-selected",subtle:"text-fg-muted hover:bg-surface-hover hover:text-fg",danger:"bg-danger-solid text-danger-fg shadow-xs hover:brightness-110 active:scale-[0.98]",link:"text-accent underline underline-offset-2 hover:no-underline"},p1={sm:"gap-1.5 px-2 py-1 text-xs rounded-md",md:"gap-2 px-3.5 py-2 text-sm rounded-lg","icon-sm":"h-6 w-6 justify-center rounded-md","icon-md":"h-9 w-9 justify-center rounded-lg"};function jt({variant:e="ghost",size:t="md",icon:n,loading:r=!1,loadingLabel:o,align:s="center",className:i,children:a,disabled:u,type:c="button",...d}){return l.jsxs("button",{type:c,disabled:u||r,"aria-busy":r||void 0,className:Ye("inline-flex select-none items-center font-medium","motion-fast transition-[color,background-color,border-color,box-shadow,transform]","disabled:cursor-not-allowed disabled:opacity-50",s==="start"?"justify-start text-left":"justify-center",p1[t],h1[e],i),...d,children:[n,r&&o?o:a]})}const Vu=["w-full rounded-lg border border-edge-strong bg-surface-sunken px-3 py-2 text-sm text-fg","outline-none motion-fast transition-[border-color,box-shadow]","focus:border-accent focus:ring-2 focus:ring-accent/25","disabled:cursor-not-allowed disabled:opacity-60","aria-[invalid=true]:border-danger aria-[invalid=true]:focus:ring-danger/25"].join(" ");function OS({className:e,...t}){return l.jsx("input",{className:Ye(Vu,e),...t})}function $S({className:e,...t}){return l.jsx("textarea",{className:Ye(Vu,"resize-y",e),...t})}function AS({className:e,...t}){return l.jsx("select",{className:Ye(Vu,e),...t})}function zS({checked:e,onChange:t,label:n,disabled:r,id:o,className:s}){const i=x.useId(),a=o??i;return l.jsxs("label",{htmlFor:a,className:Ye("relative inline-block shrink-0 cursor-pointer",s),children:[l.jsx("input",{id:a,type:"checkbox","aria-label":n,className:"peer sr-only",checked:e,disabled:r,onChange:u=>t(u.target.checked)}),l.jsx("span",{className:Ye("block h-[18px] w-8 rounded-full bg-edge-strong","motion-fast transition-colors","after:absolute after:left-0.5 after:top-0.5 after:h-3.5 after:w-3.5 after:rounded-full","after:bg-surface-raised after:shadow-2xs after:transition-transform after:content-['']","peer-checked:bg-accent-solid peer-checked:after:translate-x-3.5","peer-focus-visible:ring-2 peer-focus-visible:ring-accent/50","peer-disabled:opacity-50")})]})}function rm({label:e,description:t,indeterminate:n=!1,className:r,...o}){const s=x.useRef(null);x.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const i=l.jsx("input",{ref:s,type:"checkbox",...n?{"aria-checked":"mixed"}:{},className:Ye("h-4 w-4 shrink-0 cursor-pointer rounded border-edge-strong accent-[var(--accent-solid)]","disabled:cursor-not-allowed disabled:opacity-50",e?"mt-0.5":"",r),...o});return e?l.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-sm text-fg",children:[i,l.jsxs("span",{className:"min-w-0",children:[e,t&&l.jsx("span",{className:"block text-xs leading-snug text-fg-muted",children:t})]})]}):i}const om={neutral:"bg-surface-active text-fg-muted",accent:"bg-accent-soft text-accent",success:"bg-success-soft text-success",warn:"bg-warn-soft text-warn",danger:"bg-danger-soft text-danger",info:"bg-info-soft text-info",lineage:"bg-lineage-soft text-lineage"},sm={neutral:"bg-fg-subtle",accent:"bg-accent-solid",success:"bg-success-solid",warn:"bg-warn-solid",danger:"bg-danger-solid",info:"bg-info-solid",lineage:"bg-lineage-solid"};function m1({tone:e="neutral",shape:t="tag",size:n="md",dot:r=!1,icon:o,title:s,className:i,children:a}){return l.jsxs("span",{title:s,className:Ye("inline-flex items-center gap-1 font-medium leading-none",t==="pill"?"rounded-full px-2 py-0.5":"rounded-md px-1.5 py-0.5",n==="sm"?"text-3xs":"text-2xs",om[e],i),children:[r&&l.jsx("span",{className:Ye("h-1.5 w-1.5 shrink-0 rounded-full",sm[e])}),o,a]})}function FS({tone:e="neutral",pulse:t=!1,className:n}){return l.jsx("span",{className:Ye("inline-block h-2 w-2 shrink-0 rounded-full",sm[e],t&&"animate-pulse",n)})}function Xt({tone:e="info",icon:t,className:n,children:r}){const o={neutral:"border-edge",accent:"border-accent-edge",success:"border-success-edge",warn:"border-warn-edge",danger:"border-danger-edge",info:"border-info-edge",lineage:"border-lineage-edge"};return l.jsxs("div",{role:e==="danger"?"alert":void 0,className:Ye("flex items-start gap-2 rounded-lg border px-3 py-2 text-sm",om[e],o[e],n),children:[t&&l.jsx("span",{className:"mt-0.5 shrink-0",children:t}),l.jsx("div",{className:"min-w-0",children:r})]})}function g1(e,t){x.useEffect(()=>{if(!e)return;const n=r=>{r.key==="Escape"&&t()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,t])}const v1={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl"};function y1({open:e,onClose:t,title:n,hideTitle:r=!1,description:o,footer:s,size:i="md",role:a="dialog",dismissOnBackdrop:u=!0,onSubmit:c,className:d,children:f}){const p=x.useRef(null),S=x.useRef(null);if(g1(e,t),x.useEffect(()=>{var C,m;return e?(S.current=document.activeElement,(m=((C=p.current)==null?void 0:C.querySelector("[autofocus], input:not([type=hidden]), textarea, select, button, [href], [tabindex]:not([tabindex='-1'])"))??p.current)==null||m.focus(),()=>{const h=S.current;h instanceof HTMLElement&&h.focus()}):void 0},[e]),x.useEffect(()=>{if(!e)return;const g=C=>{if(C.key!=="Tab"||!p.current)return;const m=[...p.current.querySelectorAll("input:not([type=hidden]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [href], [tabindex]:not([tabindex='-1'])")];if(m.length===0)return;const h=m[0],v=m[m.length-1],E=document.activeElement;C.shiftKey&&(E===h||!p.current.contains(E))?(C.preventDefault(),v.focus()):!C.shiftKey&&E===v&&(C.preventDefault(),h.focus())};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[e]),!e)return null;const k=c?"form":"div";return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>u&&t(),children:l.jsxs(k,{ref:p,role:a,"aria-modal":"true","aria-label":n,tabIndex:-1,onClick:g=>g.stopPropagation(),onSubmit:c,className:Ye("flex max-h-[85vh] w-full flex-col animate-scale-in rounded-2xl border border-edge","bg-surface-raised p-6 shadow-2xl outline-none",v1[i],d),children:[!r&&l.jsx("h2",{className:"text-base font-semibold text-fg",children:n}),o&&l.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:o}),l.jsx("div",{className:"-mx-1 min-h-0 flex-1 overflow-y-auto px-1 py-1",children:f}),s&&l.jsx("div",{className:"mt-4 flex items-center justify-end gap-2",children:s})]})})}function im({content:e,children:t,delayMs:n=250,className:r=""}){const o=x.useId(),s=x.useRef(null),i=x.useRef(null),a=x.useRef(null),[u,c]=x.useState(null),d=()=>{a.current&&clearTimeout(a.current),a.current=null},f=x.useCallback(()=>{d(),c(null)},[]),p=x.useCallback(()=>{var m;const g=(m=s.current)==null?void 0:m.getBoundingClientRect();if(!g)return;const C=g.top<56;c({x:g.left+g.width/2,y:C?g.bottom+6:g.top-6,below:C})},[]);x.useEffect(()=>d,[]),x.useEffect(()=>{if(!u)return;const g=C=>{C.key==="Escape"&&f()};return window.addEventListener("keydown",g),window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("keydown",g),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[u,f]),x.useLayoutEffect(()=>{if(!u||!i.current)return;const g=i.current.offsetWidth;if(!g)return;const C=8+g/2,m=window.innerWidth-8-g/2,h=Math.min(Math.max(u.x,C),Math.max(C,m));h!==u.x&&c({...u,x:h})},[u]);const S=x.Children.only(t),k=x.isValidElement(S)?x.cloneElement(S,{"aria-describedby":u?o:void 0}):S;return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:s,className:`inline-flex ${r}`,onPointerEnter:g=>{g.pointerType!=="touch"&&(d(),a.current=setTimeout(p,n))},onPointerLeave:f,onPointerDown:f,onFocusCapture:p,onBlurCapture:f,children:k}),u&&Oi.createPortal(l.jsx("div",{ref:i,id:o,role:"tooltip",style:{position:"fixed",left:u.x,top:u.y,transform:`translate(-50%, ${u.below?"0":"-100%"})`},className:"pointer-events-none z-[70] max-w-[15rem] animate-fade-in rounded-lg bg-fg px-2 py-1 text-2xs leading-snug text-surface shadow-lg",children:e}),document.body)]})}function am({open:e,onClose:t,onCompleted:n}){const[r,o]=x.useState(null),[s,i]=x.useState(new Set),[a,u]=x.useState({kind:"loading"}),[c,d]=x.useState("all"),f=x.useRef(!1),p=x.useCallback(async()=>{u({kind:"loading"});try{const v=await ar.transcriptsMigrationChats();o(v),i(r1(v)),u({kind:"plan"})}catch(v){u({kind:"load-failed",message:dm(v)})}},[]);x.useEffect(()=>{e&&(d("all"),p())},[e,p]);const S=x.useMemo(()=>Bi(r),[r]),k=x.useMemo(()=>u1(r),[r]),g=x.useMemo(()=>S.reduce((v,E)=>v+(s.has(E.sessionId)?1:0),0),[S,s]),C=x.useMemo(()=>S.filter(O1).length,[S]),m=x.useCallback(async()=>{if(!(!r||f.current)){f.current=!0,u({kind:"running"});try{const v=await ar.runTranscriptsMigration(l1(r,s));n1(),u({kind:"result",result:v}),v.ok&&(n==null||n())}catch(v){u({kind:"refused",error:v})}finally{f.current=!1}}},[r,s,n]),h=a.kind==="running";return l.jsxs(B1,{open:e,onClose:h?()=>{}:t,dismissOnBackdrop:!h,title:A1(a),footer:l.jsx(_1,{phase:a,plan:r,rows:S,selectedCount:g,alsoMoving:k.total,onClose:t,onRetry:m,onReload:p,onSubmit:m}),children:[a.kind==="loading"&&l.jsxs("p",{className:"py-8 text-center text-sm text-fg-muted",children:["Comparing this instance's chats with your ",l.jsx(Ce,{children:"~/.claude"}),"…"]}),a.kind==="load-failed"&&l.jsxs(Xt,{tone:"danger",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"Could not read the migration plan."}),l.jsx("p",{className:"mt-1",children:a.message}),l.jsx("p",{className:"mt-1 text-xs",children:"Nothing has been moved."})]}),a.kind==="running"&&l.jsx(P1,{plan:r,count:g}),a.kind==="refused"&&l.jsx(T1,{error:a.error,plan:r,rows:S,selected:s}),a.kind==="result"&&l.jsx(R1,{result:a.result}),a.kind==="plan"&&r&&l.jsx(x1,{plan:r,rows:S,selected:s,setSelected:i,filter:c,setFilter:d,decisionCount:C,alsoMoving:k})]})}function x1({plan:e,rows:t,selected:n,setSelected:r,filter:o,setFilter:s,decisionCount:i,alsoMoving:a}){if(tm(e))return l.jsxs("div",{className:"py-6 text-sm text-fg-muted",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Nothing to move."}),l.jsxs("p",{className:"mt-1",children:["Every project's ",l.jsx(Ce,{children:".chats/"})," is already empty, so there is nothing to merge into your ",l.jsx(Ce,{children:"~/.claude"}),"."]})]});const u=t.length>0&&t.every(d=>n.has(d.sessionId)),c=t.reduce((d,f)=>d+(n.has(f.sessionId)?1:0),0);return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("p",{className:"text-base text-fg",children:[l.jsxs("strong",{className:"font-semibold",children:[c.toLocaleString()," of ",t.length.toLocaleString()," ",t.length===1?"chat":"chats"]})," ","will move into ",l.jsx(Ce,{children:"~/.claude"}),"."," ",l.jsxs("span",{className:"text-fg-muted",children:["The rest are set aside in ",l.jsx(Ce,{children:".chats-pre-migration/"}),", not deleted."]})]}),l.jsx(w1,{plan:e}),l.jsx(S1,{plan:e,filter:o,setFilter:s,decisionCount:i}),l.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-edge pb-2",children:l.jsx(rm,{checked:u,indeterminate:!u&&n.size>0,onChange:()=>r(i1(e,!u)),label:l.jsx("span",{className:"text-xs",children:"Select all"})})}),l.jsx("ul",{className:"space-y-4",children:e.projects.map(d=>l.jsx(E1,{project:d,selected:n,setSelected:r,filter:o},d.slug))}),a.total>0&&l.jsx(k1,{alsoMoving:a})]})}function w1({plan:e}){const[t,n]=x.useState(!1),r=e.warnings.length+(e.scanBudgetExhausted?1:0);return r===0?null:l.jsxs("div",{className:"rounded-lg border border-warn-edge bg-warn-soft/30",children:[l.jsxs("button",{type:"button",onClick:()=>n(!t),"aria-expanded":t,className:"focus-visible:focus-ring flex w-full items-center gap-1.5 rounded-lg px-3 py-2 text-left text-xs font-semibold text-warn-fg",children:[l.jsx(lm,{open:t}),r.toLocaleString()," ",r===1?"warning":"warnings",l.jsx("span",{className:"ml-auto font-normal text-fg-muted",children:t?"Hide":"Show"})]}),t&&l.jsxs("div",{className:"space-y-2 px-3 pb-3 pl-8 text-xs text-warn-fg",children:[e.scanBudgetExhausted&&l.jsxs("p",{children:[l.jsxs("strong",{className:"font-semibold",children:[e.totals.unknown.toLocaleString()," ",e.totals.unknown===1?"chat":"chats"," could not be compared."]})," ","Comparing two copies means reading both in full, and this instance has more of them than one pass is allowed to read. Those rows start unticked — Paddock will not assume a chat is safe to merge when it has not looked. Nothing is lost either way."]}),e.warnings.length>0&&l.jsx(um,{warnings:e.warnings})]})]})}function S1({plan:e,filter:t,setFilter:n,decisionCount:r}){const o=[{state:"new",n:e.totals.new},{state:"fast-forward",n:e.totals.fastForward},{state:"diverged",n:e.totals.diverged},{state:"unknown",n:e.totals.unknown}];return l.jsxs("div",{role:"tablist","aria-label":"Filter chats",className:"flex flex-wrap items-center gap-1",children:[l.jsx(Na,{active:t==="all",onClick:()=>n("all"),label:`All ${e.totals.chats.toLocaleString()}`}),r>0&&l.jsx(Na,{active:t==="needs-decision",onClick:()=>n("needs-decision"),label:`${r.toLocaleString()} need a decision`}),l.jsx("span",{className:"mx-1 h-4 w-px bg-edge","aria-hidden":"true"}),o.map(({state:s,n:i})=>i===0?null:l.jsx(im,{content:xi(s).hint,children:l.jsx(Na,{active:t===s,onClick:()=>n(s),label:`${i.toLocaleString()} ${xi(s).label.toLowerCase()}`,tone:cm[s]})},s))]})}function Na({active:e,onClick:t,label:n,tone:r}){return l.jsx("button",{type:"button",role:"tab","aria-selected":e,onClick:t,className:Wi("focus-visible:focus-ring rounded-full border px-2.5 py-1 text-xs transition",e?"border-accent-edge bg-accent-soft font-semibold text-fg":"border-edge text-fg-muted can-hover:hover:border-edge-strong can-hover:hover:text-fg",!e&&r==="info"&&"text-info-fg",!e&&r==="success"&&"text-success-fg",!e&&r==="warn"&&"text-warn-fg"),children:n})}function k1({alsoMoving:e}){const[t,n]=x.useState(!1),r=[];return e.identical>0&&r.push(`${e.identical.toLocaleString()} ${e.identical===1?"chat that is":"chats that are"} already identical in both places`),e.projectExtras>0&&r.push(`${e.projectExtras.toLocaleString()} project ${e.projectExtras===1?"file":"files"} such as agent memory`),e.sweeperChats>0&&r.push(`${e.sweeperChats.toLocaleString()} internal sweeper transcripts`),l.jsxs("div",{className:"border-t border-edge pt-3",children:[l.jsxs("button",{type:"button",onClick:()=>n(!t),"aria-expanded":t,className:"focus-visible:focus-ring flex w-full items-center gap-1.5 rounded text-left text-xs text-fg-muted can-hover:hover:text-fg",children:[l.jsx(lm,{open:t}),l.jsxs("span",{children:["Also moving: ",l.jsx("span",{className:"text-fg",children:j1(e)})]})]}),t&&l.jsxs("p",{className:"mt-1.5 pl-5 text-xs text-fg-muted",children:[U1(r),". These have no decision attached — Paddock's copy of an identical chat is set aside rather than deleted, and the rest have no counterpart to conflict with."," ",l.jsx(Ce,{children:".chats/"})," has to end up completely empty for the switch to take effect."]})]})}function j1(e){const t=[],n=e.identical+e.projectExtras;return n>0&&t.push(`+${n.toLocaleString()} ${n===1?"chat":"chats"}`),e.sweeperChats>0&&t.push(`+${e.sweeperChats.toLocaleString()} sweeper`),t.join(", ")}function lm({open:e}){return l.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":"true",className:Wi("h-3 w-3 shrink-0 transition-transform duration-fast",e&&"rotate-90"),children:l.jsx("path",{d:"M4 2.5 8 6l-4 3.5z",fill:"currentColor"})})}function E1({project:e,selected:t,setSelected:n,filter:r}){const o=e.chats.filter(a=>f1(a,r)),s=x.useMemo(()=>({...e,chats:o}),[e,o]),i=o1(s,t);return o.length===0&&e.projectExtras.length===0?null:l.jsxs("li",{children:[l.jsxs("div",{className:"mb-1.5 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 border-t border-edge pt-3",children:[l.jsx(im,{content:l.jsxs("span",{className:"block max-w-xs break-all font-mono text-2xs",children:["→ ",Qd(e.hostStore),o.some($1)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),"kept, not deleted → ",Qd(e.preserveDir)]})]}),className:"min-w-0",children:l.jsx("h3",{className:"min-w-0 truncate text-base font-semibold text-fg",children:e.name||"Root workspace"})}),o.length>0&&l.jsx(rm,{checked:i.all,indeterminate:i.some,onChange:()=>n(s1(t,s,!i.all)),label:l.jsxs("span",{className:"whitespace-nowrap text-2xs text-fg-muted",children:[i.selected," of ",i.total]})})]}),o.length===0?l.jsxs("p",{className:"rounded-lg border border-dashed border-edge px-3 py-2 text-xs text-fg-muted",children:["No chats here need a decision — ",e.projectExtras.length.toLocaleString()," project"," ",e.projectExtras.length===1?"file moves":"files move"," with it anyway."]}):l.jsx("ul",{className:"space-y-1",children:o.map(a=>l.jsx(N1,{chat:a,checked:t.has(a.sessionId),onToggle:()=>n(a1(t,a.sessionId))},a.sessionId))})]})}function N1({chat:e,checked:t,onToggle:n}){const r=e.state==="diverged"||e.state==="unknown";return l.jsx("li",{children:l.jsxs("label",{title:D1(e),className:Wi("flex cursor-pointer items-start gap-2.5 rounded-lg border px-3 py-2 transition","can-hover:hover:bg-surface-hover",r?"border-warn-edge bg-warn-soft/30":"border-edge"),children:[l.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:t,onChange:n,"aria-label":`Merge ${e.name??e.sessionId} into ~/.claude`}),l.jsxs("span",{className:"min-w-0 flex-1",children:[l.jsxs("span",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[l.jsx("span",{className:"min-w-0 truncate text-sm text-fg",children:e.name??l.jsx("span",{className:"font-mono text-xs",children:e.sessionId})}),l.jsx(I1,{state:e.state})]}),e.preview&&e.preview!==e.name&&l.jsx("span",{className:"mt-0.5 block truncate text-xs text-fg-muted",children:e.preview}),r&&e.host&&l.jsx(C1,{chat:e,checked:t})]})]})})}function C1({chat:e,checked:t}){return e.host?l.jsxs("span",{className:"mt-1.5 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[l.jsx(Gd,{title:"Paddock's copy",side:e.own,wins:t,note:t?"moves into ~/.claude":"kept in the preserve folder"}),l.jsx(Gd,{title:"Your ~/.claude copy",side:e.host,wins:!t,note:t?"moved aside, kept":"stays where it is"})]}):null}function Gd({title:e,side:t,wins:n,note:r}){return l.jsxs("span",{className:Wi("block rounded-md border px-2 py-1.5 text-2xs",n?"border-accent-edge bg-accent-soft":"border-edge bg-surface"),children:[l.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("span",{className:"font-semibold text-fg",children:e}),l.jsx("span",{className:n?"text-accent":"text-fg-muted",children:r})]}),l.jsxs("span",{className:"mt-0.5 block text-fg-muted tabular",children:[t.messageCount!==void 0?`${t.messageCount.toLocaleString()} ${t.messageCount===1?"message":"messages"}`:F1(t.sizeBytes)," · ",t.lastMessageAt?l.jsxs(l.Fragment,{children:["last message ",yi(t.lastMessageAt)]}):l.jsxs(l.Fragment,{children:["file touched ",yi(t.mtime)]})]})]})}function P1({plan:e,count:t}){var n;return l.jsxs("div",{className:"space-y-3 py-6",children:[l.jsxs("p",{className:"text-sm font-semibold text-fg",children:[l.jsx("span",{className:"mr-2 inline-block h-2 w-2 animate-pulse rounded-full bg-accent-solid"}),"Merging ",t.toLocaleString()," ",t===1?"chat":"chats","…"]}),l.jsxs("ol",{className:"ml-4 list-decimal space-y-1 text-xs text-fg-muted",children:[l.jsx("li",{children:"Stopping any turns that are still running."}),l.jsxs("li",{children:["Moving transcripts into"," ",l.jsx(Ce,{children:((n=e==null?void 0:e.projects[0])==null?void 0:n.hostStore.replace(/\/[^/]*$/,"/…"))??"~/.claude"}),"."]}),l.jsxs("li",{children:["Setting ",l.jsx(Ce,{children:"claude.transcripts: host"}),"."]})]}),l.jsx("p",{className:"text-xs text-fg-subtle",children:"Please leave this open. Nothing is deleted at any point, and if this is interrupted the migration can simply be run again."})]})}function T1({error:e,plan:t,rows:n,selected:r}){const o=e instanceof $n?e.code:void 0,s=z1(e),i=a=>{var u;return((u=n.find(c=>c.sessionId===a))==null?void 0:u.name)??a};return l.jsxs("div",{className:"space-y-3",children:[l.jsxs(Xt,{tone:o==="env_shadowed"?"danger":"warn",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:b1[o??""]??"The migration did not run."}),l.jsxs("p",{className:"mt-1 text-fg",children:[l.jsx("strong",{className:"font-semibold",children:"Nothing was moved."})," Every one of these checks runs before the first file is touched, so your chats are exactly where they were."]}),l.jsx("p",{className:"mt-1.5 text-xs",children:dm(e)})]}),o==="turn_running"&&s.length>0&&l.jsxs("div",{className:"text-xs text-fg-muted",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Still running:"}),l.jsx("ul",{className:"mt-1 space-y-0.5",children:s.map(a=>l.jsxs("li",{className:"break-all",children:[l.jsx("span",{className:"text-fg",children:i(a)})," ",l.jsx("span",{className:"font-mono text-2xs text-fg-subtle",children:a})]},a))}),l.jsxs("p",{className:"mt-1.5",children:["A chat mid-turn is still writing to its transcript, so moving it would race the write. Wait for it to finish — or stop it from its own chat screen — then try again. One chat left behind would leave that project's ",l.jsx(Ce,{children:".chats/"})," non-empty, which is why the whole migration refuses rather than skipping it."]})]}),o==="config_conflict"&&l.jsxs("p",{className:"text-xs text-fg-muted",children:["Something else edited ",l.jsx(Ce,{children:(t==null?void 0:t.configPath)??"paddock.config.yaml"})," after this plan was built — another tab, or an editor. Reload the plan so your choices are made against the current file, then submit again."]}),o==="migration_in_progress"&&l.jsx("p",{className:"text-xs text-fg-muted",children:"Another tab or window is running this migration right now. Let it finish — when it does, reload this plan and it will report that there is nothing left to move."}),o==="env_shadowed"&&l.jsxs("p",{className:"text-xs text-fg-muted",children:[l.jsx(Ce,{children:"PADDOCK_CLAUDE_TRANSCRIPTS"})," is set in this server's environment, and an environment variable beats the config file. Writing"," ",l.jsx(Ce,{children:"claude.transcripts: host"})," would have no effect, so the chats would have been moved for nothing. Unset it, restart Paddock, and the offer will come back."]}),l.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Your selection is still here: ",r.size.toLocaleString()," of"," ",n.length.toLocaleString()," ticked."]})]})}const b1={turn_running:"A chat is still mid-turn.",config_conflict:"The config file changed underneath this plan.",migration_in_progress:"A migration is already running.",env_shadowed:"An environment variable is overriding the config file.",invalid:"That request was not valid."};function R1({result:e}){const t=nm(e),n=c1(e.preserved),r=e.projects.filter(o=>o.outcome==="skipped-busy");return l.jsxs("div",{className:"space-y-3",children:[t==="partial"?l.jsxs(Xt,{tone:"warn",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"The migration did not finish."}),l.jsxs("p",{className:"mt-1",children:[l.jsx(Ce,{children:"claude.transcripts"})," was ",l.jsx("strong",{className:"font-semibold",children:"not"})," ","changed, so this instance is still using its own store and nothing about how Paddock behaves has changed yet. Files that did move are already in place and will not move twice — ",l.jsx("strong",{className:"font-semibold",children:"running this again is safe"})," and picks up where it stopped."]})]}):t==="already"?l.jsxs(Xt,{tone:"info",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"Already merged."}),l.jsxs("p",{className:"mt-1",children:["Everything was already in your ",l.jsx(Ce,{children:"~/.claude"})," and"," ",l.jsx(Ce,{children:"claude.transcripts"})," was already ",l.jsx(Ce,{children:"host"}),". Nothing needed doing."]})]}):l.jsxs(Xt,{tone:"success",className:"text-sm",children:[l.jsxs("p",{className:"font-semibold",children:["Merged ",e.migrated.length.toLocaleString()," ",e.migrated.length===1?"chat":"chats"," into your ",l.jsx(Ce,{children:"~/.claude"}),"."]}),e.preserved.length>0&&l.jsxs("p",{className:"mt-1",children:[e.preserved.length.toLocaleString()," ",e.preserved.length===1?"copy was":"copies were"," set aside rather than overwritten. Every one is listed below."]})]}),e.restartRequired&&l.jsx(L1,{ok:t!=="partial",configWritten:e.configWritten}),e.failed.length>0&&l.jsxs("section",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:[e.failed.length.toLocaleString()," could not be moved"]}),l.jsx("ul",{className:"mt-1 space-y-1",children:e.failed.map((o,s)=>l.jsxs("li",{className:"rounded-md border border-warn-edge bg-warn-soft/40 px-2 py-1.5 text-2xs",children:[l.jsx("span",{className:"block break-all font-mono text-fg",children:Yd(o)}),l.jsxs("span",{className:"block text-fg-muted",children:[o.reason,o.message?` — ${o.message}`:""]}),o.path&&Yd(o)!==o.path&&l.jsx("span",{className:"block break-all font-mono text-fg-subtle",children:o.path})]},`${o.slug}:${o.sessionId}:${s}`))})]}),r.length>0&&l.jsxs(Xt,{tone:"warn",className:"text-xs",children:[l.jsxs("p",{className:"font-semibold",children:[r.length," ",r.length===1?"project was":"projects were"," left untouched."]}),l.jsxs("p",{className:"mt-1",children:["A turn started again between the stop and the move, so"," ",r.map(o=>o.slug||"the root workspace").join(", ")," was skipped entirely rather than half-moved. Run the migration again once it is idle."]})]}),e.preserved.length>0&&l.jsxs("section",{"data-testid":"migration-preserved",children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:["Kept, not deleted — ",e.preserved.length.toLocaleString()," ",e.preserved.length===1?"item":"items"]}),l.jsxs("p",{className:"mt-0.5 text-2xs text-fg-muted",children:["Every copy that did not end up in ",l.jsx(Ce,{children:"~/.claude"}),", and exactly where it is now. Nothing here was removed; you can open any of these paths. A chat's sub-agent transcripts, tool results and revert history move with it."]}),n.map(o=>l.jsxs("div",{className:"mt-2",children:[l.jsx("p",{className:"text-2xs font-semibold text-fg-muted",children:o.slug||"root workspace"}),l.jsx("ul",{className:"mt-0.5 space-y-0.5",children:o.items.map((s,i)=>l.jsxs("li",{className:"text-2xs",children:[l.jsx("span",{className:"block break-all font-mono text-fg",children:s.path}),l.jsx("span",{className:"text-fg-subtle",children:M1(s.reason,s.side)})]},`${s.path}:${i}`))})]},o.slug))]}),e.unplanned.length>0&&l.jsxs("section",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:[e.unplanned.length.toLocaleString()," appeared after you opened this"]}),l.jsx("p",{className:"mt-0.5 text-2xs text-fg-muted",children:"These chats were created between the table being built and Submit, so you were never shown them. Each was handled by the same default its classification would have had."}),l.jsx("ul",{className:"mt-1 space-y-0.5",children:e.unplanned.map((o,s)=>l.jsxs("li",{className:"break-all text-2xs",children:[l.jsx("span",{className:"font-mono text-fg",children:o.sessionId})," ",l.jsxs("span",{className:"text-fg-muted",children:["— ",xi(o.state).label.toLowerCase(),", so it was"," ",o.action==="migrated"?"merged":"kept in the preserve folder"]})]},`${o.sessionId}:${s}`))})]}),e.ignoredSessionIds.length>0&&l.jsxs("p",{className:"text-2xs text-fg-muted",children:[e.ignoredSessionIds.length.toLocaleString()," ticked"," ",e.ignoredSessionIds.length===1?"chat was":"chats were"," no longer on disk and were skipped."]}),e.warnings.length>0&&l.jsx(um,{warnings:e.warnings}),e.sweepers.chats>0&&l.jsxs("p",{className:"text-2xs text-fg-subtle",children:[e.sweepers.chats.toLocaleString()," internal sweeper transcripts across"," ",e.sweepers.stores.toLocaleString()," ",e.sweepers.stores===1?"store":"stores"," moved with their projects."]})]})}function L1({ok:e,configWritten:t}){return e?t?l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Restart the Paddock server now."}),l.jsxs("p",{className:"mt-1",children:["The setting is written, but Paddock reads it once when it starts — so this running server has not picked it up yet."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Until you restart, your chat list will look empty."})," ","That is expected and nothing is wrong: the running process is still looking in the old location, which the migration just emptied. Everything is on disk — the merged chats are in your ",l.jsx(Ce,{children:"~/.claude"})," and the set-aside copies are in the folders listed here. They all come back the moment Paddock restarts."]})]}):l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Restart the Paddock server now."}),l.jsxs("p",{className:"mt-1",children:["Your configuration already asked for ",l.jsx(Ce,{children:"~/.claude"}),", so"," ",l.jsx("strong",{className:"font-semibold text-fg",children:"nothing about it was changed"})," — the chats were simply stranded where Paddock could not reach them, and they are now back in the store it reads. Paddock only wires that up at startup, so this running server has not caught up yet."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Restart and the chats that were missing will reappear."})," ","The copies set aside along the way are in the folders listed here."]})]}):l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Run the migration again, then restart."}),l.jsxs("p",{className:"mt-1",children:["Some chats have already moved out of Paddock's own store, and because the setting was not written this server still looks for them there."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Until the migration finishes, your chat list will look incomplete."})," ","Nothing is lost — every file is either in your ",l.jsx(Ce,{children:"~/.claude"})," or in the folders listed below. Fix what is reported above, run this again, and restart when it completes."]})]})}function M1(e,t){switch(e){case"unchecked":return"you left this one unticked, so Paddock's copy was set aside and your ~/.claude copy is untouched";case"unplanned-diverged":return"created after the table was built and had conflicting edits, so it was set aside rather than merged without asking";case"identical":return"already identical in both places, so Paddock's duplicate was set aside";case"already-ahead":return"your ~/.claude copy was the longer one and was kept, so Paddock's shorter copy was set aside";case"superseded":return"your ~/.claude copy was moved here first, then Paddock's copy took its place — this is the original";default:return`set aside from the ${t==="host"?"~/.claude":"Paddock"} side (${e})`}}function _1({phase:e,plan:t,rows:n,selectedCount:r,alsoMoving:o,onClose:s,onRetry:i,onReload:a,onSubmit:u}){if(e.kind==="running")return l.jsx("span",{className:"text-xs text-fg-muted",children:"Working — this usually takes under a second."});if(e.kind==="result")return l.jsx(jt,{variant:"primary",size:"sm",onClick:s,children:"Close"});if(e.kind==="load-failed")return l.jsxs(l.Fragment,{children:[l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Close"}),l.jsx(jt,{variant:"primary",size:"sm",onClick:a,children:"Try again"})]});if(e.kind==="refused"){const c=e.error instanceof $n?e.error.code:void 0,d=c!=="env_shadowed"&&c!=="invalid";return l.jsxs(l.Fragment,{children:[l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Close"}),c==="config_conflict"?l.jsx(jt,{variant:"primary",size:"sm",onClick:a,children:"Reload the plan"}):d&&l.jsx(jt,{variant:"primary",size:"sm",onClick:i,children:"Try again"})]})}return e.kind==="loading"||!t?l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}):tm(t)?l.jsx(jt,{variant:"primary",size:"sm",onClick:s,children:"Close"}):l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"mr-auto text-xs text-fg-muted",children:[r.toLocaleString()," of ",n.length.toLocaleString()," ticked",o>0&&l.jsxs("span",{className:"text-fg-subtle",children:[" · ",o.toLocaleString()," more move anyway"]})]}),l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}),l.jsx(jt,{variant:"primary",size:"sm",onClick:u,children:r===0?"Merge nothing, keep everything":`Merge ${r.toLocaleString()} ${r===1?"chat":"chats"}`})]})}function um({warnings:e}){return l.jsx("ul",{className:"space-y-1",children:e.map((t,n)=>l.jsxs("li",{children:[l.jsx("span",{children:t.message}),t.paths&&t.paths.length>0&&l.jsxs("details",{className:"mt-0.5",children:[l.jsx("summary",{className:"focus-visible:focus-ring cursor-pointer text-2xs underline underline-offset-2",children:t.paths.length===1?"Show the path":`Show ${t.paths.length} paths`}),l.jsx("ul",{className:"mt-0.5",children:t.paths.map(r=>l.jsx("li",{className:"break-all font-mono text-2xs text-fg-subtle",children:r},r))})]})]},`${t.code}:${n}`))})}const cm={new:"success","fast-forward":"info",diverged:"warn",unknown:"neutral"};function I1({state:e,n:t}){if(t===0)return null;const n=xi(e);return l.jsx(m1,{tone:cm[e]??"neutral",title:n.hint,children:t===void 0?n.label:`${t.toLocaleString()} ${n.label.toLowerCase()}`})}function D1(e){const t=[];return e.name!==void 0&&t.push(e.sessionId),e.extras.length>0&&t.push(`+${e.extras.length} sidecar ${e.extras.length===1?"file":"files"}`),t.length>0?t.join(" · "):void 0}function O1(e){return!e.defaultSelected}function $1(e){return e.state==="diverged"||e.state==="unknown"}function Ce({children:e}){return l.jsx("span",{className:"break-all font-mono",children:e})}function dm(e){return e instanceof Error?e.message:String(e)}function A1(e){const t="Merge chats into ~/.claude";if(e.kind!=="result")return t;switch(nm(e.result)){case"partial":return`${t} — unfinished`;case"already":return`${t} — nothing to do`;default:return`${t} — done`}}function Yd(e){return e.sessionId&&e.sessionId!=="-"?e.sessionId:e.path??"Project files"}function z1(e){if(!(e instanceof $n))return[];const t=e.body;if(typeof t!="object"||t===null)return[];const n=t.sessionIds;return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}function F1(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function U1(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Wi(...e){return e.filter(Boolean).join(" ")}function B1(e){return l.jsx(y1,{...e,size:"lg",className:"sm:max-w-4xl"})}function J(e){return{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",...e}}const W1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 5v14M5 12h14"})}),US=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),H1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M3 10.5 12 3l9 7.5"}),l.jsx("path",{d:"M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5"})]}),BS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),Jd=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"11",cy:"11",r:"7"}),l.jsx("path",{d:"m21 21-4.3-4.3"})]}),WS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M4 5h16"}),l.jsx("path",{d:"M8 5v6h12"}),l.jsx("path",{d:"M8 11v6h12"})]}),HS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),VS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})}),KS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"m22 2-7 20-4-9-9-4Z"}),l.jsx("path",{d:"M22 2 11 13"})]}),QS=e=>l.jsx("svg",{...J(e),children:l.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),GS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),l.jsx("path",{d:"M5 10a7 7 0 0 0 14 0"}),l.jsx("path",{d:"M12 17v4M8 21h8"})]}),YS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m9 18 6-6-6-6"})}),JS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M14.7 6.3a4 4 0 0 0-5.4 5.4L3 18l3 3 6.3-6.3a4 4 0 0 0 5.4-5.4l-2.6 2.6-2-2 2.6-2.6Z"})}),V1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"3"}),l.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z"})]}),K1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"}),l.jsx("path",{d:"M12 9v4M12 17h.01"})]}),XS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8"})}),Hi=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M18 6 6 18M6 6l12 12"})}),ZS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12z"})}),qS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M6 4.5v15l13-7.5z"})}),Q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})}),ek=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"9"}),l.jsx("path",{d:"M12 7v5l3 2"})]}),tk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"5",r:"1"}),l.jsx("circle",{cx:"12",cy:"12",r:"1"}),l.jsx("circle",{cx:"12",cy:"19",r:"1"})]}),nk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M10 11v6M14 11v6"})}),rk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 20h9"}),l.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),ok=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),l.jsx("path",{d:"M14 2v6h6"})]}),sk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 17v5"}),l.jsx("path",{d:"M9 10.76V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v6.76a2 2 0 0 0 .59 1.42l1.12 1.12A1 1 0 0 1 17 15H7a1 1 0 0 1-.71-1.7l1.12-1.12A2 2 0 0 0 9 10.76Z"})]}),G1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M20 6 9 17l-5-5"})}),ik=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),l.jsx("path",{d:"M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1"})]}),ak=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),l.jsx("path",{d:"M5 21h14"})]}),lk=({open:e,...t})=>e?l.jsxs("svg",{...J(t),children:[l.jsx("path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z"}),l.jsx("path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10"})]}):l.jsxs("svg",{...J(t),children:[l.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),l.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),uk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"6",cy:"6",r:"3"}),l.jsx("circle",{cx:"6",cy:"18",r:"3"}),l.jsx("circle",{cx:"18",cy:"6",r:"3"}),l.jsx("path",{d:"M6 9v6M18 9a9 9 0 0 1-9 9"})]}),ck=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M9.5 14.5l-1.7 1.7a4 4 0 0 1-5.66-5.66l1.7-1.7"}),l.jsx("path",{d:"M14.5 9.5l1.7-1.7a4 4 0 0 1 5.66 5.66l-1.7 1.7"}),l.jsx("path",{d:"M8 3.5v2M3.5 8h2M16 20.5v-2M20.5 16h-2"})]}),dk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),l.jsx("path",{d:"M17 8l-5-5-5 5M12 3v12"})]}),fk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 17l6-5-6-5M12 19h8"})}),hk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.9a3.4 3.4 0 0 0-1-2.6c3-.3 6.2-1.5 6.2-6.6a5.2 5.2 0 0 0-1.4-3.6 4.8 4.8 0 0 0-.1-3.6s-1.1-.3-3.7 1.4a12.6 12.6 0 0 0-6.6 0C6.5 1.3 5.4 1.6 5.4 1.6a4.8 4.8 0 0 0-.1 3.6 5.2 5.2 0 0 0-1.4 3.6c0 5.1 3.2 6.3 6.2 6.6a3.4 3.4 0 0 0-1 2.6V22"})}),Y1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"4"}),l.jsx("path",{d:"M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"})]}),J1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})}),X1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.5 1.5"}),l.jsx("path",{d:"M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.5-1.5"})]}),pk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m6 9 6 6 6-6"})}),mk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"4",rx:"1"}),l.jsx("path",{d:"M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8"}),l.jsx("path",{d:"M10 12h4"})]}),gk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 2.5l2.9 5.88 6.49.94-4.7 4.58 1.11 6.46L12 17.8l-5.8 3.05 1.11-6.46-4.7-4.58 6.49-.94z"})});function Z1({message:e,tone:t="success",onDismiss:n,durationMs:r=6e3,action:o}){if(x.useEffect(()=>{if(e===null||r<=0)return;const i=setTimeout(n,r);return()=>clearTimeout(i)},[e,r,n]),e===null)return null;const s=t==="error";return l.jsx("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 bottom-4 z-50 flex justify-center px-4",children:l.jsxs("div",{className:`pointer-events-auto flex max-w-md items-start gap-2 rounded-lg border px-3 py-2 text-sm shadow-lg ${s?"border-danger-edge bg-danger-soft text-danger":"border-edge bg-surface-raised text-fg"}`,children:[s?l.jsx(K1,{width:16,height:16,className:"mt-0.5 shrink-0"}):l.jsx(G1,{width:16,height:16,className:"mt-0.5 shrink-0 text-success-solid"}),l.jsx("span",{className:"break-words",children:e}),o&&l.jsx("button",{type:"button",onClick:o.onAct,className:"ml-1 shrink-0 font-medium underline underline-offset-2 transition hover:opacity-80",children:o.label}),l.jsx("button",{type:"button",onClick:n,"aria-label":"Dismiss notification",className:"-mr-1 ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded transition hover:bg-surface-hover",children:l.jsx(Hi,{width:12,height:12})})]})})}function q1(){const{showBanner:e,dismiss:t}=em(),n=es(),[r,o]=x.useState(!1),[s,i]=x.useState(null),[a,u]=x.useState(!1),c=()=>{t(),i("Hidden on this browser. The migration is still on the Config screen.")};return l.jsxs(l.Fragment,{children:[e&&!a&&l.jsxs("div",{"data-testid":"migration-offer",className:"hidden h-6 shrink-0 items-center rounded-md border border-accent-edge bg-accent-soft pr-0.5 sm:flex",children:[l.jsxs("button",{type:"button",onClick:()=>o(!0),title:"Your chats live in Paddock's own store, not in ~/.claude. Merge them in so the Claude Code CLI sees them too.","aria-label":"Merge this instance's chats into your ~/.claude",className:"focus-visible:focus-ring flex h-6 items-center gap-1.5 rounded-md pl-2 pr-1.5 text-2xs can-hover:hover:underline",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-[1px] bg-accent-solid","aria-hidden":"true"}),l.jsxs("span",{className:"whitespace-nowrap text-fg-muted",children:["Chats are separate from ",l.jsx("span",{className:"font-mono",children:"~/.claude"})]}),l.jsx("span",{className:"whitespace-nowrap font-semibold text-accent",children:"Merge"})]}),l.jsx("button",{type:"button","data-testid":"migration-offer-dismiss",onClick:c,"aria-label":"Hide the transcript migration offer",title:"Hide this. You can still start the migration from the Config screen.",className:"focus-visible:focus-ring flex h-5 w-5 shrink-0 items-center justify-center rounded text-accent can-hover:hover:bg-accent-solid/15",children:l.jsx(Hi,{width:11,height:11})})]}),l.jsx(am,{open:r,onClose:()=>o(!1),onCompleted:()=>u(!0)}),l.jsx(Z1,{message:s,onDismiss:()=>i(null),durationMs:12e3,action:{label:"Open Config",onAct:()=>{i(null),n("/config")}}})]})}function vk(){const{showInConfig:e}=em(),[t,n]=x.useState(!1),[r,o]=x.useState(!1);return e?l.jsxs("div",{className:"px-3 pt-3 sm:px-6","data-testid":"migration-offer-card",children:[!r&&l.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 rounded-xl border border-accent-edge bg-accent-soft px-3 py-2.5",children:[l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsxs("p",{className:"text-sm font-semibold text-fg",children:["Chats are separate from ",l.jsx("span",{className:"font-mono",children:"~/.claude"})]}),l.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:["This instance keeps its transcripts in each project's own store, so the Claude Code CLI does not see them. Merging moves them into your Claude home and switches"," ",l.jsx("span",{className:"font-mono",children:"claude.transcripts"})," to"," ",l.jsx("span",{className:"font-mono",children:"host"}),"."]})]}),l.jsx(jt,{variant:"primary",size:"sm",onClick:()=>n(!0),children:"Merge chats…"})]}),l.jsx(am,{open:t,onClose:()=>n(!1),onCompleted:()=>o(!0)})]}):null}const Ca=6,ew=.75,tw=.9,nw=250,rw=3e4;function ow(e){const[,t]=x.useState(0);x.useEffect(()=>{if(e==null)return;const n=setInterval(()=>t(r=>r+1),e);return()=>clearInterval(n)},[e])}function sw(){const[e,t]=x.useState(new Map);return x.useEffect(()=>Wu.onActiveInfos(n=>t(new Map(n))),[]),e}function iw(e,t){const[n,r]=x.useState(new Map),o=x.useRef(0);return x.useEffect(()=>{const s=new Set([...e.split(","),...t.split(",")].filter(Boolean));if(s.size===0){o.current++,r(new Map);return}r(d=>{const f=new Map([...d].filter(([p])=>s.has(p)));return f.size===d.size?d:f});let i=!1;const a=async()=>{const d=++o.current;try{const f=await ar.attentionChats(_u);if(i||d!==o.current)return;r(p=>{const S=new Map([...p].filter(([k])=>s.has(k)));for(const k of[...f.recent??[],...f.unread??[],...f.running??[]]){if(!s.has(k.sessionId))continue;const g=S.get(k.sessionId);S.set(k.sessionId,k.contextTokens==null&&(g==null?void 0:g.contextTokens)!=null?{...k,contextTokens:g.contextTokens,contextLimit:g.contextLimit}:k)}return S})}catch{}},u=setTimeout(()=>void a(),nw),c=e?setInterval(()=>{document.visibilityState==="visible"&&a()},rw):null;return()=>{i=!0,clearTimeout(u),c&&clearInterval(c)}},[e,t]),n}function fm({fill:e}){const t=e<=0?0:Math.max(1,Math.min(Ca,Math.round(e*Ca))),n=e<ew?"bg-accent-solid":e<tw?"bg-warn-solid":"bg-danger-solid";return l.jsx("span",{className:"flex items-center gap-px",title:`Context ${Math.round(e*100)}% full`,"aria-hidden":"true",children:Array.from({length:Ca},(r,o)=>l.jsx("span",{className:Ye("h-2.5 w-[3px] rounded-[1px]",o<t?n:"bg-edge")},o))})}function aw({projectSlug:e,projectName:t,chatName:n,sessionId:r,startedAt:o,fill:s}){const i=o==null?"—:—":qx(Date.now()-o),a=n??"Running turn";return l.jsxs(ts,{"data-testid":"fleet-channel",to:`${Up(e)}/chat/${encodeURIComponent(r)}`,title:`${a} — ${t}`,"aria-label":`${a} in ${t}, running${o==null?"":` for ${i}`}`,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-2 rounded-md border border-edge-subtle bg-surface px-2 text-2xs can-hover:hover:border-edge can-hover:hover:bg-surface-hover",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-[1px] bg-accent-solid","aria-hidden":"true"}),l.jsx("span",{className:"max-w-[14ch] truncate font-medium text-fg",children:t}),l.jsx("span",{className:"font-mono tabular text-fg-muted",children:i}),s!=null&&l.jsx(fm,{fill:s})]})}function lw({projectSlug:e,projectName:t,chatName:n,sessionId:r,at:o,fill:s}){const i=yi(new Date(o).toISOString()),a=n??"Finished turn";return l.jsxs(ts,{"data-testid":"fleet-finished",to:`${Up(e)}/chat/${encodeURIComponent(r)}`,title:`${a} — ${t} · finished ${i}, unread`,"aria-label":`${a} in ${t}, finished ${i}, unread`,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-2 rounded-md border border-dashed border-edge px-2 text-2xs can-hover:hover:border-solid can-hover:hover:bg-surface-hover",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-warn-solid","aria-hidden":"true"}),l.jsx("span",{className:"max-w-[14ch] truncate font-medium text-fg-muted",children:t}),l.jsx("span",{className:"text-fg-subtle",children:i}),s!=null&&l.jsx("span",{className:"opacity-50",children:l.jsx(fm,{fill:s})})]})}function uw(){const e=x.useRef(null),[t,n]=x.useState(!1),[r,o]=x.useState(!1);return x.useEffect(()=>{const s=e.current;if(!s)return;const i=()=>{n(s.scrollLeft>1),o(s.scrollLeft+s.clientWidth<s.scrollWidth-1)},a=d=>{s.scrollWidth<=s.clientWidth||Math.abs(d.deltaX)>Math.abs(d.deltaY)||(s.scrollLeft+=d.deltaY,d.preventDefault())};i(),s.addEventListener("scroll",i,{passive:!0}),s.addEventListener("wheel",a,{passive:!1});const u=typeof ResizeObserver>"u"?null:new ResizeObserver(i);u==null||u.observe(s);const c=typeof MutationObserver>"u"?null:new MutationObserver(i);return c==null||c.observe(s,{childList:!0,subtree:!0,characterData:!0}),()=>{s.removeEventListener("scroll",i),s.removeEventListener("wheel",a),u==null||u.disconnect(),c==null||c.disconnect()}},[]),{ref:e,moreLeft:t,moreRight:r}}function Xd({value:e,unit:t,to:n,tone:r,title:o}){return l.jsxs(ts,{"data-testid":`fleet-${t}`,to:n,title:o,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-1.5 rounded-md px-1.5 can-hover:hover:bg-surface-hover",children:[l.jsx("span",{"aria-hidden":"true",className:Ye("h-1.5 w-1.5 shrink-0 rounded-[1px]",r==="live"&&"bg-accent-solid",r==="attention"&&"bg-warn-solid",r==="rest"&&"bg-edge-strong")}),l.jsx("span",{"data-testid":`fleet-${t}-value`,className:"font-mono tabular text-2xs font-semibold text-fg",children:e}),l.jsx("span",{className:"text-3xs font-semibold uppercase tracking-[0.14em] text-fg-subtle",children:t})]})}function cw({unread:e,finished:t=[]}){const{projects:n,rootWorkspace:r}=Wp(),o=sw(),s=x.useMemo(()=>[...o.keys()].sort().join(","),[o]),i=x.useMemo(()=>t.map(g=>g.sessionId).join(","),[t]),a=iw(s,i);ow(o.size>0?1e3:t.length>0?3e4:null);const u=uw(),c=x.useMemo(()=>{const g=new Map;for(const C of n)g.set(C.slug,C.name);return r&&g.set(r.slug,r.name),g},[n,r]),d=x.useMemo(()=>[...o.entries()].map(([g,C])=>{const m=a.get(g);return{sessionId:g,projectSlug:C,projectName:c.get(C)??(m==null?void 0:m.projectName)??C,chatName:(m==null?void 0:m.name)??null,startedAt:Wu.turnStartedAt(g),fill:(m==null?void 0:m.contextTokens)!=null&&m.contextLimit?Math.min(1,m.contextTokens/m.contextLimit):null}}).sort((g,C)=>(g.startedAt??1/0)-(C.startedAt??1/0)),[o,a,c]),f=g=>(g==null?void 0:g.contextTokens)!=null&&g.contextLimit?Math.min(1,g.contextTokens/g.contextLimit):null,p=t.map(g=>{const C=a.get(g.sessionId);return{...g,projectName:c.get(g.projectSlug)??(C==null?void 0:C.projectName)??g.projectSlug,chatName:(C==null?void 0:C.name)??null,fill:f(C)}}),S=x.useMemo(()=>{let g="";for(const C of r?[...n,r]:n)for(const m of C.chatTurns??[])m.lastTurnCompletedAt>g&&(g=m.lastTurnCompletedAt);return g},[n,r]),k=o.size===0?`Fleet idle. ${e} unread.`:`${o.size} running. ${e} unread.`;return l.jsxs("div",{"data-testid":"fleet-readout",className:"flex h-9 shrink-0 items-center gap-2 border-b border-edge-subtle bg-surface-sunken px-2 sm:px-3",children:[l.jsx(Xd,{value:o.size,unit:"running",to:"/",tone:o.size>0?"live":"rest",title:o.size>0?"Turns in flight across every project":"Nothing running"}),l.jsx(Xd,{value:e,unit:"unread",to:"/",tone:e>0?"attention":"rest",title:"Chats holding a reply you have not read"}),l.jsx("span",{className:"h-4 w-px shrink-0 bg-edge-subtle","aria-hidden":"true"}),l.jsxs("div",{ref:u.ref,"data-testid":"fleet-channels",className:Ye("scrollbar-none flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overflow-y-hidden overscroll-x-contain",u.moreLeft&&u.moreRight?"fade-both":u.moreLeft?"fade-start":u.moreRight&&"fade-end"),children:[d.map(g=>l.jsx(aw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,startedAt:g.startedAt,fill:g.fill},g.sessionId)),p.map(g=>l.jsx(lw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,at:g.at,fill:g.fill},g.sessionId)),d.length===0&&p.length===0&&(S?l.jsxs("span",{className:"truncate text-2xs text-fg-subtle",children:["Idle · last turn ",yi(S)]}):l.jsx(ts,{to:"/chat",className:"focus-visible:focus-ring truncate rounded-md px-1 text-2xs text-accent can-hover:hover:underline",children:"No turns yet — start a chat →"}))]}),l.jsx(q1,{}),l.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})}let Pa;function dw(){if(Pa===void 0){const e=Intl.Segmenter;Pa=e?new e(void 0,{granularity:"grapheme"}):null}return Pa}function Zd(e){const t=dw();return t?Array.from(t.segment(e),n=>n.segment):Array.from(e)}const fw=/[^\p{Cf}\p{Cc}\p{M}\p{Z}\p{White_Space}]/u;function hw(e){const t=Zd(e.normalize("NFC")).filter(o=>fw.test(o));if(t.length===0)return"?";const n=t.find(o=>/[\p{L}\p{N}\p{Extended_Pictographic}\p{Regional_Indicator}]/u.test(o))??t[0],r=n.toLocaleUpperCase();return Zd(r).length===1?r:n}function pw({slug:e,name:t,color:n,className:r=""}){const o=n??Au(e);return l.jsx("span",{"aria-hidden":"true","data-testid":"project-chip",className:`flex h-4 w-4 shrink-0 select-none items-center justify-center overflow-hidden rounded-sm text-3xs font-semibold leading-none ${r}`,style:{backgroundColor:o,color:Uu(o)},children:hw(t)})}function qd(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e:"~"}function mw(e,t,n){const r=Math.abs(e-t)%n;return Math.min(r,n-r)}function gw(e,t,n){let r=-1,o=-1/0,s=1/0;for(let i=0;i<n;i++){if(e.has(i))continue;let a=1/0;for(const c of e)a=Math.min(a,gx(i,c));const u=mw(i,t,n);(a>o||a===o&&u<s)&&(r=i,o=a,s=u)}return r}function vw(e){const t=ns.length,n=[...e].sort((s,i)=>{const a=qd(s.started),u=qd(i.started);return a!==u?a<u?-1:1:s.slug<i.slug?-1:s.slug>i.slug?1:0}),r=new Set,o=new Map;for(const{slug:s}of n){if(o.has(s))continue;const i=Kp(s),a=!r.has(i)||r.size>=t?i:gw(r,i,t);r.add(a),o.set(s,a)}return o}function yw(e){const t=new Map;for(const[n,r]of vw(e))t.set(n,ns[r]);return t}const xw=["idea","active","paused","blocked","done"];function ww({open:e,onClose:t,onCreated:n}){const[r,o]=x.useState(""),[s,i]=x.useState(""),[a,u]=x.useState(""),[c,d]=x.useState(""),[f,p]=x.useState("active"),[S,k]=x.useState(""),[g,C]=x.useState(""),[m,h]=x.useState(!1),[v,E]=x.useState(!1),[T,R]=x.useState(null);if(x.useEffect(()=>{e&&(o(""),i(""),u(""),d(""),p("active"),k(""),C(""),h(!1),R(null))},[e]),x.useEffect(()=>{const y=D=>{D.key==="Escape"&&e&&!v&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[e,v,t]),!e)return null;const M=async y=>{if(y.preventDefault(),!!r.trim()){E(!0),R(null);try{const D=await ar.createProject({name:r.trim(),status:f,group:c||void 0,summary:s.trim()||void 0,repo:S.trim()||void 0,path:g.trim()||void 0,managed:g.trim()&&!S.trim()?m:void 0,domain:a.split(",").map(b=>b.trim()).filter(Boolean)});n(D)}catch(D){R(D instanceof $n?D.message:"Failed to create project")}finally{E(!1)}}};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!v&&t(),children:l.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:y=>y.stopPropagation(),onSubmit:M,children:[l.jsxs("div",{className:"mb-5 flex items-center justify-between",children:[l.jsx("h2",{className:"text-lg font-semibold",children:"New project"}),l.jsx("button",{type:"button",onClick:t,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:l.jsx(Hi,{width:18,height:18})})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Name"}),l.jsx("input",{autoFocus:!0,className:"input",value:r,onChange:y=>o(y.target.value),placeholder:"Garage Water Heater Replacement"})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Summary (optional)"}),l.jsx("input",{className:"input",value:s,onChange:y=>i(y.target.value),placeholder:"One line on what this project is about"})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Area"}),l.jsxs("select",{className:"input",value:c,onChange:y=>d(y.target.value),children:[l.jsx("option",{value:"",children:"Unsorted"}),Bu.map(y=>l.jsx("option",{value:y.slug,children:y.label},y.slug))]})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Directory on this machine (optional)"}),l.jsx("input",{className:"input",value:g,onChange:y=>C(y.target.value),placeholder:"/home/ed/Code/foo"}),l.jsx("span",{className:"mt-1 block text-xs text-fg-subtle",children:"Where this project's content lives. An existing checkout is used in place — its real history, branches and remotes — and Paddock writes nothing into it. Absolute path; created for you if it doesn't exist."})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Git repository URL (optional)"}),l.jsx("input",{className:"input",value:S,onChange:y=>k(y.target.value),placeholder:"https://github.com/owner/repo.git"}),l.jsx("span",{className:"mt-1 block text-xs text-fg-subtle",children:g.trim()?"Cloned into the directory above if it doesn't exist yet; otherwise the directory is used as-is and this just records which repo it is.":"Paddock clones this repo into the project and works in the checkout. Leave both blank for a notes project."})]}),g.trim()&&!S.trim()&&l.jsxs("label",{className:"mb-4 flex cursor-pointer items-start gap-2",children:[l.jsx("input",{type:"checkbox",className:"mt-0.5",checked:m,onChange:y=>h(y.target.checked)}),l.jsxs("span",{className:"text-xs text-fg-muted",children:[l.jsx("span",{className:"font-medium",children:"These are notes — let Paddock curate them."})," ","Its OVERVIEW.md, CHANGELOG.md and CLAUDE.md are written into that directory. Leave unticked for a code checkout you version yourself, and Paddock will write nothing into it."]})]}),l.jsxs("div",{className:"mb-5 grid grid-cols-2 gap-3",children:[l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"field-label",children:"Domain tags"}),l.jsx("input",{className:"input",value:a,onChange:y=>u(y.target.value),placeholder:"home, plumbing"})]}),l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"field-label",children:"Status"}),l.jsx("select",{className:"input capitalize",value:f,onChange:y=>p(y.target.value),children:xw.map(y=>l.jsx("option",{value:y,className:"capitalize",children:y},y))})]})]}),T&&l.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:T}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx("button",{type:"button",className:"btn-ghost",onClick:t,disabled:v,children:"Cancel"}),l.jsx("button",{type:"submit",className:"btn-primary",disabled:v||!r.trim(),children:v?"Creating…":"Create project"})]})]})})}function ef(e){if(typeof window>"u"||typeof window.matchMedia!="function")return null;try{return window.matchMedia(e)??null}catch{return null}}function Sw(e){const[t,n]=x.useState(()=>{var r;return((r=ef(e))==null?void 0:r.matches)??!1});return x.useEffect(()=>{var s;const r=ef(e);if(!r)return;const o=()=>n(!!r.matches);return o(),typeof r.addEventListener=="function"?(r.addEventListener("change",o),()=>r.removeEventListener("change",o)):((s=r.addListener)==null||s.call(r,o),()=>{var i;return(i=r.removeListener)==null?void 0:i.call(r,o)})},[e]),t}const Ku="paddock:panewidth:",kw={key:"sidenav",def:288,min:200,max:480},yk={key:"chatlist",def:256,min:220,max:520},jw="(min-width: 1024px)";function Or(e,t){return Math.min(Math.max(t,e.min),e.max)}function tf(e,t,n){return Or(n,e+t)}function Ew(e){try{const t=localStorage.getItem(Ku+e.key);if(t==null)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?Or(e,n):null}catch{return null}}function Nw(e,t){try{localStorage.setItem(Ku+e.key,String(Or(e,t)))}catch{}}function Cw(e){try{localStorage.removeItem(Ku+e.key)}catch{}}function Pw(e){const t=Sw(jw),[n,r]=x.useState(()=>Ew(e)),o=Or(e,n??e.def);return{isDesktop:t,width:o,style:t?{width:o}:void 0,preview:s=>r(Or(e,s)),commit:s=>{const i=Or(e,s);r(i),Nw(e,i)},reset:()=>{r(null),Cw(e)},spec:e}}function Tw({spec:e,width:t,onPreview:n,onCommit:r,onReset:o,label:s}){const i=x.useRef(null),a=x.useRef(t);a.current=t;const u=16;return l.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":s,"aria-valuenow":Math.round(t),"aria-valuemin":e.min,"aria-valuemax":e.max,tabIndex:0,onPointerDown:c=>{i.current={startX:c.clientX,startWidth:t},c.currentTarget.setPointerCapture(c.pointerId)},onPointerMove:c=>{i.current&&n(tf(i.current.startWidth,c.clientX-i.current.startX,e))},onPointerUp:c=>{if(i.current){i.current=null;try{c.currentTarget.releasePointerCapture(c.pointerId)}catch{}r(a.current)}},onDoubleClick:o,onKeyDown:c=>{if(c.key==="ArrowLeft"||c.key==="ArrowRight"){c.preventDefault();const d=tf(t,c.key==="ArrowRight"?u:-u,e);n(d),r(d)}},title:"Drag to resize · double-click to reset",className:"group/resizer absolute inset-y-0 right-0 z-10 hidden w-1.5 -mr-0.5 cursor-ew-resize touch-none lg:block",children:l.jsx("span",{className:"absolute inset-y-0 right-0 w-px bg-edge transition group-hover/resizer:w-0.5 group-hover/resizer:bg-accent-solid group-focus/resizer:w-0.5 group-focus/resizer:bg-accent-solid"})})}function bw(e){const[t,n]=x.useState(new Map),r=x.useRef(new Map),[o,s]=x.useState(0);return x.useEffect(()=>{const i=r.current;for(const a of e)for(const u of a.chatTurns??[]){Gx(u.sessionId,u.lastSeen);const c=Date.parse(u.lastTurnCompletedAt);if(!Number.isFinite(c))continue;const d=i.get(u.sessionId);!d||c>d.at?i.set(u.sessionId,{slug:a.slug,at:c,unread:u.unread}):d.unread=u.unread}if(e.length>0){const a=new Set(e.map(u=>u.slug));for(const[u,c]of i)a.has(c.slug)||i.delete(u)}s(a=>a+1)},[e]),x.useEffect(()=>{const i=a=>{var d;const u=((d=a.detail)==null?void 0:d.sessionIds)??[];let c=!1;for(const f of u)c=r.current.delete(f)||c;c&&s(f=>f+1)};return window.addEventListener(Ml,i),()=>window.removeEventListener(Ml,i)},[]),x.useEffect(()=>{const i=new Map;return Wu.onActiveInfos(a=>{for(const[u,c]of i)a.has(u)||r.current.set(u,{slug:c,at:Date.now()});i.clear();for(const[u,c]of a)i.set(u,c);n(new Map(a)),s(u=>u+1)})},[]),x.useEffect(()=>{const i=()=>s(a=>a+1);return window.addEventListener(Ll,i),()=>window.removeEventListener(Ll,i)},[]),x.useMemo(()=>{const i=new Map,a=[],u=c=>{let d=i.get(c);return d||(d={unread:0,inflight:0},i.set(c,d)),d};for(const[c,{slug:d,at:f,unread:p}]of r.current)!t.has(c)&&(p||f>Qx(c))&&(u(d).unread+=1,a.push({sessionId:c,projectSlug:d,at:f}));for(const c of t.values())u(c).inflight+=1;return a.sort((c,d)=>d.at-c.at),{badges:i,unreadChats:a,active:t}},[t,o])}function Rw(){const{projects:e,rootWorkspace:t,loading:n,upsert:r}=Wp(),{dark:o,toggle:s}=lx(),[i,a]=x.useState(!1),[u,c]=x.useState(!1),d=es(),f=cr(),p=Hp(),S=dx(),k=Pw(kw),g=f.pathname==="/"||f.pathname==="/projects"||f.pathname.startsWith("/chat"),C=f.pathname.startsWith("/projects/")||g;x.useEffect(()=>{a(!1)},[f.pathname]);const m=x.useMemo(()=>{const b=new Map;for(const B of e){const ee=B.group??"",ce=b.get(ee);ce?ce.push(B):b.set(ee,[B])}return Bx(b.keys()).map(B=>[B,b.get(B)??[]])},[e]),h=x.useMemo(()=>yw(e),[e]),v=x.useMemo(()=>t?[...e,t]:e,[e,t]),{badges:E,unreadChats:T,active:R}=bw(v),M=Fx({active:R,finished:T});Dx(p,Ax(M.status));const y=E.get(_u),D=x.useMemo(()=>{let b=0;for(const B of E.values())b+=B.unread;return b},[E]);return l.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden bg-surface lg:flex-row",children:[!C&&l.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2 lg:hidden",children:[l.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":"Open menu",className:"btn-subtle -ml-1 px-2 py-2",children:l.jsx(Q1,{width:20,height:20})}),l.jsxs(yn,{to:"/",className:"flex items-center gap-2",children:[l.jsx(nf,{brand:p,className:"h-7 w-7 text-sm"}),l.jsx("span",{className:"text-md font-semibold tracking-tight",children:p.name})]})]}),i&&l.jsx("div",{className:"fixed inset-0 z-30 bg-overlay backdrop-blur-sm lg:hidden","aria-hidden":"true",onClick:()=>a(!1)}),l.jsxs("aside",{style:k.style,className:`fixed inset-y-0 left-0 z-40 flex w-72 max-w-[85%] shrink-0 flex-col border-r border-edge bg-surface 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/50 lg:shadow-none ${i?"translate-x-0":"-translate-x-full"}`,children:[k.isDesktop&&l.jsx(Tw,{spec:k.spec,width:k.width,onPreview:k.preview,onCommit:k.commit,onReset:k.reset,label:"Resize sidebar"}),l.jsxs("div",{className:"flex items-center gap-2 px-5 py-4",children:[l.jsxs(yn,{to:"/",className:"group flex items-center gap-2",children:[l.jsx(nf,{brand:p,className:"h-8 w-8 text-base"}),l.jsx("span",{className:"text-lg font-semibold tracking-tight",children:p.name})]}),l.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":"Close menu",className:"btn-subtle ml-auto px-2 py-2 lg:hidden",children:l.jsx(Hi,{width:18,height:18})})]}),l.jsx("div",{className:"px-3 pb-1",children:l.jsxs(yn,{to:"/",end:!0,className:({isActive:b})=>`btn-subtle w-full justify-start ${b?"bg-surface-selected":""}`,title:"The root workspace — every project, and the instance's own chats",children:[l.jsx(H1,{width:16,height:16}),"Home",l.jsx(hm,{badge:y,className:"ml-auto"})]})}),l.jsxs("div",{className:"mt-5 mb-1 flex items-center justify-between pr-3",children:[l.jsx(yn,{to:nx(),className:"section-label hover:text-accent",children:"Projects"}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx(yn,{to:"/discover","aria-label":"Discover projects",title:"Find directories with existing Claude Code history to import",className:({isActive:b})=>`btn-subtle px-1.5 py-1 hover:text-accent ${b?"text-accent":"text-fg-subtle"}`,children:l.jsx(Jd,{width:14,height:14})}),l.jsx("button",{type:"button",onClick:()=>c(!0),"aria-label":"New Project",title:"New Project",className:"btn-subtle -mr-1 px-1.5 py-1 text-fg-subtle hover:text-accent",children:l.jsx(W1,{width:14,height:14})})]})]}),l.jsxs("nav",{className:"flex-1 overflow-y-auto px-2 pb-4",children:[n&&l.jsx("div",{className:"space-y-2 px-2 py-2",children:[0,1,2].map(b=>l.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},b))}),!n&&e.length===0&&l.jsx("p",{className:"px-3 py-2 text-sm text-fg-muted",children:"No projects yet."}),!n&&e.length>0&&m.map(([b,B])=>l.jsxs("div",{className:"mb-2",children:[m.length>1&&l.jsx("div",{className:"px-2.5 pb-1 pt-2 text-3xs font-semibold uppercase tracking-wider text-fg-subtle",children:Ux(b)}),B.map(ee=>l.jsx(Mw,{project:ee,badge:E.get(ee.slug),chipColor:h.get(ee.slug)},ee.slug))]},b||"unsorted"))]}),l.jsxs("div",{className:"border-t border-edge px-3 py-3",children:[l.jsxs(yn,{to:"/config",className:({isActive:b})=>`btn-subtle w-full justify-start ${b?"bg-surface-selected":""}`,title:"Instance config — paddock.config.yaml (restart required)",children:[l.jsx(V1,{width:15,height:15}),"Config"]}),l.jsxs(yn,{to:"/discover",className:({isActive:b})=>`btn-subtle mt-1 w-full justify-start ${b?"bg-surface-selected":""}`,title:"Find directories with existing Claude Code history to import",children:[l.jsx(Jd,{width:15,height:15}),"Discover"]}),S.enabled&&l.jsxs("a",{href:S.path,target:"_blank",rel:"noreferrer",className:"btn-subtle mt-1 w-full justify-start",title:"OpenAPI / Swagger reference (opens in a new tab)",children:[l.jsx(X1,{width:15,height:15}),"Swagger API"]}),l.jsxs("button",{type:"button",onClick:s,className:"btn-subtle mt-1 w-full justify-start","aria-label":o?"Switch to light mode":"Switch to dark mode",title:"Toggle light / dark theme",children:[o?l.jsx(Y1,{width:15,height:15}):l.jsx(J1,{width:15,height:15}),o?"Light mode":"Dark mode"]}),l.jsxs("p",{className:"mt-2 px-2 text-2xs text-fg-subtle",children:["v","0.77.0"]})]})]}),l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[l.jsx(cw,{unread:D,finished:T}),l.jsx("main",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:l.jsx(x.Suspense,{fallback:l.jsx(Lw,{}),children:l.jsx(Jp.Provider,{value:M,children:l.jsx(M0,{context:{openNav:()=>a(!0)}})})})})]}),l.jsx(ww,{open:u,onClose:()=>c(!1),onCreated:b=>{r(b),c(!1),d(`/projects/${b.slug}/chat`)}})]})}function nf({brand:e,className:t=""}){const n=wx(e);return l.jsx("span",{className:`flex shrink-0 items-center justify-center overflow-hidden rounded-lg bg-accent-solid text-accent-fg shadow-sm ${t}`,style:n?{backgroundColor:n,color:Uu(n)}:void 0,"data-testid":"brand-chip",children:Vp(e.logo)?l.jsx("img",{src:e.logo,alt:"",className:"h-full w-full object-cover"}):e.logo})}function Lw(){return l.jsxs("div",{className:"flex h-full items-center justify-center","aria-busy":"true","aria-live":"polite",children:[l.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),l.jsx("span",{className:"sr-only",children:"Loading…"})]})}function Mw({project:e,badge:t,chipColor:n}){return l.jsxs(yn,{to:`/projects/${e.slug}`,className:({isActive:r})=>`group mb-0.5 flex flex-col gap-1 rounded-lg px-2.5 py-2 text-sm transition-colors ${r?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[l.jsxs("span",{className:"flex items-center justify-between gap-2",children:[l.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[l.jsx(pw,{slug:e.slug,name:e.name,color:n}),l.jsx("span",{className:"truncate font-medium",children:e.name})]}),l.jsx(hm,{badge:t})]}),e.domain.length>0&&l.jsxs("span",{className:"flex min-w-0 items-center gap-1 overflow-hidden pl-[22px]",children:[e.domain.slice(0,2).map(r=>l.jsx(Yx,{tag:r,className:"max-w-[7rem] truncate"},r)),e.domain.length>2&&l.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:["+",e.domain.length-2]})]})]})}function hm({badge:e,className:t=""}){const n=(e==null?void 0:e.unread)??0,r=(e==null?void 0:e.inflight)??0;return n===0&&r===0?null:l.jsxs("span",{className:`flex shrink-0 items-center gap-1.5 ${t}`,children:[r>0&&l.jsxs("span",{className:"flex items-center gap-1 text-2xs tabular text-fg-muted",title:`${r} chat${r===1?"":"s"} in flight`,"aria-label":`${r} chat${r===1?"":"s"} in flight`,children:[l.jsx("span",{"aria-hidden":"true",className:"h-2.5 w-2.5 spin-eco rounded-full border-[1.5px] border-edge-strong border-t-transparent"}),r]}),n>0&&l.jsx("span",{className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-accent-solid px-1.5 py-0.5 text-2xs font-semibold leading-none tabular text-accent-fg",title:`${n} unread ${n===1?"reply":"replies"}`,"aria-label":`${n} unread ${n===1?"reply":"replies"}`,children:n})]})}const pm="paddock:chunkReloadAt",_w=1e4,rf=/dynamically imported module|module script|importing a module|failed to fetch|unable to preload|load failed|error loading/i;function Iw(e){return e?e instanceof Error?e.name==="ChunkLoadError"?!0:rf.test(e.message):rf.test(String(e)):!1}function Qu(){try{return typeof sessionStorage<"u"?sessionStorage:void 0}catch{return}}function Dw(e=Date.now(),t=Qu()){if(!t)return!1;const n=t.getItem(pm);if(!n)return!1;const r=Number(n);return Number.isFinite(r)&&e-r<_w}function Ow(e=Date.now(),t=Qu()){try{t==null||t.setItem(pm,String(e))}catch{}}function $w(e,t=Date.now(),n=Qu()){return Iw(e)&&!Dw(t,n)?"reload":"show"}function Aw(){const e=Ap(),t=$w(e);if(x.useEffect(()=>{t==="reload"&&(Ow(),window.location.reload())},[t]),t==="reload")return l.jsxs("div",{className:"flex h-[100dvh] items-center justify-center bg-surface","aria-busy":"true","aria-live":"polite",children:[l.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),l.jsx("span",{className:"sr-only",children:"Updating…"})]});const n=e instanceof Error?e.message:typeof e=="string"?e:"";return l.jsxs("div",{className:"flex h-[100dvh] flex-col items-center justify-center gap-4 bg-surface px-6 text-center",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:"Something went wrong"}),l.jsx("p",{className:"mt-1 max-w-md text-sm text-fg-muted",children:"The app hit an unexpected error. Reloading usually fixes it."}),n?l.jsx("p",{className:"mt-2 max-w-md break-words font-mono text-2xs text-fg-subtle",children:n}):null]}),l.jsx("button",{className:"btn-primary",onClick:()=>window.location.reload(),children:"Reload"})]})}function zw(){typeof navigator>"u"||!("serviceWorker"in navigator)||window.addEventListener("load",()=>{const e=navigator.serviceWorker,t=!!e.controller;let n=!1;e.addEventListener("controllerchange",()=>{n||!t||(n=!0,window.location.reload())}),e.register("/sw.js").catch(()=>{})})}const Dt=4.5,mm=3,Tt=.12,gm=["--accent","--accent-600","--accent-700","--accent-solid","--accent-solid-hover","--accent-text"];function gt(e,t){const n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return null;const r=/^\d+(\.\d+)?( \d+(\.\d+)?){2}$/.test(n)?`rgb(${n})`:n;try{return Cn(r,{})}catch{return null}}function Fw(e,t,n){let r=0,o=1;for(let s=0;s<32;s++){const i=(r+o)/2;et(Qr(i,t,n))<e?r=i:o=i}return(r+o)/2}function vm(e,t,n){if($d(e,t,n))return t;let r=0,o=t;for(let s=0;s<24;s++){const i=(r+o)/2;$d(e,i,n)?r=i:o=i}return r}function Ta(e,t,n,r,o){const s=et(r);let i=t,a=.5;for(let u=0;u<4;u++){const c=Fw(s,i,n);let d=o?0:c,f=o?c:1;for(let p=0;p<28;p++){const S=(d+f)/2,k=We(Qr(S,i,n),r)>=e;o?k?d=S:f=S:k?f=S:d=S}a=o?d:f,i=vm(a,t,n)}return{L:a,C:i,rgb:Qr(a,i,n)}}const Uw=.75;function $r(e,t,n,r,o,s=e){const i=Ta(e,t,n,r,o),a=f=>f.C>=t*Uw;if(a(i)||s>=e)return{...i,hit:We(i.rgb,r)>=e-.01};let u=s,c=e,d=Ta(s,t,n,r,o);for(let f=0;f<16;f++){const p=(u+c)/2,S=Ta(p,t,n,r,o);a(S)?(d=S,u=p):c=p}return{...d,hit:We(d.rgb,r)>=s-.01}}function ba({r:e,g:t,b:n}){const r=o=>Math.round(Math.max(0,Math.min(1,o))*255);return`${r(e)} ${r(t)} ${r(n)}`}const ym=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected","--border-subtle","--border","--border-strong","--text","--text-muted","--text-subtle","--scroll-thumb"],of=["--text","--text-muted","--text-subtle"],Bw=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected"];function xm(e=document.documentElement){for(const t of ym)e.style.removeProperty(t)}function Ww(e,t,n=document.documentElement){xm(n);for(const o of ym){const s=gt(n,o);if(!s)continue;const{L:i,C:a}=tn(s),u=of.includes(o),c=Math.max(a,t*(u?.5:1));n.style.setProperty(o,Gt(Qr(i,vm(i,c,e),e)))}let r=1/0;for(const o of of){const s=gt(n,o);if(s)for(const i of Bw){const a=gt(n,i);a&&(r=Math.min(r,We(s,a)))}}return r}function wm(e=document.documentElement){for(const t of gm)e.style.removeProperty(t)}function Sm(e,t){const n=gm.map(r=>[r,e.style.getPropertyValue(r)]);wm(e);try{return t()}finally{for(const[r,o]of n)o&&e.style.setProperty(r,o)}}function Hw(e=document.documentElement){return Sm(e,()=>{const t=gt(e,"--accent");return t?tn(t).H:0})}const ho={r:1,g:1,b:1,a:1};function km(e=document.documentElement){return Sm(e,()=>Vw(e))}function Vw(e){const t={accent:gt(e,"--accent")??ho,a600:gt(e,"--accent-600")??ho,a700:gt(e,"--accent-700")??ho},n=gt(e,"--accent-fg")??ho,r=gt(e,"--surface")??ho,o=["--surface","--surface-raised","--surface-sunken"].map(a=>gt(e,a)).filter(a=>a!==null),s=o.length?o:[r],i=s.reduce((a,u)=>We(t.a700,a)<We(t.a700,u)?a:u);return{fg:n,surface:r,surfaces:s,targets:{accent:Math.max(We(t.accent,r),mm+Tt),a600:Math.max(We(t.a600,n),Dt+Tt),a700:Math.max(s.reduce((a,u)=>Math.min(a,We(t.a700,u)),1/0),Dt+Tt)},chroma:{accent:tn(t.accent).C,a600:tn(t.a600).C,a700:tn(t.a700).C},darker:{accent:et(t.accent)<et(r),a600:et(n)>et(t.a600),a700:et(t.a700)<et(i)},a700Bg:i}}function Kw(e,t){const n=Dt+Tt;return{accent:$r(e.targets.accent,e.chroma.accent,t,e.surface,e.darker.accent,mm+Tt),a600:$r(e.targets.a600,e.chroma.a600,t,e.fg,e.darker.a600,n),a700:$r(e.targets.a700,e.chroma.a700,t,e.a700Bg,e.darker.a700,n)}}function xk(e,t=document.documentElement){const n=km(t);return e.map(r=>Gt($r(n.targets.a600,n.chroma.a600,r,n.fg,n.darker.a600,Dt+Tt).rgb))}function Qw(e,t=document.documentElement,n={}){const r=t.classList.contains("dark")?"dark":"light",o=n.context??km(t),s=Kw(o,e),{a600:i,a700:a,accent:u}=s,c={C:o.chroma.a700};wm(t),t.style.setProperty("--accent",ba(u.rgb)),t.style.setProperty("--accent-600",ba(i.rgb)),t.style.setProperty("--accent-700",ba(a.rgb));const d={};for(const v of["--accent-fg","--accent-solid","--accent-solid-hover","--accent-text","--surface","--surface-raised","--surface-sunken","--accent-soft"])d[v]=gt(t,v);const f=[],p=d["--accent-fg"]??o.fg,S=(v,E,T)=>{const R=d[v];if(!R)return 1/0;let M=We(R,p),y=!1;if(M<T+Tt){const{C:D}=tn(R),b=$r(T+Tt,Math.max(D,o.chroma.a600),e,p,et(R)<et(p),Dt+Tt);t.style.setProperty(v,Gt(b.rgb)),M=We(b.rgb,p),y=!0}return f.push({label:E,fg:"--accent-fg",bg:v,ratio:M,floor:T,repaired:y}),M},k=S("--accent-solid","Primary button",Dt);S("--accent-solid-hover","Primary button, hovered",Math.min(k+.6,12));const g=[];for(const v of["--surface","--surface-raised","--surface-sunken","--accent-soft"]){const E=d[v];E&&g.push({name:v,c:E})}let C=1/0;const m=d["--accent-text"];if(m&&g.length){const v=g.reduce((T,R)=>We(m,T.c)<We(m,R.c)?T:R,g[0]);C=We(m,v.c);let E=!1;if(C<Dt+Tt){const{C:T}=tn(m),R=$r(Dt+Tt,T||c.C,e,v.c,et(m)<et(v.c));t.style.setProperty("--accent-text",Gt(R.rgb)),C=g.reduce((M,y)=>Math.min(M,We(R.rgb,y.c)),1/0),E=!0}f.push({label:"Accent text",fg:"--accent-text",bg:v.name,ratio:C,floor:Dt,repaired:E})}const h={};if(!n.live)for(const v of["--accent-solid","--accent-solid-hover","--accent-text"]){const E=gt(t,v);E&&(h[v]=Gt(E))}return{hue:e,mode:r,channels:{accent:Gt(u.rgb),accent600:Gt(i.rgb),accent700:Gt(a.rgb)},applied:h,checks:f,ok:f.every(v=>v.ratio>=v.floor-.005)&&k>=Dt}}const Gw=[{id:"foundation",label:"Foundation",blurb:"The neutral base. Warm ground, terracotta accent."},{id:"parchment",label:"Parchment",blurb:"Wine chrome, corner brackets, an old-style serif. A 90s RPG menu."},{id:"terminal",label:"Terminal",blurb:"Green phosphor and ANSI in the dark; greenbar and ribbon ink in the light."},{id:"scifi",label:"Sci-Fi",blurb:"Deep-space ground and luminous cyan. Hairlines, telemetry, glow."}],wk=[{name:"Ember",hue:40},{name:"Amber",hue:75},{name:"Olive",hue:110},{name:"Forest",hue:148},{name:"Teal",hue:190},{name:"Sky",hue:235},{name:"Indigo",hue:268},{name:"Violet",hue:300},{name:"Magenta",hue:330},{name:"Rose",hue:12}],Sk=[{level:0,label:"None"},{level:1,label:"A little"},{level:2,label:"More"}];function Yw(e=document.documentElement){const t=Hp().accent;if(t&&t.toLowerCase()!==An.accent.toLowerCase())try{return tn(Cn(t,{})).H}catch{}return Hw(e)}const sf={theme:"foundation",hue:null,tint:0},jm="paddock:appearance",af="paddock:appearance-cache";function Jw(){try{const e=localStorage.getItem(jm);if(!e)return sf;const t=JSON.parse(e);return{theme:Gw.some(n=>n.id===t.theme)?t.theme:"foundation",hue:typeof t.hue=="number"?(t.hue%360+360)%360:null,tint:t.tint===1||t.tint===2?t.tint:0}}catch{return sf}}function Xw(e){try{localStorage.setItem(jm,JSON.stringify(e))}catch{}}function Zw(e,t,n){try{const r=JSON.parse(localStorage.getItem(af)||"{}"),o=`${e}:${t?"dark":"light"}`;n?r[o]={...n.applied,"--accent":n.channels.accent}:delete r[o],localStorage.setItem(af,JSON.stringify(r))}catch{}}function qw(e,t=document.documentElement){t.setAttribute("data-theme",e.theme);const n=e.hue??Yw(t);let r=null;e.tint===0?xm(t):r=Ww(n,rS[e.tint],t);const o=Qw(n,t);return o&&r!==null&&(o.checks.push({label:"Body text on the tinted ground",fg:"--text-*",bg:"--surface-*",ratio:r,floor:4.5,repaired:!1}),o.ok=o.ok&&r>=4.5),Zw(e.theme,t.classList.contains("dark"),o),o}function eS(e,t){Xw(e);const n=qw(e,t);return window.dispatchEvent(new CustomEvent(tS,{detail:n})),n}const tS="paddock:appearance";function nS(){const e=()=>eS(Jw());e();const t=new MutationObserver(n=>{n.some(r=>r.attributeName==="class")&&e()});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()}const rS=[0,.008,.018],Em=x.lazy(()=>Zt(()=>import("./ProjectsGrid-BYgv4KBI.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.ProjectsGrid}))),Te=x.lazy(()=>Zt(()=>import("./ProjectView-Bj95W0f4.js").then(e=>e.a),__vite__mapDeps([4,5,1,2,6,7,3])).then(e=>({default:e.ProjectView}))),oS=x.lazy(()=>Zt(()=>import("./ProjectRedirect-BscldZqe.js"),__vite__mapDeps([8,2])).then(e=>({default:e.ProjectRedirect}))),sS=x.lazy(()=>Zt(()=>import("./InstanceConfigPage-C9cJA3mw.js"),__vite__mapDeps([9,6,3])).then(e=>({default:e.InstanceConfigPage}))),iS=x.lazy(()=>Zt(()=>import("./DiscoverPage-DzR0ltxH.js"),__vite__mapDeps([10,7,6,3])).then(e=>({default:e.DiscoverPage}))),aS=x.lazy(()=>Zt(()=>import("./RootHome-2SxtceM_.js"),__vite__mapDeps([11,4,5,1,2,6,7,3])).then(e=>({default:e.RootHome})));nS();const Nm=()=>document.documentElement.setAttribute("data-tab-hidden",document.hidden?"true":"false");document.addEventListener("visibilitychange",Nm);Nm();function lS(){const{tag:e}=w0();return l.jsx(Em,{filterTag:e?decodeURIComponent(e):void 0})}const uS=F0([{path:"/",element:l.jsx(Rw,{}),errorElement:l.jsx(Aw,{}),children:[{index:!0,element:l.jsx(aS,{})},{path:"projects",element:l.jsx(Em,{})},{path:"tags/:tag",element:l.jsx(lS,{})},{path:"projects/:slug",element:l.jsx(oS,{})},{path:"projects/:slug/home",element:l.jsx(Te,{})},{path:"projects/:slug/chat",element:l.jsx(Te,{})},{path:"projects/:slug/chat/:sessionId",element:l.jsx(Te,{})},{path:"projects/:slug/files",element:l.jsx(Te,{})},{path:"projects/:slug/files/*",element:l.jsx(Te,{})},{path:"projects/:slug/changes",element:l.jsx(Te,{})},{path:"projects/:slug/changes/:file",element:l.jsx(Te,{})},{path:"projects/:slug/history",element:l.jsx(Te,{})},{path:"projects/:slug/settings",element:l.jsx(Te,{})},{path:"projects/:slug/triggers",element:l.jsx(Te,{})},{path:"projects/:slug/hooks",element:l.jsx(Te,{})},{path:"chat",element:l.jsx(Te,{root:!0})},{path:"chat/:sessionId",element:l.jsx(Te,{root:!0})},{path:"files",element:l.jsx(Te,{root:!0})},{path:"files/*",element:l.jsx(Te,{root:!0})},{path:"changes",element:l.jsx(Te,{root:!0})},{path:"changes/:file",element:l.jsx(Te,{root:!0})},{path:"history",element:l.jsx(Te,{root:!0})},{path:"triggers",element:l.jsx(Te,{root:!0})},{path:"settings",element:l.jsx(Te,{root:!0})},{path:"config",element:l.jsx(sS,{})},{path:"discover",element:l.jsx(iS,{})}]}]);Ra.createRoot(document.getElementById("root")).render(l.jsx(wf.StrictMode,{children:l.jsx(sx,{children:l.jsx(G0,{router:uS})})}));zw();export{$S as $,K1 as A,uk as B,BS as C,wk as D,Sk as E,wm as F,Qw as G,km as H,jt as I,m1 as J,FS as K,ts as L,tk as M,fS as N,Sw as O,rk as P,Jd as Q,_u as R,XS as S,nk as T,OS as U,Xt as V,G1 as W,Hi as X,zS as Y,$n as Z,AS as _,ar as a,yS as a$,dS as a0,Q1 as a1,V1 as a2,vk as a3,VS as a4,fk as a5,rm as a6,pk as a7,cS as a8,GS as a9,JS as aA,Wu as aB,US as aC,dk as aD,hk as aE,sk as aF,Iu as aG,Bu as aH,qS as aI,jS as aJ,im as aK,HS as aL,Tw as aM,ES as aN,ck as aO,mk as aP,lk as aQ,gk as aR,wS as aS,SS as aT,Gx as aU,Qx as aV,kS as aW,Z1 as aX,gS as aY,hS as aZ,Up as a_,QS as aa,ok as ab,ZS as ac,X1 as ad,KS as ae,PS as af,TS as ag,LS as ah,RS as ai,bS as aj,MS as ak,IS as al,_S as am,qx as an,y1 as ao,WS as ap,Xx as aq,Ea as ar,NS as as,Zt as at,ik as au,ak as av,Oi as aw,DS as ax,rx as ay,CS as az,Zd as b,cr as b0,pS as b1,mS as b2,Pw as b3,vS as b4,yk as b5,Ye as c,Wp as d,g1 as e,uf as f,Hp as g,es as h,W1 as i,l as j,ww as k,nx as l,Yx as m,ek as n,Bx as o,yi as p,xS as q,x as r,Ux as s,YS as t,w0 as u,Jw as v,eS as w,tS as x,xk as y,Gw as z};
70
+ */function Kr(){return Kr=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Kr.apply(this,arguments)}function zp(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function D0(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function O0(e,t){return e.button===0&&(!t||t==="_self")&&!D0(e)}const $0=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],A0=["aria-current","caseSensitive","className","end","style","to","unstable_viewTransition","children"],z0="6";try{window.__reactRouterVersion=z0}catch{}function F0(e,t){return Gy({basename:void 0,future:Kr({},void 0,{v7_prependBasename:!0}),history:yy({window:void 0}),hydrationData:U0(),routes:e,mapRouteProperties:I0,unstable_dataStrategy:void 0,unstable_patchRoutesOnNavigation:void 0,window:void 0}).initialize()}function U0(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Kr({},t,{errors:B0(t.errors)})),t}function B0(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,o]of t)if(o&&o.__type==="RouteErrorResponse")n[r]=new mi(o.status,o.statusText,o.data,o.internal===!0);else if(o&&o.__type==="Error"){if(o.__subType){let s=window[o.__subType];if(typeof s=="function")try{let i=new s(o.message);i.stack="",n[r]=i}catch{}}if(n[r]==null){let s=new Error(o.message);s.stack="",n[r]=s}}else n[r]=o;return n}const Fp=x.createContext({isTransitioning:!1}),W0=x.createContext(new Map),H0="startTransition",Md=sg[H0],V0="flushSync",_d=vy[V0];function K0(e){Md?Md(e):e()}function fo(e){_d?_d(e):e()}class Q0{constructor(){this.status="pending",this.promise=new Promise((t,n)=>{this.resolve=r=>{this.status==="pending"&&(this.status="resolved",t(r))},this.reject=r=>{this.status==="pending"&&(this.status="rejected",n(r))}})}}function G0(e){let{fallbackElement:t,router:n,future:r}=e,[o,s]=x.useState(n.state),[i,a]=x.useState(),[u,c]=x.useState({isTransitioning:!1}),[d,f]=x.useState(),[p,S]=x.useState(),[k,g]=x.useState(),C=x.useRef(new Map),{v7_startTransition:m}=r||{},h=x.useCallback(y=>{m?K0(y):y()},[m]),v=x.useCallback((y,D)=>{let{deletedFetchers:b,unstable_flushSync:B,unstable_viewTransitionOpts:ee}=D;b.forEach(fe=>C.current.delete(fe)),y.fetchers.forEach((fe,st)=>{fe.data!==void 0&&C.current.set(st,fe.data)});let ce=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!ee||ce){B?fo(()=>s(y)):h(()=>s(y));return}if(B){fo(()=>{p&&(d&&d.resolve(),p.skipTransition()),c({isTransitioning:!0,flushSync:!0,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation})});let fe=n.window.document.startViewTransition(()=>{fo(()=>s(y))});fe.finished.finally(()=>{fo(()=>{f(void 0),S(void 0),a(void 0),c({isTransitioning:!1})})}),fo(()=>S(fe));return}p?(d&&d.resolve(),p.skipTransition(),g({state:y,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation})):(a(y),c({isTransitioning:!0,flushSync:!1,currentLocation:ee.currentLocation,nextLocation:ee.nextLocation}))},[n.window,p,d,C,h]);x.useLayoutEffect(()=>n.subscribe(v),[n,v]),x.useEffect(()=>{u.isTransitioning&&!u.flushSync&&f(new Q0)},[u]),x.useEffect(()=>{if(d&&i&&n.window){let y=i,D=d.promise,b=n.window.document.startViewTransition(async()=>{h(()=>s(y)),await D});b.finished.finally(()=>{f(void 0),S(void 0),a(void 0),c({isTransitioning:!1})}),S(b)}},[h,i,d,n.window]),x.useEffect(()=>{d&&i&&o.location.key===i.location.key&&d.resolve()},[d,p,o.location,i]),x.useEffect(()=>{!u.isTransitioning&&k&&(a(k.state),c({isTransitioning:!0,flushSync:!1,currentLocation:k.currentLocation,nextLocation:k.nextLocation}),g(void 0))},[u.isTransitioning,k]),x.useEffect(()=>{},[]);let E=x.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:y=>n.navigate(y),push:(y,D,b)=>n.navigate(y,{state:D,preventScrollReset:b==null?void 0:b.preventScrollReset}),replace:(y,D,b)=>n.navigate(y,{replace:!0,state:D,preventScrollReset:b==null?void 0:b.preventScrollReset})}),[n]),T=n.basename||"/",R=x.useMemo(()=>({router:n,navigator:E,static:!1,basename:T}),[n,E,T]),M=x.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return x.createElement(x.Fragment,null,x.createElement(qo.Provider,{value:R},x.createElement(Lu.Provider,{value:o},x.createElement(W0.Provider,{value:C.current},x.createElement(Fp.Provider,{value:u},x.createElement(_0,{basename:T,location:o.location,navigationType:o.historyAction,navigator:E,future:M},o.initialized||n.future.v7_partialHydration?x.createElement(Y0,{routes:n.routes,future:n.future,state:o}):t))))),null)}const Y0=x.memo(J0);function J0(e){let{routes:t,future:n,state:r}=e;return S0(t,void 0,r,n)}const X0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Z0=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ts=x.forwardRef(function(t,n){let{onClick:r,relative:o,reloadDocument:s,replace:i,state:a,target:u,to:c,preventScrollReset:d,unstable_viewTransition:f}=t,p=zp(t,$0),{basename:S}=x.useContext(cn),k,g=!1;if(typeof c=="string"&&Z0.test(c)&&(k=c,X0))try{let v=new URL(window.location.href),E=c.startsWith("//")?new URL(v.protocol+c):new URL(c),T=ln(E.pathname,S);E.origin===v.origin&&T!=null?c=T+E.search+E.hash:g=!0}catch{}let C=v0(c,{relative:o}),m=ex(c,{replace:i,state:a,target:u,preventScrollReset:d,relative:o,unstable_viewTransition:f});function h(v){r&&r(v),v.defaultPrevented||m(v)}return x.createElement("a",Kr({},p,{href:k||C,onClick:g||s?r:h,ref:n,target:u}))}),yn=x.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:o=!1,className:s="",end:i=!1,style:a,to:u,unstable_viewTransition:c,children:d}=t,f=zp(t,A0),p=Fi(u,{relative:f.relative}),S=cr(),k=x.useContext(Lu),{navigator:g,basename:C}=x.useContext(cn),m=k!=null&&tx(p)&&c===!0,h=g.encodeLocation?g.encodeLocation(p).pathname:p.pathname,v=S.pathname,E=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;o||(v=v.toLowerCase(),E=E?E.toLowerCase():null,h=h.toLowerCase()),E&&C&&(E=ln(E,C)||E);const T=h!=="/"&&h.endsWith("/")?h.length-1:h.length;let R=v===h||!i&&v.startsWith(h)&&v.charAt(T)==="/",M=E!=null&&(E===h||!i&&E.startsWith(h)&&E.charAt(h.length)==="/"),y={isActive:R,isPending:M,isTransitioning:m},D=R?r:void 0,b;typeof s=="function"?b=s(y):b=[s,R?"active":null,M?"pending":null,m?"transitioning":null].filter(Boolean).join(" ");let B=typeof a=="function"?a(y):a;return x.createElement(ts,Kr({},f,{"aria-current":D,className:b,ref:n,style:B,to:u,unstable_viewTransition:c}),typeof d=="function"?d(y):d)});var Nl;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Nl||(Nl={}));var Id;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Id||(Id={}));function q0(e){let t=x.useContext(qo);return t||q(!1),t}function ex(e,t){let{target:n,replace:r,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a}=t===void 0?{}:t,u=es(),c=cr(),d=Fi(e,{relative:i});return x.useCallback(f=>{if(O0(f,n)){f.preventDefault();let p=r!==void 0?r:ir(c)===ir(d);u(e,{replace:p,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a})}},[c,u,d,r,o,n,e,s,i,a])}function tx(e,t){t===void 0&&(t={});let n=x.useContext(Fp);n==null&&q(!1);let{basename:r}=q0(Nl.useViewTransitionState),o=Fi(e,{relative:t.relative});if(!n.isTransitioning)return!1;let s=ln(n.currentLocation.pathname,r)||n.currentLocation.pathname,i=ln(n.nextLocation.pathname,r)||n.nextLocation.pathname;return pi(o.pathname,i)!=null||pi(o.pathname,s)!=null}const _u="";function Iu(e){return e===_u}function K(e){return Iu(e)?"/api/root":`/api/projects/${encodeURIComponent(e)}`}function Up(e){return Iu(e)?"":`/projects/${e}`}function hS(e){return e===""?"/":`${e}/home`}function nx(){return"/projects"}function pS(e,t){const n=e.startsWith(t)?e.slice(t.length):e;return n.startsWith("/files")?"files":n.startsWith("/changes")?"changes":n.startsWith("/history")?"history":n.startsWith("/settings")?"settings":n.startsWith("/triggers")||n.startsWith("/hooks")?"triggers":n.startsWith("/home")?"home":n.startsWith("/chat")?"chat":t===""?"home":"chat"}function mS(e,t){const n=`${t}/files`;if(!e.startsWith(n))return"";const r=e.slice(n.length).replace(/^\//,"");return r?r.split("/").filter(Boolean).map(o=>{try{return decodeURIComponent(o)}catch{return o}}).join("/"):""}function rx(e){return`m-${e}`}function gS(e,t,n){return`${e}/chat/${encodeURIComponent(t)}#${rx(n)}`}function vS(e){var t;return(t=/^#?m-([0-9a-fA-F][0-9a-fA-F-]{7,})$/.exec(e))==null?void 0:t[1]}const Gn="";async function U(e,t){const n=await fetch(`${Gn}${e}`,{headers:{"content-type":"application/json",...(t==null?void 0:t.headers)??{}},...t});if(!n.ok){let r=n.statusText,o,s;try{s=await n.json();const i=s;i.error&&(r=i.error),typeof i.code=="string"&&(o=i.code)}catch{}throw new $n(r,n.status,o,s)}return await n.json()}async function ox(e,t){const n=await fetch(`${Gn}${e}`,t);if(!n.ok){let r=n.statusText;try{const o=JSON.parse(await n.text());o.error&&(r=o.error)}catch{}throw new $n(r,n.status)}return n.text()}class $n extends Error{constructor(t,n,r,o){super(t),this.status=n,this.code=r,this.body=o,this.name="ApiError"}}const Dd={transcriptRenderLimit:500};let Od=null;const ar={async me(){return U("/api/me")},async markChatSeen(e,t,n,r){const o=`${K(e)}/chats/${encodeURIComponent(t)}/seen`;await U(o,{method:"POST",body:JSON.stringify({...n!==void 0?{when:n}:{},...r!=null&&r.keepUnread?{keepUnread:!0}:{}})})},async markChatUnread(e,t,n){const r=`${K(e)}/chats/${encodeURIComponent(t)}/unread`;await U(r,{method:"POST",body:JSON.stringify({unread:n})})},async projectRuns(e,t){const n=t!==void 0?`?limit=${encodeURIComponent(t)}`:"";return U(`${K(e)}/runs${n}`)},async markRunsSeen(e,t){await U(`${K(e)}/runs/seen`,{method:"POST",body:JSON.stringify(t!==void 0?{when:t}:{})})},async getModels(){return U("/api/models")},async getInstanceConfig(){return U("/api/instance-config")},async updateInstanceConfig(e,t){return U("/api/instance-config",{method:"PUT",body:JSON.stringify(t===void 0?{patch:e}:{patch:e,expectedVersion:t})})},async uploadAttachments(e,t,n){const r=new FormData;for(const s of n)r.append("files",s,s.name);const o=await fetch(`${Gn}${K(e)}/chats/${encodeURIComponent(t)}/upload`,{method:"POST",body:r});if(!o.ok){let s=o.statusText;try{const i=await o.json();i.error&&(s=i.error)}catch{}throw new $n(s,o.status)}return await o.json()},async projectCommands(e){const{commands:t}=await U(`${K(e)}/commands`);return t},async listProjects(){const{projects:e,root:t}=await U("/api/projects");return{projects:e,root:t??null}},async getProjectDetail(e){return U(`${K(e)}`)},async attentionChats(e){const t=await U(`${K(e)}/chats/attention`);return{running:t.running??[],unread:t.unread??[],recent:t.recent??[]}},async createProject(e){const{project:t}=await U("/api/projects",{method:"POST",body:JSON.stringify(e)});return t},async updateProject(e,t){const{project:n}=await U(`${K(e)}`,{method:"PATCH",body:JSON.stringify(t)});return n},async promoteProject(e,t){const{project:n}=await U(`${K(e)}/promote`,{method:"POST",body:JSON.stringify({repo:t})});return n},async deleteProject(e){await U(`${K(e)}`,{method:"DELETE"})},async deleteProjectChat(e,t){await U(`${K(e)}/chats/${encodeURIComponent(t)}`,{method:"DELETE"})},async renameProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({name:n})})},async archiveProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/archive`,{method:"POST",body:JSON.stringify({archived:n})})},async starProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/star`,{method:"POST",body:JSON.stringify({starred:n})})},async archiveProjectChats(e,t,n){await U(`${K(e)}/chats/batch/archive`,{method:"POST",body:JSON.stringify({sessionIds:t,archived:n})})},async markChatsUnread(e,t,n){await U(`${K(e)}/chats/batch/unread`,{method:"POST",body:JSON.stringify({sessionIds:t,unread:n})})},async deleteProjectChats(e,t){const n=await U(`${K(e)}/chats/batch/delete`,{method:"POST",body:JSON.stringify({sessionIds:t})});return{removed:n.removed??[],failed:n.failed??[]}},async detachProjectChat(e,t,n){await U(`${K(e)}/chats/${encodeURIComponent(t)}/detach`,{method:"POST",body:JSON.stringify({detached:n})})},async promoteChat(e,t,n){return U(`${K(e)}/chats/${encodeURIComponent(t)}/promote`,{method:"POST",body:JSON.stringify(n)})},async forkChat(e,t,n,r){const{sessionId:o}=await U(`${K(e)}/chats/${encodeURIComponent(t)}/fork`,{method:"POST",body:JSON.stringify({name:n,fromUuid:r})});return o},async revertChat(e,t,n){const{removed:r}=await U(`${K(e)}/chats/${encodeURIComponent(t)}/revert`,{method:"POST",body:JSON.stringify({uuid:n})});return r},async listProjectDir(e,t=""){const n=t?`?path=${encodeURIComponent(t)}`:"";return U(`${K(e)}/files${n}`)},async listProjectFiles(e){const{entries:t}=await this.listProjectDir(e);return t.filter(n=>n.kind==="file").map(n=>n.name)},async getProjectFile(e,t){return U(`${K(e)}/files/${encodeURIComponent(t)}`)},projectFileRawUrl(e,t){return`${Gn}${K(e)}/files/${encodeURIComponent(t)}?raw=1`},chatFileRawUrl(e){return`${Gn}/api/chat-files/${encodeURIComponent(e)}`},async pinFile(e,t){const{project:n}=await U(`${K(e)}/pins`,{method:"PUT",body:JSON.stringify({file:t})});return n},async unpinFile(e,t){const{project:n}=await U(`${K(e)}/pins/${encodeURIComponent(t)}`,{method:"DELETE"});return n},async listProjectChats(e){const{chats:t}=await U(`${K(e)}/chats`);return t},async getAdoptableChats(e){return U(`${K(e)}/adoptable-chats`)},async adoptChats(e,t){return U(`${K(e)}/adopt-chats`,{method:"POST",body:JSON.stringify(t??{})})},async unadoptChats(e,t){return U(`${K(e)}/unadopt-chats`,{method:"POST",body:JSON.stringify(t??{})})},async chatUsage(e,t){const n=t?`?scope=${t}`:"",{usage:r}=await U(`${K(e)}/chats/usage${n}`);return r},uiConfig(){return Od??(Od=ar.getModels().then(e=>e.uiDefault??Dd).catch(()=>Dd)),Od},async projectChatMessages(e,t,n=0){const r=n>0?`?limit=${n}`:"",o=await U(`${K(e)}/chats/${encodeURIComponent(t)}/messages${r}`);return{messages:o.messages,total:o.total??o.messages.length,truncated:o.truncated??!1}},async subagentMessages(e,t,n){const r=`${K(e)}/chats/${encodeURIComponent(t)}`,{messages:o}=await U(`${r}/subagents/${encodeURIComponent(n)}/messages`);return o},async chatContext(e,t){const n=`${K(e)}/chats/${encodeURIComponent(t)}/context`,{usage:r}=await U(n);return r},async listTriggers(e){return U(`${K(e)}/triggers`)},async putTrigger(e,t,n){const{trigger:r}=await U(`${K(e)}/triggers/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)});return r},async deleteTrigger(e,t){await U(`${K(e)}/triggers/${encodeURIComponent(t)}`,{method:"DELETE"})},async triggerRuntime(e){return U(`${K(e)}/triggers/runtime`)},async runTrigger(e,t){const{sessionId:n}=await U(`${K(e)}/triggers/${encodeURIComponent(t)}/run`,{method:"POST",body:"{}"});return n},async gitInfo(){return U("/api/git")},async gitStatus(e){return U(`${K(e)}/git/status`)},async gitDiff(e,t){const n=t?`?file=${encodeURIComponent(t)}`:"";return ox(`${K(e)}/git/diff${n}`)},async gitCommit(e,t,n){return U(`${K(e)}/git/commit`,{method:"POST",body:JSON.stringify(n?{message:t,files:n}:{message:t})})},async gitProjectInfo(e){return U(`${K(e)}/git/remote`)},async gitPush(e){return U(`${K(e)}/git/push`,{method:"POST"})},async gitUntrackedFile(e,t){return U(`${K(e)}/git/file?path=${encodeURIComponent(t)}`)},gitUntrackedFileRawUrl(e,t){return`${Gn}${K(e)}/git/file?path=${encodeURIComponent(t)}&raw=1`},async githubConnect(){return U("/api/git/github/connect",{method:"POST"})},async githubPoll(e){return U("/api/git/github/poll",{method:"POST",body:JSON.stringify({deviceCode:e})})},async githubDisconnect(){await U("/api/git/github/disconnect",{method:"POST"})},async discover(e){const t=new URLSearchParams;e!=null&&e.includeNonGit&&t.set("includeNonGit","1"),e!=null&&e.includeOutsideHome&&t.set("includeOutsideHome","1");const n=t.toString();return U(`/api/discover${n?`?${n}`:""}`)},async discoverSessions(e){return U(`/api/discover/sessions?dir=${encodeURIComponent(e)}`)},async transcriptionStatus(){return U("/api/transcription")},async transcribe(e,t="dictation.webm",n){const r=new FormData;r.append("file",e,t);const o=await fetch(`${Gn}/api/transcribe`,{method:"POST",body:r,signal:n});if(!o.ok){let i=o.statusText;try{const a=await o.json();a.error&&(i=a.error)}catch{}throw new $n(i,o.status)}const{text:s}=await o.json();return s},async transcriptsMigration(){return U("/api/transcripts/migration")},async transcriptsMigrationChats(e){const t=e===void 0?"":`?slug=${encodeURIComponent(e)}`;return U(`/api/transcripts/migration/chats${t}`)},async runTranscriptsMigration(e){return U("/api/transcripts/migration",{method:"POST",body:JSON.stringify(e)})}},Bp=x.createContext(null);function sx({children:e}){const[t,n]=x.useState([]),[r,o]=x.useState(null),[s,i]=x.useState(!0),[a,u]=x.useState(null),c=x.useRef(!1),d=x.useCallback(async()=>{c.current||i(!0),u(null);try{const{projects:k,root:g}=await ar.listProjects();c.current=!0,n(k),g&&o(g)}catch(k){u(k instanceof Error?k.message:"Failed to load projects")}finally{i(!1)}},[]),f=x.useCallback(k=>{if(Iu(k.slug)){o(k);return}n(g=>[k,...g.filter(C=>C.slug!==k.slug)])},[]),p=x.useCallback(k=>{n(g=>g.filter(C=>C.slug!==k))},[]);x.useEffect(()=>{d()},[d]);const S=x.useMemo(()=>({projects:t,rootWorkspace:r,loading:s,error:a,refresh:d,upsert:f,remove:p}),[t,r,s,a,d,f,p]);return l.jsx(Bp.Provider,{value:S,children:e})}function Wp(){const e=x.useContext(Bp);if(!e)throw new Error("useProjects must be used within ProjectsProvider");return e}const ix="paddock:theme";function ax(){return typeof document<"u"&&document.documentElement.classList.contains("dark")}function lx(){const[e,t]=x.useState(ax),n=x.useCallback(()=>{t(r=>{const o=!r;document.documentElement.classList.toggle("dark",o);try{localStorage.setItem(ix,o?"dark":"light")}catch{}return o})},[]);return{dark:e,toggle:n}}const An={name:"Paddock",logo:"🐎",accent:"#c2603c"},ux={running:"#f97316",unread:"#22c55e"},cx={enabled:!1,path:"/open-api"};function Hp(){const e=globalThis.__PADDOCK_CONFIG__;return{...An,...(e==null?void 0:e.brand)??{}}}function dx(){const e=globalThis.__PADDOCK_CONFIG__;return{...cx,...(e==null?void 0:e.openapi)??{}}}function Vp(e){return/^(https?:\/\/|\/)/i.test(e.trim())}const Du=e=>e<0?0:e>1?1:e;function Ou(e){return e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055}function It(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function $u({L:e,a:t,b:n}){const r=(e+.3963377774*t+.2158037573*n)**3,o=(e-.1055613458*t-.0638541728*n)**3,s=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s]}function Cl(e,t,n){const r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),o=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),s=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return{L:.2104542553*r+.793617785*o-.0040720468*s,a:1.9779984951*r-2.428592205*o+.4505937099*s,b:.0259040371*r+.7827717662*o-.808675766*s}}function Qr(e,t,n,r=1){const o=n*Math.PI/180,s=$u({L:e,a:t*Math.cos(o),b:t*Math.sin(o)}),[i,a,u]=s.map(c=>Du(Ou(c)));return{r:i,g:a,b:u,a:r}}function $d(e,t,n){const r=n*Math.PI/180;return $u({L:e,a:t*Math.cos(r),b:t*Math.sin(r)}).map(Ou).every(o=>o>=-.0015&&o<=1.0015)}function Gt({r:e,g:t,b:n}){const r=o=>Math.round(Du(o)*255).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`}function et({r:e,g:t,b:n}){const[r,o,s]=[e,t,n].map(It);return .2126*r+.7152*o+.0722*s}function fx(e,t){if(e.a>=1)return e;const n=e.a;return{r:e.r*n+t.r*(1-n),g:e.g*n+t.g*(1-n),b:e.b*n+t.b*(1-n),a:1}}function We(e,t){const n=et(fx(e,t)),r=et(t),[o,s]=n>r?[n,r]:[r,n];return(o+.05)/(s+.05)}const Ad={white:{r:1,g:1,b:1,a:1},black:{r:0,g:0,b:0,a:1},transparent:{r:0,g:0,b:0,a:0}};function ja(e){const t=[];let n=0,r="";for(const o of e)o==="("?n++:o===")"&&n--,o===","&&n===0?(t.push(r.trim()),r=""):r+=o;return r.trim()&&t.push(r.trim()),t}function mr(e,t){return!e.startsWith(`${t}(`)||!e.endsWith(")")?null:e.slice(t.length+1,-1)}function gn(e){const t=e.endsWith("%")?Number(e.slice(0,-1))/100:Number(e);if(!Number.isFinite(t))throw new Error(`not a number: ${e}`);return t}function Cn(e,t,n=0){if(n>24)throw new Error(`var() cycle resolving ${e}`);const r=e.trim();if(Ad[r])return Ad[r];if(r.startsWith("#")){let u=r.slice(1);if(u.length===3&&(u=[...u].map(d=>d+d).join("")),u.length!==6)throw new Error(`bad hex: ${r}`);const c=parseInt(u,16);return{r:(c>>16&255)/255,g:(c>>8&255)/255,b:(c&255)/255,a:1}}const o=mr(r,"var");if(o!==null){const[u,...c]=ja(o),d=t[u]??c.join(",");if(!d)throw new Error(`undefined custom property: ${u}`);return Cn(d,t,n+1)}const s=mr(r,"oklch");if(s!==null){const[u,c]=s.split("/"),d=u.trim().split(/\s+/);if(d.length!==3)throw new Error(`bad oklch(): ${r}`);return Qr(gn(d[0]),gn(d[1]),gn(d[2]),c?gn(c.trim()):1)}const i=mr(r,"rgb")??mr(r,"rgba");if(i!==null){const u=i.trim(),c=mr(u,"var");if(c!==null){const[S]=ja(c),k=t[S];if(!k)throw new Error(`undefined custom property: ${S}`);return Cn(`rgb(${k})`,t,n+1)}const[d,f]=u.split("/"),p=d.trim().split(/[\s,]+/);if(p.length<3)throw new Error(`bad rgb(): ${r}`);return{r:gn(p[0])/255,g:gn(p[1])/255,b:gn(p[2])/255,a:f?gn(f.trim()):1}}const a=mr(r,"color-mix");if(a!==null){const[u,c,d]=ja(a),f=u.trim();if(f!=="in oklab"&&f!=="in srgb")throw new Error(`only \`in oklab\` and \`in srgb\` color-mix are supported, got: ${u}`);const p=zd(c),S=zd(d);let k=p.pct,g=S.pct;k===null&&g===null?(k=.5,g=.5):k===null?k=1-g:g===null&&(g=1-k);const C=k+g,m=k/C,h=Cn(p.color,t,n+1),v=Cn(S.color,t,n+1);return f==="in srgb"?hx(h,v,m):px(h,v,m)}throw new Error(`unsupported colour value: ${r}`)}function zd(e){const t=/\s+(-?[\d.]+)%$/.exec(e.trim());return t?{color:e.trim().slice(0,t.index).trim(),pct:Number(t[1])/100}:{color:e.trim(),pct:null}}function hx(e,t,n){return{r:e.r*n+t.r*(1-n),g:e.g*n+t.g*(1-n),b:e.b*n+t.b*(1-n),a:e.a*n+t.a*(1-n)}}function px(e,t,n){const r=Cl(It(e.r),It(e.g),It(e.b)),o=Cl(It(t.r),It(t.g),It(t.b)),s={L:r.L*n+o.L*(1-n),a:r.a*n+o.a*(1-n),b:r.b*n+o.b*(1-n)},[i,a,u]=$u(s).map(c=>Du(Ou(c)));return{r:i,g:a,b:u,a:e.a*n+t.a*(1-n)}}function tn({r:e,g:t,b:n}){const{L:r,a:o,b:s}=Cl(It(e),It(t),It(n)),i=Math.hypot(o,s),a=i<1e-6?0:(Math.atan2(s,o)*180/Math.PI+360)%360;return{L:r,C:i,H:a}}const mx=[[.47,.17,25],[.5,.122,55],[.555,.112,90],[.48,.12,125],[.545,.15,150],[.44,.077,185],[.555,.098,215],[.545,.15,252],[.44,.17,282],[.58,.16,308],[.48,.17,338],[.58,.16,5]],ns=Object.freeze(mx.map(([e,t,n])=>Gt(Qr(e,t,n)))),Fd=ns.map(e=>{const{L:t,C:n,H:r}=tn(Cn(e,{})),o=r*Math.PI/180;return{L:t,a:n*Math.cos(o),b:n*Math.sin(o)}});function gx(e,t){const n=Fd[e],r=Fd[t];return Math.hypot(n.L-r.L,n.a-r.a,n.b-r.b)}function vx(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function Kp(e){return vx(e.trim())%ns.length}function Au(e){return ns[Kp(e)]}const Ui=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function zu(e){return!e||Ui(e,An.accent)}function yx(e){return Ui(e.name,An.name)&&e.logo.trim()===An.logo&&zu(e.accent)}function Fu(e){try{return Cn(e,{})}catch{return null}}function xx(e){return!zu(e.accent)&&Fu(e.accent)?e.accent.trim():Ui(e.name,An.name)?An.accent:Au(e.name)}function wx(e){return!zu(e.accent)&&Fu(e.accent)||Ui(e.name,An.name)?null:Au(e.name)}function Uu(e,t=4.5){const n=Fu(e);return n?We({r:1,g:1,b:1,a:1},n)>=t?"white":"black":"white"}const Pl={small:16,large:32},Sx=.22,kx=.76,Ud='"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, -apple-system, "Segoe UI", sans-serif';function Qp(e,t){const n=t*Sx;e.beginPath(),e.moveTo(n,0),e.lineTo(t-n,0),e.quadraticCurveTo(t,0,t,n),e.lineTo(t,t-n),e.quadraticCurveTo(t,t,t-n,t),e.lineTo(n,t),e.quadraticCurveTo(0,t,0,t-n),e.lineTo(0,n),e.quadraticCurveTo(0,0,n,0),e.closePath()}function jx(e,t,n){Qp(e,t),e.fillStyle=n,e.fill()}function Bd(e,t){const n=e.measureText(t),r=n.actualBoundingBoxLeft??0,o=n.actualBoundingBoxRight??n.width,s=n.actualBoundingBoxAscent??0,i=n.actualBoundingBoxDescent??0;return{left:r,ascent:s,w:r+o,h:s+i}}function Ex(e,t,n,r){const o=t*kx;let s=o;e.font=`600 ${s}px ${Ud}`;let i=Bd(e,n);const a=Math.max(i.w,i.h);a>0&&(s=s*o/a,e.font=`600 ${s}px ${Ud}`,i=Bd(e,n)),e.fillStyle=r,e.textAlign="left",e.textBaseline="alphabetic",e.fillText(n,(t-i.w)/2+i.left,(t-i.h)/2+i.ascent)}function Nx(e,t,n){const r=n.naturalWidth||n.width||t,o=n.naturalHeight||n.height||t,s=Math.max(t/r,t/o),i=r*s,a=o*s;e.save(),Qp(e,t),e.clip(),e.drawImage(n,(t-i)/2,(t-a)/2,i,a),e.restore()}function Cx(e,t){const{content:n,size:r}=t;"glyph"in n?Ex(e,r,n.glyph,t.foreground??"white"):"image"in n?Nx(e,r,n.image):e.drawImage(n.icon,0,0,r,r)}const Px=.22,Tx=.07;function bx(e,t,n){const r=t*Px,o=t-r;e.save(),e.globalCompositeOperation="destination-out",e.beginPath(),e.arc(o,o,r+t*Tx,0,Math.PI*2),e.fill(),e.restore(),e.beginPath(),e.arc(o,o,r,0,Math.PI*2),e.fillStyle=n,e.fill()}function Tl(e){try{const n=(e.doc??document).createElement("canvas");n.width=e.size,n.height=e.size;const r=n.getContext("2d");if(!r)return null;"icon"in e.content||jx(r,e.size,e.color),Cx(r,e),e.dot&&bx(r,e.size,e.dot);const o=n.toDataURL("image/png");return o.startsWith("data:image/png")?o:null}catch{return null}}const Dr="data-paddock-default-href",bl="data-paddock-default-type",vi="data-paddock-favicon";function Gp(e){return Array.from(e.head.querySelectorAll('link[rel~="icon"]'))}function Rx(e,t=document){let n=Gp(t);if(n.length===0){const r=t.createElement("link");r.rel="icon",r.setAttribute(vi,""),t.head.appendChild(r),n=[r]}for(const r of n){!r.hasAttribute(Dr)&&!r.hasAttribute(vi)&&(r.setAttribute(Dr,r.getAttribute("href")??""),r.setAttribute(bl,r.getAttribute("type")??""));const o=r.getAttribute("sizes")==="16x16"?e.small:e.large;r.getAttribute("href")!==o&&r.setAttribute("href",o),e.type?r.setAttribute("type",e.type):r.removeAttribute("type")}}function Wd(e=document){for(const t of Gp(e)){if(t.hasAttribute(vi)){t.remove();continue}if(!t.hasAttribute(Dr))continue;t.setAttribute("href",t.getAttribute(Dr)??"");const n=t.getAttribute(bl);n?t.setAttribute("type",n):t.removeAttribute("type"),t.removeAttribute(Dr),t.removeAttribute(bl)}}function Lx(e=document){const t=e.head.querySelector('link[rel~="icon"][sizes="32x32"]')??e.head.querySelector('link[rel~="icon"][type="image/png"]');return!t||t.hasAttribute(vi)?null:t.getAttribute(Dr)??t.getAttribute("href")}function Rl(e,t){return new Promise((n,r)=>{const o=new Image;t&&(o.crossOrigin="anonymous"),o.onload=()=>n(o),o.onerror=()=>r(new Error(`favicon: could not load ${e}`)),o.src=e})}function Hd(e,t,n){const r=Uu(t,3),o=Tl({content:e,color:t,foreground:r,dot:n,size:Pl.large}),s=o&&Tl({content:e,color:t,foreground:r,dot:n,size:Pl.small});return o&&s?{large:o,small:s,type:"image/png"}:null}function Mx(e){return(Array.from(e.trim())[0]??"P").toUpperCase()}function _x(e,t){if(yx(e))return t({kind:"shipped"}),()=>{};const n=xx(e),r=e.logo.trim(),o={glyph:Mx(e.name)};if(!Vp(r))return t({kind:"chip",content:{glyph:r},color:n}),()=>{};let s=!1;const i=u=>{s||t(u)},a=()=>Rl(r,!1).then(()=>i({kind:"raw",src:r}),()=>i({kind:"chip",content:o,color:n}));return Rl(r,!0).then(u=>{s||(Tl({content:{image:u},color:n,size:Pl.small})?i({kind:"chip",content:{image:u},color:n}):a())},a),()=>{s=!0}}function Ix(e,t,n){const r=t?ux[t]:void 0;switch(e.kind){case"shipped":return r?n().then(o=>o?Hd({icon:o},"transparent",r):null):null;case"chip":return Hd(e.content,e.color,r);case"raw":return{small:e.src,large:e.src}}}function Dx(e,t=null){const{name:n,logo:r,accent:o}=e,[s,i]=x.useState(null),a=x.useRef(new WeakMap),u=x.useRef(null);x.useEffect(()=>_x({name:n,logo:r,accent:o},i),[n,r,o]),x.useEffect(()=>{if(!s)return;const c=t??"none";let d=a.current.get(s);d||a.current.set(s,d=new Map);const f=g=>{g?Rx(g):Wd()};if(d.has(c)){f(d.get(c)??null);return}const S=Ix(s,t,()=>{if(!u.current){const g=Lx(),C=g?Rl(g,!1).catch(()=>(u.current===C&&(u.current=null),null)):Promise.resolve(null);u.current=C}return u.current});if(!(S instanceof Promise)){d.set(c,S),f(S);return}let k=!1;return S.then(g=>{g&&d.set(c,g),k||f(g)}),()=>{k=!0}},[s,t]),x.useEffect(()=>()=>Wd(),[])}const Yp={running:!1,unread:0,kind:"none"};function Ox(e,{active:t,finished:n,hiddenSince:r}){if(!e)return Yp;if(e.kind==="chat"){const a=t.has(e.sessionId);return{kind:"chat",running:a,unread:!a&&e.unread?1:0}}const o=a=>e.kind==="instance"||a===e.key;let s=!1;for(const a of t.values())o(a)&&(s=!0);let i=0;if(r!==null)for(const a of n)a.at>r&&o(a.projectSlug)&&(i+=1);return{kind:e.kind,running:s,unread:i}}function $x(e){let t=e.running?"● ":"";return e.unread>0&&(t+=e.kind==="chat"?"✓ ":`(${e.unread}) `),t}function Ax(e){return e.running?"running":e.unread>0?"unread":null}function Ws(e){return e?e.kind==="chat"?`chat:${e.sessionId}:${e.unread?1:0}`:e.kind==="workspace"?`ws:${e.key}`:"instance":"none"}const Jp=x.createContext({status:Yp,scopeKey:"none",setScope:()=>{}});function yS(e){const{status:t,scopeKey:n,setScope:r}=x.useContext(Jp),o=Ws(e),s=x.useMemo(()=>e,[o]);return x.useEffect(()=>{r(s)},[s,r]),x.useEffect(()=>()=>r(null),[r]),n===o?$x(t):""}function zx(){const[e,t]=x.useState(()=>typeof document<"u"&&document.visibilityState==="hidden"?Date.now():null);return x.useEffect(()=>{const n=()=>t(r=>document.visibilityState==="hidden"?r??Date.now():null);return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Fx(e){const[t,n]=x.useState(null),r=x.useCallback(u=>{n(c=>Ws(c)===Ws(u)?c:u)},[]),o=zx(),s=Ox(t,{...e,hiddenSince:o}),i=Ws(t),a=`${i}|${s.kind}|${s.running?1:0}|${s.unread}`;return x.useMemo(()=>({status:s,scopeKey:i,setScope:r}),[a,r])}const Bu=[{slug:"homelab",label:"Homelab",blurb:"Servers, networking, self-hosted services."},{slug:"house",label:"House",blurb:"Physical home systems — water, climate, power, garden."},{slug:"side-projects",label:"Side Projects",blurb:"Apps and ideas of your own."}],Vd="",Xp=new Map(Bu.map(e=>[e.slug,e]));function Ux(e){if(!e)return"Unsorted";const t=Xp.get(e);return t?t.label:e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function xS(e){var t;return(t=Xp.get(e))==null?void 0:t.blurb}function Bx(e){const t=new Set(e),n=[];for(const o of Bu)t.has(o.slug)&&(n.push(o.slug),t.delete(o.slug));const r=t.delete(Vd);return n.push(...[...t].sort()),r&&n.push(Vd),n}const Zp=25e3,qp=1e4,Wx=Zp+qp+5e3,Hx=500,Vx=1e4;class Kx{constructor(){this.ws=null,this.outbox=[],this.subs=new Map,this.pingTimer=null,this.pongTimer=null,this.awaitingPong=!1,this.lastPongAt=0,this.reconnectTimer=null,this.reconnectAttempts=0,this.manualClose=!1,this.stateListeners=new Set,this._state="closed",this.activeSessions=new Map,this.activeStartedAt=new Map,this.backgroundTasks=new Map,this.backgroundListeners=new Set,this.stopTaskListeners=new Set,this.activeListeners=new Set,this.activeInfoListeners=new Set,this.knownSessions=new Set;const n=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`;if(this.url=`${n.replace(/^http/,"ws")}/ws`,typeof window<"u"){const r=()=>this.ensureLive();window.addEventListener("online",r),window.addEventListener("focus",r),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&this.ensureLive()})}}get state(){return this._state}onState(t){return this.stateListeners.add(t),t(this._state),()=>this.stateListeners.delete(t)}setState(t){if(this._state!==t){this._state=t;for(const n of this.stateListeners)n(t)}}onActiveSessions(t){return this.activeListeners.add(t),t(new Set(this.activeSessions.keys())),this.connect(),()=>this.activeListeners.delete(t)}onActiveInfos(t){return this.activeInfoListeners.add(t),t(new Map(this.activeSessions)),this.connect(),()=>this.activeInfoListeners.delete(t)}turnStartedAt(t){return this.activeStartedAt.get(t)??null}backgroundWork(t){return this.backgroundTasks.get(t)??[]}onBackgroundWork(t,n){const r=(o,s)=>{o===t&&n(s)};return this.backgroundListeners.add(r),n(this.backgroundWork(t)),this.connect(),()=>this.backgroundListeners.delete(r)}setActive(t,n,r,o){const s=this.activeSessions.has(t);if(n?(this.activeSessions.set(t,r),o!=null&&!this.activeStartedAt.has(t)&&this.activeStartedAt.set(t,o)):(this.activeSessions.delete(t),this.activeStartedAt.delete(t)),this.activeSessions.has(t)!==s){const i=new Set(this.activeSessions.keys());for(const u of this.activeListeners)u(i);const a=new Map(this.activeSessions);for(const u of this.activeInfoListeners)u(a)}}subscribe(t,n,r){const o=Symbol("chat-sub"),s={projectSlug:t,sessionId:n,handlers:r,lastSeq:-1,turnActive:!1};return this.subs.set(o,s),this.connect(),n&&this.attachSession(s,!1),{setSessionId:i=>{const a=this.subs.get(o);a&&(a.sessionId=i,i&&this.attachSession(a,!1))},unsubscribe:()=>{this.subs.delete(o)}}}attachSession(t,n){t.sessionId&&(this.knownSessions.add(t.sessionId),this.transmit(JSON.stringify({type:"chat:subscribe",payload:{projectSlug:t.projectSlug,sessionId:t.sessionId,wantReplay:n,lastSeq:t.lastSeq}})))}send(t,n,r,o){const s={projectSlug:t,sessionId:r,message:n};o!=null&&o.preloadContext&&(s.preloadContext=!0),o!=null&&o.model&&(s.model=o.model),o!=null&&o.attachments&&o.attachments.length>0&&(s.attachments=o.attachments),this.markTurnStart(t,r),this.transmit(JSON.stringify({type:"chat:send",payload:s}))}setQueued(t,n,r,o,s){const i={projectSlug:t,sessionId:n,text:r,qid:o};s&&s.length>0&&(i.attachments=s.map(a=>({id:a.id,filename:a.filename,kind:a.kind}))),this.transmit(JSON.stringify({type:"chat:set_queue",payload:i}))}markTurnStart(t,n){for(const r of this.subs.values())r.projectSlug===t&&r.sessionId===n&&(r.lastSeq=-1,r.turnActive=!0)}sendCommand(t,n,r){this.markTurnStart(t,r),this.transmit(JSON.stringify({type:"chat:command",payload:{projectSlug:t,sessionId:r,command:n}}))}cancel(t){this.transmit(JSON.stringify({type:"chat:cancel",payload:{jobId:t}}))}stopTask(t,n){this.transmit(JSON.stringify({type:"chat:stop_task",payload:{sessionId:t,taskId:n}}))}onStopTaskResult(t,n){const r=(o,s)=>{o===t&&n(s)};return this.stopTaskListeners.add(r),()=>this.stopTaskListeners.delete(r)}continueChat(t,n){this.markTurnStart(t,n),this.transmit(JSON.stringify({type:"chat:continue",payload:{projectSlug:t,sessionId:n}}))}transmit(t){this.isLive()?this.ws.send(t):(this.outbox.push(t),this.ensureLive())}isLive(){var t;return((t=this.ws)==null?void 0:t.readyState)!==WebSocket.OPEN?!1:Date.now()-this.lastPongAt<Wx}wantsSocket(){return this.subs.size>0||this.activeListeners.size>0||this.activeInfoListeners.size>0}ensureLive(){var n;if(!this.wantsSocket())return;const t=(n=this.ws)==null?void 0:n.readyState;t===WebSocket.OPEN?this.sendPing():t!==WebSocket.CONNECTING&&(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectAttempts=0,this.connect())}flushOutbox(){var n;if(((n=this.ws)==null?void 0:n.readyState)!==WebSocket.OPEN||this.outbox.length===0)return;const t=this.outbox;this.outbox=[];for(const r of t)this.ws.send(r)}connect(){if(this.manualClose=!1,this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))return;this.setState("connecting");let t;try{t=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.ws=t,t.onopen=()=>{this.reconnectAttempts=0,this.awaitingPong=!1,this.lastPongAt=Date.now(),this.setState("open"),this.flushOutbox();for(const n of this.subs.values())n.sessionId&&this.attachSession(n,n.turnActive);this.startPing()},t.onclose=()=>{this.stopPing(),this.setState("closed"),this.manualClose||this.scheduleReconnect()},t.onerror=()=>{t.close()},t.onmessage=n=>this.dispatch(n.data)}startPing(){this.stopPing(),this.pingTimer=setInterval(()=>this.sendPing(),Zp)}sendPing(){var t;if(!(((t=this.ws)==null?void 0:t.readyState)!==WebSocket.OPEN||this.awaitingPong)){this.awaitingPong=!0;try{this.ws.send(JSON.stringify({type:"ping"}))}catch{this.awaitingPong=!1,this.ws.close();return}this.pongTimer=setTimeout(()=>{var n;this.pongTimer=null,this.awaitingPong&&((n=this.ws)==null||n.close())},qp)}}stopPing(){this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.pongTimer&&clearTimeout(this.pongTimer),this.pongTimer=null,this.awaitingPong=!1}scheduleReconnect(){if(this.reconnectTimer)return;const t=Math.min(Vx,Hx*2**this.reconnectAttempts);this.reconnectAttempts+=1,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},t)}route(t,n){const r=[...this.subs.values()].filter(s=>s.projectSlug===t);if(r.length===0)return;if(n){const s=r.find(i=>i.sessionId===n);if(s)return s;if(this.knownSessions.has(n))return}const o=r.find(s=>s.sessionId===null);if(o)return o;if(n===null&&r.length===1)return r[0]}dispatch(t){var c,d,f,p,S,k,g,C,m,h,v,E,T,R,M,y,D,b,B,ee,ce,fe,st,Ze,St,I,z,Q;let n;try{n=JSON.parse(t)}catch{return}if(n.type==="pong"){this.awaitingPong=!1,this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null),this.lastPongAt=Date.now(),this.flushOutbox();return}if(n.type==="chat:stop_task_result"){const{sessionId:O,taskId:Y,outcome:se,message:X}=n.payload;if(O&&Y&&se)for(const Ee of this.stopTaskListeners)Ee(O,{taskId:Y,outcome:se,message:X});return}const r=n.payload.projectSlug;if(r==null)return;if(n.type==="chat:error"){const O=this.route(r,null);(d=O==null?void 0:(c=O.handlers).onError)==null||d.call(c,n.payload.error);return}if(n.type==="chat:resync"){const O=this.route(r,n.payload.sessionId);(p=O==null?void 0:(f=O.handlers).onResync)==null||p.call(f);return}if(n.type==="chat:background"){const{sessionId:O,tasks:Y}=n.payload;if(O){const se=Array.isArray(Y)?Y:[];se.length===0?this.backgroundTasks.delete(O):this.backgroundTasks.set(O,se);for(const X of this.backgroundListeners)X(O,se)}return}if(n.type==="chat:active"){this.setActive(n.payload.sessionId,n.payload.running,r,n.payload.startedAt);for(const O of this.subs.values())O.projectSlug===r&&O.sessionId===n.payload.sessionId&&((k=(S=O.handlers).onActive)==null||k.call(S,{running:n.payload.running,turnRunning:n.payload.turnRunning??n.payload.running,jobId:n.payload.jobId}));return}if(n.type==="chat:queued_flushed"){const{sessionId:O,text:Y,attachments:se}=n.payload;if(O){Zt(async()=>{const{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{X(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((C=(g=X.handlers).onQueuedFlushed)==null||C.call(g,{text:Y,attachments:se}))}return}if(n.type==="chat:queued_state"){const{sessionId:O,text:Y,qid:se,reason:X,attachments:Ee}=n.payload;if(O){const ie=Y&&Y.length>0?Y:null,ze=Ee??[],Ft=ie!==null||ze.length>0;Zt(async()=>{const{writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr}=await import("./queued-CagZVfWU.js");return{writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr}},[]).then(({writeQueued:Ut,writeQueuedId:dn,writeQueuedAttachments:Zr})=>{Ut(O,r,ie),dn(O,r,Ft?se??null:null),Zr(O,r,ze)});for(const Ut of this.subs.values())Ut.projectSlug===r&&Ut.sessionId===O&&((h=(m=Ut.handlers).onQueuedState)==null||h.call(m,{text:ie,attachments:ze,qid:se,reason:X}))}return}if(n.type==="chat:queued_returned"){const{sessionId:O,text:Y,attachments:se}=n.payload;if(O&&typeof Y=="string"){Zt(async()=>{const{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:X,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{X(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((E=(v=X.handlers).onQueuedReturned)==null||E.call(v,{text:Y,attachments:se}))}return}if(n.type==="chat:killed_task"){const{sessionId:O,summary:Y,timestamp:se}=n.payload;if(O)for(const X of this.subs.values())X.projectSlug===r&&X.sessionId===O&&((R=(T=X.handlers).onKilledTask)==null||R.call(T,{summary:Y??"",timestamp:se??""}));return}const{sessionId:o,jobId:s}=n.payload,i=this.route(r,o);if(!i)return;const a={sessionId:o,jobId:s},u=n.payload.seq;switch(typeof u=="number"&&u>i.lastSeq&&(i.lastSeq=u),i.turnActive=n.type!=="chat:complete",n.type){case"chat:response":(y=(M=i.handlers).onResponse)==null||y.call(M,n.payload.chunk,a);break;case"chat:tool_call":(b=(D=i.handlers).onToolCall)==null||b.call(D,{toolName:n.payload.toolName,inputSummary:n.payload.inputSummary,output:n.payload.output,isError:n.payload.isError,durationMs:n.payload.durationMs,toolUseId:n.payload.toolUseId,subagentType:n.payload.subagentType,description:n.payload.description,hasSubagent:n.payload.hasSubagent},a);break;case"chat:tool_start":(ee=(B=i.handlers).onToolStart)==null||ee.call(B,{toolName:n.payload.toolName,inputSummary:n.payload.inputSummary,toolUseId:n.payload.toolUseId,output:"",isError:!1,pending:!0,subagentType:n.payload.subagentType,description:n.payload.description,hasSubagent:n.payload.hasSubagent},a);break;case"chat:message_boundary":(fe=(ce=i.handlers).onMessageBoundary)==null||fe.call(ce,a);break;case"chat:injected":(Ze=(st=i.handlers).onInjected)==null||Ze.call(st,{sender:n.payload.sender,content:n.payload.content,timestamp:n.payload.timestamp},a);break;case"chat:notice":(I=(St=i.handlers).onNotice)==null||I.call(St,n.payload.notice,a);break;case"chat:complete":(Q=(z=i.handlers).onComplete)==null||Q.call(z,{...a,success:n.payload.success,error:n.payload.error,model:n.payload.model,usage:n.payload.usage});break}}}const Wu=new Kx,nn=new Map,Ll="paddock:lastSeen-changed";function Hu(e){try{window.dispatchEvent(new CustomEvent(Ll,{detail:{sessionId:e}}))}catch{}}function Qx(e){return nn.get(e)??0}function Gx(e,t){!t||!Number.isFinite(t)||t<=(nn.get(e)??0)||(nn.set(e,t),Hu(e))}function wS(e,t=Date.now()){const n=nn.get(e)??0;return t<=n||(nn.set(e,t),Hu(e)),n}function SS(e,t,n){nn.get(e)===n&&(t?nn.set(e,t):nn.delete(e),Hu(e))}const Ml="paddock:chats-gone";function kS(e){if(e.length!==0){for(const t of e)nn.delete(t);try{window.dispatchEvent(new CustomEvent(Ml,{detail:{sessionIds:e}}))}catch{}}}function Yx({tag:e,className:t=""}){const n=es();return l.jsx("button",{type:"button",onClick:r=>{r.preventDefault(),r.stopPropagation(),n(`/tags/${encodeURIComponent(e)}`)},title:`Show projects tagged ${e}`,className:`tag relative z-10 transition-colors hover:bg-surface-selected ${t}`,children:e})}const Jx=/^\d{4}-\d{2}-\d{2}$/;function yi(e){if(!e)return"";if(Jx.test(e)){const[u,c,d]=e.split("-").map(Number),f=new Date(u,c-1,d);if(Number.isNaN(f.getTime()))return e;const p=new Date,S=new Date(p.getFullYear(),p.getMonth(),p.getDate()),k=Math.round((S.getTime()-f.getTime())/864e5);return k<=0?"today":k===1?"yesterday":k<7?`${k}d ago`:k<35?`${Math.round(k/7)}w ago`:k<365?`${Math.round(k/30)}mo ago`:`${Math.round(k/365)}y ago`}const t=new Date(e).getTime();if(Number.isNaN(t))return e;const n=Math.round((Date.now()-t)/1e3);if(n<45)return"just now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const o=Math.round(r/60);if(o<24)return`${o}h ago`;const s=Math.round(o/24);if(s<7)return`${s}d ago`;const i=Math.round(s/7);if(i<5)return`${i}w ago`;const a=Math.round(s/30);return a<12?`${a}mo ago`:`${Math.round(s/365)}y ago`}function jS(e){if(!e)return"";const t=new Date(e).getTime();if(Number.isNaN(t))return e;const n=Math.round((t-Date.now())/1e3);if(n<=30)return"now";const r=Math.round(n/60);if(r<60)return`in ${r}m`;const o=Math.round(r/60);if(o<24)return`in ${o}h`;const s=Math.round(o/24);if(s<7)return`in ${s}d`;const i=Math.round(s/7);if(i<5)return`in ${i}w`;const a=Math.round(s/30);return a<12?`in ${a}mo`:`in ${Math.round(s/365)}y`}function Ea(e){return!Number.isFinite(e)||e<0?"0":e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:2)}M`:e>=1e3?`${Math.round(e/1e3)}K`:`${Math.round(e)}`}function Xx(e){return!Number.isFinite(e)||e<=0?"$0.00":e<.01?"<$0.01":`$${e.toFixed(2)}`}function ES(e){if(!(!e||e.totalTokens==null))return{inputTokens:e.inputTokens??0,outputTokens:e.outputTokens??0,cacheReadTokens:e.cacheReadTokens??0,cacheCreationTokens:e.cacheCreationTokens??0,totalTokens:e.totalTokens,costUsd:e.costUsd??null}}function NS(e){const t=e.inputTokens+e.cacheReadTokens+e.cacheCreationTokens,n=`${Ea(e.totalTokens)} tokens · ${Ea(t)} in / ${Ea(e.outputTokens)} out`;return e.costUsd==null?n:`${n} · ~${Xx(e.costUsd)} at API rates`}function CS(e){if(e==null||Number.isNaN(e))return null;if(e<1e3)return`${Math.round(e)}ms`;const t=e/1e3;if(t<10)return`${t.toFixed(1)}s`;if(t<60)return`${Math.round(t)}s`;const n=Math.floor(t/60),r=Math.round(t%60);return r?`${n}m ${r}s`:`${n}m`}const Zx="This session is being continued from a previous conversation";function PS(e){return e.trimStart().startsWith(Zx)}function TS(e){const t=/^\s*<command-name>([^<]*)<\/command-name>/.exec(e);if(!t)return null;const n=t[1].trim();return n.length>0?n:null}function bS(e){return e.trimStart().startsWith("<local-command-caveat>")}function RS(e){const t=/^\s*<local-command-stdout>([\s\S]*)<\/local-command-stdout>\s*$/.exec(e);if(!t)return null;const n=t[1].trim();return n.length>0?n:null}function LS(e){return/^\s*<local-command-stdout>[\s\S]*<\/local-command-stdout>\s*$/.test(e)}function MS(e){return e.trimStart().startsWith("<task-notification>")}function _S(e){var r;const t=/<summary>([\s\S]*?)<\/summary>/.exec(e),n=(r=t==null?void 0:t[1])==null?void 0:r.trim();return n&&n.length>0?n:"Background agent updated"}function IS(e){var r;const t=/<status>([\s\S]*?)<\/status>/.exec(e),n=(r=t==null?void 0:t[1])==null?void 0:r.trim().toLowerCase();return n&&n.length>0?n:null}function DS(e){return e==="killed"||e==="stopped"}function qx(e){const t=Math.max(0,Math.floor(e/1e3)),n=t%60,r=Math.floor(t/60)%60,o=Math.floor(t/3600),s=String(n).padStart(2,"0");return o>0?`${o}:${String(r).padStart(2,"0")}:${s}`:`${r}:${s}`}const _l="paddock:transcriptsMigration:dismissed";function e1(){try{return localStorage.getItem(_l)==="1"}catch{return!1}}function Kd(e){try{e?localStorage.setItem(_l,"1"):localStorage.removeItem(_l)}catch{}}let xo=null;function t1(){if(!xo)try{xo=ar.transcriptsMigration().catch(()=>null)}catch{xo=Promise.resolve(null)}return xo}function n1(){xo=null}function em(){const[e,t]=x.useState(null),[n,r]=x.useState(e1);x.useEffect(()=>{let s=!0;return t1().then(i=>{!s||!i||(t(i),i&&!i.eligible&&(Kd(!1),r(!1)))}),()=>{s=!1}},[]);const o=x.useCallback(()=>{Kd(!0),r(!0)},[]);return{probe:e,showBanner:(e==null?void 0:e.eligible)===!0&&!n,showInConfig:e!=null&&e.mode==="own"&&(e.eligible||e.reason==="profile-paranoid"),dismiss:o}}function Bi(e){return((e==null?void 0:e.projects)??[]).flatMap(t=>t.chats)}function r1(e){return new Set(Bi(e).filter(t=>t.defaultSelected).map(t=>t.sessionId))}function o1(e,t){const n=e.chats.length,r=e.chats.reduce((o,s)=>o+(t.has(s.sessionId)?1:0),0);return{selected:r,total:n,all:n>0&&r===n,some:r>0&&r<n}}function s1(e,t,n){const r=new Set(e);for(const o of t.chats)n?r.add(o.sessionId):r.delete(o.sessionId);return r}function i1(e,t){return t?new Set(Bi(e).map(n=>n.sessionId)):new Set}function a1(e,t){const n=new Set(e);return n.delete(t)||n.add(t),n}function l1(e,t){const n=Bi(e).map(r=>r.sessionId);return{sessionIds:n.filter(r=>t.has(r)),plannedSessionIds:n,expectedVersion:e.configVersion}}function u1(e){const t=(e==null?void 0:e.totals.identical)??0,n=((e==null?void 0:e.projects)??[]).reduce((o,s)=>o+s.projectExtras.length,0),r=(e==null?void 0:e.sweepers.chats)??0;return{identical:t,projectExtras:n,sweeperChats:r,total:t+n+r}}function tm(e){return e?e.projects.length===0&&e.sweepers.stores===0:!1}function nm(e){return!e.ok||e.failed.length>0?"partial":e.alreadyMigrated?"already":e.migrated.length===0&&e.preserved.length===0?"nothing":"done"}function c1(e){const t=new Map;for(const n of e){const r=t.get(n.slug);r?r.push(n):t.set(n.slug,[n])}return[...t.entries()].map(([n,r])=>({slug:n,items:r}))}const d1={new:{label:"New",hint:"Not in ~/.claude yet. Moving it in loses nothing."},"fast-forward":{label:"Fast-forward",hint:"One copy is just a longer version of the other. Lossless either way."},diverged:{label:"Diverged",hint:"Both copies have messages the other does not. Ticking keeps Paddock's copy in ~/.claude; the other is kept too, in the preserve folder."},unknown:{label:"Not compared",hint:"Paddock ran out of scan budget before it could compare these two copies, so it has not assumed they are safe to merge."}};function xi(e){return d1[e]??{label:String(e),hint:"This Paddock build does not recognise this state, so it is shown as the server described it."}}function Qd(e){const t=e.indexOf("/.claude/");return t===-1?e:`~${e.slice(t)}`}function f1(e,t){return t==="all"?!0:t==="needs-decision"?!e.defaultSelected:e.state===t}function Ye(...e){return e.filter(Boolean).join(" ")}const h1={primary:"bg-accent-solid text-accent-fg shadow-xs hover:bg-accent-solid-hover active:scale-[0.98]",ghost:"bg-surface-active text-fg hover:bg-surface-selected",subtle:"text-fg-muted hover:bg-surface-hover hover:text-fg",danger:"bg-danger-solid text-danger-fg shadow-xs hover:brightness-110 active:scale-[0.98]",link:"text-accent underline underline-offset-2 hover:no-underline"},p1={sm:"gap-1.5 px-2 py-1 text-xs rounded-md",md:"gap-2 px-3.5 py-2 text-sm rounded-lg","icon-sm":"h-6 w-6 justify-center rounded-md","icon-md":"h-9 w-9 justify-center rounded-lg"};function jt({variant:e="ghost",size:t="md",icon:n,loading:r=!1,loadingLabel:o,align:s="center",className:i,children:a,disabled:u,type:c="button",...d}){return l.jsxs("button",{type:c,disabled:u||r,"aria-busy":r||void 0,className:Ye("inline-flex select-none items-center font-medium","motion-fast transition-[color,background-color,border-color,box-shadow,transform]","disabled:cursor-not-allowed disabled:opacity-50",s==="start"?"justify-start text-left":"justify-center",p1[t],h1[e],i),...d,children:[n,r&&o?o:a]})}const Vu=["w-full rounded-lg border border-edge-strong bg-surface-sunken px-3 py-2 text-sm text-fg","outline-none motion-fast transition-[border-color,box-shadow]","focus:border-accent focus:ring-2 focus:ring-accent/25","disabled:cursor-not-allowed disabled:opacity-60","aria-[invalid=true]:border-danger aria-[invalid=true]:focus:ring-danger/25"].join(" ");function OS({className:e,...t}){return l.jsx("input",{className:Ye(Vu,e),...t})}function $S({className:e,...t}){return l.jsx("textarea",{className:Ye(Vu,"resize-y",e),...t})}function AS({className:e,...t}){return l.jsx("select",{className:Ye(Vu,e),...t})}function zS({checked:e,onChange:t,label:n,disabled:r,id:o,className:s}){const i=x.useId(),a=o??i;return l.jsxs("label",{htmlFor:a,className:Ye("relative inline-block shrink-0 cursor-pointer",s),children:[l.jsx("input",{id:a,type:"checkbox","aria-label":n,className:"peer sr-only",checked:e,disabled:r,onChange:u=>t(u.target.checked)}),l.jsx("span",{className:Ye("block h-[18px] w-8 rounded-full bg-edge-strong","motion-fast transition-colors","after:absolute after:left-0.5 after:top-0.5 after:h-3.5 after:w-3.5 after:rounded-full","after:bg-surface-raised after:shadow-2xs after:transition-transform after:content-['']","peer-checked:bg-accent-solid peer-checked:after:translate-x-3.5","peer-focus-visible:ring-2 peer-focus-visible:ring-accent/50","peer-disabled:opacity-50")})]})}function rm({label:e,description:t,indeterminate:n=!1,className:r,...o}){const s=x.useRef(null);x.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const i=l.jsx("input",{ref:s,type:"checkbox",...n?{"aria-checked":"mixed"}:{},className:Ye("h-4 w-4 shrink-0 cursor-pointer rounded border-edge-strong accent-[var(--accent-solid)]","disabled:cursor-not-allowed disabled:opacity-50",e?"mt-0.5":"",r),...o});return e?l.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-sm text-fg",children:[i,l.jsxs("span",{className:"min-w-0",children:[e,t&&l.jsx("span",{className:"block text-xs leading-snug text-fg-muted",children:t})]})]}):i}const om={neutral:"bg-surface-active text-fg-muted",accent:"bg-accent-soft text-accent",success:"bg-success-soft text-success",warn:"bg-warn-soft text-warn",danger:"bg-danger-soft text-danger",info:"bg-info-soft text-info",lineage:"bg-lineage-soft text-lineage"},sm={neutral:"bg-fg-subtle",accent:"bg-accent-solid",success:"bg-success-solid",warn:"bg-warn-solid",danger:"bg-danger-solid",info:"bg-info-solid",lineage:"bg-lineage-solid"};function m1({tone:e="neutral",shape:t="tag",size:n="md",dot:r=!1,icon:o,title:s,className:i,children:a}){return l.jsxs("span",{title:s,className:Ye("inline-flex items-center gap-1 font-medium leading-none",t==="pill"?"rounded-full px-2 py-0.5":"rounded-md px-1.5 py-0.5",n==="sm"?"text-3xs":"text-2xs",om[e],i),children:[r&&l.jsx("span",{className:Ye("h-1.5 w-1.5 shrink-0 rounded-full",sm[e])}),o,a]})}function FS({tone:e="neutral",pulse:t=!1,className:n}){return l.jsx("span",{className:Ye("inline-block h-2 w-2 shrink-0 rounded-full",sm[e],t&&"animate-pulse",n)})}function Xt({tone:e="info",icon:t,className:n,children:r}){const o={neutral:"border-edge",accent:"border-accent-edge",success:"border-success-edge",warn:"border-warn-edge",danger:"border-danger-edge",info:"border-info-edge",lineage:"border-lineage-edge"};return l.jsxs("div",{role:e==="danger"?"alert":void 0,className:Ye("flex items-start gap-2 rounded-lg border px-3 py-2 text-sm",om[e],o[e],n),children:[t&&l.jsx("span",{className:"mt-0.5 shrink-0",children:t}),l.jsx("div",{className:"min-w-0",children:r})]})}function g1(e,t){x.useEffect(()=>{if(!e)return;const n=r=>{r.key==="Escape"&&t()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,t])}const v1={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl"};function y1({open:e,onClose:t,title:n,hideTitle:r=!1,description:o,footer:s,size:i="md",role:a="dialog",dismissOnBackdrop:u=!0,onSubmit:c,className:d,children:f}){const p=x.useRef(null),S=x.useRef(null);if(g1(e,t),x.useEffect(()=>{var C,m;return e?(S.current=document.activeElement,(m=((C=p.current)==null?void 0:C.querySelector("[autofocus], input:not([type=hidden]), textarea, select, button, [href], [tabindex]:not([tabindex='-1'])"))??p.current)==null||m.focus(),()=>{const h=S.current;h instanceof HTMLElement&&h.focus()}):void 0},[e]),x.useEffect(()=>{if(!e)return;const g=C=>{if(C.key!=="Tab"||!p.current)return;const m=[...p.current.querySelectorAll("input:not([type=hidden]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [href], [tabindex]:not([tabindex='-1'])")];if(m.length===0)return;const h=m[0],v=m[m.length-1],E=document.activeElement;C.shiftKey&&(E===h||!p.current.contains(E))?(C.preventDefault(),v.focus()):!C.shiftKey&&E===v&&(C.preventDefault(),h.focus())};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[e]),!e)return null;const k=c?"form":"div";return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>u&&t(),children:l.jsxs(k,{ref:p,role:a,"aria-modal":"true","aria-label":n,tabIndex:-1,onClick:g=>g.stopPropagation(),onSubmit:c,className:Ye("flex max-h-[85vh] w-full flex-col animate-scale-in rounded-2xl border border-edge","bg-surface-raised p-6 shadow-2xl outline-none",v1[i],d),children:[!r&&l.jsx("h2",{className:"text-base font-semibold text-fg",children:n}),o&&l.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:o}),l.jsx("div",{className:"-mx-1 min-h-0 flex-1 overflow-y-auto px-1 py-1",children:f}),s&&l.jsx("div",{className:"mt-4 flex items-center justify-end gap-2",children:s})]})})}function im({content:e,children:t,delayMs:n=250,className:r=""}){const o=x.useId(),s=x.useRef(null),i=x.useRef(null),a=x.useRef(null),[u,c]=x.useState(null),d=()=>{a.current&&clearTimeout(a.current),a.current=null},f=x.useCallback(()=>{d(),c(null)},[]),p=x.useCallback(()=>{var m;const g=(m=s.current)==null?void 0:m.getBoundingClientRect();if(!g)return;const C=g.top<56;c({x:g.left+g.width/2,y:C?g.bottom+6:g.top-6,below:C})},[]);x.useEffect(()=>d,[]),x.useEffect(()=>{if(!u)return;const g=C=>{C.key==="Escape"&&f()};return window.addEventListener("keydown",g),window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("keydown",g),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[u,f]),x.useLayoutEffect(()=>{if(!u||!i.current)return;const g=i.current.offsetWidth;if(!g)return;const C=8+g/2,m=window.innerWidth-8-g/2,h=Math.min(Math.max(u.x,C),Math.max(C,m));h!==u.x&&c({...u,x:h})},[u]);const S=x.Children.only(t),k=x.isValidElement(S)?x.cloneElement(S,{"aria-describedby":u?o:void 0}):S;return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:s,className:`inline-flex ${r}`,onPointerEnter:g=>{g.pointerType!=="touch"&&(d(),a.current=setTimeout(p,n))},onPointerLeave:f,onPointerDown:f,onFocusCapture:p,onBlurCapture:f,children:k}),u&&Oi.createPortal(l.jsx("div",{ref:i,id:o,role:"tooltip",style:{position:"fixed",left:u.x,top:u.y,transform:`translate(-50%, ${u.below?"0":"-100%"})`},className:"pointer-events-none z-[70] max-w-[15rem] animate-fade-in rounded-lg bg-fg px-2 py-1 text-2xs leading-snug text-surface shadow-lg",children:e}),document.body)]})}function am({open:e,onClose:t,onCompleted:n}){const[r,o]=x.useState(null),[s,i]=x.useState(new Set),[a,u]=x.useState({kind:"loading"}),[c,d]=x.useState("all"),f=x.useRef(!1),p=x.useCallback(async()=>{u({kind:"loading"});try{const v=await ar.transcriptsMigrationChats();o(v),i(r1(v)),u({kind:"plan"})}catch(v){u({kind:"load-failed",message:dm(v)})}},[]);x.useEffect(()=>{e&&(d("all"),p())},[e,p]);const S=x.useMemo(()=>Bi(r),[r]),k=x.useMemo(()=>u1(r),[r]),g=x.useMemo(()=>S.reduce((v,E)=>v+(s.has(E.sessionId)?1:0),0),[S,s]),C=x.useMemo(()=>S.filter(O1).length,[S]),m=x.useCallback(async()=>{if(!(!r||f.current)){f.current=!0,u({kind:"running"});try{const v=await ar.runTranscriptsMigration(l1(r,s));n1(),u({kind:"result",result:v}),v.ok&&(n==null||n())}catch(v){u({kind:"refused",error:v})}finally{f.current=!1}}},[r,s,n]),h=a.kind==="running";return l.jsxs(B1,{open:e,onClose:h?()=>{}:t,dismissOnBackdrop:!h,title:A1(a),footer:l.jsx(_1,{phase:a,plan:r,rows:S,selectedCount:g,alsoMoving:k.total,onClose:t,onRetry:m,onReload:p,onSubmit:m}),children:[a.kind==="loading"&&l.jsxs("p",{className:"py-8 text-center text-sm text-fg-muted",children:["Comparing this instance's chats with your ",l.jsx(Ce,{children:"~/.claude"}),"…"]}),a.kind==="load-failed"&&l.jsxs(Xt,{tone:"danger",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"Could not read the migration plan."}),l.jsx("p",{className:"mt-1",children:a.message}),l.jsx("p",{className:"mt-1 text-xs",children:"Nothing has been moved."})]}),a.kind==="running"&&l.jsx(P1,{plan:r,count:g}),a.kind==="refused"&&l.jsx(T1,{error:a.error,plan:r,rows:S,selected:s}),a.kind==="result"&&l.jsx(R1,{result:a.result}),a.kind==="plan"&&r&&l.jsx(x1,{plan:r,rows:S,selected:s,setSelected:i,filter:c,setFilter:d,decisionCount:C,alsoMoving:k})]})}function x1({plan:e,rows:t,selected:n,setSelected:r,filter:o,setFilter:s,decisionCount:i,alsoMoving:a}){if(tm(e))return l.jsxs("div",{className:"py-6 text-sm text-fg-muted",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Nothing to move."}),l.jsxs("p",{className:"mt-1",children:["Every project's ",l.jsx(Ce,{children:".chats/"})," is already empty, so there is nothing to merge into your ",l.jsx(Ce,{children:"~/.claude"}),"."]})]});const u=t.length>0&&t.every(d=>n.has(d.sessionId)),c=t.reduce((d,f)=>d+(n.has(f.sessionId)?1:0),0);return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("p",{className:"text-base text-fg",children:[l.jsxs("strong",{className:"font-semibold",children:[c.toLocaleString()," of ",t.length.toLocaleString()," ",t.length===1?"chat":"chats"]})," ","will move into ",l.jsx(Ce,{children:"~/.claude"}),"."," ",l.jsxs("span",{className:"text-fg-muted",children:["The rest are set aside in ",l.jsx(Ce,{children:".chats-pre-migration/"}),", not deleted."]})]}),l.jsx(w1,{plan:e}),l.jsx(S1,{plan:e,filter:o,setFilter:s,decisionCount:i}),l.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-edge pb-2",children:l.jsx(rm,{checked:u,indeterminate:!u&&n.size>0,onChange:()=>r(i1(e,!u)),label:l.jsx("span",{className:"text-xs",children:"Select all"})})}),l.jsx("ul",{className:"space-y-4",children:e.projects.map(d=>l.jsx(E1,{project:d,selected:n,setSelected:r,filter:o},d.slug))}),a.total>0&&l.jsx(k1,{alsoMoving:a})]})}function w1({plan:e}){const[t,n]=x.useState(!1),r=e.warnings.length+(e.scanBudgetExhausted?1:0);return r===0?null:l.jsxs("div",{className:"rounded-lg border border-warn-edge bg-warn-soft/30",children:[l.jsxs("button",{type:"button",onClick:()=>n(!t),"aria-expanded":t,className:"focus-visible:focus-ring flex w-full items-center gap-1.5 rounded-lg px-3 py-2 text-left text-xs font-semibold text-warn-fg",children:[l.jsx(lm,{open:t}),r.toLocaleString()," ",r===1?"warning":"warnings",l.jsx("span",{className:"ml-auto font-normal text-fg-muted",children:t?"Hide":"Show"})]}),t&&l.jsxs("div",{className:"space-y-2 px-3 pb-3 pl-8 text-xs text-warn-fg",children:[e.scanBudgetExhausted&&l.jsxs("p",{children:[l.jsxs("strong",{className:"font-semibold",children:[e.totals.unknown.toLocaleString()," ",e.totals.unknown===1?"chat":"chats"," could not be compared."]})," ","Comparing two copies means reading both in full, and this instance has more of them than one pass is allowed to read. Those rows start unticked — Paddock will not assume a chat is safe to merge when it has not looked. Nothing is lost either way."]}),e.warnings.length>0&&l.jsx(um,{warnings:e.warnings})]})]})}function S1({plan:e,filter:t,setFilter:n,decisionCount:r}){const o=[{state:"new",n:e.totals.new},{state:"fast-forward",n:e.totals.fastForward},{state:"diverged",n:e.totals.diverged},{state:"unknown",n:e.totals.unknown}];return l.jsxs("div",{role:"tablist","aria-label":"Filter chats",className:"flex flex-wrap items-center gap-1",children:[l.jsx(Na,{active:t==="all",onClick:()=>n("all"),label:`All ${e.totals.chats.toLocaleString()}`}),r>0&&l.jsx(Na,{active:t==="needs-decision",onClick:()=>n("needs-decision"),label:`${r.toLocaleString()} need a decision`}),l.jsx("span",{className:"mx-1 h-4 w-px bg-edge","aria-hidden":"true"}),o.map(({state:s,n:i})=>i===0?null:l.jsx(im,{content:xi(s).hint,children:l.jsx(Na,{active:t===s,onClick:()=>n(s),label:`${i.toLocaleString()} ${xi(s).label.toLowerCase()}`,tone:cm[s]})},s))]})}function Na({active:e,onClick:t,label:n,tone:r}){return l.jsx("button",{type:"button",role:"tab","aria-selected":e,onClick:t,className:Wi("focus-visible:focus-ring rounded-full border px-2.5 py-1 text-xs transition",e?"border-accent-edge bg-accent-soft font-semibold text-fg":"border-edge text-fg-muted can-hover:hover:border-edge-strong can-hover:hover:text-fg",!e&&r==="info"&&"text-info-fg",!e&&r==="success"&&"text-success-fg",!e&&r==="warn"&&"text-warn-fg"),children:n})}function k1({alsoMoving:e}){const[t,n]=x.useState(!1),r=[];return e.identical>0&&r.push(`${e.identical.toLocaleString()} ${e.identical===1?"chat that is":"chats that are"} already identical in both places`),e.projectExtras>0&&r.push(`${e.projectExtras.toLocaleString()} project ${e.projectExtras===1?"file":"files"} such as agent memory`),e.sweeperChats>0&&r.push(`${e.sweeperChats.toLocaleString()} internal sweeper transcripts`),l.jsxs("div",{className:"border-t border-edge pt-3",children:[l.jsxs("button",{type:"button",onClick:()=>n(!t),"aria-expanded":t,className:"focus-visible:focus-ring flex w-full items-center gap-1.5 rounded text-left text-xs text-fg-muted can-hover:hover:text-fg",children:[l.jsx(lm,{open:t}),l.jsxs("span",{children:["Also moving: ",l.jsx("span",{className:"text-fg",children:j1(e)})]})]}),t&&l.jsxs("p",{className:"mt-1.5 pl-5 text-xs text-fg-muted",children:[U1(r),". These have no decision attached — Paddock's copy of an identical chat is set aside rather than deleted, and the rest have no counterpart to conflict with."," ",l.jsx(Ce,{children:".chats/"})," has to end up completely empty for the switch to take effect."]})]})}function j1(e){const t=[],n=e.identical+e.projectExtras;return n>0&&t.push(`+${n.toLocaleString()} ${n===1?"chat":"chats"}`),e.sweeperChats>0&&t.push(`+${e.sweeperChats.toLocaleString()} sweeper`),t.join(", ")}function lm({open:e}){return l.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":"true",className:Wi("h-3 w-3 shrink-0 transition-transform duration-fast",e&&"rotate-90"),children:l.jsx("path",{d:"M4 2.5 8 6l-4 3.5z",fill:"currentColor"})})}function E1({project:e,selected:t,setSelected:n,filter:r}){const o=e.chats.filter(a=>f1(a,r)),s=x.useMemo(()=>({...e,chats:o}),[e,o]),i=o1(s,t);return o.length===0&&e.projectExtras.length===0?null:l.jsxs("li",{children:[l.jsxs("div",{className:"mb-1.5 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 border-t border-edge pt-3",children:[l.jsx(im,{content:l.jsxs("span",{className:"block max-w-xs break-all font-mono text-2xs",children:["→ ",Qd(e.hostStore),o.some($1)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),"kept, not deleted → ",Qd(e.preserveDir)]})]}),className:"min-w-0",children:l.jsx("h3",{className:"min-w-0 truncate text-base font-semibold text-fg",children:e.name||"Root workspace"})}),o.length>0&&l.jsx(rm,{checked:i.all,indeterminate:i.some,onChange:()=>n(s1(t,s,!i.all)),label:l.jsxs("span",{className:"whitespace-nowrap text-2xs text-fg-muted",children:[i.selected," of ",i.total]})})]}),o.length===0?l.jsxs("p",{className:"rounded-lg border border-dashed border-edge px-3 py-2 text-xs text-fg-muted",children:["No chats here need a decision — ",e.projectExtras.length.toLocaleString()," project"," ",e.projectExtras.length===1?"file moves":"files move"," with it anyway."]}):l.jsx("ul",{className:"space-y-1",children:o.map(a=>l.jsx(N1,{chat:a,checked:t.has(a.sessionId),onToggle:()=>n(a1(t,a.sessionId))},a.sessionId))})]})}function N1({chat:e,checked:t,onToggle:n}){const r=e.state==="diverged"||e.state==="unknown";return l.jsx("li",{children:l.jsxs("label",{title:D1(e),className:Wi("flex cursor-pointer items-start gap-2.5 rounded-lg border px-3 py-2 transition","can-hover:hover:bg-surface-hover",r?"border-warn-edge bg-warn-soft/30":"border-edge"),children:[l.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:t,onChange:n,"aria-label":`Merge ${e.name??e.sessionId} into ~/.claude`}),l.jsxs("span",{className:"min-w-0 flex-1",children:[l.jsxs("span",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[l.jsx("span",{className:"min-w-0 truncate text-sm text-fg",children:e.name??l.jsx("span",{className:"font-mono text-xs",children:e.sessionId})}),l.jsx(I1,{state:e.state})]}),e.preview&&e.preview!==e.name&&l.jsx("span",{className:"mt-0.5 block truncate text-xs text-fg-muted",children:e.preview}),r&&e.host&&l.jsx(C1,{chat:e,checked:t})]})]})})}function C1({chat:e,checked:t}){return e.host?l.jsxs("span",{className:"mt-1.5 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[l.jsx(Gd,{title:"Paddock's copy",side:e.own,wins:t,note:t?"moves into ~/.claude":"kept in the preserve folder"}),l.jsx(Gd,{title:"Your ~/.claude copy",side:e.host,wins:!t,note:t?"moved aside, kept":"stays where it is"})]}):null}function Gd({title:e,side:t,wins:n,note:r}){return l.jsxs("span",{className:Wi("block rounded-md border px-2 py-1.5 text-2xs",n?"border-accent-edge bg-accent-soft":"border-edge bg-surface"),children:[l.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("span",{className:"font-semibold text-fg",children:e}),l.jsx("span",{className:n?"text-accent":"text-fg-muted",children:r})]}),l.jsxs("span",{className:"mt-0.5 block text-fg-muted tabular",children:[t.messageCount!==void 0?`${t.messageCount.toLocaleString()} ${t.messageCount===1?"message":"messages"}`:F1(t.sizeBytes)," · ",t.lastMessageAt?l.jsxs(l.Fragment,{children:["last message ",yi(t.lastMessageAt)]}):l.jsxs(l.Fragment,{children:["file touched ",yi(t.mtime)]})]})]})}function P1({plan:e,count:t}){var n;return l.jsxs("div",{className:"space-y-3 py-6",children:[l.jsxs("p",{className:"text-sm font-semibold text-fg",children:[l.jsx("span",{className:"mr-2 inline-block h-2 w-2 animate-pulse rounded-full bg-accent-solid"}),"Merging ",t.toLocaleString()," ",t===1?"chat":"chats","…"]}),l.jsxs("ol",{className:"ml-4 list-decimal space-y-1 text-xs text-fg-muted",children:[l.jsx("li",{children:"Stopping any turns that are still running."}),l.jsxs("li",{children:["Moving transcripts into"," ",l.jsx(Ce,{children:((n=e==null?void 0:e.projects[0])==null?void 0:n.hostStore.replace(/\/[^/]*$/,"/…"))??"~/.claude"}),"."]}),l.jsxs("li",{children:["Setting ",l.jsx(Ce,{children:"claude.transcripts: host"}),"."]})]}),l.jsx("p",{className:"text-xs text-fg-subtle",children:"Please leave this open. Nothing is deleted at any point, and if this is interrupted the migration can simply be run again."})]})}function T1({error:e,plan:t,rows:n,selected:r}){const o=e instanceof $n?e.code:void 0,s=z1(e),i=a=>{var u;return((u=n.find(c=>c.sessionId===a))==null?void 0:u.name)??a};return l.jsxs("div",{className:"space-y-3",children:[l.jsxs(Xt,{tone:o==="env_shadowed"?"danger":"warn",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:b1[o??""]??"The migration did not run."}),l.jsxs("p",{className:"mt-1 text-fg",children:[l.jsx("strong",{className:"font-semibold",children:"Nothing was moved."})," Every one of these checks runs before the first file is touched, so your chats are exactly where they were."]}),l.jsx("p",{className:"mt-1.5 text-xs",children:dm(e)})]}),o==="turn_running"&&s.length>0&&l.jsxs("div",{className:"text-xs text-fg-muted",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Still running:"}),l.jsx("ul",{className:"mt-1 space-y-0.5",children:s.map(a=>l.jsxs("li",{className:"break-all",children:[l.jsx("span",{className:"text-fg",children:i(a)})," ",l.jsx("span",{className:"font-mono text-2xs text-fg-subtle",children:a})]},a))}),l.jsxs("p",{className:"mt-1.5",children:["A chat mid-turn is still writing to its transcript, so moving it would race the write. Wait for it to finish — or stop it from its own chat screen — then try again. One chat left behind would leave that project's ",l.jsx(Ce,{children:".chats/"})," non-empty, which is why the whole migration refuses rather than skipping it."]})]}),o==="config_conflict"&&l.jsxs("p",{className:"text-xs text-fg-muted",children:["Something else edited ",l.jsx(Ce,{children:(t==null?void 0:t.configPath)??"paddock.config.yaml"})," after this plan was built — another tab, or an editor. Reload the plan so your choices are made against the current file, then submit again."]}),o==="migration_in_progress"&&l.jsx("p",{className:"text-xs text-fg-muted",children:"Another tab or window is running this migration right now. Let it finish — when it does, reload this plan and it will report that there is nothing left to move."}),o==="env_shadowed"&&l.jsxs("p",{className:"text-xs text-fg-muted",children:[l.jsx(Ce,{children:"PADDOCK_CLAUDE_TRANSCRIPTS"})," is set in this server's environment, and an environment variable beats the config file. Writing"," ",l.jsx(Ce,{children:"claude.transcripts: host"})," would have no effect, so the chats would have been moved for nothing. Unset it, restart Paddock, and the offer will come back."]}),l.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Your selection is still here: ",r.size.toLocaleString()," of"," ",n.length.toLocaleString()," ticked."]})]})}const b1={turn_running:"A chat is still mid-turn.",config_conflict:"The config file changed underneath this plan.",migration_in_progress:"A migration is already running.",env_shadowed:"An environment variable is overriding the config file.",invalid:"That request was not valid."};function R1({result:e}){const t=nm(e),n=c1(e.preserved),r=e.projects.filter(o=>o.outcome==="skipped-busy");return l.jsxs("div",{className:"space-y-3",children:[t==="partial"?l.jsxs(Xt,{tone:"warn",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"The migration did not finish."}),l.jsxs("p",{className:"mt-1",children:[l.jsx(Ce,{children:"claude.transcripts"})," was ",l.jsx("strong",{className:"font-semibold",children:"not"})," ","changed, so this instance is still using its own store and nothing about how Paddock behaves has changed yet. Files that did move are already in place and will not move twice — ",l.jsx("strong",{className:"font-semibold",children:"running this again is safe"})," and picks up where it stopped."]})]}):t==="already"?l.jsxs(Xt,{tone:"info",className:"text-sm",children:[l.jsx("p",{className:"font-semibold",children:"Already merged."}),l.jsxs("p",{className:"mt-1",children:["Everything was already in your ",l.jsx(Ce,{children:"~/.claude"})," and"," ",l.jsx(Ce,{children:"claude.transcripts"})," was already ",l.jsx(Ce,{children:"host"}),". Nothing needed doing."]})]}):l.jsxs(Xt,{tone:"success",className:"text-sm",children:[l.jsxs("p",{className:"font-semibold",children:["Merged ",e.migrated.length.toLocaleString()," ",e.migrated.length===1?"chat":"chats"," into your ",l.jsx(Ce,{children:"~/.claude"}),"."]}),e.preserved.length>0&&l.jsxs("p",{className:"mt-1",children:[e.preserved.length.toLocaleString()," ",e.preserved.length===1?"copy was":"copies were"," set aside rather than overwritten. Every one is listed below."]})]}),e.restartRequired&&l.jsx(L1,{ok:t!=="partial",configWritten:e.configWritten}),e.failed.length>0&&l.jsxs("section",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:[e.failed.length.toLocaleString()," could not be moved"]}),l.jsx("ul",{className:"mt-1 space-y-1",children:e.failed.map((o,s)=>l.jsxs("li",{className:"rounded-md border border-warn-edge bg-warn-soft/40 px-2 py-1.5 text-2xs",children:[l.jsx("span",{className:"block break-all font-mono text-fg",children:Yd(o)}),l.jsxs("span",{className:"block text-fg-muted",children:[o.reason,o.message?` — ${o.message}`:""]}),o.path&&Yd(o)!==o.path&&l.jsx("span",{className:"block break-all font-mono text-fg-subtle",children:o.path})]},`${o.slug}:${o.sessionId}:${s}`))})]}),r.length>0&&l.jsxs(Xt,{tone:"warn",className:"text-xs",children:[l.jsxs("p",{className:"font-semibold",children:[r.length," ",r.length===1?"project was":"projects were"," left untouched."]}),l.jsxs("p",{className:"mt-1",children:["A turn started again between the stop and the move, so"," ",r.map(o=>o.slug||"the root workspace").join(", ")," was skipped entirely rather than half-moved. Run the migration again once it is idle."]})]}),e.preserved.length>0&&l.jsxs("section",{"data-testid":"migration-preserved",children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:["Kept, not deleted — ",e.preserved.length.toLocaleString()," ",e.preserved.length===1?"item":"items"]}),l.jsxs("p",{className:"mt-0.5 text-2xs text-fg-muted",children:["Every copy that did not end up in ",l.jsx(Ce,{children:"~/.claude"}),", and exactly where it is now. Nothing here was removed; you can open any of these paths. A chat's sub-agent transcripts, tool results and revert history move with it."]}),n.map(o=>l.jsxs("div",{className:"mt-2",children:[l.jsx("p",{className:"text-2xs font-semibold text-fg-muted",children:o.slug||"root workspace"}),l.jsx("ul",{className:"mt-0.5 space-y-0.5",children:o.items.map((s,i)=>l.jsxs("li",{className:"text-2xs",children:[l.jsx("span",{className:"block break-all font-mono text-fg",children:s.path}),l.jsx("span",{className:"text-fg-subtle",children:M1(s.reason,s.side)})]},`${s.path}:${i}`))})]},o.slug))]}),e.unplanned.length>0&&l.jsxs("section",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-fg",children:[e.unplanned.length.toLocaleString()," appeared after you opened this"]}),l.jsx("p",{className:"mt-0.5 text-2xs text-fg-muted",children:"These chats were created between the table being built and Submit, so you were never shown them. Each was handled by the same default its classification would have had."}),l.jsx("ul",{className:"mt-1 space-y-0.5",children:e.unplanned.map((o,s)=>l.jsxs("li",{className:"break-all text-2xs",children:[l.jsx("span",{className:"font-mono text-fg",children:o.sessionId})," ",l.jsxs("span",{className:"text-fg-muted",children:["— ",xi(o.state).label.toLowerCase(),", so it was"," ",o.action==="migrated"?"merged":"kept in the preserve folder"]})]},`${o.sessionId}:${s}`))})]}),e.ignoredSessionIds.length>0&&l.jsxs("p",{className:"text-2xs text-fg-muted",children:[e.ignoredSessionIds.length.toLocaleString()," ticked"," ",e.ignoredSessionIds.length===1?"chat was":"chats were"," no longer on disk and were skipped."]}),e.warnings.length>0&&l.jsx(um,{warnings:e.warnings}),e.sweepers.chats>0&&l.jsxs("p",{className:"text-2xs text-fg-subtle",children:[e.sweepers.chats.toLocaleString()," internal sweeper transcripts across"," ",e.sweepers.stores.toLocaleString()," ",e.sweepers.stores===1?"store":"stores"," moved with their projects."]})]})}function L1({ok:e,configWritten:t}){return e?t?l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Restart the Paddock server now."}),l.jsxs("p",{className:"mt-1",children:["The setting is written, but Paddock reads it once when it starts — so this running server has not picked it up yet."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Until you restart, your chat list will look empty."})," ","That is expected and nothing is wrong: the running process is still looking in the old location, which the migration just emptied. Everything is on disk — the merged chats are in your ",l.jsx(Ce,{children:"~/.claude"})," and the set-aside copies are in the folders listed here. They all come back the moment Paddock restarts."]})]}):l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Restart the Paddock server now."}),l.jsxs("p",{className:"mt-1",children:["Your configuration already asked for ",l.jsx(Ce,{children:"~/.claude"}),", so"," ",l.jsx("strong",{className:"font-semibold text-fg",children:"nothing about it was changed"})," — the chats were simply stranded where Paddock could not reach them, and they are now back in the store it reads. Paddock only wires that up at startup, so this running server has not caught up yet."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Restart and the chats that were missing will reappear."})," ","The copies set aside along the way are in the folders listed here."]})]}):l.jsxs(Xt,{tone:"accent",className:"text-sm",children:[l.jsx("p",{className:"font-semibold text-fg",children:"Run the migration again, then restart."}),l.jsxs("p",{className:"mt-1",children:["Some chats have already moved out of Paddock's own store, and because the setting was not written this server still looks for them there."," ",l.jsx("strong",{className:"font-semibold text-fg",children:"Until the migration finishes, your chat list will look incomplete."})," ","Nothing is lost — every file is either in your ",l.jsx(Ce,{children:"~/.claude"})," or in the folders listed below. Fix what is reported above, run this again, and restart when it completes."]})]})}function M1(e,t){switch(e){case"unchecked":return"you left this one unticked, so Paddock's copy was set aside and your ~/.claude copy is untouched";case"unplanned-diverged":return"created after the table was built and had conflicting edits, so it was set aside rather than merged without asking";case"identical":return"already identical in both places, so Paddock's duplicate was set aside";case"already-ahead":return"your ~/.claude copy was the longer one and was kept, so Paddock's shorter copy was set aside";case"superseded":return"your ~/.claude copy was moved here first, then Paddock's copy took its place — this is the original";default:return`set aside from the ${t==="host"?"~/.claude":"Paddock"} side (${e})`}}function _1({phase:e,plan:t,rows:n,selectedCount:r,alsoMoving:o,onClose:s,onRetry:i,onReload:a,onSubmit:u}){if(e.kind==="running")return l.jsx("span",{className:"text-xs text-fg-muted",children:"Working — this usually takes under a second."});if(e.kind==="result")return l.jsx(jt,{variant:"primary",size:"sm",onClick:s,children:"Close"});if(e.kind==="load-failed")return l.jsxs(l.Fragment,{children:[l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Close"}),l.jsx(jt,{variant:"primary",size:"sm",onClick:a,children:"Try again"})]});if(e.kind==="refused"){const c=e.error instanceof $n?e.error.code:void 0,d=c!=="env_shadowed"&&c!=="invalid";return l.jsxs(l.Fragment,{children:[l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Close"}),c==="config_conflict"?l.jsx(jt,{variant:"primary",size:"sm",onClick:a,children:"Reload the plan"}):d&&l.jsx(jt,{variant:"primary",size:"sm",onClick:i,children:"Try again"})]})}return e.kind==="loading"||!t?l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}):tm(t)?l.jsx(jt,{variant:"primary",size:"sm",onClick:s,children:"Close"}):l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"mr-auto text-xs text-fg-muted",children:[r.toLocaleString()," of ",n.length.toLocaleString()," ticked",o>0&&l.jsxs("span",{className:"text-fg-subtle",children:[" · ",o.toLocaleString()," more move anyway"]})]}),l.jsx(jt,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}),l.jsx(jt,{variant:"primary",size:"sm",onClick:u,children:r===0?"Merge nothing, keep everything":`Merge ${r.toLocaleString()} ${r===1?"chat":"chats"}`})]})}function um({warnings:e}){return l.jsx("ul",{className:"space-y-1",children:e.map((t,n)=>l.jsxs("li",{children:[l.jsx("span",{children:t.message}),t.paths&&t.paths.length>0&&l.jsxs("details",{className:"mt-0.5",children:[l.jsx("summary",{className:"focus-visible:focus-ring cursor-pointer text-2xs underline underline-offset-2",children:t.paths.length===1?"Show the path":`Show ${t.paths.length} paths`}),l.jsx("ul",{className:"mt-0.5",children:t.paths.map(r=>l.jsx("li",{className:"break-all font-mono text-2xs text-fg-subtle",children:r},r))})]})]},`${t.code}:${n}`))})}const cm={new:"success","fast-forward":"info",diverged:"warn",unknown:"neutral"};function I1({state:e,n:t}){if(t===0)return null;const n=xi(e);return l.jsx(m1,{tone:cm[e]??"neutral",title:n.hint,children:t===void 0?n.label:`${t.toLocaleString()} ${n.label.toLowerCase()}`})}function D1(e){const t=[];return e.name!==void 0&&t.push(e.sessionId),e.extras.length>0&&t.push(`+${e.extras.length} sidecar ${e.extras.length===1?"file":"files"}`),t.length>0?t.join(" · "):void 0}function O1(e){return!e.defaultSelected}function $1(e){return e.state==="diverged"||e.state==="unknown"}function Ce({children:e}){return l.jsx("span",{className:"break-all font-mono",children:e})}function dm(e){return e instanceof Error?e.message:String(e)}function A1(e){const t="Merge chats into ~/.claude";if(e.kind!=="result")return t;switch(nm(e.result)){case"partial":return`${t} — unfinished`;case"already":return`${t} — nothing to do`;default:return`${t} — done`}}function Yd(e){return e.sessionId&&e.sessionId!=="-"?e.sessionId:e.path??"Project files"}function z1(e){if(!(e instanceof $n))return[];const t=e.body;if(typeof t!="object"||t===null)return[];const n=t.sessionIds;return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}function F1(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function U1(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Wi(...e){return e.filter(Boolean).join(" ")}function B1(e){return l.jsx(y1,{...e,size:"lg",className:"sm:max-w-4xl"})}function J(e){return{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",...e}}const W1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 5v14M5 12h14"})}),US=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),H1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M3 10.5 12 3l9 7.5"}),l.jsx("path",{d:"M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5"})]}),BS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),Jd=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"11",cy:"11",r:"7"}),l.jsx("path",{d:"m21 21-4.3-4.3"})]}),WS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M4 5h16"}),l.jsx("path",{d:"M8 5v6h12"}),l.jsx("path",{d:"M8 11v6h12"})]}),HS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),VS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"})}),KS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"m22 2-7 20-4-9-9-4Z"}),l.jsx("path",{d:"M22 2 11 13"})]}),QS=e=>l.jsx("svg",{...J(e),children:l.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),GS=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),l.jsx("path",{d:"M5 10a7 7 0 0 0 14 0"}),l.jsx("path",{d:"M12 17v4M8 21h8"})]}),YS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m9 18 6-6-6-6"})}),JS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M14.7 6.3a4 4 0 0 0-5.4 5.4L3 18l3 3 6.3-6.3a4 4 0 0 0 5.4-5.4l-2.6 2.6-2-2 2.6-2.6Z"})}),V1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"3"}),l.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z"})]}),K1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"}),l.jsx("path",{d:"M12 9v4M12 17h.01"})]}),XS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8"})}),Hi=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M18 6 6 18M6 6l12 12"})}),ZS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12z"})}),qS=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M6 4.5v15l13-7.5z"})}),Q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})}),ek=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"9"}),l.jsx("path",{d:"M12 7v5l3 2"})]}),tk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"5",r:"1"}),l.jsx("circle",{cx:"12",cy:"12",r:"1"}),l.jsx("circle",{cx:"12",cy:"19",r:"1"})]}),nk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M10 11v6M14 11v6"})}),rk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 20h9"}),l.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),ok=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),l.jsx("path",{d:"M14 2v6h6"})]}),sk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 17v5"}),l.jsx("path",{d:"M9 10.76V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v6.76a2 2 0 0 0 .59 1.42l1.12 1.12A1 1 0 0 1 17 15H7a1 1 0 0 1-.71-1.7l1.12-1.12A2 2 0 0 0 9 10.76Z"})]}),G1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M20 6 9 17l-5-5"})}),ik=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),l.jsx("path",{d:"M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1"})]}),ak=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),l.jsx("path",{d:"M5 21h14"})]}),lk=({open:e,...t})=>e?l.jsxs("svg",{...J(t),children:[l.jsx("path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z"}),l.jsx("path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10"})]}):l.jsxs("svg",{...J(t),children:[l.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),l.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),uk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"6",cy:"6",r:"3"}),l.jsx("circle",{cx:"6",cy:"18",r:"3"}),l.jsx("circle",{cx:"18",cy:"6",r:"3"}),l.jsx("path",{d:"M6 9v6M18 9a9 9 0 0 1-9 9"})]}),ck=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M9.5 14.5l-1.7 1.7a4 4 0 0 1-5.66-5.66l1.7-1.7"}),l.jsx("path",{d:"M14.5 9.5l1.7-1.7a4 4 0 0 1 5.66 5.66l-1.7 1.7"}),l.jsx("path",{d:"M8 3.5v2M3.5 8h2M16 20.5v-2M20.5 16h-2"})]}),dk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),l.jsx("path",{d:"M17 8l-5-5-5 5M12 3v12"})]}),fk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 17l6-5-6-5M12 19h8"})}),hk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.9a3.4 3.4 0 0 0-1-2.6c3-.3 6.2-1.5 6.2-6.6a5.2 5.2 0 0 0-1.4-3.6 4.8 4.8 0 0 0-.1-3.6s-1.1-.3-3.7 1.4a12.6 12.6 0 0 0-6.6 0C6.5 1.3 5.4 1.6 5.4 1.6a4.8 4.8 0 0 0-.1 3.6 5.2 5.2 0 0 0-1.4 3.6c0 5.1 3.2 6.3 6.2 6.6a3.4 3.4 0 0 0-1 2.6V22"})}),Y1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"4"}),l.jsx("path",{d:"M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"})]}),J1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})}),X1=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.5 1.5"}),l.jsx("path",{d:"M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.5-1.5"})]}),pk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m6 9 6 6 6-6"})}),mk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"4",rx:"1"}),l.jsx("path",{d:"M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8"}),l.jsx("path",{d:"M10 12h4"})]}),gk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 2.5l2.9 5.88 6.49.94-4.7 4.58 1.11 6.46L12 17.8l-5.8 3.05 1.11-6.46-4.7-4.58 6.49-.94z"})});function Z1({message:e,tone:t="success",onDismiss:n,durationMs:r=6e3,action:o}){if(x.useEffect(()=>{if(e===null||r<=0)return;const i=setTimeout(n,r);return()=>clearTimeout(i)},[e,r,n]),e===null)return null;const s=t==="error";return l.jsx("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 bottom-4 z-50 flex justify-center px-4",children:l.jsxs("div",{className:`pointer-events-auto flex max-w-md items-start gap-2 rounded-lg border px-3 py-2 text-sm shadow-lg ${s?"border-danger-edge bg-danger-soft text-danger":"border-edge bg-surface-raised text-fg"}`,children:[s?l.jsx(K1,{width:16,height:16,className:"mt-0.5 shrink-0"}):l.jsx(G1,{width:16,height:16,className:"mt-0.5 shrink-0 text-success-solid"}),l.jsx("span",{className:"break-words",children:e}),o&&l.jsx("button",{type:"button",onClick:o.onAct,className:"ml-1 shrink-0 font-medium underline underline-offset-2 transition hover:opacity-80",children:o.label}),l.jsx("button",{type:"button",onClick:n,"aria-label":"Dismiss notification",className:"-mr-1 ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded transition hover:bg-surface-hover",children:l.jsx(Hi,{width:12,height:12})})]})})}function q1(){const{showBanner:e,dismiss:t}=em(),n=es(),[r,o]=x.useState(!1),[s,i]=x.useState(null),[a,u]=x.useState(!1),c=()=>{t(),i("Hidden on this browser. The migration is still on the Config screen.")};return l.jsxs(l.Fragment,{children:[e&&!a&&l.jsxs("div",{"data-testid":"migration-offer",className:"hidden h-6 shrink-0 items-center rounded-md border border-accent-edge bg-accent-soft pr-0.5 sm:flex",children:[l.jsxs("button",{type:"button",onClick:()=>o(!0),title:"Your chats live in Paddock's own store, not in ~/.claude. Merge them in so the Claude Code CLI sees them too.","aria-label":"Merge this instance's chats into your ~/.claude",className:"focus-visible:focus-ring flex h-6 items-center gap-1.5 rounded-md pl-2 pr-1.5 text-2xs can-hover:hover:underline",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-[1px] bg-accent-solid","aria-hidden":"true"}),l.jsxs("span",{className:"whitespace-nowrap text-fg-muted",children:["Chats are separate from ",l.jsx("span",{className:"font-mono",children:"~/.claude"})]}),l.jsx("span",{className:"whitespace-nowrap font-semibold text-accent",children:"Merge"})]}),l.jsx("button",{type:"button","data-testid":"migration-offer-dismiss",onClick:c,"aria-label":"Hide the transcript migration offer",title:"Hide this. You can still start the migration from the Config screen.",className:"focus-visible:focus-ring flex h-5 w-5 shrink-0 items-center justify-center rounded text-accent can-hover:hover:bg-accent-solid/15",children:l.jsx(Hi,{width:11,height:11})})]}),l.jsx(am,{open:r,onClose:()=>o(!1),onCompleted:()=>u(!0)}),l.jsx(Z1,{message:s,onDismiss:()=>i(null),durationMs:12e3,action:{label:"Open Config",onAct:()=>{i(null),n("/config")}}})]})}function vk(){const{showInConfig:e}=em(),[t,n]=x.useState(!1),[r,o]=x.useState(!1);return e?l.jsxs("div",{className:"px-3 pt-3 sm:px-6","data-testid":"migration-offer-card",children:[!r&&l.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 rounded-xl border border-accent-edge bg-accent-soft px-3 py-2.5",children:[l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsxs("p",{className:"text-sm font-semibold text-fg",children:["Chats are separate from ",l.jsx("span",{className:"font-mono",children:"~/.claude"})]}),l.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:["This instance keeps its transcripts in each project's own store, so the Claude Code CLI does not see them. Merging moves them into your Claude home and switches"," ",l.jsx("span",{className:"font-mono",children:"claude.transcripts"})," to"," ",l.jsx("span",{className:"font-mono",children:"host"}),"."]})]}),l.jsx(jt,{variant:"primary",size:"sm",onClick:()=>n(!0),children:"Merge chats…"})]}),l.jsx(am,{open:t,onClose:()=>n(!1),onCompleted:()=>o(!0)})]}):null}const Ca=6,ew=.75,tw=.9,nw=250,rw=3e4;function ow(e){const[,t]=x.useState(0);x.useEffect(()=>{if(e==null)return;const n=setInterval(()=>t(r=>r+1),e);return()=>clearInterval(n)},[e])}function sw(){const[e,t]=x.useState(new Map);return x.useEffect(()=>Wu.onActiveInfos(n=>t(new Map(n))),[]),e}function iw(e,t){const[n,r]=x.useState(new Map),o=x.useRef(0);return x.useEffect(()=>{const s=new Set([...e.split(","),...t.split(",")].filter(Boolean));if(s.size===0){o.current++,r(new Map);return}r(d=>{const f=new Map([...d].filter(([p])=>s.has(p)));return f.size===d.size?d:f});let i=!1;const a=async()=>{const d=++o.current;try{const f=await ar.attentionChats(_u);if(i||d!==o.current)return;r(p=>{const S=new Map([...p].filter(([k])=>s.has(k)));for(const k of[...f.recent??[],...f.unread??[],...f.running??[]]){if(!s.has(k.sessionId))continue;const g=S.get(k.sessionId);S.set(k.sessionId,k.contextTokens==null&&(g==null?void 0:g.contextTokens)!=null?{...k,contextTokens:g.contextTokens,contextLimit:g.contextLimit}:k)}return S})}catch{}},u=setTimeout(()=>void a(),nw),c=e?setInterval(()=>{document.visibilityState==="visible"&&a()},rw):null;return()=>{i=!0,clearTimeout(u),c&&clearInterval(c)}},[e,t]),n}function fm({fill:e}){const t=e<=0?0:Math.max(1,Math.min(Ca,Math.round(e*Ca))),n=e<ew?"bg-accent-solid":e<tw?"bg-warn-solid":"bg-danger-solid";return l.jsx("span",{className:"flex items-center gap-px",title:`Context ${Math.round(e*100)}% full`,"aria-hidden":"true",children:Array.from({length:Ca},(r,o)=>l.jsx("span",{className:Ye("h-2.5 w-[3px] rounded-[1px]",o<t?n:"bg-edge")},o))})}function aw({projectSlug:e,projectName:t,chatName:n,sessionId:r,startedAt:o,fill:s}){const i=o==null?"—:—":qx(Date.now()-o),a=n??"Running turn";return l.jsxs(ts,{"data-testid":"fleet-channel",to:`${Up(e)}/chat/${encodeURIComponent(r)}`,title:`${a} — ${t}`,"aria-label":`${a} in ${t}, running${o==null?"":` for ${i}`}`,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-2 rounded-md border border-edge-subtle bg-surface px-2 text-2xs can-hover:hover:border-edge can-hover:hover:bg-surface-hover",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-[1px] bg-accent-solid","aria-hidden":"true"}),l.jsx("span",{className:"max-w-[14ch] truncate font-medium text-fg",children:t}),l.jsx("span",{className:"font-mono tabular text-fg-muted",children:i}),s!=null&&l.jsx(fm,{fill:s})]})}function lw({projectSlug:e,projectName:t,chatName:n,sessionId:r,at:o,fill:s}){const i=yi(new Date(o).toISOString()),a=n??"Finished turn";return l.jsxs(ts,{"data-testid":"fleet-finished",to:`${Up(e)}/chat/${encodeURIComponent(r)}`,title:`${a} — ${t} · finished ${i}, unread`,"aria-label":`${a} in ${t}, finished ${i}, unread`,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-2 rounded-md border border-dashed border-edge px-2 text-2xs can-hover:hover:border-solid can-hover:hover:bg-surface-hover",children:[l.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-warn-solid","aria-hidden":"true"}),l.jsx("span",{className:"max-w-[14ch] truncate font-medium text-fg-muted",children:t}),l.jsx("span",{className:"text-fg-subtle",children:i}),s!=null&&l.jsx("span",{className:"opacity-50",children:l.jsx(fm,{fill:s})})]})}function uw(){const e=x.useRef(null),[t,n]=x.useState(!1),[r,o]=x.useState(!1);return x.useEffect(()=>{const s=e.current;if(!s)return;const i=()=>{n(s.scrollLeft>1),o(s.scrollLeft+s.clientWidth<s.scrollWidth-1)},a=d=>{s.scrollWidth<=s.clientWidth||Math.abs(d.deltaX)>Math.abs(d.deltaY)||(s.scrollLeft+=d.deltaY,d.preventDefault())};i(),s.addEventListener("scroll",i,{passive:!0}),s.addEventListener("wheel",a,{passive:!1});const u=typeof ResizeObserver>"u"?null:new ResizeObserver(i);u==null||u.observe(s);const c=typeof MutationObserver>"u"?null:new MutationObserver(i);return c==null||c.observe(s,{childList:!0,subtree:!0,characterData:!0}),()=>{s.removeEventListener("scroll",i),s.removeEventListener("wheel",a),u==null||u.disconnect(),c==null||c.disconnect()}},[]),{ref:e,moreLeft:t,moreRight:r}}function Xd({value:e,unit:t,to:n,tone:r,title:o}){return l.jsxs(ts,{"data-testid":`fleet-${t}`,to:n,title:o,className:"focus-visible:focus-ring flex h-6 shrink-0 items-center gap-1.5 rounded-md px-1.5 can-hover:hover:bg-surface-hover",children:[l.jsx("span",{"aria-hidden":"true",className:Ye("h-1.5 w-1.5 shrink-0 rounded-[1px]",r==="live"&&"bg-accent-solid",r==="attention"&&"bg-warn-solid",r==="rest"&&"bg-edge-strong")}),l.jsx("span",{"data-testid":`fleet-${t}-value`,className:"font-mono tabular text-2xs font-semibold text-fg",children:e}),l.jsx("span",{className:"text-3xs font-semibold uppercase tracking-[0.14em] text-fg-subtle",children:t})]})}function cw({unread:e,finished:t=[]}){const{projects:n,rootWorkspace:r}=Wp(),o=sw(),s=x.useMemo(()=>[...o.keys()].sort().join(","),[o]),i=x.useMemo(()=>t.map(g=>g.sessionId).join(","),[t]),a=iw(s,i);ow(o.size>0?1e3:t.length>0?3e4:null);const u=uw(),c=x.useMemo(()=>{const g=new Map;for(const C of n)g.set(C.slug,C.name);return r&&g.set(r.slug,r.name),g},[n,r]),d=x.useMemo(()=>[...o.entries()].map(([g,C])=>{const m=a.get(g);return{sessionId:g,projectSlug:C,projectName:c.get(C)??(m==null?void 0:m.projectName)??C,chatName:(m==null?void 0:m.name)??null,startedAt:Wu.turnStartedAt(g),fill:(m==null?void 0:m.contextTokens)!=null&&m.contextLimit?Math.min(1,m.contextTokens/m.contextLimit):null}}).sort((g,C)=>(g.startedAt??1/0)-(C.startedAt??1/0)),[o,a,c]),f=g=>(g==null?void 0:g.contextTokens)!=null&&g.contextLimit?Math.min(1,g.contextTokens/g.contextLimit):null,p=t.map(g=>{const C=a.get(g.sessionId);return{...g,projectName:c.get(g.projectSlug)??(C==null?void 0:C.projectName)??g.projectSlug,chatName:(C==null?void 0:C.name)??null,fill:f(C)}}),S=x.useMemo(()=>{let g="";for(const C of r?[...n,r]:n)for(const m of C.chatTurns??[])m.lastTurnCompletedAt>g&&(g=m.lastTurnCompletedAt);return g},[n,r]),k=o.size===0?`Fleet idle. ${e} unread.`:`${o.size} running. ${e} unread.`;return l.jsxs("div",{"data-testid":"fleet-readout",className:"flex h-9 shrink-0 items-center gap-2 border-b border-edge-subtle bg-surface-sunken px-2 sm:px-3",children:[l.jsx(Xd,{value:o.size,unit:"running",to:"/",tone:o.size>0?"live":"rest",title:o.size>0?"Turns in flight across every project":"Nothing running"}),l.jsx(Xd,{value:e,unit:"unread",to:"/",tone:e>0?"attention":"rest",title:"Chats holding a reply you have not read"}),l.jsx("span",{className:"h-4 w-px shrink-0 bg-edge-subtle","aria-hidden":"true"}),l.jsxs("div",{ref:u.ref,"data-testid":"fleet-channels",className:Ye("scrollbar-none flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overflow-y-hidden overscroll-x-contain",u.moreLeft&&u.moreRight?"fade-both":u.moreLeft?"fade-start":u.moreRight&&"fade-end"),children:[d.map(g=>l.jsx(aw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,startedAt:g.startedAt,fill:g.fill},g.sessionId)),p.map(g=>l.jsx(lw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,at:g.at,fill:g.fill},g.sessionId)),d.length===0&&p.length===0&&(S?l.jsxs("span",{className:"truncate text-2xs text-fg-subtle",children:["Idle · last turn ",yi(S)]}):l.jsx(ts,{to:"/chat",className:"focus-visible:focus-ring truncate rounded-md px-1 text-2xs text-accent can-hover:hover:underline",children:"No turns yet — start a chat →"}))]}),l.jsx(q1,{}),l.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})}let Pa;function dw(){if(Pa===void 0){const e=Intl.Segmenter;Pa=e?new e(void 0,{granularity:"grapheme"}):null}return Pa}function Zd(e){const t=dw();return t?Array.from(t.segment(e),n=>n.segment):Array.from(e)}const fw=/[^\p{Cf}\p{Cc}\p{M}\p{Z}\p{White_Space}]/u;function hw(e){const t=Zd(e.normalize("NFC")).filter(o=>fw.test(o));if(t.length===0)return"?";const n=t.find(o=>/[\p{L}\p{N}\p{Extended_Pictographic}\p{Regional_Indicator}]/u.test(o))??t[0],r=n.toLocaleUpperCase();return Zd(r).length===1?r:n}function pw({slug:e,name:t,color:n,className:r=""}){const o=n??Au(e);return l.jsx("span",{"aria-hidden":"true","data-testid":"project-chip",className:`flex h-4 w-4 shrink-0 select-none items-center justify-center overflow-hidden rounded-sm text-3xs font-semibold leading-none ${r}`,style:{backgroundColor:o,color:Uu(o)},children:hw(t)})}function qd(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e:"~"}function mw(e,t,n){const r=Math.abs(e-t)%n;return Math.min(r,n-r)}function gw(e,t,n){let r=-1,o=-1/0,s=1/0;for(let i=0;i<n;i++){if(e.has(i))continue;let a=1/0;for(const c of e)a=Math.min(a,gx(i,c));const u=mw(i,t,n);(a>o||a===o&&u<s)&&(r=i,o=a,s=u)}return r}function vw(e){const t=ns.length,n=[...e].sort((s,i)=>{const a=qd(s.started),u=qd(i.started);return a!==u?a<u?-1:1:s.slug<i.slug?-1:s.slug>i.slug?1:0}),r=new Set,o=new Map;for(const{slug:s}of n){if(o.has(s))continue;const i=Kp(s),a=!r.has(i)||r.size>=t?i:gw(r,i,t);r.add(a),o.set(s,a)}return o}function yw(e){const t=new Map;for(const[n,r]of vw(e))t.set(n,ns[r]);return t}const xw=["idea","active","paused","blocked","done"];function ww({open:e,onClose:t,onCreated:n}){const[r,o]=x.useState(""),[s,i]=x.useState(""),[a,u]=x.useState(""),[c,d]=x.useState(""),[f,p]=x.useState("active"),[S,k]=x.useState(""),[g,C]=x.useState(""),[m,h]=x.useState(!1),[v,E]=x.useState(!1),[T,R]=x.useState(null);if(x.useEffect(()=>{e&&(o(""),i(""),u(""),d(""),p("active"),k(""),C(""),h(!1),R(null))},[e]),x.useEffect(()=>{const y=D=>{D.key==="Escape"&&e&&!v&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[e,v,t]),!e)return null;const M=async y=>{if(y.preventDefault(),!!r.trim()){E(!0),R(null);try{const D=await ar.createProject({name:r.trim(),status:f,group:c||void 0,summary:s.trim()||void 0,repo:S.trim()||void 0,path:g.trim()||void 0,managed:g.trim()&&!S.trim()?m:void 0,domain:a.split(",").map(b=>b.trim()).filter(Boolean)});n(D)}catch(D){R(D instanceof $n?D.message:"Failed to create project")}finally{E(!1)}}};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4 backdrop-blur-sm",onClick:()=>!v&&t(),children:l.jsxs("form",{className:"w-full max-w-md animate-scale-in rounded-2xl border border-edge bg-surface-raised p-6 shadow-2xl",onClick:y=>y.stopPropagation(),onSubmit:M,children:[l.jsxs("div",{className:"mb-5 flex items-center justify-between",children:[l.jsx("h2",{className:"text-lg font-semibold",children:"New project"}),l.jsx("button",{type:"button",onClick:t,className:"rounded-lg p-1 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted","aria-label":"Close",children:l.jsx(Hi,{width:18,height:18})})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Name"}),l.jsx("input",{autoFocus:!0,className:"input",value:r,onChange:y=>o(y.target.value),placeholder:"Garage Water Heater Replacement"})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Summary (optional)"}),l.jsx("input",{className:"input",value:s,onChange:y=>i(y.target.value),placeholder:"One line on what this project is about"})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Area"}),l.jsxs("select",{className:"input",value:c,onChange:y=>d(y.target.value),children:[l.jsx("option",{value:"",children:"Unsorted"}),Bu.map(y=>l.jsx("option",{value:y.slug,children:y.label},y.slug))]})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Directory on this machine (optional)"}),l.jsx("input",{className:"input",value:g,onChange:y=>C(y.target.value),placeholder:"/home/ed/Code/foo"}),l.jsx("span",{className:"mt-1 block text-xs text-fg-subtle",children:"Where this project's content lives. An existing checkout is used in place — its real history, branches and remotes — and Paddock writes nothing into it. Absolute path; created for you if it doesn't exist."})]}),l.jsxs("label",{className:"mb-4 block",children:[l.jsx("span",{className:"field-label",children:"Git repository URL (optional)"}),l.jsx("input",{className:"input",value:S,onChange:y=>k(y.target.value),placeholder:"https://github.com/owner/repo.git"}),l.jsx("span",{className:"mt-1 block text-xs text-fg-subtle",children:g.trim()?"Cloned into the directory above if it doesn't exist yet; otherwise the directory is used as-is and this just records which repo it is.":"Paddock clones this repo into the project and works in the checkout. Leave both blank for a notes project."})]}),g.trim()&&!S.trim()&&l.jsxs("label",{className:"mb-4 flex cursor-pointer items-start gap-2",children:[l.jsx("input",{type:"checkbox",className:"mt-0.5",checked:m,onChange:y=>h(y.target.checked)}),l.jsxs("span",{className:"text-xs text-fg-muted",children:[l.jsx("span",{className:"font-medium",children:"These are notes — let Paddock curate them."})," ","Its OVERVIEW.md, CHANGELOG.md and CLAUDE.md are written into that directory. Leave unticked for a code checkout you version yourself, and Paddock will write nothing into it."]})]}),l.jsxs("div",{className:"mb-5 grid grid-cols-2 gap-3",children:[l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"field-label",children:"Domain tags"}),l.jsx("input",{className:"input",value:a,onChange:y=>u(y.target.value),placeholder:"home, plumbing"})]}),l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"field-label",children:"Status"}),l.jsx("select",{className:"input capitalize",value:f,onChange:y=>p(y.target.value),children:xw.map(y=>l.jsx("option",{value:y,className:"capitalize",children:y},y))})]})]}),T&&l.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:T}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx("button",{type:"button",className:"btn-ghost",onClick:t,disabled:v,children:"Cancel"}),l.jsx("button",{type:"submit",className:"btn-primary",disabled:v||!r.trim(),children:v?"Creating…":"Create project"})]})]})})}function ef(e){if(typeof window>"u"||typeof window.matchMedia!="function")return null;try{return window.matchMedia(e)??null}catch{return null}}function Sw(e){const[t,n]=x.useState(()=>{var r;return((r=ef(e))==null?void 0:r.matches)??!1});return x.useEffect(()=>{var s;const r=ef(e);if(!r)return;const o=()=>n(!!r.matches);return o(),typeof r.addEventListener=="function"?(r.addEventListener("change",o),()=>r.removeEventListener("change",o)):((s=r.addListener)==null||s.call(r,o),()=>{var i;return(i=r.removeListener)==null?void 0:i.call(r,o)})},[e]),t}const Ku="paddock:panewidth:",kw={key:"sidenav",def:288,min:200,max:480},yk={key:"chatlist",def:256,min:220,max:520},jw="(min-width: 1024px)";function Or(e,t){return Math.min(Math.max(t,e.min),e.max)}function tf(e,t,n){return Or(n,e+t)}function Ew(e){try{const t=localStorage.getItem(Ku+e.key);if(t==null)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?Or(e,n):null}catch{return null}}function Nw(e,t){try{localStorage.setItem(Ku+e.key,String(Or(e,t)))}catch{}}function Cw(e){try{localStorage.removeItem(Ku+e.key)}catch{}}function Pw(e){const t=Sw(jw),[n,r]=x.useState(()=>Ew(e)),o=Or(e,n??e.def);return{isDesktop:t,width:o,style:t?{width:o}:void 0,preview:s=>r(Or(e,s)),commit:s=>{const i=Or(e,s);r(i),Nw(e,i)},reset:()=>{r(null),Cw(e)},spec:e}}function Tw({spec:e,width:t,onPreview:n,onCommit:r,onReset:o,label:s}){const i=x.useRef(null),a=x.useRef(t);a.current=t;const u=16;return l.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":s,"aria-valuenow":Math.round(t),"aria-valuemin":e.min,"aria-valuemax":e.max,tabIndex:0,onPointerDown:c=>{i.current={startX:c.clientX,startWidth:t},c.currentTarget.setPointerCapture(c.pointerId)},onPointerMove:c=>{i.current&&n(tf(i.current.startWidth,c.clientX-i.current.startX,e))},onPointerUp:c=>{if(i.current){i.current=null;try{c.currentTarget.releasePointerCapture(c.pointerId)}catch{}r(a.current)}},onDoubleClick:o,onKeyDown:c=>{if(c.key==="ArrowLeft"||c.key==="ArrowRight"){c.preventDefault();const d=tf(t,c.key==="ArrowRight"?u:-u,e);n(d),r(d)}},title:"Drag to resize · double-click to reset",className:"group/resizer absolute inset-y-0 right-0 z-10 hidden w-1.5 -mr-0.5 cursor-ew-resize touch-none lg:block",children:l.jsx("span",{className:"absolute inset-y-0 right-0 w-px bg-edge transition group-hover/resizer:w-0.5 group-hover/resizer:bg-accent-solid group-focus/resizer:w-0.5 group-focus/resizer:bg-accent-solid"})})}function bw(e){const[t,n]=x.useState(new Map),r=x.useRef(new Map),[o,s]=x.useState(0);return x.useEffect(()=>{const i=r.current;for(const a of e)for(const u of a.chatTurns??[]){Gx(u.sessionId,u.lastSeen);const c=Date.parse(u.lastTurnCompletedAt);if(!Number.isFinite(c))continue;const d=i.get(u.sessionId);!d||c>d.at?i.set(u.sessionId,{slug:a.slug,at:c,unread:u.unread}):d.unread=u.unread}if(e.length>0){const a=new Set(e.map(u=>u.slug));for(const[u,c]of i)a.has(c.slug)||i.delete(u)}s(a=>a+1)},[e]),x.useEffect(()=>{const i=a=>{var d;const u=((d=a.detail)==null?void 0:d.sessionIds)??[];let c=!1;for(const f of u)c=r.current.delete(f)||c;c&&s(f=>f+1)};return window.addEventListener(Ml,i),()=>window.removeEventListener(Ml,i)},[]),x.useEffect(()=>{const i=new Map;return Wu.onActiveInfos(a=>{for(const[u,c]of i)a.has(u)||r.current.set(u,{slug:c,at:Date.now()});i.clear();for(const[u,c]of a)i.set(u,c);n(new Map(a)),s(u=>u+1)})},[]),x.useEffect(()=>{const i=()=>s(a=>a+1);return window.addEventListener(Ll,i),()=>window.removeEventListener(Ll,i)},[]),x.useMemo(()=>{const i=new Map,a=[],u=c=>{let d=i.get(c);return d||(d={unread:0,inflight:0},i.set(c,d)),d};for(const[c,{slug:d,at:f,unread:p}]of r.current)!t.has(c)&&(p||f>Qx(c))&&(u(d).unread+=1,a.push({sessionId:c,projectSlug:d,at:f}));for(const c of t.values())u(c).inflight+=1;return a.sort((c,d)=>d.at-c.at),{badges:i,unreadChats:a,active:t}},[t,o])}function Rw(){const{projects:e,rootWorkspace:t,loading:n,upsert:r}=Wp(),{dark:o,toggle:s}=lx(),[i,a]=x.useState(!1),[u,c]=x.useState(!1),d=es(),f=cr(),p=Hp(),S=dx(),k=Pw(kw),g=f.pathname==="/"||f.pathname==="/projects"||f.pathname.startsWith("/chat"),C=f.pathname.startsWith("/projects/")||g;x.useEffect(()=>{a(!1)},[f.pathname]);const m=x.useMemo(()=>{const b=new Map;for(const B of e){const ee=B.group??"",ce=b.get(ee);ce?ce.push(B):b.set(ee,[B])}return Bx(b.keys()).map(B=>[B,b.get(B)??[]])},[e]),h=x.useMemo(()=>yw(e),[e]),v=x.useMemo(()=>t?[...e,t]:e,[e,t]),{badges:E,unreadChats:T,active:R}=bw(v),M=Fx({active:R,finished:T});Dx(p,Ax(M.status));const y=E.get(_u),D=x.useMemo(()=>{let b=0;for(const B of E.values())b+=B.unread;return b},[E]);return l.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden bg-surface lg:flex-row",children:[!C&&l.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2 lg:hidden",children:[l.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":"Open menu",className:"btn-subtle -ml-1 px-2 py-2",children:l.jsx(Q1,{width:20,height:20})}),l.jsxs(yn,{to:"/",className:"flex items-center gap-2",children:[l.jsx(nf,{brand:p,className:"h-7 w-7 text-sm"}),l.jsx("span",{className:"text-md font-semibold tracking-tight",children:p.name})]})]}),i&&l.jsx("div",{className:"fixed inset-0 z-30 bg-overlay backdrop-blur-sm lg:hidden","aria-hidden":"true",onClick:()=>a(!1)}),l.jsxs("aside",{style:k.style,className:`fixed inset-y-0 left-0 z-40 flex w-72 max-w-[85%] shrink-0 flex-col border-r border-edge bg-surface 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/50 lg:shadow-none ${i?"translate-x-0":"-translate-x-full"}`,children:[k.isDesktop&&l.jsx(Tw,{spec:k.spec,width:k.width,onPreview:k.preview,onCommit:k.commit,onReset:k.reset,label:"Resize sidebar"}),l.jsxs("div",{className:"flex items-center gap-2 px-5 py-4",children:[l.jsxs(yn,{to:"/",className:"group flex items-center gap-2",children:[l.jsx(nf,{brand:p,className:"h-8 w-8 text-base"}),l.jsx("span",{className:"text-lg font-semibold tracking-tight",children:p.name})]}),l.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":"Close menu",className:"btn-subtle ml-auto px-2 py-2 lg:hidden",children:l.jsx(Hi,{width:18,height:18})})]}),l.jsx("div",{className:"px-3 pb-1",children:l.jsxs(yn,{to:"/",end:!0,className:({isActive:b})=>`btn-subtle w-full justify-start ${b?"bg-surface-selected":""}`,title:"The root workspace — every project, and the instance's own chats",children:[l.jsx(H1,{width:16,height:16}),"Home",l.jsx(hm,{badge:y,className:"ml-auto"})]})}),l.jsxs("div",{className:"mt-5 mb-1 flex items-center justify-between pr-3",children:[l.jsx(yn,{to:nx(),className:"section-label hover:text-accent",children:"Projects"}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx(yn,{to:"/discover","aria-label":"Discover projects",title:"Find directories with existing Claude Code history to import",className:({isActive:b})=>`btn-subtle px-1.5 py-1 hover:text-accent ${b?"text-accent":"text-fg-subtle"}`,children:l.jsx(Jd,{width:14,height:14})}),l.jsx("button",{type:"button",onClick:()=>c(!0),"aria-label":"New Project",title:"New Project",className:"btn-subtle -mr-1 px-1.5 py-1 text-fg-subtle hover:text-accent",children:l.jsx(W1,{width:14,height:14})})]})]}),l.jsxs("nav",{className:"flex-1 overflow-y-auto px-2 pb-4",children:[n&&l.jsx("div",{className:"space-y-2 px-2 py-2",children:[0,1,2].map(b=>l.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},b))}),!n&&e.length===0&&l.jsx("p",{className:"px-3 py-2 text-sm text-fg-muted",children:"No projects yet."}),!n&&e.length>0&&m.map(([b,B])=>l.jsxs("div",{className:"mb-2",children:[m.length>1&&l.jsx("div",{className:"px-2.5 pb-1 pt-2 text-3xs font-semibold uppercase tracking-wider text-fg-subtle",children:Ux(b)}),B.map(ee=>l.jsx(Mw,{project:ee,badge:E.get(ee.slug),chipColor:h.get(ee.slug)},ee.slug))]},b||"unsorted"))]}),l.jsxs("div",{className:"border-t border-edge px-3 py-3",children:[l.jsxs(yn,{to:"/config",className:({isActive:b})=>`btn-subtle w-full justify-start ${b?"bg-surface-selected":""}`,title:"Instance config — paddock.config.yaml (restart required)",children:[l.jsx(V1,{width:15,height:15}),"Config"]}),l.jsxs(yn,{to:"/discover",className:({isActive:b})=>`btn-subtle mt-1 w-full justify-start ${b?"bg-surface-selected":""}`,title:"Find directories with existing Claude Code history to import",children:[l.jsx(Jd,{width:15,height:15}),"Discover"]}),S.enabled&&l.jsxs("a",{href:S.path,target:"_blank",rel:"noreferrer",className:"btn-subtle mt-1 w-full justify-start",title:"OpenAPI / Swagger reference (opens in a new tab)",children:[l.jsx(X1,{width:15,height:15}),"Swagger API"]}),l.jsxs("button",{type:"button",onClick:s,className:"btn-subtle mt-1 w-full justify-start","aria-label":o?"Switch to light mode":"Switch to dark mode",title:"Toggle light / dark theme",children:[o?l.jsx(Y1,{width:15,height:15}):l.jsx(J1,{width:15,height:15}),o?"Light mode":"Dark mode"]}),l.jsxs("p",{className:"mt-2 px-2 text-2xs text-fg-subtle",children:["v","0.78.0"]})]})]}),l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[l.jsx(cw,{unread:D,finished:T}),l.jsx("main",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:l.jsx(x.Suspense,{fallback:l.jsx(Lw,{}),children:l.jsx(Jp.Provider,{value:M,children:l.jsx(M0,{context:{openNav:()=>a(!0)}})})})})]}),l.jsx(ww,{open:u,onClose:()=>c(!1),onCreated:b=>{r(b),c(!1),d(`/projects/${b.slug}/chat`)}})]})}function nf({brand:e,className:t=""}){const n=wx(e);return l.jsx("span",{className:`flex shrink-0 items-center justify-center overflow-hidden rounded-lg bg-accent-solid text-accent-fg shadow-sm ${t}`,style:n?{backgroundColor:n,color:Uu(n)}:void 0,"data-testid":"brand-chip",children:Vp(e.logo)?l.jsx("img",{src:e.logo,alt:"",className:"h-full w-full object-cover"}):e.logo})}function Lw(){return l.jsxs("div",{className:"flex h-full items-center justify-center","aria-busy":"true","aria-live":"polite",children:[l.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),l.jsx("span",{className:"sr-only",children:"Loading…"})]})}function Mw({project:e,badge:t,chipColor:n}){return l.jsxs(yn,{to:`/projects/${e.slug}`,className:({isActive:r})=>`group mb-0.5 flex flex-col gap-1 rounded-lg px-2.5 py-2 text-sm transition-colors ${r?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[l.jsxs("span",{className:"flex items-center justify-between gap-2",children:[l.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[l.jsx(pw,{slug:e.slug,name:e.name,color:n}),l.jsx("span",{className:"truncate font-medium",children:e.name})]}),l.jsx(hm,{badge:t})]}),e.domain.length>0&&l.jsxs("span",{className:"flex min-w-0 items-center gap-1 overflow-hidden pl-[22px]",children:[e.domain.slice(0,2).map(r=>l.jsx(Yx,{tag:r,className:"max-w-[7rem] truncate"},r)),e.domain.length>2&&l.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:["+",e.domain.length-2]})]})]})}function hm({badge:e,className:t=""}){const n=(e==null?void 0:e.unread)??0,r=(e==null?void 0:e.inflight)??0;return n===0&&r===0?null:l.jsxs("span",{className:`flex shrink-0 items-center gap-1.5 ${t}`,children:[r>0&&l.jsxs("span",{className:"flex items-center gap-1 text-2xs tabular text-fg-muted",title:`${r} chat${r===1?"":"s"} in flight`,"aria-label":`${r} chat${r===1?"":"s"} in flight`,children:[l.jsx("span",{"aria-hidden":"true",className:"h-2.5 w-2.5 spin-eco rounded-full border-[1.5px] border-edge-strong border-t-transparent"}),r]}),n>0&&l.jsx("span",{className:"inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-accent-solid px-1.5 py-0.5 text-2xs font-semibold leading-none tabular text-accent-fg",title:`${n} unread ${n===1?"reply":"replies"}`,"aria-label":`${n} unread ${n===1?"reply":"replies"}`,children:n})]})}const pm="paddock:chunkReloadAt",_w=1e4,rf=/dynamically imported module|module script|importing a module|failed to fetch|unable to preload|load failed|error loading/i;function Iw(e){return e?e instanceof Error?e.name==="ChunkLoadError"?!0:rf.test(e.message):rf.test(String(e)):!1}function Qu(){try{return typeof sessionStorage<"u"?sessionStorage:void 0}catch{return}}function Dw(e=Date.now(),t=Qu()){if(!t)return!1;const n=t.getItem(pm);if(!n)return!1;const r=Number(n);return Number.isFinite(r)&&e-r<_w}function Ow(e=Date.now(),t=Qu()){try{t==null||t.setItem(pm,String(e))}catch{}}function $w(e,t=Date.now(),n=Qu()){return Iw(e)&&!Dw(t,n)?"reload":"show"}function Aw(){const e=Ap(),t=$w(e);if(x.useEffect(()=>{t==="reload"&&(Ow(),window.location.reload())},[t]),t==="reload")return l.jsxs("div",{className:"flex h-[100dvh] items-center justify-center bg-surface","aria-busy":"true","aria-live":"polite",children:[l.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),l.jsx("span",{className:"sr-only",children:"Updating…"})]});const n=e instanceof Error?e.message:typeof e=="string"?e:"";return l.jsxs("div",{className:"flex h-[100dvh] flex-col items-center justify-center gap-4 bg-surface px-6 text-center",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:"Something went wrong"}),l.jsx("p",{className:"mt-1 max-w-md text-sm text-fg-muted",children:"The app hit an unexpected error. Reloading usually fixes it."}),n?l.jsx("p",{className:"mt-2 max-w-md break-words font-mono text-2xs text-fg-subtle",children:n}):null]}),l.jsx("button",{className:"btn-primary",onClick:()=>window.location.reload(),children:"Reload"})]})}function zw(){typeof navigator>"u"||!("serviceWorker"in navigator)||window.addEventListener("load",()=>{const e=navigator.serviceWorker,t=!!e.controller;let n=!1;e.addEventListener("controllerchange",()=>{n||!t||(n=!0,window.location.reload())}),e.register("/sw.js").catch(()=>{})})}const Dt=4.5,mm=3,Tt=.12,gm=["--accent","--accent-600","--accent-700","--accent-solid","--accent-solid-hover","--accent-text"];function gt(e,t){const n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return null;const r=/^\d+(\.\d+)?( \d+(\.\d+)?){2}$/.test(n)?`rgb(${n})`:n;try{return Cn(r,{})}catch{return null}}function Fw(e,t,n){let r=0,o=1;for(let s=0;s<32;s++){const i=(r+o)/2;et(Qr(i,t,n))<e?r=i:o=i}return(r+o)/2}function vm(e,t,n){if($d(e,t,n))return t;let r=0,o=t;for(let s=0;s<24;s++){const i=(r+o)/2;$d(e,i,n)?r=i:o=i}return r}function Ta(e,t,n,r,o){const s=et(r);let i=t,a=.5;for(let u=0;u<4;u++){const c=Fw(s,i,n);let d=o?0:c,f=o?c:1;for(let p=0;p<28;p++){const S=(d+f)/2,k=We(Qr(S,i,n),r)>=e;o?k?d=S:f=S:k?f=S:d=S}a=o?d:f,i=vm(a,t,n)}return{L:a,C:i,rgb:Qr(a,i,n)}}const Uw=.75;function $r(e,t,n,r,o,s=e){const i=Ta(e,t,n,r,o),a=f=>f.C>=t*Uw;if(a(i)||s>=e)return{...i,hit:We(i.rgb,r)>=e-.01};let u=s,c=e,d=Ta(s,t,n,r,o);for(let f=0;f<16;f++){const p=(u+c)/2,S=Ta(p,t,n,r,o);a(S)?(d=S,u=p):c=p}return{...d,hit:We(d.rgb,r)>=s-.01}}function ba({r:e,g:t,b:n}){const r=o=>Math.round(Math.max(0,Math.min(1,o))*255);return`${r(e)} ${r(t)} ${r(n)}`}const ym=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected","--border-subtle","--border","--border-strong","--text","--text-muted","--text-subtle","--scroll-thumb"],of=["--text","--text-muted","--text-subtle"],Bw=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected"];function xm(e=document.documentElement){for(const t of ym)e.style.removeProperty(t)}function Ww(e,t,n=document.documentElement){xm(n);for(const o of ym){const s=gt(n,o);if(!s)continue;const{L:i,C:a}=tn(s),u=of.includes(o),c=Math.max(a,t*(u?.5:1));n.style.setProperty(o,Gt(Qr(i,vm(i,c,e),e)))}let r=1/0;for(const o of of){const s=gt(n,o);if(s)for(const i of Bw){const a=gt(n,i);a&&(r=Math.min(r,We(s,a)))}}return r}function wm(e=document.documentElement){for(const t of gm)e.style.removeProperty(t)}function Sm(e,t){const n=gm.map(r=>[r,e.style.getPropertyValue(r)]);wm(e);try{return t()}finally{for(const[r,o]of n)o&&e.style.setProperty(r,o)}}function Hw(e=document.documentElement){return Sm(e,()=>{const t=gt(e,"--accent");return t?tn(t).H:0})}const ho={r:1,g:1,b:1,a:1};function km(e=document.documentElement){return Sm(e,()=>Vw(e))}function Vw(e){const t={accent:gt(e,"--accent")??ho,a600:gt(e,"--accent-600")??ho,a700:gt(e,"--accent-700")??ho},n=gt(e,"--accent-fg")??ho,r=gt(e,"--surface")??ho,o=["--surface","--surface-raised","--surface-sunken"].map(a=>gt(e,a)).filter(a=>a!==null),s=o.length?o:[r],i=s.reduce((a,u)=>We(t.a700,a)<We(t.a700,u)?a:u);return{fg:n,surface:r,surfaces:s,targets:{accent:Math.max(We(t.accent,r),mm+Tt),a600:Math.max(We(t.a600,n),Dt+Tt),a700:Math.max(s.reduce((a,u)=>Math.min(a,We(t.a700,u)),1/0),Dt+Tt)},chroma:{accent:tn(t.accent).C,a600:tn(t.a600).C,a700:tn(t.a700).C},darker:{accent:et(t.accent)<et(r),a600:et(n)>et(t.a600),a700:et(t.a700)<et(i)},a700Bg:i}}function Kw(e,t){const n=Dt+Tt;return{accent:$r(e.targets.accent,e.chroma.accent,t,e.surface,e.darker.accent,mm+Tt),a600:$r(e.targets.a600,e.chroma.a600,t,e.fg,e.darker.a600,n),a700:$r(e.targets.a700,e.chroma.a700,t,e.a700Bg,e.darker.a700,n)}}function xk(e,t=document.documentElement){const n=km(t);return e.map(r=>Gt($r(n.targets.a600,n.chroma.a600,r,n.fg,n.darker.a600,Dt+Tt).rgb))}function Qw(e,t=document.documentElement,n={}){const r=t.classList.contains("dark")?"dark":"light",o=n.context??km(t),s=Kw(o,e),{a600:i,a700:a,accent:u}=s,c={C:o.chroma.a700};wm(t),t.style.setProperty("--accent",ba(u.rgb)),t.style.setProperty("--accent-600",ba(i.rgb)),t.style.setProperty("--accent-700",ba(a.rgb));const d={};for(const v of["--accent-fg","--accent-solid","--accent-solid-hover","--accent-text","--surface","--surface-raised","--surface-sunken","--accent-soft"])d[v]=gt(t,v);const f=[],p=d["--accent-fg"]??o.fg,S=(v,E,T)=>{const R=d[v];if(!R)return 1/0;let M=We(R,p),y=!1;if(M<T+Tt){const{C:D}=tn(R),b=$r(T+Tt,Math.max(D,o.chroma.a600),e,p,et(R)<et(p),Dt+Tt);t.style.setProperty(v,Gt(b.rgb)),M=We(b.rgb,p),y=!0}return f.push({label:E,fg:"--accent-fg",bg:v,ratio:M,floor:T,repaired:y}),M},k=S("--accent-solid","Primary button",Dt);S("--accent-solid-hover","Primary button, hovered",Math.min(k+.6,12));const g=[];for(const v of["--surface","--surface-raised","--surface-sunken","--accent-soft"]){const E=d[v];E&&g.push({name:v,c:E})}let C=1/0;const m=d["--accent-text"];if(m&&g.length){const v=g.reduce((T,R)=>We(m,T.c)<We(m,R.c)?T:R,g[0]);C=We(m,v.c);let E=!1;if(C<Dt+Tt){const{C:T}=tn(m),R=$r(Dt+Tt,T||c.C,e,v.c,et(m)<et(v.c));t.style.setProperty("--accent-text",Gt(R.rgb)),C=g.reduce((M,y)=>Math.min(M,We(R.rgb,y.c)),1/0),E=!0}f.push({label:"Accent text",fg:"--accent-text",bg:v.name,ratio:C,floor:Dt,repaired:E})}const h={};if(!n.live)for(const v of["--accent-solid","--accent-solid-hover","--accent-text"]){const E=gt(t,v);E&&(h[v]=Gt(E))}return{hue:e,mode:r,channels:{accent:Gt(u.rgb),accent600:Gt(i.rgb),accent700:Gt(a.rgb)},applied:h,checks:f,ok:f.every(v=>v.ratio>=v.floor-.005)&&k>=Dt}}const Gw=[{id:"foundation",label:"Foundation",blurb:"The neutral base. Warm ground, terracotta accent."},{id:"parchment",label:"Parchment",blurb:"Wine chrome, corner brackets, an old-style serif. A 90s RPG menu."},{id:"terminal",label:"Terminal",blurb:"Green phosphor and ANSI in the dark; greenbar and ribbon ink in the light."},{id:"scifi",label:"Sci-Fi",blurb:"Deep-space ground and luminous cyan. Hairlines, telemetry, glow."}],wk=[{name:"Ember",hue:40},{name:"Amber",hue:75},{name:"Olive",hue:110},{name:"Forest",hue:148},{name:"Teal",hue:190},{name:"Sky",hue:235},{name:"Indigo",hue:268},{name:"Violet",hue:300},{name:"Magenta",hue:330},{name:"Rose",hue:12}],Sk=[{level:0,label:"None"},{level:1,label:"A little"},{level:2,label:"More"}];function Yw(e=document.documentElement){const t=Hp().accent;if(t&&t.toLowerCase()!==An.accent.toLowerCase())try{return tn(Cn(t,{})).H}catch{}return Hw(e)}const sf={theme:"foundation",hue:null,tint:0},jm="paddock:appearance",af="paddock:appearance-cache";function Jw(){try{const e=localStorage.getItem(jm);if(!e)return sf;const t=JSON.parse(e);return{theme:Gw.some(n=>n.id===t.theme)?t.theme:"foundation",hue:typeof t.hue=="number"?(t.hue%360+360)%360:null,tint:t.tint===1||t.tint===2?t.tint:0}}catch{return sf}}function Xw(e){try{localStorage.setItem(jm,JSON.stringify(e))}catch{}}function Zw(e,t,n){try{const r=JSON.parse(localStorage.getItem(af)||"{}"),o=`${e}:${t?"dark":"light"}`;n?r[o]={...n.applied,"--accent":n.channels.accent}:delete r[o],localStorage.setItem(af,JSON.stringify(r))}catch{}}function qw(e,t=document.documentElement){t.setAttribute("data-theme",e.theme);const n=e.hue??Yw(t);let r=null;e.tint===0?xm(t):r=Ww(n,rS[e.tint],t);const o=Qw(n,t);return o&&r!==null&&(o.checks.push({label:"Body text on the tinted ground",fg:"--text-*",bg:"--surface-*",ratio:r,floor:4.5,repaired:!1}),o.ok=o.ok&&r>=4.5),Zw(e.theme,t.classList.contains("dark"),o),o}function eS(e,t){Xw(e);const n=qw(e,t);return window.dispatchEvent(new CustomEvent(tS,{detail:n})),n}const tS="paddock:appearance";function nS(){const e=()=>eS(Jw());e();const t=new MutationObserver(n=>{n.some(r=>r.attributeName==="class")&&e()});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()}const rS=[0,.008,.018],Em=x.lazy(()=>Zt(()=>import("./ProjectsGrid-BihtN69c.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.ProjectsGrid}))),Te=x.lazy(()=>Zt(()=>import("./ProjectView-JuOCBGKC.js").then(e=>e.a),__vite__mapDeps([4,5,1,2,6,7,3])).then(e=>({default:e.ProjectView}))),oS=x.lazy(()=>Zt(()=>import("./ProjectRedirect-CWAQx9Uc.js"),__vite__mapDeps([8,2])).then(e=>({default:e.ProjectRedirect}))),sS=x.lazy(()=>Zt(()=>import("./InstanceConfigPage-bpZrpumd.js"),__vite__mapDeps([9,6,3])).then(e=>({default:e.InstanceConfigPage}))),iS=x.lazy(()=>Zt(()=>import("./DiscoverPage-LE2yFc0F.js"),__vite__mapDeps([10,7,6,3])).then(e=>({default:e.DiscoverPage}))),aS=x.lazy(()=>Zt(()=>import("./RootHome-Bw3ZuHAb.js"),__vite__mapDeps([11,4,5,1,2,6,7,3])).then(e=>({default:e.RootHome})));nS();const Nm=()=>document.documentElement.setAttribute("data-tab-hidden",document.hidden?"true":"false");document.addEventListener("visibilitychange",Nm);Nm();function lS(){const{tag:e}=w0();return l.jsx(Em,{filterTag:e?decodeURIComponent(e):void 0})}const uS=F0([{path:"/",element:l.jsx(Rw,{}),errorElement:l.jsx(Aw,{}),children:[{index:!0,element:l.jsx(aS,{})},{path:"projects",element:l.jsx(Em,{})},{path:"tags/:tag",element:l.jsx(lS,{})},{path:"projects/:slug",element:l.jsx(oS,{})},{path:"projects/:slug/home",element:l.jsx(Te,{})},{path:"projects/:slug/chat",element:l.jsx(Te,{})},{path:"projects/:slug/chat/:sessionId",element:l.jsx(Te,{})},{path:"projects/:slug/files",element:l.jsx(Te,{})},{path:"projects/:slug/files/*",element:l.jsx(Te,{})},{path:"projects/:slug/changes",element:l.jsx(Te,{})},{path:"projects/:slug/changes/:file",element:l.jsx(Te,{})},{path:"projects/:slug/history",element:l.jsx(Te,{})},{path:"projects/:slug/settings",element:l.jsx(Te,{})},{path:"projects/:slug/triggers",element:l.jsx(Te,{})},{path:"projects/:slug/hooks",element:l.jsx(Te,{})},{path:"chat",element:l.jsx(Te,{root:!0})},{path:"chat/:sessionId",element:l.jsx(Te,{root:!0})},{path:"files",element:l.jsx(Te,{root:!0})},{path:"files/*",element:l.jsx(Te,{root:!0})},{path:"changes",element:l.jsx(Te,{root:!0})},{path:"changes/:file",element:l.jsx(Te,{root:!0})},{path:"history",element:l.jsx(Te,{root:!0})},{path:"triggers",element:l.jsx(Te,{root:!0})},{path:"settings",element:l.jsx(Te,{root:!0})},{path:"config",element:l.jsx(sS,{})},{path:"discover",element:l.jsx(iS,{})}]}]);Ra.createRoot(document.getElementById("root")).render(l.jsx(wf.StrictMode,{children:l.jsx(sx,{children:l.jsx(G0,{router:uS})})}));zw();export{$S as $,K1 as A,uk as B,BS as C,wk as D,Sk as E,wm as F,Qw as G,km as H,jt as I,m1 as J,FS as K,ts as L,tk as M,fS as N,Sw as O,rk as P,Jd as Q,_u as R,XS as S,nk as T,OS as U,Xt as V,G1 as W,Hi as X,zS as Y,$n as Z,AS as _,ar as a,yS as a$,dS as a0,Q1 as a1,V1 as a2,vk as a3,VS as a4,fk as a5,rm as a6,pk as a7,cS as a8,GS as a9,JS as aA,Wu as aB,US as aC,dk as aD,hk as aE,sk as aF,Iu as aG,Bu as aH,qS as aI,jS as aJ,im as aK,HS as aL,Tw as aM,ES as aN,ck as aO,mk as aP,lk as aQ,gk as aR,wS as aS,SS as aT,Gx as aU,Qx as aV,kS as aW,Z1 as aX,gS as aY,hS as aZ,Up as a_,QS as aa,ok as ab,ZS as ac,X1 as ad,KS as ae,PS as af,TS as ag,LS as ah,RS as ai,bS as aj,MS as ak,IS as al,_S as am,qx as an,y1 as ao,WS as ap,Xx as aq,Ea as ar,NS as as,Zt as at,ik as au,ak as av,Oi as aw,DS as ax,rx as ay,CS as az,Zd as b,cr as b0,pS as b1,mS as b2,Pw as b3,vS as b4,yk as b5,Ye as c,Wp as d,g1 as e,uf as f,Hp as g,es as h,W1 as i,l as j,ww as k,nx as l,Yx as m,ek as n,Bx as o,yi as p,xS as q,x as r,Ux as s,YS as t,w0 as u,Jw as v,eS as w,tS as x,xk as y,Gw as z};
71
71