@puddle-code/cli 0.2.3 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +2 -13
  2. package/README.md +33 -23
  3. package/dist/host-control.mjs +40 -2
  4. package/dist/index.js +541 -313
  5. package/dist/install-cli.sh +167 -0
  6. package/dist/install.sh +7 -10
  7. package/dist/public/assets/{App-JZgRWo4t.js → App-CzuHShdO.js} +2 -2
  8. package/dist/public/assets/{Dashboard-DNWLZwxT.js → Dashboard-B5qWtmwb.js} +1 -1
  9. package/dist/public/assets/{EditorTabClose-CdpMpKYq.js → EditorTabClose-uxuNJdgx.js} +1 -1
  10. package/dist/public/assets/FindWidget-lUpiYZJG.js +1 -0
  11. package/dist/public/assets/{LazyTerminal-DVeI2Lkl.js → LazyTerminal-BYbPpGEI.js} +2 -2
  12. package/dist/public/assets/{ModelRefcount-ALfiNB9K.js → ModelRefcount-N0Xh_Y-_.js} +1 -1
  13. package/dist/public/assets/{NewProjectDialog-RHBHLIQe.js → NewProjectDialog-D3bNK3u_.js} +1 -1
  14. package/dist/public/assets/PaneEditorBody-DrSiMzrp.js +553 -0
  15. package/dist/public/assets/{PdfViewer-DZrh-S3Z.js → PdfViewer-BhqrWfmb.js} +2 -2
  16. package/dist/public/assets/{SettingsDialog-D-yMKqY9.js → SettingsDialog-CamnF91I.js} +2 -2
  17. package/dist/public/assets/Terminal-Ds17sCF_.js +60 -0
  18. package/dist/public/assets/Workspace-B6mgQyIM.css +1 -0
  19. package/dist/public/assets/{Workspace-DhFU_Ltc.js → Workspace-BmtA0kYQ.js} +6 -6
  20. package/dist/public/assets/{abnfDiagram-VCTEODGH-Bb_QGl6J.js → abnfDiagram-VCTEODGH-B4ZtDUXi.js} +1 -1
  21. package/dist/public/assets/architecture-7GRP2DOG-D0iH6Lxl.js +1 -0
  22. package/dist/public/assets/{architectureDiagram-5GKGNRK7-CF6YHpo7.js → architectureDiagram-5GKGNRK7-Cyzuyzwl.js} +1 -1
  23. package/dist/public/assets/{blockDiagram-I7D4REHJ-DgUouS8v.js → blockDiagram-I7D4REHJ-BN00JnNl.js} +1 -1
  24. package/dist/public/assets/{buffer-store-DcARHjQ8.js → buffer-store--4yU4YqM.js} +2 -2
  25. package/dist/public/assets/{button-CyO-gAMJ.js → button-DehrlYw7.js} +1 -1
  26. package/dist/public/assets/{c4Diagram-7LVT6UL2-CFhvq4-y.js → c4Diagram-7LVT6UL2-DpUKodBy.js} +1 -1
  27. package/dist/public/assets/channel-DT2izo70.js +1 -0
  28. package/dist/public/assets/{chunk-2E4U76K2-CskNiADZ.js → chunk-2E4U76K2-BksaqXZU.js} +1 -1
  29. package/dist/public/assets/{chunk-4HAMMTFA-DY74ei7y.js → chunk-4HAMMTFA-D01k6w0A.js} +1 -1
  30. package/dist/public/assets/{chunk-75Z2AOVW-sHPItT4L.js → chunk-75Z2AOVW-DJJjslyX.js} +1 -1
  31. package/dist/public/assets/{chunk-CLGD4ZFX-BbZdl00J.js → chunk-CLGD4ZFX-CX1B9i6H.js} +1 -1
  32. package/dist/public/assets/{chunk-DU6HZSFF-BZvHUJoN.js → chunk-DU6HZSFF-Bx2ELCn-.js} +1 -1
  33. package/dist/public/assets/{chunk-F27PBJKO-C-FJqBSD.js → chunk-F27PBJKO-CCDhODx8.js} +1 -1
  34. package/dist/public/assets/{chunk-GMAD6QVW-DPkzF1Ic.js → chunk-GMAD6QVW-C1evXXZi.js} +1 -1
  35. package/dist/public/assets/{chunk-GVQU2GXP-Batc2xZS.js → chunk-GVQU2GXP-C1iphgLK.js} +1 -1
  36. package/dist/public/assets/{chunk-IMKFNOWR-CAMx72vu.js → chunk-IMKFNOWR-5wMdkmsQ.js} +1 -1
  37. package/dist/public/assets/{chunk-L3NEJ4N5-CuIGdGy-.js → chunk-L3NEJ4N5-B-aXfMpF.js} +1 -1
  38. package/dist/public/assets/{chunk-OSK3NFVY-uNp8Mp7C.js → chunk-OSK3NFVY-Bm2MaFOc.js} +1 -1
  39. package/dist/public/assets/{chunk-P2QGCYS3-CoRPhFtM.js → chunk-P2QGCYS3-H02JaAun.js} +1 -1
  40. package/dist/public/assets/{chunk-POPQ4Y6H-DMOCBqAw.js → chunk-POPQ4Y6H-Dmm46Beg.js} +1 -1
  41. package/dist/public/assets/{chunk-PWAF6VOD-DOQkLdyp.js → chunk-PWAF6VOD-CRt8Ete5.js} +1 -1
  42. package/dist/public/assets/{chunk-SHT3W25Y-BJJe_uau.js → chunk-SHT3W25Y-w4aNK54y.js} +1 -1
  43. package/dist/public/assets/{chunk-SVP7TREG-D5B1jrjj.js → chunk-SVP7TREG-Cl3QpMDs.js} +1 -1
  44. package/dist/public/assets/{chunk-TICWLB2K-C9NafHGC.js → chunk-TICWLB2K-BpBbot9h.js} +1 -1
  45. package/dist/public/assets/{chunk-TLUHSLCS-Ctl_RxEM.js → chunk-TLUHSLCS-BOnIB6P6.js} +2 -2
  46. package/dist/public/assets/classDiagram-ZZMXUADV-BSshJUxJ.js +1 -0
  47. package/dist/public/assets/classDiagram-v2-VYDZK3BY-BSshJUxJ.js +1 -0
  48. package/dist/public/assets/{context-menu-BuiHQTu6.js → context-menu-BT88Vgia.js} +1 -1
  49. package/dist/public/assets/{cssMode-DozYXR6g.js → cssMode-gXT_K4po.js} +1 -1
  50. package/dist/public/assets/{cynefin-OW5HDTMX-gj0lEe4i.js → cynefin-OW5HDTMX-CJakxaH8.js} +1 -1
  51. package/dist/public/assets/{cynefinDiagram-5FMLGOSQ-lYCffbhY.js → cynefinDiagram-5FMLGOSQ-BJ_fVnC9.js} +1 -1
  52. package/dist/public/assets/{dagre-GXQ25YYZ-DyYVAAw7.js → dagre-GXQ25YYZ-CjflcbuS.js} +1 -1
  53. package/dist/public/assets/{diagram-S7CK7UJ4-Dop5OEsZ.js → diagram-S7CK7UJ4-g8pKIWrY.js} +1 -1
  54. package/dist/public/assets/{diagram-UQ7AKVKN-B5qxPK0m.js → diagram-UQ7AKVKN-Dm5Pg4rY.js} +1 -1
  55. package/dist/public/assets/{diagram-VSXAHHWV-zvsxaxBC.js → diagram-VSXAHHWV-DV5CVAXg.js} +1 -1
  56. package/dist/public/assets/{diagram-VX7I27RA-S7nRhoRV.js → diagram-VX7I27RA-Be9qCk-h.js} +1 -1
  57. package/dist/public/assets/{diagram-Z3DM3KII-C_jkP2wb.js → diagram-Z3DM3KII-C3-xDrxs.js} +1 -1
  58. package/dist/public/assets/{dialog-D6I1fiX4.js → dialog-CAMTxigV.js} +1 -1
  59. package/dist/public/assets/{disclosure-Dn2Pws0i.js → disclosure-DvM7-z38.js} +1 -1
  60. package/dist/public/assets/dist-3tmIo7Ja.js +1 -0
  61. package/dist/public/assets/{dist-Dt0LZb5E.js → dist-sLs_LTiG.js} +1 -1
  62. package/dist/public/assets/{ebnfDiagram-PWID7BFC-B1OmWQdM.js → ebnfDiagram-PWID7BFC-Bq92n7k-.js} +1 -1
  63. package/dist/public/assets/{erDiagram-RLTQ6QDP-DJKky3Wx.js → erDiagram-RLTQ6QDP-C5I2bKnS.js} +1 -1
  64. package/dist/public/assets/eventmodeling-NTZA5JFV-CWxfOZuS.js +1 -0
  65. package/dist/public/assets/flowDiagram-HODETNUW-ddOOBXlS.js +1 -0
  66. package/dist/public/assets/{ganttDiagram-EL5Y4UJY-qEYH72Jx.js → ganttDiagram-EL5Y4UJY-qUaBgbbK.js} +1 -1
  67. package/dist/public/assets/{gitGraph-4MIJSDKK-DlVqGPr_.js → gitGraph-4MIJSDKK-CUfoq3Sa.js} +1 -1
  68. package/dist/public/assets/{gitGraphDiagram-WWUBYQGX-DjfCMlWr.js → gitGraphDiagram-WWUBYQGX-kj34Cchu.js} +1 -1
  69. package/dist/public/assets/{hotkeys-Bx0QQoOi.js → hotkeys-DbIEec2f.js} +1 -1
  70. package/dist/public/assets/{htmlMode-DlKAkkNW.js → htmlMode-C_uC6TDH.js} +1 -1
  71. package/dist/public/assets/index-BLx1AR0-.js +82 -0
  72. package/dist/public/assets/index-uKreLbru.css +2 -0
  73. package/dist/public/assets/{info-A6RAGUB7-CH2cc1Sk.js → info-A6RAGUB7-C938EzS-.js} +1 -1
  74. package/dist/public/assets/{infoDiagram-27XIBGKW-QLQ5mJz6.js → infoDiagram-27XIBGKW-BoTxIjdn.js} +1 -1
  75. package/dist/public/assets/input-DXYRmAFr.js +1 -0
  76. package/dist/public/assets/{ishikawaDiagram-5VMMS53U-Dgd8STMm.js → ishikawaDiagram-5VMMS53U-j98L6THV.js} +1 -1
  77. package/dist/public/assets/{journeyDiagram-3NMN7TZE-BaIBwMwN.js → journeyDiagram-3NMN7TZE-DI-XCC2F.js} +1 -1
  78. package/dist/public/assets/{jsonMode-B-xhmxpv.js → jsonMode-BQ3590Ds.js} +1 -1
  79. package/dist/public/assets/{kanban-definition-UXKFOSKX-DUwkSFm5.js → kanban-definition-UXKFOSKX-BCTvFJTJ.js} +1 -1
  80. package/dist/public/assets/{line-DBd--km9.js → line-hE2Okp1W.js} +1 -1
  81. package/dist/public/assets/{media-refresh-store-C2PF6Nl9.js → media-refresh-store-CxqhHl8x.js} +1 -1
  82. package/dist/public/assets/{mermaid-parser.core-CH9r0Plq.js → mermaid-parser.core-n0Wb6T7Q.js} +3 -3
  83. package/dist/public/assets/{mermaid.core-Dx4uf1Og.js → mermaid.core-Cb0bw4D8.js} +3 -3
  84. package/dist/public/assets/{mindmap-definition-YA3MSWOX-DFlzr0Rk.js → mindmap-definition-YA3MSWOX-92LM1OuK.js} +1 -1
  85. package/dist/public/assets/{notification-permission-BJ5Ee1QS.js → notification-permission-CG2r3Oi8.js} +1 -1
  86. package/dist/public/assets/{packet-AYTQ26CC-BoGgl5A0.js → packet-AYTQ26CC-_HBkwHYp.js} +1 -1
  87. package/dist/public/assets/{pdf-CIIeLqAE.js → pdf-DABk-fGs.js} +1 -1
  88. package/dist/public/assets/{pegDiagram-XKGWAZYB-dBubzdqe.js → pegDiagram-XKGWAZYB-B-fG_WHS.js} +1 -1
  89. package/dist/public/assets/{pie-WAS4IAKB-C8Ujmmnq.js → pie-WAS4IAKB-ByxJto7v.js} +1 -1
  90. package/dist/public/assets/{pieDiagram-E7YTZNPT-BarO3dDM.js → pieDiagram-E7YTZNPT-Ci8ZSq4L.js} +1 -1
  91. package/dist/public/assets/{project-abbrev-BlBz9tcM.js → project-abbrev-BU2DBpdq.js} +1 -1
  92. package/dist/public/assets/{quadrantDiagram-AXDQQJYC-Bq7mziYZ.js → quadrantDiagram-AXDQQJYC-B97Yoxpb.js} +1 -1
  93. package/dist/public/assets/{radar-RG4KPBEZ-CSOiAaDJ.js → radar-RG4KPBEZ-BT2qdAqW.js} +1 -1
  94. package/dist/public/assets/{railroad-74A4TZTK-B72WpbJE.js → railroad-74A4TZTK-Buny6l3B.js} +1 -1
  95. package/dist/public/assets/railroad-abnf-HS5TGJTU-C_aUf3vj.js +1 -0
  96. package/dist/public/assets/railroad-ebnf-LZEXJU2U-BGUVD_Qq.js +1 -0
  97. package/dist/public/assets/railroad-peg-WCYAUIDC-CGdTjBGv.js +1 -0
  98. package/dist/public/assets/{railroadDiagram-O6MQD6OU-CdpFpJTq.js → railroadDiagram-O6MQD6OU-BktpI6J7.js} +1 -1
  99. package/dist/public/assets/{requirementDiagram-BXWQKSXE-D5gAf9X3.js → requirementDiagram-BXWQKSXE-DYy_YKmd.js} +1 -1
  100. package/dist/public/assets/{sankeyDiagram-P5KCCOFB-CWGxwWQO.js → sankeyDiagram-P5KCCOFB-BeKH_sFV.js} +1 -1
  101. package/dist/public/assets/{sequenceDiagram-WJ2MYXX4-D4OU6YFv.js → sequenceDiagram-WJ2MYXX4-DD8okFGM.js} +1 -1
  102. package/dist/public/assets/{stateDiagram-D77RDMKH-DL34KHS6.js → stateDiagram-D77RDMKH-Bfk3E3Oa.js} +1 -1
  103. package/dist/public/assets/stateDiagram-v2-MP3YSRHH-DCg8-XDy.js +1 -0
  104. package/dist/public/assets/{swimlanes-42K2YHIH-ClnyergN.js → swimlanes-42K2YHIH-OVNrzhfn.js} +1 -1
  105. package/dist/public/assets/swimlanesDiagram-VR7AAH4N-DAqvbP32.js +8 -0
  106. package/dist/public/assets/{switch-JLAneJz1.js → switch-CN9NW-du.js} +1 -1
  107. package/dist/public/assets/{timeline-definition-24CTP7MA-Bouu1PMd.js → timeline-definition-24CTP7MA-C78a8EdU.js} +1 -1
  108. package/dist/public/assets/{treeView-Q6P3EWNA-OLbwx3G_.js → treeView-Q6P3EWNA-Cl5tCoga.js} +1 -1
  109. package/dist/public/assets/{treemap-WGGIJYW6-BWtOLy1c.js → treemap-WGGIJYW6-4YVcjSz9.js} +1 -1
  110. package/dist/public/assets/{tsMode-BChcsbnx.js → tsMode-CmGZ7MCT.js} +1 -1
  111. package/dist/public/assets/{use-ui-state-xRIsbDTY.js → use-ui-state-CzR7YpWb.js} +1 -1
  112. package/dist/public/assets/{vennDiagram-4TSXK5OY-B7Iv-Yti.js → vennDiagram-4TSXK5OY-Lih9MwBs.js} +1 -1
  113. package/dist/public/assets/{wardley-WFR3VGLG-bREi8xGw.js → wardley-WFR3VGLG-CcU7I6bt.js} +1 -1
  114. package/dist/public/assets/{wardleyDiagram-VM6X3IG4-BCZ7iNOW.js → wardleyDiagram-VM6X3IG4-DxHrszj8.js} +1 -1
  115. package/dist/public/assets/{ws-BzWidrUz.js → ws-C-kvwpeD.js} +1 -1
  116. package/dist/public/assets/{xychartDiagram-S5SC5T6Z-eLBpE0yW.js → xychartDiagram-S5SC5T6Z-DpLvvdIG.js} +1 -1
  117. package/dist/public/index.html +2 -2
  118. package/dist/public/preview.html +18 -0
  119. package/package.json +1 -1
  120. package/dist/public/assets/PaneEditorBody-BnTDt5LG.js +0 -553
  121. package/dist/public/assets/Terminal-CoQpOpFQ.js +0 -60
  122. package/dist/public/assets/Workspace-klU-NMuZ.css +0 -1
  123. package/dist/public/assets/architecture-7GRP2DOG-DR2uP7PV.js +0 -1
  124. package/dist/public/assets/channel-CUVxklBM.js +0 -1
  125. package/dist/public/assets/classDiagram-ZZMXUADV-Cgl1n0Dz.js +0 -1
  126. package/dist/public/assets/classDiagram-v2-VYDZK3BY-Cgl1n0Dz.js +0 -1
  127. package/dist/public/assets/dist-tn5vjhJE.js +0 -1
  128. package/dist/public/assets/eventmodeling-NTZA5JFV-mkLPvEKM.js +0 -1
  129. package/dist/public/assets/flowDiagram-HODETNUW-O3VTLiVc.js +0 -1
  130. package/dist/public/assets/index-Ctw2P0rY.css +0 -2
  131. package/dist/public/assets/index-DWTNflld.js +0 -82
  132. package/dist/public/assets/input-CWrHR6Ba.js +0 -1
  133. package/dist/public/assets/railroad-abnf-HS5TGJTU-6aqbSR4_.js +0 -1
  134. package/dist/public/assets/railroad-ebnf-LZEXJU2U-DSe-edrj.js +0 -1
  135. package/dist/public/assets/railroad-peg-WCYAUIDC-CxQjyuGw.js +0 -1
  136. package/dist/public/assets/stateDiagram-v2-MP3YSRHH-C86Q0rld.js +0 -1
  137. package/dist/public/assets/swimlanesDiagram-VR7AAH4N-TVdovaZm.js +0 -8
  138. package/dist/public/assets/use-find-controls-DEA0SpBh.js +0 -1
