@puddle-code/cli 0.3.0 → 0.3.2

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 (135) hide show
  1. package/CHANGELOG.md +7 -3
  2. package/README.md +2 -2
  3. package/dist/host-control.mjs +27 -3
  4. package/dist/index.js +40 -10
  5. package/dist/install-cli.sh +16 -5
  6. package/dist/public/assets/App-D_YTB3jH.js +2 -0
  7. package/dist/public/assets/{Dashboard-DMEBtYwv.js → Dashboard-Djw9nPV_.js} +1 -1
  8. package/dist/public/assets/{EditorTabClose-PbgNs_rN.js → EditorTabClose-BCunnuEj.js} +1 -1
  9. package/dist/public/assets/{FindWidget-ZDHywlX4.js → FindWidget-Ch-y_4eH.js} +1 -1
  10. package/dist/public/assets/{LazyTerminal-DRgaFViU.js → LazyTerminal-BN3rEDcD.js} +2 -2
  11. package/dist/public/assets/{ModelRefcount-CI3cYeQp.js → ModelRefcount-Dkp1avzM.js} +1 -1
  12. package/dist/public/assets/{NewProjectDialog-Bhfj_sYl.js → NewProjectDialog-BK_gfWmL.js} +1 -1
  13. package/dist/public/assets/{PaneEditorBody-Bz74yrKU.js → PaneEditorBody-ClWRSuGV.js} +3 -3
  14. package/dist/public/assets/{PdfViewer-73_UlYnM.js → PdfViewer-CbC1KAkq.js} +2 -2
  15. package/dist/public/assets/{SettingsDialog-DJmvzJHQ.js → SettingsDialog-DsmyHhQB.js} +1 -1
  16. package/dist/public/assets/{Terminal-BwuoWKED.js → Terminal-CDnGRsgd.js} +4 -4
  17. package/dist/public/assets/Workspace-CmclLFK3.js +20 -0
  18. package/dist/public/assets/{abnfDiagram-VCTEODGH-AawOhIcj.js → abnfDiagram-VCTEODGH-Aa5uAdnV.js} +1 -1
  19. package/dist/public/assets/architecture-7GRP2DOG-D3814jvH.js +1 -0
  20. package/dist/public/assets/{architectureDiagram-5GKGNRK7-D9vP5DO8.js → architectureDiagram-5GKGNRK7-B0d475xG.js} +1 -1
  21. package/dist/public/assets/{blockDiagram-I7D4REHJ-Cm9i3cTT.js → blockDiagram-I7D4REHJ-NHlOsaCN.js} +1 -1
  22. package/dist/public/assets/{buffer-store-BIpSx_-b.js → buffer-store-BtRP7zZm.js} +2 -2
  23. package/dist/public/assets/{button-CgZcwDne.js → button-D3DTuFk3.js} +1 -1
  24. package/dist/public/assets/{c4Diagram-7LVT6UL2-BiN1-NKB.js → c4Diagram-7LVT6UL2-ZLfrwKT4.js} +1 -1
  25. package/dist/public/assets/channel-C6g1aWXR.js +1 -0
  26. package/dist/public/assets/{chunk-2E4U76K2-BxAMvG2q.js → chunk-2E4U76K2-DyVxGuz5.js} +1 -1
  27. package/dist/public/assets/{chunk-4HAMMTFA-D4UgoMR5.js → chunk-4HAMMTFA-Brp_wxZT.js} +1 -1
  28. package/dist/public/assets/{chunk-75Z2AOVW-ViSC5KeO.js → chunk-75Z2AOVW-9vLeKuoB.js} +1 -1
  29. package/dist/public/assets/{chunk-CLGD4ZFX-C1obqh7u.js → chunk-CLGD4ZFX-B8Oa13vy.js} +1 -1
  30. package/dist/public/assets/{chunk-DU6HZSFF-Dd9xUi9L.js → chunk-DU6HZSFF-ziCxw8j9.js} +1 -1
  31. package/dist/public/assets/{chunk-F27PBJKO-S5xJlLKg.js → chunk-F27PBJKO-I29_mrbz.js} +1 -1
  32. package/dist/public/assets/{chunk-GMAD6QVW-DXbO7ojE.js → chunk-GMAD6QVW-ZzqGXNRY.js} +1 -1
  33. package/dist/public/assets/{chunk-GVQU2GXP-vZ5Z6XwC.js → chunk-GVQU2GXP-DiJctosx.js} +1 -1
  34. package/dist/public/assets/{chunk-IMKFNOWR-BGcGac3f.js → chunk-IMKFNOWR-yuPnJltA.js} +1 -1
  35. package/dist/public/assets/{chunk-L3NEJ4N5-BfxBma0T.js → chunk-L3NEJ4N5-DB3LOw2c.js} +1 -1
  36. package/dist/public/assets/{chunk-OSK3NFVY-BaWjSKfn.js → chunk-OSK3NFVY-ygO9ccvX.js} +1 -1
  37. package/dist/public/assets/{chunk-P2QGCYS3-Ce8Ukv1J.js → chunk-P2QGCYS3-CaO30dnF.js} +1 -1
  38. package/dist/public/assets/{chunk-POPQ4Y6H-lrRlaehc.js → chunk-POPQ4Y6H-BS_wlBQ7.js} +1 -1
  39. package/dist/public/assets/{chunk-PWAF6VOD-DcoK5-E2.js → chunk-PWAF6VOD-BYtVJDwT.js} +1 -1
  40. package/dist/public/assets/{chunk-SHT3W25Y-BWdHabuP.js → chunk-SHT3W25Y-DbWwFCez.js} +1 -1
  41. package/dist/public/assets/{chunk-SVP7TREG-CfpAvBiO.js → chunk-SVP7TREG-DLDU3lFF.js} +1 -1
  42. package/dist/public/assets/{chunk-TICWLB2K-BnqQqZIp.js → chunk-TICWLB2K-Bo_jKuAY.js} +1 -1
  43. package/dist/public/assets/{chunk-TLUHSLCS-Cd6EShzW.js → chunk-TLUHSLCS-BGFLoTUj.js} +2 -2
  44. package/dist/public/assets/classDiagram-ZZMXUADV-BiQrxRCS.js +1 -0
  45. package/dist/public/assets/classDiagram-v2-VYDZK3BY-BiQrxRCS.js +1 -0
  46. package/dist/public/assets/{context-menu-CtKnUzHa.js → context-menu-CwR-PGrS.js} +1 -1
  47. package/dist/public/assets/{copy-Xz4fK2YI.js → copy-ZzKoF5dj.js} +1 -1
  48. package/dist/public/assets/{cssMode-CNBJ-DrN.js → cssMode-DBrJeag9.js} +1 -1
  49. package/dist/public/assets/{cynefin-OW5HDTMX-C1-MjjCZ.js → cynefin-OW5HDTMX-DsXo9hDP.js} +1 -1
  50. package/dist/public/assets/{cynefinDiagram-5FMLGOSQ-xt5hQJ88.js → cynefinDiagram-5FMLGOSQ-CNr5UISm.js} +1 -1
  51. package/dist/public/assets/{dagre-GXQ25YYZ-Bgahh86t.js → dagre-GXQ25YYZ-DJ40uVpF.js} +1 -1
  52. package/dist/public/assets/{diagram-S7CK7UJ4-Djip7YHP.js → diagram-S7CK7UJ4-CakLFIEW.js} +1 -1
  53. package/dist/public/assets/{diagram-UQ7AKVKN-StD7DYFa.js → diagram-UQ7AKVKN-Blm9jWHJ.js} +1 -1
  54. package/dist/public/assets/{diagram-VSXAHHWV-C6W2XMTF.js → diagram-VSXAHHWV-BzXCydDQ.js} +1 -1
  55. package/dist/public/assets/{diagram-VX7I27RA-C5rBIjxM.js → diagram-VX7I27RA-VJip2Tpi.js} +1 -1
  56. package/dist/public/assets/{diagram-Z3DM3KII-DDzmZnRU.js → diagram-Z3DM3KII-CPQuWy39.js} +1 -1
  57. package/dist/public/assets/{dialog-_JRACgt4.js → dialog-BoaHxScl.js} +1 -1
  58. package/dist/public/assets/{disclosure-DBXM9uBm.js → disclosure-DNbP2Rp4.js} +1 -1
  59. package/dist/public/assets/{dist-CzEdee3K.js → dist-CQZ_zg-s.js} +1 -1
  60. package/dist/public/assets/{dist-Bl7vUoam.js → dist-DUfD4S2p.js} +1 -1
  61. package/dist/public/assets/{ebnfDiagram-PWID7BFC-TJlh5Fea.js → ebnfDiagram-PWID7BFC-x8Hm-8FP.js} +1 -1
  62. package/dist/public/assets/{erDiagram-RLTQ6QDP-BSNVCw_x.js → erDiagram-RLTQ6QDP-DqwnnH7t.js} +1 -1
  63. package/dist/public/assets/{errors-BzfxU_Kw.js → errors-BkbAF9Bu.js} +1 -1
  64. package/dist/public/assets/eventmodeling-NTZA5JFV-DE-zSV6F.js +1 -0
  65. package/dist/public/assets/flowDiagram-HODETNUW-Cn9XuALP.js +1 -0
  66. package/dist/public/assets/{ganttDiagram-EL5Y4UJY-BGFNgCoM.js → ganttDiagram-EL5Y4UJY-BvWbPqg4.js} +1 -1
  67. package/dist/public/assets/{gitGraph-4MIJSDKK-Du3WBCxU.js → gitGraph-4MIJSDKK-DKeR8Wjx.js} +1 -1
  68. package/dist/public/assets/{gitGraphDiagram-WWUBYQGX-Dq_yAVmM.js → gitGraphDiagram-WWUBYQGX-CPJ482wi.js} +1 -1
  69. package/dist/public/assets/{htmlMode-BWm5ayBQ.js → htmlMode-CKCaIwmL.js} +1 -1
  70. package/dist/public/assets/{index-BP-EF5G2.js → index-CPKHBs7z.js} +5 -5
  71. package/dist/public/assets/{info-A6RAGUB7-V0hlAV3d.js → info-A6RAGUB7-CYKUxPau.js} +1 -1
  72. package/dist/public/assets/{infoDiagram-27XIBGKW-DZM1jHkq.js → infoDiagram-27XIBGKW-5qHuu76B.js} +1 -1
  73. package/dist/public/assets/{ishikawaDiagram-5VMMS53U-CZlO72MU.js → ishikawaDiagram-5VMMS53U-Bq13tOFJ.js} +1 -1
  74. package/dist/public/assets/{journeyDiagram-3NMN7TZE-DZZieltZ.js → journeyDiagram-3NMN7TZE-7GJvjukT.js} +1 -1
  75. package/dist/public/assets/{jsonMode-DA3Di61-.js → jsonMode-C6jAdn8r.js} +1 -1
  76. package/dist/public/assets/{kanban-definition-UXKFOSKX-BAFfgDCD.js → kanban-definition-UXKFOSKX-BIFvSwV9.js} +1 -1
  77. package/dist/public/assets/{line-DNRJuk5l.js → line-BjlS8UJs.js} +1 -1
  78. package/dist/public/assets/{markdown-mermaid-zldCuMow.js → markdown-mermaid-B_y_6yBe.js} +2 -2
  79. package/dist/public/assets/{math-Bl0zHVK2.js → math-BNNuKpUP.js} +1 -1
  80. package/dist/public/assets/{media-refresh-store-BemN_6sc.js → media-refresh-store-BnZNW8xS.js} +1 -1
  81. package/dist/public/assets/{mermaid-parser.core-DpOHgT8D.js → mermaid-parser.core-BwJKOdFv.js} +3 -3
  82. package/dist/public/assets/{mermaid.core-DuO1Atct.js → mermaid.core-Cii531li.js} +3 -3
  83. package/dist/public/assets/{mindmap-definition-YA3MSWOX-Bbgshnhk.js → mindmap-definition-YA3MSWOX-Cy4SIHHe.js} +1 -1
  84. package/dist/public/assets/{notification-delivery-DehaYHWS.js → notification-delivery-Cn-YcMec.js} +1 -1
  85. package/dist/public/assets/{packet-AYTQ26CC-H2b8zBMM.js → packet-AYTQ26CC-y8aHtpCT.js} +1 -1
  86. package/dist/public/assets/{pdf-DTc2umrm.js → pdf-Cnp8bCq1.js} +1 -1
  87. package/dist/public/assets/{pegDiagram-XKGWAZYB-BKdl5Qrn.js → pegDiagram-XKGWAZYB-yIL7Oty_.js} +1 -1
  88. package/dist/public/assets/{pie-WAS4IAKB-SB8x1Dpp.js → pie-WAS4IAKB-DNZ4gYKN.js} +1 -1
  89. package/dist/public/assets/{pieDiagram-E7YTZNPT-YXMNp-5O.js → pieDiagram-E7YTZNPT-CUwYqrWF.js} +1 -1
  90. package/dist/public/assets/{project-abbrev-D7aa-LGS.js → project-abbrev-B5CMO00I.js} +1 -1
  91. package/dist/public/assets/{protocol-support-Dm8bEo7Y.js → protocol-support-hVrRUHAd.js} +1 -1
  92. package/dist/public/assets/{quadrantDiagram-AXDQQJYC-B2TAChhA.js → quadrantDiagram-AXDQQJYC-2BigfRRK.js} +1 -1
  93. package/dist/public/assets/{radar-RG4KPBEZ-D2xzXNL8.js → radar-RG4KPBEZ-DCE8-Z-G.js} +1 -1
  94. package/dist/public/assets/{railroad-74A4TZTK-CKug6hj8.js → railroad-74A4TZTK-BfnC2It7.js} +1 -1
  95. package/dist/public/assets/railroad-abnf-HS5TGJTU-C8QChwRk.js +1 -0
  96. package/dist/public/assets/railroad-ebnf-LZEXJU2U-DN6nLE-f.js +1 -0
  97. package/dist/public/assets/railroad-peg-WCYAUIDC-emPIg_g-.js +1 -0
  98. package/dist/public/assets/{railroadDiagram-O6MQD6OU-Bft2oh-d.js → railroadDiagram-O6MQD6OU-DpX2WbJ5.js} +1 -1
  99. package/dist/public/assets/{requirementDiagram-BXWQKSXE-e0GCEfhM.js → requirementDiagram-BXWQKSXE-BfBBVeo_.js} +1 -1
  100. package/dist/public/assets/{sankeyDiagram-P5KCCOFB-Csb70YNA.js → sankeyDiagram-P5KCCOFB-BHy22mhl.js} +1 -1
  101. package/dist/public/assets/{scroll-restoration-D7f4DDsJ.js → scroll-restoration-rhyw8Ck0.js} +1 -1
  102. package/dist/public/assets/{selection-actions-D5wKfiBu.js → selection-actions-BDJnKwuj.js} +1 -1
  103. package/dist/public/assets/{sequenceDiagram-WJ2MYXX4-DcnD8T30.js → sequenceDiagram-WJ2MYXX4-Dhgnxvrt.js} +1 -1
  104. package/dist/public/assets/{stateDiagram-D77RDMKH-GnwFUlNg.js → stateDiagram-D77RDMKH-CPWwa5Aj.js} +1 -1
  105. package/dist/public/assets/stateDiagram-v2-MP3YSRHH-CmGYleZg.js +1 -0
  106. package/dist/public/assets/{swimlanes-42K2YHIH-CPq_eKyi.js → swimlanes-42K2YHIH-DsqTASlp.js} +1 -1
  107. package/dist/public/assets/swimlanesDiagram-VR7AAH4N-CUahIPDv.js +8 -0
  108. package/dist/public/assets/{switch-DZbOKnZ0.js → switch-DGZtVofo.js} +1 -1
  109. package/dist/public/assets/{timeline-definition-24CTP7MA-DjUPAJJx.js → timeline-definition-24CTP7MA-B7hjD0KJ.js} +1 -1
  110. package/dist/public/assets/{treeView-Q6P3EWNA-DBuhlxaq.js → treeView-Q6P3EWNA-WU6eWUi6.js} +1 -1
  111. package/dist/public/assets/{treemap-WGGIJYW6-3TKwSIeh.js → treemap-WGGIJYW6-BNZcLwqI.js} +1 -1
  112. package/dist/public/assets/{tsMode-BYwFH3pC.js → tsMode-CillYPbz.js} +1 -1
  113. package/dist/public/assets/{use-ui-state-BXROVbIw.js → use-ui-state-BZeOd2de.js} +1 -1
  114. package/dist/public/assets/{vennDiagram-4TSXK5OY-oDrGN_Dh.js → vennDiagram-4TSXK5OY-BvS0i65j.js} +1 -1
  115. package/dist/public/assets/{view-state-store-vUrDt7wu.js → view-state-store-BEl9Q1Jm.js} +1 -1
  116. package/dist/public/assets/{wardley-WFR3VGLG-Br5CacuJ.js → wardley-WFR3VGLG-ChvHhLGz.js} +1 -1
  117. package/dist/public/assets/{wardleyDiagram-VM6X3IG4-Cw_uOLXA.js → wardleyDiagram-VM6X3IG4-CxconmGB.js} +1 -1
  118. package/dist/public/assets/{ws-Ug1Tr2sh.js → ws-B6RLTvWI.js} +1 -1
  119. package/dist/public/assets/{xychartDiagram-S5SC5T6Z-Cl8gNx_J.js → xychartDiagram-S5SC5T6Z-DSJMW0r7.js} +1 -1
  120. package/dist/public/index.html +1 -1
  121. package/dist/{puddlang.js → pudl.js} +42 -17
  122. package/package.json +2 -2
  123. package/dist/public/assets/App-XpQccO6u.js +0 -2
  124. package/dist/public/assets/Workspace-DPL1IKA6.js +0 -20
  125. package/dist/public/assets/architecture-7GRP2DOG-BbAArV9u.js +0 -1
  126. package/dist/public/assets/channel-CUWW1WRo.js +0 -1
  127. package/dist/public/assets/classDiagram-ZZMXUADV-Cve4a5Gc.js +0 -1
  128. package/dist/public/assets/classDiagram-v2-VYDZK3BY-Cve4a5Gc.js +0 -1
  129. package/dist/public/assets/eventmodeling-NTZA5JFV-DZ8G1RJ1.js +0 -1
  130. package/dist/public/assets/flowDiagram-HODETNUW-Dd9WpTU6.js +0 -1
  131. package/dist/public/assets/railroad-abnf-HS5TGJTU-cj9XZHow.js +0 -1
  132. package/dist/public/assets/railroad-ebnf-LZEXJU2U-CCIfyLjg.js +0 -1
  133. package/dist/public/assets/railroad-peg-WCYAUIDC-DkxYDi7O.js +0 -1
  134. package/dist/public/assets/stateDiagram-v2-MP3YSRHH-Bktkoy9c.js +0 -1
  135. package/dist/public/assets/swimlanesDiagram-VR7AAH4N-BmjIwfwd.js +0 -8
