@mycadet/cli 0.13.0-dev.202610291822.708cf19 → 0.13.0-dev.202610301156.c292dd8
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 +1 -1
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +2 -2
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +41 -13
- package/node_modules/@mycadet/local-mode/src/resolve-local-server.test.ts +82 -0
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/package.json +1 -1
- package/scripts/practice-build-remote-images.sh +34 -0
- package/scripts/stage-remote-image-context.ts +30 -0
- package/src/__tests__/multi-local.test.ts +2 -6
- package/src/__tests__/nginx.test.ts +104 -108
- package/src/__tests__/ps-cloud-status.test.ts +0 -1
- package/src/__tests__/root-process-lockfile.test.ts +8 -8
- package/src/__tests__/tailscale.test.ts +3 -5
- package/src/__tests__/teleport-backup.test.ts +3 -3
- package/src/__tests__/tunnel-startup-summary.test.ts +0 -18
- package/src/__tests__/tunnel-stop.test.ts +2 -1
- package/src/__tests__/tunnel.test.ts +7 -12
- package/src/__tests__/uninstall.test.ts +5 -1
- package/src/__tests__/wake.test.ts +15 -58
- package/src/__tests__/web-dist.test.ts +12 -1
- package/src/commands/hatch.ts +1 -4
- package/src/commands/ps.ts +2 -16
- package/src/commands/sleep.ts +0 -1
- package/src/commands/tunnel.ts +4 -1
- package/src/commands/uninstall.ts +5 -1
- package/src/lib/__tests__/cloud-client-signed-url.test.ts +3 -15
- package/src/lib/assistant-client.ts +0 -1
- package/src/lib/assistant-config.ts +6 -11
- package/src/lib/docker.ts +1 -3
- package/src/lib/environments/__tests__/paths.test.ts +10 -4
- package/src/lib/environments/paths.ts +3 -1
- package/src/lib/hatch-local.ts +4 -1
- package/src/lib/local.ts +14 -11
- package/src/lib/remotes/baseten/Dockerfile +6 -1
- package/src/lib/retire-local.ts +4 -1
- package/src/lib/servers/nginx.ts +61 -157
- package/src/lib/tunnel.ts +20 -52
- package/src/lib/tunnels/ngrok.ts +2 -9
- package/src/lib/version-compat.ts +0 -1
- package/src/lib/xdg-log.ts +0 -1
package/knip.json
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
getLoopbackGatewayPort,
|
|
11
11
|
isCloudHome,
|
|
12
12
|
isLoopbackGatewayCloud,
|
|
13
|
-
|
|
13
|
+
isUsableBaseUrl,
|
|
14
14
|
LockfileAssistantSchema,
|
|
15
15
|
} from "./lockfile-contract";
|
|
16
16
|
import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
|
|
@@ -224,7 +224,7 @@ export function gatewayTargetsFromLockfile(lockfile: {
|
|
|
224
224
|
if (isCloudHome(parsed.data.cloud)) {
|
|
225
225
|
continue;
|
|
226
226
|
}
|
|
227
|
-
if (
|
|
227
|
+
if (isUsableBaseUrl(gatewayUrl) && !isLoopbackPublicUrl(gatewayUrl)) {
|
|
228
228
|
targets.set(assistantId, { kind: "remote", runtimeUrl: gatewayUrl });
|
|
229
229
|
continue;
|
|
230
230
|
}
|
|
@@ -95,6 +95,16 @@ export const InjectedConfigSchema = z.object({
|
|
|
95
95
|
|
|
96
96
|
export type InjectedConfig = z.infer<typeof InjectedConfigSchema>;
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* What a host stamps into a served document before parsing is in play: the
|
|
100
|
+
* recorded `remote` may be omitted outright (the schema's parse-time
|
|
101
|
+
* default answers for it) — the edge stamps the truthful recorded kind or
|
|
102
|
+
* nothing, never a served-spelling alias.
|
|
103
|
+
*/
|
|
104
|
+
export type InjectedConfigStamp = Omit<InjectedConfig, "remote"> & {
|
|
105
|
+
remote?: Remote;
|
|
106
|
+
};
|
|
107
|
+
|
|
98
108
|
/**
|
|
99
109
|
* Strip every `SENSITIVE_KEYS` field from a parsed lockfile, in place: from
|
|
100
110
|
* each assistant entry and from that entry's `resources`. The one redaction
|
|
@@ -135,7 +145,7 @@ export function isCloudHome(cloud: unknown): boolean {
|
|
|
135
145
|
* absolute http(s) URL. Shared by the renderer's paired-gateway URL derivation
|
|
136
146
|
* and the host-side paired allowlist reader so the two can't drift.
|
|
137
147
|
*/
|
|
138
|
-
export function
|
|
148
|
+
export function isUsableBaseUrl(url: unknown): url is string {
|
|
139
149
|
if (typeof url !== "string" || url === "") {
|
|
140
150
|
return false;
|
|
141
151
|
}
|
|
@@ -147,6 +157,31 @@ export function isUsableRuntimeUrl(url: unknown): url is string {
|
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
|
|
160
|
+
/**
|
|
161
|
+
* The local build's control-plane base, read from the lockfile alone: the
|
|
162
|
+
* auto-tunnel's recorded `publicUrl` when one is up, else the app server
|
|
163
|
+
* edge's loopback port. A loopback base is reachable from the iOS simulator
|
|
164
|
+
* only — a device's `127.0.0.1` is the phone itself — so a device build
|
|
165
|
+
* wants a tunnel up before it stamps. `undefined` when neither record
|
|
166
|
+
* carries a usable address.
|
|
167
|
+
*
|
|
168
|
+
* The assistants play no role in this resolution — the capacitor app shell
|
|
169
|
+
* only deals with the app server — and the CLI's workspace config is never
|
|
170
|
+
* touched: the lockfile is the single home for edge state.
|
|
171
|
+
*/
|
|
172
|
+
export function resolveLocalServerUrl(): string | undefined {
|
|
173
|
+
const lockfile = readLockfile();
|
|
174
|
+
const tunnelUrl = lockfile.tunnel?.publicUrl;
|
|
175
|
+
if (isUsableBaseUrl(tunnelUrl)) {
|
|
176
|
+
return tunnelUrl;
|
|
177
|
+
}
|
|
178
|
+
const port = lockfile.app?.port;
|
|
179
|
+
if (typeof port === "number") {
|
|
180
|
+
return `http://127.0.0.1:${port}`;
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
150
185
|
/**
|
|
151
186
|
* The id-keyed, same-origin gateway proxy base for any assistant entry: the
|
|
152
187
|
* serving host (Electron `app://` handler, Vite dev middleware, CLI web
|
|
@@ -234,6 +269,7 @@ export function getGatewayUrl(entry: LockfileAssistant): string {
|
|
|
234
269
|
}
|
|
235
270
|
|
|
236
271
|
/**
|
|
272
|
+
|
|
237
273
|
* Per-instance resources for a local assistant: the renderer-facing ports,
|
|
238
274
|
* the instance directory, the local runtime install metadata, and the
|
|
239
275
|
* host-only ports. Strict: every field the CLI round-trips is modeled, so
|
|
@@ -354,23 +390,15 @@ export type TunnelProcessRecord = z.infer<typeof TunnelProcessRecordSchema>;
|
|
|
354
390
|
* tunnel serves a URL, the edge serves a port.
|
|
355
391
|
*/
|
|
356
392
|
export const AppProcessRecordSchema = z.object({
|
|
357
|
-
/**
|
|
358
|
-
* The edge process's bookkeeping, present while the edge runs. Absent on
|
|
359
|
-
* a stamp-only entry: the built-sha stamp below survives the edge's own
|
|
360
|
-
* stop, so between runs the `app` entry may carry only that.
|
|
361
|
-
*/
|
|
393
|
+
/** The edge process's bookkeeping, present while the edge runs. */
|
|
362
394
|
pid: z.number().optional(),
|
|
363
|
-
/** The assistant the edge fronts, so `cadet ps` can nest the row. */
|
|
364
|
-
assistantId: z.string().optional(),
|
|
365
395
|
startedAt: z.string().optional(),
|
|
366
396
|
/** Listening port for the nginx edge. */
|
|
367
|
-
port: z.number()
|
|
397
|
+
port: z.number(),
|
|
368
398
|
/**
|
|
369
399
|
* The commit the edge's source-built client bundles were last built from
|
|
370
|
-
* — the auto-build staleness stamp.
|
|
371
|
-
*
|
|
372
|
-
* state, and survives the edge's own stop (a build-cache fact, not a
|
|
373
|
-
* process fact) so restarting the edge never pays a needless rebuild.
|
|
400
|
+
* — the auto-build staleness stamp. Rides the running edge's record: a
|
|
401
|
+
* build only stamps when an edge record exists to carry it.
|
|
374
402
|
*/
|
|
375
403
|
builtSha: z.string().optional(),
|
|
376
404
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
5
|
+
import { resolveLocalServerUrl } from "./lockfile-contract";
|
|
6
|
+
|
|
7
|
+
describe("resolveLocalServerUrl", () => {
|
|
8
|
+
// The house env pattern: point the config-home resolution at a temp dir
|
|
9
|
+
// per test (pinned to the local environment so the paths line up), and
|
|
10
|
+
// restore the environment afterwards.
|
|
11
|
+
let dir: string;
|
|
12
|
+
let savedEnv: [string, string | undefined][];
|
|
13
|
+
|
|
14
|
+
function writeLockfile(content: string): void {
|
|
15
|
+
mkdirSync(join(dir, "cadet-local"), { recursive: true });
|
|
16
|
+
writeFileSync(join(dir, "cadet-local", "lockfile.json"), content);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
dir = mkdtempSync(join(tmpdir(), "cadet-local-server-"));
|
|
21
|
+
savedEnv = ["CADET_ENVIRONMENT", "XDG_CONFIG_HOME"].map(
|
|
22
|
+
(key) => [key, process.env[key]] as [string, string | undefined],
|
|
23
|
+
);
|
|
24
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
25
|
+
process.env.CADET_ENVIRONMENT = "local";
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
for (const [key, value] of savedEnv) {
|
|
30
|
+
if (value === undefined) Reflect.deleteProperty(process.env, key);
|
|
31
|
+
else process.env[key] = value;
|
|
32
|
+
}
|
|
33
|
+
rmSync(dir, { recursive: true, force: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("the tunnel record's public URL wins when one is up", () => {
|
|
37
|
+
writeLockfile(
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
tunnel: {
|
|
40
|
+
pid: 4321,
|
|
41
|
+
provider: "cadet",
|
|
42
|
+
startedAt: "2026-10-22T00:00:00Z",
|
|
43
|
+
publicUrl: "https://tunnel.example.net",
|
|
44
|
+
},
|
|
45
|
+
app: { pid: 4322, port: 8000 },
|
|
46
|
+
assistants: [],
|
|
47
|
+
activeAssistant: null,
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
expect(resolveLocalServerUrl()).toBe("https://tunnel.example.net");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("without a tunnel, the app server edge's loopback port is the base", () => {
|
|
54
|
+
writeLockfile(
|
|
55
|
+
JSON.stringify({
|
|
56
|
+
app: { pid: 4322, port: 8000 },
|
|
57
|
+
assistants: [],
|
|
58
|
+
activeAssistant: null,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
expect(resolveLocalServerUrl()).toBe("http://127.0.0.1:8000");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("the tunnel's address only counts when it is a usable base URL", () => {
|
|
65
|
+
writeLockfile(
|
|
66
|
+
JSON.stringify({
|
|
67
|
+
tunnel: { publicUrl: "not a url" },
|
|
68
|
+
app: { pid: 4322, port: 8000 },
|
|
69
|
+
assistants: [],
|
|
70
|
+
activeAssistant: null,
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
expect(resolveLocalServerUrl()).toBe("http://127.0.0.1:8000");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("no records resolve to undefined so the caller can fall back", () => {
|
|
77
|
+
writeLockfile(
|
|
78
|
+
JSON.stringify({ assistants: [], activeAssistant: null }),
|
|
79
|
+
);
|
|
80
|
+
expect(resolveLocalServerUrl()).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# practice-build-remote-images.sh — build every remote sandbox image locally.
|
|
3
|
+
#
|
|
4
|
+
# Discovers each remote's Dockerfile (cli/src/lib/remotes/*/Dockerfile),
|
|
5
|
+
# stages its build context through the CLI's own staging code — the exact
|
|
6
|
+
# bytes `cadet hatch --remote <name>` uploads — and docker builds it.
|
|
7
|
+
#
|
|
8
|
+
# The release workflows' ci-remote-images job runs this to gate the
|
|
9
|
+
# @mycadet/cli publish: a broken image recipe (missing apt packages, bad bun
|
|
10
|
+
# pin, hatch regressions) stops the release before anything ships.
|
|
11
|
+
#
|
|
12
|
+
# The build pins the latest PUBLISHED mycadet: pre-publish, the version being
|
|
13
|
+
# released is not on npm yet, so this validates the image recipe; the
|
|
14
|
+
# release's own bits are validated by the ci-* family.
|
|
15
|
+
set -euo pipefail
|
|
16
|
+
|
|
17
|
+
repo_root="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
18
|
+
cd "$repo_root"
|
|
19
|
+
|
|
20
|
+
published=$(npm view mycadet version)
|
|
21
|
+
echo "Practice-building remote images against published mycadet@${published}"
|
|
22
|
+
|
|
23
|
+
shopt -s nullglob
|
|
24
|
+
dockerfiles=(cli/src/lib/remotes/*/Dockerfile)
|
|
25
|
+
[ ${#dockerfiles[@]} -gt 0 ] || { echo "::error::no remote Dockerfiles found"; exit 1; }
|
|
26
|
+
|
|
27
|
+
for dockerfile in "${dockerfiles[@]}"; do
|
|
28
|
+
remote=$(basename "$(dirname "${dockerfile}")")
|
|
29
|
+
echo "== remote: ${remote} =="
|
|
30
|
+
staged=$(bun cli/scripts/stage-remote-image-context.ts --remote "${remote}")
|
|
31
|
+
sed -i "s/^ARG MYCADET_VERSION=.*/ARG MYCADET_VERSION=\"${published}\"/" "${staged}/Dockerfile"
|
|
32
|
+
docker build -t "cadet-remote-practice:${remote}" "${staged}"
|
|
33
|
+
rm -rf "${staged}"
|
|
34
|
+
done
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// stage-remote-image-context.ts — stage a remote sandbox image build context
|
|
2
|
+
// for CI practice builds.
|
|
3
|
+
//
|
|
4
|
+
// Uses the CLI's own staging code so the practice build exercises the exact
|
|
5
|
+
// context `cadet hatch --remote <name>` uploads — not a parallel shell
|
|
6
|
+
// imitation that can drift. Prints the staged directory; the caller
|
|
7
|
+
// (cli/scripts/practice-build-remote-images.sh) owns cleanup.
|
|
8
|
+
//
|
|
9
|
+
// Usage: bun cli/scripts/stage-remote-image-context.ts --remote <name>
|
|
10
|
+
|
|
11
|
+
import { stageBasetenBuildContext } from "../src/lib/remotes/baseten/context.js";
|
|
12
|
+
|
|
13
|
+
const argv = process.argv.slice(2);
|
|
14
|
+
const remoteFlag = argv.indexOf("--remote");
|
|
15
|
+
const remote = remoteFlag >= 0 ? argv[remoteFlag + 1] : undefined;
|
|
16
|
+
if (!remote) {
|
|
17
|
+
console.error("usage: bun cli/scripts/stage-remote-image-context.ts --remote <name>");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
switch (remote) {
|
|
22
|
+
case "baseten": {
|
|
23
|
+
const staged = stageBasetenBuildContext();
|
|
24
|
+
console.log(staged.dir);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
default:
|
|
28
|
+
console.error(`unknown remote "${remote}" — supported: baseten`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
@@ -316,10 +316,7 @@ describe("multi-local", () => {
|
|
|
316
316
|
describe("remote non-regression", () => {
|
|
317
317
|
test("resolveTargetAssistant works with remote entries", () => {
|
|
318
318
|
writeLockfile({
|
|
319
|
-
assistants: [
|
|
320
|
-
makeEntry("my-remote", "custom", {
|
|
321
|
-
}),
|
|
322
|
-
],
|
|
319
|
+
assistants: [makeEntry("my-remote", "custom", {})],
|
|
323
320
|
activeAssistant: "my-remote",
|
|
324
321
|
});
|
|
325
322
|
const result = resolveTargetAssistant();
|
|
@@ -328,8 +325,7 @@ describe("multi-local", () => {
|
|
|
328
325
|
});
|
|
329
326
|
|
|
330
327
|
test("remote entries don't get resources applied", () => {
|
|
331
|
-
const remoteEntry = makeEntry("cloud-box", "custom", {
|
|
332
|
-
});
|
|
328
|
+
const remoteEntry = makeEntry("cloud-box", "custom", {});
|
|
333
329
|
writeLockfile({ assistants: [remoteEntry] });
|
|
334
330
|
// Save and reload to verify resources are not injected
|
|
335
331
|
saveLockfileAssistant(remoteEntry);
|