@edspencer/paddock 0.80.0 → 0.81.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 (97) hide show
  1. package/package.json +1 -1
  2. package/packages/server/dist/app.d.ts +7 -0
  3. package/packages/server/dist/app.js +1 -1
  4. package/packages/server/dist/auth.d.ts +3 -2
  5. package/packages/server/dist/auth.js +11 -0
  6. package/packages/server/dist/background-live.d.ts +17 -0
  7. package/packages/server/dist/background-live.js +24 -0
  8. package/packages/server/dist/busy.d.ts +96 -0
  9. package/packages/server/dist/busy.js +88 -0
  10. package/packages/server/dist/cli/args.d.ts +20 -4
  11. package/packages/server/dist/cli/args.js +120 -7
  12. package/packages/server/dist/cli/busy-command.d.ts +58 -0
  13. package/packages/server/dist/cli/busy-command.js +108 -0
  14. package/packages/server/dist/cli/busy.d.ts +69 -0
  15. package/packages/server/dist/cli/busy.js +150 -0
  16. package/packages/server/dist/cli/output.d.ts +52 -0
  17. package/packages/server/dist/cli/output.js +84 -0
  18. package/packages/server/dist/cli/paddock.js +16 -2
  19. package/packages/server/dist/cli/service/index.d.ts +12 -0
  20. package/packages/server/dist/cli/service/index.js +38 -4
  21. package/packages/server/dist/cli/service/launchd.d.ts +15 -1
  22. package/packages/server/dist/cli/service/launchd.js +116 -18
  23. package/packages/server/dist/herdctl.d.ts +19 -0
  24. package/packages/server/dist/herdctl.js +26 -0
  25. package/packages/server/dist/routes/meta.js +45 -0
  26. package/packages/server/dist/runtime-file.d.ts +26 -0
  27. package/packages/server/dist/runtime-file.js +91 -0
  28. package/packages/server/dist/start.d.ts +33 -0
  29. package/packages/server/dist/start.js +115 -8
  30. package/packages/server/dist/ws-context.d.ts +9 -0
  31. package/packages/server/dist/ws-turn.js +1 -0
  32. package/packages/server/package.json +1 -1
  33. package/packages/web/dist/assets/{DeleteProjectDialog-DHczLhwQ.js → DeleteProjectDialog-D8oIJ8HC.js} +1 -1
  34. package/packages/web/dist/assets/DiscoverPage-CQlzxsn4.js +2 -0
  35. package/packages/web/dist/assets/{DiscoverView-DtTOpTji.js → DiscoverView-o0KCr3aB.js} +1 -1
  36. package/packages/web/dist/assets/{InstanceConfigPage-BRoBh1C1.js → InstanceConfigPage-RSJz7oL3.js} +1 -1
  37. package/packages/web/dist/assets/{MarkdownRenderer-DJf8IJuk.js → MarkdownRenderer-39mafH8b.js} +1 -1
  38. package/packages/web/dist/assets/{ProjectRedirect-EioguUKW.js → ProjectRedirect-Bq7GVguY.js} +1 -1
  39. package/packages/web/dist/assets/{ProjectView-BiKnGfk6.js → ProjectView-BoBIru1g.js} +3 -3
  40. package/packages/web/dist/assets/{ProjectsGrid-D6kfaIal.js → ProjectsGrid-mJ4gqbr6.js} +1 -1
  41. package/packages/web/dist/assets/{RootHome-DpcyuV6e.js → RootHome-C0kwFyYp.js} +1 -1
  42. package/packages/web/dist/assets/{Surfaces-CHM29PhP.js → Surfaces-MkhXlB8z.js} +1 -1
  43. package/packages/web/dist/assets/{arc-fiqD05Hu.js → arc-DExlwAwO.js} +1 -1
  44. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-BuuB2Nkf.js → architectureDiagram-3BPJPVTR-CZly3W79.js} +1 -1
  45. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DQMBuzfi.js → blockDiagram-GPEHLZMM-AgES73i3.js} +1 -1
  46. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-BKN0UxCH.js → c4Diagram-AAUBKEIU-N9mD8Pfk.js} +1 -1
  47. package/packages/web/dist/assets/channel-ExsAG7qT.js +2 -0
  48. package/packages/web/dist/assets/{chunk-2J33WTMH-DW37EupX.js → chunk-2J33WTMH-Dsx_kfUl.js} +1 -1
  49. package/packages/web/dist/assets/{chunk-4BX2VUAB-Dyv7zV_c.js → chunk-4BX2VUAB-BQjqcjPj.js} +1 -1
  50. package/packages/web/dist/assets/{chunk-55IACEB6-DzMR0dOk.js → chunk-55IACEB6-CCxpYQpY.js} +1 -1
  51. package/packages/web/dist/assets/{chunk-727SXJPM-BdZ3Sor8.js → chunk-727SXJPM-DpFRdnUa.js} +1 -1
  52. package/packages/web/dist/assets/{chunk-AQP2D5EJ-B4i7_og0.js → chunk-AQP2D5EJ-D2BAlzoO.js} +1 -1
  53. package/packages/web/dist/assets/{chunk-FMBD7UC4-jcTr85it.js → chunk-FMBD7UC4-BFaMRzUF.js} +1 -1
  54. package/packages/web/dist/assets/{chunk-ND2GUHAM-fgMsadqB.js → chunk-ND2GUHAM-B9NGJ9xZ.js} +1 -1
  55. package/packages/web/dist/assets/{chunk-QZHKN3VN-bJNHYS1W.js → chunk-QZHKN3VN-CF1IHyMS.js} +1 -1
  56. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-si7g9okq.js +2 -0
  57. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-si7g9okq.js +2 -0
  58. package/packages/web/dist/assets/{core-Bk4KFrmN.js → core-XjElsvQ7.js} +1 -1
  59. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BIqCSlQy.js → cose-bilkent-S5V4N54A-CF972Flx.js} +1 -1
  60. package/packages/web/dist/assets/{dagre-BM42HDAG-6nyhtVQz.js → dagre-BM42HDAG-DsneI8YE.js} +1 -1
  61. package/packages/web/dist/assets/{diagram-2AECGRRQ-CjizfipR.js → diagram-2AECGRRQ-BHyrVzIk.js} +1 -1
  62. package/packages/web/dist/assets/{diagram-5GNKFQAL-DlgB5vWb.js → diagram-5GNKFQAL-Dj4q8xEi.js} +1 -1
  63. package/packages/web/dist/assets/{diagram-KO2AKTUF-CNC9qanV.js → diagram-KO2AKTUF-BHe3Puv_.js} +1 -1
  64. package/packages/web/dist/assets/{diagram-LMA3HP47-DSJ-s9lh.js → diagram-LMA3HP47-wzt6G2FE.js} +1 -1
  65. package/packages/web/dist/assets/{diagram-OG6HWLK6-C9FoHBDg.js → diagram-OG6HWLK6-CZMbMRJq.js} +1 -1
  66. package/packages/web/dist/assets/{documentTitle-Cj_AY97j.js → documentTitle-BwTIA8rI.js} +1 -1
  67. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-z6gku4Yt.js → erDiagram-TEJ5UH35-Dtu14BL1.js} +1 -1
  68. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-Dl5c_FgU.js → flowDiagram-I6XJVG4X-T34ql9j0.js} +1 -1
  69. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-CIscJ-Dt.js → ganttDiagram-6RSMTGT7-DQLOeCXK.js} +1 -1
  70. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-CvttOXM_.js → gitGraphDiagram-PVQCEYII-Bk11zea6.js} +1 -1
  71. package/packages/web/dist/assets/{index-DN82do6Z.js → index-CvaWErFv.js} +2 -2
  72. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-dzWYdDJj.js → infoDiagram-5YYISTIA-CsE83lu0.js} +1 -1
  73. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-8yX9k4bo.js → ishikawaDiagram-YF4QCWOH-DNVgA93n.js} +1 -1
  74. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-BmitzJDR.js → journeyDiagram-JHISSGLW-CLpSNjM3.js} +1 -1
  75. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-BZmIkfkW.js → kanban-definition-UN3LZRKU-BRzuXcKr.js} +1 -1
  76. package/packages/web/dist/assets/{linear-BBLXE4o7.js → linear-BxOawONt.js} +1 -1
  77. package/packages/web/dist/assets/{mermaid.core-mSKff4yu.js → mermaid.core-Dvs1QCcz.js} +4 -4
  78. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-BWAUa4CP.js → mindmap-definition-RKZ34NQL-Dmt7pYwF.js} +1 -1
  79. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-VmVdiL4C.js → pieDiagram-4H26LBE5-BHiZaJD-.js} +1 -1
  80. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-Dybfv6NU.js → quadrantDiagram-W4KKPZXB-U0A1noRE.js} +1 -1
  81. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-BPnOvB7w.js → requirementDiagram-4Y6WPE33-CZLsr6yi.js} +1 -1
  82. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-YXIEmKw7.js → sankeyDiagram-5OEKKPKP-BTlLGILU.js} +1 -1
  83. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-DintIRUe.js → sequenceDiagram-3UESZ5HK-DpSS_Gb1.js} +1 -1
  84. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-eMsjahWp.js → stateDiagram-AJRCARHV-D9srE-tV.js} +1 -1
  85. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-AxWqsDh-.js +2 -0
  86. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-as4zRCPn.js → timeline-definition-PNZ67QCA-BYQ5CKab.js} +1 -1
  87. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-CPzvUkM0.js → vennDiagram-CIIHVFJN-B4W2CtSV.js} +1 -1
  88. package/packages/web/dist/assets/{wardley-L42UT6IY-q6moXj5g.js → wardley-L42UT6IY--XUV7GvD.js} +1 -1
  89. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-BsEEb9Gm.js → wardleyDiagram-YWT4CUSO-Bl2VIEGY.js} +1 -1
  90. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-DSgZlcZW.js → xychartDiagram-2RQKCTM6-Bj2H9Rcf.js} +1 -1
  91. package/packages/web/dist/index.html +1 -1
  92. package/packages/web/dist/sw.js +1 -1
  93. package/packages/web/dist/assets/DiscoverPage-BSGSzTEs.js +0 -2
  94. package/packages/web/dist/assets/channel-B7yh6Su_.js +0 -2
  95. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DIlhMPgi.js +0 -2
  96. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DIlhMPgi.js +0 -2
  97. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-CpAOGzbO.js +0 -2
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectsGrid-D6kfaIal.js","assets/DeleteProjectDialog-DHczLhwQ.js","assets/lastTab-CU1zsF0j.js","assets/documentTitle-Cj_AY97j.js","assets/ProjectView-BiKnGfk6.js","assets/queued-CagZVfWU.js","assets/Surfaces-CHM29PhP.js","assets/DiscoverView-DtTOpTji.js","assets/ProjectRedirect-EioguUKW.js","assets/InstanceConfigPage-BRoBh1C1.js","assets/DiscoverPage-BSGSzTEs.js","assets/RootHome-DpcyuV6e.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectsGrid-mJ4gqbr6.js","assets/DeleteProjectDialog-D8oIJ8HC.js","assets/lastTab-CU1zsF0j.js","assets/documentTitle-BwTIA8rI.js","assets/ProjectView-BoBIru1g.js","assets/queued-CagZVfWU.js","assets/Surfaces-MkhXlB8z.js","assets/DiscoverView-o0KCr3aB.js","assets/ProjectRedirect-Bq7GVguY.js","assets/InstanceConfigPage-RSJz7oL3.js","assets/DiscoverPage-CQlzxsn4.js","assets/RootHome-C0kwFyYp.js"])))=>i.map(i=>d[i]);
2
2
  function df(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 Qm="modulepreload",Gm=function(e){return"/"+e},uc={},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=Gm(u),u in uc)return;uc[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":Qm,c||(f.as="script"),f.crossOrigin="",f.href=u,a&&f.setAttribute("nonce",a),document.head.appendChild(f),c)return new Promise((h,w)=>{f.addEventListener("load",h),f.addEventListener("error",()=>w(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 kS=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ff(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var hf={exports:{}},wi={},pf={exports:{}},ee={};/**
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 Qr(){return Qr=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},Qr.apply(this,arguments)}function Wp(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 F0(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function U0(e,t){return e.button===0&&(!t||t==="_self")&&!F0(e)}const B0=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],W0=["aria-current","caseSensitive","className","end","style","to","unstable_viewTransition","children"],H0="6";try{window.__reactRouterVersion=H0}catch{}function V0(e,t){return Zy({basename:void 0,future:Qr({},void 0,{v7_prependBasename:!0}),history:jy({window:void 0}),hydrationData:K0(),routes:e,mapRouteProperties:z0,unstable_dataStrategy:void 0,unstable_patchRoutesOnNavigation:void 0,window:void 0}).initialize()}function K0(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Qr({},t,{errors:Q0(t.errors)})),t}function Q0(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 Hp=y.createContext({isTransitioning:!1}),G0=y.createContext(new Map),Y0="startTransition",Id=cg[Y0],J0="flushSync",Dd=ky[J0];function X0(e){Id?Id(e):e()}function fo(e){Dd?Dd(e):e()}class Z0{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 q0(e){let{fallbackElement:t,router:n,future:r}=e,[o,s]=y.useState(n.state),[i,a]=y.useState(),[u,c]=y.useState({isTransitioning:!1}),[d,f]=y.useState(),[h,w]=y.useState(),[k,g]=y.useState(),N=y.useRef(new Map),{v7_startTransition:m}=r||{},p=y.useCallback(x=>{m?X0(x):x()},[m]),v=y.useCallback((x,D)=>{let{deletedFetchers:b,unstable_flushSync:W,unstable_viewTransitionOpts:te}=D;b.forEach(fe=>N.current.delete(fe)),x.fetchers.forEach((fe,st)=>{fe.data!==void 0&&N.current.set(st,fe.data)});let ce=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!te||ce){W?fo(()=>s(x)):p(()=>s(x));return}if(W){fo(()=>{h&&(d&&d.resolve(),h.skipTransition()),c({isTransitioning:!0,flushSync:!0,currentLocation:te.currentLocation,nextLocation:te.nextLocation})});let fe=n.window.document.startViewTransition(()=>{fo(()=>s(x))});fe.finished.finally(()=>{fo(()=>{f(void 0),w(void 0),a(void 0),c({isTransitioning:!1})})}),fo(()=>w(fe));return}h?(d&&d.resolve(),h.skipTransition(),g({state:x,currentLocation:te.currentLocation,nextLocation:te.nextLocation})):(a(x),c({isTransitioning:!0,flushSync:!1,currentLocation:te.currentLocation,nextLocation:te.nextLocation}))},[n.window,h,d,N,p]);y.useLayoutEffect(()=>n.subscribe(v),[n,v]),y.useEffect(()=>{u.isTransitioning&&!u.flushSync&&f(new Z0)},[u]),y.useEffect(()=>{if(d&&i&&n.window){let x=i,D=d.promise,b=n.window.document.startViewTransition(async()=>{p(()=>s(x)),await D});b.finished.finally(()=>{f(void 0),w(void 0),a(void 0),c({isTransitioning:!1})}),w(b)}},[p,i,d,n.window]),y.useEffect(()=>{d&&i&&o.location.key===i.location.key&&d.resolve()},[d,h,o.location,i]),y.useEffect(()=>{!u.isTransitioning&&k&&(a(k.state),c({isTransitioning:!0,flushSync:!1,currentLocation:k.currentLocation,nextLocation:k.nextLocation}),g(void 0))},[u.isTransitioning,k]),y.useEffect(()=>{},[]);let E=y.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:x=>n.navigate(x),push:(x,D,b)=>n.navigate(x,{state:D,preventScrollReset:b==null?void 0:b.preventScrollReset}),replace:(x,D,b)=>n.navigate(x,{replace:!0,state:D,preventScrollReset:b==null?void 0:b.preventScrollReset})}),[n]),T=n.basename||"/",R=y.useMemo(()=>({router:n,navigator:E,static:!1,basename:T}),[n,E,T]),M=y.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return y.createElement(y.Fragment,null,y.createElement(es.Provider,{value:R},y.createElement(Mu.Provider,{value:o},y.createElement(G0.Provider,{value:N.current},y.createElement(Hp.Provider,{value:u},y.createElement(A0,{basename:T,location:o.location,navigationType:o.historyAction,navigator:E,future:M},o.initialized||n.future.v7_partialHydration?y.createElement(ex,{routes:n.routes,future:n.future,state:o}):t))))),null)}const ex=y.memo(tx);function tx(e){let{routes:t,future:n,state:r}=e;return N0(t,void 0,r,n)}const nx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",rx=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ns=y.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,h=Wp(t,B0),{basename:w}=y.useContext(cn),k,g=!1;if(typeof c=="string"&&rx.test(c)&&(k=c,nx))try{let v=new URL(window.location.href),E=c.startsWith("//")?new URL(v.protocol+c):new URL(c),T=ln(E.pathname,w);E.origin===v.origin&&T!=null?c=T+E.search+E.hash:g=!0}catch{}let N=S0(c,{relative:o}),m=sx(c,{replace:i,state:a,target:u,preventScrollReset:d,relative:o,unstable_viewTransition:f});function p(v){r&&r(v),v.defaultPrevented||m(v)}return y.createElement("a",Qr({},h,{href:k||N,onClick:g||s?r:p,ref:n,target:u}))}),yn=y.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=Wp(t,W0),h=Fi(u,{relative:f.relative}),w=Wn(),k=y.useContext(Mu),{navigator:g,basename:N}=y.useContext(cn),m=k!=null&&ix(h)&&c===!0,p=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=w.pathname,E=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;o||(v=v.toLowerCase(),E=E?E.toLowerCase():null,p=p.toLowerCase()),E&&N&&(E=ln(E,N)||E);const T=p!=="/"&&p.endsWith("/")?p.length-1:p.length;let R=v===p||!i&&v.startsWith(p)&&v.charAt(T)==="/",M=E!=null&&(E===p||!i&&E.startsWith(p)&&E.charAt(p.length)==="/"),x={isActive:R,isPending:M,isTransitioning:m},D=R?r:void 0,b;typeof s=="function"?b=s(x):b=[s,R?"active":null,M?"pending":null,m?"transitioning":null].filter(Boolean).join(" ");let W=typeof a=="function"?a(x):a;return y.createElement(ns,Qr({},f,{"aria-current":D,className:b,ref:n,style:W,to:u,unstable_viewTransition:c}),typeof d=="function"?d(x):d)});var Cl;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Cl||(Cl={}));var Od;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Od||(Od={}));function ox(e){let t=y.useContext(es);return t||X(!1),t}function sx(e,t){let{target:n,replace:r,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a}=t===void 0?{}:t,u=ts(),c=Wn(),d=Fi(e,{relative:i});return y.useCallback(f=>{if(U0(f,n)){f.preventDefault();let h=r!==void 0?r:ar(c)===ar(d);u(e,{replace:h,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a})}},[c,u,d,r,o,n,e,s,i,a])}function ix(e,t){t===void 0&&(t={});let n=y.useContext(Hp);n==null&&X(!1);let{basename:r}=ox(Cl.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 Go(o.pathname,i)!=null||Go(o.pathname,s)!=null}const Iu="";function Du(e){return e===Iu}function K(e){return Du(e)?"/api/root":`/api/projects/${encodeURIComponent(e)}`}function Vp(e){return Du(e)?"":`/projects/${e}`}function CS(e){return e===""?"/":`${e}/home`}function ax(){return"/projects"}function NS(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 PS(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 lx(e){return`m-${e}`}function TS(e,t,n){return`${e}/chat/${encodeURIComponent(t)}#${lx(n)}`}function bS(e){var t;return(t=/^#?m-([0-9a-fA-F][0-9a-fA-F-]{7,})$/.exec(e))==null?void 0:t[1]}const Yn="";async function U(e,t){const n=await fetch(`${Yn}${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 ux(e,t){const n=await fetch(`${Yn}${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 $d={transcriptRenderLimit:500};let Ad=null;const lr={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(`${Yn}${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`${Yn}${K(e)}/files/${encodeURIComponent(t)}?raw=1`},chatFileRawUrl(e){return`${Yn}/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 Ad??(Ad=lr.getModels().then(e=>e.uiDefault??$d).catch(()=>$d)),Ad},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 ux(`${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`${Yn}${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(`${Yn}/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)})}},Kp=y.createContext(null);function cx({children:e}){const[t,n]=y.useState([]),[r,o]=y.useState(null),[s,i]=y.useState(!0),[a,u]=y.useState(null),c=y.useRef(!1),d=y.useCallback(async()=>{c.current||i(!0),u(null);try{const{projects:k,root:g}=await lr.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=y.useCallback(k=>{if(Du(k.slug)){o(k);return}n(g=>[k,...g.filter(N=>N.slug!==k.slug)])},[]),h=y.useCallback(k=>{n(g=>g.filter(N=>N.slug!==k))},[]);y.useEffect(()=>{d()},[d]);const w=y.useMemo(()=>({projects:t,rootWorkspace:r,loading:s,error:a,refresh:d,upsert:f,remove:h}),[t,r,s,a,d,f,h]);return l.jsx(Kp.Provider,{value:w,children:e})}function Qp(){const e=y.useContext(Kp);if(!e)throw new Error("useProjects must be used within ProjectsProvider");return e}const dx="paddock:theme";function fx(){return typeof document<"u"&&document.documentElement.classList.contains("dark")}function hx(){const[e,t]=y.useState(fx),n=y.useCallback(()=>{t(r=>{const o=!r;document.documentElement.classList.toggle("dark",o);try{localStorage.setItem(dx,o?"dark":"light")}catch{}return o})},[]);return{dark:e,toggle:n}}const An={name:"Paddock",logo:"🐎",accent:"#c2603c"},px={running:"#f97316",unread:"#22c55e"},mx={enabled:!1,path:"/open-api"};function Gp(){const e=globalThis.__PADDOCK_CONFIG__;return{...An,...(e==null?void 0:e.brand)??{}}}function gx(){const e=globalThis.__PADDOCK_CONFIG__;return{...mx,...(e==null?void 0:e.openapi)??{}}}function Yp(e){return/^(https?:\/\/|\/)/i.test(e.trim())}const Ou=e=>e<0?0:e>1?1:e;function $u(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 Au({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 Nl(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 Gr(e,t,n,r=1){const o=n*Math.PI/180,s=Au({L:e,a:t*Math.cos(o),b:t*Math.sin(o)}),[i,a,u]=s.map(c=>Ou($u(c)));return{r:i,g:a,b:u,a:r}}function zd(e,t,n){const r=n*Math.PI/180;return Au({L:e,a:t*Math.cos(r),b:t*Math.sin(r)}).map($u).every(o=>o>=-.0015&&o<=1.0015)}function Gt({r:e,g:t,b:n}){const r=o=>Math.round(Ou(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 vx(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(vx(e,t)),r=et(t),[o,s]=n>r?[n,r]:[r,n];return(o+.05)/(s+.05)}const Fd={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 gr(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 Nn(e,t,n=0){if(n>24)throw new Error(`var() cycle resolving ${e}`);const r=e.trim();if(Fd[r])return Fd[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=gr(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 Nn(d,t,n+1)}const s=gr(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 Gr(gn(d[0]),gn(d[1]),gn(d[2]),c?gn(c.trim()):1)}const i=gr(r,"rgb")??gr(r,"rgba");if(i!==null){const u=i.trim(),c=gr(u,"var");if(c!==null){const[w]=ja(c),k=t[w];if(!k)throw new Error(`undefined custom property: ${w}`);return Nn(`rgb(${k})`,t,n+1)}const[d,f]=u.split("/"),h=d.trim().split(/[\s,]+/);if(h.length<3)throw new Error(`bad rgb(): ${r}`);return{r:gn(h[0])/255,g:gn(h[1])/255,b:gn(h[2])/255,a:f?gn(f.trim()):1}}const a=gr(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 h=Ud(c),w=Ud(d);let k=h.pct,g=w.pct;k===null&&g===null?(k=.5,g=.5):k===null?k=1-g:g===null&&(g=1-k);const N=k+g,m=k/N,p=Nn(h.color,t,n+1),v=Nn(w.color,t,n+1);return f==="in srgb"?yx(p,v,m):xx(p,v,m)}throw new Error(`unsupported colour value: ${r}`)}function Ud(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 yx(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 xx(e,t,n){const r=Nl(It(e.r),It(e.g),It(e.b)),o=Nl(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]=Au(s).map(c=>Ou($u(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}=Nl(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 wx=[[.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]],rs=Object.freeze(wx.map(([e,t,n])=>Gt(Gr(e,t,n)))),Bd=rs.map(e=>{const{L:t,C:n,H:r}=tn(Nn(e,{})),o=r*Math.PI/180;return{L:t,a:n*Math.cos(o),b:n*Math.sin(o)}});function Sx(e,t){const n=Bd[e],r=Bd[t];return Math.hypot(n.L-r.L,n.a-r.a,n.b-r.b)}function kx(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 Jp(e){return kx(e.trim())%rs.length}function zu(e){return rs[Jp(e)]}const Ui=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function Fu(e){return!e||Ui(e,An.accent)}function jx(e){return Ui(e.name,An.name)&&e.logo.trim()===An.logo&&Fu(e.accent)}function Uu(e){try{return Nn(e,{})}catch{return null}}function Ex(e){return!Fu(e.accent)&&Uu(e.accent)?e.accent.trim():Ui(e.name,An.name)?An.accent:zu(e.name)}function Cx(e){return!Fu(e.accent)&&Uu(e.accent)||Ui(e.name,An.name)?null:zu(e.name)}function Bu(e,t=4.5){const n=Uu(e);return n?We({r:1,g:1,b:1,a:1},n)>=t?"white":"black":"white"}const Pl={small:16,large:32},Nx=.22,Px=.76,Wd='"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, -apple-system, "Segoe UI", sans-serif';function Xp(e,t){const n=t*Nx;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 Tx(e,t,n){Xp(e,t),e.fillStyle=n,e.fill()}function Hd(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 bx(e,t,n,r){const o=t*Px;let s=o;e.font=`600 ${s}px ${Wd}`;let i=Hd(e,n);const a=Math.max(i.w,i.h);a>0&&(s=s*o/a,e.font=`600 ${s}px ${Wd}`,i=Hd(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 Rx(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(),Xp(e,t),e.clip(),e.drawImage(n,(t-i)/2,(t-a)/2,i,a),e.restore()}function Lx(e,t){const{content:n,size:r}=t;"glyph"in n?bx(e,r,n.glyph,t.foreground??"white"):"image"in n?Rx(e,r,n.image):e.drawImage(n.icon,0,0,r,r)}const Mx=.22,_x=.07;function Ix(e,t,n){const r=t*Mx,o=t-r;e.save(),e.globalCompositeOperation="destination-out",e.beginPath(),e.arc(o,o,r+t*_x,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||Tx(r,e.size,e.color),Lx(r,e),e.dot&&Ix(r,e.size,e.dot);const o=n.toDataURL("image/png");return o.startsWith("data:image/png")?o:null}catch{return null}}const Or="data-paddock-default-href",bl="data-paddock-default-type",vi="data-paddock-favicon";function Zp(e){return Array.from(e.head.querySelectorAll('link[rel~="icon"]'))}function Dx(e,t=document){let n=Zp(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(Or)&&!r.hasAttribute(vi)&&(r.setAttribute(Or,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 Vd(e=document){for(const t of Zp(e)){if(t.hasAttribute(vi)){t.remove();continue}if(!t.hasAttribute(Or))continue;t.setAttribute("href",t.getAttribute(Or)??"");const n=t.getAttribute(bl);n?t.setAttribute("type",n):t.removeAttribute("type"),t.removeAttribute(Or),t.removeAttribute(bl)}}function Ox(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(Or)??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 Kd(e,t,n){const r=Bu(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 $x(e){return(Array.from(e.trim())[0]??"P").toUpperCase()}function Ax(e,t){if(jx(e))return t({kind:"shipped"}),()=>{};const n=Ex(e),r=e.logo.trim(),o={glyph:$x(e.name)};if(!Yp(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 zx(e,t,n){const r=t?px[t]:void 0;switch(e.kind){case"shipped":return r?n().then(o=>o?Kd({icon:o},"transparent",r):null):null;case"chip":return Kd(e.content,e.color,r);case"raw":return{small:e.src,large:e.src}}}function Fx(e,t=null){const{name:n,logo:r,accent:o}=e,[s,i]=y.useState(null),a=y.useRef(new WeakMap),u=y.useRef(null);y.useEffect(()=>Ax({name:n,logo:r,accent:o},i),[n,r,o]),y.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?Dx(g):Vd()};if(d.has(c)){f(d.get(c)??null);return}const w=zx(s,t,()=>{if(!u.current){const g=Ox(),N=g?Rl(g,!1).catch(()=>(u.current===N&&(u.current=null),null)):Promise.resolve(null);u.current=N}return u.current});if(!(w instanceof Promise)){d.set(c,w),f(w);return}let k=!1;return w.then(g=>{g&&d.set(c,g),k||f(g)}),()=>{k=!0}},[s,t]),y.useEffect(()=>()=>Vd(),[])}const qp={running:!1,unread:0,kind:"none"};function Ux(e,{active:t,finished:n,hiddenSince:r}){if(!e)return qp;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 Bx(e){let t=e.running?"● ":"";return e.unread>0&&(t+=e.kind==="chat"?"✓ ":`(${e.unread}) `),t}function Wx(e){return e.running?"running":e.unread>0?"unread":null}function Hs(e){return e?e.kind==="chat"?`chat:${e.sessionId}:${e.unread?1:0}`:e.kind==="workspace"?`ws:${e.key}`:"instance":"none"}const em=y.createContext({status:qp,scopeKey:"none",setScope:()=>{}});function RS(e){const{status:t,scopeKey:n,setScope:r}=y.useContext(em),o=Hs(e),s=y.useMemo(()=>e,[o]);return y.useEffect(()=>{r(s)},[s,r]),y.useEffect(()=>()=>r(null),[r]),n===o?Bx(t):""}function Hx(){const[e,t]=y.useState(()=>typeof document<"u"&&document.visibilityState==="hidden"?Date.now():null);return y.useEffect(()=>{const n=()=>t(r=>document.visibilityState==="hidden"?r??Date.now():null);return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Vx(e){const[t,n]=y.useState(null),r=y.useCallback(u=>{n(c=>Hs(c)===Hs(u)?c:u)},[]),o=Hx(),s=Ux(t,{...e,hiddenSince:o}),i=Hs(t),a=`${i}|${s.kind}|${s.running?1:0}|${s.unread}`;return y.useMemo(()=>({status:s,scopeKey:i,setScope:r}),[a,r])}const Wu=[{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."}],Qd="",tm=new Map(Wu.map(e=>[e.slug,e]));function Kx(e){if(!e)return"Unsorted";const t=tm.get(e);return t?t.label:e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function LS(e){var t;return(t=tm.get(e))==null?void 0:t.blurb}function Qx(e){const t=new Set(e),n=[];for(const o of Wu)t.has(o.slug)&&(n.push(o.slug),t.delete(o.slug));const r=t.delete(Qd);return n.push(...[...t].sort()),r&&n.push(Qd),n}const nm=25e3,rm=1e4,Gx=nm+rm+5e3,Yx=500,Jx=1e4;class Xx{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<Gx}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(),nm)}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())},rm)}}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(Jx,Yx*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,h,w,k,g,N,m,p,v,E,T,R,M,x,D,b,W,te,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:Z}=n.payload;if(O&&Y&&se)for(const Ee of this.stopTaskListeners)Ee(O,{taskId:Y,outcome:se,message:Z});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);(h=O==null?void 0:(f=O.handlers).onResync)==null||h.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 Z of this.backgroundListeners)Z(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=(w=O.handlers).onActive)==null||k.call(w,{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:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{Z(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((N=(g=Z.handlers).onQueuedFlushed)==null||N.call(g,{text:Y,attachments:se}))}return}if(n.type==="chat:queued_state"){const{sessionId:O,text:Y,qid:se,reason:Z,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&&((p=(m=Ut.handlers).onQueuedState)==null||p.call(m,{text:ie,attachments:ze,qid:se,reason:Z}))}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:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{Z(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((E=(v=Z.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 Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((R=(T=Z.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":(x=(M=i.handlers).onResponse)==null||x.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":(te=(W=i.handlers).onToolStart)==null||te.call(W,{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 Hu=new Xx,nn=new Map,Ll="paddock:lastSeen-changed";function Vu(e){try{window.dispatchEvent(new CustomEvent(Ll,{detail:{sessionId:e}}))}catch{}}function Zx(e){return nn.get(e)??0}function qx(e,t){!t||!Number.isFinite(t)||t<=(nn.get(e)??0)||(nn.set(e,t),Vu(e))}function MS(e,t=Date.now()){const n=nn.get(e)??0;return t<=n||(nn.set(e,t),Vu(e)),n}function _S(e,t,n){nn.get(e)===n&&(t?nn.set(e,t):nn.delete(e),Vu(e))}const Ml="paddock:chats-gone";function IS(e){if(e.length!==0){for(const t of e)nn.delete(t);try{window.dispatchEvent(new CustomEvent(Ml,{detail:{sessionIds:e}}))}catch{}}}const e1=/^\d{4}-\d{2}-\d{2}$/;function yi(e){if(!e)return"";if(e1.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 h=new Date,w=new Date(h.getFullYear(),h.getMonth(),h.getDate()),k=Math.round((w.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 DS(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 t1(e){return!Number.isFinite(e)||e<=0?"$0.00":e<.01?"<$0.01":`$${e.toFixed(2)}`}function OS(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 $S(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} · ~${t1(e.costUsd)} at API rates`}function AS(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 n1="This session is being continued from a previous conversation";function zS(e){return e.trimStart().startsWith(n1)}function FS(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 US(e){return e.trimStart().startsWith("<local-command-caveat>")}function BS(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 WS(e){return/^\s*<local-command-stdout>[\s\S]*<\/local-command-stdout>\s*$/.test(e)}function HS(e){return e.trimStart().startsWith("<task-notification>")}function VS(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 KS(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 QS(e){return e==="killed"||e==="stopped"}function r1(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 o1(){try{return localStorage.getItem(_l)==="1"}catch{return!1}}function Gd(e){try{e?localStorage.setItem(_l,"1"):localStorage.removeItem(_l)}catch{}}let xo=null;function s1(){if(!xo)try{xo=lr.transcriptsMigration().catch(()=>null)}catch{xo=Promise.resolve(null)}return xo}function i1(){xo=null}function om(){const[e,t]=y.useState(null),[n,r]=y.useState(o1);y.useEffect(()=>{let s=!0;return s1().then(i=>{!s||!i||(t(i),i&&!i.eligible&&(Gd(!1),r(!1)))}),()=>{s=!1}},[]);const o=y.useCallback(()=>{Gd(!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 a1(e){return new Set(Bi(e).filter(t=>t.defaultSelected).map(t=>t.sessionId))}function l1(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 u1(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 c1(e,t){return t?new Set(Bi(e).map(n=>n.sessionId)):new Set}function d1(e,t){const n=new Set(e);return n.delete(t)||n.add(t),n}function f1(e,t){const n=Bi(e).map(r=>r.sessionId);return{sessionIds:n.filter(r=>t.has(r)),plannedSessionIds:n,expectedVersion:e.configVersion}}function h1(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 sm(e){return e?e.projects.length===0&&e.sweepers.stores===0:!1}function im(e){return!e.ok||e.failed.length>0?"partial":e.alreadyMigrated?"already":e.migrated.length===0&&e.preserved.length===0?"nothing":"done"}function p1(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 m1={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 m1[e]??{label:String(e),hint:"This Paddock build does not recognise this state, so it is shown as the server described it."}}function Yd(e){const t=e.indexOf("/.claude/");return t===-1?e:`~${e.slice(t)}`}function g1(e,t){return t==="all"?!0:t==="needs-decision"?!e.defaultSelected:e.state===t}function Ye(...e){return e.filter(Boolean).join(" ")}const v1={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"},y1={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",y1[t],v1[e],i),...d,children:[n,r&&o?o:a]})}const Ku=["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 GS({className:e,...t}){return l.jsx("input",{className:Ye(Ku,e),...t})}function YS({className:e,...t}){return l.jsx("textarea",{className:Ye(Ku,"resize-y",e),...t})}function JS({className:e,...t}){return l.jsx("select",{className:Ye(Ku,e),...t})}function XS({checked:e,onChange:t,label:n,disabled:r,id:o,className:s}){const i=y.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 am({label:e,description:t,indeterminate:n=!1,className:r,...o}){const s=y.useRef(null);y.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 lm={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"},um={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 x1({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",lm[e],i),children:[r&&l.jsx("span",{className:Ye("h-1.5 w-1.5 shrink-0 rounded-full",um[e])}),o,a]})}function ZS({tone:e="neutral",pulse:t=!1,className:n}){return l.jsx("span",{className:Ye("inline-block h-2 w-2 shrink-0 rounded-full",um[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",lm[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 w1(e,t){y.useEffect(()=>{if(!e)return;const n=r=>{r.key==="Escape"&&t()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,t])}const S1={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl"};function k1({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 h=y.useRef(null),w=y.useRef(null);if(w1(e,t),y.useEffect(()=>{var N,m;return e?(w.current=document.activeElement,(m=((N=h.current)==null?void 0:N.querySelector("[autofocus], input:not([type=hidden]), textarea, select, button, [href], [tabindex]:not([tabindex='-1'])"))??h.current)==null||m.focus(),()=>{const p=w.current;p instanceof HTMLElement&&p.focus()}):void 0},[e]),y.useEffect(()=>{if(!e)return;const g=N=>{if(N.key!=="Tab"||!h.current)return;const m=[...h.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 p=m[0],v=m[m.length-1],E=document.activeElement;N.shiftKey&&(E===p||!h.current.contains(E))?(N.preventDefault(),v.focus()):!N.shiftKey&&E===v&&(N.preventDefault(),p.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:h,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",S1[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 cm({content:e,children:t,delayMs:n=250,className:r=""}){const o=y.useId(),s=y.useRef(null),i=y.useRef(null),a=y.useRef(null),[u,c]=y.useState(null),d=()=>{a.current&&clearTimeout(a.current),a.current=null},f=y.useCallback(()=>{d(),c(null)},[]),h=y.useCallback(()=>{var m;const g=(m=s.current)==null?void 0:m.getBoundingClientRect();if(!g)return;const N=g.top<56;c({x:g.left+g.width/2,y:N?g.bottom+6:g.top-6,below:N})},[]);y.useEffect(()=>d,[]),y.useEffect(()=>{if(!u)return;const g=N=>{N.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]),y.useLayoutEffect(()=>{if(!u||!i.current)return;const g=i.current.offsetWidth;if(!g)return;const N=8+g/2,m=window.innerWidth-8-g/2,p=Math.min(Math.max(u.x,N),Math.max(N,m));p!==u.x&&c({...u,x:p})},[u]);const w=y.Children.only(t),k=y.isValidElement(w)?y.cloneElement(w,{"aria-describedby":u?o:void 0}):w;return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:s,className:`inline-flex ${r}`,onPointerEnter:g=>{g.pointerType!=="touch"&&(d(),a.current=setTimeout(h,n))},onPointerLeave:f,onPointerDown:f,onFocusCapture:h,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 dm({open:e,onClose:t,onCompleted:n}){const[r,o]=y.useState(null),[s,i]=y.useState(new Set),[a,u]=y.useState({kind:"loading"}),[c,d]=y.useState("all"),f=y.useRef(!1),h=y.useCallback(async()=>{u({kind:"loading"});try{const v=await lr.transcriptsMigrationChats();o(v),i(a1(v)),u({kind:"plan"})}catch(v){u({kind:"load-failed",message:mm(v)})}},[]);y.useEffect(()=>{e&&(d("all"),h())},[e,h]);const w=y.useMemo(()=>Bi(r),[r]),k=y.useMemo(()=>h1(r),[r]),g=y.useMemo(()=>w.reduce((v,E)=>v+(s.has(E.sessionId)?1:0),0),[w,s]),N=y.useMemo(()=>w.filter(F1).length,[w]),m=y.useCallback(async()=>{if(!(!r||f.current)){f.current=!0,u({kind:"running"});try{const v=await lr.runTranscriptsMigration(f1(r,s));i1(),u({kind:"result",result:v}),v.ok&&(n==null||n())}catch(v){u({kind:"refused",error:v})}finally{f.current=!1}}},[r,s,n]),p=a.kind==="running";return l.jsxs(K1,{open:e,onClose:p?()=>{}:t,dismissOnBackdrop:!p,title:B1(a),footer:l.jsx($1,{phase:a,plan:r,rows:w,selectedCount:g,alsoMoving:k.total,onClose:t,onRetry:m,onReload:h,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(Ne,{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(L1,{plan:r,count:g}),a.kind==="refused"&&l.jsx(M1,{error:a.error,plan:r,rows:w,selected:s}),a.kind==="result"&&l.jsx(I1,{result:a.result}),a.kind==="plan"&&r&&l.jsx(j1,{plan:r,rows:w,selected:s,setSelected:i,filter:c,setFilter:d,decisionCount:N,alsoMoving:k})]})}function j1({plan:e,rows:t,selected:n,setSelected:r,filter:o,setFilter:s,decisionCount:i,alsoMoving:a}){if(sm(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(Ne,{children:".chats/"})," is already empty, so there is nothing to merge into your ",l.jsx(Ne,{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(Ne,{children:"~/.claude"}),"."," ",l.jsxs("span",{className:"text-fg-muted",children:["The rest are set aside in ",l.jsx(Ne,{children:".chats-pre-migration/"}),", not deleted."]})]}),l.jsx(E1,{plan:e}),l.jsx(C1,{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(am,{checked:u,indeterminate:!u&&n.size>0,onChange:()=>r(c1(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(T1,{project:d,selected:n,setSelected:r,filter:o},d.slug))}),a.total>0&&l.jsx(N1,{alsoMoving:a})]})}function E1({plan:e}){const[t,n]=y.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(fm,{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(hm,{warnings:e.warnings})]})]})}function C1({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(Ca,{active:t==="all",onClick:()=>n("all"),label:`All ${e.totals.chats.toLocaleString()}`}),r>0&&l.jsx(Ca,{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(cm,{content:xi(s).hint,children:l.jsx(Ca,{active:t===s,onClick:()=>n(s),label:`${i.toLocaleString()} ${xi(s).label.toLowerCase()}`,tone:pm[s]})},s))]})}function Ca({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 N1({alsoMoving:e}){const[t,n]=y.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(fm,{open:t}),l.jsxs("span",{children:["Also moving: ",l.jsx("span",{className:"text-fg",children:P1(e)})]})]}),t&&l.jsxs("p",{className:"mt-1.5 pl-5 text-xs text-fg-muted",children:[V1(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(Ne,{children:".chats/"})," has to end up completely empty for the switch to take effect."]})]})}function P1(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 fm({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 T1({project:e,selected:t,setSelected:n,filter:r}){const o=e.chats.filter(a=>g1(a,r)),s=y.useMemo(()=>({...e,chats:o}),[e,o]),i=l1(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(cm,{content:l.jsxs("span",{className:"block max-w-xs break-all font-mono text-2xs",children:["→ ",Yd(e.hostStore),o.some(U1)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),"kept, not deleted → ",Yd(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(am,{checked:i.all,indeterminate:i.some,onChange:()=>n(u1(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(b1,{chat:a,checked:t.has(a.sessionId),onToggle:()=>n(d1(t,a.sessionId))},a.sessionId))})]})}function b1({chat:e,checked:t,onToggle:n}){const r=e.state==="diverged"||e.state==="unknown";return l.jsx("li",{children:l.jsxs("label",{title:z1(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(A1,{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(R1,{chat:e,checked:t})]})]})})}function R1({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(Jd,{title:"Paddock's copy",side:e.own,wins:t,note:t?"moves into ~/.claude":"kept in the preserve folder"}),l.jsx(Jd,{title:"Your ~/.claude copy",side:e.host,wins:!t,note:t?"moved aside, kept":"stays where it is"})]}):null}function Jd({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"}`:H1(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 L1({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(Ne,{children:((n=e==null?void 0:e.projects[0])==null?void 0:n.hostStore.replace(/\/[^/]*$/,"/…"))??"~/.claude"}),"."]}),l.jsxs("li",{children:["Setting ",l.jsx(Ne,{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 M1({error:e,plan:t,rows:n,selected:r}){const o=e instanceof $n?e.code:void 0,s=W1(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:_1[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:mm(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(Ne,{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(Ne,{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(Ne,{children:"PADDOCK_CLAUDE_TRANSCRIPTS"})," is set in this server's environment, and an environment variable beats the config file. Writing"," ",l.jsx(Ne,{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 _1={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 I1({result:e}){const t=im(e),n=p1(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(Ne,{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(Ne,{children:"~/.claude"})," and"," ",l.jsx(Ne,{children:"claude.transcripts"})," was already ",l.jsx(Ne,{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(Ne,{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(D1,{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:Xd(o)}),l.jsxs("span",{className:"block text-fg-muted",children:[o.reason,o.message?` — ${o.message}`:""]}),o.path&&Xd(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(Ne,{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:O1(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(hm,{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 D1({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(Ne,{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(Ne,{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(Ne,{children:"~/.claude"})," or in the folders listed below. Fix what is reported above, run this again, and restart when it completes."]})]})}function O1(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"}):sm(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 hm({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 pm={new:"success","fast-forward":"info",diverged:"warn",unknown:"neutral"};function A1({state:e,n:t}){if(t===0)return null;const n=xi(e);return l.jsx(x1,{tone:pm[e]??"neutral",title:n.hint,children:t===void 0?n.label:`${t.toLocaleString()} ${n.label.toLowerCase()}`})}function z1(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 F1(e){return!e.defaultSelected}function U1(e){return e.state==="diverged"||e.state==="unknown"}function Ne({children:e}){return l.jsx("span",{className:"break-all font-mono",children:e})}function mm(e){return e instanceof Error?e.message:String(e)}function B1(e){const t="Merge chats into ~/.claude";if(e.kind!=="result")return t;switch(im(e.result)){case"partial":return`${t} — unfinished`;case"already":return`${t} — nothing to do`;default:return`${t} — done`}}function Xd(e){return e.sessionId&&e.sessionId!=="-"?e.sessionId:e.path??"Project files"}function W1(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 H1(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function V1(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 K1(e){return l.jsx(k1,{...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 Q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 5v14M5 12h14"})}),qS=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"})}),G1=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"})]}),ek=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"})}),Zd=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"})]}),tk=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"})]}),nk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),rk=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"})}),ok=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"})]}),sk=e=>l.jsx("svg",{...J(e),children:l.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),ik=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"})]}),Y1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m9 18 6-6-6-6"})}),ak=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"})}),J1=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"})]}),X1=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"})]}),lk=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"})}),uk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12z"})}),ck=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M6 4.5v15l13-7.5z"})}),Z1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})}),dk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"9"}),l.jsx("path",{d:"M12 7v5l3 2"})]}),fk=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"})]}),hk=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"})}),pk=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"})]}),mk=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"})]}),gk=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"})]}),q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M20 6 9 17l-5-5"})}),vk=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"})]}),yk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),l.jsx("path",{d:"M5 21h14"})]}),xk=({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"})]}),wk=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"})]}),Sk=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"})]}),kk=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"})]}),jk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 17l6-5-6-5M12 19h8"})}),Ek=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"})}),ew=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"})]}),tw=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"})}),nw=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"})]}),Ck=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m6 9 6 6 6-6"})}),Nk=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"})]}),Pk=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 rw({message:e,tone:t="success",onDismiss:n,durationMs:r=6e3,action:o}){if(y.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(X1,{width:16,height:16,className:"mt-0.5 shrink-0"}):l.jsx(q1,{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 ow(){const{showBanner:e,dismiss:t}=om(),n=ts(),[r,o]=y.useState(!1),[s,i]=y.useState(null),[a,u]=y.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(dm,{open:r,onClose:()=>o(!1),onCompleted:()=>u(!0)}),l.jsx(rw,{message:s,onDismiss:()=>i(null),durationMs:12e3,action:{label:"Open Config",onAct:()=>{i(null),n("/config")}}})]})}function Tk(){const{showInConfig:e}=om(),[t,n]=y.useState(!1),[r,o]=y.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(dm,{open:t,onClose:()=>n(!1),onCompleted:()=>o(!0)})]}):null}const Na=6,sw=.75,iw=.9,aw=250,lw=3e4;function uw(e){const[,t]=y.useState(0);y.useEffect(()=>{if(e==null)return;const n=setInterval(()=>t(r=>r+1),e);return()=>clearInterval(n)},[e])}function cw(){const[e,t]=y.useState(new Map);return y.useEffect(()=>Hu.onActiveInfos(n=>t(new Map(n))),[]),e}function dw(e,t){const[n,r]=y.useState(new Map),o=y.useRef(0);return y.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(([h])=>s.has(h)));return f.size===d.size?d:f});let i=!1;const a=async()=>{const d=++o.current;try{const f=await lr.attentionChats(Iu);if(i||d!==o.current)return;r(h=>{const w=new Map([...h].filter(([k])=>s.has(k)));for(const k of[...f.recent??[],...f.unread??[],...f.running??[]]){if(!s.has(k.sessionId))continue;const g=w.get(k.sessionId);w.set(k.sessionId,k.contextTokens==null&&(g==null?void 0:g.contextTokens)!=null?{...k,contextTokens:g.contextTokens,contextLimit:g.contextLimit}:k)}return w})}catch{}},u=setTimeout(()=>void a(),aw),c=e?setInterval(()=>{document.visibilityState==="visible"&&a()},lw):null;return()=>{i=!0,clearTimeout(u),c&&clearInterval(c)}},[e,t]),n}function gm({fill:e}){const t=e<=0?0:Math.max(1,Math.min(Na,Math.round(e*Na))),n=e<sw?"bg-accent-solid":e<iw?"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:Na},(r,o)=>l.jsx("span",{className:Ye("h-2.5 w-[3px] rounded-[1px]",o<t?n:"bg-edge")},o))})}function fw({projectSlug:e,projectName:t,chatName:n,sessionId:r,startedAt:o,fill:s}){const i=o==null?"—:—":r1(Date.now()-o),a=n??"Running turn";return l.jsxs(ns,{"data-testid":"fleet-channel",to:`${Vp(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(gm,{fill:s})]})}function hw({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(ns,{"data-testid":"fleet-finished",to:`${Vp(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(gm,{fill:s})})]})}function pw(){const e=y.useRef(null),[t,n]=y.useState(!1),[r,o]=y.useState(!1);return y.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 qd({value:e,unit:t,to:n,tone:r,title:o}){return l.jsxs(ns,{"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 mw({unread:e,finished:t=[]}){const{projects:n,rootWorkspace:r}=Qp(),o=cw(),s=y.useMemo(()=>[...o.keys()].sort().join(","),[o]),i=y.useMemo(()=>t.map(g=>g.sessionId).join(","),[t]),a=dw(s,i);uw(o.size>0?1e3:t.length>0?3e4:null);const u=pw(),c=y.useMemo(()=>{const g=new Map;for(const N of n)g.set(N.slug,N.name);return r&&g.set(r.slug,r.name),g},[n,r]),d=y.useMemo(()=>[...o.entries()].map(([g,N])=>{const m=a.get(g);return{sessionId:g,projectSlug:N,projectName:c.get(N)??(m==null?void 0:m.projectName)??N,chatName:(m==null?void 0:m.name)??null,startedAt:Hu.turnStartedAt(g),fill:(m==null?void 0:m.contextTokens)!=null&&m.contextLimit?Math.min(1,m.contextTokens/m.contextLimit):null}}).sort((g,N)=>(g.startedAt??1/0)-(N.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,h=t.map(g=>{const N=a.get(g.sessionId);return{...g,projectName:c.get(g.projectSlug)??(N==null?void 0:N.projectName)??g.projectSlug,chatName:(N==null?void 0:N.name)??null,fill:f(N)}}),w=y.useMemo(()=>{let g="";for(const N of r?[...n,r]:n)for(const m of N.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(qd,{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(qd,{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(fw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,startedAt:g.startedAt,fill:g.fill},g.sessionId)),h.map(g=>l.jsx(hw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,at:g.at,fill:g.fill},g.sessionId)),d.length===0&&h.length===0&&(w?l.jsxs("span",{className:"truncate text-2xs text-fg-subtle",children:["Idle · last turn ",yi(w)]}):l.jsx(ns,{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(ow,{}),l.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})}const vm="paddock:area-collapsed:";function ym(e){return vm+(e||"unsorted")}const Il=new Set,gw=()=>{for(const e of Il)e()};function ef(e){try{return localStorage.getItem(ym(e))==="1"}catch{return!1}}function vw(e,t){try{localStorage.setItem(ym(e),t?"1":"0")}catch{}gw()}function yw(e){Il.add(e);const t=n=>{(n.key===null||n.key.startsWith(vm))&&e()};return window.addEventListener("storage",t),()=>{Il.delete(e),window.removeEventListener("storage",t)}}function xw(e){const t=y.useSyncExternalStore(yw,()=>ef(e),()=>!1),n=y.useCallback(()=>vw(e,!ef(e)),[e]);return[t,n]}function ww({tag:e,className:t=""}){const n=ts();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})}let Pa;function Sw(){if(Pa===void 0){const e=Intl.Segmenter;Pa=e?new e(void 0,{granularity:"grapheme"}):null}return Pa}function tf(e){const t=Sw();return t?Array.from(t.segment(e),n=>n.segment):Array.from(e)}const kw=/[^\p{Cf}\p{Cc}\p{M}\p{Z}\p{White_Space}]/u;function jw(e){const t=tf(e.normalize("NFC")).filter(o=>kw.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 tf(r).length===1?r:n}function Ew({slug:e,name:t,color:n,className:r=""}){const o=n??zu(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:Bu(o)},children:jw(t)})}function Cw({sections:e,badges:t,chipColors:n}){var s;const r=(s=k0("/projects/:slug/*"))==null?void 0:s.params.slug,o=e.length>1;return l.jsx(l.Fragment,{children:e.map(([i,a])=>l.jsx(Nw,{slug:i,projects:a,badges:t,chipColors:n,activeSlug:r,showHeading:o},i||"unsorted"))})}function Nw({slug:e,projects:t,badges:n,chipColors:r,activeSlug:o,showHeading:s}){const[i,a]=xw(e),u=y.useId(),c=s&&i,d=c?t.filter(h=>h.slug===o):t,f=y.useMemo(()=>{const h={unread:0,inflight:0};if(!c)return h;for(const w of t){if(w.slug===o)continue;const k=n.get(w.slug);h.unread+=(k==null?void 0:k.unread)??0,h.inflight+=(k==null?void 0:k.inflight)??0}return h},[c,t,o,n]);return l.jsxs("div",{className:"mb-2",children:[s&&l.jsxs("button",{type:"button",onClick:a,"aria-expanded":!i,"aria-controls":u,title:i?"Expand group":"Collapse group",className:"flex w-full items-center gap-1 rounded-md px-2.5 pb-1 pt-2 text-left text-3xs font-semibold uppercase tracking-wider text-fg-subtle hover:text-fg-muted focus-visible:focus-ring",children:[l.jsx(Y1,{width:10,height:10,"aria-hidden":"true",className:`-ml-0.5 shrink-0 transition-transform ${i?"":"rotate-90"}`}),l.jsx("span",{className:"min-w-0 truncate",children:Kx(e)}),l.jsx(Qu,{badge:f,className:"ml-auto font-normal normal-case tracking-normal"})]}),l.jsx("div",{id:u,children:d.map(h=>l.jsx(Pw,{project:h,badge:n.get(h.slug),chipColor:r.get(h.slug)},h.slug))})]})}function Pw({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(Ew,{slug:e.slug,name:e.name,color:n}),l.jsx("span",{className:"truncate font-medium",children:e.name})]}),l.jsx(Qu,{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(ww,{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 Qu({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})]})}function nf(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e:"~"}function Tw(e,t,n){const r=Math.abs(e-t)%n;return Math.min(r,n-r)}function bw(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,Sx(i,c));const u=Tw(i,t,n);(a>o||a===o&&u<s)&&(r=i,o=a,s=u)}return r}function Rw(e){const t=rs.length,n=[...e].sort((s,i)=>{const a=nf(s.started),u=nf(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=Jp(s),a=!r.has(i)||r.size>=t?i:bw(r,i,t);r.add(a),o.set(s,a)}return o}function Lw(e){const t=new Map;for(const[n,r]of Rw(e))t.set(n,rs[r]);return t}const Mw=["idea","active","paused","blocked","done"];function _w({open:e,onClose:t,onCreated:n}){const[r,o]=y.useState(""),[s,i]=y.useState(""),[a,u]=y.useState(""),[c,d]=y.useState(""),[f,h]=y.useState("active"),[w,k]=y.useState(""),[g,N]=y.useState(""),[m,p]=y.useState(!1),[v,E]=y.useState(!1),[T,R]=y.useState(null);if(y.useEffect(()=>{e&&(o(""),i(""),u(""),d(""),h("active"),k(""),N(""),p(!1),R(null))},[e]),y.useEffect(()=>{const x=D=>{D.key==="Escape"&&e&&!v&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[e,v,t]),!e)return null;const M=async x=>{if(x.preventDefault(),!!r.trim()){E(!0),R(null);try{const D=await lr.createProject({name:r.trim(),status:f,group:c||void 0,summary:s.trim()||void 0,repo:w.trim()||void 0,path:g.trim()||void 0,managed:g.trim()&&!w.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:x=>x.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:x=>o(x.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:x=>i(x.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:x=>d(x.target.value),children:[l.jsx("option",{value:"",children:"Unsorted"}),Wu.map(x=>l.jsx("option",{value:x.slug,children:x.label},x.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:x=>N(x.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:w,onChange:x=>k(x.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()&&!w.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:x=>p(x.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:x=>u(x.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:x=>h(x.target.value),children:Mw.map(x=>l.jsx("option",{value:x,className:"capitalize",children:x},x))})]})]}),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 rf(e){if(typeof window>"u"||typeof window.matchMedia!="function")return null;try{return window.matchMedia(e)??null}catch{return null}}function Iw(e){const[t,n]=y.useState(()=>{var r;return((r=rf(e))==null?void 0:r.matches)??!1});return y.useEffect(()=>{var s;const r=rf(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 Gu="paddock:panewidth:",Dw={key:"sidenav",def:288,min:200,max:480},bk={key:"chatlist",def:256,min:220,max:520},Ow="(min-width: 1024px)";function $r(e,t){return Math.min(Math.max(t,e.min),e.max)}function of(e,t,n){return $r(n,e+t)}function $w(e){try{const t=localStorage.getItem(Gu+e.key);if(t==null)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?$r(e,n):null}catch{return null}}function Aw(e,t){try{localStorage.setItem(Gu+e.key,String($r(e,t)))}catch{}}function zw(e){try{localStorage.removeItem(Gu+e.key)}catch{}}function Fw(e){const t=Iw(Ow),[n,r]=y.useState(()=>$w(e)),o=$r(e,n??e.def);return{isDesktop:t,width:o,style:t?{width:o}:void 0,preview:s=>r($r(e,s)),commit:s=>{const i=$r(e,s);r(i),Aw(e,i)},reset:()=>{r(null),zw(e)},spec:e}}function Uw({spec:e,width:t,onPreview:n,onCommit:r,onReset:o,label:s}){const i=y.useRef(null),a=y.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(of(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=of(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]=y.useState(new Map),r=y.useRef(new Map),[o,s]=y.useState(0);return y.useEffect(()=>{const i=r.current;for(const a of e)for(const u of a.chatTurns??[]){qx(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]),y.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)},[]),y.useEffect(()=>{const i=new Map;return Hu.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)})},[]),y.useEffect(()=>{const i=()=>s(a=>a+1);return window.addEventListener(Ll,i),()=>window.removeEventListener(Ll,i)},[]),y.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:h}]of r.current)!t.has(c)&&(h||f>Zx(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 Ww(){const{projects:e,rootWorkspace:t,loading:n,upsert:r}=Qp(),{dark:o,toggle:s}=hx(),[i,a]=y.useState(!1),[u,c]=y.useState(!1),d=ts(),f=Wn(),h=Gp(),w=gx(),k=Fw(Dw),g=f.pathname==="/"||f.pathname==="/projects"||f.pathname.startsWith("/chat"),N=f.pathname.startsWith("/projects/")||g;y.useEffect(()=>{a(!1)},[f.pathname]);const m=y.useMemo(()=>{const b=new Map;for(const W of e){const te=W.group??"",ce=b.get(te);ce?ce.push(W):b.set(te,[W])}return Qx(b.keys()).map(W=>[W,b.get(W)??[]])},[e]),p=y.useMemo(()=>Lw(e),[e]),v=y.useMemo(()=>t?[...e,t]:e,[e,t]),{badges:E,unreadChats:T,active:R}=Bw(v),M=Vx({active:R,finished:T});Fx(h,Wx(M.status));const x=E.get(Iu),D=y.useMemo(()=>{let b=0;for(const W of E.values())b+=W.unread;return b},[E]);return l.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden bg-surface lg:flex-row",children:[!N&&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(Z1,{width:20,height:20})}),l.jsxs(yn,{to:"/",className:"flex items-center gap-2",children:[l.jsx(sf,{brand:h,className:"h-7 w-7 text-sm"}),l.jsx("span",{className:"text-md font-semibold tracking-tight",children:h.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(Uw,{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(sf,{brand:h,className:"h-8 w-8 text-base"}),l.jsx("span",{className:"text-lg font-semibold tracking-tight",children:h.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(G1,{width:16,height:16}),"Home",l.jsx(Qu,{badge:x,className:"ml-auto"})]})}),l.jsxs("div",{className:"mt-5 mb-1 flex items-center justify-between pr-3",children:[l.jsx(yn,{to:ax(),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(Zd,{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(Q1,{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&&l.jsx(Cw,{sections:m,badges:E,chipColors:p})]}),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(J1,{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(Zd,{width:15,height:15}),"Discover"]}),w.enabled&&l.jsxs("a",{href:w.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(nw,{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(ew,{width:15,height:15}):l.jsx(tw,{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.80.0"]})]})]}),l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[l.jsx(mw,{unread:D,finished:T}),l.jsx("main",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:l.jsx(y.Suspense,{fallback:l.jsx(Hw,{}),children:l.jsx(em.Provider,{value:M,children:l.jsx($0,{context:{openNav:()=>a(!0)}})})})})]}),l.jsx(_w,{open:u,onClose:()=>c(!1),onCreated:b=>{r(b),c(!1),d(`/projects/${b.slug}/chat`)}})]})}function sf({brand:e,className:t=""}){const n=Cx(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:Bu(n)}:void 0,"data-testid":"brand-chip",children:Yp(e.logo)?l.jsx("img",{src:e.logo,alt:"",className:"h-full w-full object-cover"}):e.logo})}function Hw(){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…"})]})}const xm="paddock:chunkReloadAt",Vw=1e4,af=/dynamically imported module|module script|importing a module|failed to fetch|unable to preload|load failed|error loading/i;function Kw(e){return e?e instanceof Error?e.name==="ChunkLoadError"?!0:af.test(e.message):af.test(String(e)):!1}function Yu(){try{return typeof sessionStorage<"u"?sessionStorage:void 0}catch{return}}function Qw(e=Date.now(),t=Yu()){if(!t)return!1;const n=t.getItem(xm);if(!n)return!1;const r=Number(n);return Number.isFinite(r)&&e-r<Vw}function Gw(e=Date.now(),t=Yu()){try{t==null||t.setItem(xm,String(e))}catch{}}function Yw(e,t=Date.now(),n=Yu()){return Kw(e)&&!Qw(t,n)?"reload":"show"}function Jw(){const e=Bp(),t=Yw(e);if(y.useEffect(()=>{t==="reload"&&(Gw(),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 Xw(){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,wm=3,Tt=.12,Sm=["--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 Nn(r,{})}catch{return null}}function Zw(e,t,n){let r=0,o=1;for(let s=0;s<32;s++){const i=(r+o)/2;et(Gr(i,t,n))<e?r=i:o=i}return(r+o)/2}function km(e,t,n){if(zd(e,t,n))return t;let r=0,o=t;for(let s=0;s<24;s++){const i=(r+o)/2;zd(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=Zw(s,i,n);let d=o?0:c,f=o?c:1;for(let h=0;h<28;h++){const w=(d+f)/2,k=We(Gr(w,i,n),r)>=e;o?k?d=w:f=w:k?f=w:d=w}a=o?d:f,i=km(a,t,n)}return{L:a,C:i,rgb:Gr(a,i,n)}}const qw=.75;function Ar(e,t,n,r,o,s=e){const i=Ta(e,t,n,r,o),a=f=>f.C>=t*qw;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 h=(u+c)/2,w=Ta(h,t,n,r,o);a(w)?(d=w,u=h):c=h}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 jm=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected","--border-subtle","--border","--border-strong","--text","--text-muted","--text-subtle","--scroll-thumb"],lf=["--text","--text-muted","--text-subtle"],eS=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected"];function Em(e=document.documentElement){for(const t of jm)e.style.removeProperty(t)}function tS(e,t,n=document.documentElement){Em(n);for(const o of jm){const s=gt(n,o);if(!s)continue;const{L:i,C:a}=tn(s),u=lf.includes(o),c=Math.max(a,t*(u?.5:1));n.style.setProperty(o,Gt(Gr(i,km(i,c,e),e)))}let r=1/0;for(const o of lf){const s=gt(n,o);if(s)for(const i of eS){const a=gt(n,i);a&&(r=Math.min(r,We(s,a)))}}return r}function Cm(e=document.documentElement){for(const t of Sm)e.style.removeProperty(t)}function Nm(e,t){const n=Sm.map(r=>[r,e.style.getPropertyValue(r)]);Cm(e);try{return t()}finally{for(const[r,o]of n)o&&e.style.setProperty(r,o)}}function nS(e=document.documentElement){return Nm(e,()=>{const t=gt(e,"--accent");return t?tn(t).H:0})}const ho={r:1,g:1,b:1,a:1};function Pm(e=document.documentElement){return Nm(e,()=>rS(e))}function rS(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),wm+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 oS(e,t){const n=Dt+Tt;return{accent:Ar(e.targets.accent,e.chroma.accent,t,e.surface,e.darker.accent,wm+Tt),a600:Ar(e.targets.a600,e.chroma.a600,t,e.fg,e.darker.a600,n),a700:Ar(e.targets.a700,e.chroma.a700,t,e.a700Bg,e.darker.a700,n)}}function Rk(e,t=document.documentElement){const n=Pm(t);return e.map(r=>Gt(Ar(n.targets.a600,n.chroma.a600,r,n.fg,n.darker.a600,Dt+Tt).rgb))}function sS(e,t=document.documentElement,n={}){const r=t.classList.contains("dark")?"dark":"light",o=n.context??Pm(t),s=oS(o,e),{a600:i,a700:a,accent:u}=s,c={C:o.chroma.a700};Cm(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=[],h=d["--accent-fg"]??o.fg,w=(v,E,T)=>{const R=d[v];if(!R)return 1/0;let M=We(R,h),x=!1;if(M<T+Tt){const{C:D}=tn(R),b=Ar(T+Tt,Math.max(D,o.chroma.a600),e,h,et(R)<et(h),Dt+Tt);t.style.setProperty(v,Gt(b.rgb)),M=We(b.rgb,h),x=!0}return f.push({label:E,fg:"--accent-fg",bg:v,ratio:M,floor:T,repaired:x}),M},k=w("--accent-solid","Primary button",Dt);w("--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 N=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]);N=We(m,v.c);let E=!1;if(N<Dt+Tt){const{C:T}=tn(m),R=Ar(Dt+Tt,T||c.C,e,v.c,et(m)<et(v.c));t.style.setProperty("--accent-text",Gt(R.rgb)),N=g.reduce((M,x)=>Math.min(M,We(R.rgb,x.c)),1/0),E=!0}f.push({label:"Accent text",fg:"--accent-text",bg:v.name,ratio:N,floor:Dt,repaired:E})}const p={};if(!n.live)for(const v of["--accent-solid","--accent-solid-hover","--accent-text"]){const E=gt(t,v);E&&(p[v]=Gt(E))}return{hue:e,mode:r,channels:{accent:Gt(u.rgb),accent600:Gt(i.rgb),accent700:Gt(a.rgb)},applied:p,checks:f,ok:f.every(v=>v.ratio>=v.floor-.005)&&k>=Dt}}const iS=[{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."}],Lk=[{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}],Mk=[{level:0,label:"None"},{level:1,label:"A little"},{level:2,label:"More"}];function aS(e=document.documentElement){const t=Gp().accent;if(t&&t.toLowerCase()!==An.accent.toLowerCase())try{return tn(Nn(t,{})).H}catch{}return nS(e)}const uf={theme:"foundation",hue:null,tint:0},Tm="paddock:appearance",cf="paddock:appearance-cache";function lS(){try{const e=localStorage.getItem(Tm);if(!e)return uf;const t=JSON.parse(e);return{theme:iS.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 uf}}function uS(e){try{localStorage.setItem(Tm,JSON.stringify(e))}catch{}}function cS(e,t,n){try{const r=JSON.parse(localStorage.getItem(cf)||"{}"),o=`${e}:${t?"dark":"light"}`;n?r[o]={...n.applied,"--accent":n.channels.accent}:delete r[o],localStorage.setItem(cf,JSON.stringify(r))}catch{}}function dS(e,t=document.documentElement){t.setAttribute("data-theme",e.theme);const n=e.hue??aS(t);let r=null;e.tint===0?Em(t):r=tS(n,mS[e.tint],t);const o=sS(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),cS(e.theme,t.classList.contains("dark"),o),o}function fS(e,t){uS(e);const n=dS(e,t);return window.dispatchEvent(new CustomEvent(hS,{detail:n})),n}const hS="paddock:appearance";function pS(){const e=()=>fS(lS());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 mS=[0,.008,.018],bm=y.lazy(()=>Zt(()=>import("./ProjectsGrid-D6kfaIal.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.ProjectsGrid}))),Te=y.lazy(()=>Zt(()=>import("./ProjectView-BiKnGfk6.js").then(e=>e.a),__vite__mapDeps([4,5,1,2,6,7,3])).then(e=>({default:e.ProjectView}))),gS=y.lazy(()=>Zt(()=>import("./ProjectRedirect-EioguUKW.js"),__vite__mapDeps([8,2])).then(e=>({default:e.ProjectRedirect}))),vS=y.lazy(()=>Zt(()=>import("./InstanceConfigPage-BRoBh1C1.js"),__vite__mapDeps([9,6,3])).then(e=>({default:e.InstanceConfigPage}))),yS=y.lazy(()=>Zt(()=>import("./DiscoverPage-BSGSzTEs.js"),__vite__mapDeps([10,7,6,3])).then(e=>({default:e.DiscoverPage}))),xS=y.lazy(()=>Zt(()=>import("./RootHome-DpcyuV6e.js"),__vite__mapDeps([11,4,5,1,2,6,7,3])).then(e=>({default:e.RootHome})));pS();const Rm=()=>document.documentElement.setAttribute("data-tab-hidden",document.hidden?"true":"false");document.addEventListener("visibilitychange",Rm);Rm();function wS(){const{tag:e}=C0();return l.jsx(bm,{filterTag:e?decodeURIComponent(e):void 0})}const SS=V0([{path:"/",element:l.jsx(Ww,{}),errorElement:l.jsx(Jw,{}),children:[{index:!0,element:l.jsx(xS,{})},{path:"projects",element:l.jsx(bm,{})},{path:"tags/:tag",element:l.jsx(wS,{})},{path:"projects/:slug",element:l.jsx(gS,{})},{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(vS,{})},{path:"discover",element:l.jsx(yS,{})}]}]);Ra.createRoot(document.getElementById("root")).render(l.jsx(jf.StrictMode,{children:l.jsx(cx,{children:l.jsx(q0,{router:SS})})}));Xw();export{JS as $,X1 as A,wk as B,ek as C,iS as D,Lk as E,Mk as F,Cm as G,sS as H,Pm as I,jt as J,x1 as K,ns as L,fk as M,ES as N,ZS as O,pk as P,Iw as Q,Iu as R,lk as S,hk as T,Zd as U,GS as V,Xt as W,Hi as X,q1 as Y,XS as Z,$n as _,lr as a,Vp as a$,YS as a0,jS as a1,Z1 as a2,J1 as a3,Tk as a4,rk as a5,jk as a6,am as a7,Ck as a8,kS as a9,AS as aA,ak as aB,Hu as aC,qS as aD,kk as aE,Ek as aF,gk as aG,Du as aH,Wu as aI,ck as aJ,DS as aK,cm as aL,nk as aM,Uw as aN,OS as aO,Sk as aP,Nk as aQ,xk as aR,Pk as aS,MS as aT,_S as aU,qx as aV,Zx as aW,IS as aX,rw as aY,TS as aZ,CS as a_,ik as aa,sk as ab,mk as ac,uk as ad,nw as ae,ok as af,zS as ag,FS as ah,WS as ai,BS as aj,US as ak,HS as al,KS as am,VS as an,r1 as ao,k1 as ap,tk as aq,t1 as ar,Ea as as,$S as at,Zt as au,vk as av,yk as aw,Oi as ax,QS as ay,lx as az,tf as b,RS as b0,Wn as b1,NS as b2,PS as b3,Fw as b4,bS as b5,bk as b6,Ye as c,Qp as d,w1 as e,ff as f,Gp as g,ts as h,Q1 as i,l as j,_w as k,ax as l,ww as m,dk as n,Qx as o,yi as p,xw as q,y as r,LS as s,Kx as t,C0 as u,Y1 as v,lS as w,fS as x,hS as y,Rk as z};
70
+ */function Qr(){return Qr=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},Qr.apply(this,arguments)}function Wp(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 F0(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function U0(e,t){return e.button===0&&(!t||t==="_self")&&!F0(e)}const B0=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],W0=["aria-current","caseSensitive","className","end","style","to","unstable_viewTransition","children"],H0="6";try{window.__reactRouterVersion=H0}catch{}function V0(e,t){return Zy({basename:void 0,future:Qr({},void 0,{v7_prependBasename:!0}),history:jy({window:void 0}),hydrationData:K0(),routes:e,mapRouteProperties:z0,unstable_dataStrategy:void 0,unstable_patchRoutesOnNavigation:void 0,window:void 0}).initialize()}function K0(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Qr({},t,{errors:Q0(t.errors)})),t}function Q0(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 Hp=y.createContext({isTransitioning:!1}),G0=y.createContext(new Map),Y0="startTransition",Id=cg[Y0],J0="flushSync",Dd=ky[J0];function X0(e){Id?Id(e):e()}function fo(e){Dd?Dd(e):e()}class Z0{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 q0(e){let{fallbackElement:t,router:n,future:r}=e,[o,s]=y.useState(n.state),[i,a]=y.useState(),[u,c]=y.useState({isTransitioning:!1}),[d,f]=y.useState(),[h,w]=y.useState(),[k,g]=y.useState(),N=y.useRef(new Map),{v7_startTransition:m}=r||{},p=y.useCallback(x=>{m?X0(x):x()},[m]),v=y.useCallback((x,D)=>{let{deletedFetchers:b,unstable_flushSync:W,unstable_viewTransitionOpts:te}=D;b.forEach(fe=>N.current.delete(fe)),x.fetchers.forEach((fe,st)=>{fe.data!==void 0&&N.current.set(st,fe.data)});let ce=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!te||ce){W?fo(()=>s(x)):p(()=>s(x));return}if(W){fo(()=>{h&&(d&&d.resolve(),h.skipTransition()),c({isTransitioning:!0,flushSync:!0,currentLocation:te.currentLocation,nextLocation:te.nextLocation})});let fe=n.window.document.startViewTransition(()=>{fo(()=>s(x))});fe.finished.finally(()=>{fo(()=>{f(void 0),w(void 0),a(void 0),c({isTransitioning:!1})})}),fo(()=>w(fe));return}h?(d&&d.resolve(),h.skipTransition(),g({state:x,currentLocation:te.currentLocation,nextLocation:te.nextLocation})):(a(x),c({isTransitioning:!0,flushSync:!1,currentLocation:te.currentLocation,nextLocation:te.nextLocation}))},[n.window,h,d,N,p]);y.useLayoutEffect(()=>n.subscribe(v),[n,v]),y.useEffect(()=>{u.isTransitioning&&!u.flushSync&&f(new Z0)},[u]),y.useEffect(()=>{if(d&&i&&n.window){let x=i,D=d.promise,b=n.window.document.startViewTransition(async()=>{p(()=>s(x)),await D});b.finished.finally(()=>{f(void 0),w(void 0),a(void 0),c({isTransitioning:!1})}),w(b)}},[p,i,d,n.window]),y.useEffect(()=>{d&&i&&o.location.key===i.location.key&&d.resolve()},[d,h,o.location,i]),y.useEffect(()=>{!u.isTransitioning&&k&&(a(k.state),c({isTransitioning:!0,flushSync:!1,currentLocation:k.currentLocation,nextLocation:k.nextLocation}),g(void 0))},[u.isTransitioning,k]),y.useEffect(()=>{},[]);let E=y.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:x=>n.navigate(x),push:(x,D,b)=>n.navigate(x,{state:D,preventScrollReset:b==null?void 0:b.preventScrollReset}),replace:(x,D,b)=>n.navigate(x,{replace:!0,state:D,preventScrollReset:b==null?void 0:b.preventScrollReset})}),[n]),T=n.basename||"/",R=y.useMemo(()=>({router:n,navigator:E,static:!1,basename:T}),[n,E,T]),M=y.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return y.createElement(y.Fragment,null,y.createElement(es.Provider,{value:R},y.createElement(Mu.Provider,{value:o},y.createElement(G0.Provider,{value:N.current},y.createElement(Hp.Provider,{value:u},y.createElement(A0,{basename:T,location:o.location,navigationType:o.historyAction,navigator:E,future:M},o.initialized||n.future.v7_partialHydration?y.createElement(ex,{routes:n.routes,future:n.future,state:o}):t))))),null)}const ex=y.memo(tx);function tx(e){let{routes:t,future:n,state:r}=e;return N0(t,void 0,r,n)}const nx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",rx=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ns=y.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,h=Wp(t,B0),{basename:w}=y.useContext(cn),k,g=!1;if(typeof c=="string"&&rx.test(c)&&(k=c,nx))try{let v=new URL(window.location.href),E=c.startsWith("//")?new URL(v.protocol+c):new URL(c),T=ln(E.pathname,w);E.origin===v.origin&&T!=null?c=T+E.search+E.hash:g=!0}catch{}let N=S0(c,{relative:o}),m=sx(c,{replace:i,state:a,target:u,preventScrollReset:d,relative:o,unstable_viewTransition:f});function p(v){r&&r(v),v.defaultPrevented||m(v)}return y.createElement("a",Qr({},h,{href:k||N,onClick:g||s?r:p,ref:n,target:u}))}),yn=y.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=Wp(t,W0),h=Fi(u,{relative:f.relative}),w=Wn(),k=y.useContext(Mu),{navigator:g,basename:N}=y.useContext(cn),m=k!=null&&ix(h)&&c===!0,p=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=w.pathname,E=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;o||(v=v.toLowerCase(),E=E?E.toLowerCase():null,p=p.toLowerCase()),E&&N&&(E=ln(E,N)||E);const T=p!=="/"&&p.endsWith("/")?p.length-1:p.length;let R=v===p||!i&&v.startsWith(p)&&v.charAt(T)==="/",M=E!=null&&(E===p||!i&&E.startsWith(p)&&E.charAt(p.length)==="/"),x={isActive:R,isPending:M,isTransitioning:m},D=R?r:void 0,b;typeof s=="function"?b=s(x):b=[s,R?"active":null,M?"pending":null,m?"transitioning":null].filter(Boolean).join(" ");let W=typeof a=="function"?a(x):a;return y.createElement(ns,Qr({},f,{"aria-current":D,className:b,ref:n,style:W,to:u,unstable_viewTransition:c}),typeof d=="function"?d(x):d)});var Cl;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Cl||(Cl={}));var Od;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Od||(Od={}));function ox(e){let t=y.useContext(es);return t||X(!1),t}function sx(e,t){let{target:n,replace:r,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a}=t===void 0?{}:t,u=ts(),c=Wn(),d=Fi(e,{relative:i});return y.useCallback(f=>{if(U0(f,n)){f.preventDefault();let h=r!==void 0?r:ar(c)===ar(d);u(e,{replace:h,state:o,preventScrollReset:s,relative:i,unstable_viewTransition:a})}},[c,u,d,r,o,n,e,s,i,a])}function ix(e,t){t===void 0&&(t={});let n=y.useContext(Hp);n==null&&X(!1);let{basename:r}=ox(Cl.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 Go(o.pathname,i)!=null||Go(o.pathname,s)!=null}const Iu="";function Du(e){return e===Iu}function K(e){return Du(e)?"/api/root":`/api/projects/${encodeURIComponent(e)}`}function Vp(e){return Du(e)?"":`/projects/${e}`}function CS(e){return e===""?"/":`${e}/home`}function ax(){return"/projects"}function NS(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 PS(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 lx(e){return`m-${e}`}function TS(e,t,n){return`${e}/chat/${encodeURIComponent(t)}#${lx(n)}`}function bS(e){var t;return(t=/^#?m-([0-9a-fA-F][0-9a-fA-F-]{7,})$/.exec(e))==null?void 0:t[1]}const Yn="";async function U(e,t){const n=await fetch(`${Yn}${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 ux(e,t){const n=await fetch(`${Yn}${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 $d={transcriptRenderLimit:500};let Ad=null;const lr={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(`${Yn}${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`${Yn}${K(e)}/files/${encodeURIComponent(t)}?raw=1`},chatFileRawUrl(e){return`${Yn}/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 Ad??(Ad=lr.getModels().then(e=>e.uiDefault??$d).catch(()=>$d)),Ad},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 ux(`${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`${Yn}${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(`${Yn}/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)})}},Kp=y.createContext(null);function cx({children:e}){const[t,n]=y.useState([]),[r,o]=y.useState(null),[s,i]=y.useState(!0),[a,u]=y.useState(null),c=y.useRef(!1),d=y.useCallback(async()=>{c.current||i(!0),u(null);try{const{projects:k,root:g}=await lr.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=y.useCallback(k=>{if(Du(k.slug)){o(k);return}n(g=>[k,...g.filter(N=>N.slug!==k.slug)])},[]),h=y.useCallback(k=>{n(g=>g.filter(N=>N.slug!==k))},[]);y.useEffect(()=>{d()},[d]);const w=y.useMemo(()=>({projects:t,rootWorkspace:r,loading:s,error:a,refresh:d,upsert:f,remove:h}),[t,r,s,a,d,f,h]);return l.jsx(Kp.Provider,{value:w,children:e})}function Qp(){const e=y.useContext(Kp);if(!e)throw new Error("useProjects must be used within ProjectsProvider");return e}const dx="paddock:theme";function fx(){return typeof document<"u"&&document.documentElement.classList.contains("dark")}function hx(){const[e,t]=y.useState(fx),n=y.useCallback(()=>{t(r=>{const o=!r;document.documentElement.classList.toggle("dark",o);try{localStorage.setItem(dx,o?"dark":"light")}catch{}return o})},[]);return{dark:e,toggle:n}}const An={name:"Paddock",logo:"🐎",accent:"#c2603c"},px={running:"#f97316",unread:"#22c55e"},mx={enabled:!1,path:"/open-api"};function Gp(){const e=globalThis.__PADDOCK_CONFIG__;return{...An,...(e==null?void 0:e.brand)??{}}}function gx(){const e=globalThis.__PADDOCK_CONFIG__;return{...mx,...(e==null?void 0:e.openapi)??{}}}function Yp(e){return/^(https?:\/\/|\/)/i.test(e.trim())}const Ou=e=>e<0?0:e>1?1:e;function $u(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 Au({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 Nl(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 Gr(e,t,n,r=1){const o=n*Math.PI/180,s=Au({L:e,a:t*Math.cos(o),b:t*Math.sin(o)}),[i,a,u]=s.map(c=>Ou($u(c)));return{r:i,g:a,b:u,a:r}}function zd(e,t,n){const r=n*Math.PI/180;return Au({L:e,a:t*Math.cos(r),b:t*Math.sin(r)}).map($u).every(o=>o>=-.0015&&o<=1.0015)}function Gt({r:e,g:t,b:n}){const r=o=>Math.round(Ou(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 vx(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(vx(e,t)),r=et(t),[o,s]=n>r?[n,r]:[r,n];return(o+.05)/(s+.05)}const Fd={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 gr(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 Nn(e,t,n=0){if(n>24)throw new Error(`var() cycle resolving ${e}`);const r=e.trim();if(Fd[r])return Fd[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=gr(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 Nn(d,t,n+1)}const s=gr(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 Gr(gn(d[0]),gn(d[1]),gn(d[2]),c?gn(c.trim()):1)}const i=gr(r,"rgb")??gr(r,"rgba");if(i!==null){const u=i.trim(),c=gr(u,"var");if(c!==null){const[w]=ja(c),k=t[w];if(!k)throw new Error(`undefined custom property: ${w}`);return Nn(`rgb(${k})`,t,n+1)}const[d,f]=u.split("/"),h=d.trim().split(/[\s,]+/);if(h.length<3)throw new Error(`bad rgb(): ${r}`);return{r:gn(h[0])/255,g:gn(h[1])/255,b:gn(h[2])/255,a:f?gn(f.trim()):1}}const a=gr(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 h=Ud(c),w=Ud(d);let k=h.pct,g=w.pct;k===null&&g===null?(k=.5,g=.5):k===null?k=1-g:g===null&&(g=1-k);const N=k+g,m=k/N,p=Nn(h.color,t,n+1),v=Nn(w.color,t,n+1);return f==="in srgb"?yx(p,v,m):xx(p,v,m)}throw new Error(`unsupported colour value: ${r}`)}function Ud(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 yx(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 xx(e,t,n){const r=Nl(It(e.r),It(e.g),It(e.b)),o=Nl(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]=Au(s).map(c=>Ou($u(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}=Nl(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 wx=[[.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]],rs=Object.freeze(wx.map(([e,t,n])=>Gt(Gr(e,t,n)))),Bd=rs.map(e=>{const{L:t,C:n,H:r}=tn(Nn(e,{})),o=r*Math.PI/180;return{L:t,a:n*Math.cos(o),b:n*Math.sin(o)}});function Sx(e,t){const n=Bd[e],r=Bd[t];return Math.hypot(n.L-r.L,n.a-r.a,n.b-r.b)}function kx(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 Jp(e){return kx(e.trim())%rs.length}function zu(e){return rs[Jp(e)]}const Ui=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function Fu(e){return!e||Ui(e,An.accent)}function jx(e){return Ui(e.name,An.name)&&e.logo.trim()===An.logo&&Fu(e.accent)}function Uu(e){try{return Nn(e,{})}catch{return null}}function Ex(e){return!Fu(e.accent)&&Uu(e.accent)?e.accent.trim():Ui(e.name,An.name)?An.accent:zu(e.name)}function Cx(e){return!Fu(e.accent)&&Uu(e.accent)||Ui(e.name,An.name)?null:zu(e.name)}function Bu(e,t=4.5){const n=Uu(e);return n?We({r:1,g:1,b:1,a:1},n)>=t?"white":"black":"white"}const Pl={small:16,large:32},Nx=.22,Px=.76,Wd='"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, -apple-system, "Segoe UI", sans-serif';function Xp(e,t){const n=t*Nx;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 Tx(e,t,n){Xp(e,t),e.fillStyle=n,e.fill()}function Hd(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 bx(e,t,n,r){const o=t*Px;let s=o;e.font=`600 ${s}px ${Wd}`;let i=Hd(e,n);const a=Math.max(i.w,i.h);a>0&&(s=s*o/a,e.font=`600 ${s}px ${Wd}`,i=Hd(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 Rx(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(),Xp(e,t),e.clip(),e.drawImage(n,(t-i)/2,(t-a)/2,i,a),e.restore()}function Lx(e,t){const{content:n,size:r}=t;"glyph"in n?bx(e,r,n.glyph,t.foreground??"white"):"image"in n?Rx(e,r,n.image):e.drawImage(n.icon,0,0,r,r)}const Mx=.22,_x=.07;function Ix(e,t,n){const r=t*Mx,o=t-r;e.save(),e.globalCompositeOperation="destination-out",e.beginPath(),e.arc(o,o,r+t*_x,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||Tx(r,e.size,e.color),Lx(r,e),e.dot&&Ix(r,e.size,e.dot);const o=n.toDataURL("image/png");return o.startsWith("data:image/png")?o:null}catch{return null}}const Or="data-paddock-default-href",bl="data-paddock-default-type",vi="data-paddock-favicon";function Zp(e){return Array.from(e.head.querySelectorAll('link[rel~="icon"]'))}function Dx(e,t=document){let n=Zp(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(Or)&&!r.hasAttribute(vi)&&(r.setAttribute(Or,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 Vd(e=document){for(const t of Zp(e)){if(t.hasAttribute(vi)){t.remove();continue}if(!t.hasAttribute(Or))continue;t.setAttribute("href",t.getAttribute(Or)??"");const n=t.getAttribute(bl);n?t.setAttribute("type",n):t.removeAttribute("type"),t.removeAttribute(Or),t.removeAttribute(bl)}}function Ox(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(Or)??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 Kd(e,t,n){const r=Bu(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 $x(e){return(Array.from(e.trim())[0]??"P").toUpperCase()}function Ax(e,t){if(jx(e))return t({kind:"shipped"}),()=>{};const n=Ex(e),r=e.logo.trim(),o={glyph:$x(e.name)};if(!Yp(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 zx(e,t,n){const r=t?px[t]:void 0;switch(e.kind){case"shipped":return r?n().then(o=>o?Kd({icon:o},"transparent",r):null):null;case"chip":return Kd(e.content,e.color,r);case"raw":return{small:e.src,large:e.src}}}function Fx(e,t=null){const{name:n,logo:r,accent:o}=e,[s,i]=y.useState(null),a=y.useRef(new WeakMap),u=y.useRef(null);y.useEffect(()=>Ax({name:n,logo:r,accent:o},i),[n,r,o]),y.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?Dx(g):Vd()};if(d.has(c)){f(d.get(c)??null);return}const w=zx(s,t,()=>{if(!u.current){const g=Ox(),N=g?Rl(g,!1).catch(()=>(u.current===N&&(u.current=null),null)):Promise.resolve(null);u.current=N}return u.current});if(!(w instanceof Promise)){d.set(c,w),f(w);return}let k=!1;return w.then(g=>{g&&d.set(c,g),k||f(g)}),()=>{k=!0}},[s,t]),y.useEffect(()=>()=>Vd(),[])}const qp={running:!1,unread:0,kind:"none"};function Ux(e,{active:t,finished:n,hiddenSince:r}){if(!e)return qp;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 Bx(e){let t=e.running?"● ":"";return e.unread>0&&(t+=e.kind==="chat"?"✓ ":`(${e.unread}) `),t}function Wx(e){return e.running?"running":e.unread>0?"unread":null}function Hs(e){return e?e.kind==="chat"?`chat:${e.sessionId}:${e.unread?1:0}`:e.kind==="workspace"?`ws:${e.key}`:"instance":"none"}const em=y.createContext({status:qp,scopeKey:"none",setScope:()=>{}});function RS(e){const{status:t,scopeKey:n,setScope:r}=y.useContext(em),o=Hs(e),s=y.useMemo(()=>e,[o]);return y.useEffect(()=>{r(s)},[s,r]),y.useEffect(()=>()=>r(null),[r]),n===o?Bx(t):""}function Hx(){const[e,t]=y.useState(()=>typeof document<"u"&&document.visibilityState==="hidden"?Date.now():null);return y.useEffect(()=>{const n=()=>t(r=>document.visibilityState==="hidden"?r??Date.now():null);return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Vx(e){const[t,n]=y.useState(null),r=y.useCallback(u=>{n(c=>Hs(c)===Hs(u)?c:u)},[]),o=Hx(),s=Ux(t,{...e,hiddenSince:o}),i=Hs(t),a=`${i}|${s.kind}|${s.running?1:0}|${s.unread}`;return y.useMemo(()=>({status:s,scopeKey:i,setScope:r}),[a,r])}const Wu=[{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."}],Qd="",tm=new Map(Wu.map(e=>[e.slug,e]));function Kx(e){if(!e)return"Unsorted";const t=tm.get(e);return t?t.label:e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function LS(e){var t;return(t=tm.get(e))==null?void 0:t.blurb}function Qx(e){const t=new Set(e),n=[];for(const o of Wu)t.has(o.slug)&&(n.push(o.slug),t.delete(o.slug));const r=t.delete(Qd);return n.push(...[...t].sort()),r&&n.push(Qd),n}const nm=25e3,rm=1e4,Gx=nm+rm+5e3,Yx=500,Jx=1e4;class Xx{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<Gx}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(),nm)}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())},rm)}}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(Jx,Yx*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,h,w,k,g,N,m,p,v,E,T,R,M,x,D,b,W,te,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:Z}=n.payload;if(O&&Y&&se)for(const Ee of this.stopTaskListeners)Ee(O,{taskId:Y,outcome:se,message:Z});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);(h=O==null?void 0:(f=O.handlers).onResync)==null||h.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 Z of this.backgroundListeners)Z(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=(w=O.handlers).onActive)==null||k.call(w,{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:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{Z(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((N=(g=Z.handlers).onQueuedFlushed)==null||N.call(g,{text:Y,attachments:se}))}return}if(n.type==="chat:queued_state"){const{sessionId:O,text:Y,qid:se,reason:Z,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&&((p=(m=Ut.handlers).onQueuedState)==null||p.call(m,{text:ie,attachments:ze,qid:se,reason:Z}))}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:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}=await import("./queued-CagZVfWU.js");return{writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie}},[]).then(({writeQueued:Z,writeQueuedId:Ee,writeQueuedAttachments:ie})=>{Z(O,r,null),Ee(O,r,null),ie(O,r,[])});for(const Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((E=(v=Z.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 Z of this.subs.values())Z.projectSlug===r&&Z.sessionId===O&&((R=(T=Z.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":(x=(M=i.handlers).onResponse)==null||x.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":(te=(W=i.handlers).onToolStart)==null||te.call(W,{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 Hu=new Xx,nn=new Map,Ll="paddock:lastSeen-changed";function Vu(e){try{window.dispatchEvent(new CustomEvent(Ll,{detail:{sessionId:e}}))}catch{}}function Zx(e){return nn.get(e)??0}function qx(e,t){!t||!Number.isFinite(t)||t<=(nn.get(e)??0)||(nn.set(e,t),Vu(e))}function MS(e,t=Date.now()){const n=nn.get(e)??0;return t<=n||(nn.set(e,t),Vu(e)),n}function _S(e,t,n){nn.get(e)===n&&(t?nn.set(e,t):nn.delete(e),Vu(e))}const Ml="paddock:chats-gone";function IS(e){if(e.length!==0){for(const t of e)nn.delete(t);try{window.dispatchEvent(new CustomEvent(Ml,{detail:{sessionIds:e}}))}catch{}}}const e1=/^\d{4}-\d{2}-\d{2}$/;function yi(e){if(!e)return"";if(e1.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 h=new Date,w=new Date(h.getFullYear(),h.getMonth(),h.getDate()),k=Math.round((w.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 DS(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 t1(e){return!Number.isFinite(e)||e<=0?"$0.00":e<.01?"<$0.01":`$${e.toFixed(2)}`}function OS(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 $S(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} · ~${t1(e.costUsd)} at API rates`}function AS(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 n1="This session is being continued from a previous conversation";function zS(e){return e.trimStart().startsWith(n1)}function FS(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 US(e){return e.trimStart().startsWith("<local-command-caveat>")}function BS(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 WS(e){return/^\s*<local-command-stdout>[\s\S]*<\/local-command-stdout>\s*$/.test(e)}function HS(e){return e.trimStart().startsWith("<task-notification>")}function VS(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 KS(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 QS(e){return e==="killed"||e==="stopped"}function r1(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 o1(){try{return localStorage.getItem(_l)==="1"}catch{return!1}}function Gd(e){try{e?localStorage.setItem(_l,"1"):localStorage.removeItem(_l)}catch{}}let xo=null;function s1(){if(!xo)try{xo=lr.transcriptsMigration().catch(()=>null)}catch{xo=Promise.resolve(null)}return xo}function i1(){xo=null}function om(){const[e,t]=y.useState(null),[n,r]=y.useState(o1);y.useEffect(()=>{let s=!0;return s1().then(i=>{!s||!i||(t(i),i&&!i.eligible&&(Gd(!1),r(!1)))}),()=>{s=!1}},[]);const o=y.useCallback(()=>{Gd(!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 a1(e){return new Set(Bi(e).filter(t=>t.defaultSelected).map(t=>t.sessionId))}function l1(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 u1(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 c1(e,t){return t?new Set(Bi(e).map(n=>n.sessionId)):new Set}function d1(e,t){const n=new Set(e);return n.delete(t)||n.add(t),n}function f1(e,t){const n=Bi(e).map(r=>r.sessionId);return{sessionIds:n.filter(r=>t.has(r)),plannedSessionIds:n,expectedVersion:e.configVersion}}function h1(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 sm(e){return e?e.projects.length===0&&e.sweepers.stores===0:!1}function im(e){return!e.ok||e.failed.length>0?"partial":e.alreadyMigrated?"already":e.migrated.length===0&&e.preserved.length===0?"nothing":"done"}function p1(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 m1={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 m1[e]??{label:String(e),hint:"This Paddock build does not recognise this state, so it is shown as the server described it."}}function Yd(e){const t=e.indexOf("/.claude/");return t===-1?e:`~${e.slice(t)}`}function g1(e,t){return t==="all"?!0:t==="needs-decision"?!e.defaultSelected:e.state===t}function Ye(...e){return e.filter(Boolean).join(" ")}const v1={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"},y1={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",y1[t],v1[e],i),...d,children:[n,r&&o?o:a]})}const Ku=["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 GS({className:e,...t}){return l.jsx("input",{className:Ye(Ku,e),...t})}function YS({className:e,...t}){return l.jsx("textarea",{className:Ye(Ku,"resize-y",e),...t})}function JS({className:e,...t}){return l.jsx("select",{className:Ye(Ku,e),...t})}function XS({checked:e,onChange:t,label:n,disabled:r,id:o,className:s}){const i=y.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 am({label:e,description:t,indeterminate:n=!1,className:r,...o}){const s=y.useRef(null);y.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 lm={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"},um={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 x1({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",lm[e],i),children:[r&&l.jsx("span",{className:Ye("h-1.5 w-1.5 shrink-0 rounded-full",um[e])}),o,a]})}function ZS({tone:e="neutral",pulse:t=!1,className:n}){return l.jsx("span",{className:Ye("inline-block h-2 w-2 shrink-0 rounded-full",um[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",lm[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 w1(e,t){y.useEffect(()=>{if(!e)return;const n=r=>{r.key==="Escape"&&t()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,t])}const S1={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl"};function k1({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 h=y.useRef(null),w=y.useRef(null);if(w1(e,t),y.useEffect(()=>{var N,m;return e?(w.current=document.activeElement,(m=((N=h.current)==null?void 0:N.querySelector("[autofocus], input:not([type=hidden]), textarea, select, button, [href], [tabindex]:not([tabindex='-1'])"))??h.current)==null||m.focus(),()=>{const p=w.current;p instanceof HTMLElement&&p.focus()}):void 0},[e]),y.useEffect(()=>{if(!e)return;const g=N=>{if(N.key!=="Tab"||!h.current)return;const m=[...h.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 p=m[0],v=m[m.length-1],E=document.activeElement;N.shiftKey&&(E===p||!h.current.contains(E))?(N.preventDefault(),v.focus()):!N.shiftKey&&E===v&&(N.preventDefault(),p.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:h,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",S1[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 cm({content:e,children:t,delayMs:n=250,className:r=""}){const o=y.useId(),s=y.useRef(null),i=y.useRef(null),a=y.useRef(null),[u,c]=y.useState(null),d=()=>{a.current&&clearTimeout(a.current),a.current=null},f=y.useCallback(()=>{d(),c(null)},[]),h=y.useCallback(()=>{var m;const g=(m=s.current)==null?void 0:m.getBoundingClientRect();if(!g)return;const N=g.top<56;c({x:g.left+g.width/2,y:N?g.bottom+6:g.top-6,below:N})},[]);y.useEffect(()=>d,[]),y.useEffect(()=>{if(!u)return;const g=N=>{N.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]),y.useLayoutEffect(()=>{if(!u||!i.current)return;const g=i.current.offsetWidth;if(!g)return;const N=8+g/2,m=window.innerWidth-8-g/2,p=Math.min(Math.max(u.x,N),Math.max(N,m));p!==u.x&&c({...u,x:p})},[u]);const w=y.Children.only(t),k=y.isValidElement(w)?y.cloneElement(w,{"aria-describedby":u?o:void 0}):w;return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:s,className:`inline-flex ${r}`,onPointerEnter:g=>{g.pointerType!=="touch"&&(d(),a.current=setTimeout(h,n))},onPointerLeave:f,onPointerDown:f,onFocusCapture:h,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 dm({open:e,onClose:t,onCompleted:n}){const[r,o]=y.useState(null),[s,i]=y.useState(new Set),[a,u]=y.useState({kind:"loading"}),[c,d]=y.useState("all"),f=y.useRef(!1),h=y.useCallback(async()=>{u({kind:"loading"});try{const v=await lr.transcriptsMigrationChats();o(v),i(a1(v)),u({kind:"plan"})}catch(v){u({kind:"load-failed",message:mm(v)})}},[]);y.useEffect(()=>{e&&(d("all"),h())},[e,h]);const w=y.useMemo(()=>Bi(r),[r]),k=y.useMemo(()=>h1(r),[r]),g=y.useMemo(()=>w.reduce((v,E)=>v+(s.has(E.sessionId)?1:0),0),[w,s]),N=y.useMemo(()=>w.filter(F1).length,[w]),m=y.useCallback(async()=>{if(!(!r||f.current)){f.current=!0,u({kind:"running"});try{const v=await lr.runTranscriptsMigration(f1(r,s));i1(),u({kind:"result",result:v}),v.ok&&(n==null||n())}catch(v){u({kind:"refused",error:v})}finally{f.current=!1}}},[r,s,n]),p=a.kind==="running";return l.jsxs(K1,{open:e,onClose:p?()=>{}:t,dismissOnBackdrop:!p,title:B1(a),footer:l.jsx($1,{phase:a,plan:r,rows:w,selectedCount:g,alsoMoving:k.total,onClose:t,onRetry:m,onReload:h,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(Ne,{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(L1,{plan:r,count:g}),a.kind==="refused"&&l.jsx(M1,{error:a.error,plan:r,rows:w,selected:s}),a.kind==="result"&&l.jsx(I1,{result:a.result}),a.kind==="plan"&&r&&l.jsx(j1,{plan:r,rows:w,selected:s,setSelected:i,filter:c,setFilter:d,decisionCount:N,alsoMoving:k})]})}function j1({plan:e,rows:t,selected:n,setSelected:r,filter:o,setFilter:s,decisionCount:i,alsoMoving:a}){if(sm(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(Ne,{children:".chats/"})," is already empty, so there is nothing to merge into your ",l.jsx(Ne,{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(Ne,{children:"~/.claude"}),"."," ",l.jsxs("span",{className:"text-fg-muted",children:["The rest are set aside in ",l.jsx(Ne,{children:".chats-pre-migration/"}),", not deleted."]})]}),l.jsx(E1,{plan:e}),l.jsx(C1,{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(am,{checked:u,indeterminate:!u&&n.size>0,onChange:()=>r(c1(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(T1,{project:d,selected:n,setSelected:r,filter:o},d.slug))}),a.total>0&&l.jsx(N1,{alsoMoving:a})]})}function E1({plan:e}){const[t,n]=y.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(fm,{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(hm,{warnings:e.warnings})]})]})}function C1({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(Ca,{active:t==="all",onClick:()=>n("all"),label:`All ${e.totals.chats.toLocaleString()}`}),r>0&&l.jsx(Ca,{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(cm,{content:xi(s).hint,children:l.jsx(Ca,{active:t===s,onClick:()=>n(s),label:`${i.toLocaleString()} ${xi(s).label.toLowerCase()}`,tone:pm[s]})},s))]})}function Ca({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 N1({alsoMoving:e}){const[t,n]=y.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(fm,{open:t}),l.jsxs("span",{children:["Also moving: ",l.jsx("span",{className:"text-fg",children:P1(e)})]})]}),t&&l.jsxs("p",{className:"mt-1.5 pl-5 text-xs text-fg-muted",children:[V1(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(Ne,{children:".chats/"})," has to end up completely empty for the switch to take effect."]})]})}function P1(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 fm({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 T1({project:e,selected:t,setSelected:n,filter:r}){const o=e.chats.filter(a=>g1(a,r)),s=y.useMemo(()=>({...e,chats:o}),[e,o]),i=l1(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(cm,{content:l.jsxs("span",{className:"block max-w-xs break-all font-mono text-2xs",children:["→ ",Yd(e.hostStore),o.some(U1)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),"kept, not deleted → ",Yd(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(am,{checked:i.all,indeterminate:i.some,onChange:()=>n(u1(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(b1,{chat:a,checked:t.has(a.sessionId),onToggle:()=>n(d1(t,a.sessionId))},a.sessionId))})]})}function b1({chat:e,checked:t,onToggle:n}){const r=e.state==="diverged"||e.state==="unknown";return l.jsx("li",{children:l.jsxs("label",{title:z1(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(A1,{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(R1,{chat:e,checked:t})]})]})})}function R1({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(Jd,{title:"Paddock's copy",side:e.own,wins:t,note:t?"moves into ~/.claude":"kept in the preserve folder"}),l.jsx(Jd,{title:"Your ~/.claude copy",side:e.host,wins:!t,note:t?"moved aside, kept":"stays where it is"})]}):null}function Jd({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"}`:H1(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 L1({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(Ne,{children:((n=e==null?void 0:e.projects[0])==null?void 0:n.hostStore.replace(/\/[^/]*$/,"/…"))??"~/.claude"}),"."]}),l.jsxs("li",{children:["Setting ",l.jsx(Ne,{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 M1({error:e,plan:t,rows:n,selected:r}){const o=e instanceof $n?e.code:void 0,s=W1(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:_1[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:mm(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(Ne,{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(Ne,{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(Ne,{children:"PADDOCK_CLAUDE_TRANSCRIPTS"})," is set in this server's environment, and an environment variable beats the config file. Writing"," ",l.jsx(Ne,{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 _1={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 I1({result:e}){const t=im(e),n=p1(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(Ne,{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(Ne,{children:"~/.claude"})," and"," ",l.jsx(Ne,{children:"claude.transcripts"})," was already ",l.jsx(Ne,{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(Ne,{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(D1,{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:Xd(o)}),l.jsxs("span",{className:"block text-fg-muted",children:[o.reason,o.message?` — ${o.message}`:""]}),o.path&&Xd(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(Ne,{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:O1(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(hm,{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 D1({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(Ne,{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(Ne,{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(Ne,{children:"~/.claude"})," or in the folders listed below. Fix what is reported above, run this again, and restart when it completes."]})]})}function O1(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"}):sm(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 hm({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 pm={new:"success","fast-forward":"info",diverged:"warn",unknown:"neutral"};function A1({state:e,n:t}){if(t===0)return null;const n=xi(e);return l.jsx(x1,{tone:pm[e]??"neutral",title:n.hint,children:t===void 0?n.label:`${t.toLocaleString()} ${n.label.toLowerCase()}`})}function z1(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 F1(e){return!e.defaultSelected}function U1(e){return e.state==="diverged"||e.state==="unknown"}function Ne({children:e}){return l.jsx("span",{className:"break-all font-mono",children:e})}function mm(e){return e instanceof Error?e.message:String(e)}function B1(e){const t="Merge chats into ~/.claude";if(e.kind!=="result")return t;switch(im(e.result)){case"partial":return`${t} — unfinished`;case"already":return`${t} — nothing to do`;default:return`${t} — done`}}function Xd(e){return e.sessionId&&e.sessionId!=="-"?e.sessionId:e.path??"Project files"}function W1(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 H1(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function V1(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 K1(e){return l.jsx(k1,{...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 Q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M12 5v14M5 12h14"})}),qS=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"})}),G1=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"})]}),ek=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"})}),Zd=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"})]}),tk=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"})]}),nk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),rk=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"})}),ok=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"})]}),sk=e=>l.jsx("svg",{...J(e),children:l.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),ik=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"})]}),Y1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m9 18 6-6-6-6"})}),ak=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"})}),J1=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"})]}),X1=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"})]}),lk=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"})}),uk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12z"})}),ck=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M6 4.5v15l13-7.5z"})}),Z1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M3 6h18M3 12h18M3 18h18"})}),dk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("circle",{cx:"12",cy:"12",r:"9"}),l.jsx("path",{d:"M12 7v5l3 2"})]}),fk=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"})]}),hk=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"})}),pk=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"})]}),mk=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"})]}),gk=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"})]}),q1=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M20 6 9 17l-5-5"})}),vk=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"})]}),yk=e=>l.jsxs("svg",{...J(e),children:[l.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),l.jsx("path",{d:"M5 21h14"})]}),xk=({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"})]}),wk=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"})]}),Sk=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"})]}),kk=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"})]}),jk=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"M4 17l6-5-6-5M12 19h8"})}),Ek=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"})}),ew=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"})]}),tw=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"})}),nw=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"})]}),Ck=e=>l.jsx("svg",{...J(e),children:l.jsx("path",{d:"m6 9 6 6 6-6"})}),Nk=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"})]}),Pk=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 rw({message:e,tone:t="success",onDismiss:n,durationMs:r=6e3,action:o}){if(y.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(X1,{width:16,height:16,className:"mt-0.5 shrink-0"}):l.jsx(q1,{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 ow(){const{showBanner:e,dismiss:t}=om(),n=ts(),[r,o]=y.useState(!1),[s,i]=y.useState(null),[a,u]=y.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(dm,{open:r,onClose:()=>o(!1),onCompleted:()=>u(!0)}),l.jsx(rw,{message:s,onDismiss:()=>i(null),durationMs:12e3,action:{label:"Open Config",onAct:()=>{i(null),n("/config")}}})]})}function Tk(){const{showInConfig:e}=om(),[t,n]=y.useState(!1),[r,o]=y.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(dm,{open:t,onClose:()=>n(!1),onCompleted:()=>o(!0)})]}):null}const Na=6,sw=.75,iw=.9,aw=250,lw=3e4;function uw(e){const[,t]=y.useState(0);y.useEffect(()=>{if(e==null)return;const n=setInterval(()=>t(r=>r+1),e);return()=>clearInterval(n)},[e])}function cw(){const[e,t]=y.useState(new Map);return y.useEffect(()=>Hu.onActiveInfos(n=>t(new Map(n))),[]),e}function dw(e,t){const[n,r]=y.useState(new Map),o=y.useRef(0);return y.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(([h])=>s.has(h)));return f.size===d.size?d:f});let i=!1;const a=async()=>{const d=++o.current;try{const f=await lr.attentionChats(Iu);if(i||d!==o.current)return;r(h=>{const w=new Map([...h].filter(([k])=>s.has(k)));for(const k of[...f.recent??[],...f.unread??[],...f.running??[]]){if(!s.has(k.sessionId))continue;const g=w.get(k.sessionId);w.set(k.sessionId,k.contextTokens==null&&(g==null?void 0:g.contextTokens)!=null?{...k,contextTokens:g.contextTokens,contextLimit:g.contextLimit}:k)}return w})}catch{}},u=setTimeout(()=>void a(),aw),c=e?setInterval(()=>{document.visibilityState==="visible"&&a()},lw):null;return()=>{i=!0,clearTimeout(u),c&&clearInterval(c)}},[e,t]),n}function gm({fill:e}){const t=e<=0?0:Math.max(1,Math.min(Na,Math.round(e*Na))),n=e<sw?"bg-accent-solid":e<iw?"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:Na},(r,o)=>l.jsx("span",{className:Ye("h-2.5 w-[3px] rounded-[1px]",o<t?n:"bg-edge")},o))})}function fw({projectSlug:e,projectName:t,chatName:n,sessionId:r,startedAt:o,fill:s}){const i=o==null?"—:—":r1(Date.now()-o),a=n??"Running turn";return l.jsxs(ns,{"data-testid":"fleet-channel",to:`${Vp(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(gm,{fill:s})]})}function hw({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(ns,{"data-testid":"fleet-finished",to:`${Vp(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(gm,{fill:s})})]})}function pw(){const e=y.useRef(null),[t,n]=y.useState(!1),[r,o]=y.useState(!1);return y.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 qd({value:e,unit:t,to:n,tone:r,title:o}){return l.jsxs(ns,{"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 mw({unread:e,finished:t=[]}){const{projects:n,rootWorkspace:r}=Qp(),o=cw(),s=y.useMemo(()=>[...o.keys()].sort().join(","),[o]),i=y.useMemo(()=>t.map(g=>g.sessionId).join(","),[t]),a=dw(s,i);uw(o.size>0?1e3:t.length>0?3e4:null);const u=pw(),c=y.useMemo(()=>{const g=new Map;for(const N of n)g.set(N.slug,N.name);return r&&g.set(r.slug,r.name),g},[n,r]),d=y.useMemo(()=>[...o.entries()].map(([g,N])=>{const m=a.get(g);return{sessionId:g,projectSlug:N,projectName:c.get(N)??(m==null?void 0:m.projectName)??N,chatName:(m==null?void 0:m.name)??null,startedAt:Hu.turnStartedAt(g),fill:(m==null?void 0:m.contextTokens)!=null&&m.contextLimit?Math.min(1,m.contextTokens/m.contextLimit):null}}).sort((g,N)=>(g.startedAt??1/0)-(N.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,h=t.map(g=>{const N=a.get(g.sessionId);return{...g,projectName:c.get(g.projectSlug)??(N==null?void 0:N.projectName)??g.projectSlug,chatName:(N==null?void 0:N.name)??null,fill:f(N)}}),w=y.useMemo(()=>{let g="";for(const N of r?[...n,r]:n)for(const m of N.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(qd,{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(qd,{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(fw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,startedAt:g.startedAt,fill:g.fill},g.sessionId)),h.map(g=>l.jsx(hw,{projectSlug:g.projectSlug,projectName:g.projectName,chatName:g.chatName,sessionId:g.sessionId,at:g.at,fill:g.fill},g.sessionId)),d.length===0&&h.length===0&&(w?l.jsxs("span",{className:"truncate text-2xs text-fg-subtle",children:["Idle · last turn ",yi(w)]}):l.jsx(ns,{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(ow,{}),l.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})}const vm="paddock:area-collapsed:";function ym(e){return vm+(e||"unsorted")}const Il=new Set,gw=()=>{for(const e of Il)e()};function ef(e){try{return localStorage.getItem(ym(e))==="1"}catch{return!1}}function vw(e,t){try{localStorage.setItem(ym(e),t?"1":"0")}catch{}gw()}function yw(e){Il.add(e);const t=n=>{(n.key===null||n.key.startsWith(vm))&&e()};return window.addEventListener("storage",t),()=>{Il.delete(e),window.removeEventListener("storage",t)}}function xw(e){const t=y.useSyncExternalStore(yw,()=>ef(e),()=>!1),n=y.useCallback(()=>vw(e,!ef(e)),[e]);return[t,n]}function ww({tag:e,className:t=""}){const n=ts();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})}let Pa;function Sw(){if(Pa===void 0){const e=Intl.Segmenter;Pa=e?new e(void 0,{granularity:"grapheme"}):null}return Pa}function tf(e){const t=Sw();return t?Array.from(t.segment(e),n=>n.segment):Array.from(e)}const kw=/[^\p{Cf}\p{Cc}\p{M}\p{Z}\p{White_Space}]/u;function jw(e){const t=tf(e.normalize("NFC")).filter(o=>kw.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 tf(r).length===1?r:n}function Ew({slug:e,name:t,color:n,className:r=""}){const o=n??zu(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:Bu(o)},children:jw(t)})}function Cw({sections:e,badges:t,chipColors:n}){var s;const r=(s=k0("/projects/:slug/*"))==null?void 0:s.params.slug,o=e.length>1;return l.jsx(l.Fragment,{children:e.map(([i,a])=>l.jsx(Nw,{slug:i,projects:a,badges:t,chipColors:n,activeSlug:r,showHeading:o},i||"unsorted"))})}function Nw({slug:e,projects:t,badges:n,chipColors:r,activeSlug:o,showHeading:s}){const[i,a]=xw(e),u=y.useId(),c=s&&i,d=c?t.filter(h=>h.slug===o):t,f=y.useMemo(()=>{const h={unread:0,inflight:0};if(!c)return h;for(const w of t){if(w.slug===o)continue;const k=n.get(w.slug);h.unread+=(k==null?void 0:k.unread)??0,h.inflight+=(k==null?void 0:k.inflight)??0}return h},[c,t,o,n]);return l.jsxs("div",{className:"mb-2",children:[s&&l.jsxs("button",{type:"button",onClick:a,"aria-expanded":!i,"aria-controls":u,title:i?"Expand group":"Collapse group",className:"flex w-full items-center gap-1 rounded-md px-2.5 pb-1 pt-2 text-left text-3xs font-semibold uppercase tracking-wider text-fg-subtle hover:text-fg-muted focus-visible:focus-ring",children:[l.jsx(Y1,{width:10,height:10,"aria-hidden":"true",className:`-ml-0.5 shrink-0 transition-transform ${i?"":"rotate-90"}`}),l.jsx("span",{className:"min-w-0 truncate",children:Kx(e)}),l.jsx(Qu,{badge:f,className:"ml-auto font-normal normal-case tracking-normal"})]}),l.jsx("div",{id:u,children:d.map(h=>l.jsx(Pw,{project:h,badge:n.get(h.slug),chipColor:r.get(h.slug)},h.slug))})]})}function Pw({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(Ew,{slug:e.slug,name:e.name,color:n}),l.jsx("span",{className:"truncate font-medium",children:e.name})]}),l.jsx(Qu,{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(ww,{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 Qu({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})]})}function nf(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e:"~"}function Tw(e,t,n){const r=Math.abs(e-t)%n;return Math.min(r,n-r)}function bw(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,Sx(i,c));const u=Tw(i,t,n);(a>o||a===o&&u<s)&&(r=i,o=a,s=u)}return r}function Rw(e){const t=rs.length,n=[...e].sort((s,i)=>{const a=nf(s.started),u=nf(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=Jp(s),a=!r.has(i)||r.size>=t?i:bw(r,i,t);r.add(a),o.set(s,a)}return o}function Lw(e){const t=new Map;for(const[n,r]of Rw(e))t.set(n,rs[r]);return t}const Mw=["idea","active","paused","blocked","done"];function _w({open:e,onClose:t,onCreated:n}){const[r,o]=y.useState(""),[s,i]=y.useState(""),[a,u]=y.useState(""),[c,d]=y.useState(""),[f,h]=y.useState("active"),[w,k]=y.useState(""),[g,N]=y.useState(""),[m,p]=y.useState(!1),[v,E]=y.useState(!1),[T,R]=y.useState(null);if(y.useEffect(()=>{e&&(o(""),i(""),u(""),d(""),h("active"),k(""),N(""),p(!1),R(null))},[e]),y.useEffect(()=>{const x=D=>{D.key==="Escape"&&e&&!v&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[e,v,t]),!e)return null;const M=async x=>{if(x.preventDefault(),!!r.trim()){E(!0),R(null);try{const D=await lr.createProject({name:r.trim(),status:f,group:c||void 0,summary:s.trim()||void 0,repo:w.trim()||void 0,path:g.trim()||void 0,managed:g.trim()&&!w.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:x=>x.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:x=>o(x.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:x=>i(x.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:x=>d(x.target.value),children:[l.jsx("option",{value:"",children:"Unsorted"}),Wu.map(x=>l.jsx("option",{value:x.slug,children:x.label},x.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:x=>N(x.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:w,onChange:x=>k(x.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()&&!w.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:x=>p(x.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:x=>u(x.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:x=>h(x.target.value),children:Mw.map(x=>l.jsx("option",{value:x,className:"capitalize",children:x},x))})]})]}),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 rf(e){if(typeof window>"u"||typeof window.matchMedia!="function")return null;try{return window.matchMedia(e)??null}catch{return null}}function Iw(e){const[t,n]=y.useState(()=>{var r;return((r=rf(e))==null?void 0:r.matches)??!1});return y.useEffect(()=>{var s;const r=rf(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 Gu="paddock:panewidth:",Dw={key:"sidenav",def:288,min:200,max:480},bk={key:"chatlist",def:256,min:220,max:520},Ow="(min-width: 1024px)";function $r(e,t){return Math.min(Math.max(t,e.min),e.max)}function of(e,t,n){return $r(n,e+t)}function $w(e){try{const t=localStorage.getItem(Gu+e.key);if(t==null)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?$r(e,n):null}catch{return null}}function Aw(e,t){try{localStorage.setItem(Gu+e.key,String($r(e,t)))}catch{}}function zw(e){try{localStorage.removeItem(Gu+e.key)}catch{}}function Fw(e){const t=Iw(Ow),[n,r]=y.useState(()=>$w(e)),o=$r(e,n??e.def);return{isDesktop:t,width:o,style:t?{width:o}:void 0,preview:s=>r($r(e,s)),commit:s=>{const i=$r(e,s);r(i),Aw(e,i)},reset:()=>{r(null),zw(e)},spec:e}}function Uw({spec:e,width:t,onPreview:n,onCommit:r,onReset:o,label:s}){const i=y.useRef(null),a=y.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(of(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=of(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]=y.useState(new Map),r=y.useRef(new Map),[o,s]=y.useState(0);return y.useEffect(()=>{const i=r.current;for(const a of e)for(const u of a.chatTurns??[]){qx(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]),y.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)},[]),y.useEffect(()=>{const i=new Map;return Hu.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)})},[]),y.useEffect(()=>{const i=()=>s(a=>a+1);return window.addEventListener(Ll,i),()=>window.removeEventListener(Ll,i)},[]),y.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:h}]of r.current)!t.has(c)&&(h||f>Zx(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 Ww(){const{projects:e,rootWorkspace:t,loading:n,upsert:r}=Qp(),{dark:o,toggle:s}=hx(),[i,a]=y.useState(!1),[u,c]=y.useState(!1),d=ts(),f=Wn(),h=Gp(),w=gx(),k=Fw(Dw),g=f.pathname==="/"||f.pathname==="/projects"||f.pathname.startsWith("/chat"),N=f.pathname.startsWith("/projects/")||g;y.useEffect(()=>{a(!1)},[f.pathname]);const m=y.useMemo(()=>{const b=new Map;for(const W of e){const te=W.group??"",ce=b.get(te);ce?ce.push(W):b.set(te,[W])}return Qx(b.keys()).map(W=>[W,b.get(W)??[]])},[e]),p=y.useMemo(()=>Lw(e),[e]),v=y.useMemo(()=>t?[...e,t]:e,[e,t]),{badges:E,unreadChats:T,active:R}=Bw(v),M=Vx({active:R,finished:T});Fx(h,Wx(M.status));const x=E.get(Iu),D=y.useMemo(()=>{let b=0;for(const W of E.values())b+=W.unread;return b},[E]);return l.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden bg-surface lg:flex-row",children:[!N&&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(Z1,{width:20,height:20})}),l.jsxs(yn,{to:"/",className:"flex items-center gap-2",children:[l.jsx(sf,{brand:h,className:"h-7 w-7 text-sm"}),l.jsx("span",{className:"text-md font-semibold tracking-tight",children:h.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(Uw,{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(sf,{brand:h,className:"h-8 w-8 text-base"}),l.jsx("span",{className:"text-lg font-semibold tracking-tight",children:h.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(G1,{width:16,height:16}),"Home",l.jsx(Qu,{badge:x,className:"ml-auto"})]})}),l.jsxs("div",{className:"mt-5 mb-1 flex items-center justify-between pr-3",children:[l.jsx(yn,{to:ax(),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(Zd,{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(Q1,{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&&l.jsx(Cw,{sections:m,badges:E,chipColors:p})]}),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(J1,{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(Zd,{width:15,height:15}),"Discover"]}),w.enabled&&l.jsxs("a",{href:w.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(nw,{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(ew,{width:15,height:15}):l.jsx(tw,{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.81.0"]})]})]}),l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[l.jsx(mw,{unread:D,finished:T}),l.jsx("main",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:l.jsx(y.Suspense,{fallback:l.jsx(Hw,{}),children:l.jsx(em.Provider,{value:M,children:l.jsx($0,{context:{openNav:()=>a(!0)}})})})})]}),l.jsx(_w,{open:u,onClose:()=>c(!1),onCreated:b=>{r(b),c(!1),d(`/projects/${b.slug}/chat`)}})]})}function sf({brand:e,className:t=""}){const n=Cx(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:Bu(n)}:void 0,"data-testid":"brand-chip",children:Yp(e.logo)?l.jsx("img",{src:e.logo,alt:"",className:"h-full w-full object-cover"}):e.logo})}function Hw(){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…"})]})}const xm="paddock:chunkReloadAt",Vw=1e4,af=/dynamically imported module|module script|importing a module|failed to fetch|unable to preload|load failed|error loading/i;function Kw(e){return e?e instanceof Error?e.name==="ChunkLoadError"?!0:af.test(e.message):af.test(String(e)):!1}function Yu(){try{return typeof sessionStorage<"u"?sessionStorage:void 0}catch{return}}function Qw(e=Date.now(),t=Yu()){if(!t)return!1;const n=t.getItem(xm);if(!n)return!1;const r=Number(n);return Number.isFinite(r)&&e-r<Vw}function Gw(e=Date.now(),t=Yu()){try{t==null||t.setItem(xm,String(e))}catch{}}function Yw(e,t=Date.now(),n=Yu()){return Kw(e)&&!Qw(t,n)?"reload":"show"}function Jw(){const e=Bp(),t=Yw(e);if(y.useEffect(()=>{t==="reload"&&(Gw(),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 Xw(){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,wm=3,Tt=.12,Sm=["--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 Nn(r,{})}catch{return null}}function Zw(e,t,n){let r=0,o=1;for(let s=0;s<32;s++){const i=(r+o)/2;et(Gr(i,t,n))<e?r=i:o=i}return(r+o)/2}function km(e,t,n){if(zd(e,t,n))return t;let r=0,o=t;for(let s=0;s<24;s++){const i=(r+o)/2;zd(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=Zw(s,i,n);let d=o?0:c,f=o?c:1;for(let h=0;h<28;h++){const w=(d+f)/2,k=We(Gr(w,i,n),r)>=e;o?k?d=w:f=w:k?f=w:d=w}a=o?d:f,i=km(a,t,n)}return{L:a,C:i,rgb:Gr(a,i,n)}}const qw=.75;function Ar(e,t,n,r,o,s=e){const i=Ta(e,t,n,r,o),a=f=>f.C>=t*qw;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 h=(u+c)/2,w=Ta(h,t,n,r,o);a(w)?(d=w,u=h):c=h}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 jm=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected","--border-subtle","--border","--border-strong","--text","--text-muted","--text-subtle","--scroll-thumb"],lf=["--text","--text-muted","--text-subtle"],eS=["--surface","--surface-raised","--surface-sunken","--surface-hover","--surface-active","--surface-selected"];function Em(e=document.documentElement){for(const t of jm)e.style.removeProperty(t)}function tS(e,t,n=document.documentElement){Em(n);for(const o of jm){const s=gt(n,o);if(!s)continue;const{L:i,C:a}=tn(s),u=lf.includes(o),c=Math.max(a,t*(u?.5:1));n.style.setProperty(o,Gt(Gr(i,km(i,c,e),e)))}let r=1/0;for(const o of lf){const s=gt(n,o);if(s)for(const i of eS){const a=gt(n,i);a&&(r=Math.min(r,We(s,a)))}}return r}function Cm(e=document.documentElement){for(const t of Sm)e.style.removeProperty(t)}function Nm(e,t){const n=Sm.map(r=>[r,e.style.getPropertyValue(r)]);Cm(e);try{return t()}finally{for(const[r,o]of n)o&&e.style.setProperty(r,o)}}function nS(e=document.documentElement){return Nm(e,()=>{const t=gt(e,"--accent");return t?tn(t).H:0})}const ho={r:1,g:1,b:1,a:1};function Pm(e=document.documentElement){return Nm(e,()=>rS(e))}function rS(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),wm+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 oS(e,t){const n=Dt+Tt;return{accent:Ar(e.targets.accent,e.chroma.accent,t,e.surface,e.darker.accent,wm+Tt),a600:Ar(e.targets.a600,e.chroma.a600,t,e.fg,e.darker.a600,n),a700:Ar(e.targets.a700,e.chroma.a700,t,e.a700Bg,e.darker.a700,n)}}function Rk(e,t=document.documentElement){const n=Pm(t);return e.map(r=>Gt(Ar(n.targets.a600,n.chroma.a600,r,n.fg,n.darker.a600,Dt+Tt).rgb))}function sS(e,t=document.documentElement,n={}){const r=t.classList.contains("dark")?"dark":"light",o=n.context??Pm(t),s=oS(o,e),{a600:i,a700:a,accent:u}=s,c={C:o.chroma.a700};Cm(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=[],h=d["--accent-fg"]??o.fg,w=(v,E,T)=>{const R=d[v];if(!R)return 1/0;let M=We(R,h),x=!1;if(M<T+Tt){const{C:D}=tn(R),b=Ar(T+Tt,Math.max(D,o.chroma.a600),e,h,et(R)<et(h),Dt+Tt);t.style.setProperty(v,Gt(b.rgb)),M=We(b.rgb,h),x=!0}return f.push({label:E,fg:"--accent-fg",bg:v,ratio:M,floor:T,repaired:x}),M},k=w("--accent-solid","Primary button",Dt);w("--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 N=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]);N=We(m,v.c);let E=!1;if(N<Dt+Tt){const{C:T}=tn(m),R=Ar(Dt+Tt,T||c.C,e,v.c,et(m)<et(v.c));t.style.setProperty("--accent-text",Gt(R.rgb)),N=g.reduce((M,x)=>Math.min(M,We(R.rgb,x.c)),1/0),E=!0}f.push({label:"Accent text",fg:"--accent-text",bg:v.name,ratio:N,floor:Dt,repaired:E})}const p={};if(!n.live)for(const v of["--accent-solid","--accent-solid-hover","--accent-text"]){const E=gt(t,v);E&&(p[v]=Gt(E))}return{hue:e,mode:r,channels:{accent:Gt(u.rgb),accent600:Gt(i.rgb),accent700:Gt(a.rgb)},applied:p,checks:f,ok:f.every(v=>v.ratio>=v.floor-.005)&&k>=Dt}}const iS=[{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."}],Lk=[{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}],Mk=[{level:0,label:"None"},{level:1,label:"A little"},{level:2,label:"More"}];function aS(e=document.documentElement){const t=Gp().accent;if(t&&t.toLowerCase()!==An.accent.toLowerCase())try{return tn(Nn(t,{})).H}catch{}return nS(e)}const uf={theme:"foundation",hue:null,tint:0},Tm="paddock:appearance",cf="paddock:appearance-cache";function lS(){try{const e=localStorage.getItem(Tm);if(!e)return uf;const t=JSON.parse(e);return{theme:iS.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 uf}}function uS(e){try{localStorage.setItem(Tm,JSON.stringify(e))}catch{}}function cS(e,t,n){try{const r=JSON.parse(localStorage.getItem(cf)||"{}"),o=`${e}:${t?"dark":"light"}`;n?r[o]={...n.applied,"--accent":n.channels.accent}:delete r[o],localStorage.setItem(cf,JSON.stringify(r))}catch{}}function dS(e,t=document.documentElement){t.setAttribute("data-theme",e.theme);const n=e.hue??aS(t);let r=null;e.tint===0?Em(t):r=tS(n,mS[e.tint],t);const o=sS(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),cS(e.theme,t.classList.contains("dark"),o),o}function fS(e,t){uS(e);const n=dS(e,t);return window.dispatchEvent(new CustomEvent(hS,{detail:n})),n}const hS="paddock:appearance";function pS(){const e=()=>fS(lS());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 mS=[0,.008,.018],bm=y.lazy(()=>Zt(()=>import("./ProjectsGrid-mJ4gqbr6.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.ProjectsGrid}))),Te=y.lazy(()=>Zt(()=>import("./ProjectView-BoBIru1g.js").then(e=>e.a),__vite__mapDeps([4,5,1,2,6,7,3])).then(e=>({default:e.ProjectView}))),gS=y.lazy(()=>Zt(()=>import("./ProjectRedirect-Bq7GVguY.js"),__vite__mapDeps([8,2])).then(e=>({default:e.ProjectRedirect}))),vS=y.lazy(()=>Zt(()=>import("./InstanceConfigPage-RSJz7oL3.js"),__vite__mapDeps([9,6,3])).then(e=>({default:e.InstanceConfigPage}))),yS=y.lazy(()=>Zt(()=>import("./DiscoverPage-CQlzxsn4.js"),__vite__mapDeps([10,7,6,3])).then(e=>({default:e.DiscoverPage}))),xS=y.lazy(()=>Zt(()=>import("./RootHome-C0kwFyYp.js"),__vite__mapDeps([11,4,5,1,2,6,7,3])).then(e=>({default:e.RootHome})));pS();const Rm=()=>document.documentElement.setAttribute("data-tab-hidden",document.hidden?"true":"false");document.addEventListener("visibilitychange",Rm);Rm();function wS(){const{tag:e}=C0();return l.jsx(bm,{filterTag:e?decodeURIComponent(e):void 0})}const SS=V0([{path:"/",element:l.jsx(Ww,{}),errorElement:l.jsx(Jw,{}),children:[{index:!0,element:l.jsx(xS,{})},{path:"projects",element:l.jsx(bm,{})},{path:"tags/:tag",element:l.jsx(wS,{})},{path:"projects/:slug",element:l.jsx(gS,{})},{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(vS,{})},{path:"discover",element:l.jsx(yS,{})}]}]);Ra.createRoot(document.getElementById("root")).render(l.jsx(jf.StrictMode,{children:l.jsx(cx,{children:l.jsx(q0,{router:SS})})}));Xw();export{JS as $,X1 as A,wk as B,ek as C,iS as D,Lk as E,Mk as F,Cm as G,sS as H,Pm as I,jt as J,x1 as K,ns as L,fk as M,ES as N,ZS as O,pk as P,Iw as Q,Iu as R,lk as S,hk as T,Zd as U,GS as V,Xt as W,Hi as X,q1 as Y,XS as Z,$n as _,lr as a,Vp as a$,YS as a0,jS as a1,Z1 as a2,J1 as a3,Tk as a4,rk as a5,jk as a6,am as a7,Ck as a8,kS as a9,AS as aA,ak as aB,Hu as aC,qS as aD,kk as aE,Ek as aF,gk as aG,Du as aH,Wu as aI,ck as aJ,DS as aK,cm as aL,nk as aM,Uw as aN,OS as aO,Sk as aP,Nk as aQ,xk as aR,Pk as aS,MS as aT,_S as aU,qx as aV,Zx as aW,IS as aX,rw as aY,TS as aZ,CS as a_,ik as aa,sk as ab,mk as ac,uk as ad,nw as ae,ok as af,zS as ag,FS as ah,WS as ai,BS as aj,US as ak,HS as al,KS as am,VS as an,r1 as ao,k1 as ap,tk as aq,t1 as ar,Ea as as,$S as at,Zt as au,vk as av,yk as aw,Oi as ax,QS as ay,lx as az,tf as b,RS as b0,Wn as b1,NS as b2,PS as b3,Fw as b4,bS as b5,bk as b6,Ye as c,Qp as d,w1 as e,ff as f,Gp as g,ts as h,Q1 as i,l as j,_w as k,ax as l,ww as m,dk as n,Qx as o,yi as p,xw as q,y as r,LS as s,Kx as t,C0 as u,Y1 as v,lS as w,fS as x,hS as y,Rk as z};
71
71