@mycadet/cli 0.13.0-dev.202610231952.fa65022 → 0.13.0-dev.202610241003.f9cbe80

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 (87) hide show
  1. package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +0 -4
  2. package/node_modules/@mycadet/local-mode/src/index.ts +6 -2
  3. package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -3
  4. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -2
  5. package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +0 -31
  6. package/node_modules/@mycadet/local-mode/src/lockfile.ts +28 -48
  7. package/package.json +1 -1
  8. package/src/__tests__/app-command.test.ts +2 -2
  9. package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
  10. package/src/__tests__/assistant-client-refresh.test.ts +2 -2
  11. package/src/__tests__/assistant-config.test.ts +28 -27
  12. package/src/__tests__/backup-ops.test.ts +4 -3
  13. package/src/__tests__/backup.test.ts +2 -2
  14. package/src/__tests__/client-tui-refresh.test.ts +3 -3
  15. package/src/__tests__/connect-import.test.ts +4 -52
  16. package/src/__tests__/debug.test.ts +1 -1
  17. package/src/__tests__/devices.test.ts +5 -6
  18. package/src/__tests__/gateway-token.test.ts +3 -3
  19. package/src/__tests__/helpers/lockfile-entry.ts +37 -0
  20. package/src/__tests__/host-teleport-docker.test.ts +2 -2
  21. package/src/__tests__/host-teleport.test.ts +15 -15
  22. package/src/__tests__/local-runtime-version.test.ts +4 -2
  23. package/src/__tests__/multi-local.test.ts +14 -25
  24. package/src/__tests__/nginx-ingress.test.ts +73 -5
  25. package/src/__tests__/orphan-detection.test.ts +13 -12
  26. package/src/__tests__/ps-cloud-status.test.ts +9 -9
  27. package/src/__tests__/restore.test.ts +32 -28
  28. package/src/__tests__/retire-local.test.ts +25 -29
  29. package/src/__tests__/retire.test.ts +33 -32
  30. package/src/__tests__/root-backup-docker.test.ts +2 -2
  31. package/src/__tests__/root-backup.test.ts +2 -3
  32. package/src/__tests__/root-restore-command.test.ts +2 -2
  33. package/src/__tests__/setup.test.ts +2 -5
  34. package/src/__tests__/signing-key-continuity.test.ts +2 -93
  35. package/src/__tests__/sleep.test.ts +13 -6
  36. package/src/__tests__/teleport-backup.test.ts +8 -2
  37. package/src/__tests__/teleport.test.ts +1 -1
  38. package/src/__tests__/tui-midsession-refresh.test.ts +4 -23
  39. package/src/__tests__/tunnel-stop.test.ts +2 -3
  40. package/src/__tests__/tunnel.test.ts +27 -16
  41. package/src/__tests__/uninstall.test.ts +31 -28
  42. package/src/__tests__/upgrade-local.test.ts +29 -15
  43. package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
  44. package/src/__tests__/use.test.ts +16 -24
  45. package/src/__tests__/wake-error.test.ts +0 -1
  46. package/src/__tests__/wake.test.ts +22 -24
  47. package/src/commands/client.ts +5 -5
  48. package/src/commands/completions.test.ts +2 -2
  49. package/src/commands/debug.ts +13 -5
  50. package/src/commands/devices.ts +5 -5
  51. package/src/commands/gateway/token.ts +4 -4
  52. package/src/commands/hatch.ts +2 -2
  53. package/src/commands/login.ts +2 -2
  54. package/src/commands/logs.ts +4 -4
  55. package/src/commands/pair.ts +5 -5
  56. package/src/commands/ps.ts +23 -17
  57. package/src/commands/restore.ts +32 -20
  58. package/src/commands/retire.ts +6 -6
  59. package/src/commands/sleep.ts +117 -96
  60. package/src/commands/uninstall.ts +6 -4
  61. package/src/commands/upgrade.ts +200 -140
  62. package/src/commands/wake.ts +93 -93
  63. package/src/lib/__tests__/local-gateway-cli.test.ts +3 -3
  64. package/src/lib/__tests__/runtime-url.test.ts +1 -15
  65. package/src/lib/assistant-client.ts +5 -2
  66. package/src/lib/assistant-config.ts +43 -81
  67. package/src/lib/cloud-login.ts +12 -6
  68. package/src/lib/constants.ts +0 -1
  69. package/src/lib/docker.ts +11 -11
  70. package/src/lib/exec-apple-container.ts +2 -2
  71. package/src/lib/hatch-local.ts +12 -6
  72. package/src/lib/health-check.ts +123 -109
  73. package/src/lib/host-teleport.ts +31 -23
  74. package/src/lib/ingress-config.ts +2 -2
  75. package/src/lib/live-voice/connection.ts +2 -2
  76. package/src/lib/local.ts +76 -48
  77. package/src/lib/nginx-ingress.ts +41 -10
  78. package/src/lib/orphan-detection.ts +4 -3
  79. package/src/lib/retire-apple-container.ts +2 -2
  80. package/src/lib/retire-local.ts +11 -5
  81. package/src/lib/root-backup.ts +35 -21
  82. package/src/lib/runtime-url.ts +4 -4
  83. package/src/lib/ssh-apple-container.ts +2 -2
  84. package/src/lib/sync-cloud-assistants.ts +5 -5
  85. package/src/lib/teleport-backup.ts +15 -13
  86. package/src/lib/tunnel.ts +6 -6
  87. package/src/lib/upgrade-lifecycle.ts +36 -30
