@mycadet/cli 0.13.0-dev.202611141959.760a53b → 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 (43) 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 +5 -3
  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/index.ts +1 -0
  23. package/node_modules/@mycadet/local-mode/src/operations/pair.ts +27 -7
  24. package/node_modules/@mycadet/local-mode/src/pair.ts +0 -1
  25. package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +75 -61
  26. package/node_modules/@mycadet/local-mode/src/remotes/docker/pair.ts +7 -3
  27. package/node_modules/@mycadet/local-mode/src/remotes/docker/wake.ts +40 -15
  28. package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +18 -0
  29. package/node_modules/@mycadet/local-mode/src/remotes/local/pair.ts +7 -3
  30. package/node_modules/@mycadet/local-mode/src/upgrade-lifecycle.ts +2 -3
  31. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  32. package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +12 -0
  33. package/node_modules/@mycadet/shared/package.json +1 -1
  34. package/node_modules/@mycadet/shared/seeds.ts +5 -22
  35. package/package.json +1 -1
  36. package/src/__tests__/assistant-client-refresh.test.ts +5 -2
  37. package/src/__tests__/client-tui-refresh.test.ts +12 -1
  38. package/src/__tests__/guardian-token.test.ts +57 -31
  39. package/src/__tests__/setup.test.ts +10 -6
  40. package/src/__tests__/tui-midsession-refresh.test.ts +12 -1
  41. package/src/commands/pair.ts +13 -11
  42. package/src/index.ts +1 -9
  43. package/src/lib/guardian-token.ts +16 -34
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611141959.760a53b",
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/avatar-manifest",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611141959.760a53b",
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.202611141959.760a53b",
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();
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@mycadet/local-mode",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142201.aad87f9",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
9
  "./contract": "./src/lockfile-contract.ts",
10
- "./teleport-backup-policy": "./src/teleport-backup-policy.ts"
10
+ "./teleport-backup-policy": "./src/teleport-backup-policy.ts",
11
+ "./guardian-contract": "./src/guardian-contract.ts"
11
12
  },
12
13
  "scripts": {
13
14
  "typecheck": "bunx tsc --noEmit",
@@ -72,7 +72,7 @@ describe("getGuardianAccessToken", () => {
72
72
  });
73
73
  });
74
74
 
