@puddle-code/cli 0.3.13 → 0.3.14

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 (34) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/host-control.mjs +25 -25
  3. package/dist/index.js +58 -57
  4. package/dist/public/assets/App-5QiKmUI_.js +2 -0
  5. package/dist/public/assets/{CompilationCommandForm-Bzt5OaiJ.js → CompilationCommandForm-8ipw9M-Z.js} +1 -1
  6. package/dist/public/assets/{Dashboard-D6cwjmKX.js → Dashboard-B9v8mQKk.js} +1 -1
  7. package/dist/public/assets/{EditorTabClose-xasqNn4b.js → EditorTabClose-o1L4BgTN.js} +1 -1
  8. package/dist/public/assets/{LazyTerminal-B2eXi-NW.js → LazyTerminal-Crwcrh-K.js} +2 -2
  9. package/dist/public/assets/{ModelRefcount-Dfulry9I.js → ModelRefcount-0o8MEOUT.js} +1 -1
  10. package/dist/public/assets/{NewProjectDialog-DTZfXXpH.js → NewProjectDialog-qFDLTphH.js} +1 -1
  11. package/dist/public/assets/{NotebookWidget-D2ddZny7.js → NotebookWidget-Ci7TAuWd.js} +1 -1
  12. package/dist/public/assets/{PaneEditorBody-DM3RxU9y.js → PaneEditorBody-C8uTV9yU.js} +29 -29
  13. package/dist/public/assets/PdfViewer-BoFsXAue.js +2 -0
  14. package/dist/public/assets/{SettingsDialog-DK_xpwwR.js → SettingsDialog-tW18Y_Wr.js} +1 -1
  15. package/dist/public/assets/{Terminal-C56yFFee.js → Terminal-B3Iw783s.js} +21 -21
  16. package/dist/public/assets/{Workspace-DJGOiast.js → Workspace-D2IYXJV2.js} +5 -5
  17. package/dist/public/assets/{buffer-store-JDgXuYJp.js → buffer-store-B2nYD11t.js} +1 -1
  18. package/dist/public/assets/{button-BgeBH2Uc.js → button-9AVMLaMQ.js} +1 -1
  19. package/dist/public/assets/{index-B_fYaxIG.js → index-B9DFgBft.js} +2 -2
  20. package/dist/public/assets/index-DwtrJj9v.css +2 -0
  21. package/dist/public/assets/{markdown-mermaid-BVt1aqNY.js → markdown-mermaid-CZnHoKN5.js} +1 -1
  22. package/dist/public/assets/{notification-delivery-DhFtFhEH.js → notification-delivery-DdTD40aA.js} +1 -1
  23. package/dist/public/assets/scroll-restoration-gKZDDamc.js +1 -0
  24. package/dist/public/assets/{selection-actions--OSfjvlG.js → selection-actions-BjVj7hXw.js} +1 -1
  25. package/dist/public/assets/use-ui-state-CQp93ZE4.js +1 -0
  26. package/dist/public/assets/view-state-store-CVAUWqnG.js +1 -0
  27. package/dist/public/index.html +2 -2
  28. package/dist/pudl.js +29 -29
  29. package/package.json +1 -1
  30. package/dist/public/assets/App-Dtn-lPJX.js +0 -2
  31. package/dist/public/assets/PdfViewer-BR_qnX0w.js +0 -2
  32. package/dist/public/assets/index-ChK3zzci.css +0 -2
  33. package/dist/public/assets/scroll-restoration-xYrqc2k4.js +0 -1
  34. package/dist/public/assets/use-ui-state-DEsKtleW.js +0 -1
package/dist/index.js CHANGED
@@ -3754,7 +3754,7 @@ var init_wrapper = __esm({
3754
3754
  }
3755
3755
  });
3756
3756
 
