@mycadet/cli 0.13.0-dev.202610231952.fa65022 → 0.13.0-dev.202610251252.f691e47

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 (102) hide show
  1. package/eslint.config.mjs +1 -1
  2. package/node_modules/@mycadet/assistant-api/events/assistant-status.ts +1 -3
  3. package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +0 -4
  4. package/node_modules/@mycadet/local-mode/src/__tests__/wake.test.ts +12 -6
  5. package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +1 -1
  6. package/node_modules/@mycadet/local-mode/src/index.ts +7 -8
  7. package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +1 -10
  8. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +4 -10
  9. package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +8 -39
  10. package/node_modules/@mycadet/local-mode/src/lockfile.ts +5 -49
  11. package/node_modules/@mycadet/local-mode/src/pair.ts +2 -2
  12. package/node_modules/@mycadet/local-mode/src/wake.ts +36 -14
  13. package/package.json +1 -1
  14. package/src/__tests__/app-command.test.ts +2 -2
  15. package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
  16. package/src/__tests__/assistant-client-refresh.test.ts +2 -2
  17. package/src/__tests__/assistant-config.test.ts +29 -28
  18. package/src/__tests__/backup-ops.test.ts +10 -4
  19. package/src/__tests__/backup.test.ts +2 -2
  20. package/src/__tests__/client-tui-refresh.test.ts +3 -3
  21. package/src/__tests__/connect-import.test.ts +4 -52
  22. package/src/__tests__/debug.test.ts +1 -1
  23. package/src/__tests__/devices.test.ts +5 -6
  24. package/src/__tests__/gateway-token.test.ts +3 -3
  25. package/src/__tests__/helpers/lockfile-entry.ts +37 -0
  26. package/src/__tests__/host-teleport-docker.test.ts +2 -2
  27. package/src/__tests__/host-teleport.test.ts +15 -20
  28. package/src/__tests__/local-runtime-version.test.ts +4 -2
  29. package/src/__tests__/multi-local.test.ts +14 -25
  30. package/src/__tests__/nginx-ingress.test.ts +109 -5
  31. package/src/__tests__/orphan-detection.test.ts +13 -12
  32. package/src/__tests__/ps-cloud-status.test.ts +9 -9
  33. package/src/__tests__/restore.test.ts +27 -105
  34. package/src/__tests__/retire-local.test.ts +25 -29
  35. package/src/__tests__/retire.test.ts +33 -32
  36. package/src/__tests__/root-backup-docker.test.ts +2 -2
  37. package/src/__tests__/root-backup.test.ts +9 -45
  38. package/src/__tests__/root-restore-command.test.ts +2 -2
  39. package/src/__tests__/setup.test.ts +2 -5
  40. package/src/__tests__/sleep.test.ts +13 -6
  41. package/src/__tests__/statefulset.test.ts +0 -1
  42. package/src/__tests__/teleport-backup.test.ts +8 -2
  43. package/src/__tests__/teleport.test.ts +1 -1
  44. package/src/__tests__/tui-midsession-refresh.test.ts +4 -23
  45. package/src/__tests__/tunnel-stop.test.ts +2 -3
  46. package/src/__tests__/tunnel.test.ts +27 -16
  47. package/src/__tests__/uninstall.test.ts +31 -28
  48. package/src/__tests__/upgrade-local.test.ts +39 -35
  49. package/src/__tests__/upgrade-replay-env.test.ts +10 -7
  50. package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
  51. package/src/__tests__/use.test.ts +16 -24
  52. package/src/__tests__/wake.test.ts +56 -372
  53. package/src/commands/client.ts +19 -13
  54. package/src/commands/completions.test.ts +2 -2
  55. package/src/commands/debug.ts +13 -5
  56. package/src/commands/devices.ts +5 -5
  57. package/src/commands/gateway/token.ts +13 -12
  58. package/src/commands/gateway.ts +14 -15
  59. package/src/commands/hatch.ts +2 -2
  60. package/src/commands/login.ts +2 -2
  61. package/src/commands/logs.ts +4 -4
  62. package/src/commands/pair.ts +5 -5
  63. package/src/commands/ps.ts +33 -61
  64. package/src/commands/restore.ts +31 -25
  65. package/src/commands/retire.ts +6 -6
  66. package/src/commands/sleep.ts +117 -96
  67. package/src/commands/uninstall.ts +6 -4
  68. package/src/commands/upgrade.ts +197 -147
  69. package/src/commands/wake.ts +82 -215
  70. package/src/index.ts +1 -8
  71. package/src/lib/__tests__/docker.test.ts +5 -8
  72. package/src/lib/__tests__/local-gateway-cli.test.ts +3 -3
  73. package/src/lib/__tests__/runtime-url.test.ts +1 -15
  74. package/src/lib/assistant-client.ts +5 -2
  75. package/src/lib/assistant-config.ts +43 -81
  76. package/src/lib/cli-error.ts +0 -5
  77. package/src/lib/cloud-login.ts +12 -6
  78. package/src/lib/constants.ts +0 -1
  79. package/src/lib/docker.ts +11 -19
  80. package/src/lib/exec-apple-container.ts +2 -2
  81. package/src/lib/hatch-local.ts +29 -25
  82. package/src/lib/health-check.ts +123 -109
  83. package/src/lib/host-teleport.ts +34 -25
  84. package/src/lib/ingress-config.ts +2 -2
  85. package/src/lib/live-voice/connection.ts +2 -2
  86. package/src/lib/local.ts +80 -66
  87. package/src/lib/nginx-ingress.ts +64 -10
  88. package/src/lib/orphan-detection.ts +4 -3
  89. package/src/lib/retire-apple-container.ts +2 -2
  90. package/src/lib/retire-local.ts +11 -5
  91. package/src/lib/root-backup.ts +36 -73
  92. package/src/lib/root-signing-key.ts +13 -1
  93. package/src/lib/runtime-url.ts +4 -4
  94. package/src/lib/ssh-apple-container.ts +2 -2
  95. package/src/lib/statefulset.ts +4 -4
  96. package/src/lib/sync-cloud-assistants.ts +5 -5
  97. package/src/lib/teleport-backup.ts +15 -13
  98. package/src/lib/tunnel.ts +6 -6
  99. package/src/lib/upgrade-lifecycle.ts +38 -40
  100. package/node_modules/@mycadet/local-mode/src/local-signing-key.ts +0 -73
  101. package/src/__tests__/signing-key-continuity.test.ts +0 -261
  102. package/src/__tests__/wake-error.test.ts +0 -76