package/CHANGELOG.md CHANGED
@@ -4,12 +4,16 @@ Archived release changelog. Governance lives in CLAUDE.md §"Changelog disciplin
4
4
 
5
5
  # Changelog
6
6
 
7
- ## [0.3.0] — 2026-10-14
7
+ ## [0.3.2] — 2026-10-14
8
8
 
9
9
  ### Added
10
10
 
11
- - Add puddlang: host-executed TypeScript agent workflows, Codex exact turns and structured replies, profile/account selection, durable run records, cancellation, CLI and stdio MCP access; bundle `puddlang` with existing CLI installers (daemon protocol 23.0, remote protocol unchanged).
11
+ - Support Claude Code, Codex, OpenCode and Gemini CLI in Puddlang with per-agent interactive or headless execution, persisted mode selection, exact reply correlation and account-preserving native conversation resume (daemon protocol 24.0).
12
12
 
13
13
  ### Changed
14
14
 
15
- - Bump daemon/cockpit protocol to 23.0 for the puddlang rollout; require matching clients and hosts through the existing approved upgrade flow, while retaining remote transport protocol 3.
15
+ - Rename Puddlang's `scripted` execution mode to `headless` across spawn options, session state, agent modules, examples and documentation; migrate existing placements and advance daemon protocol to 24.0 and remote protocol to 4.
16
+
17
+ ### Fixed
18
+
19
+ - Include the Puddlang runner and its imports in standalone daemon archives, with a release smoke test that executes a TypeScript programme using both `puddlang` and `zod`.
package/README.md CHANGED
@@ -29,8 +29,8 @@ installer (replace the example host):
29
29
  curl -fsSL https://app.example.com/install.sh | sh
