@mycadet/cli 0.12.10 → 0.13.0-dev.202610171617.9ea363e

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 (111) hide show
  1. package/README.md +13 -0
  2. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  3. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  4. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  5. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  6. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  8. package/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  9. package/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  10. package/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  11. package/package.json +8 -3
  12. package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
  13. package/src/__tests__/backup-ops-matching.test.ts +15 -13
  14. package/src/__tests__/backup-ops.test.ts +105 -0
  15. package/src/__tests__/backup.test.ts +114 -673
  16. package/src/__tests__/cloud-login-poll.test.ts +69 -0
  17. package/src/__tests__/cloud-releases.test.ts +82 -0
  18. package/src/__tests__/commands-mock.ts +101 -0
  19. package/src/__tests__/debug.test.ts +17 -91
  20. package/src/__tests__/devices.test.ts +64 -2
  21. package/src/__tests__/ensure-binary.test.ts +52 -0
  22. package/src/__tests__/gateway-token.test.ts +267 -0
  23. package/src/__tests__/hatch-next-steps.test.ts +38 -0
  24. package/src/__tests__/host-teleport-docker.test.ts +371 -0
  25. package/src/__tests__/host-teleport.test.ts +405 -0
  26. package/src/__tests__/multi-local.test.ts +3 -3
  27. package/src/__tests__/nginx-ingress.test.ts +587 -36
  28. package/src/__tests__/orphan-detection.test.ts +1 -1
  29. package/src/__tests__/paired-lifecycle.test.ts +2 -2
  30. package/src/__tests__/ps-cloud-status.test.ts +8 -7
  31. package/src/__tests__/root-backup-docker.test.ts +294 -0
  32. package/src/__tests__/root-backup.test.ts +527 -0
  33. package/src/__tests__/root-restore-command.test.ts +147 -0
  34. package/src/__tests__/root-signing-key.test.ts +50 -0
  35. package/src/__tests__/setup.test.ts +17 -7
  36. package/src/__tests__/shell-mode.test.ts +83 -0
  37. package/src/__tests__/sleep.test.ts +11 -0
  38. package/src/__tests__/teleport.test.ts +68 -2996
  39. package/src/__tests__/tunnel-startup-summary.test.ts +110 -0
  40. package/src/__tests__/tunnel-stop.test.ts +226 -0
  41. package/src/__tests__/tunnel.test.ts +22 -4
  42. package/src/__tests__/upgrade-local.test.ts +21 -11
  43. package/src/__tests__/upgrade-replay-env.test.ts +2 -2
  44. package/src/__tests__/upgrade-root-recovery.test.ts +185 -0
  45. package/src/__tests__/wake.test.ts +4 -1
  46. package/src/__tests__/windows-lifecycle.test.ts +25 -0
  47. package/src/commands/backup.ts +44 -399
  48. package/src/commands/client.ts +3 -3
  49. package/src/commands/completions.ts +0 -2
  50. package/src/commands/debug.ts +75 -131
  51. package/src/commands/devices.ts +117 -47
  52. package/src/commands/gateway/token.ts +77 -23
  53. package/src/commands/hatch.ts +10 -52
  54. package/src/commands/pair.ts +9 -3
  55. package/src/commands/ps.ts +4 -2
  56. package/src/commands/restore.ts +77 -444
  57. package/src/commands/retire.ts +2 -3
  58. package/src/commands/sleep.ts +15 -2
  59. package/src/commands/teleport.ts +47 -1559
  60. package/src/commands/tunnel.ts +91 -11
  61. package/src/commands/upgrade.ts +84 -157
  62. package/src/commands/wake.ts +1 -1
  63. package/src/index.ts +0 -4
  64. package/src/lib/__tests__/http-client-version.test.ts +29 -0
  65. package/src/lib/__tests__/runtime-url.test.ts +3 -75
  66. package/src/lib/__tests__/web-dist.test.ts +27 -1
  67. package/src/lib/assistant-client.ts +1 -1
  68. package/src/lib/assistant-config.ts +43 -23
  69. package/src/lib/backup-ops.ts +37 -251
  70. package/src/lib/cloud-client.ts +10 -13
  71. package/src/lib/cloud-login-poll.ts +75 -0
  72. package/src/lib/cloud-login.ts +5 -2
  73. package/src/lib/cloud-releases.ts +54 -10
  74. package/src/lib/cloud-values.ts +1 -1
  75. package/src/lib/confirm-action.ts +2 -2
  76. package/src/lib/docker.ts +65 -34
  77. package/src/lib/ensure-binary.ts +65 -6
  78. package/src/lib/github-repository.ts +2 -0
  79. package/src/lib/guardian-token.ts +1 -23
  80. package/src/lib/hatch-local.ts +18 -52
  81. package/src/lib/hatch-next-steps.ts +15 -2
  82. package/src/lib/host-teleport.ts +506 -0
  83. package/src/lib/http-client.ts +25 -0
  84. package/src/lib/ingress-config.ts +31 -0
  85. package/src/lib/live-voice/tunnel.test.ts +1 -1
  86. package/src/lib/live-voice/tunnel.ts +3 -3
  87. package/src/lib/local.ts +10 -8
  88. package/src/lib/nginx-ingress.ts +572 -95
  89. package/src/lib/process.ts +13 -0
  90. package/src/lib/root-backup.ts +917 -0
  91. package/src/lib/root-signing-key.ts +31 -0
  92. package/src/lib/runtime-url.ts +0 -29
  93. package/src/lib/teleport-backup.ts +3 -16
  94. package/src/lib/tunnel.ts +87 -34
  95. package/src/lib/tunnels/cadet.ts +12 -1
  96. package/src/lib/tunnels/cloudflare.ts +36 -1
  97. package/src/lib/tunnels/ngrok.ts +16 -2
  98. package/src/lib/tunnels/process-lifecycle.ts +26 -0
  99. package/src/lib/tunnels/tailscale.ts +79 -1
  100. package/src/lib/upgrade-lifecycle.ts +63 -141
  101. package/src/lib/web-dist.ts +79 -1
  102. package/src/lib/xdg-log.ts +11 -0
  103. package/src/__tests__/bundle-staging.test.ts +0 -268
  104. package/src/__tests__/unpair.test.ts +0 -160
  105. package/src/commands/rollback.ts +0 -479
  106. package/src/commands/unpair.ts +0 -122
  107. package/src/lib/__tests__/job-polling.test.ts +0 -278
  108. package/src/lib/__tests__/local-runtime-client.test.ts +0 -666
  109. package/src/lib/bundle-staging.ts +0 -220
  110. package/src/lib/job-polling.ts +0 -195
  111. package/src/lib/local-runtime-client.ts +0 -374