@@ -13,9 +13,10 @@ import { basename, dirname, join } from "path";
13
13
  import { resolveExistingLocalSigningKey } from "@mycadet/local-mode";
14
14
  import {
15
15
  findAssistantByName,
16
- saveAssistantEntry,
16
+ getLocalInstanceDir,
17
+ saveLockfileAssistant,
17
18
  } from "../lib/assistant-config.js";
18
- import type { AssistantEntry } from "../lib/assistant-config.js";
19
+ import type { LockfileAssistant } from "../lib/assistant-config.js";
19
20
  import {
20
21
  generateLocalSigningKey,
21
22
  startCes,
@@ -35,7 +36,9 @@ import {
35
36
  import { restoreRootBackup, validateRootArchive } from "../lib/root-backup.js";
36
37
 
37
38
  function printUsage(): void {
38
- console.log(`Usage: ${cliCommand()} restore <name> [--from <path>] [--dry-run]`);
39
+ console.log(
40
+ `Usage: ${cliCommand()} restore <name> [--from <path>] [--dry-run]`,
41
+ );
39
42
  console.log("");
40
43
  console.log(
41
44
  "Restore all persistent roots from a tar archive into an assistant.",
@@ -57,8 +60,12 @@ function printUsage(): void {
57
60
  console.log("Examples:");
58
61
  console.log(` ${cliCommand()} restore my-retired-assistant`);
59
62
  console.log(` ${cliCommand()} restore my-assistant --from backup.tar.gz`);
60
- console.log(` ${cliCommand()} restore my-cloud-assistant --from backup.tar.gz`);
61
- console.log(` ${cliCommand()} restore my-assistant --from backup.tar.gz --dry-run`);
63
+ console.log(
64
+ ` ${cliCommand()} restore my-cloud-assistant --from backup.tar.gz`,
65
+ );
66
+ console.log(
67
+ ` ${cliCommand()} restore my-assistant --from backup.tar.gz --dry-run`,
68
+ );
62
69
  }
63
70
 
64
71
  function parseArgs(argv: string[]): {
@@ -145,7 +152,7 @@ interface ImportResponse {
145
152
  // ---------------------------------------------------------------------------
146
153
 
147
154
  async function restorePlatform(
148
- entry: AssistantEntry,
155
+ entry: LockfileAssistant,
149
156
  name: string,
150
157
  bundleData: Buffer,
151
158
  opts: { dryRun: boolean },
@@ -193,7 +200,9 @@ async function restorePlatform(
193
200
  preflightResult.statusCode === 401 ||
194
201
  preflightResult.statusCode === 403
195
202
  ) {
196
- console.error(`Authentication failed. Run '${cliCommand()} login' to refresh.`);
203
+ console.error(
204
+ `Authentication failed. Run '${cliCommand()} login' to refresh.`,
205
+ );
197
206
  process.exit(1);
198
207
  }
199
208
 
@@ -301,7 +310,9 @@ async function restorePlatform(
301
310
  }
302
311
 
303
312
  if (importResult.statusCode === 401 || importResult.statusCode === 403) {
304
- console.error(`Authentication failed. Run '${cliCommand()} login' to refresh.`);
313
+ console.error(
314
+ `Authentication failed. Run '${cliCommand()} login' to refresh.`,
315
+ );
305
316
  process.exit(1);
306
317
  }
307
318
 
@@ -458,7 +469,9 @@ async function recoverFromArchive(name: string): Promise<void> {
458
469
  }
459
470
 
460
471
  // Read and validate metadata before any side effects
461
- const entry: AssistantEntry = JSON.parse(readFileSync(metadataPath, "utf-8"));
472
+ const entry: LockfileAssistant = JSON.parse(
473
+ readFileSync(metadataPath, "utf-8"),
474
+ );
462
475
  if (!entry.resources) {
463
476
  throw new Error(
464
477
  `Retired assistant '${name}' is missing resource configuration. ` +
@@ -466,9 +479,10 @@ async function recoverFromArchive(name: string): Promise<void> {
466
479
  `or run 'cadet hatch' to re-provision with proper resource allocation.`,
467
480
  );
468
481
  }
482
+ const resources = entry.resources;
469
483
 
470
484
  // Check that the recovering entry's own target directory is free.
471
- const target = entry.resources.instanceDir;
485
+ const target = getLocalInstanceDir(resources);
472
486
  if (existsSync(target)) {
473
487
  console.error(
474
488
  `Error: ${target} already exists (owned by ${entry.assistantId}). ` +
@@ -487,32 +501,30 @@ async function recoverFromArchive(name: string): Promise<void> {
487
501
  // Correct restoration: extract to retiredDir, then rename the staging entry
488
502
  // back to the original target path. Using homedir() as the -C target was
489
503
  // wrong for any instance stored outside the home directory.
490
- const targetDir = entry.resources.instanceDir;
504
+ const targetDir = getLocalInstanceDir(resources);
491
505
  const retiredDir = dirname(archivePath);
492
506
  const extractedPath = join(retiredDir, basename(archivePath) + ".staging");
493
507
 
494
508
  await exec("tar", ["xzf", archivePath, "-C", retiredDir]);
495
509
  // Validate the staged identity before occupying the destination or updating
496
510
  // the registry. A failed validation leaves the archive available for retry.
497
- const signingKey = resolveExistingLocalSigningKey(
498
- entry.resources,
499
- extractedPath,
500
- );
511
+ const signingKey = resolveExistingLocalSigningKey(resources, extractedPath);
501
512
  const bootstrapSecret =
502
513
  entry.guardianBootstrapSecret ?? generateLocalSigningKey();
503
- entry.resources = { ...entry.resources, signingKey };
514
+ const updatedResources = { ...resources, signingKey };
515
+ entry.resources = updatedResources;
504
516
  entry.guardianBootstrapSecret = bootstrapSecret;
505
517
  mkdirSync(dirname(targetDir), { recursive: true });
506
518
  renameSync(extractedPath, targetDir);
507
- saveAssistantEntry(entry);
519
+ saveLockfileAssistant(entry);
508
520
 
509
521
  // Start CES sibling + daemon + gateway in parallel, the way the
510
522
  // Docker topology brings its sibling processes up together. startCes
511
523
  // always launches the CES sibling.
512
524
  await Promise.all([
513
- startCes(false, entry.resources),
514
- startLocalDaemon(false, entry.resources, { signingKey }),
515
- startGateway(false, entry.resources, { signingKey, bootstrapSecret }),
525
+ startCes(false, updatedResources),
526
+ startLocalDaemon(false, updatedResources, { signingKey }),
527
+ startGateway(false, updatedResources, { signingKey, bootstrapSecret }),
516
528
  ]);
517
529
 
518
530
  unlinkSync(archivePath);
@@ -11,8 +11,8 @@ import {
11
11
  getAssistantDisplayName,
12
12
  loadAllAssistants,
13
13
  lookupAssistantByIdentifier,
14
- removeAssistantEntry,
15
- type AssistantEntry,
14
+ removeLockfileAssistant,
15
+ type LockfileAssistant,
16
16
  } from "../lib/assistant-config.js";
17
17
  import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
18
18
  import {
@@ -100,7 +100,7 @@ async function deleteCloudAssistant(
100
100
  }
101
101
 
102
102
  async function unregisterSelfHostedLocalPlatformRecord(
103
- entry: AssistantEntry,
103
+ entry: LockfileAssistant,
104
104
  ): Promise<void> {
105
105
  const token = readPlatformRetireToken();
106
106
  if (!token) return;
@@ -119,7 +119,7 @@ async function unregisterSelfHostedLocalPlatformRecord(
119
119
  });
120
120
  }
121
121
 
122
- async function retireCustom(entry: AssistantEntry): Promise<void> {
122
+ async function retireCustom(entry: LockfileAssistant): Promise<void> {
123
123
  const host = extractHostFromEntry(entry);
124
124
  const sshHost = `root@${host}`;
125
125
 
@@ -200,7 +200,7 @@ function parseRetireArgs(args: string[]): RetireArgs {
200
200
  };
201
201
  }
202
202
 
203
- function printRetireTarget(entry: AssistantEntry, cloud: string): void {
203
+ function printRetireTarget(entry: LockfileAssistant, cloud: string): void {
204
204
  console.log("Assistant to retire:");
205
205
  printInstanceDetails(
206
206
  {
@@ -368,7 +368,7 @@ async function retireInner(): Promise<void> {
368
368
  process.exit(1);
369
369
  }
370
370
 
371
- removeAssistantEntry(assistantId);
371
+ removeLockfileAssistant(assistantId);
372
372
  console.log(`Removed ${getAssistantDisplayName(entry)} from config.`);
373
373
 
374
374
  // When no assistants remain, remove the dock-display-name sentinel so
@@ -4,10 +4,11 @@ import { join } from "path";
4
4
 
5
5
  import {
6
6
  getDaemonPidPath,
7
+ getLocalInstanceDir,
7
8
  loadAllAssistants,
8
9
  resolveTargetAssistant,
9
10
  } from "../lib/assistant-config.js";
10
- import type { AssistantEntry } from "../lib/assistant-config.js";
11
+ import type { LockfileAssistant } from "../lib/assistant-config.js";
11
12
  import { getGatewayUrl } from "../lib/runtime-url.js";
12
13
  import { dockerResourceNames, sleepContainers } from "../lib/docker.js";
13
14
  import {
@@ -34,13 +35,13 @@ type ActiveCallLease = {
34
35
  callSessionId: string;
35
36
  };
36
37
 
37
- function getAssistantRootDir(entry: AssistantEntry): string {
38
+ function getAssistantRootDir(entry: LockfileAssistant): string {
38
39
  if (!entry.resources) {
39
40
  throw new Error(
40
41
  `Local assistant '${entry.assistantId}' is missing resource configuration. Re-hatch to fix.`,
41
42
  );
42
43
  }
43
- return entry.resources.instanceDir;
44
+ return getLocalInstanceDir(entry.resources);
44
45
  }
45
46
 
46
47
  function readActiveCallLeases(cadetDir: string): ActiveCallLease[] {
@@ -66,108 +67,121 @@ function readActiveCallLeases(cadetDir: string): ActiveCallLease[] {
66
67
 
67
68
  export const sleep = Object.assign(
68
69
  async function sleep(): Promise<void> {
69
- const args = process.argv.slice(3);
70
- if (args.includes("--help") || args.includes("-h")) {
71
- console.log(`Usage: ${cliCommand()} sleep [<name> | --all] [--force] [--wait [<duration>]]`);
72
- console.log("");
73
- console.log("Gracefully stop all services; abort if they do not exit without forced termination.");
74
- console.log("");
75
- console.log("Arguments:");
76
- console.log(
77
- " <name> Name of the assistant to stop, defaults to active or only local",
78
- );
79
- console.log("");
80
- console.log("Options:");
81
- console.log(
82
- " --all Stop every assistant across all remotes instead of one",
83
- );
84
- console.log(
85
- " --force Stop the assistant even if a phone call keepalive lease is active",
86
- );
87
- console.log(
88
- " --wait Wait for in-flight background work (heartbeats, memory jobs,",
89
- );
90
- console.log(
91
- " schedules) to finish before stopping. Waits as long as it",
92
- );
93
- console.log(
94
- " takes by default; pass a duration, e.g. --wait 90s or --wait 10m",
95
- );
96
- console.log(
97
- " to bound the wait. Ctrl-C cancels and leaves the assistant running.",
98
- );
99
- process.exit(0);
100
- }
101
-
102
- const knownFlags = new Set(["--all", "--force", "--wait"]);
103
- const unknownFlag = args.find((arg) => arg.startsWith("-") && !knownFlags.has(arg) && !arg.startsWith("--wait="));
104
- if (unknownFlag) { console.error(`Unknown sleep option: ${unknownFlag}`); process.exit(1); }
105
-
106
- const force = args.includes("--force");
107
- let wait = false;
108
- let waitMs: number | null = null;
109
- let waitDurationToken: string | null = null;
110
- const waitEqArg = args.find((a) => a.startsWith("--wait="));
111
- if (waitEqArg) {
112
- wait = true;
113
- const raw = waitEqArg.slice("--wait=".length);
114
- waitMs = parseWaitDuration(raw);
115
- if (waitMs == null) {
116
- console.error(
117
- `Error: invalid --wait duration '${raw}'. Use seconds or a value like 90s or 10m.`,
70
+ const args = process.argv.slice(3);
71
+ if (args.includes("--help") || args.includes("-h")) {
72
+ console.log(
73
+ `Usage: ${cliCommand()} sleep [<name> | --all] [--force] [--wait [<duration>]]`,
74
+ );
75
+ console.log("");
76
+ console.log(
77
+ "Gracefully stop all services; abort if they do not exit without forced termination.",
78
+ );
79
+ console.log("");
80
+ console.log("Arguments:");
81
+ console.log(
82
+ " <name> Name of the assistant to stop, defaults to active or only local",
83
+ );
84
+ console.log("");
85
+ console.log("Options:");
86
+ console.log(
87
+ " --all Stop every assistant across all remotes instead of one",
88
+ );
89
+ console.log(
90
+ " --force Stop the assistant even if a phone call keepalive lease is active",
91
+ );
92
+ console.log(
93
+ " --wait Wait for in-flight background work (heartbeats, memory jobs,",
94
+ );
95
+ console.log(
96
+ " schedules) to finish before stopping. Waits as long as it",
97
+ );
98
+ console.log(
99
+ " takes by default; pass a duration, e.g. --wait 90s or --wait 10m",
100
+ );
101
+ console.log(
102
+ " to bound the wait. Ctrl-C cancels and leaves the assistant running.",
118
103
  );
104
+ process.exit(0);
105
+ }
106
+
107
+ const knownFlags = new Set(["--all", "--force", "--wait"]);
108
+ const unknownFlag = args.find(
109
+ (arg) =>
110
+ arg.startsWith("-") &&
111
+ !knownFlags.has(arg) &&
112
+ !arg.startsWith("--wait="),
113
+ );
114
+ if (unknownFlag) {
115
+ console.error(`Unknown sleep option: ${unknownFlag}`);
119
116
  process.exit(1);
120
117
  }
121
- } else {
122
- const waitIndex = args.indexOf("--wait");
123
- if (waitIndex !== -1) {
118
+
119
+ const force = args.includes("--force");
120
+ let wait = false;
121
+ let waitMs: number | null = null;
122
+ let waitDurationToken: string | null = null;
123
+ const waitEqArg = args.find((a) => a.startsWith("--wait="));
124
+ if (waitEqArg) {
124
125
  wait = true;
125
- // A bare `--wait` waits indefinitely; a following duration token
126
- // (e.g. `90s`, `10m`, `120`) bounds it. Anything else is the name arg.
127
- const next = args[waitIndex + 1];
128
- if (next !== undefined && /^\d+(s|m)?$/.test(next)) {
129
- waitDurationToken = next;
130
- waitMs = parseWaitDuration(next);
131
- if (waitMs == null) {
132
- console.error(
133
- `Error: invalid --wait duration '${next}'. Use seconds or a value like 90s or 10m.`,
134
- );
135
- process.exit(1);
126
+ const raw = waitEqArg.slice("--wait=".length);
127
+ waitMs = parseWaitDuration(raw);
128
+ if (waitMs == null) {
129
+ console.error(
130
+ `Error: invalid --wait duration '${raw}'. Use seconds or a value like 90s or 10m.`,
131
+ );
132
+ process.exit(1);
133
+ }
134
+ } else {
135
+ const waitIndex = args.indexOf("--wait");
136
+ if (waitIndex !== -1) {
137
+ wait = true;
138
+ // A bare `--wait` waits indefinitely; a following duration token
139
+ // (e.g. `90s`, `10m`, `120`) bounds it. Anything else is the name arg.
140
+ const next = args[waitIndex + 1];
141
+ if (next !== undefined && /^\d+(s|m)?$/.test(next)) {
142
+ waitDurationToken = next;
143
+ waitMs = parseWaitDuration(next);
144
+ if (waitMs == null) {
145
+ console.error(
146
+ `Error: invalid --wait duration '${next}'. Use seconds or a value like 90s or 10m.`,
147
+ );
148
+ process.exit(1);
149
+ }
136
150
  }
137
151
  }
138
152
  }
139
- }
140
- const nameArg = args.find(
141
- (a) => !a.startsWith("-") && a !== waitDurationToken,
142
- );
143
- const all = args.includes("--all");
153
+ const nameArg = args.find(
154
+ (a) => !a.startsWith("-") && a !== waitDurationToken,
155
+ );
156
+ const all = args.includes("--all");
144
157
 
145
- if (all && nameArg) {
146
- console.error("Error: --all cannot be combined with an assistant name.");
147
- process.exit(1);
148
- }
158
+ if (all && nameArg) {
159
+ console.error("Error: --all cannot be combined with an assistant name.");
160
+ process.exit(1);
161
+ }
149
162
 
150
- if (all) {
151
- await sleepAll({ force, wait, waitMs });
152
- return;
153
- }
163
+ if (all) {
164
+ await sleepAll({ force, wait, waitMs });
165
+ return;
166
+ }
154
167
 
155
- const entry = resolveTargetAssistant(nameArg);
156
- try {
157
- await sleepAssistant(entry, { force, wait, waitMs });
158
- } catch (err) {
159
- if (err instanceof SleepExit) {
160
- console.log(err.message);
161
- process.exit(err.exitCode);
168
+ const entry = resolveTargetAssistant(nameArg);
169
+ try {
170
+ await sleepAssistant(entry, { force, wait, waitMs });
171
+ } catch (err) {
172
+ if (err instanceof SleepExit) {
173
+ console.log(err.message);
174
+ process.exit(err.exitCode);
175
+ }
176
+ console.error(
177
+ `Error: ${err instanceof Error ? err.message : String(err)}`,
178
+ );
179
+ process.exit(1);
162
180
  }
163
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
164
- process.exit(1);
165
- }
166
- },
181
+ },
167
182
  { description: "Stop the assistant process" },
168
183
  );
169
184
 
170
-
171
185
  type SleepOptions = {
172
186
  force: boolean;
173
187
  wait: boolean;
@@ -198,7 +212,9 @@ class SleepExit extends Error {
198
212
  async function sleepAll(opts: SleepOptions): Promise<void> {
199
213
  const entries = loadAllAssistants();
200
214
  if (entries.length === 0) {
201
- console.error(`Error: no assistants found. Run '${cliCommand()} hatch' first.`);
215
+ console.error(
216
+ `Error: no assistants found. Run '${cliCommand()} hatch' first.`,
217
+ );
202
218
  process.exit(1);
203
219
  }
204
220
 
@@ -240,7 +256,7 @@ async function sleepAll(opts: SleepOptions): Promise<void> {
240
256
  * (single-assistant path) and continuing to the next entry (`--all`).
241
257
  */
242
258
  export async function sleepAssistant(
243
- entry: AssistantEntry,
259
+ entry: LockfileAssistant,
244
260
  opts: SleepOptions,
245
261
  ): Promise<void> {
246
262
  const { force, wait, waitMs } = opts;
@@ -279,7 +295,9 @@ export async function sleepAssistant(
279
295
  }
280
296
  const resources = entry.resources;
281
297
  if (process.platform === "win32") {
282
- throw new Error("Graceful-only shutdown is not supported for Windows local services.");
298
+ throw new Error(
299
+ "Graceful-only shutdown is not supported for Windows local services.",
300
+ );
283
301
  }
284
302
  const assistantPidFile = getDaemonPidPath(resources);
285
303
  const cadetDir = getAssistantRootDir(entry);
@@ -312,7 +330,10 @@ export async function sleepAssistant(
312
330
  if (wait) {
313
331
  const outcome = await runDrainPhase(entry, assistantPidFile, waitMs);
314
332
  if (outcome === "cancelled") {
315
- throw new SleepExit(130, "Sleep cancelled — the assistant is still running.");
333
+ throw new SleepExit(
334
+ 130,
335
+ "Sleep cancelled — the assistant is still running.",
336
+ );
316
337
  }
317
338
  }
318
339
 
@@ -373,7 +394,7 @@ export async function sleepAssistant(
373
394
  * never make `cadet sleep` less reliable than it is without `--wait`.
374
395
  */
375
396
  async function runDrainPhase(
376
- entry: AssistantEntry,
397
+ entry: LockfileAssistant,
377
398
  assistantPidFile: string,
378
399
  waitMs: number | null,
379
400
  ): Promise<DrainOutcome | "skipped"> {
@@ -5,8 +5,9 @@ import { fileURLToPath } from "url";
5
5
 
6
6
  import {
7
7
  getDaemonPidPath,
8
+ getLocalInstanceDir,
8
9
  loadAllAssistants,
9
- type AssistantEntry,
10
+ type LockfileAssistant,
10
11
  } from "../lib/assistant-config.js";
11
12
  import {
12
13
  canPromptForConfirmation,
@@ -29,7 +30,7 @@ import { stopProcessByPidFile } from "../lib/process";
29
30
  * Everything on-disk is deleted by the sweep regardless — this is the part
30
31
  * uninstall could NOT do before it refused.
31
32
  */
32
- async function retireAssistantData(entry: AssistantEntry): Promise<void> {
33
+ async function retireAssistantData(entry: LockfileAssistant): Promise<void> {
33
34
  if (entry.cloud === "docker") {
34
35
  await retireDocker(entry.assistantId);
35
36
  return;
@@ -37,7 +38,7 @@ async function retireAssistantData(entry: AssistantEntry): Promise<void> {
37
38
  const resources = entry.resources;
38
39
  if (!resources) return;
39
40
  await stopProcessByPidFile(
40
- join(resources.instanceDir, "gateway.pid"),
41
+ join(getLocalInstanceDir(resources), "gateway.pid"),
41
42
  "gateway",
42
43
  );
43
44
  await stopProcessByPidFile(getDaemonPidPath(resources), "assistant");
@@ -187,7 +188,8 @@ function collectDeleteTargets(env = getCurrentEnvironment()): DeleteTarget[] {
187
188
  const targets: DeleteTarget[] = [
188
189
  {
189
190
  path: getStateDir(env),
190
- description: "assistant state, retired archives, and the assistants it holds",
191
+ description:
192
+ "assistant state, retired archives, and the assistants it holds",
191
193
  },
192
194
  ...getConfigDirs(env).map((dir) => ({
193
195
  path: dir,