30
30
  ```
31
31
 
32
- The CLI also includes `puddlang`, a TypeScript interface for coder/reviewer loops
33
- and other agent workflows, available through the shell or stdio MCP. See the
32
+ The CLI also includes `pudl`, which runs puddlang programmes for coder/reviewer
33
+ loops and other agent workflows through the shell or stdio MCP. See the
34
34
  [puddlang guide](docs/puddlang.md) for setup, examples and initial limitations.
35
35
 
36
36
  This installs the CLI under `~/.local/share/puddle/cli` and its launcher at
@@ -14602,7 +14602,20 @@ var agentLifecycleSignalSchema = external_exports.object({
14602
14602
  native_created_at: external_exports.iso.datetime({ offset: true }).optional(),
14603
14603
  native_updated_at: external_exports.iso.datetime({ offset: true }).optional()
14604
14604
  });
14605
- var agentSignalRequestSchema = external_exports.union([statusSignalSchema, agentLifecycleSignalSchema]);
14605
+ var agentTurnSignalSchema = external_exports.object({
14606
+ nonce: external_exports.string().min(16).max(200),
14607
+ event: external_exports.enum(["turn_start", "turn_complete", "turn_failed"]),
14608
+ agent_session_ref: external_exports.string().min(1).max(200),
14609
+ turn_id: external_exports.string().min(1).max(200),
14610
+ prompt_hash: external_exports.string().regex(/^[a-f0-9]{64}$/).optional(),
14611
+ reply: external_exports.string().max(256 * 1024).refine((value) => new TextEncoder().encode(value).length <= 256 * 1024).optional(),
14612
+ error: external_exports.string().max(4096).optional()
14613
+ });
14614
+ var agentSignalRequestSchema = external_exports.union([
14615
+ statusSignalSchema,
14616
+ agentLifecycleSignalSchema,
14617
+ agentTurnSignalSchema
14618
+ ]);
14606
14619
 
14607
14620
  // ../shared/src/api/config.ts
14608
14621
  var fields = {
@@ -14941,6 +14954,7 @@ var sessionStatusSchema = external_exports.enum([
14941
14954
  "archived"
14942
14955
  ]);
14943
14956
  var sessionKindSchema = external_exports.enum(["agent", "terminal"]);
14957
+ var agentModeSchema = external_exports.enum(["interactive", "headless"]);
14944
14958
  var sessionSchema = external_exports.object({
14945
14959
  id: sessionId,
14946
14960
  project_id: projectId,
@@ -14954,6 +14968,8 @@ var sessionSchema = external_exports.object({
14954
14968
  kind: sessionKindSchema,
14955
14969
  /** Null for terminal sessions, which run a plain shell rather than an agent. */
14956
14970
  agent_type: external_exports.string().nullable(),
14971
+ /** Native TUI or structured CLI execution with a terminal transcript. */
14972
+ agent_mode: agentModeSchema.optional(),
14957
14973
  /** Live foreground agent in a terminal session; icon hint only, never persisted. */
14958
14974
  detected_agent_type: external_exports.string().nullable().optional(),
14959
14975
  agent_session_ref: external_exports.string().nullable(),
@@ -15816,7 +15832,7 @@ var wsServerMessageSchema = external_exports.discriminatedUnion("t", [
15816
15832
  ]);
15817
15833
 
15818
15834
  // ../shared/src/remote/protocol.ts
15819
- var REMOTE_PROTOCOL_VERSION = 3;
15835
+ var REMOTE_PROTOCOL_VERSION = 4;
15820
15836
  var REMOTE_POLICY = {
15821
15837
  chunkBytes: 32 * 1024,
15822
15838
  frameBytes: 48 * 1024,
@@ -16196,6 +16212,7 @@ var sourceSchema = external_exports.string().min(1).max(PUDDLANG_MAX_SOURCE).ref
16196
16212
  );
16197
16213
  var puddlangSpawnSchema = external_exports.object({
16198
16214
  agent: external_exports.string().min(1).max(100),
16215
+ mode: agentModeSchema.optional(),
16199
16216
  account: external_exports.union([external_exports.string().min(1).max(100), external_exports.number().int().positive()]).optional(),
16200
16217
  project: external_exports.string().min(1).max(200).optional(),
16201
16218
  worktree: external_exports.string().min(1).max(4096).optional(),
@@ -16271,7 +16288,14 @@ var puddlangContextSchema = external_exports.object({
16271
16288
  accounts: external_exports.array(
16272
16289
  external_exports.object({ id: external_exports.number(), label: external_exports.string(), agent: external_exports.string(), logged_in: external_exports.boolean() })
16273
16290
  ),
16274
- agents: external_exports.array(external_exports.object({ id: external_exports.string(), scripted_turns: external_exports.boolean() }))
16291
+ agents: external_exports.array(
16292
+ external_exports.object({
16293
+ id: external_exports.string(),
16294
+ /** Automated turn support in either mode; this is not a mode name. */
16295
+ scripted_turns: external_exports.boolean(),
16296
+ modes: external_exports.array(agentModeSchema).optional()
16297
+ })
16298
+ )
16275
16299
  });
16276
16300
 
16277
16301
  // ../shared/src/api/puddlang-mcp.ts
package/dist/index.js CHANGED
@@ -3925,7 +3925,7 @@ import { createInterface } from "node:readline";
3925
3925
  import { Writable } from "node:stream";
3926
3926
 
3927
3927
  // ../shared/src/protocol.ts
3928
- var PROTOCOL_VERSION = { major: 23, minor: 0 };
3928
+ var PROTOCOL_VERSION = { major: 24, minor: 0 };
3929
3929
 
3930
3930
  // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
3931
3931
  var external_exports = {};
@@ -18522,7 +18522,20 @@ var agentLifecycleSignalSchema = external_exports.object({
18522
18522
  native_created_at: external_exports.iso.datetime({ offset: true }).optional(),
18523
18523
  native_updated_at: external_exports.iso.datetime({ offset: true }).optional()
18524
18524
  });
18525
- var agentSignalRequestSchema = external_exports.union([statusSignalSchema, agentLifecycleSignalSchema]);
18525
+ var agentTurnSignalSchema = external_exports.object({
18526
+ nonce: external_exports.string().min(16).max(200),
18527
+ event: external_exports.enum(["turn_start", "turn_complete", "turn_failed"]),
18528
+ agent_session_ref: external_exports.string().min(1).max(200),
18529
+ turn_id: external_exports.string().min(1).max(200),
18530
+ prompt_hash: external_exports.string().regex(/^[a-f0-9]{64}$/).optional(),
18531
+ reply: external_exports.string().max(256 * 1024).refine((value) => new TextEncoder().encode(value).length <= 256 * 1024).optional(),
18532
+ error: external_exports.string().max(4096).optional()
18533
+ });
18534
+ var agentSignalRequestSchema = external_exports.union([
18535
+ statusSignalSchema,
18536
+ agentLifecycleSignalSchema,
18537
+ agentTurnSignalSchema
18538
+ ]);
18526
18539
 
18527
18540
  // ../shared/src/api/config.ts
18528
18541
  var fields = {
@@ -18861,6 +18874,7 @@ var sessionStatusSchema = external_exports.enum([
18861
18874
  "archived"
18862
18875
  ]);
18863
18876
  var sessionKindSchema = external_exports.enum(["agent", "terminal"]);
18877
+ var agentModeSchema = external_exports.enum(["interactive", "headless"]);
18864
18878
  var sessionSchema = external_exports.object({
18865
18879
  id: sessionId,
18866
18880
  project_id: projectId,
@@ -18874,6 +18888,8 @@ var sessionSchema = external_exports.object({
18874
18888
  kind: sessionKindSchema,
18875
18889
  /** Null for terminal sessions, which run a plain shell rather than an agent. */
18876
18890
  agent_type: external_exports.string().nullable(),
18891
+ /** Native TUI or structured CLI execution with a terminal transcript. */
18892
+ agent_mode: agentModeSchema.optional(),
18877
18893
  /** Live foreground agent in a terminal session; icon hint only, never persisted. */
18878
18894
  detected_agent_type: external_exports.string().nullable().optional(),
18879
18895
  agent_session_ref: external_exports.string().nullable(),
@@ -19736,7 +19752,7 @@ var wsServerMessageSchema = external_exports.discriminatedUnion("t", [
19736
19752
  ]);
19737
19753
 
19738
19754
  // ../shared/src/remote/protocol.ts
19739
- var REMOTE_PROTOCOL_VERSION = 3;
19755
+ var REMOTE_PROTOCOL_VERSION = 4;
19740
19756
  var REMOTE_POLICY = {
19741
19757
  chunkBytes: 32 * 1024,
19742
19758
  frameBytes: 48 * 1024,
@@ -20116,6 +20132,7 @@ var sourceSchema = external_exports.string().min(1).max(PUDDLANG_MAX_SOURCE).ref
20116
20132
  );
20117
20133
  var puddlangSpawnSchema = external_exports.object({
20118
20134
  agent: external_exports.string().min(1).max(100),
20135
+ mode: agentModeSchema.optional(),
20119
20136
  account: external_exports.union([external_exports.string().min(1).max(100), external_exports.number().int().positive()]).optional(),
20120
20137
  project: external_exports.string().min(1).max(200).optional(),
20121
20138
  worktree: external_exports.string().min(1).max(4096).optional(),
@@ -20191,7 +20208,14 @@ var puddlangContextSchema = external_exports.object({
20191
20208
  accounts: external_exports.array(
20192
20209
  external_exports.object({ id: external_exports.number(), label: external_exports.string(), agent: external_exports.string(), logged_in: external_exports.boolean() })
20193
20210
  ),
20194
- agents: external_exports.array(external_exports.object({ id: external_exports.string(), scripted_turns: external_exports.boolean() }))
20211
+ agents: external_exports.array(
20212
+ external_exports.object({
20213
+ id: external_exports.string(),
20214
+ /** Automated turn support in either mode; this is not a mode name. */
20215
+ scripted_turns: external_exports.boolean(),
20216
+ modes: external_exports.array(agentModeSchema).optional()
20217
+ })
20218
+ )
20195
20219
  });
20196
20220
 
20197
20221
  // ../shared/src/api/puddlang-mcp.ts
@@ -21793,7 +21817,7 @@ import { readFileSync as readFileSync4 } from "node:fs";
21793
21817
  import { dirname as dirname4, join as join5 } from "node:path";
21794
21818
  import { fileURLToPath as fileURLToPath2 } from "node:url";
21795
21819
  function cliVersion() {
21796
- if (true) return "0.3.0";
21820
+ if (true) return "0.3.2";
21797
21821
  const here = dirname4(fileURLToPath2(import.meta.url));
21798
21822
  for (const candidate of [
21799
21823
  join5(here, "..", "..", "package.json"),
@@ -22191,7 +22215,9 @@ var RELEASE_PROTOCOLS = {
22191
22215
  "0.2.22": { major: 22, minor: 4 },
22192
22216
  "0.2.23": { major: 22, minor: 5 },
22193
22217
  "0.2.24": { major: 22, minor: 5 },
22194
- "0.3.0": { major: 23, minor: 0 }
22218
+ "0.3.0": { major: 23, minor: 0 },
22219
+ "0.3.1": { major: 23, minor: 0 },
22220
+ "0.3.2": { major: 24, minor: 0 }
22195
22221
  };
22196
22222
  function validProtocol(value) {
22197
22223
  if (typeof value !== "object" || value === null) return false;
@@ -24453,7 +24479,7 @@ init_types();
24453
24479
  import { spawn as spawn6 } from "node:child_process";
24454
24480
  import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync9, realpathSync as realpathSync2 } from "node:fs";
24455
24481
  import { mkdir as mkdir2, readFile as readFile2, rm as rm2, unlink } from "node:fs/promises";
24456
- import { dirname as dirname9, isAbsolute, join as join15, resolve as resolve5 } from "node:path";
24482
+ import { basename, dirname as dirname9, isAbsolute, join as join15, resolve as resolve5 } from "node:path";
24457
24483
  import { fileURLToPath as fileURLToPath4 } from "node:url";
24458
24484
  function standaloneInstallation(entryFile = fileURLToPath4(import.meta.url), execPath = process.execPath) {
24459
24485
  const release = resolve5(dirname9(entryFile), "..");
@@ -24461,7 +24487,7 @@ function standaloneInstallation(entryFile = fileURLToPath4(import.meta.url), exe
24461
24487
  try {
24462
24488
  const root = resolve5(release, "..", "..");
24463
24489
  const record2 = JSON.parse(readFileSync9(join15(root, "installation.json"), "utf8"));
24464
- if (readFileSync9(join15(release, "STANDALONE"), "utf8").trim() !== "puddle-cli" || readFileSync9(join15(root, "INSTALLATION"), "utf8").trim() !== "puddle-cli" || dirname9(release) !== join15(root, "versions") || realpathSync2(release) !== release || realpathSync2(execPath) !== join15(release, "bin/node") || record2.kind !== "puddle-cli" || typeof record2.launcher !== "string" || !isAbsolute(record2.launcher) || record2.scriptLauncher !== void 0 && record2.scriptLauncher !== join15(dirname9(record2.launcher), "puddlang"))
24490
+ if (readFileSync9(join15(release, "STANDALONE"), "utf8").trim() !== "puddle-cli" || readFileSync9(join15(root, "INSTALLATION"), "utf8").trim() !== "puddle-cli" || dirname9(release) !== join15(root, "versions") || realpathSync2(release) !== release || realpathSync2(execPath) !== join15(release, "bin/node") || record2.kind !== "puddle-cli" || typeof record2.launcher !== "string" || !isAbsolute(record2.launcher) || record2.scriptLauncher !== void 0 && record2.scriptLauncher !== join15(dirname9(record2.launcher), "pudl") && record2.scriptLauncher !== join15(dirname9(record2.launcher), "puddlang"))
24465
24491
  throw new Error("Installation metadata does not match this CLI");
24466
24492
  return {
24467
24493
  root,
@@ -24520,8 +24546,12 @@ async function removeStandaloneCli(installation) {
24520
24546
  if (lstatSync2(installation.launcher).isSymbolicLink() || await readFile2(installation.launcher, "utf8") !== standaloneLauncher(installation.root))
24521
24547
  throw new CliError("not_installed", "the CLI launcher was replaced; refusing removal");
24522
24548
  if (installation.scriptLauncher && existsSync5(installation.scriptLauncher)) {
24523
- if (!lstatSync2(installation.scriptLauncher).isFile() || await readFile2(installation.scriptLauncher, "utf8") !== standaloneLauncher(installation.root, "puddlang"))
24524
- throw new CliError("not_installed", "the puddlang launcher was replaced; refusing removal");
24549
+ const command = basename(installation.scriptLauncher);
24550
+ if (command !== "pudl" && command !== "puddlang" || !lstatSync2(installation.scriptLauncher).isFile() || await readFile2(installation.scriptLauncher, "utf8") !== standaloneLauncher(installation.root, command))
24551
+ throw new CliError(
24552
+ "not_installed",
24553
+ `the ${command} launcher was replaced; refusing removal`
24554
+ );
24525
24555
  await unlink(installation.scriptLauncher);
24526
24556
  }
24527
24557
  await unlink(installation.launcher);
@@ -125,7 +125,9 @@ main() {
125
125
  done
126
126
  # Help loads the bundle without touching a daemon or user state.
127
127
  "$STAGE/puddle" --help >/dev/null || die "CLI smoke test failed"
128
- if [ -f "$STAGE/puddlang" ]; then
128
+ if [ -f "$STAGE/pudl" ]; then
129
+ "$STAGE/pudl" --help >/dev/null || die "pudl smoke test failed"
130
+ elif [ -f "$STAGE/puddlang" ]; then
129
131
  "$STAGE/puddlang" --help >/dev/null || die "puddlang smoke test failed"
130
132
  fi
131
133
  "$STAGE/bin/node" --input-type=commonjs - "$PREFIX" "$BIN_DIR" "$STAGE" <<'NODE'
@@ -134,9 +136,12 @@ const [root, binDir, stage] = process.argv.slice(2);
134
136
  const launcher = path.join(binDir, 'puddle');
135
137
  const quote = (s) => "'" + s.replaceAll("'", "'\\''") + "'";
136
138
  const wrapper = '#!/bin/sh\n# puddle standalone launcher\nexec ' + quote(path.join(root, 'current/puddle')) + ' "$@"\n';
137
- const scriptLauncher = path.join(binDir, 'puddlang');
138
- const scriptWrapper = '#!/bin/sh\n# puddle standalone launcher\nexec ' + quote(path.join(root, 'current/puddlang')) + ' "$@"\n';
139
- const hasScript = fs.existsSync(path.join(stage, 'puddlang'));
139
+ // Older archives remain installable; current releases provide only pudl.
140
+ const scriptCommand = ['pudl', 'puddlang'].find((name) => fs.existsSync(path.join(stage, name)));
141
+ const scriptLauncher = path.join(binDir, scriptCommand || 'pudl');
142
+ const scriptWrapperFor = (name) => '#!/bin/sh\n# puddle standalone launcher\nexec ' + quote(path.join(root, 'current', name)) + ' "$@"\n';
143
+ const scriptWrapper = scriptWrapperFor(scriptCommand || 'pudl');
144
+ const hasScript = scriptCommand !== undefined;
140
145
  const stat = (p) => { try { return fs.lstatSync(p); } catch (e) { if (e.code === 'ENOENT') return null; throw e; } };
141
146
  if (stat(launcher) && (!stat(launcher).isFile() || fs.readFileSync(launcher, 'utf8') !== wrapper)) {
142
147
  throw Error('Refusing to replace an unrelated launcher: ' + launcher + '; choose --bin-dir');
@@ -160,7 +165,13 @@ try {
160
165
  fs.renameSync(launcher + tmp, launcher);
161
166
  if (hasScript) fs.renameSync(scriptLauncher + tmp, scriptLauncher);
162
167
  fs.renameSync(current + tmp, current); // Activate only after every other write succeeds.
163
- if (!hasScript && ownsScript) fs.unlinkSync(scriptLauncher); // Named older releases remain installable.
168
+ // Remove only exact wrappers owned by this installation when the command
169
+ // changes or a named older release does not contain a scripting command.
170
+ for (const name of ['pudl', 'puddlang']) {
171
+ if (name === scriptCommand) continue;
172
+ const obsolete = path.join(binDir, name);
173
+ if (stat(obsolete)?.isFile() && fs.readFileSync(obsolete, 'utf8') === scriptWrapperFor(name)) fs.unlinkSync(obsolete);
174
+ }
164
175
  } finally {
165
176
  for (const file of [record + tmp, launcher + tmp, scriptLauncher + tmp, current + tmp]) fs.rmSync(file, { force: true });
166
177
  }
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsDialog-DsmyHhQB.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/index-CPKHBs7z.js","assets/index-CAvJOpdz.css","assets/dist-CQZ_zg-s.js","assets/protocol-support-hVrRUHAd.js","assets/dialog-BoaHxScl.js","assets/button-D3DTuFk3.js","assets/x-CZCUod6A.js","assets/createLucideIcon-DyMAgLa3.js","assets/LazyTerminal-BN3rEDcD.js","assets/switch-DGZtVofo.js","assets/notification-delivery-Cn-YcMec.js","assets/disclosure-DNbP2Rp4.js","assets/chevron-down--sjpQEHH.js","assets/dist-DUfD4S2p.js","assets/code-DRWf9a5s.js","assets/errors-BkbAF9Bu.js","assets/use-debounced-value-C86N-mOK.js","assets/Dashboard-Djw9nPV_.js","assets/project-abbrev-B5CMO00I.js","assets/context-menu-CwR-PGrS.js","assets/NewProjectDialog-BK_gfWmL.js","assets/ws-B6RLTvWI.js","assets/Workspace-CmclLFK3.js","assets/copy-ZzKoF5dj.js","assets/media-refresh-store-BnZNW8xS.js","assets/use-ui-state-BZeOd2de.js","assets/preview-kind-QJSMKfUN.js","assets/debounce-B9DrqirV.js","assets/selection-actions-BDJnKwuj.js","assets/drafts-B_tChlzR.js","assets/buffer-logic-BAkSBQT7.js","assets/view-state-store-BEl9Q1Jm.js","assets/scroll-restoration-rhyw8Ck0.js","assets/Workspace-DdL3ODEC.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{K as n,N as r,S as i,T as a,U as o,a as s,c,g as l,h as u,i as d,m as f,n as p,nt as m,ot as h,r as g,s as _,t as v,tt as y,y as b}from"./index-CPKHBs7z.js";import{i as x,n as S,t as C}from"./dist-CQZ_zg-s.js";import{$t as w,A as T,B as ee,Bt as E,C as D,D as O,E as k,Et as A,F as te,Gt as j,Ht as ne,It as re,Jt as ie,K as ae,Kt as M,M as oe,Mt as se,N as ce,Nt as le,O as ue,P as de,Pt as fe,Qt as N,St as pe,T as me,Ut as he,V as ge,Vt as _e,W as ve,Wt as ye,Xt as be,Y as xe,Yt as Se,Z as Ce,Zt as we,_ as Te,a as Ee,b as De,ct as Oe,ft as ke,g as Ae,gt as je,ht as Me,k as Ne,lt as Pe,m as Fe,mt as Ie,nt as Le,ot as Re,p as ze,pt as Be,qt as Ve,rt as He,st as Ue,tt as We,w as Ge,x as Ke,y as qe,zt as Je}from"./protocol-support-hVrRUHAd.js";import{n as Ye,t as Xe}from"./copy-ZzKoF5dj.js";import{a as Ze,c as Qe,d as $e,f as et,i as tt,l as nt,m as rt,p as it,s as at,u as ot}from"./project-abbrev-B5CMO00I.js";import{S as P,c as st,l as ct,n as lt,s as ut,t as dt,u as ft,v as F}from"./dialog-BoaHxScl.js";import{i as pt,t as I}from"./button-D3DTuFk3.js";import{c as mt,f as ht,i as gt,o as _t,s as L,u as vt}from"./LazyTerminal-BN3rEDcD.js";import{a as yt,c as bt,d as xt,f as St,l as Ct,t as wt,u as Tt}from"./switch-DGZtVofo.js";import{$ as Et,G as Dt,H as Ot,J as kt,K as At,Q as jt,U as Mt,W as Nt,X as Pt,Y as Ft,at as It,d as Lt,et as Rt,f as zt,h as R,i as Bt,it as z,m as Vt,nt as Ht,ot as B,p as Ut,q as Wt,r as Gt,rt as V,t as Kt,tt as qt}from"./use-ui-state-BZeOd2de.js";import{n as H}from"./x-CZCUod6A.js";import{t as U}from"./createLucideIcon-DyMAgLa3.js";import{a as Jt,b as Yt,d as Xt,f as Zt,g as Qt,h as $t,i as en,l as tn,m as nn,o as rn,p as an,s as on,t as sn,u as cn,v as ln,x as un}from"./notification-delivery-Cn-YcMec.js";import{t as dn}from"./NewProjectDialog-BK_gfWmL.js";import{n as W}from"./errors-BkbAF9Bu.js";import{t as G}from"./ws-B6RLTvWI.js";var K=e(t(),1),q=p();function fn(){let[e,t]=(0,K.useState)(`Opening forwarded application…`);return(0,K.useEffect)(()=>{if(!/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname)){t(`This forwarding link is invalid.`);return}let e=!0;return Ye(new URL(window.location.href)).then(t=>{e&&window.location.replace(t)}).catch(()=>{e&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{e=!1}},[]),(0,q.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var pn=class extends we{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 fe({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=mn(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=mn(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=mn(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=mn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){E.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=>ye(t,e))}findAll(e={}){return this.getAll().filter(t=>ye(e,t))}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return E.batch(()=>Promise.all(e.map(e=>e.continue().catch(M))))}};function mn(e){return e.options.scope?.id}var hn=class extends we{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??he(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(){E.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=>j(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>j(e,t)):t}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){E.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){E.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},gn=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new hn,this.#t=e.mutationCache||new pn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=be.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Je.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(ie(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=_e(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return E.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;E.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return E.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=E.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(M).catch(M)}invalidateQueries(e,t={}){return E.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=E.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(M)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(M)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(ie(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(M).catch(M)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(M).catch(M)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Je.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(ne(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ve(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(ne(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ve(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||=he(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===Se&&(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()}},_n=class extends K.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,q.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,q.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,q.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,q.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,q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,q.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,q.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function vn(){return(0,q.jsx)(C,{theme:(0,K.useSyncExternalStore)(_,s),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 yn(){return(0,q.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,q.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,q.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,q.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,q.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,q.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var bn=e(h(),1),xn=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,Sn=`.monaco-editor`;function Cn(e,t){return e?.closest(Sn)&&!e.closest(t)?`text`:e?.closest(xn)?`interactive`:`default`}function wn(e,t=`.no-custom-caret`){(0,K.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(Sn),s=Cn(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 Tn=[`top`,`right`,`bottom`,`left`];function En(){let e=(0,K.useRef)(null);return wn(e),(0,q.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:Tn.map(e=>(0,q.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function Dn(){let e=(0,K.useRef)(null);return wn(e),(0,q.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var On=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,kn=40.5,J=4.05,An=J*Math.sqrt(3)/2;function jn(){let e=[],t=[],n=kn/2,r=Math.ceil(n/An)+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*An,s=o+An,c=(i%2+2)%2*(J/2);for(let i=-r;i<r;i+=1){let r=n+i*J+c,l=[[r+J/2,o],[r,s],[r+J,s]],u=[[r+J/2,o],[r+3*J/2,o],[r+J,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<kn&&Math.max(...n)>0&&Math.min(...n)<kn};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var Mn=jn();function Nn(){let e=(0,K.useRef)(null);return wn(e,On),(0,q.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,q.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${kn} ${kn}`,focusable:`false`,children:[(0,q.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:Mn.light}),(0,q.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:Mn.dark})]})})}function Pn(){let{cursorPackage:e}=l(),t=null;switch(e){case`rangefinder`:t=(0,q.jsx)(Nn,{});break;case`drafting`:t=(0,q.jsx)(En,{});break;case`invert`:t=(0,q.jsx)(Dn,{});break;case`system`:return null}return(0,bn.createPortal)(t,document.body)}var Fn=U(`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`}]]),In=U(`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`}]]),Ln=U(`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`}]]),Rn=U(`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`}]]),zn=U(`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`}]]),Bn=U(`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`}]]),Vn=U(`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 Hn(){let e=Ie(),t=ge(),[r,i]=(0,K.useState)(``),[a,o]=(0,K.useState)(n),s=()=>{r.trim()&&t.mutate({name:r.trim(),branch_prefix:a.trim()},{onSuccess:e=>me(e.id)})},c=(e.data?.length??0)>0;return(0,q.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,q.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,q.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),c&&(0,q.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,q.jsxs)(`button`,{onClick:()=>me(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,q.jsx)($t,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,q.jsx)(`span`,{className:H(`text-base`,Qt(e.icon_colour)||`text-fg`),children:e.name}),e.branch_prefix&&(0,q.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),s()},children:[c&&(0,q.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(_t,{htmlFor:`profile-name`,children:`Name`}),(0,q.jsx)(L,{id:`profile-name`,placeholder:`e.g. alice`,value:r,onChange:e=>i(e.target.value),className:`h-10`,autoFocus:!c})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(_t,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,q.jsx)(L,{id:`branch-prefix`,placeholder:`no prefix`,value:a,onChange:e=>o(e.target.value),className:`h-10`})]}),t.error&&(0,q.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,q.jsx)(I,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!r.trim()||t.isPending,children:`Create profile`})]})]})})}var Un=1,Wn=.9,Gn=.8,Kn=.17,qn=.1,Jn=.999,Yn=.9999,Xn=.99,Zn=/[\\\/_+.#"@\[\(\{&]/,Qn=/[\\\/_+.#"@\[\(\{&]/g,$n=/[\s-]/,er=/[\s-]/g;function tr(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Un:Xn;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=tr(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Un:Zn.test(e.charAt(l-1))?(d*=Gn,p=e.slice(i,l-1).match(Qn),p&&i>0&&(d*=Jn**+p.length)):$n.test(e.charAt(l-1))?(d*=Wn,m=e.slice(i,l-1).match(er),m&&i>0&&(d*=Jn**+m.length)):(d*=Kn,i>0&&(d*=Jn**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=Yn)),(d<qn&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=tr(e,t,n,r,l+1,a+2,o),f*qn>d&&(d=f*qn)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function nr(e){return e.toLowerCase().replace(er,` `)}function rr(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,tr(e,t,nr(e),nr(t),0,0,{})}var ir=`[cmdk-group=""]`,ar=`[cmdk-group-items=""]`,or=`[cmdk-group-heading=""]`,sr=`[cmdk-item=""]`,cr=`${sr}:not([aria-disabled="true"])`,lr=`cmdk-item-select`,Y=`data-value`,ur=(e,t,n)=>rr(e,t,n),dr=K.createContext(void 0),fr=()=>K.useContext(dr),pr=K.createContext(void 0),mr=()=>K.useContext(pr),hr=K.createContext(void 0),gr=K.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=Dr(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=F(),y=F(),b=F(),x=K.useRef(null),S=kr();Z(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),Z(()=>{S(6,O)},[]);let C=K.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`)D(),ee(),S(1,E);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=k()?.id,C.emit()}),r||S(5,O),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=K.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,()=>{ee(),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,()=>{D(),ee(),n.current.value||E(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=k();S(4,()=>{D(),t?.getAttribute(`id`)===e&&E(),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??ur;return e?r(e,n.current.search,t):0}function ee(){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;A().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(ar);t?t.appendChild(e.parentElement===t?e:e.closest(`${ar} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${ar} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${ir}[${Y}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function E(){let e=A().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(Y);C.setState(`value`,e||void 0)}function D(){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 O(){var e;let t=k();t&&(t.parentElement?.firstChild===t&&((e=t.closest(ir)?.querySelector(or))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function k(){return x.current?.querySelector(`${sr}[aria-selected="true"]`)}function A(){return Array.from(x.current?.querySelectorAll(cr)||[])}function te(e){let t=A()[e];t&&C.setState(`value`,t.getAttribute(Y))}function j(e){var t;let n=k(),r=A(),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(Y))}function ne(e){let t=k()?.closest(ir),n;for(;t&&!n;)t=e>0?Tr(t,ir):Er(t,ir),n=t?.querySelector(cr);n?C.setState(`value`,n.getAttribute(Y)):j(e)}let re=()=>te(A().length-1),ie=e=>{e.preventDefault(),e.metaKey?re():e.altKey?ne(1):j(1)},ae=e=>{e.preventDefault(),e.metaKey?te(0):e.altKey?ne(-1):j(-1)};return K.createElement(P.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&&ie(e);break;case`ArrowDown`:ie(e);break;case`p`:case`k`:g&&e.ctrlKey&&ae(e);break;case`ArrowUp`:ae(e);break;case`Home`:e.preventDefault(),te(0);break;case`End`:e.preventDefault(),re();break;case`Enter`:{e.preventDefault();let t=k();if(t){let e=new Event(lr);t.dispatchEvent(e)}}}}},K.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:Mr},c),jr(e,e=>K.createElement(pr.Provider,{value:C},K.createElement(dr.Provider,{value:w},e))))}),_r=K.forwardRef((e,t)=>{let n=F(),r=K.useRef(null),i=K.useContext(hr),a=fr(),o=Dr(e),s=o.current?.forceMount??i?.forceMount;Z(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=Or(n,r,[e.value,e.children,r],e.keywords),l=mr(),u=$(e=>e.value&&e.value===c.current),d=$(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);K.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(lr,f),()=>t.removeEventListener(lr,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 K.createElement(P.div,{ref:pt(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)}),vr=K.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=F(),s=K.useRef(null),c=K.useRef(null),l=F(),u=fr(),d=$(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));Z(()=>u.group(o),[]),Or(o,s,[e.value,e.heading,c]);let f=K.useMemo(()=>({id:o,forceMount:i}),[i]);return K.createElement(P.div,{ref:pt(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&K.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),jr(e,e=>K.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},K.createElement(hr.Provider,{value:f},e))))}),yr=K.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=K.useRef(null),a=$(e=>!e.search);return!n&&!a?null:K.createElement(P.div,{ref:pt(i,t),...r,"cmdk-separator":``,role:`separator`})}),br=K.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=mr(),o=$(e=>e.search),s=$(e=>e.selectedItemId),c=fr();return K.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),K.createElement(P.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)}})}),xr=K.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=K.useRef(null),o=K.useRef(null),s=$(e=>e.selectedItemId),c=fr();return K.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)}}},[]),K.createElement(P.div,{ref:pt(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},jr(e,e=>K.createElement(`div`,{ref:pt(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),Sr=K.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return K.createElement(ut,{open:n,onOpenChange:r},K.createElement(ft,{container:o},K.createElement(ct,{"cmdk-overlay":``,className:i}),K.createElement(st,{"aria-label":e.label,"cmdk-dialog":``,className:a},K.createElement(gr,{ref:t,...s}))))}),Cr=K.forwardRef((e,t)=>$(e=>e.filtered.count===0)?K.createElement(P.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),wr=K.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return K.createElement(P.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},jr(e,e=>K.createElement(`div`,{"aria-hidden":!0},e)))}),X=Object.assign(gr,{List:xr,Item:_r,Input:br,Group:vr,Separator:yr,Dialog:Sr,Empty:Cr,Loading:wr});function Tr(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Er(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Dr(e){let t=K.useRef(e);return Z(()=>{t.current=e}),t}var Z=typeof window>`u`?K.useEffect:K.useLayoutEffect;function Q(e){let t=K.useRef();return t.current===void 0&&(t.current=e()),t}function $(e){let t=mr(),n=()=>e(t.snapshot());return K.useSyncExternalStore(t.subscribe,n,n)}function Or(e,t,n,r=[]){let i=K.useRef(),a=fr();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(Y,s),i.current=s}),i}var kr=()=>{let[e,t]=K.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 Ar(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function jr({asChild:e,children:t},n){return e&&K.isValidElement(t)?K.cloneElement(Ar(t),{ref:t.ref},n(t.props.children)):n(t)}var Mr={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function Nr({className:e,...t}){return(0,q.jsx)(X,{className:H(`flex size-full flex-col overflow-hidden rounded-lg bg-elevated`,e),...t})}function Pr({open:e,onOpenChange:t,children:n}){return(0,q.jsx)(dt,{open:e,onOpenChange:t,children:(0,q.jsx)(lt,{className:`max-w-lg overflow-hidden p-0 [&>button]:hidden`,children:(0,q.jsx)(Nr,{loop:!0,children:n})})})}function Fr({className:e,...t}){return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pt-1`,children:[(0,q.jsx)(Ht,{className:`size-4 shrink-0 text-fg-muted`}),(0,q.jsx)(X.Input,{className:H(`flex h-10 w-full bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted`,e),...t})]})}function Ir({className:e,...t}){return(0,q.jsx)(X.List,{className:H(`max-h-72 overflow-y-auto p-1`,e),...t})}function Lr(e){return(0,q.jsx)(X.Empty,{className:`py-6 text-center text-sm text-fg-muted`,...e})}function Rr({className:e,...t}){return(0,q.jsx)(X.Group,{className:H(`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 zr({className:e,...t}){return(0,q.jsx)(X.Item,{className:H(ht,vt,`[&_svg]:size-3.5 [&_svg]:text-fg-muted data-[selected=true]:[&_svg]:text-action-ink`,e),...t})}function Br({className:e,...t}){return(0,q.jsx)(`span`,{className:H(`ml-auto font-mono text-2xs tracking-widest text-fg-muted`,e),...t})}var Vr=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 ${b.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=r.parse(await n.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 n=a.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}},Hr=null;function Ur(e){return Hr=e,()=>{Hr===e&&(Hr=null)}}function Wr(){Hr?.()}var Gr=new Set;function Kr(){return[...Gr].flatMap(e=>e())}function qr({onNewSession:e,onNewProject:t}){let[n,r]=(0,K.useState)(!1),[i,a]=(0,K.useState)(`commands`),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(null),[u,d]=(0,K.useState)(!1),f=it(),p=rt(),m=k(),h=p.id,_=je(m??void 0),v=A(h),y=Ft();(0,K.useEffect)(()=>De(`palette.toggle`,()=>r(e=>!e)),[]),(0,K.useEffect)(()=>Et(()=>r(!0)),[]),(0,K.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let b=(0,K.useMemo)(()=>{let n=[];for(let e of _.data??[])n.push({id:`project-${e.id}`,group:`Projects`,label:e.name,icon:Ze,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:tt,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return h!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:St,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:tt,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),h!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:Ze,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:xt,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:Yt,keywords:`switch theme dark appearance`,run:()=>void g(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:ln,keywords:`switch theme light appearance`,run:()=>void g(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:Ln,keywords:`switch theme system appearance`,run:()=>void g(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Vn,keywords:`open settings preferences options configure`,run:()=>yt()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:bt,keywords:`switch profile identity user change`,run:()=>Ge.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:Tt,keywords:`refresh connection reconnect restart cockpit tunnel ssh daemon`,run:()=>Wr()}),[...n,...Kr()]},[_.data,v.data,h,f,e,t,y]),x=(0,K.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 Pt(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,q.jsxs)(Pr,{open:n,onOpenChange:r,children:[(0,q.jsx)(Fr,{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,q.jsx)(Ir,{children:(0,q.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,q.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,q.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,q.jsxs)(Ir,{children:[(0,q.jsx)(Lr,{children:`Nothing matches.`}),x.map(([e,t])=>(0,q.jsx)(Rr,{heading:e,children:t.map(e=>{let t=e.icon;return(0,q.jsxs)(zr,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,q.jsx)(t,{}),e.label,e.shortcut&&(0,q.jsx)(Br,{children:e.shortcut})]},e.id)})},e))]})]})}function Jr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Yr(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Xr(){let e=Be(k()??void 0).data?.hotkeys;return(0,K.useEffect)(()=>{Ke(e&&typeof e==`object`?e:void 0)},[e]),(0,K.useEffect)(()=>De(`window.close`,()=>{let e=N();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,K.useEffect)(()=>{let e=e=>{let t=Fe(e);if(!t)return;let n=ze(t);if(!n)return;let r=Ae(n);if(!r||!qe(r,Yr()))return;let i=Te(n);i&&(e.preventDefault(),e.stopPropagation(),i())},t=e=>{let t=Fe(e);if(!t)return;let n=ze(t);if(!n)return;let r=Ae(n);if(!r||r.editor&&Yr()||r.deferInTerminal&&Jr())return;let i=Te(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 Zr=4e3;function Qr(){let[e,t]=(0,K.useState)(`hidden`),n=(0,K.useRef)(e);n.current=e,(0,K.useEffect)(()=>{let e=null,r=G.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`)},Zr))});return()=>{r(),e!==null&&clearTimeout(e)}},[]);let r=(0,K.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Vr.refresh()||(S.error(`The cockpit has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(G.isConnected()?`hidden`:`lost`)))},[]);return(0,K.useEffect)(()=>Ur(()=>void r()),[r]),e===`hidden`?null:(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the cockpit.`:`Connection to the daemon lost.`}),e===`lost`&&(0,q.jsxs)(I,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,q.jsx)(Tt,{}),`Refresh connection`]})]})}function $r({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,q.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,q.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,q.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function ei(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ti(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 ni({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=oe(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,q.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,q.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,q.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,q.jsxs)(q.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 `,ti(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,q.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[ei(i.data.agent_usage.input_tokens),` in ·`,` `,ei(i.data.agent_usage.output_tokens),` out ·`,` `,ei(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,q.jsx)(`span`,{className:`mt-1 block`,children:(0,q.jsx)($r,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,q.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,q.jsx)(un,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,q.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,q.jsx)($r,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function ri(){let[e,t]=(0,K.useState)(!1),[n,r]=(0,K.useState)(!1),i=k(),a=Ie(),o=Oe(),s=a.data?.find(e=>e.id===i),c=ce(i??void 0),l=de(),u=He(),{open:d,handler:f}=kt(),[p,m]=(0,K.useState)(null),h=e=>u.mutate(e.id,{onSuccess:t=>m({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>W(e)}),g=e=>{t(!1),d({accountId:e.id})};return n&&s?(0,q.jsxs)(`div`,{className:`flex h-8 items-center gap-2 px-3`,children:[(0,q.jsx)($t,{icon:s.icon,colour:s.icon_colour}),(0,q.jsx)(Rt,{initial:s.name,maxLength:100,className:H(`w-32 text-sm`,Qt(s.icon_colour)),onCommit:e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>W(e)})},onCancel:()=>r(!1)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Zt,{open:e,onOpenChange:t,children:[(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsx)(nn,{asChild:!0,children:(0,q.jsxs)(I,{variant:`ghost`,size:`sm`,className:`font-sans compact:h-7 compact:px-1.5`,children:[(0,q.jsx)($t,{icon:s?.icon,colour:s?.icon_colour}),(0,q.jsx)(`span`,{className:Qt(s?.icon_colour),...qt(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})}),(0,q.jsx)(z,{children:`Profile`})]}),(0,q.jsxs)(an,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,q.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,q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,q.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,q.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,q.jsx)(ni,{account:e,onLogin:()=>h(e),onStartSession:f&&n?()=>g(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,q.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,q.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,q.jsxs)(I,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),yt(`accounts`)},children:[(0,q.jsx)(xt,{}),`Add account`]}),(0,q.jsxs)(I,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),Ge.set(null)},children:[(0,q.jsx)(Bn,{}),`Switch profile`]})]})]})]}),p&&(0,q.jsx)(Xt,{stream:p.stream,label:p.label,onClose:()=>m(null)})]})}var ii=`desktop-update`;function ai(){let e=(0,K.useRef)(null);return(0,K.useEffect)(()=>{let t=N();if(t?.updateReady===void 0||t.onUpdateReady===void 0)return;let n=t=>{e.current!==t&&(e.current=t,S(`Puddle ${t} is downloaded and ready.`,{id:ii,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{N()?.installUpdate?.(),S.loading(`Restarting into Puddle ${t}…`,{id:`${ii}-restarting`,duration:1/0})}}}))};return t.updateReady().then(e=>{e!==null&&n(e)}),t.onUpdateReady(n)},[]),null}function oi(){let e=k(),t=Ie().data?.find(t=>t.id===e),n=Be(e??void 0),r=pe(e??void 0,void 0),i=l(),a=rn(),o=on(),s=Pe(e??``),d=Oe(),f=ve(),[p,m]=(0,K.useReducer)(e=>e+1,0);(0,K.useEffect)(()=>_(()=>m()),[]);let h=(0,K.useRef)(null);(0,K.useEffect)(()=>{h.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=s.isPending||d.isPending||f.isPending||o.isPending||n.isFetching||r.isFetching;(0,K.useEffect)(()=>{if(!y||!b?.enabled||x)return;let a={client:i,theme:c(),profileSettings:n.data,profile:t,scratchpad:r.data},l={setClient:e=>u(e),setTheme:e=>{typeof e==`string`&&g(e)},patchProfileSettings:e=>s.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(h.current!==p){h.current=p,tn(b.doc,l,a,b.groups);return}let m=cn(b.groups,a),_=JSON.stringify(m);_!==p&&(h.current=_,o.mutate({profile:t.name,entry:{...b,doc:m,updatedAt:new Date().toISOString()}}))})}function si(e){let t=t=>{let n=m.safeParse(t);n.success&&e(n.data)},n=N()?.onNotificationClick?.((e,n)=>t(n)),r=e=>{e.data?.t===`notification-click`&&t(e.data.target)};return navigator.serviceWorker?.addEventListener(`message`,r),()=>{n?.(),navigator.serviceWorker?.removeEventListener(`message`,r)}}var ci=5e3,li=`[data-notification-session]`;function ui(e){let t=null,n=()=>{t=null},r=e=>e.target instanceof Element?e.target.closest(li):null,i=e=>{if(!e.isTrusted)return;let n=r(e),i=n?.dataset.notificationSession;t=n&&i?{element:n,session:i,at:performance.now()}:null},a=e=>{r(e)!==t?.element&&n()},o=[`pointerdown`,`keydown`,`input`,`paste`];for(let t of o)e.addEventListener(t,i,!0);return e.addEventListener(`focusin`,a,!0),e.addEventListener(`visibilitychange`,n),e.defaultView?.addEventListener(`blur`,n),{isInteracting(n){return t!==null&&t.session===n&&performance.now()-t.at<ci&&e.visibilityState===`visible`&&e.hasFocus()&&t.element.isConnected&&t.element.dataset.notificationSession===n&&t.element.getClientRects().length>0},dispose(){n();for(let t of o)e.removeEventListener(t,i,!0);e.removeEventListener(`focusin`,a,!0),e.removeEventListener(`visibilitychange`,n),e.defaultView?.removeEventListener(`blur`,n)}}}var di=new Set,fi=e=>!!e&&di.has(e),pi=y.parse({});function mi(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&(e.permission===`granted`||e.permission===`unverified`)&&(e.prefs.when_focused||!e.sessionFocused),sound:e.prefs.sound}}function hi(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 gi(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function _i(){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 vi(){let e=it(),t=(0,K.useRef)(null);(0,K.useEffect)(()=>{let e=ui(document);return t.current=e,()=>{t.current=null,e.dispose()}},[]),(0,K.useEffect)(()=>si(t=>{t.host||e(`/project/${t.project}/session/${t.session}`,{state:{notificationSession:t.session}})}),[e]),yi(t=>{e(`/project/${t.project_id}/session/${t.id}`,{state:{notificationSession:t.id}})},e=>t.current?.isInteracting(e.id)??!1)}function yi(e,t=()=>document.hasFocus()){let n=le(),r=(0,K.useRef)(e);r.current=e;let a=(0,K.useRef)(t);a.current=t;let o=Ne(We().data)??`Puddle`,s=(0,K.useRef)(o);(0,K.useEffect)(()=>{document.title===s.current&&(document.title=o),s.current=o},[o]),(0,K.useEffect)(()=>{let e=new Set,t=()=>{document.title=e.size>0?`(${e.size}) ${s.current}`:s.current},o=!0,c=async e=>{let t=hi(n,e.session);if(!t)try{t=(await O(n)).find(t=>t.id===e.session)}catch{return}if(!o||!t)return;let s=t,c;try{let e=await n.fetchQuery({queryKey:[`project`,s.project_id],queryFn:()=>x(`GET`,`/api/projects/${s.project_id}`),staleTime:1e4});if(!o)return;let t=e.project.profile_id,r=await n.fetchQuery({queryKey:[`profile-settings`,t],queryFn:()=>x(`GET`,`/api/profiles/${t}/settings`),staleTime:1e4});c=y.catch(pi).parse(r.notifications??{})}catch{return}if(!o)return;let l=mi({prefs:c,projectId:s.project_id,sessionFocused:a.current(s),permission:en()});l.sound&&_i(),l.desktop&&!fi(i()?.scope)&&await sn({id:e.id?`puddle-event-${e.id}`:`puddle-agent-${s.id}`,title:e.content?.title??gi(s).slice(0,160),body:e.content?.body??(e.reason===`exited`?`Agent finished running`:`Waiting for your input`),target:{project:s.project_id,session:s.id,...i()?.notificationHost?{host:i().notificationHost}:{}}},()=>{o&&r.current(s)})},l=G.onAgentNotification(e=>{c(e)}),u=G.onStatus(r=>{let i=e.has(r.session);r.status===`waiting_input`?e.add(r.session):e.delete(r.session),t(),!(r.status!==`waiting_input`||i)&&n.fetchQuery({queryKey:[`version`],queryFn:()=>x(`GET`,`/api/version`),staleTime:1/0}).then(e=>{if(!(e.protocol.major>22||e.protocol.major===22&&e.protocol.minor>=3))return c({session:r.session,reason:`waiting_input`})}).catch(()=>{})});return()=>{o=!1,u(),l(),document.title=s.current}},[n])}function bi({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,K.useState)(e?.title??``),[c,l]=(0,K.useState)(e?.body??``),[u,d]=(0,K.useState)(n?e?.scope??t:`profile`),[f,p]=(0,K.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,K.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,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(L,{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,q.jsx)(mt,{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,q.jsx)(L,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,q.jsx)(wt,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,q.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,q.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:H(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,q.jsx)(At,{type:e.id,className:`size-3.5`}),(0,q.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,q.jsx)(I,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,q.jsx)(I,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function xi(){let e=Dt(),t=k(),n=rt().id,r=pe(t??void 0,n).data??[],i=de().data??[],a=ve(),o=ke(),s=Ce(),c=Nt(),[l,u]=(0,K.useState)(null),[d,f]=(0,K.useState)(null),[p,m]=(0,K.useState)(null),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(null);(0,K.useEffect)(()=>De(`scratchpad.toggle`,Mt),[]),(0,K.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,K.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),b=(0,K.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),x=d!==null||p!==null,C=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),w=x?C:_??r,T=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))},ee=(e,t)=>{o.mutate({id:e,scope:t.scope,project_id:t.scope===`project`?n??null:null,title:t.title,body:t.body,tags:t.tags,agent_type:t.agent_type}),u(null)},E=(e,t)=>{let n=_??r,i=n.findIndex(t=>t.id===e),a=n.findIndex(e=>e.id===t);if(i===-1||a===-1||i===a)return;let o=n.slice(),[s]=o.splice(i,1);o.splice(a,0,s),v(o)},D=()=>{let e=h,t=_;if(g(null),v(null),e===null||!t)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=t[n-1],i=t[n+1],a=r?i?(r.position+i.position)/2:r.position+1:(i?i.position:0)-1;o.mutate({id:e,position:a})},O=e=>{navigator.clipboard?.writeText(e.body),S.success(`Copied to clipboard`)};return(0,q.jsxs)(Zt,{open:e,onOpenChange:Ot,children:[(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsx)(nn,{asChild:!0,children:(0,q.jsxs)(I,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,q.jsx)(Rn,{}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,q.jsx)(z,{children:`Scratchpad`})]}),(0,q.jsxs)(an,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,q.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,q.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,q.jsx)(xt,{className:`size-4`}),(0,q.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||b.length>0)&&(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:H(`rounded-full px-2 py-0.5 text-2xs transition-colors`,d===e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:e},e)),b.map(e=>(0,q.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:H(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,q.jsx)(At,{type:e,className:`size-3.5`})},e))]}),(0,q.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[l===`new`&&(0,q.jsx)(`div`,{className:`px-3 py-2`,children:(0,q.jsx)(bi,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:T,onCancel:()=>u(null)})}),w.length===0&&l!==`new`&&(0,q.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:x?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,q.jsx)(`ul`,{className:`flex flex-col`,children:w.map(e=>l===e.id?(0,q.jsx)(`li`,{className:`px-3 py-2`,children:(0,q.jsx)(bi,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>ee(e.id,t),onCancel:()=>u(null)})},e.id):(0,q.jsx)(`li`,{draggable:!x&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&E(h,e.id))},onDragEnd:D,className:H(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,q.jsx)(Si,{entry:e,onInsert:c?()=>{c(e.body),Ot(!1)}:null,onCopy:()=>O(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})},e.id))})]})]})]})}function Si({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,K.useState)(!1);return(0,q.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,q.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,q.jsx)(`p`,{className:H(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,q.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:`Delete`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]}):(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,q.jsx)(At,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,q.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[t&&(0,q.jsx)(Ci,{icon:Fn,label:`Insert into focused terminal`,onClick:t}),(0,q.jsx)(Ci,{icon:Xe,label:`Copy`,onClick:n}),(0,q.jsx)(Ci,{icon:gt,label:`Edit`,onClick:r}),(0,q.jsx)(Ci,{icon:Ct,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function Ci({icon:e,label:t,onClick:n}){return(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,q.jsx)(e,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,q.jsx)(z,{children:t})]})}var wi=o.parse({});function Ti(e,t){let[n,r]=(0,K.useState)(null),i=te(t).data,a=je(e??void 0,t&&e!==null).data;return(0,K.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=Kt(sessionStorage.getItem(Gt(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return ue(e).then(e=>{n||r(e?e.ui_state:wi)}).catch(()=>{n||r(wi)}),()=>{n=!0}},[t,e]),(0,K.useMemo)(()=>{if(!t||e===null||n===null)return null;let o=t=>{if(!i||!a)return!1;let{patch:o,projectBased:s}=Bt(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),T(e,c).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Gt(e),JSON.stringify(c))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}return f().projectBasedLayout!==s&&u({projectBasedLayout:s}),!0},s=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:R(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:R(null),slices:s,capture:()=>({layout_tree:null,active_session:null}),apply:o}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:R(n.layout_tree),slices:s,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),apply:o}},[t,e,n,i,a])}var Ei=R(null);function Di(){let e=Vt(),t=it(),n=k(),r=Ut(),i=Ti(n,e&&r===null),a=r??i,o=Le(n??void 0,void 0).data??[],s=je(n??void 0,e&&n!==null).data??[],c=ee(),l=Ue(),u=xe(),[d,f]=(0,K.useState)(``),[p,m]=(0,K.useState)(!1),[h,g]=(0,K.useState)(null);(0,K.useEffect)(()=>De(`layouts.toggle`,zt),[]),(0,K.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!==Ei:R(v.layout_tree)!==a.signature),b=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?R(n.layout_tree)!==t.signature:t.signature!==Ei},x=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:b(e.project_id):y||b(e.project_id),C=e=>v!==null&&e.id===v.id,w=e=>(e===null?void 0:s.find(t=>t.id===e)?.name)??`Project`,T=a!==null&&!_&&a.scope===`project`?o.filter(e=>e.scope===`profile`||e.project_id===a.projectId):o,E=[...T.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(T.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:w(e)})).sort((e,t)=>e.name.localeCompare(t.name))],D=h===null?T:h===`profile`?T.filter(e=>e.scope===`profile`):T.filter(e=>e.project_id===h),O=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=>W(e)})},te=e=>{if(!a)return;let t=O(e)?e:o.find(t=>t.name===e.name&&O(t));if(!t){A(e.name,a.capture(),!0);return}l.mutate({id:t.id,...a.capture()},{onSuccess:e=>a.apply(e),onError:e=>W(e)})},j=(e,t)=>A(t,{layout_tree:e.layout_tree,active_session:e.active_session},!1),ne=e=>{if(a){if(!a.apply(e)){S.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}`),Lt(!1)}};return(0,q.jsxs)(Zt,{open:e,onOpenChange:Lt,children:[(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsx)(nn,{asChild:!0,children:(0,q.jsxs)(I,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,q.jsx)(In,{}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,q.jsx)(z,{children:`Layouts`})]}),(0,q.jsxs)(an,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,q.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),a!==null&&!_&&(0,q.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,q.jsx)(xt,{className:`size-4`}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),a===null?(0,q.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):_?(0,q.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,q.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[v===null&&(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,q.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:a.scope===`profile`?`Profile-wide`:`Project`}),(0,q.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,q.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,q.jsx)(L,{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,q.jsx)(I,{size:`sm`,type:`submit`,disabled:!d.trim(),children:`Save`}),v!==null&&(0,q.jsx)(I,{variant:`ghost`,size:`sm`,onClick:()=>m(!1),children:`Cancel`})]})]}),E.length>1&&(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:E.map(e=>(0,q.jsx)(Ai,{active:h===e.key,onClick:()=>g(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,q.jsxs)(`div`,{className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[D.length===0&&(0,q.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,q.jsx)(`ul`,{className:`flex flex-col`,children:D.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(Oi,{layout:e,projectLabel:e.scope===`profile`?null:w(e.project_id),isCurrent:C(e),dirty:y,loadable:a!==null,savable:a!==null&&!_,confirmBeforeLoad:x(e),overwrites:O(e),onLoad:()=>ne(e),onRename:t=>l.mutate({id:e.id,name:t}),onDelete:()=>u.mutate(e.id),onSaveAs:()=>te(e),onDuplicate:t=>j(e,t)})},e.id))})]})]})]})}function Oi({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,K.useState)(null),[h,g]=(0,K.useState)(null),[_,v]=(0,K.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,q.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||y()},className:H(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[h===null?(0,q.jsxs)(`p`,{className:H(`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,q.jsx)(`span`,{className:`text-2xs font-normal`,children:S===`active`?`Active`:`Unsaved`})]}):(0,q.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,q.jsx)(L,{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,q.jsx)(I,{size:`sm`,type:`submit`,disabled:!_.trim(),children:h===`rename`?`Rename`:`Save`})]}),p===`save`?(0,q.jsx)(ki,{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,q.jsx)(ki,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{m(null),u()},onCancel:()=>m(null)}):p===`load`?(0,q.jsx)(ki,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:y,onCancel:()=>m(null)}):(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,q.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[a&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(ji,{icon:zn,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:x}),(0,q.jsx)(ji,{icon:Xe,label:`Duplicate`,onClick:()=>b(`duplicate`)})]}),(0,q.jsx)(ji,{icon:gt,label:`Rename`,onClick:()=>b(`rename`)}),(0,q.jsx)(ji,{icon:Ct,label:`Delete`,onClick:()=>m(`delete`)})]})]})]})}function ki({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,q.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,q.jsx)(`button`,{type:`button`,onClick:n,className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:t}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]})}function Ai({active:e,onClick:t,children:n}){return(0,q.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:H(`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 ji({icon:e,label:t,onClick:n}){return(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,q.jsx)(e,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,q.jsx)(z,{children:t})]})}var Mi=N()!==void 0&&/Mac/.test(navigator.platform),Ni=(0,K.lazy)(()=>v(()=>import(`./SettingsDialog-DsmyHhQB.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,18,19])));function Pi(){let e=le();(0,K.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=G.onStatus(e=>t(t=>t.id===e.session?{...t,status:e.status,last_activity_at:e.last_activity_at}:t)),r=G.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=G.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=G.onSessionsChanged(e=>a(e.project_ids)),s=G.onSessionSwitched(e=>a([e.target_project]));return()=>{n(),r(),i(),o(),s()}},[e])}function Fi(){let e=We(),t=Re(),[n,r]=(0,K.useState)(!1),i=Ne(e.data),a=n=>{r(!1);let a=n.trim();a!==i&&t.mutate({displayName:a===e.data?.hostname?``:a},{onError:e=>W(e)})},o=!Mi&&(0,q.jsx)(`img`,{src:`/puddle.svg`,alt:`Puddle`,className:`size-4`}),s=H(`flex shrink-0 items-center gap-2`,Mi&&`[-webkit-app-region:no-drag]`),c=`truncate text-sm font-semibold text-fg-secondary`;return n&&i!==void 0?(0,q.jsxs)(`div`,{className:s,children:[o,(0,q.jsx)(Rt,{initial:e.data?.displayName??i,maxLength:64,className:H(c,`w-40`),onCommit:a,onCancel:()=>r(!1)})]}):(0,q.jsxs)(Qe,{to:`/`,className:H(s,`transition-opacity hover:opacity-70`),title:`All projects`,children:[o,i!==void 0&&(0,q.jsx)(`span`,{className:c,...qt(()=>r(!0)),children:i})]})}function Ii(){let e=rt(),t=D(`palette.toggle`),n=Me(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,q.jsxs)(`button`,{type:`button`,onClick:jt,className:H(`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`,Mi&&`[-webkit-app-region:no-drag]`),children:[(0,q.jsx)(`span`,{className:`truncate text-xs`,children:r??`Puddle`}),(0,q.jsx)(`span`,{className:`text-2xs`,children:t})]})}function Li(){let{fullScreen:e,animate:t}=w();return(0,q.jsxs)(`header`,{className:H(`relative flex h-9 shrink-0 items-center gap-3 bg-surface pl-3 pr-3`,Mi&&!e&&`pl-[88px] [-webkit-app-region:drag]`,t&&`transition-[padding] duration-200 ease-out`),children:[(0,q.jsx)(Fi,{}),(0,q.jsx)(Ii,{}),(0,q.jsxs)(`div`,{className:H(`ml-auto flex items-center`,Mi&&`[-webkit-app-region:no-drag]`),children:[(0,q.jsxs)(V,{children:[(0,q.jsx)(B,{asChild:!0,children:(0,q.jsxs)(I,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>yt(),children:[(0,q.jsx)(Vn,{}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,q.jsx)(z,{children:`Settings`})]}),(0,q.jsx)(Di,{}),(0,q.jsx)(xi,{}),(0,q.jsx)(ri,{})]})]})}function Ri(){Pi(),oi(),vi();let{handler:e}=kt(),t=k(),{pathname:n}=et(),[r,i]=(0,K.useState)(!1),a=ae(),o=a.data!==void 0&&Ee(a.data.protocol);return(0,K.useEffect)(()=>{if(!o)return;let e=()=>{let e=d();G.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),_(e)},[o]),(0,q.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[(0,q.jsx)(Li,{}),(0,q.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,q.jsx)(_n,{resetOn:n,scope:n.startsWith(`/project/`)?`workspace`:`view`,children:(0,q.jsx)(nt,{})})}),(0,q.jsx)(Qr,{}),(0,q.jsx)(ai,{}),(0,q.jsx)(qr,{onNewSession:e??void 0,onNewProject:()=>i(!0)}),t!==null&&(0,q.jsx)(dn,{profileId:t,open:r,onOpenChange:i}),(0,q.jsx)(K.Suspense,{fallback:null,children:(0,q.jsx)(Ni,{})}),(0,q.jsx)(Xr,{})]})}function zi(){return(0,q.jsx)(Wt,{children:(0,q.jsx)(Ri,{})})}var Bi=(0,K.lazy)(()=>v(()=>import(`./Dashboard-Djw9nPV_.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([20,1,2,3,4,6,5,21,10,7,8,9,11,22,16,23,19,18,24]))),Vi=(0,K.lazy)(()=>v(()=>import(`./Workspace-CmclLFK3.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([25,1,2,3,4,5,6,26,10,27,21,7,8,9,11,12,28,29,30,22,16,31,24,14,15,18,32,33,34,35,36]))),Hi=new gn({defaultOptions:{queries:{retry:1,staleTime:5e3}},mutationCache:new pn({onError:e=>W(e)})});function Ui(){let e=k(),t=Ie(),n=e!==null&&t.data!==void 0&&!t.data.some(t=>t.id===e);return e===null||n?(0,q.jsx)(Hn,{}):(0,q.jsx)(at,{useTransitions:!1,children:(0,q.jsx)(K.Suspense,{fallback:null,children:(0,q.jsx)($e,{children:(0,q.jsxs)(ot,{element:(0,q.jsx)(zi,{}),children:[(0,q.jsx)(ot,{path:`/`,element:(0,q.jsx)(Bi,{})}),(0,q.jsx)(ot,{path:`/project/:id`,element:(0,q.jsx)(Vi,{})}),(0,q.jsx)(ot,{path:`/project/:id/session/:sid`,element:(0,q.jsx)(Vi,{})})]})})})})}function Wi(){let e=(0,K.useSyncExternalStore)(b.subscribe,b.get);return(0,q.jsx)(se,{client:Hi,children:(0,q.jsxs)(It,{delayDuration:300,children:[(0,q.jsx)(Pn,{}),(0,q.jsx)(_n,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,q.jsx)(fn,{}):(0,q.jsx)(Ui,{}):(0,q.jsx)(yn,{})}),(0,q.jsx)(vn,{})]})})}export{Wi as App};
@@ -1 +1 @@
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-BP-EF5G2.js";import{C as i,E as a,Et as o,gt as s,lt as c,pt as l,ut as u,xt as d}from"./protocol-support-Dm8bEo7Y.js";import{a as f,c as p,i as m,n as h,r as g}from"./project-abbrev-D7aa-LGS.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-_JRACgt4.js";import{t as S}from"./button-CgZcwDne.js";import{a as C,i as w,o as T,s as E,t as D}from"./LazyTerminal-DRgaFViU.js";import{n as O}from"./x-CZCUod6A.js";import{A as k,M as A,c as j,j as M,k as N,n as P,r as F,t as I}from"./context-menu-CtKnUzHa.js";import{r as L}from"./dist-Bl7vUoam.js";import{t as R}from"./NewProjectDialog-Bhfj_sYl.js";import{n as z}from"./errors-BzfxU_Kw.js";import{t as B}from"./ws-Ug1Tr2sh.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)(D,{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=u(),l=o(e.id),[d,f]=(0,V.useState)(!1),[m,C]=(0,V.useState)(e.name),[D,k]=(0,V.useState)(g(e)),N=t=>c.mutate({id:e.id,archived:t},{onError:e=>z(e)}),L=()=>{C(e.name),k(g(e)),f(!0)},R=()=>{let t=m.trim(),n=h(D);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=>z(e)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(I,{children:[(0,H.jsx)(j,{asChild:!0,children:(0,H.jsxs)(`div`,{draggable:n,onDragStart:i,onDragEnd:a,onDragOver:s,className:O(`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:A,label:`Reopen project`,onClick:()=>N(!1)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{icon:w,label:`Edit project`,onClick:L}),(0,H.jsx)(Y,{icon:M,label:`Archive project`,onClick:()=>N(!0)})]})})]})}),(0,H.jsx)(P,{children:e.archived?(0,H.jsxs)(F,{onSelect:()=>N(!1),children:[(0,H.jsx)(A,{}),` Reopen`]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(F,{onSelect:L,children:[(0,H.jsx)(w,{}),` Edit`]}),(0,H.jsxs)(F,{onSelect:()=>N(!0),children:[(0,H.jsx)(M,{}),` Archive`]})]})})]}),(0,H.jsx)(x,{open:d,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(),R()},children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(T,{htmlFor:`project-name-${e.id}`,children:`Name`}),(0,H.jsx)(E,{id:`project-name-${e.id}`,value:m,onChange:e=>C(e.target.value),autoFocus:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(T,{htmlFor:`project-abbrev-${e.id}`,children:`Abbreviation`}),(0,H.jsx)(E,{id:`project-abbrev-${e.id}`,maxLength:5,value:D,onChange:e=>k(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)(T,{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=a(),t=s(e??void 0),n=d(),r=l(e??void 0),o=c(e??``),[u,p]=(0,V.useState)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(!1),y=W(),b=i(`palette.toggle`),x=e=>n.data?.find(t=>t.id===e)?.path,S=t.data??[],w=r.data?.projectOrder??[],T=N(S.filter(e=>!e.archived),w),E=S.filter(e=>e.archived),D=(e,t)=>{e!==t&&o.mutate({projectOrder:k(T.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)(C,{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:[T.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&&D(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})]}),E.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)(L,{className:O(`size-3 transition-transform`,_&&`rotate-90`)}),(0,H.jsx)(M,{className:`size-3`}),(0,H.jsx)(`span`,{children:`Archived`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:E.length})]}),_&&(0,H.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:E.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)(R,{profileId:e,open:u,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-CPKHBs7z.js";import{C as i,E as a,Et as o,gt as s,lt as c,pt as l,ut as u,xt as d}from"./protocol-support-hVrRUHAd.js";import{a as f,c as p,i as m,n as h,r as g}from"./project-abbrev-B5CMO00I.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-BoaHxScl.js";import{t as S}from"./button-D3DTuFk3.js";import{a as C,i as w,o as T,s as E,t as D}from"./LazyTerminal-BN3rEDcD.js";import{n as O}from"./x-CZCUod6A.js";import{A as k,M as A,c as j,j as M,k as N,n as P,r as F,t as I}from"./context-menu-CwR-PGrS.js";import{r as L}from"./dist-DUfD4S2p.js";import{t as R}from"./NewProjectDialog-BK_gfWmL.js";import{n as z}from"./errors-BkbAF9Bu.js";import{t as B}from"./ws-B6RLTvWI.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)(D,{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=u(),l=o(e.id),[d,f]=(0,V.useState)(!1),[m,C]=(0,V.useState)(e.name),[D,k]=(0,V.useState)(g(e)),N=t=>c.mutate({id:e.id,archived:t},{onError:e=>z(e)}),L=()=>{C(e.name),k(g(e)),f(!0)},R=()=>{let t=m.trim(),n=h(D);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=>z(e)})};return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(I,{children:[(0,H.jsx)(j,{asChild:!0,children:(0,H.jsxs)(`div`,{draggable:n,onDragStart:i,onDragEnd:a,onDragOver:s,className:O(`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:A,label:`Reopen project`,onClick:()=>N(!1)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{icon:w,label:`Edit project`,onClick:L}),(0,H.jsx)(Y,{icon:M,label:`Archive project`,onClick:()=>N(!0)})]})})]})}),(0,H.jsx)(P,{children:e.archived?(0,H.jsxs)(F,{onSelect:()=>N(!1),children:[(0,H.jsx)(A,{}),` Reopen`]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(F,{onSelect:L,children:[(0,H.jsx)(w,{}),` Edit`]}),(0,H.jsxs)(F,{onSelect:()=>N(!0),children:[(0,H.jsx)(M,{}),` Archive`]})]})})]}),(0,H.jsx)(x,{open:d,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(),R()},children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(T,{htmlFor:`project-name-${e.id}`,children:`Name`}),(0,H.jsx)(E,{id:`project-name-${e.id}`,value:m,onChange:e=>C(e.target.value),autoFocus:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(T,{htmlFor:`project-abbrev-${e.id}`,children:`Abbreviation`}),(0,H.jsx)(E,{id:`project-abbrev-${e.id}`,maxLength:5,value:D,onChange:e=>k(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)(T,{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=a(),t=s(e??void 0),n=d(),r=l(e??void 0),o=c(e??``),[u,p]=(0,V.useState)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(!1),y=W(),b=i(`palette.toggle`),x=e=>n.data?.find(t=>t.id===e)?.path,S=t.data??[],w=r.data?.projectOrder??[],T=N(S.filter(e=>!e.archived),w),E=S.filter(e=>e.archived),D=(e,t)=>{e!==t&&o.mutate({projectOrder:k(T.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)(C,{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:[T.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&&D(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})]}),E.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)(L,{className:O(`size-3 transition-transform`,_&&`rotate-90`)}),(0,H.jsx)(M,{className:`size-3`}),(0,H.jsx)(`span`,{children:`Archived`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:E.length})]}),_&&(0,H.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:E.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)(R,{profileId:e,open:u,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-BP-EF5G2.js";import{i as r,t as i,u as a}from"./buffer-store-BIpSx_-b.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./dialog-_JRACgt4.js";import{t as f}from"./button-CgZcwDne.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-CPKHBs7z.js";import{i as r,t as i,u as a}from"./buffer-store-BtRP7zZm.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./dialog-BoaHxScl.js";import{t as f}from"./button-D3DTuFk3.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 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n}from"./index-BP-EF5G2.js";import{n as r,t as i}from"./x-CZCUod6A.js";import{t as a}from"./createLucideIcon-DyMAgLa3.js";import{C as o,b as s,x as c}from"./selection-actions-D5wKfiBu.js";import{t as l}from"./chevron-down--sjpQEHH.js";var u=a(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),d=/[.*+?^${}()|[\]\\]/g;function f(e,t){if(e.length===0)return null;try{let n=t.regex?e:e.replace(d,`\\$&`);return t.wholeWord&&(n=`\\b(?:${n})\\b`),new RegExp(n,t.caseSensitive?`g`:`gi`)}catch{return null}}function p(e,t){return e.length===0||f(e,t)!==null}function m(e,t,n,r=1e3){let i=f(t,n);if(t.length>0&&i===null)return{matches:[],invalid:!0,limited:!1};if(!i)return{matches:[],invalid:!1,limited:!1};let a=[],o;for(;(o=i.exec(e))!==null;){if(o[0].length===0){i.lastIndex++;continue}if(a.length===r)return{matches:a,invalid:!1,limited:!0};a.push({start:o.index,end:o.index+o[0].length})}return{matches:a,invalid:!1,limited:!1}}var h=e(t(),1),g={index:-1,count:0},_={caseSensitive:!1,wholeWord:!1,regex:!1},v=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform);function y(e,t=v){return e.key.toLowerCase()===`f`&&!e.altKey&&!e.shiftKey&&(t?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)}function b({shortcutEnabled:e,onFind:t,onClear:n,onCloseFocus:r}){let[i,a]=(0,h.useState)(!1),[o,s]=(0,h.useState)(0),[c,l]=(0,h.useState)(``),[u,d]=(0,h.useState)(_),[f,p]=(0,h.useState)(g),m=(0,h.useRef)({open:i,query:c,options:u});m.current={open:i,query:c,options:u};let v=(0,h.useRef)(t);v.current=t;let b=(0,h.useRef)(n);b.current=n;let x=(0,h.useRef)(r);x.current=r;let S=(0,h.useCallback)(e=>{let t=m.current;if(!t.open)return;let n=v.current(t.query,t.options,e);n&&p(n)},[]),C=(0,h.useCallback)(()=>{a(!0),s(e=>e+1)},[]),w=(0,h.useCallback)(()=>{a(!1),b.current(),x.current?.()},[]),T=(0,h.useCallback)(()=>S(`next`),[S]),E=(0,h.useCallback)(()=>S(`previous`),[S]),D=(0,h.useCallback)(()=>S(`reset`),[S]);return(0,h.useEffect)(()=>{i&&S(`reset`)},[i,c,u,S]),(0,h.useEffect)(()=>{if(!e)return;let t=e=>{y(e)&&(e.preventDefault(),e.stopPropagation(),C())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,C]),(0,h.useEffect)(()=>()=>{b.current()},[]),{open:i,focusKey:o,query:c,options:u,result:f,openFind:C,close:w,next:T,previous:E,refresh:D,setQuery:l,setOptions:d,setResult:p}}var x=[[`$$`,`$$`,!0],[`\\[`,`\\]`,!0],[`\\(`,`\\)`,!1],[`$`,`$`,!1]];function S(e){return e===`$`||e===`\\`}function C(e,t=0){for(let[n,r,i]of x){if(!e.startsWith(n,t))continue;let a=t+n.length,o=T(e,a,r);if(o<0)continue;let s=e.slice(a,o);if(!(s.trim()===``||/\n[ \t]*\n/.test(s))&&!(n===`$`&&!E(s,e[o+r.length])))return{length:o+r.length-t,tex:s,display:i}}return null}function w(e,t=0){for(let n=t;n<e.length;n++){if(!S(e[n]))continue;let t=C(e,n);if(t)return{...t,start:n}}return null}function T(e,t,n){for(let r=t;r<e.length;r++){if(e.startsWith(n,r))return r;e[r]===`\\`&&r++}return-1}function E(e,t){return!/^\s|\s$/.test(e)&&!(t!==void 0&&/\d/.test(t))}var D=n();function O({active:e,label:t,onClick:n,children:i}){return(0,D.jsx)(`button`,{type:`button`,"aria-label":t,"aria-pressed":e,title:t,onClick:n,className:r(`rounded-sm p-1 transition-colors`,e?`bg-surface text-accent`:`text-fg-muted hover:bg-surface hover:text-fg`),children:i})}function k({query:e,result:t}){return e.length===0?null:t.invalid?(0,D.jsx)(D.Fragment,{children:`Invalid expression`}):t.count===0?(0,D.jsx)(D.Fragment,{children:`No results`}):t.limited?(0,D.jsxs)(D.Fragment,{children:[t.count,`+ results`]}):t.index<0?(0,D.jsxs)(D.Fragment,{children:[t.count,` results`]}):(0,D.jsxs)(D.Fragment,{children:[t.index+1,` of `,t.count]})}function A({query:e,focusKey:t,options:n,result:r,onQueryChange:a,onOptionsChange:d,onNext:f,onPrevious:p,onClose:m}){let g=(0,h.useRef)(null);(0,h.useEffect)(()=>{g.current?.focus(),g.current?.select()},[t]);let _=r.count>0&&!r.invalid;return(0,D.jsxs)(`div`,{role:`search`,"aria-label":`Find in view`,className:`absolute right-2 top-0 z-30 flex h-10 w-[min(34rem,calc(100%-0.5rem))] items-center gap-1.5 rounded-b-md bg-surface px-1.5 shadow-lg`,onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),m();return}if(e.key===`Enter`){e.preventDefault(),e.stopPropagation(),e.shiftKey?p():f();return}y(e.nativeEvent)&&(e.preventDefault(),e.stopPropagation(),g.current?.select())},children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center rounded-md bg-elevated pl-2 pr-0.5`,children:[(0,D.jsx)(`input`,{ref:g,value:e,onChange:e=>a(e.target.value),placeholder:`Find`,spellCheck:!1,autoComplete:`off`,"aria-label":`Find`,className:`h-7 min-w-0 flex-1 bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted`}),(0,D.jsx)(O,{active:n.caseSensitive,label:`Match case`,onClick:()=>d({...n,caseSensitive:!n.caseSensitive}),children:(0,D.jsx)(o,{className:`size-3.5`})}),(0,D.jsx)(O,{active:n.wholeWord,label:`Match whole word`,onClick:()=>d({...n,wholeWord:!n.wholeWord}),children:(0,D.jsx)(s,{className:`size-3.5`})}),(0,D.jsx)(O,{active:n.regex,label:`Use regular expression`,onClick:()=>d({...n,regex:!n.regex}),children:(0,D.jsx)(c,{className:`size-3.5`})})]}),(0,D.jsx)(`div`,{className:`w-20 shrink-0 text-center text-xs text-fg-muted`,children:(0,D.jsx)(k,{query:e,result:r})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,disabled:!_,onClick:p,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,children:(0,D.jsx)(u,{className:`size-4`})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Next match`,title:`Next match (Enter)`,disabled:!_,onClick:f,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,children:(0,D.jsx)(l,{className:`size-4`})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Close find`,title:`Close (Escape)`,onClick:m,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg`,children:(0,D.jsx)(i,{className:`size-4`})})]})}export{b as a,m as c,C as i,p as l,S as n,y as o,w as r,g as s,A as t};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n}from"./index-CPKHBs7z.js";import{n as r,t as i}from"./x-CZCUod6A.js";import{t as a}from"./createLucideIcon-DyMAgLa3.js";import{C as o,b as s,x as c}from"./selection-actions-BDJnKwuj.js";import{t as l}from"./chevron-down--sjpQEHH.js";var u=a(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),d=/[.*+?^${}()|[\]\\]/g;function f(e,t){if(e.length===0)return null;try{let n=t.regex?e:e.replace(d,`\\$&`);return t.wholeWord&&(n=`\\b(?:${n})\\b`),new RegExp(n,t.caseSensitive?`g`:`gi`)}catch{return null}}function p(e,t){return e.length===0||f(e,t)!==null}function m(e,t,n,r=1e3){let i=f(t,n);if(t.length>0&&i===null)return{matches:[],invalid:!0,limited:!1};if(!i)return{matches:[],invalid:!1,limited:!1};let a=[],o;for(;(o=i.exec(e))!==null;){if(o[0].length===0){i.lastIndex++;continue}if(a.length===r)return{matches:a,invalid:!1,limited:!0};a.push({start:o.index,end:o.index+o[0].length})}return{matches:a,invalid:!1,limited:!1}}var h=e(t(),1),g={index:-1,count:0},_={caseSensitive:!1,wholeWord:!1,regex:!1},v=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform);function y(e,t=v){return e.key.toLowerCase()===`f`&&!e.altKey&&!e.shiftKey&&(t?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)}function b({shortcutEnabled:e,onFind:t,onClear:n,onCloseFocus:r}){let[i,a]=(0,h.useState)(!1),[o,s]=(0,h.useState)(0),[c,l]=(0,h.useState)(``),[u,d]=(0,h.useState)(_),[f,p]=(0,h.useState)(g),m=(0,h.useRef)({open:i,query:c,options:u});m.current={open:i,query:c,options:u};let v=(0,h.useRef)(t);v.current=t;let b=(0,h.useRef)(n);b.current=n;let x=(0,h.useRef)(r);x.current=r;let S=(0,h.useCallback)(e=>{let t=m.current;if(!t.open)return;let n=v.current(t.query,t.options,e);n&&p(n)},[]),C=(0,h.useCallback)(()=>{a(!0),s(e=>e+1)},[]),w=(0,h.useCallback)(()=>{a(!1),b.current(),x.current?.()},[]),T=(0,h.useCallback)(()=>S(`next`),[S]),E=(0,h.useCallback)(()=>S(`previous`),[S]),D=(0,h.useCallback)(()=>S(`reset`),[S]);return(0,h.useEffect)(()=>{i&&S(`reset`)},[i,c,u,S]),(0,h.useEffect)(()=>{if(!e)return;let t=e=>{y(e)&&(e.preventDefault(),e.stopPropagation(),C())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,C]),(0,h.useEffect)(()=>()=>{b.current()},[]),{open:i,focusKey:o,query:c,options:u,result:f,openFind:C,close:w,next:T,previous:E,refresh:D,setQuery:l,setOptions:d,setResult:p}}var x=[[`$$`,`$$`,!0],[`\\[`,`\\]`,!0],[`\\(`,`\\)`,!1],[`$`,`$`,!1]];function S(e){return e===`$`||e===`\\`}function C(e,t=0){for(let[n,r,i]of x){if(!e.startsWith(n,t))continue;let a=t+n.length,o=T(e,a,r);if(o<0)continue;let s=e.slice(a,o);if(!(s.trim()===``||/\n[ \t]*\n/.test(s))&&!(n===`$`&&!E(s,e[o+r.length])))return{length:o+r.length-t,tex:s,display:i}}return null}function w(e,t=0){for(let n=t;n<e.length;n++){if(!S(e[n]))continue;let t=C(e,n);if(t)return{...t,start:n}}return null}function T(e,t,n){for(let r=t;r<e.length;r++){if(e.startsWith(n,r))return r;e[r]===`\\`&&r++}return-1}function E(e,t){return!/^\s|\s$/.test(e)&&!(t!==void 0&&/\d/.test(t))}var D=n();function O({active:e,label:t,onClick:n,children:i}){return(0,D.jsx)(`button`,{type:`button`,"aria-label":t,"aria-pressed":e,title:t,onClick:n,className:r(`rounded-sm p-1 transition-colors`,e?`bg-surface text-accent`:`text-fg-muted hover:bg-surface hover:text-fg`),children:i})}function k({query:e,result:t}){return e.length===0?null:t.invalid?(0,D.jsx)(D.Fragment,{children:`Invalid expression`}):t.count===0?(0,D.jsx)(D.Fragment,{children:`No results`}):t.limited?(0,D.jsxs)(D.Fragment,{children:[t.count,`+ results`]}):t.index<0?(0,D.jsxs)(D.Fragment,{children:[t.count,` results`]}):(0,D.jsxs)(D.Fragment,{children:[t.index+1,` of `,t.count]})}function A({query:e,focusKey:t,options:n,result:r,onQueryChange:a,onOptionsChange:d,onNext:f,onPrevious:p,onClose:m}){let g=(0,h.useRef)(null);(0,h.useEffect)(()=>{g.current?.focus(),g.current?.select()},[t]);let _=r.count>0&&!r.invalid;return(0,D.jsxs)(`div`,{role:`search`,"aria-label":`Find in view`,className:`absolute right-2 top-0 z-30 flex h-10 w-[min(34rem,calc(100%-0.5rem))] items-center gap-1.5 rounded-b-md bg-surface px-1.5 shadow-lg`,onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),m();return}if(e.key===`Enter`){e.preventDefault(),e.stopPropagation(),e.shiftKey?p():f();return}y(e.nativeEvent)&&(e.preventDefault(),e.stopPropagation(),g.current?.select())},children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center rounded-md bg-elevated pl-2 pr-0.5`,children:[(0,D.jsx)(`input`,{ref:g,value:e,onChange:e=>a(e.target.value),placeholder:`Find`,spellCheck:!1,autoComplete:`off`,"aria-label":`Find`,className:`h-7 min-w-0 flex-1 bg-transparent text-sm text-fg outline-none placeholder:text-fg-muted`}),(0,D.jsx)(O,{active:n.caseSensitive,label:`Match case`,onClick:()=>d({...n,caseSensitive:!n.caseSensitive}),children:(0,D.jsx)(o,{className:`size-3.5`})}),(0,D.jsx)(O,{active:n.wholeWord,label:`Match whole word`,onClick:()=>d({...n,wholeWord:!n.wholeWord}),children:(0,D.jsx)(s,{className:`size-3.5`})}),(0,D.jsx)(O,{active:n.regex,label:`Use regular expression`,onClick:()=>d({...n,regex:!n.regex}),children:(0,D.jsx)(c,{className:`size-3.5`})})]}),(0,D.jsx)(`div`,{className:`w-20 shrink-0 text-center text-xs text-fg-muted`,children:(0,D.jsx)(k,{query:e,result:r})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,disabled:!_,onClick:p,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,children:(0,D.jsx)(u,{className:`size-4`})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Next match`,title:`Next match (Enter)`,disabled:!_,onClick:f,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,children:(0,D.jsx)(l,{className:`size-4`})}),(0,D.jsx)(`button`,{type:`button`,"aria-label":`Close find`,title:`Close (Escape)`,onClick:m,className:`rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg`,children:(0,D.jsx)(i,{className:`size-4`})})]})}export{b as a,m as c,C as i,p as l,S as n,y as o,w as r,g as s,A as t};