@@ -0,0 +1,167 @@
1
+ #!/bin/sh
2
+ # Standalone CLI installer, published as install.sh. Daemon bootstrap stays embedded.
3
+ # Release/app builds bake @@REPO@@; source runs accept --repo or PUDDLE_REPO.
4
+ # Keep old releases: running cockpits still serve assets from their own tree.
5
+ set -eu
6
+
7
+ say() { printf 'puddle install: %s\n' "$1"; }
8
+ die() { printf 'puddle install: error: %s\n' "$1" >&2; exit 1; }
9
+ usage() {
10
+ cat <<'EOF'
11
+ usage: install.sh [--version X.Y.Z] [--repo owner/repo]
12
+ [--prefix <directory>] [--bin-dir <directory>]
13
+ [--tarball <path>] [--sums <path>]
14
+
15
+ Installs the CLI with its own Node runtime; no npm or sudo required.
16
+ --version release to install (default: latest); also accepts vX.Y.Z
17
+ --prefix installation root (default: ~/.local/share/puddle/cli,
18
+ respecting XDG_DATA_HOME or PUDDLE_CLI_HOME)
19
+ --bin-dir launcher directory (default: ~/.local/bin)
20
+ --tarball local archive for offline/development installation
21
+ --sums SHA256SUMS for a local archive (otherwise warns and skips)
22
+ --repo GitHub release repository (or PUDDLE_REPO)
23
+ EOF
24
+ }
25
+
26
+ main() {
27
+ REPO="${PUDDLE_REPO:-@@REPO@@}"
28
+ VERSION=""
29
+ PREFIX="${PUDDLE_CLI_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/puddle/cli}"
30
+ BIN_DIR="$HOME/.local/bin"
31
+ TARBALL=""
32
+ SUMS=""
33
+ while [ $# -gt 0 ]; do
34
+ case "$1" in
35
+ --version|--repo|--prefix|--bin-dir|--tarball|--sums)
36
+ [ $# -ge 2 ] && [ -n "$2" ] || die "$1 requires a value"
37
+ case "$1" in
38
+ --version) VERSION=${2#v} ;; --repo) REPO=$2 ;;
39
+ --prefix) PREFIX=$2 ;; --bin-dir) BIN_DIR=$2 ;;
40
+ --tarball) TARBALL=$2 ;; --sums) SUMS=$2 ;;
41
+ esac
42
+ shift 2 ;;
43
+ -h|--help) usage; return ;;
44
+ *) die "unknown flag $1 (see --help)" ;;
45
+ esac
46
+ done
47
+ OS=$(uname -s)
48
+ case "$OS" in Linux) OS=linux ;; Darwin) OS=darwin ;; *) die "unsupported OS $OS" ;; esac
49
+ ARCH=$(uname -m)
50
+ case "$ARCH" in x86_64|amd64) ARCH=x64 ;; aarch64|arm64) ARCH=arm64 ;; *) die "unsupported architecture $ARCH" ;; esac
51
+ if [ "$OS" = linux ] && [ -f /etc/alpine-release ]; then
52
+ die "the bundled Node runtime requires glibc; Alpine is not supported"
53
+ fi
54
+ case "$PREFIX" in /*) ;; *) die "--prefix must be an absolute path" ;; esac
55
+ case "$BIN_DIR" in /*) ;; *) die "--bin-dir must be an absolute path" ;; esac
56
+ while [ "$PREFIX" != / ] && [ "${PREFIX%/}" != "$PREFIX" ]; do PREFIX=${PREFIX%/}; done
57
+ [ ! -L "$PREFIX" ] || die "installation root must not be a symlink"
58
+ umask 077
59
+ mkdir -p "$PREFIX"
60
+ PREFIX=$(CDPATH= cd -- "$PREFIX" && pwd -P)
61
+ case "$OS" in
62
+ darwin) OWNER=$(stat -f '%u' "$PREFIX"); MODE=$(stat -f '%Lp' "$PREFIX") ;;
63
+ linux) OWNER=$(stat -c '%u' "$PREFIX"); MODE=$(stat -c '%a' "$PREFIX") ;;
64
+ esac
65
+ [ "$OWNER" = "$(id -u)" ] && [ "$((0$MODE & 0022))" -eq 0 ] || die "installation root must be owned by you and not writable by others"
66
+ if [ -e "$PREFIX/INSTALLATION" ]; then
67
+ [ ! -L "$PREFIX/INSTALLATION" ] && [ "$(cat "$PREFIX/INSTALLATION")" = puddle-cli ] || die "unrecognised installation root"
68
+ else
69
+ [ -z "$(ls -A "$PREFIX")" ] || die "refusing a non-empty unmanaged installation root"
70
+ printf 'puddle-cli\n' > "$PREFIX/INSTALLATION"
71
+ fi
72
+ chmod 700 "$PREFIX"
73
+ mkdir "$PREFIX/.install-lock" 2>/dev/null || die "another installer is running (if interrupted, remove $PREFIX/.install-lock and retry)"
74
+ WORK=""
75
+ STAGE=""
76
+ trap 'test -z "$WORK" || rm -rf "$WORK"; if [ -n "$STAGE" ] && [ "$(readlink "$PREFIX/current" 2>/dev/null || true)" != "versions/$(basename "$STAGE")" ]; then rm -rf "$STAGE"; fi; rmdir "$PREFIX/.install-lock"' 0
77
+ trap 'exit 1' 1 2 3 15
78
+ [ ! -L "$PREFIX/versions" ] || die "versions must not be a symlink"
79
+ mkdir -p "$PREFIX/versions" "$BIN_DIR"
80
+ BIN_DIR=$(CDPATH= cd -- "$BIN_DIR" && pwd -P)
81
+ WORK=$(mktemp -d "$PREFIX/.download.XXXXXX")
82
+
83
+ if [ -n "$TARBALL" ]; then
84
+ [ -f "$TARBALL" ] || die "tarball not found: $TARBALL"
85
+ TARBALL="$(CDPATH= cd -- "$(dirname -- "$TARBALL")" && pwd)/$(basename -- "$TARBALL")"
86
+ if [ -z "$VERSION" ]; then
87
+ VERSION=$(basename "$TARBALL" | sed -n "s/^puddle-cli-v\(.*\)-$OS-$ARCH.tar.gz\$/\1/p")
88
+ fi
89
+ else
90
+ case "$REPO" in *@@*|'') die "no repository baked in; pass --repo owner/repo" ;; esac
91
+ command -v curl >/dev/null 2>&1 || die "curl is required"
92
+ if [ -z "$VERSION" ]; then
93
+ LATEST=$(curl -fsSLI -o /dev/null -w '%{url_effective}' "https://github.com/$REPO/releases/latest") || die "cannot resolve latest release"
94
+ VERSION=$(printf '%s' "$LATEST" | sed -n 's#.*/tag/v\{0,1\}##p')
95
+ fi
96
+ fi
97
+ # Version strings become paths; accept release semver, including prereleases.
98
+ printf '%s\n' "$VERSION" | LC_ALL=C grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([+-][A-Za-z0-9.-]+)?$' || die "invalid release version: $VERSION"
99
+ FILE="puddle-cli-v$VERSION-$OS-$ARCH.tar.gz"
100
+ if [ -z "$TARBALL" ]; then
101
+ BASE="https://github.com/$REPO/releases/download/v$VERSION"
102
+ TARBALL="$WORK/$FILE"
103
+ SUMS="$WORK/SHA256SUMS"
104
+ say "fetching $BASE/$FILE"
105
+ curl -fSL --progress-bar -o "$TARBALL" "$BASE/$FILE" || die "download failed (this platform/version may not be published)"
106
+ curl -fsSL -o "$SUMS" "$BASE/SHA256SUMS" || die "checksums download failed"
107
+ fi
108
+ if [ -n "$SUMS" ]; then
109
+ [ -f "$SUMS" ] || die "checksums file not found: $SUMS"
110
+ EXPECTED=$(awk -v name="$(basename "$TARBALL")" '$2 == name {print $1}' "$SUMS")
111
+ [ "${#EXPECTED}" -eq 64 ] || die "missing or ambiguous checksum"
112
+ if command -v sha256sum >/dev/null 2>&1; then ACTUAL=$(sha256sum "$TARBALL" | cut -d ' ' -f 1)
113
+ elif command -v shasum >/dev/null 2>&1; then ACTUAL=$(shasum -a 256 "$TARBALL" | cut -d ' ' -f 1)
114
+ else die "sha256sum or shasum is required"
115
+ fi
116
+ [ "$EXPECTED" = "$ACTUAL" ] || die "checksum mismatch"
117
+ else
118
+ say "warning: --tarball without --sums — checksum verification skipped"
119
+ fi
120
+ STAGE=$(mktemp -d "$PREFIX/versions/$VERSION.XXXXXX")
121
+ tar -xzf "$TARBALL" --strip-components=1 -C "$STAGE" || die "extraction failed"
122
+ [ "$(cat "$STAGE/STANDALONE")" = puddle-cli ] && [ "$(cat "$STAGE/VERSION")" = "$VERSION" ] || die "archive metadata mismatch"
123
+ for ASSET in cli/index.js cli/host-control.mjs cli/public/index.html cli/install.sh cli/install-cli.sh; do
124
+ [ -f "$STAGE/$ASSET" ] || die "archive is missing $ASSET"
125
+ done
126
+ # Help loads the bundle without touching a daemon or user state.
127
+ "$STAGE/puddle" --help >/dev/null || die "CLI smoke test failed"
128
+ "$STAGE/bin/node" --input-type=commonjs - "$PREFIX" "$BIN_DIR" "$STAGE" <<'NODE'
129
+ const fs = require('node:fs'), path = require('node:path');
130
+ const [root, binDir, stage] = process.argv.slice(2);
131
+ const launcher = path.join(binDir, 'puddle');
132
+ const quote = (s) => "'" + s.replaceAll("'", "'\\''") + "'";
133
+ const wrapper = '#!/bin/sh\n# puddle standalone launcher\nexec ' + quote(path.join(root, 'current/puddle')) + ' "$@"\n';
134
+ const stat = (p) => { try { return fs.lstatSync(p); } catch (e) { if (e.code === 'ENOENT') return null; throw e; } };
135
+ if (stat(launcher) && (!stat(launcher).isFile() || fs.readFileSync(launcher, 'utf8') !== wrapper)) {
136
+ throw Error('Refusing to replace an unrelated launcher: ' + launcher + '; choose --bin-dir');
137
+ }
138
+ const current = path.join(root, 'current');
139
+ if (stat(current) && !stat(current).isSymbolicLink()) throw Error('current must be a symlink');
140
+ const record = path.join(root, 'installation.json');
141
+ if (stat(record)) {
142
+ const old = JSON.parse(fs.readFileSync(record, 'utf8'));
143
+ if (old.launcher !== launcher) throw Error('Reuse the original --bin-dir: ' + path.dirname(old.launcher));
144
+ }
145
+ const tmp = '.new-' + process.pid;
146
+ try {
147
+ fs.writeFileSync(record + tmp, JSON.stringify({ kind: 'puddle-cli', launcher }) + '\n', { flag: 'wx', mode: 0o600 });
148
+ fs.writeFileSync(launcher + tmp, wrapper, { flag: 'wx', mode: 0o755 });
149
+ fs.symlinkSync(path.relative(root, stage), current + tmp);
150
+ fs.renameSync(record + tmp, record);
151
+ fs.renameSync(launcher + tmp, launcher);
152
+ fs.renameSync(current + tmp, current); // Activate only after every other write succeeds.
153
+ } finally {
154
+ for (const file of [record + tmp, launcher + tmp, current + tmp]) fs.rmSync(file, { force: true });
155
+ }
156
+ NODE
157
+ STAGE="" # Published releases stay intact, including those serving live cockpits.
158
+ say "installed CLI $VERSION at $BIN_DIR/puddle"
159
+ case ":$PATH:" in *":$BIN_DIR:"*) ;; *) say "add $BIN_DIR to PATH (for example in your shell profile)" ;; esac
160
+ RESOLVED=$(command -v puddle || true)
161
+ if [ -n "$RESOLVED" ] && [ "$RESOLVED" != "$BIN_DIR/puddle" ]; then
162
+ say "warning: $RESOLVED precedes this installation on PATH; use $BIN_DIR/puddle or update PATH"
163
+ fi
164
+ }
165
+
166
+ # Read the complete script before doing work when invoked through curl | sh.
167
+ main "$@"
package/dist/install.sh CHANGED
@@ -1,19 +1,16 @@
1
1
  #!/bin/sh
2
- # puddled installer — the single bootstrap implementation (SPEC §10).
2
+ # Internal puddled bootstrap — embedded in the CLI and desktop (SPEC §10).
3
3
  #
4
- # Runs three ways, always with the same steps:
5
- # 1. curl-piped: curl -fsSL .../install.sh | sh -s -- --version 0.1.0
6
- # 2. by the puddle CLI over SSH (the CLI embeds this exact script and pipes
7
- # it through the master connection: ssh host 'sh -s -- ...')
8
- # 3. by hand, for daemon-only installs without the CLI.
4
+ # The launcher pipes this exact script locally or through its SSH master
5
+ # connection. It fetches daemon archives from GitHub Releases, including on
6
+ # first connection to a new host. It is not a public installer asset; public
7
+ # install.sh comes from scripts/install-cli.sh and installs the CLI only.
9
8
  #
10
9
  # Everything lands under ~/.puddle — never sudo. Idempotent: upgrade and
11
10
  # rollback are the same script with a different --version.
12
11
  #
13
- # The committed template carries @@REPO@@; the release workflow substitutes
14
- # the publishing repository before attaching this file to the release, so no
15
- # owner slug lives in the repo (CLAUDE.md conventions). Running the template
16
- # directly requires --repo or PUDDLE_REPO=owner/repo.
12
+ # The launcher supplies --repo from its baked-in release repository; no owner
13
+ # slug lives in this template (CLAUDE.md conventions).
17
14
  set -eu
18
15
 
