@puddle-code/cli 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,16 +4,16 @@ Archived release changelog. Governance lives in CLAUDE.md §"Changelog disciplin
4
4
 
5
5
  # Changelog
6
6
 
7
- ## [0.5.9] — 2026-11-21
7
+ ## [0.5.10] — 2026-11-22
8
8
 
9
- ### Daemon
9
+ ### Frontend
10
10
 
11
11
  #### Fixed
12
12
 
13
- - Keep new blank agent sessions temporary until native storage records a conversation, omit ended unsaved launches from history, and honour Codex, Claude Code, Gemini and OpenCode persistence differences.
13
+ - Show current runtime takeover blockers during host recovery and explain verification, continuation and separate session interruption.
14
14
 
15
- ### Runtime
15
+ ### Daemon
16
16
 
17
17
  #### Fixed
18
18
 
19
- - Reuse identical anonymous terminal hyperlinks across agent redraws so repeated links do not exhaust screen retention and leave sessions blank or unavailable after switching projects or reloading.
19
+ - Block daemon replacement when existing runtimes report unsaved state, expose bounded recovery diagnostics through existing update reviews, and show affected runtime ids in CLI status without relaxing completion checks or replaying actions.
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__
44
44
  var define_PUDDLE_COMPONENT_VERSIONS_default;
45
45
  var init_define_PUDDLE_COMPONENT_VERSIONS = __esm({
46
46
  "<define:__PUDDLE_COMPONENT_VERSIONS__>"() {
47
- define_PUDDLE_COMPONENT_VERSIONS_default = { frontend: "0.5.9", daemon: "0.5.9", runtime: "0.5.9" };
47
+ define_PUDDLE_COMPONENT_VERSIONS_default = { frontend: "0.5.10", daemon: "0.5.10", runtime: "0.5.9" };
48
48
  }
49
49
  });
50
50
 
@@ -23259,6 +23259,31 @@ function presentHostUpdate(reply, options = {}) {
23259
23259
  );
23260
23260
  }
23261
23261
 
23262
+ // ../shared/src/installation/update-messages.ts
23263
+ init_define_PUDDLE_COMPONENT_VERSIONS();
23264
+ function hostUpdateBlockerMessage(code) {
23265
+ switch (code) {
23266
+ case "runtime_persistence_pending":
23267
+ return "A runtime cannot confirm saved state. Inspect the affected session before retrying. Stopping it interrupts its agents and shell jobs and requires your approval.";
23268
+ case "runtime_reconciliation_pending":
23269
+ return "A runtime has not finished reconnecting and saving its observations. Check its session, then verify completion again.";
23270
+ case "runtime_adoption_changed":
23271
+ return "A runtime no longer matches the saved takeover checkpoint. Inspect its session before continuing recovery.";
23272
+ case "runtime_unavailable":
23273
+ return "A runtime cannot be inspected. Check its session and host connection before retrying.";
23274
+ case "daemon_adoption_unconfirmed":
23275
+ return "The replacement daemon has not proved takeover of the saved runtimes. Inspect host update status before continuing recovery.";
23276
+ case "daemon_release_changed":
23277
+ return "The running daemon does not match the exact approved release. Inspect the selected release before continuing recovery.";
23278
+ case "adoption_evidence_unavailable":
23279
+ return "The saved takeover evidence could not be inspected. Check the host update logs; do not repeat installation.";
23280
+ case "runtime_lifetime_unverified":
23281
+ return "A runtime has a limited or unverified host lifetime. Daemon replacement is blocked while it runs. Updating also requires a supported host service manager.";
23282
+ default:
23283
+ return `Check failed: ${(code === "cockpit_incompatible" ? "frontend_incompatible" : code).replaceAll("_", " ")}`;
23284
+ }
23285
+ }
23286
+
23262
23287
  // ../shared/src/remote/maintenance.ts
23263
23288
  init_define_PUDDLE_COMPONENT_VERSIONS();
23264
23289
 
@@ -29072,7 +29097,7 @@ import { readFileSync as readFileSync4 } from "node:fs";
29072
29097
  import { dirname as dirname6, join as join10 } from "node:path";
29073
29098
  import { fileURLToPath as fileURLToPath2 } from "node:url";