@@ -11,7 +11,9 @@ import {
11
11
 
12
12
  import {
13
13
  lookupAssistantByIdentifier,
14
+ readEdgeShellSelection,
14
15
  saveAssistantEntry,
16
+ saveEdgeShellSelection,
15
17
  type AssistantEntry,
16
18
  } from "./assistant-config.js";
17
19
  import { getStateDir } from "./environments/paths.js";
@@ -68,6 +70,35 @@ export function getDefaultWorkspaceDir(): string {
68
70
  );
69
71
  }
70
72
 
73
+ /** Which client bundle the nginx edge serves as the outer shell. */
74
+ export type ShellMode = "web" | "app";
75
+
76
+ export const DEFAULT_SHELL_MODE: ShellMode = "web";
77
+
78
+ /**
79
+ * Read the persisted shell mode from the CLI lockfile. The nginx edge is a
80
+ * CLI-managed server — the lockfile's `app` record — not a per-cadet
81
+ * setting, so its shell lives beside that record there rather than in any
82
+ * one cadet's workspace config. Unset records read as the default so the
83
+ * edge's behavior never depends on config files that predate the setting;
84
+ * an unrecognized value fails loudly rather than silently serving a shell
85
+ * the user did not ask for.
86
+ */
87
+ export function readShellMode(): ShellMode {
88
+ const raw = readEdgeShellSelection();
89
+ if (raw === undefined) return DEFAULT_SHELL_MODE;
90
+ if (raw === "web" || raw === "app") return raw;
91
+ throw new Error(
92
+ `The nginx edge shell mode must be "web" or "app" (got ${JSON.stringify(raw)}). ` +
93
+ "Fix it in the CLI lockfile or run `cadet tunnel --shell <web|app>`.",
94
+ );
95
+ }
96
+
97
+ /** Persist the shell mode to the CLI lockfile beside the nginx edge record. */
98
+ export function saveShellMode(mode: ShellMode): void {
99
+ saveEdgeShellSelection(mode);
100
+ }
101
+
71
102
  function getConfigPath(workspaceDir: string): string {
72
103
  return join(workspaceDir, "config.json");
73
104
  }
