@mycadet/cli 0.13.0-dev.202610291822.708cf19 → 0.13.0-dev.202610311714.d661ca6
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/knip.json +1 -4
- package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +2 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/providers/baseten.test.ts +41 -0
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/providers/baseten.ts +40 -0
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/gateway-proxy.test.ts +38 -5
- package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token.test.ts +84 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +20 -25
- package/node_modules/@mycadet/local-mode/src/__tests__/unpair.test.ts +2 -1
- package/node_modules/@mycadet/local-mode/src/avatar.test.ts +5 -9
- package/node_modules/@mycadet/local-mode/src/config.ts +51 -0
- package/node_modules/@mycadet/local-mode/src/devices.ts +8 -4
- package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +6 -7
- package/node_modules/@mycadet/local-mode/src/guardian-token.ts +92 -4
- package/node_modules/@mycadet/local-mode/src/hatch.ts +6 -4
- package/node_modules/@mycadet/local-mode/src/index.ts +16 -2
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +102 -38
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +209 -99
- package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +23 -12
- package/node_modules/@mycadet/local-mode/src/lockfile.ts +50 -28
- package/node_modules/@mycadet/local-mode/src/resolve-local-server.test.ts +82 -0
- package/node_modules/@mycadet/local-mode/src/retire.ts +6 -4
- package/node_modules/@mycadet/local-mode/src/served-config.test.ts +19 -10
- package/node_modules/@mycadet/local-mode/src/sleep.ts +6 -4
- package/node_modules/@mycadet/local-mode/src/status.ts +16 -26
- package/node_modules/@mycadet/local-mode/src/wake.ts +6 -4
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/package.json +2 -1
- package/node_modules/@mycadet/shared/providers/baseten.test.ts +41 -0
- package/node_modules/@mycadet/shared/providers/baseten.ts +40 -0
- package/package.json +1 -2
- package/scripts/practice-build-remote-images.sh +34 -0
- package/scripts/stage-remote-image-context.ts +32 -0
- package/src/__tests__/assistant-config.test.ts +66 -110
- package/src/__tests__/backup-ops.test.ts +4 -6
- package/src/__tests__/backup.test.ts +2 -0
- package/src/__tests__/connect-import.test.ts +3 -1
- package/src/__tests__/debug.test.ts +2 -1
- package/src/__tests__/devices.test.ts +5 -7
- package/src/__tests__/guardian-token.test.ts +10 -3
- package/src/__tests__/helpers/lockfile-entry.ts +137 -18
- package/src/__tests__/host-teleport-docker.test.ts +1 -0
- package/src/__tests__/host-teleport.test.ts +10 -14
- package/src/__tests__/local-runtime-version.test.ts +20 -8
- package/src/__tests__/multi-local.test.ts +51 -61
- package/src/__tests__/nginx.test.ts +204 -174
- package/src/__tests__/ps-cloud-status.test.ts +0 -1
- package/src/__tests__/restore.test.ts +17 -10
- package/src/__tests__/retire-local.test.ts +29 -34
- package/src/__tests__/retire.test.ts +23 -39
- package/src/__tests__/root-backup-docker.test.ts +1 -0
- package/src/__tests__/root-backup.test.ts +10 -10
- package/src/__tests__/root-process-lockfile.test.ts +8 -8
- package/src/__tests__/root-restore-command.test.ts +1 -0
- package/src/__tests__/runtime-url.test.ts +6 -5
- package/src/__tests__/setup.test.ts +20 -23
- package/src/__tests__/sleep.test.ts +16 -24
- package/src/__tests__/tailscale.test.ts +3 -5
- package/src/__tests__/teleport-backup.test.ts +3 -3
- package/src/__tests__/teleport.test.ts +1 -0
- package/src/__tests__/tunnel-startup-summary.test.ts +0 -18
- package/src/__tests__/tunnel-stop.test.ts +6 -7
- package/src/__tests__/tunnel.test.ts +29 -23
- package/src/__tests__/uninstall.test.ts +8 -29
- package/src/__tests__/upgrade-local.test.ts +23 -21
- package/src/__tests__/upgrade-root-recovery.test.ts +1 -0
- package/src/__tests__/use.test.ts +11 -39
- package/src/__tests__/wake.test.ts +89 -95
- package/src/__tests__/web-dist.test.ts +12 -1
- package/src/commands/client.ts +2 -23
- package/src/commands/debug.ts +8 -0
- package/src/commands/exec.ts +5 -3
- package/src/commands/gateway/token.ts +10 -5
- package/src/commands/hatch.ts +2 -5
- package/src/commands/login.ts +2 -2
- package/src/commands/pair.ts +2 -2
- package/src/commands/ps.ts +23 -340
- package/src/commands/restore.ts +17 -13
- package/src/commands/retire.ts +10 -4
- package/src/commands/setup.ts +10 -6
- package/src/commands/sleep.ts +11 -14
- package/src/commands/terminal.ts +1 -1
- package/src/commands/tunnel.ts +4 -1
- package/src/commands/uninstall.ts +15 -5
- package/src/commands/upgrade.ts +44 -532
- package/src/commands/wake.ts +8 -282
- package/src/components/DefaultMainScreen.tsx +0 -11
- package/src/lib/__tests__/cloud-client-signed-url.test.ts +3 -15
- package/src/lib/__tests__/local-ces.test.ts +7 -1
- package/src/lib/__tests__/local-daemon-readiness.test.ts +4 -1
- package/src/lib/__tests__/local-gateway-cli.test.ts +20 -8
- package/src/lib/__tests__/port-heal.test.ts +58 -32
- package/src/lib/__tests__/runtime-url.test.ts +27 -7
- package/src/lib/assistant-client.ts +1 -3
- package/src/lib/assistant-config.ts +74 -40
- package/src/lib/cloud-login.ts +8 -6
- package/src/lib/detached-process.ts +1 -1
- package/src/lib/docker.ts +27 -22
- package/src/lib/environments/__tests__/paths.test.ts +10 -4
- package/src/lib/environments/paths.ts +3 -1
- package/src/lib/guardian-token.ts +59 -2
- package/src/lib/host-teleport.ts +29 -5
- package/src/lib/port-heal.ts +15 -17
- package/src/lib/{ssh-apple-container.ts → remotes/apple-container.ts} +139 -1
- package/src/lib/remotes/baseten/Dockerfile +6 -1
- package/src/lib/remotes/baseten/api.test.ts +76 -15
- package/src/lib/remotes/baseten/api.ts +41 -4
- package/src/lib/remotes/baseten/baseten-cli.ts +8 -0
- package/src/lib/remotes/baseten/context.test.ts +5 -3
- package/src/lib/remotes/baseten/context.ts +3 -1
- package/src/lib/remotes/baseten/index.ts +84 -6
- package/src/lib/remotes/docker.ts +517 -0
- package/src/lib/{local.ts → remotes/local.ts} +878 -164
- package/src/lib/retire-apple-container.ts +10 -1
- package/src/lib/retire-local.ts +17 -17
- package/src/lib/root-backup.ts +47 -25
- package/src/lib/servers/nginx.ts +70 -178
- package/src/lib/tunnel.ts +54 -67
- package/src/lib/tunnels/ngrok.ts +2 -9
- package/src/lib/upgrade-lifecycle.ts +10 -1
- package/src/lib/version-compat.ts +0 -1
- package/src/lib/xdg-log.ts +0 -1
- package/src/lib/exec-apple-container.ts +0 -122
- package/src/lib/hatch-local.ts +0 -451
- package/src/lib/pgrep.ts +0 -32
package/knip.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/shared",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202610311714.d661ca6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./github-repository.ts",
|
|
7
7
|
"./github-repository": "./github-repository.ts",
|
|
8
|
+
"./providers/baseten": "./providers/baseten.ts",
|
|
8
9
|
"./scripts/run-isolated-tests": "./scripts/run-isolated-tests.ts",
|
|
9
10
|
"./version": "./version.ts"
|
|
10
11
|
}
|
package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/providers/baseten.test.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { BASETEN_API_KEY_ENV, runBaseten } from "./baseten";
|
|
4
|
+
|
|
5
|
+
describe("runBaseten", () => {
|
|
6
|
+
test("throws the install message when the CLI is absent from PATH", () => {
|
|
7
|
+
const savedPath = process.env.PATH;
|
|
8
|
+
process.env.PATH = "";
|
|
9
|
+
try {
|
|
10
|
+
expect(() => runBaseten(["sandbox", "list"], "nope")).toThrow(
|
|
11
|
+
/Baseten CLI was not found on PATH/,
|
|
12
|
+
);
|
|
13
|
+
} finally {
|
|
14
|
+
if (savedPath === undefined) delete process.env.PATH;
|
|
15
|
+
else process.env.PATH = savedPath;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("throws with the failing command on a non-zero exit", () => {
|
|
20
|
+
expect(() => runBaseten(["--version-not-a-flag"], "flag probe")).toThrow(
|
|
21
|
+
/flag probe: baseten --version-not-a-flag exited with/,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("BASETEN_API_KEY_ENV", () => {
|
|
27
|
+
const saved = process.env[BASETEN_API_KEY_ENV];
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (saved === undefined) delete process.env[BASETEN_API_KEY_ENV];
|
|
30
|
+
else process.env[BASETEN_API_KEY_ENV] = saved;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("the key contract points at the vaulted credential", () => {
|
|
34
|
+
process.env[BASETEN_API_KEY_ENV] = "";
|
|
35
|
+
// The scripted consumers check this before invoking the CLI; the name
|
|
36
|
+
// must stay stable — it is what `assistant credentials` vaults under
|
|
37
|
+
// baseten:api_key.
|
|
38
|
+
expect(BASETEN_API_KEY_ENV).toBe("BASETEN_API_KEY");
|
|
39
|
+
expect(process.env[BASETEN_API_KEY_ENV]).toBe("");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Baseten sandbox helpers every Baseten consumer shares: the CLI runner
|
|
5
|
+
* (spawn, stream, ENOENT message, exit-code check) and the API-key env
|
|
6
|
+
* contract. Consumers keep their own argv assembly and credential posture —
|
|
7
|
+
* the CLI's sandbox flow authenticates via `baseten auth login` and never
|
|
8
|
+
* requires the env key, while scripted consumers (the desktop-QA manager)
|
|
9
|
+
* check the key themselves.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The env var the Baseten CLI reads its API key from. */
|
|
13
|
+
export const BASETEN_API_KEY_ENV = "BASETEN_API_KEY";
|
|
14
|
+
|
|
15
|
+
/** The CLI-not-found message, with Baseten's install doc. */
|
|
16
|
+
export const BASETEN_CLI_MISSING =
|
|
17
|
+
"The Baseten CLI was not found on PATH. Install it first: " +
|
|
18
|
+
"https://docs.baseten.co/reference/cli/baseten/overview.md#install";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Run the `baseten` CLI with inherited stdio so build/exec logs stream to
|
|
22
|
+
* the caller. Throws on a missing CLI, a spawn failure, or a non-zero exit.
|
|
23
|
+
*/
|
|
24
|
+
export function runBaseten(args: string[], failure: string): void {
|
|
25
|
+
const result = spawnSync("baseten", args, {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
env: process.env,
|
|
28
|
+
});
|
|
29
|
+
if (result.error) {
|
|
30
|
+
if ("code" in result.error && result.error.code === "ENOENT") {
|
|
31
|
+
throw new Error(BASETEN_CLI_MISSING);
|
|
32
|
+
}
|
|
33
|
+
throw result.error;
|
|
34
|
+
}
|
|
35
|
+
if (result.status !== 0) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`${failure}: baseten ${args.join(" ")} exited with ${result.status}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -226,7 +226,8 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
226
226
|
{
|
|
227
227
|
assistantId: "abc-123",
|
|
228
228
|
cloud: "local",
|
|
229
|
-
|
|
229
|
+
port: 8080,
|
|
230
|
+
daemonPort: 8501,
|
|
230
231
|
},
|
|
231
232
|
],
|
|
232
233
|
}),
|
|
@@ -248,12 +249,13 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
248
249
|
{
|
|
249
250
|
assistantId: "abc-123",
|
|
250
251
|
cloud: "local",
|
|
251
|
-
|
|
252
|
+
port: 80,
|
|
253
|
+
daemonPort: 8501,
|
|
252
254
|
},
|
|
253
255
|
{
|
|
254
256
|
assistantId: "def-456",
|
|
255
257
|
cloud: "docker",
|
|
256
|
-
|
|
258
|
+
port: 70000,
|
|
257
259
|
},
|
|
258
260
|
],
|
|
259
261
|
}),
|
|
@@ -292,6 +294,35 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
292
294
|
);
|
|
293
295
|
});
|
|
294
296
|
|
|
297
|
+
test("a baseten entry resolves to a remote target on the sandbox /port/ route", () => {
|
|
298
|
+
expect(
|
|
299
|
+
gatewayTargetsFromLockfile({
|
|
300
|
+
assistants: [
|
|
301
|
+
{
|
|
302
|
+
assistantId: "sbx-1",
|
|
303
|
+
cloud: "baseten",
|
|
304
|
+
sandboxUrl: "https://sbx-name-abc123.us-pdx-1.b10.co",
|
|
305
|
+
port: 7830,
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
}),
|
|
309
|
+
).toEqual(
|
|
310
|
+
targets({
|
|
311
|
+
"sbx-1": remote("https://sbx-name-abc123.us-pdx-1.b10.co/port/7830"),
|
|
312
|
+
})(),
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("a baseten entry without a recorded URL is not targetable", () => {
|
|
317
|
+
// The hatch records the entry only once describe returns a URL; a
|
|
318
|
+
// URL-less record must not forward anywhere.
|
|
319
|
+
expect(
|
|
320
|
+
gatewayTargetsFromLockfile({
|
|
321
|
+
assistants: [{ assistantId: "sbx-1", cloud: "baseten", port: 7830 }],
|
|
322
|
+
}),
|
|
323
|
+
).toEqual(new Map());
|
|
324
|
+
});
|
|
325
|
+
|
|
295
326
|
test("tolerates malformed entries", () => {
|
|
296
327
|
expect(
|
|
297
328
|
gatewayTargetsFromLockfile({
|
|
@@ -303,7 +334,8 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
303
334
|
{
|
|
304
335
|
assistantId: "abc-123",
|
|
305
336
|
cloud: "local",
|
|
306
|
-
|
|
337
|
+
port: 8080,
|
|
338
|
+
daemonPort: 8501,
|
|
307
339
|
},
|
|
308
340
|
],
|
|
309
341
|
}),
|
|
@@ -334,7 +366,8 @@ describe("readGatewayTargets", () => {
|
|
|
334
366
|
{
|
|
335
367
|
assistantId: "abc-123",
|
|
336
368
|
cloud: "local",
|
|
337
|
-
|
|
369
|
+
port: 8080,
|
|
370
|
+
daemonPort: 8501,
|
|
338
371
|
},
|
|
339
372
|
{
|
|
340
373
|
assistantId: "def-456",
|
|
@@ -5,14 +5,17 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getGuardianAccessToken,
|
|
8
|
+
getPairedGuardianAccessToken,
|
|
8
9
|
formatGuardianRefreshCliFailure,
|
|
9
10
|
parseGuardianRefreshCliFailure,
|
|
10
11
|
PAIRED_GUARDIAN_TARGET_MISMATCH_ERROR,
|
|
11
12
|
PAIRED_GUARDIAN_TOKEN_HOST_ONLY_ERROR,
|
|
12
13
|
isConfidentialRefreshUrl,
|
|
14
|
+
saveBasetenSandboxToken,
|
|
13
15
|
saveGuardianToken,
|
|
14
16
|
type GuardianTokenData,
|
|
15
17
|
} from "../guardian-token";
|
|
18
|
+
import { saveLockfileAssistant } from "../lockfile";
|
|
16
19
|
import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
|
|
17
20
|
import type { CliInvocation } from "../util";
|
|
18
21
|
|
|
@@ -263,3 +266,84 @@ describe("isConfidentialRefreshUrl", () => {
|
|
|
263
266
|
expect(isConfidentialRefreshUrl("https://evil.localhost:8443")).toBe(true);
|
|
264
267
|
});
|
|
265
268
|
});
|
|
269
|
+
|
|
270
|
+
describe("getPairedGuardianAccessToken — baseten sandboxes", () => {
|
|
271
|
+
let configDir: string;
|
|
272
|
+
|
|
273
|
+
beforeEach(() => {
|
|
274
|
+
// Same ambient-resolution fixture as the guardian tests: XDG at the tmp
|
|
275
|
+
// home, reads and writes through the production environment dir.
|
|
276
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "baseten-token-test-"));
|
|
277
|
+
process.env.XDG_CONFIG_HOME = home;
|
|
278
|
+
configDir = path.join(home, "cadet");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
Reflect.deleteProperty(process.env, "XDG_CONFIG_HOME");
|
|
283
|
+
fs.rmSync(path.dirname(configDir), { recursive: true, force: true });
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("a baseten entry reads the saved sandbox token and never leases", async () => {
|
|
287
|
+
// The invocation fails loudly if any branch spawns the CLI — the baseten
|
|
288
|
+
// credential is a file read, not a lease.
|
|
289
|
+
saveLockfileAssistant({
|
|
290
|
+
assistantId: "asst_bx",
|
|
291
|
+
cloud: "baseten",
|
|
292
|
+
sandboxUrl: "https://sbx-name-abc123.us-pdx-1.b10.co",
|
|
293
|
+
port: 7830,
|
|
294
|
+
});
|
|
295
|
+
saveBasetenSandboxToken("asst_bx", "sbx-token-1");
|
|
296
|
+
|
|
297
|
+
expect(
|
|
298
|
+
await getPairedGuardianAccessToken(
|
|
299
|
+
"asst_bx",
|
|
300
|
+
"https://sbx-name-abc123.us-pdx-1.b10.co/port/7830",
|
|
301
|
+
invocation,
|
|
302
|
+
false,
|
|
303
|
+
),
|
|
304
|
+
).toEqual({ ok: true, accessToken: "sbx-token-1" });
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("a missing token file is a structured 404, not a throw", async () => {
|
|
308
|
+
saveLockfileAssistant({
|
|
309
|
+
assistantId: "asst_bx",
|
|
310
|
+
cloud: "baseten",
|
|
311
|
+
sandboxUrl: "https://sbx-name-abc123.us-pdx-1.b10.co",
|
|
312
|
+
port: 7830,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
expect(
|
|
316
|
+
await getPairedGuardianAccessToken(
|
|
317
|
+
"asst_bx",
|
|
318
|
+
"https://sbx-name-abc123.us-pdx-1.b10.co/port/7830",
|
|
319
|
+
invocation,
|
|
320
|
+
false,
|
|
321
|
+
),
|
|
322
|
+
).toMatchObject({ ok: false, status: 404 });
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test("a non-baseten entry still leases through the guardian path", async () => {
|
|
326
|
+
saveLockfileAssistant({ assistantId: "asst_local", cloud: "local" });
|
|
327
|
+
|
|
328
|
+
// A local entry behind a non-loopback paired URL trips the paired path's
|
|
329
|
+
// target-binding guard (403) — the guardian path, not the token-file
|
|
330
|
+
// branch, answered.
|
|
331
|
+
expect(
|
|
332
|
+
await getPairedGuardianAccessToken(
|
|
333
|
+
"asst_local",
|
|
334
|
+
"https://gw.example.com",
|
|
335
|
+
invocation,
|
|
336
|
+
false,
|
|
337
|
+
),
|
|
338
|
+
).toMatchObject({ ok: false, status: 403 });
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("the token file is saved 0600 under the assistants dir", () => {
|
|
342
|
+
saveBasetenSandboxToken("asst_bx", "t");
|
|
343
|
+
|
|
344
|
+
const stat = fs.statSync(
|
|
345
|
+
path.join(configDir, "assistants", "asst_bx", "baseten-token.json"),
|
|
346
|
+
);
|
|
347
|
+
expect(stat.mode & 0o777).toBe(0o600);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
@@ -25,11 +25,9 @@ function writeLocalLockfile(overrides: Record<string, unknown> = {}): void {
|
|
|
25
25
|
writeLockfile({
|
|
26
26
|
assistantId: "local-1",
|
|
27
27
|
cloud: "local",
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
gatewayPort: 30102,
|
|
32
|
-
},
|
|
28
|
+
instanceDir,
|
|
29
|
+
daemonPort: 30101,
|
|
30
|
+
port: 30102,
|
|
33
31
|
...overrides,
|
|
34
32
|
});
|
|
35
33
|
}
|
|
@@ -104,10 +102,9 @@ describe("getLocalAssistantStatus", () => {
|
|
|
104
102
|
});
|
|
105
103
|
});
|
|
106
104
|
|
|
107
|
-
test("returns sleeping for
|
|
105
|
+
test("returns sleeping for local entries without recorded ports", async () => {
|
|
108
106
|
writeLockfile({
|
|
109
107
|
assistantId: "legacy-local",
|
|
110
|
-
baseDataDir: instanceDir,
|
|
111
108
|
runtimeUrl: "http://127.0.0.1:30102",
|
|
112
109
|
});
|
|
113
110
|
|
|
@@ -144,11 +141,9 @@ describe("getLocalAssistantStatus", () => {
|
|
|
144
141
|
|
|
145
142
|
test("returns starting when a fresh assistant PID is alive but health is not ready yet", async () => {
|
|
146
143
|
writeLocalLockfile({
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
gatewayPort: 30102,
|
|
151
|
-
},
|
|
144
|
+
instanceDir,
|
|
145
|
+
daemonPort: await unusedPort(),
|
|
146
|
+
port: 30102,
|
|
152
147
|
});
|
|
153
148
|
writeAssistantPid(String(process.pid));
|
|
154
149
|
|
|
@@ -163,11 +158,9 @@ describe("getLocalAssistantStatus", () => {
|
|
|
163
158
|
|
|
164
159
|
test("returns crashed when an old live assistant PID is still not responding", async () => {
|
|
165
160
|
writeLocalLockfile({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
gatewayPort: 30102,
|
|
170
|
-
},
|
|
161
|
+
instanceDir,
|
|
162
|
+
daemonPort: await unusedPort(),
|
|
163
|
+
port: 30102,
|
|
171
164
|
});
|
|
172
165
|
const pidPath = writeAssistantPid(String(process.pid));
|
|
173
166
|
markStale(pidPath);
|
|
@@ -189,11 +182,9 @@ describe("getLocalAssistantStatus", () => {
|
|
|
189
182
|
const daemonPort = await listen(server);
|
|
190
183
|
try {
|
|
191
184
|
writeLocalLockfile({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
gatewayPort: await unusedPort(),
|
|
196
|
-
},
|
|
185
|
+
instanceDir,
|
|
186
|
+
daemonPort,
|
|
187
|
+
port: await unusedPort(),
|
|
197
188
|
});
|
|
198
189
|
writeAssistantPid(String(process.pid));
|
|
199
190
|
|
|
@@ -233,8 +224,12 @@ describe("resolveLockfileInstanceDir", () => {
|
|
|
233
224
|
});
|
|
234
225
|
});
|
|
235
226
|
|
|
236
|
-
test("
|
|
237
|
-
writeLockfile({
|
|
227
|
+
test("reads the recorded instance dir off the entry", () => {
|
|
228
|
+
writeLockfile({
|
|
229
|
+
assistantId: "local-1",
|
|
230
|
+
cloud: "local",
|
|
231
|
+
instanceDir,
|
|
232
|
+
});
|
|
238
233
|
expect(resolveLockfileInstanceDir("local-1")).toEqual({
|
|
239
234
|
ok: true,
|
|
240
235
|
instanceDir,
|
|
@@ -279,7 +274,7 @@ describe("resolveLockfileInstanceDir", () => {
|
|
|
279
274
|
writeFileSync(
|
|
280
275
|
legacyPath,
|
|
281
276
|
JSON.stringify({
|
|
282
|
-
assistants: [{ assistantId: "local-1",
|
|
277
|
+
assistants: [{ assistantId: "local-1", cloud: "local" }],
|
|
283
278
|
}),
|
|
284
279
|
);
|
|
285
280
|
expect(resolveLockfileInstanceDir("local-1")).toEqual({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GATEWAY_PORT } from "../lockfile-contract";
|
|
1
2
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import os from "node:os";
|
|
@@ -70,7 +71,7 @@ describe("unpairAssistant", () => {
|
|
|
70
71
|
// modeled fields and drops anything a newer writer added to an entry.
|
|
71
72
|
const onDisk = readLockfileFromDisk();
|
|
72
73
|
expect(onDisk.assistants).toEqual([
|
|
73
|
-
{ assistantId: "local-1", cloud: "local" },
|
|
74
|
+
{ assistantId: "local-1", cloud: "local", port: GATEWAY_PORT },
|
|
74
75
|
]);
|
|
75
76
|
expect(onDisk.activeAssistant).toBe("local-1");
|
|
76
77
|
});
|
|
@@ -18,10 +18,7 @@ describe("readLockfileAssistantAvatar", () => {
|
|
|
18
18
|
const read = (assistantId = "asst-1") =>
|
|
19
19
|
readLockfileAssistantAvatar(assistantId);
|
|
20
20
|
|
|
21
|
-
const writeLockfileEntry = (
|
|
22
|
-
resources?: Record<string, unknown>,
|
|
23
|
-
extra: Record<string, unknown> = {},
|
|
24
|
-
): void => {
|
|
21
|
+
const writeLockfileEntry = (extra: Record<string, unknown> = {}): void => {
|
|
25
22
|
fs.mkdirSync(path.dirname(lockfilePath), { recursive: true });
|
|
26
23
|
fs.writeFileSync(
|
|
27
24
|
lockfilePath,
|
|
@@ -31,7 +28,6 @@ describe("readLockfileAssistantAvatar", () => {
|
|
|
31
28
|
assistantId: "asst-1",
|
|
32
29
|
cloud: "local",
|
|
33
30
|
runtimeUrl: "http://127.0.0.1:1",
|
|
34
|
-
resources,
|
|
35
31
|
...extra,
|
|
36
32
|
},
|
|
37
33
|
],
|
|
@@ -59,7 +55,7 @@ describe("readLockfileAssistantAvatar", () => {
|
|
|
59
55
|
lockfilePath = path.join(tempDir, "cadet", "lockfile.json");
|
|
60
56
|
instanceDir = path.join(tempDir, "instance");
|
|
61
57
|
avatarDir = path.join(instanceDir, "workspace", "data", "avatar");
|
|
62
|
-
writeLockfileEntry({ instanceDir,
|
|
58
|
+
writeLockfileEntry({ instanceDir, port: 1, daemonPort: 2 });
|
|
63
59
|
});
|
|
64
60
|
|
|
65
61
|
afterEach(() => {
|
|
@@ -149,7 +145,7 @@ describe("readLockfileAssistantAvatar", () => {
|
|
|
149
145
|
});
|
|
150
146
|
|
|
151
147
|
test("entry without an instanceDir reads the default instance dir", () => {
|
|
152
|
-
writeLockfileEntry({
|
|
148
|
+
writeLockfileEntry({ port: 1, daemonPort: 2 });
|
|
153
149
|
const defaultAvatarDir = path.join(
|
|
154
150
|
process.env.XDG_DATA_HOME ?? "",
|
|
155
151
|
"cadet",
|
|
@@ -172,13 +168,13 @@ describe("readLockfileAssistantAvatar", () => {
|
|
|
172
168
|
});
|
|
173
169
|
|
|
174
170
|
test("entry without an instanceDir and no default workspace yields null", () => {
|
|
175
|
-
writeLockfileEntry({
|
|
171
|
+
writeLockfileEntry({ port: 1, daemonPort: 2 });
|
|
176
172
|
|
|
177
173
|
expect(read()).toEqual({ ok: true, avatar: null });
|
|
178
174
|
});
|
|
179
175
|
|
|
180
176
|
test("legacy lockfile entry with only baseDataDir resolves", () => {
|
|
181
|
-
writeLockfileEntry(
|
|
177
|
+
writeLockfileEntry({ instanceDir });
|
|
182
178
|
writeAvatarFile("character-traits.json", JSON.stringify(traits));
|
|
183
179
|
|
|
184
180
|
expect(read()).toEqual({
|
|
@@ -64,6 +64,57 @@ export function resolveInstanceDir(assistantId: string): string {
|
|
|
64
64
|
return joinLocalPath(resolveAssistantsDir(), assistantId);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The on-disk location of an assistant's Baseten sandbox access token, given
|
|
69
|
+
* an already resolved config dir. Same contract as {@link guardianTokenPath}:
|
|
70
|
+
* the single source of truth for this path so the CLI writer and every
|
|
71
|
+
* host-seam reader agree — the desktop proxy reads the file the hatch wrote.
|
|
72
|
+
* The token is a short-lived bearer for the sandbox's API server; it never
|
|
73
|
+
* enters the lockfile (which crosses the renderer boundary).
|
|
74
|
+
*/
|
|
75
|
+
export function basetenTokenPath(assistantId: string): string {
|
|
76
|
+
assertSafePathSegment(assistantId, "assistant ID");
|
|
77
|
+
return joinLocalPath(
|
|
78
|
+
resolveConfigDir(),
|
|
79
|
+
"assistants",
|
|
80
|
+
assistantId,
|
|
81
|
+
"baseten-token.json",
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The on-disk location of an assistant's guardian bootstrap secret, given an
|
|
87
|
+
* already resolved config dir. Same contract as {@link guardianTokenPath}:
|
|
88
|
+
* the single source of truth for this path. Secrets never live in the
|
|
89
|
+
* lockfile (which crosses the renderer boundary); the hatch/docker/restore
|
|
90
|
+
* writers create the file and every lease-repair reader goes through here.
|
|
91
|
+
*/
|
|
92
|
+
export function guardianBootstrapSecretPath(assistantId: string): string {
|
|
93
|
+
assertSafePathSegment(assistantId, "assistant ID");
|
|
94
|
+
return joinLocalPath(
|
|
95
|
+
resolveConfigDir(),
|
|
96
|
+
"assistants",
|
|
97
|
+
assistantId,
|
|
98
|
+
"guardian-bootstrap-secret",
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The on-disk location of an assistant's bearer token, given an already
|
|
104
|
+
* resolved config dir. Same contract as {@link guardianTokenPath}. The
|
|
105
|
+
* platform sync strips the bearer from the lockfile rows it writes and
|
|
106
|
+
* persists it here instead; readers go through this path.
|
|
107
|
+
*/
|
|
108
|
+
export function assistantBearerTokenPath(assistantId: string): string {
|
|
109
|
+
assertSafePathSegment(assistantId, "assistant ID");
|
|
110
|
+
return joinLocalPath(
|
|
111
|
+
resolveConfigDir(),
|
|
112
|
+
"assistants",
|
|
113
|
+
assistantId,
|
|
114
|
+
"bearer-token",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
67
118
|
/**
|
|
68
119
|
* The on-disk location of an assistant's guardian token, given an already
|
|
69
120
|
* resolved config dir. The single source of truth for this path so the CLI
|
|
@@ -157,10 +157,12 @@ function parseDeviceRecords(stdout: string): DeviceRecord[] | null {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
export async function runDevicesList(
|
|
160
|
-
invocation: CliInvocation,
|
|
160
|
+
invocation: CliInvocation | (() => Promise<CliInvocation>),
|
|
161
161
|
assistantId: string,
|
|
162
162
|
): Promise<DevicesListResult> {
|
|
163
|
-
const
|
|
163
|
+
const resolved =
|
|
164
|
+
typeof invocation === "function" ? await invocation() : invocation;
|
|
165
|
+
const result = await runDevicesCli(resolved, [
|
|
164
166
|
"devices",
|
|
165
167
|
assistantId,
|
|
166
168
|
"--json",
|
|
@@ -180,11 +182,13 @@ export async function runDevicesList(
|
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
export async function runDevicesRevoke(
|
|
183
|
-
invocation: CliInvocation,
|
|
185
|
+
invocation: CliInvocation | (() => Promise<CliInvocation>),
|
|
184
186
|
assistantId: string,
|
|
185
187
|
hashedDeviceId: string,
|
|
186
188
|
): Promise<DevicesRevokeResult> {
|
|
187
|
-
const
|
|
189
|
+
const resolved =
|
|
190
|
+
typeof invocation === "function" ? await invocation() : invocation;
|
|
191
|
+
const result = await runDevicesCli(resolved, [
|
|
188
192
|
"devices",
|
|
189
193
|
"revoke",
|
|
190
194
|
hashedDeviceId,
|
|
@@ -7,10 +7,9 @@ import {
|
|
|
7
7
|
FLATTENED_FIRST_SEGMENTS,
|
|
8
8
|
GATEWAY_PORT,
|
|
9
9
|
getGatewayUrl,
|
|
10
|
-
|
|
11
|
-
isCloudHome,
|
|
10
|
+
isCloudEntry,
|
|
12
11
|
isLoopbackGatewayCloud,
|
|
13
|
-
|
|
12
|
+
isUsableBaseUrl,
|
|
14
13
|
LockfileAssistantSchema,
|
|
15
14
|
} from "./lockfile-contract";
|
|
16
15
|
import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
|
|
@@ -197,7 +196,7 @@ const MAX_GATEWAY_PORT = 65535;
|
|
|
197
196
|
* off-machine `runtimeUrl` (an absolute http(s) address that is not
|
|
198
197
|
* loopback — a connect import's remote gateway) resolves to it directly;
|
|
199
198
|
* otherwise a loopback-gateway cloud (`local`, `docker`) resolves to its
|
|
200
|
-
* recorded loopback port
|
|
199
|
+
* recorded loopback port (`entry.port`). Everything
|
|
201
200
|
* else — the cloud — is left out, and an absent id is a proxy
|
|
202
201
|
* rejection.
|
|
203
202
|
*
|
|
@@ -221,17 +220,17 @@ export function gatewayTargetsFromLockfile(lockfile: {
|
|
|
221
220
|
const gatewayUrl = getGatewayUrl(parsed.data);
|
|
222
221
|
// Cloud assistants are driven through the platform session, never
|
|
223
222
|
// forwarded over this machine's proxy.
|
|
224
|
-
if (
|
|
223
|
+
if (isCloudEntry(parsed.data)) {
|
|
225
224
|
continue;
|
|
226
225
|
}
|
|
227
|
-
if (
|
|
226
|
+
if (isUsableBaseUrl(gatewayUrl) && !isLoopbackPublicUrl(gatewayUrl)) {
|
|
228
227
|
targets.set(assistantId, { kind: "remote", runtimeUrl: gatewayUrl });
|
|
229
228
|
continue;
|
|
230
229
|
}
|
|
231
230
|
if (!isLoopbackGatewayCloud(parsed.data.cloud)) {
|
|
232
231
|
continue;
|
|
233
232
|
}
|
|
234
|
-
const port =
|
|
233
|
+
const port = parsed.data.port;
|
|
235
234
|
if (port != null && port >= MIN_GATEWAY_PORT && port <= MAX_GATEWAY_PORT) {
|
|
236
235
|
targets.set(assistantId, { kind: "loopback", port });
|
|
237
236
|
}
|