@lizard-build/cli 4.0.111 → 4.0.113
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/dist/commands/sandbox-schedules.d.ts +2 -0
- package/dist/commands/sandbox-schedules.js +239 -0
- package/dist/commands/sandbox-schedules.js.map +1 -0
- package/dist/commands/sandbox.js +21 -14
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/lib/skills-data.generated.js +2 -2
- package/dist/lib/skills-data.generated.js.map +1 -1
- package/dist/lib/updater.d.ts +1 -1
- package/dist/lib/updater.js +1 -1
- package/package.json +1 -1
- package/skill-data/core/references/sandboxes.md +31 -2
- package/skill-data/core/references/sdk.md +2 -2
- package/src/commands/sandbox-schedules.ts +230 -0
- package/src/commands/sandbox.ts +22 -16
- package/src/lib/updater.ts +1 -1
- package/test/unit/sandbox.test.ts +38 -5
package/src/commands/sandbox.ts
CHANGED
|
@@ -14,7 +14,8 @@ import { resolveVolume } from "../lib/volume.js";
|
|
|
14
14
|
import { sandboxShell } from "./sandbox-ssh.js";
|
|
15
15
|
import { startVncTunnel, vncTarget } from "./sandbox-vnc.js";
|
|
16
16
|
import { registerSandboxAgentCommands } from "./agents.js";
|
|
17
|
-
import {
|
|
17
|
+
import { registerSandboxScheduleCommands } from "./sandbox-schedules.js";
|
|
18
|
+
import { success, info, warn, error, isJSONMode, printJSON, table, statusColor, timeAgo, isTTY } from "../lib/format.js";
|
|
18
19
|
|
|
19
20
|
// Templates are per-region rows in sandbox_templates, not a constant. Hardcoding them
|
|
20
21
|
// here meant a template that was built, registered and sitting warm in every region was
|
|
@@ -412,6 +413,7 @@ Examples:
|
|
|
412
413
|
});
|
|
413
414
|
|
|
414
415
|
registerSandboxAgentCommands(sb);
|
|
416
|
+
registerSandboxScheduleCommands(sb);
|
|
415
417
|
|
|
416
418
|
sb.command("ssh")
|
|
417
419
|
.alias("shell")
|
|
@@ -598,8 +600,9 @@ Examples:
|
|
|
598
600
|
sb.command("snapshot")
|
|
599
601
|
.argument("<id>", "Running sandbox ID")
|
|
600
602
|
.requiredOption("--name <name>", "Name for this private snapshot")
|
|
601
|
-
|
|
602
|
-
|
|
603
|
+
// A snapshot now restores only in its own project. --scope stays, out of the help, so
|
|
604
|
+
// older scripts still run; it is no longer sent.
|
|
605
|
+
.addOption(new Option("--scope <scope>").choices(SNAPSHOT_SCOPES).hideHelp())
|
|
603
606
|
.option("--no-wait", "Return once capture is queued")
|
|
604
607
|
// Files only by default (the platform's): about a second whatever the RAM, sandboxes started
|
|
605
608
|
// from it boot fresh. --full keeps memory and processes too. Sent as memory: true/false, which
|
|
@@ -609,10 +612,11 @@ Examples:
|
|
|
609
612
|
.description("Save a running sandbox's files (--full: also its memory and running processes)")
|
|
610
613
|
.action(async (id: string, opts) => {
|
|
611
614
|
if (opts.full && opts.fast) throw new Error("Use either --full or --fast, not both");
|
|
615
|
+
if (opts.scope && opts.scope !== "project") warn(`--scope ${opts.scope} has no effect: a snapshot now restores only in its own project.`);
|
|
612
616
|
// No pool size: Firecracker and gVisor snapshots keep no warm copies, and a runc pod
|
|
613
617
|
// (the fallback when a Firecracker create fails) gets the server's default.
|
|
614
618
|
const choice = opts.full ? { memory: true } : opts.fast ? { memory: false } : {};
|
|
615
|
-
const taken = await api.post<SnapshotRecord & { withMemory?: boolean; fastSnapshotUnavailable?: string }>(`/api/sandboxes/${id}/snapshot`, { name: opts.name,
|
|
619
|
+
const taken = await api.post<SnapshotRecord & { withMemory?: boolean; fastSnapshotUnavailable?: string }>(`/api/sandboxes/${id}/snapshot`, { name: opts.name, ...choice });
|
|
616
620
|
let snapshot: SnapshotRecord = taken;
|
|
617
621
|
if (opts.wait) snapshot = await waitForSnapshot(taken.id);
|
|
618
622
|
if (isJSONMode()) printJSON({ ...snapshot, ...(taken.withMemory !== undefined ? { withMemory: taken.withMemory } : {}), ...(taken.fastSnapshotUnavailable ? { fastSnapshotUnavailable: taken.fastSnapshotUnavailable } : {}) });
|
|
@@ -660,7 +664,7 @@ Examples:
|
|
|
660
664
|
sb.command("restore")
|
|
661
665
|
.argument("<snapshot-id>", "Saved snapshot ID")
|
|
662
666
|
.option("--timeout <ms>", "Lifetime in milliseconds; 0 disables expiration", parseTimeoutOption, 300_000)
|
|
663
|
-
.option("-p, --project <id>", "Project to start it in
|
|
667
|
+
.option("-p, --project <id>", "Project to start it in (name, slug, or ID); a snapshot restores only in its own project, the default")
|
|
664
668
|
.option("--volume <name-or-id>", "Mount this volume at /workspace (Firecracker snapshot of a sandbox that had no volume; same region)")
|
|
665
669
|
.description("Start a new sandbox from a private snapshot")
|
|
666
670
|
.action(async (snapshotId: string, opts) => {
|
|
@@ -733,14 +737,16 @@ Examples:
|
|
|
733
737
|
else success(`Snapshot ${chalk.bold(id)} will keep ${count} copies warm`);
|
|
734
738
|
});
|
|
735
739
|
|
|
736
|
-
|
|
740
|
+
// Every snapshot now restores only in its own project, so there is no scope left to change.
|
|
741
|
+
// The command stays, out of the help and without an API call, so older scripts still run.
|
|
742
|
+
sb.command("snapshot-scope", { hidden: true })
|
|
737
743
|
.argument("<snapshot-id>", "Saved snapshot ID")
|
|
738
|
-
.argument("<scope>",
|
|
739
|
-
.description("
|
|
740
|
-
.action(
|
|
741
|
-
const
|
|
742
|
-
if (isJSONMode()) printJSON(
|
|
743
|
-
else
|
|
744
|
+
.argument("<scope>", SNAPSHOT_SCOPES.join(" | "), parseSnapshotScope)
|
|
745
|
+
.description("No longer needed: every snapshot restores only in its own project")
|
|
746
|
+
.action((id: string) => {
|
|
747
|
+
const message = "Nothing to change: every snapshot now restores only in its own project.";
|
|
748
|
+
if (isJSONMode()) printJSON({ id, scope: "project", message });
|
|
749
|
+
else info(message);
|
|
744
750
|
});
|
|
745
751
|
|
|
746
752
|
sb.command("snapshots")
|
|
@@ -753,12 +759,12 @@ Examples:
|
|
|
753
759
|
const { projectId, scope } = await resolveProjectScope(opts.project);
|
|
754
760
|
path = withScope(`/api/projects/${projectId}/snapshots`, scope);
|
|
755
761
|
}
|
|
756
|
-
const snaps = await api.get<Array<{ id: string; template: string; name?: string; region: string; projectId: string;
|
|
762
|
+
const snaps = await api.get<Array<{ id: string; template: string; name?: string; region: string; projectId: string; sourceSandboxId?: string; cpus: number; memoryMb: number; createdAt: number }>>(path);
|
|
757
763
|
if (isJSONMode()) { printJSON(snaps); return; }
|
|
758
764
|
if (!snaps.length) { console.log("No snapshots."); return; }
|
|
759
765
|
table(
|
|
760
|
-
["Snapshot ID", "Name", "
|
|
761
|
-
snaps.map((s) => [s.id, s.name ?? "", s.
|
|
766
|
+
["Snapshot ID", "Name", "Project", "Region", "CPU/Mem", "Created"],
|
|
767
|
+
snaps.map((s) => [s.id, s.name ?? "", s.projectId, s.region, `${s.cpus} vCPU / ${s.memoryMb} MB`, timeAgo(s.createdAt as any)]),
|
|
762
768
|
);
|
|
763
769
|
});
|
|
764
770
|
|
|
@@ -1057,8 +1063,8 @@ interface SnapshotRecord {
|
|
|
1057
1063
|
id: string; name: string; projectId: string; region: string; status: string;
|
|
1058
1064
|
poolSize: number; readyCount: number; error?: string; scope?: string;
|
|
1059
1065
|
}
|
|
1066
|
+
// Old values, still accepted (and ignored) by `snapshot --scope` and `snapshot-scope`.
|
|
1060
1067
|
const SNAPSHOT_SCOPES = ["user", "workspace", "project"];
|
|
1061
|
-
const SCOPE_TEXT: Record<string, string> = { user: "in any of your projects and workspaces", workspace: "only in its own workspace", project: "only in its own project" };
|
|
1062
1068
|
function parseSnapshotScope(value: string): string {
|
|
1063
1069
|
if (!SNAPSHOT_SCOPES.includes(value)) throw new Error(`Scope must be one of: ${SNAPSHOT_SCOPES.join(", ")}`);
|
|
1064
1070
|
return value;
|
package/src/lib/updater.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { join, dirname } from "node:path";
|
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
|
|
8
|
-
export const CURRENT_VERSION = "4.0.
|
|
8
|
+
export const CURRENT_VERSION = "4.0.113";
|
|
9
9
|
const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
|
|
10
10
|
const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
|
|
11
11
|
|
|
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { registerSandbox, lifetimeLine, sandboxNextSteps } from "../../src/commands/sandbox.js";
|
|
4
4
|
import { api, APIError } from "../../src/lib/api.js";
|
|
5
|
-
import { printJSON } from "../../src/lib/format.js";
|
|
5
|
+
import { printJSON, warn } from "../../src/lib/format.js";
|
|
6
6
|
import { getProjectLink, resolveProjectId } from "../../src/lib/config.js";
|
|
7
7
|
|
|
8
8
|
vi.mock("../../src/lib/api.js", () => {
|
|
@@ -18,7 +18,7 @@ vi.mock("../../src/lib/config.js", () => ({
|
|
|
18
18
|
looksLikeId: (v: string) => /^[A-Za-z0-9_-]{21}$/.test(v) && /[A-Z]/.test(v),
|
|
19
19
|
DEFAULT_REGION: "us-east-1",
|
|
20
20
|
}));
|
|
21
|
-
vi.mock("../../src/lib/format.js", () => ({ isJSONMode: () => true, printJSON: vi.fn() }));
|
|
21
|
+
vi.mock("../../src/lib/format.js", () => ({ isJSONMode: () => true, printJSON: vi.fn(), warn: vi.fn() }));
|
|
22
22
|
|
|
23
23
|
function create(args: string[]) {
|
|
24
24
|
const program = new Command().exitOverride();
|
|
@@ -224,13 +224,46 @@ describe("private sandbox snapshots", () => {
|
|
|
224
224
|
it("creates a snapshot without a pool size", async () => {
|
|
225
225
|
const program = new Command().exitOverride(); registerSandbox(program);
|
|
226
226
|
await program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'My app', '--no-wait'], { from: 'user' });
|
|
227
|
-
//
|
|
228
|
-
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app'
|
|
227
|
+
// Never a scope: every snapshot restores only in its own project.
|
|
228
|
+
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app' });
|
|
229
|
+
expect(warn).not.toHaveBeenCalled();
|
|
229
230
|
});
|
|
230
231
|
it.each([[['--full'], { memory: true }], [['--fast'], { memory: false }]])("snapshot %j sends %j", async (flags, choice) => {
|
|
231
232
|
const program = new Command().exitOverride(); registerSandbox(program);
|
|
232
233
|
await program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'My app', ...flags as string[], '--no-wait'], { from: 'user' });
|
|
233
|
-
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app',
|
|
234
|
+
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app', ...choice });
|
|
235
|
+
});
|
|
236
|
+
it.each(['user', 'workspace'])("still takes --scope %s from older scripts, warns and sends no scope", async scope => {
|
|
237
|
+
const program = new Command().exitOverride(); registerSandbox(program);
|
|
238
|
+
await program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'My app', '--scope', scope, '--no-wait'], { from: 'user' });
|
|
239
|
+
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app' });
|
|
240
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
241
|
+
expect(warn).toHaveBeenCalledWith(expect.stringMatching(/only in its own project/));
|
|
242
|
+
});
|
|
243
|
+
it("takes --scope project quietly", async () => {
|
|
244
|
+
const program = new Command().exitOverride(); registerSandbox(program);
|
|
245
|
+
await program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'My app', '--scope', 'project', '--no-wait'], { from: 'user' });
|
|
246
|
+
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app' });
|
|
247
|
+
expect(warn).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
it("hides --scope and snapshot-scope from help", () => {
|
|
250
|
+
const program = new Command().exitOverride(); registerSandbox(program);
|
|
251
|
+
const sandbox = program.commands.find(c => c.name() === 'sandbox')!;
|
|
252
|
+
const snapshot = sandbox.commands.find(c => c.name() === 'snapshot')!;
|
|
253
|
+
expect(snapshot.helpInformation()).not.toMatch(/--scope/);
|
|
254
|
+
expect(sandbox.helpInformation()).not.toMatch(/snapshot-scope/);
|
|
255
|
+
});
|
|
256
|
+
it.each(['user', 'workspace', 'project'])("snapshot-scope %s changes nothing, calls no API and succeeds", async scope => {
|
|
257
|
+
const program = new Command().exitOverride(); registerSandbox(program);
|
|
258
|
+
await program.parseAsync(['sandbox', 'snapshot-scope', 'snap-test', scope], { from: 'user' });
|
|
259
|
+
expect(api.post).not.toHaveBeenCalled();
|
|
260
|
+
expect(api.get).not.toHaveBeenCalled();
|
|
261
|
+
expect(printJSON).toHaveBeenCalledWith({ id: 'snap-test', scope: 'project', message: expect.stringMatching(/only in its own project/) });
|
|
262
|
+
});
|
|
263
|
+
it("snapshot-scope still refuses an unknown scope", async () => {
|
|
264
|
+
const program = new Command().exitOverride().configureOutput({ writeErr: () => {} }); registerSandbox(program);
|
|
265
|
+
await expect(program.parseAsync(['sandbox', 'snapshot-scope', 'snap-test', 'team'], { from: 'user' })).rejects.toThrow(/Scope must be one of/);
|
|
266
|
+
expect(printJSON).not.toHaveBeenCalled();
|
|
234
267
|
});
|
|
235
268
|
it("no longer takes --warm", async () => {
|
|
236
269
|
const program = new Command().exitOverride(); registerSandbox(program);
|