@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.
- package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +0 -4
- package/node_modules/@mycadet/local-mode/src/index.ts +6 -2
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -3
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +0 -31
- package/node_modules/@mycadet/local-mode/src/lockfile.ts +28 -48
- package/package.json +1 -1
- package/src/__tests__/app-command.test.ts +2 -2
- package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
- package/src/__tests__/assistant-client-refresh.test.ts +2 -2
- package/src/__tests__/assistant-config.test.ts +28 -27
- package/src/__tests__/backup-ops.test.ts +4 -3
- package/src/__tests__/backup.test.ts +2 -2
- package/src/__tests__/client-tui-refresh.test.ts +3 -3
- package/src/__tests__/connect-import.test.ts +4 -52
- package/src/__tests__/debug.test.ts +1 -1
- package/src/__tests__/devices.test.ts +5 -6
- package/src/__tests__/gateway-token.test.ts +3 -3
- package/src/__tests__/helpers/lockfile-entry.ts +37 -0
- package/src/__tests__/host-teleport-docker.test.ts +2 -2
- package/src/__tests__/host-teleport.test.ts +15 -15
- package/src/__tests__/local-runtime-version.test.ts +4 -2
- package/src/__tests__/multi-local.test.ts +14 -25
- package/src/__tests__/nginx-ingress.test.ts +73 -5
- package/src/__tests__/orphan-detection.test.ts +13 -12
- package/src/__tests__/ps-cloud-status.test.ts +9 -9
- package/src/__tests__/restore.test.ts +32 -28
- package/src/__tests__/retire-local.test.ts +25 -29
- package/src/__tests__/retire.test.ts +33 -32
- package/src/__tests__/root-backup-docker.test.ts +2 -2
- package/src/__tests__/root-backup.test.ts +2 -3
- package/src/__tests__/root-restore-command.test.ts +2 -2
- package/src/__tests__/setup.test.ts +2 -5
- package/src/__tests__/signing-key-continuity.test.ts +2 -93
- package/src/__tests__/sleep.test.ts +13 -6
- package/src/__tests__/teleport-backup.test.ts +8 -2
- package/src/__tests__/teleport.test.ts +1 -1
- package/src/__tests__/tui-midsession-refresh.test.ts +4 -23
- package/src/__tests__/tunnel-stop.test.ts +2 -3
- package/src/__tests__/tunnel.test.ts +27 -16
- package/src/__tests__/uninstall.test.ts +31 -28
- package/src/__tests__/upgrade-local.test.ts +29 -15
- package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
- package/src/__tests__/use.test.ts +16 -24
- package/src/__tests__/wake-error.test.ts +0 -1
- package/src/__tests__/wake.test.ts +22 -24
- package/src/commands/client.ts +5 -5
- package/src/commands/completions.test.ts +2 -2
- package/src/commands/debug.ts +13 -5
- package/src/commands/devices.ts +5 -5
- package/src/commands/gateway/token.ts +4 -4
- package/src/commands/hatch.ts +2 -2
- package/src/commands/login.ts +2 -2
- package/src/commands/logs.ts +4 -4
- package/src/commands/pair.ts +5 -5
- package/src/commands/ps.ts +23 -17
- package/src/commands/restore.ts +32 -20
- package/src/commands/retire.ts +6 -6
- package/src/commands/sleep.ts +117 -96
- package/src/commands/uninstall.ts +6 -4
- package/src/commands/upgrade.ts +200 -140
- package/src/commands/wake.ts +93 -93
- package/src/lib/__tests__/local-gateway-cli.test.ts +3 -3
- package/src/lib/__tests__/runtime-url.test.ts +1 -15
- package/src/lib/assistant-client.ts +5 -2
- package/src/lib/assistant-config.ts +43 -81
- package/src/lib/cloud-login.ts +12 -6
- package/src/lib/constants.ts +0 -1
- package/src/lib/docker.ts +11 -11
- package/src/lib/exec-apple-container.ts +2 -2
- package/src/lib/hatch-local.ts +12 -6
- package/src/lib/health-check.ts +123 -109
- package/src/lib/host-teleport.ts +31 -23
- package/src/lib/ingress-config.ts +2 -2
- package/src/lib/live-voice/connection.ts +2 -2
- package/src/lib/local.ts +76 -48
- package/src/lib/nginx-ingress.ts +41 -10
- package/src/lib/orphan-detection.ts +4 -3
- package/src/lib/retire-apple-container.ts +2 -2
- package/src/lib/retire-local.ts +11 -5
- package/src/lib/root-backup.ts +35 -21
- package/src/lib/runtime-url.ts +4 -4
- package/src/lib/ssh-apple-container.ts +2 -2
- package/src/lib/sync-cloud-assistants.ts +5 -5
- package/src/lib/teleport-backup.ts +15 -13
- package/src/lib/tunnel.ts +6 -6
- package/src/lib/upgrade-lifecycle.ts +36 -30
|
@@ -23,7 +23,7 @@ import * as nginxIngress from "../lib/nginx-ingress.js";
|
|
|
23
23
|
import * as ngrok from "../lib/tunnels/ngrok.js";
|
|
24
24
|
import * as processLib from "../lib/process.js";
|
|
25
25
|
import * as portAllocator from "../lib/port-allocator.js";
|
|
26
|
-
import type {
|
|
26
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
27
27
|
import { makeGuardianTokenData } from "./helpers/guardian-token.js";
|
|
28
28
|
|
|
29
29
|
const realAssistantConfig = { ...assistantConfig };
|
|
@@ -42,11 +42,11 @@ const loadAllAssistantsMock = mock<typeof assistantConfig.loadAllAssistants>(
|
|
|
42
42
|
const loadAllAssistantsAcrossEnvsMock = mock<
|
|
43
43
|
typeof assistantConfig.loadAllAssistantsAcrossEnvs
|
|
44
44
|
>(() => []);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
);
|
|
45
|
+
const saveLockfileAssistantMock = mock<
|
|
46
|
+
typeof assistantConfig.saveLockfileAssistant
|
|
47
|
+
>(() => {});
|
|
48
48
|
const getDaemonPidPathMock = mock<typeof assistantConfig.getDaemonPidPath>(
|
|
49
|
-
(resources) => join(resources
|
|
49
|
+
(resources) => join(resources?.instanceDir ?? "missing", "daemon.pid"),
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
mock.module("../lib/assistant-config.js", () => ({
|
|
@@ -54,7 +54,7 @@ mock.module("../lib/assistant-config.js", () => ({
|
|
|
54
54
|
resolveTargetAssistant: resolveTargetAssistantMock,
|
|
55
55
|
loadAllAssistants: loadAllAssistantsMock,
|
|
56
56
|
loadAllAssistantsAcrossEnvs: loadAllAssistantsAcrossEnvsMock,
|
|
57
|
-
|
|
57
|
+
saveLockfileAssistant: saveLockfileAssistantMock,
|
|
58
58
|
getDaemonPidPath: getDaemonPidPathMock,
|
|
59
59
|
}));
|
|
60
60
|
|
|
@@ -222,9 +222,9 @@ let originalArgv: string[];
|
|
|
222
222
|
let logSpy: ReturnType<typeof spyOn>;
|
|
223
223
|
let warnSpy: ReturnType<typeof spyOn>;
|
|
224
224
|
let errorSpy: ReturnType<typeof spyOn>;
|
|
225
|
-
let localEntry:
|
|
225
|
+
let localEntry: LockfileAssistant;
|
|
226
226
|
|
|
227
|
-
function makeLocalEntry():
|
|
227
|
+
function makeLocalEntry(): LockfileAssistant {
|
|
228
228
|
tempDir = mkdtempSync(join(tmpdir(), "cadet-wake-test-"));
|
|
229
229
|
return {
|
|
230
230
|
assistantId: "local-assistant",
|
|
@@ -234,7 +234,6 @@ function makeLocalEntry(): AssistantEntry {
|
|
|
234
234
|
instanceDir: tempDir,
|
|
235
235
|
daemonPort: 7821,
|
|
236
236
|
gatewayPort: 7830,
|
|
237
|
-
qdrantPort: 6333,
|
|
238
237
|
cesPort: 7822,
|
|
239
238
|
signingKey: "ab".repeat(32),
|
|
240
239
|
},
|
|
@@ -256,10 +255,10 @@ beforeEach(() => {
|
|
|
256
255
|
loadAllAssistantsMock.mockReturnValue([]);
|
|
257
256
|
loadAllAssistantsAcrossEnvsMock.mockReset();
|
|
258
257
|
loadAllAssistantsAcrossEnvsMock.mockReturnValue([]);
|
|
259
|
-
|
|
258
|
+
saveLockfileAssistantMock.mockReset();
|
|
260
259
|
getDaemonPidPathMock.mockReset();
|
|
261
260
|
getDaemonPidPathMock.mockImplementation((resources) =>
|
|
262
|
-
join(resources
|
|
261
|
+
join(resources?.instanceDir ?? "missing", "daemon.pid"),
|
|
263
262
|
);
|
|
264
263
|
resolveProcessStateMock.mockReset();
|
|
265
264
|
resolveProcessStateMock.mockImplementation(
|
|
@@ -353,7 +352,7 @@ describe("cadet wake", () => {
|
|
|
353
352
|
expect(startGatewayMock).not.toHaveBeenCalled();
|
|
354
353
|
expect(generateLocalSigningKeyMock).not.toHaveBeenCalled();
|
|
355
354
|
expect(resetGuardianBootstrapMock).not.toHaveBeenCalled();
|
|
356
|
-
expect(
|
|
355
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
357
356
|
});
|
|
358
357
|
|
|
359
358
|
test("recovers the existing deprecated key before process startup", async () => {
|
|
@@ -368,7 +367,7 @@ describe("cadet wake", () => {
|
|
|
368
367
|
process.argv = ["bun", "cadet", "wake", "local-assistant"];
|
|
369
368
|
resolveProcessStateMock.mockImplementation(async () => {
|
|
370
369
|
expect(localEntry.resources!.signingKey).toBe("cd".repeat(32));
|
|
371
|
-
expect(
|
|
370
|
+
expect(saveLockfileAssistantMock).toHaveBeenCalled();
|
|
372
371
|
return { status: "needs_start", pid: null };
|
|
373
372
|
});
|
|
374
373
|
isProcessAliveMock.mockReturnValue({ alive: true, pid: 123 });
|
|
@@ -404,7 +403,7 @@ describe("cadet wake", () => {
|
|
|
404
403
|
await expect(wake()).rejects.toThrow("signing key conflict");
|
|
405
404
|
expect(resolveProcessStateMock).not.toHaveBeenCalled();
|
|
406
405
|
expect(stopProcessByPidFileMock).not.toHaveBeenCalled();
|
|
407
|
-
expect(
|
|
406
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
408
407
|
});
|
|
409
408
|
|
|
410
409
|
for (const failure of [
|
|
@@ -445,7 +444,7 @@ describe("cadet wake", () => {
|
|
|
445
444
|
const replacement = "ef".repeat(32);
|
|
446
445
|
generateLocalSigningKeyMock.mockReturnValue(replacement);
|
|
447
446
|
resolveProcessStateMock.mockImplementation(async () => {
|
|
448
|
-
expect(
|
|
447
|
+
expect(saveLockfileAssistantMock).toHaveBeenCalled();
|
|
449
448
|
expect(stopProcessByPidFileMock).toHaveBeenCalledTimes(2);
|
|
450
449
|
return { status: "needs_start", pid: null };
|
|
451
450
|
});
|
|
@@ -512,7 +511,7 @@ describe("cadet wake", () => {
|
|
|
512
511
|
stopProcessByPidFileMock.mockResolvedValue(false);
|
|
513
512
|
isProcessAliveMock.mockReturnValue({ alive: true, pid: 123 });
|
|
514
513
|
await expect(wake()).rejects.toThrow("could not be stopped");
|
|
515
|
-
expect(
|
|
514
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
516
515
|
expect(startLocalDaemonMock).not.toHaveBeenCalled();
|
|
517
516
|
expect(startGatewayMock).not.toHaveBeenCalled();
|
|
518
517
|
expect(leaseGuardianTokenMock).not.toHaveBeenCalled();
|
|
@@ -553,7 +552,7 @@ describe("cadet wake", () => {
|
|
|
553
552
|
pid: null,
|
|
554
553
|
});
|
|
555
554
|
startLocalDaemonMock.mockImplementation(async () => {
|
|
556
|
-
expect(
|
|
555
|
+
expect(saveLockfileAssistantMock).toHaveBeenCalled();
|
|
557
556
|
isProcessAliveMock.mockReturnValue({ alive: true, pid: 123 });
|
|
558
557
|
});
|
|
559
558
|
try {
|
|
@@ -561,7 +560,7 @@ describe("cadet wake", () => {
|
|
|
561
560
|
`could not confirm that ${label} port ${port} is free`,
|
|
562
561
|
);
|
|
563
562
|
expect(localEntry.resources!.signingKey).toBeUndefined();
|
|
564
|
-
expect(
|
|
563
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
565
564
|
expect(startLocalDaemonMock).not.toHaveBeenCalled();
|
|
566
565
|
expect(startGatewayMock).not.toHaveBeenCalled();
|
|
567
566
|
expect(leaseGuardianTokenMock).not.toHaveBeenCalled();
|
|
@@ -598,7 +597,7 @@ describe("cadet wake", () => {
|
|
|
598
597
|
findOpenPortMock.mockRejectedValue(new Error("EPERM"));
|
|
599
598
|
await expect(wake()).rejects.toThrow("no replacement key was saved");
|
|
600
599
|
expect(localEntry.resources!.signingKey).toBeUndefined();
|
|
601
|
-
expect(
|
|
600
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
602
601
|
expect(startLocalDaemonMock).not.toHaveBeenCalled();
|
|
603
602
|
expect(startGatewayMock).not.toHaveBeenCalled();
|
|
604
603
|
expect(leaseGuardianTokenMock).not.toHaveBeenCalled();
|
|
@@ -613,7 +612,7 @@ describe("cadet wake", () => {
|
|
|
613
612
|
"local-assistant",
|
|
614
613
|
"--repair-guardian",
|
|
615
614
|
];
|
|
616
|
-
|
|
615
|
+
saveLockfileAssistantMock.mockImplementation(() => {
|
|
617
616
|
throw new Error("registry write failed");
|
|
618
617
|
});
|
|
619
618
|
await expect(wake()).rejects.toThrow("registry write failed");
|
|
@@ -625,7 +624,7 @@ describe("cadet wake", () => {
|
|
|
625
624
|
test("restarts a running gateway without watch mode when backfilling the bootstrap secret", async () => {
|
|
626
625
|
await wake();
|
|
627
626
|
|
|
628
|
-
expect(
|
|
627
|
+
expect(saveLockfileAssistantMock).toHaveBeenCalledWith(
|
|
629
628
|
expect.objectContaining({
|
|
630
629
|
guardianBootstrapSecret: "generated-bootstrap-secret",
|
|
631
630
|
}),
|
|
@@ -1607,7 +1606,7 @@ describe("cadet wake — app server restore", () => {
|
|
|
1607
1606
|
function makeAllEntry(
|
|
1608
1607
|
assistantId: string,
|
|
1609
1608
|
instanceDir: string,
|
|
1610
|
-
):
|
|
1609
|
+
): LockfileAssistant {
|
|
1611
1610
|
return {
|
|
1612
1611
|
assistantId,
|
|
1613
1612
|
runtimeUrl: "http://127.0.0.1:7830",
|
|
@@ -1616,14 +1615,13 @@ describe("cadet wake — app server restore", () => {
|
|
|
1616
1615
|
instanceDir,
|
|
1617
1616
|
daemonPort: 7821,
|
|
1618
1617
|
gatewayPort: 7830,
|
|
1619
|
-
qdrantPort: 6333,
|
|
1620
1618
|
cesPort: 7822,
|
|
1621
1619
|
signingKey: "ab".repeat(32),
|
|
1622
1620
|
},
|
|
1623
1621
|
};
|
|
1624
1622
|
}
|
|
1625
1623
|
|
|
1626
|
-
function makeAllEntries():
|
|
1624
|
+
function makeAllEntries(): LockfileAssistant[] {
|
|
1627
1625
|
mkdirSync(join(tempDir, "instance-1"), { recursive: true });
|
|
1628
1626
|
mkdirSync(join(tempDir, "instance-2"), { recursive: true });
|
|
1629
1627
|
return [
|
package/src/commands/client.ts
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
lookupAssistantByIdentifier,
|
|
10
10
|
resolveAssistant,
|
|
11
11
|
resolveConversationKey,
|
|
12
|
-
|
|
13
|
-
type
|
|
12
|
+
saveLockfileAssistant,
|
|
13
|
+
type LockfileAssistant,
|
|
14
14
|
} from "../lib/assistant-config";
|
|
15
15
|
import { GATEWAY_PORT } from "../lib/constants";
|
|
16
16
|
import {
|
|
@@ -63,7 +63,7 @@ function collapseHomeForDisplay(dir: string): string {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** The assistant's data root (from the lockfile), for the TUI details panel. */
|
|
66
|
-
function readWorkspaceRoot(entry:
|
|
66
|
+
function readWorkspaceRoot(entry: LockfileAssistant | null): string | undefined {
|
|
67
67
|
const instanceDir = entry?.resources?.instanceDir;
|
|
68
68
|
return instanceDir ? collapseHomeForDisplay(instanceDir) : undefined;
|
|
69
69
|
}
|
|
@@ -99,7 +99,7 @@ export function parseArgs(): ParsedArgs {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
let entry:
|
|
102
|
+
let entry: LockfileAssistant | null = null;
|
|
103
103
|
if (positionalName) {
|
|
104
104
|
const result = lookupAssistantByIdentifier(positionalName);
|
|
105
105
|
if (result.status !== "found") {
|
|
@@ -250,7 +250,7 @@ async function maybeHydrateCloudAssistantName(
|
|
|
250
250
|
|
|
251
251
|
const entry = findAssistantByName(assistantId);
|
|
252
252
|
if (entry && entry.name !== hydratedName) {
|
|
253
|
-
|
|
253
|
+
saveLockfileAssistant({
|
|
254
254
|
...entry,
|
|
255
255
|
name: hydratedName,
|
|
256
256
|
});
|
|
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync } from "fs";
|
|
|
3
3
|
import { tmpdir } from "os";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { saveLockfileAssistant } from "../lib/assistant-config.js";
|
|
7
7
|
import { completeCadet } from "./completions.js";
|
|
8
8
|
|
|
9
9
|
const COMMAND_NAMES = [
|
|
@@ -38,7 +38,7 @@ describe("completeCadet", () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
function seed(id: string): void {
|
|
41
|
-
|
|
41
|
+
saveLockfileAssistant({
|
|
42
42
|
assistantId: id,
|
|
43
43
|
cloud: "docker",
|
|
44
44
|
runtimeUrl: "http://localhost:7830",
|
package/src/commands/debug.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { isCloudHome } from "../lib/cloud-values.js";
|
|
|
4
4
|
import {
|
|
5
5
|
getAssistantDisplayName,
|
|
6
6
|
resolveTargetAssistant,
|
|
7
|
+
type LockfileAssistant,
|
|
7
8
|
} from "../lib/assistant-config.js";
|
|
8
9
|
import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
|
|
9
10
|
import { loadGuardianToken, leaseGuardianToken } from "../lib/guardian-token";
|
|
@@ -72,6 +73,12 @@ export const debug = Object.assign(
|
|
|
72
73
|
console.error(`Not logged in. Run '${cliCommand()} login' first.`);
|
|
73
74
|
process.exit(1);
|
|
74
75
|
}
|
|
76
|
+
if (!entry.runtimeUrl) {
|
|
77
|
+
console.error(
|
|
78
|
+
`Error: '${reference}' has no recorded gateway URL to export logs from.`,
|
|
79
|
+
);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
75
82
|
const cloudAssistantId = entry.cloudAssistantId?.trim();
|
|
76
83
|
if (!cloudAssistantId) {
|
|
77
84
|
console.error(
|
|
@@ -134,11 +141,7 @@ export const debug = Object.assign(
|
|
|
134
141
|
);
|
|
135
142
|
|
|
136
143
|
async function daemonAccessToken(
|
|
137
|
-
entry:
|
|
138
|
-
assistantId: string;
|
|
139
|
-
runtimeUrl: string;
|
|
140
|
-
guardianBootstrapSecret?: string;
|
|
141
|
-
},
|
|
144
|
+
entry: LockfileAssistant,
|
|
142
145
|
reference: string,
|
|
143
146
|
forceRefresh: boolean,
|
|
144
147
|
): Promise<string> {
|
|
@@ -152,6 +155,11 @@ async function daemonAccessToken(
|
|
|
152
155
|
return cached.accessToken;
|
|
153
156
|
}
|
|
154
157
|
}
|
|
158
|
+
if (!entry.runtimeUrl) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`No recorded gateway URL to lease a guardian token from for ${reference}.`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
155
163
|
try {
|
|
156
164
|
return (
|
|
157
165
|
await leaseGuardianToken(
|
package/src/commands/devices.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { hostname } from "node:os";
|
|
|
16
16
|
import type { DeviceRecord } from "@mycadet/local-mode";
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
type
|
|
19
|
+
type LockfileAssistant,
|
|
20
20
|
getAssistantDisplayName,
|
|
21
21
|
resolveTargetAssistant,
|
|
22
22
|
} from "../lib/assistant-config";
|
|
@@ -75,7 +75,7 @@ EXAMPLES:
|
|
|
75
75
|
* Resolve the LOOPBACK gateway base URL for a host-side assistant, or exit with
|
|
76
76
|
* a helpful error. Never falls back to a non-loopback URL.
|
|
77
77
|
*/
|
|
78
|
-
function resolveLoopbackBase(entry:
|
|
78
|
+
function resolveLoopbackBase(entry: LockfileAssistant): string {
|
|
79
79
|
const displayName = getAssistantDisplayName(entry);
|
|
80
80
|
|
|
81
81
|
if (entry.cloud === "docker")
|
|
@@ -97,7 +97,7 @@ function resolveLoopbackBase(entry: AssistantEntry): string {
|
|
|
97
97
|
|
|
98
98
|
/** Docker host management enters the gateway network namespace before calling loopback-only routes. */
|
|
99
99
|
async function deviceRequest(
|
|
100
|
-
entry:
|
|
100
|
+
entry: LockfileAssistant,
|
|
101
101
|
url: string,
|
|
102
102
|
init: RequestInit,
|
|
103
103
|
): Promise<Response> {
|
|
@@ -164,7 +164,7 @@ function formatTimestamp(ms: number | null, absent: string): string {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
async function listDevices(
|
|
167
|
-
entry:
|
|
167
|
+
entry: LockfileAssistant,
|
|
168
168
|
base: string,
|
|
169
169
|
jsonOutput: boolean,
|
|
170
170
|
): Promise<void> {
|
|
@@ -245,7 +245,7 @@ async function listDevices(
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
async function revokeDevice(
|
|
248
|
-
entry:
|
|
248
|
+
entry: LockfileAssistant,
|
|
249
249
|
base: string,
|
|
250
250
|
hashedDeviceId: string,
|
|
251
251
|
yes: boolean,
|
|
@@ -3,9 +3,9 @@ import { cliCommand } from "../../lib/cli-name.js";
|
|
|
3
3
|
import { getGatewayUrl } from "../../lib/runtime-url.js";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
type
|
|
6
|
+
type LockfileAssistant,
|
|
7
7
|
resolveTargetAssistant,
|
|
8
|
-
|
|
8
|
+
saveLockfileAssistant,
|
|
9
9
|
} from "../../lib/assistant-config.js";
|
|
10
10
|
import {
|
|
11
11
|
GuardianLeasePermanentError,
|
|
@@ -40,14 +40,14 @@ function printUsage(): void {
|
|
|
40
40
|
* stderr. Returns true on success (the newly leased token is persisted).
|
|
41
41
|
*/
|
|
42
42
|
async function repairGuardianCredential(
|
|
43
|
-
entry:
|
|
43
|
+
entry: LockfileAssistant,
|
|
44
44
|
gatewayUrl: string,
|
|
45
45
|
): Promise<boolean> {
|
|
46
46
|
let bootstrapSecret = entry.guardianBootstrapSecret;
|
|
47
47
|
if (!bootstrapSecret) {
|
|
48
48
|
bootstrapSecret = generateLocalSigningKey();
|
|
49
49
|
entry.guardianBootstrapSecret = bootstrapSecret;
|
|
50
|
-
|
|
50
|
+
saveLockfileAssistant(entry);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const maxAttempts = 3;
|
package/src/commands/hatch.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { cliCommand } from "../lib/cli-name.js";
|
|
|
4
4
|
import cliPkg from "../../package.json";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
saveLockfileAssistant,
|
|
8
8
|
setActiveAssistant,
|
|
9
9
|
} from "../lib/assistant-config";
|
|
10
10
|
import { green } from "../lib/color";
|
|
@@ -291,7 +291,7 @@ async function hatchCadetPlatform(): Promise<void> {
|
|
|
291
291
|
|
|
292
292
|
const cloudUrl = getCloudUrl();
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
saveLockfileAssistant({
|
|
295
295
|
assistantId: result.id,
|
|
296
296
|
runtimeUrl: cloudUrl,
|
|
297
297
|
cloud: "cloud",
|
package/src/commands/login.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { cliCommand } from "../lib/cli-name.js";
|
|
|
4
4
|
import {
|
|
5
5
|
getActiveAssistant,
|
|
6
6
|
loadAllAssistants,
|
|
7
|
-
|
|
7
|
+
removeLockfileAssistant,
|
|
8
8
|
setActiveAssistant,
|
|
9
9
|
} from "../lib/assistant-config";
|
|
10
10
|
import {
|
|
@@ -158,7 +158,7 @@ export const logout = Object.assign(
|
|
|
158
158
|
isCloudHome(a.cloud),
|
|
159
159
|
);
|
|
160
160
|
for (const a of cloudAssistants) {
|
|
161
|
-
|
|
161
|
+
removeLockfileAssistant(a.assistantId);
|
|
162
162
|
}
|
|
163
163
|
if (cloudAssistants.length > 0) {
|
|
164
164
|
console.log(
|
package/src/commands/logs.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { join } from "path";
|
|
|
8
8
|
import {
|
|
9
9
|
extractHostFromEntry,
|
|
10
10
|
resolveAssistant,
|
|
11
|
-
type
|
|
11
|
+
type LockfileAssistant,
|
|
12
12
|
} from "../lib/assistant-config";
|
|
13
13
|
import { dockerResourceNames } from "../lib/docker";
|
|
14
14
|
import { getLogDir } from "../lib/xdg-log";
|
|
@@ -169,7 +169,7 @@ function extractServiceTag(line: string): string | null {
|
|
|
169
169
|
// ── Local topology ──────────────────────────────────────────────
|
|
170
170
|
|
|
171
171
|
async function showLocalLogs(
|
|
172
|
-
entry:
|
|
172
|
+
entry: LockfileAssistant,
|
|
173
173
|
opts: LogsArgs,
|
|
174
174
|
): Promise<void> {
|
|
175
175
|
const logDir = getLogDir();
|
|
@@ -291,7 +291,7 @@ async function showLocalLogs(
|
|
|
291
291
|
// ── Docker topology ─────────────────────────────────────────────
|
|
292
292
|
|
|
293
293
|
async function showDockerLogs(
|
|
294
|
-
entry:
|
|
294
|
+
entry: LockfileAssistant,
|
|
295
295
|
opts: LogsArgs,
|
|
296
296
|
): Promise<void> {
|
|
297
297
|
const res = dockerResourceNames(entry.assistantId);
|
|
@@ -441,7 +441,7 @@ function buildRemoteLogCommand(opts: LogsArgs): string {
|
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
async function showCustomLogs(
|
|
444
|
-
entry:
|
|
444
|
+
entry: LockfileAssistant,
|
|
445
445
|
opts: LogsArgs,
|
|
446
446
|
): Promise<void> {
|
|
447
447
|
const host = extractHostFromEntry(entry);
|
package/src/commands/pair.ts
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
getAssistantDisplayName,
|
|
33
33
|
lookupAssistantByIdentifier,
|
|
34
34
|
resolveAssistant,
|
|
35
|
-
type
|
|
35
|
+
type LockfileAssistant,
|
|
36
36
|
} from "../lib/assistant-config.js";
|
|
37
37
|
import { getCurrentEnvironment } from "../lib/environments/resolve.js";
|
|
38
38
|
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
@@ -43,7 +43,7 @@ import { formatWebApproveFailure, parseGatewayErrorCode } from "../lib/pair.js";
|
|
|
43
43
|
import { STALE_CLI_UPDATE_HINT } from "../lib/stale-cli-hint.js";
|
|
44
44
|
import { execOutput } from "../lib/step-runner.js";
|
|
45
45
|
|
|
46
|
-
function assistantDisplayName(entry:
|
|
46
|
+
function assistantDisplayName(entry: LockfileAssistant): string {
|
|
47
47
|
return entry.name || entry.assistantId;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -189,7 +189,7 @@ async function exitOnHttpError(response: Response): Promise<Response> {
|
|
|
189
189
|
* topologies keep the loopback HTTP mint they used before.
|
|
190
190
|
*/
|
|
191
191
|
async function mintPairingChallengeOrExit(
|
|
192
|
-
entry:
|
|
192
|
+
entry: LockfileAssistant,
|
|
193
193
|
): Promise<RemoteWebPairingChallengeResponse> {
|
|
194
194
|
if (entry.cloud !== "local" && entry.cloud !== "docker") {
|
|
195
195
|
return mintPairingChallengeOverLoopbackOrExit(entry);
|
|
@@ -258,7 +258,7 @@ async function mintPairingChallengeOrExit(
|
|
|
258
258
|
* cloud-managed), where no gateway-CLI execution surface is defined.
|
|
259
259
|
*/
|
|
260
260
|
async function mintPairingChallengeOverLoopbackOrExit(
|
|
261
|
-
entry:
|
|
261
|
+
entry: LockfileAssistant,
|
|
262
262
|
): Promise<RemoteWebPairingChallengeResponse> {
|
|
263
263
|
// Mint over loopback (the derived port avoids mDNS for same-machine calls),
|
|
264
264
|
// then approve immediately: running this CLI on the host IS the
|
|
@@ -366,7 +366,7 @@ export const pair = Object.assign(
|
|
|
366
366
|
// assistant. Join positional tokens so multi-word display names work even
|
|
367
367
|
// unquoted (e.g. `cadet pair My Assistant`).
|
|
368
368
|
const assistantName = parseAssistantTargetArg(args);
|
|
369
|
-
let entry:
|
|
369
|
+
let entry: LockfileAssistant | null;
|
|
370
370
|
if (assistantName) {
|
|
371
371
|
const result = lookupAssistantByIdentifier(assistantName);
|
|
372
372
|
if (result.status !== "found") {
|
package/src/commands/ps.ts
CHANGED
|
@@ -20,20 +20,22 @@ import {
|
|
|
20
20
|
getActiveAssistant,
|
|
21
21
|
getAssistantDisplayName,
|
|
22
22
|
getDaemonPidPath,
|
|
23
|
+
getLocalInstanceDir,
|
|
23
24
|
loadAllAssistants,
|
|
24
25
|
lookupAssistantByIdentifier,
|
|
25
26
|
readRootProcesses,
|
|
26
|
-
type
|
|
27
|
+
type LockfileAssistant,
|
|
27
28
|
} from "../lib/assistant-config";
|
|
29
|
+
import type { LocalAssistantResources } from "@mycadet/local-mode/contract";
|
|
28
30
|
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
29
31
|
import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
|
|
30
32
|
import { resolveEnvironmentSource } from "../lib/environments/resolve";
|
|
31
33
|
import { loadGuardianToken } from "../lib/guardian-token";
|
|
32
34
|
import {
|
|
35
|
+
checkCloudHealth,
|
|
33
36
|
checkHealth,
|
|
34
|
-
|
|
37
|
+
fetchCloudPs,
|
|
35
38
|
fetchGatewayPs,
|
|
36
|
-
fetchManagedPs,
|
|
37
39
|
type ManagedProcessEntry,
|
|
38
40
|
} from "../lib/health-check";
|
|
39
41
|
import { readCloudToken } from "../lib/cloud-client";
|
|
@@ -243,7 +245,7 @@ const REMOTE_PS_CMD = [
|
|
|
243
245
|
const REMOTE_SSH_TIMEOUT_MS = 30_000;
|
|
244
246
|
|
|
245
247
|
async function getRemoteProcessesCustom(
|
|
246
|
-
entry:
|
|
248
|
+
entry: LockfileAssistant,
|
|
247
249
|
): Promise<string> {
|
|
248
250
|
const host = extractHostFromEntry(entry);
|
|
249
251
|
return execOutput("ssh", [...SSH_OPTS, `root@${host}`, REMOTE_PS_CMD], {
|
|
@@ -337,14 +339,16 @@ function formatDetectionInfo(proc: DetectedProcess): string {
|
|
|
337
339
|
return parts.join(" | ");
|
|
338
340
|
}
|
|
339
341
|
|
|
340
|
-
async function getLocalProcesses(
|
|
342
|
+
async function getLocalProcesses(
|
|
343
|
+
entry: LockfileAssistant,
|
|
344
|
+
): Promise<TableRow[]> {
|
|
341
345
|
const resources = entry.resources;
|
|
342
|
-
if (!resources
|
|
346
|
+
if (!resources) {
|
|
343
347
|
throw new Error(
|
|
344
348
|
`Local assistant '${entry.assistantId}' is missing resource configuration. Re-hatch to fix.`,
|
|
345
349
|
);
|
|
346
350
|
}
|
|
347
|
-
const cadetDir = resources
|
|
351
|
+
const cadetDir = getLocalInstanceDir(resources);
|
|
348
352
|
const gatewayUrl = getGatewayUrl(entry);
|
|
349
353
|
const token = loadGuardianToken(entry.assistantId)?.accessToken;
|
|
350
354
|
|
|
@@ -381,7 +385,7 @@ async function getLocalProcesses(entry: AssistantEntry): Promise<TableRow[]> {
|
|
|
381
385
|
// gateway version that predates the route): probe each known process
|
|
382
386
|
// directly.
|
|
383
387
|
async function detectLocalProcessesFallback(
|
|
384
|
-
resources:
|
|
388
|
+
resources: LocalAssistantResources,
|
|
385
389
|
cadetDir: string,
|
|
386
390
|
): Promise<TableRow[]> {
|
|
387
391
|
const assistantSpec: ProcessSpec = {
|
|
@@ -394,7 +398,7 @@ async function detectLocalProcessesFallback(
|
|
|
394
398
|
{
|
|
395
399
|
name: "├─ qdrant",
|
|
396
400
|
pgrepName: "qdrant",
|
|
397
|
-
port:
|
|
401
|
+
port: 0,
|
|
398
402
|
pidFile: join(cadetDir, "workspace", "data", "qdrant", "qdrant.pid"),
|
|
399
403
|
},
|
|
400
404
|
{
|
|
@@ -446,7 +450,9 @@ function isLocalProcessAlive(pid: number): boolean {
|
|
|
446
450
|
}
|
|
447
451
|
}
|
|
448
452
|
|
|
449
|
-
async function getDockerProcesses(
|
|
453
|
+
async function getDockerProcesses(
|
|
454
|
+
entry: LockfileAssistant,
|
|
455
|
+
): Promise<TableRow[]> {
|
|
450
456
|
const res = dockerResourceNames(entry.assistantId);
|
|
451
457
|
|
|
452
458
|
const containers: { name: string; containerName: string }[] = [
|
|
@@ -491,7 +497,7 @@ async function getDockerProcesses(entry: AssistantEntry): Promise<TableRow[]> {
|
|
|
491
497
|
return results;
|
|
492
498
|
}
|
|
493
499
|
|
|
494
|
-
function locationFor(entry:
|
|
500
|
+
function locationFor(entry: LockfileAssistant): string {
|
|
495
501
|
if (entry.cloud === "local") {
|
|
496
502
|
return entry.resources?.instanceDir ?? "unknown — no instance dir recorded";
|
|
497
503
|
}
|
|
@@ -502,7 +508,7 @@ function locationFor(entry: AssistantEntry): string {
|
|
|
502
508
|
}
|
|
503
509
|
|
|
504
510
|
async function getAssistantProcessRows(
|
|
505
|
-
entry:
|
|
511
|
+
entry: LockfileAssistant,
|
|
506
512
|
): Promise<TableRow[]> {
|
|
507
513
|
const cloud = entry.cloud;
|
|
508
514
|
|
|
@@ -520,7 +526,7 @@ async function getAssistantProcessRows(
|
|
|
520
526
|
if (isCloudHome(cloud)) {
|
|
521
527
|
console.log(` Cadet Cloud ID: ${entry.assistantId}\n`);
|
|
522
528
|
|
|
523
|
-
const psData = await
|
|
529
|
+
const psData = await fetchCloudPs(entry);
|
|
524
530
|
|
|
525
531
|
if (!psData) {
|
|
526
532
|
return [
|
|
@@ -761,7 +767,7 @@ function assistantLabelFor(assistantId: string | undefined): string | null {
|
|
|
761
767
|
* splits into /app and /ui — so every CLI-managed row renders machine-level.
|
|
762
768
|
*/
|
|
763
769
|
async function assistantRowsWithRootProcesses(
|
|
764
|
-
assistants:
|
|
770
|
+
assistants: LockfileAssistant[],
|
|
765
771
|
healths: AssistantHealth[],
|
|
766
772
|
activeAssistantId: string | null,
|
|
767
773
|
): Promise<TableRow[]> {
|
|
@@ -784,7 +790,7 @@ type AssistantHealth = {
|
|
|
784
790
|
};
|
|
785
791
|
|
|
786
792
|
async function getAssistantListHealth(
|
|
787
|
-
entry:
|
|
793
|
+
entry: LockfileAssistant,
|
|
788
794
|
): Promise<AssistantHealth> {
|
|
789
795
|
const resources = entry.resources;
|
|
790
796
|
if (entry.cloud === "local" && resources) {
|
|
@@ -819,7 +825,7 @@ async function getAssistantListHealth(
|
|
|
819
825
|
}
|
|
820
826
|
|
|
821
827
|
if (isCloudHome(entry.cloud)) {
|
|
822
|
-
return
|
|
828
|
+
return checkCloudHealth(entry);
|
|
823
829
|
}
|
|
824
830
|
|
|
825
831
|
const token = loadGuardianToken(entry.assistantId)?.accessToken;
|
|
@@ -827,7 +833,7 @@ async function getAssistantListHealth(
|
|
|
827
833
|
}
|
|
828
834
|
|
|
829
835
|
function formatAssistantListRow(
|
|
830
|
-
entry:
|
|
836
|
+
entry: LockfileAssistant,
|
|
831
837
|
activeAssistantId: string | null,
|
|
832
838
|
health: AssistantHealth,
|
|
833
839
|
): TableRow {
|