@@ -23,7 +23,7 @@ describe("tunnelHostForCloudUrl", () => {
23
23
  "tunnel.mycadet.ai",
24
24
  );
25
25
  expect(tunnelHostForCloudUrl("https://dev-cloud.mycadet.ai")).toBe(
26
- "tunnel-dev.mycadet.ai",
26
+ "dev-tunnel.mycadet.ai",
27
27
  );
28
28
  });
29
29
 
@@ -28,7 +28,7 @@
28
28
  * mint again rather than reuse what resolution returned.
29
29
  */
30
30
 
31
- import { tunnelHostForPlatformHost } from "@mycadet/service-contracts/ingress";
31
+ import { tunnelHostForCloudHost } from "@mycadet/service-contracts/ingress";
32
32
 
33
33
  import { authHeaders } from "../cloud-client.js";
34
34
 
@@ -55,7 +55,7 @@ export class TunnelWsTokenError extends Error {
55
55
  * reached: its tunnel is a loopback port that no naming convention predicts.
56
56
  * Otherwise the deployment convention maps the cloud host onto its sibling
57
57
  * (`cloud.mycadet.ai` to `tunnel.mycadet.ai`, `dev-cloud.mycadet.ai` to
58
- * `tunnel-dev.mycadet.ai`). A host outside that convention, including localhost,
58
+ * `dev-tunnel.mycadet.ai`). A host outside that convention, including localhost,
59
59
  * yields the production default, because guessing a tunnel for it would be
60
60
  * worse than dialing the one host that certainly exists.
61
61
  */
@@ -66,7 +66,7 @@ export function tunnelHostForCloudUrl(cloudUrl: string): string {
66
66
  }
67
67
  try {
68
68
  return (
69
- tunnelHostForPlatformHost(new URL(cloudUrl).host) ??
69
+ tunnelHostForCloudHost(new URL(cloudUrl).host) ??
70
70
  DEFAULT_TUNNEL_HOST
71
71
  );
72
72
  } catch {
package/src/lib/local.ts CHANGED
@@ -76,10 +76,11 @@ import {
76
76
  pathListDelimiter,
77
77
  resolveProcessState,
78
78
  stopProcessByPidFile,
79
+ stopProcessGracefully,
79
80
  } from "./process.js";
80
81
  import { stopTunnelProcess } from "./tunnel.js";
81
82
  import { stripVersionPrefix } from "./version-compat.js";
82
- import { openLogFile, pipeToLogFile } from "./xdg-log.js";
83
+ import { openLogFile, openRuntimeLogFile, pipeToLogFile } from "./xdg-log.js";
83
84
 
84
85
  const _require = createRequire(import.meta.url);
85
86
 
@@ -839,7 +840,7 @@ async function startDaemonFromSource(
839
840
  windowsHide: true,
840
841
  })