75
- test("expired refresh token yields hatch/wake guidance by default", async () => {
75
+ test("expired refresh token yields the unified re-run guidance", async () => {
76
76
  saveGuardianToken(
77
77
  "asst-1",
78
78
  makeTokenData({
@@ -86,17 +86,17 @@ describe("getGuardianAccessToken", () => {
86
86
  expect(result).toEqual({
87
87
  ok: false,
88
88
  status: 401,
89
- error: "Guardian token expired. Re-run `cadet hatch` or `cadet wake`.",
89
+ error:
90
+ "Guardian token expired. Re-run `cadet hatch`, `cadet wake`, or `cadet pair`.",
90
91
  });
91
92
  });
92
93
 
93
- test("expired refresh token yields re-pair guidance for a paired entry", async () => {
94
+ test("expired refresh token yields the same guidance without the paired provenance", async () => {
94
95
  saveGuardianToken(
95
96
  "asst-1",
96
97
  makeTokenData({
97
98
  accessTokenExpiresAt: PAST,
98
99
  refreshTokenExpiresAt: PAST,
99
- pairedGatewayUrl: "https://gateway.example.com",
100
100
  }),
101
101
  );
102
102
 
@@ -106,7 +106,7 @@ describe("getGuardianAccessToken", () => {
106
106
  ok: false,
107
107
  status: 401,
108
108
  error:
109
- "Guardian token expired. Run `cadet pair` on the assistant's machine, then re-import it from the app's connect flow or with `cadet connect import`.",
109
+ "Guardian token expired. Re-run `cadet hatch`, `cadet wake`, or `cadet pair`.",
110
110
  });
111
111
  });
112
112
  });
@@ -33,10 +33,25 @@ let capturedApply: CapturedApply | undefined;
33
33
  // replaces the whole module record for every file that runs later in the
34
34
  // same bun test process.
35
35
  const actualLocalWake = await import("../remotes/local/wake");
36
- const wakeMock = mock(
37
- async (_entry: unknown, _opts?: { watch?: boolean }) =>
38
- ({ ok: true }) as never,
39
- );
36
+
37
+ // The readyz seam: hatch's readiness wait polls the entry's gateway port, so
38
+ // the wake stub brings up a real HTTP server that answers ready there — the
39
+ // same contract the actual gateway serves.
40
+ let readyzServer: ReturnType<typeof Bun.serve> | undefined;
41
+ const wakeMock = mock(async (entry: unknown) => {
42
+ const port = (entry as { port?: number }).port;
43
+ if (typeof port !== "number") throw new Error("no gateway port allocated");
44
+ readyzServer = Bun.serve({
45
+ port,
46
+ fetch: (request) => {
47
+ const url = new URL(request.url);
48
+ return Response.json(
49
+ url.pathname === "/readyz" ? { ready: true } : {},
50
+ );
51
+ },
52
+ });
53
+ return { ok: true } as never;
54
+ });
40
55
  mock.module("../remotes/local/wake", () => ({
41
56
  ...actualLocalWake,
42
57
  wakeLocal: wakeMock,
@@ -105,6 +120,8 @@ beforeEach(() => {
105
120
  });
106
121
 
107
122
  afterEach(() => {
123
+ readyzServer?.stop(true);
124
+ readyzServer = undefined;
108
125
  for (const [key, value] of saved) {
109
126
  if (value === undefined) Reflect.deleteProperty(process.env, key);
110
127
  else process.env[key] = value;
@@ -8,6 +8,7 @@ import {
8
8
  test,
9
9
  } from "bun:test";
10
10
  import type { LocalAssistant, LockfileAssistant } from "../lockfile-contract";
11
+ import type { GuardianTokenData } from "../guardian-token";
11
12
  import type {
12
13
  PairDeviceIdentity,
13
14
  PairOperationResult,
@@ -19,23 +20,35 @@ import type {
19
20
  const realLocalPair = { ...(await import("../remotes/local/pair")) };
20
21
  const realDockerPair = { ...(await import("../remotes/docker/pair")) };
21
22
 
23
+ /** A minimal valid GuardianTokenData — the router test cares about routing. */
24
+ const fakeToken = (origin: string): GuardianTokenData => ({
25
+ guardianPrincipalId: `guardian-${origin}`,
26
+ accessToken: `access-${origin}`,
27
+ accessTokenExpiresAt: 0,
28
+ refreshToken: `refresh-${origin}`,
29
+ refreshTokenExpiresAt: 0,
30
+ refreshAfter: "1970-01-01T00:00:00.000Z",
31
+ deviceId: "device-test",
32
+ leasedAt: "1970-01-01T00:00:00.000Z",
33
+ });
34
+
22
35
  const pairLocalMock = mock<
23
36
  (
24
37
  entry: LocalAssistant,
25
38
  device?: PairDeviceIdentity,
26
- ) => Promise<string | PairOperationResult>
39
+ ) => Promise<string | PairOperationResult<GuardianTokenData>>
27
40
  >(async () => ({
28
41
  ok: true,
29
- response: { token: "local" },
42
+ response: fakeToken("local"),
30
43
  }));
31
44
  const pairDockerMock = mock<
32
45
  (
33
46
  entry: LockfileAssistant,
34
47
  device?: PairDeviceIdentity,
35
- ) => Promise<string | PairOperationResult>
48
+ ) => Promise<string | PairOperationResult<GuardianTokenData>>
36
49
  >(async () => ({
37
50
  ok: true,
38
- response: { token: "docker" },
51
+ response: fakeToken("docker"),
39
52
  }));
40
53
 
41
54
  mock.module("../remotes/local/pair", () => ({
@@ -71,10 +84,10 @@ afterEach(() => {
71
84
 
72
85
  describe("pairDevice — the credential door routes by remote", () => {
73
86
  beforeEach(() => {
74
- pairLocalMock.mockResolvedValue({ ok: true, response: { token: "local" } });
87
+ pairLocalMock.mockResolvedValue({ ok: true, response: fakeToken("local") });
75
88
  pairDockerMock.mockResolvedValue({
76
89
  ok: true,
77
- response: { token: "docker" },
90
+ response: fakeToken("docker"),
78
91
  });
79
92
  });
80
93
 
@@ -90,7 +103,7 @@ describe("pairDevice — the credential door routes by remote", () => {
90
103
  const [entryArg, deviceArg] = pairLocalMock.mock.calls[0]!;
91
104
  expect(entryArg).toBe(entry);
92
105
  expect(deviceArg).toEqual(device);
93
- expect(result).toEqual({ ok: true, response: { token: "local" } });
106
+ expect(result).toEqual({ ok: true, response: fakeToken("local") });
94
107
  expect(pairDockerMock).not.toHaveBeenCalled();
95
108
  });
96
109
 
@@ -101,7 +114,7 @@ describe("pairDevice — the credential door routes by remote", () => {
101
114
  const [entryArg, deviceArg] = pairDockerMock.mock.calls[0]!;
102
115
  expect(entryArg).toBe(dockerEntry);
103
116
  expect(deviceArg).toEqual(device);
104
- expect(result).toEqual({ ok: true, response: { token: "docker" } });
117
+ expect(result).toEqual({ ok: true, response: fakeToken("docker") });
105
118
  expect(pairLocalMock).not.toHaveBeenCalled();
106
119
  });
107
120
 
@@ -273,7 +273,6 @@ describe("pairAssistant", () => {
273
273
  refreshTokenExpiresAt: 0,
274
274
  refreshAfter: "",
275
275
  deviceId: "dev-aaa",
276
- pairedGatewayUrl: "http://10.0.0.5:7830",
277
276
  });
278
277
  expect(new Date(leasedAt as string).toISOString()).toBe(leasedAt as string);
279
278
  expect(Object.keys(token)).toEqual([
@@ -285,7 +284,6 @@ describe("pairAssistant", () => {
285
284
  "refreshAfter",
286
285
  "deviceId",
287
286
  "leasedAt",
288
- "pairedGatewayUrl",
289
287
  ]);
290
288
 
291
289
  expect(fs.statSync(tokenPath).mode & 0o777).toBe(0o600);
@@ -1,5 +1,17 @@
1
1
  import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
  import type { DockerAssistant } from "../lockfile-contract";
3
+ import type { GuardianTokenData } from "../guardian-token";
4
+ /** A minimal valid guardian token payload — these tests exercise the door. */
5
+ const fakeToken = (token: string): GuardianTokenData => ({
6
+ guardianPrincipalId: "guardian-1",
7
+ accessToken: token,
8
+ accessTokenExpiresAt: 0,
9
+ refreshToken: "refresh-1",
10
+ refreshTokenExpiresAt: 0,
11
+ refreshAfter: "1970-01-01T00:00:00.000Z",
12
+ deviceId: "device-1",
13
+ leasedAt: "1970-01-01T00:00:00.000Z",
14
+ });
3
15
 
4
16
  // Snapshot the real modules before mocking so the module-scoped `afterAll`
5
17
  // below can restore them — bun runs every test file in one process with a
@@ -31,7 +43,7 @@ describe("pairDocker — the in-container gateway CLI is the docker presence pro
31
43
  });
32
44
 
33
45
  test("docker-execs `gateway pairing mint` with the device identity as flags", async () => {
34
- execOutputMock.mockResolvedValue(JSON.stringify({ token: "t" }));
46
+ execOutputMock.mockResolvedValue(JSON.stringify(fakeToken("t")));
35
47
  const result = await pairDocker(entry, {
36
48
  platform: "cli",
37
49
  deviceId: "device-1",
@@ -58,18 +70,16 @@ describe("pairDocker — the in-container gateway CLI is the docker presence pro
58
70
  "box",
59
71
  ]);
60
72
  expect(options?.timeoutMs).toBe(30_000);
61
- expect(result).toEqual({ ok: true, response: { token: "t" } });
73
+ expect(result).toEqual({ ok: true, response: fakeToken("t") });
62
74
  });
63
75
 
64
76
  test("parses the LAST stdout line of the mint", async () => {
65
- execOutputMock.mockResolvedValue(
66
- `warn\n${JSON.stringify({ token: "t", isNew: true })}`,
67
- );
77
+ execOutputMock.mockResolvedValue(`warn\n${JSON.stringify(fakeToken("t"))}`);
68
78
  const result = await pairDocker(entry, {
69
79
  platform: "cli",
70
80
  deviceId: "device-2",
71
81
  });
72
- expect(result).toEqual({ ok: true, response: { token: "t", isNew: true } });
82
+ expect(result).toEqual({ ok: true, response: fakeToken("t") });
73
83
  });
74
84
 
75
85
  test("an exec failure (container gone) comes back structured", async () => {
@@ -1,5 +1,18 @@
1
1
  import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
  import type { LocalAssistant } from "../lockfile-contract";
3
+ import type { GuardianTokenData } from "../guardian-token";
4
+
5
+ /** A minimal valid guardian token payload — these tests exercise the door. */
6
+ const fakeToken = (token: string): GuardianTokenData => ({
7
+ guardianPrincipalId: "guardian-1",
8
+ accessToken: token,
9
+ accessTokenExpiresAt: 0,
10
+ refreshToken: "refresh-1",
11
+ refreshTokenExpiresAt: 0,
12
+ refreshAfter: "1970-01-01T00:00:00.000Z",
13
+ deviceId: "device-1",
14
+ leasedAt: "1970-01-01T00:00:00.000Z",
15
+ });
3
16
 
4
17
  // Snapshot the real modules before mocking so the module-scoped `afterAll`
5
18
  // below can restore them — bun runs every test file in one process with a
@@ -53,7 +66,7 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
53
66
  });
54
67
 
55
68
  test("runs `gateway pairing mint` with the device identity as flags", async () => {
56
- execOutputMock.mockResolvedValue(JSON.stringify({ token: "t" }));
69
+ execOutputMock.mockResolvedValue(JSON.stringify(fakeToken("t")));
57
70
  const result = await pairLocal(entry, {
58
71
  platform: "cli",
59
72
  deviceId: "device-1",
@@ -77,11 +90,11 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
77
90
  expect(options?.cwd).toBe("/fake/state-root");
78
91
  expect(options?.env).toEqual({});
79
92
  expect(options?.timeoutMs).toBe(30_000);
80
- expect(result).toEqual({ ok: true, response: { token: "t" } });
93
+ expect(result).toEqual({ ok: true, response: fakeToken("t") });
81
94
  });
82
95
 
83
96
  test("omits the name flag when the device reports none", async () => {
84
- execOutputMock.mockResolvedValue(JSON.stringify({ token: "t" }));
97
+ execOutputMock.mockResolvedValue(JSON.stringify(fakeToken("t")));
85
98
  await pairLocal(entry, { platform: "cli", deviceId: "device-2" });
86
99
  expect(execOutputMock.mock.calls[0]![1]).toEqual([
87
100
  "run",
@@ -97,16 +110,13 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
97
110
 
98
111
  test("parses the LAST stdout line — earlier lines are warnings", async () => {
99
112
  execOutputMock.mockResolvedValue(
100
- `warning: cache cold\n${JSON.stringify({ token: "t", guardianId: "g" })}`,
113
+ `warning: cache cold\n${JSON.stringify(fakeToken("t"))}`,
101
114
  );
102
115
  const result = await pairLocal(entry, {
103
116
  platform: "cli",
104
117
  deviceId: "device-3",
105
118
  });
106
- expect(result).toEqual({
107
- ok: true,
108
- response: { token: "t", guardianId: "g" },
109
- });
119
+ expect(result).toEqual({ ok: true, response: fakeToken("t") });
110
120
  });
111
121
 
112
122
  test("an unparseable answer comes back structured", async () => {
@@ -20,7 +20,7 @@ import {
20
20
  stageRootArchive,
21
21
  STATE_ROOTS,
22
22
  } from "../root-backup";
23
- import { startContainers } from "../remotes/docker/wake";
23
+ import { createContainers } from "../remotes/docker/wake";
24
24
  import { sleepDocker } from "../remotes/docker/sleep";
25
25
  import { dockerResourceNames } from "../remotes/docker/retire";
26
26
  import type { LockfileAssistant } from "../lockfile-contract";
@@ -259,9 +259,8 @@ test("create-only provisioning creates every target container without starting s
259
259
  return { stdout: "created" };
260
260
  },
261
261
  );
262
- await startContainers(
262
+ await createContainers(
263
263
  {
264
- createOnly: true,
265
264
  gatewayPort: 7830,
266
265
  imageTags: {
267
266
  assistant: "assistant:target",
@@ -21,6 +21,7 @@ const save = spyOn(localMode, "saveLockfileAssistant");
21
21
  const restore = spyOn(backups, "restoreBackup");
22
22
  const sleep = spyOn(sleepDockerModule, "sleepDocker");
23
23
  const start = spyOn(dockerWake, "startContainers");
24
+ const create = spyOn(dockerWake, "createContainers");
24
25
  const fetch = spyOn(localMode, "loopbackSafeFetch");
25
26
  const res = localMode.dockerResourceNames("recovery");
26
27
  const entry: LockfileAssistant = {
@@ -54,6 +55,7 @@ beforeEach(() => {
54
55
  restore.mockReset();
55
56
  sleep.mockReset();
56
57
  start.mockReset();
58
+ create.mockReset();
57
59
  fetch.mockReset();
58
60
  restore.mockImplementation(async () => {
59
61
  events.push("restore-roots");
@@ -75,6 +77,7 @@ afterAll(() => {
75
77
  restore,
76
78
  sleep,
77
79
  start,
80
+ create,
78
81
  fetch,
79
82
  capture,
80
83
  images,
@@ -130,7 +133,7 @@ test("versioned restore installs roots into stopped target containers before fir
130
133
  await mockChildProcessSpawn((command, args) => {
131
134
  if (command === "docker" && args[0] === "inspect") {
132
135
  return {
133
- stdout: JSON.stringify(["ACTOR_TOKEN_SIGNING_KEY=" + "01".repeat(32)]),
136
+ stdout: JSON.stringify(["PATH=/usr/local/bin:/usr/bin"]),
134
137
  code: 0,
135
138
  pid: 4242,
136
139
  unref: () => {},
@@ -151,8 +154,7 @@ test("versioned restore installs roots into stopped target containers before fir
151
154
  "credential-executor": "ces:current",
152
155
  });
153
156
  pull.mockResolvedValue(undefined);
154
- start.mockImplementation(async (options) => {
155
- expect((options as { createOnly?: boolean }).createOnly).toBe(true);
157
+ create.mockImplementation(async () => {
156
158
  events.push("create-stopped-target");
157
159
  });
158
160
  wake.mockImplementation(async () => {
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The guardian credential contract — one Zod schema that is the single
3
+ * source of truth for the credential's shape on the wire and at rest:
4
+ * the gateway's pairing mint and device-bound refresh both answer with
5
+ * it, the lease parses with it, and the token file persists it.
6
+ *
7
+ * Kept in its own module, exported from the package as
8
+ * `./guardian-contract`, so the CLI can import the contract without
9
+ * pulling in the host I/O graph. It references no node built-ins and
10
+ * `zod` is its only import.
11
+ *
12
+ * MIRRORED in `gateway/src/guardian-contract.ts` (same names, same
13
+ * shape): the gateway can't depend on this package because local-mode
14
+ * carries operator-facing APIs the gateway must never see. The
15
+ * duplication is temporary — once the gateway client-generation
16
+ * workstream lands, the generated SDK types replace both hand-rolled
17
+ * copies. Delete the leftovers then.
18
+ */
19
+ import { z } from "zod";
20
+
21
+ export const GuardianTokenFileSchema = z.object({
22
+ guardianPrincipalId: z.string(),
23
+ accessToken: z.string(),
24
+ /** ISO date string or epoch-ms number as returned by the gateway. */
25
+ accessTokenExpiresAt: z.union([z.string(), z.number()]),
26
+ refreshToken: z.string(),
27
+ /** ISO date string or epoch-ms number as returned by the gateway. */
28
+ refreshTokenExpiresAt: z.union([z.string(), z.number()]),
29
+ refreshAfter: z.string(),
30
+ /** The paired device's id, echoed by the gateway so the binding persists. */
31
+ deviceId: z.string(),
32
+ /** ISO-8601 instant the credential was leased or rotated. */
33
+ leasedAt: z.string(),
34
+ });
35
+
36
+ export type GuardianTokenData = z.infer<typeof GuardianTokenFileSchema>;
@@ -25,25 +25,12 @@ import { resolveCliInvocation } from "./cli-invocation";
25
25
  const GUARDIAN_TOKEN_REFRESH_TIMEOUT_MS = 15_000;
26
26
  const guardianTokenRefreshes = new Map<string, Promise<TokenResult>>();
27
27
 
28
- /** The persisted shape of an assistant's guardian token file. */
29
- export const GuardianTokenFileSchema = z.object({
30
- guardianPrincipalId: z.string(),
31
- accessToken: z.string(),
32
- /** ISO date string or epoch-ms number as returned by the gateway. */
33
- accessTokenExpiresAt: z.union([z.string(), z.number()]),
34
- refreshToken: z.string(),
35
- /** ISO date string or epoch-ms number as returned by the gateway. */
36
- refreshTokenExpiresAt: z.union([z.string(), z.number()]),
37
- refreshAfter: z.string(),
38
- deviceId: z.string(),
39
- leasedAt: z.string(),
40
- /** Remote gateway bound to a credential imported through the pairing flow. */
41
- pairedGatewayUrl: z.string().optional(),
42
- });
28
+ import {
29
+ GuardianTokenFileSchema,
30
+ type GuardianTokenData,
31
+ } from "./guardian-contract";
43
32
 
44
- export interface GuardianTokenData extends z.infer<
45
- typeof GuardianTokenFileSchema
46
- > {}
33
+ export { GuardianTokenFileSchema, type GuardianTokenData };
47
34
 
48
35
  /**
49
36
  * Persist an assistant's guardian token where every host-seam reader resolves
@@ -344,9 +331,8 @@ export async function getGuardianAccessToken(
344
331
  return Promise.resolve({
345
332
  ok: false,
346
333
  status: 401,
347
- error: data.pairedGatewayUrl
348
- ? "Guardian token expired. Run `cadet pair` on the assistant's machine, then re-import it from the app's connect flow or with `cadet connect import`."
349
- : "Guardian token expired. Re-run `cadet hatch` or `cadet wake`.",
334
+ error:
335
+ "Guardian token expired. Re-run `cadet hatch`, `cadet wake`, or `cadet pair`.",
350
336
  });
351
337
  }
352
338
 
@@ -643,7 +629,8 @@ export async function leaseGuardianToken(
643
629
  });
644
630
  if (!paired.ok) throw new Error(paired.error);
645
631
 
646
- const tokenData = parseGuardianToken(paired.response);
632
+ // The pair door already zod-parsed the mint's stdout line.
633
+ const tokenData = paired.response;
647
634
 
648
635
  saveGuardianToken(assistantId, tokenData);
649
636
  return tokenData;
@@ -194,6 +194,7 @@ export {
194
194
 
195
195
  export { loopbackSafeFetch, isLoopbackUrl } from "./loopback-fetch";
196
196
  export {
197
+ pairCliStdoutToResult,
197
198
  pairDevice,
198
199
  type PairDeviceIdentity,
199
200
  type PairOperationResult,