19
16
  REPO="${PUDDLE_REPO:-@@REPO@@}"
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsDialog-D-yMKqY9.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/index-DWTNflld.js","assets/index-Ctw2P0rY.css","assets/dist-tn5vjhJE.js","assets/hotkeys-Bx0QQoOi.js","assets/dialog-D6I1fiX4.js","assets/button-CyO-gAMJ.js","assets/x-CZCUod6A.js","assets/createLucideIcon-DyMAgLa3.js","assets/LazyTerminal-DVeI2Lkl.js","assets/switch-JLAneJz1.js","assets/notification-permission-BJ5Ee1QS.js","assets/disclosure-Dn2Pws0i.js","assets/chevron-down--sjpQEHH.js","assets/dist-Dt0LZb5E.js","assets/use-debounced-value-C86N-mOK.js","assets/Dashboard-DNWLZwxT.js","assets/project-abbrev-BlBz9tcM.js","assets/context-menu-BuiHQTu6.js","assets/NewProjectDialog-RHBHLIQe.js","assets/ws-BzWidrUz.js","assets/Workspace-DhFU_Ltc.js","assets/media-refresh-store-C2PF6Nl9.js","assets/use-ui-state-xRIsbDTY.js","assets/preview-kind-QJSMKfUN.js","assets/debounce-B9DrqirV.js","assets/input-CWrHR6Ba.js","assets/protocol-support-C1NCVjbV.js","assets/drafts-B_tChlzR.js","assets/buffer-logic-BAkSBQT7.js","assets/Workspace-klU-NMuZ.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{E as n,T as r,V as i,W as a,a as o,c as s,et as c,g as l,h as u,i as d,j as f,m as p,n as m,r as h,s as g,t as _,y as v}from"./index-DWTNflld.js";import{i as y,n as b,t as x}from"./dist-tn5vjhJE.js";import{$ as S,Bt as C,D as w,E as T,Et as E,Ft as D,Ht as O,I as k,It as A,J as j,Lt as M,M as ee,Mt as N,N as te,Nt as ne,Ot as re,Pt as ie,Q as ae,R as oe,Rt as P,S as se,T as ce,Tt as le,U as ue,Ut as de,V as fe,Vt as pe,Y as me,_ as he,at as ge,b as _e,ct as ve,d as ye,et as be,g as xe,h as Se,i as Ce,it as we,jt as Te,l as Ee,m as De,mt as Oe,o as ke,ot as Ae,p as je,q as Me,r as Ne,s as Pe,st as Fe,tt as Ie,u as Le,v as F,vt as Re,w as ze,wt as Be,x as Ve,y as He,zt as Ue}from"./hotkeys-Bx0QQoOi.js";import{a as We,c as Ge,d as Ke,f as qe,i as Je,l as Ye,m as Xe,p as Ze,s as Qe,u as $e}from"./project-abbrev-BlBz9tcM.js";import{S as I,c as et,l as tt,n as nt,s as rt,t as it,u as at,v as L}from"./dialog-D6I1fiX4.js";import{i as ot,t as R}from"./button-CyO-gAMJ.js";import{a as z,c as st,f as ct,l as B,m as lt,o as ut,u as dt}from"./LazyTerminal-DVeI2Lkl.js";import{a as ft,c as pt,d as mt,f as ht,l as gt,t as _t,u as vt}from"./switch-JLAneJz1.js";import{$ as yt,G as bt,H as xt,J as St,K as Ct,Q as wt,U as Tt,W as Et,X as Dt,Y as Ot,at as kt,d as At,et as jt,f as Mt,h as V,i as Nt,it as H,m as Pt,nt as Ft,ot as U,p as It,q as Lt,r as Rt,rt as W,t as zt,tt as Bt}from"./use-ui-state-xRIsbDTY.js";import{n as G}from"./x-CZCUod6A.js";import{t as K}from"./createLucideIcon-DyMAgLa3.js";import{_ as Vt,c as Ht,d as Ut,f as Wt,h as Gt,i as Kt,l as qt,n as Jt,o as Yt,p as Xt,r as Zt,s as Qt,t as $t,u as en,v as tn}from"./notification-permission-BJ5Ee1QS.js";import{t as nn}from"./copy-CGsu8426.js";import{t as rn}from"./NewProjectDialog-RHBHLIQe.js";import{a as an}from"./protocol-support-C1NCVjbV.js";import{t as q}from"./ws-BzWidrUz.js";var J=e(t(),1),Y=m();function on(){let[e,t]=(0,J.useState)(`Opening forwarded application…`);return(0,J.useEffect)(()=>{let e=/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname);if(!e){t(`This forwarding link is invalid.`);return}let r=!0;return y(`POST`,`/cockpit/proxy-grant`,{session:e[1],port:Number(e[2]),path:new URLSearchParams(window.location.search).get(`path`)??`/`}).then(e=>{r&&window.location.replace(n.parse(e).url)}).catch(()=>{r&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{r=!1}},[]),(0,Y.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var sn=class extends de{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new E({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t);if(n)if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}else return!0}runNext(e){let t=cn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){N.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>A(t,e))}findAll(e={}){return this.getAll().filter(t=>A(e,t))}notify(e){N.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return N.batch(()=>Promise.all(e.map(e=>e.continue().catch(P))))}};function cn(e){return e.options.scope?.id}var ln=class extends de{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??D(r,t),a=this.get(i);return a||(a=new re({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){N.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>M(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>M(e,t)):t}notify(e){N.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){N.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){N.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},un=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new ln,this.#t=e.mutationCache||new sn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=O.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Te.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(C(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=ne(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return N.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;N.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return N.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=N.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(P).catch(P)}invalidateQueries(e,t={}){return N.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=N.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(P)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(P)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(C(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(P).catch(P)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(P).catch(P)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Te.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(ie(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ue(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(ie(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ue(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=D(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===pe&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},dn=class extends J.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,Y.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,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,Y.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Y.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,Y.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function fn(){return(0,Y.jsx)(x,{theme:(0,J.useSyncExternalStore)(g,o),position:`bottom-right`,toastOptions:{style:{background:`var(--bg-elevated)`,border:`none`,boxShadow:`0 8px 30px rgb(0 0 0 / 0.25)`,color:`var(--text-primary)`},classNames:{description:`whitespace-pre-wrap break-words font-mono text-2xs leading-snug max-h-40 overflow-y-auto`}}})}function pn(){return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,Y.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,Y.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,Y.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var mn=e(c(),1),hn=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,gn=`.monaco-editor`;function _n(e,t){return e?.closest(gn)&&!e.closest(t)?`text`:e?.closest(hn)?`interactive`:`default`}function vn(e,t=`.no-custom-caret`){(0,J.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=()=>{n.style.opacity=`0`},a=e=>{if(e.pointerType===`touch`||!r.matches){i();return}n.style.transform=`translate3d(${e.clientX}px, ${e.clientY}px, 0) translate(-50%, -50%)`;let a=e.target instanceof Element?e.target:null;if(a instanceof HTMLIFrameElement){i();return}n.style.opacity=`1`;let o=a?.closest(gn),s=_n(a,t),c=s===`text`,l=s===`interactive`,u=c;if(c&&o){let e=getComputedStyle(o);n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`)}else if(!l&&a&&!a.closest(t)&&Array.from(a.childNodes).some(e=>e.nodeType===Node.TEXT_NODE&&e.textContent?.trim())){let e=getComputedStyle(a);e.userSelect!==`none`&&(u=!0,n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`))}n.classList.toggle(`is-interactive`,l),n.classList.toggle(`is-text`,u)};return window.addEventListener(`pointermove`,a,{passive:!0}),document.documentElement.addEventListener(`pointerleave`,i),window.addEventListener(`blur`,i),()=>{window.removeEventListener(`pointermove`,a),document.documentElement.removeEventListener(`pointerleave`,i),window.removeEventListener(`blur`,i)}},[t,e])}var yn=[`top`,`right`,`bottom`,`left`];function bn(){let e=(0,J.useRef)(null);return vn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:yn.map(e=>(0,Y.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function xn(){let e=(0,J.useRef)(null);return vn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var Sn=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Cn=40.5,X=4.05,wn=X*Math.sqrt(3)/2;function Tn(){let e=[],t=[],n=Cn/2,r=Math.ceil(n/wn)+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*wn,s=o+wn,c=(i%2+2)%2*(X/2);for(let i=-r;i<r;i+=1){let r=n+i*X+c,l=[[r+X/2,o],[r,s],[r+X,s]],u=[[r+X/2,o],[r+3*X/2,o],[r+X,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Cn&&Math.max(...n)>0&&Math.min(...n)<Cn};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var En=Tn();function Dn(){let e=(0,J.useRef)(null);return vn(e,Sn),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,Y.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Cn} ${Cn}`,focusable:`false`,children:[(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:En.light}),(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:En.dark})]})})}function On(){let{cursorPackage:e}=l(),t=null;switch(e){case`rangefinder`:t=(0,Y.jsx)(Dn,{});break;case`drafting`:t=(0,Y.jsx)(bn,{});break;case`invert`:t=(0,Y.jsx)(xn,{});break;case`system`:return null}return(0,mn.createPortal)(t,document.body)}var kn=K(`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`}]]),An=K(`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`}]]),jn=K(`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`}]]),Mn=K(`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`}]]),Nn=K(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),Pn=K(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),Fn=K(`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 In(){let e=Ae(),t=te(),[n,r]=(0,J.useState)(``),[i,o]=(0,J.useState)(a),s=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:i.trim()},{onSuccess:e=>he(e.id)})},c=(e.data?.length??0)>0;return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),c&&(0,Y.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>he(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,Y.jsx)(Wt,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,Y.jsx)(`span`,{className:G(`text-base`,Xt(e.icon_colour)||`text-fg`),children:e.name}),e.branch_prefix&&(0,Y.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,Y.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),s()},children:[c&&(0,Y.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(st,{htmlFor:`profile-name`,children:`Name`}),(0,Y.jsx)(B,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>r(e.target.value),className:`h-10`,autoFocus:!c})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(st,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,Y.jsx)(B,{id:`branch-prefix`,placeholder:`no prefix`,value:i,onChange:e=>o(e.target.value),className:`h-10`})]}),t.error&&(0,Y.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,Y.jsx)(R,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}var Ln=1,Rn=.9,zn=.8,Bn=.17,Vn=.1,Hn=.999,Un=.9999,Wn=.99,Gn=/[\\\/_+.#"@\[\(\{&]/,Kn=/[\\\/_+.#"@\[\(\{&]/g,qn=/[\s-]/,Jn=/[\s-]/g;function Yn(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Ln:Wn;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=Yn(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Ln:Gn.test(e.charAt(l-1))?(d*=zn,p=e.slice(i,l-1).match(Kn),p&&i>0&&(d*=Hn**+p.length)):qn.test(e.charAt(l-1))?(d*=Rn,m=e.slice(i,l-1).match(Jn),m&&i>0&&(d*=Hn**+m.length)):(d*=Bn,i>0&&(d*=Hn**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Un)),(d<Vn&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=Yn(e,t,n,r,l+1,a+2,o),f*Vn>d&&(d=f*Vn)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function Xn(e){return e.toLowerCase().replace(Jn,` `)}function Zn(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,Yn(e,t,Xn(e),Xn(t),0,0,{})}var Qn=`[cmdk-group=""]`,$n=`[cmdk-group-items=""]`,er=`[cmdk-group-heading=""]`,tr=`[cmdk-item=""]`,nr=`${tr}:not([aria-disabled="true"])`,rr=`cmdk-item-select`,ir=`data-value`,ar=(e,t,n)=>Zn(e,t,n),or=J.createContext(void 0),sr=()=>J.useContext(or),cr=J.createContext(void 0),lr=()=>J.useContext(cr),ur=J.createContext(void 0),dr=J.forwardRef((e,t)=>{let n=Q(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=Q(()=>new Set),i=Q(()=>new Map),a=Q(()=>new Map),o=Q(()=>new Set),s=Cr(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=L(),y=L(),b=L(),x=J.useRef(null),S=Tr();Z(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),Z(()=>{S(6,k)},[]);let C=J.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)O(),E(),S(1,D);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(b);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(S(7,()=>{n.current.selectedItemId=A()?.id,C.emit()}),r||S(5,k),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),w=J.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,T(t,r)),S(2,()=>{E(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),S(3,()=>{O(),E(),n.current.value||D(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=A();S(4,()=>{O(),t?.getAttribute(`id`)===e&&D(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:b,labelId:y,listInnerRef:x}),[]);function T(e,t){let r=s.current?.filter??ar;return e?r(e,n.current.search,t):0}function E(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=x.current;j().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest($n);t?t.appendChild(e.parentElement===t?e:e.closest(`${$n} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${$n} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${Qn}[${ir}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(ir);C.setState(`value`,e||void 0)}function O(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=T(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function k(){var e;let t=A();t&&(t.parentElement?.firstChild===t&&((e=t.closest(Qn)?.querySelector(er))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${tr}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(nr)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(ir))}function ee(e){var t;let n=A(),r=j(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&C.setState(`value`,a.getAttribute(ir))}function N(e){let t=A()?.closest(Qn),n;for(;t&&!n;)t=e>0?xr(t,Qn):Sr(t,Qn),n=t?.querySelector(nr);n?C.setState(`value`,n.getAttribute(ir)):ee(e)}let te=()=>M(j().length-1),ne=e=>{e.preventDefault(),e.metaKey?te():e.altKey?N(1):ee(1)},re=e=>{e.preventDefault(),e.metaKey?M(0):e.altKey?N(-1):ee(-1)};return J.createElement(I.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&ne(e);break;case`ArrowDown`:ne(e);break;case`p`:case`k`:g&&e.ctrlKey&&re(e);break;case`ArrowUp`:re(e);break;case`Home`:e.preventDefault(),M(0);break;case`End`:e.preventDefault(),te();break;case`Enter`:{e.preventDefault();let t=A();if(t){let e=new Event(rr);t.dispatchEvent(e)}}}}},J.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:Or},c),Dr(e,e=>J.createElement(cr.Provider,{value:C},J.createElement(or.Provider,{value:w},e))))}),fr=J.forwardRef((e,t)=>{let n=L(),r=J.useRef(null),i=J.useContext(ur),a=sr(),o=Cr(e),s=o.current?.forceMount??i?.forceMount;Z(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=wr(n,r,[e.value,e.children,r],e.keywords),l=lr(),u=$(e=>e.value&&e.value===c.current),d=$(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);J.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(rr,f),()=>t.removeEventListener(rr,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:v,...y}=e;return J.createElement(I.div,{ref:ot(r,t),...y,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),pr=J.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=L(),s=J.useRef(null),c=J.useRef(null),l=L(),u=sr(),d=$(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));Z(()=>u.group(o),[]),wr(o,s,[e.value,e.heading,c]);let f=J.useMemo(()=>({id:o,forceMount:i}),[i]);return J.createElement(I.div,{ref:ot(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&J.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),Dr(e,e=>J.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},J.createElement(ur.Provider,{value:f},e))))}),mr=J.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=J.useRef(null),a=$(e=>!e.search);return!n&&!a?null:J.createElement(I.div,{ref:ot(i,t),...r,"cmdk-separator":``,role:`separator`})}),hr=J.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=lr(),o=$(e=>e.search),s=$(e=>e.selectedItemId),c=sr();return J.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),J.createElement(I.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),gr=J.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=J.useRef(null),o=J.useRef(null),s=$(e=>e.selectedItemId),c=sr();return J.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),J.createElement(I.div,{ref:ot(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},Dr(e,e=>J.createElement(`div`,{ref:ot(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),_r=J.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return J.createElement(rt,{open:n,onOpenChange:r},J.createElement(at,{container:o},J.createElement(tt,{"cmdk-overlay":``,className:i}),J.createElement(et,{"aria-label":e.label,"cmdk-dialog":``,className:a},J.createElement(dr,{ref:t,...s}))))}),vr=J.forwardRef((e,t)=>$(e=>e.filtered.count===0)?J.createElement(I.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),yr=J.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return J.createElement(I.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Dr(e,e=>J.createElement(`div`,{"aria-hidden":!0},e)))}),br=Object.assign(dr,{List:gr,Item:fr,Input:hr,Group:pr,Separator:mr,Dialog:_r,Empty:vr,Loading:yr});function xr(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Sr(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Cr(e){let t=J.useRef(e);return Z(()=>{t.current=e}),t}var Z=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Q(e){let t=J.useRef();return t.current===void 0&&(t.current=e()),t}function $(e){let t=lr(),n=()=>e(t.snapshot());return J.useSyncExternalStore(t.subscribe,n,n)}function wr(e,t,n,r=[]){let i=J.useRef(),a=sr();return Z(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(ir,s),i.current=s}),i}var Tr=()=>{let[e,t]=J.useState(),n=Q(()=>new Map);return Z(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Er(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function Dr({asChild:e,children:t},n){return e&&J.isValidElement(t)?J.cloneElement(Er(t),{ref:t.ref},n(t.props.children)):n(t)}var Or={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function kr({className:e,...t}){return(0,Y.jsx)(br,{className:G(`flex size-full flex-col overflow-hidden rounded-lg bg-elevated`,e),...t})}function Ar({open:e,onOpenChange:t,children:n}){return(0,Y.jsx)(it,{open:e,onOpenChange:t,children:(0,Y.jsx)(nt,{className:`max-w-lg overflow-hidden p-0 [&>button]:hidden`,children:(0,Y.jsx)(kr,{loop:!0,children:n})})})}function jr({className:e,...t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pt-1`,children:[(0,Y.jsx)(Ft,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(br.Input,{className:G(`flex h-10 w-full bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted`,e),...t})]})}function Mr({className:e,...t}){return(0,Y.jsx)(br.List,{className:G(`max-h-72 overflow-y-auto p-1`,e),...t})}function Nr(e){return(0,Y.jsx)(br.Empty,{className:`py-6 text-center text-sm text-fg-muted`,...e})}function Pr({className:e,...t}){return(0,Y.jsx)(br.Group,{className:G(`overflow-hidden [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-2xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide [&_[cmdk-group-heading]]:text-fg-muted`,e),...t})}function Fr({className:e,...t}){return(0,Y.jsx)(br.Item,{className:G(lt,ct,`[&_svg]:size-3.5 [&_svg]:text-fg-muted data-[selected=true]:[&_svg]:text-action-ink`,e),...t})}function Ir({className:e,...t}){return(0,Y.jsx)(`span`,{className:G(`ml-auto font-mono text-2xs tracking-widest text-fg-muted`,e),...t})}var Lr=new class{transport;reload;pause;phase=`idle`;pending=null;constructor(e=fetch,t=()=>window.location.reload(),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 ${v.get()??``}`,"content-type":`application/json`};try{let n=await this.transport(`/cockpit/refresh`,{method:`POST`,headers:t,signal:AbortSignal.timeout(1e4),body:JSON.stringify({refreshId:crypto.randomUUID()})});if(n.status!==202)throw Error(`refresh rejected`);let i=f.parse(await n.json());this.phase=`waiting`;let a=Date.now()+e;for(;Date.now()<a;){await this.pause(1e3);try{let e=await this.transport(`/cockpit/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let n=r.parse(await e.json());if(n.instance===i.instance||n.refreshId!==i.refreshId||n.upstream!==`ready`)continue;return this.phase=`complete`,this.reload(),!0}catch{}}}catch{}return this.phase=`failed`,!1}},Rr=null;function zr(e){return Rr=e,()=>{Rr===e&&(Rr=null)}}function Br(){Rr?.()}var Vr=new Set;function Hr(){return[...Vr].flatMap(e=>e())}function Ur({onNewSession:e,onNewProject:t}){let[n,r]=(0,J.useState)(!1),[i,a]=(0,J.useState)(`commands`),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(!1),f=Ze(),p=Xe(),m=F(),g=p.id,_=ve(m??void 0),v=Re(g),y=Ot();(0,J.useEffect)(()=>Le(`palette.toggle`,()=>r(e=>!e)),[]),(0,J.useEffect)(()=>yt(()=>r(!0)),[]),(0,J.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let b=(0,J.useMemo)(()=>{let n=[];for(let e of _.data??[])n.push({id:`project-${e.id}`,group:`Projects`,label:e.name,icon:We,keywords:`switch project open`,run:()=>void f(`/project/${e.id}`)});for(let e of v.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:y(e),icon:Je,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return g!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:ht,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:Je,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),g!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:We,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:mt,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:Vt,keywords:`switch theme dark appearance`,run:()=>void h(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:Gt,keywords:`switch theme light appearance`,run:()=>void h(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:jn,keywords:`switch theme system appearance`,run:()=>void h(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Fn,keywords:`open settings preferences options configure`,run:()=>ft()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:pt,keywords:`switch profile identity user change`,run:()=>xe.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:vt,keywords:`refresh connection reconnect restart cockpit tunnel ssh daemon`,run:()=>Br()}),[...n,...Hr()]},[_.data,v.data,g,f,e,t,y]),x=(0,J.useMemo)(()=>{let e=new Map;for(let t of b){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[b]),S=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await Dt(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,Y.jsxs)(Ar,{open:n,onOpenChange:r,children:[(0,Y.jsx)(jr,{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(),S()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,Y.jsx)(Mr,{children:(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,Y.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,Y.jsxs)(Mr,{children:[(0,Y.jsx)(Nr,{children:`Nothing matches.`}),x.map(([e,t])=>(0,Y.jsx)(Pr,{heading:e,children:t.map(e=>{let t=e.icon;return(0,Y.jsxs)(Fr,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,Y.jsx)(t,{}),e.label,e.shortcut&&(0,Y.jsx)(Ir,{children:e.shortcut})]},e.id)})},e))]})]})}function Wr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Gr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Kr(){let e=ge(F()??void 0).data?.hotkeys;return(0,J.useEffect)(()=>{ye(e&&typeof e==`object`?e:void 0)},[e]),(0,J.useEffect)(()=>Le(`window.close`,()=>{let e=De();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,J.useEffect)(()=>{let e=e=>{let t=Ce(e);if(!t)return;let n=Ne(t);if(!n)return;let r=ke(n);if(!r||!Ee(r,Gr()))return;let i=Pe(n);i&&(e.preventDefault(),e.stopPropagation(),i())},t=e=>{let t=Ce(e);if(!t)return;let n=Ne(t);if(!n)return;let r=ke(n);if(!r||r.editor&&Gr()||r.deferInTerminal&&Wr())return;let i=Pe(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 Jr(){let[e,t]=(0,J.useState)(`hidden`),n=(0,J.useRef)(e);n.current=e,(0,J.useEffect)(()=>{let e=null,r=q.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,J.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Lr.refresh()||(b.error(`The cockpit has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(q.isConnected()?`hidden`:`lost`)))},[]);return(0,J.useEffect)(()=>zr(()=>void r()),[r]),e===`hidden`?null:(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the cockpit.`:`Connection to the daemon lost.`}),e===`lost`&&(0,Y.jsxs)(R,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,Y.jsx)(vt,{}),`Refresh connection`]})]})}function Yr({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,Y.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,Y.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,Y.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function Xr(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Zr(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 Qr({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=ze(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,Y.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,Y.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,Y.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,Y.jsxs)(Y.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 `,Zr(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[Xr(i.data.agent_usage.input_tokens),` in ·`,` `,Xr(i.data.agent_usage.output_tokens),` out ·`,` `,Xr(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,Y.jsx)(`span`,{className:`mt-1 block`,children:(0,Y.jsx)(Yr,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,Y.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,Y.jsx)(tn,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,Y.jsx)(Yr,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function $r(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(!1),i=F(),a=Ae(),o=be(),s=a.data?.find(e=>e.id===i),c=ce(i??void 0),l=T(),u=me(),{open:d,handler:f}=St(),[p,m]=(0,J.useState)(null),h=e=>u.mutate(e.id,{onSuccess:t=>m({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>z(e)}),g=e=>{t(!1),d({accountId:e.id})};return n&&s?(0,Y.jsxs)(`div`,{className:`flex h-8 items-center gap-2 px-3`,children:[(0,Y.jsx)(Wt,{icon:s.icon,colour:s.icon_colour}),(0,Y.jsx)(jt,{initial:s.name,maxLength:100,className:G(`w-32 text-sm`,Xt(s.icon_colour)),onCommit:e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>z(e)})},onCancel:()=>r(!1)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(qt,{open:e,onOpenChange:t,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,className:`font-sans compact:h-7 compact:px-1.5`,children:[(0,Y.jsx)(Wt,{icon:s?.icon,colour:s?.icon_colour}),(0,Y.jsx)(`span`,{className:Xt(s?.icon_colour),...Bt(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})}),(0,Y.jsx)(H,{children:`Profile`})]}),(0,Y.jsxs)(en,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,Y.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,Y.jsx)(Qr,{account:e,onLogin:()=>h(e),onStartSession:f&&n?()=>g(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,Y.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),ft(`accounts`)},children:[(0,Y.jsx)(mt,{}),`Add account`]}),(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),xe.set(null)},children:[(0,Y.jsx)(Pn,{}),`Switch profile`]})]})]})]}),p&&(0,Y.jsx)(Ht,{stream:p.stream,label:p.label,onClose:()=>m(null)})]})}var ei=`desktop-update`;function ti(){let e=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let t=De();if(t?.updateReady===void 0||t.onUpdateReady===void 0)return;let n=t=>{e.current!==t&&(e.current=t,b(`Puddle ${t} is downloaded and ready.`,{id:ei,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{De()?.installUpdate?.(),b.loading(`Restarting into Puddle ${t}…`,{id:`${ei}-restarting`,duration:1/0})}}}))};return t.updateReady().then(e=>{e!==null&&n(e)}),t.onUpdateReady(n)},[]),null}function ni(){let e=F(),t=Ae().data?.find(t=>t.id===e),n=ge(e??void 0),r=Oe(e??void 0,void 0),i=l(),a=Zt(),o=Kt(),c=Ie(e??``),d=be(),f=k(),[p,m]=(0,J.useReducer)(e=>e+1,0);(0,J.useEffect)(()=>g(()=>m()),[]);let _=(0,J.useRef)(null);(0,J.useEffect)(()=>{_.current=null},[t?.name]);let v=a.data?.available===!0?a.data.file:void 0,y=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&v!==void 0,b=t&&v?Jt(v,t.name):void 0,x=c.isPending||d.isPending||f.isPending||o.isPending||n.isFetching||r.isFetching;(0,J.useEffect)(()=>{if(!y||!b?.enabled||x)return;let a={client:i,theme:s(),profileSettings:n.data,profile:t,scratchpad:r.data},l={setClient:e=>u(e),setTheme:e=>{typeof e==`string`&&h(e)},patchProfileSettings:e=>c.mutate(e),patchProfileColumns:t=>d.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)f.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},p=JSON.stringify(b.doc);if(_.current!==p){_.current=p,Yt(b.doc,l,a,b.groups);return}let m=Qt(b.groups,a),g=JSON.stringify(m);g!==p&&(_.current=g,o.mutate({profile:t.name,entry:{...b,doc:m,updatedAt:new Date().toISOString()}}))})}var ri={desktop:!0,sound:!1,muted_projects:[]};function ii(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&e.permission===`granted`&&!e.windowFocused,sound:e.prefs.sound}}function ai(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 oi(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function si(){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 ci(){let e=le(),t=Ze(),n=ge(F()??void 0),r=(0,J.useRef)(ri);r.current={...ri,...n.data?.notifications??{}};let i=Ve(Me().data)??`Puddle`,a=(0,J.useRef)(i);(0,J.useEffect)(()=>{document.title===a.current&&(document.title=i),a.current=i},[i]),(0,J.useEffect)(()=>{let n=new Set,i=()=>{document.title=n.size>0?`(${n.size}) ${a.current}`:a.current},o=q.onStatus(a=>{let o=n.has(a.session);a.status===`waiting_input`?n.add(a.session):n.delete(a.session),i(),!(a.status!==`waiting_input`||o)&&(async()=>{let n=ai(e,a.session);if(!n)try{n=(await He(e)).find(e=>e.id===a.session)}catch{return}if(!n||n.kind===`terminal`)return;let i=n,o=ii({prefs:r.current,projectId:i.project_id,windowFocused:document.hasFocus(),permission:$t()});if(o.sound&&si(),o.desktop){let e=new Notification(oi(i),{body:`Waiting for your input`,tag:`puddle-waiting-${i.id}`});e.onclick=()=>{De()?.raiseWindow(),window.focus(),t(`/project/${i.project_id}/session/${i.id}`),e.close()}}})()});return()=>{o(),document.title=a.current}},[e,t])}function li({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,J.useState)(e?.title??``),[c,l]=(0,J.useState)(e?.body??``),[u,d]=(0,J.useState)(n?e?.scope??t:`profile`),[f,p]=(0,J.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,J.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,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(B,{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,Y.jsx)(dt,{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,Y.jsx)(B,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,Y.jsx)(_t,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:G(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,Y.jsx)(Ct,{type:e.id,className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,Y.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,Y.jsx)(R,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function ui(){let e=bt(),t=F(),n=Xe().id,r=Oe(t??void 0,n).data??[],i=T().data??[],a=k(),o=we(),s=ue(),c=Et(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null);(0,J.useEffect)(()=>Le(`scratchpad.toggle`,Tt),[]),(0,J.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,J.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),x=(0,J.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),S=d!==null||p!==null,C=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),w=S?C:_??r,E=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))},D=(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)},O=(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)},A=()=>{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})},j=e=>{navigator.clipboard?.writeText(e.body),b.success(`Copied to clipboard`)};return(0,Y.jsxs)(qt,{open:e,onOpenChange:xt,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(Mn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,Y.jsx)(H,{children:`Scratchpad`})]}),(0,Y.jsxs)(en,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(mt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||x.length>0)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:G(`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)),x.map(e=>(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:G(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,Y.jsx)(Ct,{type:e,className:`size-3.5`})},e))]}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[l===`new`&&(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(li,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:E,onCancel:()=>u(null)})}),w.length===0&&l!==`new`&&(0,Y.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:S?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,Y.jsx)(`ul`,{className:`flex flex-col`,children:w.map(e=>l===e.id?(0,Y.jsx)(`li`,{className:`px-3 py-2`,children:(0,Y.jsx)(li,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>D(e.id,t),onCancel:()=>u(null)})},e.id):(0,Y.jsx)(`li`,{draggable:!S&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&O(h,e.id))},onDragEnd:A,className:G(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,Y.jsx)(di,{entry:e,onInsert:c?()=>{c(e.body),xt(!1)}:null,onCopy:()=>j(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})},e.id))})]})]})]})}function di({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,J.useState)(!1);return(0,Y.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,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:G(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:`Delete`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,Y.jsx)(Ct,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,Y.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[t&&(0,Y.jsx)(fi,{icon:kn,label:`Insert into focused terminal`,onClick:t}),(0,Y.jsx)(fi,{icon:nn,label:`Copy`,onClick:n}),(0,Y.jsx)(fi,{icon:ut,label:`Edit`,onClick:r}),(0,Y.jsx)(fi,{icon:gt,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function fi({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(H,{children:t})]})}var pi=i.parse({});function mi(e,t){let[n,r]=(0,J.useState)(null),i=w(t).data,a=ve(e??void 0,t&&e!==null).data;return(0,J.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=zt(sessionStorage.getItem(Rt(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return _e(e).then(e=>{n||r(e?e.ui_state:pi)}).catch(()=>{n||r(pi)}),()=>{n=!0}},[t,e]),(0,J.useMemo)(()=>{if(!t||e===null||n===null)return null;let o=t=>{if(!i||!a)return!1;let{patch:o,projectBased:s}=Nt(n,t,{alive:new Set(i.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(i.map(e=>[e.id,e.project_id])),projectIds:a.map(e=>e.id),currentProject:null}),c={...n,...o};r(c),se(e,c).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Rt(e),JSON.stringify(c))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}return p().projectBasedLayout!==s&&u({projectBasedLayout:s}),!0},s=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:V(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:V(null),slices:s,capture:()=>({layout_tree:null,active_session:null}),apply:o}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:V(n.layout_tree),slices:s,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),apply:o}},[t,e,n,i,a])}var hi=V(null);function gi(){let e=Pt(),t=Ze(),n=F(),r=It(),i=mi(n,e&&r===null),a=r??i,o=j(n??void 0,void 0).data??[],s=ve(n??void 0,e&&n!==null).data??[],c=ee(),l=S(),u=fe(),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null);(0,J.useEffect)(()=>Le(`layouts.toggle`,Mt),[]),(0,J.useEffect)(()=>{e||(f(``),m(!1),g(null))},[e]);let _=a?.headless===!0,v=a===null||_?null:o.find(e=>e.id===a.layoutRef)??null,y=a!==null&&!_&&(v===null?a.signature!==hi:V(v.layout_tree)!==a.signature),x=e=>{let t=a?.slices?.[e];if(!t)return!1;let n=t.layoutRef===null?null:o.find(e=>e.id===t.layoutRef)??null;return n?V(n.layout_tree)!==t.signature:t.signature!==hi},C=e=>a===null?!1:e.scope===`profile`?a.scope===`profile`&&y:e.project_id===null?!1:a.scope===`project`?!_&&e.project_id===a.projectId?y:x(e.project_id):y||x(e.project_id),w=e=>v!==null&&e.id===v.id,T=e=>(e===null?void 0:s.find(t=>t.id===e)?.name)??`Project`,E=a!==null&&!_&&a.scope===`project`?o.filter(e=>e.scope===`profile`||e.project_id===a.projectId):o,D=[...E.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(E.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:T(e)})).sort((e,t)=>e.name.localeCompare(t.name))],O=h===null?E:h===`profile`?E.filter(e=>e.scope===`profile`):E.filter(e=>e.project_id===h),k=e=>a!==null&&e.scope===a.scope&&(a.scope===`profile`||e.project_id===a.projectId),A=(e,t,r)=>{!a||!n||c.mutate({profile_id:n,scope:a.scope,project_id:a.scope===`project`?a.projectId:void 0,name:e,...t},{onSuccess:e=>{r&&a.apply(e)},onError:e=>z(e)})},M=e=>{if(!a)return;let t=k(e)?e:o.find(t=>t.name===e.name&&k(t));if(!t){A(e.name,a.capture(),!0);return}l.mutate({id:t.id,...a.capture()},{onSuccess:e=>a.apply(e),onError:e=>z(e)})},N=(e,t)=>A(t,{layout_tree:e.layout_tree,active_session:e.active_session},!1),te=e=>{if(a){if(!a.apply(e)){b.error(`Workspace is still loading — try again in a moment`);return}e.project_id!==null&&e.project_id!==a.projectId&&t(`/project/${e.project_id}`),At(!1)}};return(0,Y.jsxs)(qt,{open:e,onOpenChange:At,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(An,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,Y.jsx)(H,{children:`Layouts`})]}),(0,Y.jsxs)(en,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),a!==null&&!_&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(mt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),a===null?(0,Y.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):_?(0,Y.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.`}):(v===null||p)&&(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[v===null&&(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:a.scope===`profile`?`Profile-wide`:`Project`}),(0,Y.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=d.trim();t&&(A(t,a.capture(),!0),f(``),m(!1))},children:[(0,Y.jsx)(B,{autoFocus:p,value:d,placeholder:v===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&m(!1)},className:`h-8 flex-1 text-sm`}),(0,Y.jsx)(R,{size:`sm`,type:`submit`,disabled:!d.trim(),children:`Save`}),v!==null&&(0,Y.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>m(!1),children:`Cancel`})]})]}),D.length>1&&(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:D.map(e=>(0,Y.jsx)(yi,{active:h===e.key,onClick:()=>g(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[O.length===0&&(0,Y.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:h===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,Y.jsx)(`ul`,{className:`flex flex-col`,children:O.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(_i,{layout:e,projectLabel:e.scope===`profile`?null:T(e.project_id),isCurrent:w(e),dirty:y,loadable:a!==null,savable:a!==null&&!_,confirmBeforeLoad:C(e),overwrites:k(e),onLoad:()=>te(e),onRename:t=>l.mutate({id:e.id,name:t}),onDelete:()=>u.mutate(e.id),onSaveAs:()=>M(e),onDuplicate:t=>N(e,t)})},e.id))})]})]})]})}function _i({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,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.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,Y.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||y()},className:G(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[h===null?(0,Y.jsxs)(`p`,{className:G(`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,Y.jsx)(`span`,{className:`text-2xs font-normal`,children:S===`active`?`Active`:`Unsaved`})]}):(0,Y.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,Y.jsx)(B,{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,Y.jsx)(R,{size:`sm`,type:`submit`,disabled:!_.trim(),children:h===`rename`?`Rename`:`Save`})]}),p===`save`?(0,Y.jsx)(vi,{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,Y.jsx)(vi,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{m(null),u()},onCancel:()=>m(null)}):p===`load`?(0,Y.jsx)(vi,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:y,onCancel:()=>m(null)}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[a&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bi,{icon:Nn,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:x}),(0,Y.jsx)(bi,{icon:nn,label:`Duplicate`,onClick:()=>b(`duplicate`)})]}),(0,Y.jsx)(bi,{icon:ut,label:`Rename`,onClick:()=>b(`rename`)}),(0,Y.jsx)(bi,{icon:gt,label:`Delete`,onClick:()=>m(`delete`)})]})]})]})}function vi({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:t}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]})}function yi({active:e,onClick:t,children:n}){return(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:G(`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 bi({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(H,{children:t})]})}var xi=De()!==void 0&&/Mac/.test(navigator.platform),Si=(0,J.lazy)(()=>_(()=>import(`./SettingsDialog-D-yMKqY9.js`).then(e=>({default:e.SettingsDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])));function Ci(){let e=le();(0,J.useEffect)(()=>{let t=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)})},n=q.onStatus(e=>t(t=>t.id===e.session?{...t,status:e.status,last_activity_at:e.last_activity_at}:t)),r=q.onRenamed(e=>t(t=>t.id===e.session?{...t,title:e.title,agent_title:`agent_title`in e?e.agent_title:t.agent_title,osc_title:`osc_title`in e?e.osc_title:t.osc_title}:t)),i=q.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))}),a=t=>{e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},o=q.onSessionsChanged(e=>a(e.project_ids)),s=q.onSessionSwitched(e=>a([e.target_project]));return()=>{n(),r(),i(),o(),s()}},[e])}function wi(){let e=Me(),t=ae(),[n,r]=(0,J.useState)(!1),i=Ve(e.data),a=n=>{r(!1);let a=n.trim();a!==i&&t.mutate({displayName:a===e.data?.hostname?``:a},{onError:e=>z(e)})},o=!xi&&(0,Y.jsx)(`img`,{src:`/puddle.svg`,alt:`Puddle`,className:`size-4`}),s=G(`flex shrink-0 items-center gap-2`,xi&&`[-webkit-app-region:no-drag]`),c=`truncate text-sm font-semibold text-fg-secondary`;return n&&i!==void 0?(0,Y.jsxs)(`div`,{className:s,children:[o,(0,Y.jsx)(jt,{initial:e.data?.displayName??i,maxLength:64,className:G(c,`w-40`),onCommit:a,onCancel:()=>r(!1)})]}):(0,Y.jsxs)(Ge,{to:`/`,className:G(s,`transition-opacity hover:opacity-70`),title:`All projects`,children:[o,i!==void 0&&(0,Y.jsx)(`span`,{className:c,...Bt(()=>r(!0)),children:i})]})}function Ti(){let e=Xe(),t=je(`palette.toggle`),n=Fe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,Y.jsxs)(`button`,{type:`button`,onClick:wt,className:G(`absolute left-1/2 flex h-6 w-[min(30rem,42%)] -translate-x-1/2 items-center justify-center gap-2 rounded-md bg-ground text-fg-muted transition-colors hover:bg-elevated hover:text-fg-secondary`,xi&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsx)(`span`,{className:`truncate text-xs`,children:r??`Puddle`}),(0,Y.jsx)(`span`,{className:`text-2xs`,children:t})]})}function Ei(){let{fullScreen:e,animate:t}=Se();return(0,Y.jsxs)(`header`,{className:G(`relative flex h-9 shrink-0 items-center gap-3 bg-surface pl-3 pr-3`,xi&&!e&&`pl-[88px] [-webkit-app-region:drag]`,t&&`transition-[padding] duration-200 ease-out`),children:[(0,Y.jsx)(wi,{}),(0,Y.jsx)(Ti,{}),(0,Y.jsxs)(`div`,{className:G(`ml-auto flex items-center`,xi&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>ft(),children:[(0,Y.jsx)(Fn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,Y.jsx)(H,{children:`Settings`})]}),(0,Y.jsx)(gi,{}),(0,Y.jsx)(ui,{}),(0,Y.jsx)($r,{})]})]})}function Di(){Ci(),ni(),ci();let{handler:e}=St(),t=F(),{pathname:n}=qe(),[r,i]=(0,J.useState)(!1),a=oe(),o=a.data!==void 0&&an(a.data.protocol);return(0,J.useEffect)(()=>{if(!o)return;let e=()=>{let e=d();q.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),g(e)},[o]),(0,Y.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[(0,Y.jsx)(Ei,{}),(0,Y.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,Y.jsx)(dn,{resetOn:n,scope:n.startsWith(`/project/`)?`workspace`:`view`,children:(0,Y.jsx)(Ye,{})})}),(0,Y.jsx)(Jr,{}),(0,Y.jsx)(ti,{}),(0,Y.jsx)(Ur,{onNewSession:e??void 0,onNewProject:()=>i(!0)}),t!==null&&(0,Y.jsx)(rn,{profileId:t,open:r,onOpenChange:i}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Si,{})}),(0,Y.jsx)(Kr,{})]})}function Oi(){return(0,Y.jsx)(Lt,{children:(0,Y.jsx)(Di,{})})}var ki=(0,J.lazy)(()=>_(()=>import(`./Dashboard-DNWLZwxT.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([18,1,2,3,4,6,5,19,10,7,8,9,11,20,16,21,17,22]))),Ai=(0,J.lazy)(()=>_(()=>import(`./Workspace-DhFU_Ltc.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([23,1,2,3,4,5,6,24,10,19,7,8,9,11,12,25,26,27,20,16,28,22,14,15,29,30,31,32]))),ji=new un({defaultOptions:{queries:{retry:1,staleTime:5e3}},mutationCache:new sn({onError:e=>z(e)})});function Mi(){let e=F(),t=Ae(),n=e!==null&&t.data!==void 0&&!t.data.some(t=>t.id===e);return e===null||n?(0,Y.jsx)(In,{}):(0,Y.jsx)(Qe,{useTransitions:!1,children:(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Ke,{children:(0,Y.jsxs)($e,{element:(0,Y.jsx)(Oi,{}),children:[(0,Y.jsx)($e,{path:`/`,element:(0,Y.jsx)(ki,{})}),(0,Y.jsx)($e,{path:`/project/:id`,element:(0,Y.jsx)(Ai,{})}),(0,Y.jsx)($e,{path:`/project/:id/session/:sid`,element:(0,Y.jsx)(Ai,{})})]})})})})}function Ni(){let e=(0,J.useSyncExternalStore)(v.subscribe,v.get);return(0,Y.jsx)(Be,{client:ji,children:(0,Y.jsxs)(kt,{delayDuration:300,children:[(0,Y.jsx)(On,{}),(0,Y.jsx)(dn,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,Y.jsx)(on,{}):(0,Y.jsx)(Mi,{}):(0,Y.jsx)(pn,{})}),(0,Y.jsx)(fn,{})]})})}export{Ni as App};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsDialog-CamnF91I.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/index-BLx1AR0-.js","assets/index-uKreLbru.css","assets/dist-3tmIo7Ja.js","assets/hotkeys-DbIEec2f.js","assets/dialog-CAMTxigV.js","assets/button-DehrlYw7.js","assets/x-CZCUod6A.js","assets/createLucideIcon-DyMAgLa3.js","assets/LazyTerminal-BYbPpGEI.js","assets/switch-CN9NW-du.js","assets/notification-permission-CG2r3Oi8.js","assets/disclosure-DvM7-z38.js","assets/chevron-down--sjpQEHH.js","assets/dist-sLs_LTiG.js","assets/use-debounced-value-C86N-mOK.js","assets/Dashboard-B5qWtmwb.js","assets/project-abbrev-BU2DBpdq.js","assets/context-menu-BT88Vgia.js","assets/NewProjectDialog-D3bNK3u_.js","assets/ws-C-kvwpeD.js","assets/Workspace-BmtA0kYQ.js","assets/media-refresh-store-CxqhHl8x.js","assets/use-ui-state-CzR7YpWb.js","assets/preview-kind-QJSMKfUN.js","assets/debounce-B9DrqirV.js","assets/input-DXYRmAFr.js","assets/protocol-support-C1NCVjbV.js","assets/drafts-B_tChlzR.js","assets/buffer-logic-BAkSBQT7.js","assets/Workspace-B6mgQyIM.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{D as n,N as r,O as i,W as a,a as o,c as s,g as c,h as l,i as u,it as d,m as f,n as p,q as m,r as h,s as g,t as _,y as v}from"./index-BLx1AR0-.js";import{i as y,n as b,t as x}from"./dist-3tmIo7Ja.js";import{$ as S,Bt as C,D as w,E as T,Et as E,Ft as D,Ht as O,I as k,It as A,J as j,Lt as M,M as ee,Mt as N,N as te,Nt as ne,Ot as re,Pt as ie,Q as ae,R as oe,Rt as P,S as se,T as ce,Tt as le,U as ue,Ut as de,V as fe,Vt as pe,Y as me,_ as he,at as ge,b as _e,ct as ve,d as ye,et as be,g as xe,h as Se,i as Ce,it as we,jt as Te,l as Ee,m as De,mt as Oe,o as ke,ot as Ae,p as je,q as Me,r as Ne,s as Pe,st as Fe,tt as Ie,u as Le,v as F,vt as Re,w as ze,wt as Be,x as Ve,y as He,zt as Ue}from"./hotkeys-DbIEec2f.js";import{a as We,c as Ge,d as Ke,f as qe,i as Je,l as Ye,m as Xe,p as Ze,s as Qe,u as $e}from"./project-abbrev-BU2DBpdq.js";import{S as I,c as et,l as tt,n as nt,s as rt,t as it,u as at,v as L}from"./dialog-CAMTxigV.js";import{i as ot,t as R}from"./button-DehrlYw7.js";import{a as z,c as st,f as ct,l as B,m as lt,o as ut,u as dt}from"./LazyTerminal-BYbPpGEI.js";import{a as ft,c as pt,d as mt,f as ht,l as gt,t as _t,u as vt}from"./switch-CN9NW-du.js";import{$ as yt,G as bt,H as xt,J as St,K as Ct,Q as wt,U as Tt,W as Et,X as Dt,Y as Ot,at as kt,d as At,et as jt,f as Mt,h as V,i as Nt,it as H,m as Pt,nt as Ft,ot as U,p as It,q as Lt,r as Rt,rt as W,t as zt,tt as Bt}from"./use-ui-state-CzR7YpWb.js";import{n as G}from"./x-CZCUod6A.js";import{t as K}from"./createLucideIcon-DyMAgLa3.js";import{_ as Vt,c as Ht,d as Ut,f as Wt,h as Gt,i as Kt,l as qt,n as Jt,o as Yt,p as Xt,r as Zt,s as Qt,t as $t,u as en,v as tn}from"./notification-permission-CG2r3Oi8.js";import{t as nn}from"./copy-CGsu8426.js";import{t as rn}from"./NewProjectDialog-D3bNK3u_.js";import{a as an}from"./protocol-support-C1NCVjbV.js";import{t as q}from"./ws-C-kvwpeD.js";var J=e(t(),1),Y=p();function on(){let[e,t]=(0,J.useState)(`Opening forwarded application…`);return(0,J.useEffect)(()=>{let e=/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname);if(!e){t(`This forwarding link is invalid.`);return}let n=!0;return y(`POST`,`/cockpit/proxy-grant`,{session:e[1],port:Number(e[2]),path:new URLSearchParams(window.location.search).get(`path`)??`/`}).then(e=>{n&&window.location.replace(i.parse(e).url)}).catch(()=>{n&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{n=!1}},[]),(0,Y.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var sn=class extends de{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new E({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t);if(n)if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=cn(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}else return!0}runNext(e){let t=cn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){N.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>A(t,e))}findAll(e={}){return this.getAll().filter(t=>A(e,t))}notify(e){N.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return N.batch(()=>Promise.all(e.map(e=>e.continue().catch(P))))}};function cn(e){return e.options.scope?.id}var ln=class extends de{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??D(r,t),a=this.get(i);return a||(a=new re({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){N.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>M(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>M(e,t)):t}notify(e){N.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){N.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){N.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},un=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new ln,this.#t=e.mutationCache||new sn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=O.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Te.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(C(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=ne(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return N.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;N.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return N.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=N.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(P).catch(P)}invalidateQueries(e,t={}){return N.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=N.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(P)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(P)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(C(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(P).catch(P)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(P).catch(P)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Te.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(ie(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ue(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(ie(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ue(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=D(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===pe&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},dn=class extends J.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,Y.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,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,Y.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Y.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,Y.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function fn(){return(0,Y.jsx)(x,{theme:(0,J.useSyncExternalStore)(g,o),position:`bottom-right`,toastOptions:{style:{background:`var(--bg-elevated)`,border:`none`,boxShadow:`0 8px 30px rgb(0 0 0 / 0.25)`,color:`var(--text-primary)`},classNames:{description:`whitespace-pre-wrap break-words font-mono text-2xs leading-snug max-h-40 overflow-y-auto`}}})}function pn(){return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,Y.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,Y.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,Y.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var mn=e(d(),1),hn=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,gn=`.monaco-editor`;function _n(e,t){return e?.closest(gn)&&!e.closest(t)?`text`:e?.closest(hn)?`interactive`:`default`}function vn(e,t=`.no-custom-caret`){(0,J.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=()=>{n.style.opacity=`0`},a=e=>{if(e.pointerType===`touch`||!r.matches){i();return}n.style.transform=`translate3d(${e.clientX}px, ${e.clientY}px, 0) translate(-50%, -50%)`;let a=e.target instanceof Element?e.target:null;if(a instanceof HTMLIFrameElement){i();return}n.style.opacity=`1`;let o=a?.closest(gn),s=_n(a,t),c=s===`text`,l=s===`interactive`,u=c;if(c&&o){let e=getComputedStyle(o);n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`)}else if(!l&&a&&!a.closest(t)&&Array.from(a.childNodes).some(e=>e.nodeType===Node.TEXT_NODE&&e.textContent?.trim())){let e=getComputedStyle(a);e.userSelect!==`none`&&(u=!0,n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`))}n.classList.toggle(`is-interactive`,l),n.classList.toggle(`is-text`,u)};return window.addEventListener(`pointermove`,a,{passive:!0}),document.documentElement.addEventListener(`pointerleave`,i),window.addEventListener(`blur`,i),()=>{window.removeEventListener(`pointermove`,a),document.documentElement.removeEventListener(`pointerleave`,i),window.removeEventListener(`blur`,i)}},[t,e])}var yn=[`top`,`right`,`bottom`,`left`];function bn(){let e=(0,J.useRef)(null);return vn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:yn.map(e=>(0,Y.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function xn(){let e=(0,J.useRef)(null);return vn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var Sn=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Cn=40.5,X=4.05,wn=X*Math.sqrt(3)/2;function Tn(){let e=[],t=[],n=Cn/2,r=Math.ceil(n/wn)+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*wn,s=o+wn,c=(i%2+2)%2*(X/2);for(let i=-r;i<r;i+=1){let r=n+i*X+c,l=[[r+X/2,o],[r,s],[r+X,s]],u=[[r+X/2,o],[r+3*X/2,o],[r+X,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Cn&&Math.max(...n)>0&&Math.min(...n)<Cn};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var En=Tn();function Dn(){let e=(0,J.useRef)(null);return vn(e,Sn),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,Y.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Cn} ${Cn}`,focusable:`false`,children:[(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:En.light}),(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:En.dark})]})})}function On(){let{cursorPackage:e}=c(),t=null;switch(e){case`rangefinder`:t=(0,Y.jsx)(Dn,{});break;case`drafting`:t=(0,Y.jsx)(bn,{});break;case`invert`:t=(0,Y.jsx)(xn,{});break;case`system`:return null}return(0,mn.createPortal)(t,document.body)}var kn=K(`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`}]]),An=K(`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`}]]),jn=K(`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`}]]),Mn=K(`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`}]]),Nn=K(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),Pn=K(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),Fn=K(`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 In(){let e=Ae(),t=te(),[n,r]=(0,J.useState)(``),[i,a]=(0,J.useState)(m),o=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:i.trim()},{onSuccess:e=>he(e.id)})},s=(e.data?.length??0)>0;return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),s&&(0,Y.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>he(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,Y.jsx)(Wt,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,Y.jsx)(`span`,{className:G(`text-base`,Xt(e.icon_colour)||`text-fg`),children:e.name}),e.branch_prefix&&(0,Y.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,Y.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),o()},children:[s&&(0,Y.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(st,{htmlFor:`profile-name`,children:`Name`}),(0,Y.jsx)(B,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>r(e.target.value),className:`h-10`,autoFocus:!s})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(st,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,Y.jsx)(B,{id:`branch-prefix`,placeholder:`no prefix`,value:i,onChange:e=>a(e.target.value),className:`h-10`})]}),t.error&&(0,Y.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,Y.jsx)(R,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}var Ln=1,Rn=.9,zn=.8,Bn=.17,Vn=.1,Hn=.999,Un=.9999,Wn=.99,Gn=/[\\\/_+.#"@\[\(\{&]/,Kn=/[\\\/_+.#"@\[\(\{&]/g,qn=/[\s-]/,Jn=/[\s-]/g;function Yn(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Ln:Wn;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=Yn(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Ln:Gn.test(e.charAt(l-1))?(d*=zn,p=e.slice(i,l-1).match(Kn),p&&i>0&&(d*=Hn**+p.length)):qn.test(e.charAt(l-1))?(d*=Rn,m=e.slice(i,l-1).match(Jn),m&&i>0&&(d*=Hn**+m.length)):(d*=Bn,i>0&&(d*=Hn**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Un)),(d<Vn&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=Yn(e,t,n,r,l+1,a+2,o),f*Vn>d&&(d=f*Vn)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function Xn(e){return e.toLowerCase().replace(Jn,` `)}function Zn(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,Yn(e,t,Xn(e),Xn(t),0,0,{})}var Qn=`[cmdk-group=""]`,$n=`[cmdk-group-items=""]`,er=`[cmdk-group-heading=""]`,tr=`[cmdk-item=""]`,nr=`${tr}:not([aria-disabled="true"])`,rr=`cmdk-item-select`,ir=`data-value`,ar=(e,t,n)=>Zn(e,t,n),or=J.createContext(void 0),sr=()=>J.useContext(or),cr=J.createContext(void 0),lr=()=>J.useContext(cr),ur=J.createContext(void 0),dr=J.forwardRef((e,t)=>{let n=Q(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=Q(()=>new Set),i=Q(()=>new Map),a=Q(()=>new Map),o=Q(()=>new Set),s=Cr(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=L(),y=L(),b=L(),x=J.useRef(null),S=Tr();Z(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),Z(()=>{S(6,k)},[]);let C=J.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)O(),E(),S(1,D);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(b);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(S(7,()=>{n.current.selectedItemId=A()?.id,C.emit()}),r||S(5,k),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),w=J.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,T(t,r)),S(2,()=>{E(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),S(3,()=>{O(),E(),n.current.value||D(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=A();S(4,()=>{O(),t?.getAttribute(`id`)===e&&D(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:b,labelId:y,listInnerRef:x}),[]);function T(e,t){let r=s.current?.filter??ar;return e?r(e,n.current.search,t):0}function E(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=x.current;j().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest($n);t?t.appendChild(e.parentElement===t?e:e.closest(`${$n} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${$n} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${Qn}[${ir}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(ir);C.setState(`value`,e||void 0)}function O(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=T(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function k(){var e;let t=A();t&&(t.parentElement?.firstChild===t&&((e=t.closest(Qn)?.querySelector(er))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${tr}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll(nr)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(ir))}function ee(e){var t;let n=A(),r=j(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&C.setState(`value`,a.getAttribute(ir))}function N(e){let t=A()?.closest(Qn),n;for(;t&&!n;)t=e>0?xr(t,Qn):Sr(t,Qn),n=t?.querySelector(nr);n?C.setState(`value`,n.getAttribute(ir)):ee(e)}let te=()=>M(j().length-1),ne=e=>{e.preventDefault(),e.metaKey?te():e.altKey?N(1):ee(1)},re=e=>{e.preventDefault(),e.metaKey?M(0):e.altKey?N(-1):ee(-1)};return J.createElement(I.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&ne(e);break;case`ArrowDown`:ne(e);break;case`p`:case`k`:g&&e.ctrlKey&&re(e);break;case`ArrowUp`:re(e);break;case`Home`:e.preventDefault(),M(0);break;case`End`:e.preventDefault(),te();break;case`Enter`:{e.preventDefault();let t=A();if(t){let e=new Event(rr);t.dispatchEvent(e)}}}}},J.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:Or},c),Dr(e,e=>J.createElement(cr.Provider,{value:C},J.createElement(or.Provider,{value:w},e))))}),fr=J.forwardRef((e,t)=>{let n=L(),r=J.useRef(null),i=J.useContext(ur),a=sr(),o=Cr(e),s=o.current?.forceMount??i?.forceMount;Z(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=wr(n,r,[e.value,e.children,r],e.keywords),l=lr(),u=$(e=>e.value&&e.value===c.current),d=$(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);J.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(rr,f),()=>t.removeEventListener(rr,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:v,...y}=e;return J.createElement(I.div,{ref:ot(r,t),...y,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),pr=J.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=L(),s=J.useRef(null),c=J.useRef(null),l=L(),u=sr(),d=$(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));Z(()=>u.group(o),[]),wr(o,s,[e.value,e.heading,c]);let f=J.useMemo(()=>({id:o,forceMount:i}),[i]);return J.createElement(I.div,{ref:ot(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&J.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),Dr(e,e=>J.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},J.createElement(ur.Provider,{value:f},e))))}),mr=J.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=J.useRef(null),a=$(e=>!e.search);return!n&&!a?null:J.createElement(I.div,{ref:ot(i,t),...r,"cmdk-separator":``,role:`separator`})}),hr=J.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=lr(),o=$(e=>e.search),s=$(e=>e.selectedItemId),c=sr();return J.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),J.createElement(I.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),gr=J.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=J.useRef(null),o=J.useRef(null),s=$(e=>e.selectedItemId),c=sr();return J.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),J.createElement(I.div,{ref:ot(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},Dr(e,e=>J.createElement(`div`,{ref:ot(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),_r=J.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return J.createElement(rt,{open:n,onOpenChange:r},J.createElement(at,{container:o},J.createElement(tt,{"cmdk-overlay":``,className:i}),J.createElement(et,{"aria-label":e.label,"cmdk-dialog":``,className:a},J.createElement(dr,{ref:t,...s}))))}),vr=J.forwardRef((e,t)=>$(e=>e.filtered.count===0)?J.createElement(I.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),yr=J.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return J.createElement(I.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Dr(e,e=>J.createElement(`div`,{"aria-hidden":!0},e)))}),br=Object.assign(dr,{List:gr,Item:fr,Input:hr,Group:pr,Separator:mr,Dialog:_r,Empty:vr,Loading:yr});function xr(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Sr(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Cr(e){let t=J.useRef(e);return Z(()=>{t.current=e}),t}var Z=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Q(e){let t=J.useRef();return t.current===void 0&&(t.current=e()),t}function $(e){let t=lr(),n=()=>e(t.snapshot());return J.useSyncExternalStore(t.subscribe,n,n)}function wr(e,t,n,r=[]){let i=J.useRef(),a=sr();return Z(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(ir,s),i.current=s}),i}var Tr=()=>{let[e,t]=J.useState(),n=Q(()=>new Map);return Z(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Er(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function Dr({asChild:e,children:t},n){return e&&J.isValidElement(t)?J.cloneElement(Er(t),{ref:t.ref},n(t.props.children)):n(t)}var Or={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function kr({className:e,...t}){return(0,Y.jsx)(br,{className:G(`flex size-full flex-col overflow-hidden rounded-lg bg-elevated`,e),...t})}function Ar({open:e,onOpenChange:t,children:n}){return(0,Y.jsx)(it,{open:e,onOpenChange:t,children:(0,Y.jsx)(nt,{className:`max-w-lg overflow-hidden p-0 [&>button]:hidden`,children:(0,Y.jsx)(kr,{loop:!0,children:n})})})}function jr({className:e,...t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pt-1`,children:[(0,Y.jsx)(Ft,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(br.Input,{className:G(`flex h-10 w-full bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted`,e),...t})]})}function Mr({className:e,...t}){return(0,Y.jsx)(br.List,{className:G(`max-h-72 overflow-y-auto p-1`,e),...t})}function Nr(e){return(0,Y.jsx)(br.Empty,{className:`py-6 text-center text-sm text-fg-muted`,...e})}function Pr({className:e,...t}){return(0,Y.jsx)(br.Group,{className:G(`overflow-hidden [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-2xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide [&_[cmdk-group-heading]]:text-fg-muted`,e),...t})}function Fr({className:e,...t}){return(0,Y.jsx)(br.Item,{className:G(lt,ct,`[&_svg]:size-3.5 [&_svg]:text-fg-muted data-[selected=true]:[&_svg]:text-action-ink`,e),...t})}function Ir({className:e,...t}){return(0,Y.jsx)(`span`,{className:G(`ml-auto font-mono text-2xs tracking-widest text-fg-muted`,e),...t})}var Lr=new class{transport;reload;pause;phase=`idle`;pending=null;constructor(e=fetch,t=()=>window.location.reload(),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 ${v.get()??``}`,"content-type":`application/json`};try{let i=await this.transport(`/cockpit/refresh`,{method:`POST`,headers:t,signal:AbortSignal.timeout(1e4),body:JSON.stringify({refreshId:crypto.randomUUID()})});if(i.status!==202)throw Error(`refresh rejected`);let a=r.parse(await i.json());this.phase=`waiting`;let o=Date.now()+e;for(;Date.now()<o;){await this.pause(1e3);try{let e=await this.transport(`/cockpit/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let r=n.parse(await e.json());if(r.instance===a.instance||r.refreshId!==a.refreshId||r.upstream!==`ready`)continue;return this.phase=`complete`,this.reload(),!0}catch{}}}catch{}return this.phase=`failed`,!1}},Rr=null;function zr(e){return Rr=e,()=>{Rr===e&&(Rr=null)}}function Br(){Rr?.()}var Vr=new Set;function Hr(){return[...Vr].flatMap(e=>e())}function Ur({onNewSession:e,onNewProject:t}){let[n,r]=(0,J.useState)(!1),[i,a]=(0,J.useState)(`commands`),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(!1),f=Ze(),p=Xe(),m=F(),g=p.id,_=ve(m??void 0),v=Re(g),y=Ot();(0,J.useEffect)(()=>Le(`palette.toggle`,()=>r(e=>!e)),[]),(0,J.useEffect)(()=>yt(()=>r(!0)),[]),(0,J.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let b=(0,J.useMemo)(()=>{let n=[];for(let e of _.data??[])n.push({id:`project-${e.id}`,group:`Projects`,label:e.name,icon:We,keywords:`switch project open`,run:()=>void f(`/project/${e.id}`)});for(let e of v.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:y(e),icon:Je,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return g!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:ht,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:Je,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),g!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:We,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:mt,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:Vt,keywords:`switch theme dark appearance`,run:()=>void h(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:Gt,keywords:`switch theme light appearance`,run:()=>void h(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:jn,keywords:`switch theme system appearance`,run:()=>void h(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Fn,keywords:`open settings preferences options configure`,run:()=>ft()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:pt,keywords:`switch profile identity user change`,run:()=>xe.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:vt,keywords:`refresh connection reconnect restart cockpit tunnel ssh daemon`,run:()=>Br()}),[...n,...Hr()]},[_.data,v.data,g,f,e,t,y]),x=(0,J.useMemo)(()=>{let e=new Map;for(let t of b){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[b]),S=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await Dt(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,Y.jsxs)(Ar,{open:n,onOpenChange:r,children:[(0,Y.jsx)(jr,{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(),S()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,Y.jsx)(Mr,{children:(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,Y.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,Y.jsxs)(Mr,{children:[(0,Y.jsx)(Nr,{children:`Nothing matches.`}),x.map(([e,t])=>(0,Y.jsx)(Pr,{heading:e,children:t.map(e=>{let t=e.icon;return(0,Y.jsxs)(Fr,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,Y.jsx)(t,{}),e.label,e.shortcut&&(0,Y.jsx)(Ir,{children:e.shortcut})]},e.id)})},e))]})]})}function Wr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Gr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Kr(){let e=ge(F()??void 0).data?.hotkeys;return(0,J.useEffect)(()=>{ye(e&&typeof e==`object`?e:void 0)},[e]),(0,J.useEffect)(()=>Le(`window.close`,()=>{let e=De();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,J.useEffect)(()=>{let e=e=>{let t=Ce(e);if(!t)return;let n=Ne(t);if(!n)return;let r=ke(n);if(!r||!Ee(r,Gr()))return;let i=Pe(n);i&&(e.preventDefault(),e.stopPropagation(),i())},t=e=>{let t=Ce(e);if(!t)return;let n=Ne(t);if(!n)return;let r=ke(n);if(!r||r.editor&&Gr()||r.deferInTerminal&&Wr())return;let i=Pe(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 Jr(){let[e,t]=(0,J.useState)(`hidden`),n=(0,J.useRef)(e);n.current=e,(0,J.useEffect)(()=>{let e=null,r=q.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,J.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Lr.refresh()||(b.error(`The cockpit has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(q.isConnected()?`hidden`:`lost`)))},[]);return(0,J.useEffect)(()=>zr(()=>void r()),[r]),e===`hidden`?null:(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the cockpit.`:`Connection to the daemon lost.`}),e===`lost`&&(0,Y.jsxs)(R,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,Y.jsx)(vt,{}),`Refresh connection`]})]})}function Yr({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,Y.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,Y.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,Y.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function Xr(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Zr(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 Qr({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=ze(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,Y.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,Y.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,Y.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,Y.jsxs)(Y.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 `,Zr(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[Xr(i.data.agent_usage.input_tokens),` in ·`,` `,Xr(i.data.agent_usage.output_tokens),` out ·`,` `,Xr(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,Y.jsx)(`span`,{className:`mt-1 block`,children:(0,Y.jsx)(Yr,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,Y.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,Y.jsx)(tn,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,Y.jsx)(Yr,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function $r(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(!1),i=F(),a=Ae(),o=be(),s=a.data?.find(e=>e.id===i),c=ce(i??void 0),l=T(),u=me(),{open:d,handler:f}=St(),[p,m]=(0,J.useState)(null),h=e=>u.mutate(e.id,{onSuccess:t=>m({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>z(e)}),g=e=>{t(!1),d({accountId:e.id})};return n&&s?(0,Y.jsxs)(`div`,{className:`flex h-8 items-center gap-2 px-3`,children:[(0,Y.jsx)(Wt,{icon:s.icon,colour:s.icon_colour}),(0,Y.jsx)(jt,{initial:s.name,maxLength:100,className:G(`w-32 text-sm`,Xt(s.icon_colour)),onCommit:e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>z(e)})},onCancel:()=>r(!1)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(qt,{open:e,onOpenChange:t,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,className:`font-sans compact:h-7 compact:px-1.5`,children:[(0,Y.jsx)(Wt,{icon:s?.icon,colour:s?.icon_colour}),(0,Y.jsx)(`span`,{className:Xt(s?.icon_colour),...Bt(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})}),(0,Y.jsx)(H,{children:`Profile`})]}),(0,Y.jsxs)(en,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,Y.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,Y.jsx)(Qr,{account:e,onLogin:()=>h(e),onStartSession:f&&n?()=>g(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,Y.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),ft(`accounts`)},children:[(0,Y.jsx)(mt,{}),`Add account`]}),(0,Y.jsxs)(R,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),xe.set(null)},children:[(0,Y.jsx)(Pn,{}),`Switch profile`]})]})]})]}),p&&(0,Y.jsx)(Ht,{stream:p.stream,label:p.label,onClose:()=>m(null)})]})}var ei=`desktop-update`;function ti(){let e=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let t=De();if(t?.updateReady===void 0||t.onUpdateReady===void 0)return;let n=t=>{e.current!==t&&(e.current=t,b(`Puddle ${t} is downloaded and ready.`,{id:ei,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{De()?.installUpdate?.(),b.loading(`Restarting into Puddle ${t}…`,{id:`${ei}-restarting`,duration:1/0})}}}))};return t.updateReady().then(e=>{e!==null&&n(e)}),t.onUpdateReady(n)},[]),null}function ni(){let e=F(),t=Ae().data?.find(t=>t.id===e),n=ge(e??void 0),r=Oe(e??void 0,void 0),i=c(),a=Zt(),o=Kt(),u=Ie(e??``),d=be(),f=k(),[p,m]=(0,J.useReducer)(e=>e+1,0);(0,J.useEffect)(()=>g(()=>m()),[]);let _=(0,J.useRef)(null);(0,J.useEffect)(()=>{_.current=null},[t?.name]);let v=a.data?.available===!0?a.data.file:void 0,y=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&v!==void 0,b=t&&v?Jt(v,t.name):void 0,x=u.isPending||d.isPending||f.isPending||o.isPending||n.isFetching||r.isFetching;(0,J.useEffect)(()=>{if(!y||!b?.enabled||x)return;let a={client:i,theme:s(),profileSettings:n.data,profile:t,scratchpad:r.data},c={setClient:e=>l(e),setTheme:e=>{typeof e==`string`&&h(e)},patchProfileSettings:e=>u.mutate(e),patchProfileColumns:t=>d.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)f.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},p=JSON.stringify(b.doc);if(_.current!==p){_.current=p,Yt(b.doc,c,a,b.groups);return}let m=Qt(b.groups,a),g=JSON.stringify(m);g!==p&&(_.current=g,o.mutate({profile:t.name,entry:{...b,doc:m,updatedAt:new Date().toISOString()}}))})}var ri={desktop:!0,sound:!1,muted_projects:[]};function ii(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&e.permission===`granted`&&!e.windowFocused,sound:e.prefs.sound}}function ai(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 oi(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function si(){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 ci(){let e=le(),t=Ze(),n=ge(F()??void 0),r=(0,J.useRef)(ri);r.current={...ri,...n.data?.notifications??{}};let i=Ve(Me().data)??`Puddle`,a=(0,J.useRef)(i);(0,J.useEffect)(()=>{document.title===a.current&&(document.title=i),a.current=i},[i]),(0,J.useEffect)(()=>{let n=new Set,i=()=>{document.title=n.size>0?`(${n.size}) ${a.current}`:a.current},o=q.onStatus(a=>{let o=n.has(a.session);a.status===`waiting_input`?n.add(a.session):n.delete(a.session),i(),!(a.status!==`waiting_input`||o)&&(async()=>{let n=ai(e,a.session);if(!n)try{n=(await He(e)).find(e=>e.id===a.session)}catch{return}if(!n||n.kind===`terminal`)return;let i=n,o=ii({prefs:r.current,projectId:i.project_id,windowFocused:document.hasFocus(),permission:$t()});if(o.sound&&si(),o.desktop){let e=new Notification(oi(i),{body:`Waiting for your input`,tag:`puddle-waiting-${i.id}`});e.onclick=()=>{De()?.raiseWindow(),window.focus(),t(`/project/${i.project_id}/session/${i.id}`),e.close()}}})()});return()=>{o(),document.title=a.current}},[e,t])}function li({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,J.useState)(e?.title??``),[c,l]=(0,J.useState)(e?.body??``),[u,d]=(0,J.useState)(n?e?.scope??t:`profile`),[f,p]=(0,J.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,J.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,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(B,{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,Y.jsx)(dt,{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,Y.jsx)(B,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,Y.jsx)(_t,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:G(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,Y.jsx)(Ct,{type:e.id,className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,Y.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,Y.jsx)(R,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function ui(){let e=bt(),t=F(),n=Xe().id,r=Oe(t??void 0,n).data??[],i=T().data??[],a=k(),o=we(),s=ue(),c=Et(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null);(0,J.useEffect)(()=>Le(`scratchpad.toggle`,Tt),[]),(0,J.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,J.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),x=(0,J.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),S=d!==null||p!==null,C=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),w=S?C:_??r,E=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))},D=(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)},O=(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)},A=()=>{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})},j=e=>{navigator.clipboard?.writeText(e.body),b.success(`Copied to clipboard`)};return(0,Y.jsxs)(qt,{open:e,onOpenChange:xt,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(Mn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,Y.jsx)(H,{children:`Scratchpad`})]}),(0,Y.jsxs)(en,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(mt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||x.length>0)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:G(`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)),x.map(e=>(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:G(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,Y.jsx)(Ct,{type:e,className:`size-3.5`})},e))]}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[l===`new`&&(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(li,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:E,onCancel:()=>u(null)})}),w.length===0&&l!==`new`&&(0,Y.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:S?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,Y.jsx)(`ul`,{className:`flex flex-col`,children:w.map(e=>l===e.id?(0,Y.jsx)(`li`,{className:`px-3 py-2`,children:(0,Y.jsx)(li,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>D(e.id,t),onCancel:()=>u(null)})},e.id):(0,Y.jsx)(`li`,{draggable:!S&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&O(h,e.id))},onDragEnd:A,className:G(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,Y.jsx)(di,{entry:e,onInsert:c?()=>{c(e.body),xt(!1)}:null,onCopy:()=>j(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})},e.id))})]})]})]})}function di({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,J.useState)(!1);return(0,Y.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,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:G(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:`Delete`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,Y.jsx)(Ct,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,Y.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[t&&(0,Y.jsx)(fi,{icon:kn,label:`Insert into focused terminal`,onClick:t}),(0,Y.jsx)(fi,{icon:nn,label:`Copy`,onClick:n}),(0,Y.jsx)(fi,{icon:ut,label:`Edit`,onClick:r}),(0,Y.jsx)(fi,{icon:gt,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function fi({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(H,{children:t})]})}var pi=a.parse({});function mi(e,t){let[n,r]=(0,J.useState)(null),i=w(t).data,a=ve(e??void 0,t&&e!==null).data;return(0,J.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=zt(sessionStorage.getItem(Rt(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return _e(e).then(e=>{n||r(e?e.ui_state:pi)}).catch(()=>{n||r(pi)}),()=>{n=!0}},[t,e]),(0,J.useMemo)(()=>{if(!t||e===null||n===null)return null;let o=t=>{if(!i||!a)return!1;let{patch:o,projectBased:s}=Nt(n,t,{alive:new Set(i.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(i.map(e=>[e.id,e.project_id])),projectIds:a.map(e=>e.id),currentProject:null}),c={...n,...o};r(c),se(e,c).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Rt(e),JSON.stringify(c))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}return f().projectBasedLayout!==s&&l({projectBasedLayout:s}),!0},s=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:V(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:V(null),slices:s,capture:()=>({layout_tree:null,active_session:null}),apply:o}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:V(n.layout_tree),slices:s,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),apply:o}},[t,e,n,i,a])}var hi=V(null);function gi(){let e=Pt(),t=Ze(),n=F(),r=It(),i=mi(n,e&&r===null),a=r??i,o=j(n??void 0,void 0).data??[],s=ve(n??void 0,e&&n!==null).data??[],c=ee(),l=S(),u=fe(),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null);(0,J.useEffect)(()=>Le(`layouts.toggle`,Mt),[]),(0,J.useEffect)(()=>{e||(f(``),m(!1),g(null))},[e]);let _=a?.headless===!0,v=a===null||_?null:o.find(e=>e.id===a.layoutRef)??null,y=a!==null&&!_&&(v===null?a.signature!==hi:V(v.layout_tree)!==a.signature),x=e=>{let t=a?.slices?.[e];if(!t)return!1;let n=t.layoutRef===null?null:o.find(e=>e.id===t.layoutRef)??null;return n?V(n.layout_tree)!==t.signature:t.signature!==hi},C=e=>a===null?!1:e.scope===`profile`?a.scope===`profile`&&y:e.project_id===null?!1:a.scope===`project`?!_&&e.project_id===a.projectId?y:x(e.project_id):y||x(e.project_id),w=e=>v!==null&&e.id===v.id,T=e=>(e===null?void 0:s.find(t=>t.id===e)?.name)??`Project`,E=a!==null&&!_&&a.scope===`project`?o.filter(e=>e.scope===`profile`||e.project_id===a.projectId):o,D=[...E.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(E.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:T(e)})).sort((e,t)=>e.name.localeCompare(t.name))],O=h===null?E:h===`profile`?E.filter(e=>e.scope===`profile`):E.filter(e=>e.project_id===h),k=e=>a!==null&&e.scope===a.scope&&(a.scope===`profile`||e.project_id===a.projectId),A=(e,t,r)=>{!a||!n||c.mutate({profile_id:n,scope:a.scope,project_id:a.scope===`project`?a.projectId:void 0,name:e,...t},{onSuccess:e=>{r&&a.apply(e)},onError:e=>z(e)})},M=e=>{if(!a)return;let t=k(e)?e:o.find(t=>t.name===e.name&&k(t));if(!t){A(e.name,a.capture(),!0);return}l.mutate({id:t.id,...a.capture()},{onSuccess:e=>a.apply(e),onError:e=>z(e)})},N=(e,t)=>A(t,{layout_tree:e.layout_tree,active_session:e.active_session},!1),te=e=>{if(a){if(!a.apply(e)){b.error(`Workspace is still loading — try again in a moment`);return}e.project_id!==null&&e.project_id!==a.projectId&&t(`/project/${e.project_id}`),At(!1)}};return(0,Y.jsxs)(qt,{open:e,onOpenChange:At,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsx)(Ut,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(An,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,Y.jsx)(H,{children:`Layouts`})]}),(0,Y.jsxs)(en,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),a!==null&&!_&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(mt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),a===null?(0,Y.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):_?(0,Y.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.`}):(v===null||p)&&(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[v===null&&(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:a.scope===`profile`?`Profile-wide`:`Project`}),(0,Y.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=d.trim();t&&(A(t,a.capture(),!0),f(``),m(!1))},children:[(0,Y.jsx)(B,{autoFocus:p,value:d,placeholder:v===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&m(!1)},className:`h-8 flex-1 text-sm`}),(0,Y.jsx)(R,{size:`sm`,type:`submit`,disabled:!d.trim(),children:`Save`}),v!==null&&(0,Y.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>m(!1),children:`Cancel`})]})]}),D.length>1&&(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:D.map(e=>(0,Y.jsx)(yi,{active:h===e.key,onClick:()=>g(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[O.length===0&&(0,Y.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:h===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,Y.jsx)(`ul`,{className:`flex flex-col`,children:O.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(_i,{layout:e,projectLabel:e.scope===`profile`?null:T(e.project_id),isCurrent:w(e),dirty:y,loadable:a!==null,savable:a!==null&&!_,confirmBeforeLoad:C(e),overwrites:k(e),onLoad:()=>te(e),onRename:t=>l.mutate({id:e.id,name:t}),onDelete:()=>u.mutate(e.id),onSaveAs:()=>M(e),onDuplicate:t=>N(e,t)})},e.id))})]})]})]})}function _i({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,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.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,Y.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||y()},className:G(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[h===null?(0,Y.jsxs)(`p`,{className:G(`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,Y.jsx)(`span`,{className:`text-2xs font-normal`,children:S===`active`?`Active`:`Unsaved`})]}):(0,Y.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,Y.jsx)(B,{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,Y.jsx)(R,{size:`sm`,type:`submit`,disabled:!_.trim(),children:h===`rename`?`Rename`:`Save`})]}),p===`save`?(0,Y.jsx)(vi,{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,Y.jsx)(vi,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{m(null),u()},onCancel:()=>m(null)}):p===`load`?(0,Y.jsx)(vi,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:y,onCancel:()=>m(null)}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[a&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bi,{icon:Nn,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:x}),(0,Y.jsx)(bi,{icon:nn,label:`Duplicate`,onClick:()=>b(`duplicate`)})]}),(0,Y.jsx)(bi,{icon:ut,label:`Rename`,onClick:()=>b(`rename`)}),(0,Y.jsx)(bi,{icon:gt,label:`Delete`,onClick:()=>m(`delete`)})]})]})]})}function vi({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:t}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]})}function yi({active:e,onClick:t,children:n}){return(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:G(`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 bi({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(H,{children:t})]})}var xi=De()!==void 0&&/Mac/.test(navigator.platform),Si=(0,J.lazy)(()=>_(()=>import(`./SettingsDialog-CamnF91I.js`).then(e=>({default:e.SettingsDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])));function Ci(){let e=le();(0,J.useEffect)(()=>{let t=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)})},n=q.onStatus(e=>t(t=>t.id===e.session?{...t,status:e.status,last_activity_at:e.last_activity_at}:t)),r=q.onRenamed(e=>t(t=>t.id===e.session?{...t,title:e.title,agent_title:`agent_title`in e?e.agent_title:t.agent_title,osc_title:`osc_title`in e?e.osc_title:t.osc_title}:t)),i=q.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))}),a=t=>{e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},o=q.onSessionsChanged(e=>a(e.project_ids)),s=q.onSessionSwitched(e=>a([e.target_project]));return()=>{n(),r(),i(),o(),s()}},[e])}function wi(){let e=Me(),t=ae(),[n,r]=(0,J.useState)(!1),i=Ve(e.data),a=n=>{r(!1);let a=n.trim();a!==i&&t.mutate({displayName:a===e.data?.hostname?``:a},{onError:e=>z(e)})},o=!xi&&(0,Y.jsx)(`img`,{src:`/puddle.svg`,alt:`Puddle`,className:`size-4`}),s=G(`flex shrink-0 items-center gap-2`,xi&&`[-webkit-app-region:no-drag]`),c=`truncate text-sm font-semibold text-fg-secondary`;return n&&i!==void 0?(0,Y.jsxs)(`div`,{className:s,children:[o,(0,Y.jsx)(jt,{initial:e.data?.displayName??i,maxLength:64,className:G(c,`w-40`),onCommit:a,onCancel:()=>r(!1)})]}):(0,Y.jsxs)(Ge,{to:`/`,className:G(s,`transition-opacity hover:opacity-70`),title:`All projects`,children:[o,i!==void 0&&(0,Y.jsx)(`span`,{className:c,...Bt(()=>r(!0)),children:i})]})}function Ti(){let e=Xe(),t=je(`palette.toggle`),n=Fe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,Y.jsxs)(`button`,{type:`button`,onClick:wt,className:G(`absolute left-1/2 flex h-6 w-[min(30rem,42%)] -translate-x-1/2 items-center justify-center gap-2 rounded-md bg-ground text-fg-muted transition-colors hover:bg-elevated hover:text-fg-secondary`,xi&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsx)(`span`,{className:`truncate text-xs`,children:r??`Puddle`}),(0,Y.jsx)(`span`,{className:`text-2xs`,children:t})]})}function Ei(){let{fullScreen:e,animate:t}=Se();return(0,Y.jsxs)(`header`,{className:G(`relative flex h-9 shrink-0 items-center gap-3 bg-surface pl-3 pr-3`,xi&&!e&&`pl-[88px] [-webkit-app-region:drag]`,t&&`transition-[padding] duration-200 ease-out`),children:[(0,Y.jsx)(wi,{}),(0,Y.jsx)(Ti,{}),(0,Y.jsxs)(`div`,{className:G(`ml-auto flex items-center`,xi&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(U,{asChild:!0,children:(0,Y.jsxs)(R,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>ft(),children:[(0,Y.jsx)(Fn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,Y.jsx)(H,{children:`Settings`})]}),(0,Y.jsx)(gi,{}),(0,Y.jsx)(ui,{}),(0,Y.jsx)($r,{})]})]})}function Di(){Ci(),ni(),ci();let{handler:e}=St(),t=F(),{pathname:n}=qe(),[r,i]=(0,J.useState)(!1),a=oe(),o=a.data!==void 0&&an(a.data.protocol);return(0,J.useEffect)(()=>{if(!o)return;let e=()=>{let e=u();q.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),g(e)},[o]),(0,Y.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[(0,Y.jsx)(Ei,{}),(0,Y.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,Y.jsx)(dn,{resetOn:n,scope:n.startsWith(`/project/`)?`workspace`:`view`,children:(0,Y.jsx)(Ye,{})})}),(0,Y.jsx)(Jr,{}),(0,Y.jsx)(ti,{}),(0,Y.jsx)(Ur,{onNewSession:e??void 0,onNewProject:()=>i(!0)}),t!==null&&(0,Y.jsx)(rn,{profileId:t,open:r,onOpenChange:i}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Si,{})}),(0,Y.jsx)(Kr,{})]})}function Oi(){return(0,Y.jsx)(Lt,{children:(0,Y.jsx)(Di,{})})}var ki=(0,J.lazy)(()=>_(()=>import(`./Dashboard-B5qWtmwb.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([18,1,2,3,4,6,5,19,10,7,8,9,11,20,16,21,17,22]))),Ai=(0,J.lazy)(()=>_(()=>import(`./Workspace-BmtA0kYQ.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([23,1,2,3,4,5,6,24,10,19,7,8,9,11,12,25,26,27,20,16,28,22,14,15,29,30,31,32]))),ji=new un({defaultOptions:{queries:{retry:1,staleTime:5e3}},mutationCache:new sn({onError:e=>z(e)})});function Mi(){let e=F(),t=Ae(),n=e!==null&&t.data!==void 0&&!t.data.some(t=>t.id===e);return e===null||n?(0,Y.jsx)(In,{}):(0,Y.jsx)(Qe,{useTransitions:!1,children:(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Ke,{children:(0,Y.jsxs)($e,{element:(0,Y.jsx)(Oi,{}),children:[(0,Y.jsx)($e,{path:`/`,element:(0,Y.jsx)(ki,{})}),(0,Y.jsx)($e,{path:`/project/:id`,element:(0,Y.jsx)(Ai,{})}),(0,Y.jsx)($e,{path:`/project/:id/session/:sid`,element:(0,Y.jsx)(Ai,{})})]})})})})}function Ni(){let e=(0,J.useSyncExternalStore)(v.subscribe,v.get);return(0,Y.jsx)(Be,{client:ji,children:(0,Y.jsxs)(kt,{delayDuration:300,children:[(0,Y.jsx)(On,{}),(0,Y.jsx)(dn,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,Y.jsx)(on,{}):(0,Y.jsx)(Mi,{}):(0,Y.jsx)(pn,{})}),(0,Y.jsx)(fn,{})]})})}export{Ni as App};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{A as n,n as r}from"./index-DWTNflld.js";import{at as i,ct as a,nt as o,p as s,pt as c,tt as l,v as u,vt as d}from"./hotkeys-Bx0QQoOi.js";import{a as f,c as p,i as m,n as h,r as g}from"./project-abbrev-BlBz9tcM.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-D6I1fiX4.js";import{t as S}from"./button-CyO-gAMJ.js";import{a as C,c as w,l as T,o as E,s as D,t as O}from"./LazyTerminal-DVeI2Lkl.js";import{n as k}from"./x-CZCUod6A.js";import{A,M as j,c as M,j as N,k as P,n as F,r as I,t as L}from"./context-menu-BuiHQTu6.js";import{r as R}from"./dist-Dt0LZb5E.js";import{t as z}from"./NewProjectDialog-RHBHLIQe.js";import{t as B}from"./ws-BzWidrUz.js";var V=e(t(),1),H=r(),U=!1;function W(){let[e,t]=(0,V.useState)(U),[r,i]=(0,V.useState)(null);(0,V.useEffect)(()=>{if(!e)return;let t=!1;return B.spawnShell(n).then(e=>{t||i(e)}),()=>{t=!0}},[e]);let a=()=>{U=!1,t(!1),i(null)};return{open:e,term:r,toggle:()=>{e?(r&&B.killShell(n,r),a()):(U=!0,t(!0))},onExit:a}}function G({term:e,onExit:t}){return(0,H.jsx)(`div`,{className:`h-72 shrink-0 pb-6`,children:(0,H.jsx)(`div`,{className:`mx-auto size-full max-w-4xl px-6`,children:e!==null&&(0,H.jsx)(O,{stream:`home`,term:e,onExit:t})})})}var K=`group block w-full rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,q=[{status:`running`,colour:`bg-running`},{status:`waiting_input`,colour:`bg-waiting`},{status:`interrupted`,colour:`bg-interrupted`}];function J({project:e,repoPath:t,sessions:n}){let r=n.filter(e=>e.status!==`archived`);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`truncate pr-16 text-base font-semibold text-fg group-hover:text-accent`,children:e.name}),(0,H.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:t??`…`}),(0,H.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3 text-2xs text-fg-muted tabular-nums`,children:[(0,H.jsxs)(`span`,{children:[r.length,` session`,r.length===1?``:`s`]}),q.map(({status:e,colour:t})=>{let n=r.filter(t=>t.status===e).length;return n>0?(0,H.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full ${t}`}),n,` `,e.replace(`_`,` `)]},e):null})]})]})}function Y({icon:e,label:t,onClick:n}){return(0,H.jsx)(`button`,{type:`button`,"aria-label":t,title:t,onClick:e=>{e.preventDefault(),e.stopPropagation(),n()},className:`flex items-center rounded-md p-1.5 text-fg-muted transition-colors hover:bg-ground hover:text-fg`,children:(0,H.jsx)(e,{className:`size-4`})})}function X({project:e,repoPath:t,draggable:n,dragging:r,onDragStart:i,onDragEnd:a,onDragOver:s}){let c=o(),l=d(e.id),[u,f]=(0,V.useState)(!1),[m,D]=(0,V.useState)(e.name),[O,A]=(0,V.useState)(g(e)),P=t=>c.mutate({id:e.id,archived:t},{onError:e=>C(e)}),R=()=>{D(e.name),A(g(e)),f(!0)},z=()=>{let t=m.trim(),n=h(O);if(!t){f(!1);return}let r={...t===e.name?{}:{name:t},...n&&n!==g(e)?{abbrev:n}:{}};if(Object.keys(r).length===0){f(!1);return}c.mutate({id:e.id,...r},{onSuccess:()=>f(!1),onError:e=>C(e)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(L,{children:[(0,H.jsx)(M,{asChild:!0,children:(0,H.jsxs)(`div`,{draggable:n,onDragStart:i,onDragEnd:a,onDragOver:s,className:k(`group relative transition-opacity`,r&&`opacity-50`),children:[(0,H.jsx)(p,{draggable:!1,to:`/project/${e.id}`,className:K,children:(0,H.jsx)(J,{project:e,repoPath:t,sessions:l.data??[]})}),(0,H.jsx)(`div`,{className:`absolute right-2 top-2 hidden gap-0.5 group-hover:flex has-[[data-state=open]]:flex pointer-coarse:flex`,children:e.archived?(0,H.jsx)(Y,{icon:j,label:`Reopen project`,onClick:()=>P(!1)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{icon:E,label:`Edit project`,onClick:R}),(0,H.jsx)(Y,{icon:N,label:`Archive project`,onClick:()=>P(!0)})]})})]})}),(0,H.jsx)(F,{children:e.archived?(0,H.jsxs)(I,{onSelect:()=>P(!1),children:[(0,H.jsx)(j,{}),` Reopen`]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(I,{onSelect:R,children:[(0,H.jsx)(E,{}),` Edit`]}),(0,H.jsxs)(I,{onSelect:()=>P(!0),children:[(0,H.jsx)(N,{}),` Archive`]})]})})]}),(0,H.jsx)(x,{open:u,onOpenChange:f,children:(0,H.jsxs)(y,{children:[(0,H.jsx)(_,{children:(0,H.jsx)(b,{children:`Edit project`})}),(0,H.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),z()},children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(w,{htmlFor:`project-name-${e.id}`,children:`Name`}),(0,H.jsx)(T,{id:`project-name-${e.id}`,value:m,onChange:e=>D(e.target.value),autoFocus:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(w,{htmlFor:`project-abbrev-${e.id}`,children:`Abbreviation`}),(0,H.jsx)(T,{id:`project-abbrev-${e.id}`,maxLength:5,value:O,onChange:e=>A(h(e.target.value)),className:`w-24 uppercase`}),(0,H.jsxs)(`p`,{className:`text-2xs text-fg-muted`,children:[`Up to `,5,` characters — the label on the collapsed sidebar rail.`]})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(w,{className:`text-fg-muted`,children:`Path`}),(0,H.jsx)(`p`,{className:`truncate text-2xs text-fg-muted`,children:t??`…`})]}),(0,H.jsxs)(v,{children:[(0,H.jsx)(S,{type:`button`,variant:`ghost`,onClick:()=>f(!1),children:`Cancel`}),(0,H.jsx)(S,{type:`submit`,disabled:!m.trim()||c.isPending,children:`Save`})]})]})]})})]})}function Z({icon:e,label:t,hint:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,onClick:r,className:`group flex flex-col rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,children:[(0,H.jsxs)(`h2`,{className:`flex items-center gap-2 truncate text-base font-semibold text-fg group-hover:text-accent`,children:[(0,H.jsx)(e,{className:`size-4 shrink-0`}),t]}),(0,H.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:n})]})}function Q(){let e=u(),t=a(e??void 0),n=c(),r=i(e??void 0),o=l(e??``),[d,p]=(0,V.useState)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(!1),y=W(),b=s(`palette.toggle`),x=e=>n.data?.find(t=>t.id===e)?.path,S=t.data??[],C=r.data?.projectOrder??[],w=P(S.filter(e=>!e.archived),C),T=S.filter(e=>e.archived),E=(e,t)=>{e!==t&&o.mutate({projectOrder:A(w.map(e=>e.id),e,t)})};return(0,H.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[S.length===0&&(0,H.jsxs)(`div`,{className:`mb-8 mt-16 flex flex-col items-center gap-3 text-center`,children:[(0,H.jsx)(D,{className:`size-8 text-fg-muted`}),(0,H.jsxs)(`p`,{className:`text-sm text-fg-secondary`,children:[`No projects yet — open one below, or press `,b,`.`]})]}),(0,H.jsxs)(`div`,{className:`grid auto-rows-fr grid-cols-1 gap-3 sm:grid-cols-2`,children:[w.map(e=>(0,H.jsx)(X,{project:e,repoPath:x(e.repo_id),draggable:!0,dragging:h===e.id,onDragStart:()=>g(e.id),onDragEnd:()=>g(null),onDragOver:t=>{t.preventDefault(),h&&h!==e.id&&E(h,e.id)}},e.id)),(0,H.jsx)(Z,{icon:f,label:`Open project`,hint:`Point at a repository on this host`,onClick:()=>p(!0)}),(0,H.jsx)(Z,{icon:m,label:y.open?`Close terminal`:`Open terminal`,hint:y.open?`End the shell below`:`A shell at ~ for cloning repositories`,onClick:y.toggle})]}),T.length>0&&(0,H.jsxs)(`div`,{className:`mt-6`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`flex items-center gap-1.5 px-1 py-1.5 text-2xs uppercase tracking-wide text-fg-muted transition-colors hover:text-fg`,children:[(0,H.jsx)(R,{className:k(`size-3 transition-transform`,_&&`rotate-90`)}),(0,H.jsx)(N,{className:`size-3`}),(0,H.jsx)(`span`,{children:`Archived`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:T.length})]}),_&&(0,H.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:T.map(e=>(0,H.jsx)(X,{project:e,repoPath:x(e.repo_id),draggable:!1,dragging:!1,onDragStart:()=>{},onDragEnd:()=>{},onDragOver:()=>{}},e.id))})]})]})}),y.open&&(0,H.jsx)(G,{term:y.term,onExit:y.onExit}),e!==null&&(0,H.jsx)(z,{profileId:e,open:d,onOpenChange:p})]})}export{Q as Dashboard};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{M as n,n as r}from"./index-BLx1AR0-.js";import{at as i,ct as a,nt as o,p as s,pt as c,tt as l,v as u,vt as d}from"./hotkeys-DbIEec2f.js";import{a as f,c as p,i as m,n as h,r as g}from"./project-abbrev-BU2DBpdq.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-CAMTxigV.js";import{t as S}from"./button-DehrlYw7.js";import{a as C,c as w,l as T,o as E,s as D,t as O}from"./LazyTerminal-BYbPpGEI.js";import{n as k}from"./x-CZCUod6A.js";import{A,M as j,c as M,j as N,k as P,n as F,r as I,t as L}from"./context-menu-BT88Vgia.js";import{r as R}from"./dist-sLs_LTiG.js";import{t as z}from"./NewProjectDialog-D3bNK3u_.js";import{t as B}from"./ws-C-kvwpeD.js";var V=e(t(),1),H=r(),U=!1;function W(){let[e,t]=(0,V.useState)(U),[r,i]=(0,V.useState)(null);(0,V.useEffect)(()=>{if(!e)return;let t=!1;return B.spawnShell(n).then(e=>{t||i(e)}),()=>{t=!0}},[e]);let a=()=>{U=!1,t(!1),i(null)};return{open:e,term:r,toggle:()=>{e?(r&&B.killShell(n,r),a()):(U=!0,t(!0))},onExit:a}}function G({term:e,onExit:t}){return(0,H.jsx)(`div`,{className:`h-72 shrink-0 pb-6`,children:(0,H.jsx)(`div`,{className:`mx-auto size-full max-w-4xl px-6`,children:e!==null&&(0,H.jsx)(O,{stream:`home`,term:e,onExit:t})})})}var K=`group block w-full rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,q=[{status:`running`,colour:`bg-running`},{status:`waiting_input`,colour:`bg-waiting`},{status:`interrupted`,colour:`bg-interrupted`}];function J({project:e,repoPath:t,sessions:n}){let r=n.filter(e=>e.status!==`archived`);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`truncate pr-16 text-base font-semibold text-fg group-hover:text-accent`,children:e.name}),(0,H.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:t??`…`}),(0,H.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3 text-2xs text-fg-muted tabular-nums`,children:[(0,H.jsxs)(`span`,{children:[r.length,` session`,r.length===1?``:`s`]}),q.map(({status:e,colour:t})=>{let n=r.filter(t=>t.status===e).length;return n>0?(0,H.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full ${t}`}),n,` `,e.replace(`_`,` `)]},e):null})]})]})}function Y({icon:e,label:t,onClick:n}){return(0,H.jsx)(`button`,{type:`button`,"aria-label":t,title:t,onClick:e=>{e.preventDefault(),e.stopPropagation(),n()},className:`flex items-center rounded-md p-1.5 text-fg-muted transition-colors hover:bg-ground hover:text-fg`,children:(0,H.jsx)(e,{className:`size-4`})})}function X({project:e,repoPath:t,draggable:n,dragging:r,onDragStart:i,onDragEnd:a,onDragOver:s}){let c=o(),l=d(e.id),[u,f]=(0,V.useState)(!1),[m,D]=(0,V.useState)(e.name),[O,A]=(0,V.useState)(g(e)),P=t=>c.mutate({id:e.id,archived:t},{onError:e=>C(e)}),R=()=>{D(e.name),A(g(e)),f(!0)},z=()=>{let t=m.trim(),n=h(O);if(!t){f(!1);return}let r={...t===e.name?{}:{name:t},...n&&n!==g(e)?{abbrev:n}:{}};if(Object.keys(r).length===0){f(!1);return}c.mutate({id:e.id,...r},{onSuccess:()=>f(!1),onError:e=>C(e)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(L,{children:[(0,H.jsx)(M,{asChild:!0,children:(0,H.jsxs)(`div`,{draggable:n,onDragStart:i,onDragEnd:a,onDragOver:s,className:k(`group relative transition-opacity`,r&&`opacity-50`),children:[(0,H.jsx)(p,{draggable:!1,to:`/project/${e.id}`,className:K,children:(0,H.jsx)(J,{project:e,repoPath:t,sessions:l.data??[]})}),(0,H.jsx)(`div`,{className:`absolute right-2 top-2 hidden gap-0.5 group-hover:flex has-[[data-state=open]]:flex pointer-coarse:flex`,children:e.archived?(0,H.jsx)(Y,{icon:j,label:`Reopen project`,onClick:()=>P(!1)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{icon:E,label:`Edit project`,onClick:R}),(0,H.jsx)(Y,{icon:N,label:`Archive project`,onClick:()=>P(!0)})]})})]})}),(0,H.jsx)(F,{children:e.archived?(0,H.jsxs)(I,{onSelect:()=>P(!1),children:[(0,H.jsx)(j,{}),` Reopen`]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(I,{onSelect:R,children:[(0,H.jsx)(E,{}),` Edit`]}),(0,H.jsxs)(I,{onSelect:()=>P(!0),children:[(0,H.jsx)(N,{}),` Archive`]})]})})]}),(0,H.jsx)(x,{open:u,onOpenChange:f,children:(0,H.jsxs)(y,{children:[(0,H.jsx)(_,{children:(0,H.jsx)(b,{children:`Edit project`})}),(0,H.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),z()},children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(w,{htmlFor:`project-name-${e.id}`,children:`Name`}),(0,H.jsx)(T,{id:`project-name-${e.id}`,value:m,onChange:e=>D(e.target.value),autoFocus:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(w,{htmlFor:`project-abbrev-${e.id}`,children:`Abbreviation`}),(0,H.jsx)(T,{id:`project-abbrev-${e.id}`,maxLength:5,value:O,onChange:e=>A(h(e.target.value)),className:`w-24 uppercase`}),(0,H.jsxs)(`p`,{className:`text-2xs text-fg-muted`,children:[`Up to `,5,` characters — the label on the collapsed sidebar rail.`]})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(w,{className:`text-fg-muted`,children:`Path`}),(0,H.jsx)(`p`,{className:`truncate text-2xs text-fg-muted`,children:t??`…`})]}),(0,H.jsxs)(v,{children:[(0,H.jsx)(S,{type:`button`,variant:`ghost`,onClick:()=>f(!1),children:`Cancel`}),(0,H.jsx)(S,{type:`submit`,disabled:!m.trim()||c.isPending,children:`Save`})]})]})]})})]})}function Z({icon:e,label:t,hint:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,onClick:r,className:`group flex flex-col rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,children:[(0,H.jsxs)(`h2`,{className:`flex items-center gap-2 truncate text-base font-semibold text-fg group-hover:text-accent`,children:[(0,H.jsx)(e,{className:`size-4 shrink-0`}),t]}),(0,H.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:n})]})}function Q(){let e=u(),t=a(e??void 0),n=c(),r=i(e??void 0),o=l(e??``),[d,p]=(0,V.useState)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(!1),y=W(),b=s(`palette.toggle`),x=e=>n.data?.find(t=>t.id===e)?.path,S=t.data??[],C=r.data?.projectOrder??[],w=P(S.filter(e=>!e.archived),C),T=S.filter(e=>e.archived),E=(e,t)=>{e!==t&&o.mutate({projectOrder:A(w.map(e=>e.id),e,t)})};return(0,H.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[S.length===0&&(0,H.jsxs)(`div`,{className:`mb-8 mt-16 flex flex-col items-center gap-3 text-center`,children:[(0,H.jsx)(D,{className:`size-8 text-fg-muted`}),(0,H.jsxs)(`p`,{className:`text-sm text-fg-secondary`,children:[`No projects yet — open one below, or press `,b,`.`]})]}),(0,H.jsxs)(`div`,{className:`grid auto-rows-fr grid-cols-1 gap-3 sm:grid-cols-2`,children:[w.map(e=>(0,H.jsx)(X,{project:e,repoPath:x(e.repo_id),draggable:!0,dragging:h===e.id,onDragStart:()=>g(e.id),onDragEnd:()=>g(null),onDragOver:t=>{t.preventDefault(),h&&h!==e.id&&E(h,e.id)}},e.id)),(0,H.jsx)(Z,{icon:f,label:`Open project`,hint:`Point at a repository on this host`,onClick:()=>p(!0)}),(0,H.jsx)(Z,{icon:m,label:y.open?`Close terminal`:`Open terminal`,hint:y.open?`End the shell below`:`A shell at ~ for cloning repositories`,onClick:y.toggle})]}),T.length>0&&(0,H.jsxs)(`div`,{className:`mt-6`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`flex items-center gap-1.5 px-1 py-1.5 text-2xs uppercase tracking-wide text-fg-muted transition-colors hover:text-fg`,children:[(0,H.jsx)(R,{className:k(`size-3 transition-transform`,_&&`rotate-90`)}),(0,H.jsx)(N,{className:`size-3`}),(0,H.jsx)(`span`,{children:`Archived`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:T.length})]}),_&&(0,H.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:T.map(e=>(0,H.jsx)(X,{project:e,repoPath:x(e.repo_id),draggable:!1,dragging:!1,onDragStart:()=>{},onDragEnd:()=>{},onDragOver:()=>{}},e.id))})]})]})}),y.open&&(0,H.jsx)(G,{term:y.term,onExit:y.onExit}),e!==null&&(0,H.jsx)(z,{profileId:e,open:d,onOpenChange:p})]})}export{Q as Dashboard};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n}from"./index-DWTNflld.js";import{i as r,t as i,u as a}from"./buffer-store-DcARHjQ8.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./dialog-D6I1fiX4.js";import{t as f}from"./button-CyO-gAMJ.js";import{t as p}from"./x-CZCUod6A.js";import{t as m}from"./createLucideIcon-DyMAgLa3.js";import{t as h}from"./drafts-B_tChlzR.js";import{t as g}from"./editor-sync-W1bamxAP.js";var _=m(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),v=e(t(),1),y=n();function b(e,t,n){let o=i(e,t,n);return(0,v.useSyncExternalStore)((0,v.useCallback)(e=>a(o,e),[o]),()=>r(o))}function x({session:e,path:t,kind:n,root:r}){return b(e,t,r)&&n!==`commit`?(0,y.jsx)(_,{"aria-hidden":!0,className:`size-2 shrink-0 fill-current text-fg-muted group-hover:hidden`}):null}function S({session:e,path:t,kind:n,root:r,label:i,onClose:a}){let m=b(e,t,r)&&n!==`commit`,[_,x]=(0,v.useState)(!1),S=()=>m?x(!0):a();return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S()},className:`hidden size-4 items-center justify-center rounded-sm text-fg-muted transition-colors hover:text-fg group-hover:flex pointer-coarse:flex`,"aria-label":`Close ${i}`,children:(0,y.jsx)(p,{className:`size-3`})}),(0,y.jsx)(d,{open:_,onOpenChange:e=>!e&&x(!1),children:(0,y.jsxs)(c,{children:[(0,y.jsxs)(o,{children:[(0,y.jsxs)(l,{children:[`Discard changes to `,i,`?`]}),(0,y.jsx)(u,{children:`This file has unsaved changes. Closing the tab will discard them.`})]}),(0,y.jsxs)(s,{children:[(0,y.jsx)(f,{variant:`ghost`,onClick:()=>x(!1),children:`Keep editing`}),(0,y.jsx)(f,{variant:`danger`,onClick:()=>{h(e,t,r),g(e,t,r),x(!1),a()},children:`Discard`})]})]})})]})}export{x as EditorDirtyDot,S as EditorTabClose};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n}from"./index-BLx1AR0-.js";import{i as r,t as i,u as a}from"./buffer-store--4yU4YqM.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./dialog-CAMTxigV.js";import{t as f}from"./button-DehrlYw7.js";import{t as p}from"./x-CZCUod6A.js";import{t as m}from"./createLucideIcon-DyMAgLa3.js";import{t as h}from"./drafts-B_tChlzR.js";import{t as g}from"./editor-sync-W1bamxAP.js";var _=m(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),v=e(t(),1),y=n();function b(e,t,n){let o=i(e,t,n);return(0,v.useSyncExternalStore)((0,v.useCallback)(e=>a(o,e),[o]),()=>r(o))}function x({session:e,path:t,kind:n,root:r}){return b(e,t,r)&&n!==`commit`?(0,y.jsx)(_,{"aria-hidden":!0,className:`size-2 shrink-0 fill-current text-fg-muted group-hover:hidden`}):null}function S({session:e,path:t,kind:n,root:r,label:i,onClose:a}){let m=b(e,t,r)&&n!==`commit`,[_,x]=(0,v.useState)(!1),S=()=>m?x(!0):a();return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S()},className:`hidden size-4 items-center justify-center rounded-sm text-fg-muted transition-colors hover:text-fg group-hover:flex pointer-coarse:flex`,"aria-label":`Close ${i}`,children:(0,y.jsx)(p,{className:`size-3`})}),(0,y.jsx)(d,{open:_,onOpenChange:e=>!e&&x(!1),children:(0,y.jsxs)(c,{children:[(0,y.jsxs)(o,{children:[(0,y.jsxs)(l,{children:[`Discard changes to `,i,`?`]}),(0,y.jsx)(u,{children:`This file has unsaved changes. Closing the tab will discard them.`})]}),(0,y.jsxs)(s,{children:[(0,y.jsx)(f,{variant:`ghost`,onClick:()=>x(!1),children:`Keep editing`}),(0,y.jsx)(f,{variant:`danger`,onClick:()=>{h(e,t,r),g(e,t,r),x(!1),a()},children:`Discard`})]})]})})]})}export{x as EditorDirtyDot,S as EditorTabClose};