841
842
  : (() => {
842
- const daemonLogFd = openLogFile("hatch.log");
843
+ const daemonLogFd = openRuntimeLogFile(resources?.instanceDir ?? spawnStateRoot(), "assistant");
843
844
  const c = spawn(bunPath, ["run", resolve(daemonMainPath)], {
844
845
  cwd: spawnStateRoot(),
845
846
  detached: true,
@@ -912,7 +913,7 @@ async function startDaemonWatchFromSource(
912
913
  // detect the in-progress spawn and wait instead of racing.
913
914
  writeFileSync(pidFile, "starting", "utf-8");
914
915
 
915
- const daemonLogFd = openLogFile("hatch.log");
916
+ const daemonLogFd = openRuntimeLogFile(resources?.instanceDir ?? spawnStateRoot(), "assistant");
916
917
  const child = spawn(
917
918
  resolveBunExecutable(),
918
919
  ["--watch", "run", resolve(mainPath)],
@@ -1699,7 +1700,7 @@ export async function startLocalDaemon(
1699
1700
  windowsHide: true,
1700
1701
  })
1701
1702
  : (() => {
1702
- const daemonLogFd = openLogFile("hatch.log");
1703
+ const daemonLogFd = openRuntimeLogFile(resources?.instanceDir ?? spawnStateRoot(), "assistant");
1703
1704
  const c = spawn(daemonBinary, [], {
1704
1705
  cwd: spawnStateRoot(),
1705
1706
  detached: true,
@@ -1905,7 +1906,7 @@ export async function startGateway(
1905
1906
  // Use the compiled gateway binary when available (desktop app or compiled
1906
1907
  // CLI invoked from the terminal). In watch mode, skip the bundled binary
1907
1908
  // and use source (bun --watch only works with source files).
1908
- const gatewayLogFd = openLogFile("hatch.log");
1909
+ const gatewayLogFd = openRuntimeLogFile(resources?.instanceDir ?? spawnStateRoot(), "gateway");
1909
1910
  gateway = spawn(gatewayBinary, [], {
1910
1911
  cwd: spawnStateRoot(),
1911
1912
  detached: true,
@@ -1921,7 +1922,7 @@ export async function startGateway(
1921
1922
  const bunArgs = watch
1922
1923
  ? ["--watch", "run", gatewayEntry, "--cadet-gateway"]
1923
1924
  : ["run", gatewayEntry, "--cadet-gateway"];
1924
- const gwLogFd = openLogFile("hatch.log");
1925
+ const gwLogFd = openRuntimeLogFile(resources?.instanceDir ?? spawnStateRoot(), "gateway");
1925
1926
  gateway = spawn(resolveBunExecutable(), bunArgs, {
1926
1927
  cwd: spawnStateRoot(),
1927
1928
  detached: true,
@@ -1981,15 +1982,16 @@ export async function stopLocalProcesses(
1981
1982
  "daemon",
1982
1983
  undefined,
1983
1984
  DAEMON_STOP_TIMEOUT_MS,
1985
+ stopProcessGracefully,
1984
1986
  );
1985
1987
 
1986
1988
  const gatewayPidFile = join(cadetDir, "gateway.pid");
1987
- await stopProcessByPidFile(gatewayPidFile, "gateway", undefined, 7000);
1989
+ await stopProcessByPidFile(gatewayPidFile, "gateway", undefined, 7000, stopProcessGracefully);
1988
1990
 
1989
1991
  // Stop the CES sibling if one was launched. No-op when the
1990
1992
  // PID file is absent.
1991
1993
  const cesPidFile = join(cadetDir, "ces.pid");
1992
- await stopProcessByPidFile(cesPidFile, "credential-executor");
1994
+ await stopProcessByPidFile(cesPidFile, "credential-executor", undefined, DAEMON_STOP_TIMEOUT_MS, stopProcessGracefully);
1993
1995
 
1994
1996
  // Stop the tunnel agent this CLI spawned (root lockfile `tunnel` entry),
1995
1997
  // verifying the pid still belongs to the provider's binary before signaling