@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
@@ -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));
@@ -46,7 +46,6 @@ export {
46
46
  renameLockfileAssistantIfPresent,
47
47
  stampLockfileAssistantOnboardedIfPresent,
48
48
  upsertLockfileAssistant,
49
- upsertRendererLockfileAssistant,
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,
@@ -229,7 +229,6 @@ 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
233
  signingKey: "hunter2",
235
234
  },
@@ -243,7 +242,6 @@ describe("parseLockfile", () => {
243
242
  daemonPort: 7778,
244
243
  runtimeVersion: "v0.8.13",
245
244
  runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
246
- qdrantPort: 7779,
247
245
  cesPort: 7780,
248
246
  signingKey: "hunter2",
249
247
  });
@@ -255,7 +253,6 @@ describe("parseLockfile", () => {
255
253
  daemonPort: 7778,
256
254
  runtimeVersion: "v0.8.13",
257
255
  runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
258
- qdrantPort: 7779,
259
256
  cesPort: 7780,
260
257
  });
261
258
  });
@@ -200,8 +200,6 @@ export const LocalAssistantResourcesSchema = z.object({
200
200
  instanceDir: z.string().optional(),
201
201
  gatewayPort: z.number(),
202
202
  daemonPort: z.number(),
203
- /** HTTP port for the Qdrant vector store (host-only). */
204
- qdrantPort: z.number().optional(),
205
203
  /** HTTP port for the CES (Claude Extension Server) (host-only). */
206
204
  cesPort: z.number().optional(),
207
205
  runtimeVersion: z.string().optional(),
@@ -10,7 +10,6 @@ import {
10
10
  stampLockfileAssistantOnboardedIfPresent,
11
11
  replaceCloudAssistants,
12
12
  upsertLockfileAssistant,
13
- upsertRendererLockfileAssistant,
14
13
  } from "./lockfile";
15
14
 
16
15
  let dir: string;
@@ -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({
@@ -292,7 +292,34 @@ 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
+ const existing = assistants[existingIdx]!;
296
+ let incoming: Record<string, unknown> = assistant;
297
+ const storedResources = existing.resources;
298
+ const incomingResources = incoming.resources;
299
+ if (
300
+ incomingResources !== undefined &&
301
+ typeof storedResources === "object" &&
302
+ storedResources !== null &&
303
+ "signingKey" in storedResources &&
304
+ typeof storedResources.signingKey === "string" &&
305
+ !(
306
+ typeof incomingResources === "object" &&
307
+ incomingResources !== null &&
308
+ "signingKey" in incomingResources &&
309
+ incomingResources.signingKey !== undefined
310
+ )
311
+ ) {
312
+ // The signing key is host custody: a save whose resources ride
313
+ // without one (the renderer's stripped view) never unsets it.
314
+ incoming = {
315
+ ...incoming,
316
+ resources: {
317
+ ...incomingResources,
318
+ signingKey: storedResources.signingKey,
319
+ },
320
+ };
321
+ }
322
+ assistants[existingIdx] = { ...existing, ...incoming };
296
323
  } else {
297
324
  assistants.push(assistant);
298
325
  }
@@ -306,53 +333,6 @@ export function upsertLockfileAssistant(
306
333
  return locked.ok ? locked.value : lockFailure(locked.error);
307
334
  }
308
335
 
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
336
  export function isActiveAssistant(
357
337
  lockfilePaths: string[],
358
338
  assistantId: string,
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.202610241003.f9cbe80",
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,
@@ -29,12 +29,12 @@ import {
29
29
  formatAssistantLookupError,
30
30
  getAssistantDisplayName,
31
31
  lookupAssistantByIdentifier,
32
- removeAssistantEntry,
32
+ removeLockfileAssistant,
33
33
  loadAllAssistants,
34
34
  resolveTargetAssistant,
35
- saveAssistantEntry,
35
+ saveLockfileAssistant,
36
36
  getActiveAssistant,
37
- type AssistantEntry,
37
+ type LockfileAssistant,
38
38
  } from "../lib/assistant-config.js";
39
39
 
40
40
  afterAll(() => {
@@ -52,8 +52,8 @@ function writeLockfile(data: unknown): void {
52
52
  const makeEntry = (
53
53
  id: string,
54
54
  runtimeUrl = "http://localhost:7821",
55
- extra?: Partial<AssistantEntry>,
56
- ): AssistantEntry => ({
55
+ extra?: Partial<LockfileAssistant>,
56
+ ): LockfileAssistant => ({
57
57
  assistantId: id,
58
58
  runtimeUrl,
59
59
  cloud: "local",
@@ -94,38 +94,38 @@ describe("assistant-config", () => {
94
94
  expect(loadAllAssistants()).toEqual([]);
95
95
  });
96
96
 
97
- test("saveAssistantEntry and loadAllAssistants round-trip", () => {
97
+ test("saveLockfileAssistant and loadAllAssistants round-trip", () => {
98
98
  const entry = makeEntry("test-1");
99
- saveAssistantEntry(entry);
99
+ saveLockfileAssistant(entry);
100
100
  const all = loadAllAssistants();
101
101
  expect(all).toHaveLength(1);
102
102
  expect(all[0].assistantId).toBe("test-1");
103
103
  });
104
104
 
105
- test("saveAssistantEntry writes under the advisory lock and cleans it up", () => {
106
- saveAssistantEntry(makeEntry("locked-1"));
105
+ test("saveLockfileAssistant writes under the advisory lock and cleans it up", () => {
106
+ saveLockfileAssistant(makeEntry("locked-1"));
107
107
  expect(loadAllAssistants()).toHaveLength(1);
108
108
  // The shared `${lockfilePath}.lock` key hosts contend on is released.
109
109
  expect(existsSync(join(testDir, "lockfile.json.lock"))).toBe(false);
110
110
  });
111
111
 
112
- test("saveAssistantEntry breaks a stale lock and still lands the write", () => {
112
+ test("saveLockfileAssistant breaks a stale lock and still lands the write", () => {
113
113
  const lockDir = join(testDir, "lockfile.json.lock");
114
114
  mkdirSync(lockDir);
115
115
  const past = new Date(Date.now() - 60_000);
116
116
  utimesSync(lockDir, past, past);
117
117
 
118
- saveAssistantEntry(makeEntry("stale-lock-1"));
118
+ saveLockfileAssistant(makeEntry("stale-lock-1"));
119
119
  expect(loadAllAssistants()).toHaveLength(1);
120
120
  expect(existsSync(lockDir)).toBe(false);
121
121
  });
122
122
 
123
- test("saveAssistantEntry fails fast without writing when another holder is fresh", () => {
123
+ test("saveLockfileAssistant fails fast without writing when another holder is fresh", () => {
124
124
  const lockDir = join(testDir, "lockfile.json.lock");
125
125
  mkdirSync(lockDir);
126
126
  try {
127
127
  const start = Date.now();
128
- expect(() => saveAssistantEntry(makeEntry("contended-1"))).toThrow(
128
+ expect(() => saveLockfileAssistant(makeEntry("contended-1"))).toThrow(
129
129
  /Timed out acquiring lockfile lock/,
130
130
  );
131
131
  expect(Date.now() - start).toBeLessThan(2_000);
@@ -221,42 +221,42 @@ describe("assistant-config", () => {
221
221
  expect(findAssistantByName("missing")).toBeNull();
222
222
  });
223
223
 
224
- test("removeAssistantEntry removes matching entry", () => {
224
+ test("removeLockfileAssistant removes matching entry", () => {
225
225
  writeLockfile({
226
226
  assistants: [makeEntry("a"), makeEntry("b"), makeEntry("c")],
227
227
  });
228
- removeAssistantEntry("b");
228
+ removeLockfileAssistant("b");
229
229
  const all = loadAllAssistants();
230
230
  expect(all).toHaveLength(2);
231
231
  expect(all.map((e) => e.assistantId)).toEqual(["a", "c"]);
232
232
  });
233
233
 
234
- test("removeAssistantEntry reassigns activeAssistant to remaining entry", () => {
234
+ test("removeLockfileAssistant reassigns activeAssistant to remaining entry", () => {
235
235
  writeLockfile({
236
236
  assistants: [makeEntry("a"), makeEntry("b")],
237
237
  activeAssistant: "a",
238
238
  });
239
- removeAssistantEntry("a");
239
+ removeLockfileAssistant("a");
240
240
  expect(getActiveAssistant()).toBe("b");
241
241
  expect(loadAllAssistants()).toHaveLength(1);
242
242
  });
243
243
 
244
- test("removeAssistantEntry clears activeAssistant when no entries remain", () => {
244
+ test("removeLockfileAssistant clears activeAssistant when no entries remain", () => {
245
245
  writeLockfile({
246
246
  assistants: [makeEntry("only")],
247
247
  activeAssistant: "only",
248
248
  });
249
- removeAssistantEntry("only");
249
+ removeLockfileAssistant("only");
250
250
  expect(getActiveAssistant()).toBeNull();
251
251
  expect(loadAllAssistants()).toHaveLength(0);
252
252
  });
253
253
 
254
- test("removeAssistantEntry preserves activeAssistant when removing a different entry", () => {
254
+ test("removeLockfileAssistant preserves activeAssistant when removing a different entry", () => {
255
255
  writeLockfile({
256
256
  assistants: [makeEntry("a"), makeEntry("b"), makeEntry("c")],
257
257
  activeAssistant: "a",
258
258
  });
259
- removeAssistantEntry("b");
259
+ removeLockfileAssistant("b");
260
260
  expect(getActiveAssistant()).toBe("a");
261
261
  expect(loadAllAssistants()).toHaveLength(2);
262
262
  });
@@ -297,17 +297,18 @@ describe("assistant-config", () => {
297
297
  expect(latest!.assistantId).toBe("with-date");
298
298
  });
299
299
 
300
- test("loadAllAssistants filters out entries missing required fields", () => {
300
+ test("loadAllAssistants returns every schema-valid entry", () => {
301
301
  writeLockfile({
302
302
  assistants: [
303
303
  makeEntry("valid"),
304
- { cloud: "local" }, // missing assistantId and runtimeUrl
305
- { assistantId: "no-url", cloud: "local" }, // missing runtimeUrl
304
+ { cloud: "local" }, // missing assistantId: the schema drops it
305
+ { assistantId: "no-url", cloud: "local" }, // valid: runtimeUrl is optional
306
306
  ],
307
307
  });
308
308
  const all = loadAllAssistants();
309
- expect(all).toHaveLength(1);
309
+ expect(all).toHaveLength(2);
310
310
  expect(all[0].assistantId).toBe("valid");
311
+ expect(all[1].assistantId).toBe("no-url");
311
312
  });
312
313
  });
313
314
 
@@ -326,7 +327,7 @@ describe("env-scoped lockfile and migration", () => {
326
327
  delete process.env.CADET_LOCKFILE_DIR;
327
328
  try {
328
329
  // WHEN we save an assistant entry (which triggers writeLockfile)
329
- saveAssistantEntry({
330
+ saveLockfileAssistant({
330
331
  assistantId: "dev-env-bot",
331
332
  runtimeUrl: "http://localhost:7830",
332
333
  cloud: "local",
@@ -372,7 +373,7 @@ describe("env-scoped lockfile and migration", () => {
372
373
  rmSync(join(testDir, "lockfile.json"), { force: true });
373
374
  rmSync(join(testDir, ".cadet.lock.json"), { force: true });
374
375
 
375
- saveAssistantEntry({
376
+ saveLockfileAssistant({
376
377
  assistantId: "prod-bot",
377
378
  runtimeUrl: "http://localhost:7830",
378
379
  cloud: "local",
@@ -17,7 +17,7 @@ import { stageRootArchive, STATE_ROOTS } from "../lib/root-backup.js";
17
17
  const directory = await mkdtemp(join(tmpdir(), "safety-root-backup-"));
18
18
  const root = join(directory, "instance");
19
19
  const backupDir = join(directory, "backups");
20
- const entry: config.AssistantEntry = {
20
+ const entry: config.LockfileAssistant & { runtimeUrl: string } = {
21
21
  assistantId: "alpha",
22
22
  cloud: "local",
23
23
  runtimeUrl: "http://127.0.0.1:1",
@@ -26,13 +26,14 @@ const entry: config.AssistantEntry = {
26
26
  daemonPort: 1,
27
27
  gatewayPort: 2,
28
28
  cesPort: 3,
29
- qdrantPort: 4,
30
29
  signingKey: "07".repeat(32),
31
30
  },
32
31
  };
33
32
  const lookup = spyOn(config, "findAssistantByName").mockReturnValue(entry);
34
33
  const location = spyOn(backups, "getBackupsDir").mockReturnValue(backupDir);
35
- const save = spyOn(config, "saveAssistantEntry").mockImplementation(() => {});
34
+ const save = spyOn(config, "saveLockfileAssistant").mockImplementation(
35
+ () => {},
36
+ );
36
37
  const tokens = spyOn(guardian, "loadGuardianToken").mockImplementation(() => {
37
38
  throw new Error("no guardian token access allowed");
38
39
  });
@@ -58,7 +58,7 @@ afterAll(() => {
58
58
 
59
59
  for (const topology of ["local", "docker"] as const) {
60
60
  test(`${topology} backup uses root storage without runtime auth`, async () => {
61
- const entry: config.AssistantEntry = {
61
+ const entry: config.LockfileAssistant = {
62
62
  assistantId: "test",
63
63
  cloud: topology,
64
64
  runtimeUrl: "http://127.0.0.1:1",
@@ -77,7 +77,7 @@ for (const topology of ["local", "docker"] as const) {
77
77
  }
78
78
 
79
79
  test("cloud backup calls the cloud backup API with session authentication", async () => {
80
- const entry: config.AssistantEntry = {
80
+ const entry: config.LockfileAssistant = {
81
81
  assistantId: "cloud-test",
82
82
  cloud: "cloud",
83
83
  runtimeUrl: "https://cloud.mycadet.ai",
@@ -14,7 +14,7 @@ const ORIGINAL_LOCKFILE_DIR = process.env.CADET_LOCKFILE_DIR;
14
14
  const ORIGINAL_FETCH = globalThis.fetch;
15
15
 
16
16
  import { resolveFreshBearerToken } from "../commands/client.js";
17
- import { saveAssistantEntry } from "../lib/assistant-config.js";
17
+ import { saveLockfileAssistant } from "../lib/assistant-config.js";
18
18
  import { saveGuardianToken } from "../lib/guardian-token.js";
19
19
 
20
20
  const RUNTIME = "https://gw.example.com";
@@ -26,7 +26,7 @@ const future = () => new Date(Date.now() + 60 * 60 * 1000).toISOString();
26
26
  * The paired shape is a loopback-cloud entry whose runtimeUrl points
27
27
  * off-machine — paired-ness derives from it, no stored flag. */
28
28
  function seedEntry(): void {
29
- saveAssistantEntry({
29
+ saveLockfileAssistant({
30
30
  assistantId: "px",
31
31
  name: "Paired",
32
32
  runtimeUrl: RUNTIME,
@@ -80,7 +80,7 @@ describe("resolveFreshBearerToken", () => {
80
80
  beforeEach(() => {
81
81
  tempHome = mkdtempSync(join(tmpdir(), "client-tui-refresh-test-"));
82
82
  process.env.XDG_CONFIG_HOME = tempHome;
83
- // Isolate the lockfile too — saveAssistantEntry writes the prod lockfile
83
+ // Isolate the lockfile too — saveLockfileAssistant writes the prod lockfile
84
84
  // (~/.cadet.lock.json) unless CADET_LOCKFILE_DIR is set.
85
85
  process.env.CADET_LOCKFILE_DIR = tempHome;
86
86
  delete process.env.CADET_ENVIRONMENT; // prod config dir
@@ -25,7 +25,7 @@ const ORIGINAL_ARGV = [...process.argv];
25
25
  import { connectImport } from "../commands/connect/import.js";
26
26
  import {
27
27
  findAssistantByName,
28
- saveAssistantEntry,
28
+ saveLockfileAssistant,
29
29
  } from "../lib/assistant-config.js";
30
30
  import { z } from "zod";
31
31
  import { loadGuardianToken } from "../lib/guardian-token.js";
@@ -53,6 +53,7 @@ function challengeBody(overrides: Record<string, unknown> = {}) {
53
53
  deviceCode: "dev-code",
54
54
  userCode: "ABCD-EFGH",
55
55
  verificationUri: `${HOST}/assistant/pair`,
56
+ publicBaseUrl: HOST,
56
57
  expiresAt: new Date(Date.now() + 600_000).toISOString(),
57
58
  expiresInSeconds: 600,
58
59
  intervalSeconds: POLL_INTERVAL_SECONDS,
@@ -265,7 +266,7 @@ describe("connect import", () => {
265
266
  TOKEN_URL,
266
267
  TOKEN_URL,
267
268
  ]);
268
- expect(calls[0].body).toEqual({ publicBaseUrl: HOST });
269
+ expect(calls[0].body).toEqual({});
269
270
  expect(calls[1].body.platform).toBe("cli");
270
271
 
271
272
  // One pending poll, waited out at exactly the cadence the gateway named.
@@ -590,57 +591,8 @@ describe("connect import", () => {
590
591
  expect(findAssistantByName("guarded-box")).toBeNull();
591
592
  });
592
593
 
593
- test("re-pairing the same host with no --name updates one entry", async () => {
594
- const outcomes: string[] = [];
595
- const ids: string[] = [];
596
- for (const token of ["tok1", "tok2"]) {
597
- process.argv = ["bun", "cadet", "connect", "import", PAIRING_LINK];
598
- stubFetch(() => jsonResponse(approvedBody({ accessToken: token })));
599
- const { logs, restore } = captureLogs();
600
- try {
601
- await connectImport();
602
- } finally {
603
- restore();
604
- }
605
- const match = logs.join("\n").match(/(\w+) paired assistant '([^']+)'/);
606
- expect(match).not.toBeNull();
607
- outcomes.push(match![1]);
608
- ids.push(match![2]);
609
- }
610
-
611
- // The default id keys on the assistant's address, which survives the fresh
612
- // device id every attempt mints, so the second pairing replaces the first
613
- // rather than stranding it in the lockfile.
614
- expect(ids[0]).toBe(ids[1]);
615
- expect(ids[0]).not.toContain("/");
616
- expect(outcomes).toEqual(["Imported", "Updated"]);
617
- expect(loadGuardianToken(ids[0])?.accessToken).toBe("tok2");
618
- });
619
-
620
- test("re-importing under the same --name updates in place", async () => {
621
- for (const token of ["t1", "t2"]) {
622
- process.argv = [
623
- "bun",
624
- "cadet",
625
- "connect",
626
- "import",
627
- PAIRING_LINK,
628
- "--name",
629
- "reused",
630
- ];
631
- stubFetch(() => jsonResponse(approvedBody({ accessToken: token })));
632
- const { restore } = captureLogs();
633
- try {
634
- await connectImport();
635
- } finally {
636
- restore();
637
- }
638
- }
639
- expect(loadGuardianToken("reused")?.accessToken).toBe("t2");
640
- });
641
-
642
594
  test("does not overwrite an existing non-paired assistant", async () => {
643
- saveAssistantEntry({
595
+ saveLockfileAssistant({
644
596
  assistantId: "desk",
645
597
  name: "Desk",
646
598
  runtimeUrl: "http://127.0.0.1:7830",
@@ -61,7 +61,7 @@ const LOCAL_ENTRY = {
61
61
  cloudAssistantId: "11111111-2222-3333-4444-555555555555",
62
62
  cloudBaseUrl: "https://cloud.mycadet.ai",
63
63
  cloudOrganizationId: "org-1",
64
- } satisfies assistantConfig.AssistantEntry;
64
+ } satisfies assistantConfig.LockfileAssistant;
65
65
 
66
66
  let originalFetch: typeof globalThis.fetch;
67
67
  let originalExit: typeof process.exit;
@@ -28,7 +28,7 @@ import { createHash } from "node:crypto";
28
28
 
29
29
  import * as stepRunner from "../lib/step-runner.js";
30
30
  import { devices } from "../commands/devices.js";
31
- import { saveAssistantEntry } from "../lib/assistant-config.js";
31
+ import { saveLockfileAssistant } from "../lib/assistant-config.js";
32
32
  import { computeDeviceId } from "../lib/guardian-token.js";
33
33
 
34
34
  interface FetchCall {
@@ -104,7 +104,7 @@ describe("cadet devices", () => {
104
104
  });
105
105
 
106
106
  test("Docker devices list and revoke execute inside the gateway without a host port", async () => {
107
- saveAssistantEntry({
107
+ saveLockfileAssistant({
108
108
  assistantId: "docker-fixture",
109
109
  cloud: "docker",
110
110
  runtimeUrl: "https://tunnel.example",
@@ -146,7 +146,7 @@ describe("cadet devices", () => {
146
146
  });
147
147
 
148
148
  test("Docker gateway output rejects malformed status and body fields", async () => {
149
- saveAssistantEntry({
149
+ saveLockfileAssistant({
150
150
  assistantId: "docker-invalid",
151
151
  cloud: "docker",
152
152
  runtimeUrl: "https://tunnel.example",
@@ -179,7 +179,7 @@ describe("cadet devices", () => {
179
179
  });
180
180
 
181
181
  function seedLocal(id: string, gatewayPort = 7830): void {
182
- saveAssistantEntry({
182
+ saveLockfileAssistant({
183
183
  assistantId: id,
184
184
  name: id,
185
185
  runtimeUrl: "http://127.0.0.1:7830",
@@ -188,7 +188,6 @@ describe("cadet devices", () => {
188
188
  instanceDir: testDir,
189
189
  gatewayPort,
190
190
  daemonPort: 8501,
191
- qdrantPort: 9001,
192
191
  cesPort: 9002,
193
192
  },
194
193
  });
@@ -427,7 +426,7 @@ describe("cadet devices", () => {
427
426
  });
428
427
 
429
428
  test("host-gates a paired connection (points to the host)", async () => {
430
- saveAssistantEntry({
429
+ saveLockfileAssistant({
431
430
  assistantId: "paired-box",
432
431
  name: "Paired Box",
433
432
  runtimeUrl: "http://10.0.0.9:7830",