package/eslint.config.mjs CHANGED
@@ -10,7 +10,7 @@ const eslintConfig = defineConfig([
10
10
  "error",
11
11
  { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
12
12
  ],
13
- // Ban `as` casts (the platform repo's rule) at warning level: the
13
+ // Ban `as` casts (the cloud repo's rule) at warning level: the
14
14
  // lint script pins --max-warnings to the current count and each PR
15
15
  // chips away at it — prefer zod schemas or `in`-narrowing.
16
16
  "@typescript-eslint/consistent-type-assertions": [
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * `assistant_status` SSE event.
3
3
  *
4
- * Server → client status announcement carrying the daemon `version`
5
- * and, when present, the assistant's key `keyFingerprint`.
4
+ * Server → client status announcement carrying the daemon `version`.
6
5
  *
7
6
  * Canonical wire-contract source. Daemon code imports the type
8
7
  * directly from this file; external consumers import via
@@ -14,7 +13,6 @@ import { z } from "zod";
14
13
  export const AssistantStatusEventSchema = z.object({
15
14
  type: z.literal("assistant_status"),
16
15
  version: z.string().optional(),
17
- keyFingerprint: z.string().optional(),
18
16
  });
19
17
 
20
18
  export type AssistantStatusEvent = z.infer<typeof AssistantStatusEventSchema>;
@@ -28,7 +28,6 @@ function writeLocalLockfile(overrides: Record<string, unknown> = {}): void {
28
28
  instanceDir,
29
29
  daemonPort: 30101,
30
30
  gatewayPort: 30102,
31
- qdrantPort: 30103,
32
31
  },
33
32
  ...overrides,
34
33
  });
@@ -147,7 +146,6 @@ describe("getLocalAssistantStatus", () => {
147
146
  instanceDir,
148
147
  daemonPort: await unusedPort(),
149
148
  gatewayPort: 30102,
150
- qdrantPort: 30103,
151
149
  },
152
150
  });