3757
- // src/lib/ws-client.ts
3757
+ // src/lib/transport/ws-client.ts
3758
3758
  function connectGateway(port, authority) {
3759
3759
  return new Promise((resolve6, reject) => {
3760
3760
  const ws = new wrapper_default(`ws://127.0.0.1:${port}/ws`, {
@@ -3810,14 +3810,14 @@ function connectGateway(port, authority) {
3810
3810
  });
3811
3811
  }
3812
3812
  var init_ws_client = __esm({
3813
- "src/lib/ws-client.ts"() {
3813
+ "src/lib/transport/ws-client.ts"() {
3814
3814
  "use strict";
3815
3815
  init_wrapper();
3816
3816
  init_types();
3817
3817
  }
3818
3818
  });
3819
3819
 
3820
- // src/lib/attach.ts
3820
+ // src/lib/connection/attach.ts
3821
3821
  var attach_exports = {};
3822
3822
  __export(attach_exports, {
3823
3823
  attachSession: () => attachSession,
@@ -3909,7 +3909,7 @@ async function attachSession(opts) {
3909
3909
  }
3910
3910
  var DETACH;
3911
3911
  var init_attach = __esm({
3912
- "src/lib/attach.ts"() {
3912
+ "src/lib/connection/attach.ts"() {
3913
3913
  "use strict";
3914
3914
  init_ws_client();
3915
3915
  init_types();
@@ -18493,7 +18493,7 @@ var agentNotificationSchema = external_exports.object({
18493
18493
  content: notificationContentSchema.optional()
18494
18494
  });
18495
18495
 
18496
- // ../shared/src/api/version.ts
18496
+ // ../shared/src/api/connection/version.ts
18497
18497
  var versionResponseSchema = external_exports.object({
18498
18498
  version: external_exports.string(),
18499
18499
  /** Added by the host connector; absent on direct daemon responses and older connectors. */
@@ -18506,7 +18506,7 @@ var versionResponseSchema = external_exports.object({
18506
18506
  })
18507
18507
  });
18508
18508
 
18509
- // ../shared/src/api/agent-signal.ts
18509
+ // ../shared/src/api/agents/agent-signal.ts
18510
18510
  var statusSignalSchema = external_exports.object({
18511
18511
  nonce: external_exports.string().min(16),
18512
18512
  state: external_exports.enum(["working", "waiting_input"])
@@ -18586,7 +18586,7 @@ var fsDirsResponseSchema = external_exports.object({
18586
18586
  entries: external_exports.array(fsDirEntrySchema)
18587
18587
  });
18588
18588
 
18589
- // ../shared/src/api/host.ts
18589
+ // ../shared/src/api/connection/host.ts
18590
18590
  var hostInfoSchema = external_exports.object({
18591
18591
  username: external_exports.string(),
18592
18592
  hostname: external_exports.string(),
@@ -18711,7 +18711,7 @@ var untitledFileResponseSchema = external_exports.object({
18711
18711
  var putUntitledRequestSchema = external_exports.object({ content: external_exports.string() });
18712
18712
  var putUntitledResponseSchema = external_exports.object({ mtime_ms: external_exports.number() });
18713
18713
 
18714
- // ../shared/src/api/accounts.ts
18714
+ // ../shared/src/api/agents/accounts.ts
18715
18715
  var accountSchema = external_exports.object({
18716
18716
  id: rowId,
18717
18717
  profile_id: profileId,
@@ -18782,7 +18782,7 @@ var accountUsageSchema = external_exports.looseObject({
18782
18782
  }).nullable()
18783
18783
  });
18784
18784
 
18785
- // ../shared/src/api/agents.ts
18785
+ // ../shared/src/api/agents/agents.ts
18786
18786
  var agentTypeSchema = external_exports.object({
18787
18787
  id: external_exports.string(),
18788
18788
  display_name: external_exports.string(),
@@ -18805,7 +18805,7 @@ var agentTypeSchema = external_exports.object({
18805
18805
  available: external_exports.boolean().optional()
18806
18806
  });
18807
18807
 
18808
- // ../shared/src/api/repos.ts
18808
+ // ../shared/src/api/workspace/repos.ts
18809
18809
  var repoSchema = external_exports.object({
18810
18810
  id: rowId,
18811
18811
  path: external_exports.string(),
@@ -18868,7 +18868,7 @@ var patchRepoRequestSchema = external_exports.object({
18868
18868
  fetch_enabled: external_exports.boolean().optional()
18869
18869
  });
18870
18870
 
18871
- // ../shared/src/api/sessions.ts
18871
+ // ../shared/src/api/agents/sessions.ts
18872
18872
  var sessionStatusSchema = external_exports.enum([
18873
18873
  "starting",
18874
18874
  "running",
@@ -19035,7 +19035,7 @@ var archiveRequestSchema = external_exports.object({
19035
19035
  delete_branch: external_exports.boolean().default(false)
19036
19036
  });
19037
19037
 
19038
- // ../shared/src/api/projects.ts
19038
+ // ../shared/src/api/workspace/projects.ts
19039
19039
  var projectAbbrev2 = external_exports.string().min(1).max(5);
19040
19040
  var projectColourSchema = external_exports.enum(PROFILE_ICON_COLOURS);
19041
19041
  var projectSchema = external_exports.object({
@@ -19072,7 +19072,7 @@ var projectDetailSchema = external_exports.object({
19072
19072
  sessions: external_exports.array(sessionSchema)
19073
19073
  });
19074
19074
 
19075
- // ../shared/src/api/scratchpad.ts
19075
+ // ../shared/src/api/workspace/scratchpad.ts
19076
19076
  var scratchpadScopeSchema = external_exports.enum(["project", "profile"]);
19077
19077
  var scratchpadEntrySchema = external_exports.object({
19078
19078
  id: rowId,
@@ -19235,7 +19235,7 @@ var updateCompilationDefaultsRequestSchema = compilationDefaultsRequestSchema.ex
19235
19235
  command: updateCompilationSettingsRequestSchema.shape.command
19236
19236
  });
19237
19237
 
19238
- // ../shared/src/api/ui-state.ts
19238
+ // ../shared/src/api/workspace/ui-state.ts
19239
19239
  var editorTabRefSchema = external_exports.object({
19240
19240
  session: sessionId,
19241
19241
  path: external_exports.string(),
@@ -19372,7 +19372,7 @@ var uiStateResponseSchema = external_exports.object({
19372
19372
  updated_at: isoTimestamp
19373
19373
  });
19374
19374
 
19375
- // ../shared/src/api/layouts.ts
19375
+ // ../shared/src/api/workspace/layouts.ts
19376
19376
  var layoutScopeSchema = external_exports.enum(["project", "profile"]);
19377
19377
  var savedLayoutSchema = external_exports.object({
19378
19378
  id: rowId,
@@ -19400,7 +19400,7 @@ var patchLayoutRequestSchema = external_exports.object({
19400
19400
  active_session: sessionId.nullable().optional()
19401
19401
  });
19402
19402
 
19403
- // ../shared/src/api/notebooks.ts
19403
+ // ../shared/src/api/notebooks/notebooks.ts
19404
19404
  var notebookKernelSpecSchema = external_exports.object({
19405
19405
  name: external_exports.string().min(1),
19406
19406
  display_name: external_exports.string().min(1),
@@ -19459,7 +19459,7 @@ var latexSynctexResponseSchema = compilationFileTargetSchema.extend({
19459
19459
  column: external_exports.number().int().nonnegative().optional()
19460
19460
  });
19461
19461
 
19462
- // ../shared/src/api/worktrees.ts
19462
+ // ../shared/src/api/worktrees/worktrees.ts
19463
19463
  var pasteImageMimeSchema = external_exports.enum(["image/png", "image/jpeg", "image/gif", "image/webp"]);
19464
19464
  var pasteImageRequestSchema = external_exports.object({
19465
19465
  mime: pasteImageMimeSchema,
@@ -19494,7 +19494,7 @@ var resolvePathResponseSchema = external_exports.object({
19494
19494
  root: external_exports.string().optional()
19495
19495
  });
19496
19496
 
19497
- // ../shared/src/api/worktree-files.ts
19497
+ // ../shared/src/api/worktrees/worktree-files.ts
19498
19498
  var treeEntrySchema = external_exports.object({
19499
19499
  name: external_exports.string(),
19500
19500
  /**
@@ -19546,7 +19546,7 @@ var uploadResponseSchema = external_exports.object({
19546
19546
  )
19547
19547
  });
19548
19548
 
19549
- // ../shared/src/api/worktree-fs.ts
19549
+ // ../shared/src/api/worktrees/worktree-fs.ts
19550
19550
  var createEntryRequestSchema = external_exports.object({
19551
19551
  path: external_exports.string().min(1),
19552
19552
  kind: external_exports.enum(["file", "dir"])
@@ -19576,7 +19576,7 @@ var fsOpResponseSchema = external_exports.object({
19576
19576
  path: external_exports.string()
19577
19577
  });
19578
19578
 
19579
- // ../shared/src/api/worktree-git.ts
19579
+ // ../shared/src/api/worktrees/worktree-git.ts
19580
19580
  var diffStatusSchema = external_exports.enum(["added", "modified", "deleted", "renamed"]);
19581
19581
  var gitAreaSchema = external_exports.enum(["staged", "unstaged"]);
19582
19582
  var diffEntrySchema = external_exports.object({
@@ -19704,7 +19704,7 @@ var showCommitResponseSchema = external_exports.object({
19704
19704
  files: external_exports.array(diffEntrySchema)
19705
19705
  });
19706
19706
 
19707
- // ../shared/src/api/worktree-search.ts
19707
+ // ../shared/src/api/worktrees/worktree-search.ts
19708
19708
  var searchMatchSchema = external_exports.object({
19709
19709
  line: external_exports.number().int().positive(),
19710
19710
  text: external_exports.string()
@@ -19737,7 +19737,7 @@ var sessionPortsResponseSchema = external_exports.object({
19737
19737
  scanned_at: isoTimestamp
19738
19738
  });
19739
19739
 
19740
- // ../shared/src/api/cockpit.ts
19740
+ // ../shared/src/api/connection/cockpit.ts
19741
19741
  var cockpitRefreshRequestSchema = external_exports.object({ refreshId: external_exports.string().uuid() }).strict();
19742
19742
  var cockpitRefreshResponseSchema = external_exports.object({
19743
19743
  status: external_exports.literal("refreshing"),
@@ -20015,7 +20015,7 @@ var remoteBrowserHostSchema = external_exports.object({
20015
20015
  privateKey: remoteIdentitySchema
20016
20016
  }).strict();
20017
20017
 
20018
- // ../shared/src/api/cockpit-remote.ts
20018
+ // ../shared/src/api/connection/cockpit-remote.ts
20019
20019
  var connectorLocalRequestSchema = external_exports.union([
20020
20020
  remoteAdminRequestSchema,
20021
20021
  external_exports.object({ t: external_exports.literal("delete_registration") }).strict()
@@ -20046,7 +20046,7 @@ var connectorProfileSchema = external_exports.object({ profile: profileId }).str
20046
20046
  var connectorAdminSchema = external_exports.object({ profile: profileId, request: connectorLocalRequestSchema }).strict();
20047
20047
  var connectorConfigureSchema = external_exports.object({ profile: profileId, setup: connectorSetupSchema }).strict();
20048
20048
 
20049
- // ../shared/src/api/connection-auth.ts
20049
+ // ../shared/src/api/connection/connection-auth.ts
20050
20050
  var CONNECTION_POLICY = {
20051
20051
  participationMs: 15e3,
20052
20052
  leaseMs: 45e3,
@@ -20205,7 +20205,7 @@ var connectorNotificationSchema = external_exports.object({
20205
20205
  var pushDispatchResultSchema = external_exports.object({ accepted: external_exports.number().int().nonnegative(), failed: external_exports.number().int().nonnegative() }).strict();
20206
20206
  var pushPreferenceResultSchema = external_exports.object({ enabled: external_exports.boolean() }).strict();
20207
20207
 
20208
- // ../shared/src/api/puddlang.ts
20208
+ // ../shared/src/api/agents/puddlang.ts
20209
20209
  var PUDDLANG_MAX_SOURCE = 256 * 1024;
20210
20210
  var sourceSchema = external_exports.string().min(1).max(PUDDLANG_MAX_SOURCE).refine(
20211
20211
  (source) => new TextEncoder().encode(source).length <= PUDDLANG_MAX_SOURCE,
@@ -20299,7 +20299,7 @@ var puddlangContextSchema = external_exports.object({
20299
20299
  )
20300
20300
  });
20301
20301
 
20302
- // ../shared/src/api/puddlang-mcp.ts
20302
+ // ../shared/src/api/agents/puddlang-mcp.ts
20303
20303
  var puddlangMcpRequestSchema = external_exports.object({
20304
20304
  jsonrpc: external_exports.literal("2.0"),
20305
20305
  id: external_exports.union([external_exports.string(), external_exports.number()]).optional(),
@@ -20360,7 +20360,7 @@ var puddlangMcpTools = definitions.map(([name, description, schema, readOnlyHint
20360
20360
  }
20361
20361
  }));
20362
20362
 
20363
- // ../shared/src/api/notebook-execution.ts
20363
+ // ../shared/src/api/notebooks/notebook-execution.ts
20364
20364
  var cellId = external_exports.string().min(1).max(128);
20365
20365
  var cellSource = external_exports.object({ id: cellId, source: external_exports.string().max(1024 * 1024) });
20366
20366
  var notebookExecuteSchema = external_exports.object({
@@ -20405,7 +20405,7 @@ var notebookInputReplySchema = external_exports.object({
20405
20405
  value: external_exports.string().max(65536)
20406
20406
  });
20407
20407
 
20408
- // ../shared/src/api/notebook-intelligence.ts
20408
+ // ../shared/src/api/notebooks/notebook-intelligence.ts
20409
20409
  var notebookIntelligenceRequestSchema = external_exports.object({
20410
20410
  source: compilationFileTargetSchema,
20411
20411
  kind: external_exports.enum(["complete", "inspect"]),
@@ -20420,7 +20420,7 @@ var notebookIntelligenceResponseSchema = external_exports.object({
20420
20420
  documentation: external_exports.string().max(32768)
20421
20421
  });
20422
20422
 
20423
- // ../shared/src/api/notebook-widgets.ts
20423
+ // ../shared/src/api/notebooks/notebook-widgets.ts
20424
20424
  var id = external_exports.string().min(1).max(128);
20425
20425
  var json2 = external_exports.record(external_exports.string(), external_exports.unknown());
20426
20426
  var binary = external_exports.string().max(2 * 1024 * 1024).regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/);
@@ -21289,7 +21289,7 @@ function argvFor(command) {
21289
21289
  // src/cli/daemon-upgrade-prompt.ts
21290
21290
  import { randomUUID } from "node:crypto";
21291
21291
 
21292
- // src/lib/handshake.ts
21292
+ // src/lib/connection/handshake.ts
21293
21293
  init_types();
21294
21294
  var CLI_UPGRADE_COMMAND = "puddle upgrade cli";
21295
21295
  function decideHandshake(cli, daemon) {
@@ -21989,7 +21989,7 @@ import { existsSync as existsSync7 } from "node:fs";
21989
21989
  import { dirname as dirname13, join as join17 } from "node:path";
21990
21990
  import { fileURLToPath as fileURLToPath5 } from "node:url";
21991
21991
 
21992
- // src/lib/browser.ts
21992
+ // src/lib/serve/browser.ts
21993
21993
  import { spawn as spawn3 } from "node:child_process";
21994
21994
  function openBrowser(url2, platform = process.platform) {
21995
21995
  const command = platform === "darwin" ? { bin: "open", args: [url2] } : platform === "win32" ? { bin: "cmd", args: ["/c", "start", "", url2] } : { bin: "xdg-open", args: [url2] };
@@ -22004,7 +22004,7 @@ function openBrowser(url2, platform = process.platform) {
22004
22004
  }
22005
22005
  }
22006
22006
 
22007
- // src/lib/component-versions.ts
22007
+ // src/lib/installation/component-versions.ts
22008
22008
  import {
22009
22009
  existsSync as existsSync2,
22010
22010
  mkdirSync as mkdirSync4,
@@ -22015,7 +22015,7 @@ import {
22015
22015
  } from "node:fs";
22016
22016
  import { dirname as dirname6, join as join7, resolve as resolve2 } from "node:path";
22017
22017
 
22018
- // src/lib/desktop-update.ts
22018
+ // src/lib/installation/desktop-update.ts
22019
22019
  import { createHash as createHash2 } from "node:crypto";
22020
22020
  import { spawn as spawn4 } from "node:child_process";
22021
22021
  import { constants as constants2, createReadStream, createWriteStream } from "node:fs";
@@ -22030,7 +22030,7 @@ import { readFileSync as readFileSync4 } from "node:fs";
22030
22030
  import { dirname as dirname4, join as join5 } from "node:path";
22031
22031
  import { fileURLToPath as fileURLToPath2 } from "node:url";
22032
22032
  function cliVersion() {
22033
- if (true) return "0.3.13";
22033
+ if (true) return "0.3.14";
22034
22034
  const here = dirname4(fileURLToPath2(import.meta.url));
22035
22035
  for (const candidate of [
22036
22036
  join5(here, "..", "..", "package.json"),
@@ -22053,7 +22053,7 @@ function repoSlug(env = process.env) {
22053
22053
  return void 0;
22054
22054
  }
22055
22055
 
22056
- // src/lib/desktop-update.ts
22056
+ // src/lib/installation/desktop-update.ts
22057
22057
  function isNewerVersion(candidate, current) {
22058
22058
  const parse3 = (v) => {
22059
22059
  const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(v.trim());
@@ -22333,7 +22333,7 @@ function run(command, args) {
22333
22333
  });
22334
22334
  }
22335
22335
 
22336
- // src/lib/component-versions.ts
22336
+ // src/lib/installation/component-versions.ts
22337
22337
  var RELEASE_PROTOCOLS = {
22338
22338
  "0.0.1": { major: 5, minor: 1 },
22339
22339
  "0.0.2": { major: 6, minor: 0 },
@@ -22441,7 +22441,8 @@ var RELEASE_PROTOCOLS = {
22441
22441
  "0.3.10": { major: 25, minor: 4 },
22442
22442
  "0.3.11": { major: 25, minor: 4 },
22443
22443
  "0.3.12": { major: 25, minor: 5 },
22444
- "0.3.13": { major: 25, minor: 6 }
22444
+ "0.3.13": { major: 25, minor: 6 },
22445
+ "0.3.14": { major: 25, minor: 6 }
22445
22446
  };
22446
22447
  function validProtocol(value) {
22447
22448
  if (typeof value !== "object" || value === null) return false;
@@ -22561,13 +22562,13 @@ function formatComponentVersions(components) {
22561
22562
  }).join("\n");
22562
22563
  }
22563
22564
 
22564
- // src/lib/connect.ts
22565
+ // src/lib/connection/connect.ts
22565
22566
  import { join as join12 } from "node:path";
22566
22567
 
22567
- // src/lib/attached-daemon.ts
22568
+ // src/lib/connection/attached-daemon.ts
22568
22569
  import { randomUUID as randomUUID2 } from "node:crypto";
22569
22570
 
22570
- // src/lib/bootstrap.ts
22571
+ // src/lib/installation/bootstrap.ts
22571
22572
  import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
22572
22573
  import { dirname as dirname7, join as join8, resolve as resolve3 } from "node:path";
22573
22574
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -22643,8 +22644,8 @@ function readInstallScript() {
22643
22644
  const candidates = [
22644
22645
  join8(here, "install.sh"),
22645
22646
  // dist/index.js → dist/install.sh
22646
- join8(here, "..", "..", "..", "..", "scripts", "install.sh")
22647
- // src/lib/ → repo root
22647
+ join8(here, "..", "..", "..", "..", "..", "scripts", "install.sh")
22648
+ // src/lib/installation/ → repo root
22648
22649
  ];
22649
22650
  for (const candidate of candidates) {
22650
22651
  if (existsSync3(candidate)) return readFileSync6(candidate, "utf8");
@@ -22652,7 +22653,7 @@ function readInstallScript() {
22652
22653
  throw new CliError("not_installed", "install.sh is missing from this build");
22653
22654
  }
22654
22655
 
22655
- // src/lib/net.ts
22656
+ // src/lib/transport/net.ts
22656
22657
  import { connect as connect4, createServer as createServer2 } from "node:net";
22657
22658
  function findFreePort() {
22658
22659
  return new Promise((resolve6, reject) => {
@@ -22701,7 +22702,7 @@ function sleep(ms) {
22701
22702
  return new Promise((r) => setTimeout(r, ms));
22702
22703
  }
22703
22704
 
22704
- // src/lib/cockpit.ts
22705
+ // src/lib/connection/cockpit.ts
22705
22706
  init_types();
22706
22707
  async function ensureDaemon(transport, opts) {
22707
22708
  const logger = opts.logger ?? silentLogger;
@@ -22799,7 +22800,7 @@ function startTimeout(transport) {
22799
22800
  );
22800
22801
  }
22801
22802
 
22802
- // src/lib/attached-daemon.ts
22803
+ // src/lib/connection/attached-daemon.ts
22803
22804
  init_types();
22804
22805
  var AttachedDaemon = class {
22805
22806
  constructor(ssh, logger = silentLogger) {
@@ -22948,7 +22949,7 @@ var AttachedDaemon = class {
22948
22949
  }
22949
22950
  };
22950
22951
 
22951
- // src/lib/daemon-client.ts
22952
+ // src/lib/connection/daemon-client.ts
22952
22953
  init_types();
22953
22954
  var LIVE = /* @__PURE__ */ new Set(["starting", "running", "waiting_input"]);
22954
22955
  var DaemonClient = class {
@@ -24107,7 +24108,7 @@ async function listen(server, startPort, strict, avoidPort) {
24107
24108
  );
24108
24109
  }
24109
24110
 
24110
- // src/lib/remote-access.ts
24111
+ // src/lib/host/remote-access.ts
24111
24112
  var binary2 = `${hostPaths.current}/bin/node ${hostPaths.current}/daemon/connector.mjs`;
24112
24113
  var RemoteAccessControl = class {
24113
24114
  constructor(transport) {
@@ -24171,7 +24172,7 @@ var RemoteAccessControl = class {
24171
24172
  }
24172
24173
  };
24173
24174
 
24174
- // src/lib/tunnel.ts
24175
+ // src/lib/transport/tunnel.ts
24175
24176
  import { spawn as spawn5 } from "node:child_process";
24176
24177
  init_types();
24177
24178
  var RECONNECT_INITIAL_MS = 500;
@@ -24349,7 +24350,7 @@ async function openTunnel(ssh, remotePort, opts = {}) {
24349
24350
  };
24350
24351
  }
24351
24352
 
24352
- // src/lib/connect.ts
24353
+ // src/lib/connection/connect.ts
24353
24354
  init_types();
24354
24355
  var CODEX_OAUTH_PORT = 1455;
24355
24356
  async function connectRemote(opts) {
@@ -24637,11 +24638,11 @@ function sanitise(record2) {
24637
24638
  };
24638
24639
  }
24639
24640
 
24640
- // src/lib/start.ts
24641
+ // src/lib/connection/start.ts
24641
24642
  import { join as join14 } from "node:path";
24642
24643
  init_types();
24643
24644
 
24644
- // src/lib/file-manager.ts
24645
+ // src/lib/host/file-manager.ts
24645
24646
  import { execFile, spawn as spawn6 } from "node:child_process";
24646
24647
  import { lstat, stat } from "node:fs/promises";
24647
24648
  import { dirname as dirname9, isAbsolute, win32 } from "node:path";
@@ -24702,7 +24703,7 @@ function localFileManager(platform = process.platform) {
24702
24703
  };
24703
24704
  }
24704
24705
 
24705
- // src/lib/start.ts
24706
+ // src/lib/connection/start.ts
24706
24707
  async function startLocal(opts) {
24707
24708
  const logger = opts.logger ?? silentLogger;
24708
24709
  const transport = new LocalTransport();
@@ -24766,7 +24767,7 @@ async function startLocal(opts) {
24766
24767
  }
24767
24768
  }
24768
24769
 
24769
- // src/lib/status.ts
24770
+ // src/lib/connection/status.ts
24770
24771
  var LIVE_FIRST = {
24771
24772
  running: 0,
24772
24773
  waiting_input: 1,
@@ -24795,7 +24796,7 @@ init_types();
24795
24796
  import { spawn as spawn8 } from "node:child_process";
24796
24797
  import { dirname as dirname11 } from "node:path";
24797
24798
 
24798
- // src/lib/standalone-cli.ts
24799
+ // src/lib/installation/standalone-cli.ts
24799
24800
  init_types();
24800
24801
  import { spawn as spawn7 } from "node:child_process";
24801
24802
  import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync9, realpathSync as realpathSync2 } from "node:fs";
@@ -24969,7 +24970,7 @@ import { chmod as chmod2, copyFile, mkdir as mkdir3, rename, rm as rm3 } from "n
24969
24970
  import { homedir as homedir2 } from "node:os";
24970
24971
  import { join as join16 } from "node:path";
24971
24972
 
24972
- // src/lib/releases.ts
24973
+ // src/lib/installation/releases.ts
24973
24974
  init_types();
24974
24975
  async function latestReleaseVersion(opts = {}) {
24975
24976
  const slug2 = repoSlug();
@@ -24997,7 +24998,7 @@ async function latestReleaseVersion(opts = {}) {
24997
24998
  return version2;
24998
24999
  }
24999
25000
 
25000
- // src/lib/remove-daemon.ts
25001
+ // src/lib/installation/remove-daemon.ts
25001
25002
  init_types();
25002
25003
  async function sweepDirtyWorktrees(transport) {
25003
25004
  const script = `
@@ -25090,7 +25091,7 @@ fi`;
25090
25091
  // src/cli/manage.ts
25091
25092
  init_types();
25092
25093
 
25093
- // src/lib/upgrade.ts
25094
+ // src/lib/installation/upgrade.ts
25094
25095
  init_types();
25095
25096
  async function upgradeDaemon(transport, opts = {}) {
25096
25097
  const logger = opts.logger ?? silentLogger;
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsDialog-tW18Y_Wr.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-CIb9G2C5.js","assets/LazyTerminal-Crwcrh-K.js","assets/jsx-runtime-By8HlURe.js","assets/preload-helper-Czpn1I53.js","assets/dialog-BMWRC2HO.js","assets/react-dom-cJyBB_A4.js","assets/x-DCpy1q13.js","assets/createLucideIcon-DyMAgLa3.js","assets/chevron-right-BRjnLYaO.js","assets/notification-delivery-DdTD40aA.js","assets/api-CfmzEbQ_.js","assets/hotkeys-DOpJ1a7g.js","assets/protocol-support-BGk73LFk.js","assets/switch-iVuj74VW.js","assets/dist-Cde1E3eV.js","assets/client-settings-CwqpIric.js","assets/index-B9DFgBft.js","assets/index-DwtrJj9v.css","assets/dist-BOS6OKSE.js","assets/button-9AVMLaMQ.js","assets/select-9OADuw7W.js","assets/chevron-down--sjpQEHH.js","assets/dist-CBag2On7.js","assets/code-DRWf9a5s.js","assets/rotate-ccw-CNjR2LSi.js","assets/errors-DTaodZDR.js","assets/use-debounced-value-C86N-mOK.js","assets/popover-CtxJVkPi.js","assets/CompilationCommandForm-8ipw9M-Z.js","assets/Dashboard-B9v8mQKk.js","assets/session-order-SN_zG4Us.js","assets/context-menu-D-5BvS0X.js","assets/dist-CcLyf3-2.js","assets/NewProjectDialog-qFDLTphH.js","assets/ws-CspBmo8M.js","assets/Workspace-D2IYXJV2.js","assets/forward-link-C-8Xn8gf.js","assets/media-refresh-store-DDvrEM5K.js","assets/use-ui-state-CQp93ZE4.js","assets/preview-kind-DiWpvEc0.js","assets/debounce-B9DrqirV.js","assets/whole-word-2m2pmAFT.js","assets/selection-actions-BjVj7hXw.js","assets/copy-CGsu8426.js","assets/view-state-store-CVAUWqnG.js","assets/drafts-B_tChlzR.js","assets/buffer-logic-BAkSBQT7.js","assets/scroll-restoration-gKZDDamc.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{t as n}from"./react-dom-cJyBB_A4.js";import{P as r,U as i,W as a,f as o,j as s,o as c,r as l,x as u}from"./auth-CIb9G2C5.js";import{a as d,c as f,o as p}from"./LazyTerminal-Crwcrh-K.js";import{a as m,d as h,f as g,g as _,h as v,i as y,l as b,m as x,o as S,s as C,t as w,u as ee}from"./notification-delivery-DdTD40aA.js";import{i as T,r as E,t as D}from"./client-settings-CwqpIric.js";import{t as te}from"./jsx-runtime-By8HlURe.js";import{t as ne}from"./preload-helper-Czpn1I53.js";import{a as O,n as re,o as ie,r as ae,t as k}from"./index-B9DFgBft.js";import{n as A}from"./api-CfmzEbQ_.js";import{_ as j,d as oe,g as M,h as se,i as ce,l as le,m as ue,o as de,p as fe,r as pe,s as me,u as he,v as ge}from"./hotkeys-DOpJ1a7g.js";import{t as _e}from"./forward-link-C-8Xn8gf.js";import{$ as ve,At as ye,B as be,Bt as xe,C as Se,Ct as Ce,Dt as we,E as Te,F as Ee,Ft as De,H as Oe,Ht as ke,It as Ae,J as je,K as Me,L as Ne,Lt as N,M as Pe,Mt as Fe,Nt as Ie,Pt as Le,Q as Re,Rt as ze,T as Be,Tt as Ve,Vt as He,Z as Ue,_t as We,at as P,b as Ge,et as Ke,it as qe,j as Je,jt as F,o as Ye,ot as Xe,pt as Ze,q as Qe,rt as $e,st as et,v as tt,w as nt,wt as rt,x as it,xt as at,y as ot,zt as st}from"./protocol-support-BGk73LFk.js";import{a as ct,c as lt,d as I,f as ut,h as dt,l as ft,m as pt,o as mt,p as ht,r as gt,u as _t}from"./session-order-SN_zG4Us.js";import{n as L,t as vt}from"./dist-BOS6OKSE.js";import{n as R}from"./x-DCpy1q13.js";import{n as z,r as yt}from"./chevron-right-BRjnLYaO.js";import{n as bt,r as xt}from"./dist-Cde1E3eV.js";import{$ as St,G as Ct,H as wt,J as Tt,K as Et,Q as Dt,U as Ot,W as kt,X as At,Y as jt,at as Mt,d as Nt,et as Pt,f as Ft,h as B,i as It,it as V,m as Lt,nt as Rt,ot as H,p as zt,q as Bt,r as Vt,rt as U,t as Ht,tt as Ut}from"./use-ui-state-CQp93ZE4.js";import{n as Wt,t as W}from"./button-9AVMLaMQ.js";import{t as G}from"./createLucideIcon-DyMAgLa3.js";import{c as Gt,d as Kt,i as qt,l as Jt,o as Yt,t as Xt}from"./switch-iVuj74VW.js";import{t as Zt}from"./copy-CGsu8426.js";import{t as Qt}from"./NewProjectDialog-qFDLTphH.js";import{n as K}from"./errors-DTaodZDR.js";import{t as q}from"./ws-CspBmo8M.js";import{a as $t,c as en,i as tn,n as nn,o as rn,r as an,s as on}from"./command-BUOkDmUW.js";import{n as sn,r as cn,t as ln}from"./popover-CtxJVkPi.js";var J=e(t(),1),Y=te();function un(){let[e,t]=(0,J.useState)(`Opening forwarded application…`);return(0,J.useEffect)(()=>{if(!/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname)){t(`This forwarding link is invalid.`);return}let e=!0;return _e(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,Y.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var dn=class extends ke{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 Ve({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=X(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=X(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=X(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=X(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){F.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=>De(t,e))}findAll(e={}){return this.getAll().filter(t=>De(e,t))}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return F.batch(()=>Promise.all(e.map(e=>e.continue().catch(N))))}};function X(e){return e.options.scope?.id}var fn=class extends ke{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??Le(r,t),a=this.get(i);return a||(a=new we({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(){F.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=>Ae(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>Ae(e,t)):t}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){F.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){F.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},pn=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new fn,this.#t=e.mutationCache||new dn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=He.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=ye.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(st(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=Fe(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return F.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;F.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return F.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=F.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(N).catch(N)}invalidateQueries(e,t={}){return F.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=F.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(N)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(N)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(st(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(N).catch(N)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(N).catch(N)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return ye.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Ie(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{ze(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Ie(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{ze(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||=Le(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===xe&&(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()}},mn=class extends J.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidUpdate(e){this.state.error!==null&&e.resetOn!==this.props.resetOn&&this.setState({error:null})}componentDidCatch(e,t){console.error(`Puddle: the ${this.props.scope} crashed`,e,t.componentStack)}render(){let{error:e}=this.state;return e===null?this.props.children:(0,Y.jsxs)(`div`,{className:`flex h-full min-h-40 flex-col items-center justify-center gap-4 px-8 py-10 text-center`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,Y.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,Y.jsx)(`p`,{className:`max-w-sm text-2xs leading-relaxed text-fg-muted`,children:`Your sessions and their worktrees are on the daemon and untouched; the layout is saved. The console has the full stack.`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null}),className:`text-2xs font-medium text-fg-gold transition-colors hover:underline`,children:`Try again`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function hn(){return(0,Y.jsx)(vt,{theme:(0,J.useSyncExternalStore)(O,ae),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 gn(){return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,Y.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,Y.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,Y.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var _n=e(n(),1),vn=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,yn=`.monaco-editor`;function bn(e,t){return e?.closest(yn)&&!e.closest(t)?`text`:e?.closest(vn)?`interactive`:`default`}function xn(e,t=`.no-custom-caret`){(0,J.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=()=>{n.style.opacity=`0`},a=e=>{if(e.pointerType===`touch`||!r.matches){i();return}n.style.transform=`translate3d(${e.clientX}px, ${e.clientY}px, 0) translate(-50%, -50%)`;let a=e.target instanceof Element?e.target:null;if(a instanceof HTMLIFrameElement){i();return}n.style.opacity=`1`;let o=a?.closest(yn),s=bn(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 Sn=[`top`,`right`,`bottom`,`left`];function Cn(){let e=(0,J.useRef)(null);return xn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:Sn.map(e=>(0,Y.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function wn(){let e=(0,J.useRef)(null);return xn(e),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var Tn=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Z=40.5,Q=4.05,En=Q*Math.sqrt(3)/2;function Dn(){let e=[],t=[],n=Z/2,r=Math.ceil(n/En)+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*En,s=o+En,c=(i%2+2)%2*(Q/2);for(let i=-r;i<r;i+=1){let r=n+i*Q+c,l=[[r+Q/2,o],[r,s],[r+Q,s]],u=[[r+Q/2,o],[r+3*Q/2,o],[r+Q,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Z&&Math.max(...n)>0&&Math.min(...n)<Z};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var On=Dn();function kn(){let e=(0,J.useRef)(null);return xn(e,Tn),(0,Y.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,Y.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Z} ${Z}`,focusable:`false`,children:[(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:On.light}),(0,Y.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:On.dark})]})})}function An(){let{cursorPackage:e}=T(),t=null;switch(e){case`rangefinder`:t=(0,Y.jsx)(kn,{});break;case`drafting`:t=(0,Y.jsx)(Cn,{});break;case`invert`:t=(0,Y.jsx)(wn,{});break;case`system`:return null}return(0,_n.createPortal)(t,document.body)}var jn=G(`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`}]]),Mn=G(`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`}]]),Nn=G(`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`}]]),Pn=G(`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`}]]),Fn=G(`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`}]]),In=G(`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`}]]),Ln=G(`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 Rn(){let e=P(),t=Pe(),[n,i]=(0,J.useState)(``),[a,o]=(0,J.useState)(r),s=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:a.trim()},{onSuccess:e=>se(e.id)})},c=(e.data?.length??0)>0;return(0,Y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),c&&(0,Y.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>se(e.id),className:`flex items-center gap-3 rounded-md px-3 py-2.5 text-left transition-colors hover:bg-elevated active:bg-border/70`,children:[(0,Y.jsx)(g,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,Y.jsx)(`span`,{className:R(`text-base`,d(e.icon_colour)||`text-fg`),children:e.name}),e.branch_prefix&&(0,Y.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,Y.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),s()},children:[c&&(0,Y.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(f,{htmlFor:`profile-name`,children:`Name`}),(0,Y.jsx)(z,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>i(e.target.value),className:`h-10`,autoFocus:!c})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(f,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,Y.jsx)(z,{id:`branch-prefix`,placeholder:`no prefix`,value:a,onChange:e=>o(e.target.value),className:`h-10`})]}),t.error&&(0,Y.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,Y.jsx)(W,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}function zn(){let e=Ne().data?.protocol,t=e!==void 0&&(e.major>25||e.major===25&&e.minor>=5),{data:n}=at({queryKey:[`storage`],queryFn:()=>A(`GET`,`/api/storage`),enabled:t&&!c(),refetchInterval:1e4,retry:!1});if(!t||c()||!n)return null;let r=n.volumes.filter(e=>e.level!==`ok`);if(!n.logs_degraded&&!n.database_degraded&&r.length===0)return null;let i=r.some(e=>e.level===`critical`);return(0,Y.jsxs)(`div`,{role:`status`,className:`flex shrink-0 items-start gap-2 px-3 py-2 text-xs text-warning`,children:[(0,Y.jsx)(Rt,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[n.database_degraded&&(0,Y.jsx)(`p`,{children:`Storage is full. Changes cannot be saved. Live session status may be unsaved.`}),n.logs_degraded&&(0,Y.jsx)(`p`,{children:`Terminal history is temporarily not being saved. Live terminals remain connected.`}),i&&(0,Y.jsx)(`p`,{children:`Storage is critically low. Free space or inodes before starting new sessions or worktrees.`}),r.length>0&&(0,Y.jsx)(Yt,{summary:`${r.length} storage ${r.length===1?`location needs`:`locations need`} attention`,children:(0,Y.jsx)(`div`,{className:`max-h-32 overflow-y-auto pl-4`,children:r.map(e=>(0,Y.jsxs)(`p`,{className:`break-all text-fg-secondary`,children:[e.level===`unknown`?`Could not check storage`:`Low storage`,` at`,` `,e.path,e.available_bytes!==null&&` · ${Math.round(e.available_bytes/1024**2).toLocaleString()} MiB available`,e.available_inodes!==null&&` · ${e.available_inodes.toLocaleString()} inodes available`]},e.path))})})]})]})}var Bn=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 ${l.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 r=u.parse(await n.json());this.phase=`waiting`;let i=Date.now()+e;for(;Date.now()<i;){await this.pause(1e3);try{let e=await this.transport(`/cockpit/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let n=o.parse(await e.json());if(n.instance===r.instance||n.refreshId!==r.refreshId||n.upstream!==`ready`)continue;return this.phase=`complete`,this.reload(),!0}catch{}}}catch{}return this.phase=`failed`,!1}},Vn=null;function Hn(e){return Vn=e,()=>{Vn===e&&(Vn=null)}}function Un(){Vn?.()}var Wn=new Set;function Gn(){return[...Wn].flatMap(e=>e())}function Kn({onNewSession:e,onNewProject:t}){let[n,r]=(0,J.useState)(!1),[i,a]=(0,J.useState)(`commands`),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(!1),f=pt(),p=dt(),m=M(),h=p.id,g=et(m??void 0),_=qe(m??void 0),y=We(h),b=jt();(0,J.useEffect)(()=>he(`palette.toggle`,()=>r(e=>!e)),[]),(0,J.useEffect)(()=>St(()=>r(!0)),[]),(0,J.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let S=(0,J.useMemo)(()=>{let n=[],r=gt((g.data??[]).filter(e=>!e.archived),_.data?.projectOrder??[]);for(let e of r)n.push({id:`project-${e.id}`,group:`Projects`,label:e.name,icon:mt,keywords:`switch project open`,run:()=>void f(`/project/${e.id}`)});for(let e of y.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:b(e),icon:ct,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:Kt,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:ct,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:mt,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:v,keywords:`switch theme dark appearance`,run:()=>void k(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:x,keywords:`switch theme light appearance`,run:()=>void k(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:Nn,keywords:`switch theme system appearance`,run:()=>void k(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Ln,keywords:`open settings preferences options configure`,run:()=>qt()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:Gt,keywords:`switch profile identity user change`,run:()=>ue.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:Jt,keywords:`refresh connection reconnect restart cockpit tunnel ssh daemon`,run:()=>Un()}),[...n,...Gn()]},[g.data,_.data?.projectOrder,y.data,h,f,e,t,b]),C=(0,J.useMemo)(()=>{let e=new Map;for(let t of S){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[S]),w=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await At(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,Y.jsxs)(nn,{open:n,onOpenChange:r,children:[(0,Y.jsx)($t,{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(),w()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,Y.jsx)(on,{children:(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,Y.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,Y.jsxs)(on,{children:[(0,Y.jsx)(an,{children:`Nothing matches.`}),C.map(([e,t])=>(0,Y.jsx)(tn,{heading:e,children:t.map(e=>{let t=e.icon;return(0,Y.jsxs)(rn,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,Y.jsx)(t,{}),e.label,e.shortcut&&(0,Y.jsx)(en,{children:e.shortcut})]},e.id)})},e))]})]})}function qn(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Jn(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Yn(){let e=qe(M()??void 0).data?.hotkeys;return(0,J.useEffect)(()=>{oe(e&&typeof e==`object`?e:void 0)},[e]),(0,J.useEffect)(()=>he(`window.close`,()=>{let e=j();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,J.useEffect)(()=>{let e=e=>{let t=ce(e);if(!t)return;let n=pe(t);if(!n)return;let r=de(n);if(!r||!le(r,Jn()))return;let i=me(n);i&&(e.preventDefault(),e.stopPropagation(),i())},t=e=>{let t=ce(e);if(!t)return;let n=pe(t);if(!n)return;let r=de(n);if(!r||r.editor&&Jn()||r.deferInTerminal&&qn())return;let i=me(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 Xn=4e3;function Zn(){let[e,t]=(0,J.useState)(`hidden`),n=(0,J.useRef)(e);n.current=e,(0,J.useEffect)(()=>{let e=null,r=q.onConnectionChange(r=>{if(r){e!==null&&clearTimeout(e),e=null,n.current===`lost`&&t(`hidden`);return}e!==null||n.current!==`hidden`||(e=setTimeout(()=>{e=null,n.current===`hidden`&&t(`lost`)},Xn))});return()=>{r(),e!==null&&clearTimeout(e)}},[]);let r=(0,J.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Bn.refresh()||(L.error(`The cockpit has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(q.isConnected()?`hidden`:`lost`)))},[]);return(0,J.useEffect)(()=>Hn(()=>void r()),[r]),e===`hidden`?null:(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the cockpit.`:`Connection to the daemon lost.`}),e===`lost`&&(0,Y.jsxs)(W,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,Y.jsx)(Jt,{}),`Refresh connection`]})]})}function Qn({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,Y.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,Y.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full ${r>=90?`bg-danger`:r>=75?`bg-warning`:`bg-action`}`,style:{width:`${r}%`}})}),(0,Y.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function $n(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function er(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 tr({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=Se(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,Y.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,Y.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,Y.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,i.data.session_count,` session`,i.data.session_count===1?``:`s`,i.data.active_session_count>0&&` (${i.data.active_session_count} active)`,` · `,`last `,er(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,Y.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[$n(i.data.agent_usage.input_tokens),` in ·`,` `,$n(i.data.agent_usage.output_tokens),` out ·`,` `,$n(i.data.agent_usage.cache_read_input_tokens),` cached ·`,` `,i.data.agent_usage.message_count,` msgs`]}),i.data?.live_usage?.context_used_percentage!=null&&(0,Y.jsx)(`span`,{className:`mt-1 block`,children:(0,Y.jsx)(Qn,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,Y.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,Y.jsx)(_,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,Y.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,Y.jsx)(Qn,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function nr(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(!1),i=M(),a=P(),o=ve(),s=a.data?.find(e=>e.id===i),c=nt(i??void 0),l=Be(),u=je(),{open:f,handler:p}=Tt(),[m,_]=(0,J.useState)(null),v=e=>u.mutate(e.id,{onSuccess:t=>_({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>K(e)}),y=e=>{t(!1),f({accountId:e.id})},b=e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>K(e)})},x=`font-sans compact:h-7 compact:px-1.5`;return n&&s?(0,Y.jsxs)(`div`,{className:Wt({variant:`ghost`,size:`sm`,className:x}),children:[(0,Y.jsx)(g,{icon:s.icon,colour:s.icon_colour}),(0,Y.jsx)(Pt,{initial:s.name,maxLength:100,fitContent:!0,className:d(s.icon_colour),onCommit:b,onCancel:()=>r(!1)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(ln,{open:e,onOpenChange:t,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsx)(cn,{asChild:!0,children:(0,Y.jsxs)(W,{variant:`ghost`,size:`sm`,className:x,children:[(0,Y.jsx)(g,{icon:s?.icon,colour:s?.icon_colour}),(0,Y.jsx)(`span`,{className:d(s?.icon_colour),...Ut(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})}),(0,Y.jsx)(V,{children:`Profile`})]}),(0,Y.jsxs)(sn,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(l.data??[]).map(e=>{let t=c.data?.filter(t=>t.agent_type===e.id)??[];if(t.length===0)return null;let n=e.available!==!1;return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,Y.jsxs)(`span`,{className:`ml-2 normal-case tracking-normal text-fg-muted`,children:[`not installed — no `,e.binary??e.id,` on PATH`]})]}),t.map(e=>(0,Y.jsx)(tr,{account:e,onLogin:()=>v(e),onStartSession:p&&n?()=>y(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,Y.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,Y.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),qt(`accounts`)},children:[(0,Y.jsx)(xt,{}),`Add account`]}),(0,Y.jsxs)(W,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),ue.set(null)},children:[(0,Y.jsx)(In,{}),`Switch profile`]})]})]})]}),m&&(0,Y.jsx)(h,{stream:m.stream,label:m.label,onClose:()=>_(null)})]})}var rr=`desktop-update`;function ir(){let e=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let t=j();if(t?.updateReady===void 0||t.onUpdateReady===void 0)return;let n=t=>{e.current!==t&&(e.current=t,L(`Puddle ${t} is downloaded and ready.`,{id:rr,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{j()?.installUpdate?.(),L.loading(`Restarting into Puddle ${t}…`,{id:`${rr}-restarting`,duration:1/0})}}}))};return t.updateReady().then(e=>{e!==null&&n(e)}),t.onUpdateReady(n)},[]),null}function ar(){let e=M(),t=P().data?.find(t=>t.id===e),n=qe(e??void 0),r=Ze(e??void 0,void 0),i=T(),a=S(),o=C(),s=Ke(e??``),c=ve(),l=Ee(),[u,d]=(0,J.useReducer)(e=>e+1,0);(0,J.useEffect)(()=>O(()=>d()),[]);let f=(0,J.useRef)(null);(0,J.useEffect)(()=>{f.current=null},[t?.name]);let p=a.data?.available===!0?a.data.file:void 0,h=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&p!==void 0,g=t&&p?m(p,t.name):void 0,_=s.isPending||c.isPending||l.isPending||o.isPending||n.isFetching||r.isFetching;(0,J.useEffect)(()=>{if(!h||!g?.enabled||_)return;let a={client:i,theme:ie(),profileSettings:n.data,profile:t,scratchpad:r.data},u={setClient:e=>E(e),setTheme:e=>{typeof e==`string`&&k(e)},patchProfileSettings:e=>s.mutate(e),patchProfileColumns:t=>c.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)l.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},d=JSON.stringify(g.doc);if(f.current!==d){f.current=d,b(g.doc,u,a,g.groups);return}let p=ee(g.groups,a),m=JSON.stringify(p);m!==d&&(f.current=m,o.mutate({profile:t.name,entry:{...g,doc:p,updatedAt:new Date().toISOString()}}))})}function or(e){let t=t=>{let n=a.safeParse(t);n.success&&e(n.data)},n=j()?.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 sr=5e3,cr=`[data-notification-session]`;function lr(e){let t=null,n=()=>{t=null},r=e=>e.target instanceof Element?e.target.closest(cr):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<sr&&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 ur=new Set,dr=e=>!!e&&ur.has(e),fr=i.parse({});function pr(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 mr(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 hr(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function gr(){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 _r(){let e=pt(),t=(0,J.useRef)(null);(0,J.useEffect)(()=>{let e=lr(document);return t.current=e,()=>{t.current=null,e.dispose()}},[]),(0,J.useEffect)(()=>or(t=>{t.host||e(`/project/${t.project}/session/${t.session}`,{state:{notificationSession:t.session}})}),[e]),vr(t=>{e(`/project/${t.project_id}/session/${t.id}`,{state:{notificationSession:t.id}})},e=>t.current?.isInteracting(e.id)??!1)}function vr(e,t=()=>document.hasFocus()){let n=rt(),r=(0,J.useRef)(e);r.current=e;let a=(0,J.useRef)(t);a.current=t;let o=Ge(Me().data)??`Puddle`,s=(0,J.useRef)(o);(0,J.useEffect)(()=>{document.title===s.current&&(document.title=o),s.current=o},[o]),(0,J.useEffect)(()=>{let e=new Set,t=()=>{document.title=e.size>0?`(${e.size}) ${s.current}`:s.current},o=!0,l=async e=>{let t=mr(n,e.session);if(!t)try{t=(await tt(n)).find(t=>t.id===e.session)}catch{return}if(!o||!t)return;let l=t,u,d;try{let e=await n.fetchQuery({queryKey:[`project`,l.project_id],queryFn:()=>A(`GET`,`/api/projects/${l.project_id}`),staleTime:1e4});if(!o)return;d=e.project;let t=d.profile_id,r=await n.fetchQuery({queryKey:[`profile-settings`,t],queryFn:()=>A(`GET`,`/api/profiles/${t}/settings`),staleTime:1e4});u=i.catch(fr).parse(r.notifications??{})}catch{return}if(!o)return;let f=pr({prefs:u,projectId:l.project_id,sessionFocused:a.current(l),permission:y()});f.sound&&gr(),f.desktop&&!dr(c()?.scope)&&await w({id:e.id?`puddle-event-${e.id}`:`puddle-agent-${l.id}`,title:e.content?.title??hr(l).slice(0,160),body:e.content?.body??(e.reason===`exited`?`Agent finished running`:`Waiting for your input`),target:{project:l.project_id,session:l.id,...c()?.notificationHost?{host:c().notificationHost}:{}}},()=>{o&&r.current(l)},{host:s.current,project:d})},u=q.onAgentNotification(e=>{l(e)}),d=q.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:()=>A(`GET`,`/api/version`),staleTime:1/0}).then(e=>{if(!(e.protocol.major>22||e.protocol.major===22&&e.protocol.minor>=3))return l({session:r.session,reason:`waiting_input`})}).catch(()=>{})});return()=>{o=!1,d(),u(),document.title=s.current}},[n])}function yr({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,J.useState)(e?.title??``),[c,l]=(0,J.useState)(e?.body??``),[u,d]=(0,J.useState)(n?e?.scope??t:`profile`),[f,p]=(0,J.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,J.useState)(e?.agent_type??null),g=()=>{let e=c.trim();e&&i({title:o.trim()||null,body:e,scope:u,tags:f.split(`,`).map(e=>e.trim()).filter(Boolean),agent_type:m})};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(z,{value:o,placeholder:`Title (optional)`,spellCheck:!1,onChange:e=>s(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-9 text-sm font-medium`}),(0,Y.jsx)(yt,{autoFocus:!0,value:c,placeholder:`Prompt or note…`,spellCheck:!1,rows:10,onChange:e=>l(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`?a():e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},className:`resize-y text-sm leading-relaxed`}),(0,Y.jsx)(z,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,Y.jsx)(Xt,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:R(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,Y.jsx)(Et,{type:e.id,className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,Y.jsx)(W,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,Y.jsx)(W,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function br(){let e=Ct(),t=M(),n=dt().id,r=Ze(t??void 0,n).data??[],i=Be().data??[],a=Ee(),o=$e(),s=Oe(),c=kt(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null);(0,J.useEffect)(()=>he(`scratchpad.toggle`,Ot),[]),(0,J.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,J.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),b=(0,J.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),x=d!==null||p!==null,S=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),C=x?S:_??r,w=e=>{t&&(a.mutate({profile_id:t,scope:e.scope,project_id:e.scope===`project`?n:void 0,title:e.title??void 0,body:e.body,tags:e.tags,agent_type:e.agent_type??void 0}),u(null))},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)},T=(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)},E=()=>{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})},D=e=>{navigator.clipboard?.writeText(e.body),L.success(`Copied to clipboard`)};return(0,Y.jsxs)(ln,{open:e,onOpenChange:wt,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsx)(cn,{asChild:!0,children:(0,Y.jsxs)(W,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(Pn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,Y.jsx)(V,{children:`Scratchpad`})]}),(0,Y.jsxs)(sn,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(xt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||b.length>0)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:R(`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,Y.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:R(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,Y.jsx)(Et,{type:e,className:`size-3.5`})},e))]}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[l===`new`&&(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(yr,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:w,onCancel:()=>u(null)})}),C.length===0&&l!==`new`&&(0,Y.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,Y.jsx)(`ul`,{className:`flex flex-col`,children:C.map(e=>l===e.id?(0,Y.jsx)(`li`,{className:`px-3 py-2`,children:(0,Y.jsx)(yr,{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,Y.jsx)(`li`,{draggable:!x&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&T(h,e.id))},onDragEnd:E,className:R(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,Y.jsx)(xr,{entry:e,onInsert:c?()=>{c(e.body),wt(!1)}:null,onCopy:()=>D(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})},e.id))})]})]})]})}function xr({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,J.useState)(!1);return(0,Y.jsxs)(`div`,{onClick:e=>{e.target.closest(`button`)||r()},className:`cursor-pointer rounded-md px-3 py-2.5 transition-colors hover:bg-surface`,children:[e.title&&(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:R(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:`Delete`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,Y.jsx)(Et,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,Y.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[t&&(0,Y.jsx)(Sr,{icon:jn,label:`Insert into focused terminal`,onClick:t}),(0,Y.jsx)(Sr,{icon:Zt,label:`Copy`,onClick:n}),(0,Y.jsx)(Sr,{icon:p,label:`Edit`,onClick:r}),(0,Y.jsx)(Sr,{icon:bt,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function Sr({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(V,{children:t})]})}var Cr=s.parse({});function wr(e,t){let[n,r]=(0,J.useState)(null),i=Te(t).data,a=et(e??void 0,t&&e!==null).data;return(0,J.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=Ht(sessionStorage.getItem(Vt(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return ot(e).then(e=>{n||r(e?e.ui_state:Cr)}).catch(()=>{n||r(Cr)}),()=>{n=!0}},[t,e]),(0,J.useMemo)(()=>{if(!t||e===null||n===null)return null;let o=t=>{if(!i||!a)return!1;let{patch:o,projectBased:s}=It(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),it(e,c).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Vt(e),JSON.stringify(c))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}return D().projectBasedLayout!==s&&E({projectBasedLayout:s}),!0},s=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:B(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:B(null),slices:s,capture:()=>({layout_tree:null,active_session:null}),apply:o}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:B(n.layout_tree),slices:s,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),apply:o}},[t,e,n,i,a])}var Tr=B(null);function Er(){let e=Lt(),t=pt(),n=M(),r=zt(),i=wr(n,e&&r===null),a=r??i,o=Qe(n??void 0,void 0).data??[],s=et(n??void 0,e&&n!==null).data??[],c=Je(),l=Re(),u=be(),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null);(0,J.useEffect)(()=>he(`layouts.toggle`,Ft),[]),(0,J.useEffect)(()=>{e||(f(``),m(!1),g(null))},[e]);let _=a?.headless===!0,v=a===null||_?null:o.find(e=>e.id===a.layoutRef)??null,y=a!==null&&!_&&(v===null?a.signature!==Tr:B(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?B(n.layout_tree)!==t.signature:t.signature!==Tr},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),S=e=>v!==null&&e.id===v.id,C=e=>(e===null?void 0:s.find(t=>t.id===e)?.name)??`Project`,w=a!==null&&!_&&a.scope===`project`?o.filter(e=>e.scope===`profile`||e.project_id===a.projectId):o,ee=[...w.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(w.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:C(e)})).sort((e,t)=>e.name.localeCompare(t.name))],T=h===null?w:h===`profile`?w.filter(e=>e.scope===`profile`):w.filter(e=>e.project_id===h),E=e=>a!==null&&e.scope===a.scope&&(a.scope===`profile`||e.project_id===a.projectId),D=(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=>K(e)})},te=e=>{if(!a)return;let t=E(e)?e:o.find(t=>t.name===e.name&&E(t));if(!t){D(e.name,a.capture(),!0);return}l.mutate({id:t.id,...a.capture()},{onSuccess:e=>a.apply(e),onError:e=>K(e)})},ne=(e,t)=>D(t,{layout_tree:e.layout_tree,active_session:e.active_session},!1),O=e=>{if(a){if(!a.apply(e)){L.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}`),Nt(!1)}};return(0,Y.jsxs)(ln,{open:e,onOpenChange:Nt,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsx)(cn,{asChild:!0,children:(0,Y.jsxs)(W,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,Y.jsx)(Mn,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,Y.jsx)(V,{children:`Layouts`})]}),(0,Y.jsxs)(sn,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,Y.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),a!==null&&!_&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,Y.jsx)(xt,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),a===null?(0,Y.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):_?(0,Y.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Project-based layout is on — every project keeps its own layout. Open a project to name or save it; loading works from here.`}):(v===null||p)&&(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[v===null&&(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:a.scope===`profile`?`Profile-wide`:`Project`}),(0,Y.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=d.trim();t&&(D(t,a.capture(),!0),f(``),m(!1))},children:[(0,Y.jsx)(z,{autoFocus:p,value:d,placeholder:v===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&m(!1)},className:`h-8 flex-1 text-sm`}),(0,Y.jsx)(W,{size:`sm`,type:`submit`,disabled:!d.trim(),children:`Save`}),v!==null&&(0,Y.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>m(!1),children:`Cancel`})]})]}),ee.length>1&&(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:ee.map(e=>(0,Y.jsx)(kr,{active:h===e.key,onClick:()=>g(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,Y.jsxs)(`div`,{className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[T.length===0&&(0,Y.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:h===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,Y.jsx)(`ul`,{className:`flex flex-col`,children:T.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(Dr,{layout:e,projectLabel:e.scope===`profile`?null:C(e.project_id),isCurrent:S(e),dirty:y,loadable:a!==null,savable:a!==null&&!_,confirmBeforeLoad:x(e),overwrites:E(e),onLoad:()=>O(e),onRename:t=>l.mutate({id:e.id,name:t}),onDelete:()=>u.mutate(e.id),onSaveAs:()=>te(e),onDuplicate:t=>ne(e,t)})},e.id))})]})]})]})}function Dr({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[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(null),[v,y]=(0,J.useState)(e.name),b=()=>{if(!(!i||g!==null)){if(o&&m!==`load`){h(`load`);return}h(null),c()}},x=t=>{h(null),y(t===`rename`?e.name:`${e.name} copy`),_(t)},S=()=>{if(n){d();return}h(`save`)},C=n?r?`unsaved`:`active`:null;return(0,Y.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||b()},className:R(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[g===null?(0,Y.jsxs)(`p`,{className:R(`flex items-baseline gap-2 text-sm font-medium`,C===`active`?`text-success`:C===`unsaved`?`text-interrupted`:`text-fg`),children:[e.name,C!==null&&(0,Y.jsx)(`span`,{className:`text-2xs font-normal`,children:C===`active`?`Active`:`Unsaved`})]}):(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:t=>{t.preventDefault();let n=v.trim();n&&(g===`rename`?n!==e.name&&l(n):f(n)),_(null)},children:[(0,Y.jsx)(z,{autoFocus:!0,value:v,spellCheck:!1,onChange:e=>y(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&_(null)},className:`h-7 flex-1 text-sm`}),(0,Y.jsx)(W,{size:`sm`,type:`submit`,disabled:!v.trim(),children:g===`rename`?`Rename`:`Save`})]}),m===`save`?(0,Y.jsx)(Or,{question:s?`Overwrite “${e.name}” with the current layout?`:`Save the current layout as “${e.name}” here?`,verb:s?`Overwrite`:`Save`,onConfirm:()=>{h(null),d()},onCancel:()=>h(null)}):m===`delete`?(0,Y.jsx)(Or,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{h(null),u()},onCancel:()=>h(null)}):m===`load`?(0,Y.jsx)(Or,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:b,onCancel:()=>h(null)}):(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,Y.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[a&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ar,{icon:Fn,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:S}),(0,Y.jsx)(Ar,{icon:Zt,label:`Duplicate`,onClick:()=>x(`duplicate`)})]}),(0,Y.jsx)(Ar,{icon:p,label:`Rename`,onClick:()=>x(`rename`)}),(0,Y.jsx)(Ar,{icon:bt,label:`Delete`,onClick:()=>h(`delete`)})]})]})]})}function Or({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:t}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]})}function kr({active:e,onClick:t,children:n}){return(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:R(`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 Ar({icon:e,label:t,onClick:n}){return(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Y.jsx)(e,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Y.jsx)(V,{children:t})]})}var $=j()!==void 0&&/Mac/.test(navigator.platform),jr=(0,J.lazy)(()=>ne(()=>import(`./SettingsDialog-tW18Y_Wr.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,20,21,22,23,24,25,26,27,28,29,30,31])));function Mr(){let e=rt();(0,J.useEffect)(()=>{let t=t=>{for(let[n,r]of e.getQueriesData({queryKey:[`sessions`]}))r&&e.setQueryData(n,r.map(t));for(let[n,r]of e.getQueriesData({queryKey:[`project`]}))r&&e.setQueryData(n,{...r,sessions:r.sessions.map(t)})},n=q.onStatus(e=>t(t=>t.id===e.session?{...t,status:e.status,last_activity_at:e.last_activity_at}:t)),r=q.onRenamed(e=>t(t=>t.id===e.session?{...t,title:e.title,agent_title:`agent_title`in e?e.agent_title:t.agent_title,osc_title:`osc_title`in e?e.osc_title:t.osc_title}:t)),i=q.onAccount(t=>{for(let[n,r]of e.getQueriesData({queryKey:[`accounts`]}))r&&e.setQueryData(n,r.map(e=>e.id===t.account_id?{...e,logged_in:t.logged_in}:e))}),a=t=>{e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},o=q.onSessionsChanged(e=>a(e.project_ids)),s=q.onSessionSwitched(e=>a([e.target_project]));return()=>{n(),r(),i(),o(),s()}},[e])}function Nr(){let e=Me(),t=Ue(),[n,r]=(0,J.useState)(!1),i=Ge(e.data),a=n=>{r(!1);let a=n.trim();a!==i&&t.mutate({displayName:a===e.data?.hostname?``:a},{onError:e=>K(e)})},o=!$&&(0,Y.jsx)(`img`,{src:`/puddle.svg`,alt:`Puddle`,className:`size-4`}),s=R(`flex shrink-0 items-center gap-2`,$&&`[-webkit-app-region:no-drag]`),c=`truncate text-sm font-semibold text-fg-secondary`;return n&&i!==void 0?(0,Y.jsxs)(`div`,{className:s,children:[o,(0,Y.jsx)(Pt,{initial:e.data?.displayName??i,maxLength:64,className:R(c,`w-40`),onCommit:a,onCancel:()=>r(!1)})]}):(0,Y.jsxs)(ft,{to:`/`,className:R(s,`transition-opacity hover:opacity-70`),title:`All projects`,children:[o,i!==void 0&&(0,Y.jsx)(`span`,{className:c,...Ut(()=>r(!0)),children:i})]})}function Pr(){let e=dt(),t=fe(`palette.toggle`),n=Xe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,Y.jsxs)(`button`,{type:`button`,onClick:Dt,className:R(`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`,$&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsx)(`span`,{className:R(`truncate text-xs`,r&&d(n?.colour)),children:r??`Puddle`}),(0,Y.jsx)(`span`,{className:`text-2xs`,children:t})]})}function Fr(){let{fullScreen:e,animate:t}=ge();return(0,Y.jsxs)(`header`,{className:R(`relative flex h-9 shrink-0 items-center gap-3 bg-surface pl-3 pr-3`,$&&!e&&`pl-[88px] [-webkit-app-region:drag]`,t&&`transition-[padding] duration-200 ease-out`),children:[(0,Y.jsx)(Nr,{}),(0,Y.jsx)(Pr,{}),(0,Y.jsxs)(`div`,{className:R(`ml-auto flex items-center`,$&&`[-webkit-app-region:no-drag]`),children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.jsxs)(W,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>qt(),children:[(0,Y.jsx)(Ln,{}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,Y.jsx)(V,{children:`Settings`})]}),(0,Y.jsx)(Er,{}),(0,Y.jsx)(br,{}),(0,Y.jsx)(nr,{})]})]})}function Ir(){Mr(),ar(),_r();let{handler:e}=Tt(),t=M(),{pathname:n}=ht(),[r,i]=(0,J.useState)(!1),a=Ne(),o=a.data!==void 0&&Ye(a.data.protocol);return(0,J.useEffect)(()=>{if(!o)return;let e=()=>{let e=re();q.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),O(e)},[o]),(0,Y.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[(0,Y.jsx)(Fr,{}),(0,Y.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,Y.jsx)(mn,{resetOn:n,scope:n.startsWith(`/project/`)?`workspace`:`view`,children:(0,Y.jsx)(_t,{})})}),(0,Y.jsx)(zn,{}),(0,Y.jsx)(Zn,{}),(0,Y.jsx)(ir,{}),(0,Y.jsx)(Kn,{onNewSession:e??void 0,onNewProject:()=>i(!0)}),t!==null&&(0,Y.jsx)(Qt,{profileId:t,open:r,onOpenChange:i}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(jr,{})}),(0,Y.jsx)(Yn,{})]})}function Lr(){return(0,Y.jsx)(Bt,{children:(0,Y.jsx)(Ir,{})})}var Rr=(0,J.lazy)(()=>ne(()=>import(`./Dashboard-B9v8mQKk.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([32,1,2,3,4,5,6,7,8,9,10,11,14,15,13,33,22,34,35,25,36,29,28,21,37]))),zr=(0,J.lazy)(()=>ne(()=>import(`./Workspace-D2IYXJV2.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([38,1,2,8,3,4,5,6,7,9,10,11,18,19,20,13,14,39,15,40,21,35,25,33,17,41,16,42,43,22,34,44,23,24,45,46,37,28,47,48,49,50,31,51]))),Br=new pn({defaultOptions:{queries:{retry:1,staleTime:5e3}},mutationCache:new dn({onError:e=>K(e)})});function Vr(){let e=M(),t=P(),n=e!==null&&t.data!==void 0&&!t.data.some(t=>t.id===e);return e===null||n?(0,Y.jsx)(Rn,{}):(0,Y.jsx)(lt,{useTransitions:!1,children:(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(ut,{children:(0,Y.jsxs)(I,{element:(0,Y.jsx)(Lr,{}),children:[(0,Y.jsx)(I,{path:`/`,element:(0,Y.jsx)(Rr,{})}),(0,Y.jsx)(I,{path:`/project/:id`,element:(0,Y.jsx)(zr,{})}),(0,Y.jsx)(I,{path:`/project/:id/session/:sid`,element:(0,Y.jsx)(zr,{})})]})})})})}function Hr(){let e=(0,J.useSyncExternalStore)(l.subscribe,l.get);return(0,Y.jsx)(Ce,{client:Br,children:(0,Y.jsxs)(Mt,{delayDuration:300,children:[(0,Y.jsx)(An,{}),(0,Y.jsx)(mn,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,Y.jsx)(un,{}):(0,Y.jsx)(Vr,{}):(0,Y.jsx)(gn,{})}),(0,Y.jsx)(hn,{})]})})}export{Hr as App};