29074
29099
  function cliVersion() {
29075
- if (true) return "0.5.9";
29100
+ if (true) return "0.5.10";
29076
29101
  const here = dirname6(fileURLToPath2(import.meta.url));
29077
29102
  for (const candidate of [
29078
29103
  join10(here, "..", "..", "package.json"),
@@ -29498,7 +29523,8 @@ var RELEASE_PROTOCOLS = {
29498
29523
  "0.5.6": { major: 28, minor: 34 },
29499
29524
  "0.5.7": { major: 28, minor: 35 },
29500
29525
  "0.5.8": { major: 28, minor: 36 },
29501
- "0.5.9": { major: 28, minor: 36 }
29526
+ "0.5.9": { major: 28, minor: 36 },
29527
+ "0.5.10": { major: 28, minor: 36 }
29502
29528
  };
29503
29529
  function validProtocol(value) {
29504
29530
  if (typeof value !== "object" || value === null) return false;
@@ -33690,6 +33716,13 @@ async function removeDaemonCmd(cmd, logger) {
33690
33716
  // src/cli/management/updates.ts
33691
33717
  init_define_PUDDLE_COMPONENT_VERSIONS();
33692
33718
  init_types();
33719
+ function reportBlockers(result, logger) {
33720
+ if (!result.ok || !result.review) return;
33721
+ for (const blocker of result.review.blockers)
33722
+ logger.info(` ${blocker.target}: ${hostUpdateBlockerMessage(blocker.code)}`);
33723
+ if (result.review.more_blockers)
33724
+ logger.info(` ${result.review.more_blockers} additional checks failed`);
33725
+ }
33693
33726
  async function runUpdates(command, logger) {
33694
33727
  const transport = await openHostTransport(command.host);
33695
33728
  try {
@@ -33749,17 +33782,30 @@ async function runUpdates(command, logger) {
33749
33782
  reason: "cancelled"
33750
33783
  }
33751
33784
  );
33752
- if (!result.ok || !result.operation)
33785
+ if (!result.ok || !result.operation) {
33786
+ if (authority && (command.recover || command.continue)) {
33787
+ try {
33788
+ const status = await authority.hostUpdate({
33789
+ action: "status",
33790
+ id: command.operation,
33791
+ ...recoverySupported ? { include_recovery: true } : {}
33792
+ });
33793
+ reportBlockers(status, logger);
33794
+ } catch {
33795
+ }
33796
+ }
33753
33797
  throw new CliError(
33754
33798
  "upgrade_failed",
33755
33799
  command.continue ? "Update continuation was not confirmed; inspect its recorded state before another action" : command.recover ? "Update completion was not verified; inspect its current state before another recovery action" : "Update was not cancelled; inspect its current state before another action"
33756
33800
  );
33801
+ }
33757
33802
  }
33758
33803
  const operation3 = result.operation;
33759
33804
  logger.info(`host update ${operation3.id} on ${transport.label}: ${operation3.phase}`);
33760
33805
  for (const target2 of operation3.targets)
33761
33806
  logger.info(` ${target2.component} v${target2.version}`);
33762
33807
  if (operation3.message) logger.info(operation3.message);
33808
+ reportBlockers(result, logger);
33763
33809
  if (result.recovery) {
33764
33810
  logger.info(
33765
33811
  `recorded recovery ${result.recovery.id}: ${result.recovery.consumed ? "worker consumed the attempt" : "accepted for dispatch"}`
@@ -1,15 +1,15 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ReleaseNotesDialog-B1DpXA1c.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/jsx-runtime-ffCh33zF.js","assets/purify.es-D8QhFVkO.js","assets/dialog-DfdBRe6G.js","assets/utils-B6KiDbIe.js","assets/x-CbfJFzGo.js","assets/createLucideIcon-DyMAgLa3.js","assets/dialog-BX0tebJL.css","assets/queue-4USHmW_D.js","assets/markdown-it-CWoG9_Dn.js","assets/markdown-Dj7Cr7RL.js","assets/source-anchor-map-BNxSa_bJ.js","assets/math-CSw6sgCC.js","assets/math-delimiters-BCnTi7Ii.js","assets/SettingsDialog-Dxyi7dhn.js","assets/protocol-support-DIWnYJkt.js","assets/local-store-DKFKEHML.js","assets/LazyTerminal-Cu5V6ejk.js","assets/preload-helper-Czpn1I53.js","assets/dist-CNoWjXWo.js","assets/chevron-right-6pjfw_yV.js","assets/notification-delivery-yJcsFWYx.js","assets/theme-swfNLod9.js","assets/api-DhfvolrJ.js","assets/auth-BPXeEntX.js","assets/window-context-DddmcmmO.js","assets/queries-C9DYtGQW.js","assets/editor-links-Djdkea3i.js","assets/client-settings-BdKglwtW.js","assets/colour-picker-Dwq4M4eT.js","assets/profile-icons-BmQVYS_o.js","assets/switch-DZ2lisDt.js","assets/select-DHaYbZVV.js","assets/chevron-down--sjpQEHH.js","assets/session-display-DHxCigRa.js","assets/profile-store-BnferXV3.js","assets/ws-fD2y3o7n.js","assets/dist-DMpqv5CF.js","assets/notification-delivery-BZzMYzIP.css","assets/use-desktop-state-xeH1nq63.js","assets/errors-SnGDjajv.js","assets/preview-kind-CJ9RTgbs.js","assets/content-state-PQEVgsS8.js","assets/debounce-B9DrqirV.js","assets/button-BNH9tKwf.js","assets/shield-check-CY69Ons-.js","assets/code-DRWf9a5s.js","assets/disclosure-oYVpfMYO.js","assets/rotate-ccw-CNjR2LSi.js","assets/trash-2-WYPJMQLN.js","assets/hotkeys-B417biB9.js","assets/control-tray-jUtkASPS.js","assets/control-tray-CG26TqqQ.css","assets/use-debounced-value-C86N-mOK.js","assets/popover-CNEMQBFf.js","assets/preferences-BP2Incj1.js","assets/CompilationCommandForm--aglvHpg.js","assets/SettingsDialog-CJX0gDhJ.css","assets/Dashboard-CLdNA8WP.js","assets/square-terminal-CrlDquCd.js","assets/session-order-BK0vJanT.js","assets/motion-Bd_MB9cH.js","assets/use-arrangement-ready-CMe547fb.js","assets/context-menu-CaNn4t1W.js","assets/project-actions-DX_j3cML.js","assets/expanding-content-CKYjs3iT.js","assets/Workspace-DQDh6TQ7.js","assets/forward-link-BT0QTRVB.js","assets/editor-context-Bijx3uIG.js","assets/tooltip-CtT-5xHL.js","assets/DraftRecovery-Da7OryXQ.js","assets/whole-word-2m2pmAFT.js","assets/selection-actions-DX3EnNRv.js","assets/copy-CGsu8426.js","assets/state-BegCSQn_.js","assets/view-state-store-Cr1BaTzj.js","assets/search-Ct_rLLa4.js","assets/project-drag-DZbLfoWj.js","assets/drafts-CqDYmkTF.js","assets/buffer-logic-D9FvoilV.js","assets/scroll-restoration-C-VTTLs8.js","assets/FileCloseScope-B527gWqW.js","assets/file-links-CEjYCLBn.js","assets/Workspace-CiATCR9s.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n,t as r}from"./jsx-runtime-ffCh33zF.js";import{C as i,c as a,o}from"./protocol-support-DIWnYJkt.js";import{$ as s,En as c,G as l,K as u,L as d,Mn as f,Nn as p,T as m,X as h,_ as g,a as _,kn as v,q as y,r as b,yn as x}from"./local-store-DKFKEHML.js";import{C as S,D as C,E as w,T,_ as E,a as D,d as ee,g as te,h as ne,i as re,j as O,k,l as ie,m as A,o as ae,p as oe,s as se,t as ce,u as le,w as ue}from"./notification-delivery-yJcsFWYx.js";import{r as de}from"./auth-BPXeEntX.js";import{i as fe,r as pe,t as me}from"./client-settings-BdKglwtW.js";import{c as he,n as ge,r as _e,s as ve,t as ye}from"./theme-swfNLod9.js";import{t as be}from"./preload-helper-Czpn1I53.js";import{n as j}from"./api-DhfvolrJ.js";import{a as M,n as N,o as xe,s as Se,t as Ce}from"./window-context-DddmcmmO.js";import{t as we}from"./forward-link-BT0QTRVB.js";import{A as Te,B as Ee,C as De,F as Oe,H as ke,I as Ae,L as je,P as Me,T as Ne,U as Pe,V as Fe,W as Ie,X as Le,_t as Re,b as ze,c as Be,et as Ve,h as He,i as Ue,j as We,k as Ge,l as Ke,m as qe,n as Je,o as Ye,r as Xe,s as Ze,st as Qe,t as $e,v as et,vt as tt}from"./queries-C9DYtGQW.js";import{D as nt,H as rt,N as it,R as at,Z as P,_ as ot,g as st,h as ct,k as lt,o as ut,r as dt,z as ft}from"./use-desktop-state-xeH1nq63.js";import{a as pt,c as mt,d as ht,i as gt,l as _t,n as vt,o as yt,r as bt,s as xt,t as St,u as Ct}from"./square-terminal-CrlDquCd.js";import{t as wt}from"./motion-Bd_MB9cH.js";import{t as F}from"./utils-B6KiDbIe.js";import{o as Tt,r as Et}from"./session-order-BK0vJanT.js";import{o as Dt,r as Ot,s as kt,t as At}from"./dialog-DfdBRe6G.js";import{n as I,t as jt}from"./dist-DMpqv5CF.js";import{f as Mt,r as Nt}from"./dist-CNoWjXWo.js";import{a as Pt,i as Ft,n as It,r as Lt,t as Rt}from"./select-DHaYbZVV.js";import{i as L,n as R,r as zt,t as z}from"./tooltip-CtT-5xHL.js";import{n as Bt,t as B}from"./button-BNH9tKwf.js";import{n as V,r as Vt}from"./chevron-right-6pjfw_yV.js";import{a as Ht,n as Ut,o as Wt,r as Gt,t as Kt}from"./colour-picker-Dwq4M4eT.js";import{t as H}from"./createLucideIcon-DyMAgLa3.js";import{i as qt,r as Jt}from"./profile-icons-BmQVYS_o.js";import{a as Yt,i as Xt,r as Zt,t as Qt}from"./switch-DZ2lisDt.js";import{t as $t}from"./copy-CGsu8426.js";import{n as en,r as tn,t as nn}from"./expanding-content-CKYjs3iT.js";import{n as rn,t as an}from"./disclosure-oYVpfMYO.js";import{t as on}from"./save-BT7q_AMN.js";import{t as sn}from"./settings-2-CInoy48z.js";import{t as cn}from"./trash-2-WYPJMQLN.js";import{C as ln,D as un,E as dn,O as fn,S as pn,T as mn,_ as hn,b as gn,c as _n,d as vn,f as U,g as yn,h as bn,i as xn,k as Sn,l as Cn,m as wn,o as Tn,r as En,u as Dn,v as On,x as kn,y as An}from"./project-drag-DZbLfoWj.js";import{a as jn,r as W}from"./session-display-DHxCigRa.js";import{i as G,n as Mn,r as Nn,t as Pn}from"./profile-store-BnferXV3.js";import{c as Fn,i as In,n as Ln,r as Rn,t as zn}from"./context-menu-CaNn4t1W.js";import{a as Bn,c as Vn,d as K,f as Hn,h as Un,i as Wn,m as Gn,o as Kn,r as qn,s as Jn,u as Yn}from"./hotkeys-B417biB9.js";import{t as Xn}from"./control-tray-jUtkASPS.js";import{n as q}from"./errors-SnGDjajv.js";import{t as J}from"./ws-fD2y3o7n.js";import{a as Zn,c as Qn,i as $n,n as er,o as tr,r as nr,s as rr}from"./command-RRKOl81e.js";import{n as ir,r as ar,t as or}from"./popover-CNEMQBFf.js";import{n as sr,r as cr,t as lr}from"./queue-4USHmW_D.js";import{n as ur,t as dr}from"./project-actions-DX_j3cML.js";var Y=e(t(),1),X=r();function fr(){let[e,t]=(0,Y.useState)(`Opening forwarded application…`);return(0,Y.useEffect)(()=>{if(!/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname)){t(`This forwarding link is invalid.`);return}let e=!0;return we(new URL(window.location.href)).then(t=>{e&&window.location.replace(t)}).catch(()=>{e&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{e=!1}},[]),(0,X.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var pr=class extends Y.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidUpdate(e){this.state.error!==null&&e.resetOn!==this.props.resetOn&&this.setState({error:null})}componentDidCatch(e,t){console.error(`Puddle: the ${this.props.scope} crashed`,e,t.componentStack)}render(){let{error:e}=this.state;return e===null?this.props.children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-40 flex-col items-center justify-center gap-4 px-8 py-10 text-center`,children:[(0,X.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,X.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,X.jsx)(`p`,{className:`max-w-sm text-2xs leading-relaxed text-fg-muted`,children:`Your sessions and their worktrees are on the daemon and untouched; the layout is saved. The console has the full stack.`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null}),className:`text-2xs font-medium text-fg-gold transition-colors hover:underline`,children:`Try again`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{xe().catch(e=>this.setState({error:e instanceof Error?e:Error(`Could not reload this window`)}))},className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function mr(){return(0,X.jsx)(jt,{theme:(0,Y.useSyncExternalStore)(ve,_e),position:`bottom-right`,toastOptions:{style:{background:`var(--bg-elevated)`,border:`none`,boxShadow:`var(--ui-overlay-shadow)`,borderRadius:`var(--ui-surface-radius)`,outline:`1px solid var(--border)`,color:`var(--text-primary)`},classNames:{description:`whitespace-pre-wrap break-words font-mono text-2xs leading-snug max-h-40 overflow-y-auto`}}})}function hr(){return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,X.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,X.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,X.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var gr=e(n(),1),_r=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,vr=`.monaco-editor`;function yr(e,t){return e?.closest(vr)&&!e.closest(t)?`text`:e?.closest(_r)?`interactive`:`default`}function br(e,t=`.no-custom-caret`){(0,Y.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=0,a=null,o=null,s=!0,c=!1,l=new MutationObserver(()=>d()),u=()=>{a&&!i&&(i=requestAnimationFrame(p))},d=()=>{s=!0,c=!0,u()},f=()=>{cancelAnimationFrame(i),i=0,a=null,o=null,s=!0,l.disconnect(),n.style.opacity=`0`},p=()=>{if(i=0,!a)return;let{x:e,y:u}=a,d=c?document.elementFromPoint(e,u):a.target;if(a.target=d,c=!1,d instanceof HTMLIFrameElement||!r.matches){f();return}if(n.style.transform=`translate3d(${e}px, ${u}px, 0) translate(-50%, -50%)`,n.style.opacity=`1`,!s&&d===o)return;if(s=!1,o=d,l.disconnect(),d&&d!==n&&!n.contains(d)){l.observe(d,{attributes:!0,childList:!0});for(let e of d.childNodes)e.nodeType===Node.TEXT_NODE&&l.observe(e,{characterData:!0});for(let e=d.parentElement;e;e=e.parentElement)l.observe(e,{attributes:!0,childList:!0})}l.observe(document.head,{attributes:!0,childList:!0,characterData:!0,subtree:!0});let p=d?.closest(vr),m=yr(d,t),h=m===`text`,g=m===`interactive`,_=h;if(h&&p){let e=getComputedStyle(p);n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`)}else if(!g&&d&&!d.closest(t)&&Array.from(d.childNodes).some(e=>e.nodeType===Node.TEXT_NODE&&e.textContent?.trim())){let e=getComputedStyle(d);e.userSelect!==`none`&&(_=!0,n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`))}n.classList.toggle(`is-interactive`,g),n.classList.toggle(`is-text`,_)},m=e=>{if(e.pointerType===`touch`||!r.matches){f();return}a={x:e.clientX,y:e.clientY,target:e.target instanceof Element?e.target:null},c=!1,u()},h=()=>{r.matches?d():f()};return window.addEventListener(`pointermove`,m,{passive:!0,capture:!0}),document.documentElement.addEventListener(`pointerleave`,f),window.addEventListener(`blur`,f),window.addEventListener(`resize`,d),document.addEventListener(`scroll`,d,!0),document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,d),document.addEventListener(`pointerdown`,d,!0),document.addEventListener(`pointerup`,d,!0),r.addEventListener(`change`,h),document.fonts.addEventListener(`loadingdone`,d),()=>{window.removeEventListener(`pointermove`,m,!0),document.documentElement.removeEventListener(`pointerleave`,f),window.removeEventListener(`blur`,f),window.removeEventListener(`resize`,d),document.removeEventListener(`scroll`,d,!0),document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,d),document.removeEventListener(`pointerdown`,d,!0),document.removeEventListener(`pointerup`,d,!0),r.removeEventListener(`change`,h),document.fonts.removeEventListener(`loadingdone`,d),f()}},[t,e])}var xr=[`top`,`right`,`bottom`,`left`];function Sr(){let e=(0,Y.useRef)(null);return br(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:xr.map(e=>(0,X.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function Cr(){let e=(0,Y.useRef)(null);return br(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var wr=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Z=40.5,Q=4.05,Tr=Q*Math.sqrt(3)/2;function Er(){let e=[],t=[],n=Z/2,r=Math.ceil(n/Tr)+1,i=e=>Math.round(e*100)/100,a=e=>`M${e.map(([e,t])=>`${i(e)} ${i(t)}`).join(`L`)}Z`;for(let i=-r;i<r;i+=1){let o=n+i*Tr,s=o+Tr,c=(i%2+2)%2*(Q/2);for(let i=-r;i<r;i+=1){let r=n+i*Q+c,l=[[r+Q/2,o],[r,s],[r+Q,s]],u=[[r+Q/2,o],[r+3*Q/2,o],[r+Q,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Z&&Math.max(...n)>0&&Math.min(...n)<Z};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var Dr=Er();function Or(){let e=(0,Y.useRef)(null);return br(e,wr),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,X.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Z} ${Z}`,focusable:`false`,children:[(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:Dr.light}),(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:Dr.dark})]})})}function kr(){let{cursorPackage:e}=fe(),t=null;switch(e){case`rangefinder`:t=(0,X.jsx)(Or,{});break;case`drafting`:t=(0,X.jsx)(Sr,{});break;case`invert`:t=(0,X.jsx)(Cr,{});break;case`system`:return null}return(0,gr.createPortal)(t,document.body)}var Ar=H(`corner-down-left`,[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`,key:`6o5b7l`}],[`path`,{d:`m9 10-5 5 5 5`,key:`1kshq7`}]]),jr=H(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),Mr=H(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),Nr=H(`notebook-pen`,[[`path`,{d:`M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4`,key:`re6nr2`}],[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`path`,{d:`M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`pqwjuv`}]]),Pr=H(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]);function Fr(){let e=ke(),t=He(),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(x),o=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:i.trim()},{onSuccess:e=>Nn(e.id)})},s=(e.data?.length??0)>0;return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),s&&(0,X.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,X.jsxs)(`button`,{onClick:()=>Nn(e.id),className:`flex items-center gap-3 rounded-md px-3 py-2.5 text-left transition-colors hover:bg-elevated active:bg-border/70`,children:[(0,X.jsx)(k,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,X.jsx)(`span`,{className:F(`text-base`,Ut(e.icon_colour)||`text-fg`),style:Gt(e.icon_colour),children:e.name}),e.branch_prefix&&(0,X.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,X.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),o()},children:[s&&(0,X.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(Wt,{htmlFor:`profile-name`,children:`Name`}),(0,X.jsx)(V,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>r(e.target.value),className:`h-10`,autoFocus:!s})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(Wt,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,X.jsx)(V,{id:`branch-prefix`,placeholder:`no prefix`,value:i,onChange:e=>a(e.target.value),className:`h-10`})]}),t.error&&(0,X.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,X.jsx)(B,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}function Ir({kind:e,colour:t,onRename:n,onColour:r,custom:i=!0,pending:a=!1,onUpdates:o}){let[s,c]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(Ln,{children:[(0,X.jsxs)(Rn,{onSelect:n,children:[(0,X.jsx)(Ht,{}),`Rename `,e]}),(0,X.jsxs)(Rn,{onSelect:()=>c(!0),children:[(0,X.jsx)(Xt,{}),`Change `,e,` colour`]}),o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(In,{}),(0,X.jsxs)(Rn,{onSelect:o,children:[(0,X.jsx)(Zt,{}),`Host updates`]})]})]}),(0,X.jsx)(At,{open:s,onOpenChange:c,children:(0,X.jsxs)(Ot,{children:[(0,X.jsx)(Dt,{children:(0,X.jsx)(kt,{children:e===`host`?`Host accent`:`Profile colour`})}),(0,X.jsx)(Kt,{value:t,onChange:r,onCustomChange:i?r:void 0,disabled:a,label:e===`host`?`Host accent`:`Profile colour`})]})})]})}function Lr(){let e=Ge(),{icon:t}=C(),n=G(),r=Gn()[`host.peek`],{showHostOnFocus:i}=fe(),[a,o]=(0,Y.useState)(null),s=/Mac/.test(navigator.platform),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(-1/0);return(0,Y.useEffect)(()=>{let e,t=document.hidden||!document.hasFocus(),n=-1/0,a,u=()=>{clearTimeout(e),e=void 0},d=()=>{u(),c.current=!1,o(null)},f=()=>{t=!0,d()},p=()=>{if(document.hidden)return;let r=performance.now(),a=r-l.current>=(s?750:250);l.current=r;let f=t;t=!1,!(!f||!a||!i||c.current)&&(n=r,u(),o(`focus`),e=setTimeout(()=>{if(!s||wt())return d();o(`focus-closing`),e=setTimeout(d,120)},s?400:1200))},m=t=>{t instanceof KeyboardEvent&&[`Meta`,`Alt`,`Control`,`Shift`].includes(t.key)||t.type===`pointerdown`&&performance.now()-n<100||e!==void 0&&d()},h=r?.split(`+`)??[],g=h.at(-1),_={Meta:`meta`,Control:`ctrl`,Alt:`alt`,Shift:`shift`},v=e=>{c.current&&(e.key===`Escape`&&(e.preventDefault(),e.stopPropagation()),(e.type===`keyup`&&(e.code===g||h.includes(_[e.key]??_[e.code.replace(/(Left|Right)$/,``)]??``))||e.key===`Escape`||h.includes(`meta`)&&!e.metaKey||h.includes(`ctrl`)&&!e.ctrlKey||h.includes(`alt`)&&!e.altKey||h.includes(`shift`)&&!e.shiftKey)&&d())},y=()=>{document.hidden?f():p()},b=K(`host.peek`,()=>{c.current||document.hidden||(u(),c.current=!0,o(`shortcut`))});window.addEventListener(`keyup`,v,!0),window.addEventListener(`keydown`,v,!0),window.addEventListener(`blur`,f),window.addEventListener(`pagehide`,f),window.addEventListener(`focus`,p),window.addEventListener(`keydown`,m,!0),window.addEventListener(`pointerdown`,m,!0),window.addEventListener(`wheel`,m,{passive:!0,capture:!0}),document.addEventListener(`visibilitychange`,y);let x=M()?.onWindowFocusChange?.(e=>{let n=e!==a;a=e,e?n&&(t=!0,p()):f()});return()=>{x?.(),b(),window.removeEventListener(`keyup`,v,!0),window.removeEventListener(`keydown`,v,!0),window.removeEventListener(`blur`,f),window.removeEventListener(`pagehide`,f),window.removeEventListener(`focus`,p),window.removeEventListener(`keydown`,m,!0),window.removeEventListener(`pointerdown`,m,!0),window.removeEventListener(`wheel`,m,!0),document.removeEventListener(`visibilitychange`,y),d()}},[r,s,n,i]),a?(0,gr.createPortal)((0,X.jsx)(`div`,{"data-host-peek":!0,"data-state":a===`focus-closing`?`closed`:a===`focus`&&s?`instant-open`:`open`,className:`overlay-backdrop-motion fixed inset-0 z-[200] flex items-center justify-center p-8 text-fg backdrop-blur-[8px]`,style:a===`shortcut`?void 0:{pointerEvents:`none`,...a===`focus-closing`?{animationFillMode:`forwards`,opacity:0}:{}},onPointerDown:e=>e.preventDefault(),role:`status`,"aria-live":`polite`,children:(0,X.jsxs)(`div`,{className:`flex max-w-full flex-col items-center gap-6 px-12 py-10 text-center`,children:[(0,X.jsx)(w,{icon:t,className:`size-[clamp(4.5rem,13.5vmin,10.5rem)] shrink-0`}),(0,X.jsx)(`span`,{className:`max-w-full break-words font-sans text-[clamp(0.8333rem,1.75vw,1.75rem)] leading-tight font-medium`,children:Xe(e.data)??`Host`})]})}),document.body):null}function Rr(){let e=ze().data?.protocol,t=e!==void 0&&(e.major>25||e.major===25&&e.minor>=5),{data:n}=Qe({queryKey:[`storage`],queryFn:()=>j(`GET`,`/api/storage`),enabled:t&&!b(),refetchInterval:1e4,retry:!1});if(!t||b()||!n)return null;let r=n.volumes.filter(e=>e.level!==`ok`);if(!n.logs_degraded&&!n.database_degraded&&r.length===0)return null;let i=r.some(e=>e.level===`critical`);return(0,X.jsxs)(`div`,{role:`status`,className:`flex shrink-0 items-start gap-2 px-3 py-2 text-xs text-warning`,children:[(0,X.jsx)(Sn,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[n.database_degraded&&(0,X.jsx)(`p`,{children:`Storage is full. Changes cannot be saved. Live session status may be unsaved.`}),n.logs_degraded&&(0,X.jsx)(`p`,{children:`Terminal history is temporarily not being saved. Live terminals remain connected.`}),i&&(0,X.jsx)(`p`,{children:`Storage is critically low. Free space or inodes before starting new sessions or worktrees.`}),r.length>0&&(0,X.jsx)(an,{summary:`${r.length} storage ${r.length===1?`location needs`:`locations need`} attention`,children:(0,X.jsx)(`div`,{className:`max-h-32 overflow-y-auto pl-4`,children:r.map(e=>(0,X.jsxs)(`p`,{className:`break-all text-fg-secondary`,children:[e.level===`unknown`?`Could not check storage`:`Low storage`,` at`,` `,e.path,e.available_bytes!==null&&` · ${Math.round(e.available_bytes/1024**2).toLocaleString()} MiB available`,e.available_inodes!==null&&` · ${e.available_inodes.toLocaleString()} inodes available`]},e.path))})})]})]})}function zr(e,t){for(let[n,r]of e.getQueriesData({queryKey:[`sessions`]}))r&&e.setQueryData(n,r.map(t));for(let[n,r]of e.getQueriesData({queryKey:[`project`]}))r&&e.setQueryData(n,{...r,sessions:r.sessions.map(t)})}function Br(e,t){zr(e,e=>e.id===t.session?{...e,status:t.status,last_activity_at:t.last_activity_at}:e)}function Vr(e,t){zr(e,e=>e.id===t.session?{...e,title:t.title,agent_title:`agent_title`in t?t.agent_title:e.agent_title,osc_title:`osc_title`in t?t.osc_title:e.osc_title}:e)}var Hr=new class{transport;reload;pause;phase=`idle`;pending=null;constructor(e=fetch,t=xe,n=e=>new Promise(t=>setTimeout(t,e))){this.transport=e,this.reload=t,this.pause=n}refresh(e=12e4){return this.pending||=this.run(e).finally(()=>{this.pending=null}),this.pending}async run(e){this.phase=`requesting`;let t={authorization:`Bearer ${de.get()??``}`,"content-type":`application/json`};try{let n=await this.transport(`/frontend/refresh`,{method:`POST`,headers:t,signal:AbortSignal.timeout(1e4),body:JSON.stringify({refreshId:crypto.randomUUID()})});if(n.status!==202)throw Error(`refresh rejected`);let r=d.parse(await n.json());this.phase=`waiting`;let i=Date.now()+e;for(;Date.now()<i;){await this.pause(1e3);try{let e=await this.transport(`/frontend/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let n=m.parse(await e.json());if(n.instance===r.instance||n.refreshId!==r.refreshId||n.upstream!==`ready`)continue}catch{continue}return await this.reload(),this.phase=`complete`,!0}}catch{}return this.phase=`failed`,!1}},Ur=null;function Wr(e){return Ur=e,()=>{Ur===e&&(Ur=null)}}function Gr(){Ur?.()}var Kr=new Set;function qr(){return[...Kr].flatMap(e=>e())}function Jr({onNewSession:e,onNewProject:t}){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(`commands`),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),f=mt(),p=_t(),m=G(),h=p.id,g=Ie(m??void 0),_=Fe(m??void 0),v=Ve(h),y=pn(),b=Gn();(0,Y.useEffect)(()=>K(`palette.toggle`,()=>r(e=>!e)),[]),(0,Y.useEffect)(()=>dn(()=>r(!0)),[]),(0,Y.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let x=(0,Y.useMemo)(()=>{let n=[],r=Et((g.data??[]).filter(e=>!e.archived),_.data?.projectOrder??[]);for(let[e,t]of r.entries()){let r=qn[e];n.push({id:`project-${t.id}`,group:`Projects`,label:t.name,icon:tn,keywords:`switch project open`,shortcut:r?Kn(b[r.id]??``):void 0,run:()=>void f(`/project/${t.id}`)})}for(let e of v.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:y(e),icon:St,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return h!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:Yt,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:St,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),h!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:tn,keywords:`open path file directory folder editor tree browse absolute relative home`,closeOnRun:!1,run:()=>{s(``),l(null),a(`path`)}}),t&&n.push({id:`new-project`,group:`Actions`,label:`New project`,icon:rn,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:qt,keywords:`switch theme dark appearance`,run:()=>void ye(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:Jt,keywords:`switch theme light appearance`,run:()=>void ye(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:Mr,keywords:`switch theme system appearance`,run:()=>void ye(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Pr,keywords:`open settings preferences options configure`,run:()=>W()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:jn,keywords:`switch profile identity user change`,run:()=>Mn.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:Zt,keywords:`refresh connection reconnect restart frontend tunnel ssh daemon`,run:()=>Gr()}),[...n,...qr()]},[b,g.data,_.data?.projectOrder,v.data,h,f,e,t,y]),S=(0,Y.useMemo)(()=>{let e=new Map;for(let t of x){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[x]),C=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await ln(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,X.jsxs)(er,{open:n,onOpenChange:r,children:[(0,X.jsx)(Zn,{value:o,onValueChange:e=>{s(e),l(null)},placeholder:i===`path`?`Enter a path…`:`Type a command or search…`,onKeyDown:e=>{i===`path`&&(e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),C()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,X.jsx)(rr,{children:(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,X.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,X.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,X.jsxs)(rr,{children:[(0,X.jsx)(nr,{children:`Nothing matches.`}),S.map(([e,t])=>(0,X.jsx)($n,{heading:e,children:t.map(e=>{let t=e.icon;return(0,X.jsxs)(tr,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,X.jsx)(t,{}),e.label,e.shortcut&&(0,X.jsx)(Qn,{children:e.shortcut})]},e.id)})},e))]})]})}function Yr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Xr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Zr(){let e=mt(),t=G(),n=Ie(t??void 0),r=Fe(t??void 0),i=r.data?.hotkeys;return(0,Y.useEffect)(()=>{Hn(i&&typeof i==`object`?i:void 0)},[i]),(0,Y.useEffect)(()=>{if(t===null)return;let i=Et((n.data??[]).filter(e=>!e.archived),r.data?.projectOrder??[]),a=qn.map((t,n)=>K(t.id,()=>{let t=i[n];t&&e(`/project/${t.id}`)}));return()=>a.forEach(e=>e())},[e,t,n.data,r.data?.projectOrder]),(0,Y.useEffect)(()=>K(`window.close`,()=>{let e=M();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,Y.useEffect)(()=>{let e=e=>{if(e.target instanceof Element&&e.target.closest(`[data-hotkey-recording]`))return;let t=Bn(e);if(!t)return;let n=Wn(t);if(!n)return;let r=Jn(n);if(!r||!Yn(r,Xr())||r.deferInTerminal&&Yr())return;let i=Vn(n);i&&(e.preventDefault(),e.stopPropagation(),(!r.hold||!e.repeat)&&i())},t=e=>{let t=Bn(e);if(!t)return;let n=Wn(t);if(!n)return;let r=Jn(n);if(!r||r.editor&&Xr()||r.deferInTerminal&&Yr())return;let i=Vn(n);i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`keydown`,t)}},[]),null}var Qr=4e3;function $r(){let[e,t]=(0,Y.useState)(`hidden`),n=(0,Y.useRef)(e);n.current=e,(0,Y.useEffect)(()=>{let e=null,r=J.onConnectionChange(r=>{if(r){e!==null&&clearTimeout(e),e=null,n.current===`lost`&&t(`hidden`);return}e!==null||n.current!==`hidden`||(e=setTimeout(()=>{e=null,n.current===`hidden`&&t(`lost`)},Qr))});return()=>{r(),e!==null&&clearTimeout(e)}},[]);let r=(0,Y.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Hr.refresh()||(I.error(`The frontend has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(J.isConnected()?`hidden`:`lost`)))},[]);return(0,Y.useEffect)(()=>Wr(()=>void r()),[r]),e===`hidden`?null:(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the frontend.`:`Connection to the daemon lost.`}),e===`lost`&&(0,X.jsxs)(B,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,X.jsx)(Zt,{}),`Refresh connection`]})]})}function ei({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,X.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,X.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full ${r>=90?`bg-danger`:r>=75?`bg-warning`:`bg-action`}`,style:{width:`${r}%`}})}),(0,X.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function ti(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ni(e){if(e===null)return`never`;let t=new Date(e).getTime(),n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`just now`;let r=Math.round(n/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}function ri({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=Ye(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,X.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,X.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,X.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,X.jsxs)(X.Fragment,{children:[` · `,i.data.session_count,` session`,i.data.session_count===1?``:`s`,i.data.active_session_count>0&&` (${i.data.active_session_count} active)`,` · `,`last `,ni(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[ti(i.data.agent_usage.input_tokens),` in ·`,` `,ti(i.data.agent_usage.output_tokens),` out ·`,` `,ti(i.data.agent_usage.cache_read_input_tokens),` cached ·`,` `,i.data.agent_usage.message_count,` msgs`]}),i.data?.live_usage?.context_used_percentage!=null&&(0,X.jsx)(`span`,{className:`mt-1 block`,children:(0,X.jsx)(ei,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,X.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,X.jsx)(O,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,X.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,X.jsx)(ei,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function ii(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(!1),i=G(),a=ke(),o=Ae(),s=a.data?.find(e=>e.id===i),c=Ze(i??void 0),l=Be(),u=We(),{open:d,handler:f}=kn(),[p,m]=(0,Y.useState)(null),h=e=>u.mutate(e.id,{onSuccess:t=>m({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>q(e)}),g=e=>{t(!1),d({accountId:e.id})},_=e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>q(e)})},v=`profile-trigger font-sans compact:h-7 compact:px-1.5`;return n&&s?(0,X.jsxs)(`div`,{className:Bt({variant:`ghost`,size:`sm`,className:v}),style:Gt(s.icon_colour),children:[(0,X.jsx)(k,{icon:s.icon,colour:s.icon_colour}),(0,X.jsx)(un,{initial:s.name,maxLength:100,fitContent:!0,className:Ut(s.icon_colour),onCommit:_,onCancel:()=>r(!1)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(zn,{onOpenChange:e=>{e&&t(!1)},children:[(0,X.jsxs)(or,{open:e,onOpenChange:t,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsx)(Fn,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:v,children:[(0,X.jsx)(k,{icon:s?.icon,colour:s?.icon_colour}),(0,X.jsx)(`span`,{className:Ut(s?.icon_colour),style:Gt(s?.icon_colour),...fn(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})})}),(0,X.jsx)(R,{children:`Profile`})]}),(0,X.jsxs)(ir,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(l.data??[]).map(e=>{let t=c.data?.filter(t=>t.agent_type===e.id)??[];if(t.length===0)return null;let n=e.available!==!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,X.jsxs)(`span`,{className:`ml-2 normal-case tracking-normal text-fg-muted`,children:[`not installed — no `,e.binary??e.id,` on PATH`]})]}),t.map(e=>(0,X.jsx)(ri,{account:e,onLogin:()=>h(e),onStartSession:f&&n?()=>g(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,X.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),W(`accounts`)},children:[(0,X.jsx)(rn,{}),`Add account`]}),(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),Mn.set(null)},children:[(0,X.jsx)(sn,{}),`Switch profile`]})]})]})]}),(0,X.jsx)(Ir,{kind:`profile`,colour:s?.icon_colour,onRename:()=>{t(!1),r(!0)},onColour:e=>{i&&o.mutate({id:i,icon_colour:e},{onError:q})},pending:o.isPending||!i})]}),p&&(0,X.jsx)(S,{stream:p.stream,label:p.label,onClose:()=>m(null)})]})}function ai(e=`hostOffers`){let t=M()?.windows?.effects,[n,r]=(0,Y.useState)(()=>!t||null);return(0,Y.useEffect)(()=>{if(!t)return;let n=!0,i=!1,a=t=>{let i=_.safeParse(t);n&&i.success&&r(i.data[e])},o=t.onChanged(e=>{i=!0,a(e)});return t.status().then(e=>{i||a(e)}).catch(()=>{n&&!i&&r(!1)}),()=>{n=!1,o()}},[t,e]),n}var oi=`desktop-update`,si=null;function ci(){let e=ai(`desktopOffers`);return(0,Y.useEffect)(()=>{e===!1&&I.dismiss(oi)},[e]),e?(0,X.jsx)(li,{}):null}function li(){return(0,Y.useEffect)(()=>{let e=M();if(e?.updateReady===void 0||e.onUpdateReady===void 0)return;let t=!0,n=e=>{!t||si===e||(si=e,I(`Puddle ${e} is downloaded and ready.`,{id:oi,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{M()?.installUpdate?.(),I.loading(`Restarting into Puddle ${e}…`,{id:`${oi}-restarting`,duration:1/0})}}}))};e.updateReady().then(e=>{e!==null&&n(e)});let r=e.onUpdateReady(n);return()=>{t=!1,r()}},[]),null}var ui=new te,di=new Set;function fi({onReview:e}={}){let t=ai();return oe(),(0,Y.useEffect)(()=>{if(t===!1){for(let e of di)I.dismiss(e);di.clear()}},[t]),t?(0,X.jsx)(pi,{onReview:e}):null}function pi({onReview:e}){let t=A(),n=ee(),r=Xe(Ge().data),i=ne();return(0,Y.useEffect)(()=>{if(!(!n||!r||t.isError))for(let n of ui.take(i,E(t.data))){let t=n.component===`daemon`?`Daemon`:`Runtime software`,a=`host-update-${i}-${n.component}-${n.version}`;di.add(a),I(`${r}: ${t} ${n.version} is available.`,{id:a,duration:1/0,closeButton:!0,action:{label:`Review update`,onClick:e??(()=>W(`host`))}})}},[t.data,t.isError,r,n,i,e]),null}function mi({hostKey:e,enabled:t=!0}){let n=Qe({queryKey:[`host`],queryFn:async({signal:e})=>c.parse(await j(`GET`,`/api/host`,void 0,e)),staleTime:1/0,enabled:t&&!e,retry:!1}),r=e??(n.data?lr(n.data):void 0),i=b(),a=i?.generation,o=Qe({queryKey:[`release-notes`,r],queryFn:async({signal:e})=>{let t=v.parse(await j(`GET`,`/api/release-notes`,void 0,e));if(b()!==i||i?.generation!==a)throw Error(`Release notes connection changed`);return t},enabled:t&&!!r,staleTime:1/0,retry:!1});return(0,Y.useEffect)(()=>{t&&r&&o.data&&!o.isError&&cr(r,o.data)},[t,r,o.data,o.isError]),null}var hi=(0,Y.lazy)(()=>be(()=>import(`./ReleaseNotesDialog-B1DpXA1c.js`).then(e=>({default:e.ReleaseNotesDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])));function gi({remote:e=!1}){let t=(0,Y.useSyncExternalStore)(sr.subscribe,sr.snapshot)[0];return(0,Y.useEffect)(()=>{let t=e?[`frontend`,`remote`]:[`frontend`];sr.enqueue(`browser`,t.map(e=>({component:e,version:`0.5.9`,markdown:`## [0.5.9] — 2026-11-21
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ReleaseNotesDialog-B1DpXA1c.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/jsx-runtime-ffCh33zF.js","assets/purify.es-D8QhFVkO.js","assets/dialog-DfdBRe6G.js","assets/utils-B6KiDbIe.js","assets/x-CbfJFzGo.js","assets/createLucideIcon-DyMAgLa3.js","assets/dialog-BX0tebJL.css","assets/queue-4USHmW_D.js","assets/markdown-it-CWoG9_Dn.js","assets/markdown-Dj7Cr7RL.js","assets/source-anchor-map-BNxSa_bJ.js","assets/math-CSw6sgCC.js","assets/math-delimiters-BCnTi7Ii.js","assets/SettingsDialog-cl6-0q5x.js","assets/protocol-support-DIWnYJkt.js","assets/local-store-DKFKEHML.js","assets/LazyTerminal-Cu5V6ejk.js","assets/preload-helper-Czpn1I53.js","assets/dist-CNoWjXWo.js","assets/chevron-right-6pjfw_yV.js","assets/notification-delivery-yJcsFWYx.js","assets/theme-swfNLod9.js","assets/api-DhfvolrJ.js","assets/auth-BPXeEntX.js","assets/window-context-DddmcmmO.js","assets/queries-C9DYtGQW.js","assets/editor-links-Djdkea3i.js","assets/client-settings-BdKglwtW.js","assets/colour-picker-Dwq4M4eT.js","assets/profile-icons-BmQVYS_o.js","assets/switch-DZ2lisDt.js","assets/select-DHaYbZVV.js","assets/chevron-down--sjpQEHH.js","assets/session-display-DHxCigRa.js","assets/profile-store-BnferXV3.js","assets/ws-fD2y3o7n.js","assets/dist-DMpqv5CF.js","assets/notification-delivery-BZzMYzIP.css","assets/use-desktop-state-xeH1nq63.js","assets/errors-SnGDjajv.js","assets/preview-kind-CJ9RTgbs.js","assets/content-state-PQEVgsS8.js","assets/debounce-B9DrqirV.js","assets/button-BNH9tKwf.js","assets/shield-check-CY69Ons-.js","assets/code-DRWf9a5s.js","assets/disclosure-oYVpfMYO.js","assets/rotate-ccw-CNjR2LSi.js","assets/trash-2-WYPJMQLN.js","assets/hotkeys-B417biB9.js","assets/control-tray-jUtkASPS.js","assets/control-tray-CG26TqqQ.css","assets/use-debounced-value-C86N-mOK.js","assets/popover-CNEMQBFf.js","assets/preferences-BP2Incj1.js","assets/CompilationCommandForm--aglvHpg.js","assets/SettingsDialog-CJX0gDhJ.css","assets/Dashboard-CLdNA8WP.js","assets/square-terminal-CrlDquCd.js","assets/session-order-BK0vJanT.js","assets/motion-Bd_MB9cH.js","assets/use-arrangement-ready-CMe547fb.js","assets/context-menu-CaNn4t1W.js","assets/project-actions-DX_j3cML.js","assets/expanding-content-CKYjs3iT.js","assets/Workspace-DQDh6TQ7.js","assets/forward-link-BT0QTRVB.js","assets/editor-context-Bijx3uIG.js","assets/tooltip-CtT-5xHL.js","assets/DraftRecovery-Da7OryXQ.js","assets/whole-word-2m2pmAFT.js","assets/selection-actions-DX3EnNRv.js","assets/copy-CGsu8426.js","assets/state-BegCSQn_.js","assets/view-state-store-Cr1BaTzj.js","assets/search-Ct_rLLa4.js","assets/project-drag-DZbLfoWj.js","assets/drafts-CqDYmkTF.js","assets/buffer-logic-D9FvoilV.js","assets/scroll-restoration-C-VTTLs8.js","assets/FileCloseScope-B527gWqW.js","assets/file-links-CEjYCLBn.js","assets/Workspace-CiATCR9s.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n,t as r}from"./jsx-runtime-ffCh33zF.js";import{C as i,c as a,o}from"./protocol-support-DIWnYJkt.js";import{$ as s,En as c,G as l,K as u,L as d,Mn as f,Nn as p,T as m,X as h,_ as g,a as _,kn as v,q as y,r as b,yn as x}from"./local-store-DKFKEHML.js";import{C as S,D as C,E as w,T,_ as E,a as D,d as ee,g as te,h as ne,i as re,j as O,k,l as ie,m as A,o as ae,p as oe,s as se,t as ce,u as le,w as ue}from"./notification-delivery-yJcsFWYx.js";import{r as de}from"./auth-BPXeEntX.js";import{i as fe,r as pe,t as me}from"./client-settings-BdKglwtW.js";import{c as he,n as ge,r as _e,s as ve,t as ye}from"./theme-swfNLod9.js";import{t as be}from"./preload-helper-Czpn1I53.js";import{n as j}from"./api-DhfvolrJ.js";import{a as M,n as N,o as xe,s as Se,t as Ce}from"./window-context-DddmcmmO.js";import{t as we}from"./forward-link-BT0QTRVB.js";import{A as Te,B as Ee,C as De,F as Oe,H as ke,I as Ae,L as je,P as Me,T as Ne,U as Pe,V as Fe,W as Ie,X as Le,_t as Re,b as ze,c as Be,et as Ve,h as He,i as Ue,j as We,k as Ge,l as Ke,m as qe,n as Je,o as Ye,r as Xe,s as Ze,st as Qe,t as $e,v as et,vt as tt}from"./queries-C9DYtGQW.js";import{D as nt,H as rt,N as it,R as at,Z as P,_ as ot,g as st,h as ct,k as lt,o as ut,r as dt,z as ft}from"./use-desktop-state-xeH1nq63.js";import{a as pt,c as mt,d as ht,i as gt,l as _t,n as vt,o as yt,r as bt,s as xt,t as St,u as Ct}from"./square-terminal-CrlDquCd.js";import{t as wt}from"./motion-Bd_MB9cH.js";import{t as F}from"./utils-B6KiDbIe.js";import{o as Tt,r as Et}from"./session-order-BK0vJanT.js";import{o as Dt,r as Ot,s as kt,t as At}from"./dialog-DfdBRe6G.js";import{n as I,t as jt}from"./dist-DMpqv5CF.js";import{f as Mt,r as Nt}from"./dist-CNoWjXWo.js";import{a as Pt,i as Ft,n as It,r as Lt,t as Rt}from"./select-DHaYbZVV.js";import{i as L,n as R,r as zt,t as z}from"./tooltip-CtT-5xHL.js";import{n as Bt,t as B}from"./button-BNH9tKwf.js";import{n as V,r as Vt}from"./chevron-right-6pjfw_yV.js";import{a as Ht,n as Ut,o as Wt,r as Gt,t as Kt}from"./colour-picker-Dwq4M4eT.js";import{t as H}from"./createLucideIcon-DyMAgLa3.js";import{i as qt,r as Jt}from"./profile-icons-BmQVYS_o.js";import{a as Yt,i as Xt,r as Zt,t as Qt}from"./switch-DZ2lisDt.js";import{t as $t}from"./copy-CGsu8426.js";import{n as en,r as tn,t as nn}from"./expanding-content-CKYjs3iT.js";import{n as rn,t as an}from"./disclosure-oYVpfMYO.js";import{t as on}from"./save-BT7q_AMN.js";import{t as sn}from"./settings-2-CInoy48z.js";import{t as cn}from"./trash-2-WYPJMQLN.js";import{C as ln,D as un,E as dn,O as fn,S as pn,T as mn,_ as hn,b as gn,c as _n,d as vn,f as U,g as yn,h as bn,i as xn,k as Sn,l as Cn,m as wn,o as Tn,r as En,u as Dn,v as On,x as kn,y as An}from"./project-drag-DZbLfoWj.js";import{a as jn,r as W}from"./session-display-DHxCigRa.js";import{i as G,n as Mn,r as Nn,t as Pn}from"./profile-store-BnferXV3.js";import{c as Fn,i as In,n as Ln,r as Rn,t as zn}from"./context-menu-CaNn4t1W.js";import{a as Bn,c as Vn,d as K,f as Hn,h as Un,i as Wn,m as Gn,o as Kn,r as qn,s as Jn,u as Yn}from"./hotkeys-B417biB9.js";import{t as Xn}from"./control-tray-jUtkASPS.js";import{n as q}from"./errors-SnGDjajv.js";import{t as J}from"./ws-fD2y3o7n.js";import{a as Zn,c as Qn,i as $n,n as er,o as tr,r as nr,s as rr}from"./command-RRKOl81e.js";import{n as ir,r as ar,t as or}from"./popover-CNEMQBFf.js";import{n as sr,r as cr,t as lr}from"./queue-4USHmW_D.js";import{n as ur,t as dr}from"./project-actions-DX_j3cML.js";var Y=e(t(),1),X=r();function fr(){let[e,t]=(0,Y.useState)(`Opening forwarded application…`);return(0,Y.useEffect)(()=>{if(!/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname)){t(`This forwarding link is invalid.`);return}let e=!0;return we(new URL(window.location.href)).then(t=>{e&&window.location.replace(t)}).catch(()=>{e&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{e=!1}},[]),(0,X.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var pr=class extends Y.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidUpdate(e){this.state.error!==null&&e.resetOn!==this.props.resetOn&&this.setState({error:null})}componentDidCatch(e,t){console.error(`Puddle: the ${this.props.scope} crashed`,e,t.componentStack)}render(){let{error:e}=this.state;return e===null?this.props.children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-40 flex-col items-center justify-center gap-4 px-8 py-10 text-center`,children:[(0,X.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,X.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,X.jsx)(`p`,{className:`max-w-sm text-2xs leading-relaxed text-fg-muted`,children:`Your sessions and their worktrees are on the daemon and untouched; the layout is saved. The console has the full stack.`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null}),className:`text-2xs font-medium text-fg-gold transition-colors hover:underline`,children:`Try again`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{xe().catch(e=>this.setState({error:e instanceof Error?e:Error(`Could not reload this window`)}))},className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function mr(){return(0,X.jsx)(jt,{theme:(0,Y.useSyncExternalStore)(ve,_e),position:`bottom-right`,toastOptions:{style:{background:`var(--bg-elevated)`,border:`none`,boxShadow:`var(--ui-overlay-shadow)`,borderRadius:`var(--ui-surface-radius)`,outline:`1px solid var(--border)`,color:`var(--text-primary)`},classNames:{description:`whitespace-pre-wrap break-words font-mono text-2xs leading-snug max-h-40 overflow-y-auto`}}})}function hr(){return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,X.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,X.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,X.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var gr=e(n(),1),_r=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,vr=`.monaco-editor`;function yr(e,t){return e?.closest(vr)&&!e.closest(t)?`text`:e?.closest(_r)?`interactive`:`default`}function br(e,t=`.no-custom-caret`){(0,Y.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=0,a=null,o=null,s=!0,c=!1,l=new MutationObserver(()=>d()),u=()=>{a&&!i&&(i=requestAnimationFrame(p))},d=()=>{s=!0,c=!0,u()},f=()=>{cancelAnimationFrame(i),i=0,a=null,o=null,s=!0,l.disconnect(),n.style.opacity=`0`},p=()=>{if(i=0,!a)return;let{x:e,y:u}=a,d=c?document.elementFromPoint(e,u):a.target;if(a.target=d,c=!1,d instanceof HTMLIFrameElement||!r.matches){f();return}if(n.style.transform=`translate3d(${e}px, ${u}px, 0) translate(-50%, -50%)`,n.style.opacity=`1`,!s&&d===o)return;if(s=!1,o=d,l.disconnect(),d&&d!==n&&!n.contains(d)){l.observe(d,{attributes:!0,childList:!0});for(let e of d.childNodes)e.nodeType===Node.TEXT_NODE&&l.observe(e,{characterData:!0});for(let e=d.parentElement;e;e=e.parentElement)l.observe(e,{attributes:!0,childList:!0})}l.observe(document.head,{attributes:!0,childList:!0,characterData:!0,subtree:!0});let p=d?.closest(vr),m=yr(d,t),h=m===`text`,g=m===`interactive`,_=h;if(h&&p){let e=getComputedStyle(p);n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`)}else if(!g&&d&&!d.closest(t)&&Array.from(d.childNodes).some(e=>e.nodeType===Node.TEXT_NODE&&e.textContent?.trim())){let e=getComputedStyle(d);e.userSelect!==`none`&&(_=!0,n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`))}n.classList.toggle(`is-interactive`,g),n.classList.toggle(`is-text`,_)},m=e=>{if(e.pointerType===`touch`||!r.matches){f();return}a={x:e.clientX,y:e.clientY,target:e.target instanceof Element?e.target:null},c=!1,u()},h=()=>{r.matches?d():f()};return window.addEventListener(`pointermove`,m,{passive:!0,capture:!0}),document.documentElement.addEventListener(`pointerleave`,f),window.addEventListener(`blur`,f),window.addEventListener(`resize`,d),document.addEventListener(`scroll`,d,!0),document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,d),document.addEventListener(`pointerdown`,d,!0),document.addEventListener(`pointerup`,d,!0),r.addEventListener(`change`,h),document.fonts.addEventListener(`loadingdone`,d),()=>{window.removeEventListener(`pointermove`,m,!0),document.documentElement.removeEventListener(`pointerleave`,f),window.removeEventListener(`blur`,f),window.removeEventListener(`resize`,d),document.removeEventListener(`scroll`,d,!0),document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,d),document.removeEventListener(`pointerdown`,d,!0),document.removeEventListener(`pointerup`,d,!0),r.removeEventListener(`change`,h),document.fonts.removeEventListener(`loadingdone`,d),f()}},[t,e])}var xr=[`top`,`right`,`bottom`,`left`];function Sr(){let e=(0,Y.useRef)(null);return br(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:xr.map(e=>(0,X.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function Cr(){let e=(0,Y.useRef)(null);return br(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var wr=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Z=40.5,Q=4.05,Tr=Q*Math.sqrt(3)/2;function Er(){let e=[],t=[],n=Z/2,r=Math.ceil(n/Tr)+1,i=e=>Math.round(e*100)/100,a=e=>`M${e.map(([e,t])=>`${i(e)} ${i(t)}`).join(`L`)}Z`;for(let i=-r;i<r;i+=1){let o=n+i*Tr,s=o+Tr,c=(i%2+2)%2*(Q/2);for(let i=-r;i<r;i+=1){let r=n+i*Q+c,l=[[r+Q/2,o],[r,s],[r+Q,s]],u=[[r+Q/2,o],[r+3*Q/2,o],[r+Q,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Z&&Math.max(...n)>0&&Math.min(...n)<Z};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var Dr=Er();function Or(){let e=(0,Y.useRef)(null);return br(e,wr),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,X.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Z} ${Z}`,focusable:`false`,children:[(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:Dr.light}),(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:Dr.dark})]})})}function kr(){let{cursorPackage:e}=fe(),t=null;switch(e){case`rangefinder`:t=(0,X.jsx)(Or,{});break;case`drafting`:t=(0,X.jsx)(Sr,{});break;case`invert`:t=(0,X.jsx)(Cr,{});break;case`system`:return null}return(0,gr.createPortal)(t,document.body)}var Ar=H(`corner-down-left`,[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`,key:`6o5b7l`}],[`path`,{d:`m9 10-5 5 5 5`,key:`1kshq7`}]]),jr=H(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),Mr=H(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),Nr=H(`notebook-pen`,[[`path`,{d:`M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4`,key:`re6nr2`}],[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`path`,{d:`M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`pqwjuv`}]]),Pr=H(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]);function Fr(){let e=ke(),t=He(),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(x),o=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:i.trim()},{onSuccess:e=>Nn(e.id)})},s=(e.data?.length??0)>0;return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),s&&(0,X.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,X.jsxs)(`button`,{onClick:()=>Nn(e.id),className:`flex items-center gap-3 rounded-md px-3 py-2.5 text-left transition-colors hover:bg-elevated active:bg-border/70`,children:[(0,X.jsx)(k,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,X.jsx)(`span`,{className:F(`text-base`,Ut(e.icon_colour)||`text-fg`),style:Gt(e.icon_colour),children:e.name}),e.branch_prefix&&(0,X.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,X.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),o()},children:[s&&(0,X.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(Wt,{htmlFor:`profile-name`,children:`Name`}),(0,X.jsx)(V,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>r(e.target.value),className:`h-10`,autoFocus:!s})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(Wt,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,X.jsx)(V,{id:`branch-prefix`,placeholder:`no prefix`,value:i,onChange:e=>a(e.target.value),className:`h-10`})]}),t.error&&(0,X.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,X.jsx)(B,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}function Ir({kind:e,colour:t,onRename:n,onColour:r,custom:i=!0,pending:a=!1,onUpdates:o}){let[s,c]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(Ln,{children:[(0,X.jsxs)(Rn,{onSelect:n,children:[(0,X.jsx)(Ht,{}),`Rename `,e]}),(0,X.jsxs)(Rn,{onSelect:()=>c(!0),children:[(0,X.jsx)(Xt,{}),`Change `,e,` colour`]}),o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(In,{}),(0,X.jsxs)(Rn,{onSelect:o,children:[(0,X.jsx)(Zt,{}),`Host updates`]})]})]}),(0,X.jsx)(At,{open:s,onOpenChange:c,children:(0,X.jsxs)(Ot,{children:[(0,X.jsx)(Dt,{children:(0,X.jsx)(kt,{children:e===`host`?`Host accent`:`Profile colour`})}),(0,X.jsx)(Kt,{value:t,onChange:r,onCustomChange:i?r:void 0,disabled:a,label:e===`host`?`Host accent`:`Profile colour`})]})})]})}function Lr(){let e=Ge(),{icon:t}=C(),n=G(),r=Gn()[`host.peek`],{showHostOnFocus:i}=fe(),[a,o]=(0,Y.useState)(null),s=/Mac/.test(navigator.platform),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(-1/0);return(0,Y.useEffect)(()=>{let e,t=document.hidden||!document.hasFocus(),n=-1/0,a,u=()=>{clearTimeout(e),e=void 0},d=()=>{u(),c.current=!1,o(null)},f=()=>{t=!0,d()},p=()=>{if(document.hidden)return;let r=performance.now(),a=r-l.current>=(s?750:250);l.current=r;let f=t;t=!1,!(!f||!a||!i||c.current)&&(n=r,u(),o(`focus`),e=setTimeout(()=>{if(!s||wt())return d();o(`focus-closing`),e=setTimeout(d,120)},s?400:1200))},m=t=>{t instanceof KeyboardEvent&&[`Meta`,`Alt`,`Control`,`Shift`].includes(t.key)||t.type===`pointerdown`&&performance.now()-n<100||e!==void 0&&d()},h=r?.split(`+`)??[],g=h.at(-1),_={Meta:`meta`,Control:`ctrl`,Alt:`alt`,Shift:`shift`},v=e=>{c.current&&(e.key===`Escape`&&(e.preventDefault(),e.stopPropagation()),(e.type===`keyup`&&(e.code===g||h.includes(_[e.key]??_[e.code.replace(/(Left|Right)$/,``)]??``))||e.key===`Escape`||h.includes(`meta`)&&!e.metaKey||h.includes(`ctrl`)&&!e.ctrlKey||h.includes(`alt`)&&!e.altKey||h.includes(`shift`)&&!e.shiftKey)&&d())},y=()=>{document.hidden?f():p()},b=K(`host.peek`,()=>{c.current||document.hidden||(u(),c.current=!0,o(`shortcut`))});window.addEventListener(`keyup`,v,!0),window.addEventListener(`keydown`,v,!0),window.addEventListener(`blur`,f),window.addEventListener(`pagehide`,f),window.addEventListener(`focus`,p),window.addEventListener(`keydown`,m,!0),window.addEventListener(`pointerdown`,m,!0),window.addEventListener(`wheel`,m,{passive:!0,capture:!0}),document.addEventListener(`visibilitychange`,y);let x=M()?.onWindowFocusChange?.(e=>{let n=e!==a;a=e,e?n&&(t=!0,p()):f()});return()=>{x?.(),b(),window.removeEventListener(`keyup`,v,!0),window.removeEventListener(`keydown`,v,!0),window.removeEventListener(`blur`,f),window.removeEventListener(`pagehide`,f),window.removeEventListener(`focus`,p),window.removeEventListener(`keydown`,m,!0),window.removeEventListener(`pointerdown`,m,!0),window.removeEventListener(`wheel`,m,!0),document.removeEventListener(`visibilitychange`,y),d()}},[r,s,n,i]),a?(0,gr.createPortal)((0,X.jsx)(`div`,{"data-host-peek":!0,"data-state":a===`focus-closing`?`closed`:a===`focus`&&s?`instant-open`:`open`,className:`overlay-backdrop-motion fixed inset-0 z-[200] flex items-center justify-center p-8 text-fg backdrop-blur-[8px]`,style:a===`shortcut`?void 0:{pointerEvents:`none`,...a===`focus-closing`?{animationFillMode:`forwards`,opacity:0}:{}},onPointerDown:e=>e.preventDefault(),role:`status`,"aria-live":`polite`,children:(0,X.jsxs)(`div`,{className:`flex max-w-full flex-col items-center gap-6 px-12 py-10 text-center`,children:[(0,X.jsx)(w,{icon:t,className:`size-[clamp(4.5rem,13.5vmin,10.5rem)] shrink-0`}),(0,X.jsx)(`span`,{className:`max-w-full break-words font-sans text-[clamp(0.8333rem,1.75vw,1.75rem)] leading-tight font-medium`,children:Xe(e.data)??`Host`})]})}),document.body):null}function Rr(){let e=ze().data?.protocol,t=e!==void 0&&(e.major>25||e.major===25&&e.minor>=5),{data:n}=Qe({queryKey:[`storage`],queryFn:()=>j(`GET`,`/api/storage`),enabled:t&&!b(),refetchInterval:1e4,retry:!1});if(!t||b()||!n)return null;let r=n.volumes.filter(e=>e.level!==`ok`);if(!n.logs_degraded&&!n.database_degraded&&r.length===0)return null;let i=r.some(e=>e.level===`critical`);return(0,X.jsxs)(`div`,{role:`status`,className:`flex shrink-0 items-start gap-2 px-3 py-2 text-xs text-warning`,children:[(0,X.jsx)(Sn,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[n.database_degraded&&(0,X.jsx)(`p`,{children:`Storage is full. Changes cannot be saved. Live session status may be unsaved.`}),n.logs_degraded&&(0,X.jsx)(`p`,{children:`Terminal history is temporarily not being saved. Live terminals remain connected.`}),i&&(0,X.jsx)(`p`,{children:`Storage is critically low. Free space or inodes before starting new sessions or worktrees.`}),r.length>0&&(0,X.jsx)(an,{summary:`${r.length} storage ${r.length===1?`location needs`:`locations need`} attention`,children:(0,X.jsx)(`div`,{className:`max-h-32 overflow-y-auto pl-4`,children:r.map(e=>(0,X.jsxs)(`p`,{className:`break-all text-fg-secondary`,children:[e.level===`unknown`?`Could not check storage`:`Low storage`,` at`,` `,e.path,e.available_bytes!==null&&` · ${Math.round(e.available_bytes/1024**2).toLocaleString()} MiB available`,e.available_inodes!==null&&` · ${e.available_inodes.toLocaleString()} inodes available`]},e.path))})})]})]})}function zr(e,t){for(let[n,r]of e.getQueriesData({queryKey:[`sessions`]}))r&&e.setQueryData(n,r.map(t));for(let[n,r]of e.getQueriesData({queryKey:[`project`]}))r&&e.setQueryData(n,{...r,sessions:r.sessions.map(t)})}function Br(e,t){zr(e,e=>e.id===t.session?{...e,status:t.status,last_activity_at:t.last_activity_at}:e)}function Vr(e,t){zr(e,e=>e.id===t.session?{...e,title:t.title,agent_title:`agent_title`in t?t.agent_title:e.agent_title,osc_title:`osc_title`in t?t.osc_title:e.osc_title}:e)}var Hr=new class{transport;reload;pause;phase=`idle`;pending=null;constructor(e=fetch,t=xe,n=e=>new Promise(t=>setTimeout(t,e))){this.transport=e,this.reload=t,this.pause=n}refresh(e=12e4){return this.pending||=this.run(e).finally(()=>{this.pending=null}),this.pending}async run(e){this.phase=`requesting`;let t={authorization:`Bearer ${de.get()??``}`,"content-type":`application/json`};try{let n=await this.transport(`/frontend/refresh`,{method:`POST`,headers:t,signal:AbortSignal.timeout(1e4),body:JSON.stringify({refreshId:crypto.randomUUID()})});if(n.status!==202)throw Error(`refresh rejected`);let r=d.parse(await n.json());this.phase=`waiting`;let i=Date.now()+e;for(;Date.now()<i;){await this.pause(1e3);try{let e=await this.transport(`/frontend/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let n=m.parse(await e.json());if(n.instance===r.instance||n.refreshId!==r.refreshId||n.upstream!==`ready`)continue}catch{continue}return await this.reload(),this.phase=`complete`,!0}}catch{}return this.phase=`failed`,!1}},Ur=null;function Wr(e){return Ur=e,()=>{Ur===e&&(Ur=null)}}function Gr(){Ur?.()}var Kr=new Set;function qr(){return[...Kr].flatMap(e=>e())}function Jr({onNewSession:e,onNewProject:t}){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(`commands`),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),f=mt(),p=_t(),m=G(),h=p.id,g=Ie(m??void 0),_=Fe(m??void 0),v=Ve(h),y=pn(),b=Gn();(0,Y.useEffect)(()=>K(`palette.toggle`,()=>r(e=>!e)),[]),(0,Y.useEffect)(()=>dn(()=>r(!0)),[]),(0,Y.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let x=(0,Y.useMemo)(()=>{let n=[],r=Et((g.data??[]).filter(e=>!e.archived),_.data?.projectOrder??[]);for(let[e,t]of r.entries()){let r=qn[e];n.push({id:`project-${t.id}`,group:`Projects`,label:t.name,icon:tn,keywords:`switch project open`,shortcut:r?Kn(b[r.id]??``):void 0,run:()=>void f(`/project/${t.id}`)})}for(let e of v.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:y(e),icon:St,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return h!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:Yt,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:St,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),h!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:tn,keywords:`open path file directory folder editor tree browse absolute relative home`,closeOnRun:!1,run:()=>{s(``),l(null),a(`path`)}}),t&&n.push({id:`new-project`,group:`Actions`,label:`New project`,icon:rn,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:qt,keywords:`switch theme dark appearance`,run:()=>void ye(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:Jt,keywords:`switch theme light appearance`,run:()=>void ye(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:Mr,keywords:`switch theme system appearance`,run:()=>void ye(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Pr,keywords:`open settings preferences options configure`,run:()=>W()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:jn,keywords:`switch profile identity user change`,run:()=>Mn.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:Zt,keywords:`refresh connection reconnect restart frontend tunnel ssh daemon`,run:()=>Gr()}),[...n,...qr()]},[b,g.data,_.data?.projectOrder,v.data,h,f,e,t,y]),S=(0,Y.useMemo)(()=>{let e=new Map;for(let t of x){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[x]),C=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await ln(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,X.jsxs)(er,{open:n,onOpenChange:r,children:[(0,X.jsx)(Zn,{value:o,onValueChange:e=>{s(e),l(null)},placeholder:i===`path`?`Enter a path…`:`Type a command or search…`,onKeyDown:e=>{i===`path`&&(e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),C()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,X.jsx)(rr,{children:(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,X.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,X.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,X.jsxs)(rr,{children:[(0,X.jsx)(nr,{children:`Nothing matches.`}),S.map(([e,t])=>(0,X.jsx)($n,{heading:e,children:t.map(e=>{let t=e.icon;return(0,X.jsxs)(tr,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,X.jsx)(t,{}),e.label,e.shortcut&&(0,X.jsx)(Qn,{children:e.shortcut})]},e.id)})},e))]})]})}function Yr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Xr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Zr(){let e=mt(),t=G(),n=Ie(t??void 0),r=Fe(t??void 0),i=r.data?.hotkeys;return(0,Y.useEffect)(()=>{Hn(i&&typeof i==`object`?i:void 0)},[i]),(0,Y.useEffect)(()=>{if(t===null)return;let i=Et((n.data??[]).filter(e=>!e.archived),r.data?.projectOrder??[]),a=qn.map((t,n)=>K(t.id,()=>{let t=i[n];t&&e(`/project/${t.id}`)}));return()=>a.forEach(e=>e())},[e,t,n.data,r.data?.projectOrder]),(0,Y.useEffect)(()=>K(`window.close`,()=>{let e=M();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,Y.useEffect)(()=>{let e=e=>{if(e.target instanceof Element&&e.target.closest(`[data-hotkey-recording]`))return;let t=Bn(e);if(!t)return;let n=Wn(t);if(!n)return;let r=Jn(n);if(!r||!Yn(r,Xr())||r.deferInTerminal&&Yr())return;let i=Vn(n);i&&(e.preventDefault(),e.stopPropagation(),(!r.hold||!e.repeat)&&i())},t=e=>{let t=Bn(e);if(!t)return;let n=Wn(t);if(!n)return;let r=Jn(n);if(!r||r.editor&&Xr()||r.deferInTerminal&&Yr())return;let i=Vn(n);i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`keydown`,t)}},[]),null}var Qr=4e3;function $r(){let[e,t]=(0,Y.useState)(`hidden`),n=(0,Y.useRef)(e);n.current=e,(0,Y.useEffect)(()=>{let e=null,r=J.onConnectionChange(r=>{if(r){e!==null&&clearTimeout(e),e=null,n.current===`lost`&&t(`hidden`);return}e!==null||n.current!==`hidden`||(e=setTimeout(()=>{e=null,n.current===`hidden`&&t(`lost`)},Qr))});return()=>{r(),e!==null&&clearTimeout(e)}},[]);let r=(0,Y.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Hr.refresh()||(I.error(`The frontend has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(J.isConnected()?`hidden`:`lost`)))},[]);return(0,Y.useEffect)(()=>Wr(()=>void r()),[r]),e===`hidden`?null:(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the frontend.`:`Connection to the daemon lost.`}),e===`lost`&&(0,X.jsxs)(B,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,X.jsx)(Zt,{}),`Refresh connection`]})]})}function ei({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,X.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,X.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full ${r>=90?`bg-danger`:r>=75?`bg-warning`:`bg-action`}`,style:{width:`${r}%`}})}),(0,X.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function ti(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ni(e){if(e===null)return`never`;let t=new Date(e).getTime(),n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`just now`;let r=Math.round(n/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}function ri({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=Ye(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,X.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,X.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,X.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,X.jsxs)(X.Fragment,{children:[` · `,i.data.session_count,` session`,i.data.session_count===1?``:`s`,i.data.active_session_count>0&&` (${i.data.active_session_count} active)`,` · `,`last `,ni(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[ti(i.data.agent_usage.input_tokens),` in ·`,` `,ti(i.data.agent_usage.output_tokens),` out ·`,` `,ti(i.data.agent_usage.cache_read_input_tokens),` cached ·`,` `,i.data.agent_usage.message_count,` msgs`]}),i.data?.live_usage?.context_used_percentage!=null&&(0,X.jsx)(`span`,{className:`mt-1 block`,children:(0,X.jsx)(ei,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,X.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,X.jsx)(O,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,X.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,X.jsx)(ei,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function ii(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(!1),i=G(),a=ke(),o=Ae(),s=a.data?.find(e=>e.id===i),c=Ze(i??void 0),l=Be(),u=We(),{open:d,handler:f}=kn(),[p,m]=(0,Y.useState)(null),h=e=>u.mutate(e.id,{onSuccess:t=>m({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>q(e)}),g=e=>{t(!1),d({accountId:e.id})},_=e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>q(e)})},v=`profile-trigger font-sans compact:h-7 compact:px-1.5`;return n&&s?(0,X.jsxs)(`div`,{className:Bt({variant:`ghost`,size:`sm`,className:v}),style:Gt(s.icon_colour),children:[(0,X.jsx)(k,{icon:s.icon,colour:s.icon_colour}),(0,X.jsx)(un,{initial:s.name,maxLength:100,fitContent:!0,className:Ut(s.icon_colour),onCommit:_,onCancel:()=>r(!1)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(zn,{onOpenChange:e=>{e&&t(!1)},children:[(0,X.jsxs)(or,{open:e,onOpenChange:t,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsx)(Fn,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:v,children:[(0,X.jsx)(k,{icon:s?.icon,colour:s?.icon_colour}),(0,X.jsx)(`span`,{className:Ut(s?.icon_colour),style:Gt(s?.icon_colour),...fn(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})})}),(0,X.jsx)(R,{children:`Profile`})]}),(0,X.jsxs)(ir,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(l.data??[]).map(e=>{let t=c.data?.filter(t=>t.agent_type===e.id)??[];if(t.length===0)return null;let n=e.available!==!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,X.jsxs)(`span`,{className:`ml-2 normal-case tracking-normal text-fg-muted`,children:[`not installed — no `,e.binary??e.id,` on PATH`]})]}),t.map(e=>(0,X.jsx)(ri,{account:e,onLogin:()=>h(e),onStartSession:f&&n?()=>g(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,X.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),W(`accounts`)},children:[(0,X.jsx)(rn,{}),`Add account`]}),(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),Mn.set(null)},children:[(0,X.jsx)(sn,{}),`Switch profile`]})]})]})]}),(0,X.jsx)(Ir,{kind:`profile`,colour:s?.icon_colour,onRename:()=>{t(!1),r(!0)},onColour:e=>{i&&o.mutate({id:i,icon_colour:e},{onError:q})},pending:o.isPending||!i})]}),p&&(0,X.jsx)(S,{stream:p.stream,label:p.label,onClose:()=>m(null)})]})}function ai(e=`hostOffers`){let t=M()?.windows?.effects,[n,r]=(0,Y.useState)(()=>!t||null);return(0,Y.useEffect)(()=>{if(!t)return;let n=!0,i=!1,a=t=>{let i=_.safeParse(t);n&&i.success&&r(i.data[e])},o=t.onChanged(e=>{i=!0,a(e)});return t.status().then(e=>{i||a(e)}).catch(()=>{n&&!i&&r(!1)}),()=>{n=!1,o()}},[t,e]),n}var oi=`desktop-update`,si=null;function ci(){let e=ai(`desktopOffers`);return(0,Y.useEffect)(()=>{e===!1&&I.dismiss(oi)},[e]),e?(0,X.jsx)(li,{}):null}function li(){return(0,Y.useEffect)(()=>{let e=M();if(e?.updateReady===void 0||e.onUpdateReady===void 0)return;let t=!0,n=e=>{!t||si===e||(si=e,I(`Puddle ${e} is downloaded and ready.`,{id:oi,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{M()?.installUpdate?.(),I.loading(`Restarting into Puddle ${e}…`,{id:`${oi}-restarting`,duration:1/0})}}}))};e.updateReady().then(e=>{e!==null&&n(e)});let r=e.onUpdateReady(n);return()=>{t=!1,r()}},[]),null}var ui=new te,di=new Set;function fi({onReview:e}={}){let t=ai();return oe(),(0,Y.useEffect)(()=>{if(t===!1){for(let e of di)I.dismiss(e);di.clear()}},[t]),t?(0,X.jsx)(pi,{onReview:e}):null}function pi({onReview:e}){let t=A(),n=ee(),r=Xe(Ge().data),i=ne();return(0,Y.useEffect)(()=>{if(!(!n||!r||t.isError))for(let n of ui.take(i,E(t.data))){let t=n.component===`daemon`?`Daemon`:`Runtime software`,a=`host-update-${i}-${n.component}-${n.version}`;di.add(a),I(`${r}: ${t} ${n.version} is available.`,{id:a,duration:1/0,closeButton:!0,action:{label:`Review update`,onClick:e??(()=>W(`host`))}})}},[t.data,t.isError,r,n,i,e]),null}function mi({hostKey:e,enabled:t=!0}){let n=Qe({queryKey:[`host`],queryFn:async({signal:e})=>c.parse(await j(`GET`,`/api/host`,void 0,e)),staleTime:1/0,enabled:t&&!e,retry:!1}),r=e??(n.data?lr(n.data):void 0),i=b(),a=i?.generation,o=Qe({queryKey:[`release-notes`,r],queryFn:async({signal:e})=>{let t=v.parse(await j(`GET`,`/api/release-notes`,void 0,e));if(b()!==i||i?.generation!==a)throw Error(`Release notes connection changed`);return t},enabled:t&&!!r,staleTime:1/0,retry:!1});return(0,Y.useEffect)(()=>{t&&r&&o.data&&!o.isError&&cr(r,o.data)},[t,r,o.data,o.isError]),null}var hi=(0,Y.lazy)(()=>be(()=>import(`./ReleaseNotesDialog-B1DpXA1c.js`).then(e=>({default:e.ReleaseNotesDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])));function gi({remote:e=!1}){let t=(0,Y.useSyncExternalStore)(sr.subscribe,sr.snapshot)[0];return(0,Y.useEffect)(()=>{let t=e?[`frontend`,`remote`]:[`frontend`];sr.enqueue(`browser`,t.map(e=>({component:e,version:`0.5.10`,markdown:`## [0.5.10] — 2026-11-22
3
3
 
4
- ### Daemon
4
+ ### Frontend
5
5
 
6
6
  #### Fixed
7
7
 
8
- - Keep new blank agent sessions temporary until native storage records a conversation, omit ended unsaved launches from history, and honour Codex, Claude Code, Gemini and OpenCode persistence differences.
8
+ - Show current runtime takeover blockers during host recovery and explain verification, continuation and separate session interruption.
9
9
 
10
- ### Runtime
10
+ ### Daemon
11
11
 
12
12
  #### Fixed
13
13
 
14
- - Reuse identical anonymous terminal hyperlinks across agent redraws so repeated links do not exhaust screen retention and leave sessions blank or unavailable after switching projects or reloading.
15
- `})))},[e]),t?(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(hi,{current:t})}):null}function _i(){let e=G(),t=ke().data?.find(t=>t.id===e),n=Fe(e??void 0),r=Le(e??void 0,void 0),i=fe(),a=ae(),o=se(),s=je(e??``),c=Ae(),l=et(),[u,d]=(0,Y.useReducer)(e=>e+1,0);(0,Y.useEffect)(()=>ve(()=>d()),[]);let f=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{f.current=null},[t?.name]);let p=a.data?.available===!0?a.data.file:void 0,m=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&p!==void 0,h=t&&p?D(p,t.name):void 0,g=s.isPending||c.isPending||l.isPending||o.isPending||n.isFetching||r.isFetching;(0,Y.useEffect)(()=>{if(!m||!h?.enabled||g)return;let a={client:i,theme:he(),profileSettings:n.data,profile:t,scratchpad:r.data},u={setClient:e=>pe(e),setTheme:e=>{typeof e==`string`&&ye(e)},patchProfileSettings:e=>s.mutate(e),patchProfileColumns:t=>c.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)l.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},d=JSON.stringify(h.doc);if(f.current!==d){f.current=d,ie(h.doc,u,a,h.groups);return}let p=le(h.groups,a),_=JSON.stringify(p);_!==d&&(f.current=_,o.mutate({profile:t.name,entry:{...h,doc:p,updatedAt:new Date().toISOString()}}))})}function vi(e){let t=t=>{let n=p.safeParse(t);n.success&&e(n.data)},n=M()?.onNotificationClick?.((e,n)=>t(n)),r=e=>{e.data?.t===`notification-click`&&t(e.data.target)};return navigator.serviceWorker?.addEventListener(`message`,r),()=>{n?.(),navigator.serviceWorker?.removeEventListener(`message`,r)}}var yi=5e3,bi=`[data-notification-session]`;function xi(e){let t=null,n=()=>{t=null},r=e=>e.target instanceof Element?e.target.closest(bi):null,i=e=>{if(!e.isTrusted)return;let n=r(e),i=n?.dataset.notificationSession;t=n&&i?{element:n,session:i,at:performance.now()}:null},a=e=>{r(e)!==t?.element&&n()},o=[`pointerdown`,`keydown`,`input`,`paste`];for(let t of o)e.addEventListener(t,i,!0);return e.addEventListener(`focusin`,a,!0),e.addEventListener(`visibilitychange`,n),e.defaultView?.addEventListener(`blur`,n),{isInteracting(n){return t!==null&&t.session===n&&performance.now()-t.at<yi&&e.visibilityState===`visible`&&e.hasFocus()&&t.element.isConnected&&t.element.dataset.notificationSession===n&&t.element.getClientRects().length>0},dispose(){n();for(let t of o)e.removeEventListener(t,i,!0);e.removeEventListener(`focusin`,a,!0),e.removeEventListener(`visibilitychange`,n),e.defaultView?.removeEventListener(`blur`,n)}}}var Si=new Set,Ci=e=>!!e&&Si.has(e);async function wi(e,t,n){let r=M()?.windows?.effects;if(!r)return!0;try{return await r.claimNotification({id:e,...t?{legacy:!0}:{},...r.setNotificationProfile?{profileId:n}:{}})}catch{return!1}}async function Ti(e){let t=M()?.windows,n=t?.projects;if(!n||e.host)return!1;let r=await P.fetchQuery({queryKey:[`project`,e.project],queryFn:()=>j(`GET`,`/api/projects/${e.project}`),staleTime:1e4}),i={profileId:r.project.profile_id,route:`/project/${e.project}/session/${e.session}`};return await t?.transfers?.focusPane?.({profileId:i.profileId,ref:h(r.sessions.find(t=>t.id===e.session)??{id:e.session,kind:`agent`})})||await n.route(i)||await dr({...i,kind:`navigate-project`}),!0}var Ei=f.parse({});function Di(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&(e.permission===`granted`||e.permission===`unverified`)&&(e.prefs.when_focused||!e.sessionFocused),sound:e.prefs.sound}}function Oi(e,t){for(let[,n]of e.getQueriesData({queryKey:[`sessions`]})){let e=n?.find(e=>e.id===t);if(e)return e}for(let[,n]of e.getQueriesData({queryKey:[`project`]})){let e=n?.sessions.find(e=>e.id===t);if(e)return e}}function ki(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function Ai(){try{let e=new AudioContext,t=e.createGain();t.gain.value=.04,t.connect(e.destination);for(let[n,r]of[[880,0],[1318.5,.09]]){let i=e.createOscillator();i.type=`sine`,i.frequency.value=n,i.connect(t),i.start(e.currentTime+r),i.stop(e.currentTime+r+.12)}setTimeout(()=>void e.close(),400)}catch{}}function ji(){let e=mt(),t=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=xi(document);return t.current=e,()=>{t.current=null,e.dispose()}},[]),(0,Y.useEffect)(()=>vi(t=>{t.host||Ti(t).then(n=>{n||e(`/project/${t.project}/session/${t.session}`,{state:{notificationSession:t.session}})}).catch(q)}),[e]),Mi(t=>{e(`/project/${t.project_id}/session/${t.id}`,{state:{notificationSession:t.id}})},e=>t.current?.isInteracting(e.id)??!1)}function Mi(e,t=()=>document.hasFocus()){let n=tt(),r=G(),i=(0,Y.useRef)(e);i.current=e;let a=(0,Y.useRef)(t);a.current=t;let o=Xe(Ge().data)??`Puddle`,s=(0,Y.useRef)(o);s.current=o;let[c,l]=(0,Y.useState)(0);An(`shell`,c>0?`(${c}) ${o}`:o),(0,Y.useEffect)(()=>{let e=new Set;l(0);let t=!0,o=M()?.windows?.effects,c=o?.setNotificationProfile?o.setNotificationProfile(r).then(()=>!0,()=>!1):Promise.resolve(!0),u=()=>t&&r!==null&&Pn()===r,d=async e=>{if(!u())return;let o=Oi(n,e.session);if(!o)try{o=(await $e(n)).find(t=>t.id===e.session)}catch{return}if(!u()||!o)return;let l=o,d,p;try{let e=await n.fetchQuery({queryKey:[`project`,l.project_id],queryFn:()=>j(`GET`,`/api/projects/${l.project_id}`),staleTime:1e4});if(!u())return;p=e.project;let t=p.profile_id;if(t!==r)return;let i=await n.fetchQuery({queryKey:[`profile-settings`,t],queryFn:()=>j(`GET`,`/api/profiles/${t}/settings`),staleTime:1e4});d=f.catch(Ei).parse(i.notifications??{})}catch{return}if(!await c||!u()||!await wi(e.id??`${e.session}:${e.activity??`waiting`}`,!e.id,p.profile_id)||!u())return;let m=Di({prefs:d,projectId:l.project_id,sessionFocused:a.current(l),permission:re()});m.sound&&Ai(),m.desktop&&!Ci(b()?.scope)&&await ce({id:e.id?`puddle-event-${e.id}`:`puddle-agent-${l.id}`,title:e.content?.title??ki(l).slice(0,160),body:e.content?.body??(e.reason===`exited`?`Agent finished running`:`Waiting for your input`),target:{project:l.project_id,session:l.id,...b()?.notificationHost?{host:b().notificationHost}:{}}},()=>{t&&i.current(l)},{host:s.current,project:p})},p=J.onAgentNotification(e=>{d(e)}),m=J.onStatus(t=>{let r=e.has(t.session);t.status===`waiting_input`?e.add(t.session):e.delete(t.session),l(e.size),!(t.status!==`waiting_input`||r)&&n.fetchQuery({queryKey:[`version`],queryFn:()=>j(`GET`,`/api/version`),staleTime:1/0}).then(e=>{if(!(e.protocol.major>22||e.protocol.major===22&&e.protocol.minor>=3))return d({session:t.session,reason:`waiting_input`,activity:t.last_activity_at})}).catch(()=>{})});return()=>{t=!1,m(),p(),o?.setNotificationProfile?.(null).catch(()=>{})}},[n,r])}function Ni({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,Y.useState)(e?.title??``),[c,l]=(0,Y.useState)(e?.body??``),[u,d]=(0,Y.useState)(n?e?.scope??t:`profile`),[f,p]=(0,Y.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,Y.useState)(e?.agent_type??null),g=()=>{let e=c.trim();e&&i({title:o.trim()||null,body:e,scope:u,tags:f.split(`,`).map(e=>e.trim()).filter(Boolean),agent_type:m})};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(V,{value:o,placeholder:`Title (optional)`,spellCheck:!1,onChange:e=>s(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-9 text-sm font-medium`}),(0,X.jsx)(Vt,{autoFocus:!0,value:c,placeholder:`Prompt or note…`,spellCheck:!1,rows:10,onChange:e=>l(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`?a():e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},className:`resize-y text-sm leading-relaxed`}),(0,X.jsx)(V,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,X.jsx)(Qt,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,X.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:F(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,X.jsx)(On,{type:e.id,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,X.jsx)(B,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,X.jsx)(B,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function Pi(){let e=hn(),t=G(),n=_t().id,r=Le(t??void 0,n).data??[],i=Be().data??[],a=et(),o=Ee(),s=Ne(),c=yn(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null);(0,Y.useEffect)(()=>K(`scratchpad.toggle`,bn),[]),(0,Y.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,Y.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),b=(0,Y.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),x=d!==null||p!==null,S=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),C=x?S:_??r,w=e=>{t&&(a.mutate({profile_id:t,scope:e.scope,project_id:e.scope===`project`?n:void 0,title:e.title??void 0,body:e.body,tags:e.tags,agent_type:e.agent_type??void 0}),u(null))},T=(e,t)=>{o.mutate({id:e,scope:t.scope,project_id:t.scope===`project`?n??null:null,title:t.title,body:t.body,tags:t.tags,agent_type:t.agent_type}),u(null)},E=(e,t)=>{let n=_??r,i=n.findIndex(t=>t.id===e),a=n.findIndex(e=>e.id===t);if(i===-1||a===-1||i===a)return;let o=n.slice(),[s]=o.splice(i,1);o.splice(a,0,s),v(o)},D=()=>{let e=h,t=_;if(g(null),v(null),e===null||!t)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=t[n-1],i=t[n+1],a=r?i?(r.position+i.position)/2:r.position+1:(i?i.position:0)-1;o.mutate({id:e,position:a})},ee=e=>{navigator.clipboard?.writeText(e.body),I.success(`Copied to clipboard`)};return(0,X.jsxs)(or,{open:e,onOpenChange:wn,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(Nr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,X.jsx)(R,{children:`Scratchpad`})]}),(0,X.jsxs)(ir,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:F(Nt,`ml-auto`),children:[(0,X.jsx)(rn,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||b.length>0)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:F(`rounded-full px-2 py-0.5 text-2xs transition-colors`,d===e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:e},e)),b.map(e=>(0,X.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:F(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,X.jsx)(On,{type:e,className:`size-3.5`})},e))]}),(0,X.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[(0,X.jsx)(nn,{expanded:l===`new`,children:l===`new`&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Ni,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:w,onCancel:()=>u(null)})})}),C.length===0&&l!==`new`&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:x?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:C.map(e=>(0,X.jsx)(`li`,{draggable:!x&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&E(h,e.id))},onDragEnd:D,className:F(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,X.jsx)(nn,{expanded:l===e.id,children:l===e.id?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Ni,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>T(e.id,t),onCancel:()=>u(null)})}):(0,X.jsx)(Fi,{entry:e,onInsert:c?()=>{c(e.body),wn(!1)}:null,onCopy:()=>ee(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})})},e.id))})]})]})]})}function Fi({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button`)||r()},className:`cursor-pointer rounded-md px-3 py-2.5 transition-colors hover:bg-surface`,children:[e.title&&(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,X.jsx)(`p`,{className:F(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:F(Mt,`text-danger`),children:`Delete`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:Mt,children:`Cancel`})]}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,X.jsx)(On,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,X.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,X.jsxs)(Xn,{label:`Scratchpad entry actions`,className:`ml-auto`,children:[t&&(0,X.jsx)(Ii,{icon:Ar,label:`Insert into focused terminal`,onClick:t}),(0,X.jsx)(Ii,{icon:$t,label:`Copy`,onClick:n}),(0,X.jsx)(Ii,{icon:Ht,label:`Edit`,onClick:r}),(0,X.jsx)(Ii,{icon:cn,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function Ii({icon:e,label:t,onClick:n}){return(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Nt,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(R,{children:t})]})}var Li=e=>({layout_tree:e.layout_tree,active_session:e.active_session});function Ri(e,t,n,r){if(t===`project`&&!n)throw Error(`Select a project before saving its windows`);let i=e.flatMap(({identity:e,snapshot:i,visibleProject:a})=>{if(t===`project`&&e.kind!==`host`&&e.projectId!==n)return[];let o=i;if(t===`project`&&e.kind===`host`){let e=ct({snapshot:i,buffers:[],views:{}},n,r,a??``).destination.snapshot;o={...i,layout_mode:`project`,layout_tree:null,active_session:null,project_layouts:{[n]:{...Li(e),layout_ref:null}}}}let s=o.layout_mode===`project`?o.layout_tree:o.layout_tree??nt(o);return[l.parse({key:e.kind===`host`?`host`:e.kind===`project`?`project-${e.projectId}`:e.id,kind:e.kind,project_id:e.kind===`host`?t===`project`?n:a:e.projectId,layout_mode:o.layout_mode??`profile`,layout_tree:s,active_session:o.active_session,project_layouts:Object.fromEntries(Object.entries(o.project_layouts).map(([e,t])=>[e,Li(t)]))})]}),a=u.parse({version:1,windows:i}),o=y(a,t,n);if(o)throw Error(o);let s=new Set,c=i.flatMap(e=>e.layout_mode===`project`?Object.values(e.project_layouts).map(e=>e.layout_tree):[e.layout_tree]).filter(e=>e!==null).map(e=>rt(e,e=>e.type===`editor`?!0:s.has(e.session)?!1:(s.add(e.session),!0))).filter(e=>it(e).length!==0);return{window_arrangement:a,layout_tree:c.length?lt(ft(c.length===1?c[0]:at(`row`,c))):null,active_session:i.flatMap(e=>e.layout_mode===`project`?Object.values(e.project_layouts).map(e=>e.active_session):[e.active_session]).find(e=>e!==null&&s.has(e))??null}}function zi(e,t,n,r){let i=e.entries.filter(e=>e.open).map(e=>({identity:e.identity,snapshot:e.snapshot,visibleProject:/^\/project\/([0-9a-f]{10})/.exec(e.route??``)?.[1]??null})),a=i.find(e=>e.identity.kind===`host`);for(let n of e.entries){if(!n.returnedProject||n.open||n.identity.kind!==`project`)continue;if(!a)throw Error(`The host layout has not loaded`);if(!n.snapshot.layout_tree)continue;let e=a.snapshot;a.snapshot=st({snapshot:e,buffers:[],views:{}},{snapshot:n.snapshot,buffers:[],views:{}},n.identity.projectId).snapshot,t===`project`&&e.layout_mode===`project`&&(a.snapshot={...a.snapshot,project_layouts:{...e.project_layouts,[n.identity.projectId]:a.snapshot.project_layouts[n.identity.projectId]}})}return Ri(i,t,n,r)}function Bi(e){return JSON.stringify(e.windows.map(e=>JSON.stringify({kind:e.kind,project:e.kind===`host`?null:e.project_id,mode:e.layout_mode,tree:U(e.layout_tree),slices:Object.entries(e.project_layouts).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,U(t.layout_tree)])})).sort())}function Vi(e){if(e.window_arrangement)return e.window_arrangement;let t={layout_tree:e.layout_tree,active_session:e.active_session};return u.parse({version:1,windows:[{key:`host`,kind:`host`,project_id:e.project_id,layout_mode:e.scope===`project`?`project`:`profile`,...e.scope===`project`?{layout_tree:null,active_session:null}:t,project_layouts:e.scope===`project`?{[e.project_id]:t}:{}}]})}var Hi=new class{running=!1;uncertain=null;listeners=new Set;busy=()=>this.running;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});async apply(e,t){if(!e.apply||!e.observe)throw Error(`Update the desktop app to load window layouts`);if(this.running)throw Error(`A window layout is already loading`);this.running=!0,this.listeners.forEach(e=>e());try{if(this.uncertain){let t=await e.observe(this.uncertain);throw t.status!==`committed`&&t.status!==`cancelled`?Error(`The previous layout outcome is still unknown. Reopen the host window to recover before loading another layout.`):(this.uncertain=null,Error(`The previous layout was ${t.status}. Choose the desired layout again to load it.`))}this.uncertain={id:t.id,profileId:t.profileId};let n;try{n=await e.apply(t)}catch{n=await e.observe(this.uncertain)}return(n.status===`committed`||n.status===`cancelled`)&&(this.uncertain=null),n}finally{this.running=!1,this.listeners.forEach(e=>e())}}};function Ui(e,t,n,r){let a=N(),o=a!==null,s=M()?.windows?.layouts,c=ze().data?.protocol,l=!!s?.apply&&!!s.observe&&i(c,{major:26,minor:17}),u=a?.identity.kind===`host`,d=ut(o&&u?e:null),f=(0,Y.useSyncExternalStore)(Hi.subscribe,Hi.busy),p=r===`profile`?``:r??(n?.scope===`project`?n.projectId:``),m=p?`project`:`profile`,h=Qe({queryKey:[`native-layout-capture`,a?.identity.id,e,m,p],enabled:o&&u&&l&&t&&!!e&&!!d?.loaded&&!f,retry:!1,staleTime:0,queryFn:async()=>{if(!s||!e||Pn()!==e)throw Error(`The active profile changed`);let t=await $e(P),n=await s.capture({profileId:e,scope:m,...p?{projectId:p}:{}});if(Pn()!==e)throw Error(`The active profile changed`);return zi(n,m,p||null,new Map(t.map(e=>[e.id,e.project_id])))}}),g=d?.snapshot,_=(0,Y.useRef)(g);(0,Y.useEffect)(()=>{let e=_.current!==g;_.current=g,e&&o&&u&&l&&t&&g&&!f&&P.invalidateQueries({queryKey:[`native-layout-capture`,a.identity.id]})},[o,u,l,t,g,f,a]),(0,Y.useEffect)(()=>{if(!o||!u||!l||!t||f)return;let e=()=>{P.invalidateQueries({queryKey:[`native-layout-capture`,a.identity.id]})};window.addEventListener(`focus`,e);let n=M()?.onWindowFocusChange?.(t=>{t&&e()});return()=>{window.removeEventListener(`focus`,e),n?.()}},[o,u,l,t,f,a]);let v=o&&!l?`Window layouts require an updated desktop app and host (application 26.17 or later).`:h.error?.message??null;if(!o||!u||!l||!e||!d?.loaded)return{native:o,bridge:null,busy:f,error:v};let y=()=>{if(Pn()!==e)throw Error(`The active profile changed`)};return{native:o,bridge:{native:!0,scope:m,projectId:p,layoutRef:p?d.snapshot.project_layouts[p]?.layout_ref??d.snapshot.layout_ref:d.snapshot.layout_ref,signature:h.error||h.isStale&&h.isFetching?``:h.data?Bi(h.data.window_arrangement):``,savedSignature:e=>Bi(Vi(e)),capture:async()=>{y();let e=await h.refetch({throwOnError:!0});if(!e.data)throw Error(`The window layout could not be captured`);return y(),e.data},adopt:async t=>{y();let n=dt(e),r=n.get(),i=t.project_id?r.project_layouts[t.project_id]:void 0;n.update(i&&t.project_id?{project_layouts:{...r.project_layouts,[t.project_id]:{...i,layout_ref:t.id}}}:{layout_ref:t.id}),await n.flush()},apply:async t=>{y();let n=await Hi.apply(s,{id:crypto.randomUUID(),profileId:e,scope:t.scope,...t.project_id?{projectId:t.project_id}:{},arrangement:Vi(t),layoutRef:t.id});if(n.status!==`committed`)throw Error(n.error??(n.status===`cancelled`?`The layout was cancelled; your previous windows remain available.`:`The layout outcome is not confirmed. Load again to check its recorded outcome.`));return n.error&&I.warning(n.error),!0}},busy:f||h.isFetching,error:v}}var Wi=s.parse({});function Gi(e,t){let[n,r]=(0,Y.useState)(null),i=(0,Y.useRef)({profileId:e,enabled:t});i.current={profileId:e,enabled:t};let a=Ke(t).data,o=Ie(e??void 0,t&&e!==null).data;return(0,Y.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=xn(sessionStorage.getItem(Tn(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return Je(e).then(e=>{n||r(e?e.ui_state:Wi)}).catch(()=>{n||r(Wi)}),()=>{n=!0}},[t,e]),(0,Y.useMemo)(()=>{if(!t||e===null||n===null)return null;let s=t=>{r(t),Ue(e,t).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Tn(e),JSON.stringify(t))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}},c=e=>{if(!a||!o)return!1;let{patch:t,projectBased:r}=ot(n,e,{alive:new Set(a.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(a.map(e=>[e.id,e.project_id])),projectIds:o.map(e=>e.id),currentProject:null}),i={...n,...t};return s(i),me().projectBasedLayout!==r&&pe({projectBasedLayout:r}),!0},l=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:U(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:U(null),slices:l,capture:()=>({layout_tree:null,active_session:null}),apply:c}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:U(n.layout_tree),slices:l,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),adopt:e=>{i.current.enabled&&i.current.profileId===e.profile_id&&s({...n,layout_ref:e.id})},apply:c}},[t,e,n,a,o])}var Ki=U(null);function qi(){let e=vn(),t=mt(),n=G(),r=Dn(),[i,a]=(0,Y.useState)(null),o=Ui(n,e,r,i),s=Gi(n,!o.native&&e&&r===null),c=o.native?o.bridge:r??s,[l,u]=(0,Y.useState)(!1),d=(0,Y.useRef)(!1),f=l||o.busy,p=async e=>{if(!(d.current||o.busy)){d.current=!0,u(!0);try{await e()}catch(e){q(e)}finally{d.current=!1,u(!1)}}},m=Te(n??void 0,void 0).data??[],h=Ie(n??void 0,e&&n!==null).data??[],g=qe(),_=Oe(),v=De(),[y,b]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=N()?.identity.kind;if(!e||e===`host`)return K(`layouts.toggle`,Cn)},[]),(0,Y.useEffect)(()=>{e||(b(``),S(!1),w(null),a(null))},[e]);let T=c?.headless===!0,E=c===null||T?null:m.find(e=>e.id===c.layoutRef&&(!c.native||e.scope===c.scope&&(e.scope===`profile`||e.project_id===c.projectId)))??null,D=c!==null&&!T&&(E===null?c.signature!==Ki:(c.savedSignature?.(E)??U(E.layout_tree))!==c.signature),ee=e=>{let t=c?.slices?.[e];if(!t)return!1;let n=t.layoutRef===null?null:m.find(e=>e.id===t.layoutRef)??null;return n?U(n.layout_tree)!==t.signature:t.signature!==Ki},te=e=>c===null?!1:c.native?!A(e)||!c.signature||c.savedSignature?.(e)!==c.signature:e.scope===`profile`?c.scope===`profile`&&D:e.project_id===null?!1:c.scope===`project`?!T&&e.project_id===c.projectId?D:ee(e.project_id):D||ee(e.project_id),ne=e=>E!==null&&e.id===E.id,re=e=>(e===null?void 0:h.find(t=>t.id===e)?.name)??`Project`,O=c!==null&&!T&&c.scope===`project`?m.filter(e=>e.scope===`profile`||e.project_id===c.projectId):m,k=[...O.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(O.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:re(e)})).sort((e,t)=>e.name.localeCompare(t.name))],ie=C===null?O:C===`profile`?O.filter(e=>e.scope===`profile`):O.filter(e=>e.project_id===C),A=e=>c!==null&&e.scope===c.scope&&(c.scope===`profile`||e.project_id===c.projectId),ae=async e=>{c?.adopt?await c.adopt(e):await c?.apply(e)},oe=async(e,t,r)=>{if(!c||!n)return;let i=await g.mutateAsync({profile_id:n,scope:c.scope,...c.scope===`project`?{project_id:c.projectId}:{},name:e,...t});r&&await ae(i)},se=e=>p(async()=>{if(!c)return;let t=A(e)?e:m.find(t=>t.name===e.name&&A(t)),n=await c.capture();t?await ae(await _.mutateAsync({id:t.id,...n})):await oe(e.name,n,!0)}),ce=(e,t)=>p(async()=>{await oe(t,{layout_tree:e.layout_tree,active_session:e.active_session,...A(e)&&e.window_arrangement?{window_arrangement:e.window_arrangement}:{}},!1)}),le=e=>p(async()=>{if(c){if(!await c.apply(e)){I.error(`Workspace is still loading — try again in a moment`);return}!c.native&&e.project_id!==null&&e.project_id!==c.projectId&&t(`/project/${e.project_id}`),_n(!1)}});return(0,X.jsxs)(or,{open:e,onOpenChange:_n,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(jr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,X.jsx)(R,{children:`Layouts`})]}),(0,X.jsxs)(ir,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),c!==null&&!T&&(0,X.jsxs)(`button`,{type:`button`,disabled:f,onClick:()=>S(e=>!e),className:F(`inline-flex size-[var(--ui-control-height)] shrink-0 cursor-pointer items-center justify-center rounded-[var(--ui-radius)] text-fg transition-colors hover:bg-elevated disabled:pointer-events-none disabled:opacity-50`,`ml-auto`),children:[(0,X.jsx)(rn,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),o.native&&(0,X.jsxs)(`div`,{className:`px-5 pb-3`,children:[(0,X.jsxs)(Rt,{value:c?.scope===`project`?c.projectId:`profile`,onValueChange:a,disabled:f,children:[(0,X.jsx)(Ft,{"aria-label":`Save layout for`,className:`h-8 text-sm`,children:(0,X.jsx)(Pt,{})}),(0,X.jsxs)(It,{children:[(0,X.jsx)(Lt,{value:`profile`,children:`Profile-wide`}),h.map(e=>(0,X.jsx)(Lt,{value:e.id,children:e.name},e.id))]})]}),o.error&&(0,X.jsx)(`p`,{role:`status`,className:`pt-2 text-sm text-fg-muted`,children:o.error})]}),(0,X.jsx)(nn,{expanded:c!==null&&!T&&(E===null||x),children:c===null?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):T?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Project-based layout is on — every project keeps its own layout. Open a project to name or save it; loading works from here.`}):(E===null||x)&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[E===null&&(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:c.scope===`profile`?`Profile-wide`:`Project`}),(0,X.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=y.trim();t&&p(async()=>{await oe(t,await c.capture(),!0),b(``),S(!1)})},children:[(0,X.jsx)(V,{autoFocus:x,value:y,placeholder:E===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>b(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&S(!1)},className:`h-8 flex-1 text-sm`}),(0,X.jsx)(B,{size:`sm`,type:`submit`,disabled:f||!y.trim(),children:`Save`}),E!==null&&(0,X.jsx)(B,{variant:`ghost`,size:`sm`,onClick:()=>S(!1),children:`Cancel`})]})]})}),k.length>1&&(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:k.map(e=>(0,X.jsx)(Xi,{active:C===e.key,onClick:()=>w(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,X.jsxs)(`div`,{inert:f||void 0,"aria-busy":f,className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[ie.length===0&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:C===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:ie.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(Ji,{layout:e,projectLabel:e.scope===`profile`?null:re(e.project_id),isCurrent:ne(e),dirty:D,loadable:c!==null&&!f,savable:c!==null&&!T&&!f,confirmBeforeLoad:te(e),overwrites:A(e),onLoad:()=>le(e),onRename:t=>_.mutate({id:e.id,name:t}),onDelete:()=>v.mutate(e.id),onSaveAs:()=>se(e),onDuplicate:t=>ce(e,t)})},e.id))})]})]})]})}function Ji({layout:e,projectLabel:t,isCurrent:n,dirty:r,loadable:i,savable:a,confirmBeforeLoad:o,overwrites:s,onLoad:c,onRename:l,onDelete:u,onSaveAs:d,onDuplicate:f}){let[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(e.name),y=()=>{if(!(!i||h!==null)){if(o&&p!==`load`){m(`load`);return}m(null),c()}},b=t=>{m(null),v(t===`rename`?e.name:`${e.name} copy`),g(t)},x=()=>{if(n){d();return}m(`save`)},S=n?r?`unsaved`:`active`:null;return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||y()},className:F(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[h===null?(0,X.jsxs)(`p`,{className:F(`flex items-baseline gap-2 text-sm font-medium`,S===`active`?`text-success`:S===`unsaved`?`text-interrupted`:`text-fg`),children:[e.name,S!==null&&(0,X.jsx)(`span`,{className:`text-2xs font-normal`,children:S===`active`?`Active`:`Unsaved`})]}):(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:t=>{t.preventDefault();let n=_.trim();n&&(h===`rename`?n!==e.name&&l(n):f(n)),g(null)},children:[(0,X.jsx)(V,{autoFocus:!0,value:_,spellCheck:!1,onChange:e=>v(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&g(null)},className:`h-7 flex-1 text-sm`}),(0,X.jsx)(B,{size:`sm`,type:`submit`,disabled:!_.trim(),children:h===`rename`?`Rename`:`Save`})]}),p===`save`?(0,X.jsx)(Yi,{question:s?`Overwrite “${e.name}” with the current layout?`:`Save the current layout as “${e.name}” here?`,verb:s?`Overwrite`:`Save`,onConfirm:()=>{m(null),d()},onCancel:()=>m(null)}):p===`delete`?(0,X.jsx)(Yi,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{m(null),u()},onCancel:()=>m(null)}):p===`load`?(0,X.jsx)(Yi,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:y,onCancel:()=>m(null)}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,X.jsxs)(Xn,{label:`Layout actions`,className:`ml-auto`,children:[a&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Zi,{icon:on,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:x}),(0,X.jsx)(Zi,{icon:$t,label:`Duplicate`,onClick:()=>b(`duplicate`)})]}),(0,X.jsx)(Zi,{icon:Ht,label:`Rename`,onClick:()=>b(`rename`)}),(0,X.jsx)(Zi,{icon:cn,label:`Delete`,onClick:()=>m(`delete`)})]})]})]})}function Yi({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,X.jsx)(`button`,{type:`button`,onClick:n,className:F(Mt,`text-danger`),children:t}),(0,X.jsx)(`button`,{type:`button`,onClick:r,className:Mt,children:`Cancel`})]})}function Xi({active:e,onClick:t,children:n}){return(0,X.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:F(`rounded-full px-2 py-0.5 text-2xs transition-colors`,e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:n})}function Zi({icon:e,label:t,onClick:n}){return(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Nt,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(R,{children:t})]})}var $=M()!==void 0&&/Mac/.test(navigator.platform),Qi=(0,Y.lazy)(()=>be(()=>import(`./SettingsDialog-Dxyi7dhn.js`).then(e=>({default:e.SettingsDialog})),__vite__mapDeps([16,1,2,3,17,18,19,20,6,21,5,7,8,9,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59])));function $i(){let e=tt();(0,Y.useEffect)(()=>{let t,n=new Map,r=()=>{t||=setTimeout(()=>{t=void 0,e.invalidateQueries({queryKey:[`project-catalogue`]},{cancelRefetch:!1})},250)},i=J.onStatus(t=>{Br(e,t),n.get(t.session)!==t.status&&(n.set(t.session,t.status),n.size>2048&&n.delete(n.keys().next().value),r())}),a=J.onRenamed(t=>Vr(e,t)),o=J.onAccount(t=>{for(let[n,r]of e.getQueriesData({queryKey:[`accounts`]}))r&&e.setQueryData(n,r.map(e=>e.id===t.account_id?{...e,logged_in:t.logged_in}:e))}),s=t=>{r(),e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},c=J.onSessionsChanged(e=>s(e.project_ids)),l=J.onSessionSwitched(e=>s([e.target_project]));return()=>{clearTimeout(t),i(),a(),o(),c(),l()}},[e])}function ea(){let e=G(),t=je(e??``),n=ze().data?.protocol,r=C(),i=Ge(),a=Me(),[s,c]=(0,Y.useState)(!1),l=Xe(i.data),u=e=>{c(!1);let t=e.trim();t!==l&&a.mutate({displayName:t===i.data?.hostname?``:t},{onError:e=>q(e)})},d=(0,X.jsx)(w,{icon:r.icon}),f=F(`host-identity flex h-full shrink-0 items-center gap-2 px-4`,$&&`[-webkit-app-region:no-drag]`),p=`truncate font-sans text-xs font-normal`;return s&&l!==void 0?(0,X.jsxs)(`div`,{className:f,children:[d,(0,X.jsx)(un,{initial:i.data?.displayName??l,maxLength:64,className:F(p,`w-40`),onCommit:u,onCancel:()=>c(!1)})]}):(0,X.jsxs)(zn,{children:[(0,X.jsx)(Fn,{asChild:!0,children:(0,X.jsxs)(bt,{to:`/`,className:F(f,`hover:bg-elevated focus-visible:bg-elevated`),title:`All projects`,children:[d,l!==void 0&&(0,X.jsx)(`span`,{className:p,...fn(()=>c(!0)),children:l})]})}),(0,X.jsx)(Ir,{kind:`host`,colour:r.colour,onRename:()=>c(!0),onColour:n=>{e&&t.mutate({hostColour:n},{onError:q})},pending:t.isPending||!e,custom:o(n),onUpdates:()=>W(`host`)})]})}function ta(){let e=_t(),t=Un(`palette.toggle`),n=Pe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,X.jsx)(`button`,{type:`button`,onClick:mn,className:F(`flex h-full min-w-0 w-full cursor-pointer items-center justify-center gap-2 bg-transparent px-2 font-normal text-fg-muted transition-colors hover:bg-elevated focus-visible:bg-elevated`,$&&`[-webkit-app-region:no-drag]`),children:(0,X.jsxs)(`span`,{className:F(`pointer-events-none absolute left-1/2 top-1/2 flex max-w-[40%] -translate-x-1/2 -translate-y-1/2 items-center gap-2`,r&&Ut(n?.colour)),style:r?Gt(n?.colour):void 0,children:[(0,X.jsx)(`span`,{className:`truncate text-xs`,children:r??`Puddle`}),(0,X.jsx)(`span`,{className:`shrink-0 text-2xs`,children:t})]})})}function na(){let e=C(),{fullScreen:t,animate:n}=Se(),r=$&&!t;return(0,X.jsxs)(`header`,{"data-host-colour":e.colour??void 0,onClick:e=>{let t=e.target;e.currentTarget.contains(t)&&(t.closest(`[data-header-section], [aria-label="Workspace controls"], button, a, input`)||mn())},className:F(`host-header island-outline relative grid shrink-0 cursor-pointer grid-cols-[auto_1px_minmax(0,1fr)_1px_auto] items-center overflow-hidden rounded-[var(--ui-surface-radius)] bg-surface`,`h-9`,!$&&`mx-1.5 mt-1.5`,r&&`pl-[84px] [-webkit-app-region:drag]`,n&&`transition-[padding] duration-200 ease-out`),children:[r&&(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-[84px] top-1/2 h-5 w-px -translate-y-1/2 bg-border`}),(0,X.jsx)(`div`,{"data-header-section":!0,className:`flex h-full min-w-0 cursor-default items-center overflow-hidden`,children:(0,X.jsx)(ea,{})}),(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`h-5 w-px bg-border`}),(0,X.jsx)(ta,{}),(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`h-5 w-px bg-border`}),(0,X.jsxs)(Xn,{label:`Workspace controls`,className:F(`shell-header-actions h-full justify-self-end rounded-none!`,r&&`cursor-default [-webkit-app-region:drag]`,$&&`[&>button]:[-webkit-app-region:no-drag] [&>.profile-trigger]:[-webkit-app-region:no-drag]`),children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>W(),children:[(0,X.jsx)(Pr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,X.jsx)(R,{children:`Settings`})]}),(0,X.jsx)(qi,{}),(0,X.jsx)(Pi,{}),(0,X.jsx)(ii,{})]})]})}function ra(){let e=En();$i(),_i(),ji();let{handler:t}=kn(),n=G(),{pathname:r}=xt(),[i,o]=(0,Y.useState)(!1),s=ze(),c=s.data!==void 0&&a(s.data.protocol);return(0,Y.useEffect)(()=>{if(!c)return;let e=()=>{let e=ge();J.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),ve(e)},[c]),(0,X.jsxs)(`div`,{ref:e.ref,"data-project-window-drop-target":e.enabled||void 0,className:`relative flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[e.active&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute inset-1.5 z-50 flex items-center justify-center rounded-[var(--ui-surface-radius)] bg-accent/20`,children:(0,X.jsx)(`span`,{role:`status`,className:`rounded-[var(--ui-radius)] bg-surface px-4 py-2 text-sm text-fg shadow-lg`,children:`Return project here`})}),(0,X.jsx)(T,{}),(0,X.jsx)(ue,{}),(0,X.jsx)(Lr,{}),(!N()||N()?.identity.kind===`host`)&&(0,X.jsx)(na,{}),(0,X.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,X.jsx)(pr,{resetOn:r,scope:r.startsWith(`/project/`)?`workspace`:`view`,children:(0,X.jsx)(Tt,{className:`h-full`,motionKey:r.startsWith(`/project/`)?`workspace`:r,children:(0,X.jsx)(gt,{})})})}),(0,X.jsx)(Rr,{}),(0,X.jsx)($r,{}),(0,X.jsx)(ci,{}),(0,X.jsx)(fi,{}),(0,X.jsx)(mi,{}),(0,X.jsx)(gi,{}),(0,X.jsx)(Jr,{onNewSession:t??void 0,onNewProject:()=>o(!0)}),n!==null&&(0,X.jsx)(en,{profileId:n,open:i,onOpenChange:o}),(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Qi,{})}),(0,X.jsx)(Zr,{})]})}function ia(){return(0,X.jsx)(gn,{children:(0,X.jsx)(ra,{})})}function aa({children:e}){let t=(0,Y.useContext)(Ct),n=xt(),r=G(),i=M()?.windows?.projects,a=N(),o=(0,Y.useRef)(null),[,s]=(0,Y.useState)(0),c=(0,Y.useRef)(0),l=`${r}:${n.pathname}`,u=a?.identity,d=u&&u.kind!==`host`&&(n.pathname===`/project/${u.projectId}`||n.pathname.startsWith(`/project/${u.projectId}/session/`));(a?.stagingTransfer||a?.stagingArrangement||d)&&(o.current=l);let f=(0,Y.useMemo)(()=>{if(!i||!r)return t;let e=e=>(...a)=>{let[s]=a,l=(typeof s==`string`?s:ht(s)).split(/[?#]/)[0]||n.pathname;if(!g.safeParse(l).success){t.navigator[e](...a);return}let u=++c.current;i.route({profileId:r,route:l}).then(n=>{u!==c.current||n||(o.current=`${r}:${l}`,t.navigator[e](...a))}).catch(q)};return{...t,navigator:{...t.navigator,push:e(`push`),replace:e(`replace`)}}},[i,r,t,n.pathname]);return(0,Y.useEffect)(()=>{if(!i||!r||o.current===l)return;let e=!0,t=()=>{let e=a?.identity,t=e&&e.kind!==`host`?`/project/${e.projectId}`:`/`;o.current=`${r}:${t}`,ur(t),s(e=>e+1)};return i.route({profileId:r,route:n.pathname}).then(n=>{e&&(n?t():(o.current=l,s(e=>e+1)))}).catch(n=>{e&&(q(n),t())}),()=>{e=!1}},[i,r,l,n.pathname,a]),i&&r&&o.current!==l?null:(0,X.jsx)(Ct.Provider,{value:f,children:e})}var oa=(0,Y.lazy)(()=>be(()=>import(`./Dashboard-CLdNA8WP.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([60,1,2,3,17,18,19,20,6,21,5,7,8,9,22,25,26,28,29,30,27,61,62,63,46,31,64,41,37,42,39,43,44,45,65,66,67,55,52,38]))),sa=(0,Y.lazy)(()=>be(()=>import(`./Workspace-DQDh6TQ7.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([68,1,2,3,17,18,19,20,6,21,5,7,8,9,22,30,29,25,26,27,69,28,70,39,41,37,42,43,44,45,61,63,62,34,35,71,46,31,64,65,66,72,53,54,33,73,74,75,38,76,77,49,78,51,79,36,52,80,81,82,83,58,84,85])));function ca(){let e=G(),t=ke(),n=N()?.identity,r=n!==void 0&&n.kind!==`host`,i=e!==null&&t.data!==void 0&&!r&&!t.data.some(t=>t.id===e),a=e===null||i;return(0,X.jsx)(Tt,{className:`h-screen`,motionKey:a?`profiles`:`frontend`,children:a?(0,X.jsx)(Fr,{}):(0,X.jsx)(vt,{useTransitions:!1,children:(0,X.jsx)(aa,{children:(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(yt,{children:(0,X.jsxs)(pt,{element:(0,X.jsx)(ia,{}),children:[(0,X.jsx)(pt,{path:`/`,element:(0,X.jsx)(oa,{})}),(0,X.jsx)(pt,{path:`/project/:id`,element:(0,X.jsx)(sa,{})}),(0,X.jsx)(pt,{path:`/project/:id/session/:sid`,element:(0,X.jsx)(sa,{})})]})})})})})})}function la(){let e=(0,Y.useSyncExternalStore)(de.subscribe,de.get);return(0,X.jsx)(Re,{client:P,children:(0,X.jsxs)(zt,{delayDuration:300,children:[(0,X.jsx)(kr,{}),(0,X.jsx)(pr,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,X.jsx)(fr,{}):(0,X.jsx)(Ce,{children:(0,X.jsx)(ca,{})}):(0,X.jsx)(hr,{})}),(0,X.jsx)(mr,{})]})})}export{la as App};
14
+ - Block daemon replacement when existing runtimes report unsaved state, expose bounded recovery diagnostics through existing update reviews, and show affected runtime ids in CLI status without relaxing completion checks or replaying actions.
15
+ `})))},[e]),t?(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(hi,{current:t})}):null}function _i(){let e=G(),t=ke().data?.find(t=>t.id===e),n=Fe(e??void 0),r=Le(e??void 0,void 0),i=fe(),a=ae(),o=se(),s=je(e??``),c=Ae(),l=et(),[u,d]=(0,Y.useReducer)(e=>e+1,0);(0,Y.useEffect)(()=>ve(()=>d()),[]);let f=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{f.current=null},[t?.name]);let p=a.data?.available===!0?a.data.file:void 0,m=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&p!==void 0,h=t&&p?D(p,t.name):void 0,g=s.isPending||c.isPending||l.isPending||o.isPending||n.isFetching||r.isFetching;(0,Y.useEffect)(()=>{if(!m||!h?.enabled||g)return;let a={client:i,theme:he(),profileSettings:n.data,profile:t,scratchpad:r.data},u={setClient:e=>pe(e),setTheme:e=>{typeof e==`string`&&ye(e)},patchProfileSettings:e=>s.mutate(e),patchProfileColumns:t=>c.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)l.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},d=JSON.stringify(h.doc);if(f.current!==d){f.current=d,ie(h.doc,u,a,h.groups);return}let p=le(h.groups,a),_=JSON.stringify(p);_!==d&&(f.current=_,o.mutate({profile:t.name,entry:{...h,doc:p,updatedAt:new Date().toISOString()}}))})}function vi(e){let t=t=>{let n=p.safeParse(t);n.success&&e(n.data)},n=M()?.onNotificationClick?.((e,n)=>t(n)),r=e=>{e.data?.t===`notification-click`&&t(e.data.target)};return navigator.serviceWorker?.addEventListener(`message`,r),()=>{n?.(),navigator.serviceWorker?.removeEventListener(`message`,r)}}var yi=5e3,bi=`[data-notification-session]`;function xi(e){let t=null,n=()=>{t=null},r=e=>e.target instanceof Element?e.target.closest(bi):null,i=e=>{if(!e.isTrusted)return;let n=r(e),i=n?.dataset.notificationSession;t=n&&i?{element:n,session:i,at:performance.now()}:null},a=e=>{r(e)!==t?.element&&n()},o=[`pointerdown`,`keydown`,`input`,`paste`];for(let t of o)e.addEventListener(t,i,!0);return e.addEventListener(`focusin`,a,!0),e.addEventListener(`visibilitychange`,n),e.defaultView?.addEventListener(`blur`,n),{isInteracting(n){return t!==null&&t.session===n&&performance.now()-t.at<yi&&e.visibilityState===`visible`&&e.hasFocus()&&t.element.isConnected&&t.element.dataset.notificationSession===n&&t.element.getClientRects().length>0},dispose(){n();for(let t of o)e.removeEventListener(t,i,!0);e.removeEventListener(`focusin`,a,!0),e.removeEventListener(`visibilitychange`,n),e.defaultView?.removeEventListener(`blur`,n)}}}var Si=new Set,Ci=e=>!!e&&Si.has(e);async function wi(e,t,n){let r=M()?.windows?.effects;if(!r)return!0;try{return await r.claimNotification({id:e,...t?{legacy:!0}:{},...r.setNotificationProfile?{profileId:n}:{}})}catch{return!1}}async function Ti(e){let t=M()?.windows,n=t?.projects;if(!n||e.host)return!1;let r=await P.fetchQuery({queryKey:[`project`,e.project],queryFn:()=>j(`GET`,`/api/projects/${e.project}`),staleTime:1e4}),i={profileId:r.project.profile_id,route:`/project/${e.project}/session/${e.session}`};return await t?.transfers?.focusPane?.({profileId:i.profileId,ref:h(r.sessions.find(t=>t.id===e.session)??{id:e.session,kind:`agent`})})||await n.route(i)||await dr({...i,kind:`navigate-project`}),!0}var Ei=f.parse({});function Di(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&(e.permission===`granted`||e.permission===`unverified`)&&(e.prefs.when_focused||!e.sessionFocused),sound:e.prefs.sound}}function Oi(e,t){for(let[,n]of e.getQueriesData({queryKey:[`sessions`]})){let e=n?.find(e=>e.id===t);if(e)return e}for(let[,n]of e.getQueriesData({queryKey:[`project`]})){let e=n?.sessions.find(e=>e.id===t);if(e)return e}}function ki(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function Ai(){try{let e=new AudioContext,t=e.createGain();t.gain.value=.04,t.connect(e.destination);for(let[n,r]of[[880,0],[1318.5,.09]]){let i=e.createOscillator();i.type=`sine`,i.frequency.value=n,i.connect(t),i.start(e.currentTime+r),i.stop(e.currentTime+r+.12)}setTimeout(()=>void e.close(),400)}catch{}}function ji(){let e=mt(),t=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=xi(document);return t.current=e,()=>{t.current=null,e.dispose()}},[]),(0,Y.useEffect)(()=>vi(t=>{t.host||Ti(t).then(n=>{n||e(`/project/${t.project}/session/${t.session}`,{state:{notificationSession:t.session}})}).catch(q)}),[e]),Mi(t=>{e(`/project/${t.project_id}/session/${t.id}`,{state:{notificationSession:t.id}})},e=>t.current?.isInteracting(e.id)??!1)}function Mi(e,t=()=>document.hasFocus()){let n=tt(),r=G(),i=(0,Y.useRef)(e);i.current=e;let a=(0,Y.useRef)(t);a.current=t;let o=Xe(Ge().data)??`Puddle`,s=(0,Y.useRef)(o);s.current=o;let[c,l]=(0,Y.useState)(0);An(`shell`,c>0?`(${c}) ${o}`:o),(0,Y.useEffect)(()=>{let e=new Set;l(0);let t=!0,o=M()?.windows?.effects,c=o?.setNotificationProfile?o.setNotificationProfile(r).then(()=>!0,()=>!1):Promise.resolve(!0),u=()=>t&&r!==null&&Pn()===r,d=async e=>{if(!u())return;let o=Oi(n,e.session);if(!o)try{o=(await $e(n)).find(t=>t.id===e.session)}catch{return}if(!u()||!o)return;let l=o,d,p;try{let e=await n.fetchQuery({queryKey:[`project`,l.project_id],queryFn:()=>j(`GET`,`/api/projects/${l.project_id}`),staleTime:1e4});if(!u())return;p=e.project;let t=p.profile_id;if(t!==r)return;let i=await n.fetchQuery({queryKey:[`profile-settings`,t],queryFn:()=>j(`GET`,`/api/profiles/${t}/settings`),staleTime:1e4});d=f.catch(Ei).parse(i.notifications??{})}catch{return}if(!await c||!u()||!await wi(e.id??`${e.session}:${e.activity??`waiting`}`,!e.id,p.profile_id)||!u())return;let m=Di({prefs:d,projectId:l.project_id,sessionFocused:a.current(l),permission:re()});m.sound&&Ai(),m.desktop&&!Ci(b()?.scope)&&await ce({id:e.id?`puddle-event-${e.id}`:`puddle-agent-${l.id}`,title:e.content?.title??ki(l).slice(0,160),body:e.content?.body??(e.reason===`exited`?`Agent finished running`:`Waiting for your input`),target:{project:l.project_id,session:l.id,...b()?.notificationHost?{host:b().notificationHost}:{}}},()=>{t&&i.current(l)},{host:s.current,project:p})},p=J.onAgentNotification(e=>{d(e)}),m=J.onStatus(t=>{let r=e.has(t.session);t.status===`waiting_input`?e.add(t.session):e.delete(t.session),l(e.size),!(t.status!==`waiting_input`||r)&&n.fetchQuery({queryKey:[`version`],queryFn:()=>j(`GET`,`/api/version`),staleTime:1/0}).then(e=>{if(!(e.protocol.major>22||e.protocol.major===22&&e.protocol.minor>=3))return d({session:t.session,reason:`waiting_input`,activity:t.last_activity_at})}).catch(()=>{})});return()=>{t=!1,m(),p(),o?.setNotificationProfile?.(null).catch(()=>{})}},[n,r])}function Ni({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,Y.useState)(e?.title??``),[c,l]=(0,Y.useState)(e?.body??``),[u,d]=(0,Y.useState)(n?e?.scope??t:`profile`),[f,p]=(0,Y.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,Y.useState)(e?.agent_type??null),g=()=>{let e=c.trim();e&&i({title:o.trim()||null,body:e,scope:u,tags:f.split(`,`).map(e=>e.trim()).filter(Boolean),agent_type:m})};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(V,{value:o,placeholder:`Title (optional)`,spellCheck:!1,onChange:e=>s(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-9 text-sm font-medium`}),(0,X.jsx)(Vt,{autoFocus:!0,value:c,placeholder:`Prompt or note…`,spellCheck:!1,rows:10,onChange:e=>l(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`?a():e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},className:`resize-y text-sm leading-relaxed`}),(0,X.jsx)(V,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,X.jsx)(Qt,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,X.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:F(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,X.jsx)(On,{type:e.id,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,X.jsx)(B,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,X.jsx)(B,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function Pi(){let e=hn(),t=G(),n=_t().id,r=Le(t??void 0,n).data??[],i=Be().data??[],a=et(),o=Ee(),s=Ne(),c=yn(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null);(0,Y.useEffect)(()=>K(`scratchpad.toggle`,bn),[]),(0,Y.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,Y.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),b=(0,Y.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),x=d!==null||p!==null,S=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),C=x?S:_??r,w=e=>{t&&(a.mutate({profile_id:t,scope:e.scope,project_id:e.scope===`project`?n:void 0,title:e.title??void 0,body:e.body,tags:e.tags,agent_type:e.agent_type??void 0}),u(null))},T=(e,t)=>{o.mutate({id:e,scope:t.scope,project_id:t.scope===`project`?n??null:null,title:t.title,body:t.body,tags:t.tags,agent_type:t.agent_type}),u(null)},E=(e,t)=>{let n=_??r,i=n.findIndex(t=>t.id===e),a=n.findIndex(e=>e.id===t);if(i===-1||a===-1||i===a)return;let o=n.slice(),[s]=o.splice(i,1);o.splice(a,0,s),v(o)},D=()=>{let e=h,t=_;if(g(null),v(null),e===null||!t)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=t[n-1],i=t[n+1],a=r?i?(r.position+i.position)/2:r.position+1:(i?i.position:0)-1;o.mutate({id:e,position:a})},ee=e=>{navigator.clipboard?.writeText(e.body),I.success(`Copied to clipboard`)};return(0,X.jsxs)(or,{open:e,onOpenChange:wn,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(Nr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,X.jsx)(R,{children:`Scratchpad`})]}),(0,X.jsxs)(ir,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:F(Nt,`ml-auto`),children:[(0,X.jsx)(rn,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||b.length>0)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:F(`rounded-full px-2 py-0.5 text-2xs transition-colors`,d===e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:e},e)),b.map(e=>(0,X.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:F(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,X.jsx)(On,{type:e,className:`size-3.5`})},e))]}),(0,X.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[(0,X.jsx)(nn,{expanded:l===`new`,children:l===`new`&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Ni,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:w,onCancel:()=>u(null)})})}),C.length===0&&l!==`new`&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:x?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:C.map(e=>(0,X.jsx)(`li`,{draggable:!x&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&E(h,e.id))},onDragEnd:D,className:F(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,X.jsx)(nn,{expanded:l===e.id,children:l===e.id?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(Ni,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>T(e.id,t),onCancel:()=>u(null)})}):(0,X.jsx)(Fi,{entry:e,onInsert:c?()=>{c(e.body),wn(!1)}:null,onCopy:()=>ee(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})})},e.id))})]})]})]})}function Fi({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button`)||r()},className:`cursor-pointer rounded-md px-3 py-2.5 transition-colors hover:bg-surface`,children:[e.title&&(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,X.jsx)(`p`,{className:F(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:F(Mt,`text-danger`),children:`Delete`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:Mt,children:`Cancel`})]}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,X.jsx)(On,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,X.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,X.jsxs)(Xn,{label:`Scratchpad entry actions`,className:`ml-auto`,children:[t&&(0,X.jsx)(Ii,{icon:Ar,label:`Insert into focused terminal`,onClick:t}),(0,X.jsx)(Ii,{icon:$t,label:`Copy`,onClick:n}),(0,X.jsx)(Ii,{icon:Ht,label:`Edit`,onClick:r}),(0,X.jsx)(Ii,{icon:cn,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function Ii({icon:e,label:t,onClick:n}){return(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Nt,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(R,{children:t})]})}var Li=e=>({layout_tree:e.layout_tree,active_session:e.active_session});function Ri(e,t,n,r){if(t===`project`&&!n)throw Error(`Select a project before saving its windows`);let i=e.flatMap(({identity:e,snapshot:i,visibleProject:a})=>{if(t===`project`&&e.kind!==`host`&&e.projectId!==n)return[];let o=i;if(t===`project`&&e.kind===`host`){let e=ct({snapshot:i,buffers:[],views:{}},n,r,a??``).destination.snapshot;o={...i,layout_mode:`project`,layout_tree:null,active_session:null,project_layouts:{[n]:{...Li(e),layout_ref:null}}}}let s=o.layout_mode===`project`?o.layout_tree:o.layout_tree??nt(o);return[l.parse({key:e.kind===`host`?`host`:e.kind===`project`?`project-${e.projectId}`:e.id,kind:e.kind,project_id:e.kind===`host`?t===`project`?n:a:e.projectId,layout_mode:o.layout_mode??`profile`,layout_tree:s,active_session:o.active_session,project_layouts:Object.fromEntries(Object.entries(o.project_layouts).map(([e,t])=>[e,Li(t)]))})]}),a=u.parse({version:1,windows:i}),o=y(a,t,n);if(o)throw Error(o);let s=new Set,c=i.flatMap(e=>e.layout_mode===`project`?Object.values(e.project_layouts).map(e=>e.layout_tree):[e.layout_tree]).filter(e=>e!==null).map(e=>rt(e,e=>e.type===`editor`?!0:s.has(e.session)?!1:(s.add(e.session),!0))).filter(e=>it(e).length!==0);return{window_arrangement:a,layout_tree:c.length?lt(ft(c.length===1?c[0]:at(`row`,c))):null,active_session:i.flatMap(e=>e.layout_mode===`project`?Object.values(e.project_layouts).map(e=>e.active_session):[e.active_session]).find(e=>e!==null&&s.has(e))??null}}function zi(e,t,n,r){let i=e.entries.filter(e=>e.open).map(e=>({identity:e.identity,snapshot:e.snapshot,visibleProject:/^\/project\/([0-9a-f]{10})/.exec(e.route??``)?.[1]??null})),a=i.find(e=>e.identity.kind===`host`);for(let n of e.entries){if(!n.returnedProject||n.open||n.identity.kind!==`project`)continue;if(!a)throw Error(`The host layout has not loaded`);if(!n.snapshot.layout_tree)continue;let e=a.snapshot;a.snapshot=st({snapshot:e,buffers:[],views:{}},{snapshot:n.snapshot,buffers:[],views:{}},n.identity.projectId).snapshot,t===`project`&&e.layout_mode===`project`&&(a.snapshot={...a.snapshot,project_layouts:{...e.project_layouts,[n.identity.projectId]:a.snapshot.project_layouts[n.identity.projectId]}})}return Ri(i,t,n,r)}function Bi(e){return JSON.stringify(e.windows.map(e=>JSON.stringify({kind:e.kind,project:e.kind===`host`?null:e.project_id,mode:e.layout_mode,tree:U(e.layout_tree),slices:Object.entries(e.project_layouts).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,U(t.layout_tree)])})).sort())}function Vi(e){if(e.window_arrangement)return e.window_arrangement;let t={layout_tree:e.layout_tree,active_session:e.active_session};return u.parse({version:1,windows:[{key:`host`,kind:`host`,project_id:e.project_id,layout_mode:e.scope===`project`?`project`:`profile`,...e.scope===`project`?{layout_tree:null,active_session:null}:t,project_layouts:e.scope===`project`?{[e.project_id]:t}:{}}]})}var Hi=new class{running=!1;uncertain=null;listeners=new Set;busy=()=>this.running;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});async apply(e,t){if(!e.apply||!e.observe)throw Error(`Update the desktop app to load window layouts`);if(this.running)throw Error(`A window layout is already loading`);this.running=!0,this.listeners.forEach(e=>e());try{if(this.uncertain){let t=await e.observe(this.uncertain);throw t.status!==`committed`&&t.status!==`cancelled`?Error(`The previous layout outcome is still unknown. Reopen the host window to recover before loading another layout.`):(this.uncertain=null,Error(`The previous layout was ${t.status}. Choose the desired layout again to load it.`))}this.uncertain={id:t.id,profileId:t.profileId};let n;try{n=await e.apply(t)}catch{n=await e.observe(this.uncertain)}return(n.status===`committed`||n.status===`cancelled`)&&(this.uncertain=null),n}finally{this.running=!1,this.listeners.forEach(e=>e())}}};function Ui(e,t,n,r){let a=N(),o=a!==null,s=M()?.windows?.layouts,c=ze().data?.protocol,l=!!s?.apply&&!!s.observe&&i(c,{major:26,minor:17}),u=a?.identity.kind===`host`,d=ut(o&&u?e:null),f=(0,Y.useSyncExternalStore)(Hi.subscribe,Hi.busy),p=r===`profile`?``:r??(n?.scope===`project`?n.projectId:``),m=p?`project`:`profile`,h=Qe({queryKey:[`native-layout-capture`,a?.identity.id,e,m,p],enabled:o&&u&&l&&t&&!!e&&!!d?.loaded&&!f,retry:!1,staleTime:0,queryFn:async()=>{if(!s||!e||Pn()!==e)throw Error(`The active profile changed`);let t=await $e(P),n=await s.capture({profileId:e,scope:m,...p?{projectId:p}:{}});if(Pn()!==e)throw Error(`The active profile changed`);return zi(n,m,p||null,new Map(t.map(e=>[e.id,e.project_id])))}}),g=d?.snapshot,_=(0,Y.useRef)(g);(0,Y.useEffect)(()=>{let e=_.current!==g;_.current=g,e&&o&&u&&l&&t&&g&&!f&&P.invalidateQueries({queryKey:[`native-layout-capture`,a.identity.id]})},[o,u,l,t,g,f,a]),(0,Y.useEffect)(()=>{if(!o||!u||!l||!t||f)return;let e=()=>{P.invalidateQueries({queryKey:[`native-layout-capture`,a.identity.id]})};window.addEventListener(`focus`,e);let n=M()?.onWindowFocusChange?.(t=>{t&&e()});return()=>{window.removeEventListener(`focus`,e),n?.()}},[o,u,l,t,f,a]);let v=o&&!l?`Window layouts require an updated desktop app and host (application 26.17 or later).`:h.error?.message??null;if(!o||!u||!l||!e||!d?.loaded)return{native:o,bridge:null,busy:f,error:v};let y=()=>{if(Pn()!==e)throw Error(`The active profile changed`)};return{native:o,bridge:{native:!0,scope:m,projectId:p,layoutRef:p?d.snapshot.project_layouts[p]?.layout_ref??d.snapshot.layout_ref:d.snapshot.layout_ref,signature:h.error||h.isStale&&h.isFetching?``:h.data?Bi(h.data.window_arrangement):``,savedSignature:e=>Bi(Vi(e)),capture:async()=>{y();let e=await h.refetch({throwOnError:!0});if(!e.data)throw Error(`The window layout could not be captured`);return y(),e.data},adopt:async t=>{y();let n=dt(e),r=n.get(),i=t.project_id?r.project_layouts[t.project_id]:void 0;n.update(i&&t.project_id?{project_layouts:{...r.project_layouts,[t.project_id]:{...i,layout_ref:t.id}}}:{layout_ref:t.id}),await n.flush()},apply:async t=>{y();let n=await Hi.apply(s,{id:crypto.randomUUID(),profileId:e,scope:t.scope,...t.project_id?{projectId:t.project_id}:{},arrangement:Vi(t),layoutRef:t.id});if(n.status!==`committed`)throw Error(n.error??(n.status===`cancelled`?`The layout was cancelled; your previous windows remain available.`:`The layout outcome is not confirmed. Load again to check its recorded outcome.`));return n.error&&I.warning(n.error),!0}},busy:f||h.isFetching,error:v}}var Wi=s.parse({});function Gi(e,t){let[n,r]=(0,Y.useState)(null),i=(0,Y.useRef)({profileId:e,enabled:t});i.current={profileId:e,enabled:t};let a=Ke(t).data,o=Ie(e??void 0,t&&e!==null).data;return(0,Y.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=xn(sessionStorage.getItem(Tn(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return Je(e).then(e=>{n||r(e?e.ui_state:Wi)}).catch(()=>{n||r(Wi)}),()=>{n=!0}},[t,e]),(0,Y.useMemo)(()=>{if(!t||e===null||n===null)return null;let s=t=>{r(t),Ue(e,t).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Tn(e),JSON.stringify(t))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}},c=e=>{if(!a||!o)return!1;let{patch:t,projectBased:r}=ot(n,e,{alive:new Set(a.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(a.map(e=>[e.id,e.project_id])),projectIds:o.map(e=>e.id),currentProject:null}),i={...n,...t};return s(i),me().projectBasedLayout!==r&&pe({projectBasedLayout:r}),!0},l=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:U(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:U(null),slices:l,capture:()=>({layout_tree:null,active_session:null}),apply:c}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:U(n.layout_tree),slices:l,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),adopt:e=>{i.current.enabled&&i.current.profileId===e.profile_id&&s({...n,layout_ref:e.id})},apply:c}},[t,e,n,a,o])}var Ki=U(null);function qi(){let e=vn(),t=mt(),n=G(),r=Dn(),[i,a]=(0,Y.useState)(null),o=Ui(n,e,r,i),s=Gi(n,!o.native&&e&&r===null),c=o.native?o.bridge:r??s,[l,u]=(0,Y.useState)(!1),d=(0,Y.useRef)(!1),f=l||o.busy,p=async e=>{if(!(d.current||o.busy)){d.current=!0,u(!0);try{await e()}catch(e){q(e)}finally{d.current=!1,u(!1)}}},m=Te(n??void 0,void 0).data??[],h=Ie(n??void 0,e&&n!==null).data??[],g=qe(),_=Oe(),v=De(),[y,b]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=N()?.identity.kind;if(!e||e===`host`)return K(`layouts.toggle`,Cn)},[]),(0,Y.useEffect)(()=>{e||(b(``),S(!1),w(null),a(null))},[e]);let T=c?.headless===!0,E=c===null||T?null:m.find(e=>e.id===c.layoutRef&&(!c.native||e.scope===c.scope&&(e.scope===`profile`||e.project_id===c.projectId)))??null,D=c!==null&&!T&&(E===null?c.signature!==Ki:(c.savedSignature?.(E)??U(E.layout_tree))!==c.signature),ee=e=>{let t=c?.slices?.[e];if(!t)return!1;let n=t.layoutRef===null?null:m.find(e=>e.id===t.layoutRef)??null;return n?U(n.layout_tree)!==t.signature:t.signature!==Ki},te=e=>c===null?!1:c.native?!A(e)||!c.signature||c.savedSignature?.(e)!==c.signature:e.scope===`profile`?c.scope===`profile`&&D:e.project_id===null?!1:c.scope===`project`?!T&&e.project_id===c.projectId?D:ee(e.project_id):D||ee(e.project_id),ne=e=>E!==null&&e.id===E.id,re=e=>(e===null?void 0:h.find(t=>t.id===e)?.name)??`Project`,O=c!==null&&!T&&c.scope===`project`?m.filter(e=>e.scope===`profile`||e.project_id===c.projectId):m,k=[...O.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(O.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:re(e)})).sort((e,t)=>e.name.localeCompare(t.name))],ie=C===null?O:C===`profile`?O.filter(e=>e.scope===`profile`):O.filter(e=>e.project_id===C),A=e=>c!==null&&e.scope===c.scope&&(c.scope===`profile`||e.project_id===c.projectId),ae=async e=>{c?.adopt?await c.adopt(e):await c?.apply(e)},oe=async(e,t,r)=>{if(!c||!n)return;let i=await g.mutateAsync({profile_id:n,scope:c.scope,...c.scope===`project`?{project_id:c.projectId}:{},name:e,...t});r&&await ae(i)},se=e=>p(async()=>{if(!c)return;let t=A(e)?e:m.find(t=>t.name===e.name&&A(t)),n=await c.capture();t?await ae(await _.mutateAsync({id:t.id,...n})):await oe(e.name,n,!0)}),ce=(e,t)=>p(async()=>{await oe(t,{layout_tree:e.layout_tree,active_session:e.active_session,...A(e)&&e.window_arrangement?{window_arrangement:e.window_arrangement}:{}},!1)}),le=e=>p(async()=>{if(c){if(!await c.apply(e)){I.error(`Workspace is still loading — try again in a moment`);return}!c.native&&e.project_id!==null&&e.project_id!==c.projectId&&t(`/project/${e.project_id}`),_n(!1)}});return(0,X.jsxs)(or,{open:e,onOpenChange:_n,children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(ar,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(jr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,X.jsx)(R,{children:`Layouts`})]}),(0,X.jsxs)(ir,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),c!==null&&!T&&(0,X.jsxs)(`button`,{type:`button`,disabled:f,onClick:()=>S(e=>!e),className:F(`inline-flex size-[var(--ui-control-height)] shrink-0 cursor-pointer items-center justify-center rounded-[var(--ui-radius)] text-fg transition-colors hover:bg-elevated disabled:pointer-events-none disabled:opacity-50`,`ml-auto`),children:[(0,X.jsx)(rn,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),o.native&&(0,X.jsxs)(`div`,{className:`px-5 pb-3`,children:[(0,X.jsxs)(Rt,{value:c?.scope===`project`?c.projectId:`profile`,onValueChange:a,disabled:f,children:[(0,X.jsx)(Ft,{"aria-label":`Save layout for`,className:`h-8 text-sm`,children:(0,X.jsx)(Pt,{})}),(0,X.jsxs)(It,{children:[(0,X.jsx)(Lt,{value:`profile`,children:`Profile-wide`}),h.map(e=>(0,X.jsx)(Lt,{value:e.id,children:e.name},e.id))]})]}),o.error&&(0,X.jsx)(`p`,{role:`status`,className:`pt-2 text-sm text-fg-muted`,children:o.error})]}),(0,X.jsx)(nn,{expanded:c!==null&&!T&&(E===null||x),children:c===null?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):T?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Project-based layout is on — every project keeps its own layout. Open a project to name or save it; loading works from here.`}):(E===null||x)&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[E===null&&(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:c.scope===`profile`?`Profile-wide`:`Project`}),(0,X.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=y.trim();t&&p(async()=>{await oe(t,await c.capture(),!0),b(``),S(!1)})},children:[(0,X.jsx)(V,{autoFocus:x,value:y,placeholder:E===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>b(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&S(!1)},className:`h-8 flex-1 text-sm`}),(0,X.jsx)(B,{size:`sm`,type:`submit`,disabled:f||!y.trim(),children:`Save`}),E!==null&&(0,X.jsx)(B,{variant:`ghost`,size:`sm`,onClick:()=>S(!1),children:`Cancel`})]})]})}),k.length>1&&(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:k.map(e=>(0,X.jsx)(Xi,{active:C===e.key,onClick:()=>w(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,X.jsxs)(`div`,{inert:f||void 0,"aria-busy":f,className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[ie.length===0&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:C===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:ie.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(Ji,{layout:e,projectLabel:e.scope===`profile`?null:re(e.project_id),isCurrent:ne(e),dirty:D,loadable:c!==null&&!f,savable:c!==null&&!T&&!f,confirmBeforeLoad:te(e),overwrites:A(e),onLoad:()=>le(e),onRename:t=>_.mutate({id:e.id,name:t}),onDelete:()=>v.mutate(e.id),onSaveAs:()=>se(e),onDuplicate:t=>ce(e,t)})},e.id))})]})]})]})}function Ji({layout:e,projectLabel:t,isCurrent:n,dirty:r,loadable:i,savable:a,confirmBeforeLoad:o,overwrites:s,onLoad:c,onRename:l,onDelete:u,onSaveAs:d,onDuplicate:f}){let[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(e.name),y=()=>{if(!(!i||h!==null)){if(o&&p!==`load`){m(`load`);return}m(null),c()}},b=t=>{m(null),v(t===`rename`?e.name:`${e.name} copy`),g(t)},x=()=>{if(n){d();return}m(`save`)},S=n?r?`unsaved`:`active`:null;return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||y()},className:F(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[h===null?(0,X.jsxs)(`p`,{className:F(`flex items-baseline gap-2 text-sm font-medium`,S===`active`?`text-success`:S===`unsaved`?`text-interrupted`:`text-fg`),children:[e.name,S!==null&&(0,X.jsx)(`span`,{className:`text-2xs font-normal`,children:S===`active`?`Active`:`Unsaved`})]}):(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:t=>{t.preventDefault();let n=_.trim();n&&(h===`rename`?n!==e.name&&l(n):f(n)),g(null)},children:[(0,X.jsx)(V,{autoFocus:!0,value:_,spellCheck:!1,onChange:e=>v(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&g(null)},className:`h-7 flex-1 text-sm`}),(0,X.jsx)(B,{size:`sm`,type:`submit`,disabled:!_.trim(),children:h===`rename`?`Rename`:`Save`})]}),p===`save`?(0,X.jsx)(Yi,{question:s?`Overwrite “${e.name}” with the current layout?`:`Save the current layout as “${e.name}” here?`,verb:s?`Overwrite`:`Save`,onConfirm:()=>{m(null),d()},onCancel:()=>m(null)}):p===`delete`?(0,X.jsx)(Yi,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{m(null),u()},onCancel:()=>m(null)}):p===`load`?(0,X.jsx)(Yi,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:y,onCancel:()=>m(null)}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,X.jsxs)(Xn,{label:`Layout actions`,className:`ml-auto`,children:[a&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Zi,{icon:on,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:x}),(0,X.jsx)(Zi,{icon:$t,label:`Duplicate`,onClick:()=>b(`duplicate`)})]}),(0,X.jsx)(Zi,{icon:Ht,label:`Rename`,onClick:()=>b(`rename`)}),(0,X.jsx)(Zi,{icon:cn,label:`Delete`,onClick:()=>m(`delete`)})]})]})]})}function Yi({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,X.jsx)(`button`,{type:`button`,onClick:n,className:F(Mt,`text-danger`),children:t}),(0,X.jsx)(`button`,{type:`button`,onClick:r,className:Mt,children:`Cancel`})]})}function Xi({active:e,onClick:t,children:n}){return(0,X.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:F(`rounded-full px-2 py-0.5 text-2xs transition-colors`,e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:n})}function Zi({icon:e,label:t,onClick:n}){return(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:Nt,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(R,{children:t})]})}var $=M()!==void 0&&/Mac/.test(navigator.platform),Qi=(0,Y.lazy)(()=>be(()=>import(`./SettingsDialog-cl6-0q5x.js`).then(e=>({default:e.SettingsDialog})),__vite__mapDeps([16,1,2,3,17,18,19,20,6,21,5,7,8,9,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59])));function $i(){let e=tt();(0,Y.useEffect)(()=>{let t,n=new Map,r=()=>{t||=setTimeout(()=>{t=void 0,e.invalidateQueries({queryKey:[`project-catalogue`]},{cancelRefetch:!1})},250)},i=J.onStatus(t=>{Br(e,t),n.get(t.session)!==t.status&&(n.set(t.session,t.status),n.size>2048&&n.delete(n.keys().next().value),r())}),a=J.onRenamed(t=>Vr(e,t)),o=J.onAccount(t=>{for(let[n,r]of e.getQueriesData({queryKey:[`accounts`]}))r&&e.setQueryData(n,r.map(e=>e.id===t.account_id?{...e,logged_in:t.logged_in}:e))}),s=t=>{r(),e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},c=J.onSessionsChanged(e=>s(e.project_ids)),l=J.onSessionSwitched(e=>s([e.target_project]));return()=>{clearTimeout(t),i(),a(),o(),c(),l()}},[e])}function ea(){let e=G(),t=je(e??``),n=ze().data?.protocol,r=C(),i=Ge(),a=Me(),[s,c]=(0,Y.useState)(!1),l=Xe(i.data),u=e=>{c(!1);let t=e.trim();t!==l&&a.mutate({displayName:t===i.data?.hostname?``:t},{onError:e=>q(e)})},d=(0,X.jsx)(w,{icon:r.icon}),f=F(`host-identity flex h-full shrink-0 items-center gap-2 px-4`,$&&`[-webkit-app-region:no-drag]`),p=`truncate font-sans text-xs font-normal`;return s&&l!==void 0?(0,X.jsxs)(`div`,{className:f,children:[d,(0,X.jsx)(un,{initial:i.data?.displayName??l,maxLength:64,className:F(p,`w-40`),onCommit:u,onCancel:()=>c(!1)})]}):(0,X.jsxs)(zn,{children:[(0,X.jsx)(Fn,{asChild:!0,children:(0,X.jsxs)(bt,{to:`/`,className:F(f,`hover:bg-elevated focus-visible:bg-elevated`),title:`All projects`,children:[d,l!==void 0&&(0,X.jsx)(`span`,{className:p,...fn(()=>c(!0)),children:l})]})}),(0,X.jsx)(Ir,{kind:`host`,colour:r.colour,onRename:()=>c(!0),onColour:n=>{e&&t.mutate({hostColour:n},{onError:q})},pending:t.isPending||!e,custom:o(n),onUpdates:()=>W(`host`)})]})}function ta(){let e=_t(),t=Un(`palette.toggle`),n=Pe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,X.jsx)(`button`,{type:`button`,onClick:mn,className:F(`flex h-full min-w-0 w-full cursor-pointer items-center justify-center gap-2 bg-transparent px-2 font-normal text-fg-muted transition-colors hover:bg-elevated focus-visible:bg-elevated`,$&&`[-webkit-app-region:no-drag]`),children:(0,X.jsxs)(`span`,{className:F(`pointer-events-none absolute left-1/2 top-1/2 flex max-w-[40%] -translate-x-1/2 -translate-y-1/2 items-center gap-2`,r&&Ut(n?.colour)),style:r?Gt(n?.colour):void 0,children:[(0,X.jsx)(`span`,{className:`truncate text-xs`,children:r??`Puddle`}),(0,X.jsx)(`span`,{className:`shrink-0 text-2xs`,children:t})]})})}function na(){let e=C(),{fullScreen:t,animate:n}=Se(),r=$&&!t;return(0,X.jsxs)(`header`,{"data-host-colour":e.colour??void 0,onClick:e=>{let t=e.target;e.currentTarget.contains(t)&&(t.closest(`[data-header-section], [aria-label="Workspace controls"], button, a, input`)||mn())},className:F(`host-header island-outline relative grid shrink-0 cursor-pointer grid-cols-[auto_1px_minmax(0,1fr)_1px_auto] items-center overflow-hidden rounded-[var(--ui-surface-radius)] bg-surface`,`h-9`,!$&&`mx-1.5 mt-1.5`,r&&`pl-[84px] [-webkit-app-region:drag]`,n&&`transition-[padding] duration-200 ease-out`),children:[r&&(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-[84px] top-1/2 h-5 w-px -translate-y-1/2 bg-border`}),(0,X.jsx)(`div`,{"data-header-section":!0,className:`flex h-full min-w-0 cursor-default items-center overflow-hidden`,children:(0,X.jsx)(ea,{})}),(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`h-5 w-px bg-border`}),(0,X.jsx)(ta,{}),(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`h-5 w-px bg-border`}),(0,X.jsxs)(Xn,{label:`Workspace controls`,className:F(`shell-header-actions h-full justify-self-end rounded-none!`,r&&`cursor-default [-webkit-app-region:drag]`,$&&`[&>button]:[-webkit-app-region:no-drag] [&>.profile-trigger]:[-webkit-app-region:no-drag]`),children:[(0,X.jsxs)(z,{children:[(0,X.jsx)(L,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>W(),children:[(0,X.jsx)(Pr,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,X.jsx)(R,{children:`Settings`})]}),(0,X.jsx)(qi,{}),(0,X.jsx)(Pi,{}),(0,X.jsx)(ii,{})]})]})}function ra(){let e=En();$i(),_i(),ji();let{handler:t}=kn(),n=G(),{pathname:r}=xt(),[i,o]=(0,Y.useState)(!1),s=ze(),c=s.data!==void 0&&a(s.data.protocol);return(0,Y.useEffect)(()=>{if(!c)return;let e=()=>{let e=ge();J.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),ve(e)},[c]),(0,X.jsxs)(`div`,{ref:e.ref,"data-project-window-drop-target":e.enabled||void 0,className:`relative flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[e.active&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute inset-1.5 z-50 flex items-center justify-center rounded-[var(--ui-surface-radius)] bg-accent/20`,children:(0,X.jsx)(`span`,{role:`status`,className:`rounded-[var(--ui-radius)] bg-surface px-4 py-2 text-sm text-fg shadow-lg`,children:`Return project here`})}),(0,X.jsx)(T,{}),(0,X.jsx)(ue,{}),(0,X.jsx)(Lr,{}),(!N()||N()?.identity.kind===`host`)&&(0,X.jsx)(na,{}),(0,X.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,X.jsx)(pr,{resetOn:r,scope:r.startsWith(`/project/`)?`workspace`:`view`,children:(0,X.jsx)(Tt,{className:`h-full`,motionKey:r.startsWith(`/project/`)?`workspace`:r,children:(0,X.jsx)(gt,{})})})}),(0,X.jsx)(Rr,{}),(0,X.jsx)($r,{}),(0,X.jsx)(ci,{}),(0,X.jsx)(fi,{}),(0,X.jsx)(mi,{}),(0,X.jsx)(gi,{}),(0,X.jsx)(Jr,{onNewSession:t??void 0,onNewProject:()=>o(!0)}),n!==null&&(0,X.jsx)(en,{profileId:n,open:i,onOpenChange:o}),(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Qi,{})}),(0,X.jsx)(Zr,{})]})}function ia(){return(0,X.jsx)(gn,{children:(0,X.jsx)(ra,{})})}function aa({children:e}){let t=(0,Y.useContext)(Ct),n=xt(),r=G(),i=M()?.windows?.projects,a=N(),o=(0,Y.useRef)(null),[,s]=(0,Y.useState)(0),c=(0,Y.useRef)(0),l=`${r}:${n.pathname}`,u=a?.identity,d=u&&u.kind!==`host`&&(n.pathname===`/project/${u.projectId}`||n.pathname.startsWith(`/project/${u.projectId}/session/`));(a?.stagingTransfer||a?.stagingArrangement||d)&&(o.current=l);let f=(0,Y.useMemo)(()=>{if(!i||!r)return t;let e=e=>(...a)=>{let[s]=a,l=(typeof s==`string`?s:ht(s)).split(/[?#]/)[0]||n.pathname;if(!g.safeParse(l).success){t.navigator[e](...a);return}let u=++c.current;i.route({profileId:r,route:l}).then(n=>{u!==c.current||n||(o.current=`${r}:${l}`,t.navigator[e](...a))}).catch(q)};return{...t,navigator:{...t.navigator,push:e(`push`),replace:e(`replace`)}}},[i,r,t,n.pathname]);return(0,Y.useEffect)(()=>{if(!i||!r||o.current===l)return;let e=!0,t=()=>{let e=a?.identity,t=e&&e.kind!==`host`?`/project/${e.projectId}`:`/`;o.current=`${r}:${t}`,ur(t),s(e=>e+1)};return i.route({profileId:r,route:n.pathname}).then(n=>{e&&(n?t():(o.current=l,s(e=>e+1)))}).catch(n=>{e&&(q(n),t())}),()=>{e=!1}},[i,r,l,n.pathname,a]),i&&r&&o.current!==l?null:(0,X.jsx)(Ct.Provider,{value:f,children:e})}var oa=(0,Y.lazy)(()=>be(()=>import(`./Dashboard-CLdNA8WP.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([60,1,2,3,17,18,19,20,6,21,5,7,8,9,22,25,26,28,29,30,27,61,62,63,46,31,64,41,37,42,39,43,44,45,65,66,67,55,52,38]))),sa=(0,Y.lazy)(()=>be(()=>import(`./Workspace-DQDh6TQ7.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([68,1,2,3,17,18,19,20,6,21,5,7,8,9,22,30,29,25,26,27,69,28,70,39,41,37,42,43,44,45,61,63,62,34,35,71,46,31,64,65,66,72,53,54,33,73,74,75,38,76,77,49,78,51,79,36,52,80,81,82,83,58,84,85])));function ca(){let e=G(),t=ke(),n=N()?.identity,r=n!==void 0&&n.kind!==`host`,i=e!==null&&t.data!==void 0&&!r&&!t.data.some(t=>t.id===e),a=e===null||i;return(0,X.jsx)(Tt,{className:`h-screen`,motionKey:a?`profiles`:`frontend`,children:a?(0,X.jsx)(Fr,{}):(0,X.jsx)(vt,{useTransitions:!1,children:(0,X.jsx)(aa,{children:(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(yt,{children:(0,X.jsxs)(pt,{element:(0,X.jsx)(ia,{}),children:[(0,X.jsx)(pt,{path:`/`,element:(0,X.jsx)(oa,{})}),(0,X.jsx)(pt,{path:`/project/:id`,element:(0,X.jsx)(sa,{})}),(0,X.jsx)(pt,{path:`/project/:id/session/:sid`,element:(0,X.jsx)(sa,{})})]})})})})})})}function la(){let e=(0,Y.useSyncExternalStore)(de.subscribe,de.get);return(0,X.jsx)(Re,{client:P,children:(0,X.jsxs)(zt,{delayDuration:300,children:[(0,X.jsx)(kr,{}),(0,X.jsx)(pr,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,X.jsx)(fr,{}):(0,X.jsx)(Ce,{children:(0,X.jsx)(ca,{})}):(0,X.jsx)(hr,{})}),(0,X.jsx)(mr,{})]})})}export{la as App};