@mycadet/cli 0.13.0-dev.202611142107.f5e00a2 → 0.13.0-dev.202611142201.aad87f9

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 (42) hide show
  1. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
  2. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +12 -0
  3. package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  4. package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  5. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  6. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
  8. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +12 -0
  9. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
  10. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/seeds.ts +5 -22
  11. package/node_modules/@mycadet/local-mode/package.json +3 -2
  12. package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token.test.ts +5 -5
  13. package/node_modules/@mycadet/local-mode/src/__tests__/hatch-local-config-api.test.ts +21 -4
  14. package/node_modules/@mycadet/local-mode/src/__tests__/operations-pair.test.ts +21 -8
  15. package/node_modules/@mycadet/local-mode/src/__tests__/pair.test.ts +0 -2
  16. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-pair.test.ts +16 -6
  17. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-pair.test.ts +18 -8
  18. package/node_modules/@mycadet/local-mode/src/__tests__/root-backup-docker.test.ts +2 -3
  19. package/node_modules/@mycadet/local-mode/src/__tests__/upgrade-root-recovery.test.ts +4 -2
  20. package/node_modules/@mycadet/local-mode/src/guardian-contract.ts +36 -0
  21. package/node_modules/@mycadet/local-mode/src/guardian-token.ts +9 -22
  22. package/node_modules/@mycadet/local-mode/src/operations/pair.ts +26 -7
  23. package/node_modules/@mycadet/local-mode/src/pair.ts +0 -1
  24. package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +75 -61
  25. package/node_modules/@mycadet/local-mode/src/remotes/docker/pair.ts +7 -3
  26. package/node_modules/@mycadet/local-mode/src/remotes/docker/wake.ts +40 -15
  27. package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +18 -0
  28. package/node_modules/@mycadet/local-mode/src/remotes/local/pair.ts +7 -3
  29. package/node_modules/@mycadet/local-mode/src/upgrade-lifecycle.ts +2 -3
  30. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  31. package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +12 -0
  32. package/node_modules/@mycadet/shared/package.json +1 -1
  33. package/node_modules/@mycadet/shared/seeds.ts +5 -22
  34. package/package.json +1 -1
  35. package/src/__tests__/assistant-client-refresh.test.ts +5 -2
  36. package/src/__tests__/client-tui-refresh.test.ts +12 -1
  37. package/src/__tests__/guardian-token.test.ts +57 -31
  38. package/src/__tests__/setup.test.ts +10 -6
  39. package/src/__tests__/tui-midsession-refresh.test.ts +12 -1
  40. package/src/commands/pair.ts +9 -8
  41. package/src/index.ts +1 -9
  42. package/src/lib/guardian-token.ts +16 -34
@@ -256,7 +256,6 @@ export function pairAssistant({ credentials, name }: PairOptions): PairResult {
256
256
  refreshAfter: credentials.refreshAfter ?? "",
257
257
  deviceId: credentials.deviceId ?? "",
258
258
  leasedAt: new Date(now).toISOString(),
259
- pairedGatewayUrl: credentials.gatewayUrl,
260
259
  });