153
151
  writeAssistantPid(String(process.pid));
@@ -167,7 +165,6 @@ describe("getLocalAssistantStatus", () => {
167
165
  instanceDir,
168
166
  daemonPort: await unusedPort(),
169
167
  gatewayPort: 30102,
170
- qdrantPort: 30103,
171
168
  },
172
169
  });
173
170
  const pidPath = writeAssistantPid(String(process.pid));
@@ -194,7 +191,6 @@ describe("getLocalAssistantStatus", () => {
194
191
  instanceDir,
195
192
  daemonPort,
196
193
  gatewayPort: await unusedPort(),
197
- qdrantPort: 30103,
198
194
  },
199
195
  });
200
196
  writeAssistantPid(String(process.pid));
@@ -35,18 +35,21 @@ describe("runWake", () => {
35
35
  expect(spawnArgs[0]).toEqual(["bun", ["run", "cli", "wake", "asst-42"]]);
36
36
  });
37
37
 
38
- test("repairGuardian: true appends --repair-guardian to the CLI args", async () => {
38
+ test("repairGuardian: true chains the gateway's own token re-lease after the wake", async () => {
39
39
  const pending = runWake(invocation, "asst-42", { repairGuardian: true });
40
- lastChild.emit("close", 0);
40
+ lastChild.emit("close", 0); // wake completes...
41
+ await Promise.resolve(); // the chain spawns the re-lease
42
+ expect(spawnArgs[0]).toEqual(["bun", ["run", "cli", "wake", "asst-42"]]);
41
43
 
44
+ lastChild.emit("close", 0); // the re-lease completes
42
45
  expect(await pending).toEqual({ ok: true });
43
- expect(spawnArgs[0]).toEqual([
46
+ expect(spawnArgs[1]).toEqual([
44
47
  "bun",
45
- ["run", "cli", "wake", "asst-42", "--repair-guardian"],
48
+ ["run", "cli", "gateway", "token", "refresh", "asst-42"],
46
49
  ]);
47
50
  });
48
51
 
49
- test("repairGuardian: false omits the flag", async () => {
52
+ test("repairGuardian: false ends at the wake", async () => {
50
53
  const pending = runWake(invocation, "asst-42", { repairGuardian: false });
51
54
  lastChild.emit("close", 0);
52
55
 
@@ -56,7 +59,10 @@ describe("runWake", () => {
56
59
 
57
60
  test("a non-zero exit resolves to a failure carrying the CLI's output", async () => {
58
61
  const pending = runWake(invocation, "asst-42");
59
- lastChild.stderr.emit("data", Buffer.from("no sibling environment to seed from"));
62
+ lastChild.stderr.emit(
63
+ "data",
64
+ Buffer.from("no sibling environment to seed from"),
65
+ );
60
66
  lastChild.emit("close", 1);
61
67
 
62
68
  expect(await pending).toEqual({
@@ -193,7 +193,7 @@ const MAX_GATEWAY_PORT = 65535;
193
193
  * loopback — a connect import's remote gateway) resolves to it directly;
194
194
  * otherwise a loopback-gateway cloud (`local`, `docker`) resolves to its
195
195
  * recorded loopback port via {@link getLoopbackGatewayPort}. Everything
196
- * else — the platform cloud — is left out, and an absent id is a proxy
196
+ * else — the cloud — is left out, and an absent id is a proxy
197
197
  * rejection.
198
198
  *
199
199
  * Pure, so a host holding an in-memory lockfile snapshot (e.g. the Electron
@@ -45,8 +45,7 @@ export {
45
45
  getLockfileData,
46
46
  renameLockfileAssistantIfPresent,
47
47
  stampLockfileAssistantOnboardedIfPresent,
48
- upsertLockfileAssistant,
49
- upsertRendererLockfileAssistant,
48
+ saveLockfileAssistant,
50
49
  replaceCloudAssistants,
51
50
  isActiveAssistant,
52
51
  isPairedLockfileEntry,
@@ -54,7 +53,12 @@ export {
54
53
  export type { LockfileResult, WriteResult } from "./lockfile";
55
54
  export { withLockfileLock } from "./lockfile-lock";
56
55
  export type { LockfileLockResult } from "./lockfile-lock";
57
- export { getLoopbackGatewayPort, parseLockfile } from "./lockfile-contract";
56
+ export {
57
+ getLoopbackGatewayPort,
58
+ LockfileAssistantSchema,
59
+ parseLockfile,
60
+ } from "./lockfile-contract";
61
+ export { readRawLockfileStrict } from "./lockfile";
58
62
  export type {
59
63
  Lockfile,
60
64
  LockfileAssistant,
@@ -144,8 +148,3 @@ export type {
144
148
  PairedForwardAuthorizationResult,
145
149
  PairedGuardianTokenProvider,
146
150
  } from "./gateway-proxy";
147
-
148
- export {
149
- resolveExistingLocalSigningKey,
150
- SigningKeyContinuityError,
151
- } from "./local-signing-key";
@@ -229,9 +229,7 @@ describe("parseLockfile", () => {
229
229
  daemonPort: 7778,
230
230
  runtimeVersion: "v0.8.13",
231
231
  runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
232
- qdrantPort: 7779,
233
232
  cesPort: 7780,
234
- signingKey: "hunter2",
235
233
  },
236
234
  },
237
235
  ],
@@ -243,9 +241,7 @@ describe("parseLockfile", () => {
243
241
  daemonPort: 7778,
244
242
  runtimeVersion: "v0.8.13",
245
243
  runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
246
- qdrantPort: 7779,
247
244
  cesPort: 7780,
248
- signingKey: "hunter2",
249
245
  });
250
246
  const stripped = structuredClone(raw);
251
247
  stripSensitiveFields(stripped);
@@ -255,7 +251,6 @@ describe("parseLockfile", () => {
255
251
  daemonPort: 7778,
256
252
  runtimeVersion: "v0.8.13",
257
253
  runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
258
- qdrantPort: 7779,
259
254
  cesPort: 7780,
260
255
  });
261
256
  });
@@ -387,10 +382,6 @@ describe("taxonomy", () => {
387
382
  });
388
383
 
389
384
  test("SENSITIVE_KEYS lists the redacted secrets", () => {
390
- expect(SENSITIVE_KEYS).toEqual([
391
- "signingKey",
392
- "bearerToken",
393
- "guardianBootstrapSecret",
394
- ]);
385
+ expect(SENSITIVE_KEYS).toEqual(["bearerToken", "guardianBootstrapSecret"]);
395
386
  });
396
387
  });
@@ -57,7 +57,6 @@ export type Remote = z.infer<typeof RemoteSchema>;
57
57
  * place they are modeled.
58
58
  */
59
59
  export const SENSITIVE_KEYS = [
60
- "signingKey",
61
60
  "bearerToken",
62
61
  "guardianBootstrapSecret",
63
62
  ] as const;
@@ -190,24 +189,19 @@ export function getLoopbackGatewayPort(entry: {
190
189
 
191
190
  /**
192
191
  * Per-instance resources for a local assistant: the renderer-facing ports,
193
- * the instance directory, and the local runtime install metadata, plus the
194
- * host-only ports and the persisted signing key the CLI read-modify-writes.
195
- * Strict: every field the CLI round-trips is modeled, so nothing is dropped
196
- * by the parse. The secrets are stripped from renderer reads by
197
- * {@link stripSensitiveFields} before the parse ever sees them.
192
+ * the instance directory, the local runtime install metadata, and the
193
+ * host-only ports. Strict: every field the CLI round-trips is modeled, so
194
+ * nothing is dropped by the parse. The secrets are stripped from renderer
195
+ * reads by {@link stripSensitiveFields} before the parse ever sees them.
198
196
  */
199
197
  export const LocalAssistantResourcesSchema = z.object({
200
198
  instanceDir: z.string().optional(),
201
199
  gatewayPort: z.number(),
202
200
  daemonPort: z.number(),
203
- /** HTTP port for the Qdrant vector store (host-only). */
204
- qdrantPort: z.number().optional(),
205
201
  /** HTTP port for the CES (Claude Extension Server) (host-only). */
206
202
  cesPort: z.number().optional(),
207
203
  runtimeVersion: z.string().optional(),
208
204
  runtimeInstallDir: z.string().optional(),
209
- /** Persisted HMAC signing key (hex); survives daemon/gateway restarts so client actor tokens remain valid across wake cycles. */
210
- signingKey: z.string().optional(),
211
205
  });
212
206
  export type LocalAssistantResources = z.infer<
213
207
  typeof LocalAssistantResourcesSchema
@@ -9,8 +9,7 @@ import {
9
9
  renameLockfileAssistantIfPresent,
10
10
  stampLockfileAssistantOnboardedIfPresent,
11
11
  replaceCloudAssistants,
12
- upsertLockfileAssistant,
13
- upsertRendererLockfileAssistant,
12
+ saveLockfileAssistant,
14
13
  } from "./lockfile";
15
14
 
16
15
  let dir: string;
@@ -127,9 +126,9 @@ describe("isPairedLockfileEntry", () => {
127
126
  });
128
127
  });
129
128
 
130
- describe("upsertLockfileAssistant", () => {
129
+ describe("saveLockfileAssistant", () => {
131
130
  test("rejects an assistant with no id", () => {
132
- const result = upsertLockfileAssistant(
131
+ const result = saveLockfileAssistant(
133
132
  [lockfilePath],
134
133
  { cloud: "local" },
135
134
  undefined,
@@ -157,7 +156,7 @@ describe("upsertLockfileAssistant", () => {
157
156
  ],
158
157
  });
159
158
 
160
- const result = upsertLockfileAssistant(
159
+ const result = saveLockfileAssistant(
161
160
  [lockfilePath],
162
161
  { assistantId: "asst_new", cloud: "local", runtimeUrl: "http://new" },
163
162
  "asst_new",
@@ -195,7 +194,7 @@ describe("upsertLockfileAssistant", () => {
195
194
  ],
196
195
  });
197
196
 
198
- upsertLockfileAssistant(
197
+ saveLockfileAssistant(
199
198
  [lockfilePath],
200
199
  { assistantId: "asst_1", name: "Renamed" },
201
200
  undefined,
@@ -226,7 +225,7 @@ describe("upsertLockfileAssistant", () => {
226
225
  };
227
226
  writeOnDisk({ activeAssistant: "asst_1", assistants: [entry] });
228
227
 
229
- const result = upsertLockfileAssistant(
228
+ const result = saveLockfileAssistant(
230
229
  [lockfilePath],
231
230
  { assistantId: "asst_1", name: "Renamed" },
232
231
  undefined,
@@ -253,7 +252,7 @@ describe("upsertLockfileAssistant", () => {
253
252
  ],
254
253
  });
255
254
 
256
- const result = upsertLockfileAssistant(
255
+ const result = saveLockfileAssistant(
257
256
  [lockfilePath],
258
257
  { assistantId: "asst_1", name: "Renamed" },
259
258
  undefined,
@@ -520,7 +519,7 @@ describe("lockfile writers under lock contention", () => {
520
519
  const before = fs.readFileSync(lockfilePath, "utf-8");
521
520
  holdLock();
522
521
 
523
- const result = upsertLockfileAssistant(
522
+ const result = saveLockfileAssistant(
524
523
  [lockfilePath],
525
524
  { assistantId: "asst_2", cloud: "local" },
526
525
  undefined,
@@ -558,36 +557,6 @@ describe("lockfile writers under lock contention", () => {
558
557
  });
559
558
  });
560
559
 
561
- describe("upsertRendererLockfileAssistant", () => {
562
- const paired = {
563
- assistantId: "paired-1",
564
- paired: true,
565
- runtimeUrl: "https://gateway.example.com",
566
- name: "Paired assistant",
567
- };
568
-
569
- test("allows non-security updates and activation of an existing pairing", () => {
570
- writeOnDisk({ assistants: [paired], activeAssistant: null });
571
-
572
- const result = upsertRendererLockfileAssistant(
573
- [lockfilePath],
574
- {
575
- assistantId: "paired-1",
576
- paired: true,
577
- runtimeUrl: "https://gateway.example.com",
578
- name: "Renamed pairing",
579
- },
580
- "paired-1",
581
- );
582
-
583
- expect(result.ok).toBe(true);
584
- expect(readOnDisk()).toEqual({
585
- assistants: [{ ...paired, name: "Renamed pairing" }],
586
- activeAssistant: "paired-1",
587
- });
588
- });
589
- });
590
-
591
560
  describe("replaceCloudAssistants", () => {
592
561
  test("rejects a renderer sync that tries to create a paired entry", () => {
593
562
  writeOnDisk({
@@ -274,7 +274,7 @@ function patchLockfileAssistantIfPresent(
274
274
  return locked.ok ? locked.value : lockFailure(locked.error);
275
275
  }
276
276
 
277
- export function upsertLockfileAssistant(
277
+ export function saveLockfileAssistant(
278
278
  lockfilePaths: string[],
279
279
  assistant: Record<string, unknown>,
280
280
  activeAssistant: string | undefined,
@@ -292,7 +292,10 @@ export function upsertLockfileAssistant(
292
292
  (a: Record<string, unknown>) => a?.assistantId === assistant.assistantId,
293
293
  );
294
294
  if (existingIdx >= 0) {
295
- assistants[existingIdx] = { ...assistants[existingIdx], ...assistant };
295
+ assistants[existingIdx] = {
296
+ ...assistants[existingIdx]!,
297
+ ...assistant,
298
+ };
296
299
  } else {
297
300
  assistants.push(assistant);
298
301
  }
@@ -306,53 +309,6 @@ export function upsertLockfileAssistant(
306
309
  return locked.ok ? locked.value : lockFailure(locked.error);
307
310
  }
308
311
 
309
- // The renderer surface is an ALLOWLIST over the strict base schema: the base
310
- // models host-owned fields (the secrets, resources, addressing, process
311
- // bookkeeping) that must never ride a renderer payload, so a renderer save
312
- // parses through the fields a renderer may write and nothing else — a newly
313
- // modeled field is renderer-invisible until deliberately added here.
314
- // `cloud` additionally never rides because the schema's `catch` would
315
- // otherwise materialize a spurious "local" into every upsert, clobbering the
316
- // recorded topology on merge.
317
- const RendererAssistantUpdateSchema = LockfileAssistantSchema.pick({
318
- assistantId: true,
319
- name: true,
320
- runtimeUrl: true,
321
- hatchedAt: true,
322
- onboardedAt: true,
323
- cloudAssistantId: true,
324
- cloudBaseUrl: true,
325
- cloudOrganizationId: true,
326
- });
327
-
328
- /**
329
- * Apply a renderer-originated lockfile upsert. Resources and secrets are
330
- * host-owned and never accepted from a renderer.
331
- */
332
- export function upsertRendererLockfileAssistant(
333
- lockfilePaths: string[],
334
- assistant: Record<string, unknown>,
335
- activeAssistant: string | undefined,
336
- ): WriteResult {
337
- if (!assistant || typeof assistant.assistantId !== "string") {
338
- return { ok: false, status: 400, error: "Missing assistant.assistantId" };
339
- }
340
-
341
- const locked = withLockfileLock(lockfilePaths, (): WriteResult => {
342
- const read = readRawLockfileStrict(lockfilePaths);
343
- if (!read.ok) {
344
- return { ok: false, status: 409, error: read.error };
345
- }
346
-
347
- const update = RendererAssistantUpdateSchema.safeParse(assistant);
348
- if (!update.success) {
349
- return { ok: false, status: 400, error: "Invalid assistant metadata" };
350
- }
351
- return upsertLockfileAssistant(lockfilePaths, update.data, activeAssistant);
352
- });
353
- return locked.ok ? locked.value : lockFailure(locked.error);
354
- }
355
-
356
312
  export function isActiveAssistant(
357
313
  lockfilePaths: string[],
358
314
  assistantId: string,
@@ -17,7 +17,7 @@ import { nanoid } from "nanoid";
17
17
 
18
18
  import { guardianTokenPath } from "./config";
19
19
  import { isConfidentialRefreshUrl, saveGuardianToken } from "./guardian-token";
20
- import { readRawLockfile, upsertLockfileAssistant } from "./lockfile";
20
+ import { readRawLockfile, saveLockfileAssistant } from "./lockfile";
21
21
 
22
22
  /**
23
23
  * The session credentials a pairing exchange yields, in the shape
@@ -306,7 +306,7 @@ export function pairAssistant(
306
306
  };
307
307
  }
308
308
 
309
- const writeResult = upsertLockfileAssistant(
309
+ const writeResult = saveLockfileAssistant(
310
310
  lockfilePaths,
311
311
  {
312
312
  assistantId: localId,
@@ -10,12 +10,15 @@ import type { CliInvocation } from "./util";
10
10
  // a slow-but-succeeding wake gets killed and misreported as a timeout.
11
11
  const WAKE_TIMEOUT_MS = 180_000;
12
12
 
13
+ /** The re-lease runs after the wake, inside the same safety-net window. */
14
+ const REPAIR_TIMEOUT_MS = 60_000;
15
+
13
16
  export type WakeResult =
14
17
  | { ok: true }
15
18
  | { ok: false; status: number; error: string };
16
19
 
17
20
  export interface WakeOptions {
18
- /** Pass --repair-guardian to re-provision a missing/expired guardian token. Revokes the assistant's other device-bound tokens, so callers must gate this behind explicit user confirmation. */
21
+ /** Re-provision the guardian credential after the wake (the gateway's bootstrap reset + re-lease, the same machinery `cadet gateway token refresh` runs). Revokes the assistant's other device-bound tokens, so callers must gate this behind explicit user confirmation. */
19
22
  repairGuardian?: boolean;
20
23
  }
21
24
 
@@ -33,18 +36,33 @@ export function runWake(
33
36
  invocation: CliInvocation,
34
37
  assistantId: string,
35
38
  options?: WakeOptions,
39
+ ): Promise<WakeResult> {
40
+ return runCli(invocation, ["wake", assistantId], WAKE_TIMEOUT_MS).then(
41
+ (woken) => {
42
+ if (!woken.ok || !options?.repairGuardian) {
43
+ return woken;
44
+ }
45
+ // The credential repair is the gateway's own machinery now: the
46
+ // gateway is up after the wake, so the re-lease runs against it.
47
+ return runCli(
48
+ invocation,
49
+ ["gateway", "token", "refresh", assistantId],
50
+ REPAIR_TIMEOUT_MS,
51
+ );
52
+ },
53
+ );
54
+ }
55
+
56
+ function runCli(
57
+ invocation: CliInvocation,
58
+ args: string[],
59
+ timeoutMs: number,
36
60
  ): Promise<WakeResult> {
37
61
  return new Promise((resolve) => {
38
- const child = spawn(
39
- invocation.command,
40
- [
41
- ...invocation.baseArgs,
42
- "wake",
43
- assistantId,
44
- ...(options?.repairGuardian ? ["--repair-guardian"] : []),
45
- ],
46
- { stdio: ["ignore", "pipe", "pipe"], windowsHide: true },
47
- );
62
+ const child = spawn(invocation.command, [...invocation.baseArgs, ...args], {
63
+ stdio: ["ignore", "pipe", "pipe"],
64
+ windowsHide: true,
65
+ });
48
66
 
49
67
  let stdout = "";
50
68
  let stderr = "";
@@ -62,9 +80,9 @@ export function runWake(
62
80
  finish({
63
81
  ok: false,
64
82
  status: 500,
65
- error: `Wake timed out after ${WAKE_TIMEOUT_MS / 1000} seconds`,
83
+ error: `CLI invocation timed out after ${timeoutMs / 1000} seconds`,
66
84
  });
67
- }, WAKE_TIMEOUT_MS);
85
+ }, timeoutMs);
68
86
 
69
87
  child.stdout.on("data", (data: Buffer) => {
70
88
  stdout += data.toString();
@@ -83,7 +101,11 @@ export function runWake(
83
101
  });
84
102
 
85
103
  child.on("error", (err) => {
86
- finish({ ok: false, status: 500, error: `Failed to spawn CLI: ${err.message}` });
104
+ finish({
105
+ ok: false,
106
+ status: 500,
107
+ error: `Failed to spawn CLI: ${err.message}`,
108
+ });
87
109
  });
88
110
  });
89
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202610231952.fa65022",
3
+ "version": "0.13.0-dev.202610251252.f691e47",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -18,7 +18,7 @@ import { join } from "node:path";
18
18
  // ---------------------------------------------------------------------------
19
19
 
20
20
  import * as tunnelLib from "../lib/tunnel.js";
21
- import type { AssistantEntry } from "../lib/assistant-config.js";
21
+ import type { LockfileAssistant } from "../lib/assistant-config.js";
22
22
  import * as nginxIngress from "../lib/nginx-ingress.js";
23
23
 
24
24
  const ensureNginxForEdgeMock = mock(tunnelLib.ensureNginxForEdge);
@@ -90,7 +90,7 @@ afterAll(() => {
90
90
  rmSync(testDir, { recursive: true, force: true });
91
91
  });
92
92
 
93
- const LOCAL_ENTRY: AssistantEntry = {
93
+ const LOCAL_ENTRY: LockfileAssistant = {
94
94
  assistantId: "assistant-1",
95
95
  runtimeUrl: "http://127.0.0.1:7830",
96
96
  cloud: "local",
@@ -22,7 +22,7 @@ const ORIGINAL_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
22
22
  const ORIGINAL_FETCH = globalThis.fetch;
23
23
 
24
24
  import { AssistantClient } from "../lib/assistant-client.js";
25
- import { saveAssistantEntry } from "../lib/assistant-config.js";
25
+ import { saveLockfileAssistant } from "../lib/assistant-config.js";
26
26
  import {
27
27
  clearCloudToken,
28
28
  saveCloudToken,
@@ -34,7 +34,7 @@ const ORG_ID = "org-abc";
34
34
 
35
35
  /** Seed a cloud-managed lockfile entry, optionally with a stored token. */
36
36
  function seedCloud(token?: string): void {
37
- saveAssistantEntry({
37
+ saveLockfileAssistant({
38
38
  assistantId: ASSISTANT_ID,
39
39
  name: "Credence",
40
40
  runtimeUrl: PLATFORM_URL,
@@ -22,7 +22,7 @@ const ORIGINAL_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
22
22
  const ORIGINAL_FETCH = globalThis.fetch;
23
23
 
24
24
  import { AssistantClient } from "../lib/assistant-client.js";
25
- import { saveAssistantEntry } from "../lib/assistant-config.js";
25
+ import { saveLockfileAssistant } from "../lib/assistant-config.js";
26
26
  import { loadGuardianToken, saveGuardianToken } from "../lib/guardian-token.js";
27
27
 
28
28
  const RUNTIME = "https://gw.example.com";
@@ -36,7 +36,7 @@ const PAST = new Date(Date.now() - 60_000).toISOString();
36
36
  */
37
37
  function seedPaired(refreshToken: string, opts?: { due?: boolean }): void {
38
38
  const due = opts?.due ?? true;
39
- saveAssistantEntry({
39
+ saveLockfileAssistant({
40
40
  assistantId: "px",
41
41
  name: "Paired",
42
42
  runtimeUrl: RUNTIME,