@lizard-build/cli 4.0.110 → 4.0.112

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.
@@ -0,0 +1,230 @@
1
+ import chalk from "chalk";
2
+ import fs from "node:fs";
3
+ import { Command, InvalidArgumentError } from "commander";
4
+ import { api } from "../lib/api.js";
5
+ import { success, info, isJSONMode, printJSON, table, timeAgo, fail } from "../lib/format.js";
6
+
7
+ // Sandbox schedules: the platform wakes a paused sandbox on a timer, runs a prompt (the coding
8
+ // agent) or a shell command in it, and puts it back to sleep. Server: /api/sandboxes/:id/schedules
9
+ // and /api/sandbox-schedules/:sid.
10
+
11
+ interface Schedule {
12
+ id: string; sandboxId: string; name: string | null;
13
+ every: string | null; cron: string | null; timezone: string;
14
+ kind: "prompt" | "command"; prompt: string | null; command: string | null;
15
+ agent: string | null; model: string | null; timeoutSeconds: number; keepMemory: boolean;
16
+ enabled: boolean; disabledReason: string | null; nextRunAt: string | null; running: boolean;
17
+ lastRunAt: string | null; lastStatus: string | null; consecutiveFailures: number; skippedCount: number;
18
+ }
19
+
20
+ interface Run {
21
+ id: string; status: string; woke: boolean; slept: boolean; startedAt: string; endedAt: string | null;
22
+ durationMs: number | null; exitCode: number | null; conversationId: string | null; output: string | null; error: string | null;
23
+ }
24
+
25
+ /** "10m", "90s", "2h", or plain seconds -> seconds. */
26
+ function parseDuration(v: string): number {
27
+ const m = v.trim().toLowerCase().match(/^(\d+)\s*(s|m|h|d)?$/);
28
+ if (!m) throw new InvalidArgumentError("Use e.g. 30s, 10m, 2h");
29
+ return Number(m[1]) * { s: 1, m: 60, h: 3600, d: 86400 }[(m[2] ?? "s") as "s"];
30
+ }
31
+
32
+ const when = (s: Schedule) => (s.every ? `every ${s.every}` : `cron ${s.cron}${s.timezone !== "UTC" ? ` (${s.timezone})` : ""}`);
33
+ const what = (s: Schedule) => {
34
+ const t = (s.kind === "prompt" ? s.prompt : s.command) ?? "";
35
+ const one = t.replace(/\s+/g, " ").trim();
36
+ return `${s.kind === "prompt" ? chalk.cyan(s.agent ?? "agent") : chalk.magenta("$")} ${one.length > 50 ? one.slice(0, 49) + "…" : one}`;
37
+ };
38
+ const inFuture = (iso: string) => {
39
+ const s = Math.round((Date.parse(iso) - Date.now()) / 1000);
40
+ if (s <= 0) return "now";
41
+ if (s < 60) return `in ${s}s`;
42
+ if (s < 3600) return `in ${Math.round(s / 60)}m`;
43
+ if (s < 86400) return `in ${Math.round(s / 3600)}h`;
44
+ return `in ${Math.round(s / 86400)}d`;
45
+ };
46
+ const runStatus = (st: string | null) =>
47
+ !st ? chalk.dim("-") : st === "succeeded" ? chalk.green(st) : st === "running" ? chalk.yellow(st) : chalk.red(st);
48
+
49
+ function printSchedule(s: Schedule) {
50
+ console.log(`${chalk.bold(s.id)}${s.name ? ` ${s.name}` : ""} ${s.enabled ? chalk.green("on") : chalk.dim("off")}`);
51
+ console.log(` sandbox ${s.sandboxId}`);
52
+ console.log(` when ${when(s)}${s.enabled && s.nextRunAt ? chalk.dim(` (next ${inFuture(s.nextRunAt)})`) : ""}`);
53
+ console.log(` runs ${what(s)}`);
54
+ console.log(` timeout ${s.timeoutSeconds}s${s.keepMemory ? " sleeps with memory" : " sleeps files-only"}`);
55
+ if (s.lastRunAt) console.log(` last run ${runStatus(s.running ? "running" : s.lastStatus)} ${chalk.dim(timeAgo(s.lastRunAt))}`);
56
+ if (s.disabledReason) console.log(chalk.yellow(` off: ${s.disabledReason}`));
57
+ }
58
+
59
+ function addTaskOptions(c: Command, forCreate: boolean) {
60
+ return c
61
+ .option("--every <interval>", "How often: 1m minimum, e.g. 5m, 1h, 1d")
62
+ .option("--cron <expr>", 'Cron instead: "m h dom mon dow", e.g. "*/5 * * * *", "0 9 * * mon-fri", @daily')
63
+ .option("--tz <zone>", "Time zone for --cron (IANA name, e.g. Europe/Berlin)")
64
+ .option("--prompt <text>", "Run the coding agent with this prompt (a new conversation each run)")
65
+ .option("--prompt-file <path>", "Read the prompt from a file")
66
+ .option("--command <cmd>", "Run this shell command instead (in /workspace, as root)")
67
+ .option("--agent <agent>", "Agent for --prompt (codex, claude, ...)")
68
+ .option("-m, --model <model>", "Model for --prompt")
69
+ .option("--effort <level>", "Reasoning effort for --prompt (minimal, low, medium, high, xhigh)")
70
+ .option("--timeout <duration>", forCreate ? "Stop a run after this long (default 10m)" : "Stop a run after this long", parseDuration)
71
+ .option("--keep-memory", "Sleep with memory: processes and open apps survive between runs (slower pause)")
72
+ .option("--files-only", "Sleep with files only (the default): fast, processes end")
73
+ .option("--name <name>", "A label for the schedule");
74
+ }
75
+
76
+ function taskBody(opts: Record<string, any>): Record<string, unknown> {
77
+ const body: Record<string, unknown> = {};
78
+ if (opts.every) body.every = opts.every;
79
+ if (opts.cron) body.cron = opts.cron;
80
+ if (opts.tz) body.timezone = opts.tz;
81
+ if (opts.promptFile) body.prompt = fs.readFileSync(opts.promptFile, "utf8");
82
+ if (opts.prompt) body.prompt = opts.prompt;
83
+ if (opts.command) body.command = opts.command;
84
+ if (opts.agent) body.agent = opts.agent;
85
+ if (opts.model) body.model = opts.model;
86
+ if (opts.effort) body.reasoningEffort = opts.effort;
87
+ if (opts.timeout) body.timeoutSeconds = opts.timeout;
88
+ if (opts.keepMemory) body.keepMemory = true;
89
+ if (opts.filesOnly) body.keepMemory = false;
90
+ if (opts.name) body.name = opts.name;
91
+ return body;
92
+ }
93
+
94
+ export function registerSandboxScheduleCommands(sb: Command) {
95
+ addTaskOptions(
96
+ sb.command("schedule")
97
+ .argument("<id>", "Sandbox ID")
98
+ .description("Wake the sandbox on a schedule, run a prompt or command, put it back to sleep"),
99
+ true,
100
+ )
101
+ .option("--disabled", "Create it switched off")
102
+ .addHelpText("after", `
103
+ Each run: a paused sandbox is woken (about a second), the prompt or command runs, and the
104
+ sandbox goes back to sleep. A sandbox that was already running is left running. You pay only
105
+ while it is awake. Files in /workspace carry over between runs; with --keep-memory, running
106
+ processes and open apps (a desktop's browser) do too.
107
+
108
+ A run that is still going when the next one is due makes that one skip. Five failed runs in
109
+ a row switch the schedule off.
110
+
111
+ Examples:
112
+ lizard sandbox schedule sb_abc123 --every 5m --prompt "Continue the research in /workspace/research; append findings to notes.md"
113
+ lizard sandbox schedule sb_abc123 --every 10m --command "python3 /workspace/job.py"
114
+ lizard sandbox schedule sb_abc123 --cron "0 9 * * mon-fri" --tz Europe/Berlin --command "./report.sh"
115
+ lizard sandbox schedule sb_desktop --every 30m --keep-memory --command "node /workspace/check.js"`)
116
+ .action(async (id: string, opts) => {
117
+ if (!opts.every && !opts.cron) fail("Say how often: --every 5m, or --cron \"*/5 * * * *\"", 2, "USAGE");
118
+ if (!opts.prompt && !opts.promptFile && !opts.command) fail("Say what to run: --prompt \"...\" or --command \"...\"", 2, "USAGE");
119
+ const body = taskBody(opts);
120
+ if (opts.disabled) body.enabled = false;
121
+ const s = await api.post<Schedule>(`/api/sandboxes/${id}/schedules`, body);
122
+ if (isJSONMode()) return printJSON(s);
123
+ success(`Scheduled ${chalk.bold(s.id)}: ${when(s)}${s.nextRunAt ? `, first run ${inFuture(s.nextRunAt)}` : ""}`);
124
+ info(chalk.dim(` lizard sandbox schedule-run ${s.id} run it now`));
125
+ info(chalk.dim(` lizard sandbox schedule-runs ${s.id} see how runs went`));
126
+ });
127
+
128
+ sb.command("schedules")
129
+ .argument("[id]", "Only this sandbox's schedules")
130
+ .description("List sandbox schedules")
131
+ .action(async (id?: string) => {
132
+ const { schedules } = id
133
+ ? await api.get<{ schedules: Schedule[] }>(`/api/sandboxes/${id}/schedules`)
134
+ : await api.get<{ schedules: Schedule[] }>(`/api/sandbox-schedules`);
135
+ if (isJSONMode()) return printJSON(schedules);
136
+ if (!schedules.length) return info("No schedules. Create one: lizard sandbox schedule <id> --every 5m --prompt \"...\"");
137
+ table(["id", "sandbox", "when", "runs", "next", "last"], schedules.map((s) => [
138
+ s.id, s.sandboxId, when(s), what(s),
139
+ !s.enabled ? chalk.dim("off") : s.running ? chalk.yellow("running") : s.nextRunAt ? inFuture(s.nextRunAt) : "-",
140
+ s.lastRunAt ? `${runStatus(s.lastStatus)} ${chalk.dim(timeAgo(s.lastRunAt))}` : chalk.dim("-"),
141
+ ]));
142
+ });
143
+
144
+ sb.command("schedule-show")
145
+ .argument("<scheduleId>", "Schedule ID (sch_...)")
146
+ .description("Show a schedule")
147
+ .action(async (sid: string) => {
148
+ const s = await api.get<Schedule>(`/api/sandbox-schedules/${sid}`);
149
+ if (isJSONMode()) return printJSON(s);
150
+ printSchedule(s);
151
+ const text = s.kind === "prompt" ? s.prompt : s.command;
152
+ if (text) console.log(chalk.dim(`\n${text}`));
153
+ });
154
+
155
+ addTaskOptions(
156
+ sb.command("schedule-set")
157
+ .argument("<scheduleId>", "Schedule ID (sch_...)")
158
+ .description("Change a schedule: timing, what it runs, or switch it on/off"),
159
+ false,
160
+ )
161
+ .option("--on", "Switch it on")
162
+ .option("--off", "Switch it off")
163
+ .action(async (sid: string, opts) => {
164
+ const body = taskBody(opts);
165
+ if (opts.on) body.enabled = true;
166
+ if (opts.off) body.enabled = false;
167
+ if (!Object.keys(body).length) fail("Nothing to change: give an option, e.g. --every 10m or --off", 2, "USAGE");
168
+ const s = await api.patch<Schedule>(`/api/sandbox-schedules/${sid}`, body);
169
+ if (isJSONMode()) return printJSON(s);
170
+ success(`Updated ${chalk.bold(s.id)}`);
171
+ printSchedule(s);
172
+ });
173
+
174
+ sb.command("schedule-run")
175
+ .argument("<scheduleId>", "Schedule ID (sch_...)")
176
+ .description("Run a schedule now (also switches it back on)")
177
+ .option("--wait", "Wait for the run to finish and print it")
178
+ .action(async (sid: string, opts) => {
179
+ const before = await api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${sid}/runs?limit=1`);
180
+ const s = await api.post<Schedule>(`/api/sandbox-schedules/${sid}/run`, {});
181
+ if (!opts.wait) {
182
+ if (isJSONMode()) return printJSON(s);
183
+ return success(`Run of ${chalk.bold(sid)} queued: it starts within a few seconds. See it: lizard sandbox schedule-runs ${sid}`);
184
+ }
185
+ const prev = before.runs[0]?.id;
186
+ let run: Run | undefined;
187
+ for (let i = 0; i < 24 * 60 * 6; i++) {
188
+ await new Promise((r) => setTimeout(r, 5000));
189
+ const { runs } = await api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${sid}/runs?limit=1`);
190
+ if (runs[0] && runs[0].id !== prev) { run = runs[0]; if (run.status !== "running") break; }
191
+ }
192
+ if (isJSONMode()) return printJSON(run ?? null);
193
+ if (run) printRun(run, true);
194
+ });
195
+
196
+ sb.command("schedule-runs")
197
+ .argument("<scheduleId>", "Schedule ID (sch_...)")
198
+ .description("Show a schedule's recent runs; --output prints the latest run's output")
199
+ .option("-n, --limit <n>", "How many runs", "20")
200
+ .option("-o, --output", "Print the latest run's output in full")
201
+ .action(async (sid: string, opts) => {
202
+ const { runs } = await api.get<{ runs: Run[] }>(`/api/sandbox-schedules/${sid}/runs?limit=${Number(opts.limit) || 20}`);
203
+ if (isJSONMode()) return printJSON(runs);
204
+ if (!runs.length) return info("No runs yet.");
205
+ if (opts.output) return printRun(runs[0], true);
206
+ table(["run", "status", "started", "took", "exit", "note"], runs.map((r) => [
207
+ r.id, runStatus(r.status), timeAgo(r.startedAt), r.durationMs != null ? `${Math.round(r.durationMs / 1000)}s` : "-",
208
+ r.exitCode != null ? String(r.exitCode) : "-",
209
+ (r.error ?? (r.output ?? "").trim().split("\n").pop() ?? "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 60),
210
+ ]));
211
+ });
212
+
213
+ sb.command("unschedule")
214
+ .alias("schedule-rm")
215
+ .argument("<scheduleId>", "Schedule ID (sch_...)")
216
+ .description("Delete a schedule")
217
+ .action(async (sid: string) => {
218
+ await api.delete(`/api/sandbox-schedules/${sid}`);
219
+ if (isJSONMode()) return printJSON({ id: sid, deleted: true });
220
+ success(`Schedule ${chalk.bold(sid)} deleted`);
221
+ });
222
+ }
223
+
224
+ function printRun(r: Run, full: boolean) {
225
+ const took = r.durationMs != null ? `${Math.round(r.durationMs / 1000)}s` : "still running";
226
+ console.log(`${chalk.bold(r.id)} ${runStatus(r.status)} ${chalk.dim(`${timeAgo(r.startedAt)}, ${took}${r.exitCode != null ? `, exit ${r.exitCode}` : ""}${r.woke ? ", woke the sandbox" : ""}${r.slept ? ", back asleep" : ""}`)}`);
227
+ if (r.conversationId) console.log(chalk.dim(` conversation ${r.conversationId}`));
228
+ if (r.error) console.log(chalk.red(` ${r.error}`));
229
+ if (full && r.output) console.log(`\n${r.output.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")}`);
230
+ }
@@ -14,6 +14,7 @@ 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 { registerSandboxScheduleCommands } from "./sandbox-schedules.js";
17
18
  import { success, info, 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
@@ -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")
@@ -24,7 +24,18 @@ function joinMessage(words: string[]): string {
24
24
  export function registerSupport(program: Command) {
25
25
  const support = program
26
26
  .command("support")
27
- .description("Tickets to the Lizard team: something on Lizard is broken, or you need higher limits / a bigger plan. Replies appear after your next lizard command.");
27
+ .description("Tickets to the Lizard team: something on Lizard is broken, or you need higher limits / a bigger plan. Replies appear after your next lizard command.")
28
+ .addHelpText("after", `
29
+ How to report a problem:
30
+ 1. Is it Lizard's fault? Not for your own typos, build errors or app bugs.
31
+ 2. Already reported? lizard support list
32
+ If an open ticket covers it: lizard support reply <ticket> "<new details>"
33
+ 3. Otherwise open one, written like a bug report:
34
+ lizard support open "<what you ran> fails with <exact error> since <when>" \\
35
+ --expected "<what should happen>" --sandbox <id> | --app <name>
36
+ Last failed calls, CLI version and OS are attached. No secrets or keys.
37
+ Limits or billing: --type limits / --type billing, say what you need and why.
38
+ Replies show after your next lizard command.`);
28
39
 
29
40
  support
30
41
  .command("open")
@@ -76,7 +76,7 @@ export function wantsSupportHint(opts: { status?: number; code?: string; exitCod
76
76
  return true;
77
77
  }
78
78
 
79
- export const SUPPORT_HINT = 'Lizard bug? Optional: lizard support open "<what happened>"';
79
+ export const SUPPORT_HINT = "Lizard bug? Optional: lizard support --help";
80
80
 
81
81
  interface UnreadTicket { ticket: string; subject: string; status: string; messages: Array<{ from: string; body: string; at: string }> }
82
82
 
@@ -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.110";
8
+ export const CURRENT_VERSION = "4.0.112";
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