261
260
  } catch (err) {
262
261
  return {
@@ -570,14 +570,6 @@ export interface HatchDockerParams {
570
570
  * leases, while the choice is fresh.
571
571
  */
572
572
  precollectedApiKey?: string;
573
- /**
574
- * Create the three containers without starting them and persist the entry
575
- * without waiting for readiness — the teleport's initialize-data half. The
576
- * caller installs the transferred archive into the created volumes and
577
- * wakes; a hatch is just initialize-data + wake, and the teleport owns
578
- * both halves itself.
579
- */
580
- createOnly?: boolean;
581
573
  /**
582
574
  * The CLI's release version — owns the Docker Hub image resolution (the
583
575
  * published images are tagged from it).
@@ -624,8 +616,8 @@ export type HatchDockerResult =
624
616
  ok: true;
625
617
  entry: DockerAssistant;
626
618
  /**
627
- * False when hatch returned early (createOnly) or the readiness wait
628
- * timed out in watch mode (where the watcher's rebuilds retry it).
619
+ * False when the readiness wait timed out in watch mode (where the
620
+ * watcher's rebuilds retry it).
629
621
  */
630
622
  ready: boolean;
631
623
  guardianAccessToken?: string;
@@ -877,12 +869,8 @@ export async function hatchDocker(
877
869
  cesImage: imageTags["credential-executor"],
878
870
  },
879
871
  };
880
- if (params.createOnly) {
881
- saveLockfileAssistant(dockerEntry);
882
- }
883
872
  await startContainers(
884
873
  {
885
- createOnly: !!params.createOnly,
886
874
  extraAssistantEnv,
887
875
  extraGatewayEnv,
888
876
  gatewayPort,
@@ -898,12 +886,6 @@ export async function hatchDocker(
898
886
  // The active-assistant switch rides the same locked write.
899
887
  saveLockfileAssistant(dockerEntry, instanceName);
900
888
 
901
- if (params.createOnly) {
902
- // The teleport's initialize-data half: containers exist (created, not
903
- // started) and the entry is persisted — the caller installs the
904
- // transferred archive into the volumes and wakes.
905
- return { ok: true, entry: dockerEntry, ready: false };
906
- }
907
889
  // Hatch always detaches; only watch mode keeps the log stream attached.
908
890
  const waitDetached = !watch;
909
891
  const { ready, guardianAccessToken, notReadyReason } =
@@ -1055,10 +1037,12 @@ async function waitForGatewayAndLease(opts: {
1055
1037
  if (detached) {
1056
1038
  // Lease a guardian token BEFORE declaring the assistant hatched so the
1057
1039
  // banner means `cadet ps`, `cadet exec`, and other CLI commands can
1058
- // already authenticate. Skip the /readyz readiness poll (the caller
1059
- // asked to detach and not block) but retry the lease silently since
1060
- // the gateway may need a moment to accept connections after the
1061
- // container starts; only a final failure surfaces to the user.
1040
+ // already authenticate. The lease only proves the GATEWAY is answering —
1041
+ // the assistant daemon behind it can still be starting, so the /readyz
1042
+ // poll below still runs (same budget): the config apply and provider
1043
+ // setup that follow the lease need the daemon actually ready, not just
1044
+ // the gateway. The lease retries silently since the gateway may need a
1045
+ // moment to accept connections after the container starts.
1062
1046
  const leaseDeadline = containersUpAt + DOCKER_READY_TIMEOUT_MS;
1063
1047
  let guardianAccessToken: string | undefined;
1064
1048
  while (Date.now() < leaseDeadline) {
@@ -1078,6 +1062,25 @@ async function waitForGatewayAndLease(opts: {
1078
1062
  );
1079
1063
  }
1080
1064
 
1065
+ // The same body-classified readiness wait the attached path runs — a
1066
+ // 503 `{"status":"starting"}` from the gateway's traffic gate is what
1067
+ // awaits anything that skips it.
1068
+ const detachedReadiness = await pollReadyzUntil(
1069
+ gatewayUrl,
1070
+ leaseDeadline,
1071
+ log,
1072
+ );
1073
+ if (detachedReadiness === "failed") {
1074
+ return {
1075
+ ready: false,
1076
+ guardianAccessToken,
1077
+ notReadyReason: "migrations_failed",
1078
+ };
1079
+ }
1080
+ if (detachedReadiness === "timeout") {
1081
+ return { ready: false, guardianAccessToken };
1082
+ }
1083
+
1081
1084
  return { ready: true, guardianAccessToken };
1082
1085
  }
1083
1086
 
@@ -1086,47 +1089,21 @@ async function waitForGatewayAndLease(opts: {
1086
1089
  log("");
1087
1090
  log("Waiting for assistant to become ready...");
1088
1091
 
1089
- const readyUrl = `${gatewayUrl}/readyz`;
1090
1092
  const start = containersUpAt;
1091
- let ready = false;
1092
- let migrationsFailed = false;
1093
-
1094
1093
  // Readiness is classified from the /readyz BODY: the assistant returns 200
1095
1094
  // with `ready: false` while DB migrations run (the k8s keep-the-pod
1096
1095
  // contract), so `resp.ok` alone would declare readiness mid-migration and
1097
1096
  // the guardian token lease below would burn its shared budget against the
1098
1097
  // gateway's still-closed traffic gate.
1099
- while (Date.now() - start < DOCKER_READY_TIMEOUT_MS) {
1100
- try {
1101
- const resp = await loopbackSafeFetch(readyUrl, {
1102
- signal: AbortSignal.timeout(5000),
1103
- });
1104
- const body = (await resp.json().catch(() => null)) as {
1105
- status?: string;
1106
- upstream?: number;
1107
- } | null;
1108
- const readiness = classifyReadyzResponse(resp.ok, body);
1109
- if (readiness === "ready") {
1110
- ready = true;
1111
- break;
1112
- }
1113
- if (readiness === "failed") {
1114
- migrationsFailed = true;
1115
- break;
1116
- }
1117
- const parts = [body?.status].filter(Boolean);
1118
- if (body?.upstream != null) parts.push(`upstream=${body.upstream}`);
1119
- const detail = parts.length > 0 ? ` — ${parts.join(", ")}` : "";
1120
- log(`Readiness check: ${resp.status}${detail} (retrying...)`);
1121
- } catch {
1122
- // Connection refused / timeout — not up yet
1123
- }
1124
- await new Promise((r) => setTimeout(r, 1000));
1125
- }
1098
+ const readiness = await pollReadyzUntil(
1099
+ gatewayUrl,
1100
+ start + DOCKER_READY_TIMEOUT_MS,
1101
+ log,
1102
+ );
1126
1103
 
1127
- if (!ready) {
1104
+ if (readiness !== "ready") {
1128
1105
  log("");
1129
- if (migrationsFailed) {
1106
+ if (readiness === "failed") {
1130
1107
  log(` \u26a0\ufe0f Assistant database migrations FAILED.`);
1131
1108
  } else {
1132
1109
  log(` \u26a0\ufe0f Timed out waiting for assistant to become ready.`);
@@ -1136,7 +1113,7 @@ async function waitForGatewayAndLease(opts: {
1136
1113
  log("");
1137
1114
  return {
1138
1115
  ready: false,
1139
- ...(migrationsFailed
1116
+ ...(readiness === "failed"
1140
1117
  ? { notReadyReason: "migrations_failed" as const }
1141
1118
  : {}),
1142
1119
  };
@@ -1191,7 +1168,44 @@ async function waitForGatewayAndLease(opts: {
1191
1168
  }
1192
1169
 
1193
1170
  /**
1194
- * Mint (and approve) a remote-web pairing challenge inside the gateway
1195
- * container — the docker topology's `gateway pairing mint`. Returns the
1196
- * command's stdout; its last line is the challenge JSON.
1171
+ * Poll the gateway's `/readyz` until the assistant answers ready, migrations
1172
+ * fail outright, or the deadline passes. Readiness is classified from the
1173
+ * response body (the same wire contract `daemon-readiness.ts` owns); every
1174
+ * interim answer is narrated so a slow hatch explains itself. Shared by the
1175
+ * attached and detached lease paths — the config apply that follows the
1176
+ * guardian-token lease needs the daemon actually ready, and skipping this
1177
+ * poll is what produced `503 {"status":"starting"}` config applies.
1197
1178
  */
1179
+ async function pollReadyzUntil(
1180
+ gatewayUrl: string,
1181
+ deadlineMs: number,
1182
+ log: (msg: string) => void,
1183
+ ): Promise<"ready" | "failed" | "timeout"> {
1184
+ const readyUrl = `${gatewayUrl}/readyz`;
1185
+ while (Date.now() < deadlineMs) {
1186
+ try {
1187
+ const resp = await loopbackSafeFetch(readyUrl, {
1188
+ signal: AbortSignal.timeout(5000),
1189
+ });
1190
+ const body = (await resp.json().catch(() => null)) as {
1191
+ status?: string;
1192
+ upstream?: number;
1193
+ } | null;
1194
+ const readiness = classifyReadyzResponse(resp.ok, body);
1195
+ if (readiness === "ready") {
1196
+ return "ready";
1197
+ }
1198
+ if (readiness === "failed") {
1199
+ return "failed";
1200
+ }
1201
+ const parts = [body?.status].filter(Boolean);
1202
+ if (body?.upstream != null) parts.push(`upstream=${body.upstream}`);
1203
+ const detail = parts.length > 0 ? ` — ${parts.join(", ")}` : "";
1204
+ log(`Readiness check: ${resp.status}${detail} (retrying...)`);
1205
+ } catch {
1206
+ // Connection refused / timeout — not up yet
1207
+ }
1208
+ await new Promise((r) => setTimeout(r, 1000));
1209
+ }
1210
+ return "timeout";
1211
+ }
@@ -6,6 +6,8 @@ import {
6
6
  } from "../../operations/pair";
7
7
  import type { LockfileAssistant } from "../../lockfile-contract";
8
8
  import { dockerResourceNames } from "./retire";
9
+ import type { GuardianTokenData } from "../../guardian-token";
10
+ import { GuardianTokenFileSchema } from "../../guardian-token";
9
11
 
10
12
  /**
11
13
  * Pair by running the gateway's OWN CLI inside the container (docker
@@ -23,11 +25,11 @@ export function pairDocker(entry: LockfileAssistant): Promise<string>;
23
25
  export function pairDocker(
24
26
  entry: LockfileAssistant,
25
27
  device: PairDeviceIdentity,
26
- ): Promise<PairOperationResult>;
28
+ ): Promise<PairOperationResult<GuardianTokenData>>;
27
29
  export async function pairDocker(
28
30
  entry: LockfileAssistant,
29
31
  device?: PairDeviceIdentity,
30
- ): Promise<string | PairOperationResult> {
32
+ ): Promise<string | PairOperationResult<GuardianTokenData>> {
31
33
  const container = dockerResourceNames(entry.assistantId).gatewayContainer;
32
34
  const args = ["exec", container, "bun", "run", "gateway", "pairing", "mint"];
33
35
  if (device) {
@@ -45,7 +47,9 @@ export async function pairDocker(
45
47
  const stdout = await execOutput("docker", args, {
46
48
  timeoutMs: 30_000,
47
49
  });
48
- return device ? pairCliStdoutToResult(stdout) : stdout;
50
+ return device
51
+ ? pairCliStdoutToResult(stdout, GuardianTokenFileSchema)
52
+ : stdout;
49
53
  } catch (err) {
50
54
  if (!device) throw err;
51
55
  return {
@@ -230,19 +230,21 @@ async function startAssistantThenSidecars(
230
230
  await Promise.all([start("gateway"), start("credential-executor")]);
231
231
  }
232
232
 
233
- /** Start all three containers: the namespace owner first, sidecars together. */
234
- export async function startContainers(
235
- opts: {
236
- createOnly?: boolean;
237
- extraAssistantEnv?: Record<string, string>;
238
- extraGatewayEnv?: Record<string, string>;
239
- gatewayPort: number;
240
- imageTags: Record<ServiceName, string>;
241
- instanceName: string;
242
- res: ReturnType<typeof dockerResourceNames>;
243
- netnsContainer?: string;
244
- assistantCaCertPath?: string;
245
- },
233
+ /** The container bring-up options shared by start and create. */
234
+ type ServiceContainersOpts = {
235
+ extraAssistantEnv?: Record<string, string>;
236
+ extraGatewayEnv?: Record<string, string>;
237
+ gatewayPort: number;
238
+ imageTags: Record<ServiceName, string>;
239
+ instanceName: string;
240
+ res: ReturnType<typeof dockerResourceNames>;
241
+ netnsContainer?: string;
242
+ assistantCaCertPath?: string;
243
+ };
244
+
245
+ async function runServiceContainers(
246
+ opts: ServiceContainersOpts,
247
+ mode: "start" | "create",
246
248
  log: (msg: string) => void,
247
249
  ): Promise<void> {
248
250
  const runArgs = buildServiceRunArgs({
@@ -251,11 +253,34 @@ export async function startContainers(
251
253
  });
252
254
  await startAssistantThenSidecars(runArgs, async (service) => {
253
255
  const args = runArgs[service]();
254
- if (opts.createOnly) {
256
+ if (mode === "create") {
255
257
  args[0] = "create";
256
258
  args.splice(args.indexOf("-d"), 1);
257
259
  }
258
- log(`${opts.createOnly ? "Creating" : "Starting"} ${service} container...`);
260
+ log(
261
+ `${mode === "create" ? "Creating" : "Starting"} ${service} container...`,
262
+ );
259
263
  await exec("docker", args);
260
264
  });
261
265
  }
266
+
267
+ /** Start all three containers: the namespace owner first, sidecars together. */
268
+ export async function startContainers(
269
+ opts: ServiceContainersOpts,
270
+ log: (msg: string) => void,
271
+ ): Promise<void> {
272
+ return runServiceContainers(opts, "start", log);
273
+ }
274
+
275
+ /**
276
+ * Create all three containers WITHOUT starting them — the initialize-data
277
+ * half of a versioned restore: the caller installs the transferred archive
278
+ * into the created volumes, then wakes. Separate from `startContainers` so
279
+ * neither flow carries the other's mode.
280
+ */
281
+ export async function createContainers(
282
+ opts: ServiceContainersOpts,
283
+ log: (msg: string) => void,
284
+ ): Promise<void> {
285
+ return runServiceContainers(opts, "create", log);
286
+ }
@@ -11,6 +11,7 @@ import { wakeLocal } from "./wake";
11
11
  import { setStartupLogging } from "./common";
12
12
  import { withLocalHatchLock } from "./hatch-lock";
13
13
  import { applyHatchConfig, buildHatchConfigValues } from "./hatch-config";
14
+ import { waitForReady } from "../../daemon-readiness";
14
15
  import { generateInstanceName } from "../../naming";
15
16
  import { mkdirSync } from "node:fs";
16
17
  import { join } from "node:path";
@@ -159,6 +160,23 @@ export async function hatchLocal(params: {
159
160
  log(`🥚 Hatching local assistant: ${instanceName}`);
160
161
  log("");
161
162
 
163
+ // Wake only proves the PROCESSES are alive — the gateway's traffic gate
164
+ // stays closed while the daemon migrates, and a config apply or guardian
165
+ // lease that races it gets `503 {"status":"starting"}`. Wait for the
166
+ // assistant to answer ready (the same body-classified poll the docker
167
+ // hatch runs) before leasing and applying config.
168
+ if (!(await waitForReady(getGatewayUrl(entry)))) {
169
+ return {
170
+ ok: false,
171
+ status: 500,
172
+ error:
173
+ `Timed out waiting for assistant to become ready\n\n` +
174
+ `❌ The assistant is running but never reported ready.\n` +
175
+ ` Logs: ${join(resolveAssistantsDir(), instanceName, "logs")} and ${join(resolveLogDir(), "hatch.log")}`,
176
+ assistantId: instanceName,
177
+ };
178
+ }
179
+
162
180
  const hatchConfigValues = buildHatchConfigValues(configValues, provider);
163
181
 
164
182
  // Lease a guardian token so the desktop app can import it on first launch
@@ -6,6 +6,8 @@ import type {
6
6
  import { pairCliStdoutToResult } from "../../operations/pair";
7
7
  import type { LocalAssistant } from "../../lockfile-contract";
8
8
  import { gatewayCliInvocation } from "./common";
9
+ import type { GuardianTokenData } from "../../guardian-token";
10
+ import { GuardianTokenFileSchema } from "../../guardian-token";
9
11
 
10
12
  /**
11
13
  * Pair by running the gateway's OWN CLI on this host (local topology): the
@@ -24,11 +26,11 @@ export function pairLocal(entry: LocalAssistant): Promise<string>;
24
26
  export function pairLocal(
25
27
  entry: LocalAssistant,
26
28
  device: PairDeviceIdentity,
27
- ): Promise<PairOperationResult>;
29
+ ): Promise<PairOperationResult<GuardianTokenData>>;
28
30
  export async function pairLocal(
29
31
  entry: LocalAssistant,
30
32
  device?: PairDeviceIdentity,
31
- ): Promise<string | PairOperationResult> {
33
+ ): Promise<string | PairOperationResult<GuardianTokenData>> {
32
34
  const invocation = gatewayCliInvocation(entry);
33
35
  const args = [...invocation.args, "pairing", "mint"];
34
36
  if (device) {
@@ -48,7 +50,9 @@ export async function pairLocal(
48
50
  env: invocation.env,
49
51
  timeoutMs: 30_000,
50
52
  });
51
- return device ? pairCliStdoutToResult(stdout) : stdout;
53
+ return device
54
+ ? pairCliStdoutToResult(stdout, GuardianTokenFileSchema)
55
+ : stdout;
52
56
  } catch (err) {
53
57
  if (!device) throw err;
54
58
  return {
@@ -10,7 +10,7 @@ import { saveLockfileAssistant } from "./lockfile";
10
10
  import type { LockfileAssistant } from "./lockfile-contract";
11
11
  import { createBackup, pruneOldBackups, restoreBackup } from "./backup-ops";
12
12
  import { captureImageRefs } from "./remotes/docker/upgrade";
13
- import { wakeDocker } from "./remotes/docker/wake";
13
+ import { createContainers, wakeDocker } from "./remotes/docker/wake";
14
14
  import { pullImage, resolveImageRefs } from "./remotes/docker/hatch";
15
15
  import {
16
16
  getBuilderManagedEnvKeys,
@@ -683,7 +683,7 @@ export async function performDockerRollback(
683
683
  let ready = false;
684
684
  try {
685
685
  console.log("Creating stopped containers with the target version...");
686
- await startContainers(
686
+ await createContainers(
687
687
  {
688
688
  extraAssistantEnv,
689
689
  extraGatewayEnv,
@@ -691,7 +691,6 @@ export async function performDockerRollback(
691
691
  imageTags: targetImageTags,
692
692
  instanceName,
693
693
  res,
694
- createOnly: true,
695
694
  },
696
695
  (msg) => console.log(msg),
697
696
  );
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611142107.f5e00a2",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,3 +1,5 @@
1
+ import { z } from "zod";
2
+
1
3
  /**
2
4
  * Wire contracts for the remote-web pairing flow — the RFC 8628-style
3
5
  * device-code exchange that connects a browser (or the iOS app) to a
@@ -59,6 +61,16 @@ export interface RemoteWebPairingChallengeResponse {
59
61
  intervalSeconds: number;
60
62
  }
61
63
 
64
+ export const RemoteWebPairingChallengeResponseSchema = z.object({
65
+ deviceCode: z.string(),
66
+ userCode: z.string(),
67
+ verificationUri: z.string(),
68
+ publicBaseUrl: z.string(),
69
+ expiresAt: z.string(),
70
+ expiresInSeconds: z.number(),
71
+ intervalSeconds: z.number(),
72
+ }) satisfies z.ZodType<RemoteWebPairingChallengeResponse>;
73
+
62
74
  /** `POST /v1/remote-web/pairing-verification` request body. */
63
75
  export interface RemoteWebPairingVerificationRequest {
64
76
  /** The `userCode` from the challenge, entered/scanned on the host. */
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/shared",
3
- "version": "0.13.0-dev.202611142107.f5e00a2",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./index.ts",
@@ -207,28 +207,11 @@ function readPersistedDefault(): CadetEnvironment | undefined {
207
207
  }
208
208
 
209
209
  /**
210
- * The environment name every surface shares — the single resolution chain
211
- * local-mode hosts and the mobile config loader both ride:
212
- *
213
- * 1. `CADET_ENVIRONMENT` (explicit override, also inherited by the
214
- * hatch/retire child processes the CLI spawns), then
215
- * `VITE_ENVIRONMENT` (the build-time inlined var bundled surfaces bake)
216
- * 2. the release channel the running copy's version carries —
217
- * `__CADET_OWN_VERSION__`, which the entrypoints that know their
218
- * package root inject (the CLI's bin computes its git/local stamp,
219
- * the Electron builds define it at build time). A released `-dev.`
220
- * install resolves `dev` even on a machine that never wrote a
221
- * persisted default
222
- * 3. the persisted default written by pre-version-tied CLIs (old files
223
- * are still honored)
224
- * 4. `production`
225
- *
226
- * The version step is what keeps every released install from silently
227
- * reading production's state: the channel is decided by the release
228
- * pipeline, not by whatever default an older CLI happened to leave behind.
229
- * Names outside `CadetEnvironment` are ignored rather than returned: an
230
- * unrecognized value falls through to the next arm instead of leaking an
231
- * unkeyable string into `SEEDS` lookups.
210
+ * The environment name every surface shares: `CADET_ENVIRONMENT`, then
211
+ * `VITE_ENVIRONMENT`, then the release channel the copy's version carries
212
+ * (`__CADET_OWN_VERSION__`, defined at build time by hosts that bundle
213
+ * local-mode), then the persisted default written by pre-version-tied CLIs,
214
+ * then production.
232
215
  */
233
216
  export function resolveEnvironmentName(): CadetEnvironment {
234
217
  const env = processEnv();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202611142107.f5e00a2",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -78,11 +78,14 @@ const isRefresh = (url: string) => url.includes("/v1/guardian/refresh");
78
78
  function refreshResponse(): Response {
79
79
  return new Response(
80
80
  JSON.stringify({
81
+ guardianPrincipalId: "imported",
81
82
  accessToken: "new-acc",
82
- refreshToken: "new-ref",
83
83
  accessTokenExpiresAt: FUTURE,
84
+ refreshToken: "new-ref",
84
85
  refreshTokenExpiresAt: FUTURE,
85
- refreshAfter: "",
86
+ refreshAfter: FUTURE,
87
+ deviceId: "dev",
88
+ leasedAt: new Date().toISOString(),
86
89
  }),
87
90
  { status: 200, headers: { "content-type": "application/json" } },
88
91
  );
@@ -60,7 +60,18 @@ function stubRefresh(ok: boolean): {
60
60
  if (String(url).includes("/v1/guardian/refresh")) {
61
61
  calledUrl = String(url);
62
62
  return new Response(
63
- ok ? JSON.stringify({ accessToken: "new-acc" }) : "nope",
63
+ ok
64
+ ? JSON.stringify({
65
+ guardianPrincipalId: "imported",
66
+ accessToken: "new-acc",
67
+ accessTokenExpiresAt: Date.now() + 60 * 60 * 1000,
68
+ refreshToken: "new-ref",
69
+ refreshTokenExpiresAt: Date.now() + 60 * 60 * 1000,
70
+ refreshAfter: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
71
+ deviceId: "dev",
72
+ leasedAt: new Date().toISOString(),
73
+ })
74
+ : "nope",
64
75
  {
65
76
  status: ok ? 200 : 401,
66
77
  headers: { "content-type": "application/json" },